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

« back to all changes in this revision

Viewing changes to fs/ubifs/commit.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:
48
48
#include <linux/slab.h>
49
49
#include "ubifs.h"
50
50
 
 
51
/*
 
52
 * nothing_to_commit - check if there is nothing to commit.
 
53
 * @c: UBIFS file-system description object
 
54
 *
 
55
 * This is a helper function which checks if there is anything to commit. It is
 
56
 * used as an optimization to avoid starting the commit if it is not really
 
57
 * necessary. Indeed, the commit operation always assumes flash I/O (e.g.,
 
58
 * writing the commit start node to the log), and it is better to avoid doing
 
59
 * this unnecessarily. E.g., 'ubifs_sync_fs()' runs the commit, but if there is
 
60
 * nothing to commit, it is more optimal to avoid any flash I/O.
 
61
 *
 
62
 * This function has to be called with @c->commit_sem locked for writing -
 
63
 * this function does not take LPT/TNC locks because the @c->commit_sem
 
64
 * guarantees that we have exclusive access to the TNC and LPT data structures.
 
65
 *
 
66
 * This function returns %1 if there is nothing to commit and %0 otherwise.
 
67
 */
 
68
static int nothing_to_commit(struct ubifs_info *c)
 
69
{
 
70
        /*
 
71
         * During mounting or remounting from R/O mode to R/W mode we may
 
72
         * commit for various recovery-related reasons.
 
73
         */
 
74
        if (c->mounting || c->remounting_rw)
 
75
                return 0;
 
76
 
 
77
        /*
 
78
         * If the root TNC node is dirty, we definitely have something to
 
79
         * commit.
 
80
         */
 
81
        if (c->zroot.znode && test_bit(DIRTY_ZNODE, &c->zroot.znode->flags))
 
82
                return 0;
 
83
 
 
84
        /*
 
85
         * Even though the TNC is clean, the LPT tree may have dirty nodes. For
 
86
         * example, this may happen if the budgeting subsystem invoked GC to
 
87
         * make some free space, and the GC found an LEB with only dirty and
 
88
         * free space. In this case GC would just change the lprops of this
 
89
         * LEB (by turning all space into free space) and unmap it.
 
90
         */
 
91
        if (c->nroot && test_bit(DIRTY_CNODE, &c->nroot->flags))
 
92
                return 0;
 
93
 
 
94
        ubifs_assert(atomic_long_read(&c->dirty_zn_cnt) == 0);
 
95
        ubifs_assert(c->dirty_pn_cnt == 0);
 
96
        ubifs_assert(c->dirty_nn_cnt == 0);
 
97
 
 
98
        return 1;
 
99
}
 
100
 
51
101
/**
52
102
 * do_commit - commit the journal.
53
103
 * @c: UBIFS file-system description object
70
120
                goto out_up;
71
121
        }
72
122
 
 
123
        if (nothing_to_commit(c)) {
 
124
                up_write(&c->commit_sem);
 
125
                err = 0;
 
126
                goto out_cancel;
 
127
        }
 
128
 
73
129
        /* Sync all write buffers (necessary for recovery) */
74
130
        for (i = 0; i < c->jhead_cnt; i++) {
75
131
                err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
126
182
        c->mst_node->root_len    = cpu_to_le32(zroot.len);
127
183
        c->mst_node->ihead_lnum  = cpu_to_le32(c->ihead_lnum);
128
184
        c->mst_node->ihead_offs  = cpu_to_le32(c->ihead_offs);
129
 
        c->mst_node->index_size  = cpu_to_le64(c->old_idx_sz);
 
185
        c->mst_node->index_size  = cpu_to_le64(c->bi.old_idx_sz);
130
186
        c->mst_node->lpt_lnum    = cpu_to_le32(c->lpt_lnum);
131
187
        c->mst_node->lpt_offs    = cpu_to_le32(c->lpt_offs);
132
188
        c->mst_node->nhead_lnum  = cpu_to_le32(c->nhead_lnum);
162
218
        if (err)
163
219
                goto out;
164
220
 
 
221
out_cancel:
165
222
        spin_lock(&c->cs_lock);
166
223
        c->cmt_state = COMMIT_RESTING;
167
224
        wake_up(&c->cmt_wq);
168
225
        dbg_cmt("commit end");
169
226
        spin_unlock(&c->cs_lock);
170
 
 
171
227
        return 0;
172
228
 
173
229
out_up: