linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] UBIFS: remove duplicated code
@ 2011-04-26  7:29 Artem Bityutskiy
  2011-04-26  7:29 ` [PATCH 2/4] UBIFS: remove dead GC LEB recovery piece of code Artem Bityutskiy
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2011-04-26  7:29 UTC (permalink / raw)
  To: MTD list; +Cc: Adrian Hunter

From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

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>
---
 fs/ubifs/gc.c       |   62 +++++++++++++++++++++++++-------------------------
 fs/ubifs/recovery.c |   19 +--------------
 2 files changed, 33 insertions(+), 48 deletions(-)

diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
index 151f108..082d21b 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)
 	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;
diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index 3dbad6f..1a72046 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -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.
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] UBIFS: remove dead GC LEB recovery piece of code
  2011-04-26  7:29 [PATCH 1/4] UBIFS: remove duplicated code Artem Bityutskiy
@ 2011-04-26  7:29 ` Artem Bityutskiy
  2011-04-26  7:29 ` [PATCH 3/4] UBIFS: print useful debugging messages when cannot recover gc_lnum Artem Bityutskiy
  2011-04-26  7:29 ` [PATCH 4/4] UBIFS: dump the stack on errors in failure mode too Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2011-04-26  7:29 UTC (permalink / raw)
  To: MTD list; +Cc: Adrian Hunter

From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

This patch removes a piece of code in 'ubifs_rcvry_gc_commit()' which is never
executed. We call 'ubifs_find_dirty_leb()' function with min_space =
wbuf->offs, so if it returns us an LEB, it is guaranteed to have at lease
'wbuf->offs' bytes of free+dirty space. So we can remove the subsequent code
which deals with "returned LEB has less than 'wbuf->offs' bytes of free+dirty
space". This simplifies 'ubifs_rcvry_gc_commit()' a little.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 fs/ubifs/recovery.c |   13 +------------
 1 files changed, 1 insertions(+), 12 deletions(-)

diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index 1a72046..3e0eedbe 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -1127,21 +1127,10 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c)
 	}
 
 	ubifs_assert(!(lp.flags & LPROPS_INDEX));
+	ubifs_assert(lp.free + lp.dirty >= wbuf->offs);
 	lnum = lp.lnum;
 
 	/*
-	 * There was no empty LEB so the used space in the dirtiest LEB must fit
-	 * in the GC head LEB.
-	 */
-	if (lp.free + lp.dirty < wbuf->offs) {
-		dbg_rcvry("LEB %d doesn't fit in GC head LEB %d:%d",
-			  lnum, wbuf->lnum, wbuf->offs);
-		err = ubifs_return_leb(c, lnum);
-		if (err)
-			return err;
-		goto find_free;
-	}
-	/*
 	 * We run the commit before garbage collection otherwise subsequent
 	 * mounts will see the GC and orphan deletion in a different order.
 	 */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] UBIFS: print useful debugging messages when cannot recover gc_lnum
  2011-04-26  7:29 [PATCH 1/4] UBIFS: remove duplicated code Artem Bityutskiy
  2011-04-26  7:29 ` [PATCH 2/4] UBIFS: remove dead GC LEB recovery piece of code Artem Bityutskiy
@ 2011-04-26  7:29 ` Artem Bityutskiy
  2011-04-26  7:29 ` [PATCH 4/4] UBIFS: dump the stack on errors in failure mode too Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2011-04-26  7:29 UTC (permalink / raw)
  To: MTD list; +Cc: Adrian Hunter

From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

If we fail to recover the gc_lnum we just return an error and it then
it is difficult to figure out why this happened. This patch adds useful
debugging information which should make it easier to debug the failure.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 fs/ubifs/recovery.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index 3e0eedbe..3d2598d 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -1177,6 +1177,8 @@ find_free:
 	lnum = ubifs_find_free_leb_for_idx(c);
 	if (lnum < 0) {
 		dbg_err("could not find an empty LEB");
+		dbg_dump_lprops(c);
+		dbg_dump_budg(c, &c->bi);
 		return lnum;
 	}
 	/* And reset the index flag */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] UBIFS: dump the stack on errors in failure mode too
  2011-04-26  7:29 [PATCH 1/4] UBIFS: remove duplicated code Artem Bityutskiy
  2011-04-26  7:29 ` [PATCH 2/4] UBIFS: remove dead GC LEB recovery piece of code Artem Bityutskiy
  2011-04-26  7:29 ` [PATCH 3/4] UBIFS: print useful debugging messages when cannot recover gc_lnum Artem Bityutskiy
@ 2011-04-26  7:29 ` Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2011-04-26  7:29 UTC (permalink / raw)
  To: MTD list; +Cc: Adrian Hunter

From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

When UBIFS is in the failure mode (used for power cut emulation testing) we for
some reasons do not dump the stack in many places, e.g., in assertions.
Probably at early days we had too many of them and disabled this to make the
development easier, but then never enabled. Nowadays I sometimes observe
assertion failures during power cut testing, but the useful stackdump is not
printed, which is bad. This patch makes UBIFS always print the stackdump when
debugging is enabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 fs/ubifs/debug.h |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h
index 8934c12..f3e235f 100644
--- a/fs/ubifs/debug.h
+++ b/fs/ubifs/debug.h
@@ -107,10 +107,7 @@ struct ubifs_debug_info {
 	}                                                                      \
 } while (0)
 
-#define dbg_dump_stack() do {                                                  \
-	if (!dbg_failure_mode)                                                 \
-		dump_stack();                                                  \
-} while (0)
+#define dbg_dump_stack() dump_stack()
 
 /* Generic debugging messages */
 #define dbg_msg(fmt, ...) do {                                                 \
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-04-26  7:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-26  7:29 [PATCH 1/4] UBIFS: remove duplicated code Artem Bityutskiy
2011-04-26  7:29 ` [PATCH 2/4] UBIFS: remove dead GC LEB recovery piece of code Artem Bityutskiy
2011-04-26  7:29 ` [PATCH 3/4] UBIFS: print useful debugging messages when cannot recover gc_lnum Artem Bityutskiy
2011-04-26  7:29 ` [PATCH 4/4] UBIFS: dump the stack on errors in failure mode too Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).