From patchwork Mon Apr 25 19:49:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8931911 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C79979F1C1 for ; Mon, 25 Apr 2016 19:51:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D11C8201EF for ; Mon, 25 Apr 2016 19:51:03 +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 D09ED2015A for ; Mon, 25 Apr 2016 19:51:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C6E8B1A1F22; Mon, 25 Apr 2016 12:51:02 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ml01.01.org (Postfix) with ESMTP id B95021A1F2D for ; Mon, 25 Apr 2016 12:51:01 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 25 Apr 2016 12:50:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,534,1455004800"; d="scan'208";a="91690181" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by fmsmga004.fm.intel.com with ESMTP; 25 Apr 2016 12:50:49 -0700 Subject: [ndctl PATCH 2/7] ndctl, create-namespace: check for ZONE_DEVICE=n kernels From: Dan Williams To: linux-nvdimm@lists.01.org Date: Mon, 25 Apr 2016 12:49:59 -0700 Message-ID: <146161379994.21779.2908319412060950116.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <146161378966.21779.1219526957524644729.stgit@dwillia2-desk3.amr.corp.intel.com> References: <146161378966.21779.1219526957524644729.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.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=-2.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 When a kernel does not support ZONE_DEVICE it is unable to support pfn-device configurations. Use the absence of a pfn-seed as the indicator of this configuration to fail the operation with an error rather than crashing. Reported-by: Linda Knippers Reported-by: Vishal Verma Signed-off-by: Dan Williams --- builtin-xaction-namespace.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/builtin-xaction-namespace.c b/builtin-xaction-namespace.c index 97bb36525d7c..40f62822facd 100644 --- a/builtin-xaction-namespace.c +++ b/builtin-xaction-namespace.c @@ -38,6 +38,7 @@ static bool verbose; static bool force; static struct parameters { bool do_scan; + bool mode_default; const char *bus; const char *map; const char *type; @@ -153,6 +154,7 @@ static int set_defaults(enum namespace_action mode) param.mode = "memory"; else param.mode = "safe"; + param.mode_default = true; } if (param.map) { @@ -265,10 +267,13 @@ static bool do_setup_pfn(struct ndctl_namespace *ndns, if (p->mode != NDCTL_NS_MODE_MEMORY) return false; - if (ndctl_namespace_get_mode(ndns) != NDCTL_NS_MODE_MEMORY) - return true; - - if (p->loc == NDCTL_PFN_LOC_PMEM) + /* + * Dynamically allocated namespaces always require a pfn + * instance, and a pfn device is required to place the memmap + * array in device memory. + */ + if (!ndns || ndctl_namespace_get_mode(ndns) != NDCTL_NS_MODE_MEMORY + || p->loc == NDCTL_PFN_LOC_PMEM) return true; return false; @@ -330,6 +335,7 @@ static int is_namespace_active(struct ndctl_namespace *ndns) /* * validate_namespace_options - init parameters for setup_namespace + * @region: parent of the namespace to create / reconfigure * @ndns: specified when we are reconfiguring, NULL otherwise * @p: parameters to fill * @@ -342,8 +348,8 @@ static int is_namespace_active(struct ndctl_namespace *ndns) * the target namespace we need to do basic sanity checks here for * pmem-only attributes specified for blk namespace and vice versa. */ -static int validate_namespace_options(struct ndctl_namespace *ndns, - struct parsed_parameters *p) +static int validate_namespace_options(struct ndctl_region *region, + struct ndctl_namespace *ndns, struct parsed_parameters *p) { int rc = 0; @@ -428,6 +434,19 @@ static int validate_namespace_options(struct ndctl_namespace *ndns, } else if (p->mode == NDCTL_NS_MODE_MEMORY) p->loc = NDCTL_PFN_LOC_PMEM; + /* check if we need, and whether the kernel supports, pfn devices */ + if (do_setup_pfn(ndns, p)) { + struct ndctl_pfn *pfn = ndctl_region_get_pfn_seed(region); + + if (!pfn && param.mode_default) { + debug("memory mode not available\n"); + p->mode = NDCTL_NS_MODE_RAW; + } else if (!pfn) { + error("operation failed, memory mode not available\n"); + return -EINVAL; + } + } + return 0; } @@ -438,7 +457,7 @@ static int namespace_create(struct ndctl_region *region) struct ndctl_namespace *ndns; struct parsed_parameters p; - if (validate_namespace_options(NULL, &p)) + if (validate_namespace_options(region, NULL, &p)) return -EINVAL; if (ndctl_region_get_ro(region)) { @@ -578,7 +597,7 @@ static int namespace_reconfig(struct ndctl_region *region, struct parsed_parameters p; int rc; - if (validate_namespace_options(ndns, &p)) + if (validate_namespace_options(region, ndns, &p)) return -EINVAL; rc = namespace_destroy(region, ndns);