summaryrefslogtreecommitdiff
path: root/cmds-replace.c
Commit message (Collapse)AuthorAge
* btrfs-progs: refactor and extend btrfs_prepare_device argumentsDavid Sterba2016-07-28
| | | | | | | | The message about discard is printed unconditionally and does not conform to the --quite option eg. in mkfs. Consolidate the operation flags into one argument and add support for verbosity. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check for negative return value from ioctlDavid Sterba2016-01-12
| | | | | | | Handle only negative values returned by ioctl syscalls, with exception of the device remove. It returns positive values that are handled later. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cmd replace: switch to common error message wrapperDavid Sterba2016-01-12
| | | | | | Message texts were adjusted. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove all btrfs_close_all_devices in sub-commandZhao Lei2015-11-02
| | | | | | | | | Since we have btrfs_close_all_devices() in btrfs's main entrance, it is not necessary to call btrfs_close_all_devices() separately in each sub-command. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* Btrfs-progs: Do not force mixed block group creation unless '-M' option is ↵Chandan Rajendra2015-11-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | specified When creating small Btrfs filesystem instances (i.e. filesystem size <= 1GiB), mkfs.btrfs fails if both sectorsize and nodesize are specified on the command line and sectorsize != nodesize, since mixed block groups involves both data and metadata blocks sharing the same block group. This is an incorrect behavior when '-M' option isn't specified on the command line. This commit makes optional the creation of mixed block groups i.e. Mixed block groups are created only when -M option is specified on the command line. Since we now allow small filesystem instances with sectorsize != nodesize to be created, we can end up in the following situation, [root@localhost ~]# mkfs.btrfs -f -n 65536 /dev/loop0 btrfs-progs v3.19-rc2-405-g976307c See http://btrfs.wiki.kernel.org for more information. Performing full device TRIM (512.00MiB) ... Label: (null) UUID: 49fab72e-0c8b-466b-a3ca-d1bfe56475f0 Node size: 65536 Sector size: 4096 Filesystem size: 512.00MiB Block group profiles: Data: single 8.00MiB Metadata: DUP 40.00MiB System: DUP 12.00MiB SSD detected: no Incompat features: extref, skinny-metadata Number of devices: 1 Devices: ID SIZE PATH 1 512.00MiB /dev/loop0 [root@localhost ~]# mount /dev/loop0 /mnt/ mount: mount /dev/loop0 on /mnt failed: No space left on device The ENOSPC occurs during the creation of the UUID tree. This is because of things like large metadata block size, DUP mode used for metadata and global reservation consuming space. Also, large nodesize does not make sense on small filesystems, hence this should not be an issue. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move is_numerical() helper to utils and renameAnand Jain2015-11-02
| | | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> [ moved to util.c and renamed ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: replace: use btrfs_open_dir for btrfs replace commandZhao Lei2015-11-02
| | | | | | | | | | | | | | | | | | | | | We can use btrfs_open_dir() to check whether target dir is in btrfs's mount point before open, instead of checking it in kernel space of ioctl, and return fuzzy error message. Before patch: # ./btrfs replace cancel /mnt/tmp1 ERROR: ioctl(DEV_REPLACE_CANCEL) failed on "/mnt/tmp1": Inappropriate ioctl for device # ./btrfs replace status /mnt/tmp1 ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device After patch: # ./btrfs replace cancel /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs replace status /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 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: fix use after free in replace startDavid Sterba2015-08-31
| | | | | | | | Commit "btrfs-progs: Add further checks to btrfs replace start command" accesses device size just after its memory is freed. Resolves-coverity-id: 1320425 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: close all fs_devices before exit in some commandsZhao Lei2015-08-31
| | | | | | | | | | | | | | | | | | mkfs creates more than one fs_devices in fs_uuids. 1: one is for file system being created 2: others are created in test_dev_for_mkfs in order to check mount point test_dev_for_mkfs()-> ... -> btrfs_scan_one_device() Current code only closes 1, and this patch also closes in case 2. Similar problem exist in other tools, eg.:: cmd-check.c: the function is: cmd_check()->check_mounted()-> ... -> btrfs_scan_one_device() ... Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: unified error handling in print_replace_statusZhao Lei2015-08-31
| | | | | | | | | | | | | | Current code of print_replace_status() mixed stdout and stderr in error case, output a error string to stderr without "\n", then output "\n" to stdout to end the line. This patch fixed above problem by using unified error handle way for 3 type of errors in print_replace_status(). Also include some small logic cleanup. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add further checks to btrfs replace start commandGoffredo Baroncelli2015-08-31
| | | | | | | | | | | | | | | | | | Add further checks to btrfs replace start command. The following tests where added in user space before calling the ioctl(): 1) check if the new disk is greather or equal to the old one 2) check if the source device is or a block device or a numerical dev-id These checks are already performed in kernel space; however when "btrfs replace start" is ran in background is not possible to show any error returned by the ioctl(), so in case of fail the user had to check dmesg to understand the what happened. Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: unify naming of command handlersDavid Sterba2015-08-31
| | | | | | Use cmd_ + group + command schema. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print error within test_dev_for_mkfsDavid Sterba2015-06-11
| | | | | | | | The error string buffer passed as an argument is of a fixed size, though we could print up to PATH_MAX + something bytes. Print the error message directly. 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: use function is_block_device() insteadAnand Jain2015-06-02
| | | | | | | | Here the delete code as below, is trying to check if the provided device is a block device, there is a function for it. Use it. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add new dev replace resultEryu Guan2014-11-25
| | | | | | | | | | | A new dev replace result was introduced by kernel commit Btrfs: return failure if btrfs_dev_replace_finishing() failed Make the userspace know about the new result too. Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: only report internal dev replace result if there's a resultEryu Guan2014-11-03
| | | | | | | | | | | | | | | | | | If BTRFS_IOC_DEV_REPLACE ioctl failed, args.result usually won't be updated by the ioctl. And the arg has been initialized with 0, the result is always 0, which is BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR, and the resulting error message looks confusing: ERROR: ioctl(DEV_REPLACE_START) failed on "/mnt/btrfs": No such file or directory, no error But in case there's an internal result returned in future, don't drop the result completely, instead print dev replace result message only if the result is updated by a failed ioctl call. Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: return error when canonicalize_path failedEryu Guan2014-10-10
| | | | | | | | Error out cmd_start_replace() if canonicalize_path() dstdev failed, add the missing "goto leave_with_error;" Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: show meaningful msgs for replace cmd upon raid56Gui Hecheng2014-08-22
| | | | | | | | | | | | This depends on the kernel patch: [PATCH] btrfs:replace EINVAL with EOPNOTSUPP for dev_replace This catches the EOPNOTSUPP and output msg that says dev_replace raid56 is not currently supported. Note that the msg will only be shown when run dev_replace not in background. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: canonicalize pathnames for device commandsJeff Mahoney2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mount(8) will canonicalize pathnames before passing them to the kernel. Links to e.g. /dev/sda will be resolved to /dev/sda. Links to /dev/dm-# will be resolved using the name of the device mapper table to /dev/mapper/<name>. Btrfs will use whatever name the user passes to it, regardless of whether it is canonical or not. That means that if a 'btrfs device ready' is issued on any device node pointing to the original device, it will adopt the new name instead of the name that was used during mount. Mounting using /dev/sdb2 will result in df: /dev/sdb2 209715200 39328 207577088 1% /mnt lrwxrwxrwx 1 root root 4 Jun 4 13:36 /dev/whatever-i-like -> sdb2 /dev/whatever-i-like 209715200 39328 207577088 1% /mnt Likewise, mounting with /dev/mapper/whatever and using /dev/dm-0 with a btrfs device command results in df showing /dev/dm-0. This can happen with multipath devices with friendly names enabled and doing something like 'partprobe' which (at least with our version) ends up issuing a 'change' uevent on the sysfs node. That *always* uses the dm-# name, and we get confused users. This patch does the same canonicalization of the paths that mount does so that we don't end up having inconsistent names reported by ->show_devices later. Signed-off-by: Jeff Mahoney <jeffm@suse.com> [use PATH_MAX in canonicalize_dm_name] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Replace the overkill assert with normal error message.Qu Wenruo2014-08-22
| | | | | | | | | When 'btrfs replace status' encounters an unknown dev replace status, it will cause an assert, which is somewhat overkilled and can be replaced with a normal error message. Signed-off-by: Qu Wenruo <quwenruo@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>
* Btrfs-progs: switch to arg_strtou64() part3Wang Shilong2014-03-21
| | | | | | | | | Switch to new helper arg_strtou64(), also check if user assign a valid super copy. 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: handle error in the btrfs_prepare_deviceAnand Jain2014-01-31
| | | | | | | | | this patch will handle the strerror reporting of the error instead of printing errno, and also replaced the BUG_ON with the error handling 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-replace.cWang Shilong2013-10-16
| | | | | | | | | | | | There are 3 kinds of return values in replace cancel: 0: cancel successfully. 1: usage or syntal errors 2: cancel a not started or finished replacing operations. 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: cmd_start_replace() to use test_dev_for_mkfs()Anand Jain2013-09-03
| | | | | | | | | | | | test_dev_for_mkfs() is a common place where we check if a device is fit for the btrfs use. cmd_start_replace() should make use of test_dev_for_mkfs(), and here the test_dev_for_mkfs() is further enhanced to fit the cmd_start_replace() needs. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: let user know that devid can be used if path is missingAnand Jain2013-09-03
| | | | | | | | | | | | | | | | | | | | | When the device disappear the path goes missing, and that will be the one of the reason that user will replace the device. The devid of the missing btrfs device can be obtained using the new cli option btrfs fi show --kernel And which can be used in the replace command. --- btrfs replace start /dev/sdc /dev/sde /btrfs Error: Unable to open device '/dev/sdc' Try using the devid instead of the path --- Signed-off-by: Anand Jain <anand.jain@oracle.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: 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: 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: free allocated di_args in cmd_start_replaceEric Sandeen2013-02-27
| | | | | | | We only freed this allocation in error paths, and leaked a bit when it went out of scope normally. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: fix open error test in cmd_start_replaceEric Sandeen2013-02-27
| | | | | | open() returns a negative fd on failure, not 0. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* Btrfs-progs: add support for device replace procedureStefan Behrens2013-01-31
This is the user mode part of the device replace patch series. The command group "btrfs replace" is added with three commands: - btrfs replace start srcdev|srcdevid targetdev [-Bfr] mount_point - btrfs replace status mount_point [-1] - btrfs replace cancel mount_point Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>