mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com,
	Heinz.Egger@linutronix.de, thomas.wucher@linutronix.de,
	shmulik.ladkani@gmail.com, tglx@linutronix.de,
	tim.bird@am.sony.com, Marius.Mazarel@ugal.ro,
	artem.bityutskiy@linux.intel.com, nyoushchenko@mvista.com,
	Richard Weinberger <richard@nod.at>
Subject: [PATCH 6/7] UBI: Fastmap: Reuse all fastmap PEB if no free PEBs are available
Date: Sat, 23 Jun 2012 15:03:21 +0200	[thread overview]
Message-ID: <1340456602-46050-7-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1340456602-46050-1-git-send-email-richard@nod.at>

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |   42 ++++++++++++++++++++++++++++++++----------
 1 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index acd0561..ecbed52 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1423,7 +1423,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 		tmp_e = ubi_wl_get_fm_peb(ubi, 0);
 		spin_unlock(&ubi->wl_lock);
 
-		if (!tmp_e) {
+		if (!tmp_e && !old_fm) {
 			int j;
 			ubi_err("could not get any free erase block");
 
@@ -1432,10 +1432,28 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 
 			ret = -ENOSPC;
 			goto err;
-		}
+		} else if (!tmp_e && old_fm) {
+			ret = erase_block(ubi, old_fm->e[i]->pnum);
+			if (ret < 0) {
+				int j;
+
+				for (j = 1; j < i; j++)
+					ubi_wl_put_fm_peb(ubi, new_fm->e[j], 0);
+
+				ubi_err("could not erase old fastmap PEB");
+				goto err;
+			}
 
-		new_fm->e[i]->pnum = tmp_e->pnum;
-		new_fm->e[i]->ec = tmp_e->ec;
+			new_fm->e[i]->pnum = old_fm->e[i]->pnum;
+			new_fm->e[i]->ec = old_fm->e[i]->ec;
+		} else {
+			new_fm->e[i]->pnum = tmp_e->pnum;
+			new_fm->e[i]->ec = tmp_e->ec;
+
+			if (old_fm)
+				ubi_wl_put_fm_peb(ubi, old_fm->e[i],
+						  old_fm->to_be_tortured[i]);
+		}
 	}
 
 	spin_lock(&ubi->wl_lock);
@@ -1447,7 +1465,11 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 		if (!tmp_e) {
 			ret = erase_block(ubi, old_fm->e[0]->pnum);
 			if (ret < 0) {
+				int i;
 				ubi_err("could not erase old anchor PEB");
+
+				for (i = 1; i < new_fm->used_blocks; i++)
+					ubi_wl_put_fm_peb(ubi, new_fm->e[i], 0);
 				goto err;
 			}
 
@@ -1461,14 +1483,14 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 			new_fm->e[0]->pnum = tmp_e->pnum;
 			new_fm->e[0]->ec = tmp_e->ec;
 		}
-
-		/* return all other fastmap block to the wl system */
-		for (i = 1; i < old_fm->used_blocks; i++)
-			ubi_wl_put_fm_peb(ubi, old_fm->e[i],
-					  old_fm->to_be_tortured[i]);
 	} else {
 		if (!tmp_e) {
-			ubi_err("could not find an anchor PEB");
+			int i;
+			ubi_err("could not find any anchor PEB");
+
+			for (i = 1; i < new_fm->used_blocks; i++)
+				ubi_wl_put_fm_peb(ubi, new_fm->e[i], 0);
+
 			ret = -ENOSPC;
 			goto err;
 		}
-- 
1.7.6.5


  parent reply	other threads:[~2012-06-23 13:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-23 13:03 UBI fastmap updates Richard Weinberger
2012-06-23 13:03 ` [PATCH 1/7] UBI: Fastmap: Modify the WL sub-system to prodcue a free anchor PEB Richard Weinberger
2012-06-23 13:03 ` [PATCH 2/7] UBI: Fastmap: Fix WARN_ON() Richard Weinberger
2012-06-23 13:03 ` [PATCH 3/7] UBI: Fastmap: Ensure that not all anchor PEBs go into a pool Richard Weinberger
2012-06-23 13:03 ` [PATCH 4/7] UBI: Fastmap: Fix ubi_assert() Richard Weinberger
2012-06-23 13:03 ` [PATCH 5/7] UBI: Fastmap: Kill max_pnum logic Richard Weinberger
2012-06-23 13:03 ` Richard Weinberger [this message]
2012-06-23 13:03 ` [PATCH 7/7] UBI: Fastmap: Get rid of fm_pool_mutex Richard Weinberger
2012-06-27  4:20 ` UBI fastmap updates Namjae Jeon
2012-06-27  6:48   ` Nikita V. Youshchenko
2012-06-27  7:17     ` Richard Weinberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340456602-46050-7-git-send-email-richard@nod.at \
    --to=richard@nod.at \
    --cc=Heinz.Egger@linutronix.de \
    --cc=Marius.Mazarel@ugal.ro \
    --cc=adrian.hunter@intel.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=nyoushchenko@mvista.com \
    --cc=shmulik.ladkani@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.wucher@linutronix.de \
    --cc=tim.bird@am.sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®