Skip to contentSkip to conversation

libxl: fix libxl__build_hvm error code return path

PATCH In review Wei Liu 3 participants 4 messages Aug 13, 2015

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH v3 1/1 libxl: fix libxl__build_hvm error code return path

In 25652f23 ("tools/libxl: detect and avoid conflicts with RDM"), new code was added to use rc to store libxl function call return value, which complied to libxl coding style. That patch, however, didn't change other locations where return value was stored in ret. In the end libxl__build_hvm could return 0 when it failed.

Change all assignments to ret to assignment to rc and abolish ret.

---
v3: store return value for libxl__domain_firmware in rc, too.

---
 tools/libxl/libxl_dom.c | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)
tools/libxl/libxl_dom.c +25 -22
index e1f11a3..1e5bb0b 100644
@@ -912,7 +912,7 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     struct xc_hvm_build_args args = {};
-    int ret, rc = ERROR_FAIL;
+    int rc;
     uint64_t mmio_start, lowmem_end, highmem_end;
     libxl_domain_build_info *const info = &d_config->b_info;
 
@@ -932,10 +932,13 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
         if (max_ram_below_4g < HVM_BELOW_4G_MMIO_START)
             args.mmio_size = info->u.hvm.mmio_hole_memkb << 10;
     }
-    if (libxl__domain_firmware(gc, info, &args)) {
+
+    rc = libxl__domain_firmware(gc, info, &args);
+    if (rc) {
         LOG(ERROR, "initializing domain firmware failed");
         goto out;
     }
+
     if (args.mem_target == 0)
         args.mem_target = args.mem_size;
     if (args.mmio_size == 0)
@@ -963,15 +966,15 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
     if (info->num_vnuma_nodes != 0) {
         int i;
 
-        ret = libxl__vnuma_build_vmemrange_hvm(gc, domid, info, state, &args);
-        if (ret) {
-            LOGEV(ERROR, ret, "hvm build vmemranges failed");
+        rc = libxl__vnuma_build_vmemrange_hvm(gc, domid, info, state, &args);
+        if (rc) {
+            LOGEV(ERROR, rc, "hvm build vmemranges failed");
             goto out;
         }
-        ret = libxl__vnuma_config_check(gc, info, state);
-        if (ret) goto out;
-        ret = set_vnuma_info(gc, domid, info, state);
-        if (ret) goto out;
+        rc = libxl__vnuma_config_check(gc, info, state);
+        if (rc) goto out;
+        rc = set_vnuma_info(gc, domid, info, state);
+        if (rc) goto out;
 
         args.nr_vmemranges = state->num_vmemranges;
         args.vmemranges = libxl__malloc(gc, sizeof(*args.vmemranges) *
@@ -991,9 +994,9 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
             args.vnode_to_pnode[i] = info->vnuma_nodes[i].pnode;
     }
 
-    ret = xc_hvm_build(ctx->xch, domid, &args);
-    if (ret) {
-        LOGEV(ERROR, ret, "hvm building failed");
+    rc = xc_hvm_build(ctx->xch, domid, &args);
+    if (rc) {
+        LOGEV(ERROR, rc, "hvm building failed");
         goto out;
     }
 
@@ -1002,22 +1005,22 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
         goto out;
     }
 
-    ret = hvm_build_set_params(ctx->xch, domid, info, state->store_port,
-                               &state->store_mfn, state->console_port,
-                               &state->console_mfn, state->store_domid,
-                               state->console_domid);
-    if (ret) {
-        LOGEV(ERROR, ret, "hvm build set params failed");
+    rc = hvm_build_set_params(ctx->xch, domid, info, state->store_port,
+                              &state->store_mfn, state->console_port,
+                              &state->console_mfn, state->store_domid,
+                              state->console_domid);
+    if (rc) {
+        LOGEV(ERROR, rc, "hvm build set params failed");
         goto out;
     }
 
-    ret = hvm_build_set_xs_values(gc, domid, &args);
-    if (ret) {
-        LOG(ERROR, "hvm build set xenstore values failed (ret=%d)", ret);
+    rc = hvm_build_set_xs_values(gc, domid, &args);
+    if (rc) {
+        LOG(ERROR, "hvm build set xenstore values failed (rc=%d)", rc);
         goto out;
     }
 
-    return 0;
+    rc = 0;
 out:
     return rc;
 }
Signature · 1 line
2.1.4
#1 lore raw

tools/libxl/libxl_dom.c int libxl__build_hvm(libxl__gc *gc, uint32_t · line 1006

Quoted 6 lines · Wei Liu
tools/libxl/libxl_dom.c +0 -1
@@ -1002,22 +1005,22 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t
 domid,
         goto out;
     }
 
-    ret = hvm_build_set_params(ctx->xch, domid, info, state->store_port,

At least this one doesn't return ERROR_*, it returns 0 or -1, assigning such to rc is wrong and ultimately returning it from this function even worse.

Remind me why we aren't just taking Roger's original patch from < [email protected]> ? It seems we are basically iterating towards it...

Quoted 29 lines
tools/libxl/libxl_dom.c +10 -9
-                               &state->store_mfn, state->console_port,
-                               &state->console_mfn, state->store_domid,
-                               state->console_domid);
-    if (ret) {
-        LOGEV(ERROR, ret, "hvm build set params failed");
+    rc = hvm_build_set_params(ctx->xch, domid, info, state->store_port,
+                              &state->store_mfn, state->console_port,
+                              &state->console_mfn, state->store_domid,
+                              state->console_domid);
+    if (rc) {
+        LOGEV(ERROR, rc, "hvm build set params failed");
         goto out;
     }
 
-    ret = hvm_build_set_xs_values(gc, domid, &args);
-    if (ret) {
-        LOG(ERROR, "hvm build set xenstore values failed (ret=%d)", 
 ret);
+    rc = hvm_build_set_xs_values(gc, domid, &args);
+    if (rc) {
+        LOG(ERROR, "hvm build set xenstore values failed (rc=%d)", rc);
         goto out;
     }
 
-    return 0;
+    rc = 0;
 out:
     return rc;

}

author
#2 lore raw
Quoted 12 lines · Ian Campbell

tools/libxl/libxl_dom.c int libxl__build_hvm(libxl__gc *gc, uint32_t · line 1006

Quoted 6 lines · Wei Liu
tools/libxl/libxl_dom.c +0 -1
@@ -1002,22 +1005,22 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t
 domid,
         goto out;
     }
 
-    ret = hvm_build_set_params(ctx->xch, domid, info, state->store_port,

At least this one doesn't return ERROR_*, it returns 0 or -1, assigning such to rc is wrong and ultimately returning it from this function even worse.

Quoted 4 lines

Remind me why we aren't just taking Roger's original patch from < [email protected]> ? It seems we are basically iterating towards it...

Maybe we should just take that patch, that would save me from doing another round.

Wei.

#3 lore raw

Wei Liu writes ("Re: [PATCH for-4.6 v3] libxl: fix libxl__build_hvm error code return path"):

Quoted 2 lines

Maybe we should just take that patch, that would save me from doing another round.

I agree.

Ian.