gfs2_withdraw() doesn't queue the withdraw work before the superblock is born. But gfs2_fill_super() makes the journal live before that and a withdraw can still happen until the mount is done, e.g. from the log or quota daemons or through the withdraw file in sysfs. The withdraw is then never processed and SDF_JOURNAL_LIVE stays set. A later remount to read-only, sysrq u included, goes through gfs2_make_fs_ro() whose log flushes bail out early on the withdrawn filesystem and then gfs2_quota_cleanup() hits its BUG_ON(). So queue the withdraw work from gfs2_reconfigure() and wait for it before going read-only. The work can't run twice so guard the queueing with a new SDF_WITHDRAW_QUEUED bit. Fixes: 9c4a3de6cd5b ("gfs2: Asynchronous withdraw") Cc: stable@vger.kernel.org Signed-off-by: Christian Brauner (Amutable) --- fs/gfs2/incore.h | 1 + fs/gfs2/ops_fstype.c | 5 +++++ fs/gfs2/util.c | 9 ++++++++- fs/gfs2/util.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 49cc232942a29..151458e90480b 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -605,6 +605,7 @@ enum { SDF_KILL = 15, SDF_EVICTING = 16, SDF_FROZEN = 17, + SDF_WITHDRAW_QUEUED = 18, }; #define GFS2_FSNAME_LEN 256 diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 6ec47376aecf2..3bd5702535dfe 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -1590,6 +1590,11 @@ static int gfs2_reconfigure(struct fs_context *fc) if ((sb->s_flags ^ fc->sb_flags) & SB_RDONLY) { if (fc->sb_flags & SB_RDONLY) { + /* gfs2_withdraw() doesn't queue the work during mount. */ + if (gfs2_withdrawn(sdp)) { + gfs2_queue_withdraw(sdp); + flush_work(&sdp->sd_withdraw_work); + } gfs2_make_fs_ro(sdp); } else { error = gfs2_make_fs_rw(sdp); diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 529c3ec37a18a..5558af374994a 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -238,6 +238,13 @@ void gfs2_withdraw_func(struct work_struct *work) fs_err(sdp, "file system withdrawn\n"); } +/* The withdraw work must only run once. */ +void gfs2_queue_withdraw(struct gfs2_sbd *sdp) +{ + if (!test_and_set_bit(SDF_WITHDRAW_QUEUED, &sdp->sd_flags)) + schedule_work(&sdp->sd_withdraw_work); +} + void gfs2_withdraw(struct gfs2_sbd *sdp) { if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW || @@ -253,7 +260,7 @@ void gfs2_withdraw(struct gfs2_sbd *sdp) if (!(sdp->sd_vfs->s_flags & SB_BORN)) return; fs_err(sdp, "about to withdraw this file system\n"); - schedule_work(&sdp->sd_withdraw_work); + gfs2_queue_withdraw(sdp); return; } diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index ffcc47d6b0b4b..78690fe76cfeb 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -195,5 +195,6 @@ void gfs2_lm(struct gfs2_sbd *sdp, const char *fmt, ...); void gfs2_withdraw_func(struct work_struct *work); void gfs2_withdraw(struct gfs2_sbd *sdp); +void gfs2_queue_withdraw(struct gfs2_sbd *sdp); #endif /* __UTIL_DOT_H__ */ -- 2.53.0