Bug 1943850 - Btrfs cannot defrag /home
Summary: Btrfs cannot defrag /home
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: btrfs-progs
Version: rawhide
Hardware: x86_64
OS: Linux
Target Milestone: ---
Assignee: Josef Bacik
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2021-03-27 20:57 UTC by Andrew Thurman
Modified: 2021-03-29 19:08 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2021-03-29 00:06:55 UTC
Type: Bug

Attachments (Terms of Use)
sudo strace -o stracebtrfsfidefrag.txt btrfs filesystem defrag -czstd -rv /home/ output (8.58 KB, text/plain)
2021-03-28 15:28 UTC, Andrew Thurman
no flags Details

System ID Private Priority Status Summary Last Updated
Github kdave btrfs-progs issues 260 0 None open defrag: add options to choose symlink/subvolume follow mode 2021-03-29 19:07:38 UTC

Description Andrew Thurman 2021-03-27 20:57:37 UTC
Description of problem:
When trying to defrag my home and root volumes for transparent compression the `btrfs` command does not defrag /home or /home/, but does defrag /home/$USER

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Run `sudo btrfs filesystem defrag -czstd -rv /home/`

Actual results:
No compression or output

Expected results:
Home directory is compressed, as this command does work with `/`

Additional info:
This can me worked around by running with /home/$USER/ but could be an annoyance on any multi-user system. For example: `sudo btrfs filesystem defrag -czstd -r / /home/andythurman/` works.

[andythurman@rockhopper ~]$ cat /etc/fstab

# /etc/fstab
# Created by anaconda on Sat Nov 28 22:39:37 2020
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
UUID=5a74d1ad-e74b-4e95-b270-35e0f11264f4 /                       btrfs   subvol=root,compress=zstd:1     0 0
UUID=8b5ebc80-af92-4537-89a0-fc1d9df5b790 /boot                   ext4    defaults        1 2
UUID=0CE3-C7A8          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
UUID=5a74d1ad-e74b-4e95-b270-35e0f11264f4 /home                   btrfs   subvol=home,compress=zstd:1     0 0

Comment 1 Chris Murphy 2021-03-28 04:06:21 UTC
Could you run:
sudo strace -o stracebtrfsfidefrag.txt btrfs filesystem defrag -czstd -rv /home/

And attach the file to the bug?

With the identical command:

[chris@fmac ~]$ sudo btrfs filesystem defrag -czstd -rv /home/
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20200709151057
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20200923162236
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20200930210336
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20201006210942
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20201020152157
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20201223104019
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20210106153251
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20210130185517
/home/chris/.mozilla/firefox/Crash Reports/InstallTime20210208183217

Comment 2 Andrew Thurman 2021-03-28 15:28:27 UTC
Created attachment 1767139 [details]
sudo strace -o stracebtrfsfidefrag.txt btrfs filesystem defrag -czstd -rv /home/ output

Comment 3 Chris Murphy 2021-03-28 23:51:10 UTC
> newfstatat(AT_FDCWD, "/home", {st_mode=S_IFLNK|0777, st_size=8, ...}, AT_SYMLINK_NOFOLLOW) = 0

Is this Silverblue? I'm pretty sure /home is a symlink pointing to /var/home. What happens if you point defrag to /var/home?

Comment 4 Andrew Thurman 2021-03-29 00:06:55 UTC
That was it! Weird that it is mounted as `/home` but still needs the funky /var/home thing. Thanks!

Comment 5 Chris Murphy 2021-03-29 00:28:33 UTC
Might still be a bug or missing feature that it doesn't follow symlinks. You could open an upstream bug at https://github.com/kdave//btrfs-progs and cross-reference them, reopening this one for tracking. Include the strace in the upstream bug and ask whether it's intentional to not follow symlinks. The use case is all rpm-ostree installations will do this, maybe there are other examples.

Also can you paste /etc/fstab here? I'm assuming the "home" subvolume is mounted at /var/home, not at /home because / is read-only and I'm pretty sure it's not possible to mount anything on read-only directories, hence the symlink.

Comment 6 Andrew Thurman 2021-03-29 00:42:03 UTC
I included my fstab earlier. That was from an installation of 33. The only thing I changed was the compression argument. I need to go now, but tomorrow I will look more into the Silverblue file system and possibly report that upstream. Thank you again!

Comment 7 Chris Murphy 2021-03-29 01:17:19 UTC
> UUID=5a74d1ad-e74b-4e95-b270-35e0f11264f4 /home                   btrfs   subvol=home,compress=zstd:1     0 0

I guess then that systemd is resolving the /home symlink to /var/home and actually mounts it there; and /proc/mounts shows this.

Comment 8 Chris Murphy 2021-03-29 03:00:27 UTC
Also does the problem happen if you try to defrag /home instead of /home/ ?

Comment 9 Andrew Thurman 2021-03-29 14:30:53 UTC
(In reply to Chris Murphy from comment #8)
> Also does the problem happen if you try to defrag /home instead of /home/ ?


> newfstatat(AT_FDCWD, "/home", {st_mode=S_IFLNK|0777, st_size=9, ...}, AT_SYMLINK_NOFOLLOW) = 0

Comment 10 Andrew Thurman 2021-03-29 18:30:19 UTC
Possibly related: https://github.com/kdave/btrfs-progs/issues/260

Note You need to log in before you can comment on or make changes to this bug.