Message ID | 1398762656-26079-14-git-send-email-cyliu@suse.com |
---|---|
State | New |
Headers | show |
On 04/29/2014 03:10 AM, Chunyan Liu wrote: > vvfat shares create options of qcow driver. To avoid vvfat broken when s/broken/breaking/ > qcow driver changes from QEMUOptionParameter to QemuOpts, let it able > to handle both cases. > > Signed-off-by: Chunyan Liu <cyliu@suse.com> > --- > block/vvfat.c | 19 ++++++++++++++----- > 1 file changed, 14 insertions(+), 5 deletions(-) > > diff --git a/block/vvfat.c b/block/vvfat.c > index 155fc9b..b49ec96 100644 > --- a/block/vvfat.c > +++ b/block/vvfat.c > @@ -2907,7 +2907,8 @@ static BlockDriver vvfat_write_target = { > static int enable_write_target(BDRVVVFATState *s) > { > BlockDriver *bdrv_qcow; > - QEMUOptionParameter *options; > + QemuOptsList *create_opts = NULL; > + QemuOpts *opts = NULL; > Error *local_err = NULL; > int ret; > int size = sector2cluster(s, s->sector_count); > @@ -2922,11 +2923,17 @@ static int enable_write_target(BDRVVVFATState *s) > } > > bdrv_qcow = bdrv_find_format("qcow"); > - options = parse_option_parameters("", bdrv_qcow->create_options, NULL); > - set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512); > - set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:"); > + assert(!(bdrv_qcow->create_opts && bdrv_qcow->create_options)); > + if (bdrv_qcow->create_options) { > + create_opts = params_to_opts(bdrv_qcow->create_options); allocated... > + } else { > + create_opts = bdrv_qcow->create_opts; vs. reference... > err: > + qemu_opts_del(opts); > + qemu_opts_free(create_opts); but unconditionally freed on either path. Calling g_free(bdrv_qcow->create_opts) is not nice.
On 05/01/2014 01:18 PM, Eric Blake wrote: > On 04/29/2014 03:10 AM, Chunyan Liu wrote: >> vvfat shares create options of qcow driver. To avoid vvfat broken when > > s/broken/breaking/ > >> qcow driver changes from QEMUOptionParameter to QemuOpts, let it able >> to handle both cases. >> >> + if (bdrv_qcow->create_options) { >> + create_opts = params_to_opts(bdrv_qcow->create_options); > > allocated... > >> + } else { >> + create_opts = bdrv_qcow->create_opts; > > vs. reference... > Couldn't you just do: create_opts = qemu_opts_append(NULL, bdrv_qcow2->create_opts, bdrv_qcow2->create_options); at which point, your blind free on cleanup will just work? >> err: >> + qemu_opts_del(opts); >> + qemu_opts_free(create_opts); > > but unconditionally freed on either path. Calling > g_free(bdrv_qcow->create_opts) is not nice. >
diff --git a/block/vvfat.c b/block/vvfat.c index 155fc9b..b49ec96 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2907,7 +2907,8 @@ static BlockDriver vvfat_write_target = { static int enable_write_target(BDRVVVFATState *s) { BlockDriver *bdrv_qcow; - QEMUOptionParameter *options; + QemuOptsList *create_opts = NULL; + QemuOpts *opts = NULL; Error *local_err = NULL; int ret; int size = sector2cluster(s, s->sector_count); @@ -2922,11 +2923,17 @@ static int enable_write_target(BDRVVVFATState *s) } bdrv_qcow = bdrv_find_format("qcow"); - options = parse_option_parameters("", bdrv_qcow->create_options, NULL); - set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512); - set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:"); + 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); + 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, options, NULL, &local_err); + ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err); if (ret < 0) { qerror_report_err(local_err); error_free(local_err); @@ -2955,6 +2962,8 @@ static int enable_write_target(BDRVVVFATState *s) return 0; err: + qemu_opts_del(opts); + qemu_opts_free(create_opts); g_free(s->qcow_filename); s->qcow_filename = NULL; return ret;
vvfat shares create options of qcow driver. To avoid vvfat broken when qcow driver changes from QEMUOptionParameter to QemuOpts, let it able to handle both cases. Signed-off-by: Chunyan Liu <cyliu@suse.com> --- block/vvfat.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)