summaryrefslogtreecommitdiff
path: root/cmds-filesystem.c
Commit message (Collapse)AuthorAge
* btrfs-progs: cmd filesystem: switch to common error message wrapperDavid Sterba2016-01-12
| | | | | | Message texts were adjusted. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use on-stack buffer for dev_to_fsidDavid Sterba2015-11-13
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused parameter from print_one_fsDavid Sterba2015-11-06
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: don't print version info from embedded subcommandsDavid Sterba2015-11-06
| | | | | | The version is provided by 'btrfs --version'. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: simplify empty stirngs checkDavid Sterba2015-11-06
| | | | | | We can do a strlen(str) == 0 in a simpler way. 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: fix uninitialized copy of btrfs_fs_devices listAnand Jain2015-11-02
| | | | | | | | | | | | | Noticed that at print_one_uuid() some of the members of btrfs_fs_devices contained some junk values. It took a while to dig this further, and found that we make a local copy of the btrfs_fs_devices list at search_umounted_fs_uuids() and wasn't initialized properly. Fixed using using calloc instead of malloc. Signed-off-by: Anand Jain <anand.jain@oracle.com> [ switched to calloc ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: filesystem: use btrfs_open_dir for btrfs filesystem 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: # (/mnt/tmp is not btrfs mountpoint) # # btrfs filesystem df /mnt/tmp ERROR: couldn't get space info - Inappropriate ioctl for device ERROR: get_df failed Inappropriate ioctl for device # After patch: # ./btrfs filesystem df /mnt/tmp ERROR: not btrfs filesystem: /mnt/tmp # Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: optimize not to scan repeated fsid mount pointsAnand Jain2015-10-07
| | | | | | | | | | | | | | | | | | | | | | | | fsid can be mounted multiple times, with different subvolid. And we don't have to scan a mount point if we already have that in the scanned list. And thus nicely avoids the following warning with multiple subvol mounts on older kernel like 2.6.32 where BTRFS_IOC_GET_FSLABEL ioctl does not exist. ./btrfs fi show -m Label: none uuid: 31845933-611e-422d-ae6f-386e57ad81aa Total devices 2 FS bytes used 172.00KiB devid 1 size 3.00GiB used 642.38MiB path /dev/sdd devid 2 size 3.00GiB used 622.38MiB path /dev/sde warning, device 2 is missing warning devid 2 not found already warning, device 2 is missing warning devid 2 not found already Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix double free during scanningDavid Sterba2015-10-02
| | | | | | | | | | If there are different devices mounted to the same directory we can run into double free issue in the scanning code and this can lead to a crash. The dev_info_arg buffer allocation get_fs_info might be skipped, eg. if the FS_INFO ioctl fails due to EPERM in older kernels. Reset the pointer before each loop starts. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctlAnand Jain2015-10-02
| | | | | | | | | | | | | Old kernels before 3.9 do not provide ioctl BTRFS_IOC_GET_FSLABEL. So we need to provide a fail safe logic for btrfs-progs running on those kernel. In this patch when get_label_mounted() fails on the old kernel it will fail back to the old method and uses get_label_unmounted(), where it will read from the disk directly. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use common unit parser for btrfs filesystem commandZhao Lei2015-09-01
| | | | | | | | | | Move to use get_unit_mode_from_arg() for cmds-filesystem.c, to make "btrfs filesystem df/show/usage"'s unit argument same. Also have cleanup effect: 19 insertions(+), 181 deletions(-) Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Accurate errormsg for resize operation on no-enouth-free-space caseZhao Lei2015-08-31
| | | | | | | | | | | | | | | | | | | btrfs progs output following error message when doing resize on no-enouth-free-space case: # btrfs filesystem resize +10g /mnt/btrfs_5gb Resize '/mnt/btrfs_5gb' of '+10g' ERROR: unable to resize '/mnt/btrfs_5gb' - File too large # It is not a good description for users, and this patch changed it to: # ./btrfs filesystem resize +10G /mnt/tmp1 Resize '/mnt/tmp1' of '+10G' ERROR: unable to resize '/mnt/tmp1' - no enouth free space # Reported-by: Taeha Kim <kthguru@gmail.com> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: defrag: remove unused variablePatrik Lundquist2015-08-31
| | | | | | | A leftover from when recursive defrag was added. Signed-off-by: Patrik Lundquist <patrik.lundquist@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: defrag: fix threshold overflow againPatrik Lundquist2015-08-31
| | | | | | | | | | | | | | | | Commit dedb1ebeee847e3c4d71e14d0c1077887630e44a broke commit 96cfbbf0ea9fce7ecaa9e03964474f407f6e76ab. Casting thresh value greater than (u32)-1 simply truncates bits while desired value is (u32)-1 for max defrag threshold. I.e. "btrfs fi defrag -t 4g" is trimmed/truncated to 0 and "-t 5g" to 1073741824. Also added a missing newline. Signed-off-by: Patrik Lundquist <patrik.lundquist@gmail.com> 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: move min-resize implementation to inspect-internalDavid Sterba2015-08-31
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* Btrfs-progs: add feature to get mininum size for resizing a fs/deviceFilipe Manana2015-08-31
| | | | | | | | | | | | | | | | | | | Currently there is not way for a user to know what is the minimum size a device of a btrfs filesystem can be resized to. Sometimes the value of total allocated space (sum of all allocated chunks/device extents), which can be parsed from 'btrfs filesystem show' and 'btrfs filesystem usage', works as the minimum size, but sometimes it does not, namely when device extents have to relocated to holes (unallocated space) within the new size of the device (the total allocated space sum). This change adds the ability to reliably compute such minimum value and extents 'btrfs filesystem resize' with the following syntax to get such value: btrfs filesystem resize [devid:]get_min_size Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: replace struct cmd_group->hidden with flagsOmar Sandoval2015-06-26
| | | | | | | | We're also going to want to support aliases, so rather than adding another member, replace "hidden" with a "flags" member. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: doc: update defrag pageDavid Sterba2015-06-26
| | | | | | | - update wording for -t - add optional argument to -c Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: defrag, check target extent earlierDavid Sterba2015-06-25
| | | | | | Print a warning if the target extent size (option -t) is larger than 4G. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix defrag threshold overflowPatrik Lundquist2015-06-25
| | | | | | | | btrfs fi defrag -t 1T overflows the u32 thresh variable and default, instead of max, threshold is used. Signed-off-by: Patrik Lundquist <patrik.lundquist@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Allow "filesystem show" command to handle different unitsQu Wenruo2015-06-22
| | | | | | | | | | Now "filesystem show" command can handle different units now. This is handy for higher level programs to get accurate output from "fi show" command. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.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: 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: report failure when resize ioctl failsZygo Blaxell2015-04-24
| | | | | | | | | | | | | | | | | The BTRFS_IOC_RESIZE ioctl returns 0 on success, negative for POSIX errors, and positive for btrfs-specific errors. If resize fails with a btrfs-specific error, decode the error and report it. If we can't decode the error, report its numeric value so that the userspace tool is not instantly useless when a new error code is defined in the kernel. Exit with non-zero status on any resize error. This is very important for scripts that will shrink the underlying storage when btrfs reports success! Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org 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: fi resize: accept only directories as pathsDavid Sterba2015-04-22
| | | | | | | | Resize of a filesystem image does not work as expected. This has been confusing and can have bad consequences as people have reported, resizing the wrong filesystem. 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: autoconf: use standard PACKAGE_* macrosKarel Zak2015-01-28
| | | | | | | | | | | | | - use standard PACKAGE_{NAME,VERSION,STRING,URL,...} autoconf macros rather than homemade BTRFS_BUILD_VERSION - don't #include version.h, now the file is necessary for library API only Note that "btrfs version" returns "btrfs-progs <version>" instead of the original confusing "btrfs <version>". Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: drop feature defines from C files, in favour of CFLAGS definesDimitri John Ledkov2015-01-27
| | | | | | | | | | | | | | | | | | | | | | glibc 2.10+ (5+ years old) enables all the desired features: _XOPEN_SOURCE 700, __XOPEN2K8, POSIX_C_SOURCE, DEFAULT_SOURCE; with a single _GNU_SOURCE define in the makefile alone. For portability to other libc implementations (e.g. dietlibc) _XOPEN_SOURCE=700 is also defined. This also resolves Debian bug report filed by Michael Tautschnig - "Inconsistent use of _XOPEN_SOURCE results in conflicting declarations". Whilst I was not able to reproduce the results, the reported fact is that _XOPEN_SOURCE set to 500 in one set of files (e.g. cmds-filesystem.c) generates/defines different struct stat from other files (cmds-replace.c). This patch thus cleans up all feature defines, and sets them at a consistent level. Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=747969 Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com> 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: make getopt tables static constDavid Sterba2015-01-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Fix wrong return value when executing 'fi show' on umounted device.Qu Wenruo2015-01-14
| | | | | | | | | | | | | | | | When executing 'btrfs fi show' on unmounted device, even no problem happens, the return value is still 1 not 0. The problem lies in search_umounted_fs_uuids(), where when it finds the given uuid, it should return 1, but later uuid copy overwrites the return value, causing it always return 0 under that case. Fix it by pass found as pointer, and return value only indicates whether anything wrong happens, whether found or not is stored in the new parameter. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix minor leak of dev_info in btrfs_scan_kernelDavid Sterba2014-12-30
| | | | | Resolves-coverity-id: 1127098 Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fi show, don't leak canonical pathDavid Sterba2014-12-30
| | | | | Resolves-coverity-id: 1260252 Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move check_arg_type() to util.cGui Hecheng2014-12-29
| | | | | | | | | The check_arg_type() function does quite generic thing, move it to utils.c. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Fix btrfs fi show by uuid and labelJustin Maggard2014-12-29
| | | | | | | | | | | | | | | | Commit 8be2fff (btrfs-progs: apply realpath for btrfs fi show when mount point is given) changed the behavior of btrfs fi show to return an error if the call to realpath() failed. This broke the ability to specify a filesystem by uuid or label. So let's not consider a failed call to realpath() as an error. If the user really specified a bad device, just return nothing like we did before. Signed-off-by: Justin Maggard <jmaggard10@gmail.com> Reviewed-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup: avoid to use literal for getopt valSatoru Takeuchi2014-12-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: skip fs with no seed when build seed/sprout mapping for fi showGui Hecheng2014-12-04
| | | | | | | | | | | There is no need to try to build seed/sprout mapping for those btrfs without seed devices, so just skip such fs. We could get the total number of devices from the disk super block, if it equals the number of items in list @fs_devices->devices, then there shouldn't be any seed devices. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: make the search target device routine more clear for fi showGui Hecheng2014-12-04
| | | | | | | | Extract the procedure of searching for a target device for fi show from the @map_seed_devices() function to make it more clear. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add original 'df' and rename 'disk_usage' to 'usage'David Sterba2014-12-04
| | | | | | | | | Add back the original output of the 'btrfs fi df' command for backward compatibility. The rich output is moved from 'disk_usage' to 'usage'. Agreed in http://www.spinics.net/lists/linux-btrfs/msg31698.html Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add command btrfs filesystem disk-usageGoffredo Baroncelli2014-12-04
| | | | | Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Enhance the command btrfs filesystem dfGoffredo Baroncelli2014-12-04
| | | | | | | | | | Enhance the command "btrfs filesystem df" to show space usage information for a mount point(s). It shows also an estimation of the space available, on the basis of the current one used. Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> [code moved under #if 0 instead of deletion] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move group type and profile pretty printers to utilsDavid Sterba2014-12-04
| | | | | | Move and add the btrfs_ prefix. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: apply realpath for btrfs fi show when mount point is givenGui Hecheng2014-11-27
| | | | | | | | | | | | | | | | For now, # btrfs fi show /mnt/btrfs gives info correctly, while # btrfs fi show /mnt/btrfs/ gives nothing. This implies that the @realpath() function should be applied to unify the behavior. Made a more clear comment right above the call as well. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> 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: use the correct SI prefixesDavid Sterba2014-11-04
| | | | | | The SI standard defines lowercase 'k' and uppercase for the rest. Signed-off-by: David Sterba <dsterba@suse.cz>