From patchwork Wed Jan 30 10:59:21 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: 10788263 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 413FF91E for ; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 283B42E3BB for ; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15C1F2E3E3; Wed, 30 Jan 2019 10:59:43 +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 935D02E3BB for ; Wed, 30 Jan 2019 10:59:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 386DD211BFCC7; Wed, 30 Jan 2019 02:59:42 -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::443; helo=mail-pf1-x443.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (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 56809211BFCC4 for ; Wed, 30 Jan 2019 02:59:41 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id u6so11225565pfh.11 for ; Wed, 30 Jan 2019 02:59:41 -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=gpcJC925Dzn4L84tSMBOywJz1xpyjGw7bG2diEjC9BE=; b=qX0qzRn3+7JY5yopwYqNP0felpK1v4A3sLZdWvDBjnZhOmssqD1L/ioF4VBNbDxtbR tvWdQ4+nELD447ZYF5i+nFV3gDZcq1GCeK30F62f3hWjEWdSlgeob+PdqBJ7Un4lQEiM 6BhnMAL9kCQFMeur4jLHz9a6vSYTTJqIJKdBraN0gvamb8/BuDCOOYxu2zeop0s1/Q5h otZqyh7etesH2/Or0ExVv+LM5ztfW/saf8e36N0OAtmVaWKAePKUmumM53xs3LiXZeMY +3VYmHWNd+IkQbkd5kfmUlwBhNQqK5gMxgEInYVsujzRQ30pfvzWGmd/h7jgoD14cyAH lSig== 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=gpcJC925Dzn4L84tSMBOywJz1xpyjGw7bG2diEjC9BE=; b=Yj2y/0IvNnBRmEDgf6RVNFcFkGk/ca5iq791fPdtD9tDXZDpOT5whGNcqQWqn+VuZC NYcEhj2P5xyYiBpqzK5R9ACEiKRlVwdFHOqwFbjpMYSmGabuw0Vqem6Ail+RpmWlLba1 zHHtvsQeFGpKshrsFrni9HXXnklO6//V/3z0aI4+GI6WINbHS6AyxIlgp+J1HiHSjfoX WlQ3OdH/n8tq2/dFXYyUhnLvpz3XdoNtuTxfmCfUlPHPjNLcsg9uKLgWTcooQO5phxMm 7Hr01AKODrmtESsQx2Q331fuaiv/xb6PN1a8mDWRzN0qif/yfhgN6M98jQEftNermtIG 0v/Q== X-Gm-Message-State: AJcUukf/YiUFEfOdKft+itrt0UhW4zlXLvNgKBfq5PqZsLKBFRJ/TgIB 8cc5NIxpoKFl3ekh6znTYao9+D6y X-Google-Smtp-Source: ALg8bN45wf+t5l8C6ru1UrdTSmJNbxVlgqVRk/L257R6una77PpvRyOjw9+jOEyZYnSdAAQhlSA8jQ== X-Received: by 2002:a62:16d6:: with SMTP id 205mr29865402pfw.256.1548845980004; Wed, 30 Jan 2019 02:59:40 -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.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:39 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 1/7] libndctl: Use the supported_alignment attribute Date: Wed, 30 Jan 2019 21:59:21 +1100 Message-Id: <20190130105927.31901-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 --- v5: Fixed comment wording 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 | 43 ++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 4 ++++ ndctl/libndctl.h | 4 ++++ 3 files changed, 51 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 830b791339d2..06f835d76117 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,19 @@ 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 assume that we running on x86 where + * 4KiB and 2MiB have always been supported. + */ + 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 +5063,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 +5302,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,