From: Dan Williams <dan.j.williams@intel.com>
To: linux-cxl@vger.kernel.org
Cc: vishal.l.verma@intel.com
Subject: [ndctl PATCH 16/37] util/sysfs: Uplevel modalias lookup helper to util/
Date: Sun, 23 Jan 2022 16:53:13 -0800 [thread overview]
Message-ID: <164298559346.3021641.11059026790676662837.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <164298550885.3021641.11210386002804544864.stgit@dwillia2-desk3.amr.corp.intel.com>
The to_module() helper looks up modules relative to a modalias. Uplevel
this to share with libcxl.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
ndctl/lib/libndctl.c | 33 +++++----------------------------
util/sysfs.c | 27 +++++++++++++++++++++++++++
util/sysfs.h | 8 ++++++++
3 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 47a234ccc8ce..1374ad9e504f 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1668,7 +1668,6 @@ static enum ndctl_fwa_result fwa_result_to_result(const char *result)
static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,
const char *devname);
static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath);
-static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char *alias);
static int populate_dimm_attributes(struct ndctl_dimm *dimm,
const char *dimm_base,
@@ -1878,7 +1877,7 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
sprintf(path, "%s/modalias", dimm_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
- dimm->module = to_module(ctx, buf);
+ dimm->module = util_modalias_to_module(ctx, buf);
dimm->handle = -1;
dimm->phys_id = -1;
@@ -2597,7 +2596,7 @@ static void *add_region(void *parent, int id, const char *region_base)
sprintf(path, "%s/modalias", region_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
- region->module = to_module(ctx, buf);
+ region->module = util_modalias_to_module(ctx, buf);
sprintf(path, "%s/numa_node", region_base);
if ((rc = sysfs_read_attr(ctx, path, buf)) == 0)
@@ -3885,28 +3884,6 @@ NDCTL_EXPORT struct ndctl_ctx *ndctl_mapping_get_ctx(
return ndctl_mapping_get_bus(mapping)->ctx;
}
-static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char *alias)
-{
- struct kmod_list *list = NULL;
- struct kmod_module *mod;
- int rc;
-
- if (!ctx->kmod_ctx)
- return NULL;
-
- rc = kmod_module_new_from_lookup(ctx->kmod_ctx, alias, &list);
- if (rc < 0 || !list) {
- dbg(ctx, "failed to find module for alias: %s %d list: %s\n",
- alias, rc, list ? "populated" : "empty");
- return NULL;
- }
- mod = kmod_module_get_module(list);
- dbg(ctx, "alias: %s module: %s\n", alias, kmod_module_get_name(mod));
- kmod_module_unref_list(list);
-
- return mod;
-}
-
static char *get_block_device(struct ndctl_ctx *ctx, const char *block_path)
{
char *bdev_name = NULL;
@@ -4069,7 +4046,7 @@ static void *add_namespace(void *parent, int id, const char *ndns_base)
sprintf(path, "%s/modalias", ndns_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
- ndns->module = to_module(ctx, buf);
+ ndns->module = util_modalias_to_module(ctx, buf);
ndctl_namespace_foreach(region, ndns_dup)
if (ndns_dup->id == ndns->id) {
@@ -5182,7 +5159,7 @@ static void *add_btt(void *parent, int id, const char *btt_base)
sprintf(path, "%s/modalias", btt_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
- btt->module = to_module(ctx, buf);
+ btt->module = util_modalias_to_module(ctx, buf);
sprintf(path, "%s/uuid", btt_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
@@ -5533,7 +5510,7 @@ static void *__add_pfn(struct ndctl_pfn *pfn, const char *pfn_base)
sprintf(path, "%s/modalias", pfn_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
- pfn->module = to_module(ctx, buf);
+ pfn->module = util_modalias_to_module(ctx, buf);
sprintf(path, "%s/uuid", pfn_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
diff --git a/util/sysfs.c b/util/sysfs.c
index cfbab7da74e9..23330cb29002 100644
--- a/util/sysfs.c
+++ b/util/sysfs.c
@@ -10,6 +10,7 @@
#include <ctype.h>
#include <fcntl.h>
#include <dirent.h>
+#include <libkmod.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -118,3 +119,29 @@ int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path,
return add_errors;
}
+
+struct kmod_module *__util_modalias_to_module(struct kmod_ctx *kmod_ctx,
+ const char *alias,
+ struct log_ctx *log)
+{
+ struct kmod_list *list = NULL;
+ struct kmod_module *mod;
+ int rc;
+
+ if (!kmod_ctx)
+ return NULL;
+
+ rc = kmod_module_new_from_lookup(kmod_ctx, alias, &list);
+ if (rc < 0 || !list) {
+ log_dbg(log,
+ "failed to find module for alias: %s %d list: %s\n",
+ alias, rc, list ? "populated" : "empty");
+ return NULL;
+ }
+ mod = kmod_module_get_module(list);
+ log_dbg(log, "alias: %s module: %s\n", alias,
+ kmod_module_get_name(mod));
+ kmod_module_unref_list(list);
+
+ return mod;
+}
diff --git a/util/sysfs.h b/util/sysfs.h
index 6485a73d8ed7..bdee4f5c291d 100644
--- a/util/sysfs.h
+++ b/util/sysfs.h
@@ -27,4 +27,12 @@ static inline const char *devpath_to_devname(const char *devpath)
{
return strrchr(devpath, '/') + 1;
}
+
+struct kmod_ctx;
+struct kmod_module;
+struct kmod_module *__util_modalias_to_module(struct kmod_ctx *kmod_ctx,
+ const char *alias,
+ struct log_ctx *log);
+#define util_modalias_to_module(ctx, buf) \
+ __util_modalias_to_module((ctx)->kmod_ctx, buf, &(ctx)->ctx)
#endif /* __UTIL_SYSFS_H__ */
next prev parent reply other threads:[~2022-01-24 0:53 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 0:51 [ndctl PATCH 00/37] cxl: Full topology enumeration Dan Williams
2022-01-24 0:51 ` [ndctl PATCH 01/37] test: Add 'suite' identifiers to tests Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 02/37] ndctl: Rename util_filter to ndctl_filter Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 03/37] build: Add tags Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 04/37] json: Add support for json_object_new_uint64() Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 05/37] cxl/json: Cleanup object leak false positive Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 06/37] cxl/list: Support multiple memdev device name filter arguments Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 07/37] cxl/list: Support comma separated lists Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 08/37] cxl/list: Introduce cxl_filter_walk() Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 09/37] cxl/list: Emit device serial numbers Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 10/37] cxl/list: Add filter by serial support Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 11/37] cxl/lib: Rename nvdimm bridge to pmem Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 12/37] cxl/list: Cleanup options definitions Dan Williams
2022-01-24 0:52 ` [ndctl PATCH 13/37] Documentation: Enhance libcxl memdev API documentation Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 14/37] cxl/list: Add bus objects Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 15/37] util/json: Warn on stderr about empty list results Dan Williams
2022-01-24 0:53 ` Dan Williams [this message]
2022-01-24 0:53 ` [ndctl PATCH 17/37] cxl/list: Add port enumeration Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 18/37] cxl/list: Add --debug option Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 19/37] cxl/list: Add endpoints Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 20/37] cxl/list: Add 'host' entries for port-like objects Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 21/37] cxl/list: Add 'host' entries for memdevs Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 22/37] cxl/list: Move enabled memdevs underneath their endpoint Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 23/37] cxl/list: Filter memdev by ancestry Dan Williams
2022-01-24 0:53 ` [ndctl PATCH 24/37] cxl/memdev: Use a local logger for debug Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 25/37] cxl/memdev: Cleanup memdev filter Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 26/37] cxl/memdev: Add serial support for memdev-related commands Dan Williams
2022-02-10 1:10 ` Alison Schofield
2022-02-10 1:55 ` Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 27/37] cxl/list: Add 'numa_node' to memdev listings Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 28/37] util: Implement common bind/unbind helpers Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 29/37] cxl/memdev: Enable / disable support Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 30/37] cxl/list: Add decoder support Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 31/37] cxl/list: Extend decoder objects with target information Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 32/37] cxl/list: Use 'physical_node' for root port attachment detection Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 33/37] cxl/list: Reuse the --target option for ports Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 34/37] cxl/list: Support filtering memdevs by decoders Dan Williams
2022-01-24 0:54 ` [ndctl PATCH 35/37] cxl/list: Support filtering memdevs by ports Dan Williams
2022-01-24 0:55 ` [ndctl PATCH 36/37] cxl/port: Add {disable,enable}-port command Dan Williams
2022-01-24 0:55 ` [ndctl PATCH 37/37] cxl/list: Filter dports and targets by memdevs Dan Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=164298559346.3021641.11059026790676662837.stgit@dwillia2-desk3.amr.corp.intel.com \
--to=dan.j.williams@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).