summaryrefslogtreecommitdiff
path: root/cmds-filesystem.c
Commit message (Collapse)AuthorAge
* btrfs-progs: move command definitions to commands.hDavid Sterba2017-08-24
| | | | | | | There are some trivial helpers, we can group the command declarations in one place. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move help defines to own headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce kernel sizes to cleanup large intermediate numberQu Wenruo2017-03-08
| | | | | | | | | | | Large numbers like (1024 * 1024 * 1024) may cost reader/reviewer to waste one second to convert to 1G. Introduce kernel include/linux/sizes.h to replace any intermediate number larger than 4096 (not including 4096) to SZ_*. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: defrag: remove v1 ioctl supportDavid Sterba2017-01-25
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: defrag: force using v2 defrag ioctl and make default 32M ↵David Sterba2017-01-25
| | | | | | | | | | | | threshold actually work A user reported on IRC that the new 32M default for target extent size does not work. This happens because if there are no commandline options, the v1 ioctl is used that does not do any fine grained defrag. As the v2 ioctl has been introduced 6 years ago (2010, kernel 2.6.33) we won't keep backward compatibility anymore. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: defrag: warn when deframgenting directories without -rDavid Sterba2016-12-14
| | | | | | | | The current implementaion of defrag ioctl on directoreis does not do what users expect. The -r needs to be specified, but we should also print a warning to avoid confusion. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: defrag: cleanup temporary errno valueDavid Sterba2016-12-14
| | | | | | | Rename a single letter variable and move the defintion to the scope of use. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: recursive defrag cleanup duplicate codeAnand Jain2016-12-14
| | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove extra newline from messagesDavid Sterba2016-12-14
| | | | | | The common message helpers add the newline. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename btrfs_scan_lblkid() to btrfs_scan_devices()Karel Zak2016-10-25
| | | | | | | | | It seems like bad idea to use a library name (lblkid) within generic function name. The currently used scanning library is implementation detail and this detail should be hidden for rest of the code. Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: constify string arguments where appropriateDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use standard allocation functions in non-kenrel codeDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: defrag: set errno correctly in the callbackDavid Sterba2016-09-21
| | | | | | | | | | | In case defrag fails, the errno is not properly reported everywhere but rather the last value of 'e', which could be 0. Then we get confusing error messages like: ERROR: defrag failed on /path/to/file: Success Reported-by: Adam Mizerski <adam@mizerski.pl> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: make superblock reading/scanning api more genericDavid Sterba2016-08-24
| | | | | | We'll add more modes that affect scanning. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fi defrag: change default extent target size to 32 MiBDavid Sterba2016-07-28
| | | | | | | The kernel default is too low, 32 MiB is recommended and should give better results. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: do not set optind if not necessaryDavid Sterba2016-07-13
| | | | | | | In the subcommand callbacks that are called just once, we don't need to explicitly reset optind. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fi show: print error message if no valid Btrfs is specifiedSatoru Takeuchi2016-06-24
| | | | | | | | | | | | | | | | | | | | | | | | * Before this patch =============================== # ./btrfs fi show foo # "foo" doesn't mean any valid Btrfs # # no error message # echo $? 1 =============================== * After this patch =============================== # ./btrfs fi show foo ERROR: foo is not a valid Btrfs # # echo $? 1 =============================== Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fi resize: fix parsing of negative argumentDavid Sterba2016-06-17
| | | | | | | | | The cleanup of option parsing caused a regression where the negative resize argument is recognized as short options and the command fails. Use the new helper to allow that. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=119971 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Check if the FSID was seen by comparing full UUIDYauhen Kharuzhy2016-05-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | is_seen_fsid() uses simple hash to check if FS was seen before at walking on FS list in 'filesystem show' command: hash key is first byte of the UUID. This function doesn't check full UUID then, so, if there are two FS with same first byte in UUIDs exist, only one will be shown: root@test:~# btrfs fi show Label: 'System' uuid: 688cb918-7bac-4c8e-9b11-8d047eb14cf4 Total devices 2 FS bytes used 1.76GiB devid 1 size 3.46TiB used 4.01GiB path /dev/sda2 devid 2 size 6.91TiB used 4.01GiB path /dev/sdb2 Global spare root@test:~# grep btrfs /proc/mounts /dev/sda2 / btrfs rw,relatime,space_cache,subvolid=256,subvol=/root 0 0 /dev/sdc /media/688cb918-7bac-4c8e-9b11-8d047eb14cf4 btrfs rw,relatime,space_cache,subvolid=5,subvol=/ 0 0 root@test:~# btrfs fi show --all-devices Label: 'System' uuid: 688cb918-7bac-4c8e-9b11-8d047eb14cf4 Total devices 2 FS bytes used 1.76GiB devid 1 size 3.46TiB used 4.03GiB path /dev/sda2 devid 2 size 6.91TiB used 4.01GiB path /dev/sdb2 Label: 'test' uuid: 683b1a80-ca7f-4c4d-b87b-7155401a4d18 Total devices 7 FS bytes used 2.06MiB devid 1 size 7.28TiB used 1.57GiB path /dev/sdc devid 2 size 7.28TiB used 1.57GiB path /dev/sdd devid 3 size 7.28TiB used 1.57GiB path /dev/sde devid 4 size 7.28TiB used 1.57GiB path /dev/sdf devid 5 size 7.28TiB used 1.57GiB path /dev/sdg devid 6 size 7.28TiB used 1.57GiB path /dev/sdh devid 7 size 7.28TiB used 1.57GiB path /dev/sdi To resolve this collision, search for full FSID in the list of seen filesystems. Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fi sync: make it silent by defaultDavid Sterba2016-05-02
| | | | | | Report only errors returned by the ioctl. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix resource leak during device scanningDavid Sterba2016-03-15
| | | | | | | The dev info is leaked each time we find a known filesystem. Resolves-coverity-id: 1127098 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Fix a regression that btrfs filesystem label doesn't workSatoru Takeuchi2016-03-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The number of arguments which is allowed to pass became wrong from the following commit. commit 176aeca9a148c5e29de0 ("btrfs-progs: add getopt stubs where needed") * actual result =========================================================== # ./btrfs prop get /btrfs label label=foo # ./btrfs fi label /btrfs btrfs filesystem label: too few arguments usage: btrfs filesystem label [<device>|<mount_point>] [<newlabel>] Get or change the label of a filesystem With one argument, get the label of filesystem on <device>. If <newlabel> is passed, set the filesystem label to <newlabel>. # ./btrfs fi label /btrfs bar foo # ./btrfs prop get /btrfs label label=foo =========================================================== * expected result =========================================================== # ./btrfs prop get /btrfs label label=foo # ./btrfs fi label /btrfs foo # ./btrfs fi label /btrfs bar # ./btrfs prop get /btrfs label label=bar =========================================================== Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add new option for specify chunk root bytenrLu Fengqi2016-03-14
| | | | | | | | | | Add new btrfsck option, '--chunk-root', to specify chunk root bytenr. And allow open_ctree_fs_info() function accept chunk_root_bytenr to override the bytenr in superblock. This will be mainly used when chunk tree corruption. Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add getopt stubs where neededDavid Sterba2016-03-14
| | | | | | | | | Commands that do not take any options do not use getopt, which means the standard option separator "--" does not work. Update all command handlers that need it, argv needs to be referenced using the optind that is correctly pointed after the separator. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: filesystem: add 'du' commandMark Fasheh2016-03-14
| | | | | | | | | | | | | | | | | 'btrfs du' differs from regular du in that it will work to resolve which blocks are shared between files in its list. This gives the user a more accurate bytecount from which they can make decisions regarding management of their file space. We still print a total number of bytes counted (like regular du), but also print the number of bytes which were found to have been shared amongst the file set provided. From there it becomes trivial to calculate how much space is exclusively owned. Signed-off-by: Mark Fasheh <mfasheh@suse.de> [ rename files to reflect the filesystem command group, add GPL v2 file headers ] 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: remove unnecessary errno temp variablesDavid Sterba2016-01-12
| | | | | | | We can read errno directly if it's not clobbered by any intermediate calls. Signed-off-by: David Sterba <dsterba@suse.com>
* 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>