Skip to content

Commit

Permalink
qobject: Use simpler QDict/QList scalar insertion macros
Browse files Browse the repository at this point in the history
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>
(cherry picked from commit 46f5ac2)
* prereq for fc0932f
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
ebblake authored and mdroth committed Jul 31, 2017
1 parent 1eaf431 commit e59084b
Show file tree
Hide file tree
Showing 33 changed files with 241 additions and 265 deletions.
45 changes: 19 additions & 26 deletions block.c
Expand Up @@ -937,16 +937,14 @@ static void update_flags_from_options(int *flags, QemuOpts *opts)
static void update_options_from_flags(QDict *options, int flags)
{
if (!qdict_haskey(options, BDRV_OPT_CACHE_DIRECT)) {
qdict_put(options, BDRV_OPT_CACHE_DIRECT,
qbool_from_bool(flags & BDRV_O_NOCACHE));
qdict_put_bool(options, BDRV_OPT_CACHE_DIRECT, flags & BDRV_O_NOCACHE);
}
if (!qdict_haskey(options, BDRV_OPT_CACHE_NO_FLUSH)) {
qdict_put(options, BDRV_OPT_CACHE_NO_FLUSH,
qbool_from_bool(flags & BDRV_O_NO_FLUSH));
qdict_put_bool(options, BDRV_OPT_CACHE_NO_FLUSH,
flags & BDRV_O_NO_FLUSH);
}
if (!qdict_haskey(options, BDRV_OPT_READ_ONLY)) {
qdict_put(options, BDRV_OPT_READ_ONLY,
qbool_from_bool(!(flags & BDRV_O_RDWR)));
qdict_put_bool(options, BDRV_OPT_READ_ONLY, !(flags & BDRV_O_RDWR));
}
}

Expand Down Expand Up @@ -1362,7 +1360,7 @@ static int bdrv_fill_options(QDict **options, const char *filename,
/* Fetch the file name from the options QDict if necessary */
if (protocol && filename) {
if (!qdict_haskey(*options, "filename")) {
qdict_put(*options, "filename", qstring_from_str(filename));
qdict_put_str(*options, "filename", filename);
parse_filename = true;
} else {
error_setg(errp, "Can't specify 'file' and 'filename' options at "
Expand All @@ -1383,7 +1381,7 @@ static int bdrv_fill_options(QDict **options, const char *filename,
}

drvname = drv->format_name;
qdict_put(*options, "driver", qstring_from_str(drvname));
qdict_put_str(*options, "driver", drvname);
} else {
error_setg(errp, "Must specify either driver or file");
return -EINVAL;
Expand Down Expand Up @@ -2038,7 +2036,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
}

if (bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
qdict_put(options, "driver", qstring_from_str(bs->backing_format));
qdict_put_str(options, "driver", bs->backing_format);
}

backing_hd = bdrv_open_inherit(*backing_filename ? backing_filename : NULL,
Expand Down Expand Up @@ -2193,12 +2191,9 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
}

/* Prepare options QDict for the temporary file */
qdict_put(snapshot_options, "file.driver",
qstring_from_str("file"));
qdict_put(snapshot_options, "file.filename",
qstring_from_str(tmp_filename));
qdict_put(snapshot_options, "driver",
qstring_from_str("qcow2"));
qdict_put_str(snapshot_options, "file.driver", "file");
qdict_put_str(snapshot_options, "file.filename", tmp_filename);
qdict_put_str(snapshot_options, "driver", "qcow2");

bs_snapshot = bdrv_open(NULL, NULL, snapshot_options, flags, errp);
snapshot_options = NULL;
Expand Down Expand Up @@ -2373,8 +2368,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
goto fail;
}

qdict_put(options, "file",
qstring_from_str(bdrv_get_node_name(file_bs)));
qdict_put_str(options, "file", bdrv_get_node_name(file_bs));
}
}

Expand All @@ -2396,8 +2390,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
* sure to update both bs->options (which has the full effective
* options for bs) and options (which has file.* already removed).
*/
qdict_put(bs->options, "driver", qstring_from_str(drv->format_name));
qdict_put(options, "driver", qstring_from_str(drv->format_name));
qdict_put_str(bs->options, "driver", drv->format_name);
qdict_put_str(options, "driver", drv->format_name);
} else if (!drv) {
error_setg(errp, "Must specify either driver or file");
goto fail;
Expand Down Expand Up @@ -2772,12 +2766,12 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
* that they are checked at the end of this function. */
value = qemu_opt_get(opts, "node-name");
if (value) {
qdict_put(reopen_state->options, "node-name", qstring_from_str(value));
qdict_put_str(reopen_state->options, "node-name", value);
}

value = qemu_opt_get(opts, "driver");
if (value) {
qdict_put(reopen_state->options, "driver", qstring_from_str(value));
qdict_put_str(reopen_state->options, "driver", value);
}

/* if we are to stay read-only, do not allow permission change
Expand Down Expand Up @@ -4268,8 +4262,7 @@ void bdrv_img_create(const char *filename, const char *fmt,

if (backing_fmt) {
backing_options = qdict_new();
qdict_put(backing_options, "driver",
qstring_from_str(backing_fmt));
qdict_put_str(backing_options, "driver", backing_fmt);
}

bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
Expand Down Expand Up @@ -4674,7 +4667,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
* contain a representation of the filename, therefore the following
* suffices without querying the (exact_)filename of this BDS. */
if (bs->file->bs->full_open_options) {
qdict_put(opts, "driver", qstring_from_str(drv->format_name));
qdict_put_str(opts, "driver", drv->format_name);
QINCREF(bs->file->bs->full_open_options);
qdict_put(opts, "file", bs->file->bs->full_open_options);

Expand All @@ -4692,7 +4685,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)

opts = qdict_new();
append_open_options(opts, bs);
qdict_put(opts, "driver", qstring_from_str(drv->format_name));
qdict_put_str(opts, "driver", drv->format_name);

if (bs->exact_filename[0]) {
/* This may not work for all block protocol drivers (some may
Expand All @@ -4702,7 +4695,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
* needs some special format of the options QDict, it needs to
* implement the driver-specific bdrv_refresh_filename() function.
*/
qdict_put(opts, "filename", qstring_from_str(bs->exact_filename));
qdict_put_str(opts, "filename", bs->exact_filename);
}

bs->full_open_options = opts;
Expand Down
6 changes: 3 additions & 3 deletions block/blkdebug.c
Expand Up @@ -301,7 +301,7 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,
if (!strstart(filename, "blkdebug:", &filename)) {
/* There was no prefix; therefore, all options have to be already
present in the QDict (except for the filename) */
qdict_put(options, "x-image", qstring_from_str(filename));
qdict_put_str(options, "x-image", filename);
return;
}

Expand All @@ -320,7 +320,7 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,

/* TODO Allow multi-level nesting and set file.filename here */
filename = c + 1;
qdict_put(options, "x-image", qstring_from_str(filename));
qdict_put_str(options, "x-image", filename);
}

static QemuOptsList runtime_opts = {
Expand Down Expand Up @@ -693,7 +693,7 @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
}

opts = qdict_new();
qdict_put(opts, "driver", qstring_from_str("blkdebug"));
qdict_put_str(opts, "driver", "blkdebug");

QINCREF(bs->file->bs->full_open_options);
qdict_put(opts, "image", bs->file->bs->full_open_options);
Expand Down
6 changes: 3 additions & 3 deletions block/blkverify.c
Expand Up @@ -67,7 +67,7 @@ static void blkverify_parse_filename(const char *filename, QDict *options,
if (!strstart(filename, "blkverify:", &filename)) {
/* There was no prefix; therefore, all options have to be already
present in the QDict (except for the filename) */
qdict_put(options, "x-image", qstring_from_str(filename));
qdict_put_str(options, "x-image", filename);
return;
}

Expand All @@ -84,7 +84,7 @@ static void blkverify_parse_filename(const char *filename, QDict *options,

/* TODO Allow multi-level nesting and set file.filename here */
filename = c + 1;
qdict_put(options, "x-image", qstring_from_str(filename));
qdict_put_str(options, "x-image", filename);
}

static QemuOptsList runtime_opts = {
Expand Down Expand Up @@ -288,7 +288,7 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options)
&& s->test_file->bs->full_open_options)
{
QDict *opts = qdict_new();
qdict_put(opts, "driver", qstring_from_str("blkverify"));
qdict_put_str(opts, "driver", "blkverify");

QINCREF(bs->file->bs->full_open_options);
qdict_put(opts, "raw", bs->file->bs->full_open_options);
Expand Down
2 changes: 1 addition & 1 deletion block/curl.c
Expand Up @@ -548,7 +548,7 @@ static void curl_clean_state(CURLState *s)
static void curl_parse_filename(const char *filename, QDict *options,
Error **errp)
{
qdict_put(options, CURL_BLOCK_OPT_URL, qstring_from_str(filename));
qdict_put_str(options, CURL_BLOCK_OPT_URL, filename);
}

static void curl_detach_aio_context(BlockDriverState *bs)
Expand Down
8 changes: 4 additions & 4 deletions block/file-posix.c
Expand Up @@ -377,7 +377,7 @@ static void raw_parse_filename(const char *filename, QDict *options,
* function call can be ignored. */
strstart(filename, "file:", &filename);

qdict_put(options, "filename", qstring_from_str(filename));
qdict_put_str(options, "filename", filename);
}

static QemuOptsList raw_runtime_opts = {
Expand Down Expand Up @@ -2150,7 +2150,7 @@ static void hdev_parse_filename(const char *filename, QDict *options,
/* The prefix is optional, just as for "file". */
strstart(filename, "host_device:", &filename);

qdict_put(options, "filename", qstring_from_str(filename));
qdict_put_str(options, "filename", filename);
}

static bool hdev_is_sg(BlockDriverState *bs)
Expand Down Expand Up @@ -2239,7 +2239,7 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
goto hdev_open_Mac_error;
}

qdict_put(options, "filename", qstring_from_str(bsd_path));
qdict_put_str(options, "filename", bsd_path);

hdev_open_Mac_error:
g_free(mediaType);
Expand Down Expand Up @@ -2449,7 +2449,7 @@ static void cdrom_parse_filename(const char *filename, QDict *options,
/* The prefix is optional, just as for "file". */
strstart(filename, "host_cdrom:", &filename);

qdict_put(options, "filename", qstring_from_str(filename));
qdict_put_str(options, "filename", filename);
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions block/file-win32.c
Expand Up @@ -282,7 +282,7 @@ static void raw_parse_filename(const char *filename, QDict *options,
* function call can be ignored. */
strstart(filename, "file:", &filename);

qdict_put(options, "filename", qstring_from_str(filename));
qdict_put_str(options, "filename", filename);
}

static QemuOptsList raw_runtime_opts = {
Expand Down Expand Up @@ -669,7 +669,7 @@ static void hdev_parse_filename(const char *filename, QDict *options,
/* The prefix is optional, just as for "file". */
strstart(filename, "host_device:", &filename);

qdict_put(options, "filename", qstring_from_str(filename));
qdict_put_str(options, "filename", filename);
}

static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
Expand Down
41 changes: 20 additions & 21 deletions block/nbd.c
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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:... */
Expand All @@ -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;

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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);
Expand Down

0 comments on commit e59084b

Please sign in to comment.