Replace submit with forward in metadata_raw_atomic
Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com> Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
parent
af3b379bb8
commit
9404716c3c
@ -32,66 +32,31 @@
|
|||||||
#define OCF_DEBUG_PARAM(cache, format, ...)
|
#define OCF_DEBUG_PARAM(cache, format, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct _raw_atomic_flush_ctx {
|
static void _raw_atomic_io_discard_cmpl(struct ocf_request *req, int error)
|
||||||
struct ocf_request *req;
|
|
||||||
ocf_req_end_t complete;
|
|
||||||
env_atomic flush_req_cnt;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void _raw_atomic_io_discard_cmpl(struct _raw_atomic_flush_ctx *ctx,
|
|
||||||
int error)
|
|
||||||
{
|
{
|
||||||
|
ocf_req_end_t complete = req->priv;
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
ctx->req->error = error;
|
ocf_metadata_error(req->cache);
|
||||||
|
|
||||||
if (env_atomic_dec_return(&ctx->flush_req_cnt))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ctx->req->error)
|
|
||||||
ocf_metadata_error(ctx->req->cache);
|
|
||||||
|
|
||||||
/* Call metadata flush completed call back */
|
/* Call metadata flush completed call back */
|
||||||
OCF_DEBUG_MSG(ctx->req->cache, "Asynchronous flushing complete");
|
OCF_DEBUG_MSG(ctx->req->cache, "Asynchronous flushing complete");
|
||||||
|
|
||||||
ctx->complete(ctx->req, ctx->req->error);
|
complete(req, error);
|
||||||
|
|
||||||
env_free(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _raw_atomic_io_discard_end(struct ocf_io *io, int error)
|
static void _raw_atomic_io_discard_do(struct ocf_request *req,
|
||||||
|
uint64_t start_addr, uint32_t len)
|
||||||
{
|
{
|
||||||
struct _raw_atomic_flush_ctx *ctx = io->priv1;
|
ocf_cache_t cache = req->cache;
|
||||||
|
|
||||||
ocf_io_put(io); /* Release IO */
|
|
||||||
|
|
||||||
_raw_atomic_io_discard_cmpl(ctx, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _raw_atomic_io_discard_do(struct ocf_cache *cache, void *context,
|
|
||||||
uint64_t start_addr, uint32_t len, struct _raw_atomic_flush_ctx *ctx)
|
|
||||||
{
|
|
||||||
struct ocf_request *req = context;
|
|
||||||
struct ocf_io *io;
|
|
||||||
|
|
||||||
io = ocf_new_cache_io(cache, NULL, start_addr, len, OCF_WRITE, 0, 0);
|
|
||||||
if (!io) {
|
|
||||||
req->error = -OCF_ERR_NO_MEM;
|
|
||||||
return req->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
OCF_DEBUG_PARAM(cache, "Page to flushing = %" ENV_PRIu64 ", count of pages = %u",
|
OCF_DEBUG_PARAM(cache, "Page to flushing = %" ENV_PRIu64 ", count of pages = %u",
|
||||||
start_addr, len);
|
start_addr, len);
|
||||||
|
|
||||||
env_atomic_inc(&ctx->flush_req_cnt);
|
|
||||||
|
|
||||||
ocf_io_set_cmpl(io, ctx, NULL, _raw_atomic_io_discard_end);
|
|
||||||
|
|
||||||
if (cache->device->volume.features.discard_zeroes)
|
if (cache->device->volume.features.discard_zeroes)
|
||||||
ocf_volume_submit_discard(io);
|
ocf_req_forward_cache_discard(req, start_addr, len);
|
||||||
else
|
else
|
||||||
ocf_volume_submit_write_zeroes(io);
|
ocf_req_forward_cache_write_zeros(req, start_addr, len);
|
||||||
|
|
||||||
return req->error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void raw_atomic_flush_mark(struct ocf_cache *cache, struct ocf_request *req,
|
void raw_atomic_flush_mark(struct ocf_cache *cache, struct ocf_request *req,
|
||||||
@ -114,14 +79,12 @@ static inline void _raw_atomic_add_page(struct ocf_cache *cache,
|
|||||||
(*idx)++;
|
(*idx)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _raw_atomic_flush_do_asynch_sec(struct ocf_cache *cache,
|
static void _raw_atomic_flush_do_asynch_sec(struct ocf_cache *cache,
|
||||||
struct ocf_request *req, int map_idx,
|
struct ocf_request *req, int map_idx)
|
||||||
struct _raw_atomic_flush_ctx *ctx)
|
|
||||||
{
|
{
|
||||||
struct ocf_map_info *map = &req->map[map_idx];
|
struct ocf_map_info *map = &req->map[map_idx];
|
||||||
uint32_t len = 0;
|
uint32_t len = 0;
|
||||||
uint64_t start_addr;
|
uint64_t start_addr;
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
start_addr = map->coll_idx;
|
start_addr = map->coll_idx;
|
||||||
start_addr *= ocf_line_size(cache);
|
start_addr *= ocf_line_size(cache);
|
||||||
@ -131,9 +94,7 @@ static int _raw_atomic_flush_do_asynch_sec(struct ocf_cache *cache,
|
|||||||
len = SECTORS_TO_BYTES(map->stop_flush - map->start_flush);
|
len = SECTORS_TO_BYTES(map->stop_flush - map->start_flush);
|
||||||
len += SECTORS_TO_BYTES(1);
|
len += SECTORS_TO_BYTES(1);
|
||||||
|
|
||||||
result = _raw_atomic_io_discard_do(cache, req, start_addr, len, ctx);
|
_raw_atomic_io_discard_do(req, start_addr, len);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int raw_atomic_flush_do_asynch(struct ocf_cache *cache, struct ocf_request *req,
|
int raw_atomic_flush_do_asynch(struct ocf_cache *cache, struct ocf_request *req,
|
||||||
@ -147,7 +108,6 @@ int raw_atomic_flush_do_asynch(struct ocf_cache *cache, struct ocf_request *req,
|
|||||||
int line_no = req->core_line_count;
|
int line_no = req->core_line_count;
|
||||||
struct ocf_map_info *map;
|
struct ocf_map_info *map;
|
||||||
uint64_t start_addr;
|
uint64_t start_addr;
|
||||||
struct _raw_atomic_flush_ctx *ctx;
|
|
||||||
|
|
||||||
ENV_BUG_ON(!complete);
|
ENV_BUG_ON(!complete);
|
||||||
|
|
||||||
@ -157,24 +117,16 @@ int raw_atomic_flush_do_asynch(struct ocf_cache *cache, struct ocf_request *req,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = env_zalloc(sizeof(*ctx), ENV_MEM_NOIO);
|
req->priv = complete;
|
||||||
if (!ctx) {
|
req->cache_forward_end = _raw_atomic_io_discard_cmpl;
|
||||||
complete(req, -OCF_ERR_NO_MEM);
|
|
||||||
return -OCF_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->req = req;
|
|
||||||
ctx->complete = complete;
|
|
||||||
env_atomic_set(&ctx->flush_req_cnt, 1);
|
|
||||||
|
|
||||||
if (line_no == 1) {
|
if (line_no == 1) {
|
||||||
map = &req->map[0];
|
map = &req->map[0];
|
||||||
if (map->flush && map->status != LOOKUP_MISS) {
|
if (map->flush && map->status != LOOKUP_MISS)
|
||||||
result = _raw_atomic_flush_do_asynch_sec(cache, req,
|
_raw_atomic_flush_do_asynch_sec(cache, req, 0);
|
||||||
0, ctx);
|
else
|
||||||
}
|
_raw_atomic_io_discard_cmpl(req, 0);
|
||||||
_raw_atomic_io_discard_cmpl(ctx, result);
|
return 0;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_no <= MAX_STACK_TAB_SIZE) {
|
if (line_no <= MAX_STACK_TAB_SIZE) {
|
||||||
@ -184,11 +136,11 @@ int raw_atomic_flush_do_asynch(struct ocf_cache *cache, struct ocf_request *req,
|
|||||||
ENV_MEM_NOIO);
|
ENV_MEM_NOIO);
|
||||||
if (!clines_tab) {
|
if (!clines_tab) {
|
||||||
complete(req, -OCF_ERR_NO_MEM);
|
complete(req, -OCF_ERR_NO_MEM);
|
||||||
env_free(ctx);
|
|
||||||
return -OCF_ERR_NO_MEM;
|
return -OCF_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ocf_req_forward_cache_get(req);
|
||||||
for (i = 0; i < line_no; i++) {
|
for (i = 0; i < line_no; i++) {
|
||||||
map = &req->map[i];
|
map = &req->map[i];
|
||||||
|
|
||||||
@ -198,8 +150,7 @@ int raw_atomic_flush_do_asynch(struct ocf_cache *cache, struct ocf_request *req,
|
|||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
/* First */
|
/* First */
|
||||||
if (map->start_flush) {
|
if (map->start_flush) {
|
||||||
_raw_atomic_flush_do_asynch_sec(cache, req, i,
|
_raw_atomic_flush_do_asynch_sec(cache, req, i);
|
||||||
ctx);
|
|
||||||
} else {
|
} else {
|
||||||
_raw_atomic_add_page(cache, clines_tab,
|
_raw_atomic_add_page(cache, clines_tab,
|
||||||
map->coll_idx, &clines_to_flush);
|
map->coll_idx, &clines_to_flush);
|
||||||
@ -207,8 +158,7 @@ int raw_atomic_flush_do_asynch(struct ocf_cache *cache, struct ocf_request *req,
|
|||||||
} else if (i == (line_no - 1)) {
|
} else if (i == (line_no - 1)) {
|
||||||
/* Last */
|
/* Last */
|
||||||
if (map->stop_flush != ocf_line_end_sector(cache)) {
|
if (map->stop_flush != ocf_line_end_sector(cache)) {
|
||||||
_raw_atomic_flush_do_asynch_sec(cache, req,
|
_raw_atomic_flush_do_asynch_sec(cache, req, i);
|
||||||
i, ctx);
|
|
||||||
} else {
|
} else {
|
||||||
_raw_atomic_add_page(cache, clines_tab,
|
_raw_atomic_add_page(cache, clines_tab,
|
||||||
map->coll_idx, &clines_to_flush);
|
map->coll_idx, &clines_to_flush);
|
||||||
@ -242,16 +192,11 @@ int raw_atomic_flush_do_asynch(struct ocf_cache *cache, struct ocf_request *req,
|
|||||||
len += ocf_line_size(cache);
|
len += ocf_line_size(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
result |= _raw_atomic_io_discard_do(cache, req, start_addr,
|
_raw_atomic_io_discard_do(req, start_addr, len);
|
||||||
len, ctx);
|
|
||||||
|
|
||||||
if (result)
|
|
||||||
break;
|
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
ocf_req_forward_cache_put(req);
|
||||||
_raw_atomic_io_discard_cmpl(ctx, result);
|
|
||||||
|
|
||||||
if (line_no > MAX_STACK_TAB_SIZE)
|
if (line_no > MAX_STACK_TAB_SIZE)
|
||||||
env_free(clines_tab);
|
env_free(clines_tab);
|
||||||
|
@ -352,8 +352,6 @@ struct raw_dynamic_load_all_context {
|
|||||||
unsigned flapping_idx;
|
unsigned flapping_idx;
|
||||||
struct ocf_request *req;
|
struct ocf_request *req;
|
||||||
ocf_cache_t cache;
|
ocf_cache_t cache;
|
||||||
struct ocf_io *io;
|
|
||||||
ctx_data_t *data;
|
|
||||||
uint8_t *zpage;
|
uint8_t *zpage;
|
||||||
uint8_t *page;
|
uint8_t *page;
|
||||||
uint64_t i_page;
|
uint64_t i_page;
|
||||||
@ -371,17 +369,15 @@ static void raw_dynamic_load_all_complete(
|
|||||||
ocf_req_put(context->req);
|
ocf_req_put(context->req);
|
||||||
env_secure_free(context->page, PAGE_SIZE);
|
env_secure_free(context->page, PAGE_SIZE);
|
||||||
env_free(context->zpage);
|
env_free(context->zpage);
|
||||||
ctx_data_free(context->cache->owner, context->data);
|
ctx_data_free(context->cache->owner, context->req->data);
|
||||||
env_vfree(context);
|
env_vfree(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_dynamic_load_all_update(struct ocf_request *req);
|
static int raw_dynamic_load_all_update(struct ocf_request *req);
|
||||||
|
|
||||||
static void raw_dynamic_load_all_read_end(struct ocf_io *io, int error)
|
static void raw_dynamic_load_all_read_end(struct ocf_request *req, int error)
|
||||||
{
|
{
|
||||||
struct raw_dynamic_load_all_context *context = io->priv1;
|
struct raw_dynamic_load_all_context *context = req->priv;
|
||||||
|
|
||||||
ocf_io_put(io);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
raw_dynamic_load_all_complete(context, error);
|
raw_dynamic_load_all_complete(context, error);
|
||||||
@ -389,7 +385,7 @@ static void raw_dynamic_load_all_read_end(struct ocf_io *io, int error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
context->req->engine_handler = raw_dynamic_load_all_update;
|
context->req->engine_handler = raw_dynamic_load_all_update;
|
||||||
ocf_queue_push_req(context->req,
|
ocf_queue_push_req(req,
|
||||||
OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
|
OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +395,6 @@ static int raw_dynamic_load_all_read(struct ocf_request *req)
|
|||||||
struct ocf_metadata_raw *raw = context->raw;
|
struct ocf_metadata_raw *raw = context->raw;
|
||||||
uint64_t ssd_pages_offset;
|
uint64_t ssd_pages_offset;
|
||||||
uint64_t count;
|
uint64_t count;
|
||||||
int result;
|
|
||||||
|
|
||||||
ssd_pages_offset = raw->ssd_pages_offset +
|
ssd_pages_offset = raw->ssd_pages_offset +
|
||||||
raw_dynamic_segment_size_on_ssd(raw) *
|
raw_dynamic_segment_size_on_ssd(raw) *
|
||||||
@ -407,28 +402,11 @@ static int raw_dynamic_load_all_read(struct ocf_request *req)
|
|||||||
|
|
||||||
count = metadata_io_size(context->i_page, raw->ssd_pages);
|
count = metadata_io_size(context->i_page, raw->ssd_pages);
|
||||||
|
|
||||||
/* Allocate IO */
|
req->cache_forward_end = raw_dynamic_load_all_read_end;
|
||||||
context->io = ocf_new_cache_io(context->cache, req->io_queue,
|
|
||||||
PAGES_TO_BYTES(ssd_pages_offset + context->i_page),
|
|
||||||
PAGES_TO_BYTES(count), OCF_READ, 0, 0);
|
|
||||||
|
|
||||||
if (!context->io) {
|
ocf_req_forward_cache_io(req, OCF_READ,
|
||||||
raw_dynamic_load_all_complete(context, -OCF_ERR_NO_MEM);
|
PAGES_TO_BYTES(ssd_pages_offset + context->i_page),
|
||||||
return 0;
|
PAGES_TO_BYTES(count), 0);
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup IO */
|
|
||||||
result = ocf_io_set_data(context->io, context->data, 0);
|
|
||||||
if (result) {
|
|
||||||
ocf_io_put(context->io);
|
|
||||||
raw_dynamic_load_all_complete(context, result);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
ocf_io_set_cmpl(context->io, context, NULL,
|
|
||||||
raw_dynamic_load_all_read_end);
|
|
||||||
|
|
||||||
/* Submit IO */
|
|
||||||
ocf_volume_submit_io(context->io);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -442,10 +420,10 @@ static int raw_dynamic_load_all_update(struct ocf_request *req)
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
/* Reset head of data buffer */
|
/* Reset head of data buffer */
|
||||||
ctx_data_seek_check(context->cache->owner, context->data,
|
ctx_data_seek_check(context->cache->owner, req->data,
|
||||||
ctx_data_seek_begin, 0);
|
ctx_data_seek_begin, 0);
|
||||||
|
|
||||||
result = raw_dynamic_update_pages(cache, raw, context->data,
|
result = raw_dynamic_update_pages(cache, raw, req->data,
|
||||||
context->i_page, count, &context->page, context->zpage);
|
context->i_page, count, &context->page, context->zpage);
|
||||||
|
|
||||||
context->i_page += count;
|
context->i_page += count;
|
||||||
@ -466,6 +444,7 @@ void raw_dynamic_load_all(ocf_cache_t cache, struct ocf_metadata_raw *raw,
|
|||||||
ocf_metadata_end_t cmpl, void *priv, unsigned flapping_idx)
|
ocf_metadata_end_t cmpl, void *priv, unsigned flapping_idx)
|
||||||
{
|
{
|
||||||
struct raw_dynamic_load_all_context *context;
|
struct raw_dynamic_load_all_context *context;
|
||||||
|
struct ocf_request *req;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
ENV_BUG_ON(raw->flapping ? flapping_idx > 1 : flapping_idx != 0);
|
ENV_BUG_ON(raw->flapping ? flapping_idx > 1 : flapping_idx != 0);
|
||||||
@ -481,37 +460,39 @@ void raw_dynamic_load_all(ocf_cache_t cache, struct ocf_metadata_raw *raw,
|
|||||||
context->cmpl = cmpl;
|
context->cmpl = cmpl;
|
||||||
context->priv = priv;
|
context->priv = priv;
|
||||||
|
|
||||||
context->data = ctx_data_alloc(cache->owner, RAW_DYNAMIC_LOAD_PAGES);
|
|
||||||
if (!context->data) {
|
|
||||||
result = -OCF_ERR_NO_MEM;
|
|
||||||
goto err_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
context->zpage = env_zalloc(PAGE_SIZE, ENV_MEM_NORMAL);
|
context->zpage = env_zalloc(PAGE_SIZE, ENV_MEM_NORMAL);
|
||||||
if (!context->zpage) {
|
if (!context->zpage) {
|
||||||
result = -OCF_ERR_NO_MEM;
|
result = -OCF_ERR_NO_MEM;
|
||||||
goto err_zpage;
|
goto err_zpage;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->req = ocf_req_new_mngt(cache, cache->mngt_queue);
|
req = ocf_req_new_mngt(cache, cache->mngt_queue);
|
||||||
if (!context->req) {
|
if (!req) {
|
||||||
result = -OCF_ERR_NO_MEM;
|
result = -OCF_ERR_NO_MEM;
|
||||||
goto err_req;
|
goto err_req;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->req->info.internal = true;
|
req->data = ctx_data_alloc(cache->owner, RAW_DYNAMIC_LOAD_PAGES);
|
||||||
context->req->priv = context;
|
if (!req->data) {
|
||||||
context->req->engine_handler = raw_dynamic_load_all_read;
|
result = -OCF_ERR_NO_MEM;
|
||||||
|
goto err_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
req->info.internal = true;
|
||||||
|
req->priv = context;
|
||||||
|
req->engine_handler = raw_dynamic_load_all_read;
|
||||||
|
|
||||||
|
context->req = req;
|
||||||
|
|
||||||
ocf_queue_push_req(context->req,
|
ocf_queue_push_req(context->req,
|
||||||
OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
|
OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
err_data:
|
||||||
|
ocf_req_put(req);
|
||||||
err_req:
|
err_req:
|
||||||
env_free(context->zpage);
|
env_free(context->zpage);
|
||||||
err_zpage:
|
err_zpage:
|
||||||
ctx_data_free(cache->owner, context->data);
|
|
||||||
err_data:
|
|
||||||
env_vfree(context);
|
env_vfree(context);
|
||||||
OCF_CMPL_RET(priv, result);
|
OCF_CMPL_RET(priv, result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user