Commit Graph

15 Commits

Author SHA1 Message Date
David Sterba 4a16608150 btrfs-progs: fi du: improved error handling in mark_inode_seen
The callchain handles errors, don't crash on unexpected condition.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 11:33:14 +02:00
David Sterba 44af5de2f3 btrfs-progs: fi du: catch bogus extent lengths
If we get a zero-length from the ioctl for whatever reason, we should
not crash.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 11:33:04 +02:00
David Sterba f551548372 btrfs-progs: do not set optind if not necessary
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>
2016-07-13 19:41:55 +02:00
Wang Shilong 419334be80 btrfs-progs: du: fix to skip not btrfs dir/file
'btrfs file du' is a very useful tool to watch my system
file usage information with snapshot aware.

when trying to run following commands:
[root@localhost btrfs-progs]# btrfs file du /
     Total   Exclusive  Set shared  Filename
ERROR: Failed to lookup root id - Inappropriate ioctl for device
ERROR: cannot check space of '/': Unknown error -1

and My Filesystem looks like this:
[root@localhost btrfs-progs]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs   16G     0   16G   0% /dev
tmpfs          tmpfs      16G  368K   16G   1% /dev/shm
tmpfs          tmpfs      16G  1.4M   16G   1% /run
tmpfs          tmpfs      16G     0   16G   0% /sys/fs/cgroup
/dev/sda3      btrfs      60G   19G   40G  33% /
tmpfs          tmpfs      16G  332K   16G   1% /tmp
/dev/sdc       btrfs     2.8T  166G  1.7T   9% /data
/dev/sda2      xfs       2.0G  452M  1.6G  23% /boot
/dev/sda1      vfat      1.9G   11M  1.9G   1% /boot/efi
tmpfs          tmpfs     3.2G   24K  3.2G   1% /run/user/1000

So I installed Btrfs as my root partition, but boot partition
can be other fs.

We can Let btrfs tool aware of this is not a btrfs file or
directory and skip those files, so that someone like me
could just run 'btrfs file du /' to scan all btrfs filesystems.

After patch, it will look like:
   Total   Exclusive  Set shared  Filename
     0.00B       0.00B           -  //root/.bash_logout
     0.00B       0.00B           -  //root/.bash_profile
     0.00B       0.00B           -  //root/.bashrc
     0.00B       0.00B           -  //root/.cshrc
     0.00B       0.00B           -  //root/.tcshrc

This works for me to analysis system usage and analysis
performaces.

Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-13 18:44:52 +02:00
Nicholas D Steeves bd2cc320af btrfs-progs: typo review of strings and comments
Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba 9971f00edd btrfs-progs: fi du: switch to negative error codes
We're using the kernel-style negative error numbers.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-11 15:53:15 +02:00
Austin S. Hemmelgarn 1c36022fe7 btrfs-progs: fix fi du so it works in more cases
Currently, btrfs fi du uses open_file_or_dir(), which tries to open
it's argument with O_RDWR.  Because of POSIX semantics, this fails for
non-root users when the file is read-only or is an executable that
is being run currently, or for all users (including root) when the
filesystem is read-only.  This results in a somewhat confusing 'Unknown
error -1' message when trying to check such files.  Switch to using
open_file_or_dir3() with O_RDONLY passed in the flags, as this avoids
the limitations listed above, and we have no need to write to the files
anyway (and thus shouldn't be opening them writable).

Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:22:53 +02:00
Alexander Fougner f7fb93d558 btrfs-progs: fi du: fix incorrect column order
Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 14:29:26 +01:00
David Sterba 4685a56081 btrfs-progs: fi du: make the output more aligned
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-15 19:00:57 +01:00
David Sterba b44d130828 btrfs-progs: fi du: update help text
Move the command-specific options to the beginning, add missing long
option.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-15 18:25:05 +01:00
David Sterba d66d44eacb btrfs-progs: switch more error messages to common helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba aad4b1f081 btrfs-progs: fi du: add long options for units
Drop -h, add just the common long options for now.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba 54dea513c6 btrfs-progs: fi du: switch to u64
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
Mark Fasheh bc23667bd2 btrfs-progs: fi du: Calculate space shared by each directory arguments file set
Here we define each file set as those found by a recursive search of a
single directory argument to btrfs fi du.

This isn't as simple as adding up shared extents - they may be shared with
each other, and may also overlap. This patch uses an interval tree to store
shared extents we find while fiemapping files. After collecting them, a 'set
shared' count is calculated by summing (without overlap) each shared region
discovered. This is then displayed to the user as 'set shared'.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
Mark Fasheh a2e7ff1eae btrfs-progs: filesystem: add 'du' command
'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>
2016-03-14 13:42:47 +01:00