Skip to content

Commit 8e0fa5d

Browse files
committed
Revert "btrfs: remove BTRFS_INODE_READDIO_NEED_LOCK"
This reverts commit 5f00816. The patch is a simplification after direct IO port to iomap infrastructure, which gets reverted. Signed-off-by: David Sterba <[email protected]>
1 parent f4c48b4 commit 8e0fa5d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

fs/btrfs/btrfs_inode.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum {
2828
BTRFS_INODE_NEEDS_FULL_SYNC,
2929
BTRFS_INODE_COPY_EVERYTHING,
3030
BTRFS_INODE_IN_DELALLOC_LIST,
31+
BTRFS_INODE_READDIO_NEED_LOCK,
3132
BTRFS_INODE_HAS_PROPS,
3233
BTRFS_INODE_SNAPSHOT_FLUSH,
3334
};
@@ -312,6 +313,23 @@ struct btrfs_dio_private {
312313
u8 csums[];
313314
};
314315

316+
/*
317+
* Disable DIO read nolock optimization, so new dio readers will be forced
318+
* to grab i_mutex. It is used to avoid the endless truncate due to
319+
* nonlocked dio read.
320+
*/
321+
static inline void btrfs_inode_block_unlocked_dio(struct btrfs_inode *inode)
322+
{
323+
set_bit(BTRFS_INODE_READDIO_NEED_LOCK, &inode->runtime_flags);
324+
smp_mb();
325+
}
326+
327+
static inline void btrfs_inode_resume_unlocked_dio(struct btrfs_inode *inode)
328+
{
329+
smp_mb__before_atomic();
330+
clear_bit(BTRFS_INODE_READDIO_NEED_LOCK, &inode->runtime_flags);
331+
}
332+
315333
/* Array of bytes with variable length, hexadecimal format 0x1234 */
316334
#define CSUM_FMT "0x%*phN"
317335
#define CSUM_FMT_VALUE(size, bytes) size, bytes

fs/btrfs/inode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4811,7 +4811,10 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
48114811

48124812
truncate_setsize(inode, newsize);
48134813

4814+
/* Disable nonlocked read DIO to avoid the endless truncate */
4815+
btrfs_inode_block_unlocked_dio(BTRFS_I(inode));
48144816
inode_dio_wait(inode);
4817+
btrfs_inode_resume_unlocked_dio(BTRFS_I(inode));
48154818

48164819
ret = btrfs_truncate(inode, newsize == oldsize);
48174820
if (ret && inode->i_nlink) {

0 commit comments

Comments
 (0)