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: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Markus Armbruster 2015-02-12 17:52:20 +01:00
parent 6be4194b92
commit f43e47dbf6
18 changed files with 131 additions and 131 deletions

View File

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

View File

@ -1859,7 +1859,8 @@ static int qcow2_create2(const char *filename, int64_t total_size,
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
aligned_total_size + meta_size, &error_abort); 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); ret = bdrv_create_file(filename, opts, &local_err);

View File

@ -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); 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_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512,
&error_abort); &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); ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, errp);
qemu_opts_del(opts); qemu_opts_del(opts);

View File

@ -187,14 +187,14 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
return NULL; return NULL;
} }
if (type != IF_DEFAULT) { 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) { if (index >= 0) {
snprintf(buf, sizeof(buf), "%d", index); snprintf(buf, sizeof(buf), "%d", index);
qemu_opt_set(opts, "index", buf); qemu_opt_set(opts, "index", buf, &error_abort);
} }
if (file) if (file)
qemu_opt_set(opts, "file", file); qemu_opt_set(opts, "file", file, &error_abort);
return opts; return opts;
} }
@ -584,7 +584,7 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to,
/* rename all items in opts */ /* rename all items in opts */
while ((value = qemu_opt_get(opts, from))) { 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); 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, devopts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
&error_abort); &error_abort);
if (arch_type == QEMU_ARCH_S390X) { 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 { } 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) { if (devaddr) {
qemu_opt_set(devopts, "addr", devaddr); qemu_opt_set(devopts, "addr", devaddr, &error_abort);
} }
} }

View File

@ -87,7 +87,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
return NULL; return NULL;
} }
qemu_opt_set(opts, "type", "nic"); qemu_opt_set(opts, "type", "nic", &error_abort);
ret = net_client_init(opts, 0, &local_err); ret = net_client_init(opts, 0, &local_err);
if (local_err) { if (local_err) {

View File

@ -1394,8 +1394,8 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
if (!opts) { if (!opts) {
return NULL; return NULL;
} }
qemu_opt_set(opts, "type", "nic"); qemu_opt_set(opts, "type", "nic", &error_abort);
qemu_opt_set(opts, "model", "usb"); qemu_opt_set(opts, "model", "usb", &error_abort);
idx = net_client_init(opts, 0, &local_err); idx = net_client_init(opts, 0, &local_err);
if (local_err) { if (local_err) {

View File

@ -683,7 +683,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
if (strstart(filename, "format=", &p2)) { if (strstart(filename, "format=", &p2)) {
int len = MIN(p1 - p2, sizeof(fmt)); int len = MIN(p1 - p2, sizeof(fmt));
pstrcpy(fmt, len, p2); pstrcpy(fmt, len, p2);
qemu_opt_set(opts, "format", fmt); qemu_opt_set(opts, "format", fmt, &error_abort);
} else if (*filename != ':') { } else if (*filename != ':') {
error_report("unrecognized USB mass-storage option %s", filename); error_report("unrecognized USB mass-storage option %s", filename);
return NULL; return NULL;
@ -694,8 +694,8 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
error_report("block device specification needed"); error_report("block device specification needed");
return NULL; return NULL;
} }
qemu_opt_set(opts, "file", filename); qemu_opt_set(opts, "file", filename, &error_abort);
qemu_opt_set(opts, "if", "none"); qemu_opt_set(opts, "if", "none", &error_abort);
/* create host drive */ /* create host drive */
dinfo = drive_new(opts, 0); dinfo = drive_new(opts, 0);

View File

@ -68,7 +68,7 @@ int select_watchdog(const char *p)
/* add the device */ /* add the device */
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
&error_abort); &error_abort);
qemu_opt_set(opts, "driver", p); qemu_opt_set(opts, "driver", p, &error_abort);
return 0; return 0;
} }
} }

View File

@ -94,8 +94,7 @@ uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name, uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
uint64_t defval); uint64_t defval);
int qemu_opt_unset(QemuOpts *opts, const char *name); int qemu_opt_unset(QemuOpts *opts, const char *name);
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); void qemu_opt_set(QemuOpts *opts, const char *name, const char *value,
void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
Error **errp); Error **errp);
void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val, void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
Error **errp); Error **errp);

View File

@ -970,7 +970,7 @@ void hmp_host_net_add(Monitor *mon, const QDict *qdict)
return; return;
} }
qemu_opt_set(opts, "type", device); qemu_opt_set(opts, "type", device, &error_abort);
net_client_init(opts, 0, &local_err); net_client_init(opts, 0, &local_err);
if (local_err) { if (local_err) {

View File

@ -772,8 +772,8 @@ int qemu_global_option(const char *str)
} }
opts = qemu_opts_create(&qemu_global_opts, NULL, 0, &error_abort); opts = qemu_opts_create(&qemu_global_opts, NULL, 0, &error_abort);
qemu_opt_set(opts, "driver", driver); qemu_opt_set(opts, "driver", driver, &error_abort);
qemu_opt_set(opts, "property", property); qemu_opt_set(opts, "property", property, &error_abort);
qemu_opt_set(opts, "value", str+offset+1); qemu_opt_set(opts, "value", str + offset + 1, &error_abort);
return 0; return 0;
} }

View File

@ -3312,14 +3312,14 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
if (strstart(filename, "mon:", &p)) { if (strstart(filename, "mon:", &p)) {
filename = p; filename = p;
qemu_opt_set(opts, "mux", "on"); qemu_opt_set(opts, "mux", "on", &error_abort);
if (strcmp(filename, "stdio") == 0) { if (strcmp(filename, "stdio") == 0) {
/* Monitor is muxed to stdio: do not exit on Ctrl+C by default /* Monitor is muxed to stdio: do not exit on Ctrl+C by default
* but pass it to the guest. Handle this only for compat syntax, * but pass it to the guest. Handle this only for compat syntax,
* for -chardev syntax we have special option for this. * for -chardev syntax we have special option for this.
* This is what -nographic did, redirecting+muxing serial+monitor * This is what -nographic did, redirecting+muxing serial+monitor
* to stdio causing Ctrl+C to be passed to guest. */ * to stdio causing Ctrl+C to be passed to guest. */
qemu_opt_set(opts, "signal", "off"); qemu_opt_set(opts, "signal", "off", &error_abort);
} }
} }
@ -3329,20 +3329,20 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
strcmp(filename, "braille") == 0 || strcmp(filename, "braille") == 0 ||
strcmp(filename, "testdev") == 0 || strcmp(filename, "testdev") == 0 ||
strcmp(filename, "stdio") == 0) { strcmp(filename, "stdio") == 0) {
qemu_opt_set(opts, "backend", filename); qemu_opt_set(opts, "backend", filename, &error_abort);
return opts; return opts;
} }
if (strstart(filename, "vc", &p)) { if (strstart(filename, "vc", &p)) {
qemu_opt_set(opts, "backend", "vc"); qemu_opt_set(opts, "backend", "vc", &error_abort);
if (*p == ':') { if (*p == ':') {
if (sscanf(p+1, "%7[0-9]x%7[0-9]", width, height) == 2) { if (sscanf(p+1, "%7[0-9]x%7[0-9]", width, height) == 2) {
/* pixels */ /* pixels */
qemu_opt_set(opts, "width", width); qemu_opt_set(opts, "width", width, &error_abort);
qemu_opt_set(opts, "height", height); qemu_opt_set(opts, "height", height, &error_abort);
} else if (sscanf(p+1, "%7[0-9]Cx%7[0-9]C", width, height) == 2) { } else if (sscanf(p+1, "%7[0-9]Cx%7[0-9]C", width, height) == 2) {
/* chars */ /* chars */
qemu_opt_set(opts, "cols", width); qemu_opt_set(opts, "cols", width, &error_abort);
qemu_opt_set(opts, "rows", height); qemu_opt_set(opts, "rows", height, &error_abort);
} else { } else {
goto fail; goto fail;
} }
@ -3350,22 +3350,22 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
return opts; return opts;
} }
if (strcmp(filename, "con:") == 0) { if (strcmp(filename, "con:") == 0) {
qemu_opt_set(opts, "backend", "console"); qemu_opt_set(opts, "backend", "console", &error_abort);
return opts; return opts;
} }
if (strstart(filename, "COM", NULL)) { if (strstart(filename, "COM", NULL)) {
qemu_opt_set(opts, "backend", "serial"); qemu_opt_set(opts, "backend", "serial", &error_abort);
qemu_opt_set(opts, "path", filename); qemu_opt_set(opts, "path", filename, &error_abort);
return opts; return opts;
} }
if (strstart(filename, "file:", &p)) { if (strstart(filename, "file:", &p)) {
qemu_opt_set(opts, "backend", "file"); qemu_opt_set(opts, "backend", "file", &error_abort);
qemu_opt_set(opts, "path", p); qemu_opt_set(opts, "path", p, &error_abort);
return opts; return opts;
} }
if (strstart(filename, "pipe:", &p)) { if (strstart(filename, "pipe:", &p)) {
qemu_opt_set(opts, "backend", "pipe"); qemu_opt_set(opts, "backend", "pipe", &error_abort);
qemu_opt_set(opts, "path", p); qemu_opt_set(opts, "path", p, &error_abort);
return opts; return opts;
} }
if (strstart(filename, "tcp:", &p) || if (strstart(filename, "tcp:", &p) ||
@ -3375,27 +3375,27 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
if (sscanf(p, ":%32[^,]%n", port, &pos) < 1) if (sscanf(p, ":%32[^,]%n", port, &pos) < 1)
goto fail; goto fail;
} }
qemu_opt_set(opts, "backend", "socket"); qemu_opt_set(opts, "backend", "socket", &error_abort);
qemu_opt_set(opts, "host", host); qemu_opt_set(opts, "host", host, &error_abort);
qemu_opt_set(opts, "port", port); qemu_opt_set(opts, "port", port, &error_abort);
if (p[pos] == ',') { if (p[pos] == ',') {
if (qemu_opts_do_parse(opts, p+pos+1, NULL) != 0) if (qemu_opts_do_parse(opts, p+pos+1, NULL) != 0)
goto fail; goto fail;
} }
if (strstart(filename, "telnet:", &p)) if (strstart(filename, "telnet:", &p))
qemu_opt_set(opts, "telnet", "on"); qemu_opt_set(opts, "telnet", "on", &error_abort);
return opts; return opts;
} }
if (strstart(filename, "udp:", &p)) { if (strstart(filename, "udp:", &p)) {
qemu_opt_set(opts, "backend", "udp"); qemu_opt_set(opts, "backend", "udp", &error_abort);
if (sscanf(p, "%64[^:]:%32[^@,]%n", host, port, &pos) < 2) { if (sscanf(p, "%64[^:]:%32[^@,]%n", host, port, &pos) < 2) {
host[0] = 0; host[0] = 0;
if (sscanf(p, ":%32[^@,]%n", port, &pos) < 1) { if (sscanf(p, ":%32[^@,]%n", port, &pos) < 1) {
goto fail; goto fail;
} }
} }
qemu_opt_set(opts, "host", host); qemu_opt_set(opts, "host", host, &error_abort);
qemu_opt_set(opts, "port", port); qemu_opt_set(opts, "port", port, &error_abort);
if (p[pos] == '@') { if (p[pos] == '@') {
p += pos + 1; p += pos + 1;
if (sscanf(p, "%64[^:]:%32[^,]%n", host, port, &pos) < 2) { if (sscanf(p, "%64[^:]:%32[^,]%n", host, port, &pos) < 2) {
@ -3404,26 +3404,26 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
goto fail; goto fail;
} }
} }
qemu_opt_set(opts, "localaddr", host); qemu_opt_set(opts, "localaddr", host, &error_abort);
qemu_opt_set(opts, "localport", port); qemu_opt_set(opts, "localport", port, &error_abort);
} }
return opts; return opts;
} }
if (strstart(filename, "unix:", &p)) { if (strstart(filename, "unix:", &p)) {
qemu_opt_set(opts, "backend", "socket"); qemu_opt_set(opts, "backend", "socket", &error_abort);
if (qemu_opts_do_parse(opts, p, "path") != 0) if (qemu_opts_do_parse(opts, p, "path") != 0)
goto fail; goto fail;
return opts; return opts;
} }
if (strstart(filename, "/dev/parport", NULL) || if (strstart(filename, "/dev/parport", NULL) ||
strstart(filename, "/dev/ppi", NULL)) { strstart(filename, "/dev/ppi", NULL)) {
qemu_opt_set(opts, "backend", "parport"); qemu_opt_set(opts, "backend", "parport", &error_abort);
qemu_opt_set(opts, "path", filename); qemu_opt_set(opts, "path", filename, &error_abort);
return opts; return opts;
} }
if (strstart(filename, "/dev/", NULL)) { if (strstart(filename, "/dev/", NULL)) {
qemu_opt_set(opts, "backend", "tty"); qemu_opt_set(opts, "backend", "tty", &error_abort);
qemu_opt_set(opts, "path", filename); qemu_opt_set(opts, "path", filename, &error_abort);
return opts; return opts;
} }

View File

@ -335,7 +335,7 @@ static int add_old_style_options(const char *fmt, QemuOpts *opts,
Error *err = NULL; Error *err = NULL;
if (base_filename) { if (base_filename) {
qemu_opt_set_err(opts, BLOCK_OPT_BACKING_FILE, base_filename, &err); qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename, &err);
if (err) { if (err) {
error_report("Backing file not supported for file format '%s'", error_report("Backing file not supported for file format '%s'",
fmt); fmt);
@ -344,7 +344,7 @@ static int add_old_style_options(const char *fmt, QemuOpts *opts,
} }
} }
if (base_fmt) { if (base_fmt) {
qemu_opt_set_err(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &err); qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &err);
if (err) { if (err) {
error_report("Backing file format not supported for file " error_report("Backing file format not supported for file "
"format '%s'", fmt); "format '%s'", fmt);
@ -2828,7 +2828,7 @@ static int img_resize(int argc, char **argv)
/* Parse size */ /* Parse size */
param = qemu_opts_create(&resize_options, NULL, 0, &error_abort); param = qemu_opts_create(&resize_options, NULL, 0, &error_abort);
qemu_opt_set_err(param, BLOCK_OPT_SIZE, size, &err); qemu_opt_set(param, BLOCK_OPT_SIZE, size, &err);
if (err) { if (err) {
error_report_err(err); error_report_err(err);
ret = -1; ret = -1;

View File

@ -148,13 +148,13 @@ static void test_qemu_opt_get(void)
opt = qemu_opt_get(opts, "str2"); opt = qemu_opt_get(opts, "str2");
g_assert(opt == NULL); g_assert(opt == NULL);
qemu_opt_set(opts, "str2", "value"); qemu_opt_set(opts, "str2", "value", &error_abort);
/* now we have set str2, should know about it */ /* now we have set str2, should know about it */
opt = qemu_opt_get(opts, "str2"); opt = qemu_opt_get(opts, "str2");
g_assert_cmpstr(opt, ==, "value"); g_assert_cmpstr(opt, ==, "value");
qemu_opt_set(opts, "str2", "value2"); qemu_opt_set(opts, "str2", "value2", &error_abort);
/* having reset the value, the returned should be the reset one */ /* having reset the value, the returned should be the reset one */
opt = qemu_opt_get(opts, "str2"); opt = qemu_opt_get(opts, "str2");
@ -331,7 +331,7 @@ static void test_qemu_opt_unset(void)
g_assert_cmpstr(value, ==, "value"); g_assert_cmpstr(value, ==, "value");
/* reset it to value2 */ /* reset it to value2 */
qemu_opt_set(opts, "key", "value2"); qemu_opt_set(opts, "key", "value2", &error_abort);
value = qemu_opt_get(opts, "key"); value = qemu_opt_get(opts, "key");
g_assert_cmpstr(value, ==, "value2"); g_assert_cmpstr(value, ==, "value2");

View File

@ -219,6 +219,7 @@ void qemu_add_opts(QemuOptsList *list)
int qemu_set_option(const char *str) int qemu_set_option(const char *str)
{ {
Error *local_err = NULL;
char group[64], id[64], arg[64]; char group[64], id[64], arg[64];
QemuOptsList *list; QemuOptsList *list;
QemuOpts *opts; QemuOpts *opts;
@ -242,7 +243,9 @@ int qemu_set_option(const char *str)
return -1; return -1;
} }
if (qemu_opt_set(opts, arg, str+offset+1) == -1) { qemu_opt_set(opts, arg, str + offset + 1, &local_err);
if (local_err) {
error_report_err(local_err);
return -1; return -1;
} }
return 0; return 0;
@ -335,7 +338,9 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
error_report("no group defined"); error_report("no group defined");
goto out; goto out;
} }
if (qemu_opt_set(opts, arg, value) != 0) { qemu_opt_set(opts, arg, value, &local_err);
if (local_err) {
error_report_err(local_err);
goto out; goto out;
} }
continue; continue;

View File

@ -548,21 +548,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
} }
} }
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) void qemu_opt_set(QemuOpts *opts, const char *name, const char *value,
{
Error *local_err = NULL;
opt_set(opts, name, value, false, &local_err);
if (local_err) {
qerror_report_err(local_err);
error_free(local_err);
return -1;
}
return 0;
}
void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
Error **errp) Error **errp)
{ {
opt_set(opts, name, value, false, errp); opt_set(opts, name, value, false, errp);
@ -701,7 +687,7 @@ void qemu_opts_set(QemuOptsList *list, const char *id,
error_propagate(errp, local_err); error_propagate(errp, local_err);
return; return;
} }
qemu_opt_set_err(opts, name, value, errp); qemu_opt_set(opts, name, value, errp);
} }
const char *qemu_opts_id(QemuOpts *opts) const char *qemu_opts_id(QemuOpts *opts)
@ -921,7 +907,7 @@ static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
return; return;
} }
qemu_opt_set_err(state->opts, key, value, state->errp); qemu_opt_set(state->opts, key, value, state->errp);
} }
/* /*

View File

@ -200,10 +200,12 @@ listen:
return -1; return -1;
} }
snprintf(uport, sizeof(uport), "%d", inet_getport(e) - port_offset); snprintf(uport, sizeof(uport), "%d", inet_getport(e) - port_offset);
qemu_opt_set(opts, "host", uaddr); qemu_opt_set(opts, "host", uaddr, &error_abort);
qemu_opt_set(opts, "port", uport); qemu_opt_set(opts, "port", uport, &error_abort);
qemu_opt_set(opts, "ipv6", (e->ai_family == PF_INET6) ? "on" : "off"); qemu_opt_set(opts, "ipv6", (e->ai_family == PF_INET6) ? "on" : "off",
qemu_opt_set(opts, "ipv4", (e->ai_family != PF_INET6) ? "on" : "off"); &error_abort);
qemu_opt_set(opts, "ipv4", (e->ai_family != PF_INET6) ? "on" : "off",
&error_abort);
freeaddrinfo(res); freeaddrinfo(res);
return slisten; return slisten;
} }
@ -586,10 +588,10 @@ static void inet_addr_to_opts(QemuOpts *opts, const InetSocketAddress *addr)
if (addr->has_to) { if (addr->has_to) {
char to[20]; char to[20];
snprintf(to, sizeof(to), "%d", addr->to); snprintf(to, sizeof(to), "%d", addr->to);
qemu_opt_set(opts, "to", to); qemu_opt_set(opts, "to", to, &error_abort);
} }
qemu_opt_set(opts, "host", addr->host); qemu_opt_set(opts, "host", addr->host, &error_abort);
qemu_opt_set(opts, "port", addr->port); qemu_opt_set(opts, "port", addr->port, &error_abort);
} }
int inet_listen(const char *str, char *ostr, int olen, int inet_listen(const char *str, char *ostr, int olen,
@ -726,7 +728,7 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
goto err; goto err;
} }
close(fd); close(fd);
qemu_opt_set(opts, "path", un.sun_path); qemu_opt_set(opts, "path", un.sun_path, &error_abort);
} }
unlink(un.sun_path); unlink(un.sun_path);
@ -838,11 +840,11 @@ int unix_listen(const char *str, char *ostr, int olen, Error **errp)
if (len) { if (len) {
path = g_malloc(len+1); path = g_malloc(len+1);
snprintf(path, len+1, "%.*s", len, str); snprintf(path, len+1, "%.*s", len, str);
qemu_opt_set(opts, "path", path); qemu_opt_set(opts, "path", path, &error_abort);
g_free(path); g_free(path);
} }
} else { } else {
qemu_opt_set(opts, "path", str); qemu_opt_set(opts, "path", str, &error_abort);
} }
sock = unix_listen_opts(opts, errp); sock = unix_listen_opts(opts, errp);
@ -859,7 +861,7 @@ int unix_connect(const char *path, Error **errp)
int sock; int sock;
opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
qemu_opt_set(opts, "path", path); qemu_opt_set(opts, "path", path, &error_abort);
sock = unix_connect_opts(opts, errp, NULL, NULL); sock = unix_connect_opts(opts, errp, NULL, NULL);
qemu_opts_del(opts); qemu_opts_del(opts);
return sock; return sock;
@ -876,7 +878,7 @@ int unix_nonblocking_connect(const char *path,
g_assert(callback != NULL); g_assert(callback != NULL);
opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
qemu_opt_set(opts, "path", path); qemu_opt_set(opts, "path", path, &error_abort);
sock = unix_connect_opts(opts, errp, callback, opaque); sock = unix_connect_opts(opts, errp, callback, opaque);
qemu_opts_del(opts); qemu_opts_del(opts);
return sock; return sock;
@ -933,7 +935,7 @@ int socket_connect(SocketAddress *addr, Error **errp,
break; break;
case SOCKET_ADDRESS_KIND_UNIX: case SOCKET_ADDRESS_KIND_UNIX:
qemu_opt_set(opts, "path", addr->q_unix->path); qemu_opt_set(opts, "path", addr->q_unix->path, &error_abort);
fd = unix_connect_opts(opts, errp, callback, opaque); fd = unix_connect_opts(opts, errp, callback, opaque);
break; break;
@ -965,7 +967,7 @@ int socket_listen(SocketAddress *addr, Error **errp)
break; break;
case SOCKET_ADDRESS_KIND_UNIX: case SOCKET_ADDRESS_KIND_UNIX:
qemu_opt_set(opts, "path", addr->q_unix->path); qemu_opt_set(opts, "path", addr->q_unix->path, &error_abort);
fd = unix_listen_opts(opts, errp); fd = unix_listen_opts(opts, errp);
break; break;
@ -990,8 +992,8 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp)
case SOCKET_ADDRESS_KIND_INET: case SOCKET_ADDRESS_KIND_INET:
inet_addr_to_opts(opts, remote->inet); inet_addr_to_opts(opts, remote->inet);
if (local) { if (local) {
qemu_opt_set(opts, "localaddr", local->inet->host); qemu_opt_set(opts, "localaddr", local->inet->host, &error_abort);
qemu_opt_set(opts, "localport", local->inet->port); qemu_opt_set(opts, "localport", local->inet->port, &error_abort);
} }
fd = inet_dgram_opts(opts, errp); fd = inet_dgram_opts(opts, errp);
break; break;

73
vl.c
View File

@ -1096,7 +1096,7 @@ static int drive_init_func(QemuOpts *opts, void *opaque)
static int drive_enable_snapshot(QemuOpts *opts, void *opaque) static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
{ {
if (qemu_opt_get(opts, "snapshot") == NULL) { if (qemu_opt_get(opts, "snapshot") == NULL) {
qemu_opt_set(opts, "snapshot", "on"); qemu_opt_set(opts, "snapshot", "on", &error_abort);
} }
return 0; return 0;
} }
@ -2074,7 +2074,7 @@ static int balloon_parse(const char *arg)
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
&error_abort); &error_abort);
} }
qemu_opt_set(opts, "driver", "virtio-balloon"); qemu_opt_set(opts, "driver", "virtio-balloon", &error_abort);
return 0; return 0;
} }
@ -2220,11 +2220,11 @@ static void monitor_parse(const char *optarg, const char *mode, bool pretty)
error_report_err(local_err); error_report_err(local_err);
exit(1); exit(1);
} }
qemu_opt_set(opts, "mode", mode); qemu_opt_set(opts, "mode", mode, &error_abort);
qemu_opt_set(opts, "chardev", label); qemu_opt_set(opts, "chardev", label, &error_abort);
qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
if (def) if (def)
qemu_opt_set(opts, "default", "on"); qemu_opt_set(opts, "default", "on", &error_abort);
monitor_device_index++; monitor_device_index++;
} }
@ -2336,13 +2336,13 @@ static int virtcon_parse(const char *devname)
bus_opts = qemu_opts_create(device, NULL, 0, &error_abort); bus_opts = qemu_opts_create(device, NULL, 0, &error_abort);
if (arch_type == QEMU_ARCH_S390X) { if (arch_type == QEMU_ARCH_S390X) {
qemu_opt_set(bus_opts, "driver", "virtio-serial-s390"); qemu_opt_set(bus_opts, "driver", "virtio-serial-s390", &error_abort);
} else { } else {
qemu_opt_set(bus_opts, "driver", "virtio-serial-pci"); qemu_opt_set(bus_opts, "driver", "virtio-serial-pci", &error_abort);
} }
dev_opts = qemu_opts_create(device, NULL, 0, &error_abort); dev_opts = qemu_opts_create(device, NULL, 0, &error_abort);
qemu_opt_set(dev_opts, "driver", "virtconsole"); qemu_opt_set(dev_opts, "driver", "virtconsole", &error_abort);
snprintf(label, sizeof(label), "virtcon%d", index); snprintf(label, sizeof(label), "virtcon%d", index);
virtcon_hds[index] = qemu_chr_new(label, devname, NULL); virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
@ -2351,7 +2351,7 @@ static int virtcon_parse(const char *devname)
" to character backend '%s'\n", devname); " to character backend '%s'\n", devname);
return -1; return -1;
} }
qemu_opt_set(dev_opts, "chardev", label); qemu_opt_set(dev_opts, "chardev", label, &error_abort);
index++; index++;
return 0; return 0;
@ -2375,7 +2375,7 @@ static int sclp_parse(const char *devname)
assert(arch_type == QEMU_ARCH_S390X); assert(arch_type == QEMU_ARCH_S390X);
dev_opts = qemu_opts_create(device, NULL, 0, NULL); dev_opts = qemu_opts_create(device, NULL, 0, NULL);
qemu_opt_set(dev_opts, "driver", "sclpconsole"); qemu_opt_set(dev_opts, "driver", "sclpconsole", &error_abort);
snprintf(label, sizeof(label), "sclpcon%d", index); snprintf(label, sizeof(label), "sclpcon%d", index);
sclp_hds[index] = qemu_chr_new(label, devname, NULL); sclp_hds[index] = qemu_chr_new(label, devname, NULL);
@ -2384,7 +2384,7 @@ static int sclp_parse(const char *devname)
" to character backend '%s'\n", devname); " to character backend '%s'\n", devname);
return -1; return -1;
} }
qemu_opt_set(dev_opts, "chardev", label); qemu_opt_set(dev_opts, "chardev", label, &error_abort);
index++; index++;
return 0; return 0;
@ -2402,8 +2402,8 @@ static int debugcon_parse(const char *devname)
fprintf(stderr, "qemu: already have a debugcon device\n"); fprintf(stderr, "qemu: already have a debugcon device\n");
exit(1); exit(1);
} }
qemu_opt_set(opts, "driver", "isa-debugcon"); qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort);
qemu_opt_set(opts, "chardev", "debugcon"); qemu_opt_set(opts, "chardev", "debugcon", &error_abort);
return 0; return 0;
} }
@ -2973,19 +2973,23 @@ int main(int argc, char **argv, char **envp)
if (hda_opts != NULL) { if (hda_opts != NULL) {
char num[16]; char num[16];
snprintf(num, sizeof(num), "%d", cyls); snprintf(num, sizeof(num), "%d", cyls);
qemu_opt_set(hda_opts, "cyls", num); qemu_opt_set(hda_opts, "cyls", num, &error_abort);
snprintf(num, sizeof(num), "%d", heads); snprintf(num, sizeof(num), "%d", heads);
qemu_opt_set(hda_opts, "heads", num); qemu_opt_set(hda_opts, "heads", num, &error_abort);
snprintf(num, sizeof(num), "%d", secs); snprintf(num, sizeof(num), "%d", secs);
qemu_opt_set(hda_opts, "secs", num); qemu_opt_set(hda_opts, "secs", num, &error_abort);
if (translation == BIOS_ATA_TRANSLATION_LARGE) { if (translation == BIOS_ATA_TRANSLATION_LARGE) {
qemu_opt_set(hda_opts, "trans", "large"); qemu_opt_set(hda_opts, "trans", "large",
&error_abort);
} else if (translation == BIOS_ATA_TRANSLATION_RECHS) { } else if (translation == BIOS_ATA_TRANSLATION_RECHS) {
qemu_opt_set(hda_opts, "trans", "rechs"); qemu_opt_set(hda_opts, "trans", "rechs",
&error_abort);
} else if (translation == BIOS_ATA_TRANSLATION_LBA) { } else if (translation == BIOS_ATA_TRANSLATION_LBA) {
qemu_opt_set(hda_opts, "trans", "lba"); qemu_opt_set(hda_opts, "trans", "lba",
&error_abort);
} else if (translation == BIOS_ATA_TRANSLATION_NONE) { } else if (translation == BIOS_ATA_TRANSLATION_NONE) {
qemu_opt_set(hda_opts, "trans", "none"); qemu_opt_set(hda_opts, "trans", "none",
&error_abort);
} }
} }
} }
@ -3271,24 +3275,27 @@ int main(int argc, char **argv, char **envp)
writeout = qemu_opt_get(opts, "writeout"); writeout = qemu_opt_get(opts, "writeout");
if (writeout) { if (writeout) {
#ifdef CONFIG_SYNC_FILE_RANGE #ifdef CONFIG_SYNC_FILE_RANGE
qemu_opt_set(fsdev, "writeout", writeout); qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
#else #else
fprintf(stderr, "writeout=immediate not supported on " fprintf(stderr, "writeout=immediate not supported on "
"this platform\n"); "this platform\n");
exit(1); exit(1);
#endif #endif
} }
qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver")); qemu_opt_set(fsdev, "fsdriver",
qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path")); qemu_opt_get(opts, "fsdriver"), &error_abort);
qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"),
&error_abort);
qemu_opt_set(fsdev, "security_model", qemu_opt_set(fsdev, "security_model",
qemu_opt_get(opts, "security_model")); qemu_opt_get(opts, "security_model"),
&error_abort);
socket = qemu_opt_get(opts, "socket"); socket = qemu_opt_get(opts, "socket");
if (socket) { if (socket) {
qemu_opt_set(fsdev, "socket", socket); qemu_opt_set(fsdev, "socket", socket, &error_abort);
} }
sock_fd = qemu_opt_get(opts, "sock_fd"); sock_fd = qemu_opt_get(opts, "sock_fd");
if (sock_fd) { if (sock_fd) {
qemu_opt_set(fsdev, "sock_fd", sock_fd); qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
} }
qemu_opt_set_bool(fsdev, "readonly", qemu_opt_set_bool(fsdev, "readonly",
@ -3296,11 +3303,11 @@ int main(int argc, char **argv, char **envp)
&error_abort); &error_abort);
device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
&error_abort); &error_abort);
qemu_opt_set(device, "driver", "virtio-9p-pci"); qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
qemu_opt_set(device, "fsdev", qemu_opt_set(device, "fsdev",
qemu_opt_get(opts, "mount_tag")); qemu_opt_get(opts, "mount_tag"), &error_abort);
qemu_opt_set(device, "mount_tag", qemu_opt_set(device, "mount_tag",
qemu_opt_get(opts, "mount_tag")); qemu_opt_get(opts, "mount_tag"), &error_abort);
break; break;
} }
case QEMU_OPTION_virtfs_synth: { case QEMU_OPTION_virtfs_synth: {
@ -3313,13 +3320,13 @@ int main(int argc, char **argv, char **envp)
fprintf(stderr, "duplicate option: %s\n", "virtfs_synth"); fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
exit(1); exit(1);
} }
qemu_opt_set(fsdev, "fsdriver", "synth"); qemu_opt_set(fsdev, "fsdriver", "synth", &error_abort);
device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
&error_abort); &error_abort);
qemu_opt_set(device, "driver", "virtio-9p-pci"); qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
qemu_opt_set(device, "fsdev", "v_synth"); qemu_opt_set(device, "fsdev", "v_synth", &error_abort);
qemu_opt_set(device, "mount_tag", "v_synth"); qemu_opt_set(device, "mount_tag", "v_synth", &error_abort);
break; break;
} }
case QEMU_OPTION_serial: case QEMU_OPTION_serial: