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

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