hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/fs/jbd2/transaction.c
....@@ -984,36 +984,28 @@
984984 * ie. locked but not dirty) or tune2fs (which may actually have
985985 * the buffer dirtied, ugh.) */
986986
987
- if (buffer_dirty(bh)) {
987
+ if (buffer_dirty(bh) && jh->b_transaction) {
988
+ warn_dirty_buffer(bh);
988989 /*
989
- * First question: is this buffer already part of the current
990
- * transaction or the existing committing transaction?
991
- */
992
- if (jh->b_transaction) {
993
- J_ASSERT_JH(jh,
994
- jh->b_transaction == transaction ||
995
- jh->b_transaction ==
996
- journal->j_committing_transaction);
997
- if (jh->b_next_transaction)
998
- J_ASSERT_JH(jh, jh->b_next_transaction ==
999
- transaction);
1000
- warn_dirty_buffer(bh);
1001
- }
1002
- /*
1003
- * In any case we need to clean the dirty flag and we must
1004
- * do it under the buffer lock to be sure we don't race
1005
- * with running write-out.
990
+ * We need to clean the dirty flag and we must do it under the
991
+ * buffer lock to be sure we don't race with running write-out.
1006992 */
1007993 JBUFFER_TRACE(jh, "Journalling dirty buffer");
1008994 clear_buffer_dirty(bh);
995
+ /*
996
+ * The buffer is going to be added to BJ_Reserved list now and
997
+ * nothing guarantees jbd2_journal_dirty_metadata() will be
998
+ * ever called for it. So we need to set jbddirty bit here to
999
+ * make sure the buffer is dirtied and written out when the
1000
+ * journaling machinery is done with it.
1001
+ */
10091002 set_buffer_jbddirty(bh);
10101003 }
1011
-
1012
- unlock_buffer(bh);
10131004
10141005 error = -EROFS;
10151006 if (is_handle_aborted(handle)) {
10161007 spin_unlock(&jh->b_state_lock);
1008
+ unlock_buffer(bh);
10171009 goto out;
10181010 }
10191011 error = 0;
....@@ -1023,8 +1015,10 @@
10231015 * b_next_transaction points to it
10241016 */
10251017 if (jh->b_transaction == transaction ||
1026
- jh->b_next_transaction == transaction)
1018
+ jh->b_next_transaction == transaction) {
1019
+ unlock_buffer(bh);
10271020 goto done;
1021
+ }
10281022
10291023 /*
10301024 * this is the first time this transaction is touching this buffer,
....@@ -1048,10 +1042,24 @@
10481042 */
10491043 smp_wmb();
10501044 spin_lock(&journal->j_list_lock);
1045
+ if (test_clear_buffer_dirty(bh)) {
1046
+ /*
1047
+ * Execute buffer dirty clearing and jh->b_transaction
1048
+ * assignment under journal->j_list_lock locked to
1049
+ * prevent bh being removed from checkpoint list if
1050
+ * the buffer is in an intermediate state (not dirty
1051
+ * and jh->b_transaction is NULL).
1052
+ */
1053
+ JBUFFER_TRACE(jh, "Journalling dirty buffer");
1054
+ set_buffer_jbddirty(bh);
1055
+ }
10511056 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
10521057 spin_unlock(&journal->j_list_lock);
1058
+ unlock_buffer(bh);
10531059 goto done;
10541060 }
1061
+ unlock_buffer(bh);
1062
+
10551063 /*
10561064 * If there is already a copy-out version of this buffer, then we don't
10571065 * need to make another one
....@@ -2370,6 +2378,9 @@
23702378 spin_unlock(&jh->b_state_lock);
23712379 write_unlock(&journal->j_state_lock);
23722380 jbd2_journal_put_journal_head(jh);
2381
+ /* Already zapped buffer? Nothing to do... */
2382
+ if (!bh->b_bdev)
2383
+ return 0;
23732384 return -EBUSY;
23742385 }
23752386 /*