Skip to contentSkip to conversation

cxl/list: remove libtracefs build dependency for --media-errors

PATCH Superseded Alison Schofield 2 participants 3 messages Sep 24, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH 1/1 cxl/list: remove libtracefs build dependency for --media-errors

When the --media-errors option was added to cxl list it inadvertently changed the optional libtracefs requirement into a mandatory one. NDCTL versions 80,81,82 no longer build without libtracefs.

With this change, NDCTL builds with or without libtracefs.

Now, when libtracefs is not enabled, users will see:

	$ cxl list -r region0 --media-errors
	Error: unknown option `media-errors'

The cxl-poison.sh unit test is omitted when libtracefs is disabled.

The man page gets a note:
The media-error option is only available with -Dlibtracefs=enabled.

Fixes d7532bb049e0 ("cxl/list: add --media-errors option to cxl list")
---
 Documentation/cxl/cxl-list.txt |  2 ++
 config.h.meson                 |  2 +-
 cxl/json.c                     | 15 ++++++++++++++-
 cxl/list.c                     |  4 ++++
 test/meson.build               |  9 +++++++--
 5 files changed, 28 insertions(+), 4 deletions(-)
Documentation/cxl/cxl-list.txt +2 -0
index 9a9911e7dd9b..0595638ee054 100644
@@ -425,6 +425,8 @@ OPTIONS
 	"source:" is one of: External, Internal, Injected, Vendor Specific,
 	or Unknown, as defined in CXL Specification v3.1 Table 8-140.
 
+The media-errors option is only available with '-Dlibtracefs=enabled'.
+
 ----
 # cxl list -m mem9 --media-errors -u
 {
config.h.meson +1 -1
index f75db3e6360f..e8539f8d04df 100644
@@ -19,7 +19,7 @@
 /* ndctl test support */
 #mesondefine ENABLE_TEST
 
-/* cxl monitor support */
+/* cxl monitor and cxl list --media-errors support */
 #mesondefine ENABLE_LIBTRACEFS
 
 /* Define to 1 if big-endian-arch */
cxl/json.c +14 -1
index e65bd803b706..a75928bf43ed 100644
@@ -9,12 +9,15 @@
 #include <json-c/json.h>
 #include <json-c/printbuf.h>
 #include <ccan/short_types/short_types.h>
+
+#ifdef ENABLE_LIBTRACEFS
 #include <tracefs.h>
+#include "../util/event_trace.h"
+#endif
 
 #include "filter.h"
 #include "json.h"
 #include "../daxctl/json.h"
-#include "../util/event_trace.h"
 
 #define CXL_FW_VERSION_STR_LEN	16
 #define CXL_FW_MAX_SLOTS	4
@@ -575,6 +578,7 @@ err_jobj:
 	return NULL;
 }
 
+#ifdef ENABLE_LIBTRACEFS
 /* CXL Spec 3.1 Table 8-140 Media Error Record */
 #define CXL_POISON_SOURCE_MAX 7
 static const char *const poison_source[] = { "Unknown", "External", "Internal",
@@ -753,6 +757,15 @@ err_free:
 	tracefs_instance_free(inst);
 	return jpoison;
 }
+#else
+static struct json_object *
+util_cxl_poison_list_to_json(struct cxl_region *region,
+			     struct cxl_memdev *memdev,
+			     unsigned long flags)
+{
+	return NULL;
+}
+#endif
 
 struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
 		unsigned long flags)
cxl/list.c +4 -0
index 0b25d78248d5..d9412ec72375 100644
@@ -57,8 +57,10 @@ static const struct option options[] = {
 		    "include memory device firmware information"),
 	OPT_BOOLEAN('A', "alert-config", &param.alert_config,
 		    "include alert configuration information"),
+#ifdef ENABLE_LIBTRACEFS
 	OPT_BOOLEAN('L', "media-errors", &param.media_errors,
 		    "include media-error information "),
+#endif
 	OPT_INCR('v', "verbose", &param.verbose, "increase output detail"),
 #ifdef ENABLE_DEBUG
 	OPT_BOOLEAN(0, "debug", &debug, "debug list walk"),
@@ -123,7 +125,9 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
 		param.fw = true;
 		param.alert_config = true;
 		param.dax = true;
+#ifdef ENABLE_LIBTRACEFS
 		param.media_errors = true;
+#endif
 		/* fallthrough */
 	case 2:
 		param.idle = true;
test/meson.build +7 -2
index 775542c1b787..615376ea635a 100644
@@ -167,7 +167,6 @@ cxl_events = find_program('cxl-events.sh')
 cxl_sanitize = find_program('cxl-sanitize.sh')
 cxl_destroy_region = find_program('cxl-destroy-region.sh')
 cxl_qos_class = find_program('cxl-qos-class.sh')
-cxl_poison = find_program('cxl-poison.sh')
 
 tests = [
   [ 'libndctl',               libndctl,		  'ndctl' ],
@@ -200,7 +199,6 @@ tests = [
   [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
   [ 'cxl-destroy-region.sh',  cxl_destroy_region, 'cxl'   ],
   [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
-  [ 'cxl-poison.sh',          cxl_poison,         'cxl'   ],
 ]
 
 if get_option('destructive').enabled()
@@ -253,6 +251,13 @@ if get_option('fwctl').enabled()
   ]
 endif
 
+if get_option('libtracefs').enabled()
+  cxl_poison = find_program('cxl-poison.sh')
+  tests += [
+    [ 'cxl-poison.sh', cxl_poison, 'cxl' ],
+  ]
+endif
+
 test_env = [
     'LC_ALL=C',
     'NDCTL=@0@'.format(ndctl_tool.full_path()),
Signature · 1 line
2.37.3
#1 lore raw
Quoted 9 lines · Alison Schofield

When the --media-errors option was added to cxl list it inadvertently changed the optional libtracefs requirement into a mandatory one. NDCTL versions 80,81,82 no longer build without libtracefs.

With this change, NDCTL builds with or without libtracefs.

Now, when libtracefs is not enabled, users will see:

	$ cxl list -r region0 --media-errors
	Error: unknown option `media-errors'

...but it is a known option that is documented. I.e. I would have expected:

  $ cxl list -r region0 --media-errors
  Notice: --media-errors support disabled at build time.
  [
    {
      "region": "region...

Let the command continue because that would also match the behavior of:

  $ cxl list -vvv

...which does not fail when media errors can not be retrieved, and would also make things like:

  $ cxl list -R --media-errors --health

...at least give some useful data and succeed rather than fail and require the script to be re-written to drop the option.

author maintainer
#2 lore raw
Quoted 25 lines · Dan Williams
Quoted 9 lines · Alison Schofield

When the --media-errors option was added to cxl list it inadvertently changed the optional libtracefs requirement into a mandatory one. NDCTL versions 80,81,82 no longer build without libtracefs.

With this change, NDCTL builds with or without libtracefs.

Now, when libtracefs is not enabled, users will see:

	$ cxl list -r region0 --media-errors
	Error: unknown option `media-errors'

...but it is a known option that is documented. I.e. I would have expected:

  $ cxl list -r region0 --media-errors
  Notice: --media-errors support disabled at build time.
  [
    {
      "region": "region...

Let the command continue because that would also match the behavior of:

  $ cxl list -vvv
Quoted 7 lines

...which does not fail when media errors can not be retrieved, and would also make things like:

  $ cxl list -R --media-errors --health

...at least give some useful data and succeed rather than fail and require the script to be re-written to drop the option.

Thanks for the review. I've implemented your suggestions.