From patchwork Tue Jul 28 03:14:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 6879151 X-Patchwork-Delegate: vishal.l.verma@intel.com 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 15C78C05AC for ; Tue, 28 Jul 2015 03:20:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1CF67206B6 for ; Tue, 28 Jul 2015 03:20:13 +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 290B5206AC for ; Tue, 28 Jul 2015 03:20:12 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1C106182837; Mon, 27 Jul 2015 20:20:12 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ml01.01.org (Postfix) with ESMTP id 59A7318280E for ; Mon, 27 Jul 2015 20:20:10 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 27 Jul 2015 20:20:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,560,1432623600"; d="scan'208";a="771124805" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.11]) by fmsmga002.fm.intel.com with ESMTP; 27 Jul 2015 20:20:10 -0700 Subject: [ndctl PATCH 1/3] ndctl: test blk namespace seed creation From: Dan Williams To: linux-nvdimm@lists.01.org Date: Mon, 27 Jul 2015 23:14:28 -0400 Message-ID: <20150728031428.19103.91342.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20150728030655.19103.47017.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20150728030655.19103.47017.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-8-g92dd MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 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=-3.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 kernel commit "8ca243536d21 libnvdimm: fix namespace seed creation" fixes a case whereby a namespace that is never enabled before being assigned to a BTT will cause the kernel to skip planting a new namespace seed for the BLK region. Test this condition as a backstop for the fix in the kernel. Reported-by: Nicholas Moulin Signed-off-by: Dan Williams --- lib/test-libndctl.c | 68 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/lib/test-libndctl.c b/lib/test-libndctl.c index 86441b2eb2be..a33e4db66a59 100644 --- a/lib/test-libndctl.c +++ b/lib/test-libndctl.c @@ -535,6 +535,9 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace return -ENXIO; for (i = 0; i < btt_s->num_sector_sizes; i++) { + struct ndctl_namespace *ns_seed = ndctl_region_get_namespace_seed(region); + struct ndctl_btt *btt_seed = ndctl_region_get_btt_seed(region); + btt = get_idle_btt(region); if (!btt) return -ENXIO; @@ -543,7 +546,6 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace ndctl_btt_set_uuid(btt, btt_s->uuid); ndctl_btt_set_sector_size(btt, btt_s->sector_sizes[i]); ndctl_btt_set_namespace(btt, ndns); - ndctl_namespace_disable(ndns); rc = ndctl_btt_enable(btt); if (namespace->ro == (rc == 0)) { fprintf(stderr, "%s: expected btt enable %s, %s read-%s\n", @@ -553,6 +555,24 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace namespace->ro ? "only" : "write"); return -ENXIO; } + + if (btt_seed == ndctl_region_get_btt_seed(region) + && btt == btt_seed) { + fprintf(stderr, "%s: failed to advance btt seed\n", + ndctl_region_get_devname(region)); + return -ENXIO; + } + + /* check new seed creation for BLK regions */ + if (ndctl_region_get_type(region) == ND_DEVICE_REGION_BLK) { + if (ns_seed == ndctl_region_get_namespace_seed(region) + && ndns == ns_seed) { + fprintf(stderr, "%s: failed to advance namespace seed\n", + ndctl_region_get_devname(region)); + return -ENXIO; + } + } + if (namespace->ro) { ndctl_region_set_ro(region, 0); rc = ndctl_btt_enable(btt); @@ -643,8 +663,14 @@ static int configure_namespace(struct ndctl_region *region, if (rc < 1) fprintf(stderr, "%s: is_configured: %d\n", devname, rc); + rc = check_btt_create(region, ndns, namespace); + if (rc < 0) { + fprintf(stderr, "%s: failed to create btt\n", devname); + return rc; + } + rc = ndctl_namespace_enable(ndns); - if (rc) + if (rc < 0) fprintf(stderr, "%s: enable: %d\n", devname, rc); return rc; @@ -769,9 +795,12 @@ static int check_namespaces(struct ndctl_region *region, } for (j = 0; j < namespace->num_sector_sizes; j++) { + struct btt *btt_s; + struct ndctl_btt *btt; + rc = configure_namespace(region, ndns, namespace, namespace->sector_sizes[j]); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: failed to configure namespace\n", devname); break; @@ -787,7 +816,24 @@ static int check_namespaces(struct ndctl_region *region, break; } - if (!ndctl_namespace_is_enabled(ndns)) { + /* + * On the second time through this loop we skip + * establishing btt since check_btt_autodetect() + * destroyed the inital instance. + */ + btt_s = namespace->do_configure + ? namespace->btt_settings : NULL; + + btt = ndctl_namespace_get_btt(ndns); + if (!!btt_s != !!btt) { + fprintf(stderr, "%s expected btt %s by default\n", + devname, namespace->btt_settings + ? "enabled" : "disabled"); + rc = -ENXIO; + break; + } + + if (!btt_s && !ndctl_namespace_is_enabled(ndns)) { fprintf(stderr, "%s: expected enabled by default\n", devname); rc = -ENXIO; @@ -824,7 +870,8 @@ static int check_namespaces(struct ndctl_region *region, break; } - sprintf(bdevpath, "/dev/%s", ndctl_namespace_get_block_device(ndns)); + sprintf(bdevpath, "/dev/%s", btt ? ndctl_btt_get_block_device(btt) + : ndctl_namespace_get_block_device(ndns)); fd = open(bdevpath, O_RDONLY); if (fd < 0) { fprintf(stderr, "%s: failed to open(%s, O_RDONLY)\n", @@ -881,12 +928,6 @@ static int check_namespaces(struct ndctl_region *region, close(fd); fd = -1; - if (check_btt_create(region, ndns, namespace) < 0) { - fprintf(stderr, "%s: failed to create btt\n", devname); - rc = -ENXIO; - break; - } - if (ndctl_namespace_disable(ndns) < 0) { fprintf(stderr, "%s: failed to disable\n", devname); rc = -ENXIO; @@ -899,8 +940,7 @@ static int check_namespaces(struct ndctl_region *region, break; } - if (namespace->btt_settings - && check_btt_autodetect(bus, ndns, buf, + if (btt_s && check_btt_autodetect(bus, ndns, buf, namespace) < 0) { fprintf(stderr, "%s, failed btt autodetect\n", devname); rc = -ENXIO; @@ -911,7 +951,7 @@ static int check_namespaces(struct ndctl_region *region, * if the namespace is being tested with a btt, there is no * point testing different sector sizes for the namespace itself */ - if (namespace->btt_settings) + if (btt_s) break; /*