btrfs-progs: don't use closed fd

In the case that btrfs scrub cancel is given a device name,
we close the file handle, and then pass it to check_mounted_where()
which eventually preads from that (now closed) fd.  Fix the logic
so that we close & re-open the discovered mountpoint properly.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Zach Brown <zab@redhat.com>
master
Eric Sandeen 2013-01-24 18:18:50 -06:00 committed by Zach Brown
parent 6bd3a02fa6
commit a2eec48a8e
1 changed files with 5 additions and 3 deletions

View File

@ -1457,14 +1457,14 @@ static int cmd_scrub_cancel(int argc, char **argv)
again:
ret = ioctl(fdmnt, BTRFS_IOC_SCRUB_CANCEL, NULL);
err = errno;
close(fdmnt);
if (ret && err == EINVAL) {
/* path is no mounted btrfs. try 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),
&fs_devices_mnt);
close(fdmnt);
if (ret) {
/* It is a device; open the mountpoint. */
close(fdmnt);
fdmnt = open_file_or_dir(mp);
if (fdmnt >= 0) {
path = mp;
@ -1473,6 +1473,8 @@ again:
}
}
close(fdmnt);
if (ret) {
fprintf(stderr, "ERROR: scrub cancel failed on %s: %s\n", path,
err == ENOTCONN ? "not running" : strerror(errno));