summaryrefslogtreecommitdiff
path: root/block/nbd.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-04-27 16:58:17 -0500
committerMarkus Armbruster <armbru@redhat.com>2017-05-09 09:13:51 +0200
commit46f5ac205a9dc5e2c24274c7df371509a286281f (patch)
tree52cd3eab32f34963a5275f6f291386d4ad8b6624 /block/nbd.c
parenta92c21591b5bb9543996538f14854ca6b528318b (diff)
downloadqemu-46f5ac205a9dc5e2c24274c7df371509a286281f.zip
qobject: Use simpler QDict/QList scalar insertion macros
We now have macros in place to make it less verbose to add a scalar to QDict and QList, so use them. Patch created mechanically via: spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir . --in-place then touched up manually to fix a couple of '?:' back to original spacing, as well as avoiding a long line in monitor.c. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20170427215821.19397-7-eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'block/nbd.c')
-rw-r--r--block/nbd.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/block/nbd.c b/block/nbd.c
index 814ab26dce..b3545f5709 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -79,7 +79,7 @@ static int nbd_parse_uri(const char *filename, QDict *options)
p = uri->path ? uri->path : "/";
p += strspn(p, "/");
if (p[0]) {
- qdict_put(options, "export", qstring_from_str(p));
+ qdict_put_str(options, "export", p);
}
qp = query_params_parse(uri->query);
@@ -94,9 +94,8 @@ static int nbd_parse_uri(const char *filename, QDict *options)
ret = -EINVAL;
goto out;
}
- qdict_put(options, "server.type", qstring_from_str("unix"));
- qdict_put(options, "server.path",
- qstring_from_str(qp->p[0].value));
+ qdict_put_str(options, "server.type", "unix");
+ qdict_put_str(options, "server.path", qp->p[0].value);
} else {
QString *host;
char *port_str;
@@ -115,11 +114,11 @@ static int nbd_parse_uri(const char *filename, QDict *options)
host = qstring_from_str(uri->server);
}
- qdict_put(options, "server.type", qstring_from_str("inet"));
+ qdict_put_str(options, "server.type", "inet");
qdict_put(options, "server.host", host);
port_str = g_strdup_printf("%d", uri->port ?: NBD_DEFAULT_PORT);
- qdict_put(options, "server.port", qstring_from_str(port_str));
+ qdict_put_str(options, "server.port", port_str);
g_free(port_str);
}
@@ -181,7 +180,7 @@ static void nbd_parse_filename(const char *filename, QDict *options,
export_name[0] = 0; /* truncate 'file' */
export_name += strlen(EN_OPTSTR);
- qdict_put(options, "export", qstring_from_str(export_name));
+ qdict_put_str(options, "export", export_name);
}
/* extract the host_spec - fail if it's not nbd:... */
@@ -196,8 +195,8 @@ static void nbd_parse_filename(const char *filename, QDict *options,
/* are we a UNIX or TCP socket? */
if (strstart(host_spec, "unix:", &unixpath)) {
- qdict_put(options, "server.type", qstring_from_str("unix"));
- qdict_put(options, "server.path", qstring_from_str(unixpath));
+ qdict_put_str(options, "server.type", "unix");
+ qdict_put_str(options, "server.path", unixpath);
} else {
InetSocketAddress *addr = NULL;
@@ -206,9 +205,9 @@ static void nbd_parse_filename(const char *filename, QDict *options,
goto out;
}
- qdict_put(options, "server.type", qstring_from_str("inet"));
- qdict_put(options, "server.host", qstring_from_str(addr->host));
- qdict_put(options, "server.port", qstring_from_str(addr->port));
+ qdict_put_str(options, "server.type", "inet");
+ qdict_put_str(options, "server.host", addr->host);
+ qdict_put_str(options, "server.port", addr->port);
qapi_free_InetSocketAddress(addr);
}
@@ -247,13 +246,13 @@ static bool nbd_process_legacy_socket_options(QDict *output_options,
return false;
}
- qdict_put(output_options, "server.type", qstring_from_str("unix"));
- qdict_put(output_options, "server.path", qstring_from_str(path));
+ qdict_put_str(output_options, "server.type", "unix");
+ qdict_put_str(output_options, "server.path", path);
} else if (host) {
- qdict_put(output_options, "server.type", qstring_from_str("inet"));
- qdict_put(output_options, "server.host", qstring_from_str(host));
- qdict_put(output_options, "server.port",
- qstring_from_str(port ?: stringify(NBD_DEFAULT_PORT)));
+ qdict_put_str(output_options, "server.type", "inet");
+ qdict_put_str(output_options, "server.host", host);
+ qdict_put_str(output_options, "server.port",
+ port ?: stringify(NBD_DEFAULT_PORT));
}
return true;
@@ -528,7 +527,7 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
path = s->saddr->u.q_unix.path;
} /* else can't represent as pseudo-filename */
- qdict_put(opts, "driver", qstring_from_str("nbd"));
+ qdict_put_str(opts, "driver", "nbd");
if (path && s->export) {
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
@@ -551,10 +550,10 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
qdict_put_obj(opts, "server", saddr_qdict);
if (s->export) {
- qdict_put(opts, "export", qstring_from_str(s->export));
+ qdict_put_str(opts, "export", s->export);
}
if (s->tlscredsid) {
- qdict_put(opts, "tls-creds", qstring_from_str(s->tlscredsid));
+ qdict_put_str(opts, "tls-creds", s->tlscredsid);
}
qdict_flatten(opts);