rbd.c: replace QEMUOptionParameter with QemuOpts
PATCH v27 25/33 rbd.c: replace QEMUOptionParameter with QemuOpts
--- block/rbd.c | 63 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 33 deletions(-)
block/rbd.c +30 -33
@@ -282,8 +282,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf)return ret; } -static int qemu_rbd_create (const char *filename,QEMUOptionParameter *options, -Error **errp) +static int qemu_rbd_create (const char *filename,QemuOpts *opts,Error **errp) {int64_t bytes =0 ;int64_t objsize;
@@ -306,24 +305,18 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options, }/* Read out options */ -while (options && options->name) { -if (!strcmp (options->name,BLOCK_OPT_SIZE )) { - bytes = options->value.n; - }else if (!strcmp (options->name,BLOCK_OPT_CLUSTER_SIZE )) { -if (options->value.n) { - objsize = options->value.n; -if ((objsize -1 ) & objsize) {/* not a power of 2? */ -error_report ("obj size needs to be power of 2" ); -return -EINVAL ; - } -if (objsize <4096 ) { -error_report ("obj size too small" ); -return -EINVAL ; - } - obj_order =ffs (objsize) -1 ; - } + bytes =qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ); + objsize =qemu_opt_get_size_del (opts,BLOCK_OPT_CLUSTER_SIZE ,0 ); +if (objsize) { +if ((objsize -1 ) & objsize) {/* not a power of 2? */ +error_report ("obj size needs to be power of 2" ); +return -EINVAL ; + } +if (objsize <4096 ) { +error_report ("obj size too small" ); +return -EINVAL ; } - options++; + obj_order =ffs (objsize) -1 ; } clientname =qemu_rbd_parse_clientname (conf, clientname_buf);
@@ -900,18 +893,22 @@ static BlockDriverAIOCB* qemu_rbd_aio_discard(BlockDriverState *bs, }#endif -static QEMUOptionParameter qemu_rbd_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - { - .name =BLOCK_OPT_CLUSTER_SIZE , - .type =OPT_SIZE , - .help ="RBD object size" - }, - {NULL } +static QemuOptsList qemu_rbd_create_opts = { + .name ="rbd-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_rbd_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + { + .name =BLOCK_OPT_CLUSTER_SIZE , + .type =QEMU_OPT_SIZE , + .help ="RBD object size" + }, + {/* end of list */ } + } };static BlockDriver bdrv_rbd = {
@@ -920,10 +917,10 @@ static BlockDriver bdrv_rbd = { .bdrv_needs_filename = true, .bdrv_file_open = qemu_rbd_open, .bdrv_close = qemu_rbd_close, - .bdrv_create = qemu_rbd_create, + .bdrv_create2 = qemu_rbd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_get_info = qemu_rbd_getinfo, - .create_options = qemu_rbd_create_options, + .create_opts = &qemu_rbd_create_opts, .bdrv_getlength = qemu_rbd_getlength, .bdrv_truncate = qemu_rbd_truncate, .protocol_name = "rbd",
Signature · 1 line
1.7.12.4
PATCH v27 26/33 sheepdog.c: replace QEMUOptionParameter with QemuOpts
--- block/sheepdog.c | 108 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 53 deletions(-)
block/sheepdog.c +55 -53
@@ -1626,12 +1626,13 @@ static int parse_redundancy(BDRVSheepdogState *s, const char *opt)return 0 ; } -static int sd_create (const char *filename,QEMUOptionParameter *options, +static int sd_create (const char *filename,QemuOpts *opts,Error **errp) {int ret =0 ;uint32_t vid =0 ;char *backing_file =NULL ; +char *buf =NULL ;BDRVSheepdogState *s;char tag[SD_MAX_VDI_TAG_LEN ];uint32_t snapid;
@@ -1650,31 +1651,26 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, goto out; } -while (options && options->name) { -if (!strcmp (options->name,BLOCK_OPT_SIZE )) { - s->inode.vdi_size = options->value.n; - }else if (!strcmp (options->name,BLOCK_OPT_BACKING_FILE )) { - backing_file = options->value.s; - }else if (!strcmp (options->name,BLOCK_OPT_PREALLOC )) { -if (!options->value.s || !strcmp (options->value.s,"off" )) { - prealloc = false; - }else if (!strcmp (options->value.s,"full" )) { - prealloc = true; - }else { -error_report ("Invalid preallocation mode: '%s'" , - options->value.s); - ret = -EINVAL ; - goto out; - } - }else if (!strcmp (options->name,BLOCK_OPT_REDUNDANCY )) { -if (options->value.s) { - ret =parse_redundancy (s, options->value.s); -if (ret <0 ) { - goto out; - } - } + s->inode.vdi_size =qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ); + backing_file =qemu_opt_get_del (opts,BLOCK_OPT_BACKING_FILE ); + buf =qemu_opt_get_del (opts,BLOCK_OPT_PREALLOC ); +if (!buf || !strcmp (buf,"off" )) { + prealloc = false; + }else if (!strcmp (buf,"full" )) { + prealloc = true; + }else { +error_report ("Invalid preallocation mode: '%s'" , buf); + ret = -EINVAL ; + goto out; + } + +g_free (buf); + buf =qemu_opt_get_del (opts,BLOCK_OPT_REDUNDANCY ); +if (buf) { + ret =parse_redundancy (s, buf); +if (ret <0 ) { + goto out; } - options++; }if (s->inode.vdi_size >SD_MAX_VDI_SIZE ) {
@@ -1724,6 +1720,8 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, ret =sd_prealloc (filename); out: +g_free (backing_file); +g_free (buf);g_free (s);return ret; }
@@ -2490,28 +2488,32 @@ static int64_t sd_get_allocated_file_size(BlockDriverState *bs)return size; } -static QEMUOptionParameter sd_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - { - .name =BLOCK_OPT_BACKING_FILE , - .type =OPT_STRING , - .help ="File name of a base image" - }, - { - .name =BLOCK_OPT_PREALLOC , - .type =OPT_STRING , - .help ="Preallocation mode (allowed values: off, full)" - }, - { - .name =BLOCK_OPT_REDUNDANCY , - .type =OPT_STRING , - .help ="Redundancy of the image" - }, - {NULL } +static QemuOptsList sd_create_opts = { + .name ="sheepdog-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (sd_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + { + .name =BLOCK_OPT_BACKING_FILE , + .type =QEMU_OPT_STRING , + .help ="File name of a base image" + }, + { + .name =BLOCK_OPT_PREALLOC , + .type =QEMU_OPT_STRING , + .help ="Preallocation mode (allowed values: off, full)" + }, + { + .name =BLOCK_OPT_REDUNDANCY , + .type =QEMU_OPT_STRING , + .help ="Redundancy of the image" + }, + {/* end of list */ } + } };static BlockDriver bdrv_sheepdog = {
@@ -2521,7 +2523,7 @@ static BlockDriver bdrv_sheepdog = { .bdrv_needs_filename = true, .bdrv_file_open = sd_open, .bdrv_close = sd_close, - .bdrv_create = sd_create, + .bdrv_create2 = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2541,7 +2543,7 @@ static BlockDriver bdrv_sheepdog = { .bdrv_save_vmstate = sd_save_vmstate, .bdrv_load_vmstate = sd_load_vmstate, - .create_options = sd_create_options, + .create_opts = &sd_create_opts, };static BlockDriver bdrv_sheepdog_tcp = {
@@ -2551,7 +2553,7 @@ static BlockDriver bdrv_sheepdog_tcp = { .bdrv_needs_filename = true, .bdrv_file_open = sd_open, .bdrv_close = sd_close, - .bdrv_create = sd_create, + .bdrv_create2 = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2571,7 +2573,7 @@ static BlockDriver bdrv_sheepdog_tcp = { .bdrv_save_vmstate = sd_save_vmstate, .bdrv_load_vmstate = sd_load_vmstate, - .create_options = sd_create_options, + .create_opts = &sd_create_opts, };static BlockDriver bdrv_sheepdog_unix = {
@@ -2581,7 +2583,7 @@ static BlockDriver bdrv_sheepdog_unix = { .bdrv_needs_filename = true, .bdrv_file_open = sd_open, .bdrv_close = sd_close, - .bdrv_create = sd_create, + .bdrv_create2 = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2601,7 +2603,7 @@ static BlockDriver bdrv_sheepdog_unix = { .bdrv_save_vmstate = sd_save_vmstate, .bdrv_load_vmstate = sd_load_vmstate, - .create_options = sd_create_options, + .create_opts = &sd_create_opts, };static void bdrv_sheepdog_init (void )
Signature · 1 line
1.7.12.4
PATCH v27 27/33 ssh.c: replace QEMUOptionParameter with QemuOpts
In reply to Chunyan Liu--- block/ssh.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
block/ssh.c +15 -17
@@ -642,17 +642,20 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,return ret; } -static QEMUOptionParameter ssh_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - {NULL } +static QemuOptsList ssh_create_opts = { + .name ="ssh-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (ssh_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + {/* end of list */ } + } }; -static int ssh_create (const char *filename,QEMUOptionParameter *options, -Error **errp) +static int ssh_create (const char *filename,QemuOpts *opts,Error **errp) {int r, ret;Error *local_err =NULL ;
@@ -665,12 +668,7 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,ssh_state_init (&s);/* Get desired file size. */ -while (options && options->name) { -if (!strcmp (options->name,BLOCK_OPT_SIZE )) { - total_size = options->value.n; - } - options++; - } + total_size =qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 );DPRINTF ("total_size=%" PRIi64, total_size); uri_options =qdict_new ();
@@ -1044,14 +1042,14 @@ static BlockDriver bdrv_ssh = { .instance_size = sizeof(BDRVSSHState), .bdrv_parse_filename = ssh_parse_filename, .bdrv_file_open = ssh_file_open, - .bdrv_create = ssh_create, + .bdrv_create2 = ssh_create, .bdrv_close = ssh_close, .bdrv_has_zero_init = ssh_has_zero_init, .bdrv_co_readv = ssh_co_readv, .bdrv_co_writev = ssh_co_writev, .bdrv_getlength = ssh_getlength, .bdrv_co_flush_to_disk = ssh_co_flush, - .create_options = ssh_create_options, + .create_opts = &ssh_create_opts, };static void bdrv_ssh_init (void )
Signature · 1 line
1.7.12.4
PATCH v27 28/33 vdi.c: replace QEMUOptionParameter with QemuOpts
In reply to Chunyan Liu--- block/vdi.c | 73 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 35 insertions(+), 38 deletions(-)
block/vdi.c +35 -38
@@ -673,8 +673,7 @@ static int vdi_co_write(BlockDriverState *bs,return ret; } -static int vdi_create (const char *filename,QEMUOptionParameter *options, -Error **errp) +static int vdi_create (const char *filename,QemuOpts *opts,Error **errp) {int fd;int result =0 ;
@@ -689,25 +688,18 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,logout ("\n" );/* Read out options. */ -while (options && options->name) { -if (!strcmp (options->name,BLOCK_OPT_SIZE )) { - bytes = options->value.n; + bytes =qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 );#if defined(CONFIG_VDI_BLOCK_SIZE ) - } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) { -if (options->value.n) { -/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */ - block_size = options->value.n; - } +/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */ + block_size =qemu_opt_get_size_del (opts, +BLOCK_OPT_CLUSTER_SIZE , +DEFAULT_CLUSTER_SIZE );#endif #if defined(CONFIG_VDI_STATIC_IMAGE ) - } else if (!strcmp(options->name, BLOCK_OPT_STATIC)) { -if (options->value.n) { - image_type =VDI_TYPE_STATIC ; - } -#endif - } - options++; +if (qemu_opt_get_bool_del (opts,BLOCK_OPT_STATIC , false)) { + image_type =VDI_TYPE_STATIC ; } +#endif if (bytes >VDI_DISK_SIZE_MAX ) { result = -ENOTSUP ;
@@ -802,29 +794,34 @@ static void vdi_close(BlockDriverState *bs)error_free (s->migration_blocker); } -static QEMUOptionParameter vdi_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, +static QemuOptsList vdi_create_opts = { + .name ="vdi-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (vdi_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, #if defined(CONFIG_VDI_BLOCK_SIZE) - { - .name =BLOCK_OPT_CLUSTER_SIZE , - .type =OPT_SIZE , - .help ="VDI cluster (block) size" , - .value = { .n =DEFAULT_CLUSTER_SIZE }, - }, + { + .name =BLOCK_OPT_CLUSTER_SIZE , + .type =QEMU_OPT_SIZE , + .help ="VDI cluster (block) size" , + .def_value_str =stringify (DEFAULT_CLUSTER_SIZE ) + }, #endif #if defined(CONFIG_VDI_STATIC_IMAGE) - { - .name =BLOCK_OPT_STATIC , - .type =OPT_FLAG , - .help ="VDI static (pre-allocated) image" - }, + { + .name =BLOCK_OPT_STATIC , + .type =QEMU_OPT_BOOL , + .help ="VDI static (pre-allocated) image" , + .def_value_str ="off" + }, #endif -/* TODO: An additional option to set UUID values might be useful. */ - {NULL } +/* TODO: An additional option to set UUID values might be useful. */ + {/* end of list */ } + } };static BlockDriver bdrv_vdi = {
@@ -834,7 +831,7 @@ static BlockDriver bdrv_vdi = { .bdrv_open = vdi_open, .bdrv_close = vdi_close, .bdrv_reopen_prepare = vdi_reopen_prepare, - .bdrv_create = vdi_create, + .bdrv_create2 = vdi_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_get_block_status = vdi_co_get_block_status, .bdrv_make_empty = vdi_make_empty,
@@ -846,7 +843,7 @@ static BlockDriver bdrv_vdi = { .bdrv_get_info = vdi_get_info, - .create_options = vdi_create_options, + .create_opts = &vdi_create_opts, .bdrv_check = vdi_check, };
Signature · 1 line
1.7.12.4
PATCH v27 29/33 vhdx.c: replace QEMUOptionParameter with QemuOpts
In reply to Chunyan Liu--- block/vhdx.c | 99 +++++++++++++++++++++++++++++------------------------------- block/vhdx.h | 1 + 2 files changed, 48 insertions(+), 52 deletions(-)
block/vhdx.c +47 -52
@@ -1716,8 +1716,7 @@ exit:* .---- ~ ----------- ~ ------------ ~ ---------------- ~ -----------. * 1MB */ -static int vhdx_create (const char *filename,QEMUOptionParameter *options, -Error **errp) +static int vhdx_create (const char *filename,QemuOpts *opts,Error **errp) {int ret =0 ;uint64_t image_size = (uint64_t )2 * GiB;
@@ -1730,24 +1729,15 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,gunichar2 *creator =NULL ;glong creator_items;BlockDriverState *bs; -const char *type =NULL ; +char *type =NULL ;VHDXImageType image_type;Error *local_err =NULL ; -while (options && options->name) { -if (!strcmp (options->name,BLOCK_OPT_SIZE )) { - image_size = options->value.n; - }else if (!strcmp (options->name,VHDX_BLOCK_OPT_LOG_SIZE )) { - log_size = options->value.n; - }else if (!strcmp (options->name,VHDX_BLOCK_OPT_BLOCK_SIZE )) { - block_size = options->value.n; - }else if (!strcmp (options->name,BLOCK_OPT_SUBFMT )) { - type = options->value.s; - }else if (!strcmp (options->name,VHDX_BLOCK_OPT_ZERO )) { - use_zero_blocks = options->value.n !=0 ; - } - options++; - } + image_size =qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ); + log_size =qemu_opt_get_size_del (opts,VHDX_BLOCK_OPT_LOG_SIZE ,0 ); + block_size =qemu_opt_get_size_del (opts,VHDX_BLOCK_OPT_BLOCK_SIZE ,0 ); + type =qemu_opt_get_del (opts,BLOCK_OPT_SUBFMT ); + use_zero_blocks =qemu_opt_get_bool_del (opts,VHDX_BLOCK_OPT_ZERO , false);if (image_size >VHDX_MAX_IMAGE_SIZE ) {error_setg_errno (errp,EINVAL ,"Image size too large; max of 64TB" );
@@ -1756,7 +1746,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, }if (type ==NULL ) { - type ="dynamic" ; + type =g_strdup ("dynamic" ); }if (!strcmp (type,"dynamic" )) {
@@ -1796,7 +1786,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, block_size = block_size >VHDX_BLOCK_SIZE_MAX ?VHDX_BLOCK_SIZE_MAX : block_size; - ret =bdrv_create_file (filename, options,NULL , &local_err); + ret =bdrv_create_file (filename,NULL , opts, &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto exit;
@@ -1856,6 +1846,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, delete_and_exit:bdrv_unref (bs); exit: +g_free (type);g_free (creator);return ret; }
@@ -1878,37 +1869,41 @@ static int vhdx_check(BlockDriverState *bs, BdrvCheckResult *result,return 0 ; } -static QEMUOptionParameter vhdx_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size; max of 64TB." - }, - { - .name =VHDX_BLOCK_OPT_LOG_SIZE , - .type =OPT_SIZE , - .value.n =1 * MiB, - .help ="Log size; min 1MB." - }, - { - .name =VHDX_BLOCK_OPT_BLOCK_SIZE , - .type =OPT_SIZE , - .value.n =0 , - .help ="Block Size; min 1MB, max 256MB. " \ -"0 means auto-calculate based on image size." - }, - { - .name =BLOCK_OPT_SUBFMT , - .type =OPT_STRING , - .help ="VHDX format type, can be either 'dynamic' or 'fixed'. " \ -"Default is 'dynamic'." - }, - { - .name =VHDX_BLOCK_OPT_ZERO , - .type =OPT_FLAG , - .help ="Force use of payload blocks of type 'ZERO'. Non-standard." - }, - {NULL } +static QemuOptsList vhdx_create_opts = { + .name ="vhdx-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (vhdx_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size; max of 64TB." + }, + { + .name =VHDX_BLOCK_OPT_LOG_SIZE , + .type =QEMU_OPT_SIZE , + .def_value_str =stringify (DEFAULT_LOG_SIZE ), + .help ="Log size; min 1MB." + }, + { + .name =VHDX_BLOCK_OPT_BLOCK_SIZE , + .type =QEMU_OPT_SIZE , + .def_value_str =stringify (0 ), + .help ="Block Size; min 1MB, max 256MB. " \ +"0 means auto-calculate based on image size." + }, + { + .name =BLOCK_OPT_SUBFMT , + .type =QEMU_OPT_STRING , + .help ="VHDX format type, can be either 'dynamic' or 'fixed'. " \ +"Default is 'dynamic'." + }, + { + .name =VHDX_BLOCK_OPT_ZERO , + .type =QEMU_OPT_BOOL , + .help ="Force use of payload blocks of type 'ZERO'. Non-standard." + }, + {NULL } + } };static BlockDriver bdrv_vhdx = {
@@ -1920,11 +1915,11 @@ static BlockDriver bdrv_vhdx = { .bdrv_reopen_prepare = vhdx_reopen_prepare, .bdrv_co_readv = vhdx_co_readv, .bdrv_co_writev = vhdx_co_writev, - .bdrv_create = vhdx_create, + .bdrv_create2 = vhdx_create, .bdrv_get_info = vhdx_get_info, .bdrv_check = vhdx_check, - .create_options = vhdx_create_options, + .create_opts = &vhdx_create_opts, };static void bdrv_vhdx_init (void )
block/vhdx.h +1 -0
@@ -23,6 +23,7 @@#define GiB (MiB * 1024)#define TiB ((uint64_t) GiB * 1024) +#define DEFAULT_LOG_SIZE 1048576/* 1MiB */ /* Structures and fields present in the VHDX file */ /* The header section has the following blocks,
Signature · 1 line
1.7.12.4
PATCH v27 30/33 vmdk.c: replace QEMUOptionParameter with QemuOpts
In reply to Chunyan Liu--- block/vmdk.c | 123 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 63 insertions(+), 60 deletions(-)
block/vmdk.c +63 -60
@@ -1682,17 +1682,16 @@ static int filename_decompose(const char *filename, char *path, char *prefix,return VMDK_OK ; } -static int vmdk_create (const char *filename,QEMUOptionParameter *options, -Error **errp) +static int vmdk_create (const char *filename,QemuOpts *opts,Error **errp) {int idx =0 ;BlockDriverState *new_bs =NULL ;Error *local_err;char *desc =NULL ;int64_t total_size =0 , filesize; -const char *adapter_type =NULL ; -const char *backing_file =NULL ; -const char *fmt =NULL ; +char *adapter_type =NULL ; +char *backing_file =NULL ; +char *fmt =NULL ;int flags =0 ;int ret =0 ;bool flat, split, compress;
@@ -1732,24 +1731,19 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, goto exit; }/* Read out options */ -while (options && options->name) { -if (!strcmp (options->name,BLOCK_OPT_SIZE )) { - total_size = options->value.n; - }else if (!strcmp (options->name,BLOCK_OPT_ADAPTER_TYPE )) { - adapter_type = options->value.s; - }else if (!strcmp (options->name,BLOCK_OPT_BACKING_FILE )) { - backing_file = options->value.s; - }else if (!strcmp (options->name,BLOCK_OPT_COMPAT6 )) { - flags |= options->value.n ?BLOCK_FLAG_COMPAT6 :0 ; - }else if (!strcmp (options->name,BLOCK_OPT_SUBFMT )) { - fmt = options->value.s; - }else if (!strcmp (options->name,BLOCK_OPT_ZEROED_GRAIN )) { - zeroed_grain |= options->value.n; - } - options++; + total_size =qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ); + adapter_type =qemu_opt_get_del (opts,BLOCK_OPT_ADAPTER_TYPE ); + backing_file =qemu_opt_get_del (opts,BLOCK_OPT_BACKING_FILE ); +if (qemu_opt_get_bool_del (opts,BLOCK_OPT_COMPAT6 , false)) { + flags |=BLOCK_FLAG_COMPAT6 ; + } + fmt =qemu_opt_get_del (opts,BLOCK_OPT_SUBFMT ); +if (qemu_opt_get_bool_del (opts,BLOCK_OPT_ZEROED_GRAIN , false)) { + zeroed_grain = true; } +if (!adapter_type) { - adapter_type ="ide" ; + adapter_type =g_strdup ("ide" ); } else if (strcmp(adapter_type, "ide") && strcmp(adapter_type, "buslogic") && strcmp(adapter_type, "lsilogic") &&
@@ -1765,7 +1759,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, }if (!fmt) {/* Default format to monolithicSparse */ - fmt ="monolithicSparse" ; + fmt =g_strdup ("monolithicSparse" ); } else if (strcmp(fmt, "monolithicFlat") && strcmp(fmt, "monolithicSparse") && strcmp(fmt, "twoGbMaxExtentSparse") &&
@@ -1866,7 +1860,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,if (!split && !flat) { desc_offset =0x200 ; }else { - ret =bdrv_create_file (filename, options,NULL , &local_err); + ret =bdrv_create_file (filename,NULL , opts, &local_err);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not create image file" ); goto exit;
@@ -1896,6 +1890,9 @@ exit:if (new_bs) {bdrv_unref (new_bs); } +g_free (adapter_type); +g_free (backing_file); +g_free (fmt);g_free (desc);g_string_free (ext_desc_lines, true);return ret;
@@ -2063,41 +2060,47 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)return spec_info; } -static QEMUOptionParameter vmdk_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - { - .name =BLOCK_OPT_ADAPTER_TYPE , - .type =OPT_STRING , - .help ="Virtual adapter type, can be one of " -"ide (default), lsilogic, buslogic or legacyESX" - }, - { - .name =BLOCK_OPT_BACKING_FILE , - .type =OPT_STRING , - .help ="File name of a base image" - }, - { - .name =BLOCK_OPT_COMPAT6 , - .type =OPT_FLAG , - .help ="VMDK version 6 image" - }, - { - .name =BLOCK_OPT_SUBFMT , - .type =OPT_STRING , - .help = -"VMDK flat extent format, can be one of " -"{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} " - }, - { - .name =BLOCK_OPT_ZEROED_GRAIN , - .type =OPT_FLAG , - .help ="Enable efficient zero writes using the zeroed-grain GTE feature" - }, - {NULL } +static QemuOptsList vmdk_create_opts = { + .name ="vmdk-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (vmdk_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + { + .name =BLOCK_OPT_ADAPTER_TYPE , + .type =QEMU_OPT_STRING , + .help ="Virtual adapter type, can be one of " +"ide (default), lsilogic, buslogic or legacyESX" + }, + { + .name =BLOCK_OPT_BACKING_FILE , + .type =QEMU_OPT_STRING , + .help ="File name of a base image" + }, + { + .name =BLOCK_OPT_COMPAT6 , + .type =QEMU_OPT_BOOL , + .help ="VMDK version 6 image" , + .def_value_str ="off" + }, + { + .name =BLOCK_OPT_SUBFMT , + .type =QEMU_OPT_STRING , + .help = +"VMDK flat extent format, can be one of " +"{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} " + }, + { + .name =BLOCK_OPT_ZEROED_GRAIN , + .type =QEMU_OPT_BOOL , + .help ="Enable efficient zero writes " +"using the zeroed-grain GTE feature" + }, + {/* end of list */ } + } };static BlockDriver bdrv_vmdk = {
@@ -2111,7 +2114,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_write = vmdk_co_write, .bdrv_co_write_zeroes = vmdk_co_write_zeroes, .bdrv_close = vmdk_close, - .bdrv_create = vmdk_create, + .bdrv_create2 = vmdk_create, .bdrv_co_flush_to_disk = vmdk_co_flush, .bdrv_co_get_block_status = vmdk_co_get_block_status, .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
@@ -2119,7 +2122,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_get_specific_info = vmdk_get_specific_info, .bdrv_refresh_limits = vmdk_refresh_limits, - .create_options = vmdk_create_options, + .create_opts = &vmdk_create_opts, };static void bdrv_vmdk_init (void )
Signature · 1 line
1.7.12.4
PATCH v27 31/33 vpc.c: replace QEMUOptionParameter with QemuOpts
In reply to Chunyan Liu--- block/vpc.c | 62 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 28 deletions(-)
block/vpc.c +34 -28
@@ -738,12 +738,11 @@ static int create_fixed_disk(int fd, uint8_t *buf, int64_t total_size)return ret; } -static int vpc_create (const char *filename,QEMUOptionParameter *options, -Error **errp) +static int vpc_create (const char *filename,QemuOpts *opts,Error **errp) {uint8_t buf[1024 ];VHDFooter *footer = (VHDFooter *) buf; -QEMUOptionParameter *disk_type_param; +char *disk_type_param;int fd, i;uint16_t cyls =0 ;uint8_t heads =0 ;
@@ -754,16 +753,16 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,int ret = -EIO ;/* Read out options */ - total_size =get_option_parameter (options,BLOCK_OPT_SIZE )->value.n; - - disk_type_param =get_option_parameter (options,BLOCK_OPT_SUBFMT ); -if (disk_type_param && disk_type_param->value.s) { -if (!strcmp (disk_type_param->value.s,"dynamic" )) { + total_size =qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ); + disk_type_param =qemu_opt_get_del (opts,BLOCK_OPT_SUBFMT ); +if (disk_type_param) { +if (!strcmp (disk_type_param,"dynamic" )) { disk_type =VHD_DYNAMIC ; - }else if (!strcmp (disk_type_param->value.s,"fixed" )) { + }else if (!strcmp (disk_type_param,"fixed" )) { disk_type =VHD_FIXED ; }else { -return -EINVAL ; + ret = -EINVAL ; + goto out; } }else { disk_type =VHD_DYNAMIC ;
@@ -772,7 +771,8 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,/* Create the file */ fd =qemu_open (filename,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,0644 );if (fd <0 ) { -return -EIO ; + ret = -EIO ; + goto out; }/*
@@ -837,8 +837,10 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, ret =create_fixed_disk (fd, buf, total_size); } - fail: +fail:qemu_close (fd); +out: +g_free (disk_type_param);return ret; }
@@ -866,20 +868,24 @@ static void vpc_close(BlockDriverState *bs)error_free (s->migration_blocker); } -static QEMUOptionParameter vpc_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - { - .name =BLOCK_OPT_SUBFMT , - .type =OPT_STRING , - .help = -"Type of virtual hard disk format. Supported formats are " -"{dynamic (default) | fixed} " - }, - {NULL } +static QemuOptsList vpc_create_opts = { + .name ="vpc-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (vpc_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + { + .name =BLOCK_OPT_SUBFMT , + .type =QEMU_OPT_STRING , + .help = +"Type of virtual hard disk format. Supported formats are " +"{dynamic (default) | fixed} " + }, + {/* end of list */ } + } };static BlockDriver bdrv_vpc = {
@@ -890,14 +896,14 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_close = vpc_close, .bdrv_reopen_prepare = vpc_reopen_prepare, - .bdrv_create = vpc_create, + .bdrv_create2 = vpc_create, .bdrv_read = vpc_co_read, .bdrv_write = vpc_co_write, .bdrv_get_info = vpc_get_info, - .create_options = vpc_create_options, + .create_opts = &vpc_create_opts, .bdrv_has_zero_init = vpc_has_zero_init, };
Signature · 1 line
1.7.12.4
PATCH v27 32/33 cleanup QEMUOptionParameter
In reply to Chunyan LiuNow that all backend drivers are using QemuOpts, remove all QEMUOptionParameter related codes.
--- block.c | 93 ++-------- block/cow.c | 4 +- block/gluster.c | 8 +- block/iscsi.c | 2 +- block/nfs.c | 2 +- block/qcow.c | 4 +- block/qcow2.c | 6 +- block/qed.c | 4 +- block/raw-posix.c | 10 +- block/raw-win32.c | 2 +- block/raw_bsd.c | 4 +- block/rbd.c | 2 +- block/sheepdog.c | 6 +- block/ssh.c | 2 +- block/vdi.c | 2 +- block/vhdx.c | 4 +- block/vmdk.c | 6 +- block/vpc.c | 2 +- block/vvfat.c | 14 +- include/block/block.h | 8 +- include/block/block_int.h | 18 +- include/qemu/option.h | 48 +----- qemu-img.c | 19 +-- util/qemu-option.c | 427 +--------------------------------------------- 24 files changed, 67 insertions(+), 630 deletions(-)
block.c +13 -80
@@ -328,13 +328,6 @@ void bdrv_register(BlockDriver *bdrv) } } -if (bdrv->bdrv_create) { -assert (!bdrv->bdrv_create2 && !bdrv->create_opts); -assert (!bdrv->bdrv_amend_options2); - }else if (bdrv->bdrv_create2) { -assert (!bdrv->bdrv_create && !bdrv->create_options); -assert (!bdrv->bdrv_amend_options); - }QLIST_INSERT_HEAD (&bdrv_drivers, bdrv, list); }
@@ -425,7 +418,6 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name, typedef struct CreateCo { BlockDriver *drv; char *filename; - QEMUOptionParameter *options; QemuOpts *opts; int ret; Error *err;
@@ -438,28 +430,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)CreateCo *cco = opaque;assert (cco->drv); -assert (!(cco->options && cco->opts)); -if (cco->drv->bdrv_create2) { -QemuOptsList *opts_list =NULL ; -if (cco->options) { - opts_list =params_to_opts (cco->options); - cco->opts =qemu_opts_create (opts_list,NULL ,0 , &error_abort); - } - ret = cco->drv->bdrv_create2 (cco->filename, cco->opts, &local_err); -if (cco->options) { -qemu_opts_del (cco->opts); -qemu_opts_free (opts_list); - } - }else { -if (cco->opts) { - cco->options =opts_to_params (cco->opts); - } - ret = cco->drv->bdrv_create (cco->filename, cco->options, &local_err); -if (cco->opts) { -free_option_parameters (cco->options); - } - } + ret = cco->drv->bdrv_create (cco->filename, cco->opts, &local_err);if (local_err) {error_propagate (&cco->err, local_err); }
@@ -467,7 +439,6 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque) }int bdrv_create (BlockDriver *drv,const char * filename, -QEMUOptionParameter *options,QemuOpts *opts,Error **errp) {int ret;
@@ -476,13 +447,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,CreateCo cco = { .drv = drv, .filename =g_strdup (filename), - .options = options, .opts = opts, .ret =NOT_DONE , .err =NULL , }; -if (!drv->bdrv_create && !drv->bdrv_create2) { +if (!drv->bdrv_create) {error_setg (errp,"Driver '%s' does not support image creation" , drv->format_name); ret = -ENOTSUP ; goto out;
@@ -513,8 +483,7 @@ out:return ret; } -int bdrv_create_file (const char * filename,QEMUOptionParameter *options, -QemuOpts *opts,Error **errp) +int bdrv_create_file (const char *filename,QemuOpts *opts,Error **errp) {BlockDriver *drv;Error *local_err =NULL ;
@@ -526,7 +495,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options,return -ENOENT ; } - ret =bdrv_create (drv, filename, options, opts, &local_err); + ret =bdrv_create (drv, filename, opts, &local_err);if (local_err) {error_propagate (errp, local_err); }
@@ -1242,7 +1211,6 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp)char *tmp_filename =g_malloc0 (PATH_MAX +1 );int64_t total_size;BlockDriver *bdrv_qcow2; -QemuOptsList *create_opts =NULL ;QemuOpts *opts =NULL ;QDict *snapshot_options;BlockDriverState *bs_snapshot;
@@ -1268,20 +1236,11 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp) } bdrv_qcow2 =bdrv_find_format ("qcow2" ); - -assert (!(bdrv_qcow2->create_options && bdrv_qcow2->create_opts)); -if (bdrv_qcow2->create_options) { - create_opts =params_to_opts (bdrv_qcow2->create_options); - }else { - create_opts = bdrv_qcow2->create_opts; - } - opts =qemu_opts_create (create_opts,NULL ,0 , &error_abort); + opts =qemu_opts_create (bdrv_qcow2->create_opts,NULL ,0 , + &error_abort);qemu_opt_set_number (opts,BLOCK_OPT_SIZE , total_size); - ret =bdrv_create (bdrv_qcow2, tmp_filename,NULL , opts, &local_err); + ret =bdrv_create (bdrv_qcow2, tmp_filename, opts, &local_err);qemu_opts_del (opts); -if (bdrv_qcow2->create_options) { -qemu_opts_free (create_opts); - }if (ret <0 ) { error_setg_errno(errp, -ret, "Could not create temporary overlay " "'%s': %s", tmp_filename,
@@ -5406,10 +5365,8 @@ void bdrv_img_create(const char *filename, const char *fmt,return ; } - create_opts =qemu_opts_append (create_opts, drv->create_opts, - drv->create_options); - create_opts =qemu_opts_append (create_opts, proto_drv->create_opts, - proto_drv->create_options); + create_opts =qemu_opts_append (create_opts, drv->create_opts); + create_opts =qemu_opts_append (create_opts, proto_drv->create_opts);/* Create parameter list with default values */ opts =qemu_opts_create (create_opts,NULL ,0 , &error_abort);
@@ -5502,7 +5459,7 @@ void bdrv_img_create(const char *filename, const char *fmt,puts ("" ); } - ret =bdrv_create (drv, filename,NULL , opts, &local_err); + ret =bdrv_create (drv, filename, opts, &local_err);if (ret == -EFBIG ) {/* This is generally a better message than whatever the driver would
@@ -5538,36 +5495,12 @@ void bdrv_add_before_write_notifier(BlockDriverState *bs,notifier_with_return_list_add (&bs->before_write_notifiers, notifier); } -int bdrv_amend_options (BlockDriverState *bs,QEMUOptionParameter *options, -QemuOpts *opts) +int bdrv_amend_options (BlockDriverState *bs,QemuOpts *opts) { -int ret; -assert (!(options && opts)); - -if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) { +if (!bs->drv->bdrv_amend_options) {return -ENOTSUP ; } -if (bs->drv->bdrv_amend_options2) { -QemuOptsList *opts_list =NULL ; -if (options) { - opts_list =params_to_opts (options); - opts =qemu_opts_create (opts_list,NULL ,0 , &error_abort); - } - ret = bs->drv->bdrv_amend_options2 (bs, opts); -if (options) { -qemu_opts_del (opts); -qemu_opts_free (opts_list); - } - }else { -if (opts) { - options =opts_to_params (opts); - } - ret = bs->drv->bdrv_amend_options (bs, options); -if (opts) { -free_option_parameters (options); - } - } -return ret; +return bs->drv->bdrv_amend_options (bs, opts); }/* This function will be called by the bdrv_recurse_is_first_non_filter method
block/cow.c +2 -2
@@ -338,7 +338,7 @@ static int cow_create(const char *filename, QemuOpts *opts, Error **errp) image_sectors =qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ) /512 ; image_filename =qemu_opt_get_del (opts,BLOCK_OPT_BACKING_FILE ); - ret =bdrv_create_file (filename,NULL , opts, &local_err); + ret =bdrv_create_file (filename, opts, &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto exit;
@@ -412,7 +412,7 @@ static BlockDriver bdrv_cow = { .bdrv_probe = cow_probe, .bdrv_open = cow_open, .bdrv_close = cow_close, - .bdrv_create2 = cow_create, + .bdrv_create = cow_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_read = cow_co_read,
block/gluster.c +4 -4
@@ -715,7 +715,7 @@ static BlockDriver bdrv_gluster = { .bdrv_reopen_commit = qemu_gluster_reopen_commit, .bdrv_reopen_abort = qemu_gluster_reopen_abort, .bdrv_close = qemu_gluster_close, - .bdrv_create2 = qemu_gluster_create, + .bdrv_create = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, .bdrv_truncate = qemu_gluster_truncate,
@@ -742,7 +742,7 @@ static BlockDriver bdrv_gluster_tcp = { .bdrv_reopen_commit = qemu_gluster_reopen_commit, .bdrv_reopen_abort = qemu_gluster_reopen_abort, .bdrv_close = qemu_gluster_close, - .bdrv_create2 = qemu_gluster_create, + .bdrv_create = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, .bdrv_truncate = qemu_gluster_truncate,
@@ -769,7 +769,7 @@ static BlockDriver bdrv_gluster_unix = { .bdrv_reopen_commit = qemu_gluster_reopen_commit, .bdrv_reopen_abort = qemu_gluster_reopen_abort, .bdrv_close = qemu_gluster_close, - .bdrv_create2 = qemu_gluster_create, + .bdrv_create = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, .bdrv_truncate = qemu_gluster_truncate,
@@ -796,7 +796,7 @@ static BlockDriver bdrv_gluster_rdma = { .bdrv_reopen_commit = qemu_gluster_reopen_commit, .bdrv_reopen_abort = qemu_gluster_reopen_abort, .bdrv_close = qemu_gluster_close, - .bdrv_create2 = qemu_gluster_create, + .bdrv_create = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, .bdrv_truncate = qemu_gluster_truncate,
block/iscsi.c +1 -1
@@ -1475,7 +1475,7 @@ static BlockDriver bdrv_iscsi = { .bdrv_needs_filename = true, .bdrv_file_open = iscsi_open, .bdrv_close = iscsi_close, - .bdrv_create2 = iscsi_create, + .bdrv_create = iscsi_create, .create_opts = &iscsi_create_opts, .bdrv_reopen_prepare = iscsi_reopen_prepare,
block/nfs.c +1 -1
@@ -421,7 +421,7 @@ static BlockDriver bdrv_nfs = { .bdrv_file_open = nfs_file_open, .bdrv_close = nfs_file_close, - .bdrv_create2 = nfs_file_create, + .bdrv_create = nfs_file_create, .bdrv_co_readv = nfs_co_readv, .bdrv_co_writev = nfs_co_writev,
block/qcow.c +2 -2
@@ -682,7 +682,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) flags |=BLOCK_FLAG_ENCRYPT ; } - ret =bdrv_create_file (filename,NULL , opts, &local_err); + ret =bdrv_create_file (filename, opts, &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto cleanup;
@@ -909,7 +909,7 @@ static BlockDriver bdrv_qcow = { .bdrv_open = qcow_open, .bdrv_close = qcow_close, .bdrv_reopen_prepare = qcow_reopen_prepare, - .bdrv_create2 = qcow_create, + .bdrv_create = qcow_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_readv = qcow_co_readv,
block/qcow2.c +3 -3
@@ -1628,7 +1628,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,Error *local_err =NULL ;int ret; - ret =bdrv_create_file (filename,NULL , opts, &local_err); + ret =bdrv_create_file (filename, opts, &local_err);if (ret <0 ) {error_propagate (errp, local_err);return ret;
@@ -2394,7 +2394,7 @@ static BlockDriver bdrv_qcow2 = { .bdrv_open = qcow2_open, .bdrv_close = qcow2_close, .bdrv_reopen_prepare = qcow2_reopen_prepare, - .bdrv_create2 = qcow2_create, + .bdrv_create = qcow2_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_get_block_status = qcow2_co_get_block_status, .bdrv_set_key = qcow2_set_key,
@@ -2426,7 +2426,7 @@ static BlockDriver bdrv_qcow2 = { .create_opts = &qcow2_create_opts, .bdrv_check = qcow2_check, - .bdrv_amend_options2 = qcow2_amend_options, + .bdrv_amend_options = qcow2_amend_options, };static void bdrv_qcow2_init (void )
block/qed.c +2 -2
@@ -566,7 +566,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,int ret =0 ;BlockDriverState *bs; - ret =bdrv_create_file (filename,NULL ,NULL , &local_err); + ret =bdrv_create_file (filename,NULL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);return ret;
@@ -1637,7 +1637,7 @@ static BlockDriver bdrv_qed = { .bdrv_open = bdrv_qed_open, .bdrv_close = bdrv_qed_close, .bdrv_reopen_prepare = bdrv_qed_reopen_prepare, - .bdrv_create2 = bdrv_qed_create, + .bdrv_create = bdrv_qed_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_get_block_status = bdrv_qed_co_get_block_status, .bdrv_aio_readv = bdrv_qed_aio_readv,
block/raw-posix.c +5 -5
@@ -1433,7 +1433,7 @@ static BlockDriver bdrv_file = { .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, .bdrv_close = raw_close, - .bdrv_create2 = raw_create, + .bdrv_create = raw_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_get_block_status = raw_co_get_block_status, .bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1830,7 +1830,7 @@ static BlockDriver bdrv_host_device = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, - .bdrv_create2 = hdev_create, + .bdrv_create = hdev_create, .create_opts = &raw_create_opts, .bdrv_co_write_zeroes = hdev_co_write_zeroes,
@@ -1974,7 +1974,7 @@ static BlockDriver bdrv_host_floppy = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, - .bdrv_create2 = hdev_create, + .bdrv_create = hdev_create, .create_opts = &raw_create_opts, .bdrv_aio_readv = raw_aio_readv,
@@ -2099,7 +2099,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, - .bdrv_create2 = hdev_create, + .bdrv_create = hdev_create, .create_opts = &raw_create_opts, .bdrv_aio_readv = raw_aio_readv,
@@ -2230,7 +2230,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, - .bdrv_create2 = hdev_create, + .bdrv_create = hdev_create, .create_opts = &raw_create_opts, .bdrv_aio_readv = raw_aio_readv,
block/raw-win32.c +1 -1
@@ -523,7 +523,7 @@ static BlockDriver bdrv_file = { .bdrv_parse_filename = raw_parse_filename, .bdrv_file_open = raw_open, .bdrv_close = raw_close, - .bdrv_create2 = raw_create, + .bdrv_create = raw_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_aio_readv = raw_aio_readv,
block/raw_bsd.c +2 -2
@@ -148,7 +148,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)Error *local_err =NULL ;int ret; - ret =bdrv_create_file (filename,NULL , opts, &local_err); + ret =bdrv_create_file (filename, opts, &local_err);if (local_err) {error_propagate (errp, local_err); }
@@ -180,7 +180,7 @@ static BlockDriver bdrv_raw = { .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_open = &raw_open, .bdrv_close = &raw_close, - .bdrv_create2 = &raw_create, + .bdrv_create = &raw_create, .bdrv_co_readv = &raw_co_readv, .bdrv_co_writev = &raw_co_writev, .bdrv_co_write_zeroes = &raw_co_write_zeroes,
block/rbd.c +1 -1
@@ -917,7 +917,7 @@ static BlockDriver bdrv_rbd = { .bdrv_needs_filename = true, .bdrv_file_open = qemu_rbd_open, .bdrv_close = qemu_rbd_close, - .bdrv_create2 = qemu_rbd_create, + .bdrv_create = qemu_rbd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_get_info = qemu_rbd_getinfo, .create_opts = &qemu_rbd_create_opts,
block/sheepdog.c +3 -3
@@ -2523,7 +2523,7 @@ static BlockDriver bdrv_sheepdog = { .bdrv_needs_filename = true, .bdrv_file_open = sd_open, .bdrv_close = sd_close, - .bdrv_create2 = sd_create, + .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2553,7 +2553,7 @@ static BlockDriver bdrv_sheepdog_tcp = { .bdrv_needs_filename = true, .bdrv_file_open = sd_open, .bdrv_close = sd_close, - .bdrv_create2 = sd_create, + .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2583,7 +2583,7 @@ static BlockDriver bdrv_sheepdog_unix = { .bdrv_needs_filename = true, .bdrv_file_open = sd_open, .bdrv_close = sd_close, - .bdrv_create2 = sd_create, + .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
block/ssh.c +1 -1
@@ -1042,7 +1042,7 @@ static BlockDriver bdrv_ssh = { .instance_size = sizeof(BDRVSSHState), .bdrv_parse_filename = ssh_parse_filename, .bdrv_file_open = ssh_file_open, - .bdrv_create2 = ssh_create, + .bdrv_create = ssh_create, .bdrv_close = ssh_close, .bdrv_has_zero_init = ssh_has_zero_init, .bdrv_co_readv = ssh_co_readv,
block/vdi.c +1 -1
@@ -831,7 +831,7 @@ static BlockDriver bdrv_vdi = { .bdrv_open = vdi_open, .bdrv_close = vdi_close, .bdrv_reopen_prepare = vdi_reopen_prepare, - .bdrv_create2 = vdi_create, + .bdrv_create = vdi_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_get_block_status = vdi_co_get_block_status, .bdrv_make_empty = vdi_make_empty,
block/vhdx.c +2 -2
@@ -1786,7 +1786,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) block_size = block_size >VHDX_BLOCK_SIZE_MAX ?VHDX_BLOCK_SIZE_MAX : block_size; - ret =bdrv_create_file (filename,NULL , opts, &local_err); + ret =bdrv_create_file (filename, opts, &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto exit;
@@ -1915,7 +1915,7 @@ static BlockDriver bdrv_vhdx = { .bdrv_reopen_prepare = vhdx_reopen_prepare, .bdrv_co_readv = vhdx_co_readv, .bdrv_co_writev = vhdx_co_writev, - .bdrv_create2 = vhdx_create, + .bdrv_create = vhdx_create, .bdrv_get_info = vhdx_get_info, .bdrv_check = vhdx_check,
block/vmdk.c +3 -3
@@ -1526,7 +1526,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,uint32_t *gd_buf =NULL ;int gd_buf_size; - ret =bdrv_create_file (filename,NULL ,NULL , &local_err); + ret =bdrv_create_file (filename,NULL , &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto exit;
@@ -1860,7 +1860,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)if (!split && !flat) { desc_offset =0x200 ; }else { - ret =bdrv_create_file (filename,NULL , opts, &local_err); + ret =bdrv_create_file (filename, opts, &local_err);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not create image file" ); goto exit;
@@ -2114,7 +2114,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_write = vmdk_co_write, .bdrv_co_write_zeroes = vmdk_co_write_zeroes, .bdrv_close = vmdk_close, - .bdrv_create2 = vmdk_create, + .bdrv_create = vmdk_create, .bdrv_co_flush_to_disk = vmdk_co_flush, .bdrv_co_get_block_status = vmdk_co_get_block_status, .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
block/vpc.c +1 -1
@@ -896,7 +896,7 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_close = vpc_close, .bdrv_reopen_prepare = vpc_reopen_prepare, - .bdrv_create2 = vpc_create, + .bdrv_create = vpc_create, .bdrv_read = vpc_co_read, .bdrv_write = vpc_co_write,
block/vvfat.c +2 -12
@@ -2907,7 +2907,6 @@ static BlockDriver vvfat_write_target = {static int enable_write_target (BDRVVVFATState *s) {BlockDriver *bdrv_qcow =NULL ; -QemuOptsList *create_opts =NULL ;QemuOpts *opts =NULL ;Error *local_err =NULL ;int ret;
@@ -2923,17 +2922,11 @@ static int enable_write_target(BDRVVVFATState *s) } bdrv_qcow =bdrv_find_format ("qcow" ); -assert (!(bdrv_qcow->create_opts && bdrv_qcow->create_options)); -if (bdrv_qcow->create_options) { - create_opts =params_to_opts (bdrv_qcow->create_options); - }else { - create_opts = bdrv_qcow->create_opts; - } - opts =qemu_opts_create (create_opts,NULL ,0 , &error_abort); + opts =qemu_opts_create (bdrv_qcow->create_opts,NULL ,0 , &error_abort);qemu_opt_set_number (opts,BLOCK_OPT_SIZE , s->sector_count *512 );qemu_opt_set (opts,BLOCK_OPT_BACKING_FILE ,"fat:" ); - ret =bdrv_create (bdrv_qcow, s->qcow_filename,NULL , opts, &local_err); + ret =bdrv_create (bdrv_qcow, s->qcow_filename, opts, &local_err);if (ret <0 ) {qerror_report_err (local_err);error_free (local_err);
@@ -2963,9 +2956,6 @@ static int enable_write_target(BDRVVVFATState *s) err:qemu_opts_del (opts); -if (bdrv_qcow->create_options) { -qemu_opts_free (create_opts); - }g_free (s->qcow_filename); s->qcow_filename =NULL ;return ret;
include/block/block.h +3 -5
@@ -178,9 +178,8 @@ BlockDriver *bdrv_find_format(const char *format_name);BlockDriver *bdrv_find_whitelisted_format (const char *format_name,bool readonly);int bdrv_create (BlockDriver *drv,const char * filename, -QEMUOptionParameter *options,QemuOpts *opts,Error **errp); -int bdrv_create_file (const char * filename,QEMUOptionParameter *options, -QemuOpts *opts,Error **errp); +QemuOpts *opts,Error **errp); +int bdrv_create_file (const char *filename,QemuOpts *opts,Error **errp);BlockDriverState *bdrv_new (const char *device_name,Error **errp);void bdrv_make_anon (BlockDriverState *bs);void bdrv_swap (BlockDriverState *bs_new,BlockDriverState *bs_old);
@@ -285,8 +284,7 @@ typedef enum {int bdrv_check (BlockDriverState *bs,BdrvCheckResult *res,BdrvCheckMode fix); -int bdrv_amend_options (BlockDriverState *bs_new,QEMUOptionParameter *options, -QemuOpts *opts); +int bdrv_amend_options (BlockDriverState *bs_new,QemuOpts *opts);/* external snapshots */ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
include/block/block_int.h +2 -16
@@ -116,10 +116,7 @@ struct BlockDriver { const uint8_t *buf, int nb_sectors);void (*bdrv_close)(BlockDriverState *bs);void (*bdrv_rebind)(BlockDriverState *bs); -int (*bdrv_create)(const char *filename,QEMUOptionParameter *options, -Error **errp); -/* FIXME: will remove the duplicate and rename back to bdrv_create later */ -int (*bdrv_create2)(const char *filename,QemuOpts *opts,Error **errp); +int (*bdrv_create)(const char *filename,QemuOpts *opts,Error **errp);int (*bdrv_set_key)(BlockDriverState *bs,const char *key);int (*bdrv_make_empty)(BlockDriverState *bs);/* aio */
@@ -218,12 +215,6 @@ struct BlockDriver { BlockDriverCompletionFunc *cb, void *opaque);/* List of options for creating images, terminated by name == NULL */ -QEMUOptionParameter *create_options; -/* FIXME: will replace create_options. -* These two fields are mutually exclusive. At most one is non-NULL. -* create_options should only be set with bdrv_create, and create_opts -* should only be set with bdrv_create2. -*/ QemuOptsList *create_opts;/*
@@ -233,12 +224,7 @@ struct BlockDriver {int (*bdrv_check)(BlockDriverState * bs,BdrvCheckResult *result,BdrvCheckMode fix); -int (*bdrv_amend_options)(BlockDriverState *bs, -QEMUOptionParameter *options); -/* FIXME: will remove the duplicate and rename back to -* bdrv_amend_options later -*/ -int (*bdrv_amend_options2)(BlockDriverState *bs,QemuOpts *opts); +int (*bdrv_amend_options)(BlockDriverState *bs,QemuOpts *opts);void (*bdrv_debug_event)(BlockDriverState *bs,BlkDebugEvent event);
include/qemu/option.h +1 -47
70 lines not on this page · raw message
qemu-img.c +7 -12
@@ -261,16 +261,14 @@ static int print_block_option_help(const char *filename, const char *fmt)return 1 ; } - create_opts =qemu_opts_append (create_opts, drv->create_opts, - drv->create_options); + create_opts =qemu_opts_append (create_opts, drv->create_opts);if (filename) { proto_drv =bdrv_find_protocol (filename, true);if (!proto_drv) {error_report ("Unknown protocol '%s'" , filename);return 1 ; } - create_opts =qemu_opts_append (create_opts, proto_drv->create_opts, - proto_drv->create_options); + create_opts =qemu_opts_append (create_opts, proto_drv->create_opts); }qemu_opts_print_help (create_opts);
@@ -1362,10 +1360,8 @@ static int img_convert(int argc, char **argv) goto out; } - create_opts =qemu_opts_append (create_opts, drv->create_opts, - drv->create_options); - create_opts =qemu_opts_append (create_opts, proto_drv->create_opts, - proto_drv->create_options); + create_opts =qemu_opts_append (create_opts, drv->create_opts); + create_opts =qemu_opts_append (create_opts, proto_drv->create_opts); opts =qemu_opts_create (create_opts,NULL ,0 , &error_abort);if (options &&qemu_opts_do_parse (opts, options,NULL )) {
@@ -1418,7 +1414,7 @@ static int img_convert(int argc, char **argv)if (!skip_create) {/* Create the new image */ - ret =bdrv_create (drv, out_filename,NULL , opts, &local_err); + ret =bdrv_create (drv, out_filename, opts, &local_err);if (ret <0 ) {error_report ("%s: error while converting %s: %s" , out_filename, out_fmt,error_get_pretty (local_err));
@@ -2746,8 +2742,7 @@ static int img_amend(int argc, char **argv) goto out; } - create_opts =qemu_opts_append (create_opts, bs->drv->create_opts, - bs->drv->create_options); + create_opts =qemu_opts_append (create_opts, bs->drv->create_opts); opts =qemu_opts_create (create_opts,NULL ,0 , &error_abort);if (options &&qemu_opts_do_parse (opts, options,NULL )) {error_report ("Invalid options for file format '%s'" , fmt);
@@ -2755,7 +2750,7 @@ static int img_amend(int argc, char **argv) goto out; } - ret =bdrv_amend_options (bs,NULL , opts); + ret =bdrv_amend_options (bs, opts);if (ret <0 ) {error_report ("Error while amending options: %s" ,strerror (-ret)); goto out;
util/qemu-option.c +4 -423
472 lines not on this page · raw message
Signature · 1 line
1.7.12.4
PATCH v27 33/33 QemuOpts: cleanup tmp 'allocated' member from QemuOptsList
In reply to Chunyan LiuNow only qemu_opts_append uses 'allocated' to indicate free memory. For this function only, we can also let result list's (const char *) members point to input list's members, only if the input list has longer lifetime than result list. In current code, that is true. So, we can remove the 'allocated' member from QemuOptsList definition to keep code clean.
--- include/qemu/option.h | 6 ------ util/qemu-option.c | 27 +++------------------------ 2 files changed, 3 insertions(+), 30 deletions(-)
include/qemu/option.h +0 -6
@@ -63,12 +63,6 @@ typedef struct QemuOptDesc { } QemuOptDesc;struct QemuOptsList { -/* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to -* indicate the need to free memory. Will remove after all drivers -* switch to QemuOpts. -*/ -bool allocated; -const char *name;const char *implied_opt_name;bool merge_lists;/* Merge multiple uses of option into a single list? */
util/qemu-option.c +3 -24
@@ -1076,26 +1076,13 @@ static size_t count_opts_list(QemuOptsList *list)void qemu_opts_free (QemuOptsList *list) { -/* List members point to new malloced space and need to be freed. -* FIXME: -* Introduced for QEMUOptionParamter->QemuOpts conversion. -* Will remove after all drivers switch to QemuOpts. -*/ -if (list && list->allocated) { -QemuOptDesc *desc = list->desc; -while (desc && desc->name) { -g_free ((char *)desc->name); -g_free ((char *)desc->help); -g_free ((char *)desc->def_value_str); - desc++; - } - } -g_free (list); }/* Realloc dst option list and append options from an option list (list) * to it. dst could be NULL or a malloced list. +* The lifetime of dst must be shorter than the input list because the +* QemuOptDesc->name, ->help, and ->def_value_str strings are shared. */ QemuOptsList *qemu_opts_append (QemuOptsList *dst,QemuOptsList *list)
@@ -1124,24 +1111,16 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst, dst->name =NULL ; dst->implied_opt_name =NULL ;QTAILQ_INIT (&dst->head); - dst->allocated = true; dst->merge_lists = false; } dst->desc[num_dst_opts].name =NULL ; -/* (const char *) members of result dst are malloced, need free. */ -assert (dst->allocated);/* append list->desc to dst->desc */ if (list) { desc = list->desc;while (desc && desc->name) {if (find_desc_by_name (dst->desc, desc->name) ==NULL ) { - dst->desc[num_dst_opts].name =g_strdup (desc->name); - dst->desc[num_dst_opts].type = desc->type; - dst->desc[num_dst_opts].help =g_strdup (desc->help); - dst->desc[num_dst_opts].def_value_str = -g_strdup (desc->def_value_str); - num_dst_opts++; + dst->desc[num_dst_opts++] = *desc; dst->desc[num_dst_opts].name =NULL ; } desc++;
Signature · 1 line
1.7.12.4