summaryrefslogtreecommitdiff
path: root/cmds-device.c
Commit message (Collapse)AuthorAge
* btrfs-progs: cleanup cmd_device_usage, simplify loop checksZhao Lei2015-11-16
| | | | | | | | | 1: Remove more_than_one variable, use iterators value instead 2: Remove "out" label, we use break instead. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> [ changelog update ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: device: use warning/error for error messageZhao Lei2015-11-16
| | | | | | | | Switch to common warning()/error() for cmds-device.c. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> [ minor tweaks ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: allow device deletion using 'missing' keyword againAlexander Fougner2015-11-16
| | | | | | | | | | Device deletion procedures ensures the device is a block device. This patch introduces 'missing' as keyword again, correctly passing it on to the kernel instead of complaining about 'missing' not being a block device. Signed-off-by: Alexander Fougner <fougner89@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: rename helpinfo unit vairablesDavid Sterba2015-11-06
| | | | 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: device add: cleanup argument handlingAnand Jain2015-11-02
| | | | | | | | This is needed by the patch which introduces new devid option for the btrfs device delete. Signed-off-by: Anand Jain <anand.jain@oracle.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 is_block_device() return checksAnand Jain2015-10-02
| | | | | | | | | | | | | | it was highlighted to me is_block_device(), returns 1 if the file is a block device, < 0 in case of an error (eg: file not found) 0 otherwise This patch makes proper return checks at all the places where is_block_device() is used. Thanks to Goffredo. Signed-off-by: Anand Jain <anand.jain@oracle.com> Suggested-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, mark more functions staticDavid Sterba2015-09-14
| | | | | | Reported by sparse. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, make usage strings staticDavid Sterba2015-09-14
| | | | | | Reported by sparse. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use common unit parser for btrfs device commandZhao Lei2015-09-01
| | | | | | | | | Move to use get_unit_mode_from_arg() for cmds-device.c, to make "btrfs device usage"'s unit argument same with other tools. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use btrfs_open_dir for btrfs device commandZhao Lei2015-08-31
| | | | | | | | | | | | | | | | | | | | | | | | We can use btrfs_open_dir() to check whether the target dir is under btrfs mount point before openning, instead of checking it in kernel through ioctl, and returning a fuzzy error message. Before patch: # (/mnt/tmp is not btrfs mountpoint) # # btrfs device add -f /dev/sda13 /mnt/tmp ERROR: error adding the device '/dev/sda13' - Inappropriate ioctl for device # After patch: # btrfs device add -f /dev/sda13 /mnt/tmp ERROR: not btrfs filesystem: /mnt/tmp # Similar fix for device remove and device usage. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> [renamed to btrfs_open_dir] 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: update help for device statsDavid Sterba2015-08-31
| | | | 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: alias btrfs device delete to btrfs device removeOmar Sandoval2015-06-26
| | | | | | | | There's an awkward asymmetry between btrfs device add and btrfs device delete. Resolve this by aliasing delete to remove. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: properly set up ioctl argumentsDavid Sterba2015-06-12
| | | | | | | | At some places we do not clear the whole ioctl structure and could pass garbage to kernel. Zero the ioctl vol_args and use a helper for copying the path. Signed-off-by: David Sterba <dsterba@suse.cz>
* 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 the correct variableAnand Jain2015-05-14
| | | | | | | | It's res instead of ret, wrong error message could be prointed in case of error. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup, rename *disk_usage* files to usageDavid Sterba2015-04-22
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: improve troubleshooting avoid duplicate error stringsAnand Jain2015-04-14
| | | | | | | | | | | | | | | | my troubleshooting experience says have unique error string per module. In the below eg, its one additional step to know error line, cat -n cmds-device.c | egrep "error removing the device" 185 "ERROR: error removing the device '%s' - %s\n", 190 "ERROR: error removing the device '%s' - %s\n", which is completely avoidable. Signed-off-by: Anand Jain <anand.jain@oracle.com> [merged the two messages into one] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup option index argument from getopt_longDavid Sterba2015-04-08
| | | | | | | We're not using it anywhere. The best practice is to add enums with values > 255 for the long options, option index counting is error prone. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: unify getopt table terminatorsDavid Sterba2015-01-21
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add --human-readable option where applicableDavid Sterba2015-01-21
| | | | | | | Add an alias to -h to 'filesystem usage', 'filesystem df' and 'device usage' commands, same as the traditional 'df'. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use predefined getopt values for unit suffixesDavid Sterba2015-01-21
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: make getopt tables static constDavid Sterba2015-01-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: unify unit mode parameters and variablesDavid Sterba2014-12-18
| | | | | | Use unsigned type and a common name everywhere. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: dev usage, add switches to set output unitsDavid Sterba2014-12-18
| | | | | | | Same set of options as 'fi df': binary and decimal bases, human readable options etc. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: clean up return codes and pathsDavid Sterba2014-12-04
| | | | | | Use the common patterns with one return statement at the end, pass down error Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: replace df_pretty_sizes with pretty_size_modeDavid Sterba2014-12-04
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup filesystem/device usage codeDavid Sterba2014-12-04
| | | | | | | | | | | | | | | The main point of this is to load the device and chunk infos at one place and pass down to the printers. The EPERM is handled separately, in case kernel does not give us all the information about chunks or devices, but we want to warn and print at least something. For non-root users, 'filesystem usage' prints only the overall stats and warns about RAID5/6. The sole cleanup changes affect mostly the modified code and the related functions, should be reasonably small. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: compare unallocated space against the correct valueDavid Sterba2014-12-04
| | | | | | | | The device may not be fully occupied by the filesystem, the value of Unallocated should not be calculated against the device size but the size provided by DEV_INFO. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Print more info about device sizesDavid Sterba2014-12-04
| | | | | | | | | | | | | | | | | | | | The entire device size may not be available to the filesystem, eg. if it's modified via resize. Print this information if it can be obtained from the DEV_INFO ioctl. Print the device ID on the same line as the device name and move size to the next line. Sample: /dev/sda7, ID: 3 Device size: 10.00GiB FS occupied: 5.00GiB Data,RAID10: 512.00MiB Metadata,RAID10: 512.00MiB System,RAID10: 4.00MiB Unallocated: 9.00GiB Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move device usage to cmds-device, more cleanupsDavid Sterba2014-12-04
| | | | | | | | | | | Move the command definitions where they belong, keep common 'usage' functions in cmds-fi-disk_usage.c and add exports. Rename structures containing 'disk' to 'device'. Fix whitespace in the modified code. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add btrfs device disk-usage commandGoffredo Baroncelli2014-12-04
| | | | | Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use canonical name for device in btrfs fi show when mountedGui Hecheng2014-11-14
| | | | | | | | | | | | | | | | When using lvm volumes to check fstests: btrfs/006, it fails like: Label: 'TestLabel.006' uuid: <UUID> Total devices <EXACTNUM> FS bytes used <SIZE> devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV + devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-4 + devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-5 + devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-6 The /dev/dm-* points to lvm volumes, use @canonicalize_path() to convert them and we will make it through. Of course we should do the same thing for dev stat. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: optimize btrfs_scan_lblkid() for multiple callsAnand Jain2014-11-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | btrfs_scan_lblikd() is called by most the device related command functions. And btrfs_scan_lblkid() is most expensive function and it becomes more expensive as number of devices in the system increase. Further some threads call this function more than once for absolutely no extra benefit and the real waste of resources. Below list of threads and number of times btrfs_scan_lblkid() is called in that thread. btrfs-find-root 1 btrfs rescue super-recover 2 btrfs-debug-tree 1 btrfs-image -r 2 btrfs check 2 btrfs restore 2 calc-size NC btrfs-corrupt-block NC btrfs-image NC btrfs-map-logical 1 btrfs-select-super NC btrfstune 2 btrfs-zero-log NC tester NC quick-test.c NC btrfs-convert 0 mkfs #number of devices to be mkfs btrfs label set unmounted 2 btrfs get label unmounted 2 This patch will: move out calling register_one_device with in btrfs_scan_lblkid() and so function setting the BTRFS_UPDATE_KERNEL to yes will call btrfs_register_all_devices() separately. introduce a global variable scan_done, which is set when scan is done succssfully per thread. So that following calls to this function will just return success. Further if any function needs to force scan after scan_done is set, then it can be done when there is such a requirement, but as of now there isn't any such requirement. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: code optimize cmd_scan_dev() use btrfs_register_one_device()Anand Jain2014-11-03
| | | | | | | | cmd_scan_dev() has it own code to register device (calling ioctl BTRFS_IOC_SCAN_DEV), apparently it could use btrfs_register_one_device(). Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: remove BTRFS_SCAN_PROC scan methodAnand Jain2014-10-10
| | | | | | | | | | | The libblkid scan method which was introduced later, will also scan devices under /proc/partitions. So we don't have to do the explicit scan of the same. Remove the scan method BTRFS_SCAN_PROC. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: scan /proc/partitions not all of /dev with "-d"Eric Sandeen2014-10-10
| | | | | | | | | | | | | | | We can scan for btrfs devices in a few ways. By default libblkid is used for "device scan" and "filesystem show"; with the -m option only mounted filesystems are scanned, and with -d we physically read every system device. But there's no reason for the complexity of a descent through /dev; /proc/partitions has every device known to the kernel, so just use that when -d is specified. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: fix typosHolger Hoffstätte2014-09-02
| | | | | | | Fix (at least one user-visible) typos: it's its, not it's. Signed-off-by: Holger Hoffstätte <holger.hoffstaette@googlemail.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: 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: Modify the help string to keep consistent with man page.Qu Wenruo2014-04-11
| | | | | | | | | Help string of "btrfs dev scan" is inconsistent with man page, which lacks the fact that -d|--all-device is conflict with <device>. This patch fixes the description Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: make the device scan logic more clearGui Hecheng2014-03-21
| | | | | | | | | | | | | | 1. Use long option to replace the original strcmp() to parse the "--all-devices". 2. the "int ret" is defined in 2 places, just define it once and make the return pattern into "goto + single return". This does not change the actual scan procedure and return values. Just make it clear, the original seems a little confusing. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: cleanup device stat usage promptGui Hecheng2014-03-21
| | | | | | | | | 1. use usage() to replace the fprintf() 2. use check_argc_exact() to replace "argc != ..." Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.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: 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>