daemon: drop error message check in do_part_expand_gpt

part-expand-gpt takes extreme cautions and doesn't proceed to writing
to the disk if the preliminary dry run of sgdisk has generated any
warnings on stdout.

This blocks the use of part-expand-gpt on disk shrink (with disk
resize being the main usecase for part-expand-gpt), because sgdisk dry
run produces a warning in that case.

So remove the excessive safety check, and leave it up to the caller.

Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
This commit is contained in:
Denis Plotnikov
2019-04-15 14:06:29 +03:00
committed by Richard W.M. Jones
parent 3b2d83d470
commit 4cfc071a84
2 changed files with 22 additions and 22 deletions

View File

@@ -699,26 +699,8 @@ do_part_expand_gpt(const char *device)
{
CLEANUP_FREE char *err = NULL;
/* If something is broken, sgdisk may try to correct it.
* (e.g. recreate partition table and so on).
* We do not want such behavior, so dry-run at first.*/
int r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
"sgdisk", "--pretend", "-e", device, NULL);
if (r == -1) {
reply_with_error ("%s --pretend -e %s: %s", "sgdisk", device, err);
return -1;
}
if (err && strlen(err) != 0) {
/* Unexpected actions. */
reply_with_error ("%s --pretend -e %s: %s", "sgdisk", device, err);
return -1;
}
free(err);
/* Now we can do a real run. */
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
"sgdisk", "-e", device, NULL);
"sgdisk", "-e", device, NULL);
if (r == -1) {
reply_with_error ("%s -e %s: %s", "sgdisk", device, err);

View File

@@ -54,11 +54,29 @@ sub tests {
my $end_sectors = 100 * 1024 * 2 - $output;
die unless $end_sectors <= 34;
# Negative tests.
# Negative test.
eval { $g->part_expand_gpt ("/dev/sdb") };
die unless $@;
eval { $g->part_expand_gpt ("/dev/sda1") };
die unless $@;
$g->close ();
# Disk shrink test
die if system ("qemu-img resize --shrink disk_gpt.img 50M &>/dev/null");
$g = Sys::Guestfs->new ();
$g->add_drive ("disk_gpt.img", format => "qcow2");
$g->launch ();
die if $g->part_expand_gpt ("/dev/sda");
my $output = $g->debug ("sh", ["sgdisk", "-p", "/dev/sda"]);
die if $output eq "";
$output =~ s/\n/ /g;
$output =~ s/.*last usable sector is (\d+).*/$1/g;
my $end_sectors = 50 * 1024 * 2 - $output;
die unless $end_sectors <= 34;
}
eval { tests() };