aboutsummaryrefslogtreecommitdiff
path: root/block/export/vduse-blk.c
diff options
context:
space:
mode:
authorXie Yongji <xieyongji@bytedance.com>2022-06-14 13:15:31 +0800
committerKevin Wolf <kwolf@redhat.com>2022-06-24 17:07:06 +0200
commit0862a087fd710a6c7ad4ea01d35309686e54e202 (patch)
tree780ebf7daabb54866ec8c0ac1a2ef6365f2df50f /block/export/vduse-blk.c
parent2866ddd121f5ccaabf1752a8d25eab9be1309d3f (diff)
vduse-blk: Add serial option
Add a 'serial' option to allow user to specify this value explicitly. And the default value is changed to an empty string as what we did in "hw/block/virtio-blk.c". Signed-off-by: Xie Yongji <xieyongji@bytedance.com> Message-Id: <20220614051532.92-6-xieyongji@bytedance.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/export/vduse-blk.c')
-rw-r--r--block/export/vduse-blk.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c
index 251d73c841..066e088b00 100644
--- a/block/export/vduse-blk.c
+++ b/block/export/vduse-blk.c
@@ -235,7 +235,7 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
Error *local_err = NULL;
struct virtio_blk_config config = { 0 };
uint64_t features;
- int i;
+ int i, ret;
if (vblk_opts->has_num_queues) {
num_queues = vblk_opts->num_queues;
@@ -265,7 +265,8 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
}
vblk_exp->num_queues = num_queues;
vblk_exp->handler.blk = exp->blk;
- vblk_exp->handler.serial = exp->id;
+ vblk_exp->handler.serial = g_strdup(vblk_opts->has_serial ?
+ vblk_opts->serial : "");
vblk_exp->handler.logical_block_size = logical_block_size;
vblk_exp->handler.writable = opts->writable;
@@ -306,16 +307,16 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
vblk_exp);
if (!vblk_exp->dev) {
error_setg(errp, "failed to create vduse device");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_dev;
}
vblk_exp->recon_file = g_strdup_printf("%s/vduse-blk-%s",
g_get_tmp_dir(), exp->id);
if (vduse_set_reconnect_log_file(vblk_exp->dev, vblk_exp->recon_file)) {
error_setg(errp, "failed to set reconnect log file");
- vduse_dev_destroy(vblk_exp->dev);
- g_free(vblk_exp->recon_file);
- return -EINVAL;
+ ret = -EINVAL;
+ goto err;
}
for (i = 0; i < num_queues; i++) {
@@ -331,6 +332,12 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
blk_set_dev_ops(exp->blk, &vduse_block_ops, exp);
return 0;
+err:
+ vduse_dev_destroy(vblk_exp->dev);
+ g_free(vblk_exp->recon_file);
+err_dev:
+ g_free(vblk_exp->handler.serial);
+ return ret;
}
static void vduse_blk_exp_delete(BlockExport *exp)
@@ -346,6 +353,7 @@ static void vduse_blk_exp_delete(BlockExport *exp)
unlink(vblk_exp->recon_file);
}
g_free(vblk_exp->recon_file);
+ g_free(vblk_exp->handler.serial);
}
static void vduse_blk_exp_request_shutdown(BlockExport *exp)