From patchwork Thu Mar 17 00:54:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8606321 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 78F74C0553 for ; Thu, 17 Mar 2016 00:55:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4BF3D20279 for ; Thu, 17 Mar 2016 00:55:14 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0BA1F20268 for ; Thu, 17 Mar 2016 00:55:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9706E1A1DEF; Wed, 16 Mar 2016 17:55:32 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ml01.01.org (Postfix) with ESMTP id 52E8C1A1DF4 for ; Wed, 16 Mar 2016 17:55:31 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 16 Mar 2016 17:55:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,347,1455004800"; d="scan'208";a="938918368" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.14]) by fmsmga002.fm.intel.com with ESMTP; 16 Mar 2016 17:55:12 -0700 Subject: [ndctl PATCH 3/5] Revert "ndctl: fix error handling in ND_BLK & PMEM tests" From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 16 Mar 2016 17:54:45 -0700 Message-ID: <20160317005445.3025.6166.stgit@dwillia2-desk3.jf.intel.com> In-Reply-To: <20160317005429.3025.395.stgit@dwillia2-desk3.jf.intel.com> References: <20160317005429.3025.395.stgit@dwillia2-desk3.jf.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 289f98097a25abd71fac7d8324e89abb4abfb19d. For pass/fail we only care about these routines returning non-zero. The current opportunistic conversion of negative libndctl return values runs the risk of a -EBADFD causing a false positive "skip test" indication. It also makes these tests follow the same error reporting scheme as the other tests. Signed-off-by: Dan Williams --- test/blk_namespaces.c | 77 +++++++++++++++++++++++++----------------------- test/pmem_namespaces.c | 46 +++++++++++++++-------------- 2 files changed, 64 insertions(+), 59 deletions(-) diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c index 41c5ce0b1bd7..f3e7a5592e2a 100644 --- a/test/blk_namespaces.c +++ b/test/blk_namespaces.c @@ -82,21 +82,22 @@ static struct ndctl_namespace *create_blk_namespace(int region_fraction, static int disable_blk_namespace(struct ndctl_namespace *ndns) { if (ndctl_namespace_disable_invalidate(ndns) < 0) - return ENODEV; + return -ENODEV; if (ndctl_namespace_delete(ndns) < 0) - return ENODEV; + return -ENODEV; return 0; } static int ns_do_io(const char *bdev) { + int fd, i; + int rc = 0; const int page_size = 4096; const int num_pages = 4; unsigned long num_dev_pages, num_blocks; off_t addr; - int fd, i, rc; void *random_page[num_pages]; void *blk_page[num_pages]; @@ -120,13 +121,13 @@ static int ns_do_io(const char *bdev) /* read random data into random_page */ if ((fd = open("/dev/urandom", O_RDONLY)) < 0) { - rc = errno; err("open"); + rc = -ENODEV; goto err_free_all; } - if (read(fd, random_page[0], page_size * num_pages) < 0) { - rc = errno; + rc = read(fd, random_page[0], page_size * num_pages); + if (rc < 0) { err("read"); close(fd); goto err_free_all; @@ -134,10 +135,9 @@ static int ns_do_io(const char *bdev) close(fd); - /* figure out our dev size */ if ((fd = open(bdev, O_RDWR|O_DIRECT)) < 0) { - rc = errno; err("open"); + rc = -ENODEV; goto err_free_all; } @@ -145,48 +145,45 @@ static int ns_do_io(const char *bdev) num_dev_pages = num_blocks / 8; /* write the random data out to each of the segments */ - if (pwrite(fd, random_page[0], page_size, 0) < 0) { - rc = errno; + rc = pwrite(fd, random_page[0], page_size, 0); + if (rc < 0) { err("write"); goto err_close; } /* two pages that span the region discontinuity */ addr = page_size * (num_dev_pages/2 - 1); - - if (pwrite(fd, random_page[1], page_size*2, addr) < 0) { - rc = errno; + rc = pwrite(fd, random_page[1], page_size*2, addr); + if (rc < 0) { err("write"); goto err_close; } addr = page_size * (num_dev_pages - 1); - - if (pwrite(fd, random_page[3], page_size, addr) < 0) { - rc = errno; + rc = pwrite(fd, random_page[3], page_size, addr); + if (rc < 0) { err("write"); goto err_close; } /* read back the random data into blk_page */ - if (pread(fd, blk_page[0], page_size, 0) < 0) { - rc = errno; + rc = pread(fd, blk_page[0], page_size, 0); + if (rc < 0) { err("read"); goto err_close; } /* two pages that span the region discontinuity */ addr = page_size * (num_dev_pages/2 - 1); - if (pread(fd, blk_page[1], page_size*2, addr) < 0) { - rc = errno; + rc = pread(fd, blk_page[1], page_size*2, addr); + if (rc < 0) { err("read"); goto err_close; } addr = page_size * (num_dev_pages - 1); - - if (pread(fd, blk_page[3], page_size, addr) < 0) { - rc = errno; + rc = pread(fd, blk_page[3], page_size, addr); + if (rc < 0) { err("read"); goto err_close; } @@ -194,9 +191,11 @@ static int ns_do_io(const char *bdev) /* verify the data */ if (memcmp(random_page[0], blk_page[0], page_size * num_pages)) { fprintf(stderr, "Block data miscompare\n"); - rc = EIO; + rc = -EIO; + goto err_close; } + rc = 0; err_close: close(fd); err_free_all: @@ -218,8 +217,8 @@ int test_blk_namespaces(int log_level) struct ndctl_region *region, *blk_region = NULL; struct ndctl_dimm *dimm; - rc = -ndctl_new(&ctx); - if (rc) + rc = ndctl_new(&ctx); + if (rc < 0) return rc; ndctl_set_log_priority(ctx, log_level); @@ -229,17 +228,18 @@ int test_blk_namespaces(int log_level) fprintf(stderr, "%s: failed to find NFIT-provider\n", comm); rc = 77; goto err_nobus; - } else + } else { fprintf(stderr, "%s: found provider: %s\n", comm, ndctl_bus_get_provider(bus)); + } /* get the system to a clean state */ ndctl_region_foreach(bus, region) ndctl_region_disable_invalidate(region); ndctl_dimm_foreach(bus, dimm) { - rc = -ndctl_dimm_zero_labels(dimm); - if (rc) { + rc = ndctl_dimm_zero_labels(dimm); + if (rc < 0) { fprintf(stderr, "failed to zero %s\n", ndctl_dimm_get_devname(dimm)); return rc; @@ -253,12 +253,13 @@ int test_blk_namespaces(int log_level) break; } - rc = ENODEV; if (!blk_region || ndctl_region_enable(blk_region) < 0) { fprintf(stderr, "%s: failed to find block region\n", comm); + rc = -ENODEV; goto err_cleanup; } + rc = -ENODEV; ndns[0] = create_blk_namespace(4, blk_region); if (!ndns[0]) { fprintf(stderr, "%s: failed to create block namespace\n", comm); @@ -272,7 +273,7 @@ int test_blk_namespaces(int log_level) } rc = disable_blk_namespace(ndns[0]); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: failed to disable block namespace\n", comm); goto err_cleanup; } @@ -280,30 +281,32 @@ int test_blk_namespaces(int log_level) ndns[0] = create_blk_namespace(2, blk_region); if (!ndns[0]) { fprintf(stderr, "%s: failed to create block namespace\n", comm); - rc = ENODEV; + rc = -ENODEV; goto err_cleanup; } rc = disable_blk_namespace(ndns[1]); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: failed to disable block namespace\n", comm); goto err_cleanup; } + rc = -ENODEV; ndns[1] = create_blk_namespace(2, blk_region); if (!ndns[1]) { fprintf(stderr, "%s: failed to create block namespace\n", comm); - rc = ENODEV; goto err_cleanup; } /* okay, all set up, do some I/O */ + rc = -EIO; sprintf(bdev, "/dev/%s", ndctl_namespace_get_block_device(ndns[0])); - rc = ns_do_io(bdev); - if (rc) + if (ns_do_io(bdev)) goto err_cleanup; sprintf(bdev, "/dev/%s", ndctl_namespace_get_block_device(ndns[1])); - rc = ns_do_io(bdev); + if (ns_do_io(bdev)) + goto err_cleanup; + rc = 0; err_cleanup: if (blk_region) { diff --git a/test/pmem_namespaces.c b/test/pmem_namespaces.c index 17c301947fa4..24f307df0c81 100644 --- a/test/pmem_namespaces.c +++ b/test/pmem_namespaces.c @@ -60,10 +60,10 @@ static struct ndctl_namespace *create_pmem_namespace(struct ndctl_region *region static int disable_pmem_namespace(struct ndctl_namespace *ndns) { if (ndctl_namespace_disable_invalidate(ndns) < 0) - return ENODEV; + return -ENODEV; if (ndctl_namespace_delete(ndns) < 0) - return ENODEV; + return -ENODEV; return 0; } @@ -73,8 +73,9 @@ static int ns_do_io(const char *bdev) unsigned long num_dev_pages, num_blocks; const int page_size = 4096; const int num_pages = 2; - int fd, i, rc; off_t addr; + int rc = 0; + int fd, i; void *random_page[num_pages]; void *pmem_page[num_pages]; @@ -98,13 +99,13 @@ static int ns_do_io(const char *bdev) /* read random data into random_page */ if ((fd = open("/dev/urandom", O_RDONLY)) < 0) { - rc = errno; err("open"); + rc = -ENODEV; goto err_free_all; } - if (read(fd, random_page[0], page_size * num_pages) < 0) { - rc = errno; + rc = read(fd, random_page[0], page_size * num_pages); + if (rc < 0) { err("read"); close(fd); goto err_free_all; @@ -114,8 +115,8 @@ static int ns_do_io(const char *bdev) /* figure out our dev size */ if ((fd = open(bdev, O_RDWR|O_DIRECT)) < 0) { - rc = errno; err("open"); + rc = -ENODEV; goto err_free_all; } @@ -123,29 +124,29 @@ static int ns_do_io(const char *bdev) num_dev_pages = num_blocks / 8; /* write the random data out to each of the segments */ - if (pwrite(fd, random_page[0], page_size, 0) < 0) { - rc = errno; + rc = pwrite(fd, random_page[0], page_size, 0); + if (rc < 0) { err("write"); goto err_close; } addr = page_size * (num_dev_pages - 1); - if (pwrite(fd, random_page[1], page_size, addr) < 0) { - rc = errno; + rc = pwrite(fd, random_page[1], page_size, addr); + if (rc < 0) { err("write"); goto err_close; } /* read back the random data into pmem_page */ - if (pread(fd, pmem_page[0], page_size, 0) < 0) { - rc = errno; + rc = pread(fd, pmem_page[0], page_size, 0); + if (rc < 0) { err("read"); goto err_close; } addr = page_size * (num_dev_pages - 1); - if (pread(fd, pmem_page[1], page_size, addr) < 0) { - rc = errno; + rc = pread(fd, pmem_page[1], page_size, addr); + if (rc < 0) { err("read"); goto err_close; } @@ -153,10 +154,11 @@ static int ns_do_io(const char *bdev) /* verify the data */ if (memcmp(random_page[0], pmem_page[0], page_size * num_pages)) { fprintf(stderr, "PMEM data miscompare\n"); - rc = EIO; + rc = -EIO; goto err_close; } + rc = 0; err_close: close(fd); err_free_all: @@ -178,8 +180,8 @@ int test_pmem_namespaces(int log_level) char bdev[50]; int rc; - rc = -ndctl_new(&ctx); - if (rc) + rc = ndctl_new(&ctx); + if (rc < 0) return rc; ndctl_set_log_priority(ctx, log_level); @@ -198,8 +200,8 @@ int test_pmem_namespaces(int log_level) ndctl_region_disable_invalidate(region); ndctl_dimm_foreach(bus, dimm) { - rc = -ndctl_dimm_zero_labels(dimm); - if (rc) { + rc = ndctl_dimm_zero_labels(dimm); + if (rc < 0) { fprintf(stderr, "failed to zero %s\n", ndctl_dimm_get_devname(dimm)); return rc; @@ -215,14 +217,14 @@ int test_pmem_namespaces(int log_level) if (!pmem_region || ndctl_region_enable(pmem_region) < 0) { fprintf(stderr, "%s: failed to find PMEM region\n", comm); - rc = ENODEV; + rc = -ENODEV; goto err; } + rc = -ENODEV; ndns = create_pmem_namespace(pmem_region); if (!ndns) { fprintf(stderr, "%s: failed to create PMEM namespace\n", comm); - rc = ENODEV; goto err; }