Move request engine callbacks to req structure

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2021-03-05 11:20:47 +01:00
parent 0e699fc982
commit ce2ff14150
6 changed files with 20 additions and 18 deletions

View File

@ -449,25 +449,24 @@ static void _ocf_engine_clean_end(void *private_data, int error)
} }
} }
static int lock_clines(struct ocf_request *req, static int _lock_clines(struct ocf_request *req)
const struct ocf_engine_callbacks *engine_cbs)
{ {
enum ocf_engine_lock_type lock_type = engine_cbs->get_lock_type(req);
struct ocf_cache_line_concurrency *c = struct ocf_cache_line_concurrency *c =
req->cache->device->concurrency.cache_line; req->cache->device->concurrency.cache_line;
enum ocf_engine_lock_type lock_type =
req->engine_cbs->get_lock_type(req);
switch (lock_type) { switch (lock_type) {
case ocf_engine_lock_write: case ocf_engine_lock_write:
return ocf_req_async_lock_wr(c, req, engine_cbs->resume); return ocf_req_async_lock_wr(c, req, req->engine_cbs->resume);
case ocf_engine_lock_read: case ocf_engine_lock_read:
return ocf_req_async_lock_rd(c, req, engine_cbs->resume); return ocf_req_async_lock_rd(c, req, req->engine_cbs->resume);
default: default:
return OCF_LOCK_ACQUIRED; return OCF_LOCK_ACQUIRED;
} }
} }
static inline int ocf_prepare_clines_miss(struct ocf_request *req, static inline int ocf_prepare_clines_miss(struct ocf_request *req)
const struct ocf_engine_callbacks *engine_cbs)
{ {
int lock_status = -OCF_ERR_NO_LOCK; int lock_status = -OCF_ERR_NO_LOCK;
struct ocf_metadata_lock *metadata_lock = &req->cache->metadata.lock; struct ocf_metadata_lock *metadata_lock = &req->cache->metadata.lock;
@ -490,7 +489,7 @@ static inline int ocf_prepare_clines_miss(struct ocf_request *req,
ocf_engine_map(req); ocf_engine_map(req);
if (!ocf_req_test_mapping_error(req)) { if (!ocf_req_test_mapping_error(req)) {
lock_status = lock_clines(req, engine_cbs); lock_status = _lock_clines(req);
if (lock_status < 0) { if (lock_status < 0) {
/* Mapping succeeded, but we failed to acquire cacheline lock. /* Mapping succeeded, but we failed to acquire cacheline lock.
* Don't try to evict, just return error to caller */ * Don't try to evict, just return error to caller */
@ -523,7 +522,7 @@ eviction:
if (ocf_req_test_mapping_error(req)) if (ocf_req_test_mapping_error(req))
goto unlock; goto unlock;
lock_status = lock_clines(req, engine_cbs); lock_status = _lock_clines(req);
if (lock_status < 0) if (lock_status < 0)
ocf_req_set_mapping_error(req); ocf_req_set_mapping_error(req);
@ -533,8 +532,7 @@ unlock:
return lock_status; return lock_status;
} }
int ocf_engine_prepare_clines(struct ocf_request *req, int ocf_engine_prepare_clines(struct ocf_request *req)
const struct ocf_engine_callbacks *engine_cbs)
{ {
bool mapped; bool mapped;
bool promote = true; bool promote = true;
@ -553,7 +551,7 @@ int ocf_engine_prepare_clines(struct ocf_request *req,
mapped = ocf_engine_is_mapped(req); mapped = ocf_engine_is_mapped(req);
if (mapped) { if (mapped) {
lock = lock_clines(req, engine_cbs); lock = _lock_clines(req);
ocf_hb_req_prot_unlock_rd(req); ocf_hb_req_prot_unlock_rd(req);
return lock; return lock;
} }
@ -567,7 +565,7 @@ int ocf_engine_prepare_clines(struct ocf_request *req,
return lock; return lock;
} }
return ocf_prepare_clines_miss(req, engine_cbs); return ocf_prepare_clines_miss(req);
} }
static int _ocf_engine_clean_getter(struct ocf_cache *cache, static int _ocf_engine_clean_getter(struct ocf_cache *cache,

View File

@ -245,8 +245,7 @@ struct ocf_engine_callbacks
* @retval LOOKUP_INSERTED successfully evicted required number of cachelines * @retval LOOKUP_INSERTED successfully evicted required number of cachelines
* @retval LOOKUP_MISS eviction failure * @retval LOOKUP_MISS eviction failure
*/ */
int ocf_engine_prepare_clines(struct ocf_request *req, int ocf_engine_prepare_clines(struct ocf_request *req);
const struct ocf_engine_callbacks *engine_cbs);
/** /**
* @brief Traverse OCF request (lookup cache) * @brief Traverse OCF request (lookup cache)

View File

@ -242,8 +242,9 @@ int ocf_read_generic(struct ocf_request *req)
/* Set resume call backs */ /* Set resume call backs */
req->io_if = &_io_if_read_generic_resume; req->io_if = &_io_if_read_generic_resume;
req->engine_cbs = &_rd_engine_callbacks;
lock = ocf_engine_prepare_clines(req, &_rd_engine_callbacks); lock = ocf_engine_prepare_clines(req);
if (!ocf_req_test_mapping_error(req)) { if (!ocf_req_test_mapping_error(req)) {
if (lock >= 0) { if (lock >= 0) {

View File

@ -189,10 +189,11 @@ int ocf_write_wb(struct ocf_request *req)
/* Set resume io_if */ /* Set resume io_if */
req->io_if = &_io_if_wb_resume; req->io_if = &_io_if_wb_resume;
req->engine_cbs = &_wb_engine_callbacks;
/* TODO: Handle fits into dirty */ /* TODO: Handle fits into dirty */
lock = ocf_engine_prepare_clines(req, &_wb_engine_callbacks); lock = ocf_engine_prepare_clines(req);
if (!ocf_req_test_mapping_error(req)) { if (!ocf_req_test_mapping_error(req)) {
if (lock >= 0) { if (lock >= 0) {

View File

@ -178,8 +178,9 @@ int ocf_write_wt(struct ocf_request *req)
/* Set resume io_if */ /* Set resume io_if */
req->io_if = &_io_if_wt_resume; req->io_if = &_io_if_wt_resume;
req->engine_cbs = &_wt_engine_callbacks;
lock = ocf_engine_prepare_clines(req, &_wt_engine_callbacks); lock = ocf_engine_prepare_clines(req);
if (!ocf_req_test_mapping_error(req)) { if (!ocf_req_test_mapping_error(req)) {
if (lock >= 0) { if (lock >= 0) {

View File

@ -103,6 +103,8 @@ struct ocf_request {
struct ocf_io_internal ioi; struct ocf_io_internal ioi;
/*!< OCF IO associated with request */ /*!< OCF IO associated with request */
const struct ocf_engine_callbacks *engine_cbs;
env_atomic ref_count; env_atomic ref_count;
/*!< Reference usage count, once OCF request reaches zero it /*!< Reference usage count, once OCF request reaches zero it
* will be de-initialed. Get/Put method are intended to modify * will be de-initialed. Get/Put method are intended to modify