From patchwork Wed Sep 9 23:01:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7149701 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 9C758BEEC1 for ; Wed, 9 Sep 2015 23:07:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8ED0B20863 for ; Wed, 9 Sep 2015 23:07:21 +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 70FED20813 for ; Wed, 9 Sep 2015 23:07:20 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6558D182E65; Wed, 9 Sep 2015 16:07:20 -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 CC029182E65 for ; Wed, 9 Sep 2015 16:07:19 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 09 Sep 2015 16:07:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,499,1437462000"; d="scan'208";a="801223699" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.137]) by orsmga002.jf.intel.com with ESMTP; 09 Sep 2015 16:07:19 -0700 Subject: [PATCH v2 3/4] ndctl: introduce ndctl_namespace_disable_invalidate() From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 09 Sep 2015 19:01:37 -0400 Message-ID: <20150909230137.4976.64773.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20150909224404.4976.10592.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20150909224404.4976.10592.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-8-g92dd MIME-Version: 1.0 Cc: Nicholas Moulin 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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_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 is driven by the rationale that disabling a namespace should guarantee that the capacity it represents is not in active use upon return. However, we don't want to change the existing meaning of ndctl_namespace_disable() that simply means the namespace device is not bound to a driver. Introduce a new symbol, similar to ndctl_region_disable_invalidate(), that implies dependent objects like btt instances are destroyed. Note that we don't have an ndctl_namespace_disable_preserve() as enabling a namespace will dynamically re-establish the claim. The _invalidate() implies that the result of a prior call to ndctl_namespace_get_btt() on the same namespace is now an invalid pointer. Reported-by: Nicholas Moulin Signed-off-by: Dan Williams --- builtin-xable-namespace.c | 2 +- lib/blk_namespaces.c | 2 +- lib/libndctl.c | 14 ++++++++++++++ lib/libndctl.sym | 1 + lib/ndctl/libndctl.h | 1 + lib/pmem_namespaces.c | 2 +- lib/test-dpa-alloc.c | 2 +- lib/test-libndctl.c | 4 ++-- lib/test-parent-uuid.c | 7 ++----- 9 files changed, 24 insertions(+), 11 deletions(-) diff --git a/builtin-xable-namespace.c b/builtin-xable-namespace.c index 1ba616257f11..13a08633487a 100644 --- a/builtin-xable-namespace.c +++ b/builtin-xable-namespace.c @@ -116,7 +116,7 @@ int cmd_disable_namespace(int argc, const char **argv) { char *xable_usage = "ndctl disable-namespace []"; const char *namespace = parse_namespace_options(argc, argv, xable_usage); - int disabled = do_xable_namespace(namespace, ndctl_namespace_disable); + int disabled = do_xable_namespace(namespace, ndctl_namespace_disable_invalidate); if (disabled < 0) { fprintf(stderr, "error disabling namespaces: %s\n", diff --git a/lib/blk_namespaces.c b/lib/blk_namespaces.c index 040da41a64e3..c3fee58f793b 100644 --- a/lib/blk_namespaces.c +++ b/lib/blk_namespaces.c @@ -82,7 +82,7 @@ static struct ndctl_namespace *create_blk_namespace(int region_fraction, static int disable_blk_namespace(struct ndctl_namespace *ndns) { - if (ndctl_namespace_disable(ndns) < 0) + if (ndctl_namespace_disable_invalidate(ndns) < 0) return ENODEV; if (ndctl_namespace_delete(ndns) < 0) diff --git a/lib/libndctl.c b/lib/libndctl.c index 5de7359f1cc5..3f653dc06630 100644 --- a/lib/libndctl.c +++ b/lib/libndctl.c @@ -3196,6 +3196,20 @@ NDCTL_EXPORT int ndctl_namespace_disable(struct ndctl_namespace *ndns) return 0; } +NDCTL_EXPORT int ndctl_namespace_disable_invalidate(struct ndctl_namespace *ndns) +{ + struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns); + + if (btt) { + int rc = ndctl_btt_delete(btt); + + if (rc) + return rc; + } + + return ndctl_namespace_disable(ndns); +} + static int pmem_namespace_is_configured(struct ndctl_namespace *ndns) { if (ndctl_namespace_get_size(ndns) < ND_MIN_NAMESPACE_SIZE) diff --git a/lib/libndctl.sym b/lib/libndctl.sym index 3d5603757cea..cf99d6f8d2f0 100644 --- a/lib/libndctl.sym +++ b/lib/libndctl.sym @@ -136,6 +136,7 @@ global: ndctl_namespace_is_enabled; ndctl_namespace_enable; ndctl_namespace_disable; + ndctl_namespace_disable_invalidate; ndctl_namespace_is_valid; ndctl_namespace_is_configured; ndctl_namespace_delete; diff --git a/lib/ndctl/libndctl.h b/lib/ndctl/libndctl.h index 4c64f78f212c..db8345e4b4ea 100644 --- a/lib/ndctl/libndctl.h +++ b/lib/ndctl/libndctl.h @@ -288,6 +288,7 @@ const char *ndctl_namespace_get_block_device(struct ndctl_namespace *ndns); int ndctl_namespace_is_enabled(struct ndctl_namespace *ndns); int ndctl_namespace_enable(struct ndctl_namespace *ndns); int ndctl_namespace_disable(struct ndctl_namespace *ndns); +int ndctl_namespace_disable_invalidate(struct ndctl_namespace *ndns); int ndctl_namespace_is_valid(struct ndctl_namespace *ndns); int ndctl_namespace_is_configured(struct ndctl_namespace *ndns); int ndctl_namespace_delete(struct ndctl_namespace *ndns); diff --git a/lib/pmem_namespaces.c b/lib/pmem_namespaces.c index 124900269a8b..127e3bee79d8 100644 --- a/lib/pmem_namespaces.c +++ b/lib/pmem_namespaces.c @@ -60,7 +60,7 @@ static struct ndctl_namespace *create_pmem_namespace(struct ndctl_region *region static int disable_pmem_namespace(struct ndctl_namespace *ndns) { - if (ndctl_namespace_disable(ndns) < 0) + if (ndctl_namespace_disable_invalidate(ndns) < 0) return ENODEV; if (ndctl_namespace_delete(ndns) < 0) diff --git a/lib/test-dpa-alloc.c b/lib/test-dpa-alloc.c index c5d536df3881..edc403b9f7be 100644 --- a/lib/test-dpa-alloc.c +++ b/lib/test-dpa-alloc.c @@ -143,7 +143,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test) ndctl_namespace_get_devname(ndns), rc); return rc; } - ndctl_namespace_disable(ndns); + ndctl_namespace_disable_invalidate(ndns); rc = ndctl_namespace_set_size(ndns, SZ_4K); if (rc) { fprintf(stderr, "failed to init %s to size: %d\n", diff --git a/lib/test-libndctl.c b/lib/test-libndctl.c index c13958334860..696f54151562 100644 --- a/lib/test-libndctl.c +++ b/lib/test-libndctl.c @@ -930,7 +930,7 @@ static int check_namespaces(struct ndctl_region *region, close(fd); fd = -1; - if (ndctl_namespace_disable(ndns) < 0) { + if (ndctl_namespace_disable_invalidate(ndns) < 0) { fprintf(stderr, "%s: failed to disable\n", devname); rc = -ENXIO; break; @@ -970,7 +970,7 @@ static int check_namespaces(struct ndctl_region *region, if (!retry_cnt) break; - if (ndctl_namespace_disable(ndns) < 0) { + if (ndctl_namespace_disable_invalidate(ndns) < 0) { fprintf(stderr, "%s: failed to disable\n", devname); break; } diff --git a/lib/test-parent-uuid.c b/lib/test-parent-uuid.c index cf48a8c4a58b..a9d7eb1ec2dc 100644 --- a/lib/test-parent-uuid.c +++ b/lib/test-parent-uuid.c @@ -100,7 +100,7 @@ static struct ndctl_namespace *create_blk_namespace(int region_fraction, static int disable_blk_namespace(struct ndctl_namespace *ndns) { - if (ndctl_namespace_disable(ndns) < 0) + if (ndctl_namespace_disable_invalidate(ndns) < 0) return -ENODEV; if (ndctl_namespace_delete(ndns) < 0) @@ -172,19 +172,16 @@ static int do_test(struct ndctl_ctx *ctx) if (!btt) return -ENXIO; + ndctl_namespace_disable_invalidate(ndns); ndctl_btt_set_uuid(btt, btt_uuid); ndctl_btt_set_sector_size(btt, 512); ndctl_btt_set_namespace(btt, ndns); - ndctl_namespace_disable(ndns); rc = ndctl_btt_enable(btt); if (rc) { fprintf(stderr, "failed to create btt 0\n"); return rc; } - /* disable the btt */ - ndctl_btt_delete(btt); - /* re-create the namespace - this should auto-enable the btt */ disable_blk_namespace(ndns); ndns = create_blk_namespace(1, blk_region, ns_size, uuid);