Re: [PATCH] jbd2: skip updating journal superblock on -ESHUTDOWN abort

From: Jan Kara

Date: Tue Dec 01 2026 - 08:17:48 EST


On Tue 01-12-26 20:32:34, Jia Zhu wrote:
> On Tue, Dec 01, 2026 at 11:29:06AM +0100, Jan Kara wrote:
> > Thanks for the fix but I think instead of this special-casing of shutdown,
> > we should just modify jbd2_write_superblock() to properly detect dead
> > device and stop doing IO to it. In fact we have there such check:
> >
> > /* Buffer got discarded which means block device got invalidated */
> > if (!buffer_mapped(bh)) {
> > unlock_buffer(bh);
> > return -EIO;
> > }
> >
> > but it doesn't work for this shutdown path because invalidate_bdev() gets
> > called only after ->mark_dead() callback is done. So just enhance this
> > check to something like:
> >
> > /*
> > * If buffer got discarded or gendisk is dead, the device doesn't
> > * exist anymore.
> > */
> > if (!buffer_mapped(bh) || !disk_live(bh->b_bdev->bd_disk))
>
> Hi Jan,
>
> Thanks for the review!
>
> My concern with !disk_live() in jbd2_write_superblock() is that on an
> orderly removal of a healthy disk, disk_live() becomes false before
> the final sync:
>
> __del_gendisk()
> bdev_unhash(part) /* disk_live() is now false */
> blk_report_disk_dead(disk, false)
> fs_bdev_mark_dead(bdev, false)
> sync_filesystem(sb) /* disk can still do I/O */
> ...
> jbd2_journal_commit_transaction()
> if (JBD2_FLUSHED)
> jbd2_journal_update_sb_log_tail() /* retval ignored */
> jbd2_write_superblock() /* -EIO, no abort */
> /* commit succeeds with on-disk s_start still 0 */
> sb->s_op->shutdown(sb)
>
> Recovery could then treat the journal as empty and skip that transaction.
> (GD_DEAD isn't set until after blk_report_disk_dead() either.)
>
> Checking disk_live() also misses blk_mark_disk_dead() (which doesn't
> unhash part0) and EXT4_IOC_SHUTDOWN(EXT4_GOING_FLAGS_NOLOGFLUSH) on an
> unresponsive device that is still live.

Fair, what I've suggested doesn't work.

> Fixing this in jbd2_journal_abort() instead avoids touching
> jbd2_write_superblock() at all. When the journal has not been aborted
> before, there is no prior error recorded in s_errno, and
> jbd2_journal_update_sb_errno() would only convert -ESHUTDOWN to 0 and
> write 0 again. If an error abort already happened first, the existing
> JBD2_ABORT branch still writes 0 to clear that error.
>
> Would you be OK with keeping the fix in jbd2_journal_abort()?

I'm a bit nervous with skipping the superblock write (the errno update
isn't needed, that's correct, I was more concerned about some other fields
needing to be written back as this is practically their last chance to be
written). But after some more thinking that shouldn't be an issue so I'm ok
with your fix.

Honza
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR