Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f42eed7c authored by Artem Bityutskiy's avatar Artem Bityutskiy Committed by Artem Bityutskiy
Browse files

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: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 1f42596e
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -78,7 +78,7 @@ static int nothing_to_commit(struct ubifs_info *c)
	 * If the root TNC node is dirty, we definitely have something to
	 * If the root TNC node is dirty, we definitely have something to
	 * commit.
	 * commit.
	 */
	 */
	if (c->zroot.znode && test_bit(DIRTY_ZNODE, &c->zroot.znode->flags))
	if (c->zroot.znode && ubifs_zn_dirty(c->zroot.znode))
		return 0;
		return 0;


	/*
	/*
+23 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,29 @@ static inline int ubifs_zn_dirty(const struct ubifs_znode *znode)
	return !!test_bit(DIRTY_ZNODE, &znode->flags);
	return !!test_bit(DIRTY_ZNODE, &znode->flags);
}
}


/**
 * ubifs_zn_obsolete - check if znode is obsolete.
 * @znode: znode to check
 *
 * This helper function returns %1 if @znode is obsolete and %0 otherwise.
 */
static inline int ubifs_zn_obsolete(const struct ubifs_znode *znode)
{
	return !!test_bit(OBSOLETE_ZNODE, &znode->flags);
}

/**
 * ubifs_zn_cow - check if znode has to be copied on write.
 * @znode: znode to check
 *
 * This helper function returns %1 if @znode is has COW flag set and %0
 * otherwise.
 */
static inline int ubifs_zn_cow(const struct ubifs_znode *znode)
{
	return !!test_bit(COW_ZNODE, &znode->flags);
}

/**
/**
 * ubifs_wake_up_bgt - wake up background thread.
 * ubifs_wake_up_bgt - wake up background thread.
 * @c: UBIFS file-system description object
 * @c: UBIFS file-system description object
+6 −7
Original line number Original line Diff line number Diff line
@@ -223,7 +223,7 @@ static struct ubifs_znode *copy_znode(struct ubifs_info *c,
	__set_bit(DIRTY_ZNODE, &zn->flags);
	__set_bit(DIRTY_ZNODE, &zn->flags);
	__clear_bit(COW_ZNODE, &zn->flags);
	__clear_bit(COW_ZNODE, &zn->flags);


	ubifs_assert(!test_bit(OBSOLETE_ZNODE, &znode->flags));
	ubifs_assert(!ubifs_zn_obsolete(znode));
	__set_bit(OBSOLETE_ZNODE, &znode->flags);
	__set_bit(OBSOLETE_ZNODE, &znode->flags);


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


	if (!test_bit(COW_ZNODE, &znode->flags)) {
	if (!ubifs_zn_cow(znode)) {
		/* znode is not being committed */
		/* znode is not being committed */
		if (!test_and_set_bit(DIRTY_ZNODE, &znode->flags)) {
		if (!test_and_set_bit(DIRTY_ZNODE, &znode->flags)) {
			atomic_long_inc(&c->dirty_zn_cnt);
			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)
	 */
	 */


	do {
	do {
		ubifs_assert(!test_bit(OBSOLETE_ZNODE, &znode->flags));
		ubifs_assert(!ubifs_zn_obsolete(znode));
		ubifs_assert(ubifs_zn_dirty(znode));
		ubifs_assert(ubifs_zn_dirty(znode));


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


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


		cnext = cnext->cnext;
		cnext = cnext->cnext;
		if (test_bit(OBSOLETE_ZNODE, &znode->flags))
		if (ubifs_zn_obsolete(znode))
			kfree(znode);
			kfree(znode);
	} while (cnext && cnext != c->cnext);
	} while (cnext && cnext != c->cnext);
}
}
+4 −4
Original line number Original line Diff line number Diff line
@@ -87,7 +87,7 @@ static int make_idx_node(struct ubifs_info *c, struct ubifs_idx_node *idx,
	atomic_long_dec(&c->dirty_zn_cnt);
	atomic_long_dec(&c->dirty_zn_cnt);


	ubifs_assert(ubifs_zn_dirty(znode));
	ubifs_assert(ubifs_zn_dirty(znode));
	ubifs_assert(test_bit(COW_ZNODE, &znode->flags));
	ubifs_assert(ubifs_zn_cow(znode));


	__clear_bit(DIRTY_ZNODE, &znode->flags);
	__clear_bit(DIRTY_ZNODE, &znode->flags);
	__clear_bit(COW_ZNODE, &znode->flags);
	__clear_bit(COW_ZNODE, &znode->flags);
@@ -639,7 +639,7 @@ static int get_znodes_to_commit(struct ubifs_info *c)
	}
	}
	cnt += 1;
	cnt += 1;
	while (1) {
	while (1) {
		ubifs_assert(!test_bit(COW_ZNODE, &znode->flags));
		ubifs_assert(!ubifs_zn_cow(znode));
		__set_bit(COW_ZNODE, &znode->flags);
		__set_bit(COW_ZNODE, &znode->flags);
		znode->alt = 0;
		znode->alt = 0;
		cnext = find_next_dirty(znode);
		cnext = find_next_dirty(znode);
@@ -888,7 +888,7 @@ static int write_index(struct ubifs_info *c)
		cnext = znode->cnext;
		cnext = znode->cnext;


		ubifs_assert(ubifs_zn_dirty(znode));
		ubifs_assert(ubifs_zn_dirty(znode));
		ubifs_assert(test_bit(COW_ZNODE, &znode->flags));
		ubifs_assert(ubifs_zn_cow(znode));


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