[Pkg-libvirt-commits] [libguestfs] 17/26: daemon: parted: Always use -s option even with -m.

Hilko Bengen bengen at moszumanska.debian.org
Sun Nov 1 17:11:29 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag upstream/1.28.12
in repository libguestfs.

commit 0c8bd4e114a1e394a2b6e57fc1a1f0610874b334
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Jun 17 10:51:40 2015 +0100

    daemon: parted: Always use -s option even with -m.
    
    See: https://bugzilla.redhat.com/show_bug.cgi?id=1232241#c3
    
    However adding the -s parameter changes the error code returned by
    parted when it processes a blank disk (or other unrecognized partition
    table).  Without -s it prints an error but returns a non-error exit
    code (0).  With -s it prints an error and returns an error exit code.
    
    Because it's useful to be able to catch this case in user code, turn
    "unrecognised disk label" into EINVAL.
    
    Change virt-alignment-scan to catch this error and ignore it.
    
    (cherry picked from commit b467afb621b054e4c1e9a2f1e8814e91a395ffb7)
---
 align/scan.c    | 16 +++++++++++-----
 daemon/parted.c | 14 ++++++++++----
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/align/scan.c b/align/scan.c
index 4740581..fd0dc39 100644
--- a/align/scan.c
+++ b/align/scan.c
@@ -279,11 +279,17 @@ scan (guestfs_h *g, const char *prefix, FILE *fp)
 
   for (i = 0; devices[i] != NULL; ++i) {
     CLEANUP_FREE char *name = NULL;
-
-    CLEANUP_FREE_PARTITION_LIST struct guestfs_partition_list *parts =
-      guestfs_part_list (g, devices[i]);
-    if (parts == NULL)
-      return -1;
+    CLEANUP_FREE_PARTITION_LIST struct guestfs_partition_list *parts = NULL;
+
+    guestfs_push_error_handler (g, NULL, NULL);
+    parts = guestfs_part_list (g, devices[i]);
+    guestfs_pop_error_handler (g);
+    if (parts == NULL) {
+      if (guestfs_last_errno (g) == EINVAL) /* unrecognised disk label */
+        continue;
+      else
+        return -1;
+    }
 
     /* Canonicalize the name of the device for printing. */
     name = guestfs_canonical_device_name (g, devices[i]);
diff --git a/daemon/parted.c b/daemon/parted.c
index 80637fa..f73e3e9 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -348,7 +348,7 @@ print_partition_table (const char *device, int parted_has_m_opt)
   int r;
 
   if (parted_has_m_opt)
-    r = command (&out, &err, str_parted, "-m", "--", device,
+    r = command (&out, &err, str_parted, "-m", "-s", "--", device,
                  "unit", "b",
                  "print", NULL);
   else
@@ -356,9 +356,15 @@ print_partition_table (const char *device, int parted_has_m_opt)
                  "unit", "b",
                  "print", NULL);
   if (r == -1) {
-    reply_with_error ("parted print: %s: %s", device,
-                      /* Hack for parted 1.x which sends errors to stdout. */
-                      *err ? err : out);
+    /* Hack for parted 1.x which sends errors to stdout. */
+    const char *msg = *err ? err : out;
+    int errcode = 0;
+
+    /* Translate "unrecognised disk label" into an errno code. */
+    if (msg && strstr (msg, "unrecognised disk label") != NULL)
+      errcode = EINVAL;
+
+    reply_with_error_errno (errcode, "parted print: %s: %s", device, msg);
     free (out);
     return NULL;
   }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list