btrfs-progs: more scrub cancel error handling

If we request scrub cancel on an unmounted or
non-btrfs device, we still get a "scrub canceled"
success message:

# btrfs scrub cancel /dev/loop1
scrub cancelled
# blkid /dev/loop1
/dev/loop1: UUID="7f586941-1d5e-4ba7-9caa-b35934849957" TYPE="xfs"

Fix this so that if check_mounted_where returns 0
we don't report success.

While we're at it, use perror to report the reason for an open
failure, if we get one.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
This commit is contained in:
Eric Sandeen 2013-02-25 16:54:41 -06:00 committed by David Sterba
parent 5eaeb577b5
commit d310e9cfff

View file

@ -1451,7 +1451,7 @@ static int cmd_scrub_cancel(int argc, char **argv)
again: again:
fdmnt = open_file_or_dir(path); fdmnt = open_file_or_dir(path);
if (fdmnt < 0) { if (fdmnt < 0) {
fprintf(stderr, "ERROR: scrub cancel failed\n"); perror("ERROR: scrub cancel failed:");
return 1; return 1;
} }
@ -1462,11 +1462,18 @@ again:
/* path is not a btrfs mount point. See if it's a device. */ /* path is not a btrfs mount point. See if it's a device. */
ret = check_mounted_where(fdmnt, path, mp, sizeof(mp), ret = check_mounted_where(fdmnt, path, mp, sizeof(mp),
&fs_devices_mnt); &fs_devices_mnt);
if (ret) { if (ret > 0) {
/* It is a device; try again with the mountpoint. */ /* It's a mounted btrfs device; retry w/ mountpoint. */
close(fdmnt); close(fdmnt);
path = mp; path = mp;
goto again; goto again;
} else {
/* It's not a mounted btrfs device either */
fprintf(stderr,
"ERROR: %s is not a mounted btrfs device\n",
path);
ret = 1;
err = EINVAL;
} }
} }
@ -1474,7 +1481,7 @@ again:
if (ret) { if (ret) {
fprintf(stderr, "ERROR: scrub cancel failed on %s: %s\n", path, fprintf(stderr, "ERROR: scrub cancel failed on %s: %s\n", path,
err == ENOTCONN ? "not running" : strerror(errno)); err == ENOTCONN ? "not running" : strerror(err));
return 1; return 1;
} }