OSDN Git Service

btrfs: trigger orphan inode cleanup during START_SYNC ioctl
authorQu Wenruo <wqu@suse.com>
Thu, 11 May 2023 23:42:05 +0000 (07:42 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 19 Jun 2023 11:59:26 +0000 (13:59 +0200)
There is an internal error report that scrub found an error in an orphan
inode's data.

However there are very limited ways to cleanup such orphan inodes:

- btrfs_start_pre_rw_mount()
  This happens at either mount, or RO->RW switch.
  This is not a viable solution for root fs which may not be unmounted
  or RO mounted.

  Furthermore this doesn't cover every subvolume, it only covers the
  currently cached subvolumes.

- btrfs_lookup_dentry()
  This happens when we first lookup the subvolume dentry.
  But dentry can be cached thus it's not ensured to be triggered every
  time.

- create_snapshot()
  This only happens for the created snapshot, not the source one.

This means if we didn't trigger orphan items cleanup, there is really no
other way to manually trigger it. Add this step to the START_SYNC ioctl.
This is a slight change in the semantics of the ioctl but as sync can be
potentially slow and is usually paired with WAIT_SYNC ioctl.

The errors are not handled because the main point of the ioctl is the
async commit, orphan cleanup is a side effect.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c

index df7603c..edbbd5c 100644 (file)
@@ -3112,6 +3112,13 @@ static noinline long btrfs_ioctl_start_sync(struct btrfs_root *root,
        struct btrfs_trans_handle *trans;
        u64 transid;
 
+       /*
+        * Start orphan cleanup here for the given root in case it hasn't been
+        * started already by other means. Errors are handled in the other
+        * functions during transaction commit.
+        */
+       btrfs_orphan_cleanup(root);
+
        trans = btrfs_attach_transaction_barrier(root);
        if (IS_ERR(trans)) {
                if (PTR_ERR(trans) != -ENOENT)