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

[PATCH v3 1/8] tools/init-dom0less: Make handles global


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Tue, 26 Aug 2025 17:08:40 -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=hb8jV7y+eU28UgOgIGo2GBFOvkJDnI7mqTnXWpd85l4=; b=gLoRlQUUh+db+AfD5GbIAs7Amy3QHM9nIlboHyBfMToYKmGofjZQG04fjbsoOX4l97pnNM115QgnLT9xLIAby/zsd0stvq0L3bKTZ8FowEhI2DLjBTj/pvI2i+1yMkUp43mCElTDX+IBdK6EsHvfnt3QvC+rJyHzvj0w8tBgwQc4aivPA57BvQ/giLmHmpGQHmyLLkfDX1qTywd18eTVsTNsgaDqBP9SHZA0C5I6l9Xt3DSc73YMbyVGkzhWgjjAvUYlbatP0DefM1r9otxbL6wEPU/PNZtt7e9CuU37kSmzy0qMWF8y7p8gFGiXhdp65Z7H7IEt7fhj/PUisdNGcA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Plf6Jy8QQxDrgVSnHUYKyyiTd0jotDC3rleISMSWL8+P4w/0LRtQAHBZtu1IcFGXT81V1SN8Om8HStKqjW0WvaswRYrO7OPWRt00xiD23hUoyBnXCxHHuj4LzqFECbvwXhq7OZFGvMHEHaPjT7iANClaLRI3pYMOG6w1++V1XY5bKQGAHN7mmqJoAoi81IsIgXIfDSxbSZhgMO37TFw5Ph2rH8lK9487ZhF/g7gvGrZaDOW4lYZhbG7d7c50Fh3SRlpQWg/Ez2YkSx6GicfwyGxlknk3w31urTczJDvvcpwAF79qNovLWab98Cph4Y45r2L6oFD5vxq7TJ0Sl7vznQ==
  • Cc: Jason Andryuk <jason.andryuk@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Tue, 26 Aug 2025 21:09:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

init-dom0less passes the assorted xen library handles from main
downward.  This is a little excessive in places with 4 handles passed
into configure_xenstore().

Replace the handle passing with file-scoped variables.

The xenstore helpers are not changed.  This keeps their implementation
common with the libxenstore functions that take a handle, transation,
and then additional arguments.

Suggested-by: Juergen Gross <jgross@xxxxxxxx>
Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
v3:
New
---
 tools/helpers/init-dom0less.c | 37 +++++++++++++++--------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/tools/helpers/init-dom0less.c b/tools/helpers/init-dom0less.c
index a182dce563..0b0be08449 100644
--- a/tools/helpers/init-dom0less.c
+++ b/tools/helpers/init-dom0less.c
@@ -18,8 +18,12 @@
 #define XENSTORE_PFN_OFFSET 1
 #define STR_MAX_LENGTH 128
 
-static int alloc_xs_page(struct xc_interface_core *xch,
-                         libxl_dominfo *info,
+static libxl_ctx *ctx;
+static struct xs_handle *xsh;
+static struct xc_interface_core *xch;
+static xenforeignmemory_handle *xfh;
+
+static int alloc_xs_page(libxl_dominfo *info,
                          uint64_t *xenstore_pfn)
 {
     int rc;
@@ -43,8 +47,7 @@ static int alloc_xs_page(struct xc_interface_core *xch,
     return 0;
 }
 
-static int get_xs_page(struct xc_interface_core *xch, libxl_dominfo *info,
-                       uint64_t *xenstore_pfn)
+static int get_xs_page(libxl_dominfo *info, uint64_t *xenstore_pfn)
 {
     int rc;
 
@@ -111,8 +114,7 @@ static bool do_xs_write_vm(struct xs_handle *xsh, 
xs_transaction_t t,
  * The list was retrieved by running xenstore-ls on a corresponding
  * domain started by xl/libxl.
  */
-static int create_xenstore(struct xs_handle *xsh,
-                           libxl_dominfo *info, libxl_uuid uuid,
+static int create_xenstore(libxl_dominfo *info, libxl_uuid uuid,
                            uint64_t xenstore_pfn,
                            evtchn_port_t xenstore_port)
 {
@@ -235,10 +237,7 @@ err:
     return rc;
 }
 
-static int init_domain(struct xs_handle *xsh,
-                       struct xc_interface_core *xch,
-                       xenforeignmemory_handle *xfh,
-                       libxl_dominfo *info)
+static int init_domain(libxl_dominfo *info)
 {
     libxl_uuid uuid;
     uint64_t xenstore_evtchn, xenstore_pfn;
@@ -258,13 +257,13 @@ static int init_domain(struct xs_handle *xsh,
         return 0;
 
     /* Get xenstore page */
-    if (get_xs_page(xch, info, &xenstore_pfn) != 0)
+    if (get_xs_page(info, &xenstore_pfn) != 0)
         return 1;
 
     if (xenstore_pfn == ~0ULL) {
         struct xenstore_domain_interface *intf;
 
-        rc = alloc_xs_page(xch, info, &xenstore_pfn);
+        rc = alloc_xs_page(info, &xenstore_pfn);
         if (rc != 0) {
             printf("Error on getting xenstore page\n");
             return 1;
@@ -299,7 +298,7 @@ static int init_domain(struct xs_handle *xsh,
     if (rc)
         err(1, "gen_stub_json_config");
 
-    rc = create_xenstore(xsh, info, uuid, xenstore_pfn, xenstore_evtchn);
+    rc = create_xenstore(info, uuid, xenstore_pfn, xenstore_evtchn);
     if (rc)
         err(1, "writing to xenstore");
 
@@ -310,7 +309,7 @@ static int init_domain(struct xs_handle *xsh,
 }
 
 /* Check if domain has been configured in XS */
-static bool domain_exists(struct xs_handle *xsh, int domid)
+static bool domain_exists(int domid)
 {
     return xs_is_domain_introduced(xsh, domid);
 }
@@ -318,11 +317,7 @@ static bool domain_exists(struct xs_handle *xsh, int domid)
 int main(int argc, char **argv)
 {
     libxl_dominfo *info = NULL;
-    libxl_ctx *ctx;
     int nb_vm = 0, rc = 0, i;
-    struct xs_handle *xsh = NULL;
-    struct xc_interface_core *xch = NULL;
-    xenforeignmemory_handle *xfh = NULL;
 
     /* TODO reuse libxl xsh connection */
     xsh = xs_open(0);
@@ -355,9 +350,9 @@ int main(int argc, char **argv)
             continue;
 
         printf("Checking domid: %u\n", domid);
-        if (!domain_exists(xsh, domid)) {
-            rc = init_domain(xsh, xch, xfh, &info[i]);
-            if (rc < 0) {
+        if (!domain_exists(domid)) {
+            rc = init_domain(&info[i]);
+            if (rc) {
                 fprintf(stderr, "init_domain failed.\n");
                 goto out;
             }
-- 
2.50.1




 


Rackspace

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