From patchwork Sat Nov 11 23:59:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10054575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 17B1A6057F for ; Sun, 12 Nov 2017 00:08:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07C2A29B0F for ; Sun, 12 Nov 2017 00:08:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0DFC29B15; Sun, 12 Nov 2017 00:08:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 74F0F29B0F for ; Sun, 12 Nov 2017 00:08:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8FF6320359A89; Sat, 11 Nov 2017 16:04:02 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C272D20359A86 for ; Sat, 11 Nov 2017 16:04:01 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Nov 2017 16:08:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,380,1505804400"; d="scan'208";a="3919939" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga001.jf.intel.com with ESMTP; 11 Nov 2017 16:08:04 -0800 Subject: [ndctl PATCH] ndctl, disable-region: check for mounted namespaces From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 11 Nov 2017 15:59:50 -0800 Message-ID: <151044479034.16188.1848810831483422153.stgit@dwillia2-desk3.amr.corp.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.22 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-Virus-Scanned: ClamAV using ClamSMTP Perform a ndctl_namespace_disable_safe loop to disable a region to make sure we are not ripping out a namespace from underneath an actively mounted filesystem. Signed-off-by: Dan Williams --- ndctl/action.h | 15 +++++++++++++++ ndctl/namespace.c | 15 ++++----------- ndctl/region.c | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 ndctl/action.h diff --git a/ndctl/action.h b/ndctl/action.h new file mode 100644 index 000000000000..43ea62adbcd2 --- /dev/null +++ b/ndctl/action.h @@ -0,0 +1,15 @@ +/* + * Copyright(c) 2015-2017 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0 + */ +#ifndef __NDCTL_ACTION_H__ +#define __NDCTL_ACTION_H__ +enum device_action { + ACTION_ENABLE, + ACTION_DISABLE, + ACTION_CREATE, + ACTION_DESTROY, + ACTION_CHECK, +}; +#endif /* __NDCTL_ACTION_H__ */ diff --git a/ndctl/namespace.c b/ndctl/namespace.c index b780924ecf4c..58f23ad0877a 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -17,6 +17,7 @@ #include #include #include +#include "action.h" #include #include #include @@ -146,15 +147,7 @@ static const struct option check_options[] = { OPT_END(), }; -enum namespace_action { - ACTION_ENABLE, - ACTION_DISABLE, - ACTION_CREATE, - ACTION_DESTROY, - ACTION_CHECK, -}; - -static int set_defaults(enum namespace_action mode) +static int set_defaults(enum device_action mode) { int rc = 0; @@ -264,7 +257,7 @@ static int set_defaults(enum namespace_action mode) * looking at actual namespace devices and available resources. */ static const char *parse_namespace_options(int argc, const char **argv, - enum namespace_action mode, const struct option *options, + enum device_action mode, const struct option *options, char *xable_usage) { const char * const u[] = { @@ -989,7 +982,7 @@ int namespace_check(struct ndctl_namespace *ndns, bool verbose, bool force, bool repair); static int do_xaction_namespace(const char *namespace, - enum namespace_action action, struct ndctl_ctx *ctx) + enum device_action action, struct ndctl_ctx *ctx) { struct ndctl_namespace *ndns, *_n; int rc = -ENXIO, success = 0; diff --git a/ndctl/region.c b/ndctl/region.c index cc3c133c3190..1402a7548be8 100644 --- a/ndctl/region.c +++ b/ndctl/region.c @@ -14,6 +14,7 @@ #include #include #include +#include "action.h" #include #include #include @@ -67,8 +68,32 @@ static const char *parse_region_options(int argc, const char **argv, return argv[0]; } -static int do_xable_region(const char *region_arg, - int (*xable_fn)(struct ndctl_region *), struct ndctl_ctx *ctx) +static int region_action(struct ndctl_region *region, enum device_action mode) +{ + struct ndctl_namespace *ndns; + int rc = 0; + + switch (mode) { + case ACTION_ENABLE: + rc = ndctl_region_enable(region); + break; + case ACTION_DISABLE: + ndctl_namespace_foreach(region, ndns) { + rc = ndctl_namespace_disable_safe(ndns); + if (rc) + return rc; + } + rc = ndctl_region_disable_invalidate(region); + break; + default: + break; + } + + return 0; +} + +static int do_xable_region(const char *region_arg, enum device_action mode, + struct ndctl_ctx *ctx) { int rc = -ENXIO, success = 0; struct ndctl_region *region; @@ -88,7 +113,7 @@ static int do_xable_region(const char *region_arg, continue; if (!util_region_filter(region, region_arg)) continue; - if (xable_fn(region) == 0) + if (region_action(region, mode) == 0) success++; } } @@ -103,8 +128,7 @@ int cmd_disable_region(int argc, const char **argv, void *ctx) { char *xable_usage = "ndctl disable-region []"; const char *region = parse_region_options(argc, argv, xable_usage); - int disabled = do_xable_region(region, ndctl_region_disable_invalidate, - ctx); + int disabled = do_xable_region(region, ACTION_DISABLE, ctx); if (disabled < 0) { fprintf(stderr, "error disabling regions: %s\n", @@ -124,7 +148,7 @@ int cmd_enable_region(int argc, const char **argv, void *ctx) { char *xable_usage = "ndctl enable-region []"; const char *region = parse_region_options(argc, argv, xable_usage); - int enabled = do_xable_region(region, ndctl_region_enable, ctx); + int enabled = do_xable_region(region, ACTION_ENABLE, ctx); if (enabled < 0) { fprintf(stderr, "error enabling regions: %s\n",