gfs2 filesystem and dlm development
 help / color / mirror / Atom feed
* [PATCH] gfs2: wait for bio in gfs2_write_log_header
@ 2026-11-26 22:44 Andreas Gruenbacher
  2026-11-26 22:55 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Gruenbacher @ 2026-11-26 22:44 UTC (permalink / raw)
  To: gfs2; +Cc: Andreas Gruenbacher

During journal recovery, clean_journal() calls gfs2_write_log_header(),
which allocates a page from gfs2_page_pool, puts that page in a bio, and
submits the bio.  If a subsequent step in gfs2_fill_super() fails after
journal replay, or a read-only mount that replayed a journal is
unmounted (where gfs2_put_super() skips gfs2_make_fs_ro()), the journal
glock can get dropped before the bio completes.  Also, if the module is
immediately removed, gfs2_page_pool can get destroyed before the page is
freed.

This very unlikely race was pointed out by Sashiko.

Fix by moving the call to log_flush_wait() from log_write_header() to
gfs2_write_log_header().

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/gfs2/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 1baaaf30c4fa..db40045ee2d0 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -908,6 +908,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 	gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock,
 		       REQ_OP_WRITE | op_flags);
 	gfs2_log_submit_write(&jd->jd_log_bio);
+	log_flush_wait(sdp);
 }
 
 /**
@@ -935,7 +936,6 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
 			      sdp->sd_log_flush_tail, sdp->sd_log_flush_head,
 			      flags, op_flags);
 	gfs2_log_incr_head(sdp);
-	log_flush_wait(sdp);
 	log_pull_tail(sdp);
 	gfs2_log_update_head(sdp);
 }
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gfs2: wait for bio in gfs2_write_log_header
  2026-11-26 22:44 [PATCH] gfs2: wait for bio in gfs2_write_log_header Andreas Gruenbacher
@ 2026-11-26 22:55 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26 22:55 UTC (permalink / raw)
  To: Andreas Gruenbacher, gfs2

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] gfs2: early withdraw returns in gfs2_write_log_header() skip
  log_flush_wait()
- [Low] gfs2: missing Fixes: trailer for commit 4a3d049db42b in commit
  message
--

commit 189e12a17911781cb0db12a8bd02ce7d201fa367
Author: Andreas Gruenbacher <agruenba@redhat.com>

> gfs2: wait for bio in gfs2_write_log_header
>
> During journal recovery, clean_journal() calls gfs2_write_log_header(),
> which allocates a page from gfs2_page_pool, puts that page in a bio, and
> submits the bio.  If a subsequent step in gfs2_fill_super() fails after
> journal replay, or a read-only mount that replayed a journal is
> unmounted (where gfs2_put_super() skips gfs2_make_fs_ro()), the journal
> glock can get dropped before the bio completes.  Also, if the module is
> immediately removed, gfs2_page_pool can get destroyed before the page is
> freed.
>
> This very unlikely race was pointed out by Sashiko.
>
> Fix by moving the call to log_flush_wait() from log_write_header() to
> gfs2_write_log_header().
>
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>

[Severity: Low]
Should this include a Fixes tag for the commit that moved log_flush_wait()
out of gfs2_write_log_header()?

  Fixes: 4a3d049db42b ("gfs2: Don't wait for journal flush in clean_journal")

> diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
> index 1baaaf30c4fa6..db40045ee2d0a 100644
> --- a/fs/gfs2/log.c
> +++ b/fs/gfs2/log.c
> @@ -908,6 +908,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
>  	gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock,
>  		       REQ_OP_WRITE | op_flags);
>  	gfs2_log_submit_write(&jd->jd_log_bio);
> +	log_flush_wait(sdp);
>  }
>  
>  /**
> @@ -935,7 +936,6 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
>  			      sdp->sd_log_flush_tail, sdp->sd_log_flush_head,
>  			      flags, op_flags);
>  	gfs2_log_incr_head(sdp);
> -	log_flush_wait(sdp);
>  	log_pull_tail(sdp);
>  	gfs2_log_update_head(sdp);
>  }

[Severity: Medium]
Can moving log_flush_wait(sdp) to the bottom of gfs2_write_log_header()
leave transaction payload bios in flight when the filesystem withdraws?

__gfs2_log_flush() submits payload bios through lops_before_commit() and
gfs2_log_submit_write() before calling log_write_header().  If the
filesystem withdraws before gfs2_write_log_header() reaches
gfs2_log_submit_write() (or if gfs2_get_extent() fails there), the early
returns in gfs2_write_log_header() bypass log_flush_wait(sdp):

fs/gfs2/log.c:gfs2_write_log_header() {
	...
	if (gfs2_withdrawn(sdp))
		return;
	...
		ret = gfs2_get_extent(jd->jd_inode, lblock, &dblock, &extlen);
		if (gfs2_assert_withdraw(sdp, ret == 0))
			return;
	...
}

Before 4a3d049db42b ("gfs2: Don't wait for journal flush in
clean_journal"), the gfs2_withdrawn(sdp) check jumped to an out label that
still called log_flush_wait(sdp).  Without that wait, __gfs2_log_flush()
finishes while earlier payload bios are still in flight, allowing unmount
and module removal to free sdp and destroy gfs2_page_pool before
gfs2_end_log_write() runs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126224415.3049791-1-agruenba@redhat.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26 22:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 22:44 [PATCH] gfs2: wait for bio in gfs2_write_log_header Andreas Gruenbacher
2026-11-26 22:55 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox