aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2017-05-09 15:49:08 -0400
committerStefan Hajnoczi <stefanha@redhat.com>2017-05-09 15:49:14 -0400
commit76d20ea0f1b26ebd5da2f5fb2fdf3250cde887bb (patch)
treebcb0e4a8f29bdcfa0f5785a09608bff57a82107c
parent7ed57b66221b5a3e23b3519824637b297dc92090 (diff)
parentdcd3b25d656d346205dc0f2254723fccf0264e45 (diff)
Merge remote-tracking branch 'armbru/tags/pull-qapi-2017-05-04-v3' into staging
QAPI patches for 2017-05-04 # gpg: Signature made Tue 09 May 2017 03:16:12 AM EDT # gpg: using RSA key 0x3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * armbru/tags/pull-qapi-2017-05-04-v3: (28 commits) qmp-shell: improve help qmp-shell: don't show version greeting if unavailable qmp-shell: Cope with query-commands error qmp-shell: add -N option to skip negotiate qmp-shell: add persistent command history qobject-input-visitor: Catch misuse of end_struct vs. end_list qapi: Document intended use of @name within alternate visits qobject-input-visitor: Document full_name_nth() qmp: Improve QMP dispatch error messages sockets: Delete unused helper socket_address_crumple() sockets: Limit SocketAddressLegacy to external interfaces sockets: Rename SocketAddressFlat to SocketAddress sockets: Rename SocketAddress to SocketAddressLegacy qapi: New QAPI_CLONE_MEMBERS() sockets: Prepare inet_parse() for flattened SocketAddress sockets: Prepare vsock_parse() for flattened SocketAddress test-qga: Actually test 0xff sync bytes fdc-test: Avoid deprecated 'change' command QemuOpts: Simplify qemu_opts_to_qdict() block: Simplify bdrv_append_temp_snapshot() logic ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--MAINTAINERS1
-rw-r--r--block.c68
-rw-r--r--block/blkdebug.c8
-rw-r--r--block/blkverify.c11
-rw-r--r--block/curl.c2
-rw-r--r--block/file-posix.c8
-rw-r--r--block/file-win32.c4
-rw-r--r--block/gluster.c48
-rw-r--r--block/nbd.c77
-rw-r--r--block/nfs.c43
-rw-r--r--block/null.c2
-rw-r--r--block/qcow2.c4
-rw-r--r--block/quorum.c16
-rw-r--r--block/rbd.c16
-rw-r--r--block/sheepdog.c20
-rw-r--r--block/snapshot.c2
-rw-r--r--block/ssh.c16
-rw-r--r--block/vvfat.c10
-rw-r--r--block/vxhs.c6
-rw-r--r--blockdev-nbd.c21
-rw-r--r--blockdev.c30
-rw-r--r--chardev/char-socket.c36
-rw-r--r--chardev/char-udp.c20
-rw-r--r--hmp.c3
-rw-r--r--hw/block/xen_disk.c2
-rw-r--r--hw/pci/pcie_aer.c48
-rw-r--r--hw/usb/xen-usb.c12
-rw-r--r--include/block/nbd.h3
-rw-r--r--include/hw/pci/pcie_aer.h4
-rw-r--r--include/io/channel-socket.h4
-rw-r--r--include/qapi/clone-visitor.h14
-rw-r--r--include/qapi/qmp/qdict.h8
-rw-r--r--include/qapi/qmp/qlist.h8
-rw-r--r--include/qapi/visitor.h6
-rw-r--r--include/qemu/sockets.h16
-rw-r--r--io/dns-resolver.c17
-rw-r--r--migration/rdma.c4
-rw-r--r--migration/socket.c20
-rw-r--r--monitor.c23
-rw-r--r--qapi-schema.json35
-rw-r--r--qapi/block-core.json6
-rw-r--r--qapi/block.json2
-rw-r--r--qapi/qapi-clone-visitor.c13
-rw-r--r--qapi/qmp-dispatch.c14
-rw-r--r--qapi/qmp-event.c2
-rw-r--r--qapi/qobject-input-visitor.c32
-rw-r--r--qemu-img.c6
-rw-r--r--qemu-io.c2
-rw-r--r--qemu-nbd.c11
-rw-r--r--qga/main.c4
-rw-r--r--qobject/qdict.c2
-rw-r--r--scripts/coccinelle/qobject.cocci35
-rwxr-xr-xscripts/qmp/qmp-shell44
-rw-r--r--target/s390x/cpu_models.c4
-rw-r--r--tests/check-qdict.c144
-rw-r--r--tests/check-qlist.c4
-rw-r--r--tests/device-introspect-test.c4
-rw-r--r--tests/fdc-test.c8
-rw-r--r--tests/libqtest.c8
-rw-r--r--tests/test-char.c5
-rw-r--r--tests/test-io-channel-socket.c52
-rw-r--r--tests/test-keyval.c4
-rw-r--r--tests/test-qemu-opts.c4
-rw-r--r--tests/test-qga.c41
-rw-r--r--tests/test-qmp-commands.c30
-rw-r--r--tests/test-qmp-event.c30
-rw-r--r--tests/test-qobject-output-visitor.c6
-rw-r--r--ui/vnc-auth-sasl.c5
-rw-r--r--ui/vnc.c68
-rw-r--r--util/qemu-option.c6
-rw-r--r--util/qemu-sockets.c181
71 files changed, 805 insertions, 668 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index f2c17be4ae..8224be0d75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1395,6 +1395,7 @@ S: Supported
F: qobject/
F: include/qapi/qmp/
X: include/qapi/qmp/dispatch.h
+F: scripts/coccinelle/qobject.cocci
F: tests/check-qdict.c
F: tests/check-qfloat.c
F: tests/check-qint.c
diff --git a/block.c b/block.c
index 6c6bb3ec7a..a45b9b5c29 100644
--- a/block.c
+++ b/block.c
@@ -974,16 +974,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));
}
}
@@ -1399,7 +1397,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 "
@@ -1420,7 +1418,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;
@@ -2075,7 +2073,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,
@@ -2197,7 +2195,7 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
char *tmp_filename = g_malloc0(PATH_MAX + 1);
int64_t total_size;
QemuOpts *opts = NULL;
- BlockDriverState *bs_snapshot;
+ BlockDriverState *bs_snapshot = NULL;
Error *local_err = NULL;
int ret;
@@ -2230,38 +2228,32 @@ 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;
if (!bs_snapshot) {
- ret = -EINVAL;
goto out;
}
- /* bdrv_append() consumes a strong reference to bs_snapshot (i.e. it will
- * call bdrv_unref() on it), so in order to be able to return one, we have
- * to increase bs_snapshot's refcount here */
+ /* bdrv_append() consumes a strong reference to bs_snapshot
+ * (i.e. it will call bdrv_unref() on it) even on error, so in
+ * order to be able to return one, we have to increase
+ * bs_snapshot's refcount here */
bdrv_ref(bs_snapshot);
bdrv_append(bs_snapshot, bs, &local_err);
if (local_err) {
error_propagate(errp, local_err);
- ret = -EINVAL;
+ bs_snapshot = NULL;
goto out;
}
- g_free(tmp_filename);
- return bs_snapshot;
-
out:
QDECREF(snapshot_options);
g_free(tmp_filename);
- return NULL;
+ return bs_snapshot;
}
/*
@@ -2410,8 +2402,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));
}
}
@@ -2433,8 +2424,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;
@@ -2810,12 +2801,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
@@ -4306,8 +4297,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,
@@ -4712,11 +4702,9 @@ 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_obj(opts, "driver",
- QOBJECT(qstring_from_str(drv->format_name)));
+ qdict_put_str(opts, "driver", drv->format_name);
QINCREF(bs->file->bs->full_open_options);
- qdict_put_obj(opts, "file",
- QOBJECT(bs->file->bs->full_open_options));
+ qdict_put(opts, "file", bs->file->bs->full_open_options);
bs->full_open_options = opts;
} else {
@@ -4732,8 +4720,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
opts = qdict_new();
append_open_options(opts, bs);
- qdict_put_obj(opts, "driver",
- QOBJECT(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
@@ -4743,8 +4730,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_obj(opts, "filename",
- QOBJECT(qstring_from_str(bs->exact_filename)));
+ qdict_put_str(opts, "filename", bs->exact_filename);
}
bs->full_open_options = opts;
diff --git a/block/blkdebug.c b/block/blkdebug.c
index d2a7561c4c..3c088934db 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -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;
}
@@ -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 = {
@@ -693,10 +693,10 @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
}
opts = qdict_new();
- qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkdebug")));
+ qdict_put_str(opts, "driver", "blkdebug");
QINCREF(bs->file->bs->full_open_options);
- qdict_put_obj(opts, "image", QOBJECT(bs->file->bs->full_open_options));
+ qdict_put(opts, "image", bs->file->bs->full_open_options);
for (e = qdict_first(options); e; e = qdict_next(options, e)) {
if (strcmp(qdict_entry_key(e), "x-image")) {
diff --git a/block/blkverify.c b/block/blkverify.c
index af23281669..6b0a603cf0 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -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;
}
@@ -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 = {
@@ -288,13 +288,12 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options)
&& s->test_file->bs->full_open_options)
{
QDict *opts = qdict_new();
- qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkverify")));
+ qdict_put_str(opts, "driver", "blkverify");
QINCREF(bs->file->bs->full_open_options);
- qdict_put_obj(opts, "raw", QOBJECT(bs->file->bs->full_open_options));
+ qdict_put(opts, "raw", bs->file->bs->full_open_options);
QINCREF(s->test_file->bs->full_open_options);
- qdict_put_obj(opts, "test",
- QOBJECT(s->test_file->bs->full_open_options));
+ qdict_put(opts, "test", s->test_file->bs->full_open_options);
bs->full_open_options = opts;
}
diff --git a/block/curl.c b/block/curl.c
index 2708d57c2f..aa6e8cc0e5 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -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)
diff --git a/block/file-posix.c b/block/file-posix.c
index 1941fb6749..19c48a043e 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -375,7 +375,7 @@ static void raw_parse_filename(const char *filename, QDict *options,
* function call can be ignored. */
strstart(filename, "file:", &filename);
- qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+ qdict_put_str(options, "filename", filename);
}
static QemuOptsList raw_runtime_opts = {
@@ -2155,7 +2155,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_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+ qdict_put_str(options, "filename", filename);
}
static bool hdev_is_sg(BlockDriverState *bs)
@@ -2244,7 +2244,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);
@@ -2454,7 +2454,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_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+ qdict_put_str(options, "filename", filename);
}
#endif
diff --git a/block/file-win32.c b/block/file-win32.c
index 7872e00a21..d1eb0a14b2 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -281,7 +281,7 @@ static void raw_parse_filename(const char *filename, QDict *options,
* function call can be ignored. */
strstart(filename, "file:", &filename);
- qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+ qdict_put_str(options, "filename", filename);
}
static QemuOptsList raw_runtime_opts = {
@@ -668,7 +668,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_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+ qdict_put_str(options, "filename", filename);
}
static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
diff --git a/block/gluster.c b/block/gluster.c
index 1d4e2f7c52..7c76cd0988 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -321,7 +321,7 @@ static int parse_volume_options(BlockdevOptionsGluster *gconf, char *path)
static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
const char *filename)
{
- SocketAddressFlat *gsconf;
+ SocketAddress *gsconf;
URI *uri;
QueryParams *qp = NULL;
bool is_unix = false;
@@ -332,19 +332,19 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
return -EINVAL;
}
- gconf->server = g_new0(SocketAddressFlatList, 1);
- gconf->server->value = gsconf = g_new0(SocketAddressFlat, 1);
+ gconf->server = g_new0(SocketAddressList, 1);
+ gconf->server->value = gsconf = g_new0(SocketAddress, 1);
/* transport */
if (!uri->scheme || !strcmp(uri->scheme, "gluster")) {
- gsconf->type = SOCKET_ADDRESS_FLAT_TYPE_INET;
+ gsconf->type = SOCKET_ADDRESS_TYPE_INET;
} else if (!strcmp(uri->scheme, "gluster+tcp")) {
- gsconf->type = SOCKET_ADDRESS_FLAT_TYPE_INET;
+ gsconf->type = SOCKET_ADDRESS_TYPE_INET;
} else if (!strcmp(uri->scheme, "gluster+unix")) {
- gsconf->type = SOCKET_ADDRESS_FLAT_TYPE_UNIX;
+ gsconf->type = SOCKET_ADDRESS_TYPE_UNIX;
is_unix = true;
} else if (!strcmp(uri->scheme, "gluster+rdma")) {
- gsconf->type = SOCKET_ADDRESS_FLAT_TYPE_INET;
+ gsconf->type = SOCKET_ADDRESS_TYPE_INET;
error_report("Warning: rdma feature is not supported, falling "
"back to tcp");
} else {
@@ -396,7 +396,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
struct glfs *glfs;
int ret;
int old_errno;
- SocketAddressFlatList *server;
+ SocketAddressList *server;
unsigned long long port;
glfs = glfs_find_preopened(gconf->volume);
@@ -413,11 +413,11 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
for (server = gconf->server; server; server = server->next) {
switch (server->value->type) {
- case SOCKET_ADDRESS_FLAT_TYPE_UNIX:
+ case SOCKET_ADDRESS_TYPE_UNIX:
ret = glfs_set_volfile_server(glfs, "unix",
server->value->u.q_unix.path, 0);
break;
- case SOCKET_ADDRESS_FLAT_TYPE_INET:
+ case SOCKET_ADDRESS_TYPE_INET:
if (parse_uint_full(server->value->u.inet.port, &port, 10) < 0 ||
port > 65535) {
error_setg(errp, "'%s' is not a valid port number",
@@ -429,8 +429,8 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
server->value->u.inet.host,
(int)port);
break;
- case SOCKET_ADDRESS_FLAT_TYPE_VSOCK:
- case SOCKET_ADDRESS_FLAT_TYPE_FD:
+ case SOCKET_ADDRESS_TYPE_VSOCK:
+ case SOCKET_ADDRESS_TYPE_FD:
default:
abort();
}
@@ -450,7 +450,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
error_setg(errp, "Gluster connection for volume %s, path %s failed"
" to connect", gconf->volume, gconf->path);
for (server = gconf->server; server; server = server->next) {
- if (server->value->type == SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
+ if (server->value->type == SOCKET_ADDRESS_TYPE_UNIX) {
error_append_hint(errp, "hint: failed on socket %s ",
server->value->u.q_unix.path);
} else {
@@ -487,8 +487,8 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
QDict *options, Error **errp)
{
QemuOpts *opts;
- SocketAddressFlat *gsconf = NULL;
- SocketAddressFlatList *curr = NULL;
+ SocketAddress *gsconf = NULL;
+ SocketAddressList *curr = NULL;
QDict *backing_options = NULL;
Error *local_err = NULL;
char *str = NULL;
@@ -542,14 +542,14 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
goto out;
}
- gsconf = g_new0(SocketAddressFlat, 1);
+ gsconf = g_new0(SocketAddress, 1);
if (!strcmp(ptr, "tcp")) {
ptr = "inet"; /* accept legacy "tcp" */
}
- type = qapi_enum_parse(SocketAddressFlatType_lookup, ptr,
- SOCKET_ADDRESS_FLAT_TYPE__MAX, -1, NULL);
- if (type != SOCKET_ADDRESS_FLAT_TYPE_INET
- && type != SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
+ type = qapi_enum_parse(SocketAddressType_lookup, ptr,
+ SOCKET_ADDRESS_TYPE__MAX, -1, NULL);
+ if (type != SOCKET_ADDRESS_TYPE_INET
+ && type != SOCKET_ADDRESS_TYPE_UNIX) {
error_setg(&local_err,
"Parameter '%s' may be 'inet' or 'unix'",
GLUSTER_OPT_TYPE);
@@ -559,7 +559,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
gsconf->type = type;
qemu_opts_del(opts);
- if (gsconf->type == SOCKET_ADDRESS_FLAT_TYPE_INET) {
+ if (gsconf->type == SOCKET_ADDRESS_TYPE_INET) {
/* create opts info from runtime_inet_opts list */
opts = qemu_opts_create(&runtime_inet_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, backing_options, &local_err);
@@ -628,11 +628,11 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
}
if (gconf->server == NULL) {
- gconf->server = g_new0(SocketAddressFlatList, 1);
+ gconf->server = g_new0(SocketAddressList, 1);
gconf->server->value = gsconf;
curr = gconf->server;
} else {
- curr->next = g_new0(SocketAddressFlatList, 1);
+ curr->next = g_new0(SocketAddressList, 1);
curr->next->value = gsconf;
curr = curr->next;
}
@@ -648,7 +648,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
out:
error_propagate(errp, local_err);
- qapi_free_SocketAddressFlat(gsconf);
+ qapi_free_SocketAddress(gsconf);
qemu_opts_del(opts);
g_free(str);
QDECREF(backing_options);
diff --git a/block/nbd.c b/block/nbd.c
index 814ab26dce..975faab2c5 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -47,7 +47,7 @@ typedef struct BDRVNBDState {
NBDClientSession client;
/* For nbd_refresh_filename() */
- SocketAddressFlat *saddr;
+ SocketAddress *saddr;
char *export, *tlscredsid;
} BDRVNBDState;
@@ -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,19 +195,19 @@ 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;
+ InetSocketAddress *addr = g_new(InetSocketAddress, 1);
- addr = inet_parse(host_spec, errp);
- if (!addr) {
- goto out;
+ if (inet_parse(addr, host_spec, errp)) {
+ goto out_inet;
}
- 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);
+ out_inet:
qapi_free_InetSocketAddress(addr);
}
@@ -247,22 +246,22 @@ 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;
}
-static SocketAddressFlat *nbd_config(BDRVNBDState *s, QDict *options,
- Error **errp)
+static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
+ Error **errp)
{
- SocketAddressFlat *saddr = NULL;
+ SocketAddress *saddr = NULL;
QDict *addr = NULL;
QObject *crumpled_addr = NULL;
Visitor *iv = NULL;
@@ -288,7 +287,7 @@ static SocketAddressFlat *nbd_config(BDRVNBDState *s, QDict *options,
* visitor expects the former.
*/
iv = qobject_input_visitor_new(crumpled_addr);
- visit_type_SocketAddressFlat(iv, NULL, &saddr, &local_err);
+ visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto done;
@@ -307,10 +306,9 @@ NBDClientSession *nbd_get_client_session(BlockDriverState *bs)
return &s->client;
}
-static QIOChannelSocket *nbd_establish_connection(SocketAddressFlat *saddr_flat,
+static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr,
Error **errp)
{
- SocketAddress *saddr = socket_address_crumple(saddr_flat);
QIOChannelSocket *sioc;
Error *local_err = NULL;
@@ -320,7 +318,6 @@ static QIOChannelSocket *nbd_establish_connection(SocketAddressFlat *saddr_flat,
qio_channel_socket_connect_sync(sioc,
saddr,
&local_err);
- qapi_free_SocketAddress(saddr);
if (local_err) {
object_unref(OBJECT(sioc));
error_propagate(errp, local_err);
@@ -413,7 +410,7 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
goto error;
}
- /* Translate @host, @port, and @path to a SocketAddressFlat */
+ /* Translate @host, @port, and @path to a SocketAddress */
if (!nbd_process_legacy_socket_options(options, opts, errp)) {
goto error;
}
@@ -434,7 +431,7 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
}
/* TODO SOCKET_ADDRESS_KIND_FD where fd has AF_INET or AF_INET6 */
- if (s->saddr->type != SOCKET_ADDRESS_FLAT_TYPE_INET) {
+ if (s->saddr->type != SOCKET_ADDRESS_TYPE_INET) {
error_setg(errp, "TLS only supported over IP sockets");
goto error;
}
@@ -461,7 +458,7 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
object_unref(OBJECT(tlscreds));
}
if (ret < 0) {
- qapi_free_SocketAddressFlat(s->saddr);
+ qapi_free_SocketAddress(s->saddr);
g_free(s->export);
g_free(s->tlscredsid);
}
@@ -487,7 +484,7 @@ static void nbd_close(BlockDriverState *bs)
nbd_client_close(bs);
- qapi_free_SocketAddressFlat(s->saddr);
+ qapi_free_SocketAddress(s->saddr);
g_free(s->export);
g_free(s->tlscredsid);
}
@@ -518,17 +515,17 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
Visitor *ov;
const char *host = NULL, *port = NULL, *path = NULL;
- if (s->saddr->type == SOCKET_ADDRESS_FLAT_TYPE_INET) {
+ if (s->saddr->type == SOCKET_ADDRESS_TYPE_INET) {
const InetSocketAddress *inet = &s->saddr->u.inet;
if (!inet->has_ipv4 && !inet->has_ipv6 && !inet->has_to) {
host = inet->host;
port = inet->port;
}
- } else if (s->saddr->type == SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
+ } else if (s->saddr->type == SOCKET_ADDRESS_TYPE_UNIX) {
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),
@@ -545,16 +542,16 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
}
ov = qobject_output_visitor_new(&saddr_qdict);
- visit_type_SocketAddressFlat(ov, NULL, &s->saddr, &error_abort);
+ visit_type_SocketAddress(ov, NULL, &s->saddr, &error_abort);
visit_complete(ov, &saddr_qdict);
visit_free(ov);
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);
diff --git a/block/nfs.c b/block/nfs.c
index 76572ae546..848b2c0bb0 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -104,9 +104,9 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
goto out;
}
- qdict_put(options, "server.host", qstring_from_str(uri->server));
- qdict_put(options, "server.type", qstring_from_str("inet"));
- qdict_put(options, "path", qstring_from_str(uri->path));
+ qdict_put_str(options, "server.host", uri->server);
+ qdict_put_str(options, "server.type", "inet");
+ qdict_put_str(options, "path", uri->path);
for (i = 0; i < qp->n; i++) {
unsigned long long val;
@@ -121,23 +121,17 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
goto out;
}
if (!strcmp(qp->p[i].name, "uid")) {
- qdict_put(options, "user",
- qstring_from_str(qp->p[i].value));
+ qdict_put_str(options, "user", qp->p[i].value);
} else if (!strcmp(qp->p[i].name, "gid")) {
- qdict_put(options, "group",
- qstring_from_str(qp->p[i].value));
+ qdict_put_str(options, "group", qp->p[i].value);
} else if (!strcmp(qp->p[i].name, "tcp-syncnt")) {
- qdict_put(options, "tcp-syn-count",
- qstring_from_str(qp->p[i].value));
+ qdict_put_str(options, "tcp-syn-count", qp->p[i].value);
} else if (!strcmp(qp->p[i].name, "readahead")) {
- qdict_put(options, "readahead-size",
- qstring_from_str(qp->p[i].value));
+ qdict_put_str(options, "readahead-size", qp->p[i].value);
} else if (!strcmp(qp->p[i].name, "pagecache")) {
- qdict_put(options, "page-cache-size",
- qstring_from_str(qp->p[i].value));
+ qdict_put_str(options, "page-cache-size", qp->p[i].value);
} else if (!strcmp(qp->p[i].name, "debug")) {
- qdict_put(options, "debug",
- qstring_from_str(qp->p[i].value));
+ qdict_put_str(options, "debug", qp->p[i].value);
} else {
error_setg(errp, "Unknown NFS parameter name: %s",
qp->p[i].name);
@@ -819,7 +813,7 @@ static void nfs_refresh_filename(BlockDriverState *bs, QDict *options)
QObject *server_qdict;
Visitor *ov;
- qdict_put(opts, "driver", qstring_from_str("nfs"));
+ qdict_put_str(opts, "driver", "nfs");
if (client->uid && !client->gid) {
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
@@ -842,28 +836,25 @@ static void nfs_refresh_filename(BlockDriverState *bs, QDict *options)
visit_type_NFSServer(ov, NULL, &client->server, &error_abort);
visit_complete(ov, &server_qdict);
qdict_put_obj(opts, "server", server_qdict);
- qdict_put(opts, "path", qstring_from_str(client->path));
+ qdict_put_str(opts, "path", client->path);
if (client->uid) {
- qdict_put(opts, "user", qint_from_int(client->uid));
+ qdict_put_int(opts, "user", client->uid);
}
if (client->gid) {
- qdict_put(opts, "group", qint_from_int(client->gid));
+ qdict_put_int(opts, "group", client->gid);
}
if (client->tcp_syncnt) {
- qdict_put(opts, "tcp-syn-cnt",
- qint_from_int(client->tcp_syncnt));
+ qdict_put_int(opts, "tcp-syn-cnt", client->tcp_syncnt);
}
if (client->readahead) {
- qdict_put(opts, "readahead-size",
- qint_from_int(client->readahead));
+ qdict_put_int(opts, "readahead-size", client->readahead);
}
if (client->pagecache) {
- qdict_put(opts, "page-cache-size",
- qint_from_int(client->pagecache));
+ qdict_put_int(opts, "page-cache-size", client->pagecache);
}
if (client->debug) {
- qdict_put(opts, "debug", qint_from_int(client->debug));
+ qdict_put_int(opts, "debug", client->debug);
}
visit_free(ov);
diff --git a/block/null.c b/block/null.c
index b300390944..876f90965b 100644
--- a/block/null.c
+++ b/block/null.c
@@ -232,7 +232,7 @@ static void null_refresh_filename(BlockDriverState *bs, QDict *opts)
bs->drv->format_name);
}
- qdict_put(opts, "driver", qstring_from_str(bs->drv->format_name));
+ qdict_put_str(opts, "driver", bs->drv->format_name);
bs->full_open_options = opts;
}
diff --git a/block/qcow2.c b/block/qcow2.c
index 5c1573c999..1c2697732b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2265,7 +2265,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
* table)
*/
options = qdict_new();
- qdict_put(options, "driver", qstring_from_str("qcow2"));
+ qdict_put_str(options, "driver", "qcow2");
blk = blk_new_open(filename, NULL, options,
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH,
&local_err);
@@ -2327,7 +2327,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
options = qdict_new();
- qdict_put(options, "driver", qstring_from_str("qcow2"));
+ qdict_put_str(options, "driver", "qcow2");
blk = blk_new_open(filename, NULL, options,
BDRV_O_RDWR | BDRV_O_NO_BACKING, &local_err);
if (blk == NULL) {
diff --git a/block/quorum.c b/block/quorum.c
index 40205fb1b3..1b2a8c3937 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -1096,19 +1096,15 @@ static void quorum_refresh_filename(BlockDriverState *bs, QDict *options)
children = qlist_new();
for (i = 0; i < s->num_children; i++) {
QINCREF(s->children[i]->bs->full_open_options);
- qlist_append_obj(children,
- QOBJECT(s->children[i]->bs->full_open_options));
+ qlist_append(children, s->children[i]->bs->full_open_options);
}
opts = qdict_new();
- qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("quorum")));
- qdict_put_obj(opts, QUORUM_OPT_VOTE_THRESHOLD,
- QOBJECT(qint_from_int(s->threshold)));
- qdict_put_obj(opts, QUORUM_OPT_BLKVERIFY,
- QOBJECT(qbool_from_bool(s->is_blkverify)));
- qdict_put_obj(opts, QUORUM_OPT_REWRITE,
- QOBJECT(qbool_from_bool(s->rewrite_corrupted)));
- qdict_put_obj(opts, "children", QOBJECT(children));
+ qdict_put_str(opts, "driver", "quorum");
+ qdict_put_int(opts, QUORUM_OPT_VOTE_THRESHOLD, s->threshold);
+ qdict_put_bool(opts, QUORUM_OPT_BLKVERIFY, s->is_blkverify);
+ qdict_put_bool(opts, QUORUM_OPT_REWRITE, s->rewrite_corrupted);
+ qdict_put(opts, "children", children);
bs->full_open_options = opts;
}
diff --git a/block/rbd.c b/block/rbd.c
index fbf30591d1..e551639e47 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -154,20 +154,20 @@ static void qemu_rbd_parse_filename(const char *filename, QDict *options,
goto done;
}
qemu_rbd_unescape(found_str);
- qdict_put(options, "pool", qstring_from_str(found_str));
+ qdict_put_str(options, "pool", found_str);
if (strchr(p, '@')) {
found_str = qemu_rbd_next_tok(p, '@', &p);
qemu_rbd_unescape(found_str);
- qdict_put(options, "image", qstring_from_str(found_str));
+ qdict_put_str(options, "image", found_str);
found_str = qemu_rbd_next_tok(p, ':', &p);
qemu_rbd_unescape(found_str);
- qdict_put(options, "snapshot", qstring_from_str(found_str));
+ qdict_put_str(options, "snapshot", found_str);
} else {
found_str = qemu_rbd_next_tok(p, ':', &p);
qemu_rbd_unescape(found_str);
- qdict_put(options, "image", qstring_from_str(found_str));
+ qdict_put_str(options, "image", found_str);
}
if (!p) {
goto done;
@@ -189,9 +189,9 @@ static void qemu_rbd_parse_filename(const char *filename, QDict *options,
qemu_rbd_unescape(value);
if (!strcmp(name, "conf")) {
- qdict_put(options, "conf", qstring_from_str(value));
+ qdict_put_str(options, "conf", value);
} else if (!strcmp(name, "id")) {
- qdict_put(options, "user" , qstring_from_str(value));
+ qdict_put_str(options, "user", value);
} else {
/*
* We pass these internally to qemu_rbd_set_keypairs(), so
@@ -204,8 +204,8 @@ static void qemu_rbd_parse_filename(const char *filename, QDict *options,
if (!keypairs) {
keypairs = qlist_new();
}
- qlist_append(keypairs, qstring_from_str(name));
- qlist_append(keypairs, qstring_from_str(value));
+ qlist_append_str(keypairs, name);
+ qlist_append_str(keypairs, value);
}
}
diff --git a/block/sheepdog.c b/block/sheepdog.c
index fe8fd923d5..a18315a1ca 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -536,14 +536,12 @@ static SocketAddress *sd_socket_address(const char *path,
SocketAddress *addr = g_new0(SocketAddress, 1);
if (path) {
- addr->type = SOCKET_ADDRESS_KIND_UNIX;
- addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- addr->u.q_unix.data->path = g_strdup(path);
+ addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ addr->u.q_unix.path = g_strdup(path);
} else {
- addr->type = SOCKET_ADDRESS_KIND_INET;
- addr->u.inet.data = g_new0(InetSocketAddress, 1);
- addr->u.inet.data->host = g_strdup(host ?: SD_DEFAULT_ADDR);
- addr->u.inet.data->port = g_strdup(port ?: stringify(SD_DEFAULT_PORT));
+ addr->type = SOCKET_ADDRESS_TYPE_INET;
+ addr->u.inet.host = g_strdup(host ?: SD_DEFAULT_ADDR);
+ addr->u.inet.port = g_strdup(port ?: stringify(SD_DEFAULT_PORT));
}
return addr;
@@ -554,7 +552,6 @@ static SocketAddress *sd_server_config(QDict *options, Error **errp)
QDict *server = NULL;
QObject *crumpled_server = NULL;
Visitor *iv = NULL;
- SocketAddressFlat *saddr_flat = NULL;
SocketAddress *saddr = NULL;
Error *local_err = NULL;
@@ -574,16 +571,13 @@ static SocketAddress *sd_server_config(QDict *options, Error **errp)
* visitor expects the former.
*/
iv = qobject_input_visitor_new(crumpled_server);
- visit_type_SocketAddressFlat(iv, NULL, &saddr_flat, &local_err);
+ visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto done;
}
- saddr = socket_address_crumple(saddr_flat);
-
done:
- qapi_free_SocketAddressFlat(saddr_flat);
visit_free(iv);
qobject_decref(crumpled_server);
QDECREF(server);
@@ -597,7 +591,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
fd = socket_connect(s->addr, NULL, NULL, errp);
- if (s->addr->type == SOCKET_ADDRESS_KIND_INET && fd >= 0) {
+ if (s->addr->type == SOCKET_ADDRESS_TYPE_INET && fd >= 0) {
int ret = socket_set_nodelay(fd);
if (ret < 0) {
error_report("%s", strerror(errno));
diff --git a/block/snapshot.c b/block/snapshot.c
index 06b1185d27..a46564e7b7 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -200,7 +200,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
qdict_extract_subqdict(options, &file_options, "file.");
QDECREF(file_options);
- qdict_put(options, "file", qstring_from_str(bdrv_get_node_name(file)));
+ qdict_put_str(options, "file", bdrv_get_node_name(file));
drv->bdrv_close(bs);
bdrv_unref_child(bs, bs->file);
diff --git a/block/ssh.c b/block/ssh.c
index df09f6c5ba..11203fc5a2 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -227,24 +227,23 @@ static int parse_uri(const char *filename, QDict *options, Error **errp)
}
if(uri->user && strcmp(uri->user, "") != 0) {
- qdict_put(options, "user", qstring_from_str(uri->user));
+ qdict_put_str(options, "user", uri->user);
}
- qdict_put(options, "server.host", qstring_from_str(uri->server));
+ qdict_put_str(options, "server.host", uri->server);
port_str = g_strdup_printf("%d", uri->port ?: 22);
- qdict_put(options, "server.port", qstring_from_str(port_str));
+ qdict_put_str(options, "server.port", port_str);
g_free(port_str);
- qdict_put(options, "path", qstring_from_str(uri->path));
+ qdict_put_str(options, "path", uri->path);
/* Pick out any query parameters that we understand, and ignore
* the rest.
*/
for (i = 0; i < qp->n; ++i) {
if (strcmp(qp->p[i].name, "host_key_check") == 0) {
- qdict_put(options, "host_key_check",
- qstring_from_str(qp->p[i].value));
+ qdict_put_str(options, "host_key_check", qp->p[i].value);
}
}
@@ -574,9 +573,8 @@ static bool ssh_process_legacy_socket_options(QDict *output_opts,
}
if (host) {
- qdict_put(output_opts, "server.host", qstring_from_str(host));
- qdict_put(output_opts, "server.port",
- qstring_from_str(port ?: stringify(22)));
+ qdict_put_str(output_opts, "server.host", host);
+ qdict_put_str(output_opts, "server.port", port ?: stringify(22));
}
return true;
diff --git a/block/vvfat.c b/block/vvfat.c
index b509d55642..9c82371360 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1057,10 +1057,10 @@ static void vvfat_parse_filename(const char *filename, QDict *options,
}
/* Fill in the options QDict */
- qdict_put(options, "dir", qstring_from_str(filename));
- qdict_put(options, "fat-type", qint_from_int(fat_type));
- qdict_put(options, "floppy", qbool_from_bool(floppy));
- qdict_put(options, "rw", qbool_from_bool(rw));
+ qdict_put_str(options, "dir", filename);
+ qdict_put_int(options, "fat-type", fat_type);
+ qdict_put_bool(options, "floppy", floppy);
+ qdict_put_bool(options, "rw", rw);
}
static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
@@ -3051,7 +3051,7 @@ static int enable_write_target(BlockDriverState *bs, Error **errp)
}
options = qdict_new();
- qdict_put(options, "write-target.driver", qstring_from_str("qcow"));
+ qdict_put_str(options, "write-target.driver", "qcow");
s->qcow = bdrv_open_child(s->qcow_filename, options, "write-target", bs,
&child_vvfat_qcow, false, errp);
QDECREF(options);
diff --git a/block/vxhs.c b/block/vxhs.c
index 9ffe9d3814..75cc6c8672 100644
--- a/block/vxhs.c
+++ b/block/vxhs.c
@@ -182,15 +182,15 @@ static int vxhs_parse_uri(const char *filename, QDict *options)
return -EINVAL;
}
- qdict_put(options, VXHS_OPT_SERVER".host", qstring_from_str(uri->server));
+ qdict_put_str(options, VXHS_OPT_SERVER ".host", uri->server);
if (uri->port) {
port = g_strdup_printf("%d", uri->port);
- qdict_put(options, VXHS_OPT_SERVER".port", qstring_from_str(port));
+ qdict_put_str(options, VXHS_OPT_SERVER ".port", port);
g_free(port);
}
- qdict_put(options, "vdisk-id", qstring_from_str(uri->path));
+ qdict_put_str(options, "vdisk-id", uri->path);
trace_vxhs_parse_uri_hostinfo(uri->server, uri->port);
uri_free(uri);
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 8a11807df3..dd0860f4a6 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -99,9 +99,8 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
}
-void qmp_nbd_server_start(SocketAddress *addr,
- bool has_tls_creds, const char *tls_creds,
- Error **errp)
+void nbd_server_start(SocketAddress *addr, const char *tls_creds,
+ Error **errp)
{
if (nbd_server) {
error_setg(errp, "NBD server already running");
@@ -118,14 +117,14 @@ void qmp_nbd_server_start(SocketAddress *addr,
goto error;
}
- if (has_tls_creds) {
+ if (tls_creds) {
nbd_server->tlscreds = nbd_get_tls_creds(tls_creds, errp);
if (!nbd_server->tlscreds) {
goto error;
}
- /* TODO SOCKET_ADDRESS_KIND_FD where fd has AF_INET or AF_INET6 */
- if (addr->type != SOCKET_ADDRESS_KIND_INET) {
+ /* TODO SOCKET_ADDRESS_TYPE_FD where fd has AF_INET or AF_INET6 */
+ if (addr->type != SOCKET_ADDRESS_TYPE_INET) {
error_setg(errp, "TLS is only supported with IPv4/IPv6");
goto error;
}
@@ -145,6 +144,16 @@ void qmp_nbd_server_start(SocketAddress *addr,
nbd_server = NULL;
}
+void qmp_nbd_server_start(SocketAddressLegacy *addr,
+ bool has_tls_creds, const char *tls_creds,
+ Error **errp)
+{
+ SocketAddress *addr_flat = socket_address_flatten(addr);
+
+ nbd_server_start(addr_flat, tls_creds, errp);
+ qapi_free_SocketAddress(addr_flat);
+}
+
void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
Error **errp)
{
diff --git a/blockdev.c b/blockdev.c
index 4d8cdedd54..0b38c3df71 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -527,7 +527,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
error_setg(errp, "Cannot specify both 'driver' and 'format'");
goto early_err;
}
- qdict_put(bs_opts, "driver", qstring_from_str(buf));
+ qdict_put_str(bs_opts, "driver", buf);
}
on_write_error = BLOCKDEV_ON_ERROR_ENOSPC;
@@ -903,10 +903,8 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
copy_on_read = false;
}
- qdict_put(bs_opts, BDRV_OPT_READ_ONLY,
- qstring_from_str(read_only ? "on" : "off"));
- qdict_put(bs_opts, "copy-on-read",
- qstring_from_str(copy_on_read ? "on" :"off"));
+ qdict_put_str(bs_opts, BDRV_OPT_READ_ONLY, read_only ? "on" : "off");
+ qdict_put_str(bs_opts, "copy-on-read", copy_on_read ? "on" : "off");
/* Controller type */
value = qemu_opt_get(legacy_opts, "if");
@@ -1030,7 +1028,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
new_id = g_strdup_printf("%s%s%i", if_name[type],
mediastr, unit_id);
}
- qdict_put(bs_opts, "id", qstring_from_str(new_id));
+ qdict_put_str(bs_opts, "id", new_id);
g_free(new_id);
}
@@ -1067,7 +1065,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
error_report("werror is not supported by this bus type");
goto fail;
}
- qdict_put(bs_opts, "werror", qstring_from_str(werror));
+ qdict_put_str(bs_opts, "werror", werror);
}
rerror = qemu_opt_get(legacy_opts, "rerror");
@@ -1077,7 +1075,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
error_report("rerror is not supported by this bus type");
goto fail;
}
- qdict_put(bs_opts, "rerror", qstring_from_str(rerror));
+ qdict_put_str(bs_opts, "rerror", rerror);
}
/* Actual block device init: Functionality shared with blockdev-add */
@@ -1737,10 +1735,9 @@ static void external_snapshot_prepare(BlkActionState *common,
options = qdict_new();
if (s->has_snapshot_node_name) {
- qdict_put(options, "node-name",
- qstring_from_str(snapshot_node_name));
+ qdict_put_str(options, "node-name", snapshot_node_name);
}
- qdict_put(options, "driver", qstring_from_str(format));
+ qdict_put_str(options, "driver", format);
flags |= BDRV_O_NO_BACKING;
}
@@ -2579,11 +2576,10 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
options = qdict_new();
detect_zeroes = blk_get_detect_zeroes_from_root_state(blk);
- qdict_put(options, "detect-zeroes",
- qstring_from_str(detect_zeroes ? "on" : "off"));
+ qdict_put_str(options, "detect-zeroes", detect_zeroes ? "on" : "off");
if (has_format) {
- qdict_put(options, "driver", qstring_from_str(format));
+ qdict_put_str(options, "driver", format);
}
medium_bs = bdrv_open(filename, NULL, options, bdrv_flags, errp);
@@ -3232,7 +3228,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
if (backup->format) {
options = qdict_new();
- qdict_put(options, "driver", qstring_from_str(backup->format));
+ qdict_put_str(options, "driver", backup->format);
}
target_bs = bdrv_open(backup->target, NULL, options, flags, errp);
@@ -3536,10 +3532,10 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
options = qdict_new();
if (arg->has_node_name) {
- qdict_put(options, "node-name", qstring_from_str(arg->node_name));
+ qdict_put_str(options, "node-name", arg->node_name);
}
if (format) {
- qdict_put(options, "driver", qstring_from_str(format));
+ qdict_put_str(options, "driver", format);
}
/* Mirroring takes care of copy-on-write using the source's backing
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 3bda89a1fa..e2fb7f7cd5 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -360,26 +360,26 @@ static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr,
bool is_listen, bool is_telnet)
{
switch (addr->type) {
- case SOCKET_ADDRESS_KIND_INET:
+ case SOCKET_ADDRESS_TYPE_INET:
return g_strdup_printf("%s%s:%s:%s%s", prefix,
is_telnet ? "telnet" : "tcp",
- addr->u.inet.data->host,
- addr->u.inet.data->port,
+ addr->u.inet.host,
+ addr->u.inet.port,
is_listen ? ",server" : "");
break;
- case SOCKET_ADDRESS_KIND_UNIX:
+ case SOCKET_ADDRESS_TYPE_UNIX:
return g_strdup_printf("%sunix:%s%s", prefix,
- addr->u.q_unix.data->path,
+ addr->u.q_unix.path,
is_listen ? ",server" : "");
break;
- case SOCKET_ADDRESS_KIND_FD:
- return g_strdup_printf("%sfd:%s%s", prefix, addr->u.fd.data->str,
+ case SOCKET_ADDRESS_TYPE_FD:
+ return g_strdup_printf("%sfd:%s%s", prefix, addr->u.fd.str,
is_listen ? ",server" : "");
break;
- case SOCKET_ADDRESS_KIND_VSOCK:
+ case SOCKET_ADDRESS_TYPE_VSOCK:
return g_strdup_printf("%svsock:%s:%s", prefix,
- addr->u.vsock.data->cid,
- addr->u.vsock.data->port);
+ addr->u.vsock.cid,
+ addr->u.vsock.port);
default:
abort();
}
@@ -648,7 +648,7 @@ static void tcp_chr_tls_init(Chardev *chr)
} else {
tioc = qio_channel_tls_new_client(
s->ioc, s->tls_creds,
- s->addr->u.inet.data->host,
+ s->addr->u.inet.host,
&err);
}
if (tioc == NULL) {
@@ -859,7 +859,6 @@ static void qmp_chardev_open_socket(Chardev *chr,
{
SocketChardev *s = SOCKET_CHARDEV(chr);
ChardevSocket *sock = backend->u.socket.data;
- SocketAddress *addr = sock->addr;
bool do_nodelay = sock->has_nodelay ? sock->nodelay : false;
bool is_listen = sock->has_server ? sock->server : true;
bool is_telnet = sock->has_telnet ? sock->telnet : false;
@@ -867,6 +866,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
bool is_waitconnect = sock->has_wait ? sock->wait : false;
int64_t reconnect = sock->has_reconnect ? sock->reconnect : 0;
QIOChannelSocket *sioc = NULL;
+ SocketAddress *addr;
s->is_listen = is_listen;
s->is_telnet = is_telnet;
@@ -905,11 +905,11 @@ static void qmp_chardev_open_socket(Chardev *chr,
}
}
- s->addr = QAPI_CLONE(SocketAddress, sock->addr);
+ s->addr = addr = socket_address_flatten(sock->addr);
qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE);
/* TODO SOCKET_ADDRESS_FD where fd has AF_UNIX */
- if (addr->type == SOCKET_ADDRESS_KIND_UNIX) {
+ if (addr->type == SOCKET_ADDRESS_TYPE_UNIX) {
qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS);
}
@@ -985,7 +985,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
const char *host = qemu_opt_get(opts, "host");
const char *port = qemu_opt_get(opts, "port");
const char *tls_creds = qemu_opt_get(opts, "tls-creds");
- SocketAddress *addr;
+ SocketAddressLegacy *addr;
ChardevSocket *sock;
backend->type = CHARDEV_BACKEND_KIND_SOCKET;
@@ -1022,14 +1022,14 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
sock->reconnect = reconnect;
sock->tls_creds = g_strdup(tls_creds);
- addr = g_new0(SocketAddress, 1);
+ addr = g_new0(SocketAddressLegacy, 1);
if (path) {
UnixSocketAddress *q_unix;
- addr->type = SOCKET_ADDRESS_KIND_UNIX;
+ addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
q_unix->path = g_strdup(path);
} else {
- addr->type = SOCKET_ADDRESS_KIND_INET;
+ addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
addr->u.inet.data = g_new(InetSocketAddress, 1);
*addr->u.inet.data = (InetSocketAddress) {
.host = g_strdup(host),
diff --git a/chardev/char-udp.c b/chardev/char-udp.c
index 76ef83f930..607647642a 100644
--- a/chardev/char-udp.c
+++ b/chardev/char-udp.c
@@ -134,7 +134,7 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
const char *localaddr = qemu_opt_get(opts, "localaddr");
const char *localport = qemu_opt_get(opts, "localport");
bool has_local = false;
- SocketAddress *addr;
+ SocketAddressLegacy *addr;
ChardevUdp *udp;
backend->type = CHARDEV_BACKEND_KIND_UDP;
@@ -159,8 +159,8 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
udp = backend->u.udp.data = g_new0(ChardevUdp, 1);
qemu_chr_parse_common(opts, qapi_ChardevUdp_base(udp));
- addr = g_new0(SocketAddress, 1);
- addr->type = SOCKET_ADDRESS_KIND_INET;
+ addr = g_new0(SocketAddressLegacy, 1);
+ addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
addr->u.inet.data = g_new(InetSocketAddress, 1);
*addr->u.inet.data = (InetSocketAddress) {
.host = g_strdup(host),
@@ -174,8 +174,8 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
if (has_local) {
udp->has_local = true;
- addr = g_new0(SocketAddress, 1);
- addr->type = SOCKET_ADDRESS_KIND_INET;
+ addr = g_new0(SocketAddressLegacy, 1);
+ addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
addr->u.inet.data = g_new(InetSocketAddress, 1);
*addr->u.inet.data = (InetSocketAddress) {
.host = g_strdup(localaddr),
@@ -191,13 +191,17 @@ static void qmp_chardev_open_udp(Chardev *chr,
Error **errp)
{
ChardevUdp *udp = backend->u.udp.data;
+ SocketAddress *local_addr = socket_address_flatten(udp->local);
+ SocketAddress *remote_addr = socket_address_flatten(udp->remote);
QIOChannelSocket *sioc = qio_channel_socket_new();
char *name;
UdpChardev *s = UDP_CHARDEV(chr);
+ int ret;
- if (qio_channel_socket_dgram_sync(sioc,
- udp->local, udp->remote,
- errp) < 0) {
+ ret = qio_channel_socket_dgram_sync(sioc, local_addr, remote_addr, errp);
+ qapi_free_SocketAddress(local_addr);
+ qapi_free_SocketAddress(remote_addr);
+ if (ret < 0) {
object_unref(OBJECT(sioc));
return;
}
diff --git a/hmp.c b/hmp.c
index bd7b1caf2b..524e5890de 100644
--- a/hmp.c
+++ b/hmp.c
@@ -34,6 +34,7 @@
#include "qapi-visit.h"
#include "qom/object_interfaces.h"
#include "ui/console.h"
+#include "block/nbd.h"
#include "block/qapi.h"
#include "qemu-io.h"
#include "qemu/cutils.h"
@@ -2121,7 +2122,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
goto exit;
}
- qmp_nbd_server_start(addr, false, NULL, &local_err);
+ nbd_server_start(addr, NULL, &local_err);
qapi_free_SocketAddress(addr);
if (local_err != NULL) {
goto exit;
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 27df0486d9..3a22805fbc 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -1082,7 +1082,7 @@ static int blk_connect(struct XenDevice *xendev)
if (strcmp(blkdev->fileproto, "<unset>")) {
options = qdict_new();
- qdict_put(options, "driver", qstring_from_str(blkdev->fileproto));
+ qdict_put_str(options, "driver", blkdev->fileproto);
}
/* setup via xenbus -> create new block driver instance */
diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
index a8c18203d6..828052b0c0 100644
--- a/hw/pci/pcie_aer.c
+++ b/hw/pci/pcie_aer.c
@@ -44,6 +44,13 @@
#define PCI_ERR_SRC_COR_OFFS 0
#define PCI_ERR_SRC_UNCOR_OFFS 2
+typedef struct PCIEErrorDetails {
+ const char *id;
+ const char *root_bus;
+ int bus;
+ int devfn;
+} PCIEErrorDetails;
+
/* From 6.2.7 Error Listing and Rules. Table 6-2, 6-3 and 6-4 */
static uint32_t pcie_aer_uncor_default_severity(uint32_t status)
{
@@ -369,7 +376,7 @@ static void pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)
*
* Walk up the bus tree from the device, propagate the error message.
*/
-void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg)
+static void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg)
{
uint8_t type;
@@ -624,7 +631,7 @@ static bool pcie_aer_inject_uncor_error(PCIEAERInject *inj, bool is_fatal)
* Figure 6-2: Flowchart Showing Sequence of Device Error Signaling and Logging
* Operations
*/
-int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err)
+static int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err)
{
uint8_t *aer_cap = NULL;
uint16_t devctl = 0;
@@ -942,8 +949,14 @@ static int pcie_aer_parse_error_string(const char *error_name,
return -EINVAL;
}
+/*
+ * Inject an error described by @qdict.
+ * On success, set @details to show where error was sent.
+ * Return negative errno if injection failed and a message was emitted.
+ */
static int do_pcie_aer_inject_error(Monitor *mon,
- const QDict *qdict, QObject **ret_data)
+ const QDict *qdict,
+ PCIEErrorDetails *details)
{
const char *id = qdict_get_str(qdict, "id");
const char *error_name;
@@ -1005,33 +1018,28 @@ static int do_pcie_aer_inject_error(Monitor *mon,
err.prefix[3] = qdict_get_try_int(qdict, "prefix3", 0);
ret = pcie_aer_inject_error(dev, &err);
- *ret_data = qobject_from_jsonf("{'id': %s, "
- "'root_bus': %s, 'bus': %d, 'devfn': %d, "
- "'ret': %d}",
- id, pci_root_bus_path(dev),
- pci_bus_num(dev->bus), dev->devfn,
- ret);
- assert(*ret_data);
+ if (ret < 0) {
+ monitor_printf(mon, "failed to inject error: %s\n",
+ strerror(-ret));
+ return ret;
+ }
+ details->id = id;
+ details->root_bus = pci_root_bus_path(dev);
+ details->bus = pci_bus_num(dev->bus);
+ details->devfn = dev->devfn;
return 0;
}
void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict)
{
- QObject *data;
- int devfn;
+ PCIEErrorDetails data;
if (do_pcie_aer_inject_error(mon, qdict, &data) < 0) {
return;
}
- qdict = qobject_to_qdict(data);
- assert(qdict);
-
- devfn = (int)qdict_get_int(qdict, "devfn");
monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n",
- qdict_get_str(qdict, "id"),
- qdict_get_str(qdict, "root_bus"),
- (int) qdict_get_int(qdict, "bus"),
- PCI_SLOT(devfn), PCI_FUNC(devfn));
+ data.id, data.root_bus, data.bus,
+ PCI_SLOT(data.devfn), PCI_FUNC(data.devfn));
}
diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c
index 370b3d9387..fe62183fe3 100644
--- a/hw/usb/xen-usb.c
+++ b/hw/usb/xen-usb.c
@@ -746,16 +746,16 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
portname++;
qdict = qdict_new();
- qdict_put(qdict, "driver", qstring_from_str("usb-host"));
+ qdict_put_str(qdict, "driver", "usb-host");
tmp = g_strdup_printf("%s.0", usbif->xendev.qdev.id);
- qdict_put(qdict, "bus", qstring_from_str(tmp));
+ qdict_put_str(qdict, "bus", tmp);
g_free(tmp);
tmp = g_strdup_printf("%s-%u", usbif->xendev.qdev.id, port);
- qdict_put(qdict, "id", qstring_from_str(tmp));
+ qdict_put_str(qdict, "id", tmp);
g_free(tmp);
- qdict_put(qdict, "port", qint_from_int(port));
- qdict_put(qdict, "hostbus", qint_from_int(atoi(busid)));
- qdict_put(qdict, "hostport", qstring_from_str(portname));
+ qdict_put_int(qdict, "port", port);
+ qdict_put_int(qdict, "hostbus", atoi(busid));
+ qdict_put_str(qdict, "hostport", portname);
opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
if (local_err) {
goto err;
diff --git a/include/block/nbd.h b/include/block/nbd.h
index 3e373f0498..0ed077502e 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -164,4 +164,7 @@ void nbd_client_new(NBDExport *exp,
void nbd_client_get(NBDClient *client);
void nbd_client_put(NBDClient *client);
+void nbd_server_start(SocketAddress *addr, const char *tls_creds,
+ Error **errp);
+
#endif
diff --git a/include/hw/pci/pcie_aer.h b/include/hw/pci/pcie_aer.h
index 526802bd31..729a9439c8 100644
--- a/include/hw/pci/pcie_aer.h
+++ b/include/hw/pci/pcie_aer.h
@@ -100,8 +100,4 @@ void pcie_aer_root_write_config(PCIDevice *dev,
uint32_t addr, uint32_t val, int len,
uint32_t root_cmd_prev);
-/* error injection */
-int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err);
-void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg);
-
#endif /* QEMU_PCIE_AER_H */
diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
index 711f8bf7ce..53801f6042 100644
--- a/include/io/channel-socket.h
+++ b/include/io/channel-socket.h
@@ -205,7 +205,7 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc,
* Get the string representation of the local socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
- * release with a call qapi_free_SocketAddress when no
+ * release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: 0 on success, -1 on error
@@ -222,7 +222,7 @@ qio_channel_socket_get_local_address(QIOChannelSocket *ioc,
* Get the string representation of the local socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
- * release with a call qapi_free_SocketAddress when no
+ * release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: the socket address struct, or NULL on error
diff --git a/include/qapi/clone-visitor.h b/include/qapi/clone-visitor.h
index b16177e1ee..a4915c7d57 100644
--- a/include/qapi/clone-visitor.h
+++ b/include/qapi/clone-visitor.h
@@ -24,6 +24,9 @@ typedef struct QapiCloneVisitor QapiCloneVisitor;
void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *,
void **, Error **));
+void qapi_clone_members(void *dst, const void *src, size_t sz,
+ void (*visit_type_members)(Visitor *, void *,
+ Error **));
/*
* Deep-clone QAPI object @src of the given @type, and return the result.
@@ -36,4 +39,15 @@ void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *,
(void (*)(Visitor *, const char *, void**, \
Error **))visit_type_ ## type))
+/*
+ * Copy deep clones of @type members from @src to @dst.
+ *
+ * Not usable on QAPI scalars (integers, strings, enums), nor on a
+ * QAPI object that references the 'any' type.
+ */
+#define QAPI_CLONE_MEMBERS(type, dst, src) \
+ qapi_clone_members(dst, src, sizeof(type), \
+ (void (*)(Visitor *, void *, \
+ Error **))visit_type_ ## type ## _members)
+
#endif
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index fe9a4c5c60..188440a6a8 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -52,6 +52,14 @@ void qdict_destroy_obj(QObject *obj);
#define qdict_put(qdict, key, obj) \
qdict_put_obj(qdict, key, QOBJECT(obj))
+/* Helpers for int, bool, and string */
+#define qdict_put_int(qdict, key, value) \
+ qdict_put(qdict, key, qint_from_int(value))
+#define qdict_put_bool(qdict, key, value) \
+ qdict_put(qdict, key, qbool_from_bool(value))
+#define qdict_put_str(qdict, key, value) \
+ qdict_put(qdict, key, qstring_from_str(value))
+
/* High level helpers */
double qdict_get_double(const QDict *qdict, const char *key);
int64_t qdict_get_int(const QDict *qdict, const char *key);
diff --git a/include/qapi/qmp/qlist.h b/include/qapi/qmp/qlist.h
index a84117ecb1..5dc4ed9616 100644
--- a/include/qapi/qmp/qlist.h
+++ b/include/qapi/qmp/qlist.h
@@ -29,6 +29,14 @@ typedef struct QList {
#define qlist_append(qlist, obj) \
qlist_append_obj(qlist, QOBJECT(obj))
+/* Helpers for int, bool, and string */
+#define qlist_append_int(qlist, value) \
+ qlist_append(qlist, qint_from_int(value))
+#define qlist_append_bool(qlist, value) \
+ qlist_append(qlist, qbool_from_bool(value))
+#define qlist_append_str(qlist, value) \
+ qlist_append(qlist, qstring_from_str(value))
+
#define QLIST_FOREACH_ENTRY(qlist, var) \
for ((var) = ((qlist)->head.tqh_first); \
(var); \
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index 1a1b62012b..b0e233df76 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -63,8 +63,10 @@
* The @name parameter of visit_type_FOO() describes the relation
* between this QAPI value and its parent container. When visiting
* the root of a tree, @name is ignored; when visiting a member of an
- * object, @name is the key associated with the value; and when
- * visiting a member of a list, @name is NULL.
+ * object, @name is the key associated with the value; when visiting a
+ * member of a list, @name is NULL; and when visiting the member of an
+ * alternate, @name should equal the name used for visiting the
+ * alternate.
*
* The visit_type_FOO() functions expect a non-null @obj argument;
* they allocate *@obj during input visits, leave it unchanged on
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index af285321b8..5c326db232 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -34,7 +34,7 @@ typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque);
int inet_ai_family_from_address(InetSocketAddress *addr,
Error **errp);
-InetSocketAddress *inet_parse(const char *str, Error **errp);
+int inet_parse(InetSocketAddress *addr, const char *str, Error **errp);
int inet_connect(const char *str, Error **errp);
int inet_connect_saddr(InetSocketAddress *saddr,
NonBlockingConnectHandler *callback, void *opaque,
@@ -65,7 +65,7 @@ int socket_init(void);
* Get the string representation of the socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
- * release with a call qapi_free_SocketAddress when no
+ * release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: the socket address struct, or NULL on error
@@ -83,7 +83,7 @@ socket_sockaddr_to_address(struct sockaddr_storage *sa,
* Get the string representation of the local socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
- * release with a call qapi_free_SocketAddress when no
+ * release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: the socket address struct, or NULL on error
@@ -98,7 +98,7 @@ SocketAddress *socket_local_address(int fd, Error **errp);
* Get the string representation of the remote socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
- * release with a call qapi_free_SocketAddress when no
+ * release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: the socket address struct, or NULL on error
@@ -121,14 +121,14 @@ SocketAddress *socket_remote_address(int fd, Error **errp);
char *socket_address_to_string(struct SocketAddress *addr, Error **errp);
/**
- * socket_address_crumple:
- * @addr_flat: the socket address to crumple
+ * socket_address_flatten:
+ * @addr: the socket address to flatten
*
- * Convert SocketAddressFlat to SocketAddress. Caller is responsible
+ * Convert SocketAddressLegacy to SocketAddress. Caller is responsible
* for freeing with qapi_free_SocketAddress().
*
* Returns: the argument converted to SocketAddress.
*/
-SocketAddress *socket_address_crumple(SocketAddressFlat *addr_flat);
+SocketAddress *socket_address_flatten(SocketAddressLegacy *addr);
#endif /* QEMU_SOCKETS_H */
diff --git a/io/dns-resolver.c b/io/dns-resolver.c
index 759d1b40d7..57a8896cbb 100644
--- a/io/dns-resolver.c
+++ b/io/dns-resolver.c
@@ -51,7 +51,7 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver,
Error **errp)
{
struct addrinfo ai, *res, *e;
- InetSocketAddress *iaddr = addr->u.inet.data;
+ InetSocketAddress *iaddr = &addr->u.inet;
char port[33];
char uaddr[INET6_ADDRSTRLEN + 1];
char uport[33];
@@ -102,15 +102,14 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver,
/* create socket + bind */
for (i = 0, e = res; e != NULL; i++, e = e->ai_next) {
SocketAddress *newaddr = g_new0(SocketAddress, 1);
- InetSocketAddress *newiaddr = g_new0(InetSocketAddress, 1);
- newaddr->u.inet.data = newiaddr;
- newaddr->type = SOCKET_ADDRESS_KIND_INET;
+
+ newaddr->type = SOCKET_ADDRESS_TYPE_INET;
getnameinfo((struct sockaddr *)e->ai_addr, e->ai_addrlen,
uaddr, INET6_ADDRSTRLEN, uport, 32,
NI_NUMERICHOST | NI_NUMERICSERV);
- *newiaddr = (InetSocketAddress){
+ newaddr->u.inet = (InetSocketAddress){
.host = g_strdup(uaddr),
.port = g_strdup(uport),
.has_numeric = true,
@@ -149,16 +148,16 @@ int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver,
Error **errp)
{
switch (addr->type) {
- case SOCKET_ADDRESS_KIND_INET:
+ case SOCKET_ADDRESS_TYPE_INET:
return qio_dns_resolver_lookup_sync_inet(resolver,
addr,
naddrs,
addrs,
errp);
- case SOCKET_ADDRESS_KIND_UNIX:
- case SOCKET_ADDRESS_KIND_VSOCK:
- case SOCKET_ADDRESS_KIND_FD:
+ case SOCKET_ADDRESS_TYPE_UNIX:
+ case SOCKET_ADDRESS_TYPE_VSOCK:
+ case SOCKET_ADDRESS_TYPE_FD:
return qio_dns_resolver_lookup_sync_nop(resolver,
addr,
naddrs,
diff --git a/migration/rdma.c b/migration/rdma.c
index fe0a4b5a83..7eaaf96479 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -2506,8 +2506,8 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
rdma->current_index = -1;
rdma->current_chunk = -1;
- addr = inet_parse(host_port, NULL);
- if (addr != NULL) {
+ addr = g_new(InetSocketAddress, 1);
+ if (!inet_parse(addr, host_port, NULL)) {
rdma->port = atoi(addr->port);
rdma->host = g_strdup(addr->host);
} else {
diff --git a/migration/socket.c b/migration/socket.c
index dc88812048..1cfbe81e69 100644
--- a/migration/socket.c
+++ b/migration/socket.c
@@ -27,17 +27,16 @@
static SocketAddress *tcp_build_address(const char *host_port, Error **errp)
{
- InetSocketAddress *iaddr = inet_parse(host_port, errp);
SocketAddress *saddr;
- if (!iaddr) {
+ saddr = g_new0(SocketAddress, 1);
+ saddr->type = SOCKET_ADDRESS_TYPE_INET;
+
+ if (inet_parse(&saddr->u.inet, host_port, errp)) {
+ qapi_free_SocketAddress(saddr);
return NULL;
}
- saddr = g_new0(SocketAddress, 1);
- saddr->type = SOCKET_ADDRESS_KIND_INET;
- saddr->u.inet.data = iaddr;
-
return saddr;
}
@@ -47,9 +46,8 @@ static SocketAddress *unix_build_address(const char *path)
SocketAddress *saddr;
saddr = g_new0(SocketAddress, 1);
- saddr->type = SOCKET_ADDRESS_KIND_UNIX;
- saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- saddr->u.q_unix.data->path = g_strdup(path);
+ saddr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ saddr->u.q_unix.path = g_strdup(path);
return saddr;
}
@@ -96,8 +94,8 @@ static void socket_start_outgoing_migration(MigrationState *s,
struct SocketConnectData *data = g_new0(struct SocketConnectData, 1);
data->s = s;
- if (saddr->type == SOCKET_ADDRESS_KIND_INET) {
- data->hostname = g_strdup(saddr->u.inet.data->host);
+ if (saddr->type == SOCKET_ADDRESS_TYPE_INET) {
+ data->hostname = g_strdup(saddr->u.inet.host);
}
qio_channel_set_name(QIO_CHANNEL(sioc), "migration-socket-outgoing");
diff --git a/monitor.c b/monitor.c
index ce1102944b..078cba5c86 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2769,7 +2769,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
}
goto fail;
}
- qdict_put(qdict, key, qstring_from_str(buf));
+ qdict_put_str(qdict, key, buf);
}
break;
case 'O':
@@ -2871,9 +2871,9 @@ static QDict *monitor_parse_arguments(Monitor *mon,
size = -1;
}
}
- qdict_put(qdict, "count", qint_from_int(count));
- qdict_put(qdict, "format", qint_from_int(format));
- qdict_put(qdict, "size", qint_from_int(size));
+ qdict_put_int(qdict, "count", count);
+ qdict_put_int(qdict, "format", format);
+ qdict_put_int(qdict, "size", size);
}
break;
case 'i':
@@ -2916,7 +2916,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
}
val <<= 20;
}
- qdict_put(qdict, key, qint_from_int(val));
+ qdict_put_int(qdict, key, val);
}
break;
case 'o':
@@ -2939,7 +2939,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
monitor_printf(mon, "invalid size\n");
goto fail;
}
- qdict_put(qdict, key, qint_from_int(val));
+ qdict_put_int(qdict, key, val);
p = end;
}
break;
@@ -2995,7 +2995,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
monitor_printf(mon, "Expected 'on' or 'off'\n");
goto fail;
}
- qdict_put(qdict, key, qbool_from_bool(val));
+ qdict_put_bool(qdict, key, val);
}
break;
case '-':
@@ -3026,7 +3026,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
} else {
/* has option */
p++;
- qdict_put(qdict, key, qbool_from_bool(true));
+ qdict_put_bool(qdict, key, true);
}
}
}
@@ -3052,7 +3052,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
cmd->name);
goto fail;
}
- qdict_put(qdict, key, qstring_from_str(p));
+ qdict_put_str(qdict, key, p);
p += len;
}
break;
@@ -3831,9 +3831,8 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
QapiErrorClass_lookup[ERROR_CLASS_COMMAND_NOT_FOUND])) {
/* Provide a more useful error message */
qdict_del(qdict, "desc");
- qdict_put(qdict, "desc",
- qstring_from_str("Expecting capabilities negotiation"
- " with 'qmp_capabilities'"));
+ qdict_put_str(qdict, "desc", "Expecting capabilities negotiation"
+ " with 'qmp_capabilities'");
}
}
diff --git a/qapi-schema.json b/qapi-schema.json
index 5bb8cb79fb..5728b7f363 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4122,13 +4122,19 @@
'port': 'str' } }
##
-# @SocketAddress:
+# @SocketAddressLegacy:
#
# Captures the address of a socket, which could also be a named file descriptor
#
+# Note: This type is deprecated in favor of SocketAddress. The
+# difference between SocketAddressLegacy and SocketAddress is that the
+# latter is a flat union rather than a simple union. Flat is nicer
+# because it avoids nesting on the wire, i.e. that form has fewer {}.
+
+#
# Since: 1.3
##
-{ 'union': 'SocketAddress',
+{ 'union': 'SocketAddressLegacy',
'data': {
'inet': 'InetSocketAddress',
'unix': 'UnixSocketAddress',
@@ -4136,9 +4142,9 @@
'fd': 'String' } }
##
-# @SocketAddressFlatType:
+# @SocketAddressType:
#
-# Available SocketAddressFlat types
+# Available SocketAddress types
#
# @inet: Internet address
#
@@ -4146,24 +4152,21 @@
#
# Since: 2.9
##
-{ 'enum': 'SocketAddressFlatType',
+{ 'enum': 'SocketAddressType',
'data': [ 'inet', 'unix', 'vsock', 'fd' ] }
##
-# @SocketAddressFlat:
+# @SocketAddress:
#
-# Captures the address of a socket
+# Captures the address of a socket, which could also be a named file
+# descriptor
#
# @type: Transport type
#
-# This is just like SocketAddress, except it's a flat union rather
-# than a simple union. Nicer because it avoids nesting on the wire,
-# i.e. this form has fewer {}.
-#
# Since: 2.9
##
-{ 'union': 'SocketAddressFlat',
- 'base': { 'type': 'SocketAddressFlatType' },
+{ 'union': 'SocketAddress',
+ 'base': { 'type': 'SocketAddressType' },
'discriminator': 'type',
'data': { 'inet': 'InetSocketAddress',
'unix': 'UnixSocketAddress',
@@ -4886,7 +4889,7 @@
#
# Since: 1.4
##
-{ 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress',
+{ 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddressLegacy',
'*tls-creds' : 'str',
'*server' : 'bool',
'*wait' : 'bool',
@@ -4906,8 +4909,8 @@
#
# Since: 1.5
##
-{ 'struct': 'ChardevUdp', 'data': { 'remote' : 'SocketAddress',
- '*local' : 'SocketAddress' },
+{ 'struct': 'ChardevUdp', 'data': { 'remote' : 'SocketAddressLegacy',
+ '*local' : 'SocketAddressLegacy' },
'base': 'ChardevCommon' }
##
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 87fb747ab6..614181b553 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2522,7 +2522,7 @@
{ 'struct': 'BlockdevOptionsGluster',
'data': { 'volume': 'str',
'path': 'str',
- 'server': ['SocketAddressFlat'],
+ 'server': ['SocketAddress'],
'*debug': 'int',
'*logfile': 'str' } }
@@ -2634,7 +2634,7 @@
# Since: 2.9
##
{ 'struct': 'BlockdevOptionsSheepdog',
- 'data': { 'server': 'SocketAddressFlat',
+ 'data': { 'server': 'SocketAddress',
'vdi': 'str',
'*snap-id': 'uint32',
'*tag': 'str' } }
@@ -2849,7 +2849,7 @@
# Since: 2.9
##
{ 'struct': 'BlockdevOptionsNbd',
- 'data': { 'server': 'SocketAddressFlat',
+ 'data': { 'server': 'SocketAddress',
'*export': 'str',
'*tls-creds': 'str' } }
diff --git a/qapi/block.json b/qapi/block.json
index 46fca0e1f3..6a2fdc73f7 100644
--- a/qapi/block.json
+++ b/qapi/block.json
@@ -204,7 +204,7 @@
# Since: 1.3.0
##
{ 'command': 'nbd-server-start',
- 'data': { 'addr': 'SocketAddress',
+ 'data': { 'addr': 'SocketAddressLegacy',
'*tls-creds': 'str'} }
##
diff --git a/qapi/qapi-clone-visitor.c b/qapi/qapi-clone-visitor.c
index 34086cbfc0..de756bfb33 100644
--- a/qapi/qapi-clone-visitor.c
+++ b/qapi/qapi-clone-visitor.c
@@ -180,3 +180,16 @@ void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *,
visit_free(v);
return dst;
}
+
+void qapi_clone_members(void *dst, const void *src, size_t sz,
+ void (*visit_type_members)(Visitor *, void *,
+ Error **))
+{
+ Visitor *v;
+
+ v = qapi_clone_visitor_new();
+ memcpy(dst, src, sz);
+ to_qcv(v)->depth++;
+ visit_type_members(v, dst, &error_abort);
+ visit_free(v);
+}
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index dc502129d8..5ad36f8a09 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -30,7 +30,7 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
dict = qobject_to_qdict(request);
if (!dict) {
- error_setg(errp, "Expected '%s' in QMP input", "object");
+ error_setg(errp, "QMP input must be a JSON object");
return NULL;
}
@@ -41,26 +41,26 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
if (!strcmp(arg_name, "execute")) {
if (qobject_type(arg_obj) != QTYPE_QSTRING) {
- error_setg(errp, "QMP input object member '%s' expects '%s'",
- "execute", "string");
+ error_setg(errp,
+ "QMP input member 'execute' must be a string");
return NULL;
}
has_exec_key = true;
} else if (!strcmp(arg_name, "arguments")) {
if (qobject_type(arg_obj) != QTYPE_QDICT) {
- error_setg(errp, "QMP input object member '%s' expects '%s'",
- "arguments", "object");
+ error_setg(errp,
+ "QMP input member 'arguments' must be an object");
return NULL;
}
} else {
- error_setg(errp, "QMP input object member '%s' is unexpected",
+ error_setg(errp, "QMP input member '%s' is unexpected",
arg_name);
return NULL;
}
}
if (!has_exec_key) {
- error_setg(errp, "Expected '%s' in QMP input", "execute");
+ error_setg(errp, "QMP input lacks member 'execute'");
return NULL;
}
diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c
index 802ede48e3..ba3029cc89 100644
--- a/qapi/qmp-event.c
+++ b/qapi/qmp-event.c
@@ -51,7 +51,7 @@ static void timestamp_put(QDict *qdict)
QDict *qmp_event_build_dict(const char *event_name)
{
QDict *dict = qdict_new();
- qdict_put(dict, "event", qstring_from_str(event_name));
+ qdict_put_str(dict, "event", event_name);
timestamp_put(dict);
return dict;
}
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 865e948ac0..d0f0002317 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -55,6 +55,17 @@ static QObjectInputVisitor *to_qiv(Visitor *v)
return container_of(v, QObjectInputVisitor, visitor);
}
+/*
+ * Find the full name of something @qiv is currently visiting.
+ * @qiv is visiting something named @name in the stack of containers
+ * @qiv->stack.
+ * If @n is zero, return its full name.
+ * If @n is positive, return the full name of the @n-th container
+ * counting from the top. The stack of containers must have at least
+ * @n elements.
+ * The returned string is valid until the next full_name_nth(@v) or
+ * destruction of @v.
+ */
static const char *full_name_nth(QObjectInputVisitor *qiv, const char *name,
int n)
{
@@ -280,6 +291,15 @@ static void qobject_input_start_struct(Visitor *v, const char *name, void **obj,
}
}
+static void qobject_input_end_struct(Visitor *v, void **obj)
+{
+ QObjectInputVisitor *qiv = to_qiv(v);
+ StackObject *tos = QSLIST_FIRST(&qiv->stack);
+
+ assert(qobject_type(tos->obj) == QTYPE_QDICT && tos->h);
+ qobject_input_pop(v, obj);
+}
+
static void qobject_input_start_list(Visitor *v, const char *name,
GenericList **list, size_t size,
@@ -335,6 +355,14 @@ static void qobject_input_check_list(Visitor *v, Error **errp)
}
}
+static void qobject_input_end_list(Visitor *v, void **obj)
+{
+ QObjectInputVisitor *qiv = to_qiv(v);
+ StackObject *tos = QSLIST_FIRST(&qiv->stack);
+
+ assert(qobject_type(tos->obj) == QTYPE_QLIST && !tos->h);
+ qobject_input_pop(v, obj);
+}
static void qobject_input_start_alternate(Visitor *v, const char *name,
GenericAlternate **obj, size_t size,
@@ -634,11 +662,11 @@ static QObjectInputVisitor *qobject_input_visitor_base_new(QObject *obj)
v->visitor.type = VISITOR_INPUT;
v->visitor.start_struct = qobject_input_start_struct;
v->visitor.check_struct = qobject_input_check_struct;
- v->visitor.end_struct = qobject_input_pop;
+ v->visitor.end_struct = qobject_input_end_struct;
v->visitor.start_list = qobject_input_start_list;
v->visitor.next_list = qobject_input_next_list;
v->visitor.check_list = qobject_input_check_list;
- v->visitor.end_list = qobject_input_pop;
+ v->visitor.end_list = qobject_input_end_list;
v->visitor.start_alternate = qobject_input_start_alternate;
v->visitor.optional = qobject_input_optional;
v->visitor.free = qobject_input_free;
diff --git a/qemu-img.c b/qemu-img.c
index c7196362df..f3b0ab49cc 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -313,7 +313,7 @@ static BlockBackend *img_open_file(const char *filename,
if (fmt) {
options = qdict_new();
- qdict_put(options, "driver", qstring_from_str(fmt));
+ qdict_put_str(options, "driver", fmt);
}
blk = blk_new_open(filename, NULL, options, flags, &local_err);
@@ -3094,7 +3094,7 @@ static int img_rebase(int argc, char **argv)
if (bs->backing_format[0] != '\0') {
options = qdict_new();
- qdict_put(options, "driver", qstring_from_str(bs->backing_format));
+ qdict_put_str(options, "driver", bs->backing_format);
}
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
@@ -3111,7 +3111,7 @@ static int img_rebase(int argc, char **argv)
if (out_baseimg[0]) {
if (out_basefmt) {
options = qdict_new();
- qdict_put(options, "driver", qstring_from_str(out_basefmt));
+ qdict_put_str(options, "driver", out_basefmt);
} else {
options = NULL;
}
diff --git a/qemu-io.c b/qemu-io.c
index 427cbaef57..ed0e2dceaa 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -601,7 +601,7 @@ int main(int argc, char **argv)
} else {
if (format) {
opts = qdict_new();
- qdict_put(opts, "driver", qstring_from_str(format));
+ qdict_put_str(opts, "driver", format);
}
if (openfile(argv[optind], flags, writethrough, opts)) {
exit(1);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index e080fb7c75..b7ab86bfa7 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -395,13 +395,12 @@ static SocketAddress *nbd_build_socket_address(const char *sockpath,
saddr = g_new0(SocketAddress, 1);
if (sockpath) {
- saddr->type = SOCKET_ADDRESS_KIND_UNIX;
- saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- saddr->u.q_unix.data->path = g_strdup(sockpath);
+ saddr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ saddr->u.q_unix.path = g_strdup(sockpath);
} else {
InetSocketAddress *inet;
- saddr->type = SOCKET_ADDRESS_KIND_INET;
- inet = saddr->u.inet.data = g_new0(InetSocketAddress, 1);
+ saddr->type = SOCKET_ADDRESS_TYPE_INET;
+ inet = &saddr->u.inet;
inet->host = g_strdup(bindto);
if (port) {
inet->port = g_strdup(port);
@@ -959,7 +958,7 @@ int main(int argc, char **argv)
} else {
if (fmt) {
options = qdict_new();
- qdict_put(options, "driver", qstring_from_str(fmt));
+ qdict_put_str(options, "driver", fmt);
}
blk = blk_new_open(srcpath, NULL, options, flags, &local_err);
}
diff --git a/qga/main.c b/qga/main.c
index ad6f68f187..cc58d2b53d 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -1388,9 +1388,9 @@ int main(int argc, char **argv)
addr = socket_local_address(FIRST_SOCKET_ACTIVATION_FD, NULL);
if (addr) {
- if (addr->type == SOCKET_ADDRESS_KIND_UNIX) {
+ if (addr->type == SOCKET_ADDRESS_TYPE_UNIX) {
config->method = g_strdup("unix-listen");
- } else if (addr->type == SOCKET_ADDRESS_KIND_VSOCK) {
+ } else if (addr->type == SOCKET_ADDRESS_TYPE_VSOCK) {
config->method = g_strdup("vsock-listen");
}
diff --git a/qobject/qdict.c b/qobject/qdict.c
index 291eef1a19..88e2ecd658 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -463,7 +463,7 @@ void qdict_set_default_str(QDict *dst, const char *key, const char *val)
return;
}
- qdict_put(dst, key, qstring_from_str(val));
+ qdict_put_str(dst, key, val);
}
static void qdict_flatten_qdict(QDict *qdict, QDict *target,
diff --git a/scripts/coccinelle/qobject.cocci b/scripts/coccinelle/qobject.cocci
new file mode 100644
index 0000000000..97703a438b
--- /dev/null
+++ b/scripts/coccinelle/qobject.cocci
@@ -0,0 +1,35 @@
+// Use QDict macros where they make sense
+@@
+expression Obj, Key, E;
+@@
+(
+- qdict_put_obj(Obj, Key, QOBJECT(E));
++ qdict_put(Obj, Key, E);
+|
+- qdict_put(Obj, Key, qint_from_int(E));
++ qdict_put_int(Obj, Key, E);
+|
+- qdict_put(Obj, Key, qbool_from_bool(E));
++ qdict_put_bool(Obj, Key, E);
+|
+- qdict_put(Obj, Key, qstring_from_str(E));
++ qdict_put_str(Obj, Key, E);
+)
+
+// Use QList macros where they make sense
+@@
+expression Obj, E;
+@@
+(
+- qlist_append_obj(Obj, QOBJECT(E));
++ qlist_append(Obj, E);
+|
+- qlist_append(Obj, qint_from_int(E));
++ qlist_append_int(Obj, E);
+|
+- qlist_append(Obj, qbool_from_bool(E));
++ qlist_append_bool(Obj, E);
+|
+- qlist_append(Obj, qstring_from_str(E));
++ qlist_append_str(Obj, E);
+)
diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index eccb88a4e8..860ffb27f2 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -70,6 +70,9 @@ import json
import ast
import readline
import sys
+import os
+import errno
+import atexit
class QMPCompleter(list):
def complete(self, text, state):
@@ -109,6 +112,8 @@ class QMPShell(qmp.QEMUMonitorProtocol):
self._pretty = pretty
self._transmode = False
self._actions = list()
+ self._histfile = os.path.join(os.path.expanduser('~'),
+ '.qmp-shell_history')
def __get_address(self, arg):
"""
@@ -126,17 +131,36 @@ class QMPShell(qmp.QEMUMonitorProtocol):
return arg
def _fill_completion(self):
- for cmd in self.cmd('query-commands')['return']:
+ cmds = self.cmd('query-commands')
+ if cmds.has_key('error'):
+ return
+ for cmd in cmds['return']:
self._completer.append(cmd['name'])
def __completer_setup(self):
self._completer = QMPCompleter()
self._fill_completion()
+ readline.set_history_length(1024)
readline.set_completer(self._completer.complete)
readline.parse_and_bind("tab: complete")
# XXX: default delimiters conflict with some command names (eg. query-),
# clearing everything as it doesn't seem to matter
readline.set_completer_delims('')
+ try:
+ readline.read_history_file(self._histfile)
+ except Exception as e:
+ if isinstance(e, IOError) and e.errno == errno.ENOENT:
+ # File not found. No problem.
+ pass
+ else:
+ print "Failed to read history '%s'; %s" % (self._histfile, e)
+ atexit.register(self.__save_history)
+
+ def __save_history(self):
+ try:
+ readline.write_history_file(self._histfile)
+ except Exception as e:
+ print "Failed to save history file '%s'; %s" % (self._histfile, e)
def __parse_value(self, val):
try:
@@ -256,12 +280,15 @@ class QMPShell(qmp.QEMUMonitorProtocol):
self._print(resp)
return True
- def connect(self):
- self._greeting = qmp.QEMUMonitorProtocol.connect(self)
+ def connect(self, negotiate):
+ self._greeting = qmp.QEMUMonitorProtocol.connect(self, negotiate)
self.__completer_setup()
def show_banner(self, msg='Welcome to the QMP low-level shell!'):
print msg
+ if not self._greeting:
+ print 'Connected'
+ return
version = self._greeting['QMP']['version']['qemu']
print 'Connected to QEMU %d.%d.%d\n' % (version['major'],version['minor'],version['micro'])
@@ -369,7 +396,11 @@ def die(msg):
def fail_cmdline(option=None):
if option:
sys.stderr.write('ERROR: bad command-line option \'%s\'\n' % option)
- sys.stderr.write('qemu-shell [ -v ] [ -p ] [ -H ] < UNIX socket path> | < TCP address:port >\n')
+ sys.stderr.write('qmp-shell [ -v ] [ -p ] [ -H ] [ -N ] < UNIX socket path> | < TCP address:port >\n')
+ sys.stderr.write(' -v Verbose (echo command sent and received)\n')
+ sys.stderr.write(' -p Pretty-print JSON\n')
+ sys.stderr.write(' -H Use HMP interface\n')
+ sys.stderr.write(' -N Skip negotiate (for qemu-ga)\n')
sys.exit(1)
def main():
@@ -378,6 +409,7 @@ def main():
hmp = False
pretty = False
verbose = False
+ negotiate = True
try:
for arg in sys.argv[1:]:
@@ -387,6 +419,8 @@ def main():
hmp = True
elif arg == "-p":
pretty = True
+ elif arg == "-N":
+ negotiate = False
elif arg == "-v":
verbose = True
else:
@@ -404,7 +438,7 @@ def main():
die('bad port number in command-line')
try:
- qemu.connect()
+ qemu.connect(negotiate)
except qmp.QMPConnectError:
die('Didn\'t get QMP greeting message')
except qmp.QMPCapabilitiesError:
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index ce461cc905..8d27363b07 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -376,12 +376,12 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
static void qdict_add_disabled_feat(const char *name, void *opaque)
{
- qdict_put(opaque, name, qbool_from_bool(false));
+ qdict_put_bool(opaque, name, false);
}
static void qdict_add_enabled_feat(const char *name, void *opaque)
{
- qdict_put(opaque, name, qbool_from_bool(true));
+ qdict_put_bool(opaque, name, true);
}
/* convert S390CPUDef into a static CpuModelInfo */
diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index 81162ee572..be8d81f07b 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -47,7 +47,7 @@ static void qdict_put_obj_test(void)
qdict = qdict_new();
// key "" will have tdb hash 12345
- qdict_put_obj(qdict, "", QOBJECT(qint_from_int(num)));
+ qdict_put_int(qdict, "", num);
g_assert(qdict_size(qdict) == 1);
ent = QLIST_FIRST(&qdict->table[12345 % QDICT_BUCKET_MAX]);
@@ -66,8 +66,8 @@ static void qdict_destroy_simple_test(void)
QDict *qdict;
qdict = qdict_new();
- qdict_put_obj(qdict, "num", QOBJECT(qint_from_int(0)));
- qdict_put_obj(qdict, "str", QOBJECT(qstring_from_str("foo")));
+ qdict_put_int(qdict, "num", 0);
+ qdict_put_str(qdict, "str", "foo");
QDECREF(qdict);
}
@@ -80,7 +80,7 @@ static void qdict_get_test(void)
const char *key = "test";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(value));
+ qdict_put_int(tests_dict, key, value);
obj = qdict_get(tests_dict, key);
g_assert(obj != NULL);
@@ -98,7 +98,7 @@ static void qdict_get_int_test(void)
const char *key = "int";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(value));
+ qdict_put_int(tests_dict, key, value);
ret = qdict_get_int(tests_dict, key);
g_assert(ret == value);
@@ -113,7 +113,7 @@ static void qdict_get_try_int_test(void)
const char *key = "int";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(value));
+ qdict_put_int(tests_dict, key, value);
ret = qdict_get_try_int(tests_dict, key, 0);
g_assert(ret == value);
@@ -128,7 +128,7 @@ static void qdict_get_str_test(void)
const char *str = "string";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qstring_from_str(str));
+ qdict_put_str(tests_dict, key, str);
p = qdict_get_str(tests_dict, key);
g_assert(p != NULL);
@@ -144,7 +144,7 @@ static void qdict_get_try_str_test(void)
const char *str = "string";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qstring_from_str(str));
+ qdict_put_str(tests_dict, key, str);
p = qdict_get_try_str(tests_dict, key);
g_assert(p != NULL);
@@ -188,7 +188,7 @@ static void qdict_haskey_test(void)
const char *key = "test";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(0));
+ qdict_put_int(tests_dict, key, 0);
g_assert(qdict_haskey(tests_dict, key) == 1);
QDECREF(tests_dict);
@@ -199,7 +199,7 @@ static void qdict_del_test(void)
const char *key = "key test";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qstring_from_str("foo"));
+ qdict_put_str(tests_dict, key, "foo");
g_assert(qdict_size(tests_dict) == 1);
qdict_del(tests_dict, key);
@@ -226,9 +226,9 @@ static void qdict_iterapi_test(void)
g_assert(qdict_first(tests_dict) == NULL);
- qdict_put(tests_dict, "key1", qint_from_int(1));
- qdict_put(tests_dict, "key2", qint_from_int(2));
- qdict_put(tests_dict, "key3", qint_from_int(3));
+ qdict_put_int(tests_dict, "key1", 1);
+ qdict_put_int(tests_dict, "key2", 2);
+ qdict_put_int(tests_dict, "key3", 3);
count = 0;
for (ent = qdict_first(tests_dict); ent; ent = qdict_next(tests_dict, ent)){
@@ -294,20 +294,20 @@ static void qdict_flatten_test(void)
* }
*/
- qdict_put(dict1, "a", qint_from_int(0));
- qdict_put(dict1, "b", qint_from_int(1));
+ qdict_put_int(dict1, "a", 0);
+ qdict_put_int(dict1, "b", 1);
- qlist_append_obj(list1, QOBJECT(qint_from_int(23)));
- qlist_append_obj(list1, QOBJECT(qint_from_int(66)));
- qlist_append_obj(list1, QOBJECT(dict1));
- qlist_append_obj(list2, QOBJECT(qint_from_int(42)));
- qlist_append_obj(list2, QOBJECT(list1));
+ qlist_append_int(list1, 23);
+ qlist_append_int(list1, 66);
+ qlist_append(list1, dict1);
+ qlist_append_int(list2, 42);
+ qlist_append(list2, list1);
- qdict_put(dict2, "c", qint_from_int(2));
- qdict_put(dict2, "d", qint_from_int(3));
- qdict_put_obj(dict3, "e", QOBJECT(list2));
- qdict_put_obj(dict3, "f", QOBJECT(dict2));
- qdict_put(dict3, "g", qint_from_int(4));
+ qdict_put_int(dict2, "c", 2);
+ qdict_put_int(dict2, "d", 3);
+ qdict_put(dict3, "e", list2);
+ qdict_put(dict3, "f", dict2);
+ qdict_put_int(dict3, "g", 4);
qdict_flatten(dict3);
@@ -369,12 +369,12 @@ static void qdict_array_split_test(void)
* This example is given in the comment of qdict_array_split().
*/
- qdict_put(test_dict, "1.x", qint_from_int(0));
- qdict_put(test_dict, "4.y", qint_from_int(1));
- qdict_put(test_dict, "0.a", qint_from_int(42));
- qdict_put(test_dict, "o.o", qint_from_int(7));
- qdict_put(test_dict, "0.b", qint_from_int(23));
- qdict_put(test_dict, "2", qint_from_int(66));
+ qdict_put_int(test_dict, "1.x", 0);
+ qdict_put_int(test_dict, "4.y", 1);
+ qdict_put_int(test_dict, "0.a", 42);
+ qdict_put_int(test_dict, "o.o", 7);
+ qdict_put_int(test_dict, "0.b", 23);
+ qdict_put_int(test_dict, "2", 66);
qdict_array_split(test_dict, &test_list);
@@ -441,9 +441,9 @@ static void qdict_array_split_test(void)
test_dict = qdict_new();
- qdict_put(test_dict, "0", qint_from_int(42));
- qdict_put(test_dict, "1", qint_from_int(23));
- qdict_put(test_dict, "1.x", qint_from_int(84));
+ qdict_put_int(test_dict, "0", 42);
+ qdict_put_int(test_dict, "1", 23);
+ qdict_put_int(test_dict, "1.x", 84);
qdict_array_split(test_dict, &test_list);
@@ -472,38 +472,38 @@ static void qdict_array_entries_test(void)
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
- qdict_put(dict, "bar", qint_from_int(0));
- qdict_put(dict, "baz.0", qint_from_int(0));
+ qdict_put_int(dict, "bar", 0);
+ qdict_put_int(dict, "baz.0", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
- qdict_put(dict, "foo.1", qint_from_int(0));
+ qdict_put_int(dict, "foo.1", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
- qdict_put(dict, "foo.0", qint_from_int(0));
+ qdict_put_int(dict, "foo.0", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 2);
- qdict_put(dict, "foo.bar", qint_from_int(0));
+ qdict_put_int(dict, "foo.bar", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
qdict_del(dict, "foo.bar");
- qdict_put(dict, "foo.2.a", qint_from_int(0));
- qdict_put(dict, "foo.2.b", qint_from_int(0));
- qdict_put(dict, "foo.2.c", qint_from_int(0));
+ qdict_put_int(dict, "foo.2.a", 0);
+ qdict_put_int(dict, "foo.2.b", 0);
+ qdict_put_int(dict, "foo.2.c", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 3);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
QDECREF(dict);
dict = qdict_new();
- qdict_put(dict, "1", qint_from_int(0));
+ qdict_put_int(dict, "1", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
- qdict_put(dict, "0", qint_from_int(0));
+ qdict_put_int(dict, "0", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 2);
- qdict_put(dict, "bar", qint_from_int(0));
+ qdict_put_int(dict, "bar", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
qdict_del(dict, "bar");
- qdict_put(dict, "2.a", qint_from_int(0));
- qdict_put(dict, "2.b", qint_from_int(0));
- qdict_put(dict, "2.c", qint_from_int(0));
+ qdict_put_int(dict, "2.a", 0);
+ qdict_put_int(dict, "2.b", 0);
+ qdict_put_int(dict, "2.c", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3);
QDECREF(dict);
@@ -529,7 +529,7 @@ static void qdict_join_test(void)
/* First iteration: Test movement */
/* Second iteration: Test empty source and non-empty destination */
- qdict_put(dict2, "foo", qint_from_int(42));
+ qdict_put_int(dict2, "foo", 42);
for (i = 0; i < 2; i++) {
qdict_join(dict1, dict2, overwrite);
@@ -541,7 +541,7 @@ static void qdict_join_test(void)
}
/* Test non-empty source and destination without conflict */
- qdict_put(dict2, "bar", qint_from_int(23));
+ qdict_put_int(dict2, "bar", 23);
qdict_join(dict1, dict2, overwrite);
@@ -552,14 +552,14 @@ static void qdict_join_test(void)
g_assert(qdict_get_int(dict1, "bar") == 23);
/* Test conflict */
- qdict_put(dict2, "foo", qint_from_int(84));
+ qdict_put_int(dict2, "foo", 84);
qdict_join(dict1, dict2, overwrite);
g_assert(qdict_size(dict1) == 2);
g_assert(qdict_size(dict2) == !overwrite);
- g_assert(qdict_get_int(dict1, "foo") == overwrite ? 84 : 42);
+ g_assert(qdict_get_int(dict1, "foo") == (overwrite ? 84 : 42));
g_assert(qdict_get_int(dict1, "bar") == 23);
if (!overwrite) {
@@ -594,15 +594,15 @@ static void qdict_crumple_test_recursive(void)
QList *rules;
src = qdict_new();
- qdict_put(src, "vnc.listen.addr", qstring_from_str("127.0.0.1"));
- qdict_put(src, "vnc.listen.port", qstring_from_str("5901"));
- qdict_put(src, "vnc.acl.rules.0.match", qstring_from_str("fred"));
- qdict_put(src, "vnc.acl.rules.0.policy", qstring_from_str("allow"));
- qdict_put(src, "vnc.acl.rules.1.match", qstring_from_str("bob"));
- qdict_put(src, "vnc.acl.rules.1.policy", qstring_from_str("deny"));
- qdict_put(src, "vnc.acl.default", qstring_from_str("deny"));
- qdict_put(src, "vnc.acl..name", qstring_from_str("acl0"));
- qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0"));
+ qdict_put_str(src, "vnc.listen.addr", "127.0.0.1");
+ qdict_put_str(src, "vnc.listen.port", "5901");
+ qdict_put_str(src, "vnc.acl.rules.0.match", "fred");
+ qdict_put_str(src, "vnc.acl.rules.0.policy", "allow");
+ qdict_put_str(src, "vnc.acl.rules.1.match", "bob");
+ qdict_put_str(src, "vnc.acl.rules.1.policy", "deny");
+ qdict_put_str(src, "vnc.acl.default", "deny");
+ qdict_put_str(src, "vnc.acl..name", "acl0");
+ qdict_put_str(src, "vnc.acl.rule..name", "acl0");
dst = qobject_to_qdict(qdict_crumple(src, &error_abort));
g_assert(dst);
@@ -669,8 +669,8 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* rule.0 can't be both a string and a dict */
- qdict_put(src, "rule.0", qstring_from_str("fred"));
- qdict_put(src, "rule.0.policy", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.0", "fred");
+ qdict_put_str(src, "rule.0.policy", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -680,8 +680,8 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* rule can't be both a list and a dict */
- qdict_put(src, "rule.0", qstring_from_str("fred"));
- qdict_put(src, "rule.a", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.0", "fred");
+ qdict_put_str(src, "rule.a", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -692,7 +692,7 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* The input should be flat, ie no dicts or lists */
qdict_put(src, "rule.a", qdict_new());
- qdict_put(src, "rule.b", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.b", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -702,8 +702,8 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* List indexes must not have gaps */
- qdict_put(src, "rule.0", qstring_from_str("deny"));
- qdict_put(src, "rule.3", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.0", "deny");
+ qdict_put_str(src, "rule.3", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -713,8 +713,8 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* List indexes must be in %zu format */
- qdict_put(src, "rule.0", qstring_from_str("deny"));
- qdict_put(src, "rule.+1", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.0", "deny");
+ qdict_put_str(src, "rule.+1", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -733,8 +733,8 @@ static void qdict_put_exists_test(void)
const char *key = "exists";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(1));
- qdict_put(tests_dict, key, qint_from_int(2));
+ qdict_put_int(tests_dict, key, 1);
+ qdict_put_int(tests_dict, key, 2);
value = qdict_get_int(tests_dict, key);
g_assert(value == 2);
diff --git a/tests/check-qlist.c b/tests/check-qlist.c
index e16da5e5c6..4983867c27 100644
--- a/tests/check-qlist.c
+++ b/tests/check-qlist.c
@@ -74,7 +74,7 @@ static void qlist_destroy_test(void)
qlist = qlist_new();
for (i = 0; i < 42; i++)
- qlist_append(qlist, qint_from_int(i));
+ qlist_append_int(qlist, i);
QDECREF(qlist);
}
@@ -103,7 +103,7 @@ static void qlist_iter_test(void)
qlist = qlist_new();
for (i = 0; i < iter_max; i++)
- qlist_append(qlist, qint_from_int(i));
+ qlist_append_int(qlist, i);
iter_called = 0;
qlist_iter(qlist, iter_func, NULL);
diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c
index c5637cc406..b1abb2ad89 100644
--- a/tests/device-introspect-test.c
+++ b/tests/device-introspect-test.c
@@ -32,9 +32,9 @@ static QList *qom_list_types(const char *implements, bool abstract)
QList *ret;
QDict *args = qdict_new();
- qdict_put(args, "abstract", qbool_from_bool(abstract));
+ qdict_put_bool(args, "abstract", abstract);
if (implements) {
- qdict_put(args, "implements", qstring_from_str(implements));
+ qdict_put_str(args, "implements", implements);
}
resp = qmp("{'execute': 'qom-list-types',"
" 'arguments': %p }", args);
diff --git a/tests/fdc-test.c b/tests/fdc-test.c
index 738c6b4a5e..325712e0f2 100644
--- a/tests/fdc-test.c
+++ b/tests/fdc-test.c
@@ -298,8 +298,8 @@ static void test_media_insert(void)
/* Insert media in drive. DSKCHK should not be reset until a step pulse
* is sent. */
- qmp_discard_response("{'execute':'change', 'arguments':{"
- " 'device':'floppy0', 'target': %s, 'arg': 'raw' }}",
+ qmp_discard_response("{'execute':'blockdev-change-medium', 'arguments':{"
+ " 'id':'floppy0', 'filename': %s, 'format': 'raw' }}",
test_image);
dir = inb(FLOPPY_BASE + reg_dir);
@@ -330,7 +330,7 @@ static void test_media_change(void)
/* Eject the floppy and check that DSKCHG is set. Reading it out doesn't
* reset the bit. */
qmp_discard_response("{'execute':'eject', 'arguments':{"
- " 'device':'floppy0' }}");
+ " 'id':'floppy0' }}");
dir = inb(FLOPPY_BASE + reg_dir);
assert_bit_set(dir, DSKCHG);
@@ -564,7 +564,7 @@ int main(int argc, char **argv)
/* Run the tests */
g_test_init(&argc, &argv, NULL);
- qtest_start(NULL);
+ qtest_start("-device floppy,id=floppy0");
qtest_irq_intercept_in(global_qtest, "ioapic");
qtest_add_func("/fdc/cmos", test_cmos);
qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 512c150266..84ecbd2bd8 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -446,6 +446,14 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap)
va_list ap_copy;
QObject *qobj;
+ /* qobject_from_jsonv() silently eats leading 0xff as invalid
+ * JSON, but we want to test sending them over the wire to force
+ * resyncs */
+ if (*fmt == '\377') {
+ socket_send(fd, fmt, 1);
+ fmt++;
+ }
+
/* Going through qobject ensures we escape strings properly.
* This seemingly unnecessary copy is required in case va_list
* is an array type.
diff --git a/tests/test-char.c b/tests/test-char.c
index 773a1c36ba..124d0c5439 100644
--- a/tests/test-char.c
+++ b/tests/test-char.c
@@ -291,7 +291,7 @@ static void char_socket_test(void)
Chardev *chr = qemu_chr_new("server", "tcp:127.0.0.1:0,server,nowait");
Chardev *chr_client;
QObject *addr;
- QDict *qdict, *data;
+ QDict *qdict;
const char *port;
SocketIdleData d = { .chr = chr };
CharBackend be;
@@ -306,8 +306,7 @@ static void char_socket_test(void)
addr = object_property_get_qobject(OBJECT(chr), "addr", &error_abort);
qdict = qobject_to_qdict(addr);
- data = qdict_get_qdict(qdict, "data");
- port = qdict_get_str(data, "port");
+ port = qdict_get_str(qdict, "port");
tmp = g_strdup_printf("tcp:127.0.0.1:%s", port);
QDECREF(qdict);
diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c
index c5c131479c..d357cd2a8e 100644
--- a/tests/test-io-channel-socket.c
+++ b/tests/test-io-channel-socket.c
@@ -125,12 +125,12 @@ static void test_io_channel_setup_sync(SocketAddress *listen_addr,
lioc = qio_channel_socket_new();
qio_channel_socket_listen_sync(lioc, listen_addr, &error_abort);
- if (listen_addr->type == SOCKET_ADDRESS_KIND_INET) {
+ if (listen_addr->type == SOCKET_ADDRESS_TYPE_INET) {
SocketAddress *laddr = qio_channel_socket_get_local_address(
lioc, &error_abort);
- g_free(connect_addr->u.inet.data->port);
- connect_addr->u.inet.data->port = g_strdup(laddr->u.inet.data->port);
+ g_free(connect_addr->u.inet.port);
+ connect_addr->u.inet.port = g_strdup(laddr->u.inet.port);
qapi_free_SocketAddress(laddr);
}
@@ -186,12 +186,12 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr,
g_assert(!data.err);
- if (listen_addr->type == SOCKET_ADDRESS_KIND_INET) {
+ if (listen_addr->type == SOCKET_ADDRESS_TYPE_INET) {
SocketAddress *laddr = qio_channel_socket_get_local_address(
lioc, &error_abort);
- g_free(connect_addr->u.inet.data->port);
- connect_addr->u.inet.data->port = g_strdup(laddr->u.inet.data->port);
+ g_free(connect_addr->u.inet.port);
+ connect_addr->u.inet.port = g_strdup(laddr->u.inet.port);
qapi_free_SocketAddress(laddr);
}
@@ -300,16 +300,14 @@ static void test_io_channel_ipv4(bool async)
SocketAddress *listen_addr = g_new0(SocketAddress, 1);
SocketAddress *connect_addr = g_new0(SocketAddress, 1);
- listen_addr->type = SOCKET_ADDRESS_KIND_INET;
- listen_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *listen_addr->u.inet.data = (InetSocketAddress) {
+ listen_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ listen_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("127.0.0.1"),
.port = NULL, /* Auto-select */
};
- connect_addr->type = SOCKET_ADDRESS_KIND_INET;
- connect_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *connect_addr->u.inet.data = (InetSocketAddress) {
+ connect_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ connect_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("127.0.0.1"),
.port = NULL, /* Filled in later */
};
@@ -338,16 +336,14 @@ static void test_io_channel_ipv6(bool async)
SocketAddress *listen_addr = g_new0(SocketAddress, 1);
SocketAddress *connect_addr = g_new0(SocketAddress, 1);
- listen_addr->type = SOCKET_ADDRESS_KIND_INET;
- listen_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *listen_addr->u.inet.data = (InetSocketAddress) {
+ listen_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ listen_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("::1"),
.port = NULL, /* Auto-select */
};
- connect_addr->type = SOCKET_ADDRESS_KIND_INET;
- connect_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *connect_addr->u.inet.data = (InetSocketAddress) {
+ connect_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ connect_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("::1"),
.port = NULL, /* Filled in later */
};
@@ -378,13 +374,11 @@ static void test_io_channel_unix(bool async)
SocketAddress *connect_addr = g_new0(SocketAddress, 1);
#define TEST_SOCKET "test-io-channel-socket.sock"
- listen_addr->type = SOCKET_ADDRESS_KIND_UNIX;
- listen_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- listen_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ listen_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ listen_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
- connect_addr->type = SOCKET_ADDRESS_KIND_UNIX;
- connect_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- connect_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ connect_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ connect_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
test_io_channel(async, listen_addr, connect_addr, true);
@@ -427,13 +421,11 @@ static void test_io_channel_unix_fd_pass(void)
fdsend[1] = testfd;
fdsend[2] = testfd;
- listen_addr->type = SOCKET_ADDRESS_KIND_UNIX;
- listen_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- listen_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ listen_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ listen_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
- connect_addr->type = SOCKET_ADDRESS_KIND_UNIX;
- connect_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- connect_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ connect_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ connect_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst);
diff --git a/tests/test-keyval.c b/tests/test-keyval.c
index ba19560a22..c556b1b117 100644
--- a/tests/test-keyval.c
+++ b/tests/test-keyval.c
@@ -628,6 +628,7 @@ static void test_keyval_visit_alternate(void)
visit_type_AltNumStr(v, "a", &ans, &error_abort);
g_assert_cmpint(ans->type, ==, QTYPE_QSTRING);
g_assert_cmpstr(ans->u.s, ==, "1");
+ qapi_free_AltNumStr(ans);
visit_type_AltNumInt(v, "a", &ani, &err);
error_free_or_abort(&err);
visit_end_struct(v, NULL);
@@ -651,9 +652,12 @@ static void test_keyval_visit_any(void)
g_assert(qlist);
qstr = qobject_to_qstring(qlist_pop(qlist));
g_assert_cmpstr(qstring_get_str(qstr), ==, "null");
+ QDECREF(qstr);
qstr = qobject_to_qstring(qlist_pop(qlist));
g_assert_cmpstr(qstring_get_str(qstr), ==, "1");
g_assert(qlist_empty(qlist));
+ QDECREF(qstr);
+ qobject_decref(any);
visit_check_struct(v, &error_abort);
visit_end_struct(v, NULL);
visit_free(v);
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
index 0ad74b464f..cc1bb1afdf 100644
--- a/tests/test-qemu-opts.c
+++ b/tests/test-qemu-opts.c
@@ -299,7 +299,7 @@ static void test_qemu_opt_get_size(void)
dict = qdict_new();
g_assert(dict != NULL);
- qdict_put(dict, "size1", qstring_from_str("10"));
+ qdict_put_str(dict, "size1", "10");
qemu_opts_absorb_qdict(opts, dict, &error_abort);
g_assert(error_abort == NULL);
@@ -309,7 +309,7 @@ static void test_qemu_opt_get_size(void)
g_assert(opt == 10);
/* reset value */
- qdict_put(dict, "size1", qstring_from_str("15"));
+ qdict_put_str(dict, "size1", "15");
qemu_opts_absorb_qdict(opts, dict, &error_abort);
g_assert(error_abort == NULL);
diff --git a/tests/test-qga.c b/tests/test-qga.c
index c780f0079a..c77f241036 100644
--- a/tests/test-qga.c
+++ b/tests/test-qga.c
@@ -146,14 +146,30 @@ static void test_qga_sync_delimited(gconstpointer fix)
QDict *ret;
gchar *cmd;
- cmd = g_strdup_printf("%c{'execute': 'guest-sync-delimited',"
- " 'arguments': {'id': %u } }", 0xff, r);
+ cmd = g_strdup_printf("\xff{'execute': 'guest-sync-delimited',"
+ " 'arguments': {'id': %u } }", r);
qmp_fd_send(fixture->fd, cmd);
g_free(cmd);
- v = read(fixture->fd, &c, 1);
- g_assert_cmpint(v, ==, 1);
- g_assert_cmpint(c, ==, 0xff);
+ /*
+ * Read and ignore garbage until resynchronized.
+ *
+ * Note that the full reset sequence would involve checking the
+ * response of guest-sync-delimited and repeating the loop if
+ * 'id' field of the response does not match the 'id' field of
+ * the request. Testing this fully would require inserting
+ * garbage in the response stream and is left as a future test
+ * to implement.
+ *
+ * TODO: The server shouldn't emit so much garbage (among other
+ * things, it loudly complains about the client's \xff being
+ * invalid JSON, even though it is a documented part of the
+ * handshake.
+ */
+ do {
+ v = read(fixture->fd, &c, 1);
+ g_assert_cmpint(v, ==, 1);
+ } while (c != 0xff);
ret = qmp_fd_receive(fixture->fd);
g_assert_nonnull(ret);
@@ -172,8 +188,19 @@ static void test_qga_sync(gconstpointer fix)
QDict *ret;
gchar *cmd;
- cmd = g_strdup_printf("%c{'execute': 'guest-sync',"
- " 'arguments': {'id': %u } }", 0xff, r);
+ /*
+ * TODO guest-sync is inherently limited: we cannot distinguish
+ * failure caused by reacting to garbage on the wire prior to this
+ * command, from failure of this actual command. Clients are
+ * supposed to be able to send a raw '\xff' byte to at least
+ * re-synchronize the server's parser prior to this command, but
+ * we are not in a position to test that here because (at least
+ * for now) it causes the server to issue an error message about
+ * invalid JSON. Testing of '\xff' handling is done in
+ * guest-sync-delimited instead.
+ */
+ cmd = g_strdup_printf("{'execute': 'guest-sync',"
+ " 'arguments': {'id': %u } }", r);
ret = qmp_fd(fixture->fd, cmd);
g_free(cmd);
diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c
index 0f81a98be2..acdded4d67 100644
--- a/tests/test-qmp-commands.c
+++ b/tests/test-qmp-commands.c
@@ -94,7 +94,7 @@ static void test_dispatch_cmd(void)
QDict *req = qdict_new();
QObject *resp;
- qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd")));
+ qdict_put_str(req, "execute", "user_def_cmd");
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
@@ -111,7 +111,7 @@ static void test_dispatch_cmd_failure(void)
QDict *args = qdict_new();
QObject *resp;
- qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2")));
+ qdict_put_str(req, "execute", "user_def_cmd2");
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
@@ -122,10 +122,10 @@ static void test_dispatch_cmd_failure(void)
/* check that with extra arguments it throws an error */
req = qdict_new();
- qdict_put(args, "a", qint_from_int(66));
+ qdict_put_int(args, "a", 66);
qdict_put(req, "arguments", args);
- qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd")));
+ qdict_put_str(req, "execute", "user_def_cmd");
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
@@ -164,14 +164,14 @@ static void test_dispatch_cmd_io(void)
QDict *ret_dict_dict2, *ret_dict_dict2_userdef;
QInt *ret3;
- qdict_put_obj(ud1a, "integer", QOBJECT(qint_from_int(42)));
- qdict_put_obj(ud1a, "string", QOBJECT(qstring_from_str("hello")));
- qdict_put_obj(ud1b, "integer", QOBJECT(qint_from_int(422)));
- qdict_put_obj(ud1b, "string", QOBJECT(qstring_from_str("hello2")));
- qdict_put_obj(args, "ud1a", QOBJECT(ud1a));
- qdict_put_obj(args, "ud1b", QOBJECT(ud1b));
- qdict_put_obj(req, "arguments", QOBJECT(args));
- qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2")));
+ qdict_put_int(ud1a, "integer", 42);
+ qdict_put_str(ud1a, "string", "hello");
+ qdict_put_int(ud1b, "integer", 422);
+ qdict_put_str(ud1b, "string", "hello2");
+ qdict_put(args, "ud1a", ud1a);
+ qdict_put(args, "ud1b", ud1b);
+ qdict_put(req, "arguments", args);
+ qdict_put_str(req, "execute", "user_def_cmd2");
ret = qobject_to_qdict(test_qmp_dispatch(req));
@@ -190,9 +190,9 @@ static void test_dispatch_cmd_io(void)
assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4"));
QDECREF(ret);
- qdict_put(args3, "a", qint_from_int(66));
+ qdict_put_int(args3, "a", 66);
qdict_put(req, "arguments", args3);
- qdict_put(req, "execute", qstring_from_str("guest-get-time"));
+ qdict_put_str(req, "execute", "guest-get-time");
ret3 = qobject_to_qint(test_qmp_dispatch(req));
assert(qint_get_int(ret3) == 66);
@@ -244,7 +244,7 @@ static void test_dealloc_partial(void)
Visitor *v;
ud2_dict = qdict_new();
- qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text)));
+ qdict_put_str(ud2_dict, "string0", text);
v = qobject_input_visitor_new(QOBJECT(ud2_dict));
visit_type_UserDefTwo(v, NULL, &ud2, &err);
diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
index 7bb621b027..4c0f09601d 100644
--- a/tests/test-qmp-event.c
+++ b/tests/test-qmp-event.c
@@ -153,7 +153,7 @@ static void test_event_a(TestEventData *data,
{
QDict *d;
d = data->expect;
- qdict_put(d, "event", qstring_from_str("EVENT_A"));
+ qdict_put_str(d, "event", "EVENT_A");
qapi_event_send_event_a(&error_abort);
}
@@ -162,7 +162,7 @@ static void test_event_b(TestEventData *data,
{
QDict *d;
d = data->expect;
- qdict_put(d, "event", qstring_from_str("EVENT_B"));
+ qdict_put_str(d, "event", "EVENT_B");
qapi_event_send_event_b(&error_abort);
}
@@ -177,16 +177,16 @@ static void test_event_c(TestEventData *data,
b.has_enum1 = false;
d_b = qdict_new();
- qdict_put(d_b, "integer", qint_from_int(2));
- qdict_put(d_b, "string", qstring_from_str("test1"));
+ qdict_put_int(d_b, "integer", 2);
+ qdict_put_str(d_b, "string", "test1");
d_data = qdict_new();
- qdict_put(d_data, "a", qint_from_int(1));
+ qdict_put_int(d_data, "a", 1);
qdict_put(d_data, "b", d_b);
- qdict_put(d_data, "c", qstring_from_str("test2"));
+ qdict_put_str(d_data, "c", "test2");
d = data->expect;
- qdict_put(d, "event", qstring_from_str("EVENT_C"));
+ qdict_put_str(d, "event", "EVENT_C");
qdict_put(d, "data", d_data);
qapi_event_send_event_c(true, 1, true, &b, "test2", &error_abort);
@@ -213,22 +213,22 @@ static void test_event_d(TestEventData *data,
a.enum2 = ENUM_ONE_VALUE2;
d_struct1 = qdict_new();
- qdict_put(d_struct1, "integer", qint_from_int(2));
- qdict_put(d_struct1, "string", qstring_from_str("test1"));
- qdict_put(d_struct1, "enum1", qstring_from_str("value1"));
+ qdict_put_int(d_struct1, "integer", 2);
+ qdict_put_str(d_struct1, "string", "test1");
+ qdict_put_str(d_struct1, "enum1", "value1");
d_a = qdict_new();
qdict_put(d_a, "struct1", d_struct1);
- qdict_put(d_a, "string", qstring_from_str("test2"));
- qdict_put(d_a, "enum2", qstring_from_str("value2"));
+ qdict_put_str(d_a, "string", "test2");
+ qdict_put_str(d_a, "enum2", "value2");
d_data = qdict_new();
qdict_put(d_data, "a", d_a);
- qdict_put(d_data, "b", qstring_from_str("test3"));
- qdict_put(d_data, "enum3", qstring_from_str("value3"));
+ qdict_put_str(d_data, "b", "test3");
+ qdict_put_str(d_data, "enum3", "value3");
d = data->expect;
- qdict_put(d, "event", qstring_from_str("EVENT_D"));
+ qdict_put_str(d, "event", "EVENT_D");
qdict_put(d, "data", d_data);
qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE3,
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c
index c213fceeb3..94b9518e40 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -343,9 +343,9 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
visitor_reset(data);
qdict = qdict_new();
- qdict_put(qdict, "integer", qint_from_int(-42));
- qdict_put(qdict, "boolean", qbool_from_bool(true));
- qdict_put(qdict, "string", qstring_from_str("foo"));
+ qdict_put_int(qdict, "integer", -42);
+ qdict_put_bool(qdict, "boolean", true);
+ qdict_put_str(qdict, "string", "foo");
qobj = QOBJECT(qdict);
visit_type_any(data->ov, NULL, &qobj, &error_abort);
qobject_decref(qobj);
diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c
index 5ae29c14cf..3ade4a4918 100644
--- a/ui/vnc-auth-sasl.c
+++ b/ui/vnc-auth-sasl.c
@@ -510,12 +510,11 @@ vnc_socket_ip_addr_string(QIOChannelSocket *ioc,
return NULL;
}
- if (addr->type != SOCKET_ADDRESS_KIND_INET) {
+ if (addr->type != SOCKET_ADDRESS_TYPE_INET) {
error_setg(errp, "Not an inet socket type");
return NULL;
}
- ret = g_strdup_printf("%s;%s", addr->u.inet.data->host,
- addr->u.inet.data->port);
+ ret = g_strdup_printf("%s;%s", addr->u.inet.host, addr->u.inet.port);
qapi_free_SocketAddress(addr);
return ret;
}
diff --git a/ui/vnc.c b/ui/vnc.c
index 349cfc9d86..9c4edcdbf5 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -113,26 +113,26 @@ static void vnc_init_basic_info(SocketAddress *addr,
Error **errp)
{
switch (addr->type) {
- case SOCKET_ADDRESS_KIND_INET:
- info->host = g_strdup(addr->u.inet.data->host);
- info->service = g_strdup(addr->u.inet.data->port);
- if (addr->u.inet.data->ipv6) {
+ case SOCKET_ADDRESS_TYPE_INET:
+ info->host = g_strdup(addr->u.inet.host);
+ info->service = g_strdup(addr->u.inet.port);
+ if (addr->u.inet.ipv6) {
info->family = NETWORK_ADDRESS_FAMILY_IPV6;
} else {
info->family = NETWORK_ADDRESS_FAMILY_IPV4;
}
break;
- case SOCKET_ADDRESS_KIND_UNIX:
+ case SOCKET_ADDRESS_TYPE_UNIX:
info->host = g_strdup("");
- info->service = g_strdup(addr->u.q_unix.data->path);
+ info->service = g_strdup(addr->u.q_unix.path);
info->family = NETWORK_ADDRESS_FAMILY_UNIX;
break;
- case SOCKET_ADDRESS_KIND_VSOCK:
- case SOCKET_ADDRESS_KIND_FD:
+ case SOCKET_ADDRESS_TYPE_VSOCK:
+ case SOCKET_ADDRESS_TYPE_FD:
error_setg(errp, "Unsupported socket address type %s",
- SocketAddressKind_lookup[addr->type]);
+ SocketAddressType_lookup[addr->type]);
break;
default:
abort();
@@ -398,26 +398,26 @@ VncInfo *qmp_query_vnc(Error **errp)
}
switch (addr->type) {
- case SOCKET_ADDRESS_KIND_INET:
- info->host = g_strdup(addr->u.inet.data->host);
- info->service = g_strdup(addr->u.inet.data->port);
- if (addr->u.inet.data->ipv6) {
+ case SOCKET_ADDRESS_TYPE_INET:
+ info->host = g_strdup(addr->u.inet.host);
+ info->service = g_strdup(addr->u.inet.port);
+ if (addr->u.inet.ipv6) {
info->family = NETWORK_ADDRESS_FAMILY_IPV6;
} else {
info->family = NETWORK_ADDRESS_FAMILY_IPV4;
}
break;
- case SOCKET_ADDRESS_KIND_UNIX:
+ case SOCKET_ADDRESS_TYPE_UNIX:
info->host = g_strdup("");
- info->service = g_strdup(addr->u.q_unix.data->path);
+ info->service = g_strdup(addr->u.q_unix.path);
info->family = NETWORK_ADDRESS_FAMILY_UNIX;
break;
- case SOCKET_ADDRESS_KIND_VSOCK:
- case SOCKET_ADDRESS_KIND_FD:
+ case SOCKET_ADDRESS_TYPE_VSOCK:
+ case SOCKET_ADDRESS_TYPE_FD:
error_setg(errp, "Unsupported socket address type %s",
- SocketAddressKind_lookup[addr->type]);
+ SocketAddressType_lookup[addr->type]);
goto out_error;
default:
abort();
@@ -3161,13 +3161,13 @@ static void vnc_display_print_local_addr(VncDisplay *vd)
return;
}
- if (addr->type != SOCKET_ADDRESS_KIND_INET) {
+ if (addr->type != SOCKET_ADDRESS_TYPE_INET) {
qapi_free_SocketAddress(addr);
return;
}
error_printf_unless_qmp("VNC server running on %s:%s\n",
- addr->u.inet.data->host,
- addr->u.inet.data->port);
+ addr->u.inet.host,
+ addr->u.inet.port);
qapi_free_SocketAddress(addr);
}
@@ -3423,9 +3423,8 @@ static int vnc_display_get_address(const char *addrstr,
addr = g_new0(SocketAddress, 1);
if (strncmp(addrstr, "unix:", 5) == 0) {
- addr->type = SOCKET_ADDRESS_KIND_UNIX;
- addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- addr->u.q_unix.data->path = g_strdup(addrstr + 5);
+ addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ addr->u.q_unix.path = g_strdup(addrstr + 5);
if (websocket) {
error_setg(errp, "UNIX sockets not supported with websock");
@@ -3461,8 +3460,8 @@ static int vnc_display_get_address(const char *addrstr,
}
}
- addr->type = SOCKET_ADDRESS_KIND_INET;
- inet = addr->u.inet.data = g_new0(InetSocketAddress, 1);
+ addr->type = SOCKET_ADDRESS_TYPE_INET;
+ inet = &addr->u.inet;
if (addrstr[0] == '[' && addrstr[hostlen - 1] == ']') {
inet->host = g_strndup(addrstr + 1, hostlen - 2);
} else {
@@ -3601,13 +3600,12 @@ static int vnc_display_get_addresses(QemuOpts *opts,
* address for websocket too
*/
if (*retnsaddr == 1 &&
- (*retsaddr)[0]->type == SOCKET_ADDRESS_KIND_INET &&
- wsaddr->type == SOCKET_ADDRESS_KIND_INET &&
- g_str_equal(wsaddr->u.inet.data->host, "") &&
- !g_str_equal((*retsaddr)[0]->u.inet.data->host, "")) {
- g_free(wsaddr->u.inet.data->host);
- wsaddr->u.inet.data->host =
- g_strdup((*retsaddr)[0]->u.inet.data->host);
+ (*retsaddr)[0]->type == SOCKET_ADDRESS_TYPE_INET &&
+ wsaddr->type == SOCKET_ADDRESS_TYPE_INET &&
+ g_str_equal(wsaddr->u.inet.host, "") &&
+ !g_str_equal((*retsaddr)[0]->u.inet.host, "")) {
+ g_free(wsaddr->u.inet.host);
+ wsaddr->u.inet.host = g_strdup((*retsaddr)[0]->u.inet.host);
}
*retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1);
@@ -3648,8 +3646,8 @@ static int vnc_display_connect(VncDisplay *vd,
error_setg(errp, "Expected a single address in reverse mode");
return -1;
}
- /* TODO SOCKET_ADDRESS_KIND_FD when fd has AF_UNIX */
- vd->is_unix = saddr[0]->type == SOCKET_ADDRESS_KIND_UNIX;
+ /* TODO SOCKET_ADDRESS_TYPE_FD when fd has AF_UNIX */
+ vd->is_unix = saddr[0]->type == SOCKET_ADDRESS_TYPE_UNIX;
sioc = qio_channel_socket_new();
qio_channel_set_name(QIO_CHANNEL(sioc), "vnc-reverse");
if (qio_channel_socket_connect_sync(sioc, saddr[0], errp) < 0) {
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 5ce1b5c246..5977bfc3e9 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1054,17 +1054,15 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp)
QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict)
{
QemuOpt *opt;
- QObject *val;
if (!qdict) {
qdict = qdict_new();
}
if (opts->id) {
- qdict_put(qdict, "id", qstring_from_str(opts->id));
+ qdict_put_str(qdict, "id", opts->id);
}
QTAILQ_FOREACH(opt, &opts->head, next) {
- val = QOBJECT(qstring_from_str(opt->str));
- qdict_put_obj(qdict, opt->name, val);
+ qdict_put_str(qdict, opt->name, opt->str);
}
return qdict;
}
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 8188d9a8d7..d8183f79d7 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -22,6 +22,7 @@
#endif /* CONFIG_AF_VSOCK */
#include "monitor/monitor.h"
+#include "qapi/clone-visitor.h"
#include "qapi/error.h"
#include "qemu/sockets.h"
#include "qemu/main-loop.h"
@@ -578,16 +579,15 @@ err:
}
/* compatibility wrapper */
-InetSocketAddress *inet_parse(const char *str, Error **errp)
+int inet_parse(InetSocketAddress *addr, const char *str, Error **errp)
{
- InetSocketAddress *addr;
const char *optstr, *h;
char host[65];
char port[33];
int to;
int pos;
- addr = g_new0(InetSocketAddress, 1);
+ memset(addr, 0, sizeof(*addr));
/* parse address */
if (str[0] == ':') {
@@ -595,20 +595,20 @@ InetSocketAddress *inet_parse(const char *str, Error **errp)
host[0] = '\0';
if (sscanf(str, ":%32[^,]%n", port, &pos) != 1) {
error_setg(errp, "error parsing port in address '%s'", str);
- goto fail;
+ return -1;
}
} else if (str[0] == '[') {
/* IPv6 addr */
if (sscanf(str, "[%64[^]]]:%32[^,]%n", host, port, &pos) != 2) {
error_setg(errp, "error parsing IPv6 address '%s'", str);
- goto fail;
+ return -1;
}
addr->ipv6 = addr->has_ipv6 = true;
} else {
/* hostname or IPv4 addr */
if (sscanf(str, "%64[^:]:%32[^,]%n", host, port, &pos) != 2) {
error_setg(errp, "error parsing address '%s'", str);
- goto fail;
+ return -1;
}
if (host[strspn(host, "0123456789.")] == '\0') {
addr->ipv4 = addr->has_ipv4 = true;
@@ -626,7 +626,7 @@ InetSocketAddress *inet_parse(const char *str, Error **errp)
if (sscanf(h, "%d%n", &to, &pos) != 1 ||
(h[pos] != '\0' && h[pos] != ',')) {
error_setg(errp, "error parsing to= argument");
- goto fail;
+ return -1;
}
addr->has_to = true;
addr->to = to;
@@ -637,11 +637,7 @@ InetSocketAddress *inet_parse(const char *str, Error **errp)
if (strstr(optstr, ",ipv6")) {
addr->ipv6 = addr->has_ipv6 = true;
}
- return addr;
-
-fail:
- qapi_free_InetSocketAddress(addr);
- return NULL;
+ return 0;
}
@@ -656,13 +652,12 @@ fail:
int inet_connect(const char *str, Error **errp)
{
int sock = -1;
- InetSocketAddress *addr;
+ InetSocketAddress *addr = g_new(InetSocketAddress, 1);
- addr = inet_parse(str, errp);
- if (addr != NULL) {
+ if (!inet_parse(addr, str, errp)) {
sock = inet_connect_saddr(addr, NULL, NULL, errp);
- qapi_free_InetSocketAddress(addr);
}
+ qapi_free_InetSocketAddress(addr);
return sock;
}
@@ -793,26 +788,25 @@ static int vsock_listen_saddr(VsockSocketAddress *vaddr,
return slisten;
}
-static VsockSocketAddress *vsock_parse(const char *str, Error **errp)
+static int vsock_parse(VsockSocketAddress *addr, const char *str,
+ Error **errp)
{
- VsockSocketAddress *addr = NULL;
char cid[33];
char port[33];
int n;
if (sscanf(str, "%32[^:]:%32[^,]%n", cid, port, &n) != 2) {
error_setg(errp, "error parsing address '%s'", str);
- return NULL;
+ return -1;
}
if (str[n] != '\0') {
error_setg(errp, "trailing characters in address '%s'", str);
- return NULL;
+ return -1;
}
- addr = g_new0(VsockSocketAddress, 1);
addr->cid = g_strdup(cid);
addr->port = g_strdup(port);
- return addr;
+ return 0;
}
#else
static void vsock_unsupported(Error **errp)
@@ -835,10 +829,11 @@ static int vsock_listen_saddr(VsockSocketAddress *vaddr,
return -1;
}
-static VsockSocketAddress *vsock_parse(const char *str, Error **errp)
+static int vsock_parse(VsockSocketAddress *addr, const char *str,
+ Error **errp)
{
vsock_unsupported(errp);
- return NULL;
+ return -1;
}
#endif /* CONFIG_AF_VSOCK */
@@ -1045,29 +1040,25 @@ SocketAddress *socket_parse(const char *str, Error **errp)
error_setg(errp, "invalid Unix socket address");
goto fail;
} else {
- addr->type = SOCKET_ADDRESS_KIND_UNIX;
- addr->u.q_unix.data = g_new(UnixSocketAddress, 1);
- addr->u.q_unix.data->path = g_strdup(str + 5);
+ addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ addr->u.q_unix.path = g_strdup(str + 5);
}
} else if (strstart(str, "fd:", NULL)) {
if (str[3] == '\0') {
error_setg(errp, "invalid file descriptor address");
goto fail;
} else {
- addr->type = SOCKET_ADDRESS_KIND_FD;
- addr->u.fd.data = g_new(String, 1);
- addr->u.fd.data->str = g_strdup(str + 3);
+ addr->type = SOCKET_ADDRESS_TYPE_FD;
+ addr->u.fd.str = g_strdup(str + 3);
}
} else if (strstart(str, "vsock:", NULL)) {
- addr->type = SOCKET_ADDRESS_KIND_VSOCK;
- addr->u.vsock.data = vsock_parse(str + strlen("vsock:"), errp);
- if (addr->u.vsock.data == NULL) {
+ addr->type = SOCKET_ADDRESS_TYPE_VSOCK;
+ if (vsock_parse(&addr->u.vsock, str + strlen("vsock:"), errp)) {
goto fail;
}
} else {
- addr->type = SOCKET_ADDRESS_KIND_INET;
- addr->u.inet.data = inet_parse(str, errp);
- if (addr->u.inet.data == NULL) {
+ addr->type = SOCKET_ADDRESS_TYPE_INET;
+ if (inet_parse(&addr->u.inet, str, errp)) {
goto fail;
}
}
@@ -1084,24 +1075,24 @@ int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback,
int fd;
switch (addr->type) {
- case SOCKET_ADDRESS_KIND_INET:
- fd = inet_connect_saddr(addr->u.inet.data, callback, opaque, errp);
+ case SOCKET_ADDRESS_TYPE_INET:
+ fd = inet_connect_saddr(&addr->u.inet, callback, opaque, errp);
break;
- case SOCKET_ADDRESS_KIND_UNIX:
- fd = unix_connect_saddr(addr->u.q_unix.data, callback, opaque, errp);
+ case SOCKET_ADDRESS_TYPE_UNIX:
+ fd = unix_connect_saddr(&addr->u.q_unix, callback, opaque, errp);
break;
- case SOCKET_ADDRESS_KIND_FD:
- fd = monitor_get_fd(cur_mon, addr->u.fd.data->str, errp);
+ case SOCKET_ADDRESS_TYPE_FD:
+ fd = monitor_get_fd(cur_mon, addr->u.fd.str, errp);
if (fd >= 0 && callback) {
qemu_set_nonblock(fd);
callback(fd, NULL, opaque);
}
break;
- case SOCKET_ADDRESS_KIND_VSOCK:
- fd = vsock_connect_saddr(addr->u.vsock.data, callback, opaque, errp);
+ case SOCKET_ADDRESS_TYPE_VSOCK:
+ fd = vsock_connect_saddr(&addr->u.vsock, callback, opaque, errp);
break;
default:
@@ -1115,20 +1106,20 @@ int socket_listen(SocketAddress *addr, Error **errp)
int fd;
switch (addr->type) {
- case SOCKET_ADDRESS_KIND_INET:
- fd = inet_listen_saddr(addr->u.inet.data, 0, false, errp);
+ case SOCKET_ADDRESS_TYPE_INET:
+ fd = inet_listen_saddr(&addr->u.inet, 0, false, errp);
break;
- case SOCKET_ADDRESS_KIND_UNIX:
- fd = unix_listen_saddr(addr->u.q_unix.data, false, errp);
+ case SOCKET_ADDRESS_TYPE_UNIX:
+ fd = unix_listen_saddr(&addr->u.q_unix, false, errp);
break;
- case SOCKET_ADDRESS_KIND_FD:
- fd = monitor_get_fd(cur_mon, addr->u.fd.data->str, errp);
+ case SOCKET_ADDRESS_TYPE_FD:
+ fd = monitor_get_fd(cur_mon, addr->u.fd.str, errp);
break;
- case SOCKET_ADDRESS_KIND_VSOCK:
- fd = vsock_listen_saddr(addr->u.vsock.data, errp);
+ case SOCKET_ADDRESS_TYPE_VSOCK:
+ fd = vsock_listen_saddr(&addr->u.vsock, errp);
break;
default:
@@ -1143,12 +1134,12 @@ void socket_listen_cleanup(int fd, Error **errp)
addr = socket_local_address(fd, errp);
- if (addr->type == SOCKET_ADDRESS_KIND_UNIX
- && addr->u.q_unix.data->path) {
- if (unlink(addr->u.q_unix.data->path) < 0 && errno != ENOENT) {
+ if (addr->type == SOCKET_ADDRESS_TYPE_UNIX
+ && addr->u.q_unix.path) {
+ if (unlink(addr->u.q_unix.path) < 0 && errno != ENOENT) {
error_setg_errno(errp, errno,
"Failed to unlink socket %s",
- addr->u.q_unix.data->path);
+ addr->u.q_unix.path);
}
}
@@ -1160,13 +1151,13 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp)
int fd;
/*
- * TODO SOCKET_ADDRESS_KIND_FD when fd is AF_INET or AF_INET6
+ * TODO SOCKET_ADDRESS_TYPE_FD when fd is AF_INET or AF_INET6
* (although other address families can do SOCK_DGRAM, too)
*/
switch (remote->type) {
- case SOCKET_ADDRESS_KIND_INET:
- fd = inet_dgram_saddr(remote->u.inet.data,
- local ? local->u.inet.data : NULL, errp);
+ case SOCKET_ADDRESS_TYPE_INET:
+ fd = inet_dgram_saddr(&remote->u.inet,
+ local ? &local->u.inet : NULL, errp);
break;
default:
@@ -1199,8 +1190,8 @@ socket_sockaddr_to_address_inet(struct sockaddr_storage *sa,
}
addr = g_new0(SocketAddress, 1);
- addr->type = SOCKET_ADDRESS_KIND_INET;
- inet = addr->u.inet.data = g_new0(InetSocketAddress, 1);
+ addr->type = SOCKET_ADDRESS_TYPE_INET;
+ inet = &addr->u.inet;
inet->host = g_strdup(host);
inet->port = g_strdup(serv);
if (sa->ss_family == AF_INET) {
@@ -1223,11 +1214,9 @@ socket_sockaddr_to_address_unix(struct sockaddr_storage *sa,
struct sockaddr_un *su = (struct sockaddr_un *)sa;
addr = g_new0(SocketAddress, 1);
- addr->type = SOCKET_ADDRESS_KIND_UNIX;
- addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
+ addr->type = SOCKET_ADDRESS_TYPE_UNIX;
if (su->sun_path[0]) {
- addr->u.q_unix.data->path = g_strndup(su->sun_path,
- sizeof(su->sun_path));
+ addr->u.q_unix.path = g_strndup(su->sun_path, sizeof(su->sun_path));
}
return addr;
@@ -1245,8 +1234,8 @@ socket_sockaddr_to_address_vsock(struct sockaddr_storage *sa,
struct sockaddr_vm *svm = (struct sockaddr_vm *)sa;
addr = g_new0(SocketAddress, 1);
- addr->type = SOCKET_ADDRESS_KIND_VSOCK;
- addr->u.vsock.data = vaddr = g_new0(VsockSocketAddress, 1);
+ addr->type = SOCKET_ADDRESS_TYPE_VSOCK;
+ vaddr = &addr->u.vsock;
vaddr->cid = g_strdup_printf("%u", svm->svm_cid);
vaddr->port = g_strdup_printf("%u", svm->svm_port);
@@ -1318,8 +1307,8 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
InetSocketAddress *inet;
switch (addr->type) {
- case SOCKET_ADDRESS_KIND_INET:
- inet = addr->u.inet.data;
+ case SOCKET_ADDRESS_TYPE_INET:
+ inet = &addr->u.inet;
if (strchr(inet->host, ':') == NULL) {
buf = g_strdup_printf("%s:%s", inet->host, inet->port);
} else {
@@ -1327,18 +1316,18 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
}
break;
- case SOCKET_ADDRESS_KIND_UNIX:
- buf = g_strdup(addr->u.q_unix.data->path);
+ case SOCKET_ADDRESS_TYPE_UNIX:
+ buf = g_strdup(addr->u.q_unix.path);
break;
- case SOCKET_ADDRESS_KIND_FD:
- buf = g_strdup(addr->u.fd.data->str);
+ case SOCKET_ADDRESS_TYPE_FD:
+ buf = g_strdup(addr->u.fd.str);
break;
- case SOCKET_ADDRESS_KIND_VSOCK:
+ case SOCKET_ADDRESS_TYPE_VSOCK:
buf = g_strdup_printf("%s:%s",
- addr->u.vsock.data->cid,
- addr->u.vsock.data->port);
+ addr->u.vsock.cid,
+ addr->u.vsock.port);
break;
default:
@@ -1347,29 +1336,33 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
return buf;
}
-SocketAddress *socket_address_crumple(SocketAddressFlat *addr_flat)
+SocketAddress *socket_address_flatten(SocketAddressLegacy *addr_legacy)
{
SocketAddress *addr = g_new(SocketAddress, 1);
- switch (addr_flat->type) {
- case SOCKET_ADDRESS_FLAT_TYPE_INET:
- addr->type = SOCKET_ADDRESS_KIND_INET;
- addr->u.inet.data = QAPI_CLONE(InetSocketAddress,
- &addr_flat->u.inet);
+ if (!addr_legacy) {
+ return NULL;
+ }
+
+ switch (addr_legacy->type) {
+ case SOCKET_ADDRESS_LEGACY_KIND_INET:
+ addr->type = SOCKET_ADDRESS_TYPE_INET;
+ QAPI_CLONE_MEMBERS(InetSocketAddress, &addr->u.inet,
+ addr_legacy->u.inet.data);
break;
- case SOCKET_ADDRESS_FLAT_TYPE_UNIX:
- addr->type = SOCKET_ADDRESS_KIND_UNIX;
- addr->u.q_unix.data = QAPI_CLONE(UnixSocketAddress,
- &addr_flat->u.q_unix);
+ case SOCKET_ADDRESS_LEGACY_KIND_UNIX:
+ addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ QAPI_CLONE_MEMBERS(UnixSocketAddress, &addr->u.q_unix,
+ addr_legacy->u.q_unix.data);
break;
- case SOCKET_ADDRESS_FLAT_TYPE_VSOCK:
- addr->type = SOCKET_ADDRESS_KIND_VSOCK;
- addr->u.vsock.data = QAPI_CLONE(VsockSocketAddress,
- &addr_flat->u.vsock);
+ case SOCKET_ADDRESS_LEGACY_KIND_VSOCK:
+ addr->type = SOCKET_ADDRESS_TYPE_VSOCK;
+ QAPI_CLONE_MEMBERS(VsockSocketAddress, &addr->u.vsock,
+ addr_legacy->u.vsock.data);
break;
- case SOCKET_ADDRESS_FLAT_TYPE_FD:
- addr->type = SOCKET_ADDRESS_KIND_FD;
- addr->u.fd.data = QAPI_CLONE(String, &addr_flat->u.fd);
+ case SOCKET_ADDRESS_LEGACY_KIND_FD:
+ addr->type = SOCKET_ADDRESS_TYPE_FD;
+ QAPI_CLONE_MEMBERS(String, &addr->u.fd, addr_legacy->u.fd.data);
break;
default:
abort();