Skip to content

Commit

Permalink
use qemu_opts_create_nofail
Browse files Browse the repository at this point in the history
We will use qemu_opts_create_nofail function, it can make code
more readable.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
pickick authored and kevmw committed Dec 11, 2012
1 parent dd39244 commit e478b44
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion blockdev.c
Expand Up @@ -568,7 +568,7 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
break;
case IF_VIRTIO:
/* add virtio block device */
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL);
opts = qemu_opts_create_nofail(qemu_find_opts("device"));
if (arch_type == QEMU_ARCH_S390X) {
qemu_opt_set(opts, "driver", "virtio-blk-s390");
} else {
Expand Down
2 changes: 1 addition & 1 deletion hw/watchdog.c
Expand Up @@ -66,7 +66,7 @@ int select_watchdog(const char *p)
QLIST_FOREACH(model, &watchdog_list, entry) {
if (strcasecmp(model->wdt_name, p) == 0) {
/* add the device */
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL);
opts = qemu_opts_create_nofail(qemu_find_opts("device"));
qemu_opt_set(opts, "driver", p);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions qemu-config.c
Expand Up @@ -756,7 +756,7 @@ int qemu_global_option(const char *str)
return -1;
}

opts = qemu_opts_create(&qemu_global_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&qemu_global_opts);
qemu_opt_set(opts, "driver", driver);
qemu_opt_set(opts, "property", property);
qemu_opt_set(opts, "value", str+offset+1);
Expand Down Expand Up @@ -843,7 +843,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
error_free(local_err);
goto out;
}
opts = qemu_opts_create(list, NULL, 0, NULL);
opts = qemu_opts_create_nofail(list);
continue;
}
if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
Expand Down
2 changes: 1 addition & 1 deletion qemu-img.c
Expand Up @@ -1934,7 +1934,7 @@ static int img_resize(int argc, char **argv)
}

/* Parse size */
param = qemu_opts_create(&resize_options, NULL, 0, NULL);
param = qemu_opts_create_nofail(&resize_options);
if (qemu_opt_set(param, BLOCK_OPT_SIZE, size)) {
/* Error message already printed when size parsing fails */
ret = -1;
Expand Down
16 changes: 8 additions & 8 deletions qemu-sockets.c
Expand Up @@ -579,7 +579,7 @@ int inet_listen(const char *str, char *ostr, int olen,

addr = inet_parse(str, errp);
if (addr != NULL) {
opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&dummy_opts);
inet_addr_to_opts(opts, addr);
qapi_free_InetSocketAddress(addr);
sock = inet_listen_opts(opts, port_offset, errp);
Expand Down Expand Up @@ -618,7 +618,7 @@ int inet_connect(const char *str, Error **errp)

addr = inet_parse(str, errp);
if (addr != NULL) {
opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&dummy_opts);
inet_addr_to_opts(opts, addr);
qapi_free_InetSocketAddress(addr);
sock = inet_connect_opts(opts, errp, NULL, NULL);
Expand Down Expand Up @@ -652,7 +652,7 @@ int inet_nonblocking_connect(const char *str,

addr = inet_parse(str, errp);
if (addr != NULL) {
opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&dummy_opts);
inet_addr_to_opts(opts, addr);
qapi_free_InetSocketAddress(addr);
sock = inet_connect_opts(opts, errp, callback, opaque);
Expand Down Expand Up @@ -795,7 +795,7 @@ int unix_listen(const char *str, char *ostr, int olen, Error **errp)
char *path, *optstr;
int sock, len;

opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&dummy_opts);

optstr = strchr(str, ',');
if (optstr) {
Expand Down Expand Up @@ -823,7 +823,7 @@ int unix_connect(const char *path, Error **errp)
QemuOpts *opts;
int sock;

opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&dummy_opts);
qemu_opt_set(opts, "path", path);
sock = unix_connect_opts(opts, errp, NULL, NULL);
qemu_opts_del(opts);
Expand All @@ -840,7 +840,7 @@ int unix_nonblocking_connect(const char *path,

g_assert(callback != NULL);

opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&dummy_opts);
qemu_opt_set(opts, "path", path);
sock = unix_connect_opts(opts, errp, callback, opaque);
qemu_opts_del(opts);
Expand Down Expand Up @@ -891,7 +891,7 @@ int socket_connect(SocketAddress *addr, Error **errp,
QemuOpts *opts;
int fd;

opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&dummy_opts);
switch (addr->kind) {
case SOCKET_ADDRESS_KIND_INET:
inet_addr_to_opts(opts, addr->inet);
Expand Down Expand Up @@ -922,7 +922,7 @@ int socket_listen(SocketAddress *addr, Error **errp)
QemuOpts *opts;
int fd;

opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
opts = qemu_opts_create_nofail(&dummy_opts);
switch (addr->kind) {
case SOCKET_ADDRESS_KIND_INET:
inet_addr_to_opts(opts, addr->inet);
Expand Down
12 changes: 5 additions & 7 deletions vl.c
Expand Up @@ -1996,7 +1996,7 @@ static int balloon_parse(const char *arg)
return -1;
} else {
/* create empty opts */
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL);
opts = qemu_opts_create_nofail(qemu_find_opts("device"));
}
qemu_opt_set(opts, "driver", "virtio-balloon");
return 0;
Expand Down Expand Up @@ -2246,14 +2246,14 @@ static int virtcon_parse(const char *devname)
exit(1);
}

bus_opts = qemu_opts_create(device, NULL, 0, NULL);
bus_opts = qemu_opts_create_nofail(device);
if (arch_type == QEMU_ARCH_S390X) {
qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
} else {
qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
}

dev_opts = qemu_opts_create(device, NULL, 0, NULL);
dev_opts = qemu_opts_create_nofail(device);
qemu_opt_set(dev_opts, "driver", "virtconsole");

snprintf(label, sizeof(label), "virtcon%d", index);
Expand Down Expand Up @@ -3105,8 +3105,7 @@ int main(int argc, char **argv, char **envp)

qemu_opt_set_bool(fsdev, "readonly",
qemu_opt_get_bool(opts, "readonly", 0));
device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
NULL);
device = qemu_opts_create_nofail(qemu_find_opts("device"));
qemu_opt_set(device, "driver", "virtio-9p-pci");
qemu_opt_set(device, "fsdev",
qemu_opt_get(opts, "mount_tag"));
Expand All @@ -3126,8 +3125,7 @@ int main(int argc, char **argv, char **envp)
}
qemu_opt_set(fsdev, "fsdriver", "synth");

device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
NULL);
device = qemu_opts_create_nofail(qemu_find_opts("device"));
qemu_opt_set(device, "driver", "virtio-9p-pci");
qemu_opt_set(device, "fsdev", "v_synth");
qemu_opt_set(device, "mount_tag", "v_synth");
Expand Down

0 comments on commit e478b44

Please sign in to comment.