From patchwork Thu Apr 27 09:14:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 9702617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DBC696032C for ; Thu, 27 Apr 2017 09:15:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3CE02860F for ; Thu, 27 Apr 2017 09:15:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A816928623; Thu, 27 Apr 2017 09:15:11 +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=-1.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no 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 5EE722860F for ; Thu, 27 Apr 2017 09:15:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 88E0221951CAD; Thu, 27 Apr 2017 02:15:10 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-pf0-x243.google.com (mail-pf0-x243.google.com [IPv6:2607:f8b0:400e:c00::243]) (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 52FA421951C94 for ; Thu, 27 Apr 2017 02:15:09 -0700 (PDT) Received: by mail-pf0-x243.google.com with SMTP id g23so8060169pfj.1 for ; Thu, 27 Apr 2017 02:15:09 -0700 (PDT) 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=QNSsqEP+mIs3gHzLJFgtiZu+9x9RFjGJvN8v3PcnqV4=; b=oikPVfrZOIoYQ43/DBweBrqrNUgn71soJzXTomTmJxKDfsZ8MwxYZnH6am4mUZtJ3X 6VRE+CzeP3hZewNAQcYgmIdkUl6I2XwM6rtqKwIoGlm9dUS1d4EnQ8/7I5/460q3gQmq Rdf/xuhtmPSXAmjYlRo6TPNzgRtvpl/t0ijJHB5JhUklRKSP/GKXJzD62yJk+yftUoNz NwRIeTNfF5zxk0GD1+pSixexr2naXWX4E01FxdlAURhfEx0A1McKnlwPK7GnBScFaubD A085DhH1tc04pim0rL5Ro/ezbbWNxSrW++P/8Ghencjuia0VT8ugcrcwSfQxn8CFOBzm HiyQ== 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=QNSsqEP+mIs3gHzLJFgtiZu+9x9RFjGJvN8v3PcnqV4=; b=Uj+c+oZEcp7VeAXE8h6oMbcXCKCFiKT1fXuvW8FCxj7Pr6F8T/ozBJmqR4o61m+qDe Qszi5jFIiK1JZwgVUfqnWcEOPqtLNqRAO5gxYPduSZSoPyQYr8vSdwrNUheTynrwzl6T RQ6ELBoaMlzPMzsyx1dplhCRkKaZ9fzmy9bpBPkW13Bk/RfKaM1kgdFGOSXfKj9toHmA yRRav7mTIBW7Z+IikTJ1Kw2lN0Hux60ZraFzT0wlslqtj2EOrxeWqMnphHMV74YFHalw MXCqtYXoqIKnP/mRbfLqcj3ZFaOMsd7ewDPc5fY+DnUsZfCRaO4TOgmF3E4sDb9GmaLK p6NA== X-Gm-Message-State: AN3rC/6tXUTFcuL+n9eZYaX7DIuqFukILXtbDvGnWHQkaziL+/mpAmv4 wJ32iaFebG0lIQ== X-Received: by 10.84.204.8 with SMTP id a8mr5849373ple.4.1493284509042; Thu, 27 Apr 2017 02:15:09 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id 3sm2954210pfe.20.2017.04.27.02.15.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Apr 2017 02:15:08 -0700 (PDT) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 2/4] ndctl: Parse supported_alignments for dax and pfn devices Date: Thu, 27 Apr 2017 19:14:52 +1000 Message-Id: <20170427091454.17412-2-oohall@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170427091454.17412-1-oohall@gmail.com> References: <20170427091454.17412-1-oohall@gmail.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 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 advertise the list of alignments that they support through sysfs. This patch adds parsing inside of libndctl to determine the alignments permitted. Signed-off-by: Oliver O'Halloran --- ndctl/lib/libndctl.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 4 ++++ ndctl/libndctl.h.in | 4 ++++ 3 files changed, 61 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 25a1e6d20d10..f9bc4ee72bb8 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -34,6 +34,7 @@ #include #endif +#include #include #include #include @@ -323,6 +324,8 @@ struct ndctl_pfn { int buf_len; uuid_t uuid; int id, generation; + struct ndctl_sizes alignments; + unsigned long default_align; }; struct ndctl_dax { @@ -4025,6 +4028,29 @@ static void *__add_pfn(struct ndctl_pfn *pfn, const char *pfn_base) else pfn->size = strtoull(buf, NULL, 0); + /* + * Newer kernels explicitly state what they support with the + * supported_alignments attribuate and older kernels only + * support 4K, 2M or 1G alignments. + */ + sprintf(path, "%s/supported_alignments", pfn_base); + if (!sysfs_read_attr(ctx, path, buf)) { + if (parse_sizes(ctx, devpath_to_devname(pfn_base), + buf, &pfn->alignments)) { + goto err_read; + } + + sprintf(path, "%s/default_alignment", pfn_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + goto err_read; + + pfn->default_align = strtoull(buf, NULL, 0); + } else { + pfn->alignments.supported = + (unsigned int []) {SZ_4K, SZ_2M, SZ_1G}; + pfn->default_align = SZ_2M; + } + free(path); return pfn; @@ -4256,6 +4282,22 @@ NDCTL_EXPORT int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align) return 0; } +NDCTL_EXPORT unsigned long ndctl_pfn_def_align(struct ndctl_pfn *pfn) +{ + return pfn->default_align; +} + +NDCTL_EXPORT int ndctl_pfn_supports_align(struct ndctl_pfn *pfn, + unsigned long align) +{ + int i; + + for (i = 0; i < pfn->alignments.num; i++) + if (pfn->alignments.supported[i] == align) + return true; + return false; +} + NDCTL_EXPORT int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn, struct ndctl_namespace *ndns) { @@ -4482,6 +4524,17 @@ NDCTL_EXPORT int ndctl_dax_has_align(struct ndctl_dax *dax) return ndctl_pfn_has_align(&dax->pfn); } +NDCTL_EXPORT unsigned long ndctl_dax_def_align(struct ndctl_dax *dax) +{ + return ndctl_pfn_def_align(&dax->pfn); +} + +NDCTL_EXPORT int ndctl_dax_supports_align(struct ndctl_dax *dax, + unsigned long align) +{ + return ndctl_pfn_supports_align(&dax->pfn, align); +} + NDCTL_EXPORT int ndctl_dax_set_align(struct ndctl_dax *dax, unsigned long align) { return ndctl_pfn_set_align(&dax->pfn, align); diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index be2e3680d202..fa60dfb82a9e 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -231,6 +231,8 @@ global: ndctl_pfn_get_location; ndctl_pfn_set_location; ndctl_pfn_get_align; + ndctl_pfn_def_align; + ndctl_pfn_supports_align; ndctl_pfn_get_size; ndctl_pfn_get_resource; ndctl_pfn_has_align; @@ -259,6 +261,8 @@ global: ndctl_dax_get_location; ndctl_dax_set_location; ndctl_dax_get_align; + ndctl_dax_def_align; + ndctl_dax_supports_align; ndctl_dax_has_align; ndctl_dax_set_align; ndctl_dax_set_namespace; diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in index c27581d939c5..be0e20b706fa 100644 --- a/ndctl/libndctl.h.in +++ b/ndctl/libndctl.h.in @@ -572,6 +572,8 @@ 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); unsigned long ndctl_pfn_get_align(struct ndctl_pfn *pfn); +unsigned long ndctl_pfn_def_align(struct ndctl_pfn *pfn); +int ndctl_pfn_supports_align(struct ndctl_pfn *pfn, unsigned long align); 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); @@ -603,6 +605,8 @@ 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); unsigned long ndctl_dax_get_align(struct ndctl_dax *dax); +unsigned long ndctl_dax_def_align(struct ndctl_dax *dax); +int ndctl_dax_supports_align(struct ndctl_dax *dax, unsigned long align); 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,