/* The journal lock should not be held on entry.  */
void journal_lock_updates(journal_t *journal)
/* The journal lock should not be held on entry.  */
void journal_lock_updates(journal_t *journal)
{
	DEFINE_WAIT(wait);
	spin_lock(&journal->j_state_lock);
	++journal->j_barrier_count;
	while (1) {
		transaction_t *transaction = journal->j_running_transaction;
		if (!transaction)
			break;
		spin_lock(&transaction->t_handle_lock);
		if (!transaction->t_updates) {
			spin_unlock(&transaction->t_handle_lock);
			break;
		}
		prepare_to_wait(&journal->j_wait_updates, &wait,
				TASK_UNINTERRUPTIBLE);
		spin_unlock(&transaction->t_handle_lock);
		spin_unlock(&journal->j_state_lock);
		schedule();
		finish_wait(&journal->j_wait_updates, &wait);
		spin_lock(&journal->j_state_lock);
	}
	spin_unlock(&journal->j_state_lock);
	mutex_lock(&journal->j_barrier);
}