Linux CXL
 help / color / mirror / Atom feed
From: "Cheatham, Benjamin" <benjamin.cheatham@amd.com>
To: Alison Schofield <alison.schofield@intel.com>
Cc: <nvdimm@lists.linux.dev>, <linux-cxl@vger.kernel.org>,
	<dave.jiang@intel.com>
Subject: Re: [PATCH v5 1/7] libcxl: Add debugfs path to CXL context
Date: Wed, 17 Dec 2025 13:55:44 -0600	[thread overview]
Message-ID: <c6b5bf72-116f-47cf-b442-1fe9903c689c@amd.com> (raw)
In-Reply-To: <aUIw5jxb0JHNubOD@aschofie-mobl2.lan>

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 <Benjamin.Cheatham@amd.com>
>> ---
>>  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
> 


  reply	other threads:[~2025-12-18  1:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15 21:36 [ndctl PATCH v5 0/7] Add error injection support Ben Cheatham
2025-12-15 21:36 ` [PATCH v5 1/7] libcxl: Add debugfs path to CXL context Ben Cheatham
2025-12-17  4:26   ` Alison Schofield
2025-12-17 19:55     ` Cheatham, Benjamin [this message]
2025-12-15 21:36 ` [PATCH v5 2/7] libcxl: Add CXL protocol errors Ben Cheatham
2025-12-17  4:31   ` Alison Schofield
2025-12-17 19:55     ` Cheatham, Benjamin
2025-12-19  4:38   ` Alison Schofield
2026-01-05 21:00     ` Cheatham, Benjamin
2025-12-15 21:36 ` [PATCH v5 3/7] libcxl: Add poison injection support Ben Cheatham
2025-12-15 21:36 ` [PATCH v5 4/7] cxl: Add inject-error command Ben Cheatham
2025-12-17  4:36   ` Alison Schofield
2025-12-17 19:56     ` Cheatham, Benjamin
2025-12-15 21:36 ` [PATCH v5 5/7] cxl: Add clear-error command Ben Cheatham
2025-12-17  4:39   ` Alison Schofield
2025-12-17 19:56     ` Cheatham, Benjamin
2025-12-15 21:36 ` [PATCH v5 6/7] cxl/list: Add injectable errors in output Ben Cheatham
2025-12-15 21:36 ` [PATCH v5 7/7] Documentation: Add docs for inject/clear-error commands Ben Cheatham
2025-12-17  4:42   ` Alison Schofield
2025-12-17 19:56     ` Cheatham, Benjamin
2025-12-19  4:52   ` Alison Schofield
2026-01-05 21:13     ` Cheatham, Benjamin
2026-01-06  4:41       ` Alison Schofield
2025-12-17  4:47 ` [ndctl PATCH v5 0/7] Add error injection support Alison Schofield
2025-12-17 19:56   ` Cheatham, Benjamin
2025-12-19  5:08     ` Alison Schofield
2026-01-05 21:14       ` Cheatham, Benjamin
2025-12-17  5:00 ` [ndctl PATCH] cxl/test: use inject and clear cmds in cxl-poison.sh Alison Schofield

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=c6b5bf72-116f-47cf-b442-1fe9903c689c@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