[PATCH v2 16/17] tools/init-dom0less: Configure already-introduced domains

Jason Andryuk posted 17 patches 3 months, 2 weeks ago
[PATCH v2 16/17] tools/init-dom0less: Configure already-introduced domains
Posted by Jason Andryuk 3 months, 2 weeks ago
With xenstore automatically introducing domains at startup, the
xs_is_domain_introduced() check is no longer accurate.  Instead, process
all domains and introduce non-introduced domains.  This writes the
xenstore entries and xl configuration for xenstore-enhanced domains as
those entries are still useful with an already-introduced domain.

Non-xenstore domains are still skipped.

While at it, remove domain_exists() which is just a simple wrapper.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
---
 tools/helpers/init-dom0less.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/tools/helpers/init-dom0less.c b/tools/helpers/init-dom0less.c
index 6ae7cf2e7e..4336e0f418 100644
--- a/tools/helpers/init-dom0less.c
+++ b/tools/helpers/init-dom0less.c
@@ -324,16 +324,14 @@ static int init_domain(struct xs_handle *xsh,
     if (rc)
         err(1, "writing to xenstore");
 
-    rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn, xenstore_evtchn);
-    if (!rc)
-        err(1, "xs_introduce_domain");
-    return 0;
-}
+    if (!xs_is_domain_introduced(xsh, info->domid)) {
+        rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn,
+                                 xenstore_evtchn);
+        if (!rc)
+            err(1, "xs_introduce_domain");
+    }
 
-/* Check if domain has been configured in XS */
-static bool domain_exists(struct xs_handle *xsh, int domid)
-{
-    return xs_is_domain_introduced(xsh, domid);
+    return 0;
 }
 
 int main(int argc, char **argv)
@@ -376,14 +374,10 @@ 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) {
-                fprintf(stderr, "init_domain failed.\n");
-                goto out;
-            }
-        } else {
-            printf("Domain %u has already been initialized\n", domid);
+        rc = init_domain(xsh, xch, xfh, &info[i]);
+        if (rc < 0) {
+            fprintf(stderr, "init_domain failed.\n");
+            goto out;
         }
     }
 out:
-- 
2.50.0
Re: [PATCH v2 16/17] tools/init-dom0less: Configure already-introduced domains
Posted by Stefano Stabellini 3 months, 2 weeks ago
On Wed, 16 Jul 2025, Jason Andryuk wrote:
> With xenstore automatically introducing domains at startup, the
> xs_is_domain_introduced() check is no longer accurate.

We can still use xs_is_domain_introduced() to skip configure_xenstore?


> Instead, process
> all domains and introduce non-introduced domains.  This writes the
> xenstore entries and xl configuration for xenstore-enhanced domains as
> those entries are still useful with an already-introduced domain.

This is OK but to protect against mistakes such as calling init-dom0less
twice, we could simply check if one of the mandatory xenstore entries
is already present, and if so return early from create_xenstore.


> Non-xenstore domains are still skipped.
> 
> While at it, remove domain_exists() which is just a simple wrapper.
> 
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
> ---
>  tools/helpers/init-dom0less.c | 28 +++++++++++-----------------
>  1 file changed, 11 insertions(+), 17 deletions(-)
> 
> diff --git a/tools/helpers/init-dom0less.c b/tools/helpers/init-dom0less.c
> index 6ae7cf2e7e..4336e0f418 100644
> --- a/tools/helpers/init-dom0less.c
> +++ b/tools/helpers/init-dom0less.c
> @@ -324,16 +324,14 @@ static int init_domain(struct xs_handle *xsh,
>      if (rc)
>          err(1, "writing to xenstore");
>  
> -    rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn, xenstore_evtchn);
> -    if (!rc)
> -        err(1, "xs_introduce_domain");
> -    return 0;
> -}
> +    if (!xs_is_domain_introduced(xsh, info->domid)) {
> +        rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn,
> +                                 xenstore_evtchn);
> +        if (!rc)
> +            err(1, "xs_introduce_domain");
> +    }
>  
> -/* Check if domain has been configured in XS */
> -static bool domain_exists(struct xs_handle *xsh, int domid)
> -{
> -    return xs_is_domain_introduced(xsh, domid);
> +    return 0;
>  }
>  
>  int main(int argc, char **argv)
> @@ -376,14 +374,10 @@ 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) {
> -                fprintf(stderr, "init_domain failed.\n");
> -                goto out;
> -            }
> -        } else {
> -            printf("Domain %u has already been initialized\n", domid);
> +        rc = init_domain(xsh, xch, xfh, &info[i]);
> +        if (rc < 0) {
> +            fprintf(stderr, "init_domain failed.\n");
> +            goto out;
>          }
>      }
>  out:
> -- 
> 2.50.0
> 
>