Move common mapping and locking logic to dedicated function
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
@@ -158,12 +158,20 @@ static const struct ocf_io_if _io_if_wt_resume = {
|
||||
.write = _ocf_write_wt_do,
|
||||
};
|
||||
|
||||
static enum ocf_engine_lock_type ocf_wt_get_lock_type(struct ocf_request *req)
|
||||
{
|
||||
return ocf_engine_lock_write;
|
||||
}
|
||||
|
||||
static const struct ocf_engine_callbacks _wt_engine_callbacks =
|
||||
{
|
||||
.get_lock_type = ocf_wt_get_lock_type,
|
||||
.resume = ocf_engine_on_resume,
|
||||
};
|
||||
|
||||
int ocf_write_wt(struct ocf_request *req)
|
||||
{
|
||||
bool mapped;
|
||||
int lock = OCF_LOCK_NOT_ACQUIRED;
|
||||
bool promote = true;
|
||||
struct ocf_metadata_lock *metadata_lock = &req->cache->metadata.lock;
|
||||
|
||||
ocf_io_start(&req->ioi.io);
|
||||
|
||||
@@ -173,45 +181,9 @@ int ocf_write_wt(struct ocf_request *req)
|
||||
/* Set resume io_if */
|
||||
req->io_if = &_io_if_wt_resume;
|
||||
|
||||
ocf_req_hash(req);
|
||||
ocf_req_hash_lock_rd(req); /*- Metadata READ access, No eviction --------*/
|
||||
lock = ocf_engine_prepare_clines(req, &_wt_engine_callbacks);
|
||||
|
||||
/* Travers to check if request is mapped fully */
|
||||
ocf_engine_traverse(req);
|
||||
|
||||
mapped = ocf_engine_is_mapped(req);
|
||||
if (mapped) {
|
||||
/* All cache line are mapped, lock request for WRITE access */
|
||||
lock = ocf_req_async_lock_wr(req, ocf_engine_on_resume);
|
||||
} else {
|
||||
promote = ocf_promotion_req_should_promote(
|
||||
req->cache->promotion_policy, req);
|
||||
}
|
||||
|
||||
if (mapped || !promote) {
|
||||
ocf_req_hash_unlock_rd(req);
|
||||
} else {
|
||||
/*- Metadata RD access ---------------------------------------*/
|
||||
ocf_req_hash_lock_upgrade(req);
|
||||
ocf_engine_map(req);
|
||||
ocf_req_hash_unlock_wr(req);
|
||||
|
||||
if (req->info.mapping_error) {
|
||||
/* Still not mapped - evict cachelines under global
|
||||
* metadata write lock */
|
||||
ocf_metadata_start_exclusive_access(metadata_lock);
|
||||
if (ocf_engine_evict(req) == LOOKUP_MAPPED)
|
||||
ocf_engine_map(req);
|
||||
ocf_metadata_end_exclusive_access(metadata_lock);
|
||||
}
|
||||
|
||||
if (!req->info.mapping_error) {
|
||||
/* Lock request for WRITE access */
|
||||
lock = ocf_req_async_lock_wr(req, ocf_engine_on_resume);
|
||||
}
|
||||
}
|
||||
|
||||
if (promote && !req->info.mapping_error) {
|
||||
if (!req->info.mapping_error) {
|
||||
if (lock >= 0) {
|
||||
if (lock != OCF_LOCK_ACQUIRED) {
|
||||
/* WR lock was not acquired, need to wait for resume */
|
||||
|
Reference in New Issue
Block a user