summaryrefslogtreecommitdiff
path: root/cmds-fi-disk_usage.c
Commit message (Collapse)AuthorAge
* btrfs-progs: fi usage, fix reporting space for degraded mountsDavid Sterba2015-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | The total size of devices was summed from raw partition size which is wrong in two ways: - if the device is missing, the size is 0 and it mismatches the size summed from chunks, leading to bogus numbers like Device unallocated: 16.00EiB Used: 1.88TiB Free (estimated): 8.00EiB (min: 8.00EiB) - we should really account the device size that's occupied by btrfs, not the real partition size altough it's the same most of the time The sum of missing devices is now printed in the summary and any missing device path is replaced with 'missing' instead of blank: Data,RAID1: Size:972.00GiB, Used:962.15GiB 972.00GiB /dev/sdb1 972.00GiB Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=94911 Reported-by: <raffix@web.de> 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: cleanup: avoid to use literal for getopt valSatoru Takeuchi2014-12-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: fi 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: fi usage, change option for tabular output to TDavid Sterba2014-12-17
| | | | | | We're going to use -t for tera- units prefix, same as 'fi df' does. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: rework calculations of fi usageDavid Sterba2014-12-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch reworks the basic calculations of 'fi usage'. It does not address all problems but should make the code more prepared to do so. The original code tries to estimate the free space that could lead to negative numbers for some raid profiles: Data, RAID1: total=147.00GiB, used=141.92GiB System, RAID1: total=32.00MiB, used=36.00KiB Metadata, RAID1: total=2.00GiB, used=1.17GiB GlobalReserve, single: total=404.00MiB, used=0.00B Overall: Device size: 279.46GiB Device allocated: 298.06GiB Device unallocated: 16.00EiB Used: 286.18GiB Free (estimated): 8.00EiB (min: 8.00EiB) Data ratio: 2.00 Metadata ratio: 2.00 Global reserve: 404.00MiB (used: 0.00B) Eg. "Device size" - "Device allocated" = negative number or a very large positive, hence the EiB values. There are logical and raw numbers multiplied by ratios mixed together, so the new code makes it explicit which kind is being used. The data and metadata ratios are calculated separately. Output after this patch will look like: Overall: Device size: 558.92GiB Device allocated: 298.06GiB Device unallocated: 260.86GiB Used: 286.18GiB Free (estimated): 135.51GiB (min: 135.51GiB) Data ratio: 2.00 Metadata ratio: 2.00 Global reserve: 404.00MiB (used: 0.00B) Data,RAID1: Size:147.00GiB, Used:141.92GiB /dev/sdc 147.00GiB /dev/sdd 147.00GiB Metadata,RAID1: Size:2.00GiB, Used:1.17GiB /dev/sdc 2.00GiB /dev/sdd 2.00GiB System,RAID1: Size:32.00MiB, Used:36.00KiB /dev/sdc 32.00MiB /dev/sdd 32.00MiB Unallocated: /dev/sdc 130.43GiB /dev/sdd 130.43GiB Changes: * Device size is now the raw size, same for the following three * Free is the logical size * Max/min were reduced to just min Filesystem Size Used Avail Use% Mounted on /dev/sdc 280G 144G 141G 51% /mnt/sdc The difference between Avail and Free is there because userspace tool does a different guesswork than kernel. Issues not addressed by this patch: * RAID56 profiles are not handled * mixed profiles are not handled Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix improper output msg for btrfs-fi-usageGui Hecheng2014-12-04
| | | | | | | | | | | | | | | | | | | | | | | | Even if run as root: # su # btrfs file usage <path> <== path exits outside the mnt point We get the output: WARNING: ..., run as root WARNING: ..., run as root ERROR:... It is because in load_chunk_info, the errno of ioctl is not judged but rather the ret value of ioctl is judged. And the ret value of ioctl is -1 which happens to match -EPERM exactly. So the outer warning is printed. Just judge the errno of ioctl and prevent the ret value of load_chunk_info to be -1 in other error conditions. For load_device_info, the problem and fix is the same. After the fix, the 'run as root' WARNINGs will not show up in this condition. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: output the correct path when fi-usage failedGui Hecheng2014-12-04
| | | | | | | | | | | | | | When we exec the following cmd: # btrfs file usage -t <path> <-- an invalid path output: # ERROR´╝Ü can't access '-t' should be: # ERROR: can't access 'path' Just replace the static 'argv[1]' with 'argv[i]'. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix wrong data ratio for raid56 in btrfs-file-usageGui Hecheng2014-12-04
| | | | | | | | | | | | | | | | | | | | | | | When run btrfs-file-usage on a btrfs with data profile raid5/6, the output message for "Free" & "Data to device ratio" seems wrong as follows: ... Device size: 100.00GiB Device allocated: 2.04GiB Device unallocated: 97.96GiB Used: 1.12MiB Free (Estimated): 197.89GiB <== Free > Device size Data to device ratio: 198 % <== > 100% Global reserve: 0.00B ... It is because the function get_raid56_used() is not iterating the chunk_info array correctly, it is just repeating adding the first chunk_info statistics. Just add a ptr to iterate over the array. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: hide FS occupied from device usage outputDavid Sterba2014-12-04
| | | | | | | | | | The term has not seen an agreement and we don't want to change it once it's in non-development branches or even released. Discussion under the patch: http://thread.gmane.org/gmane.comp.file-systems.btrfs/34627 Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move global reserve to overall summaryDavid Sterba2014-12-04
| | | | | | | | | | | | | | | | | It looks confusing among the chunks, it is not in fact a chunk type. Sample: Overall: Device size: 35.00GiB Device allocated: 8.07GiB Device unallocated: 26.93GiB Used: 1.12MiB Free (Estimated): 17.57GiB (Max: 30.98GiB, min: 17.52GiB) Data to device ratio: 50 % Global reserve: 16.00MiB (used: 0.00B) ... 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: add section of overall filesystem usageDavid Sterba2014-12-04
| | | | | | | | | | | | | | | | | The 'fi usage' lacks an overall report, this used to be in the enhanced df command. Add it back. Sample: Overall: Device size: 35.00GiB Device allocated: 8.07GiB Device unallocated: 26.93GiB Used: 1.12MiB Free (Estimated): 17.57GiB (Max: 30.98GiB, min: 17.52GiB) Data to device ratio: 50 % ... 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: zero out structures before calling ioctlDavid Sterba2014-12-04
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: check if we can't get info from ioctls due to permissionsDavid Sterba2014-12-04
| | | | | | | The TREE_SEARCH ioctl is root-only, FS_INFO will be available for non-root users with an updated kernel, let the user know. 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 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: fi usage: free memory if realloc failsRakesh Pandit2014-12-04
| | | | | | | | | Lets not assign *info_ptr to 0 before calling free on it and lose track of already allocated memory if realloc fails in add_info_to_list. Lets call free first. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Fix memleak in get_raid56_used()Qu Wenruo2014-12-04
| | | | | | | Fix memleak in get_raid56_used(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup dead return after usage() for fi-disk_usageGui Hecheng2014-12-04
| | | | | | | The usage() calls exit() internally, so remove the return after it. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> 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: 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>