Commit Graph

19 Commits (84a42b7c7145dcd3e7404e5a8180b1c5ddca530e)

Author SHA1 Message Date
Eric Sandeen 7a355379ea 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>
2013-03-12 17:07:40 +01:00
Eric Sandeen 120fdfafa3 btrfs-progs: don't open-code mountpoint discovery in scrub cancel
cmd_scrub_cancel had its own mountpoint discovery routine;
just use open_path_or_dev_mnt() for that now.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-12 16:48:10 +01:00
Eric Sandeen c3d5897555 btrfs-progs: fix scrub error return from pthread_mutex_lock
If pthread_mutex_lock() fails it returns the error in ret,
and does not set errno.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:06:37 +01:00
Eric Sandeen b79d4a217f btrfs-progs: Error handling in scrub_progress_cycle() thread
consolidate error handling to ensure that peer_fd
is closed on error paths.  Add a couple comments
to the error handling after the thread is complete.

Note that scrub_progress_cycle returns negative
errnos on any error.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:06:37 +01:00
Eric Sandeen 7b81119b1d btrfs-progs: Issue warnings if ioctls fail in sigint handlers
The two sigint handlers issue ioctls to clean up, but if
they fail, noone would know.  I'm not sure there is
any other error handling to be done at this point, but a
notification seems wise.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:06:37 +01:00
Eric Sandeen d310e9cfff 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>
2013-02-27 14:39:39 +01:00
Eric Sandeen 5eaeb577b5 btrfs-progs: fix close of error fd in scrub cancel
If we retry opening the mountpoint and fail, we'll call
close on a filehandle w/ value -1.  Rearrange so the
retry uses the same open and same error handling.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:37 +01:00
Eric Sandeen a2eec48a8e 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>
2013-02-05 16:09:41 -08:00
Eric Sandeen 6bd3a02fa6 btrfs-progs: don't double-close prg_fd
If scrub start discovers that scrub is already running,
we need to set prg_fd to -1 before goto out, or we'll
try to close it again in the error path.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:41 -08:00
Zach Brown f4dc05bf76 btrfs-progs: scrub can leak fd 0
< 0 is returned for errors opening the file, this code could leak fd 0.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -08:00
Zach Brown cb4c601a4e btrfs-progs: fix scrub socket leak
If connection fails the socket is leaked when the status file is used
instead.  Close it to trivially cut down on fd use and to bring down the
noise in static code analysis.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -08:00
Stefan Behrens 7a69dc4eec Btrfs-progs: make two utility functions globally available
Two convenient utility functions that have so far been local to scrub are
moved to utils.c.
They will be used in the device stats code in a following commit.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-30 00:40:35 +01:00
Arne Jansen 133e4520ea Btrfs-progs: bugfix for scrubbing single devices
Scrub can be invoked to scrub only a single device of a (mounted) filesystem.
The code determines whether the given path is a mountpoint of a filesystem
by issueing a btrfs-specific ioctl to it. Only in case of EINVAL it assumed
it may be a device, all other errnos just caused it fail, but some devices
(correctly) return ENOTTY. This patch adds this to the error check.

Signed-off-by: Arne Jansen <sensille@gmx.net>
2013-01-18 18:26:27 +01:00
Lluis Batlle i Rossell bb0eabc383 btrfs-progs: Fix getopt on arm platforms
There, 'char' is unsigned, so once assigned '-1' from getopt, it gets
the value 255. Then, it compared to '-1' gives false.

Signed-off-by: Lluis Batlle i Rossell <viric@viric.name>
2013-01-17 18:27:56 +01:00
Wade Cline 0d5cfddc2c Btrfs-progs: Fix compiler warnings on PPC64
The kernel uses unsigned long long for u64, but PPC64 uses unsigned
long by default. This results in compilation warnings such as:

print-tree.c:333: warning: format '%llu' expects type 'long long
unsigned int', but argument 4 has type 'u64'

To fix this, the macro __KERNEL__ needs to be defined before including
the file <asm/types.h>. This can be done by defining the macro in
"kerncompat.h" and making it the first included file in the relevant
header files; this fixes the compiler warnings on PPC64.

Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Wade Cline <clinew@linux.vnet.ibm.com>
2013-01-17 18:12:57 +01:00
Goffredo Baroncelli 5ef69ff8ec scrub_fs_info( ) file handle leaking
The function scrub_fs_info( ) closes and reopen a file handle
passed as argument, when a caller uses the file handle even after the
call.
The function scrub_fs_info( ) is updated to remove the file handle
argument, and instead uses a private own file handle.
The callers are updated to not pass the argument.
2012-07-03 16:27:46 -04:00
Ilya Dryomov 08b51bd731 Btrfs-progs: allow multi-line command group synopsis
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-08 18:55:51 +02:00
Ilya Dryomov d675085a67 Btrfs-progs: switch all existing commands to a new parser
The new infrastructure offloads checking number of arguments passed to a
command to individual command handlers.  Fix them up accordingly.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:00:17 +02:00
Ilya Dryomov 4f26833193 Btrfs-progs: rearrange files in the repo
Separate every command group into its own file (cmds_<group>.c) and
rearrange includes.  Remove btrfs_cmds.c.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:00:17 +02:00