From patchwork Mon Nov 19 08:00:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10688267 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 4FF2C14DB for ; Mon, 19 Nov 2018 08:10:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41A0629A55 for ; Mon, 19 Nov 2018 08:10:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3670A29A60; Mon, 19 Nov 2018 08:10:51 +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 EC7A029A55 for ; Mon, 19 Nov 2018 08:10:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9ECC721E11D26; Mon, 19 Nov 2018 00:10:35 -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::444; helo=mail-pf1-x444.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 9D27A21A09130 for ; Mon, 19 Nov 2018 00:01:13 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id b7so1225088pfi.8 for ; Mon, 19 Nov 2018 00:01:13 -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; bh=fdBMcWd2FTNmb+b9AUDYOifFq4U074MMAzVYo9FTYyg=; b=iwAszSnwx64suPPf/Cv5WsnV0wc6G2JufuaXbO0KbBq2OqurQAoBRxi2ZbkZYTIw1g ANpVryzXrIOLeoD2Y0HIfEI2WmQZd+wk9QmT7ng13yiI1EVPiO/+y93c0kM4YGilePBH qXVQXv9d6l1ugc6seWPdKVpId9lyDRFQ18wel5wQAGBFGCWjxidnBNO6Yy/390Na8oAX Jk02th9bTfoCO7zTaxVyiFb74R+HNsdcESqdbFHmCzuW0NDGyN92dNgeXrU57vXKfBrN HclgNkARqiOsWiCTUc+opxo36Pn7czkLPU9VCHBlDd+UujpNeTMSexZ+SISAUJ3QVaO/ n+RA== 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=fdBMcWd2FTNmb+b9AUDYOifFq4U074MMAzVYo9FTYyg=; b=W2cWGsEwoG8PLdcwYraVUKlPW2xHkm+x8TBqglKEAfK6lg3orpXY69w6bVmIklakpk o7ort8aWSpV1P3g9oT13b5K/7qi9C7YwhHscodQlt0UYbWf3CkMm4OJuE6d/2rc94Llr ditUepK92fzcVR9DSI5m+HAphqUFUibnBRm2OVWLlKgB+DZsqvQ7NWT7MZmBmhod4mMG oBEOAUYXsQruOqmOyAbwjxy1vIzVgefuEB9ffW9Nv/16VFmCNglvs99WclIMECw0thhn h5rl2ac4gBHEixITu71RHOf3TuSHStPtCnFBgBVd/qCuE0N7hKbMnwLemHEDq/yAuGVE YXxg== X-Gm-Message-State: AGRZ1gIJga4i2ge/PL8DOUjcLZvkQx+ajozwyrfIZ9tdNDPLAws4A3ll HSk843VtoD+F5vrc8yVBkRJ7LSsp X-Google-Smtp-Source: AJdET5coMV066p/Z9cL1wKT0R7B2g1v8GPu/vd7IE9mQymaWLweL4nDpDcOb3zGuSaBlca0PNShEnw== X-Received: by 2002:a63:7154:: with SMTP id b20mr19139604pgn.342.1542614473044; Mon, 19 Nov 2018 00:01:13 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id g123-v6sm56059007pfc.155.2018.11.19.00.01.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Nov 2018 00:01:12 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 4/4] ndctl/namespace: Validate alignment from the {pfn|dax} seed Date: Mon, 19 Nov 2018 19:00:56 +1100 Message-Id: <20181119080056.13386-4-oohall@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181119080056.13386-1-oohall@gmail.com> References: <20181119080056.13386-1-oohall@gmail.com> 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: , MIME-Version: 1.0 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 | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 1e04f32c0e95..6f8dca288527 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -537,8 +537,18 @@ 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: + 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 +556,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; }