Commit f43e47db authored by Markus Armbruster's avatar Markus Armbruster
Browse files

QemuOpts: Drop qemu_opt_set(), rename qemu_opt_set_err(), fix use



qemu_opt_set() is a wrapper around qemu_opt_set() that reports the
error with qerror_report_err().

Most of its users assume the function can't fail.  Make them use
qemu_opt_set_err() with &error_abort, so that should the assumption
ever break, it'll break noisily.

Just two users remain, in util/qemu-config.c.  Switch them to
qemu_opt_set_err() as well, then rename qemu_opt_set_err() to
qemu_opt_set().

Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
parent 6be4194b
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -5660,8 +5660,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
    }

    if (base_filename) {
        qemu_opt_set_err(opts, BLOCK_OPT_BACKING_FILE, base_filename,
                         &local_err);
        qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename, &local_err);
        if (local_err) {
            error_setg(errp, "Backing file not supported for file format '%s'",
                       fmt);
@@ -5670,7 +5669,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
    }

    if (base_fmt) {
        qemu_opt_set_err(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &local_err);
        qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &local_err);
        if (local_err) {
            error_setg(errp, "Backing file format not supported for file "
                             "format '%s'", fmt);
+2 −1
Original line number Diff line number Diff line
@@ -1859,7 +1859,8 @@ static int qcow2_create2(const char *filename, int64_t total_size,

        qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
                            aligned_total_size + meta_size, &error_abort);
        qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[prealloc]);
        qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[prealloc],
                     &error_abort);
    }

    ret = bdrv_create_file(filename, opts, &local_err);
+1 −1
Original line number Diff line number Diff line
@@ -2926,7 +2926,7 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
    opts = qemu_opts_create(bdrv_qcow->create_opts, NULL, 0, &error_abort);
    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512,
                        &error_abort);
    qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
    qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:", &error_abort);

    ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, errp);
    qemu_opts_del(opts);
+9 −8
Original line number Diff line number Diff line
@@ -187,14 +187,14 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
        return NULL;
    }
    if (type != IF_DEFAULT) {
        qemu_opt_set(opts, "if", if_name[type]);
        qemu_opt_set(opts, "if", if_name[type], &error_abort);
    }
    if (index >= 0) {
        snprintf(buf, sizeof(buf), "%d", index);
        qemu_opt_set(opts, "index", buf);
        qemu_opt_set(opts, "index", buf, &error_abort);
    }
    if (file)
        qemu_opt_set(opts, "file", file);
        qemu_opt_set(opts, "file", file, &error_abort);
    return opts;
}

@@ -584,7 +584,7 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to,

    /* rename all items in opts */
    while ((value = qemu_opt_get(opts, from))) {
        qemu_opt_set(opts, to, value);
        qemu_opt_set(opts, to, value, &error_abort);
        qemu_opt_unset(opts, from);
    }
}
@@ -935,13 +935,14 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
        devopts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
                                   &error_abort);
        if (arch_type == QEMU_ARCH_S390X) {
            qemu_opt_set(devopts, "driver", "virtio-blk-s390");
            qemu_opt_set(devopts, "driver", "virtio-blk-s390", &error_abort);
        } else {
            qemu_opt_set(devopts, "driver", "virtio-blk-pci");
            qemu_opt_set(devopts, "driver", "virtio-blk-pci", &error_abort);
        }
        qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id"));
        qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id"),
                     &error_abort);
        if (devaddr) {
            qemu_opt_set(devopts, "addr", devaddr);
            qemu_opt_set(devopts, "addr", devaddr, &error_abort);
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
        return NULL;
    }

    qemu_opt_set(opts, "type", "nic");
    qemu_opt_set(opts, "type", "nic", &error_abort);

    ret = net_client_init(opts, 0, &local_err);
    if (local_err) {
Loading