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

[Xen-devel] [PATCH 01/12] libxc/save: Shrink code volume where possible



A property of how the error handling (0 on success, nonzero otherwise)
allows these calls to be chained together with the ternary operatior.

No functional change, but far less boilerplate code.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Ian Jackson <Ian.Jackson@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
---
 tools/libxc/xc_sr_save.c         |  7 ++---
 tools/libxc/xc_sr_save_x86_hvm.c | 21 +++------------
 tools/libxc/xc_sr_save_x86_pv.c  | 58 ++++++++--------------------------------
 3 files changed, 16 insertions(+), 70 deletions(-)

diff --git a/tools/libxc/xc_sr_save.c b/tools/libxc/xc_sr_save.c
index f89e12c99f..9764aa743f 100644
--- a/tools/libxc/xc_sr_save.c
+++ b/tools/libxc/xc_sr_save.c
@@ -845,11 +845,8 @@ static int save(struct xc_sr_context *ctx, uint16_t 
guest_type)
 
     xc_report_progress_single(xch, "Start of stream");
 
-    rc = write_headers(ctx, guest_type);
-    if ( rc )
-        goto err;
-
-    rc = ctx->save.ops.start_of_stream(ctx);
+    rc = (write_headers(ctx, guest_type) ?:
+          ctx->save.ops.start_of_stream(ctx));
     if ( rc )
         goto err;
 
diff --git a/tools/libxc/xc_sr_save_x86_hvm.c b/tools/libxc/xc_sr_save_x86_hvm.c
index 3d86cb0600..d925a81999 100644
--- a/tools/libxc/xc_sr_save_x86_hvm.c
+++ b/tools/libxc/xc_sr_save_x86_hvm.c
@@ -187,24 +187,9 @@ static int x86_hvm_check_vm_state(struct xc_sr_context 
*ctx)
 
 static int x86_hvm_end_of_checkpoint(struct xc_sr_context *ctx)
 {
-    int rc;
-
-    /* Write the TSC record. */
-    rc = write_x86_tsc_info(ctx);
-    if ( rc )
-        return rc;
-
-    /* Write the HVM_CONTEXT record. */
-    rc = write_hvm_context(ctx);
-    if ( rc )
-        return rc;
-
-    /* Write HVM_PARAMS record contains applicable HVM params. */
-    rc = write_hvm_params(ctx);
-    if ( rc )
-        return rc;
-
-    return 0;
+    return (write_x86_tsc_info(ctx) ?:
+            write_hvm_context(ctx) ?:
+            write_hvm_params(ctx));
 }
 
 static int x86_hvm_cleanup(struct xc_sr_context *ctx)
diff --git a/tools/libxc/xc_sr_save_x86_pv.c b/tools/libxc/xc_sr_save_x86_pv.c
index 3ebc5a2bf8..94d0f68911 100644
--- a/tools/libxc/xc_sr_save_x86_pv.c
+++ b/tools/libxc/xc_sr_save_x86_pv.c
@@ -768,19 +768,10 @@ static int write_all_vcpu_information(struct 
xc_sr_context *ctx)
         if ( !vinfo.online )
             continue;
 
-        rc = write_one_vcpu_basic(ctx, i);
-        if ( rc )
-            return rc;
-
-        rc = write_one_vcpu_extended(ctx, i);
-        if ( rc )
-            return rc;
-
-        rc = write_one_vcpu_xsave(ctx, i);
-        if ( rc )
-            return rc;
-
-        rc = write_one_vcpu_msrs(ctx, i);
+        rc = (write_one_vcpu_basic(ctx, i) ?:
+              write_one_vcpu_extended(ctx, i) ?:
+              write_one_vcpu_xsave(ctx, i) ?:
+              write_one_vcpu_msrs(ctx, i));
         if ( rc )
             return rc;
     }
@@ -1031,25 +1022,10 @@ static int x86_pv_normalise_page(struct xc_sr_context 
*ctx, xen_pfn_t type,
  */
 static int x86_pv_setup(struct xc_sr_context *ctx)
 {
-    int rc;
-
-    rc = x86_pv_domain_info(ctx);
-    if ( rc )
-        return rc;
-
-    rc = x86_pv_map_m2p(ctx);
-    if ( rc )
-        return rc;
-
-    rc = map_shinfo(ctx);
-    if ( rc )
-        return rc;
-
-    rc = map_p2m(ctx);
-    if ( rc )
-        return rc;
-
-    return 0;
+    return (x86_pv_domain_info(ctx) ?:
+            x86_pv_map_m2p(ctx) ?:
+            map_shinfo(ctx) ?:
+            map_p2m(ctx));
 }
 
 static int x86_pv_start_of_stream(struct xc_sr_context *ctx)
@@ -1080,21 +1056,9 @@ static int x86_pv_start_of_checkpoint(struct 
xc_sr_context *ctx)
 
 static int x86_pv_end_of_checkpoint(struct xc_sr_context *ctx)
 {
-    int rc;
-
-    rc = write_x86_tsc_info(ctx);
-    if ( rc )
-        return rc;
-
-    rc = write_shared_info(ctx);
-    if ( rc )
-        return rc;
-
-    rc = write_all_vcpu_information(ctx);
-    if ( rc )
-        return rc;
-
-    return 0;
+    return (write_x86_tsc_info(ctx) ?:
+            write_shared_info(ctx) ?:
+            write_all_vcpu_information(ctx));
 }
 
 static int x86_pv_check_vm_state(struct xc_sr_context *ctx)
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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