btrfs-progs: rework get_fs_info to remove side effects
authorEric Sandeen <sandeen@redhat.com>
Tue, 12 Mar 2013 04:17:40 +0000 (23:17 -0500)
committerDavid Sterba <dsterba@suse.cz>
Tue, 12 Mar 2013 16:07:40 +0000 (17:07 +0100)
commit7a355379ea93856cd90d01216dde8610a225b8aa
tree6e811da01801db856d10c9644de41ad9f3d0ece3
parent120fdfafa325777c2326229d6a8393ba5ed1914f
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>
cmds-device.c
cmds-replace.c
cmds-scrub.c
utils.c
utils.h