Skip to content

Commit 19e60b2

Browse files
adam900710kdave
authored andcommitted
btrfs: add extra warning if delayed iput is added when it's not allowed
Since I have triggered the ASSERT() on the delayed iput too many times, now is the time to add some extra debug warnings for delayed iput. All delayed iputs should be queued after all ordered extents finish their IO and all involved workqueues are flushed. Thus after the btrfs_run_delayed_iputs() inside close_ctree(), there should be no more delayed puts added. So introduce a new BTRFS_FS_STATE_NO_DELAYED_IPUT, set after the above mentioned timing. And all btrfs_add_delayed_iput() will check that flag and give a WARN_ON_ONCE(). Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 0aaaf10 commit 19e60b2

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

fs/btrfs/disk-io.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4397,6 +4397,8 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
43974397
/* Ordered extents for free space inodes. */
43984398
btrfs_flush_workqueue(fs_info->endio_freespace_worker);
43994399
btrfs_run_delayed_iputs(fs_info);
4400+
/* There should be no more workload to generate new delayed iputs. */
4401+
set_bit(BTRFS_FS_STATE_NO_DELAYED_IPUT, &fs_info->fs_state);
44004402

44014403
cancel_work_sync(&fs_info->async_reclaim_work);
44024404
cancel_work_sync(&fs_info->async_data_reclaim_work);

fs/btrfs/fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ enum {
117117
/* Indicates there was an error cleaning up a log tree. */
118118
BTRFS_FS_STATE_LOG_CLEANUP_ERROR,
119119

120+
/* No more delayed iput can be queued. */
121+
BTRFS_FS_STATE_NO_DELAYED_IPUT,
122+
120123
BTRFS_FS_STATE_COUNT
121124
};
122125

fs/btrfs/inode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,6 +3427,7 @@ void btrfs_add_delayed_iput(struct btrfs_inode *inode)
34273427
if (atomic_add_unless(&inode->vfs_inode.i_count, -1, 1))
34283428
return;
34293429

3430+
WARN_ON_ONCE(test_bit(BTRFS_FS_STATE_NO_DELAYED_IPUT, &fs_info->fs_state));
34303431
atomic_inc(&fs_info->nr_delayed_iputs);
34313432
/*
34323433
* Need to be irq safe here because we can be called from either an irq

0 commit comments

Comments
 (0)