On 12/16/2025 10:26 PM, Alison Schofield wrote:
> 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.
I would expect it to only be initialized once, so my initial instinct was to
mark
it const. The actual value it points to isn't const though, so it doesn't make
too much
sense. I'll drop 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?
Yeah, I'll get rid of it.
>
>
>
>> +{
>> + 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>
Sure.
>
>
>> + debugfs_dir = calloc(strlen(ent->mnt_dir) + 1, 1);
>> + strcpy(debugfs_dir, ent->mnt_dir);
>
> perhaps -
> debugfs_dir = strdup(ent->mnt_dir);
>
I forgot about strdup() (I rarely do userspace C). I'll update it.
>
>
>
>> + break;
>> + }
>> + }
>> +
>> + endmntent(mntf);
>> + return debugfs_dir;
>> +}
>
> snip
>