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:
Richard W.M. Jones
2015-06-17 10:51:40 +01:00
parent 3ae5f72743
commit b467afb621
2 changed files with 20 additions and 8 deletions

View File

@@ -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]);

View File

@@ -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;
}