summaryrefslogtreecommitdiff
path: root/cmds-scrub.c
Commit message (Collapse)AuthorAge
* btrfs-progs: treewide: Replace strerror(errno) with %m.Rosen Penev2018-01-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As btrfs is specific to Linux, %m can be used instead of strerror(errno) in format strings. This has some size reduction benefits for embedded systems. glibc, musl, and uclibc-ng all support %m as a modifier to printf. A quick glance at the BIONIC libc source indicates that it has support for %m as well. BSDs and Windows do not but I do believe them to be beyond the scope of btrfs-progs. Compiled sizes on Ubuntu 16.04: Before: 3916512 btrfs 233688 libbtrfs.so.0.1 4899 bcp 2367672 btrfs-convert 2208488 btrfs-corrupt-block 13302 btrfs-debugfs 2152160 btrfs-debug-tree 2136024 btrfs-find-root 2287592 btrfs-image 2144600 btrfs-map-logical 2130760 btrfs-select-super 2152608 btrfstune 2131760 btrfs-zero-log 2277752 mkfs.btrfs 9166 show-blocks After: 3908744 btrfs 233256 libbtrfs.so.0.1 4899 bcp 2366560 btrfs-convert 2207432 btrfs-corrupt-block 13302 btrfs-debugfs 2151104 btrfs-debug-tree 2134968 btrfs-find-root 2281864 btrfs-image 2143536 btrfs-map-logical 2129704 btrfs-select-super 2151552 btrfstune 2130696 btrfs-zero-log 2276272 mkfs.btrfs 9166 show-blocks Total savings: 23928 (24 kilo)bytes Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move help defines to own headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce kernel sizes to cleanup large intermediate numberQu Wenruo2017-03-08
| | | | | | | | | | | Large numbers like (1024 * 1024 * 1024) may cost reader/reviewer to waste one second to convert to 1G. Introduce kernel include/linux/sizes.h to replace any intermediate number larger than 4096 (not including 4096) to SZ_*. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: scrub: improved error handling in scrub_read_fileDavid Sterba2016-09-21
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: do not set optind if not necessaryDavid Sterba2016-07-13
| | | | | | | In the subcommand callbacks that are called just once, we don't need to explicitly reset optind. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: typo review of strings and commentsNicholas D Steeves2016-06-01
| | | | | Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add getopt stubs where neededDavid Sterba2016-03-14
| | | | | | | | | Commands that do not take any options do not use getopt, which means the standard option separator "--" does not work. Update all command handlers that need it, argv needs to be referenced using the optind that is correctly pointed after the separator. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use btrfs_open_dir in open_path_or_dev_mntZhao Lei2015-11-02
| | | | | | | | | | | | | | | | | | | | | | | Use btrfs_open_dir() in open_path_or_dev_mnt() to make the function return error when target is neither block device nor btrfs mount point. Also add "verbose" argument to let function output common error message instead of putting duplicated lines in caller. Before patch: # ./btrfs device stats /mnt/tmp1 ERROR: getting dev info for devstats failed: Inappropriate ioctl for device # ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1 ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device After patch: # ./btrfs device stats /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use common warning/error for cmds-scrub.cZhao Lei2015-10-21
| | | | | | | | | | Use common warning/error functions in cmds-scrub.c, it can make message format unified and make code simple. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> [removed ending newlines from messages] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: enhance error message with status from kernel and errnoZhao Lei2015-10-19
| | | | | | | | | | | | | | | Scrub output prints the following error message in my test: ERROR: scrubbing /var/ltf/tester/scratch_mnt failed for device id 5 (Success) It is caused by a broken kernel and fs, but the we need to avoid printing both "error and success" on one line as above. This patch modified above message to: ERROR: scrubbing /var/ltf/tester/scratch_mnt failed for device id 5: ret=1, errno=0 (Success) Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> [minor updates in formatting] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use switch instead of a series of ifs for output error messageZhao Lei2015-10-19
| | | | | Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Increase running state's priority in stat outputZhao Lei2015-10-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Anthony Plack <anthony@plack.net> reported a output bug in maillist: title: btrfs-progs SCRUB reporting aborted but still running - minor btrfs scrub status report it was aborted but still runs to completion. # btrfs scrub status /mnt/data scrub status for f591ac13-1a69-476d-bd30-346f87a491da scrub started at Mon Apr 27 06:48:44 2015 and was aborted after 1089 seconds total bytes scrubbed: 1.02TiB with 0 errors # # btrfs scrub status /mnt/data scrub status for f591ac13-1a69-476d-bd30-346f87a491da scrub started at Mon Apr 27 06:48:44 2015 and was aborted after 1664 seconds total bytes scrubbed: 1.53TiB with 0 errors # ... Reason: When scrub multi-device simultaneously, if some device canceled, and some device is still running, cancel state have higher priority to be outputed in global report. So we can see "scrub aborted" in status line, with running-time keeps increased. Fix: We can increase running state's priority in output, if there is some device in scrub state, we output running state instead of cancelled state. Reported-by: Anthony Plack <anthony@plack.net> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use android compat headerDavid Sterba2015-09-01
| | | | | | Applies to sources where pthreads are used. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix memory leaks in error pathByongho Lee2015-08-31
| | | | | | | | | | This patch includes below fixes in error path: 1. fix memory leaks if realloc() fails 2. add missing call free_history() before return error in scrub_read_file() Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com> Reviewed-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: compilation errors when using musl libcBrendan Heading2015-08-31
| | | | | | | | | | | | | - limits.h must be included to pick up PATH_MAX. - remove double declaration of BTRFS_DISABLE_BACKTRACE kerncompat.h assumed that if __GLIBC__ was not defined, it could safely define BTRFS_DISABLE_BACKTRACE, however this can be defined by the configure script. Added a check to ensure it is not defined first. Signed-off-by: Brendan Heading <brendanheading@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use PATH_MAX instead of BTRFS_PATH_NAME_MAXDavid Sterba2015-06-12
| | | | | | | | | | The path bufferes should be PATH_MAX but BTRFS_PATH_NAME_MAX is shorter due to embedding in 4k aligned structures. The only reason to use BTRFS_PATH_NAME_MAX is for the respective structures btrfs_ioctl_vol_args::name. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add command group info stringsDavid Sterba2015-06-09
| | | | | | They're printed in the 'btrfs' command group summary. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: scrub: more friendly duration format in statusDavid Sterba2015-06-04
| | | | | | | | scrub status for d4dc0da9-e8cc-4bfe-9b6f-2dcf8e0754f5 scrub started at Sat Jan 1 00:00:01 UTC 2000 and finished after 00:43:05 total bytes scrubbed: 111.17GiB with 0 errors Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix check of running scrubDavid Sterba2015-01-19
| | | | | | | | Scrub on multiple devices may report wrong status if scrub finishes early on one of them. Reported-by: Sandy McArthur Jr <sandymac@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: scrub, detect stale information in the status fileDavid Sterba2014-10-10
| | | | | | | | | | | | | If scrub is not cancelled nor finished, the recorded status will prevent scrub to start again though it's not running. There's a force option to run it anyway, but this is just a bandaid and the true status of scrub should be detected automatically. The force option should not be necessary anymore. The test introduced in 9681f82853360aac1ff2 checks only the status file, not kernel status of scrub. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: random fixes for usage string of btrfs scrubSatoru Takeuchi2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | - Add missing description about "-R" option in the command usage of "btrfs scrub resume". - Add missing comma to avoid the following misformatted command usage of "btrfs scrub start". See the line of "-R" option. === usage: btrfs scrub start [-BdqrRf] [-c ioprio_class -n ioprio_classdata] <path>|<device> Start a new scrub -B do not background -d stats per device (-B only) -q be quiet -r read only mode -R raw print mode, print full data instead of summary-c set ioprio class (see ionice(1) manpage) -n set ioprio classdata (see ionice(1) manpage) -f force to skip checking whether scrub has started/resumed in userspace this is useful when scrub stats record file is damaged === Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: replace a confusing raw number with a macroGui Hecheng2014-08-22
| | | | | | | | | The raw number 36 for the uuid string length is somewhat confusing, use a macro to define replace it. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> [Use BTRFS_UUID_UNPARSED_SIZE] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: correct manpage option description for scrubGui Hecheng2014-08-22
| | | | | | | | | | | | | | | | | | The -f option of scrub means to "force starting new scrub even if a scrub is already running" *not* "force to check whether scrub has started or resumed in userspace" as described originally. So replace the orignal description in the manpage and code. Also, add description of the potential failure as follows "If a scrub is already running, it fails." Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Cc: David Sterba <dsterba@suse.cz> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: remove unnecessary judgment for fd in scrubGui Hecheng2014-08-22
| | | | | | | | | The scrub_read_file function is always on a branch, which has (fd >= 0), so there is not need to judgment the pasted in arg. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: adjust the return values for scrubGui Hecheng2014-08-22
| | | | | | | | | | | o Return 0 to indicate success, when detected errors were corrected during scrubbing. P.s. This is also to facilitate scripting when return value is to be checked. o Warn the users if there are uncorrectable errors detected. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Improve the errno string about open_path_or_dev_mnt()Qu Wenruo2014-08-22
| | | | | | | | | | | | | | | open_path_or_dev_mnt() is used to on *mounted* btrfs device or mount point, when a unmounted btrfs device is passed, errno is set to EINVAL to info the caller. If ignore the errno and just print "ERROR: can't access '%s'", end users will get confused. This patch will add check for open_path_or_dev_mnt() caller and print more meaningful error message when a unmounted btrfs device path is given. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* scrub: fix uninit return variable in scrub_progress_cycleChris Mason2014-05-28
| | | | Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: scrub: disable thread cancelability during mutex locksRakesh Pandit2014-04-22
| | | | | | | | | | | | | | | | scrub_progress_cycle thread runs in asynchronous type but locks mutex while reading shared data. This patch disables cancelability for a brief time while locks are on so as to make sure they are unlocked before thread is canceled. scrub_write_progress gets called from scrub_progress_cycle in asynchronous thread but cancelability is disabled after mutex is locked. This patch moves the call to set cancelability type before mutex lock and makes corresponding changes to labels for error handling. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: remove unsed pthread attribute objectsRakesh Pandit2014-04-22
| | | | | | | | | Threads always use default attributes in all tools, so pthread attribute objects and their initializations are of no use. Just pass NULL as attr attribute to pthread_create for default attributes. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: scrub: don't call unlock if pthread_mutex_lock failsRakesh Pandit2014-03-21
| | | | | | | | | | | | If pthread_mutex_lock fails (rare but fix it anyway), don't call pthread_mutex_unlock on mutex. Rationale being that if pthread_mutex_lock fails pthread_mutex_unlock will always fail and overwrite actual error value in err. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: fix minor grammar issuesMitchel Humpherys2014-01-31
| | | | | | | | Remove the extraneous `to' from `Can't access to X'. Signed-off-by: Mitchel Humpherys <mitch.special@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: fix resource leak in scrub_start()Eric Sandeen2014-01-31
| | | | | | | | | | Resolves-Coverity-CID: 1125934 Resolves-Coverity-CID: 1125935 Resolves-Coverity-CID: 1125936 Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: fix segfault when getting scrub statusWang Shilong2014-01-31
| | | | | | | | | I sometimes get segfault in cmd_scrub_status(), this is because free_history() forgot to check whether pointer address is valid,fix it. Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: add option to skip whether a scrub has started/resumed in userspaceWang Shilong2014-01-31
| | | | | | | | | | | | | I hit a problem that i can not start scrub when i am trying to track superblock generation mismatch problems. The fact is that we are trying to check whether we have started a scrub operation in userspace, this will make us can't start scrub if that record file is damaged itself. By adding a option to skip that check, everything will be fine. Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: define BTRFS_UUID_UNPARSE_SIZE for uuid unparse buf sizeAnand Jain2014-01-31
| | | | | | | | | we use 37 as the allocation size to hold the uuid_unparse, here it defines BTRFS_UUID_UNPARSE_SIZE for the same. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: fix magic return value in cmds-scrub.cWang Shilong2013-10-16
| | | | | | | | | | | | | | | | | | | There will be four kinds of return value for command "scrub start": 0: scrub dosen't find errors and return success. 1: usage or syntax errors. 3: scrub finds errors and correct all of them. 4: scrub finds errors and some of them are not correctable. Three kinds of return values for scrub cancel/resume: 0: cancel successfully. 1: usage or syntax errors. 2: cancel a not started or finished scrub. Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: use NULL instead of 0Zach Brown2013-09-03
| | | | | | | | | These were mostly in option structs but there were a few gross string pointer arguments given as 0. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: mark static & remove unused from non-kernel codeEric Sandeen2013-09-03
| | | | | | | | Mark many functions as static, and remove any resulting dead code. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: Update the usage strings of some cmdsQu Wenruo2013-08-09
| | | | | | | | | | | Update the usage strings of some cmds to keep the them consistent with the source. Also some minor changes are done to fit the man page syntax. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix closing of opendir()Wang Shilong2013-08-09
| | | | | | | | | | valgrind complains open_file_or_dir() causes a memory leak.That is because if we open a directoy by opendir(), and then we should call closedir() to free memory. Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: per-thread, per-call pretty bufferZach Brown2013-08-09
| | | | | | | | | | | | | | | | | We don't need callers to manage string storage for each pretty_sizes() call. We can use a macro to have per-thread and per-call static storage so that pretty_sizes() can be used as many times as needed in printf() arguments without requiring a bunch of supporting variables. This lets us have a natural interface at the cost of requiring __thread and TLS from gcc and a small amount of static storage. This seems better than the current code or doing something with illegible format specifier macros. Signed-off-by: Zach Brown <zab@redhat.com> Acked-by: Wang Shilong <wangs.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: detect when scrub is started twiceStefan Behrens2013-08-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Check whether any involved device is already busy running a scrub. This would cause damaged status messages and the state "aborted" without the explanation that a scrub was already running. Therefore check it first, prevent it and give some feedback to the user if scrub is already running. Note that if scrub is started with a block device as the parameter, only that particular block device is checked. It is a normal mode of operation to start scrub on multiple single devices, there is no reason to prevent this. Here is an example: /mnt2 is the mountpoint of a filesystem. /dev/sdk and /dev/sdl are the block devices for that filesystem. case 1: btrfs scrub start /mnt2 btrfs scrub start /mnt2 -> complain case 1: btrfs scrub start /dev/sdk btrfs scrub start /dev/sdk -> complain case 3: btrfs scrub start /dev/sdk btrfs scrub start /dev/sdl -> don't complain case 4: btrfs scrub start /dev/sdk btrfs scrub start /mnt2 -> complain case 5: btrfs scrub start /mnt2 btrfs scrub start /dev/sdk -> complain if the scrub on /dev/sdk is still running. -> don't complain if the scrub on /dev/sdk is finished, the status messages will be fine. Reported-by: David Sterba <dsterba@suse.cz> Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: fix btrfs scrub start helpAnand Jain2013-04-23
| | | | | | a very trivial fix Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Btrfs-progs: make scrub IO priority configurableStefan Behrens2013-03-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The btrfs tool is changed in order to support command line parameters to configure the IO priority of the scrub tasks. Also the default is changed. The default IO priority for scrub is the idle class now. The behavior is the same as when one would type 'ionice ... btrfs scrub start ...' or 'ionice ... btrfs scrub resume ...' (without this patch applied). The only reason for adding this to the btrfs tool is that it was not documented and not obvious that it worked like this, that all internal scrub tasks inherited the IO priority values of the btrfs tool that is starting or resuming the scrub operation. Note that after applying the patch it is no longer possible to set the IO priority using ionice since the btrfs tool always configures the priority in order to run in the idle class by default. Some basic performance measurements have been done with the goal to measure which IO priority for scrub gives the best overall disk data throughput. The kernel was configured to use the CFQ IO scheduler with default configuration and without support for throttling. The summary is, that the more the disk head movements are avoided, the faster the overall disk transfer capacity is, which is not really a big surprise. Therefore it makes sense that the best data throughput was measured setting the scrub IO priority and the scrub readahead IO priority to the idle class priority. Running with idle class IO priority means that scrub and scrub readahead IO is paused while other tasks access the disk. Doing the tasks one after the other instead of concurrently avoids many disk head movements. The overall data throughput of rotating disks is improved this way. However, if it is desired to have the scrub task done within a reasonable time, and if at the same time the filesystem is heavily loaded, the idle IO priority should be avoided. Otherwise the scrub operation will never take place and thus never terminate. The best effort IO priority class with the subclass 7 (the lowest one in the best effort class) is recommended in the case of always heavily loaded hard disks. If the filesystem is not loaded all the time and leaves some idle slots for scrub, the idle class IO priority is recommended. The idle class now is the default if the scrub operation is started with the btrfs-progs tools. Note that the patch that sets the scrub readahead IO priority to the idle class is a seperate patch, this needs to be done in the kernel. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* btrfs-progs: rework get_fs_info to remove side effectsEric Sandeen2013-03-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* btrfs-progs: don't open-code mountpoint discovery in scrub cancelEric Sandeen2013-03-12
| | | | | | | 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>
* btrfs-progs: fix scrub error return from pthread_mutex_lockEric Sandeen2013-03-10
| | | | | | | If pthread_mutex_lock() fails it returns the error in ret, and does not set errno. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: Error handling in scrub_progress_cycle() threadEric Sandeen2013-03-10
| | | | | | | | | | | 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>
* btrfs-progs: Issue warnings if ioctls fail in sigint handlersEric Sandeen2013-03-10
| | | | | | | | | 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>
* btrfs-progs: more scrub cancel error handlingEric Sandeen2013-02-27
| | | | | | | | | | | | | | | | | | | 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>