summaryrefslogtreecommitdiff
path: root/cmds-scrub.c
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2013-01-24 18:18:50 -0600
committerZach Brown <zab@redhat.com>2013-02-05 16:09:41 -0800
commita2eec48a8e863e34715cb111b5f578e58d728b7c (patch)
tree8aa5d2f0aaa4a313aec0d8ed3efb02d63d5d6c7d /cmds-scrub.c
parent6bd3a02fa67369c8a53c1b457e72c7330cfef3af (diff)
downloadbtrfs-progs-a2eec48a8e863e34715cb111b5f578e58d728b7c.tar.gz
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>
Diffstat (limited to 'cmds-scrub.c')
-rw-r--r--cmds-scrub.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/cmds-scrub.c b/cmds-scrub.c
index 31ace6d..b984e96 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -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));