|
Jeff Moyer |
2c91dc |
From e31fc778998b4d02ffec68e61869aaeccfd99be8 Mon Sep 17 00:00:00 2001
|
|
Jeff Moyer |
2c91dc |
From: Dan Williams <dan.j.williams@intel.com>
|
|
Jeff Moyer |
2c91dc |
Date: Sun, 23 Jan 2022 16:54:17 -0800
|
|
Jeff Moyer |
2c91dc |
Subject: [PATCH 114/217] util: Implement common bind/unbind helpers
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
Refactor ndctl_{bind,unbind}() into util_{bind,unbind}() for libcxl to
|
|
Jeff Moyer |
2c91dc |
reuse.
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
daxctl can not join the party for now as it needs to play games with
|
|
Jeff Moyer |
2c91dc |
'new_id'.
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
Link: https://lore.kernel.org/r/164298565707.3021641.7763459936156744907.stgit@dwillia2-desk3.amr.corp.intel.com
|
|
Jeff Moyer |
2c91dc |
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
|
|
Jeff Moyer |
2c91dc |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
Jeff Moyer |
2c91dc |
---
|
|
Jeff Moyer |
2c91dc |
ndctl/lib/libndctl.c | 103 +++++--------------------------------------
|
|
Jeff Moyer |
2c91dc |
util/sysfs.c | 76 +++++++++++++++++++++++++++++++
|
|
Jeff Moyer |
2c91dc |
util/sysfs.h | 8 ++++
|
|
Jeff Moyer |
2c91dc |
3 files changed, 96 insertions(+), 91 deletions(-)
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
|
|
Jeff Moyer |
2c91dc |
index 1374ad9..98d184b 100644
|
|
Jeff Moyer |
2c91dc |
--- a/ndctl/lib/libndctl.c
|
|
Jeff Moyer |
2c91dc |
+++ b/ndctl/lib/libndctl.c
|
|
Jeff Moyer |
2c91dc |
@@ -1665,10 +1665,6 @@ static enum ndctl_fwa_result fwa_result_to_result(const char *result)
|
|
Jeff Moyer |
2c91dc |
return NDCTL_FWA_RESULT_INVALID;
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
-static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,
|
|
Jeff Moyer |
2c91dc |
- const char *devname);
|
|
Jeff Moyer |
2c91dc |
-static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath);
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
static int populate_dimm_attributes(struct ndctl_dimm *dimm,
|
|
Jeff Moyer |
2c91dc |
const char *dimm_base,
|
|
Jeff Moyer |
2c91dc |
const char *bus_prefix)
|
|
Jeff Moyer |
2c91dc |
@@ -2305,7 +2301,7 @@ NDCTL_EXPORT int ndctl_dimm_disable(struct ndctl_dimm *dimm)
|
|
Jeff Moyer |
2c91dc |
if (!ndctl_dimm_is_enabled(dimm))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_unbind(ctx, dimm->dimm_path);
|
|
Jeff Moyer |
2c91dc |
+ util_unbind(dimm->dimm_path, ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
if (ndctl_dimm_is_enabled(dimm)) {
|
|
Jeff Moyer |
2c91dc |
err(ctx, "%s: failed to disable\n", devname);
|
|
Jeff Moyer |
2c91dc |
@@ -2324,7 +2320,7 @@ NDCTL_EXPORT int ndctl_dimm_enable(struct ndctl_dimm *dimm)
|
|
Jeff Moyer |
2c91dc |
if (ndctl_dimm_is_enabled(dimm))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_bind(ctx, dimm->module, devname);
|
|
Jeff Moyer |
2c91dc |
+ util_bind(devname, dimm->module, "nd", ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
if (!ndctl_dimm_is_enabled(dimm)) {
|
|
Jeff Moyer |
2c91dc |
err(ctx, "%s: failed to enable\n", devname);
|
|
Jeff Moyer |
2c91dc |
@@ -3573,7 +3569,7 @@ NDCTL_EXPORT int ndctl_region_enable(struct ndctl_region *region)
|
|
Jeff Moyer |
2c91dc |
if (ndctl_region_is_enabled(region))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_bind(ctx, region->module, devname);
|
|
Jeff Moyer |
2c91dc |
+ util_bind(devname, region->module, "nd", ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
if (!ndctl_region_is_enabled(region)) {
|
|
Jeff Moyer |
2c91dc |
err(ctx, "%s: failed to enable\n", devname);
|
|
Jeff Moyer |
2c91dc |
@@ -3610,7 +3606,7 @@ static int ndctl_region_disable(struct ndctl_region *region, int cleanup)
|
|
Jeff Moyer |
2c91dc |
if (!ndctl_region_is_enabled(region))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_unbind(ctx, region->region_path);
|
|
Jeff Moyer |
2c91dc |
+ util_unbind(region->region_path, ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
if (ndctl_region_is_enabled(region)) {
|
|
Jeff Moyer |
2c91dc |
err(ctx, "%s: failed to disable\n", devname);
|
|
Jeff Moyer |
2c91dc |
@@ -4373,81 +4369,6 @@ NDCTL_EXPORT struct badblock *ndctl_namespace_get_first_badblock(
|
|
Jeff Moyer |
2c91dc |
return badblocks_iter_first(&ndns->bb_iter, ctx, path);
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
-static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,
|
|
Jeff Moyer |
2c91dc |
- const char *devname)
|
|
Jeff Moyer |
2c91dc |
-{
|
|
Jeff Moyer |
2c91dc |
- DIR *dir;
|
|
Jeff Moyer |
2c91dc |
- int rc = 0;
|
|
Jeff Moyer |
2c91dc |
- char path[200];
|
|
Jeff Moyer |
2c91dc |
- struct dirent *de;
|
|
Jeff Moyer |
2c91dc |
- const int len = sizeof(path);
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- if (!devname) {
|
|
Jeff Moyer |
2c91dc |
- err(ctx, "missing devname\n");
|
|
Jeff Moyer |
2c91dc |
- return -EINVAL;
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- if (module) {
|
|
Jeff Moyer |
2c91dc |
- rc = kmod_module_probe_insert_module(module,
|
|
Jeff Moyer |
2c91dc |
- KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL,
|
|
Jeff Moyer |
2c91dc |
- NULL);
|
|
Jeff Moyer |
2c91dc |
- if (rc < 0) {
|
|
Jeff Moyer |
2c91dc |
- err(ctx, "%s: insert failure: %d\n", __func__, rc);
|
|
Jeff Moyer |
2c91dc |
- return rc;
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- if (snprintf(path, len, "/sys/bus/nd/drivers") >= len) {
|
|
Jeff Moyer |
2c91dc |
- err(ctx, "%s: buffer too small!\n", devname);
|
|
Jeff Moyer |
2c91dc |
- return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- dir = opendir(path);
|
|
Jeff Moyer |
2c91dc |
- if (!dir) {
|
|
Jeff Moyer |
2c91dc |
- err(ctx, "%s: opendir(\"%s\") failed\n", devname, path);
|
|
Jeff Moyer |
2c91dc |
- return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- while ((de = readdir(dir)) != NULL) {
|
|
Jeff Moyer |
2c91dc |
- char *drv_path;
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- if (de->d_ino == 0)
|
|
Jeff Moyer |
2c91dc |
- continue;
|
|
Jeff Moyer |
2c91dc |
- if (de->d_name[0] == '.')
|
|
Jeff Moyer |
2c91dc |
- continue;
|
|
Jeff Moyer |
2c91dc |
- if (asprintf(&drv_path, "%s/%s/bind", path, de->d_name) < 0) {
|
|
Jeff Moyer |
2c91dc |
- err(ctx, "%s: path allocation failure\n", devname);
|
|
Jeff Moyer |
2c91dc |
- continue;
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- rc = sysfs_write_attr_quiet(ctx, drv_path, devname);
|
|
Jeff Moyer |
2c91dc |
- free(drv_path);
|
|
Jeff Moyer |
2c91dc |
- if (rc == 0)
|
|
Jeff Moyer |
2c91dc |
- break;
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
- closedir(dir);
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- if (rc) {
|
|
Jeff Moyer |
2c91dc |
- dbg(ctx, "%s: bind failed\n", devname);
|
|
Jeff Moyer |
2c91dc |
- return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
- return 0;
|
|
Jeff Moyer |
2c91dc |
-}
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
-static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath)
|
|
Jeff Moyer |
2c91dc |
-{
|
|
Jeff Moyer |
2c91dc |
- const char *devname = devpath_to_devname(devpath);
|
|
Jeff Moyer |
2c91dc |
- char path[200];
|
|
Jeff Moyer |
2c91dc |
- const int len = sizeof(path);
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- if (snprintf(path, len, "%s/driver/unbind", devpath) >= len) {
|
|
Jeff Moyer |
2c91dc |
- err(ctx, "%s: buffer too small!\n", devname);
|
|
Jeff Moyer |
2c91dc |
- return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
- }
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
- return sysfs_write_attr(ctx, path, devname);
|
|
Jeff Moyer |
2c91dc |
-}
|
|
Jeff Moyer |
2c91dc |
-
|
|
Jeff Moyer |
2c91dc |
static void *add_btt(void *parent, int id, const char *btt_base);
|
|
Jeff Moyer |
2c91dc |
static void *add_pfn(void *parent, int id, const char *pfn_base);
|
|
Jeff Moyer |
2c91dc |
static void *add_dax(void *parent, int id, const char *dax_base);
|
|
Jeff Moyer |
2c91dc |
@@ -4533,7 +4454,7 @@ NDCTL_EXPORT int ndctl_namespace_enable(struct ndctl_namespace *ndns)
|
|
Jeff Moyer |
2c91dc |
if (ndctl_namespace_is_enabled(ndns))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- rc = ndctl_bind(ctx, ndns->module, devname);
|
|
Jeff Moyer |
2c91dc |
+ rc = util_bind(devname, ndns->module, "nd", ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
/*
|
|
Jeff Moyer |
2c91dc |
* Rescan now as successfully enabling a namespace device leads
|
|
Jeff Moyer |
2c91dc |
@@ -4581,7 +4502,7 @@ NDCTL_EXPORT int ndctl_namespace_disable(struct ndctl_namespace *ndns)
|
|
Jeff Moyer |
2c91dc |
if (!ndctl_namespace_is_enabled(ndns))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_unbind(ctx, ndns->ndns_path);
|
|
Jeff Moyer |
2c91dc |
+ util_unbind(ndns->ndns_path, ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
if (ndctl_namespace_is_enabled(ndns)) {
|
|
Jeff Moyer |
2c91dc |
err(ctx, "%s: failed to disable\n", devname);
|
|
Jeff Moyer |
2c91dc |
@@ -5420,7 +5341,7 @@ NDCTL_EXPORT int ndctl_btt_enable(struct ndctl_btt *btt)
|
|
Jeff Moyer |
2c91dc |
if (ndctl_btt_is_enabled(btt))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_bind(ctx, btt->module, devname);
|
|
Jeff Moyer |
2c91dc |
+ util_bind(devname, btt->module, "nd", ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
if (!ndctl_btt_is_enabled(btt)) {
|
|
Jeff Moyer |
2c91dc |
err(ctx, "%s: failed to enable\n", devname);
|
|
Jeff Moyer |
2c91dc |
@@ -5457,7 +5378,7 @@ NDCTL_EXPORT int ndctl_btt_delete(struct ndctl_btt *btt)
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_unbind(ctx, btt->btt_path);
|
|
Jeff Moyer |
2c91dc |
+ util_unbind(btt->btt_path, ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
rc = ndctl_btt_set_namespace(btt, NULL);
|
|
Jeff Moyer |
2c91dc |
if (rc) {
|
|
Jeff Moyer |
2c91dc |
@@ -5908,7 +5829,7 @@ NDCTL_EXPORT int ndctl_pfn_enable(struct ndctl_pfn *pfn)
|
|
Jeff Moyer |
2c91dc |
if (ndctl_pfn_is_enabled(pfn))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_bind(ctx, pfn->module, devname);
|
|
Jeff Moyer |
2c91dc |
+ util_bind(devname, pfn->module, "nd", ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
if (!ndctl_pfn_is_enabled(pfn)) {
|
|
Jeff Moyer |
2c91dc |
err(ctx, "%s: failed to enable\n", devname);
|
|
Jeff Moyer |
2c91dc |
@@ -5945,7 +5866,7 @@ NDCTL_EXPORT int ndctl_pfn_delete(struct ndctl_pfn *pfn)
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_unbind(ctx, pfn->pfn_path);
|
|
Jeff Moyer |
2c91dc |
+ util_unbind(pfn->pfn_path, ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
rc = ndctl_pfn_set_namespace(pfn, NULL);
|
|
Jeff Moyer |
2c91dc |
if (rc) {
|
|
Jeff Moyer |
2c91dc |
@@ -6101,7 +6022,7 @@ NDCTL_EXPORT int ndctl_dax_enable(struct ndctl_dax *dax)
|
|
Jeff Moyer |
2c91dc |
if (ndctl_dax_is_enabled(dax))
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_bind(ctx, pfn->module, devname);
|
|
Jeff Moyer |
2c91dc |
+ util_bind(devname, pfn->module, "nd", ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
if (!ndctl_dax_is_enabled(dax)) {
|
|
Jeff Moyer |
2c91dc |
err(ctx, "%s: failed to enable\n", devname);
|
|
Jeff Moyer |
2c91dc |
@@ -6132,7 +6053,7 @@ NDCTL_EXPORT int ndctl_dax_delete(struct ndctl_dax *dax)
|
|
Jeff Moyer |
2c91dc |
return 0;
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
- ndctl_unbind(ctx, pfn->pfn_path);
|
|
Jeff Moyer |
2c91dc |
+ util_unbind(pfn->pfn_path, ctx);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
rc = ndctl_dax_set_namespace(dax, NULL);
|
|
Jeff Moyer |
2c91dc |
if (rc) {
|
|
Jeff Moyer |
2c91dc |
diff --git a/util/sysfs.c b/util/sysfs.c
|
|
Jeff Moyer |
2c91dc |
index 23330cb..968683b 100644
|
|
Jeff Moyer |
2c91dc |
--- a/util/sysfs.c
|
|
Jeff Moyer |
2c91dc |
+++ b/util/sysfs.c
|
|
Jeff Moyer |
2c91dc |
@@ -145,3 +145,79 @@ struct kmod_module *__util_modalias_to_module(struct kmod_ctx *kmod_ctx,
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
return mod;
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+int __util_bind(const char *devname, struct kmod_module *module,
|
|
Jeff Moyer |
2c91dc |
+ const char *bus, struct log_ctx *ctx)
|
|
Jeff Moyer |
2c91dc |
+{
|
|
Jeff Moyer |
2c91dc |
+ DIR *dir;
|
|
Jeff Moyer |
2c91dc |
+ int rc = 0;
|
|
Jeff Moyer |
2c91dc |
+ char path[200];
|
|
Jeff Moyer |
2c91dc |
+ struct dirent *de;
|
|
Jeff Moyer |
2c91dc |
+ const int len = sizeof(path);
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (!devname) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(ctx, "missing devname\n");
|
|
Jeff Moyer |
2c91dc |
+ return -EINVAL;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (module) {
|
|
Jeff Moyer |
2c91dc |
+ rc = kmod_module_probe_insert_module(module,
|
|
Jeff Moyer |
2c91dc |
+ KMOD_PROBE_APPLY_BLACKLIST,
|
|
Jeff Moyer |
2c91dc |
+ NULL, NULL, NULL, NULL);
|
|
Jeff Moyer |
2c91dc |
+ if (rc < 0) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(ctx, "%s: insert failure: %d\n", __func__, rc);
|
|
Jeff Moyer |
2c91dc |
+ return rc;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (snprintf(path, len, "/sys/bus/%s/drivers", bus) >= len) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(ctx, "%s: buffer too small!\n", devname);
|
|
Jeff Moyer |
2c91dc |
+ return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ dir = opendir(path);
|
|
Jeff Moyer |
2c91dc |
+ if (!dir) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(ctx, "%s: opendir(\"%s\") failed\n", devname, path);
|
|
Jeff Moyer |
2c91dc |
+ return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ while ((de = readdir(dir)) != NULL) {
|
|
Jeff Moyer |
2c91dc |
+ char *drv_path;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (de->d_ino == 0)
|
|
Jeff Moyer |
2c91dc |
+ continue;
|
|
Jeff Moyer |
2c91dc |
+ if (de->d_name[0] == '.')
|
|
Jeff Moyer |
2c91dc |
+ continue;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (asprintf(&drv_path, "%s/%s/bind", path, de->d_name) < 0) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(ctx, "%s: path allocation failure\n", devname);
|
|
Jeff Moyer |
2c91dc |
+ continue;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ rc = __sysfs_write_attr_quiet(ctx, drv_path, devname);
|
|
Jeff Moyer |
2c91dc |
+ free(drv_path);
|
|
Jeff Moyer |
2c91dc |
+ if (rc == 0)
|
|
Jeff Moyer |
2c91dc |
+ break;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ closedir(dir);
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (rc) {
|
|
Jeff Moyer |
2c91dc |
+ log_dbg(ctx, "%s: bind failed\n", devname);
|
|
Jeff Moyer |
2c91dc |
+ return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ return 0;
|
|
Jeff Moyer |
2c91dc |
+}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+int __util_unbind(const char *devpath, struct log_ctx *ctx)
|
|
Jeff Moyer |
2c91dc |
+{
|
|
Jeff Moyer |
2c91dc |
+ const char *devname = devpath_to_devname(devpath);
|
|
Jeff Moyer |
2c91dc |
+ char path[200];
|
|
Jeff Moyer |
2c91dc |
+ const int len = sizeof(path);
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (snprintf(path, len, "%s/driver/unbind", devpath) >= len) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(ctx, "%s: buffer too small!\n", devname);
|
|
Jeff Moyer |
2c91dc |
+ return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ return __sysfs_write_attr(ctx, path, devname);
|
|
Jeff Moyer |
2c91dc |
+}
|
|
Jeff Moyer |
2c91dc |
diff --git a/util/sysfs.h b/util/sysfs.h
|
|
Jeff Moyer |
2c91dc |
index bdee4f5..4c95c70 100644
|
|
Jeff Moyer |
2c91dc |
--- a/util/sysfs.h
|
|
Jeff Moyer |
2c91dc |
+++ b/util/sysfs.h
|
|
Jeff Moyer |
2c91dc |
@@ -35,4 +35,12 @@ struct kmod_module *__util_modalias_to_module(struct kmod_ctx *kmod_ctx,
|
|
Jeff Moyer |
2c91dc |
struct log_ctx *log);
|
|
Jeff Moyer |
2c91dc |
#define util_modalias_to_module(ctx, buf) \
|
|
Jeff Moyer |
2c91dc |
__util_modalias_to_module((ctx)->kmod_ctx, buf, &(ctx)->ctx)
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+int __util_bind(const char *devname, struct kmod_module *module, const char *bus,
|
|
Jeff Moyer |
2c91dc |
+ struct log_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
+#define util_bind(n, m, b, c) __util_bind(n, m, b, &(c)->ctx)
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+int __util_unbind(const char *devpath, struct log_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
+#define util_unbind(p, c) __util_unbind(p, &(c)->ctx)
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
#endif /* __UTIL_SYSFS_H__ */
|
|
Jeff Moyer |
2c91dc |
--
|
|
Jeff Moyer |
2c91dc |
2.27.0
|
|
Jeff Moyer |
2c91dc |
|