UBIFS: remove duplicated code
We have duplicated code in 'ubifs_garbage_collect()' and 'ubifs_rcvry_gc_commit()', which is about handling the special case of free LEB. In both cases we just want to garbage-collect the LEB using 'ubifs_garbage_collect_leb()'. This patch teaches 'ubifs_garbage_collect_leb()' to handle free LEB's so that the caller does not have to do this and the duplicated code is removed. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
This commit is contained in:
parent
2cd0a60cf4
commit
2405f59481
|
@ -473,6 +473,37 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)
|
|||
ubifs_assert(c->gc_lnum != lnum);
|
||||
ubifs_assert(wbuf->lnum != lnum);
|
||||
|
||||
if (lp->free + lp->dirty == c->leb_size) {
|
||||
/* Special case - a free LEB */
|
||||
dbg_gc("LEB %d is free, return it", lp->lnum);
|
||||
ubifs_assert(!(lp->flags & LPROPS_INDEX));
|
||||
|
||||
if (lp->free != c->leb_size) {
|
||||
/*
|
||||
* Write buffers must be sync'd before unmapping
|
||||
* freeable LEBs, because one of them may contain data
|
||||
* which obsoletes something in 'lp->pnum'.
|
||||
*/
|
||||
err = gc_sync_wbufs(c);
|
||||
if (err)
|
||||
return err;
|
||||
err = ubifs_change_one_lp(c, lp->lnum, c->leb_size,
|
||||
0, 0, 0, 0);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
err = ubifs_leb_unmap(c, lp->lnum);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (c->gc_lnum == -1) {
|
||||
c->gc_lnum = lnum;
|
||||
return LEB_RETAINED;
|
||||
}
|
||||
|
||||
return LEB_FREED;
|
||||
}
|
||||
|
||||
/*
|
||||
* We scan the entire LEB even though we only really need to scan up to
|
||||
* (c->leb_size - lp->free).
|
||||
|
@ -682,37 +713,6 @@ int ubifs_garbage_collect(struct ubifs_info *c, int anyway)
|
|||
"(min. space %d)", lp.lnum, lp.free, lp.dirty,
|
||||
lp.free + lp.dirty, min_space);
|
||||
|
||||
if (lp.free + lp.dirty == c->leb_size) {
|
||||
/* An empty LEB was returned */
|
||||
dbg_gc("LEB %d is free, return it", lp.lnum);
|
||||
/*
|
||||
* ubifs_find_dirty_leb() doesn't return freeable index
|
||||
* LEBs.
|
||||
*/
|
||||
ubifs_assert(!(lp.flags & LPROPS_INDEX));
|
||||
if (lp.free != c->leb_size) {
|
||||
/*
|
||||
* Write buffers must be sync'd before
|
||||
* unmapping freeable LEBs, because one of them
|
||||
* may contain data which obsoletes something
|
||||
* in 'lp.pnum'.
|
||||
*/
|
||||
ret = gc_sync_wbufs(c);
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = ubifs_change_one_lp(c, lp.lnum,
|
||||
c->leb_size, 0, 0, 0,
|
||||
0);
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
ret = ubifs_leb_unmap(c, lp.lnum);
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = lp.lnum;
|
||||
break;
|
||||
}
|
||||
|
||||
space_before = c->leb_size - wbuf->offs - wbuf->used;
|
||||
if (wbuf->lnum == -1)
|
||||
space_before = 0;
|
||||
|
|
|
@ -1125,25 +1125,10 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c)
|
|||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
ubifs_assert(!(lp.flags & LPROPS_INDEX));
|
||||
lnum = lp.lnum;
|
||||
if (lp.free + lp.dirty == c->leb_size) {
|
||||
/* An empty LEB was returned */
|
||||
if (lp.free != c->leb_size) {
|
||||
err = ubifs_change_one_lp(c, lnum, c->leb_size,
|
||||
0, 0, 0, 0);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
err = ubifs_leb_unmap(c, lnum);
|
||||
if (err)
|
||||
return err;
|
||||
c->gc_lnum = lnum;
|
||||
dbg_rcvry("allocated LEB %d for GC", lnum);
|
||||
/* Run the commit */
|
||||
dbg_rcvry("committing");
|
||||
return ubifs_run_commit(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* There was no empty LEB so the used space in the dirtiest LEB must fit
|
||||
* in the GC head LEB.
|
||||
|
|
Loading…
Reference in New Issue