From patchwork Thu Apr 27 09:14:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 9702619 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 19A796032C for ; Thu, 27 Apr 2017 09:15:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E62C42860F for ; Thu, 27 Apr 2017 09:15:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB40B28623; Thu, 27 Apr 2017 09:15:12 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no 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 9DE2D2860F for ; Thu, 27 Apr 2017 09:15:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id ABA9821951CA6; Thu, 27 Apr 2017 02:15:12 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1248821951C94 for ; Thu, 27 Apr 2017 02:15:12 -0700 (PDT) Received: by mail-pf0-x241.google.com with SMTP id g23so8060540pfj.1 for ; Thu, 27 Apr 2017 02:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C3T0vUiiaYsDiQQM28RyKu+CKf13NWQT63Odr9Xk6pE=; b=IW+5NqE+8/pgPTuKozPMqzBomE8RlOy6c+yMCBFTJ/MWvw2ulATpoW4w9XhzMlWMmy HRJyBEbADBt/yOUXnFhO94TgJ6wM7H3ndtXCO2qLsm8guz2MTBWSUd+H+op5/n5vxPqt GfwUm9QIh8H4V0E5PlrNKvyl36m32zF9DSIS0XnZjcWpbq9WCN0qECUgbY7MSLEXtbsQ Y7iBPkD4yujE5ZDRdtP50akejt+OfrFXMf0+NqBRpyBFko0MkxBBktgHtuyJSSZT0cgQ /4Wf3ccr3YiBr3SUtOYznSI8PIglxvOkbT3scWboKRZG35Z2OnNMbYsRhR47l6pPUZFi nx7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C3T0vUiiaYsDiQQM28RyKu+CKf13NWQT63Odr9Xk6pE=; b=qtEd5C9/ZxpZExXXXo1wgBiLevtx6LLg0Yi8EvOOqrCZeIdl1fwv6igWOmAJ0FNzmf pgyw6OiYkbIYQZxNQrOpIBhxqhcHACWFNqjyy/rxUjCYE9jUc1HlWI2ylv7QrnYYf56C X86KT2T51eaLmPF+9eNJDMOtv3g9lAEc2FP5eAk+nUfWDaAJqu85KjUGNxR0KbWY8nPE EJncV+CnQP5pK5gQWmFIWOGXPlsDRop2us4ICJU80svm2FccAh4kNFd5+H99cpEHZwWO Co4kPe9Otz2CwDEGvcij5jaCYvCqWl1v74PFaWlnqEulH71ClyexekyCuhLhCQX0M36m mPVQ== X-Gm-Message-State: AN3rC/7eWHLmeeWvRZ4Rom0e++5pjmbbgtjFSqtKxw/uFEmmY7OxFDrY QazAkdoEzx31EZ5/ X-Received: by 10.84.230.131 with SMTP id e3mr5975025plk.100.1493284511556; Thu, 27 Apr 2017 02:15:11 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id 3sm2954210pfe.20.2017.04.27.02.15.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Apr 2017 02:15:11 -0700 (PDT) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 3/4] ndctl, create-namespace: use seed device to check dax alignment Date: Thu, 27 Apr 2017 19:14:53 +1000 Message-Id: <20170427091454.17412-3-oohall@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170427091454.17412-1-oohall@gmail.com> References: <20170427091454.17412-1-oohall@gmail.com> 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: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The alignments supported by a dax or pfn device are depend on the fault granularities supported by the kernel. Currently we just assume this means 4K, 2M and 1G alignments are allowed, but now what we can query the supported values from the seed namespace we should use that instead. Signed-off-by: Oliver O'Halloran --- ndctl/builtin-xaction-namespace.c | 79 +++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c index 46d651e86153..4fdf50ef785a 100644 --- a/ndctl/builtin-xaction-namespace.c +++ b/ndctl/builtin-xaction-namespace.c @@ -397,7 +397,7 @@ static int validate_namespace_options(struct ndctl_region *region, struct ndctl_namespace *ndns, struct parsed_parameters *p) { const char *region_name = ndctl_region_get_devname(region); - unsigned long long size_align, units = 1; + unsigned long long size_align = 0, units = 1; unsigned int ways; int rc = 0; @@ -460,57 +460,62 @@ static int validate_namespace_options(struct ndctl_region *region, p->align = parse_size64(param.align); - if (p->mode == NDCTL_NS_MODE_MEMORY && p->align != SZ_2M - && (!pfn || !ndctl_pfn_has_align(pfn))) { + if (p->mode == NDCTL_NS_MODE_MEMORY) { + if (!pfn) { + debug("%s does not support memory mode\n", + region_name); + return -EAGAIN; + } + /* * Initial pfn device support in the kernel * supported a 2M default alignment when * ndctl_pfn_has_align() returns false. */ - debug("%s not support 'align' for memory mode\n", + if (p->align != SZ_2M && !ndctl_pfn_has_align(pfn)) { + debug("%s not support 'align' for memory mode\n", region_name); - return -EAGAIN; - } else if (p->mode == NDCTL_NS_MODE_DAX - && (!dax || !ndctl_dax_has_align(dax))) { + return -EAGAIN; + } + + if (param.align_default) + p->align = ndctl_pfn_def_align(pfn); + + if (!ndctl_pfn_supports_align(pfn, p->align)) { + error("unsupported alignment for memory mode: %s\n", + param.align); + return -EINVAL; + } + + size_align = p->align; + } else if (p->mode == NDCTL_NS_MODE_DAX) { /* * Unlike the pfn case, we require the kernel to * have 'align' support for device-dax. */ - debug("%s not support 'align' for dax mode\n", - region_name); - return -EAGAIN; - } else if (!param.align_default - && (p->mode == NDCTL_NS_MODE_SAFE - || p->mode == NDCTL_NS_MODE_RAW)) { - /* - * Specifying an alignment has no effect for - * raw, or btt mode namespaces. - */ + if (!dax || !ndctl_dax_has_align(dax)) { + debug("%s not support 'align' for dax mode\n", + region_name); + return -EAGAIN; + } + + if (param.align_default) + p->align = ndctl_dax_def_align(dax); + + if (!ndctl_dax_supports_align(dax, p->align)) { + error("unsupported alignment for dax mode: %s\n", + param.align); + return -EINVAL; + } + + size_align = p->align; + } else if (!param.align_default) { + /* in other cases the user should not supply an alignment */ error("%s mode does not support setting an alignment\n", p->mode == NDCTL_NS_MODE_SAFE ? "sector" : "raw"); return -ENXIO; } - - switch (p->align) { - case SZ_4K: - case SZ_2M: - case SZ_1G: - break; - default: - error("unsupported align: %s\n", param.align); - return -ENXIO; - } - - /* - * 'raw' and 'sector' mode namespaces don't support an - * alignment attribute. - */ - if (p->mode == NDCTL_NS_MODE_MEMORY - || p->mode == NDCTL_NS_MODE_DAX) - size_align = p->align; - else - size_align = SZ_4K; } /* (re-)validate that the size satisfies the alignment */