Revision f298d071 blockdev.c

b/blockdev.c
217 217

  
218 218
static void drive_uninit(DriveInfo *dinfo)
219 219
{
220
    qemu_opts_del(dinfo->opts);
220
    if (dinfo->opts) {
221
        qemu_opts_del(dinfo->opts);
222
    }
223

  
221 224
    bdrv_unref(dinfo->bdrv);
222 225
    g_free(dinfo->id);
223 226
    QTAILQ_REMOVE(&drives, dinfo, next);
......
302 305
    return true;
303 306
}
304 307

  
305
static DriveInfo *blockdev_init(QemuOpts *all_opts,
308
/* Takes the ownership of bs_opts */
309
static DriveInfo *blockdev_init(QDict *bs_opts,
306 310
                                BlockInterfaceType block_default_type)
307 311
{
308 312
    const char *buf;
......
326 330
    int ret;
327 331
    Error *error = NULL;
328 332
    QemuOpts *opts;
329
    QDict *bs_opts;
330 333
    const char *id;
331 334
    bool has_driver_specific_opts;
332 335
    BlockDriver *drv = NULL;
......
334 337
    translation = BIOS_ATA_TRANSLATION_AUTO;
335 338
    media = MEDIA_DISK;
336 339

  
337
    /* Check common options by copying from all_opts to opts, all other options
338
     * are stored in bs_opts. */
339
    id = qemu_opts_id(all_opts);
340
    /* Check common options by copying from bs_opts to opts, all other options
341
     * stay in bs_opts for processing by bdrv_open(). */
342
    id = qdict_get_try_str(bs_opts, "id");
340 343
    opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error);
341 344
    if (error_is_set(&error)) {
342 345
        qerror_report_err(error);
......
344 347
        return NULL;
345 348
    }
346 349

  
347
    bs_opts = qdict_new();
348
    qemu_opts_to_qdict(all_opts, bs_opts);
349 350
    qemu_opts_absorb_qdict(opts, bs_opts, &error);
350 351
    if (error_is_set(&error)) {
351 352
        qerror_report_err(error);
......
630 631
    dinfo->heads = heads;
631 632
    dinfo->secs = secs;
632 633
    dinfo->trans = translation;
633
    dinfo->opts = all_opts;
634 634
    dinfo->refcount = 1;
635 635
    if (serial != NULL) {
636 636
        dinfo->serial = g_strdup(serial);
......
755 755
{
756 756
    const char *value;
757 757
    DriveInfo *dinfo;
758
    QDict *bs_opts;
758 759

  
759 760
    /* Change legacy command line options into QMP ones */
760 761
    qemu_opt_rename(all_opts, "iops", "throttling.iops-total");
......
803 804
        qemu_opt_unset(all_opts, "cache");
804 805
    }
805 806

  
807
    /* Get a QDict for processing the options */
808
    bs_opts = qdict_new();
809
    qemu_opts_to_qdict(all_opts, bs_opts);
810

  
806 811
    /* Actual block device init: Functionality shared with blockdev-add */
807
    dinfo = blockdev_init(all_opts, block_default_type);
812
    dinfo = blockdev_init(bs_opts, block_default_type);
808 813
    if (dinfo == NULL) {
809 814
        goto fail;
810 815
    }
811 816

  
812 817
    /* Set legacy DriveInfo fields */
813 818
    dinfo->enable_auto_del = true;
819
    dinfo->opts = all_opts;
814 820

  
815 821
fail:
816 822
    return dinfo;
......
2109 2115

  
2110 2116
    qdict_flatten(qdict);
2111 2117

  
2112
    QemuOpts *opts = qemu_opts_from_qdict(&qemu_drive_opts, qdict, &local_err);
2113
    if (error_is_set(&local_err)) {
2114
        error_propagate(errp, local_err);
2115
        goto fail;
2116
    }
2117

  
2118
    dinfo = blockdev_init(opts, IF_NONE);
2118
    dinfo = blockdev_init(qdict, IF_NONE);
2119 2119
    if (!dinfo) {
2120 2120
        error_setg(errp, "Could not open image");
2121 2121
        goto fail;

Also available in: Unified diff