From de4598f0c5a734863f74b7984604bfb8a89fbccd Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Thu, 6 Apr 2017 16:41:07 +0100 Subject: [PATCH 01/28] tests/check-qdict: Fix missing brackets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gcc 7 (on Fedora 26) spotted odd use of integers instead of a boolean; it's got a point. Signed-off-by: Dr. David Alan Gilbert Message-Id: <20170406154107.9178-1-dgilbert@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- tests/check-qdict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 81162ee572..6f3fbcf9c1 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -559,7 +559,7 @@ static void qdict_join_test(void) 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) { From cb69166bb8defaaa4b3e0a4e31de693737634a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 4 May 2017 02:38:42 +0400 Subject: [PATCH 02/28] test-keyval: fix leaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spotted by ASAN. Signed-off-by: Marc-André Lureau Message-Id: <20170503223846.6559-2-marcandre.lureau@redhat.com> Reviewed-by: Eric blake Signed-off-by: Markus Armbruster --- tests/test-keyval.c | 4 ++++ 1 file changed, 4 insertions(+) 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); From 9edd5338a2404909ac8d373964021e6dbb8f5815 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:12 -0500 Subject: [PATCH 03/28] pci: Use struct instead of QDict to pass back parameters It's simpler to just use a C struct than it is to bundle things into a QDict in one function just to pull them back out in the caller. Plus, doing this gets rid of one more user of dynamic JSON through qobject_from_jsonf(), as well as a memory leak of the QDict. While cleaning the code, fix things to report all errors (the code was previously silently ignoring a failure of pcie_aer_inject_error(), at a distance). Signed-off-by: Eric Blake Reviewed-by: Michael S. Tsirkin Reviewed-by: Marcel Apfelbaum Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-2-eblake@redhat.com> Signed-off-by: Markus Armbruster --- hw/pci/pcie_aer.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index a8c18203d6..653af86f4b 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) { @@ -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)); } From 8f16de18f6d8d0c0b4982bbe13f7b6a048b0e876 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:13 -0500 Subject: [PATCH 04/28] pci: Reduce scope of error injection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No one outside of pcie_aer.h was using error injection; mark them static for internal use. Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Michael S. Tsirkin Reviewed-by: Marcel Apfelbaum Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-3-eblake@redhat.com> Signed-off-by: Markus Armbruster --- hw/pci/pcie_aer.c | 4 ++-- include/hw/pci/pcie_aer.h | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index 653af86f4b..828052b0c0 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -376,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; @@ -631,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; 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 */ From a2f3453ebc64b1ebe094aeaf83f9e67896f90ac3 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:14 -0500 Subject: [PATCH 05/28] coccinelle: Add script to remove useless QObject casts We have macros in place to make it less verbose to add a subtype of QObject to both QDict and QList. While we have made cleanups like this in the past (see commit fcfcd8ffc, for example), having it be automated by Coccinelle makes it easier to maintain. The script is separate from the cleanups, for ease of review and backporting. A later patch will then add further possible cleanups. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-4-eblake@redhat.com> Signed-off-by: Markus Armbruster --- MAINTAINERS | 1 + scripts/coccinelle/qobject.cocci | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 scripts/coccinelle/qobject.cocci diff --git a/MAINTAINERS b/MAINTAINERS index efdec47319..66c9734311 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1393,6 +1393,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/scripts/coccinelle/qobject.cocci b/scripts/coccinelle/qobject.cocci new file mode 100644 index 0000000000..aa899e2f3b --- /dev/null +++ b/scripts/coccinelle/qobject.cocci @@ -0,0 +1,13 @@ +// Use QDict macros where they make sense +@@ +expression Obj, Key, E; +@@ +- qdict_put_obj(Obj, Key, QOBJECT(E)); ++ qdict_put(Obj, Key, E); + +// Use QList macros where they make sense +@@ +expression Obj, E; +@@ +- qlist_append_obj(Obj, QOBJECT(E)); ++ qlist_append(Obj, E); From de6e7951fe66053dfeaac1a237f7aceb9e079619 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:15 -0500 Subject: [PATCH 06/28] qobject: Drop useless QObject casts We have macros in place to make it less verbose to add a subtype of QObject to both QDict and QList. While we have made cleanups like this in the past (see commit fcfcd8ffc, for example), having it be automated by Coccinelle makes it easier to maintain. Patch created mechanically via: spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir . --in-place then I verified that no manual touchups were required. Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-5-eblake@redhat.com> Signed-off-by: Markus Armbruster --- block.c | 12 ++++-------- block/blkdebug.c | 4 ++-- block/blkverify.c | 7 +++---- block/file-posix.c | 6 +++--- block/file-win32.c | 4 ++-- block/quorum.c | 16 ++++++---------- tests/check-qdict.c | 20 ++++++++++---------- tests/test-qmp-commands.c | 24 ++++++++++++------------ 8 files changed, 42 insertions(+), 51 deletions(-) diff --git a/block.c b/block.c index 6c6bb3ec7a..cb5856b514 100644 --- a/block.c +++ b/block.c @@ -4712,11 +4712,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(opts, "driver", qstring_from_str(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 +4730,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(opts, "driver", qstring_from_str(drv->format_name)); if (bs->exact_filename[0]) { /* This may not work for all block protocol drivers (some may @@ -4743,8 +4740,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(opts, "filename", qstring_from_str(bs->exact_filename)); } bs->full_open_options = opts; diff --git a/block/blkdebug.c b/block/blkdebug.c index d2a7561c4c..16322d83dd 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -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(opts, "driver", qstring_from_str("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..cc29cd2b54 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -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(opts, "driver", qstring_from_str("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/file-posix.c b/block/file-posix.c index 1941fb6749..fc4b052d4f 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(options, "filename", qstring_from_str(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(options, "filename", qstring_from_str(filename)); } static bool hdev_is_sg(BlockDriverState *bs) @@ -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(options, "filename", qstring_from_str(filename)); } #endif diff --git a/block/file-win32.c b/block/file-win32.c index 7872e00a21..c4a6be7f9f 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(options, "filename", qstring_from_str(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(options, "filename", qstring_from_str(filename)); } static int hdev_open(BlockDriverState *bs, QDict *options, int flags, diff --git a/block/quorum.c b/block/quorum.c index 40205fb1b3..f7949e29f9 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(opts, "driver", qstring_from_str("quorum")); + qdict_put(opts, QUORUM_OPT_VOTE_THRESHOLD, qint_from_int(s->threshold)); + qdict_put(opts, QUORUM_OPT_BLKVERIFY, qbool_from_bool(s->is_blkverify)); + qdict_put(opts, QUORUM_OPT_REWRITE, qbool_from_bool(s->rewrite_corrupted)); + qdict_put(opts, "children", children); bs->full_open_options = opts; } diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 6f3fbcf9c1..3cb72fb12e 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(qdict, "", qint_from_int(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(qdict, "num", qint_from_int(0)); + qdict_put(qdict, "str", qstring_from_str("foo")); QDECREF(qdict); } @@ -297,16 +297,16 @@ static void qdict_flatten_test(void) qdict_put(dict1, "a", qint_from_int(0)); qdict_put(dict1, "b", qint_from_int(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(list1, qint_from_int(23)); + qlist_append(list1, qint_from_int(66)); + qlist_append(list1, dict1); + qlist_append(list2, qint_from_int(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, "e", list2); + qdict_put(dict3, "f", dict2); qdict_put(dict3, "g", qint_from_int(4)); qdict_flatten(dict3); diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index 0f81a98be2..ac3fd039e0 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(req, "execute", qstring_from_str("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(req, "execute", qstring_from_str("user_def_cmd2")); resp = qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp != NULL); @@ -125,7 +125,7 @@ static void test_dispatch_cmd_failure(void) qdict_put(args, "a", qint_from_int(66)); qdict_put(req, "arguments", args); - qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd"))); + qdict_put(req, "execute", qstring_from_str("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(ud1a, "integer", qint_from_int(42)); + qdict_put(ud1a, "string", qstring_from_str("hello")); + qdict_put(ud1b, "integer", qint_from_int(422)); + qdict_put(ud1b, "string", qstring_from_str("hello2")); + qdict_put(args, "ud1a", ud1a); + qdict_put(args, "ud1b", ud1b); + qdict_put(req, "arguments", args); + qdict_put(req, "execute", qstring_from_str("user_def_cmd2")); ret = qobject_to_qdict(test_qmp_dispatch(req)); @@ -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(ud2_dict, "string0", qstring_from_str(text)); v = qobject_input_visitor_new(QOBJECT(ud2_dict)); visit_type_UserDefTwo(v, NULL, &ud2, &err); From a92c21591b5bb9543996538f14854ca6b528318b Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:16 -0500 Subject: [PATCH 07/28] qobject: Add helper macros for common scalar insertions Rather than making lots of callers wrap a scalar in a QInt, QString, or QBool, provide helper macros that do the wrapping automatically. Update the Coccinelle script to make mass conversions easy, although the conversion itself will be done as a separate patches to ease review and backport efforts. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-6-eblake@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/qmp/qdict.h | 8 ++++++++ include/qapi/qmp/qlist.h | 8 ++++++++ scripts/coccinelle/qobject.cocci | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) 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/scripts/coccinelle/qobject.cocci b/scripts/coccinelle/qobject.cocci index aa899e2f3b..97703a438b 100644 --- a/scripts/coccinelle/qobject.cocci +++ b/scripts/coccinelle/qobject.cocci @@ -2,12 +2,34 @@ @@ 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); +) From 46f5ac205a9dc5e2c24274c7df371509a286281f Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:17 -0500 Subject: [PATCH 08/28] qobject: Use simpler QDict/QList scalar insertion macros We now have macros in place to make it less verbose to add a scalar to QDict and QList, so use them. Patch created mechanically via: spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir . --in-place then touched up manually to fix a couple of '?:' back to original spacing, as well as avoiding a long line in monitor.c. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-7-eblake@redhat.com> Reviewed-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia Signed-off-by: Markus Armbruster --- block.c | 45 ++++------ block/blkdebug.c | 6 +- block/blkverify.c | 6 +- block/curl.c | 2 +- block/file-posix.c | 8 +- block/file-win32.c | 4 +- block/nbd.c | 41 +++++---- block/nfs.c | 43 ++++----- block/null.c | 2 +- block/qcow2.c | 4 +- block/quorum.c | 8 +- block/rbd.c | 16 ++-- block/snapshot.c | 2 +- block/ssh.c | 16 ++-- block/vvfat.c | 10 +-- block/vxhs.c | 6 +- blockdev.c | 30 +++---- hw/block/xen_disk.c | 2 +- hw/usb/xen-usb.c | 12 +-- monitor.c | 23 +++-- qapi/qmp-event.c | 2 +- qemu-img.c | 6 +- qemu-io.c | 2 +- qemu-nbd.c | 2 +- qobject/qdict.c | 2 +- target/s390x/cpu_models.c | 4 +- tests/check-qdict.c | 134 ++++++++++++++-------------- tests/check-qlist.c | 4 +- tests/device-introspect-test.c | 4 +- tests/test-qemu-opts.c | 4 +- tests/test-qmp-commands.c | 24 ++--- tests/test-qmp-event.c | 30 +++---- tests/test-qobject-output-visitor.c | 6 +- util/qemu-option.c | 2 +- 34 files changed, 244 insertions(+), 268 deletions(-) diff --git a/block.c b/block.c index cb5856b514..aae8f7e85c 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, @@ -2230,12 +2228,9 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, } /* Prepare options QDict for the temporary file */ - qdict_put(snapshot_options, "file.driver", - qstring_from_str("file")); - qdict_put(snapshot_options, "file.filename", - qstring_from_str(tmp_filename)); - qdict_put(snapshot_options, "driver", - qstring_from_str("qcow2")); + qdict_put_str(snapshot_options, "file.driver", "file"); + qdict_put_str(snapshot_options, "file.filename", tmp_filename); + qdict_put_str(snapshot_options, "driver", "qcow2"); bs_snapshot = bdrv_open(NULL, NULL, snapshot_options, flags, errp); snapshot_options = NULL; @@ -2410,8 +2405,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 +2427,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 +2804,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 +4300,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,7 +4705,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) * contain a representation of the filename, therefore the following * suffices without querying the (exact_)filename of this BDS. */ if (bs->file->bs->full_open_options) { - qdict_put(opts, "driver", qstring_from_str(drv->format_name)); + qdict_put_str(opts, "driver", drv->format_name); QINCREF(bs->file->bs->full_open_options); qdict_put(opts, "file", bs->file->bs->full_open_options); @@ -4730,7 +4723,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) opts = qdict_new(); append_open_options(opts, bs); - qdict_put(opts, "driver", qstring_from_str(drv->format_name)); + qdict_put_str(opts, "driver", drv->format_name); if (bs->exact_filename[0]) { /* This may not work for all block protocol drivers (some may @@ -4740,7 +4733,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) * needs some special format of the options QDict, it needs to * implement the driver-specific bdrv_refresh_filename() function. */ - qdict_put(opts, "filename", qstring_from_str(bs->exact_filename)); + qdict_put_str(opts, "filename", bs->exact_filename); } bs->full_open_options = opts; diff --git a/block/blkdebug.c b/block/blkdebug.c index 16322d83dd..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,7 +693,7 @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) } opts = qdict_new(); - qdict_put(opts, "driver", qstring_from_str("blkdebug")); + qdict_put_str(opts, "driver", "blkdebug"); QINCREF(bs->file->bs->full_open_options); qdict_put(opts, "image", bs->file->bs->full_open_options); diff --git a/block/blkverify.c b/block/blkverify.c index cc29cd2b54..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,7 +288,7 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options) && s->test_file->bs->full_open_options) { QDict *opts = qdict_new(); - qdict_put(opts, "driver", qstring_from_str("blkverify")); + qdict_put_str(opts, "driver", "blkverify"); QINCREF(bs->file->bs->full_open_options); qdict_put(opts, "raw", bs->file->bs->full_open_options); 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 fc4b052d4f..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(options, "filename", 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(options, "filename", 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(options, "filename", qstring_from_str(filename)); + qdict_put_str(options, "filename", filename); } #endif diff --git a/block/file-win32.c b/block/file-win32.c index c4a6be7f9f..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(options, "filename", 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(options, "filename", qstring_from_str(filename)); + qdict_put_str(options, "filename", filename); } static int hdev_open(BlockDriverState *bs, QDict *options, int flags, diff --git a/block/nbd.c b/block/nbd.c index 814ab26dce..b3545f5709 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -79,7 +79,7 @@ static int nbd_parse_uri(const char *filename, QDict *options) p = uri->path ? uri->path : "/"; p += strspn(p, "/"); if (p[0]) { - qdict_put(options, "export", qstring_from_str(p)); + qdict_put_str(options, "export", p); } qp = query_params_parse(uri->query); @@ -94,9 +94,8 @@ static int nbd_parse_uri(const char *filename, QDict *options) ret = -EINVAL; goto out; } - qdict_put(options, "server.type", qstring_from_str("unix")); - qdict_put(options, "server.path", - qstring_from_str(qp->p[0].value)); + qdict_put_str(options, "server.type", "unix"); + qdict_put_str(options, "server.path", qp->p[0].value); } else { QString *host; char *port_str; @@ -115,11 +114,11 @@ static int nbd_parse_uri(const char *filename, QDict *options) host = qstring_from_str(uri->server); } - qdict_put(options, "server.type", qstring_from_str("inet")); + qdict_put_str(options, "server.type", "inet"); qdict_put(options, "server.host", host); port_str = g_strdup_printf("%d", uri->port ?: NBD_DEFAULT_PORT); - qdict_put(options, "server.port", qstring_from_str(port_str)); + qdict_put_str(options, "server.port", port_str); g_free(port_str); } @@ -181,7 +180,7 @@ static void nbd_parse_filename(const char *filename, QDict *options, export_name[0] = 0; /* truncate 'file' */ export_name += strlen(EN_OPTSTR); - qdict_put(options, "export", qstring_from_str(export_name)); + qdict_put_str(options, "export", export_name); } /* extract the host_spec - fail if it's not nbd:... */ @@ -196,8 +195,8 @@ static void nbd_parse_filename(const char *filename, QDict *options, /* are we a UNIX or TCP socket? */ if (strstart(host_spec, "unix:", &unixpath)) { - qdict_put(options, "server.type", qstring_from_str("unix")); - qdict_put(options, "server.path", qstring_from_str(unixpath)); + qdict_put_str(options, "server.type", "unix"); + qdict_put_str(options, "server.path", unixpath); } else { InetSocketAddress *addr = NULL; @@ -206,9 +205,9 @@ static void nbd_parse_filename(const char *filename, QDict *options, goto out; } - qdict_put(options, "server.type", qstring_from_str("inet")); - qdict_put(options, "server.host", qstring_from_str(addr->host)); - qdict_put(options, "server.port", qstring_from_str(addr->port)); + qdict_put_str(options, "server.type", "inet"); + qdict_put_str(options, "server.host", addr->host); + qdict_put_str(options, "server.port", addr->port); qapi_free_InetSocketAddress(addr); } @@ -247,13 +246,13 @@ static bool nbd_process_legacy_socket_options(QDict *output_options, return false; } - qdict_put(output_options, "server.type", qstring_from_str("unix")); - qdict_put(output_options, "server.path", qstring_from_str(path)); + qdict_put_str(output_options, "server.type", "unix"); + qdict_put_str(output_options, "server.path", path); } else if (host) { - qdict_put(output_options, "server.type", qstring_from_str("inet")); - qdict_put(output_options, "server.host", qstring_from_str(host)); - qdict_put(output_options, "server.port", - qstring_from_str(port ?: stringify(NBD_DEFAULT_PORT))); + qdict_put_str(output_options, "server.type", "inet"); + qdict_put_str(output_options, "server.host", host); + qdict_put_str(output_options, "server.port", + port ?: stringify(NBD_DEFAULT_PORT)); } return true; @@ -528,7 +527,7 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) path = s->saddr->u.q_unix.path; } /* else can't represent as pseudo-filename */ - qdict_put(opts, "driver", qstring_from_str("nbd")); + qdict_put_str(opts, "driver", "nbd"); if (path && s->export) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), @@ -551,10 +550,10 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) qdict_put_obj(opts, "server", saddr_qdict); if (s->export) { - qdict_put(opts, "export", qstring_from_str(s->export)); + qdict_put_str(opts, "export", s->export); } if (s->tlscredsid) { - qdict_put(opts, "tls-creds", qstring_from_str(s->tlscredsid)); + qdict_put_str(opts, "tls-creds", s->tlscredsid); } qdict_flatten(opts); 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 f7949e29f9..1b2a8c3937 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1100,10 +1100,10 @@ static void quorum_refresh_filename(BlockDriverState *bs, QDict *options) } opts = qdict_new(); - qdict_put(opts, "driver", qstring_from_str("quorum")); - qdict_put(opts, QUORUM_OPT_VOTE_THRESHOLD, qint_from_int(s->threshold)); - qdict_put(opts, QUORUM_OPT_BLKVERIFY, qbool_from_bool(s->is_blkverify)); - qdict_put(opts, QUORUM_OPT_REWRITE, qbool_from_bool(s->rewrite_corrupted)); + 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/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.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/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, "")) { 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/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/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/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/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..e4f00e26dd 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -959,7 +959,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/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/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 3cb72fb12e..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(qdict, "", 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(qdict, "num", qint_from_int(0)); - qdict_put(qdict, "str", 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(list1, qint_from_int(23)); - qlist_append(list1, qint_from_int(66)); + qlist_append_int(list1, 23); + qlist_append_int(list1, 66); qlist_append(list1, dict1); - qlist_append(list2, qint_from_int(42)); + 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_int(dict2, "c", 2); + qdict_put_int(dict2, "d", 3); qdict_put(dict3, "e", list2); qdict_put(dict3, "f", dict2); - qdict_put(dict3, "g", qint_from_int(4)); + 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,7 +552,7 @@ 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); @@ -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/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-qmp-commands.c b/tests/test-qmp-commands.c index ac3fd039e0..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(req, "execute", 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(req, "execute", 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(req, "execute", 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(ud1a, "integer", qint_from_int(42)); - qdict_put(ud1a, "string", qstring_from_str("hello")); - qdict_put(ud1b, "integer", qint_from_int(422)); - qdict_put(ud1b, "string", qstring_from_str("hello2")); + 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(req, "execute", qstring_from_str("user_def_cmd2")); + 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(ud2_dict, "string0", 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/util/qemu-option.c b/util/qemu-option.c index 5ce1b5c246..a36cafaf8c 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1060,7 +1060,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *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)); From ff6ed7141d87d26eafa2b8e4df969623e40fac49 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:18 -0500 Subject: [PATCH 09/28] block: Simplify bdrv_append_temp_snapshot() logic Noticed while checking Coccinelle results. Naming a label 'out:' when it is only used on error paths is weird. Also, we had some dead stores to 'ret'. Meanwhile we know that snapshot_options is NULL on success and that QDECREF(NULL) is safe. So merge the two exit paths into one by careful control over bs_snapshot. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-8-eblake@redhat.com> Signed-off-by: Markus Armbruster --- block.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index aae8f7e85c..a45b9b5c29 100644 --- a/block.c +++ b/block.c @@ -2195,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; @@ -2235,28 +2235,25 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, 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; } /* From 28934e0c759dae0d78b8b4336841b0287d04b4b6 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:19 -0500 Subject: [PATCH 10/28] QemuOpts: Simplify qemu_opts_to_qdict() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Noticed while investigating Coccinelle cleanups. There is no need for a temporary variable when we can use the new macro to do the same thing with less typing. Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-9-eblake@redhat.com> Signed-off-by: Markus Armbruster --- util/qemu-option.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index a36cafaf8c..5977bfc3e9 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1054,7 +1054,6 @@ 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(); @@ -1063,8 +1062,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict) 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; } From ccb61bdd73a6d9a3eb717d1b69125ec7ca638a3b Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:20 -0500 Subject: [PATCH 11/28] fdc-test: Avoid deprecated 'change' command Use the preferred blockdev-change-medium command instead. Also, use of 'device' is deprecated; adding an explicit id on the command line lets us use 'id' for both blockdev-change-medium and eject. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-10-eblake@redhat.com> Signed-off-by: Markus Armbruster --- tests/fdc-test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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); From 5229564b832e979f480011bae372ff849dbf320a Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 27 Apr 2017 16:58:21 -0500 Subject: [PATCH 12/28] test-qga: Actually test 0xff sync bytes Commit 62c39b3 introduced test-qga, and at face value, appears to be testing the 'guest-sync' behavior that is recommended for guests in sending 0xff to QGA to force the parser to reset. But this aspect of the test has never actually done anything: the qmp_fd() call chain converts its string argument into QObject, then converts that QObject back to the actual string that is sent over the wire - and the conversion process silently drops the 0xff byte from the string sent to QGA, thus never resetting the QGA parser. An upcoming patch will get rid of the wasteful round trip through QObject, at which point the string in test-qga will be directly sent over the wire. But fixing qmp_fd() to actually send 0xff over the wire is not all we have to do - the actual QMP parser loudly complains that 0xff is not valid JSON, and sends an error message _prior_ to actually parsing the 'guest-sync' or 'guest-sync-delimited' command. With 'guest-sync', we cannot easily tell if this error message is a result of our command - which is WHY we invented the 'guest-sync-delimited' command. So for the testsuite, fix things to only check 0xff behavior on 'guest-sync-delimited', and to loop until we've consumed all garbage prior to the requested delimiter, which is compatible with the documented actions that a real QGA client is supposed to do. Ideally, we'd fix the QGA JSON parser to silently ignore 0xff rather than sending an error message back, at which point we could enhance this test for 'guest-sync' as well as for 'guest-sync-delimited'. But for the sake of this patch, our testing of 'guest-sync' is no worse than it was pre-patch, because we have never been sending 0xff over the wire in the first place. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-11-eblake@redhat.com> Reviewed-by: Michael Roth [Additional comment squashed in, along with matching commit message update] Signed-off-by: Markus Armbruster --- tests/libqtest.c | 8 ++++++++ tests/test-qga.c | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) 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-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); From 4db5c619a2f03c2ee25105b4f6359075c825aecc Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:36 +0200 Subject: [PATCH 13/28] sockets: Prepare vsock_parse() for flattened SocketAddress I'm going to flatten SocketAddress: rename SocketAddress to SocketAddressLegacy, SocketAddressFlat to SocketAddress, eliminate SocketAddressLegacy except in external interfaces. vsock_parse() returns a newly allocated VsockSocketAddress. Lift the allocation from vsock_parse() into its caller socket_parse() to prepare for flattening SocketAddress. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-2-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake --- util/qemu-sockets.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 8188d9a8d7..1abe095493 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -793,26 +793,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 +834,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 */ @@ -1060,8 +1060,8 @@ SocketAddress *socket_parse(const char *str, Error **errp) } } 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->u.vsock.data = g_new(VsockSocketAddress, 1); + if (vsock_parse(addr->u.vsock.data, str + strlen("vsock:"), errp)) { goto fail; } } else { From 0785bd7a7c58ffaf533f484cb0661671a64ecffd Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:37 +0200 Subject: [PATCH 14/28] sockets: Prepare inet_parse() for flattened SocketAddress I'm going to flatten SocketAddress: rename SocketAddress to SocketAddressLegacy, SocketAddressFlat to SocketAddress, eliminate SocketAddressLegacy except in external interfaces. inet_parse() returns a newly allocated InetSocketAddress. Lift the allocation from inet_parse() into its caller socket_parse() to prepare for flattening SocketAddress. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-3-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake [Straightforward rebase] --- block/nbd.c | 8 ++++---- include/qemu/sockets.h | 2 +- migration/rdma.c | 4 ++-- migration/socket.c | 5 +++-- util/qemu-sockets.c | 30 ++++++++++++------------------ 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index b3545f5709..37969eb15e 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -198,16 +198,16 @@ static void nbd_parse_filename(const char *filename, QDict *options, 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_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); } diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index af285321b8..8b9325cb62 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, 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..5fdc723ca3 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -27,10 +27,11 @@ static SocketAddress *tcp_build_address(const char *host_port, Error **errp) { - InetSocketAddress *iaddr = inet_parse(host_port, errp); + InetSocketAddress *iaddr = g_new(InetSocketAddress, 1); SocketAddress *saddr; - if (!iaddr) { + if (inet_parse(iaddr, host_port, errp)) { + qapi_free_InetSocketAddress(iaddr); return NULL; } diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 1abe095493..62c93ba9a1 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -578,16 +578,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 +594,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 +625,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 +636,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 +651,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; } @@ -1066,8 +1060,8 @@ SocketAddress *socket_parse(const char *str, Error **errp) } } else { addr->type = SOCKET_ADDRESS_KIND_INET; - addr->u.inet.data = inet_parse(str, errp); - if (addr->u.inet.data == NULL) { + addr->u.inet.data = g_new(InetSocketAddress, 1); + if (inet_parse(addr->u.inet.data, str, errp)) { goto fail; } } From 4626a19c86c30d96cedbac2bd44ef8103303cb37 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:38 +0200 Subject: [PATCH 15/28] qapi: New QAPI_CLONE_MEMBERS() QAPI_CLONE() returns a newly allocated QAPI object. Inconvenient when we want to clone into an existing object. QAPI_CLONE_MEMBERS() does exactly that. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-4-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake --- include/qapi/clone-visitor.h | 14 ++++++++++++++ qapi/qapi-clone-visitor.c | 13 +++++++++++++ 2 files changed, 27 insertions(+) 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/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); +} From dfd100f242370886bb6732f70f1f7cbd8eb9fedc Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:39 +0200 Subject: [PATCH 16/28] sockets: Rename SocketAddress to SocketAddressLegacy The next commit will rename SocketAddressFlat to SocketAddress, and the commit after that will replace most uses of SocketAddressLegacy by SocketAddress, replacing most of this commit's renames right back. Note that checkpatch emits a few "line over 80 characters" warnings. The long lines are all temporary; the SocketAddressLegacy replacement will shorten them again. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-5-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- block/nbd.c | 4 +- block/sheepdog.c | 18 +++--- blockdev-nbd.c | 6 +- chardev/char-socket.c | 34 +++++------ chardev/char-udp.c | 10 ++-- hmp.c | 4 +- include/io/channel-socket.h | 24 ++++---- include/io/dns-resolver.h | 22 +++---- include/io/task.h | 10 ++-- include/qemu/sockets.h | 30 +++++----- io/channel-socket.c | 48 +++++++-------- io/dns-resolver.c | 48 +++++++-------- migration/socket.c | 36 ++++++------ net/socket.c | 10 ++-- qapi-schema.json | 14 +++-- qapi/block.json | 2 +- qemu-nbd.c | 12 ++-- qga/channel-posix.c | 4 +- qga/main.c | 8 +-- tests/test-io-channel-socket.c | 72 +++++++++++------------ ui/vnc-auth-sasl.c | 6 +- ui/vnc.c | 104 ++++++++++++++++----------------- util/qemu-sockets.c | 100 +++++++++++++++---------------- 23 files changed, 314 insertions(+), 312 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 37969eb15e..7f11a939fc 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -309,7 +309,7 @@ NBDClientSession *nbd_get_client_session(BlockDriverState *bs) static QIOChannelSocket *nbd_establish_connection(SocketAddressFlat *saddr_flat, Error **errp) { - SocketAddress *saddr = socket_address_crumple(saddr_flat); + SocketAddressLegacy *saddr = socket_address_crumple(saddr_flat); QIOChannelSocket *sioc; Error *local_err = NULL; @@ -319,7 +319,7 @@ static QIOChannelSocket *nbd_establish_connection(SocketAddressFlat *saddr_flat, qio_channel_socket_connect_sync(sioc, saddr, &local_err); - qapi_free_SocketAddress(saddr); + qapi_free_SocketAddressLegacy(saddr); if (local_err) { object_unref(OBJECT(sioc)); error_propagate(errp, local_err); diff --git a/block/sheepdog.c b/block/sheepdog.c index fe8fd923d5..055d10be17 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -378,7 +378,7 @@ struct BDRVSheepdogState { uint32_t cache_flags; bool discard_supported; - SocketAddress *addr; + SocketAddressLegacy *addr; int fd; CoMutex lock; @@ -530,17 +530,17 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings); } -static SocketAddress *sd_socket_address(const char *path, +static SocketAddressLegacy *sd_socket_address(const char *path, const char *host, const char *port) { - SocketAddress *addr = g_new0(SocketAddress, 1); + SocketAddressLegacy *addr = g_new0(SocketAddressLegacy, 1); if (path) { - addr->type = SOCKET_ADDRESS_KIND_UNIX; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); addr->u.q_unix.data->path = g_strdup(path); } else { - addr->type = SOCKET_ADDRESS_KIND_INET; + addr->type = SOCKET_ADDRESS_LEGACY_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)); @@ -549,13 +549,13 @@ static SocketAddress *sd_socket_address(const char *path, return addr; } -static SocketAddress *sd_server_config(QDict *options, Error **errp) +static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp) { QDict *server = NULL; QObject *crumpled_server = NULL; Visitor *iv = NULL; SocketAddressFlat *saddr_flat = NULL; - SocketAddress *saddr = NULL; + SocketAddressLegacy *saddr = NULL; Error *local_err = NULL; qdict_extract_subqdict(options, &server, "server."); @@ -597,7 +597,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_LEGACY_KIND_INET && fd >= 0) { int ret = socket_set_nodelay(fd); if (ret < 0) { error_report("%s", strerror(errno)); @@ -2149,7 +2149,7 @@ static void sd_close(BlockDriverState *bs) aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd, false, NULL, NULL, NULL, NULL); closesocket(s->fd); - qapi_free_SocketAddress(s->addr); + qapi_free_SocketAddressLegacy(s->addr); } static int64_t sd_getlength(BlockDriverState *bs) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 8a11807df3..6b0c699c22 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -99,7 +99,7 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp) } -void qmp_nbd_server_start(SocketAddress *addr, +void qmp_nbd_server_start(SocketAddressLegacy *addr, bool has_tls_creds, const char *tls_creds, Error **errp) { @@ -124,8 +124,8 @@ void qmp_nbd_server_start(SocketAddress *addr, 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_LEGACY_KIND_FD where fd has AF_INET or AF_INET6 */ + if (addr->type != SOCKET_ADDRESS_LEGACY_KIND_INET) { error_setg(errp, "TLS is only supported with IPv4/IPv6"); goto error; } diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 9d5f062c62..f872f48655 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -52,7 +52,7 @@ typedef struct { int *write_msgfds; size_t write_msgfds_num; - SocketAddress *addr; + SocketAddressLegacy *addr; bool is_listen; bool is_telnet; bool is_tn3270; @@ -356,27 +356,27 @@ static void tcp_chr_free_connection(Chardev *chr) s->connected = 0; } -static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr, +static char *SocketAddress_to_str(const char *prefix, SocketAddressLegacy *addr, bool is_listen, bool is_telnet) { switch (addr->type) { - case SOCKET_ADDRESS_KIND_INET: + case SOCKET_ADDRESS_LEGACY_KIND_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, is_listen ? ",server" : ""); break; - case SOCKET_ADDRESS_KIND_UNIX: + case SOCKET_ADDRESS_LEGACY_KIND_UNIX: return g_strdup_printf("%sunix:%s%s", prefix, addr->u.q_unix.data->path, is_listen ? ",server" : ""); break; - case SOCKET_ADDRESS_KIND_FD: + case SOCKET_ADDRESS_LEGACY_KIND_FD: return g_strdup_printf("%sfd:%s%s", prefix, addr->u.fd.data->str, is_listen ? ",server" : ""); break; - case SOCKET_ADDRESS_KIND_VSOCK: + case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: return g_strdup_printf("%svsock:%s:%s", prefix, addr->u.vsock.data->cid, addr->u.vsock.data->port); @@ -796,7 +796,7 @@ static void char_socket_finalize(Object *obj) g_source_remove(s->reconnect_timer); s->reconnect_timer = 0; } - qapi_free_SocketAddress(s->addr); + qapi_free_SocketAddressLegacy(s->addr); if (s->listen_tag) { g_source_remove(s->listen_tag); s->listen_tag = 0; @@ -859,7 +859,7 @@ static void qmp_chardev_open_socket(Chardev *chr, { SocketChardev *s = SOCKET_CHARDEV(chr); ChardevSocket *sock = backend->u.socket.data; - SocketAddress *addr = sock->addr; + SocketAddressLegacy *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; @@ -905,11 +905,11 @@ static void qmp_chardev_open_socket(Chardev *chr, } } - s->addr = QAPI_CLONE(SocketAddress, sock->addr); + s->addr = QAPI_CLONE(SocketAddressLegacy, 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_LEGACY_KIND_UNIX) { qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS); } @@ -945,7 +945,7 @@ static void qmp_chardev_open_socket(Chardev *chr, goto error; } - qapi_free_SocketAddress(s->addr); + qapi_free_SocketAddressLegacy(s->addr); s->addr = socket_local_address(sioc->fd, errp); update_disconnected_filename(s); @@ -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), @@ -1051,7 +1051,7 @@ char_socket_get_addr(Object *obj, Visitor *v, const char *name, { SocketChardev *s = SOCKET_CHARDEV(obj); - visit_type_SocketAddress(v, name, &s->addr, errp); + visit_type_SocketAddressLegacy(v, name, &s->addr, errp); } static bool @@ -1078,7 +1078,7 @@ static void char_socket_class_init(ObjectClass *oc, void *data) cc->chr_add_watch = tcp_chr_add_watch; cc->chr_update_read_handler = tcp_chr_update_read_handler; - object_class_property_add(oc, "addr", "SocketAddress", + object_class_property_add(oc, "addr", "SocketAddressLegacy", char_socket_get_addr, NULL, NULL, NULL, &error_abort); diff --git a/chardev/char-udp.c b/chardev/char-udp.c index 1958c36de4..d705c4f26b 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), diff --git a/hmp.c b/hmp.c index bd7b1caf2b..c7f161d634 100644 --- a/hmp.c +++ b/hmp.c @@ -2108,7 +2108,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) bool all = qdict_get_try_bool(qdict, "all", false); Error *local_err = NULL; BlockInfoList *block_list, *info; - SocketAddress *addr; + SocketAddressLegacy *addr; if (writable && !all) { error_setg(&local_err, "-w only valid together with -a"); @@ -2122,7 +2122,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) } qmp_nbd_server_start(addr, false, NULL, &local_err); - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); if (local_err != NULL) { goto exit; } diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h index 711f8bf7ce..c1aaa72a5d 100644 --- a/include/io/channel-socket.h +++ b/include/io/channel-socket.h @@ -91,7 +91,7 @@ qio_channel_socket_new_fd(int fd, * an error occurs. */ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddressLegacy *addr, Error **errp); /** @@ -110,7 +110,7 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, * as this function returns without waiting for completion. */ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddressLegacy *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy); @@ -128,7 +128,7 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, * an error occurs. */ int qio_channel_socket_listen_sync(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddressLegacy *addr, Error **errp); /** @@ -147,7 +147,7 @@ int qio_channel_socket_listen_sync(QIOChannelSocket *ioc, * as this function returns without waiting for completion. */ void qio_channel_socket_listen_async(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddressLegacy *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy); @@ -167,8 +167,8 @@ void qio_channel_socket_listen_async(QIOChannelSocket *ioc, * is established or an error occurs. */ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, - SocketAddress *localAddr, - SocketAddress *remoteAddr, + SocketAddressLegacy *localAddr, + SocketAddressLegacy *remoteAddr, Error **errp); /** @@ -190,8 +190,8 @@ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, * waiting for completion. */ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, - SocketAddress *localAddr, - SocketAddress *remoteAddr, + SocketAddressLegacy *localAddr, + SocketAddressLegacy *remoteAddr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy); @@ -205,12 +205,12 @@ 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_SocketAddressLegacy() when no * longer required. * * Returns: 0 on success, -1 on error */ -SocketAddress * +SocketAddressLegacy * qio_channel_socket_get_local_address(QIOChannelSocket *ioc, Error **errp); @@ -222,12 +222,12 @@ 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_SocketAddressLegacy() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddress * +SocketAddressLegacy * qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, Error **errp); diff --git a/include/io/dns-resolver.h b/include/io/dns-resolver.h index 2f69c08c13..aac46cadea 100644 --- a/include/io/dns-resolver.h +++ b/include/io/dns-resolver.h @@ -40,15 +40,15 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * QIODNSResolver: * * The QIODNSResolver class provides a framework for doing - * DNS resolution on SocketAddress objects, independently + * DNS resolution on SocketAddressLegacy objects, independently * of socket creation. * * * Resolving addresses synchronously * - * int mylisten(SocketAddress *addr, Error **errp) { + * int mylisten(SocketAddressLegacy *addr, Error **errp) { * QIODNSResolver *resolver = qio_dns_resolver_get_instance(); - * SocketAddress **rawaddrs = NULL; + * SocketAddressLegacy **rawaddrs = NULL; * size_t nrawaddrs = 0; * Error *err = NULL; * QIOChannel **socks = NULL; @@ -69,7 +69,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * socks = g_renew(QIOChannelSocket *, socks, nsocks + 1); * socks[nsocks++] = sock; * } - * qapi_free_SocketAddress(rawaddrs[i]); + * qapi_free_SocketAddressLegacy(rawaddrs[i]); * } * g_free(rawaddrs); * @@ -95,7 +95,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * MyListenData *data = opaque; * QIODNSResolver *resolver = * QIO_DNS_RESOLVER(qio_task_get_source(task); - * SocketAddress **rawaddrs = NULL; + * SocketAddressLegacy **rawaddrs = NULL; * size_t nrawaddrs = 0; * Error *err = NULL; * @@ -116,7 +116,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * socks = g_renew(QIOChannelSocket *, socks, nsocks + 1); * socks[nsocks++] = sock; * } - * qapi_free_SocketAddress(rawaddrs[i]); + * qapi_free_SocketAddressLegacy(rawaddrs[i]); * } * g_free(rawaddrs); * @@ -127,7 +127,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * } * } * - * void mylisten(SocketAddress *addr, MyListenData *data) { + * void mylisten(SocketAddressLegacy *addr, MyListenData *data) { * QIODNSResolver *resolver = qio_dns_resolver_get_instance(); * qio_dns_resolver_lookup_async(dns, addr, * mylistenresult, data, NULL); @@ -177,9 +177,9 @@ QIODNSResolver *qio_dns_resolver_get_instance(void); * Returns: 0 if resolution was successful, -1 on error */ int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver, - SocketAddress *addr, + SocketAddressLegacy *addr, size_t *naddrs, - SocketAddress ***addrs, + SocketAddressLegacy ***addrs, Error **errp); /** @@ -201,7 +201,7 @@ int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver, * of the caller will not be blocked. */ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, - SocketAddress *addr, + SocketAddressLegacy *addr, QIOTaskFunc func, gpointer opaque, GDestroyNotify notify); @@ -223,6 +223,6 @@ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, void qio_dns_resolver_lookup_result(QIODNSResolver *resolver, QIOTask *task, size_t *naddrs, - SocketAddress ***addrs); + SocketAddressLegacy ***addrs); #endif /* QIO_DNS_RESOLVER_H */ diff --git a/include/io/task.h b/include/io/task.h index 6021f51336..f65ec7aca3 100644 --- a/include/io/task.h +++ b/include/io/task.h @@ -166,7 +166,7 @@ typedef void (*QIOTaskWorker)(QIOTask *task, * gpointer opaque) * { * QMyObject obj = QMY_OBJECT(qio_task_get_source(task)); - * SocketAddress *addr = opaque; + * SocketAddressLegacy *addr = opaque; * Error *err = NULL; * * obj->fd = socket_listen(addr, &err); @@ -175,20 +175,20 @@ typedef void (*QIOTaskWorker)(QIOTask *task, * } * * void myobject_listen_async(QMyObject *obj, - * SocketAddress *addr, + * SocketAddressLegacy *addr, * QIOTaskFunc *func, * gpointer opaque, * GDestroyNotify notify) * { * QIOTask *task; - * SocketAddress *addrCopy; + * SocketAddressLegacy *addrCopy; * - * addrCopy = QAPI_CLONE(SocketAddress, addr); + * addrCopy = QAPI_CLONE(SocketAddressLegacy, addr); * task = qio_task_new(OBJECT(obj), func, opaque, notify); * * qio_task_run_in_thread(task, myobject_listen_worker, * addrCopy, - * qapi_free_SocketAddress); + * qapi_free_SocketAddressLegacy); * } * * diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 8b9325cb62..f4a4b10acf 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -45,12 +45,12 @@ NetworkAddressFamily inet_netfamily(int family); int unix_listen(const char *path, char *ostr, int olen, Error **errp); int unix_connect(const char *path, Error **errp); -SocketAddress *socket_parse(const char *str, Error **errp); -int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, +SocketAddressLegacy *socket_parse(const char *str, Error **errp); +int socket_connect(SocketAddressLegacy *addr, NonBlockingConnectHandler *callback, void *opaque, Error **errp); -int socket_listen(SocketAddress *addr, Error **errp); +int socket_listen(SocketAddressLegacy *addr, Error **errp); void socket_listen_cleanup(int fd, Error **errp); -int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); +int socket_dgram(SocketAddressLegacy *remote, SocketAddressLegacy *local, Error **errp); /* Old, ipv4 only bits. Don't use for new code. */ int parse_host_port(struct sockaddr_in *saddr, const char *str); @@ -65,12 +65,12 @@ 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_SocketAddressLegacy() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddress * +SocketAddressLegacy * socket_sockaddr_to_address(struct sockaddr_storage *sa, socklen_t salen, Error **errp); @@ -83,12 +83,12 @@ 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_SocketAddressLegacy() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddress *socket_local_address(int fd, Error **errp); +SocketAddressLegacy *socket_local_address(int fd, Error **errp); /** * socket_remote_address: @@ -98,12 +98,12 @@ 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_SocketAddressLegacy() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddress *socket_remote_address(int fd, Error **errp); +SocketAddressLegacy *socket_remote_address(int fd, Error **errp); /** * socket_address_to_string: @@ -118,17 +118,17 @@ SocketAddress *socket_remote_address(int fd, Error **errp); * * Returns: the socket address in string format, or NULL on error */ -char *socket_address_to_string(struct SocketAddress *addr, Error **errp); +char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp); /** * socket_address_crumple: * @addr_flat: the socket address to crumple * - * Convert SocketAddressFlat to SocketAddress. Caller is responsible - * for freeing with qapi_free_SocketAddress(). + * Convert SocketAddressFlat to SocketAddressLegacy. Caller is responsible + * for freeing with qapi_free_SocketAddressLegacy(). * - * Returns: the argument converted to SocketAddress. + * Returns: the argument converted to SocketAddressLegacy. */ -SocketAddress *socket_address_crumple(SocketAddressFlat *addr_flat); +SocketAddressLegacy *socket_address_crumple(SocketAddressFlat *addr_flat); #endif /* QEMU_SOCKETS_H */ diff --git a/io/channel-socket.c b/io/channel-socket.c index 53386b7ba3..a21dab640e 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -27,7 +27,7 @@ #define SOCKET_MAX_FDS 16 -SocketAddress * +SocketAddressLegacy * qio_channel_socket_get_local_address(QIOChannelSocket *ioc, Error **errp) { @@ -36,7 +36,7 @@ qio_channel_socket_get_local_address(QIOChannelSocket *ioc, errp); } -SocketAddress * +SocketAddressLegacy * qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, Error **errp) { @@ -134,7 +134,7 @@ qio_channel_socket_new_fd(int fd, int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddressLegacy *addr, Error **errp) { int fd; @@ -160,7 +160,7 @@ static void qio_channel_socket_connect_worker(QIOTask *task, gpointer opaque) { QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task)); - SocketAddress *addr = opaque; + SocketAddressLegacy *addr = opaque; Error *err = NULL; qio_channel_socket_connect_sync(ioc, addr, &err); @@ -170,16 +170,16 @@ static void qio_channel_socket_connect_worker(QIOTask *task, void qio_channel_socket_connect_async(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddressLegacy *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy) { QIOTask *task = qio_task_new( OBJECT(ioc), callback, opaque, destroy); - SocketAddress *addrCopy; + SocketAddressLegacy *addrCopy; - addrCopy = QAPI_CLONE(SocketAddress, addr); + addrCopy = QAPI_CLONE(SocketAddressLegacy, addr); /* socket_connect() does a non-blocking connect(), but it * still blocks in DNS lookups, so we must use a thread */ @@ -187,12 +187,12 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, qio_task_run_in_thread(task, qio_channel_socket_connect_worker, addrCopy, - (GDestroyNotify)qapi_free_SocketAddress); + (GDestroyNotify)qapi_free_SocketAddressLegacy); } int qio_channel_socket_listen_sync(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddressLegacy *addr, Error **errp) { int fd; @@ -219,7 +219,7 @@ static void qio_channel_socket_listen_worker(QIOTask *task, gpointer opaque) { QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task)); - SocketAddress *addr = opaque; + SocketAddressLegacy *addr = opaque; Error *err = NULL; qio_channel_socket_listen_sync(ioc, addr, &err); @@ -229,29 +229,29 @@ static void qio_channel_socket_listen_worker(QIOTask *task, void qio_channel_socket_listen_async(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddressLegacy *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy) { QIOTask *task = qio_task_new( OBJECT(ioc), callback, opaque, destroy); - SocketAddress *addrCopy; + SocketAddressLegacy *addrCopy; - addrCopy = QAPI_CLONE(SocketAddress, addr); + addrCopy = QAPI_CLONE(SocketAddressLegacy, addr); /* socket_listen() blocks in DNS lookups, so we must use a thread */ trace_qio_channel_socket_listen_async(ioc, addr); qio_task_run_in_thread(task, qio_channel_socket_listen_worker, addrCopy, - (GDestroyNotify)qapi_free_SocketAddress); + (GDestroyNotify)qapi_free_SocketAddressLegacy); } int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, - SocketAddress *localAddr, - SocketAddress *remoteAddr, + SocketAddressLegacy *localAddr, + SocketAddressLegacy *remoteAddr, Error **errp) { int fd; @@ -274,16 +274,16 @@ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, struct QIOChannelSocketDGramWorkerData { - SocketAddress *localAddr; - SocketAddress *remoteAddr; + SocketAddressLegacy *localAddr; + SocketAddressLegacy *remoteAddr; }; static void qio_channel_socket_dgram_worker_free(gpointer opaque) { struct QIOChannelSocketDGramWorkerData *data = opaque; - qapi_free_SocketAddress(data->localAddr); - qapi_free_SocketAddress(data->remoteAddr); + qapi_free_SocketAddressLegacy(data->localAddr); + qapi_free_SocketAddressLegacy(data->remoteAddr); g_free(data); } @@ -303,8 +303,8 @@ static void qio_channel_socket_dgram_worker(QIOTask *task, void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, - SocketAddress *localAddr, - SocketAddress *remoteAddr, + SocketAddressLegacy *localAddr, + SocketAddressLegacy *remoteAddr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy) @@ -314,8 +314,8 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, struct QIOChannelSocketDGramWorkerData *data = g_new0( struct QIOChannelSocketDGramWorkerData, 1); - data->localAddr = QAPI_CLONE(SocketAddress, localAddr); - data->remoteAddr = QAPI_CLONE(SocketAddress, remoteAddr); + data->localAddr = QAPI_CLONE(SocketAddressLegacy, localAddr); + data->remoteAddr = QAPI_CLONE(SocketAddressLegacy, remoteAddr); trace_qio_channel_socket_dgram_async(ioc, localAddr, remoteAddr); qio_task_run_in_thread(task, diff --git a/io/dns-resolver.c b/io/dns-resolver.c index 759d1b40d7..d3f0cbf319 100644 --- a/io/dns-resolver.c +++ b/io/dns-resolver.c @@ -45,9 +45,9 @@ QIODNSResolver *qio_dns_resolver_get_instance(void) } static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver, - SocketAddress *addr, + SocketAddressLegacy *addr, size_t *naddrs, - SocketAddress ***addrs, + SocketAddressLegacy ***addrs, Error **errp) { struct addrinfo ai, *res, *e; @@ -97,14 +97,14 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver, (*naddrs)++; } - *addrs = g_new0(SocketAddress *, *naddrs); + *addrs = g_new0(SocketAddressLegacy *, *naddrs); /* create socket + bind */ for (i = 0, e = res; e != NULL; i++, e = e->ai_next) { - SocketAddress *newaddr = g_new0(SocketAddress, 1); + SocketAddressLegacy *newaddr = g_new0(SocketAddressLegacy, 1); InetSocketAddress *newiaddr = g_new0(InetSocketAddress, 1); newaddr->u.inet.data = newiaddr; - newaddr->type = SOCKET_ADDRESS_KIND_INET; + newaddr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; getnameinfo((struct sockaddr *)e->ai_addr, e->ai_addrlen, uaddr, INET6_ADDRSTRLEN, uport, 32, @@ -129,36 +129,36 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver, static int qio_dns_resolver_lookup_sync_nop(QIODNSResolver *resolver, - SocketAddress *addr, + SocketAddressLegacy *addr, size_t *naddrs, - SocketAddress ***addrs, + SocketAddressLegacy ***addrs, Error **errp) { *naddrs = 1; - *addrs = g_new0(SocketAddress *, 1); - (*addrs)[0] = QAPI_CLONE(SocketAddress, addr); + *addrs = g_new0(SocketAddressLegacy *, 1); + (*addrs)[0] = QAPI_CLONE(SocketAddressLegacy, addr); return 0; } int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver, - SocketAddress *addr, + SocketAddressLegacy *addr, size_t *naddrs, - SocketAddress ***addrs, + SocketAddressLegacy ***addrs, Error **errp) { switch (addr->type) { - case SOCKET_ADDRESS_KIND_INET: + case SOCKET_ADDRESS_LEGACY_KIND_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_LEGACY_KIND_UNIX: + case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: + case SOCKET_ADDRESS_LEGACY_KIND_FD: return qio_dns_resolver_lookup_sync_nop(resolver, addr, naddrs, @@ -172,8 +172,8 @@ int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver, struct QIODNSResolverLookupData { - SocketAddress *addr; - SocketAddress **addrs; + SocketAddressLegacy *addr; + SocketAddressLegacy **addrs; size_t naddrs; }; @@ -183,9 +183,9 @@ static void qio_dns_resolver_lookup_data_free(gpointer opaque) struct QIODNSResolverLookupData *data = opaque; size_t i; - qapi_free_SocketAddress(data->addr); + qapi_free_SocketAddressLegacy(data->addr); for (i = 0; i < data->naddrs; i++) { - qapi_free_SocketAddress(data->addrs[i]); + qapi_free_SocketAddressLegacy(data->addrs[i]); } g_free(data->addrs); @@ -216,7 +216,7 @@ static void qio_dns_resolver_lookup_worker(QIOTask *task, void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, - SocketAddress *addr, + SocketAddressLegacy *addr, QIOTaskFunc func, gpointer opaque, GDestroyNotify notify) @@ -225,7 +225,7 @@ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, struct QIODNSResolverLookupData *data = g_new0(struct QIODNSResolverLookupData, 1); - data->addr = QAPI_CLONE(SocketAddress, addr); + data->addr = QAPI_CLONE(SocketAddressLegacy, addr); task = qio_task_new(OBJECT(resolver), func, opaque, notify); @@ -239,7 +239,7 @@ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, void qio_dns_resolver_lookup_result(QIODNSResolver *resolver, QIOTask *task, size_t *naddrs, - SocketAddress ***addrs) + SocketAddressLegacy ***addrs) { struct QIODNSResolverLookupData *data = qio_task_get_result_pointer(task); @@ -252,9 +252,9 @@ void qio_dns_resolver_lookup_result(QIODNSResolver *resolver, } *naddrs = data->naddrs; - *addrs = g_new0(SocketAddress *, data->naddrs); + *addrs = g_new0(SocketAddressLegacy *, data->naddrs); for (i = 0; i < data->naddrs; i++) { - (*addrs)[i] = QAPI_CLONE(SocketAddress, data->addrs[i]); + (*addrs)[i] = QAPI_CLONE(SocketAddressLegacy, data->addrs[i]); } } diff --git a/migration/socket.c b/migration/socket.c index 5fdc723ca3..32032764a0 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -25,30 +25,30 @@ #include "trace.h" -static SocketAddress *tcp_build_address(const char *host_port, Error **errp) +static SocketAddressLegacy *tcp_build_address(const char *host_port, Error **errp) { InetSocketAddress *iaddr = g_new(InetSocketAddress, 1); - SocketAddress *saddr; + SocketAddressLegacy *saddr; if (inet_parse(iaddr, host_port, errp)) { qapi_free_InetSocketAddress(iaddr); return NULL; } - saddr = g_new0(SocketAddress, 1); - saddr->type = SOCKET_ADDRESS_KIND_INET; + saddr = g_new0(SocketAddressLegacy, 1); + saddr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; saddr->u.inet.data = iaddr; return saddr; } -static SocketAddress *unix_build_address(const char *path) +static SocketAddressLegacy *unix_build_address(const char *path) { - SocketAddress *saddr; + SocketAddressLegacy *saddr; - saddr = g_new0(SocketAddress, 1); - saddr->type = SOCKET_ADDRESS_KIND_UNIX; + saddr = g_new0(SocketAddressLegacy, 1); + saddr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1); saddr->u.q_unix.data->path = g_strdup(path); @@ -90,14 +90,14 @@ static void socket_outgoing_migration(QIOTask *task, } static void socket_start_outgoing_migration(MigrationState *s, - SocketAddress *saddr, + SocketAddressLegacy *saddr, Error **errp) { QIOChannelSocket *sioc = qio_channel_socket_new(); struct SocketConnectData *data = g_new0(struct SocketConnectData, 1); data->s = s; - if (saddr->type == SOCKET_ADDRESS_KIND_INET) { + if (saddr->type == SOCKET_ADDRESS_LEGACY_KIND_INET) { data->hostname = g_strdup(saddr->u.inet.data->host); } @@ -107,7 +107,7 @@ static void socket_start_outgoing_migration(MigrationState *s, socket_outgoing_migration, data, socket_connect_data_free); - qapi_free_SocketAddress(saddr); + qapi_free_SocketAddressLegacy(saddr); } void tcp_start_outgoing_migration(MigrationState *s, @@ -115,7 +115,7 @@ void tcp_start_outgoing_migration(MigrationState *s, Error **errp) { Error *err = NULL; - SocketAddress *saddr = tcp_build_address(host_port, &err); + SocketAddressLegacy *saddr = tcp_build_address(host_port, &err); if (!err) { socket_start_outgoing_migration(s, saddr, &err); } @@ -126,7 +126,7 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp) { - SocketAddress *saddr = unix_build_address(path); + SocketAddressLegacy *saddr = unix_build_address(path); socket_start_outgoing_migration(s, saddr, errp); } @@ -160,7 +160,7 @@ out: } -static void socket_start_incoming_migration(SocketAddress *saddr, +static void socket_start_incoming_migration(SocketAddressLegacy *saddr, Error **errp) { QIOChannelSocket *listen_ioc = qio_channel_socket_new(); @@ -170,7 +170,7 @@ static void socket_start_incoming_migration(SocketAddress *saddr, if (qio_channel_socket_listen_sync(listen_ioc, saddr, errp) < 0) { object_unref(OBJECT(listen_ioc)); - qapi_free_SocketAddress(saddr); + qapi_free_SocketAddressLegacy(saddr); return; } @@ -179,13 +179,13 @@ static void socket_start_incoming_migration(SocketAddress *saddr, socket_accept_incoming_migration, listen_ioc, (GDestroyNotify)object_unref); - qapi_free_SocketAddress(saddr); + qapi_free_SocketAddressLegacy(saddr); } void tcp_start_incoming_migration(const char *host_port, Error **errp) { Error *err = NULL; - SocketAddress *saddr = tcp_build_address(host_port, &err); + SocketAddressLegacy *saddr = tcp_build_address(host_port, &err); if (!err) { socket_start_incoming_migration(saddr, &err); } @@ -194,6 +194,6 @@ void tcp_start_incoming_migration(const char *host_port, Error **errp) void unix_start_incoming_migration(const char *path, Error **errp) { - SocketAddress *saddr = unix_build_address(path); + SocketAddressLegacy *saddr = unix_build_address(path); socket_start_incoming_migration(saddr, errp); } diff --git a/net/socket.c b/net/socket.c index b8c931e762..ecd165ffb0 100644 --- a/net/socket.c +++ b/net/socket.c @@ -489,7 +489,7 @@ static int net_socket_listen_init(NetClientState *peer, { NetClientState *nc; NetSocketState *s; - SocketAddress *saddr; + SocketAddressLegacy *saddr; int ret; Error *local_error = NULL; @@ -501,7 +501,7 @@ static int net_socket_listen_init(NetClientState *peer, ret = socket_listen(saddr, &local_error); if (ret < 0) { - qapi_free_SocketAddress(saddr); + qapi_free_SocketAddressLegacy(saddr); error_report_err(local_error); return -1; } @@ -514,20 +514,20 @@ static int net_socket_listen_init(NetClientState *peer, net_socket_rs_init(&s->rs, net_socket_rs_finalize); qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); - qapi_free_SocketAddress(saddr); + qapi_free_SocketAddressLegacy(saddr); return 0; } typedef struct { NetClientState *peer; - SocketAddress *saddr; + SocketAddressLegacy *saddr; char *model; char *name; } socket_connect_data; static void socket_connect_data_free(socket_connect_data *c) { - qapi_free_SocketAddress(c->saddr); + qapi_free_SocketAddressLegacy(c->saddr); g_free(c->model); g_free(c->name); g_free(c); diff --git a/qapi-schema.json b/qapi-schema.json index 5bb8cb79fb..56646e0d57 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4122,13 +4122,15 @@ '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 SocketAddressFlat. +# # Since: 1.3 ## -{ 'union': 'SocketAddress', +{ 'union': 'SocketAddressLegacy', 'data': { 'inet': 'InetSocketAddress', 'unix': 'UnixSocketAddress', @@ -4156,7 +4158,7 @@ # # @type: Transport type # -# This is just like SocketAddress, except it's a flat union rather +# This is just like SocketAddressLegacy, 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 {}. # @@ -4886,7 +4888,7 @@ # # Since: 1.4 ## -{ 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress', +{ 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddressLegacy', '*tls-creds' : 'str', '*server' : 'bool', '*wait' : 'bool', @@ -4906,8 +4908,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.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/qemu-nbd.c b/qemu-nbd.c index e4f00e26dd..82d08597b0 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -57,7 +57,7 @@ static NBDExport *exp; static bool newproto; static int verbose; static char *srcpath; -static SocketAddress *saddr; +static SocketAddressLegacy *saddr; static int persistent = 0; static enum { RUNNING, TERMINATE, TERMINATING, TERMINATED } state; static int shared = 1; @@ -387,20 +387,20 @@ static void nbd_update_server_watch(void) } -static SocketAddress *nbd_build_socket_address(const char *sockpath, +static SocketAddressLegacy *nbd_build_socket_address(const char *sockpath, const char *bindto, const char *port) { - SocketAddress *saddr; + SocketAddressLegacy *saddr; - saddr = g_new0(SocketAddress, 1); + saddr = g_new0(SocketAddressLegacy, 1); if (sockpath) { - saddr->type = SOCKET_ADDRESS_KIND_UNIX; + saddr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1); saddr->u.q_unix.data->path = g_strdup(sockpath); } else { InetSocketAddress *inet; - saddr->type = SOCKET_ADDRESS_KIND_INET; + saddr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; inet = saddr->u.inet.data = g_new0(InetSocketAddress, 1); inet->host = g_strdup(bindto); if (port) { diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 3f34465159..65ab8eb634 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -203,7 +203,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, case GA_CHANNEL_VSOCK_LISTEN: { if (fd < 0) { Error *local_err = NULL; - SocketAddress *addr; + SocketAddressLegacy *addr; char *addr_str; addr_str = g_strdup_printf("vsock:%s", path); @@ -216,7 +216,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, } fd = socket_listen(addr, &local_err); - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); if (local_err != NULL) { g_critical("%s", error_get_pretty(local_err)); error_free(local_err); diff --git a/qga/main.c b/qga/main.c index ad6f68f187..cae4d7b36f 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1379,7 +1379,7 @@ int main(int argc, char **argv) goto end; } if (socket_activation) { - SocketAddress *addr; + SocketAddressLegacy *addr; g_free(config->method); g_free(config->channel_path); @@ -1388,13 +1388,13 @@ 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_LEGACY_KIND_UNIX) { config->method = g_strdup("unix-listen"); - } else if (addr->type == SOCKET_ADDRESS_KIND_VSOCK) { + } else if (addr->type == SOCKET_ADDRESS_LEGACY_KIND_VSOCK) { config->method = g_strdup("vsock-listen"); } - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); } if (!config->method) { diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index c5c131479c..a66ffc2fbc 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -115,8 +115,8 @@ static void test_io_channel_set_socket_bufs(QIOChannel *src, } -static void test_io_channel_setup_sync(SocketAddress *listen_addr, - SocketAddress *connect_addr, +static void test_io_channel_setup_sync(SocketAddressLegacy *listen_addr, + SocketAddressLegacy *connect_addr, QIOChannel **src, QIOChannel **dst) { @@ -125,14 +125,14 @@ 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) { - SocketAddress *laddr = qio_channel_socket_get_local_address( + if (listen_addr->type == SOCKET_ADDRESS_LEGACY_KIND_INET) { + SocketAddressLegacy *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); - qapi_free_SocketAddress(laddr); + qapi_free_SocketAddressLegacy(laddr); } *src = QIO_CHANNEL(qio_channel_socket_new()); @@ -165,8 +165,8 @@ static void test_io_channel_complete(QIOTask *task, } -static void test_io_channel_setup_async(SocketAddress *listen_addr, - SocketAddress *connect_addr, +static void test_io_channel_setup_async(SocketAddressLegacy *listen_addr, + SocketAddressLegacy *connect_addr, QIOChannel **src, QIOChannel **dst) { @@ -186,14 +186,14 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr, g_assert(!data.err); - if (listen_addr->type == SOCKET_ADDRESS_KIND_INET) { - SocketAddress *laddr = qio_channel_socket_get_local_address( + if (listen_addr->type == SOCKET_ADDRESS_LEGACY_KIND_INET) { + SocketAddressLegacy *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); - qapi_free_SocketAddress(laddr); + qapi_free_SocketAddressLegacy(laddr); } *src = QIO_CHANNEL(qio_channel_socket_new()); @@ -221,8 +221,8 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr, static void test_io_channel(bool async, - SocketAddress *listen_addr, - SocketAddress *connect_addr, + SocketAddressLegacy *listen_addr, + SocketAddressLegacy *connect_addr, bool passFD) { QIOChannel *src, *dst; @@ -297,17 +297,17 @@ static void test_io_channel(bool async, static void test_io_channel_ipv4(bool async) { - SocketAddress *listen_addr = g_new0(SocketAddress, 1); - SocketAddress *connect_addr = g_new0(SocketAddress, 1); + SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1); + SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1); - listen_addr->type = SOCKET_ADDRESS_KIND_INET; + listen_addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; listen_addr->u.inet.data = g_new(InetSocketAddress, 1); *listen_addr->u.inet.data = (InetSocketAddress) { .host = g_strdup("127.0.0.1"), .port = NULL, /* Auto-select */ }; - connect_addr->type = SOCKET_ADDRESS_KIND_INET; + connect_addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; connect_addr->u.inet.data = g_new(InetSocketAddress, 1); *connect_addr->u.inet.data = (InetSocketAddress) { .host = g_strdup("127.0.0.1"), @@ -316,8 +316,8 @@ static void test_io_channel_ipv4(bool async) test_io_channel(async, listen_addr, connect_addr, false); - qapi_free_SocketAddress(listen_addr); - qapi_free_SocketAddress(connect_addr); + qapi_free_SocketAddressLegacy(listen_addr); + qapi_free_SocketAddressLegacy(connect_addr); } @@ -335,17 +335,17 @@ static void test_io_channel_ipv4_async(void) static void test_io_channel_ipv6(bool async) { - SocketAddress *listen_addr = g_new0(SocketAddress, 1); - SocketAddress *connect_addr = g_new0(SocketAddress, 1); + SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1); + SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1); - listen_addr->type = SOCKET_ADDRESS_KIND_INET; + listen_addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; listen_addr->u.inet.data = g_new(InetSocketAddress, 1); *listen_addr->u.inet.data = (InetSocketAddress) { .host = g_strdup("::1"), .port = NULL, /* Auto-select */ }; - connect_addr->type = SOCKET_ADDRESS_KIND_INET; + connect_addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; connect_addr->u.inet.data = g_new(InetSocketAddress, 1); *connect_addr->u.inet.data = (InetSocketAddress) { .host = g_strdup("::1"), @@ -354,8 +354,8 @@ static void test_io_channel_ipv6(bool async) test_io_channel(async, listen_addr, connect_addr, false); - qapi_free_SocketAddress(listen_addr); - qapi_free_SocketAddress(connect_addr); + qapi_free_SocketAddressLegacy(listen_addr); + qapi_free_SocketAddressLegacy(connect_addr); } @@ -374,22 +374,22 @@ static void test_io_channel_ipv6_async(void) #ifndef _WIN32 static void test_io_channel_unix(bool async) { - SocketAddress *listen_addr = g_new0(SocketAddress, 1); - SocketAddress *connect_addr = g_new0(SocketAddress, 1); + SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1); + SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1); #define TEST_SOCKET "test-io-channel-socket.sock" - listen_addr->type = SOCKET_ADDRESS_KIND_UNIX; + listen_addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; listen_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); listen_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET); - connect_addr->type = SOCKET_ADDRESS_KIND_UNIX; + connect_addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; connect_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); connect_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET); test_io_channel(async, listen_addr, connect_addr, true); - qapi_free_SocketAddress(listen_addr); - qapi_free_SocketAddress(connect_addr); + qapi_free_SocketAddressLegacy(listen_addr); + qapi_free_SocketAddressLegacy(connect_addr); g_assert(g_file_test(TEST_SOCKET, G_FILE_TEST_EXISTS) == FALSE); } @@ -407,8 +407,8 @@ static void test_io_channel_unix_async(void) static void test_io_channel_unix_fd_pass(void) { - SocketAddress *listen_addr = g_new0(SocketAddress, 1); - SocketAddress *connect_addr = g_new0(SocketAddress, 1); + SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1); + SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1); QIOChannel *src, *dst; int testfd; int fdsend[3]; @@ -427,11 +427,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->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; listen_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); listen_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET); - connect_addr->type = SOCKET_ADDRESS_KIND_UNIX; + connect_addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; connect_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); connect_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET); @@ -488,8 +488,8 @@ static void test_io_channel_unix_fd_pass(void) object_unref(OBJECT(src)); object_unref(OBJECT(dst)); - qapi_free_SocketAddress(listen_addr); - qapi_free_SocketAddress(connect_addr); + qapi_free_SocketAddressLegacy(listen_addr); + qapi_free_SocketAddressLegacy(connect_addr); unlink(TEST_SOCKET); unlink(TEST_FILE); close(testfd); diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c index 5ae29c14cf..c7fa9b65b9 100644 --- a/ui/vnc-auth-sasl.c +++ b/ui/vnc-auth-sasl.c @@ -498,7 +498,7 @@ vnc_socket_ip_addr_string(QIOChannelSocket *ioc, bool local, Error **errp) { - SocketAddress *addr; + SocketAddressLegacy *addr; char *ret; if (local) { @@ -510,13 +510,13 @@ vnc_socket_ip_addr_string(QIOChannelSocket *ioc, return NULL; } - if (addr->type != SOCKET_ADDRESS_KIND_INET) { + if (addr->type != SOCKET_ADDRESS_LEGACY_KIND_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); - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); return ret; } diff --git a/ui/vnc.c b/ui/vnc.c index 349cfc9d86..5090a2562f 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -108,12 +108,12 @@ static void vnc_set_share_mode(VncState *vs, VncShareMode mode) } -static void vnc_init_basic_info(SocketAddress *addr, +static void vnc_init_basic_info(SocketAddressLegacy *addr, VncBasicInfo *info, Error **errp) { switch (addr->type) { - case SOCKET_ADDRESS_KIND_INET: + case SOCKET_ADDRESS_LEGACY_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) { @@ -123,16 +123,16 @@ static void vnc_init_basic_info(SocketAddress *addr, } break; - case SOCKET_ADDRESS_KIND_UNIX: + case SOCKET_ADDRESS_LEGACY_KIND_UNIX: info->host = g_strdup(""); info->service = g_strdup(addr->u.q_unix.data->path); info->family = NETWORK_ADDRESS_FAMILY_UNIX; break; - case SOCKET_ADDRESS_KIND_VSOCK: - case SOCKET_ADDRESS_KIND_FD: + case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: + case SOCKET_ADDRESS_LEGACY_KIND_FD: error_setg(errp, "Unsupported socket address type %s", - SocketAddressKind_lookup[addr->type]); + SocketAddressLegacyKind_lookup[addr->type]); break; default: abort(); @@ -145,7 +145,7 @@ static void vnc_init_basic_info_from_server_addr(QIOChannelSocket *ioc, VncBasicInfo *info, Error **errp) { - SocketAddress *addr = NULL; + SocketAddressLegacy *addr = NULL; if (!ioc) { error_setg(errp, "No listener socket available"); @@ -158,14 +158,14 @@ static void vnc_init_basic_info_from_server_addr(QIOChannelSocket *ioc, } vnc_init_basic_info(addr, info, errp); - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); } static void vnc_init_basic_info_from_remote_addr(QIOChannelSocket *ioc, VncBasicInfo *info, Error **errp) { - SocketAddress *addr = NULL; + SocketAddressLegacy *addr = NULL; addr = qio_channel_socket_get_remote_address(ioc, errp); if (!addr) { @@ -173,7 +173,7 @@ static void vnc_init_basic_info_from_remote_addr(QIOChannelSocket *ioc, } vnc_init_basic_info(addr, info, errp); - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); } static const char *vnc_auth_name(VncDisplay *vd) { @@ -377,7 +377,7 @@ VncInfo *qmp_query_vnc(Error **errp) { VncInfo *info = g_malloc0(sizeof(*info)); VncDisplay *vd = vnc_display_find(NULL); - SocketAddress *addr = NULL; + SocketAddressLegacy *addr = NULL; if (vd == NULL || !vd->nlsock) { info->enabled = false; @@ -398,7 +398,7 @@ VncInfo *qmp_query_vnc(Error **errp) } switch (addr->type) { - case SOCKET_ADDRESS_KIND_INET: + case SOCKET_ADDRESS_LEGACY_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) { @@ -408,16 +408,16 @@ VncInfo *qmp_query_vnc(Error **errp) } break; - case SOCKET_ADDRESS_KIND_UNIX: + case SOCKET_ADDRESS_LEGACY_KIND_UNIX: info->host = g_strdup(""); info->service = g_strdup(addr->u.q_unix.data->path); info->family = NETWORK_ADDRESS_FAMILY_UNIX; break; - case SOCKET_ADDRESS_KIND_VSOCK: - case SOCKET_ADDRESS_KIND_FD: + case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: + case SOCKET_ADDRESS_LEGACY_KIND_FD: error_setg(errp, "Unsupported socket address type %s", - SocketAddressKind_lookup[addr->type]); + SocketAddressLegacyKind_lookup[addr->type]); goto out_error; default: abort(); @@ -431,11 +431,11 @@ VncInfo *qmp_query_vnc(Error **errp) info->auth = g_strdup(vnc_auth_name(vd)); } - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); return info; out_error: - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); qapi_free_VncInfo(info); return NULL; } @@ -455,7 +455,7 @@ static VncServerInfo2List *qmp_query_server_entry(QIOChannelSocket *ioc, VncServerInfo2List *list; VncServerInfo2 *info; Error *err = NULL; - SocketAddress *addr; + SocketAddressLegacy *addr; addr = qio_channel_socket_get_local_address(ioc, &err); if (!addr) { @@ -465,7 +465,7 @@ static VncServerInfo2List *qmp_query_server_entry(QIOChannelSocket *ioc, info = g_new0(VncServerInfo2, 1); vnc_init_basic_info(addr, qapi_VncServerInfo2_base(info), &err); - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); if (err) { qapi_free_VncServerInfo2(info); error_free(err); @@ -3149,7 +3149,7 @@ int vnc_display_pw_expire(const char *id, time_t expires) static void vnc_display_print_local_addr(VncDisplay *vd) { - SocketAddress *addr; + SocketAddressLegacy *addr; Error *err = NULL; if (!vd->nlsock) { @@ -3161,14 +3161,14 @@ static void vnc_display_print_local_addr(VncDisplay *vd) return; } - if (addr->type != SOCKET_ADDRESS_KIND_INET) { - qapi_free_SocketAddress(addr); + if (addr->type != SOCKET_ADDRESS_LEGACY_KIND_INET) { + qapi_free_SocketAddressLegacy(addr); return; } error_printf_unless_qmp("VNC server running on %s:%s\n", addr->u.inet.data->host, addr->u.inet.data->port); - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); } static QemuOptsList qemu_vnc_opts = { @@ -3414,16 +3414,16 @@ static int vnc_display_get_address(const char *addrstr, bool has_ipv6, bool ipv4, bool ipv6, - SocketAddress **retaddr, + SocketAddressLegacy **retaddr, Error **errp) { int ret = -1; - SocketAddress *addr = NULL; + SocketAddressLegacy *addr = NULL; - addr = g_new0(SocketAddress, 1); + addr = g_new0(SocketAddressLegacy, 1); if (strncmp(addrstr, "unix:", 5) == 0) { - addr->type = SOCKET_ADDRESS_KIND_UNIX; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); addr->u.q_unix.data->path = g_strdup(addrstr + 5); @@ -3461,7 +3461,7 @@ static int vnc_display_get_address(const char *addrstr, } } - addr->type = SOCKET_ADDRESS_KIND_INET; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; inet = addr->u.inet.data = g_new0(InetSocketAddress, 1); if (addrstr[0] == '[' && addrstr[hostlen - 1] == ']') { inet->host = g_strndup(addrstr + 1, hostlen - 2); @@ -3518,21 +3518,21 @@ static int vnc_display_get_address(const char *addrstr, cleanup: if (ret < 0) { - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); } return ret; } static int vnc_display_get_addresses(QemuOpts *opts, bool reverse, - SocketAddress ***retsaddr, + SocketAddressLegacy ***retsaddr, size_t *retnsaddr, - SocketAddress ***retwsaddr, + SocketAddressLegacy ***retwsaddr, size_t *retnwsaddr, Error **errp) { - SocketAddress *saddr = NULL; - SocketAddress *wsaddr = NULL; + SocketAddressLegacy *saddr = NULL; + SocketAddressLegacy *wsaddr = NULL; QemuOptsIter addriter; const char *addr; int to = qemu_opt_get_number(opts, "to", 0); @@ -3577,7 +3577,7 @@ static int vnc_display_get_addresses(QemuOpts *opts, if (displaynum == -1) { displaynum = rv; } - *retsaddr = g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1); + *retsaddr = g_renew(SocketAddressLegacy *, *retsaddr, *retnsaddr + 1); (*retsaddr)[(*retnsaddr)++] = saddr; } @@ -3601,8 +3601,8 @@ 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 && + (*retsaddr)[0]->type == SOCKET_ADDRESS_LEGACY_KIND_INET && + wsaddr->type == SOCKET_ADDRESS_LEGACY_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); @@ -3610,7 +3610,7 @@ static int vnc_display_get_addresses(QemuOpts *opts, g_strdup((*retsaddr)[0]->u.inet.data->host); } - *retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1); + *retwsaddr = g_renew(SocketAddressLegacy *, *retwsaddr, *retnwsaddr + 1); (*retwsaddr)[(*retnwsaddr)++] = wsaddr; } @@ -3618,11 +3618,11 @@ static int vnc_display_get_addresses(QemuOpts *opts, cleanup: if (ret < 0) { for (i = 0; i < *retnsaddr; i++) { - qapi_free_SocketAddress((*retsaddr)[i]); + qapi_free_SocketAddressLegacy((*retsaddr)[i]); } g_free(*retsaddr); for (i = 0; i < *retnwsaddr; i++) { - qapi_free_SocketAddress((*retwsaddr)[i]); + qapi_free_SocketAddressLegacy((*retwsaddr)[i]); } g_free(*retwsaddr); *retsaddr = *retwsaddr = NULL; @@ -3632,9 +3632,9 @@ static int vnc_display_get_addresses(QemuOpts *opts, } static int vnc_display_connect(VncDisplay *vd, - SocketAddress **saddr, + SocketAddressLegacy **saddr, size_t nsaddr, - SocketAddress **wsaddr, + SocketAddressLegacy **wsaddr, size_t nwsaddr, Error **errp) { @@ -3648,8 +3648,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_LEGACY_KIND_FD when fd has AF_UNIX */ + vd->is_unix = saddr[0]->type == SOCKET_ADDRESS_LEGACY_KIND_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) { @@ -3662,7 +3662,7 @@ static int vnc_display_connect(VncDisplay *vd, static int vnc_display_listen_addr(VncDisplay *vd, - SocketAddress *addr, + SocketAddressLegacy *addr, const char *name, QIOChannelSocket ***lsock, guint **lsock_tag, @@ -3670,7 +3670,7 @@ static int vnc_display_listen_addr(VncDisplay *vd, Error **errp) { QIODNSResolver *resolver = qio_dns_resolver_get_instance(); - SocketAddress **rawaddrs = NULL; + SocketAddressLegacy **rawaddrs = NULL; size_t nrawaddrs = 0; Error *listenerr = NULL; bool listening = false; @@ -3700,7 +3700,7 @@ static int vnc_display_listen_addr(VncDisplay *vd, } for (i = 0; i < nrawaddrs; i++) { - qapi_free_SocketAddress(rawaddrs[i]); + qapi_free_SocketAddressLegacy(rawaddrs[i]); } g_free(rawaddrs); @@ -3724,9 +3724,9 @@ static int vnc_display_listen_addr(VncDisplay *vd, static int vnc_display_listen(VncDisplay *vd, - SocketAddress **saddr, + SocketAddressLegacy **saddr, size_t nsaddr, - SocketAddress **wsaddr, + SocketAddressLegacy **wsaddr, size_t nwsaddr, Error **errp) { @@ -3761,7 +3761,7 @@ void vnc_display_open(const char *id, Error **errp) { VncDisplay *vd = vnc_display_find(id); QemuOpts *opts = qemu_opts_find(&qemu_vnc_opts, id); - SocketAddress **saddr = NULL, **wsaddr = NULL; + SocketAddressLegacy **saddr = NULL, **wsaddr = NULL; size_t nsaddr, nwsaddr; const char *share, *device_id; QemuConsole *con; @@ -3997,10 +3997,10 @@ void vnc_display_open(const char *id, Error **errp) cleanup: for (i = 0; i < nsaddr; i++) { - qapi_free_SocketAddress(saddr[i]); + qapi_free_SocketAddressLegacy(saddr[i]); } for (i = 0; i < nwsaddr; i++) { - qapi_free_SocketAddress(wsaddr[i]); + qapi_free_SocketAddressLegacy(wsaddr[i]); } return; diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 62c93ba9a1..4c48203738 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1029,17 +1029,17 @@ int unix_connect(const char *path, Error **errp) } -SocketAddress *socket_parse(const char *str, Error **errp) +SocketAddressLegacy *socket_parse(const char *str, Error **errp) { - SocketAddress *addr; + SocketAddressLegacy *addr; - addr = g_new0(SocketAddress, 1); + addr = g_new0(SocketAddressLegacy, 1); if (strstart(str, "unix:", NULL)) { if (str[5] == '\0') { error_setg(errp, "invalid Unix socket address"); goto fail; } else { - addr->type = SOCKET_ADDRESS_KIND_UNIX; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; addr->u.q_unix.data = g_new(UnixSocketAddress, 1); addr->u.q_unix.data->path = g_strdup(str + 5); } @@ -1048,18 +1048,18 @@ SocketAddress *socket_parse(const char *str, Error **errp) error_setg(errp, "invalid file descriptor address"); goto fail; } else { - addr->type = SOCKET_ADDRESS_KIND_FD; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_FD; addr->u.fd.data = g_new(String, 1); addr->u.fd.data->str = g_strdup(str + 3); } } else if (strstart(str, "vsock:", NULL)) { - addr->type = SOCKET_ADDRESS_KIND_VSOCK; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_VSOCK; addr->u.vsock.data = g_new(VsockSocketAddress, 1); if (vsock_parse(addr->u.vsock.data, str + strlen("vsock:"), errp)) { goto fail; } } else { - addr->type = SOCKET_ADDRESS_KIND_INET; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; addr->u.inet.data = g_new(InetSocketAddress, 1); if (inet_parse(addr->u.inet.data, str, errp)) { goto fail; @@ -1068,25 +1068,25 @@ SocketAddress *socket_parse(const char *str, Error **errp) return addr; fail: - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); return NULL; } -int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, +int socket_connect(SocketAddressLegacy *addr, NonBlockingConnectHandler *callback, void *opaque, Error **errp) { int fd; switch (addr->type) { - case SOCKET_ADDRESS_KIND_INET: + case SOCKET_ADDRESS_LEGACY_KIND_INET: fd = inet_connect_saddr(addr->u.inet.data, callback, opaque, errp); break; - case SOCKET_ADDRESS_KIND_UNIX: + case SOCKET_ADDRESS_LEGACY_KIND_UNIX: fd = unix_connect_saddr(addr->u.q_unix.data, callback, opaque, errp); break; - case SOCKET_ADDRESS_KIND_FD: + case SOCKET_ADDRESS_LEGACY_KIND_FD: fd = monitor_get_fd(cur_mon, addr->u.fd.data->str, errp); if (fd >= 0 && callback) { qemu_set_nonblock(fd); @@ -1094,7 +1094,7 @@ int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, } break; - case SOCKET_ADDRESS_KIND_VSOCK: + case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: fd = vsock_connect_saddr(addr->u.vsock.data, callback, opaque, errp); break; @@ -1104,24 +1104,24 @@ int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, return fd; } -int socket_listen(SocketAddress *addr, Error **errp) +int socket_listen(SocketAddressLegacy *addr, Error **errp) { int fd; switch (addr->type) { - case SOCKET_ADDRESS_KIND_INET: + case SOCKET_ADDRESS_LEGACY_KIND_INET: fd = inet_listen_saddr(addr->u.inet.data, 0, false, errp); break; - case SOCKET_ADDRESS_KIND_UNIX: + case SOCKET_ADDRESS_LEGACY_KIND_UNIX: fd = unix_listen_saddr(addr->u.q_unix.data, false, errp); break; - case SOCKET_ADDRESS_KIND_FD: + case SOCKET_ADDRESS_LEGACY_KIND_FD: fd = monitor_get_fd(cur_mon, addr->u.fd.data->str, errp); break; - case SOCKET_ADDRESS_KIND_VSOCK: + case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: fd = vsock_listen_saddr(addr->u.vsock.data, errp); break; @@ -1133,11 +1133,11 @@ int socket_listen(SocketAddress *addr, Error **errp) void socket_listen_cleanup(int fd, Error **errp) { - SocketAddress *addr; + SocketAddressLegacy *addr; addr = socket_local_address(fd, errp); - if (addr->type == SOCKET_ADDRESS_KIND_UNIX + if (addr->type == SOCKET_ADDRESS_LEGACY_KIND_UNIX && addr->u.q_unix.data->path) { if (unlink(addr->u.q_unix.data->path) < 0 && errno != ENOENT) { error_setg_errno(errp, errno, @@ -1146,19 +1146,19 @@ void socket_listen_cleanup(int fd, Error **errp) } } - qapi_free_SocketAddress(addr); + qapi_free_SocketAddressLegacy(addr); } -int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) +int socket_dgram(SocketAddressLegacy *remote, SocketAddressLegacy *local, Error **errp) { int fd; /* - * TODO SOCKET_ADDRESS_KIND_FD when fd is AF_INET or AF_INET6 + * TODO SOCKET_ADDRESS_LEGACY_KIND_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: + case SOCKET_ADDRESS_LEGACY_KIND_INET: fd = inet_dgram_saddr(remote->u.inet.data, local ? local->u.inet.data : NULL, errp); break; @@ -1171,14 +1171,14 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) } -static SocketAddress * +static SocketAddressLegacy * socket_sockaddr_to_address_inet(struct sockaddr_storage *sa, socklen_t salen, Error **errp) { char host[NI_MAXHOST]; char serv[NI_MAXSERV]; - SocketAddress *addr; + SocketAddressLegacy *addr; InetSocketAddress *inet; int ret; @@ -1192,8 +1192,8 @@ socket_sockaddr_to_address_inet(struct sockaddr_storage *sa, return NULL; } - addr = g_new0(SocketAddress, 1); - addr->type = SOCKET_ADDRESS_KIND_INET; + addr = g_new0(SocketAddressLegacy, 1); + addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; inet = addr->u.inet.data = g_new0(InetSocketAddress, 1); inet->host = g_strdup(host); inet->port = g_strdup(serv); @@ -1208,16 +1208,16 @@ socket_sockaddr_to_address_inet(struct sockaddr_storage *sa, #ifndef WIN32 -static SocketAddress * +static SocketAddressLegacy * socket_sockaddr_to_address_unix(struct sockaddr_storage *sa, socklen_t salen, Error **errp) { - SocketAddress *addr; + SocketAddressLegacy *addr; struct sockaddr_un *su = (struct sockaddr_un *)sa; - addr = g_new0(SocketAddress, 1); - addr->type = SOCKET_ADDRESS_KIND_UNIX; + addr = g_new0(SocketAddressLegacy, 1); + addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); if (su->sun_path[0]) { addr->u.q_unix.data->path = g_strndup(su->sun_path, @@ -1229,17 +1229,17 @@ socket_sockaddr_to_address_unix(struct sockaddr_storage *sa, #endif /* WIN32 */ #ifdef CONFIG_AF_VSOCK -static SocketAddress * +static SocketAddressLegacy * socket_sockaddr_to_address_vsock(struct sockaddr_storage *sa, socklen_t salen, Error **errp) { - SocketAddress *addr; + SocketAddressLegacy *addr; VsockSocketAddress *vaddr; struct sockaddr_vm *svm = (struct sockaddr_vm *)sa; - addr = g_new0(SocketAddress, 1); - addr->type = SOCKET_ADDRESS_KIND_VSOCK; + addr = g_new0(SocketAddressLegacy, 1); + addr->type = SOCKET_ADDRESS_LEGACY_KIND_VSOCK; addr->u.vsock.data = vaddr = g_new0(VsockSocketAddress, 1); vaddr->cid = g_strdup_printf("%u", svm->svm_cid); vaddr->port = g_strdup_printf("%u", svm->svm_port); @@ -1248,7 +1248,7 @@ socket_sockaddr_to_address_vsock(struct sockaddr_storage *sa, } #endif /* CONFIG_AF_VSOCK */ -SocketAddress * +SocketAddressLegacy * socket_sockaddr_to_address(struct sockaddr_storage *sa, socklen_t salen, Error **errp) @@ -1277,7 +1277,7 @@ socket_sockaddr_to_address(struct sockaddr_storage *sa, } -SocketAddress *socket_local_address(int fd, Error **errp) +SocketAddressLegacy *socket_local_address(int fd, Error **errp) { struct sockaddr_storage ss; socklen_t sslen = sizeof(ss); @@ -1292,7 +1292,7 @@ SocketAddress *socket_local_address(int fd, Error **errp) } -SocketAddress *socket_remote_address(int fd, Error **errp) +SocketAddressLegacy *socket_remote_address(int fd, Error **errp) { struct sockaddr_storage ss; socklen_t sslen = sizeof(ss); @@ -1306,13 +1306,13 @@ SocketAddress *socket_remote_address(int fd, Error **errp) return socket_sockaddr_to_address(&ss, sslen, errp); } -char *socket_address_to_string(struct SocketAddress *addr, Error **errp) +char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp) { char *buf; InetSocketAddress *inet; switch (addr->type) { - case SOCKET_ADDRESS_KIND_INET: + case SOCKET_ADDRESS_LEGACY_KIND_INET: inet = addr->u.inet.data; if (strchr(inet->host, ':') == NULL) { buf = g_strdup_printf("%s:%s", inet->host, inet->port); @@ -1321,15 +1321,15 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp) } break; - case SOCKET_ADDRESS_KIND_UNIX: + case SOCKET_ADDRESS_LEGACY_KIND_UNIX: buf = g_strdup(addr->u.q_unix.data->path); break; - case SOCKET_ADDRESS_KIND_FD: + case SOCKET_ADDRESS_LEGACY_KIND_FD: buf = g_strdup(addr->u.fd.data->str); break; - case SOCKET_ADDRESS_KIND_VSOCK: + case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: buf = g_strdup_printf("%s:%s", addr->u.vsock.data->cid, addr->u.vsock.data->port); @@ -1341,28 +1341,28 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp) return buf; } -SocketAddress *socket_address_crumple(SocketAddressFlat *addr_flat) +SocketAddressLegacy *socket_address_crumple(SocketAddressFlat *addr_flat) { - SocketAddress *addr = g_new(SocketAddress, 1); + SocketAddressLegacy *addr = g_new(SocketAddressLegacy, 1); switch (addr_flat->type) { case SOCKET_ADDRESS_FLAT_TYPE_INET: - addr->type = SOCKET_ADDRESS_KIND_INET; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; addr->u.inet.data = QAPI_CLONE(InetSocketAddress, &addr_flat->u.inet); break; case SOCKET_ADDRESS_FLAT_TYPE_UNIX: - addr->type = SOCKET_ADDRESS_KIND_UNIX; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; addr->u.q_unix.data = QAPI_CLONE(UnixSocketAddress, &addr_flat->u.q_unix); break; case SOCKET_ADDRESS_FLAT_TYPE_VSOCK: - addr->type = SOCKET_ADDRESS_KIND_VSOCK; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_VSOCK; addr->u.vsock.data = QAPI_CLONE(VsockSocketAddress, &addr_flat->u.vsock); break; case SOCKET_ADDRESS_FLAT_TYPE_FD: - addr->type = SOCKET_ADDRESS_KIND_FD; + addr->type = SOCKET_ADDRESS_LEGACY_KIND_FD; addr->u.fd.data = QAPI_CLONE(String, &addr_flat->u.fd); break; default: From 62cf396b5d397948c5ac4d04d09596ca14f6c173 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:40 +0200 Subject: [PATCH 17/28] sockets: Rename SocketAddressFlat to SocketAddress Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-6-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Prasanna Kumar Kalever --- block/gluster.c | 48 +++++++++++++++++++++--------------------- block/nbd.c | 26 +++++++++++------------ block/sheepdog.c | 6 +++--- include/qemu/sockets.h | 4 ++-- qapi-schema.json | 14 ++++++------ qapi/block-core.json | 6 +++--- util/qemu-sockets.c | 10 ++++----- 7 files changed, 57 insertions(+), 57 deletions(-) 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 7f11a939fc..bbe0f99d6c 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; @@ -258,10 +258,10 @@ static bool nbd_process_legacy_socket_options(QDict *output_options, 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; @@ -287,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; @@ -306,7 +306,7 @@ 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_flat, Error **errp) { SocketAddressLegacy *saddr = socket_address_crumple(saddr_flat); @@ -412,7 +412,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; } @@ -433,7 +433,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; } @@ -460,7 +460,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); } @@ -486,7 +486,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); } @@ -517,13 +517,13 @@ 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 */ @@ -544,7 +544,7 @@ 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); diff --git a/block/sheepdog.c b/block/sheepdog.c index 055d10be17..b8d69b31e7 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -554,7 +554,7 @@ static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp) QDict *server = NULL; QObject *crumpled_server = NULL; Visitor *iv = NULL; - SocketAddressFlat *saddr_flat = NULL; + SocketAddress *saddr_flat = NULL; SocketAddressLegacy *saddr = NULL; Error *local_err = NULL; @@ -574,7 +574,7 @@ static SocketAddressLegacy *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_flat, &local_err); if (local_err) { error_propagate(errp, local_err); goto done; @@ -583,7 +583,7 @@ static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp) saddr = socket_address_crumple(saddr_flat); done: - qapi_free_SocketAddressFlat(saddr_flat); + qapi_free_SocketAddress(saddr_flat); visit_free(iv); qobject_decref(crumpled_server); QDECREF(server); diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index f4a4b10acf..82b7460ea4 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -124,11 +124,11 @@ char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp); * socket_address_crumple: * @addr_flat: the socket address to crumple * - * Convert SocketAddressFlat to SocketAddressLegacy. Caller is responsible + * Convert SocketAddress to SocketAddressLegacy. Caller is responsible * for freeing with qapi_free_SocketAddressLegacy(). * * Returns: the argument converted to SocketAddressLegacy. */ -SocketAddressLegacy *socket_address_crumple(SocketAddressFlat *addr_flat); +SocketAddressLegacy *socket_address_crumple(SocketAddress *addr); #endif /* QEMU_SOCKETS_H */ diff --git a/qapi-schema.json b/qapi-schema.json index 56646e0d57..eab41396e1 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4126,7 +4126,7 @@ # # Captures the address of a socket, which could also be a named file descriptor # -# Note: This type is deprecated in favor of SocketAddressFlat. +# Note: This type is deprecated in favor of SocketAddress. # # Since: 1.3 ## @@ -4138,9 +4138,9 @@ 'fd': 'String' } } ## -# @SocketAddressFlatType: +# @SocketAddressType: # -# Available SocketAddressFlat types +# Available SocketAddress types # # @inet: Internet address # @@ -4148,11 +4148,11 @@ # # Since: 2.9 ## -{ 'enum': 'SocketAddressFlatType', +{ 'enum': 'SocketAddressType', 'data': [ 'inet', 'unix', 'vsock', 'fd' ] } ## -# @SocketAddressFlat: +# @SocketAddress: # # Captures the address of a socket # @@ -4164,8 +4164,8 @@ # # Since: 2.9 ## -{ 'union': 'SocketAddressFlat', - 'base': { 'type': 'SocketAddressFlatType' }, +{ 'union': 'SocketAddress', + 'base': { 'type': 'SocketAddressType' }, 'discriminator': 'type', 'data': { 'inet': 'InetSocketAddress', 'unix': 'UnixSocketAddress', 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/util/qemu-sockets.c b/util/qemu-sockets.c index 4c48203738..801aa7a0c1 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1341,27 +1341,27 @@ char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp) return buf; } -SocketAddressLegacy *socket_address_crumple(SocketAddressFlat *addr_flat) +SocketAddressLegacy *socket_address_crumple(SocketAddress *addr_flat) { SocketAddressLegacy *addr = g_new(SocketAddressLegacy, 1); switch (addr_flat->type) { - case SOCKET_ADDRESS_FLAT_TYPE_INET: + case SOCKET_ADDRESS_TYPE_INET: addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; addr->u.inet.data = QAPI_CLONE(InetSocketAddress, &addr_flat->u.inet); break; - case SOCKET_ADDRESS_FLAT_TYPE_UNIX: + case SOCKET_ADDRESS_TYPE_UNIX: addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; addr->u.q_unix.data = QAPI_CLONE(UnixSocketAddress, &addr_flat->u.q_unix); break; - case SOCKET_ADDRESS_FLAT_TYPE_VSOCK: + case SOCKET_ADDRESS_TYPE_VSOCK: addr->type = SOCKET_ADDRESS_LEGACY_KIND_VSOCK; addr->u.vsock.data = QAPI_CLONE(VsockSocketAddress, &addr_flat->u.vsock); break; - case SOCKET_ADDRESS_FLAT_TYPE_FD: + case SOCKET_ADDRESS_TYPE_FD: addr->type = SOCKET_ADDRESS_LEGACY_KIND_FD; addr->u.fd.data = QAPI_CLONE(String, &addr_flat->u.fd); break; From bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:41 +0200 Subject: [PATCH 18/28] sockets: Limit SocketAddressLegacy to external interfaces SocketAddressLegacy is a simple union, and simple unions are awkward: they have their variant members wrapped in a "data" object on the wire, and require additional indirections in C. SocketAddress is the equivalent flat union. Convert all users of SocketAddressLegacy to SocketAddress, except for existing external interfaces. See also commit fce5d53..9445673 and 85a82e8..c5f1ae3. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-7-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake [Minor editing accident fixed, commit message and a comment tweaked] Signed-off-by: Markus Armbruster --- block/nbd.c | 4 +- block/sheepdog.c | 32 +++--- blockdev-nbd.c | 21 ++-- chardev/char-socket.c | 40 ++++---- chardev/char-udp.c | 10 +- hmp.c | 7 +- include/block/nbd.h | 3 + include/io/channel-socket.h | 24 ++--- include/io/dns-resolver.h | 22 ++-- include/io/task.h | 10 +- include/qemu/sockets.h | 33 ++++-- io/channel-socket.c | 48 ++++----- io/dns-resolver.c | 55 +++++----- migration/socket.c | 49 +++++---- net/socket.c | 10 +- qapi-schema.json | 13 +-- qemu-nbd.c | 17 ++-- qga/channel-posix.c | 4 +- qga/main.c | 8 +- tests/test-char.c | 5 +- tests/test-io-channel-socket.c | 104 +++++++++---------- ui/vnc-auth-sasl.c | 9 +- ui/vnc.c | 138 +++++++++++++------------ util/qemu-sockets.c | 180 +++++++++++++++++++-------------- 24 files changed, 440 insertions(+), 406 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index bbe0f99d6c..975faab2c5 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -306,10 +306,9 @@ NBDClientSession *nbd_get_client_session(BlockDriverState *bs) return &s->client; } -static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr_flat, +static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr, Error **errp) { - SocketAddressLegacy *saddr = socket_address_crumple(saddr_flat); QIOChannelSocket *sioc; Error *local_err = NULL; @@ -319,7 +318,6 @@ static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr_flat, qio_channel_socket_connect_sync(sioc, saddr, &local_err); - qapi_free_SocketAddressLegacy(saddr); if (local_err) { object_unref(OBJECT(sioc)); error_propagate(errp, local_err); diff --git a/block/sheepdog.c b/block/sheepdog.c index b8d69b31e7..a18315a1ca 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -378,7 +378,7 @@ struct BDRVSheepdogState { uint32_t cache_flags; bool discard_supported; - SocketAddressLegacy *addr; + SocketAddress *addr; int fd; CoMutex lock; @@ -530,32 +530,29 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings); } -static SocketAddressLegacy *sd_socket_address(const char *path, +static SocketAddress *sd_socket_address(const char *path, const char *host, const char *port) { - SocketAddressLegacy *addr = g_new0(SocketAddressLegacy, 1); + SocketAddress *addr = g_new0(SocketAddress, 1); if (path) { - addr->type = SOCKET_ADDRESS_LEGACY_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_LEGACY_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; } -static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp) +static SocketAddress *sd_server_config(QDict *options, Error **errp) { QDict *server = NULL; QObject *crumpled_server = NULL; Visitor *iv = NULL; - SocketAddress *saddr_flat = NULL; - SocketAddressLegacy *saddr = NULL; + SocketAddress *saddr = NULL; Error *local_err = NULL; qdict_extract_subqdict(options, &server, "server."); @@ -574,16 +571,13 @@ static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp) * visitor expects the former. */ iv = qobject_input_visitor_new(crumpled_server); - visit_type_SocketAddress(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_SocketAddress(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_LEGACY_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)); @@ -2149,7 +2143,7 @@ static void sd_close(BlockDriverState *bs) aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd, false, NULL, NULL, NULL, NULL); closesocket(s->fd); - qapi_free_SocketAddressLegacy(s->addr); + qapi_free_SocketAddress(s->addr); } static int64_t sd_getlength(BlockDriverState *bs) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 6b0c699c22..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(SocketAddressLegacy *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(SocketAddressLegacy *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_LEGACY_KIND_FD where fd has AF_INET or AF_INET6 */ - if (addr->type != SOCKET_ADDRESS_LEGACY_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(SocketAddressLegacy *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/chardev/char-socket.c b/chardev/char-socket.c index f872f48655..8a321a1d4d 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -52,7 +52,7 @@ typedef struct { int *write_msgfds; size_t write_msgfds_num; - SocketAddressLegacy *addr; + SocketAddress *addr; bool is_listen; bool is_telnet; bool is_tn3270; @@ -356,30 +356,30 @@ static void tcp_chr_free_connection(Chardev *chr) s->connected = 0; } -static char *SocketAddress_to_str(const char *prefix, SocketAddressLegacy *addr, +static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr, bool is_listen, bool is_telnet) { switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_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_LEGACY_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_LEGACY_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_LEGACY_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) { @@ -796,7 +796,7 @@ static void char_socket_finalize(Object *obj) g_source_remove(s->reconnect_timer); s->reconnect_timer = 0; } - qapi_free_SocketAddressLegacy(s->addr); + qapi_free_SocketAddress(s->addr); if (s->listen_tag) { g_source_remove(s->listen_tag); s->listen_tag = 0; @@ -859,7 +859,6 @@ static void qmp_chardev_open_socket(Chardev *chr, { SocketChardev *s = SOCKET_CHARDEV(chr); ChardevSocket *sock = backend->u.socket.data; - SocketAddressLegacy *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(SocketAddressLegacy, 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_LEGACY_KIND_UNIX) { + if (addr->type == SOCKET_ADDRESS_TYPE_UNIX) { qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS); } @@ -945,7 +945,7 @@ static void qmp_chardev_open_socket(Chardev *chr, goto error; } - qapi_free_SocketAddressLegacy(s->addr); + qapi_free_SocketAddress(s->addr); s->addr = socket_local_address(sioc->fd, errp); update_disconnected_filename(s); @@ -1051,7 +1051,7 @@ char_socket_get_addr(Object *obj, Visitor *v, const char *name, { SocketChardev *s = SOCKET_CHARDEV(obj); - visit_type_SocketAddressLegacy(v, name, &s->addr, errp); + visit_type_SocketAddress(v, name, &s->addr, errp); } static bool @@ -1078,7 +1078,7 @@ static void char_socket_class_init(ObjectClass *oc, void *data) cc->chr_add_watch = tcp_chr_add_watch; cc->chr_update_read_handler = tcp_chr_update_read_handler; - object_class_property_add(oc, "addr", "SocketAddressLegacy", + object_class_property_add(oc, "addr", "SocketAddress", char_socket_get_addr, NULL, NULL, NULL, &error_abort); diff --git a/chardev/char-udp.c b/chardev/char-udp.c index d705c4f26b..5f2f717928 100644 --- a/chardev/char-udp.c +++ b/chardev/char-udp.c @@ -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 c7f161d634..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" @@ -2108,7 +2109,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) bool all = qdict_get_try_bool(qdict, "all", false); Error *local_err = NULL; BlockInfoList *block_list, *info; - SocketAddressLegacy *addr; + SocketAddress *addr; if (writable && !all) { error_setg(&local_err, "-w only valid together with -a"); @@ -2121,8 +2122,8 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) goto exit; } - qmp_nbd_server_start(addr, false, NULL, &local_err); - qapi_free_SocketAddressLegacy(addr); + nbd_server_start(addr, NULL, &local_err); + qapi_free_SocketAddress(addr); if (local_err != NULL) { goto exit; } 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/io/channel-socket.h b/include/io/channel-socket.h index c1aaa72a5d..53801f6042 100644 --- a/include/io/channel-socket.h +++ b/include/io/channel-socket.h @@ -91,7 +91,7 @@ qio_channel_socket_new_fd(int fd, * an error occurs. */ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, - SocketAddressLegacy *addr, + SocketAddress *addr, Error **errp); /** @@ -110,7 +110,7 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, * as this function returns without waiting for completion. */ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, - SocketAddressLegacy *addr, + SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy); @@ -128,7 +128,7 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, * an error occurs. */ int qio_channel_socket_listen_sync(QIOChannelSocket *ioc, - SocketAddressLegacy *addr, + SocketAddress *addr, Error **errp); /** @@ -147,7 +147,7 @@ int qio_channel_socket_listen_sync(QIOChannelSocket *ioc, * as this function returns without waiting for completion. */ void qio_channel_socket_listen_async(QIOChannelSocket *ioc, - SocketAddressLegacy *addr, + SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy); @@ -167,8 +167,8 @@ void qio_channel_socket_listen_async(QIOChannelSocket *ioc, * is established or an error occurs. */ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, - SocketAddressLegacy *localAddr, - SocketAddressLegacy *remoteAddr, + SocketAddress *localAddr, + SocketAddress *remoteAddr, Error **errp); /** @@ -190,8 +190,8 @@ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, * waiting for completion. */ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, - SocketAddressLegacy *localAddr, - SocketAddressLegacy *remoteAddr, + SocketAddress *localAddr, + SocketAddress *remoteAddr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy); @@ -205,12 +205,12 @@ 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_SocketAddressLegacy() when no + * release with a call qapi_free_SocketAddress() when no * longer required. * * Returns: 0 on success, -1 on error */ -SocketAddressLegacy * +SocketAddress * qio_channel_socket_get_local_address(QIOChannelSocket *ioc, Error **errp); @@ -222,12 +222,12 @@ 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_SocketAddressLegacy() when no + * release with a call qapi_free_SocketAddress() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddressLegacy * +SocketAddress * qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, Error **errp); diff --git a/include/io/dns-resolver.h b/include/io/dns-resolver.h index aac46cadea..2f69c08c13 100644 --- a/include/io/dns-resolver.h +++ b/include/io/dns-resolver.h @@ -40,15 +40,15 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * QIODNSResolver: * * The QIODNSResolver class provides a framework for doing - * DNS resolution on SocketAddressLegacy objects, independently + * DNS resolution on SocketAddress objects, independently * of socket creation. * * * Resolving addresses synchronously * - * int mylisten(SocketAddressLegacy *addr, Error **errp) { + * int mylisten(SocketAddress *addr, Error **errp) { * QIODNSResolver *resolver = qio_dns_resolver_get_instance(); - * SocketAddressLegacy **rawaddrs = NULL; + * SocketAddress **rawaddrs = NULL; * size_t nrawaddrs = 0; * Error *err = NULL; * QIOChannel **socks = NULL; @@ -69,7 +69,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * socks = g_renew(QIOChannelSocket *, socks, nsocks + 1); * socks[nsocks++] = sock; * } - * qapi_free_SocketAddressLegacy(rawaddrs[i]); + * qapi_free_SocketAddress(rawaddrs[i]); * } * g_free(rawaddrs); * @@ -95,7 +95,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * MyListenData *data = opaque; * QIODNSResolver *resolver = * QIO_DNS_RESOLVER(qio_task_get_source(task); - * SocketAddressLegacy **rawaddrs = NULL; + * SocketAddress **rawaddrs = NULL; * size_t nrawaddrs = 0; * Error *err = NULL; * @@ -116,7 +116,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * socks = g_renew(QIOChannelSocket *, socks, nsocks + 1); * socks[nsocks++] = sock; * } - * qapi_free_SocketAddressLegacy(rawaddrs[i]); + * qapi_free_SocketAddress(rawaddrs[i]); * } * g_free(rawaddrs); * @@ -127,7 +127,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass; * } * } * - * void mylisten(SocketAddressLegacy *addr, MyListenData *data) { + * void mylisten(SocketAddress *addr, MyListenData *data) { * QIODNSResolver *resolver = qio_dns_resolver_get_instance(); * qio_dns_resolver_lookup_async(dns, addr, * mylistenresult, data, NULL); @@ -177,9 +177,9 @@ QIODNSResolver *qio_dns_resolver_get_instance(void); * Returns: 0 if resolution was successful, -1 on error */ int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver, - SocketAddressLegacy *addr, + SocketAddress *addr, size_t *naddrs, - SocketAddressLegacy ***addrs, + SocketAddress ***addrs, Error **errp); /** @@ -201,7 +201,7 @@ int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver, * of the caller will not be blocked. */ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, - SocketAddressLegacy *addr, + SocketAddress *addr, QIOTaskFunc func, gpointer opaque, GDestroyNotify notify); @@ -223,6 +223,6 @@ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, void qio_dns_resolver_lookup_result(QIODNSResolver *resolver, QIOTask *task, size_t *naddrs, - SocketAddressLegacy ***addrs); + SocketAddress ***addrs); #endif /* QIO_DNS_RESOLVER_H */ diff --git a/include/io/task.h b/include/io/task.h index f65ec7aca3..6021f51336 100644 --- a/include/io/task.h +++ b/include/io/task.h @@ -166,7 +166,7 @@ typedef void (*QIOTaskWorker)(QIOTask *task, * gpointer opaque) * { * QMyObject obj = QMY_OBJECT(qio_task_get_source(task)); - * SocketAddressLegacy *addr = opaque; + * SocketAddress *addr = opaque; * Error *err = NULL; * * obj->fd = socket_listen(addr, &err); @@ -175,20 +175,20 @@ typedef void (*QIOTaskWorker)(QIOTask *task, * } * * void myobject_listen_async(QMyObject *obj, - * SocketAddressLegacy *addr, + * SocketAddress *addr, * QIOTaskFunc *func, * gpointer opaque, * GDestroyNotify notify) * { * QIOTask *task; - * SocketAddressLegacy *addrCopy; + * SocketAddress *addrCopy; * - * addrCopy = QAPI_CLONE(SocketAddressLegacy, addr); + * addrCopy = QAPI_CLONE(SocketAddress, addr); * task = qio_task_new(OBJECT(obj), func, opaque, notify); * * qio_task_run_in_thread(task, myobject_listen_worker, * addrCopy, - * qapi_free_SocketAddressLegacy); + * qapi_free_SocketAddress); * } * * diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 82b7460ea4..a0b5cae03b 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -45,12 +45,12 @@ NetworkAddressFamily inet_netfamily(int family); int unix_listen(const char *path, char *ostr, int olen, Error **errp); int unix_connect(const char *path, Error **errp); -SocketAddressLegacy *socket_parse(const char *str, Error **errp); -int socket_connect(SocketAddressLegacy *addr, NonBlockingConnectHandler *callback, +SocketAddress *socket_parse(const char *str, Error **errp); +int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, void *opaque, Error **errp); -int socket_listen(SocketAddressLegacy *addr, Error **errp); +int socket_listen(SocketAddress *addr, Error **errp); void socket_listen_cleanup(int fd, Error **errp); -int socket_dgram(SocketAddressLegacy *remote, SocketAddressLegacy *local, Error **errp); +int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); /* Old, ipv4 only bits. Don't use for new code. */ int parse_host_port(struct sockaddr_in *saddr, const char *str); @@ -65,12 +65,12 @@ 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_SocketAddressLegacy() when no + * release with a call qapi_free_SocketAddress() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddressLegacy * +SocketAddress * socket_sockaddr_to_address(struct sockaddr_storage *sa, socklen_t salen, Error **errp); @@ -83,12 +83,12 @@ 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_SocketAddressLegacy() when no + * release with a call qapi_free_SocketAddress() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddressLegacy *socket_local_address(int fd, Error **errp); +SocketAddress *socket_local_address(int fd, Error **errp); /** * socket_remote_address: @@ -98,12 +98,12 @@ SocketAddressLegacy *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_SocketAddressLegacy() when no + * release with a call qapi_free_SocketAddress() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddressLegacy *socket_remote_address(int fd, Error **errp); +SocketAddress *socket_remote_address(int fd, Error **errp); /** * socket_address_to_string: @@ -118,7 +118,7 @@ SocketAddressLegacy *socket_remote_address(int fd, Error **errp); * * Returns: the socket address in string format, or NULL on error */ -char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp); +char *socket_address_to_string(struct SocketAddress *addr, Error **errp); /** * socket_address_crumple: @@ -131,4 +131,15 @@ char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp); */ SocketAddressLegacy *socket_address_crumple(SocketAddress *addr); +/** + * socket_address_flatten: + * @addr: the socket address to flatten + * + * Convert SocketAddressLegacy to SocketAddress. Caller is responsible + * for freeing with qapi_free_SocketAddress(). + * + * Returns: the argument converted to SocketAddress. + */ +SocketAddress *socket_address_flatten(SocketAddressLegacy *addr); + #endif /* QEMU_SOCKETS_H */ diff --git a/io/channel-socket.c b/io/channel-socket.c index a21dab640e..53386b7ba3 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -27,7 +27,7 @@ #define SOCKET_MAX_FDS 16 -SocketAddressLegacy * +SocketAddress * qio_channel_socket_get_local_address(QIOChannelSocket *ioc, Error **errp) { @@ -36,7 +36,7 @@ qio_channel_socket_get_local_address(QIOChannelSocket *ioc, errp); } -SocketAddressLegacy * +SocketAddress * qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, Error **errp) { @@ -134,7 +134,7 @@ qio_channel_socket_new_fd(int fd, int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, - SocketAddressLegacy *addr, + SocketAddress *addr, Error **errp) { int fd; @@ -160,7 +160,7 @@ static void qio_channel_socket_connect_worker(QIOTask *task, gpointer opaque) { QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task)); - SocketAddressLegacy *addr = opaque; + SocketAddress *addr = opaque; Error *err = NULL; qio_channel_socket_connect_sync(ioc, addr, &err); @@ -170,16 +170,16 @@ static void qio_channel_socket_connect_worker(QIOTask *task, void qio_channel_socket_connect_async(QIOChannelSocket *ioc, - SocketAddressLegacy *addr, + SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy) { QIOTask *task = qio_task_new( OBJECT(ioc), callback, opaque, destroy); - SocketAddressLegacy *addrCopy; + SocketAddress *addrCopy; - addrCopy = QAPI_CLONE(SocketAddressLegacy, addr); + addrCopy = QAPI_CLONE(SocketAddress, addr); /* socket_connect() does a non-blocking connect(), but it * still blocks in DNS lookups, so we must use a thread */ @@ -187,12 +187,12 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, qio_task_run_in_thread(task, qio_channel_socket_connect_worker, addrCopy, - (GDestroyNotify)qapi_free_SocketAddressLegacy); + (GDestroyNotify)qapi_free_SocketAddress); } int qio_channel_socket_listen_sync(QIOChannelSocket *ioc, - SocketAddressLegacy *addr, + SocketAddress *addr, Error **errp) { int fd; @@ -219,7 +219,7 @@ static void qio_channel_socket_listen_worker(QIOTask *task, gpointer opaque) { QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task)); - SocketAddressLegacy *addr = opaque; + SocketAddress *addr = opaque; Error *err = NULL; qio_channel_socket_listen_sync(ioc, addr, &err); @@ -229,29 +229,29 @@ static void qio_channel_socket_listen_worker(QIOTask *task, void qio_channel_socket_listen_async(QIOChannelSocket *ioc, - SocketAddressLegacy *addr, + SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy) { QIOTask *task = qio_task_new( OBJECT(ioc), callback, opaque, destroy); - SocketAddressLegacy *addrCopy; + SocketAddress *addrCopy; - addrCopy = QAPI_CLONE(SocketAddressLegacy, addr); + addrCopy = QAPI_CLONE(SocketAddress, addr); /* socket_listen() blocks in DNS lookups, so we must use a thread */ trace_qio_channel_socket_listen_async(ioc, addr); qio_task_run_in_thread(task, qio_channel_socket_listen_worker, addrCopy, - (GDestroyNotify)qapi_free_SocketAddressLegacy); + (GDestroyNotify)qapi_free_SocketAddress); } int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, - SocketAddressLegacy *localAddr, - SocketAddressLegacy *remoteAddr, + SocketAddress *localAddr, + SocketAddress *remoteAddr, Error **errp) { int fd; @@ -274,16 +274,16 @@ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, struct QIOChannelSocketDGramWorkerData { - SocketAddressLegacy *localAddr; - SocketAddressLegacy *remoteAddr; + SocketAddress *localAddr; + SocketAddress *remoteAddr; }; static void qio_channel_socket_dgram_worker_free(gpointer opaque) { struct QIOChannelSocketDGramWorkerData *data = opaque; - qapi_free_SocketAddressLegacy(data->localAddr); - qapi_free_SocketAddressLegacy(data->remoteAddr); + qapi_free_SocketAddress(data->localAddr); + qapi_free_SocketAddress(data->remoteAddr); g_free(data); } @@ -303,8 +303,8 @@ static void qio_channel_socket_dgram_worker(QIOTask *task, void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, - SocketAddressLegacy *localAddr, - SocketAddressLegacy *remoteAddr, + SocketAddress *localAddr, + SocketAddress *remoteAddr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy) @@ -314,8 +314,8 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, struct QIOChannelSocketDGramWorkerData *data = g_new0( struct QIOChannelSocketDGramWorkerData, 1); - data->localAddr = QAPI_CLONE(SocketAddressLegacy, localAddr); - data->remoteAddr = QAPI_CLONE(SocketAddressLegacy, remoteAddr); + data->localAddr = QAPI_CLONE(SocketAddress, localAddr); + data->remoteAddr = QAPI_CLONE(SocketAddress, remoteAddr); trace_qio_channel_socket_dgram_async(ioc, localAddr, remoteAddr); qio_task_run_in_thread(task, diff --git a/io/dns-resolver.c b/io/dns-resolver.c index d3f0cbf319..57a8896cbb 100644 --- a/io/dns-resolver.c +++ b/io/dns-resolver.c @@ -45,13 +45,13 @@ QIODNSResolver *qio_dns_resolver_get_instance(void) } static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver, - SocketAddressLegacy *addr, + SocketAddress *addr, size_t *naddrs, - SocketAddressLegacy ***addrs, + SocketAddress ***addrs, 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]; @@ -97,20 +97,19 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver, (*naddrs)++; } - *addrs = g_new0(SocketAddressLegacy *, *naddrs); + *addrs = g_new0(SocketAddress *, *naddrs); /* create socket + bind */ for (i = 0, e = res; e != NULL; i++, e = e->ai_next) { - SocketAddressLegacy *newaddr = g_new0(SocketAddressLegacy, 1); - InetSocketAddress *newiaddr = g_new0(InetSocketAddress, 1); - newaddr->u.inet.data = newiaddr; - newaddr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; + SocketAddress *newaddr = g_new0(SocketAddress, 1); + + 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, @@ -129,36 +128,36 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver, static int qio_dns_resolver_lookup_sync_nop(QIODNSResolver *resolver, - SocketAddressLegacy *addr, + SocketAddress *addr, size_t *naddrs, - SocketAddressLegacy ***addrs, + SocketAddress ***addrs, Error **errp) { *naddrs = 1; - *addrs = g_new0(SocketAddressLegacy *, 1); - (*addrs)[0] = QAPI_CLONE(SocketAddressLegacy, addr); + *addrs = g_new0(SocketAddress *, 1); + (*addrs)[0] = QAPI_CLONE(SocketAddress, addr); return 0; } int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver, - SocketAddressLegacy *addr, + SocketAddress *addr, size_t *naddrs, - SocketAddressLegacy ***addrs, + SocketAddress ***addrs, Error **errp) { switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_KIND_INET: + case SOCKET_ADDRESS_TYPE_INET: return qio_dns_resolver_lookup_sync_inet(resolver, addr, naddrs, addrs, errp); - case SOCKET_ADDRESS_LEGACY_KIND_UNIX: - case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: - case SOCKET_ADDRESS_LEGACY_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, @@ -172,8 +171,8 @@ int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver, struct QIODNSResolverLookupData { - SocketAddressLegacy *addr; - SocketAddressLegacy **addrs; + SocketAddress *addr; + SocketAddress **addrs; size_t naddrs; }; @@ -183,9 +182,9 @@ static void qio_dns_resolver_lookup_data_free(gpointer opaque) struct QIODNSResolverLookupData *data = opaque; size_t i; - qapi_free_SocketAddressLegacy(data->addr); + qapi_free_SocketAddress(data->addr); for (i = 0; i < data->naddrs; i++) { - qapi_free_SocketAddressLegacy(data->addrs[i]); + qapi_free_SocketAddress(data->addrs[i]); } g_free(data->addrs); @@ -216,7 +215,7 @@ static void qio_dns_resolver_lookup_worker(QIOTask *task, void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, - SocketAddressLegacy *addr, + SocketAddress *addr, QIOTaskFunc func, gpointer opaque, GDestroyNotify notify) @@ -225,7 +224,7 @@ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, struct QIODNSResolverLookupData *data = g_new0(struct QIODNSResolverLookupData, 1); - data->addr = QAPI_CLONE(SocketAddressLegacy, addr); + data->addr = QAPI_CLONE(SocketAddress, addr); task = qio_task_new(OBJECT(resolver), func, opaque, notify); @@ -239,7 +238,7 @@ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, void qio_dns_resolver_lookup_result(QIODNSResolver *resolver, QIOTask *task, size_t *naddrs, - SocketAddressLegacy ***addrs) + SocketAddress ***addrs) { struct QIODNSResolverLookupData *data = qio_task_get_result_pointer(task); @@ -252,9 +251,9 @@ void qio_dns_resolver_lookup_result(QIODNSResolver *resolver, } *naddrs = data->naddrs; - *addrs = g_new0(SocketAddressLegacy *, data->naddrs); + *addrs = g_new0(SocketAddress *, data->naddrs); for (i = 0; i < data->naddrs; i++) { - (*addrs)[i] = QAPI_CLONE(SocketAddressLegacy, data->addrs[i]); + (*addrs)[i] = QAPI_CLONE(SocketAddress, data->addrs[i]); } } diff --git a/migration/socket.c b/migration/socket.c index 32032764a0..1cfbe81e69 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -25,32 +25,29 @@ #include "trace.h" -static SocketAddressLegacy *tcp_build_address(const char *host_port, Error **errp) +static SocketAddress *tcp_build_address(const char *host_port, Error **errp) { - InetSocketAddress *iaddr = g_new(InetSocketAddress, 1); - SocketAddressLegacy *saddr; + SocketAddress *saddr; - if (inet_parse(iaddr, host_port, errp)) { - qapi_free_InetSocketAddress(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(SocketAddressLegacy, 1); - saddr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; - saddr->u.inet.data = iaddr; - return saddr; } -static SocketAddressLegacy *unix_build_address(const char *path) +static SocketAddress *unix_build_address(const char *path) { - SocketAddressLegacy *saddr; + SocketAddress *saddr; - saddr = g_new0(SocketAddressLegacy, 1); - saddr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; - saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1); - saddr->u.q_unix.data->path = g_strdup(path); + saddr = g_new0(SocketAddress, 1); + saddr->type = SOCKET_ADDRESS_TYPE_UNIX; + saddr->u.q_unix.path = g_strdup(path); return saddr; } @@ -90,15 +87,15 @@ static void socket_outgoing_migration(QIOTask *task, } static void socket_start_outgoing_migration(MigrationState *s, - SocketAddressLegacy *saddr, + SocketAddress *saddr, Error **errp) { QIOChannelSocket *sioc = qio_channel_socket_new(); struct SocketConnectData *data = g_new0(struct SocketConnectData, 1); data->s = s; - if (saddr->type == SOCKET_ADDRESS_LEGACY_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"); @@ -107,7 +104,7 @@ static void socket_start_outgoing_migration(MigrationState *s, socket_outgoing_migration, data, socket_connect_data_free); - qapi_free_SocketAddressLegacy(saddr); + qapi_free_SocketAddress(saddr); } void tcp_start_outgoing_migration(MigrationState *s, @@ -115,7 +112,7 @@ void tcp_start_outgoing_migration(MigrationState *s, Error **errp) { Error *err = NULL; - SocketAddressLegacy *saddr = tcp_build_address(host_port, &err); + SocketAddress *saddr = tcp_build_address(host_port, &err); if (!err) { socket_start_outgoing_migration(s, saddr, &err); } @@ -126,7 +123,7 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp) { - SocketAddressLegacy *saddr = unix_build_address(path); + SocketAddress *saddr = unix_build_address(path); socket_start_outgoing_migration(s, saddr, errp); } @@ -160,7 +157,7 @@ out: } -static void socket_start_incoming_migration(SocketAddressLegacy *saddr, +static void socket_start_incoming_migration(SocketAddress *saddr, Error **errp) { QIOChannelSocket *listen_ioc = qio_channel_socket_new(); @@ -170,7 +167,7 @@ static void socket_start_incoming_migration(SocketAddressLegacy *saddr, if (qio_channel_socket_listen_sync(listen_ioc, saddr, errp) < 0) { object_unref(OBJECT(listen_ioc)); - qapi_free_SocketAddressLegacy(saddr); + qapi_free_SocketAddress(saddr); return; } @@ -179,13 +176,13 @@ static void socket_start_incoming_migration(SocketAddressLegacy *saddr, socket_accept_incoming_migration, listen_ioc, (GDestroyNotify)object_unref); - qapi_free_SocketAddressLegacy(saddr); + qapi_free_SocketAddress(saddr); } void tcp_start_incoming_migration(const char *host_port, Error **errp) { Error *err = NULL; - SocketAddressLegacy *saddr = tcp_build_address(host_port, &err); + SocketAddress *saddr = tcp_build_address(host_port, &err); if (!err) { socket_start_incoming_migration(saddr, &err); } @@ -194,6 +191,6 @@ void tcp_start_incoming_migration(const char *host_port, Error **errp) void unix_start_incoming_migration(const char *path, Error **errp) { - SocketAddressLegacy *saddr = unix_build_address(path); + SocketAddress *saddr = unix_build_address(path); socket_start_incoming_migration(saddr, errp); } diff --git a/net/socket.c b/net/socket.c index ecd165ffb0..b8c931e762 100644 --- a/net/socket.c +++ b/net/socket.c @@ -489,7 +489,7 @@ static int net_socket_listen_init(NetClientState *peer, { NetClientState *nc; NetSocketState *s; - SocketAddressLegacy *saddr; + SocketAddress *saddr; int ret; Error *local_error = NULL; @@ -501,7 +501,7 @@ static int net_socket_listen_init(NetClientState *peer, ret = socket_listen(saddr, &local_error); if (ret < 0) { - qapi_free_SocketAddressLegacy(saddr); + qapi_free_SocketAddress(saddr); error_report_err(local_error); return -1; } @@ -514,20 +514,20 @@ static int net_socket_listen_init(NetClientState *peer, net_socket_rs_init(&s->rs, net_socket_rs_finalize); qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); - qapi_free_SocketAddressLegacy(saddr); + qapi_free_SocketAddress(saddr); return 0; } typedef struct { NetClientState *peer; - SocketAddressLegacy *saddr; + SocketAddress *saddr; char *model; char *name; } socket_connect_data; static void socket_connect_data_free(socket_connect_data *c) { - qapi_free_SocketAddressLegacy(c->saddr); + qapi_free_SocketAddress(c->saddr); g_free(c->model); g_free(c->name); g_free(c); diff --git a/qapi-schema.json b/qapi-schema.json index eab41396e1..5728b7f363 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4126,7 +4126,11 @@ # # Captures the address of a socket, which could also be a named file descriptor # -# Note: This type is deprecated in favor of SocketAddress. +# 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 ## @@ -4154,14 +4158,11 @@ ## # @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 SocketAddressLegacy, 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': 'SocketAddress', diff --git a/qemu-nbd.c b/qemu-nbd.c index 82d08597b0..b7ab86bfa7 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -57,7 +57,7 @@ static NBDExport *exp; static bool newproto; static int verbose; static char *srcpath; -static SocketAddressLegacy *saddr; +static SocketAddress *saddr; static int persistent = 0; static enum { RUNNING, TERMINATE, TERMINATING, TERMINATED } state; static int shared = 1; @@ -387,21 +387,20 @@ static void nbd_update_server_watch(void) } -static SocketAddressLegacy *nbd_build_socket_address(const char *sockpath, +static SocketAddress *nbd_build_socket_address(const char *sockpath, const char *bindto, const char *port) { - SocketAddressLegacy *saddr; + SocketAddress *saddr; - saddr = g_new0(SocketAddressLegacy, 1); + saddr = g_new0(SocketAddress, 1); if (sockpath) { - saddr->type = SOCKET_ADDRESS_LEGACY_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_LEGACY_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); diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 65ab8eb634..3f34465159 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -203,7 +203,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, case GA_CHANNEL_VSOCK_LISTEN: { if (fd < 0) { Error *local_err = NULL; - SocketAddressLegacy *addr; + SocketAddress *addr; char *addr_str; addr_str = g_strdup_printf("vsock:%s", path); @@ -216,7 +216,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, } fd = socket_listen(addr, &local_err); - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); if (local_err != NULL) { g_critical("%s", error_get_pretty(local_err)); error_free(local_err); diff --git a/qga/main.c b/qga/main.c index cae4d7b36f..cc58d2b53d 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1379,7 +1379,7 @@ int main(int argc, char **argv) goto end; } if (socket_activation) { - SocketAddressLegacy *addr; + SocketAddress *addr; g_free(config->method); g_free(config->channel_path); @@ -1388,13 +1388,13 @@ int main(int argc, char **argv) addr = socket_local_address(FIRST_SOCKET_ACTIVATION_FD, NULL); if (addr) { - if (addr->type == SOCKET_ADDRESS_LEGACY_KIND_UNIX) { + if (addr->type == SOCKET_ADDRESS_TYPE_UNIX) { config->method = g_strdup("unix-listen"); - } else if (addr->type == SOCKET_ADDRESS_LEGACY_KIND_VSOCK) { + } else if (addr->type == SOCKET_ADDRESS_TYPE_VSOCK) { config->method = g_strdup("vsock-listen"); } - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); } if (!config->method) { 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 a66ffc2fbc..d357cd2a8e 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -115,8 +115,8 @@ static void test_io_channel_set_socket_bufs(QIOChannel *src, } -static void test_io_channel_setup_sync(SocketAddressLegacy *listen_addr, - SocketAddressLegacy *connect_addr, +static void test_io_channel_setup_sync(SocketAddress *listen_addr, + SocketAddress *connect_addr, QIOChannel **src, QIOChannel **dst) { @@ -125,14 +125,14 @@ static void test_io_channel_setup_sync(SocketAddressLegacy *listen_addr, lioc = qio_channel_socket_new(); qio_channel_socket_listen_sync(lioc, listen_addr, &error_abort); - if (listen_addr->type == SOCKET_ADDRESS_LEGACY_KIND_INET) { - SocketAddressLegacy *laddr = qio_channel_socket_get_local_address( + 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_SocketAddressLegacy(laddr); + qapi_free_SocketAddress(laddr); } *src = QIO_CHANNEL(qio_channel_socket_new()); @@ -165,8 +165,8 @@ static void test_io_channel_complete(QIOTask *task, } -static void test_io_channel_setup_async(SocketAddressLegacy *listen_addr, - SocketAddressLegacy *connect_addr, +static void test_io_channel_setup_async(SocketAddress *listen_addr, + SocketAddress *connect_addr, QIOChannel **src, QIOChannel **dst) { @@ -186,14 +186,14 @@ static void test_io_channel_setup_async(SocketAddressLegacy *listen_addr, g_assert(!data.err); - if (listen_addr->type == SOCKET_ADDRESS_LEGACY_KIND_INET) { - SocketAddressLegacy *laddr = qio_channel_socket_get_local_address( + 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_SocketAddressLegacy(laddr); + qapi_free_SocketAddress(laddr); } *src = QIO_CHANNEL(qio_channel_socket_new()); @@ -221,8 +221,8 @@ static void test_io_channel_setup_async(SocketAddressLegacy *listen_addr, static void test_io_channel(bool async, - SocketAddressLegacy *listen_addr, - SocketAddressLegacy *connect_addr, + SocketAddress *listen_addr, + SocketAddress *connect_addr, bool passFD) { QIOChannel *src, *dst; @@ -297,27 +297,25 @@ static void test_io_channel(bool async, static void test_io_channel_ipv4(bool async) { - SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1); - SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1); + SocketAddress *listen_addr = g_new0(SocketAddress, 1); + SocketAddress *connect_addr = g_new0(SocketAddress, 1); - listen_addr->type = SOCKET_ADDRESS_LEGACY_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_LEGACY_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 */ }; test_io_channel(async, listen_addr, connect_addr, false); - qapi_free_SocketAddressLegacy(listen_addr); - qapi_free_SocketAddressLegacy(connect_addr); + qapi_free_SocketAddress(listen_addr); + qapi_free_SocketAddress(connect_addr); } @@ -335,27 +333,25 @@ static void test_io_channel_ipv4_async(void) static void test_io_channel_ipv6(bool async) { - SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1); - SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1); + SocketAddress *listen_addr = g_new0(SocketAddress, 1); + SocketAddress *connect_addr = g_new0(SocketAddress, 1); - listen_addr->type = SOCKET_ADDRESS_LEGACY_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_LEGACY_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 */ }; test_io_channel(async, listen_addr, connect_addr, false); - qapi_free_SocketAddressLegacy(listen_addr); - qapi_free_SocketAddressLegacy(connect_addr); + qapi_free_SocketAddress(listen_addr); + qapi_free_SocketAddress(connect_addr); } @@ -374,22 +370,20 @@ static void test_io_channel_ipv6_async(void) #ifndef _WIN32 static void test_io_channel_unix(bool async) { - SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1); - SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1); + SocketAddress *listen_addr = g_new0(SocketAddress, 1); + SocketAddress *connect_addr = g_new0(SocketAddress, 1); #define TEST_SOCKET "test-io-channel-socket.sock" - listen_addr->type = SOCKET_ADDRESS_LEGACY_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_LEGACY_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); - qapi_free_SocketAddressLegacy(listen_addr); - qapi_free_SocketAddressLegacy(connect_addr); + qapi_free_SocketAddress(listen_addr); + qapi_free_SocketAddress(connect_addr); g_assert(g_file_test(TEST_SOCKET, G_FILE_TEST_EXISTS) == FALSE); } @@ -407,8 +401,8 @@ static void test_io_channel_unix_async(void) static void test_io_channel_unix_fd_pass(void) { - SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1); - SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1); + SocketAddress *listen_addr = g_new0(SocketAddress, 1); + SocketAddress *connect_addr = g_new0(SocketAddress, 1); QIOChannel *src, *dst; int testfd; int fdsend[3]; @@ -427,13 +421,11 @@ static void test_io_channel_unix_fd_pass(void) fdsend[1] = testfd; fdsend[2] = testfd; - listen_addr->type = SOCKET_ADDRESS_LEGACY_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_LEGACY_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); @@ -488,8 +480,8 @@ static void test_io_channel_unix_fd_pass(void) object_unref(OBJECT(src)); object_unref(OBJECT(dst)); - qapi_free_SocketAddressLegacy(listen_addr); - qapi_free_SocketAddressLegacy(connect_addr); + qapi_free_SocketAddress(listen_addr); + qapi_free_SocketAddress(connect_addr); unlink(TEST_SOCKET); unlink(TEST_FILE); close(testfd); diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c index c7fa9b65b9..3ade4a4918 100644 --- a/ui/vnc-auth-sasl.c +++ b/ui/vnc-auth-sasl.c @@ -498,7 +498,7 @@ vnc_socket_ip_addr_string(QIOChannelSocket *ioc, bool local, Error **errp) { - SocketAddressLegacy *addr; + SocketAddress *addr; char *ret; if (local) { @@ -510,13 +510,12 @@ vnc_socket_ip_addr_string(QIOChannelSocket *ioc, return NULL; } - if (addr->type != SOCKET_ADDRESS_LEGACY_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); - qapi_free_SocketAddressLegacy(addr); + 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 5090a2562f..9c4edcdbf5 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -108,31 +108,31 @@ static void vnc_set_share_mode(VncState *vs, VncShareMode mode) } -static void vnc_init_basic_info(SocketAddressLegacy *addr, +static void vnc_init_basic_info(SocketAddress *addr, VncBasicInfo *info, Error **errp) { switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_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_LEGACY_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_LEGACY_KIND_VSOCK: - case SOCKET_ADDRESS_LEGACY_KIND_FD: + case SOCKET_ADDRESS_TYPE_VSOCK: + case SOCKET_ADDRESS_TYPE_FD: error_setg(errp, "Unsupported socket address type %s", - SocketAddressLegacyKind_lookup[addr->type]); + SocketAddressType_lookup[addr->type]); break; default: abort(); @@ -145,7 +145,7 @@ static void vnc_init_basic_info_from_server_addr(QIOChannelSocket *ioc, VncBasicInfo *info, Error **errp) { - SocketAddressLegacy *addr = NULL; + SocketAddress *addr = NULL; if (!ioc) { error_setg(errp, "No listener socket available"); @@ -158,14 +158,14 @@ static void vnc_init_basic_info_from_server_addr(QIOChannelSocket *ioc, } vnc_init_basic_info(addr, info, errp); - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); } static void vnc_init_basic_info_from_remote_addr(QIOChannelSocket *ioc, VncBasicInfo *info, Error **errp) { - SocketAddressLegacy *addr = NULL; + SocketAddress *addr = NULL; addr = qio_channel_socket_get_remote_address(ioc, errp); if (!addr) { @@ -173,7 +173,7 @@ static void vnc_init_basic_info_from_remote_addr(QIOChannelSocket *ioc, } vnc_init_basic_info(addr, info, errp); - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); } static const char *vnc_auth_name(VncDisplay *vd) { @@ -377,7 +377,7 @@ VncInfo *qmp_query_vnc(Error **errp) { VncInfo *info = g_malloc0(sizeof(*info)); VncDisplay *vd = vnc_display_find(NULL); - SocketAddressLegacy *addr = NULL; + SocketAddress *addr = NULL; if (vd == NULL || !vd->nlsock) { info->enabled = false; @@ -398,26 +398,26 @@ VncInfo *qmp_query_vnc(Error **errp) } switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_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_LEGACY_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_LEGACY_KIND_VSOCK: - case SOCKET_ADDRESS_LEGACY_KIND_FD: + case SOCKET_ADDRESS_TYPE_VSOCK: + case SOCKET_ADDRESS_TYPE_FD: error_setg(errp, "Unsupported socket address type %s", - SocketAddressLegacyKind_lookup[addr->type]); + SocketAddressType_lookup[addr->type]); goto out_error; default: abort(); @@ -431,11 +431,11 @@ VncInfo *qmp_query_vnc(Error **errp) info->auth = g_strdup(vnc_auth_name(vd)); } - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); return info; out_error: - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); qapi_free_VncInfo(info); return NULL; } @@ -455,7 +455,7 @@ static VncServerInfo2List *qmp_query_server_entry(QIOChannelSocket *ioc, VncServerInfo2List *list; VncServerInfo2 *info; Error *err = NULL; - SocketAddressLegacy *addr; + SocketAddress *addr; addr = qio_channel_socket_get_local_address(ioc, &err); if (!addr) { @@ -465,7 +465,7 @@ static VncServerInfo2List *qmp_query_server_entry(QIOChannelSocket *ioc, info = g_new0(VncServerInfo2, 1); vnc_init_basic_info(addr, qapi_VncServerInfo2_base(info), &err); - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); if (err) { qapi_free_VncServerInfo2(info); error_free(err); @@ -3149,7 +3149,7 @@ int vnc_display_pw_expire(const char *id, time_t expires) static void vnc_display_print_local_addr(VncDisplay *vd) { - SocketAddressLegacy *addr; + SocketAddress *addr; Error *err = NULL; if (!vd->nlsock) { @@ -3161,14 +3161,14 @@ static void vnc_display_print_local_addr(VncDisplay *vd) return; } - if (addr->type != SOCKET_ADDRESS_LEGACY_KIND_INET) { - qapi_free_SocketAddressLegacy(addr); + 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); - qapi_free_SocketAddressLegacy(addr); + addr->u.inet.host, + addr->u.inet.port); + qapi_free_SocketAddress(addr); } static QemuOptsList qemu_vnc_opts = { @@ -3414,18 +3414,17 @@ static int vnc_display_get_address(const char *addrstr, bool has_ipv6, bool ipv4, bool ipv6, - SocketAddressLegacy **retaddr, + SocketAddress **retaddr, Error **errp) { int ret = -1; - SocketAddressLegacy *addr = NULL; + SocketAddress *addr = NULL; - addr = g_new0(SocketAddressLegacy, 1); + addr = g_new0(SocketAddress, 1); if (strncmp(addrstr, "unix:", 5) == 0) { - addr->type = SOCKET_ADDRESS_LEGACY_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_LEGACY_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 { @@ -3518,21 +3517,21 @@ static int vnc_display_get_address(const char *addrstr, cleanup: if (ret < 0) { - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); } return ret; } static int vnc_display_get_addresses(QemuOpts *opts, bool reverse, - SocketAddressLegacy ***retsaddr, + SocketAddress ***retsaddr, size_t *retnsaddr, - SocketAddressLegacy ***retwsaddr, + SocketAddress ***retwsaddr, size_t *retnwsaddr, Error **errp) { - SocketAddressLegacy *saddr = NULL; - SocketAddressLegacy *wsaddr = NULL; + SocketAddress *saddr = NULL; + SocketAddress *wsaddr = NULL; QemuOptsIter addriter; const char *addr; int to = qemu_opt_get_number(opts, "to", 0); @@ -3577,7 +3576,7 @@ static int vnc_display_get_addresses(QemuOpts *opts, if (displaynum == -1) { displaynum = rv; } - *retsaddr = g_renew(SocketAddressLegacy *, *retsaddr, *retnsaddr + 1); + *retsaddr = g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1); (*retsaddr)[(*retnsaddr)++] = saddr; } @@ -3601,16 +3600,15 @@ static int vnc_display_get_addresses(QemuOpts *opts, * address for websocket too */ if (*retnsaddr == 1 && - (*retsaddr)[0]->type == SOCKET_ADDRESS_LEGACY_KIND_INET && - wsaddr->type == SOCKET_ADDRESS_LEGACY_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(SocketAddressLegacy *, *retwsaddr, *retnwsaddr + 1); + *retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1); (*retwsaddr)[(*retnwsaddr)++] = wsaddr; } @@ -3618,11 +3616,11 @@ static int vnc_display_get_addresses(QemuOpts *opts, cleanup: if (ret < 0) { for (i = 0; i < *retnsaddr; i++) { - qapi_free_SocketAddressLegacy((*retsaddr)[i]); + qapi_free_SocketAddress((*retsaddr)[i]); } g_free(*retsaddr); for (i = 0; i < *retnwsaddr; i++) { - qapi_free_SocketAddressLegacy((*retwsaddr)[i]); + qapi_free_SocketAddress((*retwsaddr)[i]); } g_free(*retwsaddr); *retsaddr = *retwsaddr = NULL; @@ -3632,9 +3630,9 @@ static int vnc_display_get_addresses(QemuOpts *opts, } static int vnc_display_connect(VncDisplay *vd, - SocketAddressLegacy **saddr, + SocketAddress **saddr, size_t nsaddr, - SocketAddressLegacy **wsaddr, + SocketAddress **wsaddr, size_t nwsaddr, Error **errp) { @@ -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_LEGACY_KIND_FD when fd has AF_UNIX */ - vd->is_unix = saddr[0]->type == SOCKET_ADDRESS_LEGACY_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) { @@ -3662,7 +3660,7 @@ static int vnc_display_connect(VncDisplay *vd, static int vnc_display_listen_addr(VncDisplay *vd, - SocketAddressLegacy *addr, + SocketAddress *addr, const char *name, QIOChannelSocket ***lsock, guint **lsock_tag, @@ -3670,7 +3668,7 @@ static int vnc_display_listen_addr(VncDisplay *vd, Error **errp) { QIODNSResolver *resolver = qio_dns_resolver_get_instance(); - SocketAddressLegacy **rawaddrs = NULL; + SocketAddress **rawaddrs = NULL; size_t nrawaddrs = 0; Error *listenerr = NULL; bool listening = false; @@ -3700,7 +3698,7 @@ static int vnc_display_listen_addr(VncDisplay *vd, } for (i = 0; i < nrawaddrs; i++) { - qapi_free_SocketAddressLegacy(rawaddrs[i]); + qapi_free_SocketAddress(rawaddrs[i]); } g_free(rawaddrs); @@ -3724,9 +3722,9 @@ static int vnc_display_listen_addr(VncDisplay *vd, static int vnc_display_listen(VncDisplay *vd, - SocketAddressLegacy **saddr, + SocketAddress **saddr, size_t nsaddr, - SocketAddressLegacy **wsaddr, + SocketAddress **wsaddr, size_t nwsaddr, Error **errp) { @@ -3761,7 +3759,7 @@ void vnc_display_open(const char *id, Error **errp) { VncDisplay *vd = vnc_display_find(id); QemuOpts *opts = qemu_opts_find(&qemu_vnc_opts, id); - SocketAddressLegacy **saddr = NULL, **wsaddr = NULL; + SocketAddress **saddr = NULL, **wsaddr = NULL; size_t nsaddr, nwsaddr; const char *share, *device_id; QemuConsole *con; @@ -3997,10 +3995,10 @@ void vnc_display_open(const char *id, Error **errp) cleanup: for (i = 0; i < nsaddr; i++) { - qapi_free_SocketAddressLegacy(saddr[i]); + qapi_free_SocketAddress(saddr[i]); } for (i = 0; i < nwsaddr; i++) { - qapi_free_SocketAddressLegacy(wsaddr[i]); + qapi_free_SocketAddress(wsaddr[i]); } return; diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 801aa7a0c1..9e65ebed01 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" @@ -1029,73 +1030,69 @@ int unix_connect(const char *path, Error **errp) } -SocketAddressLegacy *socket_parse(const char *str, Error **errp) +SocketAddress *socket_parse(const char *str, Error **errp) { - SocketAddressLegacy *addr; + SocketAddress *addr; - addr = g_new0(SocketAddressLegacy, 1); + addr = g_new0(SocketAddress, 1); if (strstart(str, "unix:", NULL)) { if (str[5] == '\0') { error_setg(errp, "invalid Unix socket address"); goto fail; } else { - addr->type = SOCKET_ADDRESS_LEGACY_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_LEGACY_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_LEGACY_KIND_VSOCK; - addr->u.vsock.data = g_new(VsockSocketAddress, 1); - if (vsock_parse(addr->u.vsock.data, str + strlen("vsock:"), errp)) { + addr->type = SOCKET_ADDRESS_TYPE_VSOCK; + if (vsock_parse(&addr->u.vsock, str + strlen("vsock:"), errp)) { goto fail; } } else { - addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; - addr->u.inet.data = g_new(InetSocketAddress, 1); - if (inet_parse(addr->u.inet.data, str, errp)) { + addr->type = SOCKET_ADDRESS_TYPE_INET; + if (inet_parse(&addr->u.inet, str, errp)) { goto fail; } } return addr; fail: - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); return NULL; } -int socket_connect(SocketAddressLegacy *addr, NonBlockingConnectHandler *callback, +int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, void *opaque, Error **errp) { int fd; switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_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_LEGACY_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_LEGACY_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_LEGACY_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: @@ -1104,25 +1101,25 @@ int socket_connect(SocketAddressLegacy *addr, NonBlockingConnectHandler *callbac return fd; } -int socket_listen(SocketAddressLegacy *addr, Error **errp) +int socket_listen(SocketAddress *addr, Error **errp) { int fd; switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_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_LEGACY_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_LEGACY_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_LEGACY_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: @@ -1133,34 +1130,34 @@ int socket_listen(SocketAddressLegacy *addr, Error **errp) void socket_listen_cleanup(int fd, Error **errp) { - SocketAddressLegacy *addr; + SocketAddress *addr; addr = socket_local_address(fd, errp); - if (addr->type == SOCKET_ADDRESS_LEGACY_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); } } - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); } -int socket_dgram(SocketAddressLegacy *remote, SocketAddressLegacy *local, Error **errp) +int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) { int fd; /* - * TODO SOCKET_ADDRESS_LEGACY_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_LEGACY_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: @@ -1171,14 +1168,14 @@ int socket_dgram(SocketAddressLegacy *remote, SocketAddressLegacy *local, Error } -static SocketAddressLegacy * +static SocketAddress * socket_sockaddr_to_address_inet(struct sockaddr_storage *sa, socklen_t salen, Error **errp) { char host[NI_MAXHOST]; char serv[NI_MAXSERV]; - SocketAddressLegacy *addr; + SocketAddress *addr; InetSocketAddress *inet; int ret; @@ -1192,9 +1189,9 @@ socket_sockaddr_to_address_inet(struct sockaddr_storage *sa, return NULL; } - addr = g_new0(SocketAddressLegacy, 1); - addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; - inet = addr->u.inet.data = g_new0(InetSocketAddress, 1); + addr = g_new0(SocketAddress, 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) { @@ -1208,20 +1205,18 @@ socket_sockaddr_to_address_inet(struct sockaddr_storage *sa, #ifndef WIN32 -static SocketAddressLegacy * +static SocketAddress * socket_sockaddr_to_address_unix(struct sockaddr_storage *sa, socklen_t salen, Error **errp) { - SocketAddressLegacy *addr; + SocketAddress *addr; struct sockaddr_un *su = (struct sockaddr_un *)sa; - addr = g_new0(SocketAddressLegacy, 1); - addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; - addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); + addr = g_new0(SocketAddress, 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; @@ -1229,18 +1224,18 @@ socket_sockaddr_to_address_unix(struct sockaddr_storage *sa, #endif /* WIN32 */ #ifdef CONFIG_AF_VSOCK -static SocketAddressLegacy * +static SocketAddress * socket_sockaddr_to_address_vsock(struct sockaddr_storage *sa, socklen_t salen, Error **errp) { - SocketAddressLegacy *addr; + SocketAddress *addr; VsockSocketAddress *vaddr; struct sockaddr_vm *svm = (struct sockaddr_vm *)sa; - addr = g_new0(SocketAddressLegacy, 1); - addr->type = SOCKET_ADDRESS_LEGACY_KIND_VSOCK; - addr->u.vsock.data = vaddr = g_new0(VsockSocketAddress, 1); + addr = g_new0(SocketAddress, 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); @@ -1248,7 +1243,7 @@ socket_sockaddr_to_address_vsock(struct sockaddr_storage *sa, } #endif /* CONFIG_AF_VSOCK */ -SocketAddressLegacy * +SocketAddress * socket_sockaddr_to_address(struct sockaddr_storage *sa, socklen_t salen, Error **errp) @@ -1277,7 +1272,7 @@ socket_sockaddr_to_address(struct sockaddr_storage *sa, } -SocketAddressLegacy *socket_local_address(int fd, Error **errp) +SocketAddress *socket_local_address(int fd, Error **errp) { struct sockaddr_storage ss; socklen_t sslen = sizeof(ss); @@ -1292,7 +1287,7 @@ SocketAddressLegacy *socket_local_address(int fd, Error **errp) } -SocketAddressLegacy *socket_remote_address(int fd, Error **errp) +SocketAddress *socket_remote_address(int fd, Error **errp) { struct sockaddr_storage ss; socklen_t sslen = sizeof(ss); @@ -1306,14 +1301,14 @@ SocketAddressLegacy *socket_remote_address(int fd, Error **errp) return socket_sockaddr_to_address(&ss, sslen, errp); } -char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp) +char *socket_address_to_string(struct SocketAddress *addr, Error **errp) { char *buf; InetSocketAddress *inet; switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_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 { @@ -1321,18 +1316,18 @@ char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp) } break; - case SOCKET_ADDRESS_LEGACY_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_LEGACY_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_LEGACY_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: @@ -1371,3 +1366,38 @@ SocketAddressLegacy *socket_address_crumple(SocketAddress *addr_flat) return addr; } + +SocketAddress *socket_address_flatten(SocketAddressLegacy *addr_legacy) +{ + SocketAddress *addr = g_new(SocketAddress, 1); + + 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_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_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_LEGACY_KIND_FD: + addr->type = SOCKET_ADDRESS_TYPE_FD; + QAPI_CLONE_MEMBERS(String, &addr->u.fd, addr_legacy->u.fd.data); + break; + default: + abort(); + } + + return addr; +} From 0c099fa7e9248a97c7854e5af84fc2479477ed5d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:42 +0200 Subject: [PATCH 19/28] sockets: Delete unused helper socket_address_crumple() Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-8-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake [Commit message typo fixed] --- include/qemu/sockets.h | 11 ----------- util/qemu-sockets.c | 31 ------------------------------- 2 files changed, 42 deletions(-) diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index a0b5cae03b..5c326db232 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -120,17 +120,6 @@ 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 - * - * Convert SocketAddress to SocketAddressLegacy. Caller is responsible - * for freeing with qapi_free_SocketAddressLegacy(). - * - * Returns: the argument converted to SocketAddressLegacy. - */ -SocketAddressLegacy *socket_address_crumple(SocketAddress *addr); - /** * socket_address_flatten: * @addr: the socket address to flatten diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 9e65ebed01..d8183f79d7 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1336,37 +1336,6 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp) return buf; } -SocketAddressLegacy *socket_address_crumple(SocketAddress *addr_flat) -{ - SocketAddressLegacy *addr = g_new(SocketAddressLegacy, 1); - - switch (addr_flat->type) { - case SOCKET_ADDRESS_TYPE_INET: - addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; - addr->u.inet.data = QAPI_CLONE(InetSocketAddress, - &addr_flat->u.inet); - break; - case SOCKET_ADDRESS_TYPE_UNIX: - addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; - addr->u.q_unix.data = QAPI_CLONE(UnixSocketAddress, - &addr_flat->u.q_unix); - break; - case SOCKET_ADDRESS_TYPE_VSOCK: - addr->type = SOCKET_ADDRESS_LEGACY_KIND_VSOCK; - addr->u.vsock.data = QAPI_CLONE(VsockSocketAddress, - &addr_flat->u.vsock); - break; - case SOCKET_ADDRESS_TYPE_FD: - addr->type = SOCKET_ADDRESS_LEGACY_KIND_FD; - addr->u.fd.data = QAPI_CLONE(String, &addr_flat->u.fd); - break; - default: - abort(); - } - - return addr; -} - SocketAddress *socket_address_flatten(SocketAddressLegacy *addr_legacy) { SocketAddress *addr = g_new(SocketAddress, 1); From 10e37839ed7c420c9190e20a51ed7ff39f1e1cff Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 27 Apr 2017 10:41:23 +0200 Subject: [PATCH 20/28] qmp: Improve QMP dispatch error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <1493282486-28338-2-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé --- qapi/qmp-dispatch.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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; } From 6c02258e143700314ebf268dae47eb23db17d1cf Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 27 Apr 2017 10:41:24 +0200 Subject: [PATCH 21/28] qobject-input-visitor: Document full_name_nth() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Armbruster Message-Id: <1493282486-28338-3-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau --- qapi/qobject-input-visitor.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 865e948ac0..2530959781 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) { From ed0ba0f47e8cb6d924db0a54090bbb7b095fe9ea Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 27 Apr 2017 10:41:25 +0200 Subject: [PATCH 22/28] qapi: Document intended use of @name within alternate visits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Armbruster Message-Id: <1493282486-28338-4-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau --- include/qapi/visitor.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 From 8b2e41d733850ec6a67a85743138e023cbb8921b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 27 Apr 2017 10:41:26 +0200 Subject: [PATCH 23/28] qobject-input-visitor: Catch misuse of end_struct vs. end_list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Armbruster Message-Id: <1493282486-28338-5-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau [More elaborate assertions for clarity] --- qapi/qobject-input-visitor.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 2530959781..d0f0002317 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -291,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, @@ -346,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, @@ -645,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; From aa3b167f21588a87e7783ac29aa54b0c721eb37a Mon Sep 17 00:00:00 2001 From: John Snow Date: Thu, 27 Apr 2017 18:36:28 -0400 Subject: [PATCH 24/28] qmp-shell: add persistent command history Use the existing readline history function we are utilizing to provide persistent command history across instances of qmp-shell. This assists entering debug commands across sessions that may be interrupted by QEMU sessions terminating, where the qmp-shell has to be relaunched. Signed-off-by: John Snow Message-Id: <20170427223628.20893-1-jsnow@redhat.com> Reviewed-by: Stefan Hajnoczi Reviewed-by: Kashyap Chamarthy Tested-by: Kashyap Chamarthy Signed-off-by: Markus Armbruster --- scripts/qmp/qmp-shell | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index eccb88a4e8..6ece6e7c81 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): """ @@ -132,11 +137,27 @@ class QMPShell(qmp.QEMUMonitorProtocol): 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: From c5e397df9e247bff2398400864cde94d1b40317c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 4 May 2017 16:54:29 +0400 Subject: [PATCH 25/28] qmp-shell: add -N option to skip negotiate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qemu-ga doesn't have negotiate phase. Signed-off-by: Marc-André Lureau Message-Id: <20170504125432.21653-2-marcandre.lureau@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qmp/qmp-shell | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 6ece6e7c81..b4d2dbd292 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -277,8 +277,8 @@ 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!'): @@ -390,7 +390,7 @@ 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('qemu-shell [ -v ] [ -p ] [ -H ] [ -N ] < UNIX socket path> | < TCP address:port >\n') sys.exit(1) def main(): @@ -399,6 +399,7 @@ def main(): hmp = False pretty = False verbose = False + negotiate = True try: for arg in sys.argv[1:]: @@ -408,6 +409,8 @@ def main(): hmp = True elif arg == "-p": pretty = True + elif arg == "-N": + negotiate = False elif arg == "-v": verbose = True else: @@ -425,7 +428,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: From daa5a72ebab20345da474ee2f6148a8dacd2cb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 4 May 2017 16:54:30 +0400 Subject: [PATCH 26/28] qmp-shell: Cope with query-commands error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qemu-ga doesn't implement it. Signed-off-by: Marc-André Lureau Message-Id: <20170504125432.21653-3-marcandre.lureau@redhat.com> Reviewed-by: Eric Blake [Commit message tweaked] Signed-off-by: Markus Armbruster --- scripts/qmp/qmp-shell | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index b4d2dbd292..1182f823ef 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -131,7 +131,10 @@ 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): From b13d2ff3de2d1f79107a376e883bcb8336f75d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 4 May 2017 16:54:31 +0400 Subject: [PATCH 27/28] qmp-shell: don't show version greeting if unavailable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qemu-ga doesn't have greeting. Signed-off-by: Marc-André Lureau Message-Id: <20170504125432.21653-4-marcandre.lureau@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qmp/qmp-shell | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 1182f823ef..5986e3740c 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -286,6 +286,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): 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']) From dcd3b25d656d346205dc0f2254723fccf0264e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 4 May 2017 16:54:32 +0400 Subject: [PATCH 28/28] qmp-shell: improve help MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Describe the arguments & fix the tool name. Signed-off-by: Marc-André Lureau Message-Id: <20170504125432.21653-5-marcandre.lureau@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qmp/qmp-shell | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 5986e3740c..860ffb27f2 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -396,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 ] [ -N ] < 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():