Replace submit with forward in ocf_metadata_read_sb()
This one is quite special, because it can be called before cache is instantiated, which means we can not allocate the request using ocf_req_new_mngt() due to absence of mngt_queue. For that reason we simply allocate request using env_zalloc() and then release it with env_free(). The lifecycle of the request is very straightforward and the only used fields are forward counter and callback. Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com> Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
parent
9404716c3c
commit
39d566c280
@ -651,10 +651,10 @@ unsigned ocf_metadata_superblock_get_next_flapping_idx(
|
||||
return (sb->config->flapping_idx + 1) % 2;
|
||||
}
|
||||
|
||||
static void ocf_metadata_read_sb_complete(struct ocf_io *io, int error)
|
||||
static void ocf_metadata_read_sb_complete(struct ocf_request *req, int error)
|
||||
{
|
||||
struct ocf_metadata_read_sb_ctx *context = io->priv1;
|
||||
ctx_data_t *data = ocf_io_get_data(io);
|
||||
struct ocf_metadata_read_sb_ctx *context = req->priv;
|
||||
ctx_data_t *data = req->data;
|
||||
|
||||
if (!error) {
|
||||
/* Read data from data into super block buffer */
|
||||
@ -663,12 +663,12 @@ static void ocf_metadata_read_sb_complete(struct ocf_io *io, int error)
|
||||
}
|
||||
|
||||
ctx_data_free(context->ctx, data);
|
||||
ocf_io_put(io);
|
||||
|
||||
context->error = error;
|
||||
context->cmpl(context);
|
||||
|
||||
env_free(context);
|
||||
env_free(req);
|
||||
}
|
||||
|
||||
int ocf_metadata_read_sb(ocf_ctx_t ctx, ocf_volume_t volume,
|
||||
@ -676,8 +676,7 @@ int ocf_metadata_read_sb(ocf_ctx_t ctx, ocf_volume_t volume,
|
||||
{
|
||||
struct ocf_metadata_read_sb_ctx *context;
|
||||
size_t sb_pages = BYTES_TO_PAGES(sizeof(context->superblock));
|
||||
ctx_data_t *data;
|
||||
struct ocf_io *io;
|
||||
struct ocf_request *req;
|
||||
int result = 0;
|
||||
|
||||
/* Allocate memory for first page of super block */
|
||||
@ -692,43 +691,31 @@ int ocf_metadata_read_sb(ocf_ctx_t ctx, ocf_volume_t volume,
|
||||
context->priv1 = priv1;
|
||||
context->priv2 = priv2;
|
||||
|
||||
/* Allocate resources for IO */
|
||||
io = ocf_volume_new_io(volume, NULL, 0, sb_pages * PAGE_SIZE,
|
||||
OCF_READ, 0, 0);
|
||||
if (!io) {
|
||||
req = env_zalloc(sizeof(*req), ENV_MEM_NORMAL);
|
||||
if (!req) {
|
||||
ocf_log(ctx, log_err, "Memory allocation error");
|
||||
result = -OCF_ERR_NO_MEM;
|
||||
goto err_io;
|
||||
goto err_req;
|
||||
}
|
||||
|
||||
data = ctx_data_alloc(ctx, sb_pages);
|
||||
if (!data) {
|
||||
req->data = ctx_data_alloc(ctx, sb_pages);
|
||||
if (!req->data) {
|
||||
ocf_log(ctx, log_err, "Memory allocation error");
|
||||
result = -OCF_ERR_NO_MEM;
|
||||
goto err_data;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read first page of cache device in order to recover metadata
|
||||
* properties
|
||||
*/
|
||||
result = ocf_io_set_data(io, data, 0);
|
||||
if (result) {
|
||||
ocf_log(ctx, log_err, "Metadata IO configuration error\n");
|
||||
result = -OCF_ERR_IO;
|
||||
goto err_set_data;
|
||||
}
|
||||
req->volume_forward_end = ocf_metadata_read_sb_complete;
|
||||
req->priv = context;
|
||||
|
||||
ocf_io_set_cmpl(io, context, NULL, ocf_metadata_read_sb_complete);
|
||||
ocf_volume_submit_io(io);
|
||||
ocf_req_forward_volume_io_simple(req, volume, OCF_READ, 0,
|
||||
sb_pages * PAGE_SIZE);
|
||||
|
||||
return 0;
|
||||
|
||||
err_set_data:
|
||||
ctx_data_free(ctx, data);
|
||||
err_data:
|
||||
ocf_io_put(io);
|
||||
err_io:
|
||||
env_free(req);
|
||||
err_req:
|
||||
env_free(context);
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user