[ndctl,5/6] ndctl: improve module binding debug
diff mbox

Message ID 20150618000938.13255.85898.stgit@dwillia2-desk3.amr.corp.intel.com
State Accepted
Commit 8a28d1adbd78
Headers show

Commit Message

Dan Williams June 18, 2015, 12:09 a.m. UTC
Given that we need to try every driver on an nvdimm bus the default
error message reporting from sysfs_write_attr() is not very meaningful.
Instead we really care about the case where the bind attempt failed
completely.  Suppress debug messages from sysfs_write_attr() when called
by ndctl_bind().

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 lib/libndctl.c |   22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Patch
diff mbox

diff --git a/lib/libndctl.c b/lib/libndctl.c
index 680adeac3fd2..b45fd56a0e7b 100644
--- a/lib/libndctl.c
+++ b/lib/libndctl.c
@@ -662,7 +662,8 @@  static int sysfs_read_attr(struct ndctl_ctx *ctx, const char *path, char *buf)
 	return 0;
 }
 
-static int sysfs_write_attr(struct ndctl_ctx *ctx, const char *path, const char *buf)
+static int __sysfs_write_attr(struct ndctl_ctx *ctx, const char *path,
+		const char *buf, int quiet)
 {
 	int fd = open(path, O_WRONLY|O_CLOEXEC);
 	int n, len = strlen(buf) + 1;
@@ -674,13 +675,26 @@  static int sysfs_write_attr(struct ndctl_ctx *ctx, const char *path, const char
 	n = write(fd, buf, len);
 	close(fd);
 	if (n < len) {
-		dbg(ctx, "failed to write %s to %s: %s\n", buf, path,
-				strerror(errno));
+		if (!quiet)
+			dbg(ctx, "failed to write %s to %s: %s\n", buf, path,
+					strerror(errno));
 		return -1;
 	}
 	return 0;
 }
 
+static int sysfs_write_attr(struct ndctl_ctx *ctx, const char *path,
+		const char *buf)
+{
+	return __sysfs_write_attr(ctx, path, buf, 0);
+}
+
+static int sysfs_write_attr_quiet(struct ndctl_ctx *ctx, const char *path,
+		const char *buf)
+{
+	return __sysfs_write_attr(ctx, path, buf, 1);
+}
+
 static char *__dev_path(char *type, int major, int minor, int parent)
 {
 	char *path, *dev_path;
@@ -2745,7 +2759,7 @@  static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,
 			continue;
 		}
 
-		rc = sysfs_write_attr(ctx, drv_path, devname);
+		rc = sysfs_write_attr_quiet(ctx, drv_path, devname);
 		free(drv_path);
 		if (rc == 0)
 			break;