aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-04-26 02:49:32 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-05-13 12:23:55 -0400
commit2405f5948119cdc1c28697fd3110124dad974898 (patch)
tree04bad5852693a5a18cb919c298e59dbf385c1d96 /fs
parent2cd0a60cf49db4722445337b90fb06c9672f1128 (diff)
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/ubifs/gc.c62
-rw-r--r--fs/ubifs/recovery.c19
2 files changed, 33 insertions, 48 deletions
diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
index 151f10882820..082d21bd9021 100644
--- a/fs/ubifs/gc.c
+++ b/fs/ubifs/gc.c
@@ -473,6 +473,37 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)
473 ubifs_assert(c->gc_lnum != lnum); 473 ubifs_assert(c->gc_lnum != lnum);
474 ubifs_assert(wbuf->lnum != lnum); 474 ubifs_assert(wbuf->lnum != lnum);
475 475
476 if (lp->free + lp->dirty == c->leb_size) {
477 /* Special case - a free LEB */
478 dbg_gc("LEB %d is free, return it", lp->lnum);
479 ubifs_assert(!(lp->flags & LPROPS_INDEX));
480
481 if (lp->free != c->leb_size) {
482 /*
483 * Write buffers must be sync'd before unmapping
484 * freeable LEBs, because one of them may contain data
485 * which obsoletes something in 'lp->pnum'.
486 */
487 err = gc_sync_wbufs(c);
488 if (err)
489 return err;
490 err = ubifs_change_one_lp(c, lp->lnum, c->leb_size,
491 0, 0, 0, 0);
492 if (err)
493 return err;
494 }
495 err = ubifs_leb_unmap(c, lp->lnum);
496 if (err)
497 return err;
498
499 if (c->gc_lnum == -1) {
500 c->gc_lnum = lnum;
501 return LEB_RETAINED;
502 }
503
504 return LEB_FREED;
505 }
506
476 /* 507 /*
477 * We scan the entire LEB even though we only really need to scan up to 508 * We scan the entire LEB even though we only really need to scan up to
478 * (c->leb_size - lp->free). 509 * (c->leb_size - lp->free).
@@ -682,37 +713,6 @@ int ubifs_garbage_collect(struct ubifs_info *c, int anyway)
682 "(min. space %d)", lp.lnum, lp.free, lp.dirty, 713 "(min. space %d)", lp.lnum, lp.free, lp.dirty,
683 lp.free + lp.dirty, min_space); 714 lp.free + lp.dirty, min_space);
684 715
685 if (lp.free + lp.dirty == c->leb_size) {
686 /* An empty LEB was returned */
687 dbg_gc("LEB %d is free, return it", lp.lnum);
688 /*
689 * ubifs_find_dirty_leb() doesn't return freeable index
690 * LEBs.
691 */
692 ubifs_assert(!(lp.flags & LPROPS_INDEX));
693 if (lp.free != c->leb_size) {
694 /*
695 * Write buffers must be sync'd before
696 * unmapping freeable LEBs, because one of them
697 * may contain data which obsoletes something
698 * in 'lp.pnum'.
699 */
700 ret = gc_sync_wbufs(c);
701 if (ret)
702 goto out;
703 ret = ubifs_change_one_lp(c, lp.lnum,
704 c->leb_size, 0, 0, 0,
705 0);
706 if (ret)
707 goto out;
708 }
709 ret = ubifs_leb_unmap(c, lp.lnum);
710 if (ret)
711 goto out;
712 ret = lp.lnum;
713 break;
714 }
715
716 space_before = c->leb_size - wbuf->offs - wbuf->used; 716 space_before = c->leb_size - wbuf->offs - wbuf->used;
717 if (wbuf->lnum == -1) 717 if (wbuf->lnum == -1)
718 space_before = 0; 718 space_before = 0;
diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index 3dbad6fbd1eb..1a72046efed5 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -1125,25 +1125,10 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c)
1125 } 1125 }
1126 return err; 1126 return err;
1127 } 1127 }
1128
1128 ubifs_assert(!(lp.flags & LPROPS_INDEX)); 1129 ubifs_assert(!(lp.flags & LPROPS_INDEX));
1129 lnum = lp.lnum; 1130 lnum = lp.lnum;
1130 if (lp.free + lp.dirty == c->leb_size) { 1131
1131 /* An empty LEB was returned */
1132 if (lp.free != c->leb_size) {
1133 err = ubifs_change_one_lp(c, lnum, c->leb_size,
1134 0, 0, 0, 0);
1135 if (err)
1136 return err;
1137 }
1138 err = ubifs_leb_unmap(c, lnum);
1139 if (err)
1140 return err;
1141 c->gc_lnum = lnum;
1142 dbg_rcvry("allocated LEB %d for GC", lnum);
1143 /* Run the commit */
1144 dbg_rcvry("committing");
1145 return ubifs_run_commit(c);
1146 }
1147 /* 1132 /*
1148 * There was no empty LEB so the used space in the dirtiest LEB must fit 1133 * There was no empty LEB so the used space in the dirtiest LEB must fit
1149 * in the GC head LEB. 1134 * in the GC head LEB.