Commit 9642d82c authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] JBD: t_updates locking

Provide the designating locking for transaction_t.t_updates.
parent 48fdf3e6
...@@ -82,11 +82,16 @@ void journal_commit_transaction(journal_t *journal) ...@@ -82,11 +82,16 @@ void journal_commit_transaction(journal_t *journal)
commit_transaction->t_tid); commit_transaction->t_tid);
commit_transaction->t_state = T_LOCKED; commit_transaction->t_state = T_LOCKED;
spin_lock(&commit_transaction->t_handle_lock);
while (commit_transaction->t_updates != 0) { while (commit_transaction->t_updates != 0) {
spin_unlock(&commit_transaction->t_handle_lock);
unlock_journal(journal); unlock_journal(journal);
sleep_on(&journal->j_wait_updates); sleep_on(&journal->j_wait_updates);
lock_journal(journal); lock_journal(journal);
spin_lock(&commit_transaction->t_handle_lock);
} }
spin_unlock(&commit_transaction->t_handle_lock);
J_ASSERT (commit_transaction->t_outstanding_credits <= J_ASSERT (commit_transaction->t_outstanding_credits <=
journal->j_max_transaction_buffers); journal->j_max_transaction_buffers);
......
...@@ -196,9 +196,11 @@ static int start_this_handle(journal_t *journal, handle_t *handle) ...@@ -196,9 +196,11 @@ static int start_this_handle(journal_t *journal, handle_t *handle)
* use and add the handle to the running transaction. */ * use and add the handle to the running transaction. */
handle->h_transaction = transaction; handle->h_transaction = transaction;
spin_lock(&transaction->t_handle_lock);
transaction->t_outstanding_credits += nblocks; transaction->t_outstanding_credits += nblocks;
transaction->t_updates++; transaction->t_updates++;
transaction->t_handle_count++; transaction->t_handle_count++;
spin_unlock(&transaction->t_handle_lock);
jbd_debug(4, "Handle %p given %d credits (total %d, free %d)\n", jbd_debug(4, "Handle %p given %d credits (total %d, free %d)\n",
handle, nblocks, transaction->t_outstanding_credits, handle, nblocks, transaction->t_outstanding_credits,
log_space_left(journal)); log_space_left(journal));
...@@ -363,18 +365,21 @@ int journal_restart(handle_t *handle, int nblocks) ...@@ -363,18 +365,21 @@ int journal_restart(handle_t *handle, int nblocks)
if (is_handle_aborted(handle)) if (is_handle_aborted(handle))
return 0; return 0;
/* First unlink the handle from its current transaction, and /*
* start the commit on that. */ * First unlink the handle from its current transaction, and start the
* commit on that.
J_ASSERT (transaction->t_updates > 0); */
J_ASSERT (journal_current_handle() == handle); J_ASSERT(transaction->t_updates > 0);
J_ASSERT(journal_current_handle() == handle);
lock_kernel(); lock_kernel();
spin_lock(&transaction->t_handle_lock);
transaction->t_outstanding_credits -= handle->h_buffer_credits; transaction->t_outstanding_credits -= handle->h_buffer_credits;
transaction->t_updates--; transaction->t_updates--;
if (!transaction->t_updates) if (!transaction->t_updates)
wake_up(&journal->j_wait_updates); wake_up(&journal->j_wait_updates);
spin_unlock(&transaction->t_handle_lock);
jbd_debug(2, "restarting handle %p\n", handle); jbd_debug(2, "restarting handle %p\n", handle);
log_start_commit(journal, transaction); log_start_commit(journal, transaction);
...@@ -396,7 +401,7 @@ int journal_restart(handle_t *handle, int nblocks) ...@@ -396,7 +401,7 @@ int journal_restart(handle_t *handle, int nblocks)
* *
* The journal lock should not be held on entry. * The journal lock should not be held on entry.
*/ */
void journal_lock_updates (journal_t *journal) void journal_lock_updates(journal_t *journal)
{ {
lock_journal(journal); lock_journal(journal);
...@@ -409,9 +414,13 @@ void journal_lock_updates (journal_t *journal) ...@@ -409,9 +414,13 @@ void journal_lock_updates (journal_t *journal)
transaction_t *transaction = journal->j_running_transaction; transaction_t *transaction = journal->j_running_transaction;
if (!transaction) if (!transaction)
break; break;
if (!transaction->t_updates) spin_lock(&transaction->t_handle_lock);
if (!transaction->t_updates) {
spin_unlock(&transaction->t_handle_lock);
break; break;
}
spin_unlock(&transaction->t_handle_lock);
unlock_journal(journal); unlock_journal(journal);
sleep_on(&journal->j_wait_updates); sleep_on(&journal->j_wait_updates);
lock_journal(journal); lock_journal(journal);
...@@ -1299,8 +1308,8 @@ int journal_stop(handle_t *handle) ...@@ -1299,8 +1308,8 @@ int journal_stop(handle_t *handle)
if (!handle) if (!handle)
return 0; return 0;
J_ASSERT (transaction->t_updates > 0); J_ASSERT(transaction->t_updates > 0);
J_ASSERT (journal_current_handle() == handle); J_ASSERT(journal_current_handle() == handle);
if (is_handle_aborted(handle)) if (is_handle_aborted(handle))
err = -EIO; err = -EIO;
...@@ -1334,6 +1343,7 @@ int journal_stop(handle_t *handle) ...@@ -1334,6 +1343,7 @@ int journal_stop(handle_t *handle)
current->journal_info = NULL; current->journal_info = NULL;
lock_kernel(); lock_kernel();
spin_lock(&transaction->t_handle_lock);
transaction->t_outstanding_credits -= handle->h_buffer_credits; transaction->t_outstanding_credits -= handle->h_buffer_credits;
transaction->t_updates--; transaction->t_updates--;
if (!transaction->t_updates) { if (!transaction->t_updates) {
...@@ -1341,6 +1351,7 @@ int journal_stop(handle_t *handle) ...@@ -1341,6 +1351,7 @@ int journal_stop(handle_t *handle)
if (journal->j_barrier_count) if (journal->j_barrier_count)
wake_up(&journal->j_wait_transaction_locked); wake_up(&journal->j_wait_transaction_locked);
} }
spin_unlock(&transaction->t_handle_lock);
/* Move callbacks from the handle to the transaction. */ /* Move callbacks from the handle to the transaction. */
list_splice(&handle->h_jcb, &transaction->t_jcb); list_splice(&handle->h_jcb, &transaction->t_jcb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment