48
48
#include <linux/slab.h>
52
* nothing_to_commit - check if there is nothing to commit.
53
* @c: UBIFS file-system description object
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.
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.
66
* This function returns %1 if there is nothing to commit and %0 otherwise.
68
static int nothing_to_commit(struct ubifs_info *c)
71
* During mounting or remounting from R/O mode to R/W mode we may
72
* commit for various recovery-related reasons.
74
if (c->mounting || c->remounting_rw)
78
* If the root TNC node is dirty, we definitely have something to
81
if (c->zroot.znode && test_bit(DIRTY_ZNODE, &c->zroot.znode->flags))
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.
91
if (c->nroot && test_bit(DIRTY_CNODE, &c->nroot->flags))
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);
52
102
* do_commit - commit the journal.
53
103
* @c: UBIFS file-system description object
123
if (nothing_to_commit(c)) {
124
up_write(&c->commit_sem);
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);