From patchwork Wed Jan 16 09:49:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10765595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 141F81580 for ; Wed, 16 Jan 2019 09:49:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01F6B2B2B4 for ; Wed, 16 Jan 2019 09:49:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAA152BA01; Wed, 16 Jan 2019 09:49:30 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,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 A9DAA2B2B4 for ; Wed, 16 Jan 2019 09:49:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A1EFA211B7F97; Wed, 16 Jan 2019 01:49:30 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::442; helo=mail-pf1-x442.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (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 3021B211B7F66 for ; Wed, 16 Jan 2019 01:49:29 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id z9so2835381pfi.2 for ; Wed, 16 Jan 2019 01:49:29 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=spNl99yY02+ZUw30aOxbYSSYVtznQlUYd9VRgLm+IAA=; b=mX4MuduX+ojI+GxomD00y7LZyrG/8kqR+ksOeF+Upf3/mECJnVnmSZFprNtSqG2MvL lTFnblNdkChzR32oeNHVIyZJJStTOD/BAoTB9Vb6j0JfXQcU/baVwqUdnroD70wtf32s syLE5ttLo4O2CVbJj0w4FzDiU7GY80qkY+IPNqTsiXC9nHQNyeyqtqkuzygxirxYQvfw 3TV97AuAfiqsxCzuQYsSGN8Hs7CFDZG0+YwLvuVMEeiY1x2macRBbaMrpVzMqtAniasr 9MqFju6Cfy1QBrJeHazP9P7aDrjOwXp95r6amSfMx9+9ER3sNRMotigyRoqNAmNGbmMP +L+w== 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:mime-version:content-transfer-encoding; bh=spNl99yY02+ZUw30aOxbYSSYVtznQlUYd9VRgLm+IAA=; b=on2hh/mDrD/H5DImxQL8gvBWr+NgBOJVOf//xsDyQtccQhjL5aJzXzNFZNfASVXqvy SpBFM4tRHmCPomVGnskCmHtoHLAco+JS8f19JQ0kcrYYlTji0djRrDxcPWOF8ntHUuoK 9XNI00vanHS5/3sP9pdCrhz7I0/FxC+k+E4jiMJkDrLsi/Z/YXJSzIY8YObp2Jhp3Wc+ jJnUmm2ZhdzapNZHW5kbIPxN8YjklNi44LBKKANM7Wlj6GeiHFxzQWo6iaUQA0JJ/UsK uXd6+hrjfnFow5wBBu2ioGXvTbHAkK9SDyMTFn3qAX8P/u8u49IIxgdxereOZqs4H3g1 0yFQ== X-Gm-Message-State: AJcUukdB5ZKb7qIcnlNM2tjYnmo2F4XZ3aNPBn7jYZMvPrNZ8L3ow5T6 yiIh4Au/w9rj3qj2kNa2eQDNGXo0 X-Google-Smtp-Source: ALg8bN6Q+D1ldxQsFILObq6rhOxgTyP6z7NnSj9bD9Tx+1w6Knx/GB3n6GYgKhP+CGp2brACeCVgIg== X-Received: by 2002:a63:4819:: with SMTP id v25mr8011788pga.308.1547632168668; Wed, 16 Jan 2019 01:49:28 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id f13sm8777331pfa.132.2019.01.16.01.49.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Jan 2019 01:49:28 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v3 4/6] ndctl/namespace: Validate alignment from the {pfn|dax} seed Date: Wed, 16 Jan 2019 20:49:07 +1100 Message-Id: <20190116094909.23112-4-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190116094909.23112-1-oohall@gmail.com> References: <20190116094909.23112-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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 This patch adds support to the ndctl tool for validating that the namespace alignment is valid. Signed-off-by: Oliver O'Halloran --- ndctl/namespace.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index b27cc6967a68..44fc91232ecb 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -537,8 +537,23 @@ static int validate_namespace_options(struct ndctl_region *region, } if (param.align) { - if (p->mode != NDCTL_NS_MODE_MEMORY && - p->mode != NDCTL_NS_MODE_DAX) { + int i, alignments; + + switch (p->mode) { + case NDCTL_NS_MODE_MEMORY: + if (!pfn) { + error("Kernel does not support setting an alignment in fsdax mode\n"); + return -EINVAL; + } + + alignments = ndctl_pfn_get_num_alignments(pfn); + break; + + case NDCTL_NS_MODE_DAX: + alignments = ndctl_dax_get_num_alignments(dax); + break; + + default: error("%s mode does not support setting an alignment\n", p->mode == NDCTL_NS_MODE_SAFE ? "sector" : "raw"); @@ -546,13 +561,19 @@ static int validate_namespace_options(struct ndctl_region *region, } p->align = parse_size64(param.align); + for (i = 0; i < alignments; i++) { + uint64_t a; - switch (p->align) { - case SZ_4K: - case SZ_2M: - case SZ_1G: - break; - default: + if (p->mode == NDCTL_NS_MODE_MEMORY) + a = ndctl_pfn_get_supported_alignment(pfn, i); + else + a = ndctl_dax_get_supported_alignment(dax, i); + + if (p->align == a) + break; + } + + if (i >= alignments) { error("unsupported align: %s\n", param.align); return -ENXIO; }