Skip to content

Commit f42eed7

Browse files
Artem Bityutskiydedekind
authored andcommitted
UBIFS: harmonize znode flag helpers
We have 3 znode flags: cow, obsolete, dirty. For the last flag we have a 'ubifs_zn_dirty()' helper function, but for the other 2 flags we use 'test_bit()' directly. This patch makes the situation more consistent and introduces helpers for the other 2 flags: 'ubifs_zn_cow()' and 'ubifs_zn_obsolete()'. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent 1f42596 commit f42eed7

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

‎fs/ubifs/commit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int nothing_to_commit(struct ubifs_info *c)
7878
* If the root TNC node is dirty, we definitely have something to
7979
* commit.
8080
*/
81-
if (c->zroot.znode && test_bit(DIRTY_ZNODE, &c->zroot.znode->flags))
81+
if (c->zroot.znode && ubifs_zn_dirty(c->zroot.znode))
8282
return 0;
8383

8484
/*

‎fs/ubifs/misc.h‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ static inline int ubifs_zn_dirty(const struct ubifs_znode *znode)
3838
return !!test_bit(DIRTY_ZNODE, &znode->flags);
3939
}
4040

41+
/**
42+
* ubifs_zn_obsolete - check if znode is obsolete.
43+
* @znode: znode to check
44+
*
45+
* This helper function returns %1 if @znode is obsolete and %0 otherwise.
46+
*/
47+
static inline int ubifs_zn_obsolete(const struct ubifs_znode *znode)
48+
{
49+
return !!test_bit(OBSOLETE_ZNODE, &znode->flags);
50+
}
51+
52+
/**
53+
* ubifs_zn_cow - check if znode has to be copied on write.
54+
* @znode: znode to check
55+
*
56+
* This helper function returns %1 if @znode is has COW flag set and %0
57+
* otherwise.
58+
*/
59+
static inline int ubifs_zn_cow(const struct ubifs_znode *znode)
60+
{
61+
return !!test_bit(COW_ZNODE, &znode->flags);
62+
}
63+
4164
/**
4265
* ubifs_wake_up_bgt - wake up background thread.
4366
* @c: UBIFS file-system description object

‎fs/ubifs/tnc.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static struct ubifs_znode *copy_znode(struct ubifs_info *c,
223223
__set_bit(DIRTY_ZNODE, &zn->flags);
224224
__clear_bit(COW_ZNODE, &zn->flags);
225225

226-
ubifs_assert(!test_bit(OBSOLETE_ZNODE, &znode->flags));
226+
ubifs_assert(!ubifs_zn_obsolete(znode));
227227
__set_bit(OBSOLETE_ZNODE, &znode->flags);
228228

229229
if (znode->level != 0) {
@@ -271,7 +271,7 @@ static struct ubifs_znode *dirty_cow_znode(struct ubifs_info *c,
271271
struct ubifs_znode *zn;
272272
int err;
273273

274-
if (!test_bit(COW_ZNODE, &znode->flags)) {
274+
if (!ubifs_zn_cow(znode)) {
275275
/* znode is not being committed */
276276
if (!test_and_set_bit(DIRTY_ZNODE, &znode->flags)) {
277277
atomic_long_inc(&c->dirty_zn_cnt);
@@ -2423,7 +2423,7 @@ static int tnc_delete(struct ubifs_info *c, struct ubifs_znode *znode, int n)
24232423
*/
24242424

24252425
do {
2426-
ubifs_assert(!test_bit(OBSOLETE_ZNODE, &znode->flags));
2426+
ubifs_assert(!ubifs_zn_obsolete(znode));
24272427
ubifs_assert(ubifs_zn_dirty(znode));
24282428

24292429
zp = znode->parent;
@@ -2479,9 +2479,8 @@ static int tnc_delete(struct ubifs_info *c, struct ubifs_znode *znode, int n)
24792479
c->zroot.offs = zbr->offs;
24802480
c->zroot.len = zbr->len;
24812481
c->zroot.znode = znode;
2482-
ubifs_assert(!test_bit(OBSOLETE_ZNODE,
2483-
&zp->flags));
2484-
ubifs_assert(test_bit(DIRTY_ZNODE, &zp->flags));
2482+
ubifs_assert(!ubifs_zn_obsolete(zp));
2483+
ubifs_assert(ubifs_zn_dirty(zp));
24852484
atomic_long_dec(&c->dirty_zn_cnt);
24862485

24872486
if (zp->cnext) {
@@ -2865,7 +2864,7 @@ static void tnc_destroy_cnext(struct ubifs_info *c)
28652864
struct ubifs_znode *znode = cnext;
28662865

28672866
cnext = cnext->cnext;
2868-
if (test_bit(OBSOLETE_ZNODE, &znode->flags))
2867+
if (ubifs_zn_obsolete(znode))
28692868
kfree(znode);
28702869
} while (cnext && cnext != c->cnext);
28712870
}

‎fs/ubifs/tnc_commit.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int make_idx_node(struct ubifs_info *c, struct ubifs_idx_node *idx,
8787
atomic_long_dec(&c->dirty_zn_cnt);
8888

8989
ubifs_assert(ubifs_zn_dirty(znode));
90-
ubifs_assert(test_bit(COW_ZNODE, &znode->flags));
90+
ubifs_assert(ubifs_zn_cow(znode));
9191

9292
__clear_bit(DIRTY_ZNODE, &znode->flags);
9393
__clear_bit(COW_ZNODE, &znode->flags);
@@ -639,7 +639,7 @@ static int get_znodes_to_commit(struct ubifs_info *c)
639639
}
640640
cnt += 1;
641641
while (1) {
642-
ubifs_assert(!test_bit(COW_ZNODE, &znode->flags));
642+
ubifs_assert(!ubifs_zn_cow(znode));
643643
__set_bit(COW_ZNODE, &znode->flags);
644644
znode->alt = 0;
645645
cnext = find_next_dirty(znode);
@@ -888,7 +888,7 @@ static int write_index(struct ubifs_info *c)
888888
cnext = znode->cnext;
889889

890890
ubifs_assert(ubifs_zn_dirty(znode));
891-
ubifs_assert(test_bit(COW_ZNODE, &znode->flags));
891+
ubifs_assert(ubifs_zn_cow(znode));
892892

893893
/*
894894
* It is important that other threads should see %DIRTY_ZNODE
@@ -983,7 +983,7 @@ static void free_obsolete_znodes(struct ubifs_info *c)
983983
do {
984984
znode = cnext;
985985
cnext = znode->cnext;
986-
if (test_bit(OBSOLETE_ZNODE, &znode->flags))
986+
if (ubifs_zn_obsolete(znode))
987987
kfree(znode);
988988
else {
989989
znode->cnext = NULL;

0 commit comments

Comments
 (0)