static void drive_uninit(DriveInfo *dinfo)
{
- qemu_opts_del(dinfo->opts);
+ if (dinfo->opts) {
+ qemu_opts_del(dinfo->opts);
+ }
+
bdrv_unref(dinfo->bdrv);
g_free(dinfo->id);
QTAILQ_REMOVE(&drives, dinfo, next);
return true;
}
-static DriveInfo *blockdev_init(QemuOpts *all_opts,
+/* Takes the ownership of bs_opts */
+static DriveInfo *blockdev_init(QDict *bs_opts,
BlockInterfaceType block_default_type)
{
const char *buf;
int ret;
Error *error = NULL;
QemuOpts *opts;
- QDict *bs_opts;
const char *id;
bool has_driver_specific_opts;
BlockDriver *drv = NULL;
translation = BIOS_ATA_TRANSLATION_AUTO;
media = MEDIA_DISK;
- /* Check common options by copying from all_opts to opts, all other options
- * are stored in bs_opts. */
- id = qemu_opts_id(all_opts);
+ /* Check common options by copying from bs_opts to opts, all other options
+ * stay in bs_opts for processing by bdrv_open(). */
+ id = qdict_get_try_str(bs_opts, "id");
opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error);
if (error_is_set(&error)) {
qerror_report_err(error);
return NULL;
}
- bs_opts = qdict_new();
- qemu_opts_to_qdict(all_opts, bs_opts);
qemu_opts_absorb_qdict(opts, bs_opts, &error);
if (error_is_set(&error)) {
qerror_report_err(error);
dinfo->heads = heads;
dinfo->secs = secs;
dinfo->trans = translation;
- dinfo->opts = all_opts;
dinfo->refcount = 1;
if (serial != NULL) {
dinfo->serial = g_strdup(serial);
{
const char *value;
DriveInfo *dinfo;
+ QDict *bs_opts;
/* Change legacy command line options into QMP ones */
qemu_opt_rename(all_opts, "iops", "throttling.iops-total");
qemu_opt_unset(all_opts, "cache");
}
+ /* Get a QDict for processing the options */
+ bs_opts = qdict_new();
+ qemu_opts_to_qdict(all_opts, bs_opts);
+
/* Actual block device init: Functionality shared with blockdev-add */
- dinfo = blockdev_init(all_opts, block_default_type);
+ dinfo = blockdev_init(bs_opts, block_default_type);
if (dinfo == NULL) {
goto fail;
}
/* Set legacy DriveInfo fields */
dinfo->enable_auto_del = true;
+ dinfo->opts = all_opts;
fail:
return dinfo;
qdict_flatten(qdict);
- QemuOpts *opts = qemu_opts_from_qdict(&qemu_drive_opts, qdict, &local_err);
- if (error_is_set(&local_err)) {
- error_propagate(errp, local_err);
- goto fail;
- }
-
- dinfo = blockdev_init(opts, IF_NONE);
+ dinfo = blockdev_init(qdict, IF_NONE);
if (!dinfo) {
error_setg(errp, "Could not open image");
goto fail;