From cccb7967bdf19f9d31e65d2d07d4d311e07545c4 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 16:37:44 +0100 Subject: QemuOpts: Convert qemu_opt_set_bool() to Error, fix its use Return the Error object instead of reporting it with qerror_report_err(). Change callers that assume the function can't fail to pass &error_abort, so that should the assumption ever break, it'll break noisily. Turns out all callers outside its unit test assume that. We could drop the Error ** argument, but that would make the interface less regular, so don't. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- vl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index e1ffd0a..27e738a 100644 --- a/vl.c +++ b/vl.c @@ -2222,7 +2222,7 @@ static void monitor_parse(const char *optarg, const char *mode, bool pretty) } qemu_opt_set(opts, "mode", mode); qemu_opt_set(opts, "chardev", label); - qemu_opt_set_bool(opts, "pretty", pretty); + qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); if (def) qemu_opt_set(opts, "default", "on"); monitor_device_index++; @@ -3287,7 +3287,8 @@ int main(int argc, char **argv, char **envp) } qemu_opt_set_bool(fsdev, "readonly", - qemu_opt_get_bool(opts, "readonly", 0)); + qemu_opt_get_bool(opts, "readonly", 0), + &error_abort); device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, &error_abort); qemu_opt_set(device, "driver", "virtio-9p-pci"); -- cgit v1.1 From 39101f2511f6adf1ae4380f8d729dba1213b9d7a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 16:46:36 +0100 Subject: QemuOpts: Convert qemu_opt_set_number() to Error, fix its use Return the Error object instead of reporting it with qerror_report_err(). Change callers that assume the function can't fail to pass &error_abort, so that should the assumption ever break, it'll break noisily. Turns out all callers outside its unit test assume that. We could drop the Error ** argument, but that would make the interface less regular, so don't. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index 27e738a..8ea8b08 100644 --- a/vl.c +++ b/vl.c @@ -2684,7 +2684,7 @@ static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size) } /* store value for the future use */ - qemu_opt_set_number(opts, "size", ram_size); + qemu_opt_set_number(opts, "size", ram_size, &error_abort); *maxram_size = ram_size; maxmem_str = qemu_opt_get(opts, "maxmem"); -- cgit v1.1 From 79087c782e1549a6f9c8303aafc0b74f4e637756 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 17:07:34 +0100 Subject: QemuOpts: Convert qemu_opts_set() to Error, fix its use Return the Error object instead of reporting it with qerror_report_err(). Change callers that assume the function can't fail to pass &error_abort, so that should the assumption ever break, it'll break noisily. Turns out all callers outside its unit test assume that. We could drop the Error ** argument, but that would make the interface less regular, so don't. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- vl.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index 8ea8b08..80e2be0 100644 --- a/vl.c +++ b/vl.c @@ -3023,16 +3023,20 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_kernel: - qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg); + qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg, + &error_abort); break; case QEMU_OPTION_initrd: - qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg); + qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg, + &error_abort); break; case QEMU_OPTION_append: - qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg); + qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg, + &error_abort); break; case QEMU_OPTION_dtb: - qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg); + qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg, + &error_abort); break; case QEMU_OPTION_cdrom: drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); @@ -3136,7 +3140,8 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_bios: - qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg); + qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg, + &error_abort); break; case QEMU_OPTION_singlestep: singlestep = 1; -- cgit v1.1 From f43e47dbf6de24db20ec9b588bb6cc762093dd69 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 17:52:20 +0100 Subject: 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 Reviewed-by: Eric Blake --- vl.c | 73 +++++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 33 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index 80e2be0..66b0ad8 100644 --- a/vl.c +++ b/vl.c @@ -1096,7 +1096,7 @@ static int drive_init_func(QemuOpts *opts, void *opaque) static int drive_enable_snapshot(QemuOpts *opts, void *opaque) { if (qemu_opt_get(opts, "snapshot") == NULL) { - qemu_opt_set(opts, "snapshot", "on"); + qemu_opt_set(opts, "snapshot", "on", &error_abort); } return 0; } @@ -2074,7 +2074,7 @@ static int balloon_parse(const char *arg) opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, &error_abort); } - qemu_opt_set(opts, "driver", "virtio-balloon"); + qemu_opt_set(opts, "driver", "virtio-balloon", &error_abort); return 0; } @@ -2220,11 +2220,11 @@ static void monitor_parse(const char *optarg, const char *mode, bool pretty) error_report_err(local_err); exit(1); } - qemu_opt_set(opts, "mode", mode); - qemu_opt_set(opts, "chardev", label); + qemu_opt_set(opts, "mode", mode, &error_abort); + qemu_opt_set(opts, "chardev", label, &error_abort); qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); if (def) - qemu_opt_set(opts, "default", "on"); + qemu_opt_set(opts, "default", "on", &error_abort); monitor_device_index++; } @@ -2336,13 +2336,13 @@ static int virtcon_parse(const char *devname) bus_opts = qemu_opts_create(device, NULL, 0, &error_abort); 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 { - 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); - qemu_opt_set(dev_opts, "driver", "virtconsole"); + qemu_opt_set(dev_opts, "driver", "virtconsole", &error_abort); snprintf(label, sizeof(label), "virtcon%d", index); 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); return -1; } - qemu_opt_set(dev_opts, "chardev", label); + qemu_opt_set(dev_opts, "chardev", label, &error_abort); index++; return 0; @@ -2375,7 +2375,7 @@ static int sclp_parse(const char *devname) assert(arch_type == QEMU_ARCH_S390X); 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); 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); return -1; } - qemu_opt_set(dev_opts, "chardev", label); + qemu_opt_set(dev_opts, "chardev", label, &error_abort); index++; return 0; @@ -2402,8 +2402,8 @@ static int debugcon_parse(const char *devname) fprintf(stderr, "qemu: already have a debugcon device\n"); exit(1); } - qemu_opt_set(opts, "driver", "isa-debugcon"); - qemu_opt_set(opts, "chardev", "debugcon"); + qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort); + qemu_opt_set(opts, "chardev", "debugcon", &error_abort); return 0; } @@ -2973,19 +2973,23 @@ int main(int argc, char **argv, char **envp) if (hda_opts != NULL) { char num[16]; 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); - qemu_opt_set(hda_opts, "heads", num); + qemu_opt_set(hda_opts, "heads", num, &error_abort); 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) { - qemu_opt_set(hda_opts, "trans", "large"); + qemu_opt_set(hda_opts, "trans", "large", + &error_abort); } 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) { - qemu_opt_set(hda_opts, "trans", "lba"); + qemu_opt_set(hda_opts, "trans", "lba", + &error_abort); } 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"); if (writeout) { #ifdef CONFIG_SYNC_FILE_RANGE - qemu_opt_set(fsdev, "writeout", writeout); + qemu_opt_set(fsdev, "writeout", writeout, &error_abort); #else fprintf(stderr, "writeout=immediate not supported on " "this platform\n"); exit(1); #endif } - qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver")); - qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path")); + qemu_opt_set(fsdev, "fsdriver", + 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_get(opts, "security_model")); + qemu_opt_get(opts, "security_model"), + &error_abort); socket = qemu_opt_get(opts, "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"); 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", @@ -3296,11 +3303,11 @@ int main(int argc, char **argv, char **envp) &error_abort); device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, &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_get(opts, "mount_tag")); + qemu_opt_get(opts, "mount_tag"), &error_abort); qemu_opt_set(device, "mount_tag", - qemu_opt_get(opts, "mount_tag")); + qemu_opt_get(opts, "mount_tag"), &error_abort); break; } 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"); 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, &error_abort); - qemu_opt_set(device, "driver", "virtio-9p-pci"); - qemu_opt_set(device, "fsdev", "v_synth"); - qemu_opt_set(device, "mount_tag", "v_synth"); + qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort); + qemu_opt_set(device, "fsdev", "v_synth", &error_abort); + qemu_opt_set(device, "mount_tag", "v_synth", &error_abort); break; } case QEMU_OPTION_serial: -- cgit v1.1 From a8b18f8fd2d9f0df33c3739e76fedfd9355dfa8b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Feb 2015 15:50:43 +0100 Subject: block: Simplify setting numeric options Don't convert numbers to strings for use with qemu_opt_set(), simply use qemu_opt_set_number() instead. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- vl.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index 66b0ad8..e2c1950 100644 --- a/vl.c +++ b/vl.c @@ -2971,13 +2971,12 @@ int main(int argc, char **argv, char **envp) exit(1); } if (hda_opts != NULL) { - char num[16]; - snprintf(num, sizeof(num), "%d", cyls); - qemu_opt_set(hda_opts, "cyls", num, &error_abort); - snprintf(num, sizeof(num), "%d", heads); - qemu_opt_set(hda_opts, "heads", num, &error_abort); - snprintf(num, sizeof(num), "%d", secs); - qemu_opt_set(hda_opts, "secs", num, &error_abort); + qemu_opt_set_number(hda_opts, "cyls", cyls, + &error_abort); + qemu_opt_set_number(hda_opts, "heads", heads, + &error_abort); + qemu_opt_set_number(hda_opts, "secs", secs, + &error_abort); if (translation == BIOS_ATA_TRANSLATION_LARGE) { qemu_opt_set(hda_opts, "trans", "large", &error_abort); -- cgit v1.1