From: Anthony PERARD via <qemu-devel@nongnu.org>
To: <qemu-devel@nongnu.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Paul Durrant <pdurrant@amazon.com>,
Anthony PERARD <anthony.perard@citrix.com>
Subject: [PULL 3/4] xen-bus: reduce scope of backend watch
Date: Tue, 20 Oct 2020 11:02:38 +0100 [thread overview]
Message-ID: <20201020100239.272748-4-anthony.perard@citrix.com> (raw)
In-Reply-To: <20201020100239.272748-1-anthony.perard@citrix.com>
From: Paul Durrant <pdurrant@amazon.com>
Currently a single watch on /local/domain/X/backend is registered by each
QEMU process running in service domain X (where X is usually 0). The purpose
of this watch is to ensure that QEMU is notified when the Xen toolstack
creates a new device backend area.
Such a backend area is specific to a single frontend area created for a
specific guest domain and, since each QEMU process is also created to service
a specfic guest domain, it is unnecessary and inefficient to notify all QEMU
processes.
Only the QEMU process associated with the same guest domain need
receive the notification. This patch re-factors the watch registration code
such that notifications are targetted appropriately.
Reported-by: Jerome Leseinne <jerome.leseinne@gmail.com>
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Message-Id: <20201001081500.1026-1-paul@xen.org>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
hw/xen/xen-backend.c | 11 ++++++++++
hw/xen/xen-bus.c | 40 ++++++++++++++++++++++++++++--------
include/hw/xen/xen-backend.h | 1 +
include/hw/xen/xen-bus.h | 3 ++-
4 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/hw/xen/xen-backend.c b/hw/xen/xen-backend.c
index 10199fb58d10..5b0fb76eaeb3 100644
--- a/hw/xen/xen-backend.c
+++ b/hw/xen/xen-backend.c
@@ -41,6 +41,12 @@ static void xen_backend_table_add(XenBackendImpl *impl)
g_hash_table_insert(xen_backend_table_get(), (void *)impl->type, impl);
}
+static const char **xen_backend_table_keys(unsigned int *count)
+{
+ return (const char **)g_hash_table_get_keys_as_array(
+ xen_backend_table_get(), count);
+}
+
static const XenBackendImpl *xen_backend_table_lookup(const char *type)
{
return g_hash_table_lookup(xen_backend_table_get(), type);
@@ -70,6 +76,11 @@ void xen_backend_register(const XenBackendInfo *info)
xen_backend_table_add(impl);
}
+const char **xen_backend_get_types(unsigned int *count)
+{
+ return xen_backend_table_keys(count);
+}
+
static QLIST_HEAD(, XenBackendInstance) backend_list;
static void xen_backend_list_add(XenBackendInstance *backend)
diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
index 9ce1c9540b9e..8c588920d9fc 100644
--- a/hw/xen/xen-bus.c
+++ b/hw/xen/xen-bus.c
@@ -430,7 +430,15 @@ static void xen_bus_unrealize(BusState *bus)
trace_xen_bus_unrealize();
if (xenbus->backend_watch) {
- xen_bus_remove_watch(xenbus, xenbus->backend_watch, NULL);
+ unsigned int i;
+
+ for (i = 0; i < xenbus->backend_types; i++) {
+ if (xenbus->backend_watch[i]) {
+ xen_bus_remove_watch(xenbus, xenbus->backend_watch[i], NULL);
+ }
+ }
+
+ g_free(xenbus->backend_watch);
xenbus->backend_watch = NULL;
}
@@ -446,8 +454,11 @@ static void xen_bus_unrealize(BusState *bus)
static void xen_bus_realize(BusState *bus, Error **errp)
{
+ char *key = g_strdup_printf("%u", xen_domid);
XenBus *xenbus = XEN_BUS(bus);
unsigned int domid;
+ const char **type;
+ unsigned int i;
Error *local_err = NULL;
trace_xen_bus_realize();
@@ -469,19 +480,32 @@ static void xen_bus_realize(BusState *bus, Error **errp)
module_call_init(MODULE_INIT_XEN_BACKEND);
- xenbus->backend_watch =
- xen_bus_add_watch(xenbus, "", /* domain root node */
- "backend", xen_bus_backend_changed, &local_err);
- if (local_err) {
- /* This need not be treated as a hard error so don't propagate */
- error_reportf_err(local_err,
- "failed to set up enumeration watch: ");
+ type = xen_backend_get_types(&xenbus->backend_types);
+ xenbus->backend_watch = g_new(XenWatch *, xenbus->backend_types);
+
+ for (i = 0; i < xenbus->backend_types; i++) {
+ char *node = g_strdup_printf("backend/%s", type[i]);
+
+ xenbus->backend_watch[i] =
+ xen_bus_add_watch(xenbus, node, key, xen_bus_backend_changed,
+ &local_err);
+ if (local_err) {
+ /* This need not be treated as a hard error so don't propagate */
+ error_reportf_err(local_err,
+ "failed to set up '%s' enumeration watch: ",
+ type[i]);
+ }
+
+ g_free(node);
}
+ g_free(type);
+ g_free(key);
return;
fail:
xen_bus_unrealize(bus);
+ g_free(key);
}
static void xen_bus_unplug_request(HotplugHandler *hotplug,
diff --git a/include/hw/xen/xen-backend.h b/include/hw/xen/xen-backend.h
index 010d71263876..aac2fd454d44 100644
--- a/include/hw/xen/xen-backend.h
+++ b/include/hw/xen/xen-backend.h
@@ -31,6 +31,7 @@ void xen_backend_set_device(XenBackendInstance *backend,
XenDevice *xen_backend_get_device(XenBackendInstance *backend);
void xen_backend_register(const XenBackendInfo *info);
+const char **xen_backend_get_types(unsigned int *nr);
void xen_backend_device_create(XenBus *xenbus, const char *type,
const char *name, QDict *opts, Error **errp);
diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h
index 3df696136f7b..6bdbf3ff8220 100644
--- a/include/hw/xen/xen-bus.h
+++ b/include/hw/xen/xen-bus.h
@@ -66,7 +66,8 @@ struct XenBus {
domid_t backend_id;
struct xs_handle *xsh;
XenWatchList *watch_list;
- XenWatch *backend_watch;
+ unsigned int backend_types;
+ XenWatch **backend_watch;
QLIST_HEAD(, XenDevice) inactive_devices;
};
--
Anthony PERARD
next prev parent reply other threads:[~2020-10-20 10:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-20 10:02 [PULL 0/4] xen queue 2020-10-20 Anthony PERARD via
2020-10-20 10:02 ` [PULL 1/4] xen: xenguest is not used so is not needed Anthony PERARD via
2020-10-20 10:02 ` [PULL 2/4] xen: Rename XENBACKEND_DEVICE to XENBACKEND Anthony PERARD via
2020-10-20 10:02 ` Anthony PERARD via [this message]
2020-10-20 10:02 ` [PULL 4/4] hw/xen: Set suppress-vmdesc for Xen machines Anthony PERARD via
2020-10-20 11:04 ` [PULL 0/4] xen queue 2020-10-20 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201020100239.272748-4-anthony.perard@citrix.com \
--to=qemu-devel@nongnu.org \
--cc=anthony.perard@citrix.com \
--cc=pdurrant@amazon.com \
--cc=peter.maydell@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).