[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 14/17] tools/xenstored: Auto-introduce domains


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Wed, 16 Jul 2025 17:15:01 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jKTqt/XXb9MSRAqj6LYolQnFov3cpGRvILaAGq8Cm1E=; b=AlL0x/LZurgHbvWXPj1QWfktWyeJhRPA9wVFbuTJAJ/PZIQRh9QXrQJonUeMG419hwUyj9B7u00obvYkjfzIKUEB5natFx4qAm9ePAS9NjQQWrbSesqwoGe6w5txgPAibBHzwymumKegPwHAkYUhkkv0ot7NgQZwxdR6iYceNuMdjy2LEqtUPTRGpo5AKWQZP49JeG+9IV60E6C4vJoMxVTi14JtNXloyn0MS0DCOcvhH0tJOHzqDQ0nh5rAccOJNWpdNUzajqcyJJL4nq8hnLma6bSplVQnjWtFjVP4uX0ftiFUR/pbtrldU+xTgP6pDOAtJgMNVxrlqWiyIkkzng==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WOBLu/ZUfnszltdA6l9fKOGUXV6Pwh9defYDPyfo58Wjy1ifZJ6JN/4LRCjECOTgq2PLW4pgUYgOtMHWI+bVheR1kcvFP3YrBRV61f9tdSiFt/Le8ge+nDvsMj4aLfHUYaLLOadwx453FZOkD8CIfPHv/L1qX6CgvKsP70VFRAk01guCzNtMf84zY+cqENlQJaDdGtpKIvxiB5P2isRnWaRF5H2ge8BD1U3Myx2UR/7OVJB9cXM0Ia6/em/z0FwzKNtypJYvZfnCmhPy6rZdh6gz0QPIVcRkqi/9fTmPJZYowQelRixBa+o80fl/0sOdu4B2kzHWIfpw3L7o5uC01w==
  • Cc: Jason Andryuk <jason.andryuk@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Wed, 16 Jul 2025 21:22:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Replace dom0_init() with init_domains() which uses libxenmanage to
iterate through all existing domains and introduce them.

dom0_domid is updated with the xenstore domain, since it really
indicates the local domain.

priv_domid is set to the control domain.  This makes it limited to a
single domain.

These features let xenstore automatically connect any existing domains,
which means it doesn't need to be done manually from init-dom0less.

For a legacy dom0, the result should be unchanged.

For a late xenstore stubdom it should also be the same, but priv_domid
would be set automatically to control domain (which default to 0
normally).

Always signal the event channel for initial domains.  This gets dom0 (a
local xenstored domain) to connect.

Also always write XENSTORE_CONNECTED since we know we are connected at
this point.

Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
 tools/xenstored/core.c   |  2 +-
 tools/xenstored/domain.c | 45 +++++++++++++++++++++++++++++++---------
 tools/xenstored/domain.h |  2 +-
 3 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c
index 550e879a00..835402af81 100644
--- a/tools/xenstored/core.c
+++ b/tools/xenstored/core.c
@@ -2762,7 +2762,7 @@ int main(int argc, char *argv[])
        /* Listen to hypervisor. */
        if (!live_update) {
                domain_init(-1);
-               dom0_init();
+               init_domains();
        }
 
        /* redirect to /dev/null now we're ready to accept connections */
diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
index 5443b4e608..44e997cee4 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -1257,20 +1257,45 @@ const char *get_implicit_path(const struct connection 
*conn)
        return conn->domain->path;
 }
 
-void dom0_init(void)
+void init_domains(void)
 {
-       evtchn_port_t port;
-       struct domain *dom0;
+       unsigned int domid;
+       unsigned int state;
+       unsigned int caps;
+       uint64_t unique_id;
+
+       while (!xenmanage_poll_changed_domain(xm_handle, &domid, &state, &caps,
+                                             &unique_id)) {
+               evtchn_port_t port = 0;
+               struct domain *domain;
+
+               if (caps & XENMANAGE_GETDOMSTATE_CAP_XENSTORE)
+                       dom0_domid = domid;
+
+               if (caps & XENMANAGE_GETDOMSTATE_CAP_CONTROL)
+                       priv_domid = domid;
 
-       port = get_xenbus_evtchn();
-       if (port == -1)
-               barf_perror("Failed to initialize dom0 port");
+               if (domid == dom0_domid) {
+                       port = get_xenbus_evtchn();
+                       if (port == -1)
+                               barf_perror("Failed to initialize dom%u port",
+                                           domid);
+               }
+
+               domain = introduce_domain(NULL, domid, port, false);
+               if (!domain) {
+                       xprintf("Could not initialize dom%u", domid);
+                       continue;
+               }
 
-       dom0 = introduce_domain(NULL, xenbus_master_domid(), port, false);
-       if (!dom0)
-               barf_perror("Failed to initialize dom0");
+               domain_conn_reset(domain);
 
-       xenevtchn_notify(xce_handle, dom0->port);
+               if (domain->interface)
+                       domain->interface->connection = XENSTORE_CONNECTED;
+
+               /* Notify the domain that xenstore is available */
+               xenevtchn_notify(xce_handle, domain->port);
+       }
 }
 
 void stubdom_init(void)
diff --git a/tools/xenstored/domain.h b/tools/xenstored/domain.h
index 844ac11510..6a78f06935 100644
--- a/tools/xenstored/domain.h
+++ b/tools/xenstored/domain.h
@@ -84,7 +84,7 @@ int do_reset_watches(const void *ctx, struct connection *conn,
 
 void domain_early_init(void);
 void domain_init(int evtfd);
-void dom0_init(void);
+void init_domains(void);
 void stubdom_init(void);
 void domain_deinit(void);
 void ignore_connection(struct connection *conn, unsigned int err);
-- 
2.50.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.