From: Ben Cheatham <Benjamin.Cheatham@amd.com>
To: <nvdimm@lists.linux.dev>
Cc: <linux-cxl@vger.kernel.org>, <alison.schofield@intel.com>,
<dave.jiang@intel.com>, <benjamin.cheatham@amd.com>
Subject: [PATCH v4 1/7] libcxl: Add debugfs path to CXL context
Date: Tue, 9 Dec 2025 11:13:58 -0600 [thread overview]
Message-ID: <20251209171404.64412-2-Benjamin.Cheatham@amd.com> (raw)
In-Reply-To: <20251209171404.64412-1-Benjamin.Cheatham@amd.com>
Find the CXL debugfs mount point and add it to the CXL library context.
This will be used by poison and procotol error library functions to
access the information presented by the filesystem.
Signed-off-by: Ben Cheatham <Benjamin.Cheatham@amd.com>
---
cxl/lib/libcxl.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index cafde1c..3718b76 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -54,6 +54,7 @@ struct cxl_ctx {
struct kmod_ctx *kmod_ctx;
struct daxctl_ctx *daxctl_ctx;
void *private_data;
+ const char *debugfs;
};
static void free_pmem(struct cxl_pmem *pmem)
@@ -240,6 +241,43 @@ CXL_EXPORT void *cxl_get_private_data(struct cxl_ctx *ctx)
return ctx->private_data;
}
+static const char *get_debugfs_dir(void)
+{
+ char *dev, *dir, *type, *debugfs_dir = NULL;
+ char line[PATH_MAX + 256 + 1];
+ FILE *fp;
+
+ fp = fopen("/proc/mounts", "r");
+ if (!fp)
+ return debugfs_dir;
+
+ while (fgets(line, sizeof(line), fp)) {
+ dev = strtok(line, " \t");
+ if (!dev)
+ break;
+
+ dir = strtok(NULL, " \t");
+ if (!dir)
+ break;
+
+ type = strtok(NULL, " \t");
+ if (!type)
+ break;
+
+ if (!strcmp(type, "debugfs")) {
+ debugfs_dir = calloc(strlen(dir) + 1, 1);
+ if (!debugfs_dir)
+ break;
+
+ strcpy(debugfs_dir, dir);
+ break;
+ }
+ }
+
+ fclose(fp);
+ return debugfs_dir;
+}
+
/**
* cxl_new - instantiate a new library context
* @ctx: context to establish
@@ -295,6 +333,7 @@ CXL_EXPORT int cxl_new(struct cxl_ctx **ctx)
c->udev = udev;
c->udev_queue = udev_queue;
c->timeout = 5000;
+ c->debugfs = get_debugfs_dir();
return 0;
@@ -350,6 +389,7 @@ CXL_EXPORT void cxl_unref(struct cxl_ctx *ctx)
kmod_unref(ctx->kmod_ctx);
daxctl_unref(ctx->daxctl_ctx);
info(ctx, "context %p released\n", ctx);
+ free((void *)ctx->debugfs);
free(ctx);
}
--
2.51.1
next prev parent reply other threads:[~2025-12-09 17:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 17:13 [ndctl PATCH v4 0/7] Add error injection support Ben Cheatham
2025-12-09 17:13 ` Ben Cheatham [this message]
2025-12-10 18:19 ` [PATCH v4 1/7] libcxl: Add debugfs path to CXL context Dave Jiang
2025-12-12 16:09 ` Cheatham, Benjamin
2025-12-09 17:13 ` [PATCH v4 2/7] libcxl: Add CXL protocol errors Ben Cheatham
2025-12-10 19:54 ` Dave Jiang
2025-12-12 16:10 ` Cheatham, Benjamin
2025-12-09 17:14 ` [PATCH v4 3/7] libcxl: Add poison injection support Ben Cheatham
2025-12-10 20:06 ` Dave Jiang
2025-12-10 20:09 ` Dave Jiang
2025-12-09 17:14 ` [PATCH v4 4/7] cxl: Add inject-error command Ben Cheatham
2025-12-10 20:10 ` Dave Jiang
2025-12-09 17:14 ` [PATCH v4 5/7] cxl: Add clear-error command Ben Cheatham
2025-12-10 20:11 ` Dave Jiang
2025-12-09 17:14 ` [PATCH v4 6/7] cxl/list: Add injectable errors in output Ben Cheatham
2025-12-10 20:13 ` Dave Jiang
2025-12-09 17:14 ` [PATCH v4 7/7] Documentation: Add docs for inject/clear-error commands Ben Cheatham
2025-12-10 20:15 ` Dave Jiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251209171404.64412-2-Benjamin.Cheatham@amd.com \
--to=benjamin.cheatham@amd.com \
--cc=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox