From patchwork Fri Sep 1 00:29:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9933211 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 B67C26016C for ; Fri, 1 Sep 2017 00:36:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA3EE27165 for ; Fri, 1 Sep 2017 00:36:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F46E27853; Fri, 1 Sep 2017 00:36:18 +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 5637A27165 for ; Fri, 1 Sep 2017 00:36:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 36FED21E70D33; Thu, 31 Aug 2017 17:33:34 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 64F8C20958BC3 for ; Thu, 31 Aug 2017 17:33:33 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP; 31 Aug 2017 17:36:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,456,1498546800"; d="scan'208";a="130541338" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by orsmga002.jf.intel.com with ESMTP; 31 Aug 2017 17:36:17 -0700 Subject: [PATCH] ndctl, create-namespace: support sector size settings for pmem From: Dan Williams To: linux-nvdimm@lists.01.org Date: Thu, 31 Aug 2017 17:29:53 -0700 Message-ID: <150422579319.8329.10494234762055238152.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 label support it is permissible for pmem namespaces to have a sector size. Per UEFI 2.7 the default should be 4K for inter-OS compatibility. Reported-by: Juston Li Signed-off-by: Dan Williams --- ndctl/namespace.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 55645d868b60..115119a84431 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -248,12 +248,6 @@ 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) || (param.mode @@ -360,7 +354,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 && p->sector_size < UINT_MAX) try(ndctl_namespace, set_sector_size, ndns, p->sector_size); uuid_generate(uuid); @@ -394,6 +388,13 @@ static int setup_namespace(struct ndctl_region *region, } else if (p->mode == NDCTL_NS_MODE_SAFE) { struct ndctl_btt *btt = ndctl_region_get_btt_seed(region); + /* + * Handle the case of btt on a pmem namespace where the + * pmem kernel support is pre-v1.2 namespace labels + * support (does not support sector size settings). + */ + if (p->sector_size == UINT_MAX) + p->sector_size = 4096; try(ndctl_btt, set_uuid, btt, uuid); try(ndctl_btt, set_sector_size, btt, p->sector_size); try(ndctl_btt, set_namespace, btt, ndns); @@ -632,11 +633,23 @@ static int validate_namespace_options(struct ndctl_region *region, if (btt) p->sector_size = ndctl_btt_get_sector_size(btt); - else if (ndctl_namespace_get_type(ndns) - == ND_DEVICE_NAMESPACE_BLK) + else p->sector_size = ndctl_namespace_get_sector_size(ndns); - else if (p->mode == NDCTL_NS_MODE_SAFE) - p->sector_size = 4096; + } else { + struct ndctl_namespace *seed; + + seed = ndctl_region_get_namespace_seed(region); + if (ndctl_namespace_get_type(seed) == ND_DEVICE_NAMESPACE_BLK) + debug("%s: set_defaults() should preclude this?\n", + ndctl_region_get_devname(region)); + /* + * Pick a default sector size for a pmem namespace based + * on what the kernel supports. + */ + if (ndctl_namespace_get_num_sector_sizes(seed) == 0) + p->sector_size = UINT_MAX; + else + p->sector_size = 512; } if (param.map) {