diff options
author | Eric Sandeen <sandeen@redhat.com> | 2013-03-11 23:17:40 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2013-03-12 17:07:40 +0100 |
commit | 7a355379ea93856cd90d01216dde8610a225b8aa (patch) | |
tree | 6e811da01801db856d10c9644de41ad9f3d0ece3 /cmds-device.c | |
parent | 120fdfafa325777c2326229d6a8393ba5ed1914f (diff) |
btrfs-progs: rework get_fs_info to remove side effects
get_fs_info() has been silently switching from a device to a mounted
path as needed; the caller's filehandle was unexpectedly closed &
reopened outside the caller's scope. Not so great.
The callers do want "fdmnt" to be the filehandle for the mount point
in all cases, though - the various ioctls act on this (not on an fd
for the device). But switching it in the local scope of get_fs_info
is incorrect; it just so happens that *usually* the fd number is
unchanged.
So - use the new helpers to detect when an argument is a block
device, and open the the mounted path more obviously / explicitly
for ioctl use, storing the filehandle in fdmnt.
Then, in get_fs_info, ignore the fd completely, and use the path on
the argument to determine if the caller wanted to act on just that
device, or on all devices for the filesystem.
Affects those commands which are documented to accept either
a block device or a path:
* btrfs device stats
* btrfs replace start
* btrfs scrub start
* btrfs scrub status
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Diffstat (limited to 'cmds-device.c')
-rw-r--r-- | cmds-device.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/cmds-device.c b/cmds-device.c index 58df6da6..41e79d37 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -321,13 +321,14 @@ static int cmd_dev_stats(int argc, char **argv) path = argv[optind]; - fdmnt = open_file_or_dir(path); + fdmnt = open_path_or_dev_mnt(path); + if (fdmnt < 0) { fprintf(stderr, "ERROR: can't access '%s'\n", path); return 12; } - ret = get_fs_info(fdmnt, path, &fi_args, &di_args); + ret = get_fs_info(path, &fi_args, &di_args); if (ret) { fprintf(stderr, "ERROR: getting dev info for devstats failed: " "%s\n", strerror(-ret)); |