Skip to contentSkip to conversation

tools/libxc: fix errno handling for HVM in xc_domain_save

PATCH In review Olaf Hering 4 participants 6 messages Mar 13, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxc: fix errno handling for HVM in xc_domain_save

The previous patch ("tools/libxc: pass errno to callers of xc_domain_save") did not jump to the proper label if the domU is HVM.

Also make it clearer what "out" and "out_rc" are supposed to mean:
label "out" is for failure case, it expects errno to be set. label "out_rc" is for success case, it preserves the initial errno for the caller.

---
 tools/libxc/xc_domain_save.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/libxc/xc_domain_save.c +4 -4
index 9f96bb7..5a50c5c 100644
@@ -1837,7 +1837,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
         
         /* HVM guests are done now */
         errno = 0;
-        goto out;
+        goto out_rc;
     }
 
     /* PV guests only from now on */
@@ -2037,13 +2037,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
     }
 
     /* Success! */
-    rc = errno = 0;
+    errno = 0;
     goto out_rc;
 
  out:
-    rc = errno;
-    assert(rc);
+    assert(errno);
  out_rc:
+    rc = errno;
     completed = 1;
 
     if ( !rc && callbacks->postcopy )
#1 lore raw
Quoted 7 lines · Olaf Hering

The previous patch ("tools/libxc: pass errno to callers of xc_domain_save") did not jump to the proper label if the domU is HVM.

Also make it clearer what "out" and "out_rc" are supposed to mean:
label "out" is for failure case, it expects errno to be set. label "out_rc" is for success case, it preserves the initial errno for the caller.

I wish you hadn't done this bit, since now I can't just throw the fix in as I need to think about it harder, the changes are certainly non-obvious.

Quoted 41 lines
---
 tools/libxc/xc_domain_save.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/libxc/xc_domain_save.c +4 -4
index 9f96bb7..5a50c5c 100644
@@ -1837,7 +1837,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
 
         /* HVM guests are done now */
         errno = 0;
-        goto out;
+        goto out_rc;
     }
 
     /* PV guests only from now on */
@@ -2037,13 +2037,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
     }
 
     /* Success! */
-    rc = errno = 0;
+    errno = 0;
     goto out_rc;
 
  out:
-    rc = errno;
-    assert(rc);
+    assert(errno);
  out_rc:
+    rc = errno;
     completed = 1;
 
     if ( !rc && callbacks->postcopy )

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Olaf Hering
Quoted 7 lines · Olaf Hering

The previous patch ("tools/libxc: pass errno to callers of xc_domain_save") did not jump to the proper label if the domU is HVM.

Also make it clearer what "out" and "out_rc" are supposed to mean:
label "out" is for failure case, it expects errno to be set. label "out_rc" is for success case, it preserves the initial errno for the caller.

Surely "out_rc" should be renamed to "success" then?

~Andrew

Quoted 41 lines
---
 tools/libxc/xc_domain_save.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/libxc/xc_domain_save.c +4 -4
index 9f96bb7..5a50c5c 100644
@@ -1837,7 +1837,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
 
         /* HVM guests are done now */
         errno = 0;
-        goto out;
+        goto out_rc;
     }
 
     /* PV guests only from now on */
@@ -2037,13 +2037,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
     }
 
     /* Success! */
-    rc = errno = 0;
+    errno = 0;
     goto out_rc;
 
  out:
-    rc = errno;
-    assert(rc);
+    assert(errno);
  out_rc:
+    rc = errno;
     completed = 1;
 
     if ( !rc && callbacks->postcopy )

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
In reply to Olaf Hering

Olaf Hering writes ("[PATCH] tools/libxc: fix errno handling for HVM in xc_domain_save"):

Quoted 7 lines

The previous patch ("tools/libxc: pass errno to callers of xc_domain_save") did not jump to the proper label if the domU is HVM.

Also make it clearer what "out" and "out_rc" are supposed to mean:
label "out" is for failure case, it expects errno to be set. label "out_rc" is for success case, it preserves the initial errno for the caller.

I agree with Ian that this is very confusing. How about this instead ?

tools/libxc/xc_domain_save.c +2 -2
index 9f96bb7..71f9b59 100644
@@ -1836,8 +1836,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
         }
         
         /* HVM guests are done now */
-        errno = 0;
-        goto out;
+        goto success;
     }
 
     /* PV guests only from now on */
@@ -2037,6 +2036,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
     }
 
     /* Success! */
+ success:
     rc = errno = 0;
     goto out_rc;
#4 lore raw
Quoted 10 lines · Ian Jackson

Olaf Hering writes ("[PATCH] tools/libxc: fix errno handling for HVM in xc_domain_save"):

Quoted 7 lines

The previous patch ("tools/libxc: pass errno to callers of xc_domain_save") did not jump to the proper label if the domU is HVM.

Also make it clearer what "out" and "out_rc" are supposed to mean:
label "out" is for failure case, it expects errno to be set. label "out_rc" is for success case, it preserves the initial errno for the caller.

I agree with Ian that this is very confusing. How about this instead ?

That would fix the current bug, yes.

Olaf

Reviewed-by Olaf Hering
#5 lore raw

Olaf Hering writes ("Re: [PATCH] tools/libxc: fix errno handling for HVM in xc_domain_save"):

Quoted 4 lines · Ian Jackson
Quoted 1 line

I agree with Ian that this is very confusing. How about this instead ?

That would fix the current bug, yes.

Thanks for the review. I have pushed this, in the form below.

Ian.

commit 29f0712bc008a9d6e611785424f797cfc185c1d3

Author: Ian Jackson <[email protected]>
Date:   Thu Mar 13 17:59:49 2014 +0000

tools/libxc: fix errno handling for HVM in xc_domain_save

The previous patch (dda0b77d "tools/libxc: pass errno to callers of xc_domain_save") did not jump to the proper label if the domU is HVM.

tools/libxc/xc_domain_save.c +2 -2
index 9f96bb7..71f9b59 100644
@@ -1836,8 +1836,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
         }
         
         /* HVM guests are done now */
-        errno = 0;
-        goto out;
+        goto success;
     }
 
     /* PV guests only from now on */
@@ -2037,6 +2036,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
     }
 
     /* Success! */
+ success:
     rc = errno = 0;
     goto out_rc;