From patchwork Thu Aug 4 15:32:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9263847 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 1413960754 for ; Thu, 4 Aug 2016 15:34:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05F092766D for ; Thu, 4 Aug 2016 15:34:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEC0A27F46; Thu, 4 Aug 2016 15:34:46 +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 A21D72766D for ; Thu, 4 Aug 2016 15:34:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 873F71A1DFE; Thu, 4 Aug 2016 08:34:46 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ml01.01.org (Postfix) with ESMTP id 144E71A1DFE for ; Thu, 4 Aug 2016 08:34:46 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 04 Aug 2016 08:34:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,470,1464678000"; d="scan'208";a="859751248" 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 08:34:45 -0700 Subject: [ndctl PATCH] ndctl, create-namespace: trap and report invalid sector-size values From: Dan Williams To: linux-nvdimm@lists.01.org Date: Thu, 04 Aug 2016 08:32:22 -0700 Message-ID: <147032474225.32368.15775067933518377793.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 --- ndctl/builtin-xaction-namespace.c | 40 +++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c index 8304203750d8..e136bfdefa39 100644 --- a/ndctl/builtin-xaction-namespace.c +++ b/ndctl/builtin-xaction-namespace.c @@ -415,14 +415,42 @@ 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 { + if (!ndns) + ndns = ndctl_region_get_namespace_seed(region); + num = ndctl_namespace_get_num_sector_sizes(ndns); + for (i = 0; i < num; i++) + if (ndctl_namespace_get_supported_sector_size(ndns, 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);