@@ -449,7 +449,7 @@ static int start_this_handle(journal_t *journal, handle_t *handle,
449
449
}
450
450
451
451
/* OK, account for the buffers that this operation expects to
452
- * use and add the handle to the running transaction.
452
+ * use and add the handle to the running transaction.
453
453
*/
454
454
update_t_max_wait (transaction , ts );
455
455
handle -> h_transaction = transaction ;
@@ -836,6 +836,35 @@ int jbd2_journal_restart(handle_t *handle, int nblocks)
836
836
}
837
837
EXPORT_SYMBOL (jbd2_journal_restart );
838
838
839
+ /*
840
+ * Waits for any outstanding t_updates to finish.
841
+ * This is called with write j_state_lock held.
842
+ */
843
+ void jbd2_journal_wait_updates (journal_t * journal )
844
+ {
845
+ transaction_t * commit_transaction = journal -> j_running_transaction ;
846
+
847
+ if (!commit_transaction )
848
+ return ;
849
+
850
+ spin_lock (& commit_transaction -> t_handle_lock );
851
+ while (atomic_read (& commit_transaction -> t_updates )) {
852
+ DEFINE_WAIT (wait );
853
+
854
+ prepare_to_wait (& journal -> j_wait_updates , & wait ,
855
+ TASK_UNINTERRUPTIBLE );
856
+ if (atomic_read (& commit_transaction -> t_updates )) {
857
+ spin_unlock (& commit_transaction -> t_handle_lock );
858
+ write_unlock (& journal -> j_state_lock );
859
+ schedule ();
860
+ write_lock (& journal -> j_state_lock );
861
+ spin_lock (& commit_transaction -> t_handle_lock );
862
+ }
863
+ finish_wait (& journal -> j_wait_updates , & wait );
864
+ }
865
+ spin_unlock (& commit_transaction -> t_handle_lock );
866
+ }
867
+
839
868
/**
840
869
* jbd2_journal_lock_updates () - establish a transaction barrier.
841
870
* @journal: Journal to establish a barrier on.
@@ -863,27 +892,9 @@ void jbd2_journal_lock_updates(journal_t *journal)
863
892
write_lock (& journal -> j_state_lock );
864
893
}
865
894
866
- /* Wait until there are no running updates */
867
- while (1 ) {
868
- transaction_t * transaction = journal -> j_running_transaction ;
869
-
870
- if (!transaction )
871
- break ;
895
+ /* Wait until there are no running t_updates */
896
+ jbd2_journal_wait_updates (journal );
872
897
873
- spin_lock (& transaction -> t_handle_lock );
874
- prepare_to_wait (& journal -> j_wait_updates , & wait ,
875
- TASK_UNINTERRUPTIBLE );
876
- if (!atomic_read (& transaction -> t_updates )) {
877
- spin_unlock (& transaction -> t_handle_lock );
878
- finish_wait (& journal -> j_wait_updates , & wait );
879
- break ;
880
- }
881
- spin_unlock (& transaction -> t_handle_lock );
882
- write_unlock (& journal -> j_state_lock );
883
- schedule ();
884
- finish_wait (& journal -> j_wait_updates , & wait );
885
- write_lock (& journal -> j_state_lock );
886
- }
887
898
write_unlock (& journal -> j_state_lock );
888
899
889
900
/*
0 commit comments