From patchwork Wed Jul 5 20:49:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9827035 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 5631C60361 for ; Wed, 5 Jul 2017 20:55:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47738223A6 for ; Wed, 5 Jul 2017 20:55:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C49728583; Wed, 5 Jul 2017 20:55: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 E570C223A6 for ; Wed, 5 Jul 2017 20:55:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 166AC21C9E7B6; Wed, 5 Jul 2017 13:53:55 -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]) (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 321B820958966 for ; Wed, 5 Jul 2017 13:53:54 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jul 2017 13:55:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,313,1496127600"; d="scan'208"; a="1148091672" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by orsmga001.jf.intel.com with ESMTP; 05 Jul 2017 13:55:33 -0700 Subject: [ndctl PATCH 6/6] ndctl, create-namespace: set pmem namespace sector size From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 05 Jul 2017 13:49:07 -0700 Message-ID: <149928774707.25150.9359431758968306936.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <149928771519.25150.13314997328838983545.stgit@dwillia2-desk3.amr.corp.intel.com> References: <149928771519.25150.13314997328838983545.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 Starting with v1.2 namespace labels, the "lbasize" field is expected to be non-zero for all namespace types. Signed-off-by: Dan Williams --- ndctl/namespace.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index c28d00193a62..778a65d02c2a 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -244,18 +244,14 @@ static int set_defaults(enum namespace_action mode) error("invalid sector size: %s\n", param.sector_size); rc = -EINVAL; } - - if (param.type && param.mode && strcmp(param.type, "pmem") == 0 - && strcmp(param.mode, "safe") != 0) { - error("'pmem' namespaces do not support setting 'sector size'\n"); - rc = -EINVAL; - } - } else if (!param.reconfig - && ((param.type && strcmp(param.type, "blk") == 0) + } else if (!param.reconfig) { + if ((param.type && strcmp(param.type, "blk") == 0) || (param.mode - && strcmp(param.mode, "safe") == 0))) { + && strcmp(param.mode, "safe") == 0)) /* default sector size for blk-type or safe-mode */ param.sector_size = "4096"; + else + param.sector_size = "512"; } return rc; @@ -356,7 +352,7 @@ static int setup_namespace(struct ndctl_region *region, try(ndctl_namespace, set_size, ndns, p->size); } - if (ndctl_namespace_get_type(ndns) == ND_DEVICE_NAMESPACE_BLK) + if (p->sector_size) try(ndctl_namespace, set_sector_size, ndns, p->sector_size); uuid_generate(uuid); @@ -608,22 +604,36 @@ static int validate_namespace_options(struct ndctl_region *region, if (ndctl_namespace_get_supported_sector_size(seed, i) == p->sector_size) break; - if (i >= num) { + if (i >= num) debug("%s: does not support namespace sector_size %lu\n", region_name, p->sector_size); + + /* + * Pre-4.13 kernels did not support sector sizes + * for pmem namespaces. Revert to the zero + * default in that case. + */ + if (i >= num && ndctl_region_get_type(region) + != ND_DEVICE_REGION_BLK + && (p->sector_size == 512 + || p->sector_size == 4096)) { + debug("%s: revert to default sector size\n", + region_name); + p->sector_size = 0; + } else if (i >= num) return -EINVAL; - } } } else if (ndns) { struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns); if (btt) p->sector_size = ndctl_btt_get_sector_size(btt); - else if (ndctl_namespace_get_type(ndns) - == ND_DEVICE_NAMESPACE_BLK) - p->sector_size = ndctl_namespace_get_sector_size(ndns); else if (p->mode == NDCTL_NS_MODE_SAFE) p->sector_size = 4096; + else + p->sector_size = ndctl_namespace_get_sector_size(ndns); + if (p->sector_size == UINT_MAX) + p->sector_size = 0; } if (param.map) {