Skip to contentSkip to conversation

jbd2: add mutex_lock on j_checkpoint_mutex in jbd2_journal_flush

PATCH Ben Hutchings 3 participants 4 messages Sep 27, 2015 – Oct 3, 2015 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1668256.Geort4rEnn@zealot

#1 lore raw
Quoted 4 lines · Bartosz Kwitniewski

Commit a3ceb22921615827bfed39d7612a9a370bff0edb (upstream 79feb521a44705262d15cc819a4117a447b11ea7) in 3.2.x tree introduced __jbd2_update_log_tail which requires j_checkpoint_mutex, but locking of j_checkpoint_mutex in jbd2_journal_flush was not backported from upstream.

Oops.

Quoted 41 lines

Fixes kernel BUG at fs/jbd2/journal.c:832 (__jbd2_update_log_tail):
[] ? jbd2_cleanup_journal_tail+0x5d/0x61 [jbd2]
[] ? jbd2_journal_flush+0xc2/0x156 [jbd2]
[] ? ext4_freeze+0x2f/0x71 [ext4]
[] ? filemap_write_and_wait+0x26/0x32
[] ? freeze_super+0x8c/0xdd
[] ? freeze_bdev+0x5b/0xa1
[] ? start_cow_session+0xb3/0x2d6 [hcpdriver]
[] ? printk+0x40/0x49
[] ? alloc_cts_session+0x2e/0x33 [hcpdriver]
[] ? ioctl_start_hcp_session+0x131/0x20d [hcpdriver]
[] ? handle_ioctlStartHC2+0x95/0x1ab [hcpdriver]
[] ? cow_ioctl_unlocked+0x13/0x18 [hcpdriver]
[] ? do_vfs_ioctl+0x55a/0x5a9
[] ? pax_randomize_kstack+0x4c/0x60
[] ? sysret_check+0x20/0x62
[] ? do_sys_open+0x11e/0x130
[] ? sys_ioctl+0x3c/0x5f
[] ? system_call_fastpath+0x16/0x1b

---

jbd2/journal.c> renamed from jbd2/journal.c.orig> +4 -1
@@ -1828,10 +1828,13 @@ int jbd2_journal_flush(journal_t *journa
 > 	> if (is_journal_aborted(journal))
 > 	> 	> return -EIO;
 
+> 	> mutex_lock(&journal->j_checkpoint_mutex);
 > 	> if (!err) {
 > 	> 	> err = jbd2_cleanup_journal_tail(journal);
-> 	> 	> if (err < 0)
+> 	> 	> if (err < 0) {
+> 	> 	> 	> mutex_unlock(&journal->j_checkpoint_mutex);
 > 	> 	> 	> goto out;
+> 	> 	> }
 > 	> 	> err = 0;
 > 	> }
 

jbd2/journal.c> int jbd2_journal_flush(journal_t *journa · line 1850

Quoted 7 lines
jbd2/journal.c> renamed from jbd2/journal.c.orig> +1 -0
@@ -1841,6 +1844,7 @@ int jbd2_journal_flush(journal_t *journa
 > 	>  * commits of data to the journal will restore the current
 > 	>  * s_start value. */
 > 	> jbd2_mark_journal_empty(journal);
+> 	> mutex_unlock(&journal->j_checkpoint_mutex);
 > 	> write_lock(&journal->j_state_lock);
 > 	> J_ASSERT(!journal->j_running_transaction);
 > 	> J_ASSERT(!journal->j_committing_transaction);

Why is it sufficient to add locking of j_checkpoint_mutex only in this one function?

Shouldn't I cherry-pick commits 24bcc89c7e7c ("jbd2: split updating of journal superblock and marking journal empty") and a78bb11d7acd ("jbd2:
protect all log tail updates with j_checkpoint_mutex") as well?

Ben.

Signature · 2 lines
Ben Hutchings
I say we take off; nuke the site from orbit.  It's the only way to be sure.
#2 lore raw
Quoted 73 lines · Ben Hutchings
Quoted 4 lines · Bartosz Kwitniewski

Commit a3ceb22921615827bfed39d7612a9a370bff0edb (upstream 79feb521a44705262d15cc819a4117a447b11ea7) in 3.2.x tree introduced __jbd2_update_log_tail which requires j_checkpoint_mutex, but locking of j_checkpoint_mutex in jbd2_journal_flush was not backported from upstream.

Oops.

Quoted 58 lines

Fixes kernel BUG at fs/jbd2/journal.c:832 (__jbd2_update_log_tail):
[] ? jbd2_cleanup_journal_tail+0x5d/0x61 [jbd2]
[] ? jbd2_journal_flush+0xc2/0x156 [jbd2]
[] ? ext4_freeze+0x2f/0x71 [ext4]
[] ? filemap_write_and_wait+0x26/0x32
[] ? freeze_super+0x8c/0xdd
[] ? freeze_bdev+0x5b/0xa1
[] ? start_cow_session+0xb3/0x2d6 [hcpdriver]
[] ? printk+0x40/0x49
[] ? alloc_cts_session+0x2e/0x33 [hcpdriver]
[] ? ioctl_start_hcp_session+0x131/0x20d [hcpdriver]
[] ? handle_ioctlStartHC2+0x95/0x1ab [hcpdriver]
[] ? cow_ioctl_unlocked+0x13/0x18 [hcpdriver]
[] ? do_vfs_ioctl+0x55a/0x5a9
[] ? pax_randomize_kstack+0x4c/0x60
[] ? sysret_check+0x20/0x62
[] ? do_sys_open+0x11e/0x130
[] ? sys_ioctl+0x3c/0x5f
[] ? system_call_fastpath+0x16/0x1b

---

jbd2/journal.c> renamed from jbd2/journal.c.orig> +5 -1
@@ -1828,10 +1828,13 @@ int jbd2_journal_flush(journal_t *journa
 
 > 	> if (is_journal_aborted(journal))
 > 	> 
 > 	> 	> return -EIO;
 
+> 	> mutex_lock(&journal->j_checkpoint_mutex);
 
 > 	> if (!err) {
 > 	> 
 > 	> 	> err = jbd2_cleanup_journal_tail(journal);
 
-> 	> 	> if (err < 0)
+> 	> 	> if (err < 0) {
+> 	> 	> 	> mutex_unlock(&journal->j_checkpoint_mutex);
 
 > 	> 	> 	> goto out;
 
+> 	> 	> }
 
 > 	> 	> err = 0;
 > 	> 
 > 	> }
@@ -1841,6 +1844,7 @@ int jbd2_journal_flush(journal_t *journa
 
 > 	>  * commits of data to the journal will restore the current
 > 	>  * s_start value. */
 > 	> 
 > 	> jbd2_mark_journal_empty(journal);
 
+> 	> mutex_unlock(&journal->j_checkpoint_mutex);
Quoted 3 lines
Quoted 3 lines
	> write_lock(&journal->j_state_lock);
	> J_ASSERT(!journal->j_running_transaction);
	> J_ASSERT(!journal->j_committing_transaction);

Why is it sufficient to add locking of j_checkpoint_mutex only in this one function?

Quoted 5 lines

Shouldn't I cherry-pick commits 24bcc89c7e7c ("jbd2: split updating of journal superblock and marking journal empty") and a78bb11d7acd ("jbd2:
protect all log tail updates with j_checkpoint_mutex") as well?

Ben.

Hello!

That's right, locking of j_checkpoint_mutex only in jbd2_journal_flush() is not enough. I have rushed with this patch without doing a deeper analysis, I'm sorry.

Signature · 1 line
Bartosz Kwitniewski
#3 lore raw
In reply to Ben Hutchings
Quoted 60 lines · Ben Hutchings
Quoted 4 lines · Bartosz Kwitniewski

Commit a3ceb22921615827bfed39d7612a9a370bff0edb (upstream 79feb521a44705262d15cc819a4117a447b11ea7) in 3.2.x tree introduced __jbd2_update_log_tail which requires j_checkpoint_mutex, but locking of j_checkpoint_mutex in jbd2_journal_flush was not backported from upstream.

Oops.

Quoted 41 lines

Fixes kernel BUG at fs/jbd2/journal.c:832 (__jbd2_update_log_tail):
[] ? jbd2_cleanup_journal_tail+0x5d/0x61 [jbd2]
[] ? jbd2_journal_flush+0xc2/0x156 [jbd2]
[] ? ext4_freeze+0x2f/0x71 [ext4]
[] ? filemap_write_and_wait+0x26/0x32
[] ? freeze_super+0x8c/0xdd
[] ? freeze_bdev+0x5b/0xa1
[] ? start_cow_session+0xb3/0x2d6 [hcpdriver]
[] ? printk+0x40/0x49
[] ? alloc_cts_session+0x2e/0x33 [hcpdriver]
[] ? ioctl_start_hcp_session+0x131/0x20d [hcpdriver]
[] ? handle_ioctlStartHC2+0x95/0x1ab [hcpdriver]
[] ? cow_ioctl_unlocked+0x13/0x18 [hcpdriver]
[] ? do_vfs_ioctl+0x55a/0x5a9
[] ? pax_randomize_kstack+0x4c/0x60
[] ? sysret_check+0x20/0x62
[] ? do_sys_open+0x11e/0x130
[] ? sys_ioctl+0x3c/0x5f
[] ? system_call_fastpath+0x16/0x1b

---

jbd2/journal.c> renamed from jbd2/journal.c.orig> +4 -1
@@ -1828,10 +1828,13 @@ int jbd2_journal_flush(journal_t *journa
 > 	> if (is_journal_aborted(journal))
 > 	> 	> return -EIO;
 
+> 	> mutex_lock(&journal->j_checkpoint_mutex);
 > 	> if (!err) {
 > 	> 	> err = jbd2_cleanup_journal_tail(journal);
-> 	> 	> if (err < 0)
+> 	> 	> if (err < 0) {
+> 	> 	> 	> mutex_unlock(&journal->j_checkpoint_mutex);
 > 	> 	> 	> goto out;
+> 	> 	> }
 > 	> 	> err = 0;
 > 	> }
 

jbd2/journal.c> int jbd2_journal_flush(journal_t *journa · line 1850

Quoted 7 lines
jbd2/journal.c> renamed from jbd2/journal.c.orig> +1 -0
@@ -1841,6 +1844,7 @@ int jbd2_journal_flush(journal_t *journa
 > 	>  * commits of data to the journal will restore the current
 > 	>  * s_start value. */
 > 	> jbd2_mark_journal_empty(journal);
+> 	> mutex_unlock(&journal->j_checkpoint_mutex);
 > 	> write_lock(&journal->j_state_lock);
 > 	> J_ASSERT(!journal->j_running_transaction);
 > 	> J_ASSERT(!journal->j_committing_transaction);

Why is it sufficient to add locking of j_checkpoint_mutex only in this one function?

Quoted 3 lines

Shouldn't I cherry-pick commits 24bcc89c7e7c ("jbd2: split updating of journal superblock and marking journal empty") and a78bb11d7acd ("jbd2:
protect all log tail updates with j_checkpoint_mutex") as well?

Just to confirm, I agree these two commits are the ones you should cherry-pick for commit 79feb521a44705262d15cc819a4117a447b11ea7 from upstream to work correctly.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#4 lore raw
Quoted 61 lines · Jan Kara
Quoted 60 lines · Ben Hutchings
Quoted 4 lines · Bartosz Kwitniewski

Commit a3ceb22921615827bfed39d7612a9a370bff0edb (upstream 79feb521a44705262d15cc819a4117a447b11ea7) in 3.2.x tree introduced __jbd2_update_log_tail which requires j_checkpoint_mutex, but locking of j_checkpoint_mutex in jbd2_journal_flush was not backported from upstream.

Oops.

Quoted 41 lines

Fixes kernel BUG at fs/jbd2/journal.c:832 (__jbd2_update_log_tail):
[] ? jbd2_cleanup_journal_tail+0x5d/0x61 [jbd2]
[] ? jbd2_journal_flush+0xc2/0x156 [jbd2]
[] ? ext4_freeze+0x2f/0x71 [ext4]
[] ? filemap_write_and_wait+0x26/0x32
[] ? freeze_super+0x8c/0xdd
[] ? freeze_bdev+0x5b/0xa1
[] ? start_cow_session+0xb3/0x2d6 [hcpdriver]
[] ? printk+0x40/0x49
[] ? alloc_cts_session+0x2e/0x33 [hcpdriver]
[] ? ioctl_start_hcp_session+0x131/0x20d [hcpdriver]
[] ? handle_ioctlStartHC2+0x95/0x1ab [hcpdriver]
[] ? cow_ioctl_unlocked+0x13/0x18 [hcpdriver]
[] ? do_vfs_ioctl+0x55a/0x5a9
[] ? pax_randomize_kstack+0x4c/0x60
[] ? sysret_check+0x20/0x62
[] ? do_sys_open+0x11e/0x130
[] ? sys_ioctl+0x3c/0x5f
[] ? system_call_fastpath+0x16/0x1b

---

jbd2/journal.c> > > > renamed from jbd2/journal.c.orig> > > > +4 -1
@@ -1828,10 +1828,13 @@ int jbd2_journal_flush(journal_t *journa
 > > > > 	> > > > if (is_journal_aborted(journal))
 > > > > 	> > > > > > > 	> > > > return -EIO;
 
+> > > > 	> > > > mutex_lock(&journal->j_checkpoint_mutex);
 > > > > 	> > > > if (!err) {
 > > > > 	> > > > > > > 	> > > > err = jbd2_cleanup_journal_tail(journal);
-> > > > 	> > > > > > > 	> > > > if (err < 0)
+> > > > 	> > > > > > > 	> > > > if (err < 0) {
+> > > > 	> > > > > > > 	> > > > > > > 	> > > > mutex_unlock(&journal->j_checkpoint_mutex);
 > > > > 	> > > > > > > 	> > > > > > > 	> > > > goto out;
+> > > > 	> > > > > > > 	> > > > }
 > > > > 	> > > > > > > 	> > > > err = 0;
 > > > > 	> > > > }
 

jbd2/journal.c> > > > int jbd2_journal_flush(journal_t *journa · line 1850

Quoted 7 lines
jbd2/journal.c> > > > renamed from jbd2/journal.c.orig> > > > +1 -0
@@ -1841,6 +1844,7 @@ int jbd2_journal_flush(journal_t *journa
 > > > > 	> > > >  * commits of data to the journal will restore the current
 > > > > 	> > > >  * s_start value. */
 > > > > 	> > > > jbd2_mark_journal_empty(journal);
+> > > > 	> > > > mutex_unlock(&journal->j_checkpoint_mutex);
 > > > > 	> > > > write_lock(&journal->j_state_lock);
 > > > > 	> > > > J_ASSERT(!journal->j_running_transaction);
 > > > > 	> > > > J_ASSERT(!journal->j_committing_transaction);

Why is it sufficient to add locking of j_checkpoint_mutex only in this one function?

Quoted 2 lines
Quoted 2 lines

Shouldn't I cherry-pick commits 24bcc89c7e7c ("jbd2: split updating of journal superblock and marking journal empty")

I actually applied that one already.

Quoted 6 lines
Quoted 2 lines

and a78bb11d7acd ("jbd2:
protect all log tail updates with j_checkpoint_mutex") as well?

Just to confirm, I agree these two commits are the ones you should cherry-pick for commit 79feb521a44705262d15cc819a4117a447b11ea7 from upstream to work correctly.

So here's the series of 3 patches as applied/queued to 3.2.

Ben.

Signature · 2 lines
Ben Hutchings
compatible: Gracefully accepts erroneous data from any source

From: Jan Kara <[email protected]>
Date: Tue, 13 Mar 2012 15:41:04 -0400
Subject: jbd2: split updating of journal superblock and marking journal empty

commit 24bcc89c7e7c64982e6192b4952a0a92379fc341 upstream.

There are three case of updating journal superblock. In the first case, we want to mark journal as empty (setting s_sequence to 0), in the second case we want to update log tail, in the third case we want to update s_errno. Split these cases into separate functions. It makes the code slightly more straightforward and later patches will make the distinction even more important.

[bwh: Prerequisite for "jbd2: fix ocfs2 corrupt when updating journal
superblock fails".
Backported to 3.2: drop changes to trace events.]

---

fs/jbd2/checkpoint.c +1 -1
@@ -550,7 +550,7 @@ int jbd2_cleanup_journal_tail(journal_t
 	    (journal->j_flags & JBD2_BARRIER))
 		blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL);
 	if (!(journal->j_flags & JBD2_ABORT))
-		jbd2_journal_update_superblock(journal, 1);
+		jbd2_journal_update_sb_log_tail(journal);
 	return 0;
 }
 
fs/jbd2/commit.c +1 -1
@@ -340,7 +340,7 @@ void jbd2_journal_commit_transaction(jou
 	/* Do we need to erase the effects of a prior jbd2_journal_flush? */
 	if (journal->j_flags & JBD2_FLUSHED) {
 		jbd_debug(3, "super block updated\n");
-		jbd2_journal_update_superblock(journal, 1);
+		jbd2_journal_update_sb_log_tail(journal);
 	} else {
 		jbd_debug(3, "superblock not updated\n");
 	}
fs/jbd2/journal.c +94 -67

230 lines not on this page · raw message

include/linux/jbd2.h +1 -1
@@ -1083,7 +1083,7 @@ extern int	   jbd2_journal_destroy    (j
 extern int	   jbd2_journal_recover    (journal_t *journal);
 extern int	   jbd2_journal_wipe       (journal_t *, int);
 extern int	   jbd2_journal_skip_recovery	(journal_t *);
-extern void	   jbd2_journal_update_superblock	(journal_t *, int);
+extern void	   jbd2_journal_update_sb_log_tail	(journal_t *);
 extern void	   __jbd2_journal_abort_hard	(journal_t *);
 extern void	   jbd2_journal_abort      (journal_t *, int);
 extern int	   jbd2_journal_errno      (journal_t *);

From: Jan Kara <[email protected]>
Date: Tue, 13 Mar 2012 15:43:04 -0400
Subject: jbd2: protect all log tail updates with j_checkpoint_mutex

commit a78bb11d7acd525623c6a0c2ff4e213d527573fa upstream.

There are some log tail updates that are not protected by j_checkpoint_mutex. Some of these are harmless because they happen during startup or shutdown but updates in jbd2_journal_commit_transaction() and jbd2_journal_flush() can really race with other log tail updates (e.g. someone doing jbd2_journal_flush() with someone running jbd2_cleanup_journal_tail()). So protect all log tail updates with j_checkpoint_mutex.

[bwh: Backported to 3.2:
- Adjust context
- Add unlock on the error path in jbd2_journal_flush()]

Cc Bartosz Kwitniewski <[email protected]>
---
 fs/jbd2/commit.c  |  2 ++
 fs/jbd2/journal.c | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
fs/jbd2/commit.c +2 -0
@@ -340,6 +340,7 @@ void jbd2_journal_commit_transaction(jou
 	/* Do we need to erase the effects of a prior jbd2_journal_flush? */
 	if (journal->j_flags & JBD2_FLUSHED) {
 		jbd_debug(3, "super block updated\n");
+		mutex_lock(&journal->j_checkpoint_mutex);
 		/*
 		 * We hold j_checkpoint_mutex so tail cannot change under us.
 		 * We don't need any special data guarantees for writing sb
@@ -350,6 +351,7 @@ void jbd2_journal_commit_transaction(jou
 						journal->j_tail_sequence,
 						journal->j_tail,
 						WRITE_SYNC);
+		mutex_unlock(&journal->j_checkpoint_mutex);
 	} else {
 		jbd_debug(3, "superblock not updated\n");
 	}
fs/jbd2/journal.c +19 -4
@@ -1242,6 +1242,8 @@ static int journal_reset(journal_t *jour
 			journal->j_errno);
 		journal->j_flags |= JBD2_FLUSHED;
 	} else {
+		/* Lock here to make assertions happy... */
+		mutex_lock(&journal->j_checkpoint_mutex);
 		/*
 		 * Update log tail information. We use WRITE_FUA since new
 		 * transaction will start reusing journal space and so we
@@ -1252,6 +1254,7 @@ static int journal_reset(journal_t *jour
 						journal->j_tail_sequence,
 						journal->j_tail,
 						WRITE_FUA);
+		mutex_unlock(&journal->j_checkpoint_mutex);
 	}
 	return jbd2_journal_start_thread(journal);
 }
@@ -1314,6 +1317,7 @@ int jbd2_journal_update_sb_log_tail(jour
 	journal_superblock_t *sb = journal->j_superblock;
 	int ret;
 
+	BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
 	jbd_debug(1, "JBD2: updating superblock (start %lu, seq %u)\n",
 		  tail_block, tail_tid);
 
@@ -1344,6 +1348,7 @@ static void jbd2_mark_journal_empty(jour
 {
 	journal_superblock_t *sb = journal->j_superblock;
 
+	BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
 	read_lock(&journal->j_state_lock);
 	jbd_debug(1, "JBD2: Marking journal as empty (seq %d)\n",
 		  journal->j_tail_sequence);
@@ -1577,9 +1582,11 @@ int jbd2_journal_destroy(journal_t *jour
 	spin_unlock(&journal->j_list_lock);
 
 	if (journal->j_sb_buffer) {
-		if (!is_journal_aborted(journal))
+		if (!is_journal_aborted(journal)) {
+			mutex_lock(&journal->j_checkpoint_mutex);
 			jbd2_mark_journal_empty(journal);
-		else
+			mutex_unlock(&journal->j_checkpoint_mutex);
+		} else
 			err = -EIO;
 		brelse(journal->j_sb_buffer);
 	}
@@ -1828,10 +1835,13 @@ int jbd2_journal_flush(journal_t *journa
 	if (is_journal_aborted(journal))
 		return -EIO;
 
+	mutex_lock(&journal->j_checkpoint_mutex);
 	if (!err) {
 		err = jbd2_cleanup_journal_tail(journal);
-		if (err < 0)
+		if (err < 0) {
+			mutex_unlock(&journal->j_checkpoint_mutex);
 			goto out;
+		}
 		err = 0;
 	}
 
@@ -1841,6 +1851,7 @@ int jbd2_journal_flush(journal_t *journa
 	 * commits of data to the journal will restore the current
 	 * s_start value. */
 	jbd2_mark_journal_empty(journal);
+	mutex_unlock(&journal->j_checkpoint_mutex);
 	write_lock(&journal->j_state_lock);
 	J_ASSERT(!journal->j_running_transaction);
 	J_ASSERT(!journal->j_committing_transaction);
@@ -1882,8 +1893,12 @@ int jbd2_journal_wipe(journal_t *journal
 		write ? "Clearing" : "Ignoring");
 
 	err = jbd2_journal_skip_recovery(journal);
-	if (write)
+	if (write) {
+		/* Lock to make assertions happy... */
+		mutex_lock(&journal->j_checkpoint_mutex);
 		jbd2_mark_journal_empty(journal);
+		mutex_unlock(&journal->j_checkpoint_mutex);
+	}
 
  no_recovery:
 	return err;

From: Jan Kara <[email protected]>
Date: Tue, 13 Mar 2012 22:22:54 -0400
Subject: jbd2: issue cache flush after checkpointing even with internal
journal

commit 79feb521a44705262d15cc819a4117a447b11ea7 upstream.

When we reach jbd2_cleanup_journal_tail(), there is no guarantee that checkpointed buffers are on a stable storage - especially if buffers were written out by jbd2_log_do_checkpoint(), they are likely to be only in disk's caches. Thus when we update journal superblock effectively removing old transaction from journal, this write of superblock can get to stable storage before those checkpointed buffers which can result in filesystem corruption after a crash. Thus we must unconditionally issue a cache flush before we update journal superblock in these cases.

A similar problem can also occur if journal superblock is written only in disk's caches, other transaction starts reusing space of the transaction cleaned from the log and power failure happens. Subsequent journal replay would still try to replay the old transaction but some of it's blocks may be already overwritten by the new transaction. For this reason we must use WRITE_FUA when updating log tail and we must first write new log tail to disk and update in-memory information only after that.

[bwh: Prerequisite for "jbd2: fix ocfs2 corrupt when updating journal
superblock fails".
Backported to 3.2:
- Adjust context
- Drop changes to jbd2_journal_update_sb_log_tail trace event]

---

fs/jbd2/checkpoint.c +12 -63

91 lines not on this page · raw message

fs/jbd2/commit.c +10 -1
@@ -340,7 +340,16 @@ void jbd2_journal_commit_transaction(jou
 	/* Do we need to erase the effects of a prior jbd2_journal_flush? */
 	if (journal->j_flags & JBD2_FLUSHED) {
 		jbd_debug(3, "super block updated\n");
-		jbd2_journal_update_sb_log_tail(journal);
+		/*
+		 * We hold j_checkpoint_mutex so tail cannot change under us.
+		 * We don't need any special data guarantees for writing sb
+		 * since journal is empty and it is ok for write to be
+		 * flushed only with transaction commit.
+		 */
+		jbd2_journal_update_sb_log_tail(journal,
+						journal->j_tail_sequence,
+						journal->j_tail,
+						WRITE_SYNC);
 	} else {
 		jbd_debug(3, "superblock not updated\n");
 	}
fs/jbd2/journal.c +116 -20

191 lines not on this page · raw message

fs/jbd2/recovery.c +4 -1
@@ -21,6 +21,7 @@
 #include <linux/jbd2.h>
 #include <linux/errno.h>
 #include <linux/crc32.h>
+#include <linux/blkdev.h>
 #endif
 
 /*
@@ -265,7 +266,9 @@ int jbd2_journal_recover(journal_t *jour
 	err2 = sync_blockdev(journal->j_fs_dev);
 	if (!err)
 		err = err2;
-
+	/* Make sure all replayed data is on permanent storage */
+	if (journal->j_flags & JBD2_BARRIER)
+		blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL);
 	return err;
 }
 
include/linux/jbd2.h +5 -1
@@ -972,6 +972,9 @@ extern void __journal_clean_data_list(tr
 /* Log buffer allocation */
 extern struct journal_head * jbd2_journal_get_descriptor_buffer(journal_t *);
 int jbd2_journal_next_log_block(journal_t *, unsigned long long *);
+int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid,
+			      unsigned long *block);
+void __jbd2_update_log_tail(journal_t *journal, tid_t tid, unsigned long block);
 
 /* Commit management */
 extern void jbd2_journal_commit_transaction(journal_t *);
@@ -1083,7 +1086,8 @@ extern int	   jbd2_journal_destroy    (j
 extern int	   jbd2_journal_recover    (journal_t *journal);
 extern int	   jbd2_journal_wipe       (journal_t *, int);
 extern int	   jbd2_journal_skip_recovery	(journal_t *);
-extern void	   jbd2_journal_update_sb_log_tail	(journal_t *);
+extern void	   jbd2_journal_update_sb_log_tail	(journal_t *, tid_t,
+				unsigned long, int);
 extern void	   __jbd2_journal_abort_hard	(journal_t *);
 extern void	   jbd2_journal_abort      (journal_t *, int);
 extern int	   jbd2_journal_errno      (journal_t *);
include/trace/events/jbd2.h +1 -1
@@ -200,7 +200,7 @@ TRACE_EVENT(jbd2_checkpoint_stats,
 		  __entry->forced_to_close, __entry->written, __entry->dropped)
 );
 
-TRACE_EVENT(jbd2_cleanup_journal_tail,
+TRACE_EVENT(jbd2_update_log_tail,
 
 	TP_PROTO(journal_t *journal, tid_t first_tid,
 		 unsigned long block_nr, unsigned long freed),