From patchwork Thu Dec 8 23:53:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 9467285 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 97C206071E for ; Thu, 8 Dec 2016 23:53:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BB8B285ED for ; Thu, 8 Dec 2016 23:53:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 807752861C; Thu, 8 Dec 2016 23:53:20 +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 0FAEB285ED for ; Thu, 8 Dec 2016 23:53:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C637881F7A; Thu, 8 Dec 2016 15:53:19 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 45E6D81F79 for ; Thu, 8 Dec 2016 15:53:19 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 08 Dec 2016 15:53:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.33,321,1477983600"; d="scan'208"; a="1079463569" Received: from djiang5-desk3.ch.intel.com ([143.182.137.38]) by fmsmga001.fm.intel.com with ESMTP; 08 Dec 2016 15:53:16 -0800 Subject: [PATCH 2 1/2] ndctl: introduce 4k allocation support for creating namespace From: Dave Jiang To: dan.j.williams@intel.com Date: Thu, 08 Dec 2016 16:53:16 -0700 Message-ID: <148124119683.166989.2517425646704949235.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty 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: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Existing implementation defaults all pages allocated as 2M superpages. For nfit_test dax device we need 4k pages allocated to work properly. Adding an --align,-a option to provide the alignment. Will accept 4k and 2M at the moment as proper parameter. No -a option still defaults to 2M. Signed-off-by: Dave Jiang --- ndctl/builtin-xaction-namespace.c | 34 +++++++++++++++++++++++++++++++--- util/size.h | 1 + 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c index 8257eb9..038e59f 100644 --- a/ndctl/builtin-xaction-namespace.c +++ b/ndctl/builtin-xaction-namespace.c @@ -49,6 +49,7 @@ static struct parameters { const char *region; const char *reconfig; const char *sector_size; + const char *align; } param; void builtin_xaction_namespace_reset(void) @@ -71,6 +72,7 @@ struct parsed_parameters { enum ndctl_namespace_mode mode; unsigned long long size; unsigned long sector_size; + unsigned long align; }; #define debug(fmt, ...) \ @@ -104,6 +106,8 @@ OPT_STRING('l', "sector-size", ¶m.sector_size, "lba-size", \ "specify the logical sector size in bytes"), \ OPT_STRING('t', "type", ¶m.type, "type", \ "specify the type of namespace to create 'pmem' or 'blk'"), \ +OPT_STRING('a', "align", ¶m.align, "align", \ + "specify the namespace alignment in bytes (default: 0x200000 (2M))"), \ OPT_BOOLEAN('f', "force", &force, "reconfigure namespace even if currently active") static const struct option base_options[] = { @@ -319,14 +323,13 @@ static int setup_namespace(struct ndctl_region *region, try(ndctl_pfn, set_uuid, pfn, uuid); try(ndctl_pfn, set_location, pfn, p->loc); - /* * TODO: when we allow setting a non-default alignment * we'll need to check for "has_align" earlier and fail * non-default attempts on older kernels. */ if (ndctl_pfn_has_align(pfn)) - try(ndctl_pfn, set_align, pfn, SZ_2M); + try(ndctl_pfn, set_align, pfn, p->align); try(ndctl_pfn, set_namespace, pfn, ndns); rc = ndctl_pfn_enable(pfn); } else if (p->mode == NDCTL_NS_MODE_DAX) { @@ -335,7 +338,7 @@ static int setup_namespace(struct ndctl_region *region, try(ndctl_dax, set_uuid, dax, uuid); try(ndctl_dax, set_location, dax, p->loc); /* device-dax assumes 'align' attribute present */ - try(ndctl_dax, set_align, dax, SZ_2M); + try(ndctl_dax, set_align, dax, p->align); try(ndctl_dax, set_namespace, dax, ndns); rc = ndctl_dax_enable(dax); } else if (p->mode == NDCTL_NS_MODE_SAFE) { @@ -439,6 +442,31 @@ static int validate_namespace_options(struct ndctl_region *region, } else if (ndns) p->mode = ndctl_namespace_get_mode(ndns); + if ((p->mode == NDCTL_NS_MODE_MEMORY) || + (p->mode == NDCTL_NS_MODE_DAX)) { + struct ndctl_pfn *pfn = ndctl_region_get_pfn_seed(region); + + if (!ndctl_pfn_has_align(pfn)) + return -EINVAL; + + if (param.align) { + p->align = parse_size64(param.align); + switch (p->align) { + case SZ_4K: + case SZ_2M: + break; + case SZ_1G: /* unsupported yet... */ + default: + debug("%s: invalid align\n", __func__); + return -EINVAL; + } + } else + p->align = SZ_2M; + } else if (param.align) { + debug("%s: does not support align\n", __func__); + return -EINVAL; + } + if (param.sector_size) { struct ndctl_btt *btt; int num, i; diff --git a/util/size.h b/util/size.h index 50917a5..634c926 100644 --- a/util/size.h +++ b/util/size.h @@ -2,6 +2,7 @@ #define _NDCTL_SIZE_H_ #define SZ_1K 0x00000400 +#define SZ_4K 0x00001000 #define SZ_1M 0x00100000 #define SZ_2M 0x00200000 #define SZ_4M 0x00400000