• Qu Wenruo's avatar
    btrfs: make clear_cache mount option to rebuild FST without disabling it · 1d6a4fc8
    Qu Wenruo authored
    Previously clear_cache mount option would simply disable free-space-tree
    feature temporarily then re-enable it to rebuild the whole free space
    tree.
    
    But this is problematic for block-group-tree feature, as we have an
    artificial dependency on free-space-tree feature.
    
    If we go the existing method, after clearing the free-space-tree
    feature, we would flip the filesystem to read-only mode, as we detect a
    super block write with block-group-tree but no free-space-tree feature.
    
    This patch would change the behavior by properly rebuilding the free
    space tree without disabling this feature, thus allowing clear_cache
    mount option to work with block group tree.
    
    Now we can mount a filesystem with block-group-tree feature and
    clear_mount option:
    
      $ mkfs.btrfs  -O block-group-tree /dev/test/scratch1  -f
      $ sudo mount /dev/test/scratch1 /mnt/btrfs -o clear_cache
      $ sudo dmesg -t | head -n 5
      BTRFS info (device dm-1): force clearing of disk cache
      BTRFS info (device dm-1): using free space tree
      BTRFS info (device dm-1): auto enabling async discard
      BTRFS info (device dm-1): rebuilding free space tree
      BTRFS info (device dm-1): checking UUID tree
    
    CC: stable@vger.kernel.org # 6.1+
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    1d6a4fc8
disk-io.c 145 KB