From 7c4cb50e1a39ada75aaaaaedfdaec52d0b8f8bcc Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Thu, 27 Mar 2025 14:31:08 +0100 Subject: [PATCH] bcachefs: Fix bch2_fs_get_tree() error path When a filesystem is mounted read-only, subsequent attempts to mount it as read-write fail with EBUSY. Previously, the error path in bch2_fs_get_tree() would unconditionally call __bch2_fs_stop(), improperly freeing resources for a filesystem that was still actively mounted. This change modifies the error path to only call __bch2_fs_stop() if the superblock has no valid root dentry, ensuring resources are not cleaned up prematurely when the filesystem is in use. Signed-off-by: Florian Albrechtskirchinger Signed-off-by: Kent Overstreet --- fs/bcachefs/fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c index fbca200f76365..89a30bde12206 100644 --- a/fs/bcachefs/fs.c +++ b/fs/bcachefs/fs.c @@ -2290,7 +2290,8 @@ err_stop_fs: goto err; err_put_super: - __bch2_fs_stop(c); + if (!sb->s_root) + __bch2_fs_stop(c); deactivate_locked_super(sb); goto err; } -- 2.39.5