summaryrefslogtreecommitdiff
path: root/cmds-device.c
Commit message (Collapse)AuthorAge
* 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>
* Btrfs-progs: add sanity checks for btrfs device operationsWang Shilong2014-01-31
| | | | | | | | | Make sure we are a block device firstly, this can avoid some unnecessary ioctls operations. 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: make sure we return an error when we can't add a deviceJosef Bacik2013-10-24
| | | | | | | | | | I noticed xfstests was failing in a weird way but it was because our device add was failing but not actually returning an error so we were failing further down the test. Fix this by making sure we return an error if we fail the mkfs tests. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: use the marco BTRFS_UPDATE_KERNEL where neededAnand Jain2013-10-16
| | | | | | 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: device scan use BTRFS_SCAN_LBLKID by defaultAnand Jain2013-10-16
| | | | | | | | | | | | | | | | | with this patch, BTRFS_SCAN_LBLKID (which leverages lblkid to look for btrfs disks) would be the default scan method to look for the btrfs disks. And thus the output as seen in the latest btrfs fi show and btrfs fi show -m for the mounted disks will have the consistent disks path. (it was inconsistent (across disks) because btrfs dev scan provided a different path from the mount command eg. below) devid 1 size 1.98GiB used 435.00MiB path /dev/mapper/mpatha devid 2 size 2.00GiB used 415.00MiB path /dev/dm-1 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: device add should check existing FS before addingAnand Jain2013-10-16
| | | | | | | | | | | | | | | as of now, when 'btrfs device add' adds a device it doesn't check if the given device contains an existing FS. This patch will change that to check the same. which when true add will fail, and ask user to use -f option to overwrite. further, since now we have test_dev_for_mkfs() function to check if a disk can be used, so this patch will also use this function to test the given device before adding. 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: add nodiscard option to device addDavid Sterba2013-10-16
| | | | | | | Same as for mkfs. Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix magic return value in cmds-device.cWang Shilong2013-10-16
| | | | | | 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: fix shadow symbolsZach Brown2013-09-03
| | | | | | | | | | | | | | | This fixes all the instances of warnings that symbols declared in blocks shadow symbols with the same name in surrounding scopes: cmds-device.c:341:22: warning: symbol 'path' shadows an earlier one cmds-device.c:285:14: originally declared here I just renamed or removed the risky shadow symbols instead of pulling their blocks out into functions. 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: remove __CHECKER__ from main codeZach Brown2013-09-03
| | | | | | | | | | | | __CHECKER__ is only for the type juggling used to tell sparse which types need conversion between address spaces. It is not OK to use to change the code that gets checked to avoid bugs elsewhere in the build infrastructure. We want to check the code that builds when the checker isn't enabled. 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: device delete to get errors from the kernelAnand Jain2013-08-09
| | | | | | | | | | | | | | | | | | when user runs command btrfs dev del the raid requisite error if any goes to the /var/log/messages, its not good idea to clutter messages with these user (knowledge) errors, further user don't have to review the system messages to know problem with the cli it should be dropped to the user as part of the cli return. to bring this feature created a set of the ERROR defined BTRFS_ERROR_DEV* error codes and created their error string. I expect this enum to be added with other error which we might want to communicate to the user land 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: congregate dev scanAnand Jain2013-08-09
| | | | | | | | | | | | | | | | the dev scan to find btrfs is performed at two locations all most the same way one at filesystem show and another at device scan. They both follow the same steps. This patch does not alter anything except that it brings these two same logic into the function scan_for_btrfs so that we can play tweaking it. the patch which recommends to use /dev/mapper will also need it 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 device scan usageAnand Jain2013-08-09
| | | | | | | | | the btrfs device scan usage didnt publish --all-devices option so add it 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: 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: Fix getopt on arm/ppc platformsDavid Sterba2013-08-09
| | | | | | | | | (same as commit bb0eabc383e9a3fde7cdb02591ca88243f3e31fb) 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: 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: Remove write-only var fdres in cmd_dev_stats()Eric Sandeen2013-02-27
| | | | | | | fdres is initialized to -1, then later tested, but never set. Just remove it. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: simplify ioctl name copy and null terminationEric Sandeen2013-02-05
| | | | | | | | | | | | | | | | | | | | | | | | | In the places where we copy a string into the name member of btrfs_ioctl_vol_args or btrfs_ioctl_vol_args_v2, we use strncopy (to not overflow the name array) and then set the last position to the null character. Howver, in both cases the arrays are defined with: char name[MAX+1]; hence the last array position is name[MAX]. In most cases, we now insert the null at name[MAX-1] which deprives us of one useful character. Even the above isn't consistent through the code, so make some helper code to make it simple, i.e. strncpy_null(dest, src) which automatically does the right thing based on the size of dest. Thanks to Zach Brown for the macro suggestion. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: check for open failure, don't closeZach Brown2013-02-05
| | | | | | | Check for failure by testing for a negative file descriptor, not a descriptor of 0. And if it failed we have nothing to close(). Signed-off-by: Zach Brown <zab@redhat.com>
* Btrfs-progs: add command to get/reset device stats via ioctlStefan Behrens2013-01-31
| | | | | | | | "btrfs device stats" is used to retrieve and print the device stats. "btrfs device stats -z" is used to atomically retrieve, reset and print the stats. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* Btrfs-progs: add btrfs device ready commandJosef Bacik2013-01-23
| | | | | | | | | | | This command will be used by things like dracut that wish to know very simply if all of the devices have been added to the kernel cache yet for the device to be fully mounted. This keeps initrd's from constantly having to try to mount the file system until it succeeds every time a device is added to the system. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Gene Czarcinski <gene@czarc.net>
* Btrfs-progs: only enforce a maximum size if we specify oneJosef Bacik2012-10-02
| | | | | | | | | | | | | | My patch 04609add88ef8428d725de6ef60f46a3ff0dbc8e introduced a regression where if you mkfs'ed a group of disks with different sizes it limited the disks to the size of the first one that is specified. This was not the intent of my patch, I only want it to limit the size based on the -b option, so I've reworked the code to pass in a max block count and that fixes the issue. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
* avoid several strncpy-induced buffer overrunsJim Meyering2012-06-05
| | | | | | | | | | | | | | * restore.c (main): Ensure strncpy-copied dir_name is NUL-terminated. * btrfsctl.c (main): Likewise, for a command-line argument. * utils.c (multiple functions): Likewise. * btrfs-list.c (add_root): Likewise. * btrfslabel.c (change_label_unmounted): Likewise. * cmds-device.c (cmd_add_dev, cmd_rm_dev, cmd_scan_dev): Likewise. * cmds-filesystem.c (cmd_resize): Likewise. * cmds-subvolume.c (cmd_subvol_create, cmd_subvol_delete, cmd_snapshot): Likewise. Reviewed-by: Josef Bacik <josef@redhat.com>
* Btrfs-progs: allow multi-line command group synopsisIlya Dryomov2012-02-08
| | | | Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
* Btrfs-progs: switch all existing commands to a new parserIlya Dryomov2012-02-03
| | | | | | | 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>
* Btrfs-progs: rearrange files in the repoIlya Dryomov2012-02-03
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>