479
479
int __jbd2_log_start_commit(journal_t *journal, tid_t target)
482
* Are we already doing a recent enough commit?
482
* The only transaction we can possibly wait upon is the
483
* currently running transaction (if it exists). Otherwise,
484
* the target tid must be an old one.
484
if (!tid_geq(journal->j_commit_request, target)) {
486
if (journal->j_running_transaction &&
487
journal->j_running_transaction->t_tid == target) {
486
489
* We want a new commit: OK, mark the request and wakeup the
487
490
* commit thread. We do _not_ do the commit ourselves.
493
496
journal->j_commit_sequence);
494
497
wake_up(&journal->j_wait_commit);
499
} else if (!tid_geq(journal->j_commit_request, target))
500
/* This should never happen, but if it does, preserve
501
the evidence before kjournald goes into a loop and
502
increments j_commit_sequence beyond all recognition. */
503
WARN_ONCE(1, "jbd: bad log_start_commit: %u %u %u %u\n",
504
journal->j_commit_request,
505
journal->j_commit_sequence,
506
target, journal->j_running_transaction ?
507
journal->j_running_transaction->t_tid : 0);
591
* Return 1 if a given transaction has not yet sent barrier request
592
* connected with a transaction commit. If 0 is returned, transaction
593
* may or may not have sent the barrier. Used to avoid sending barrier
594
* twice in common cases.
596
int jbd2_trans_will_send_data_barrier(journal_t *journal, tid_t tid)
599
transaction_t *commit_trans;
601
if (!(journal->j_flags & JBD2_BARRIER))
603
read_lock(&journal->j_state_lock);
604
/* Transaction already committed? */
605
if (tid_geq(journal->j_commit_sequence, tid))
607
commit_trans = journal->j_committing_transaction;
608
if (!commit_trans || commit_trans->t_tid != tid) {
613
* Transaction is being committed and we already proceeded to
614
* submitting a flush to fs partition?
616
if (journal->j_fs_dev != journal->j_dev) {
617
if (!commit_trans->t_need_data_flush ||
618
commit_trans->t_state >= T_COMMIT_DFLUSH)
621
if (commit_trans->t_state >= T_COMMIT_JFLUSH)
626
read_unlock(&journal->j_state_lock);
629
EXPORT_SYMBOL(jbd2_trans_will_send_data_barrier);
580
632
* Wait for a specified commit to complete.
581
633
* The caller may not hold the journal lock.
2026
2078
* When a buffer has its BH_JBD bit set it is immune from being released by
2027
2079
* core kernel code, mainly via ->b_count.
2029
* A journal_head may be detached from its buffer_head when the journal_head's
2030
* b_transaction, b_cp_transaction and b_next_transaction pointers are NULL.
2031
* Various places in JBD call jbd2_journal_remove_journal_head() to indicate that the
2032
* journal_head can be dropped if needed.
2081
* A journal_head is detached from its buffer_head when the journal_head's
2082
* b_jcount reaches zero. Running transaction (b_transaction) and checkpoint
2083
* transaction (b_cp_transaction) hold their references to b_jcount.
2034
2085
* Various places in the kernel want to attach a journal_head to a buffer_head
2035
2086
* _before_ attaching the journal_head to a transaction. To protect the
2042
2093
* (Attach a journal_head if needed. Increments b_jcount)
2043
2094
* struct journal_head *jh = jbd2_journal_add_journal_head(bh);
2096
* (Get another reference for transaction)
2097
* jbd2_journal_grab_journal_head(bh);
2045
2098
* jh->b_transaction = xxx;
2099
* (Put original reference)
2046
2100
* jbd2_journal_put_journal_head(jh);
2048
* Now, the journal_head's b_jcount is zero, but it is safe from being released
2049
* because it has a non-zero b_transaction.
2053
2104
* Give a buffer_head a journal_head.
2055
* Doesn't need the journal lock.
2058
2108
struct journal_head *jbd2_journal_add_journal_head(struct buffer_head *bh)
2116
2166
struct journal_head *jh = bh2jh(bh);
2118
2168
J_ASSERT_JH(jh, jh->b_jcount >= 0);
2121
if (jh->b_jcount == 0) {
2122
if (jh->b_transaction == NULL &&
2123
jh->b_next_transaction == NULL &&
2124
jh->b_cp_transaction == NULL) {
2125
J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
2126
J_ASSERT_BH(bh, buffer_jbd(bh));
2127
J_ASSERT_BH(bh, jh2bh(jh) == bh);
2128
BUFFER_TRACE(bh, "remove journal_head");
2129
if (jh->b_frozen_data) {
2130
printk(KERN_WARNING "%s: freeing "
2133
jbd2_free(jh->b_frozen_data, bh->b_size);
2135
if (jh->b_committed_data) {
2136
printk(KERN_WARNING "%s: freeing "
2137
"b_committed_data\n",
2139
jbd2_free(jh->b_committed_data, bh->b_size);
2141
bh->b_private = NULL;
2142
jh->b_bh = NULL; /* debug, really */
2143
clear_buffer_jbd(bh);
2145
journal_free_journal_head(jh);
2147
BUFFER_TRACE(bh, "journal_head was locked");
2153
* jbd2_journal_remove_journal_head(): if the buffer isn't attached to a transaction
2154
* and has a zero b_jcount then remove and release its journal_head. If we did
2155
* see that the buffer is not used by any transaction we also "logically"
2156
* decrement ->b_count.
2158
* We in fact take an additional increment on ->b_count as a convenience,
2159
* because the caller usually wants to do additional things with the bh
2160
* after calling here.
2161
* The caller of jbd2_journal_remove_journal_head() *must* run __brelse(bh) at some
2162
* time. Once the caller has run __brelse(), the buffer is eligible for
2163
* reaping by try_to_free_buffers().
2165
void jbd2_journal_remove_journal_head(struct buffer_head *bh)
2167
jbd_lock_bh_journal_head(bh);
2168
__journal_remove_journal_head(bh);
2169
jbd_unlock_bh_journal_head(bh);
2173
* Drop a reference on the passed journal_head. If it fell to zero then try to
2169
J_ASSERT_JH(jh, jh->b_transaction == NULL);
2170
J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
2171
J_ASSERT_JH(jh, jh->b_cp_transaction == NULL);
2172
J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
2173
J_ASSERT_BH(bh, buffer_jbd(bh));
2174
J_ASSERT_BH(bh, jh2bh(jh) == bh);
2175
BUFFER_TRACE(bh, "remove journal_head");
2176
if (jh->b_frozen_data) {
2177
printk(KERN_WARNING "%s: freeing b_frozen_data\n", __func__);
2178
jbd2_free(jh->b_frozen_data, bh->b_size);
2180
if (jh->b_committed_data) {
2181
printk(KERN_WARNING "%s: freeing b_committed_data\n", __func__);
2182
jbd2_free(jh->b_committed_data, bh->b_size);
2184
bh->b_private = NULL;
2185
jh->b_bh = NULL; /* debug, really */
2186
clear_buffer_jbd(bh);
2187
journal_free_journal_head(jh);
2191
* Drop a reference on the passed journal_head. If it fell to zero then
2174
2192
* release the journal_head from the buffer_head.
2176
2194
void jbd2_journal_put_journal_head(struct journal_head *jh)