Blame SOURCES/0110-cxl-memdev-Use-a-local-logger-for-debug.patch

2eb93d
From 5e1c1ab5bf6b6257552ad9fa242483ec1c1de006 Mon Sep 17 00:00:00 2001
2eb93d
From: Dan Williams <dan.j.williams@intel.com>
2eb93d
Date: Sun, 23 Jan 2022 16:53:55 -0800
2eb93d
Subject: [PATCH 110/217] cxl/memdev: Use a local logger for debug
2eb93d
2eb93d
The "fail()" macro skips some of the nicer features of the centralized
2eb93d
logger. Add one to supplement the library logger.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/164298563547.3021641.16504008034705274247.stgit@dwillia2-desk3.amr.corp.intel.com
2eb93d
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 cxl/memdev.c | 48 ++++++++++++++++++++++++------------------------
2eb93d
 1 file changed, 24 insertions(+), 24 deletions(-)
2eb93d
2eb93d
diff --git a/cxl/memdev.c b/cxl/memdev.c
2eb93d
index b9141be..327c260 100644
2eb93d
--- a/cxl/memdev.c
2eb93d
+++ b/cxl/memdev.c
2eb93d
@@ -26,11 +26,7 @@ static struct parameters {
2eb93d
 	bool verbose;
2eb93d
 } param;
2eb93d
 
2eb93d
-#define fail(fmt, ...) \
2eb93d
-do { \
2eb93d
-	fprintf(stderr, "cxl-%s:%s:%d: " fmt, \
2eb93d
-			VERSION, __func__, __LINE__, ##__VA_ARGS__); \
2eb93d
-} while (0)
2eb93d
+static struct log_ctx ml;
2eb93d
 
2eb93d
 #define BASE_OPTIONS() \
2eb93d
 OPT_BOOLEAN('v',"verbose", &param.verbose, "turn on debug")
2eb93d
@@ -79,7 +75,7 @@ static int action_zero(struct cxl_memdev *memdev, struct action_context *actx)
2eb93d
 		size = cxl_memdev_get_label_size(memdev);
2eb93d
 
2eb93d
 	if (cxl_memdev_nvdimm_bridge_active(memdev)) {
2eb93d
-		fprintf(stderr,
2eb93d
+		log_err(&ml,
2eb93d
 			"%s: has active nvdimm bridge, abort label write\n",
2eb93d
 			cxl_memdev_get_devname(memdev));
2eb93d
 		return -EBUSY;
2eb93d
@@ -87,7 +83,7 @@ static int action_zero(struct cxl_memdev *memdev, struct action_context *actx)
2eb93d
 
2eb93d
 	rc = cxl_memdev_zero_label(memdev, size, param.offset);
2eb93d
 	if (rc < 0)
2eb93d
-		fprintf(stderr, "%s: label zeroing failed: %s\n",
2eb93d
+		log_err(&ml, "%s: label zeroing failed: %s\n",
2eb93d
 			cxl_memdev_get_devname(memdev), strerror(-rc));
2eb93d
 
2eb93d
 	return rc;
2eb93d
@@ -100,7 +96,7 @@ static int action_write(struct cxl_memdev *memdev, struct action_context *actx)
2eb93d
 	int rc;
2eb93d
 
2eb93d
 	if (cxl_memdev_nvdimm_bridge_active(memdev)) {
2eb93d
-		fprintf(stderr,
2eb93d
+		log_err(&ml,
2eb93d
 			"%s: has active nvdimm bridge, abort label write\n",
2eb93d
 			cxl_memdev_get_devname(memdev));
2eb93d
 		return -EBUSY;
2eb93d
@@ -114,7 +110,7 @@ static int action_write(struct cxl_memdev *memdev, struct action_context *actx)
2eb93d
 		fseek(actx->f_in, 0L, SEEK_SET);
2eb93d
 
2eb93d
 		if (size > label_size) {
2eb93d
-			fprintf(stderr,
2eb93d
+			log_err(&ml,
2eb93d
 				"File size (%zu) greater than label area size (%zu), aborting\n",
2eb93d
 				size, label_size);
2eb93d
 			return -EINVAL;
2eb93d
@@ -133,7 +129,7 @@ static int action_write(struct cxl_memdev *memdev, struct action_context *actx)
2eb93d
 
2eb93d
 	rc = cxl_memdev_write_label(memdev, buf, size, param.offset);
2eb93d
 	if (rc < 0)
2eb93d
-		fprintf(stderr, "%s: label write failed: %s\n",
2eb93d
+		log_err(&ml, "%s: label write failed: %s\n",
2eb93d
 			cxl_memdev_get_devname(memdev), strerror(-rc));
2eb93d
 
2eb93d
 out:
2eb93d
@@ -158,7 +154,7 @@ static int action_read(struct cxl_memdev *memdev, struct action_context *actx)
2eb93d
 
2eb93d
 	rc = cxl_memdev_read_label(memdev, buf, size, param.offset);
2eb93d
 	if (rc < 0) {
2eb93d
-		fprintf(stderr, "%s: label read failed: %s\n",
2eb93d
+		log_err(&ml, "%s: label read failed: %s\n",
2eb93d
 			cxl_memdev_get_devname(memdev), strerror(-rc));
2eb93d
 		goto out;
2eb93d
 	}
2eb93d
@@ -188,6 +184,7 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
2eb93d
 	};
2eb93d
 	unsigned long id;
2eb93d
 
2eb93d
+	log_init(&ml, "cxl memdev", "CXL_MEMDEV_LOG");
2eb93d
 	argc = parse_options(argc, argv, options, u, 0);
2eb93d
 
2eb93d
 	if (argc == 0)
2eb93d
@@ -200,8 +197,8 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
2eb93d
 		}
2eb93d
 
2eb93d
 		if (sscanf(argv[i], "mem%lu", &id) != 1) {
2eb93d
-			fprintf(stderr, "'%s' is not a valid memdev name\n",
2eb93d
-					argv[i]);
2eb93d
+			log_err(&ml, "'%s' is not a valid memdev name\n",
2eb93d
+				argv[i]);
2eb93d
 			err++;
2eb93d
 		}
2eb93d
 	}
2eb93d
@@ -216,8 +213,8 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
2eb93d
 	else {
2eb93d
 		actx.f_out = fopen(param.outfile, "w+");
2eb93d
 		if (!actx.f_out) {
2eb93d
-			fprintf(stderr, "failed to open: %s: (%s)\n",
2eb93d
-					param.outfile, strerror(errno));
2eb93d
+			log_err(&ml, "failed to open: %s: (%s)\n",
2eb93d
+				param.outfile, strerror(errno));
2eb93d
 			rc = -errno;
2eb93d
 			goto out;
2eb93d
 		}
2eb93d
@@ -228,15 +225,18 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
2eb93d
 	} else {
2eb93d
 		actx.f_in = fopen(param.infile, "r");
2eb93d
 		if (!actx.f_in) {
2eb93d
-			fprintf(stderr, "failed to open: %s: (%s)\n",
2eb93d
-					param.infile, strerror(errno));
2eb93d
+			log_err(&ml, "failed to open: %s: (%s)\n", param.infile,
2eb93d
+				strerror(errno));
2eb93d
 			rc = -errno;
2eb93d
 			goto out_close_fout;
2eb93d
 		}
2eb93d
 	}
2eb93d
 
2eb93d
-	if (param.verbose)
2eb93d
+	if (param.verbose) {
2eb93d
 		cxl_set_log_priority(ctx, LOG_DEBUG);
2eb93d
+		ml.log_priority = LOG_DEBUG;
2eb93d
+	} else
2eb93d
+		ml.log_priority = LOG_INFO;
2eb93d
 
2eb93d
 	rc = 0;
2eb93d
 	err = 0;
2eb93d
@@ -299,8 +299,8 @@ int cmd_write_labels(int argc, const char **argv, struct cxl_ctx *ctx)
2eb93d
 	int count = memdev_action(argc, argv, ctx, action_write, write_options,
2eb93d
 			"cxl write-labels <memdev> [-i <filename>]");
2eb93d
 
2eb93d
-	fprintf(stderr, "wrote %d mem%s\n", count >= 0 ? count : 0,
2eb93d
-			count > 1 ? "s" : "");
2eb93d
+	log_info(&ml, "wrote %d mem%s\n", count >= 0 ? count : 0,
2eb93d
+		 count > 1 ? "s" : "");
2eb93d
 	return count >= 0 ? 0 : EXIT_FAILURE;
2eb93d
 }
2eb93d
 
2eb93d
@@ -309,8 +309,8 @@ int cmd_read_labels(int argc, const char **argv, struct cxl_ctx *ctx)
2eb93d
 	int count = memdev_action(argc, argv, ctx, action_read, read_options,
2eb93d
 			"cxl read-labels <mem0> [<mem1>..<memN>] [-o <filename>]");
2eb93d
 
2eb93d
-	fprintf(stderr, "read %d mem%s\n", count >= 0 ? count : 0,
2eb93d
-			count > 1 ? "s" : "");
2eb93d
+	log_info(&ml, "read %d mem%s\n", count >= 0 ? count : 0,
2eb93d
+		 count > 1 ? "s" : "");
2eb93d
 	return count >= 0 ? 0 : EXIT_FAILURE;
2eb93d
 }
2eb93d
 
2eb93d
@@ -319,7 +319,7 @@ int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx)
2eb93d
 	int count = memdev_action(argc, argv, ctx, action_zero, zero_options,
2eb93d
 			"cxl zero-labels <mem0> [<mem1>..<memN>] [<options>]");
2eb93d
 
2eb93d
-	fprintf(stderr, "zeroed %d mem%s\n", count >= 0 ? count : 0,
2eb93d
-			count > 1 ? "s" : "");
2eb93d
+	log_info(&ml, "zeroed %d mem%s\n", count >= 0 ? count : 0,
2eb93d
+		 count > 1 ? "s" : "");
2eb93d
 	return count >= 0 ? 0 : EXIT_FAILURE;
2eb93d
 }
2eb93d
-- 
2eb93d
2.27.0
2eb93d