Skip to content

Commit

Permalink
cleanup req->error setting
Browse files Browse the repository at this point in the history
Signed-off-by: Damian Raczkowski <[email protected]>
  • Loading branch information
Damian-Raczkowski committed Nov 2, 2022
1 parent 43894dd commit 8135cc4
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 80 deletions.
6 changes: 3 additions & 3 deletions src/engine/engine_bf.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ static void _ocf_backfill_complete(struct ocf_request *req, int error)
struct ocf_cache *cache = req->cache;

if (error) {
req->error = error;
env_atomic_cmpxchg(&req->error, 0, error);
ocf_core_stats_cache_error_update(req->core, OCF_WRITE);
}

if (req->error)
if (req->error.counter)
inc_fallback_pt_error_counter(req->cache);

/* Handle callback-caller race to let only one of the two complete the
Expand All @@ -64,7 +64,7 @@ static void _ocf_backfill_complete(struct ocf_request *req, int error)
ctx_data_free(cache->owner, req->data);
req->data = NULL;

if (req->error) {
if (req->error.counter) {
ocf_engine_invalidate(req);
} else {
ocf_req_unlock(ocf_cache_line_concurrency(cache), req);
Expand Down
9 changes: 5 additions & 4 deletions src/engine/engine_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ static void _ocf_engine_clean_end(void *private_data, int error)

if (error) {
OCF_DEBUG_RQ(req, "Cleaning ERROR");
req->error |= error;
env_atomic_cmpxchg(&req->error, 0, error);


/* End request and do not processing */
ocf_req_unlock(ocf_cache_line_concurrency(req->cache),
Expand Down Expand Up @@ -648,7 +649,7 @@ void ocf_engine_push_req_front_cb(struct ocf_request *req,
ocf_engine_cb engine_cb,
bool allow_sync)
{
req->error = 0; /* Please explain why!!! */
env_atomic_cmpxchg(&req->error, 0, 0);/* Please explain why!!! */
req->engine_handler = engine_cb;
ocf_engine_push_req_front(req, allow_sync);
}
Expand Down Expand Up @@ -687,10 +688,10 @@ static int _ocf_engine_refresh(struct ocf_request *req)
req->engine_handler(req);
} else {
ENV_WARN(true, "Inconsistent request");
req->error = -OCF_ERR_INVAL;
env_atomic_cmpxchg(&req->error, 0, -OCF_ERR_INVAL);

/* Complete request */
req->complete(req, req->error);
req->complete(req, req->error.counter);

/* Release WRITE lock of request */
ocf_req_unlock(ocf_cache_line_concurrency(req->cache), req);
Expand Down
6 changes: 3 additions & 3 deletions src/engine/engine_d2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

static void _ocf_d2c_completion(struct ocf_request *req, int error)
{
req->error = error;
env_atomic_cmpxchg(&req->error, 0, error);

OCF_DEBUG_RQ(req, "Completion");

if (req->error) {
if (req->error.counter) {
req->info.core_error = 1;
ocf_core_stats_core_error_update(req->core, req->rw);
}

/* Complete request */
req->complete(req, req->error);
req->complete(req, req->error.counter);

/* Release OCF request */
ocf_req_put(req);
Expand Down
8 changes: 4 additions & 4 deletions src/engine/engine_discard.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void _ocf_discard_finish_step(struct ocf_request *req)
static void _ocf_discard_step_complete(struct ocf_request *req, int error)
{
if (error)
req->error |= error;
env_atomic_cmpxchg(&req->error, 0, error);

if (env_atomic_dec_return(&req->req_remaining))
return;
Expand All @@ -126,9 +126,9 @@ static void _ocf_discard_step_complete(struct ocf_request *req, int error)
/* Release WRITE lock of request */
ocf_req_unlock_wr(ocf_cache_line_concurrency(req->cache), req);

if (req->error) {
if (req->error.counter) {
ocf_metadata_error(req->cache);
_ocf_discard_complete_req(req, req->error);
_ocf_discard_complete_req(req, req->error.counter);
return;
}

Expand Down Expand Up @@ -230,7 +230,7 @@ static int _ocf_discard_step(struct ocf_request *req)
}
} else {
OCF_DEBUG_RQ(req, "LOCK ERROR %d", lock);
req->error |= lock;
env_atomic_cmpxchg(&req->error, 0, lock);
_ocf_discard_finish_step(req);
}

Expand Down
6 changes: 3 additions & 3 deletions src/engine/engine_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
static void _ocf_read_fast_complete(struct ocf_request *req, int error)
{
if (error) {
req->error |= error;
env_atomic_cmpxchg(&req->error, 0, error);
ocf_core_stats_cache_error_update(req->core, OCF_READ);
}

Expand All @@ -42,15 +42,15 @@ static void _ocf_read_fast_complete(struct ocf_request *req, int error)

OCF_DEBUG_RQ(req, "HIT completion");

if (req->error) {
if (req->error.counter) {
OCF_DEBUG_RQ(req, "ERROR");

ocf_engine_push_req_front_pt(req);
} else {
ocf_req_unlock(ocf_cache_line_concurrency(req->cache), req);

/* Complete request */
req->complete(req, req->error);
req->complete(req, req->error.counter);

/* Free the request at the last point of the completion path */
ocf_req_put(req);
Expand Down
4 changes: 2 additions & 2 deletions src/engine/engine_inv.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
static void _ocf_invalidate_req(struct ocf_request *req, int error)
{
if (error) {
req->error = error;
env_atomic_cmpxchg(&req->error, 0, error);
ocf_core_stats_cache_error_update(req->core, OCF_WRITE);
}

Expand All @@ -28,7 +28,7 @@ static void _ocf_invalidate_req(struct ocf_request *req, int error)

OCF_DEBUG_RQ(req, "Completion");

if (req->error)
if (req->error.counter)
ocf_engine_error(req, true, "Failed to flush metadata to cache");

ocf_req_unlock_wr(ocf_cache_line_concurrency(req->cache), req);
Expand Down
6 changes: 3 additions & 3 deletions src/engine/engine_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
static void _ocf_engine_ops_complete(struct ocf_request *req, int error)
{
if (error)
req->error |= error;
env_atomic_cmpxchg(&req->error, 0, error);

if (env_atomic_dec_return(&req->req_remaining))
return;

OCF_DEBUG_RQ(req, "Completion");

if (req->error) {
if (req->error.counter) {
/* An error occured */
ocf_engine_error(req, false, "Core operation failure");
}

/* Complete requests - both to cache and to core*/
req->complete(req, req->error);
req->complete(req, req->error.counter);

/* Release OCF request */
ocf_req_put(req);
Expand Down
6 changes: 3 additions & 3 deletions src/engine/engine_pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
static void _ocf_read_pt_complete(struct ocf_request *req, int error)
{
if (error)
req->error |= error;
env_atomic_cmpxchg(&req->error, 0, error);

if (env_atomic_dec_return(&req->req_remaining))
return;

OCF_DEBUG_RQ(req, "Completion");

if (req->error) {
if (req->error.counter) {
req->info.core_error = 1;
ocf_core_stats_core_error_update(req->core, OCF_READ);
}

/* Complete request */
req->complete(req, req->error);
req->complete(req, req->error.counter);

ocf_req_unlock_rd(ocf_cache_line_concurrency(req->cache), req);

Expand Down
14 changes: 7 additions & 7 deletions src/engine/engine_rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void _ocf_read_generic_hit_complete(struct ocf_request *req, int error)
req->cache);

if (error) {
req->error |= error;
env_atomic_cmpxchg(&req->error, 0, error);
ocf_core_stats_cache_error_update(req->core, OCF_READ);
inc_fallback_pt_error_counter(req->cache);
}
Expand All @@ -40,13 +40,13 @@ static void _ocf_read_generic_hit_complete(struct ocf_request *req, int error)
if (env_atomic_dec_return(&req->req_remaining) == 0) {
OCF_DEBUG_RQ(req, "HIT completion");

if (req->error) {
if (req->error.counter) {
ocf_engine_push_req_front_pt(req);
} else {
ocf_req_unlock(c, req);

/* Complete request */
req->complete(req, req->error);
req->complete(req, req->error.counter);

/* Free the request at the last point
* of the completion path
Expand All @@ -61,7 +61,7 @@ static void _ocf_read_generic_miss_complete(struct ocf_request *req, int error)
struct ocf_cache *cache = req->cache;

if (error)
req->error = error;
env_atomic_cmpxchg(&req->error, 0, error);

/* Handle callback-caller race to let only one of the two complete the
* request. Also, complete original request only if this is the last
Expand All @@ -70,12 +70,12 @@ static void _ocf_read_generic_miss_complete(struct ocf_request *req, int error)
if (env_atomic_dec_return(&req->req_remaining) == 0) {
OCF_DEBUG_RQ(req, "MISS completion");

if (req->error) {
if (req->error.counter) {
/*
* --- Do not submit this request to write-back-thread.
* Stop it here ---
*/
req->complete(req, req->error);
req->complete(req, req->error.counter);

req->info.core_error = 1;
ocf_core_stats_core_error_update(req->core, OCF_READ);
Expand All @@ -96,7 +96,7 @@ static void _ocf_read_generic_miss_complete(struct ocf_request *req, int error)
req->byte_length);

/* Complete request */
req->complete(req, req->error);
req->complete(req, req->error.counter);

ocf_engine_backfill(req);
}
Expand Down
12 changes: 6 additions & 6 deletions src/engine/engine_wb.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ static void _ocf_write_wb_update_bits(struct ocf_request *req)
static void _ocf_write_wb_io_flush_metadata(struct ocf_request *req, int error)
{
if (error)
req->error = error;
env_atomic_cmpxchg(&req->error, 0, error);

if (env_atomic_dec_return(&req->req_remaining))
return;

if (req->error)
if (req->error.counter)
ocf_engine_error(req, true, "Failed to write data to cache");

ocf_req_unlock_wr(ocf_cache_line_concurrency(req->cache), req);

req->complete(req, req->error);
req->complete(req, req->error.counter);

ocf_req_put(req);
}
Expand Down Expand Up @@ -87,18 +87,18 @@ static void _ocf_write_wb_complete(struct ocf_request *req, int error)
{
if (error) {
ocf_core_stats_cache_error_update(req->core, OCF_WRITE);
req->error |= error;
env_atomic_cmpxchg(&req->error, 0, error);
}

if (env_atomic_dec_return(&req->req_remaining))
return;

OCF_DEBUG_RQ(req, "Completion");

if (req->error) {
if (req->error.counter) {
ocf_engine_error(req, true, "Failed to write data to cache");

req->complete(req, req->error);
req->complete(req, req->error.counter);

ocf_engine_invalidate(req);
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/engine/engine_wi.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int _ocf_write_wi_next_pass(struct ocf_request *req)
ocf_req_unlock_wr(ocf_cache_line_concurrency(req->cache), req);

if (req->wi_second_pass) {
req->complete(req, req->error);
req->complete(req, req->error.counter);
ocf_req_put(req);

return 0;
Expand All @@ -47,25 +47,25 @@ static void _ocf_write_wi_io_flush_metadata(struct ocf_request *req, int error)
{
if (error) {
ocf_core_stats_cache_error_update(req->core, OCF_WRITE);
req->error |= error;
env_atomic_cmpxchg(&req->error, 0, error);
}

if (env_atomic_dec_return(&req->req_remaining))
return;

if (!req->error && !req->wi_second_pass && ocf_engine_is_miss(req)) {
if (!req->error.counter && !req->wi_second_pass && ocf_engine_is_miss(req)) {
/* need another pass */
ocf_engine_push_req_front_cb(req, _ocf_write_wi_next_pass,
true);
return;
}

if (req->error)
if (req->error.counter)
ocf_engine_error(req, true, "Failed to write data to cache");

ocf_req_unlock_wr(ocf_cache_line_concurrency(req->cache), req);

req->complete(req, req->error);
req->complete(req, req->error.counter);

ocf_req_put(req);
}
Expand Down Expand Up @@ -105,7 +105,7 @@ static int ocf_write_wi_update_and_flush_metadata(struct ocf_request *req)
static void _ocf_write_wi_core_complete(struct ocf_request *req, int error)
{
if (error) {
req->error = error;
env_atomic_cmpxchg(&req->error, 0, error);
req->info.core_error = 1;
ocf_core_stats_core_error_update(req->core, OCF_WRITE);
}
Expand All @@ -115,10 +115,10 @@ static void _ocf_write_wi_core_complete(struct ocf_request *req, int error)

OCF_DEBUG_RQ(req, "Completion");

if (req->error) {
if (req->error.counter) {
ocf_req_unlock_wr(ocf_cache_line_concurrency(req->cache), req);

req->complete(req, req->error);
req->complete(req, req->error.counter);

ocf_req_put(req);
} else {
Expand Down
Loading

0 comments on commit 8135cc4

Please sign in to comment.