From patchwork Mon Nov 19 08:00:53 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: 10688261 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 D0F781709 for ; Mon, 19 Nov 2018 08:10:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C126F29A57 for ; Mon, 19 Nov 2018 08:10:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B56C029A62; Mon, 19 Nov 2018 08:10:40 +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 5784229A57 for ; Mon, 19 Nov 2018 08:10:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 43BD621D0DE66; 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::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 6B62821A09130 for ; Mon, 19 Nov 2018 00:01:08 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id y6-v6so6626417plt.3 for ; Mon, 19 Nov 2018 00:01:08 -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; bh=XMdr9gTP8i99KzzuSksUGpQpP388uPM0+FlDD5j68q0=; b=r/NAoKCcI4rVcy63bdPapTYy9zYr+lO7MVFs+JI68QmczEmzI2aWvCRM+OjEHILFmY IXG4I1Jb2KaU35nxHin9o7pKzaK/c9E+Dge3EkH3oWR3vJc6sKa56iGGmlQWDEoUox6A bg4o9hENSW2Vg4Bct9PslxoAubze4Ybygrr7cf0AUL7mXP57V6IiqRIKZ+PeHue1YdMT DIHcDV5vxZK+4I/NnuUx83mQDNi07m1Z6OhTbCO5WYaoCvXNr422aNfXHb53Pbo8G/9r fgXAknhcRLZkSKN8P0PuEMlCADjxrviXX9B0eSvNa9AvPnzfGmTNAGdOMcBHwb/LxTvN gq1w== 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; bh=XMdr9gTP8i99KzzuSksUGpQpP388uPM0+FlDD5j68q0=; b=XGzOgLhlQFjGEfvfBaPA0tBz8r9j6Lq3JpWwVSkX0a9vriwKp5nfnwst6VhIAE04h2 kscJTwn1yY7Mdx0mG9dIQfAYsLa4f3jNW8sEFHlJihFk0D8gLGbSJWITWGjzls44P1D2 sFfHarkCzuvTmLLJQu8WKQEf4OEWKXTFaXTJg3fTS7MlL37CLQYaRKux/RXej9muMTfT +JZO9kYHV2mufhT7oJJomKXLN1pcW2WedCaP2qe3yUgNaq/LWgn+DfBzxL3/HwKP0gWH 7SEAGt8FJqiiGgrdQWaiMJdKG+tqvu4HuVCEbW4mPysUC+oPJualBd8EPNh3jZo3nR7C OhRw== X-Gm-Message-State: AA+aEWbsxVxEckTE1gZATrrvENqtgydLW2cUn85LA8/0BnLKrv1YYEH1 t/xv0bY2VqIjWLzornMIfowA44C7 X-Google-Smtp-Source: AFSGD/Xo5JTQmv4/lgGkIZylmBeRdb3R7zFaHEPQVzmQGbocC8cEgs0eJx3hHcm0GTbVsFD+k6jkDw== X-Received: by 2002:a17:902:2c83:: with SMTP id n3mr1280236plb.104.1542614467587; Mon, 19 Nov 2018 00:01:07 -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.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Nov 2018 00:01:07 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 1/4] libndctl: Use the supported_alignment attribute Date: Mon, 19 Nov 2018 19:00:53 +1100 Message-Id: <20181119080056.13386-1-oohall@gmail.com> X-Mailer: git-send-email 2.17.2 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 Newer kernels provide the "supported_alignments" sysfs attribute that indicates what alignments can be used with a PFN or DAX namespace. This patch adds the plumbing inside of libndctl to allow users to query this information through using: ndctl_{dax|pfn}_get_supported_alignment(), and ndctl_{dax|pfn}_get_num_alignments() Signed-off-by: Oliver O'Halloran Reviewed-by: Dan Williams --- ndctl/lib/libndctl.c | 40 ++++++++++++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 7 +++++++ ndctl/libndctl.h | 6 ++++++ 3 files changed, 53 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 0c3a35e5bcc9..4d0e58a22953 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -237,6 +238,7 @@ struct ndctl_pfn { int buf_len; uuid_t uuid; int id, generation; + struct ndctl_lbasize alignments; }; struct ndctl_dax { @@ -4781,6 +4783,18 @@ static void *__add_pfn(struct ndctl_pfn *pfn, const char *pfn_base) else pfn->size = strtoull(buf, NULL, 0); + /* + * If the kernel doesn't provide the supported_alignments sysfs + * attribute then it's safe to assume that we are running on x86 + * which will always support 2MB and 4KB alignments. + */ + sprintf(path, "%s/supported_alignments", pfn_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + sprintf(buf, "%d %d", SZ_4K, SZ_2M); + + if (parse_lbasize_supported(ctx, pfn_base, buf, &pfn->alignments) < 0) + goto err_read; + free(path); return pfn; @@ -5015,6 +5029,22 @@ NDCTL_EXPORT int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align) return 0; } +NDCTL_EXPORT unsigned int ndctl_pfn_get_num_alignments(struct ndctl_pfn *pfn) +{ + return pfn->alignments.num; +} + +NDCTL_EXPORT int ndctl_pfn_get_supported_alignment(struct ndctl_pfn *pfn, int i) +{ + if (pfn->alignments.num == 0) + return 0; + + if (i < 0 || i > pfn->alignments.num) + return UINT_MAX; + else + return pfn->alignments.supported[i]; +} + NDCTL_EXPORT int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn, struct ndctl_namespace *ndns) { @@ -5237,6 +5267,16 @@ NDCTL_EXPORT unsigned long ndctl_dax_get_align(struct ndctl_dax *dax) return ndctl_pfn_get_align(&dax->pfn); } +NDCTL_EXPORT unsigned int ndctl_dax_get_num_alignments(struct ndctl_dax *dax) +{ + return ndctl_pfn_get_num_alignments(&dax->pfn); +} + +NDCTL_EXPORT int ndctl_dax_get_supported_alignment(struct ndctl_dax *dax, int i) +{ + return ndctl_pfn_get_supported_alignment(&dax->pfn, i); +} + NDCTL_EXPORT int ndctl_dax_has_align(struct ndctl_dax *dax) { return ndctl_pfn_has_align(&dax->pfn); diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 6c4c8b4dfb8e..0103c1b71a1d 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -385,3 +385,10 @@ global: ndctl_namespace_get_next_badblock; ndctl_dimm_get_dirty_shutdown; } LIBNDCTL_17; + +LIBNDCTL_19 { + ndctl_pfn_get_supported_alignment; + ndctl_pfn_get_num_alignments; + ndctl_dax_get_supported_alignment; + ndctl_dax_get_num_alignments; +} LIBNDCTL_18; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 62cef9e82da3..4ff25c0a4783 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -681,6 +681,12 @@ enum ND_FW_STATUS ndctl_cmd_fw_xlat_firmware_status(struct ndctl_cmd *cmd); struct ndctl_cmd *ndctl_dimm_cmd_new_ack_shutdown_count(struct ndctl_dimm *dimm); int ndctl_dimm_fw_update_supported(struct ndctl_dimm *dimm); +unsigned int ndctl_pfn_get_num_alignments(struct ndctl_pfn *pfn); +int ndctl_pfn_get_supported_alignment(struct ndctl_pfn *pfn, int i); + +unsigned int ndctl_dax_get_num_alignments(struct ndctl_dax *dax); +int ndctl_dax_get_supported_alignment(struct ndctl_dax *dax, int i); + #ifdef __cplusplus } /* extern "C" */ #endif From patchwork Mon Nov 19 08:00:54 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: 10688263 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 D4F0A14BD for ; Mon, 19 Nov 2018 08:10:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C583529A57 for ; Mon, 19 Nov 2018 08:10:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9D2529A62; Mon, 19 Nov 2018 08:10:42 +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 68B3F29A57 for ; Mon, 19 Nov 2018 08:10:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5E83A21DF809D; 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::644; helo=mail-pl1-x644.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 E721521A09130 for ; Mon, 19 Nov 2018 00:01:09 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id b22-v6so8749166pls.7 for ; Mon, 19 Nov 2018 00:01:09 -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=lRSuHadXYH/JHI9nBWMdlUc1F60ZTgL1sZQkOjahN38=; b=fvvdGBPjmZPH+r6dhgBQROwv5wkNcCQn0oBq002V6VejDZdYiBmdlLwjIC1H6LzX20 PTYbJjIiX3OVI1tNy1RpbOCk9HLtyJ4mtVG416CQapvyW12EsnX5q3FUsbyPt2VmRP4H EL2FfsKBpwFJz6MxCHXPnjVtGd0U1EgklmSS+MtYVaxQcI/aPMCke/YnGn2xYFtHwQ/N GBqW/5XXeurrwSeQJJY4gVTiWTWNyEgoVE9TXzhbqE/mMp77zNPPMQLvEX1PyonNwfl3 /4wzpBlZbeMWcxNVqD3wDtfoxLCAFDZeNGswF0dulO0Rg9lXMTnCCh/KebqWu7vCqy9l T3Bw== 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=lRSuHadXYH/JHI9nBWMdlUc1F60ZTgL1sZQkOjahN38=; b=WSrgd0nleY//ozoXcoNA4WydZclPkIfy5i6k6xXJBKVioPSAgcgoSddT2KnO/t2VXb zCANfVEZaZJ7pK8jisd9Yzw16Zazp0O863KEOpjXrHK/WVtIavsX5F7csQP6q2c6MTXi prlLMQqqF2krsrPFSb9fQ2d2WCkXjisB4gwZzrcswHPW71jqVnHFW7Sj68XGA6EEUvo1 UA3Faikw0EXBAQNvgnqDyGlp9QO7NejgZvG3ZydCt5B5Nyh8hBefeAFj0tEkGdnOo9GF fLB0ASO0NAYjQ38HtVFQT44dxEwf0qwmmt5mGoCdHTbDCQCtRjadZjeipLDsFx33DouZ +WJA== X-Gm-Message-State: AA+aEWbJYegqkuq7SwXnp6L108l336+iUbr51uCQ7nbZPAY7TCJg6yNn n1jWothGEHDHDWDkMrTONz3Hx9LV X-Google-Smtp-Source: AFSGD/V8PIsqNO4Eo27ngqRPIXyt9B0v3qdkd7fnEht/PH1hJgIM90Z0WT/UZ+q6X+QC/W3+QQVFAQ== X-Received: by 2002:a17:902:9b93:: with SMTP id y19mr10859701plp.336.1542614469405; Mon, 19 Nov 2018 00:01:09 -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.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Nov 2018 00:01:08 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 2/4] ndctl/namespace: Check for seed namespaces earlier Date: Mon, 19 Nov 2018 19:00:54 +1100 Message-Id: <20181119080056.13386-2-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 When creating an fsdax or devdax namespace we need to verify that the seed namespaces exist. This patch reworks the validation so that it's done earlier to simplify the subsequent patches in the series. No functional changes. Signed-off-by: Oliver O'Halloran --- ndctl/namespace.c | 51 +++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index b6f12306fe76..dc9a56609881 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -465,6 +465,8 @@ static int validate_namespace_options(struct ndctl_region *region, { const char *region_name = ndctl_region_get_devname(region); unsigned long long size_align = SZ_4K, units = 1, resource; + struct ndctl_pfn *pfn = NULL; + struct ndctl_dax *dax = NULL; unsigned int ways; int rc = 0; @@ -521,14 +523,28 @@ static int validate_namespace_options(struct ndctl_region *region, } else if (ndns) p->mode = ndctl_namespace_get_mode(ndns); - if (param.align) { - struct ndctl_pfn *pfn = ndctl_region_get_pfn_seed(region); - struct ndctl_dax *dax = ndctl_region_get_dax_seed(region); + if (p->mode == NDCTL_NS_MODE_MEMORY) { + pfn = ndctl_region_get_pfn_seed(region); + if (!pfn && param.mode_default) { + debug("%s fsdax mode not available\n", region_name); + p->mode = NDCTL_NS_MODE_RAW; + } else if (!pfn) { + error("Kernel does not support fsdax mode\n"); + return -ENODEV; + } + } else if (p->mode == NDCTL_NS_MODE_DAX) { + dax = ndctl_region_get_dax_seed(region); + if (!dax) { + error("Kernel does not support devdax mode\n"); + return -ENODEV; + } + } + if (param.align) { p->align = parse_size64(param.align); if (p->mode == NDCTL_NS_MODE_MEMORY && p->align != SZ_2M - && (!pfn || !ndctl_pfn_has_align(pfn))) { + && !ndctl_pfn_has_align(pfn)) { /* * Initial pfn device support in the kernel * supported a 2M default alignment when @@ -538,7 +554,7 @@ static int validate_namespace_options(struct ndctl_region *region, region_name); return -EAGAIN; } else if (p->mode == NDCTL_NS_MODE_DAX - && (!dax || !ndctl_dax_has_align(dax))) { + && !ndctl_dax_has_align(dax)) { /* * Unlike the pfn case, we require the kernel to * have 'align' support for device-dax. @@ -705,31 +721,6 @@ static int validate_namespace_options(struct ndctl_region *region, || p->mode == NDCTL_NS_MODE_DAX) p->loc = NDCTL_PFN_LOC_PMEM; - /* check if we need, and whether the kernel supports, pfn devices */ - if (do_setup_pfn(ndns, p)) { - struct ndctl_pfn *pfn = ndctl_region_get_pfn_seed(region); - - if (!pfn && param.mode_default) { - debug("%s fsdax mode not available\n", region_name); - p->mode = NDCTL_NS_MODE_RAW; - } else if (!pfn) { - error("operation failed, %s fsdax mode not available\n", - region_name); - return -EINVAL; - } - } - - /* check if we need, and whether the kernel supports, dax devices */ - if (p->mode == NDCTL_NS_MODE_DAX) { - struct ndctl_dax *dax = ndctl_region_get_dax_seed(region); - - if (!dax) { - error("operation failed, %s devdax mode not available\n", - region_name); - return -EINVAL; - } - } - p->autolabel = param.autolabel; return 0; From patchwork Mon Nov 19 08:00:55 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: 10688265 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 0AC2914BD for ; Mon, 19 Nov 2018 08:10:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE43B29A55 for ; Mon, 19 Nov 2018 08:10:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2D1D29A60; Mon, 19 Nov 2018 08:10: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 711CE29A55 for ; Mon, 19 Nov 2018 08:10:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7B72921E08179; 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 C381C21A09130 for ; Mon, 19 Nov 2018 00:01:11 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id 64so9976241pfr.9 for ; Mon, 19 Nov 2018 00:01:11 -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=SPLjcXRlsFZu9iR8PwKjZjAiloefyzq2xPb9UAEqeHY=; b=SSCH4oAR5H4F3wst9AYAV4MQHlUxF1IFTkaK+80D6DGElozEtKD/Szdtd1H+mWMVXY Q0F3pFPifogTJ0LvZ4rbqoXmXxcSk4SVNMmfhCjtSk0KysPSwI8uW3aiCARNCWvE57jD MUWWUDRExstCiwc7pnllAO73kttBGhu0lrJ8dVceOgD8RX4mcPoMcp0fOFtHyxdte7cB czNJ6yckUUPVWIZVpZzsEvrfM0tP283r/iKWA+GDqdBkUGyzr7eJpawVm47MX8iwXnLv xKJxhmvyRTbiV5z1gswru9WQfAzzidDJSjK/vwBZ8ymn0rBX68SWBhejcHBjpHioAV5R w+wA== 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=SPLjcXRlsFZu9iR8PwKjZjAiloefyzq2xPb9UAEqeHY=; b=TUBX0mWEDZNK7+cAcKF6Hbj3Sj1ti057Dk415i3VDlvrlWNOph3wsNCWifQ/0Edyw3 j/zcb1DyyyPPpVLdOzZbw8Z/rLA8tm3yzcmmVJ56gr9R7Z32HPBgZt0zK1WCOzZXhAS4 pPf90LK4p38eORNoRKELfOHo4dQBiPAT/Q+eXhisq0T1hm/WHJ7hR7k/cPfDsA3RSvUy ot3MPp5VKvRnDkVYi6VesW8vvPFothP+tAl33tlVhv+vEdi+NgyugzEBCXQo2GdByv+0 839yrUFYr8lucYP4kWtocpA6EYPM8M/Fabgodq/Rg+ueuXTdjxmbGlU/lBBeQh4ppi9j Znpg== X-Gm-Message-State: AGRZ1gJLqLDN5l2oMU1MqEp33ConK+883SYwRsxFrCNrg3QxifzIIu1l CrAb4MMW20CoSr1rRqGlfVf3M5tx X-Google-Smtp-Source: AJdET5fHe/9jAwbkQFV+V8lmmQZiLHbFuYrCeWOzVzOrxGJbSfkfAR5ZS6ElIYlSxbUyKdaRmAtalg== X-Received: by 2002:a63:e84c:: with SMTP id a12mr19012767pgk.241.1542614471225; Mon, 19 Nov 2018 00:01:11 -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.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Nov 2018 00:01:10 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 3/4] ndctl/namespace: Use seed alignment as the default Date: Mon, 19 Nov 2018 19:00:55 +1100 Message-Id: <20181119080056.13386-3-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 When creating a pfn or dax namespace ndctl uses a default alignment of 2MB when the user does not explicitly supply one. This works on most systems (x86, ARM, PPC64 with radix MMU), but it fails when the kernel does not support a 2MB page size (PPC64 with hash MMU). This patch makes ndctl use the alignment of the relevant seed namespace as the default instead. The kernel will always pick a valid default alignment so this should be a bit more portable. Signed-off-by: Oliver O'Halloran --- ndctl/namespace.c | 96 +++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index dc9a56609881..1e04f32c0e95 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -39,7 +39,6 @@ static bool logfix; static struct parameters { bool do_scan; bool mode_default; - bool align_default; bool autolabel; const char *bus; const char *map; @@ -226,9 +225,6 @@ static int set_defaults(enum device_action mode) error("failed to parse namespace alignment '%s'\n", param.align); rc = -EINVAL; - } else if (!param.align) { - param.align = "2M"; - param.align_default = true; } if (param.uuid) { @@ -464,7 +460,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 = SZ_4K, units = 1, resource; + unsigned long long size_align, units = 1, resource; struct ndctl_pfn *pfn = NULL; struct ndctl_dax *dax = NULL; unsigned int ways; @@ -541,53 +537,15 @@ static int validate_namespace_options(struct ndctl_region *region, } if (param.align) { - p->align = parse_size64(param.align); - - if (p->mode == NDCTL_NS_MODE_MEMORY && p->align != SZ_2M - && !ndctl_pfn_has_align(pfn)) { - /* - * 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 fsdax mode\n", - region_name); - return -EAGAIN; - } else if (p->mode == NDCTL_NS_MODE_DAX - && !ndctl_dax_has_align(dax)) { - /* - * Unlike the pfn case, we require the kernel to - * have 'align' support for device-dax. - */ - debug("%s not support 'align' for devdax 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 (p->mode != NDCTL_NS_MODE_MEMORY && + p->mode != NDCTL_NS_MODE_DAX) { error("%s mode does not support setting an alignment\n", p->mode == NDCTL_NS_MODE_SAFE ? "sector" : "raw"); return -ENXIO; } - /* - * Fallback to a 4K default alignment if the region is - * not 2MB (typical default) aligned. This mainly helps - * the nfit_test use case where it is backed by vmalloc - * memory. - */ - resource = ndctl_region_get_resource(region); - if (param.align_default && resource < ULLONG_MAX - && (resource & (SZ_2M - 1))) { - debug("%s: falling back to a 4K alignment\n", - region_name); - p->align = SZ_4K; - } + p->align = parse_size64(param.align); switch (p->align) { case SZ_4K: @@ -598,16 +556,48 @@ static int validate_namespace_options(struct ndctl_region *region, error("unsupported align: %s\n", param.align); return -ENXIO; } + } else { + /* + * Use the seed namespace alignment as the default if we need + * one. If we don't then use PAGE_SIZE so the size_align + * checking works. + */ + if (p->mode == NDCTL_NS_MODE_MEMORY) { + /* + * The initial pfn device support in the kernel didn't + * have the 'align' sysfs attribute and assumed a 2MB + * alignment. Fall back to that if we don't have the + * attribute. + */ + if (ndctl_pfn_has_align(pfn)) + p->align = ndctl_pfn_get_align(pfn); + else + p->align = SZ_2M; + } else if (p->mode == NDCTL_NS_MODE_DAX) { + /* + * device dax mode was added after the align attribute + * so checking for it is unnecessary. + */ + p->align = ndctl_dax_get_align(dax); + } else { + p->align = sysconf(_SC_PAGE_SIZE); + } /* - * 'raw' and 'sector' mode namespaces don't support an - * alignment attribute. + * Fallback to a page alignment if the region is not aligned + * to the default. This is mainly useful for the nfit_test + * use case where it is backed by vmalloc memory. */ - if (p->mode == NDCTL_NS_MODE_MEMORY - || p->mode == NDCTL_NS_MODE_DAX) - size_align = p->align; + resource = ndctl_region_get_resource(region); + if (resource < ULLONG_MAX && (resource & (p->align - 1))) { + debug("%s: falling back to a page alignment\n", + region_name); + p->align = sysconf(_SC_PAGE_SIZE); + } } + size_align = p->align; + /* (re-)validate that the size satisfies the alignment */ ways = ndctl_region_get_interleave_ways(region); if (p->size % (size_align * ways)) { @@ -633,8 +623,8 @@ static int validate_namespace_options(struct ndctl_region *region, p->size *= size_align; p->size /= units; error("'--size=' must align to interleave-width: %d and alignment: %ld\n" - " did you intend --size=%lld%s?\n", ways, param.align - ? p->align : SZ_4K, p->size, suffix); + " did you intend --size=%lld%s?\n", ways, p->align, + p->size, suffix); return -EINVAL; } 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; }