Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
From: <chengzhihao1@huawei.com>
To: <david.oberhollenzer@sigma-star.at>, <richard@nod.at>,
	<boris.brezillon@bootlin.com>, <david@sigma-star.at>,
	<artem.bityutskiy@linux.intel.com>, <yi.zhang@huawei.com>
Cc: chengzhihao1@huawei.com, linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH mtd-utils] ubi-tests: mkvol test: Checks return value 'ENOSPC' for 'ubi_mkvol'
Date: Fri, 14 Jun 2019 20:18:48 +0800
Message-ID: <1560514728-54932-1-git-send-email-chengzhihao1@huawei.com> (raw)

From: Zhihao Cheng <chengzhihao1@huawei.com>

UBI tests try to create too many volumes in mkvol_bad and mkvol_basic.
Currently mtd-utils allows return value 'ENFILE' from 'ubi_mkvol', that
works fine in most situations. But what if the number of PEBs equals to
the maximum count of volumes? For example, mkvol_basic test will fail in
a 64MiB flash with 512KiB PEB size.
Following is the output of mkvol_basic test:

  ======================================================================
  ======================================================================
  ======================================================================
  Test on mtdram, fastmap enabled, VID header offset factor 1
  ======================================================================
  ======================================================================
  ======================================================================
  mtdram: 64MiB, PEB size 512KiB, fastmap enabled
  Running mkvol_basic /dev/ubi0
  [mkvol_basic] mkvol_multiple():182: function ubi_mkvol() failed with
  error 28 (No space left on device)
  [mkvol_basic] mkvol_multiple():183: vol_id 122
  Error: mkvol_basic failed
  FAILURE

The reason is that there is no available PEB to support a new volume. We
can see following verbose in dmesg:

  ubi0: attached mtd0 (name "mtdram test device", size 64 MiB)
  ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
  ubi0: available PEBs: 122, total reserved PEBs: 6, PEBs reserved for
  bad PEB handling: 0

The maximum count of volumes is 128, so we can create 128 volumes
theoretically. But there are 122 available PEBs becauese of existence of
reserved PEBs. In addition, a volume occupies at least one PEB. Actually,
we can only create 122 volumes, Therefore, 'ubi_mkvol' returns 'ENOSPC'
when mkvol_basic tries to create 123rd volume. And we can see
corresponding error message in dmesg:

  ubi0 error: ubi_create_volume [ubi]: not enough PEBs, only 0 available
  ubi0 error: ubi_create_volume [ubi]: cannot create volume 122, error -28

So, 'ENOSPC' can happen before 'ENFILE' in flash with a small amount of
PEBs. This patch checks return value 'ENOSPC' for 'ubi_mkvol' when mkvol
test is trying to create too many volumes.

----------------------------------------

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
 tests/ubi-tests/mkvol_bad.c   | 2 +-
 tests/ubi-tests/mkvol_basic.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/ubi-tests/mkvol_bad.c b/tests/ubi-tests/mkvol_bad.c
index 7e46726..a5143e3 100644
--- a/tests/ubi-tests/mkvol_bad.c
+++ b/tests/ubi-tests/mkvol_bad.c
@@ -200,7 +200,7 @@ static int test_mkvol(void)
 			 * Note, because of gluebi we may be unable to create
 			 * dev_info.max_vol_count devices (MTD restrictions).
 			 */
-			if (errno == ENFILE)
+			if (errno == ENFILE || errno == ENOSPC)
 				break;
 			failed("ubi_mkvol");
 			errorm("vol_id %d", i);
diff --git a/tests/ubi-tests/mkvol_basic.c b/tests/ubi-tests/mkvol_basic.c
index c7c6984..cc3f7ba 100644
--- a/tests/ubi-tests/mkvol_basic.c
+++ b/tests/ubi-tests/mkvol_basic.c
@@ -178,7 +178,7 @@ static int mkvol_multiple(void)
 		req.name = nm;
 
 		if (ubi_mkvol(libubi, node, &req)) {
-			if (errno == ENFILE) {
+			if (errno == ENFILE || errno == ENOSPC) {
 				max = i;
 				break;
 			}
-- 
2.7.4


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 12:18 chengzhihao1 [this message]
2019-06-17  7:04 ` David Oberhollenzer

Reply instructions:

You may reply publically 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=1560514728-54932-1-git-send-email-chengzhihao1@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=david.oberhollenzer@sigma-star.at \
    --cc=david@sigma-star.at \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=yi.zhang@huawei.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

Linux-mtd Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mtd/0 linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ https://lore.kernel.org/linux-mtd \
		linux-mtd@lists.infradead.org linux-mtd@archiver.kernel.org
	public-inbox-index linux-mtd


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-mtd


AGPL code for this site: git clone https://public-inbox.org/ public-inbox