When ino is BTRFS_EMPTY_SUBVOL_DIR_OBJECTID, the item is not referred to
any file-tree. So lookup_path_rootid() doesn't return any meaningful
value.
As was reported, this can be triggered by
$ btrfs sub create test1
$ btrfs sub create test1/test2
$ btrfs sub snap test1 test1.snap
$ btrfs fi du -s test1
Total Exclusive Set shared Filename
0.00B 0.00B 0.00B test1
$ btrfs fi du -s test1.snap
Total Exclusive Set shared Filename
ERROR: cannot check space of 'test1.snap': Inappropriate ioctl for device
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.com>
In du_walk_dir(), when du_add_file() returns an error it is usually
ignored. However if the error is returned querying the last item, the
error is returned to the caller.
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.com>
The FIEMAP_EXTENT_SHARED fiemap flag was introduced in 2.6.33. If the
headers do not provide the definition, the build will fail. The support
of the fiemap sharing depends on the running kernel. There are still
systems with 2.6.32 kernel headers but running newer versions.
To support such environment, don't fail build, provide own defintion of
the structure and detect if there's an old kernel in use in the relevant
command (btrfs fi du).
Reported-by: Abhay Sachan <lkp.abhay@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
'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>
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>
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>
'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>