~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/jbd2/journal.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
479
479
int __jbd2_log_start_commit(journal_t *journal, tid_t target)
480
480
{
481
481
        /*
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.
483
485
         */
484
 
        if (!tid_geq(journal->j_commit_request, target)) {
 
486
        if (journal->j_running_transaction &&
 
487
            journal->j_running_transaction->t_tid == target) {
485
488
                /*
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);
495
498
                return 1;
496
 
        }
 
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);
497
508
        return 0;
498
509
}
499
510
 
577
588
}
578
589
 
579
590
/*
 
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.
 
595
 */
 
596
int jbd2_trans_will_send_data_barrier(journal_t *journal, tid_t tid)
 
597
{
 
598
        int ret = 0;
 
599
        transaction_t *commit_trans;
 
600
 
 
601
        if (!(journal->j_flags & JBD2_BARRIER))
 
602
                return 0;
 
603
        read_lock(&journal->j_state_lock);
 
604
        /* Transaction already committed? */
 
605
        if (tid_geq(journal->j_commit_sequence, tid))
 
606
                goto out;
 
607
        commit_trans = journal->j_committing_transaction;
 
608
        if (!commit_trans || commit_trans->t_tid != tid) {
 
609
                ret = 1;
 
610
                goto out;
 
611
        }
 
612
        /*
 
613
         * Transaction is being committed and we already proceeded to
 
614
         * submitting a flush to fs partition?
 
615
         */
 
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)
 
619
                        goto out;
 
620
        } else {
 
621
                if (commit_trans->t_state >= T_COMMIT_JFLUSH)
 
622
                        goto out;
 
623
        }
 
624
        ret = 1;
 
625
out:
 
626
        read_unlock(&journal->j_state_lock);
 
627
        return ret;
 
628
}
 
629
EXPORT_SYMBOL(jbd2_trans_will_send_data_barrier);
 
630
 
 
631
/*
580
632
 * Wait for a specified commit to complete.
581
633
 * The caller may not hold the journal lock.
582
634
 */
917
969
        journal->j_wbufsize = n;
918
970
        journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
919
971
        if (!journal->j_wbuf) {
920
 
                printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
 
972
                printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n",
921
973
                        __func__);
922
974
                goto out_err;
923
975
        }
983
1035
        journal->j_wbufsize = n;
984
1036
        journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
985
1037
        if (!journal->j_wbuf) {
986
 
                printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
 
1038
                printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n",
987
1039
                        __func__);
988
1040
                goto out_err;
989
1041
        }
991
1043
        err = jbd2_journal_bmap(journal, 0, &blocknr);
992
1044
        /* If that failed, give up */
993
1045
        if (err) {
994
 
                printk(KERN_ERR "%s: Cannnot locate journal superblock\n",
 
1046
                printk(KERN_ERR "%s: Cannot locate journal superblock\n",
995
1047
                       __func__);
996
1048
                goto out_err;
997
1049
        }
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.
2028
2080
 *
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.
2033
2084
 *
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);
2044
2095
 *      ...
 
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);
2047
 
 *
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.
2050
2101
 */
2051
2102
 
2052
2103
/*
2053
2104
 * Give a buffer_head a journal_head.
2054
2105
 *
2055
 
 * Doesn't need the journal lock.
2056
2106
 * May sleep.
2057
2107
 */
2058
2108
struct journal_head *jbd2_journal_add_journal_head(struct buffer_head *bh)
2116
2166
        struct journal_head *jh = bh2jh(bh);
2117
2167
 
2118
2168
        J_ASSERT_JH(jh, jh->b_jcount >= 0);
2119
 
 
2120
 
        get_bh(bh);
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 "
2131
 
                                                "b_frozen_data\n",
2132
 
                                                __func__);
2133
 
                                jbd2_free(jh->b_frozen_data, bh->b_size);
2134
 
                        }
2135
 
                        if (jh->b_committed_data) {
2136
 
                                printk(KERN_WARNING "%s: freeing "
2137
 
                                                "b_committed_data\n",
2138
 
                                                __func__);
2139
 
                                jbd2_free(jh->b_committed_data, bh->b_size);
2140
 
                        }
2141
 
                        bh->b_private = NULL;
2142
 
                        jh->b_bh = NULL;        /* debug, really */
2143
 
                        clear_buffer_jbd(bh);
2144
 
                        __brelse(bh);
2145
 
                        journal_free_journal_head(jh);
2146
 
                } else {
2147
 
                        BUFFER_TRACE(bh, "journal_head was locked");
2148
 
                }
2149
 
        }
2150
 
}
2151
 
 
2152
 
/*
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.
2157
 
 *
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().
2164
 
 */
2165
 
void jbd2_journal_remove_journal_head(struct buffer_head *bh)
2166
 
{
2167
 
        jbd_lock_bh_journal_head(bh);
2168
 
        __journal_remove_journal_head(bh);
2169
 
        jbd_unlock_bh_journal_head(bh);
2170
 
}
2171
 
 
2172
 
/*
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);
 
2179
        }
 
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);
 
2183
        }
 
2184
        bh->b_private = NULL;
 
2185
        jh->b_bh = NULL;        /* debug, really */
 
2186
        clear_buffer_jbd(bh);
 
2187
        journal_free_journal_head(jh);
 
2188
}
 
2189
 
 
2190
/*
 
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.
2175
2193
 */
2176
2194
void jbd2_journal_put_journal_head(struct journal_head *jh)
2180
2198
        jbd_lock_bh_journal_head(bh);
2181
2199
        J_ASSERT_JH(jh, jh->b_jcount > 0);
2182
2200
        --jh->b_jcount;
2183
 
        if (!jh->b_jcount && !jh->b_transaction) {
 
2201
        if (!jh->b_jcount) {
2184
2202
                __journal_remove_journal_head(bh);
 
2203
                jbd_unlock_bh_journal_head(bh);
2185
2204
                __brelse(bh);
2186
 
        }
2187
 
        jbd_unlock_bh_journal_head(bh);
 
2205
        } else
 
2206
                jbd_unlock_bh_journal_head(bh);
2188
2207
}
2189
2208
 
2190
2209
/*
2413
2432
        new_dev = kmalloc(sizeof(struct devname_cache), GFP_KERNEL);
2414
2433
        if (!new_dev)
2415
2434
                return "NODEV-ALLOCFAILURE"; /* Something non-NULL */
 
2435
        bd = bdget(device);
2416
2436
        spin_lock(&devname_cache_lock);
2417
2437
        if (devcache[i]) {
2418
2438
                if (devcache[i]->device == device) {
2419
2439
                        kfree(new_dev);
 
2440
                        bdput(bd);
2420
2441
                        ret = devcache[i]->devname;
2421
2442
                        spin_unlock(&devname_cache_lock);
2422
2443
                        return ret;
2425
2446
        }
2426
2447
        devcache[i] = new_dev;
2427
2448
        devcache[i]->device = device;
2428
 
        bd = bdget(device);
2429
2449
        if (bd) {
2430
2450
                bdevname(bd, devcache[i]->devname);
2431
2451
                bdput(bd);