summaryrefslogtreecommitdiff
path: root/ubifs-utils/libubifs/lpt_commit.c
diff options
context:
space:
mode:
authorZhihao Cheng <chengzhihao1@huawei.com>2024-11-11 17:08:08 +0800
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2024-11-11 10:32:46 +0100
commit47c1cfd5e8ec289597f7342f88e103811511f0a8 (patch)
tree364fe0e96fbcd6bcbd964d0349f3d4883c5f539b /ubifs-utils/libubifs/lpt_commit.c
parent59dd2cf5ad8e32c7b38b3287b9d05a2d809e93e4 (diff)
fsck.ubifs: Move common functions and data structures into check_space.c
This is a preparation for adding LPT checking support. Move some data structures and functions into check_space.c, also factor out some common functions in libubifs: 1. Move 'lpts' from rebuild module, make it resuable for non-rebuild_fs modes. 2. Move function 'get_free_leb' from rebuild_fs.c, it could be reused in building LPT. 3. Move function 'build_lpt' from rebuild_fs.c, it could be reused in building LPT. 4. Factor out lpt nodes freeing into a new function ubifs_free_lpt_nodes. 5. Factor out nnode dirty marking implementations into a new function ubifs_make_nnode_dirty. 5. Export the function of nnode number calculation, calc_nnode_num is renamed as ubifs_calc_nnode_num. 6. Export the function of making pnode dirty, do_make_pnode_dirty is renamed as ubifs_make_pnode_dirty. 7. Rename next_pnode_to_dirty to ubifs_find_next_pnode and export it. 8. Export free_buds and expend its parameters. Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubifs-utils/libubifs/lpt_commit.c')
-rw-r--r--ubifs-utils/libubifs/lpt_commit.c97
1 files changed, 52 insertions, 45 deletions
diff --git a/ubifs-utils/libubifs/lpt_commit.c b/ubifs-utils/libubifs/lpt_commit.c
index 43eb7a6..8a44546 100644
--- a/ubifs-utils/libubifs/lpt_commit.c
+++ b/ubifs-utils/libubifs/lpt_commit.c
@@ -545,16 +545,15 @@ no_space:
}
/**
- * next_pnode_to_dirty - find next pnode to dirty.
+ * ubifs_find_next_pnode - find next pnode.
* @c: UBIFS file-system description object
* @pnode: pnode
*
- * This function returns the next pnode to dirty or %NULL if there are no more
- * pnodes. Note that pnodes that have never been written (lnum == 0) are
- * skipped.
+ * This function returns the next pnode or %NULL if there are no more pnodes.
+ * Note that pnodes that have never been written (lnum == 0) are skipped.
*/
-static struct ubifs_pnode *next_pnode_to_dirty(struct ubifs_info *c,
- struct ubifs_pnode *pnode)
+struct ubifs_pnode *ubifs_find_next_pnode(struct ubifs_info *c,
+ struct ubifs_pnode *pnode)
{
struct ubifs_nnode *nnode;
int iip;
@@ -622,28 +621,35 @@ static void add_pnode_dirt(struct ubifs_info *c, struct ubifs_pnode *pnode)
}
/**
- * do_make_pnode_dirty - mark a pnode dirty.
+ * ubifs_make_nnode_dirty - mark a nnode dirty.
+ * @c: UBIFS file-system description object
+ * @nnode: nnode to mark dirty
+ */
+void ubifs_make_nnode_dirty(struct ubifs_info *c, struct ubifs_nnode *nnode)
+{
+ while (nnode) {
+ if (!test_and_set_bit(DIRTY_CNODE, &nnode->flags)) {
+ c->dirty_nn_cnt += 1;
+ ubifs_add_nnode_dirt(c, nnode);
+ nnode = nnode->parent;
+ } else
+ break;
+ }
+}
+
+/**
+ * ubifs_make_pnode_dirty - mark a pnode dirty.
* @c: UBIFS file-system description object
* @pnode: pnode to mark dirty
*/
-static void do_make_pnode_dirty(struct ubifs_info *c, struct ubifs_pnode *pnode)
+void ubifs_make_pnode_dirty(struct ubifs_info *c, struct ubifs_pnode *pnode)
{
/* Assumes cnext list is empty i.e. not called during commit */
if (!test_and_set_bit(DIRTY_CNODE, &pnode->flags)) {
- struct ubifs_nnode *nnode;
-
c->dirty_pn_cnt += 1;
add_pnode_dirt(c, pnode);
/* Mark parent and ancestors dirty too */
- nnode = pnode->parent;
- while (nnode) {
- if (!test_and_set_bit(DIRTY_CNODE, &nnode->flags)) {
- c->dirty_nn_cnt += 1;
- ubifs_add_nnode_dirt(c, nnode);
- nnode = nnode->parent;
- } else
- break;
- }
+ ubifs_make_nnode_dirty(c, pnode->parent);
}
}
@@ -667,8 +673,8 @@ static int make_tree_dirty(struct ubifs_info *c)
return PTR_ERR(pnode);
while (pnode) {
- do_make_pnode_dirty(c, pnode);
- pnode = next_pnode_to_dirty(c, pnode);
+ ubifs_make_pnode_dirty(c, pnode);
+ pnode = ubifs_find_next_pnode(c, pnode);
if (IS_ERR(pnode))
return PTR_ERR(pnode);
}
@@ -878,20 +884,7 @@ static int make_nnode_dirty(struct ubifs_info *c, int node_num, int lnum,
} else if (c->lpt_lnum != lnum || c->lpt_offs != offs)
return 0; /* nnode is obsolete */
/* Assumes cnext list is empty i.e. not called during commit */
- if (!test_and_set_bit(DIRTY_CNODE, &nnode->flags)) {
- c->dirty_nn_cnt += 1;
- ubifs_add_nnode_dirt(c, nnode);
- /* Mark parent and ancestors dirty too */
- nnode = nnode->parent;
- while (nnode) {
- if (!test_and_set_bit(DIRTY_CNODE, &nnode->flags)) {
- c->dirty_nn_cnt += 1;
- ubifs_add_nnode_dirt(c, nnode);
- nnode = nnode->parent;
- } else
- break;
- }
- }
+ ubifs_make_nnode_dirty(c, nnode);
return 0;
}
@@ -922,7 +915,7 @@ static int make_pnode_dirty(struct ubifs_info *c, int node_num, int lnum,
branch = &pnode->parent->nbranch[pnode->iip];
if (branch->lnum != lnum || branch->offs != offs)
return 0;
- do_make_pnode_dirty(c, pnode);
+ ubifs_make_pnode_dirty(c, pnode);
return 0;
}
@@ -1414,14 +1407,33 @@ static struct ubifs_nnode *next_nnode(struct ubifs_info *c,
}
/**
+ * ubifs_free_lpt_nodes - free pnodes/nnodes in LPT.
+ * @c: UBIFS file-system description object
+ */
+void ubifs_free_lpt_nodes(struct ubifs_info *c)
+{
+ int i, hght;
+ struct ubifs_nnode *nnode;
+
+ nnode = first_nnode(c, &hght);
+ while (nnode) {
+ for (i = 0; i < UBIFS_LPT_FANOUT; i++)
+ kfree(nnode->nbranch[i].nnode);
+ nnode = next_nnode(c, nnode, &hght);
+ }
+
+ kfree(c->nroot);
+ c->nroot = NULL;
+}
+
+/**
* ubifs_lpt_free - free resources owned by the LPT.
* @c: UBIFS file-system description object
* @wr_only: free only resources used for writing
*/
void ubifs_lpt_free(struct ubifs_info *c, int wr_only)
{
- struct ubifs_nnode *nnode;
- int i, hght;
+ int i;
/* Free write-only things first */
@@ -1439,17 +1451,12 @@ void ubifs_lpt_free(struct ubifs_info *c, int wr_only)
/* Now free the rest */
- nnode = first_nnode(c, &hght);
- while (nnode) {
- for (i = 0; i < UBIFS_LPT_FANOUT; i++)
- kfree(nnode->nbranch[i].nnode);
- nnode = next_nnode(c, nnode, &hght);
- }
+ ubifs_free_lpt_nodes(c);
for (i = 0; i < LPROPS_HEAP_CNT; i++)
kfree(c->lpt_heap[i].arr);
kfree(c->dirty_idx.arr);
- kfree(c->nroot);
vfree(c->ltab);
+ c->ltab = NULL;
kfree(c->lpt_nod_buf);
}