From patchwork Thu Aug 4 18:42:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9264085 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 B49756048B for ; Thu, 4 Aug 2016 18:44:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92B402841C for ; Thu, 4 Aug 2016 18:44:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F1BF28424; Thu, 4 Aug 2016 18:44:35 +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 EFB162841C for ; Thu, 4 Aug 2016 18:44:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8014B1A1DFE; Thu, 4 Aug 2016 11:44:34 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ml01.01.org (Postfix) with ESMTP id BC1BC1A1DFE for ; Thu, 4 Aug 2016 11:44:33 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 04 Aug 2016 11:44:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,471,1464678000"; d="scan'208";a="859856135" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by orsmga003.jf.intel.com with ESMTP; 04 Aug 2016 11:44:33 -0700 Subject: [ndctl PATCH v2] ndctl, create-namespace: trap and report invalid sector-size values From: Dan Williams To: linux-nvdimm@lists.01.org Date: Thu, 04 Aug 2016 11:42:09 -0700 Message-ID: <147033593728.33374.15172970808845415226.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.21 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 While the kernel will prevent invalid configurations, the user experience of a kernel error message and disabling of the namespace is too harsh. Trap and report these attempts to make create-namespace more user friendly. # ndctl create-namespace -e namespace0.0 -m sector -l 513 -f -v validate_namespace_options:437: region0: does not support btt sector_size 513 failed to reconfigure namespace Reported-by: Yi Zhang Signed-off-by: Dan Williams --- Changes in v2 to address unit test breakage: 1/ stop setting a default sector size for cases where create-namespace is operating in pmem mode. 2/ don't set ndns in validate_namespace(), use a separate 'seed' variable, otherwise we mistakenly change a 'create' to a 'reconfigure' operation. ndctl/builtin-xaction-namespace.c | 51 +++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c index 8304203750d8..76d06bbb53ba 100644 --- a/ndctl/builtin-xaction-namespace.c +++ b/ndctl/builtin-xaction-namespace.c @@ -210,8 +210,13 @@ static int set_defaults(enum namespace_action mode) error("'pmem' namespaces do not support setting 'sector size'\n"); rc = -EINVAL; } - } else if (!param.reconfig) - param.sector_size = "4096"; + } else if (!param.reconfig + && (param.type && strcmp(param.type, "blk") == 0 + || (param.mode + && strcmp(param.mode, "safe") == 0))) { + /* default sector size for blk-type or safe-mode */ + param.sector_size = "4096"; + } return rc; } @@ -415,14 +420,44 @@ static int validate_namespace_options(struct ndctl_region *region, p->mode = ndctl_namespace_get_mode(ndns); if (param.sector_size) { - p->sector_size = parse_size64(param.sector_size); + struct ndctl_btt *btt; + int num, i; - if (ndns && p->mode != NDCTL_NS_MODE_SAFE - && ndctl_namespace_get_type(ndns) - == ND_DEVICE_NAMESPACE_PMEM) { - debug("%s: does not support sector_size modification\n", - ndctl_namespace_get_devname(ndns)); + p->sector_size = parse_size64(param.sector_size); + btt = ndctl_region_get_btt_seed(region); + if (p->mode == NDCTL_NS_MODE_SAFE) { + if (!btt) { + debug("%s: does not support 'sector' mode\n", + ndctl_region_get_devname(region)); + return -EINVAL; + } + num = ndctl_btt_get_num_sector_sizes(btt); + for (i = 0; i < num; i++) + if (ndctl_btt_get_supported_sector_size(btt, i) + == p->sector_size) + break; + if (i >= num) { + debug("%s: does not support btt sector_size %lu\n", + ndctl_region_get_devname(region), + p->sector_size); + return -EINVAL; + } + } else { + struct ndctl_namespace *seed = ndns; + + if (!seed) + seed = ndctl_region_get_namespace_seed(region); + num = ndctl_namespace_get_num_sector_sizes(seed); + for (i = 0; i < num; i++) + if (ndctl_namespace_get_supported_sector_size(seed, i) + == p->sector_size) + break; + if (i >= num) { + debug("%s: does not support namespace sector_size %lu\n", + ndctl_region_get_devname(region), + p->sector_size); return -EINVAL; + } } } else if (ndns) { struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);