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