From patchwork Fri Feb 5 09:23:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Skuczynski X-Patchwork-Id: 44617 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D318EB7CC2 for ; Fri, 5 Feb 2010 20:27:26 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NdKPg-0000n9-6a; Fri, 05 Feb 2010 09:23:44 +0000 Received: from mail-bw0-f221.google.com ([209.85.218.221]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NdKPY-0000mQ-V2 for linux-mtd@lists.infradead.org; Fri, 05 Feb 2010 09:23:41 +0000 Received: by bwz21 with SMTP id 21so2999159bwz.4 for ; Fri, 05 Feb 2010 01:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=Q4KZO2rnbXk5ag2c+ILYK1Qgod1gfd0BIoaK+6huzg0=; b=j5pPLxTHcONKCEUEObrD9ubyNO2LgaXCA/jT57ZW2Sfmrevr/BRRvwvLB6iFRqnAhx hwsIF92x/KcXWDe3yKYrRa/MGe7BUnYafI+DLaizCTtg5EihKNT7Z5+zjnlqn4vy3UIz z0yvS5D7CEG7OaArnuX3nhMheBUfD8oTDDMPM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=M9psj6Xzkyy2EQ2xyfA1NlrqyGPr4/ffgNZxUT0wOfmPy9GKBFwD4g+LYAm56EnmzG Bd9J6M3uh+n98W4Jzz0LRu4xiwswtPI6UQK6HXMcGdvdsFqvfI4Qt5KmAfPjqjjQyfno lynumOt/4+Blm0sSI19jJPQ5Dwhdcub5dA26s= MIME-Version: 1.0 Received: by 10.204.7.203 with SMTP id e11mr1535999bke.39.1265361815424; Fri, 05 Feb 2010 01:23:35 -0800 (PST) In-Reply-To: <4B6B221E.2060409@gmail.com> References: <1265304794.7343.135.camel@localhost> <4B6B221E.2060409@gmail.com> Date: Fri, 5 Feb 2010 10:23:35 +0100 Message-ID: Subject: Re: Emulated write failures cause block marking as bad From: Marek Skuczynski To: linux-mtd@lists.infradead.org X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100205_042337_257442_BC979891 X-CRM114-Status: GOOD ( 11.57 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- _SUMMARY_ Cc: dedekind1@gmail.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org > Okay, maybe my case is isolated because of tested system configuration, > I will try manage this case myself. > I have prepared a patch, maybe someone will find it useful. diff --git a/drivers/mtd/ubi/Kconfig.debug b/drivers/mtd/ubi/Kconfig.debug index 1e2ee22..fa1a92c 100644 --- a/drivers/mtd/ubi/Kconfig.debug +++ b/drivers/mtd/ubi/Kconfig.debug @@ -59,6 +59,14 @@ config MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES This option emulates write failures with probability 1/100. Useful for debugging and testing how UBI handlines errors. +config MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES_SAFE_ERASE + bool "Prevent write failure during the sync erase" + depends on MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES + default n + help + This option prevents write failures during the sync erase that may + cause marking the block as bad. + config MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES bool "Emulate flash erase failures" depends on MTD_UBI_DEBUG diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index c949cb4..8ff0d6a 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c @@ -194,6 +194,23 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm); } +#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES +/** + * ubi_dbg_is_write_failure - if it is time to emulate a write failure. + * + * Returns non-zero if a write failure should be emulated, otherwise returns + * zero. + */ +int ubi_dbg_is_write_failure(struct ubi_device *ubi) +{ +#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES_SAFE_ERASE + return (!ubi->write_failure_masked && !(random32() % 500)); +#else + return !(random32() % 500); +#endif +} +#endif + #endif /* CONFIG_MTD_UBI_DEBUG */ /* diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h index fa4cffe..ff77a26 100644 --- a/drivers/mtd/ubi/debug.h +++ b/drivers/mtd/ubi/debug.h @@ -114,18 +114,9 @@ static inline int ubi_dbg_is_bitflip(void) #endif #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES -/** - * ubi_dbg_is_write_failure - if it is time to emulate a write failure. - * - * Returns non-zero if a write failure should be emulated, otherwise returns - * zero. - */ -static inline int ubi_dbg_is_write_failure(void) -{ - return !(random32() % 500); -} +int ubi_dbg_is_write_failure(struct ubi_device *ubi); #else -#define ubi_dbg_is_write_failure() 0 +#define ubi_dbg_is_write_failure(ubi) 0 #endif #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES @@ -165,7 +156,7 @@ static inline int ubi_dbg_is_erase_failure(void) #define UBI_IO_DEBUG 0 #define DBG_DISABLE_BGT 0 #define ubi_dbg_is_bitflip() 0 -#define ubi_dbg_is_write_failure() 0 +#define ubi_dbg_is_write_failure(ubi) 0 #define ubi_dbg_is_erase_failure() 0 #endif /* !CONFIG_MTD_UBI_DEBUG */ diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 2904991..c164299 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -259,7 +259,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, return err > 0 ? -EINVAL : err; } - if (ubi_dbg_is_write_failure()) { + if (ubi_dbg_is_write_failure(ubi)) { dbg_err("cannot write %d bytes to PEB %d:%d " "(emulated)", len, pnum, offset); ubi_dbg_dump_stack(); diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index d8f5915..1194549 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -438,6 +438,9 @@ struct ubi_device { #ifdef CONFIG_MTD_UBI_DEBUG void *dbg_peb_buf; struct mutex dbg_buf_mutex; +#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES_SAFE_ERASE + int write_failure_masked; +#endif #endif }; diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index dc38fc5..6799c25 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c @@ -615,10 +615,15 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, ec_hdr->ec = cpu_to_be64(ec); +#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES_SAFE_ERASE + ubi->write_failure_masked = 1; +#endif + err = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr); if (err) goto out_free; + e->ec = ec; spin_lock(&ubi->wl_lock); if (e->ec > ubi->max_ec) @@ -626,6 +631,9 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, spin_unlock(&ubi->wl_lock); out_free: +#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES_SAFE_ERASE + ubi->write_failure_masked = 0; +#endif kfree(ec_hdr); return err; }