Skip to content

Commit d62922b

Browse files
gShahrKent Overstreet
authored andcommitted
bcachefs: Prevent granting write refs when filesystem is read-only
Fix a shutdown WARNING in bch2_dev_free caused by active write I/O references (ca->io_ref[WRITE]) on a device being freed. The problem occurs when: - The filesystem is marked read-only (BCH_FS_rw clear in c->flags). - A subsequent operation (e.g., error handling for device removal) incorrectly tries to grant write references back to a device. - During final shutdown, the read-only flag causes the system to skip stopping write I/O references (bch2_dev_io_ref_stop(ca, WRITE)). - The leftover active write reference triggers the WARN_ON in bch2_dev_free. Prevent this by checking if the filesystem is read-only before attempting to grant write references to a device in the problematic code path. Ensure consistency between the filesystem state flag and the device I/O reference state during shutdown. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 55fd97f commit d62922b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/bcachefs/super.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,8 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
17571757
up_write(&c->state_lock);
17581758
return 0;
17591759
err:
1760-
if (ca->mi.state == BCH_MEMBER_STATE_rw &&
1760+
if (test_bit(BCH_FS_rw, &c->flags) &&
1761+
ca->mi.state == BCH_MEMBER_STATE_rw &&
17611762
!percpu_ref_is_zero(&ca->io_ref[READ]))
17621763
__bch2_dev_read_write(c, ca);
17631764
up_write(&c->state_lock);

0 commit comments

Comments
 (0)