summaryrefslogtreecommitdiff
path: root/cmds-filesystem.c
Commit message (Collapse)AuthorAge
* btrfs-progs: Fix check_arg_type() which doesn't use realpath() result.Qu Wenruo2014-03-21
| | | | | | | | | | Fix a problem that does not use the result of realpath(), which caused check_arg_type() can't handle mount point which ends with a final '/'. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Cc: 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 missing devices check for mounted btrfs.Qu Wenruo2014-03-21
| | | | | | | | | | | | | | In btrfs/003 of xfstest, it will check whether btrfs fi show can find missing devices. But before the patch, btrfs-progs will not check whether device missing if given a mounted btrfs mountpoint/block device. This patch fixes the bug and will pass btrfs/003. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Cc: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: return non zero when label is not foundAnand Jain2014-01-31
| | | | | | | | btrfs filesystem show <not-found-label> should return non zero 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: lblkid wouldn't find non mapper path inputAnand Jain2014-01-31
| | | | | | | | | | | | A new test case when disk is unmounted and if the non mapper disk path is given as the argument to the btrfs filesystem show <arg> we still need this to work but lblkid will pull only mapper disks, it won't match. So this will normalize the input to find btrfs by fsid and pass it to the search. 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 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: skip non-regular files while defragmentingPascal VITOUX2014-01-31
| | | | | | | | | | | Skip non-regular files to avoid ioctl errors while defragmenting. They are silently ignored in recursive mode but reported as errors when used as command-line arguments. Signed-off-by: Pascal VITOUX <vitoux.pascal@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: fix improper error prompt for defragmentGui Hecheng2014-01-31
| | | | | | | | | | | | The error msg: "ERROR: defrag range ioctl not supported in this kernel, please try without any options." should only show up when failing to do a range defraging, not upon non-range defraging. 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: call endmntent in btrfs_scan_kernelDavid Sterba2014-01-31
| | | | | | | | | | | btrfs_scan_kernel() does a getmntent() but never releases the filedescriptor it gets back from that. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=64711 Reported-by: Arjan van de Ven <arjan@linux.intel.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: let get_label return the label instead of printing itFilipe David Borba Manana2014-01-31
| | | | | | | | | get_label prints the label at the moment. Change this so that the label is returned and printing is done by the caller. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: make filesystem show by label workAnand Jain2014-01-31
| | | | | | | | | | with design revamp around filesystem show the fsid filter by label wasn't planned. but apparently that seemed to be necessary. this patch will fix it. 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 filesystem show: skip duplicate fsidsChris Mason2013-11-18
| | | | | | | | | If a given filesystem is mounted more than once, btrfs fi show will print dups. This adds a quick and dirty hash table of fsids it has already printed and makes sure we don't print any fsid more than once. Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: check for fstat failure in cmd_defragEric Sandeen2013-11-07
| | | | | | Resolves-Coverity-CID: 1125924 Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: pass positive errno to strerror in cmd_df()Eric Sandeen2013-11-07
| | | | | | | | | get_df returns a negative error number, but then we pass it to strerror, which wants a positive value... Resolves-Coverity-CID: 1125929 Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: btrfs_scan_kernel(): fd==0 is not an errorEric Sandeen2013-11-07
| | | | | | | | | | The error return from open is -1, so test that, not 0, for success/failure. Resolves-Coverity-CID: 1125931 Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: fix error returns in get_df()Eric Sandeen2013-11-07
| | | | | | | | | | | | | | get_df returns -ERRNO, or maybe (+)errno, or even 0 in the case where we inexplicably got 0 total_spaces from the BTRFS_IOC_SPACE_INFO. Consistently return a negative error number, and return -ENOENT rather than 0 for total_spaces == 0, so that the caller will know that **sargs_ret hasn't been set up. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: filesystem show of specified mounted disk should workAnand Jain2013-10-24
| | | | | | | | | | Originally, thinking was user will use mount point if the disk is mounted. But thats not really true, actually user don't (or shouldn't) care to check if disk mounted, so whether disk is mounted/unmounted when disk path is specified it should work. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: use BTRFS_SCAN_LBLKID as default scan in filesystem showAnand Jain2013-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | btrfs progs has to scan for the btrfs disks for two main reasons, one to register them with the btrfs kernel (under btrfs dev scan) 2nd to report btrfs disks to the user (under btrfs fi show) (there few more minor reasons like check_mounted etc..). To facilitate the scan, in total we have the following methods to scan for the btrfs BTRFS_SCAN_PROC which uses the /proc/partitions to look for the disks, when scanning it does it twice first would look for non dm- paths and in the 2nd scan it would pick only dm- paths. BTRFS_SCAN_DEV which scans all the block dev under /dev as they appear during scanning. BTRFS_SCAN_LBLKID this uses the library functions provided by the lblkid to get only disks which contains the btrfs SB. The better method to use would be BTRFS_SCAN_LBLKID for the obvious reasons we don't have to reinvent that feature with in btrfs-progs. For the btrfs fi show - This patch will.. - make BTRFS_SCAN_LBLKID as the default scan option (BTRFS_SCAN_DEV is accessible under the option --all-devices and BTRFS_SCAN_PROC won't be used by btrfs fi show any more) 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: use kernel for mounted disk for showAnand Jain2013-10-16
| | | | | | | | | | | | | As of now btrfs filesystem show reads directly from disks. So sometimes output can be stale, mainly when user wants to cross verify their operation like, label or device delete or add... etc. so this patch will read from the kernel ioctl if it finds that disk is mounted. 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 recursive defrag using -r optionFrank Holton2013-10-16
| | | | | | | | Add an option to defrag all files in a directory recursively. Signed-off-by: Frank Holton <fholton@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: move out print in cmd_df to another functionAnand Jain2013-10-16
| | | | | | | | | This is a prepatory work for the btrfs fi show command fixes. So that we have a function get_df to get the fs sizes 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 list_sort and use it to sort devices by idDavid Sterba2013-10-16
| | | | | | | | The devices in 'btrfs filesystem show' are now sorted by the device id, currently the order was undefined. 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-filesystem.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: 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: 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: label option in btrfs filesystem show is not codedAnand Jain2013-08-09
| | | | | | 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: 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: record errno for ioctl DEFRAG_RANGELiu Bo2013-04-23
| | | | | | In order to sparse exact error message, we need to record errno here. Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
* btrfs-progs: defrag return zero on successAnand Jain2013-03-18
| | | | Signed-off-by: Anand Jain <anand.jain@oracle.com>
* btrfs-progs: move btrfslabel.[c|h] stuff to utils.[c|h]Jeff Liu2013-02-26
| | | | | | | | | Clean btrfslabel.[c|h] out of the source tree and move those related functions to utils.[c|h]. CC: Gene Czarcinski <gene@czarc.net> Signed-off-by: Jie Liu <jeff.liu@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: fix cmd_label_usage to reflect this change.Jeff Liu2013-02-26
| | | | | | | | Fix the command usage of "btrfs filesystem label" to reflect this change. i.e. so that we can get/set the label of a mounted filesystem against the mountpoint. Signed-off-by: Jie Liu <jeff.liu@oracle.com> Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Merge branch 'cov-fixes-v1-integration-20130201' of ↵Chris Mason2013-02-06
|\ | | | | | | http://git.zabbo.net/cgit/btrfs-progs into merged
| * 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: don't leak fd in resizeZach Brown2013-02-05
| | | | | | | | | | | | | | Argument validation failed to close the fd that was opened. So check the arguments before opening anything. Signed-off-by: Zach Brown <zab@redhat.com>
* | Add basic RAID[56] supportDavid Woodhouse2013-02-01
|/ | | | | | | | | | | | | | | | David Woodhouse originally contributed this code, and Chris Mason changed it around to reflect the current design goals for raid56. The original code expected all metadata and data writes to be full stripes. This meant metadata block size == stripe size, and had a few other restrictions. This version allows metadata blocks smaller than the stripe size. It implements both raid5 and raid6, although it does not have code to rebuild from parity if one of the drives is missing or incorrect. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Move parse_size() to utils.[hc]Goffredo Baroncelli2013-01-17
| | | | | | Move the function from cmds-filesystem.c and mkfs.c to utils.c Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
* btrfs-progs: Fix up memory leakageZhi Yong Wu2012-10-04
| | | | | | | | | | Some code pathes forget to free memory on exit. Changelog from v1: Fix the variable is used uncorrectly. [Ram Pai] Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: Close file descriptor on exitZhi Yong Wu2012-10-04
| | | | | | | Need to close fd on exit. Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: Update resize documentationShawn Bohrer2012-07-03
| | | | | | | | | | | The btrfs filesystem resize command defaults to only resizing the filesystem for devid 1, and must have a devid passed in to resize the filesystem for the other devices in the filesystem. Additionally the documentation lacked information on how to actually resize the underlying partition so this provides a little more detail. Signed-off-by: Shawn Bohrer <shawn.bohrer@gmail.com>
* Btrfs-progs: make btrfs filesystem show <uuid> actually workJosef Bacik2012-07-03
| | | | | | | | The btrfs filesystem show command is only actually searching for labels, it's not searching for UUID's at all. This patch fixes that problem. Thanks, Signed-off-by: Josef Bacik <josef@redhat.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: add 'balance' command group infrastructureIlya Dryomov2012-02-03
| | | | | | | Add balance command group under both 'btrfs' and 'btrfs filesystem'. Preserve the old 'btrfs filesystem balance <path>' behaviour. 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>