On Mon, Dec 15, 2025 at 03:36:24PM -0600, Ben Cheatham wrote:
> 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 <[email protected]>
> ---
> cxl/lib/libcxl.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
> index cafde1c..71eff6d 100644
> --- a/cxl/lib/libcxl.c
> +++ b/cxl/lib/libcxl.c
> @@ -8,6 +8,7 @@
> #include <stdlib.h>
> #include <dirent.h>
> #include <unistd.h>
> +#include <mntent.h>
> #include <sys/mman.h>
> #include <sys/stat.h>
> #include <sys/types.h>
> @@ -54,6 +55,7 @@ struct cxl_ctx {
> struct kmod_ctx *kmod_ctx;
> struct daxctl_ctx *daxctl_ctx;
> void *private_data;
> + const char *debugfs;
Do you want this const? Later we alloc and eventually free it.
> };
>
> static void free_pmem(struct cxl_pmem *pmem)
> @@ -240,6 +242,28 @@ CXL_EXPORT void *cxl_get_private_data(struct cxl_ctx
> *ctx)
> return ctx->private_data;
> }
>
> +static const char* get_debugfs_dir(void)
drop const above?
> +{
> + char *debugfs_dir = NULL;
> + struct mntent *ent;
> + FILE *mntf;
> +
> + mntf = setmntent("/proc/mounts", "r");
> + if (!mntf)
> + return NULL;
> +
> + while ((ent = getmntent(mntf)) != NULL) {
> + if (!strcmp(ent->mnt_type, "debugfs")) {
include <string.h>
> + debugfs_dir = calloc(strlen(ent->mnt_dir) + 1, 1);
> + strcpy(debugfs_dir, ent->mnt_dir);
perhaps -
debugfs_dir = strdup(ent->mnt_dir);
> + break;
> + }
> + }
> +
> + endmntent(mntf);
> + return debugfs_dir;
> +}
snip