From patchwork Tue Jan 29 14:48:53 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: 10786425 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 2783A139A for ; Tue, 29 Jan 2019 14:49:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FF072C29A for ; Tue, 29 Jan 2019 14:49:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01B652C29C; Tue, 29 Jan 2019 14:49:15 +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 29DBF2C29A for ; Tue, 29 Jan 2019 14:49:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 01EA0211BB8D6; Tue, 29 Jan 2019 06:49:15 -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::544; helo=mail-pg1-x544.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 28662211B5A34 for ; Tue, 29 Jan 2019 06:49:13 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id c25so8837591pgb.4 for ; Tue, 29 Jan 2019 06:49: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:mime-version :content-transfer-encoding; bh=AwK3V4JjzI8OAj56XqChv0r1JtqL56kFM+V2uomzmQY=; b=OhcdkYyuphKHbkbcBDwJYjRo2DErFVpGFZGD9ta4IhqRHbZB1rS7qH3zZY0PsNPmgi +eYXxf26u7Ax4h7KHXG4heu8dUNlUFvhiKIYt0FcaGJyA9qdtes33RiE2E95eDqUZyv1 1u4uUaFDIqj2+rXnVqMvAC4HbPypm/zqSitFgJ4jiGce9jDa/kB1vjEcxHTzFxWRrO3c QKXEsuNLhRFqCCrwFbkizPmE2T0w2X52kaWKPEzezQiVZnQ3BetzbcvSiXxq+Oq3Gb0/ a2aFE+WR05TWuKVoKNxObFVw+QIKJ/VgcxLmdpx51yrhqG2MoGCKKB/z9wdfK7aaiB5s f5kg== 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:mime-version :content-transfer-encoding; bh=AwK3V4JjzI8OAj56XqChv0r1JtqL56kFM+V2uomzmQY=; b=W67kQm8CD+G6RpfwEb8zSLGRJez8RwClxhDjoY8I3kwiDy2xTeYFOckDxr4CKMTt4b vuymkmkkAxP3l5JIOADNU2O+IrRib0XvzCQCBTQGnXV1fnN6EXp5UELl41f1QwbFiZHx yScAOzHLsw9DpLQnsR5ynxMl4gcaX7xwtsyNApNaaI6IpY591stW1xnbIF701nr7TgWS ln0miJyx3w25OFpMIAwRH4L6HI1zKWDvFKd6gr/JdZ+WObNbE6Tb8YEmi+ApvbBmUMEW c3ktJICJ8RSlOml5C/X/Lg+nkLX824zHXfVnzgDD+c14k+vWjosypmmxcojyaCEITNIs yK5w== X-Gm-Message-State: AJcUukctshpMvXobjQTNbc4kNlTzpWDR+Zs+EkSOi1nSYoSVK5Tt8N9A 6dO1/8gjWSHXRmSZOBFxUstlzm/2 X-Google-Smtp-Source: ALg8bN6JLx9/EK0ioTplkdwwUp4z1tdYNcn0LBGRHCbil6VdYanMOD8eFQgH6rynSGt1ZPirt3DQjQ== X-Received: by 2002:a62:178f:: with SMTP id 137mr26234118pfx.226.1548773353273; Tue, 29 Jan 2019 06:49:13 -0800 (PST) Received: from 192-168-1-15.tpgi.com.au (203-219-255-210.tpgi.com.au. [203.219.255.210]) by smtp.gmail.com with ESMTPSA id g26sm44944677pfh.61.2019.01.29.06.49.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 06:49:12 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v4 1/5] libndctl: Use the supported_alignment attribute Date: Wed, 30 Jan 2019 01:48:53 +1100 Message-Id: <20190129144857.6741-1-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 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 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 --- v4: Changed return code of ndctl_pfn_get_supported_alignment from -1 to -1 to -EINVAL. Reworded comment about why we default to 4K and 2M alignments when the sysfs attribute is missing. Shuffled around prototypes in ndctl.h. 80 char compliance fixes. rebased onto pending branch v3: Changed the return type of the *_get_supported_alignment() functions to unsigned long to match the existing *_get_alignment() functions. --- ndctl/lib/libndctl.c | 44 ++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 4 ++++ ndctl/libndctl.h | 4 ++++ 3 files changed, 52 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 830b791339d2..64cd2996bbd9 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 { @@ -4814,6 +4816,20 @@ static void *__add_pfn(struct ndctl_pfn *pfn, const char *pfn_base) else pfn->size = strtoull(buf, NULL, 0); + /* + * The supported_alignments attribute was added before arches other + * than x86 had pmem support. If the kernel doesn't provide the + * attribute then it's safe to a attribute then it's safe to assume + * that we are 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; @@ -5048,6 +5064,23 @@ NDCTL_EXPORT int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align) return 0; } +NDCTL_EXPORT int ndctl_pfn_get_num_alignments(struct ndctl_pfn *pfn) +{ + return pfn->alignments.num; +} + +NDCTL_EXPORT unsigned long 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 -EINVAL; + else + return pfn->alignments.supported[i]; +} + NDCTL_EXPORT int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn, struct ndctl_namespace *ndns) { @@ -5270,6 +5303,17 @@ NDCTL_EXPORT unsigned long ndctl_dax_get_align(struct ndctl_dax *dax) return ndctl_pfn_get_align(&dax->pfn); } +NDCTL_EXPORT int ndctl_dax_get_num_alignments(struct ndctl_dax *dax) +{ + return ndctl_pfn_get_num_alignments(&dax->pfn); +} + +NDCTL_EXPORT unsigned long 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 275db92ee103..a30a93e3c012 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -390,4 +390,8 @@ LIBNDCTL_19 { global: ndctl_cmd_xlat_firmware_status; ndctl_cmd_submit_xlat; + 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 e55a5932781d..ac639b7d9142 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -597,7 +597,9 @@ int ndctl_pfn_set_uuid(struct ndctl_pfn *pfn, uuid_t uu); void ndctl_pfn_get_uuid(struct ndctl_pfn *pfn, uuid_t uu); int ndctl_pfn_has_align(struct ndctl_pfn *pfn); int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align); +int ndctl_pfn_get_num_alignments(struct ndctl_pfn *pfn); unsigned long ndctl_pfn_get_align(struct ndctl_pfn *pfn); +unsigned long ndctl_pfn_get_supported_alignment(struct ndctl_pfn *pfn, int i); unsigned long long ndctl_pfn_get_resource(struct ndctl_pfn *pfn); unsigned long long ndctl_pfn_get_size(struct ndctl_pfn *pfn); int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn, struct ndctl_namespace *ndns); @@ -628,7 +630,9 @@ unsigned long long ndctl_dax_get_resource(struct ndctl_dax *dax); int ndctl_dax_set_uuid(struct ndctl_dax *dax, uuid_t uu); enum ndctl_pfn_loc ndctl_dax_get_location(struct ndctl_dax *dax); int ndctl_dax_set_location(struct ndctl_dax *dax, enum ndctl_pfn_loc loc); +int ndctl_dax_get_num_alignments(struct ndctl_dax *dax); unsigned long ndctl_dax_get_align(struct ndctl_dax *dax); +unsigned long ndctl_dax_get_supported_alignment(struct ndctl_dax *dax, int i); int ndctl_dax_has_align(struct ndctl_dax *dax); int ndctl_dax_set_align(struct ndctl_dax *dax, unsigned long align); int ndctl_dax_set_namespace(struct ndctl_dax *dax,