Skip to contentSkip to conversation

tools: init-dom0less: Replace err() with more informative messages

PATCH Superseded Michal Orzel 3 participants 4 messages Oct 1, 2025 – Oct 6, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: init-dom0less: Replace err() with more informative messages

Current use of err() has the following issues:
- without setting errno, on error it results in printing e.g.:
"init-dom0less: writing to xenstore: Success"
This is very misleading and difficult to deduct that there was a failure.
- does not propagate error codes to the caller.
- skips "init_domain failed" message by exiting early.

Replace err() with more informative messages propagating rc when possible.

---
 tools/helpers/init-dom0less.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
tools/helpers/init-dom0less.c +17 -8
index a182dce56353..3dd2d74886eb 100644
@@ -288,24 +288,33 @@ static int init_domain(struct xs_handle *xsh,
 
         rc = xc_dom_gnttab_seed(xch, info->domid, true,
                                 (xen_pfn_t)-1, xenstore_pfn, 0, 0);
-        if (rc)
-               err(1, "xc_dom_gnttab_seed");
+        if (rc) {
+            printf("Failed to seed gnttab entries\n");
+            return rc;
+        }
     }
 
     libxl_uuid_generate(&uuid);
     xc_domain_sethandle(xch, info->domid, libxl_uuid_bytearray(&uuid));
 
     rc = gen_stub_json_config(info->domid, &uuid);
-    if (rc)
-        err(1, "gen_stub_json_config");
+    if (rc) {
+        printf("Failed to create stub json config\n");
+        return rc;
+    }
 
     rc = create_xenstore(xsh, info, uuid, xenstore_pfn, xenstore_evtchn);
-    if (rc)
-        err(1, "writing to xenstore");
+    if (rc) {
+        printf("Failed to write to xenstore\n");
+        return rc;
+    }
 
     rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn, xenstore_evtchn);
-    if (!rc)
-        err(1, "xs_introduce_domain");
+    if (!rc) {
+        printf("Failed to introduce a domain\n");
+        return 1;
+    }
+
     return 0;
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 10 lines · Michal Orzel

Current use of err() has the following issues:
- without setting errno, on error it results in printing e.g.:
"init-dom0less: writing to xenstore: Success"
This is very misleading and difficult to deduct that there was a failure.
- does not propagate error codes to the caller.
- skips "init_domain failed" message by exiting early.

Replace err() with more informative messages propagating rc when possible.

Sounds good to me. Only suggestion I'd make is to also print relevant arguments where needed, like...

Quoted 11 lines
---
 tools/helpers/init-dom0less.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
tools/helpers/init-dom0less.c +0 -0
index a182dce56353..3dd2d74886eb 100644

tools/helpers/init-dom0less.c static int init_domain(struct xs_handle *xsh, · line 292

Quoted 7 lines
tools/helpers/init-dom0less.c +2 -2
@@ -288,24 +288,33 @@ static int init_domain(struct xs_handle *xsh,
 
         rc = xc_dom_gnttab_seed(xch, info->domid, true,
                                 (xen_pfn_t)-1, xenstore_pfn, 0, 0);
-        if (rc)
-               err(1, "xc_dom_gnttab_seed");
+        if (rc) {
+            printf("Failed to seed gnttab entries\n");

... also printing the domid and the xenstore pfn here. Or...

tools/helpers/init-dom0less.c static int init_domain(struct xs_handle *xsh, · line 302

Quoted 12 lines
tools/helpers/init-dom0less.c +4 -2
+            return rc;
+        }
     }
 
     libxl_uuid_generate(&uuid);
     xc_domain_sethandle(xch, info->domid, libxl_uuid_bytearray(&uuid));
 
     rc = gen_stub_json_config(info->domid, &uuid);
-    if (rc)
-        err(1, "gen_stub_json_config");
+    if (rc) {
+        printf("Failed to create stub json config\n");

... the domid and uuid here.

Similar suggestions for the other printfs.

Quoted 7 lines
tools/helpers/init-dom0less.c +3 -2
+        return rc;
+    }
 
     rc = create_xenstore(xsh, info, uuid, xenstore_pfn, xenstore_evtchn);
-    if (rc)
-        err(1, "writing to xenstore");
+    if (rc) {

tools/helpers/init-dom0less.c static int init_domain(struct xs_handle *xsh, · line 315

Quoted 10 lines
tools/helpers/init-dom0less.c +6 -2
+        printf("Failed to write to xenstore\n");
+        return rc;
+    }
 
     rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn, xenstore_evtchn);
-    if (!rc)
-        err(1, "xs_introduce_domain");
+    if (!rc) {
+        printf("Failed to introduce a domain\n");
+        return 1;

nit: Maybe -EBUSY so it's -errno like the others?

tools/helpers/init-dom0less.c static int init_domain(struct xs_handle *xsh, · line 320

Quoted 5 lines
tools/helpers/init-dom0less.c +2 -0
+    }
+
     return 0;
 }
 

Cheers,
Alejandro

#2 lore raw
Quoted 27 lines · Alejandro Vallejo
Quoted 10 lines · Michal Orzel

Current use of err() has the following issues:
- without setting errno, on error it results in printing e.g.:
"init-dom0less: writing to xenstore: Success"
This is very misleading and difficult to deduct that there was a failure.
- does not propagate error codes to the caller.
- skips "init_domain failed" message by exiting early.

Replace err() with more informative messages propagating rc when possible.

Sounds good to me. Only suggestion I'd make is to also print relevant arguments where needed, like...

Quoted 12 lines
---
 tools/helpers/init-dom0less.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
tools/helpers/init-dom0less.c +0 -0
index a182dce56353..3dd2d74886eb 100644
@@ -288,24 +288,33 @@ static int init_domain(struct xs_handle *xsh,
 
Quoted 8 lines

tools/helpers/init-dom0less.c static int init_domain(struct xs_handle *xsh, · line 292

Quoted 6 lines
tools/helpers/init-dom0less.c +2 -2
         rc = xc_dom_gnttab_seed(xch, info->domid, true,
                                 (xen_pfn_t)-1, xenstore_pfn, 0, 0);
-        if (rc)
-               err(1, "xc_dom_gnttab_seed");
+        if (rc) {
+            printf("Failed to seed gnttab entries\n");

... also printing the domid and the xenstore pfn here. Or...

Domid is printed from main() before everything else, so no need to print it again. Not sure why we need to print pfn but I can add it here if it's a must.

Quoted 29 lines

tools/helpers/init-dom0less.c static int init_domain(struct xs_handle *xsh, · line 302

Quoted 13 lines
tools/helpers/init-dom0less.c +4 -2
+            return rc;
+        }
     }
 
     libxl_uuid_generate(&uuid);
     xc_domain_sethandle(xch, info->domid, libxl_uuid_bytearray(&uuid));
 
     rc = gen_stub_json_config(info->domid, &uuid);
-    if (rc)
-        err(1, "gen_stub_json_config");
+    if (rc) {
+        printf("Failed to create stub json config\n");

... the domid and uuid here.

Similar suggestions for the other printfs.

Quoted 11 lines
tools/helpers/init-dom0less.c +6 -2
+        return rc;
+    }
 
     rc = create_xenstore(xsh, info, uuid, xenstore_pfn, xenstore_evtchn);
-    if (rc)
-        err(1, "writing to xenstore");
+    if (rc) {
+        printf("Failed to write to xenstore\n");
+        return rc;
+    }
 
Quoted 8 lines

tools/helpers/init-dom0less.c static int init_domain(struct xs_handle *xsh, · line 315

Quoted 6 lines
tools/helpers/init-dom0less.c +3 -2
     rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn, xenstore_evtchn);
-    if (!rc)
-        err(1, "xs_introduce_domain");
+    if (!rc) {
+        printf("Failed to introduce a domain\n");
+        return 1;

nit: Maybe -EBUSY so it's -errno like the others?

There are other places in this script where we return 1.

~Michal

#3 lore raw
Quoted 11 lines · Michal
Quoted 8 lines · Alejandro Vallejo
Quoted 7 lines · Michal Orzel

Current use of err() has the following issues:
- without setting errno, on error it results in printing e.g.:
"init-dom0less: writing to xenstore: Success"
This is very misleading and difficult to deduct that there was a failure.
- does not propagate error codes to the caller.
- skips "init_domain failed" message by exiting early.

Maybe add another bullet:
- The early exit prevents setting up any remaining domains.

That was my main motivation in my attempt at this change: https://lore.kernel.org/xen-devel/[email protected]/.

Your re-written error messages are better though.

Quoted 27 lines
Quoted 27 lines
Quoted 3 lines

Replace err() with more informative messages propagating rc when possible.

Sounds good to me. Only suggestion I'd make is to also print relevant arguments where needed, like...

Quoted 19 lines
---
  tools/helpers/init-dom0less.c | 25 +++++++++++++++++--------
  1 file changed, 17 insertions(+), 8 deletions(-)
tools/helpers/init-dom0less.c +4 -2
index a182dce56353..3dd2d74886eb 100644
 
+    }
 
      rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn, xenstore_evtchn);
-    if (!rc)
-        err(1, "xs_introduce_domain");
+    if (!rc) {
+        printf("Failed to introduce a domain\n");
+        return 1;
Quoted 2 lines
Quoted 1 line

nit: Maybe -EBUSY so it's -errno like the others?

There are other places in this script where we return 1.

It's a mix of error as 1 or -errno, but at least success == 0 is consistent.

The xs_* functions set errno, so maybe here it would be good to return -errno. I think moving toward -errno, which is more informative, would be an improvement.

Thanks,
Jason