mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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.
This commit is contained in:
14
align/scan.c
14
align/scan.c
@@ -282,11 +282,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 = NULL;
|
||||
|
||||
CLEANUP_FREE_PARTITION_LIST struct guestfs_partition_list *parts =
|
||||
guestfs_part_list (g, devices[i]);
|
||||
if (parts == NULL)
|
||||
return -1;
|
||||
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]);
|
||||
|
||||
@@ -356,7 +356,7 @@ print_partition_table (const char *device,
|
||||
int r;
|
||||
|
||||
if (PARTED_OPT_HAS_M == 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
|
||||
@@ -364,9 +364,15 @@ print_partition_table (const char *device,
|
||||
"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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user