From patchwork Wed Jan 30 10:59:24 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: 10788269 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 F40D591E for ; Wed, 30 Jan 2019 10:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0E282E3BB for ; Wed, 30 Jan 2019 10:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4C942E3E2; Wed, 30 Jan 2019 10:59:47 +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 8F9022E3BB for ; Wed, 30 Jan 2019 10:59:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 88F26211BFCC5; Wed, 30 Jan 2019 02:59:47 -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::642; helo=mail-pl1-x642.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (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 7B614211BFCCE for ; Wed, 30 Jan 2019 02:59:46 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id b5so10883253plr.4 for ; Wed, 30 Jan 2019 02:59:46 -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=PGMLKYyWN6m+7zcPu8D+Qb9UkgrHqlfU5cdS5j2X1o0=; b=OWaBGkvuKLqE8TKWtlp6/ilIwAaUPch89sFjZydtQXwN/Ia+TIQe9nW4dWx4Hip8CW xVMQKL+E9p4chn9CE+pbPmLJIVYRpe2E3EBQok9LytQTj9hPYqNlrs4dMlQiyJVkaKm/ LVpAHlPZ0ce7qA5L8mq9aBvK9LpWVAAEeUx8l0RlhNQVgNkBz4bhgPNGqvQ1Sp6uHIgq T+40NL3s7hwrPmKI9U1h82rYsNakkuw6QD2aEo13IFE6huimjmRaFgLxlDktqCvcCRLU CbjvUOkJ7L2VHNHILxMeFTSLg3EjsjDZp+hR3oo7ue+7Rq/UqcBntpHewSs+cuHrB93/ c77w== 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=PGMLKYyWN6m+7zcPu8D+Qb9UkgrHqlfU5cdS5j2X1o0=; b=bB5hhrobGCSoCnLnpsvZBn1suSnbufHm6DgHrVAyLksAlRWFqDnIpunTM6qVW/0dGS ev137ShaBq3R3pwDsbkHEkT5uIllffqn2vooUQtc4j/NpPYvB+YPKlcsDaR5+JAGF8hU NajVECd+yccNPoCgaX2fcUWeOAa/vTDzJFdl0ScLgvgDdV5vgkumwacAnOVia0fIA+W2 YRjDFiA3i0wbDxjVeBNc3A1dABXiHVPdhceWJxDKPDTdDgPrpE4OEcATLUXmfcZptHjw yNZt/TuerdmgDIE3/h9CRGJ4CStVZSAThpaWFzGm+ZquKhuyQE6gwuP9xI+McPsBZaOY s5tw== X-Gm-Message-State: AJcUukfLmEcwpU/UDF0Nmw8qYdIk1sC6zcLGdrt6sCDR6Gbi+CcgTJVG I1eAufS72kjeg7hHyf/y0Bsy9GTd X-Google-Smtp-Source: ALg8bN4+AheVv5kRGbM8wvr7qAFhhsDeNKeSj9JDPAVrnH6MLNgGo+jLxJ0WCAhRWejcfMQTOTmk6A== X-Received: by 2002:a17:902:280b:: with SMTP id e11mr29919204plb.269.1548845985938; Wed, 30 Jan 2019 02:59:45 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:45 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 4/7] ndctl/namespace: Validate alignment from the {pfn|dax} seed Date: Wed, 30 Jan 2019 21:59:24 +1100 Message-Id: <20190130105927.31901-4-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130105927.31901-1-oohall@gmail.com> References: <20190130105927.31901-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 --- v3: Fail validation if an alignment is specified, but pfn mode is not supported. --- ndctl/namespace.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 5d672810a712..25e0a87676e4 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -541,8 +541,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"); @@ -550,13 +565,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; }