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;
|
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;
|
struct ocf_metadata_read_sb_ctx *context = req->priv;
|
||||||
ctx_data_t *data = ocf_io_get_data(io);
|
ctx_data_t *data = req->data;
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
/* Read data from data into super block buffer */
|
/* 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);
|
ctx_data_free(context->ctx, data);
|
||||||
ocf_io_put(io);
|
|
||||||
|
|
||||||
context->error = error;
|
context->error = error;
|
||||||
context->cmpl(context);
|
context->cmpl(context);
|
||||||
|
|
||||||
env_free(context);
|
env_free(context);
|
||||||
|
env_free(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ocf_metadata_read_sb(ocf_ctx_t ctx, ocf_volume_t volume,
|
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;
|
struct ocf_metadata_read_sb_ctx *context;
|
||||||
size_t sb_pages = BYTES_TO_PAGES(sizeof(context->superblock));
|
size_t sb_pages = BYTES_TO_PAGES(sizeof(context->superblock));
|
||||||
ctx_data_t *data;
|
struct ocf_request *req;
|
||||||
struct ocf_io *io;
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
/* Allocate memory for first page of super block */
|
/* 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->priv1 = priv1;
|
||||||
context->priv2 = priv2;
|
context->priv2 = priv2;
|
||||||
|
|
||||||
/* Allocate resources for IO */
|
req = env_zalloc(sizeof(*req), ENV_MEM_NORMAL);
|
||||||
io = ocf_volume_new_io(volume, NULL, 0, sb_pages * PAGE_SIZE,
|
if (!req) {
|
||||||
OCF_READ, 0, 0);
|
|
||||||
if (!io) {
|
|
||||||
ocf_log(ctx, log_err, "Memory allocation error");
|
ocf_log(ctx, log_err, "Memory allocation error");
|
||||||
result = -OCF_ERR_NO_MEM;
|
result = -OCF_ERR_NO_MEM;
|
||||||
goto err_io;
|
goto err_req;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = ctx_data_alloc(ctx, sb_pages);
|
req->data = ctx_data_alloc(ctx, sb_pages);
|
||||||
if (!data) {
|
if (!req->data) {
|
||||||
ocf_log(ctx, log_err, "Memory allocation error");
|
ocf_log(ctx, log_err, "Memory allocation error");
|
||||||
result = -OCF_ERR_NO_MEM;
|
result = -OCF_ERR_NO_MEM;
|
||||||
goto err_data;
|
goto err_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
req->volume_forward_end = ocf_metadata_read_sb_complete;
|
||||||
* Read first page of cache device in order to recover metadata
|
req->priv = context;
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
ocf_io_set_cmpl(io, context, NULL, ocf_metadata_read_sb_complete);
|
ocf_req_forward_volume_io_simple(req, volume, OCF_READ, 0,
|
||||||
ocf_volume_submit_io(io);
|
sb_pages * PAGE_SIZE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_set_data:
|
|
||||||
ctx_data_free(ctx, data);
|
|
||||||
err_data:
|
err_data:
|
||||||
ocf_io_put(io);
|
env_free(req);
|
||||||
err_io:
|
err_req:
|
||||||
env_free(context);
|
env_free(context);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user