Skip to content

Commit 1f4bb82

Browse files
author
Kent Overstreet
committed
bcachefs: Fix bch2_seek_hole() locking
We can't call bch2_seek_pagecache_hole(), and block on page locks, with btree locks held. This is easily fixed because we're at the end of the transaction - we can just unlock, we don't need a drop_locks_do(). Reported-by: https://github.com/nagalun Signed-off-by: Kent Overstreet <[email protected]>
1 parent 2dd202d commit 1f4bb82

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

fs/bcachefs/fs-io.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -999,17 +999,19 @@ static loff_t bch2_seek_hole(struct file *file, u64 offset)
999999
POS(inode->v.i_ino, offset >> 9),
10001000
POS(inode->v.i_ino, U64_MAX),
10011001
inum.subvol, BTREE_ITER_slots, k, ({
1002-
if (k.k->p.inode != inode->v.i_ino) {
1002+
if (k.k->p.inode != inode->v.i_ino ||
1003+
!bkey_extent_is_data(k.k)) {
1004+
loff_t start_offset = k.k->p.inode == inode->v.i_ino
1005+
? max(offset, bkey_start_offset(k.k) << 9)
1006+
: offset;
1007+
loff_t end_offset = k.k->p.inode == inode->v.i_ino
1008+
? MAX_LFS_FILESIZE
1009+
: k.k->p.offset << 9;
1010+
1011+
bch2_trans_unlock(trans);
10031012
next_hole = bch2_seek_pagecache_hole(&inode->v,
1004-
offset, MAX_LFS_FILESIZE, 0, false);
1013+
start_offset, end_offset, 0, false);
10051014
break;
1006-
} else if (!bkey_extent_is_data(k.k)) {
1007-
next_hole = bch2_seek_pagecache_hole(&inode->v,
1008-
max(offset, bkey_start_offset(k.k) << 9),
1009-
k.k->p.offset << 9, 0, false);
1010-
1011-
if (next_hole < k.k->p.offset << 9)
1012-
break;
10131015
} else {
10141016
offset = max(offset, bkey_start_offset(k.k) << 9);
10151017
}

0 commit comments

Comments
 (0)