From patchwork Sat Aug 3 09:52:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 264411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1DDB42C0087 for ; Sat, 3 Aug 2013 19:54:59 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V5YXY-00030j-Jq; Sat, 03 Aug 2013 09:54:25 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V5YXE-0006fS-Ag; Sat, 03 Aug 2013 09:54:04 +0000 Received: from mail-pd0-x22a.google.com ([2607:f8b0:400e:c02::22a]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V5YWo-0006Y7-LS for linux-mtd@lists.infradead.org; Sat, 03 Aug 2013 09:53:58 +0000 Received: by mail-pd0-f170.google.com with SMTP id x10so1510452pdj.1 for ; Sat, 03 Aug 2013 02:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=iIXVDS4Kw9xluhQ4lZoM4XYjdxb8d2G/MZWAI4SNeAU=; b=q5K6VfSTHsb0yx4pLx4Ltuv26kGXvLPTPH3R63Kojy+B9fIL3Q2T9WWu61bW+9Krcw 1fFmoTNIle6zRroX8zKXv40dwKJrlkwFClfXNJIAAyaIooEbbro5zymU/PCMAOSO4wex 4kL9k9YOsNEo6BVfl+sTYZTV0QD5SNnJSX+enIgIftap/dG7PSRN0oKXZprxvnTxL1vZ k1c3fU+DqzI+gip61gEreYEHS8Dhl/c8Z4fVDWdOs8SvFAJAzW8YCYPMJfJbnBiKebPH wlEJWI21LBu8aTDaAxjUagl7y24WjaCavfdVRhTt4QQ/FId17SeI2HNRS08orftLCZaE GsAg== X-Received: by 10.68.220.1 with SMTP id ps1mr12174520pbc.30.1375523597014; Sat, 03 Aug 2013 02:53:17 -0700 (PDT) Received: from localhost.localdomain (KD113145060135.ppp-bb.dion.ne.jp. [113.145.60.135]) by mx.google.com with ESMTPSA id ib9sm15295755pbc.43.2013.08.03.02.53.15 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 03 Aug 2013 02:53:16 -0700 (PDT) From: Akinobu Mita To: linux-mtd@lists.infradead.org Subject: [PATCH -next v2 07/10] mtd: mtd_stresstest: use mtd_test helpers Date: Sat, 3 Aug 2013 18:52:13 +0900 Message-Id: <1375523536-32671-8-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1375523536-32671-1-git-send-email-akinobu.mita@gmail.com> References: <1375523536-32671-1-git-send-email-akinobu.mita@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130803_055338_933416_59F0ADFF X-CRM114-Status: GOOD ( 18.90 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (akinobu.mita[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Artem Bityutskiy , Vikram Narayanan , Akinobu Mita , Adrian Hunter , Brian Norris , David Woodhouse X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Use mtdtest_read(), mtdtest_write(), mtdtest_erase_eraseblock(), and mtdtest_scan_for_bad_eraseblocks() in mtd_test helpers. Signed-off-by: Akinobu Mita Cc: Brian Norris Cc: Vikram Narayanan Cc: Adrian Hunter Cc: Artem Bityutskiy Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org --- * Changes from v1 - follow the changes of helper functions drivers/mtd/tests/stresstest.c | 86 ++++++------------------------------------ 1 file changed, 12 insertions(+), 74 deletions(-) diff --git a/drivers/mtd/tests/stresstest.c b/drivers/mtd/tests/stresstest.c index 3a95e61..1695248 100644 --- a/drivers/mtd/tests/stresstest.c +++ b/drivers/mtd/tests/stresstest.c @@ -31,6 +31,8 @@ #include #include +#include "mtd_test.h" + static int dev = -EINVAL; module_param(dev, int, S_IRUGO); MODULE_PARM_DESC(dev, "MTD device number to use"); @@ -81,46 +83,8 @@ static int rand_len(int offs) return len; } -static int erase_eraseblock(int ebnum) -{ - int err; - struct erase_info ei; - loff_t addr = ebnum * mtd->erasesize; - - memset(&ei, 0, sizeof(struct erase_info)); - ei.mtd = mtd; - ei.addr = addr; - ei.len = mtd->erasesize; - - err = mtd_erase(mtd, &ei); - if (unlikely(err)) { - pr_err("error %d while erasing EB %d\n", err, ebnum); - return err; - } - - if (unlikely(ei.state == MTD_ERASE_FAILED)) { - pr_err("some erase error occurred at EB %d\n", - ebnum); - return -EIO; - } - - return 0; -} - -static int is_block_bad(int ebnum) -{ - loff_t addr = ebnum * mtd->erasesize; - int ret; - - ret = mtd_block_isbad(mtd, addr); - if (ret) - pr_info("block %d is bad\n", ebnum); - return ret; -} - static int do_read(void) { - size_t read; int eb = rand_eb(); int offs = rand_offs(); int len = rand_len(offs), err; @@ -133,14 +97,10 @@ static int do_read(void) len = mtd->erasesize - offs; } addr = eb * mtd->erasesize + offs; - err = mtd_read(mtd, addr, len, &read, readbuf); - if (mtd_is_bitflip(err)) - err = 0; - if (unlikely(err || read != len)) { + err = mtdtest_read(mtd, addr, len, readbuf); + if (unlikely(err)) { pr_err("error: read failed at 0x%llx\n", (long long)addr); - if (!err) - err = -EINVAL; return err; } return 0; @@ -149,12 +109,11 @@ static int do_read(void) static int do_write(void) { int eb = rand_eb(), offs, err, len; - size_t written; loff_t addr; offs = offsets[eb]; if (offs >= mtd->erasesize) { - err = erase_eraseblock(eb); + err = mtdtest_erase_eraseblock(mtd, eb); if (err) return err; offs = offsets[eb] = 0; @@ -165,19 +124,17 @@ static int do_write(void) if (bbt[eb + 1]) len = mtd->erasesize - offs; else { - err = erase_eraseblock(eb + 1); + err = mtdtest_erase_eraseblock(mtd, eb + 1); if (err) return err; offsets[eb + 1] = 0; } } addr = eb * mtd->erasesize + offs; - err = mtd_write(mtd, addr, len, &written, writebuf); - if (unlikely(err || written != len)) { + err = mtdtest_write(mtd, addr, len, writebuf); + if (unlikely(err)) { pr_err("error: write failed at 0x%llx\n", (long long)addr); - if (!err) - err = -EINVAL; return err; } offs += len; @@ -197,28 +154,6 @@ static int do_operation(void) return do_write(); } -static int scan_for_bad_eraseblocks(void) -{ - int i, bad = 0; - - bbt = kzalloc(ebcnt, GFP_KERNEL); - if (!bbt) - return -ENOMEM; - - if (!mtd_can_have_bb(mtd)) - return 0; - - pr_info("scanning for bad eraseblocks\n"); - for (i = 0; i < ebcnt; ++i) { - bbt[i] = is_block_bad(i) ? 1 : 0; - if (bbt[i]) - bad += 1; - cond_resched(); - } - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); - return 0; -} - static int __init mtd_stresstest_init(void) { int err; @@ -280,7 +215,10 @@ static int __init mtd_stresstest_init(void) offsets[i] = mtd->erasesize; prandom_bytes(writebuf, bufsize); - err = scan_for_bad_eraseblocks(); + bbt = kzalloc(ebcnt, GFP_KERNEL); + if (!bbt) + goto out; + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); if (err) goto out;