daxctl: Add support for famfs mode
A message that is not in the archive (sent off-list or not yet received): [email protected]
v5 cover daxctl: Add support for famfs mode
From: John Groves <[email protected]>
This series adds famfs mode support to daxctl, alongside the existing devdax and system-ram modes. A daxdev is in famfs mode when it is bound to fsdev_dax.ko (drivers/dax/fsdev.c).
Patch 1 adds the library plumbing: mode detection helpers, an enable function, and the device.c reconfigure-device wiring. Patch 2 adds a test that exercises mode transitions.
This series depends on the fsdev_dax kernel driver (which provides famfs mode) and on the famfs kernel patch series.
Patches:
1/2 daxctl: Add support for famfs mode
2/2 Add test/daxctl-famfs.sh to test famfs mode transitions
Changes since V4 (addressing Alison and Ira's comments):
- Consolidate the per-mode driver-symlink lookups into a single static helper daxctl_dev_bound_to_module(); the three mode predicates now delegate to it.
- Use PATH_MAX instead of a hardcoded char[200] in the mode-check path.
- Use path_basename() instead of basename().
- Emit a dbg() message when realpath() on the driver symlink returns NULL.
- Revert the json.c change that reported unbound devices as 'unknown'. An unbound device is reported as 'devdax' again, matching the prior behavior; the configured-vs-active distinction Alison raised goes away.
- Add missing fprintf(stderr) "disable failed" messages in the "already in target mode, just re-enable" branches of reconfig_mode_devdax() and reconfig_mode_famfs(), matching the pattern used by the disable_*_device() helpers.
- Reword commit messages: clarify that the test is in a separate patch, drop the stale "json.c shows 'unknown'" line, and replace "Fix mode transition logic" with "Update mode transition logic" since these are extensions for the new mode rather than fixes to broken existing behavior.
John Groves (2):
daxctl: Add support for famfs mode
Add test/daxctl-famfs.sh to test famfs mode transitions:
daxctl/device.c | 132 +++++++++++++++-- daxctl/json.c | 13 +- daxctl/lib/libdaxctl-private.h | 2 + daxctl/lib/libdaxctl.c | 39 ++++- daxctl/lib/libdaxctl.sym | 7 + daxctl/libdaxctl.h | 3 + test/daxctl-famfs.sh | 253 +++++++++++++++++++++++++++++++++ test/meson.build | 2 + 8 files changed, 436 insertions(+), 15 deletions(-) create mode 100755 test/daxctl-famfs.sh
base-commit: 8ad90e54f0ff4f7291e7f21d44d769d10f24e2b6
Signature · 1 line
2.53.0
PATCH v5 1/2 daxctl: Add support for famfs mode
From: John Groves <[email protected]>
Putting a daxdev in famfs mode means binding it to fsdev_dax.ko (drivers/dax/fsdev.c). Finding a daxdev bound to fsdev_dax means it is in famfs mode.
A test for this functionality is added in the next commit.
With devdax, famfs, and system-ram modes, the previous logic that assumed 'not in mode X means in mode Y' needed to get slightly more complicated.
Add explicit mode detection functions:
- daxctl_dev_is_famfs_mode(): check if bound to fsdev_dax driver
- daxctl_dev_is_devdax_mode(): check if bound to device_dax driver Both delegate to a shared static helper daxctl_dev_bound_to_module() to avoid duplicating the driver-symlink lookup, as does the pre-existing daxctl_dev_is_system_ram_capable().
Update mode transition logic in device.c:
- disable_devdax_device(): verify device is actually in devdax mode
- disable_famfs_device(): verify device is actually in famfs mode
- All reconfig_mode_*() functions explicitly check each mode
- Handle unrecognized mode with an error instead of wrong assumption
Update json.c to report fsdev_dax-bound devices as 'famfs' mode. An unbound device continues to be reported as 'devdax' (the legacy default when no driver is bound), to preserve existing behavior.
--- daxctl/device.c | 132 ++++++++++++++++++++++++++++++--- daxctl/json.c | 13 +++- daxctl/lib/libdaxctl-private.h | 2 + daxctl/lib/libdaxctl.c | 39 +++++++++- daxctl/lib/libdaxctl.sym | 7 ++ daxctl/libdaxctl.h | 3 + 6 files changed, 181 insertions(+), 15 deletions(-)
daxctl/device.c +122 -10
@@ -42,6 +42,7 @@ enum dev_mode {DAXCTL_DEV_MODE_UNKNOWN ,DAXCTL_DEV_MODE_DEVDAX ,DAXCTL_DEV_MODE_RAM , + DAXCTL_DEV_MODE_FAMFS, }; struct mapping {
@@ -471,6 +472,13 @@ static const char *parse_device_options(int argc, const char **argv, "--no-online is incompatible with --mode=devdax\n"); rc = -EINVAL ; } + }else if (strcmp (param.mode,"famfs" ) ==0 ) { + reconfig_mode =DAXCTL_DEV_MODE_FAMFS ; +if (param.no_online) { +fprintf (stderr, +"--no-online is incompatible with --mode=famfs\n" ); + rc = -EINVAL ; + } }break ;case ACTION_CREATE :
@@ -696,8 +704,42 @@ static int disable_devdax_device(struct daxctl_dev *dev)int rc;if (mem) { -fprintf (stderr,"%s was already in system-ram mode\n" , - devname); +fprintf (stderr,"%s is in system-ram mode\n" , devname); +return 1 ; + } +if (daxctl_dev_is_famfs_mode (dev)) { +fprintf (stderr,"%s is in famfs mode\n" , devname); +return 1 ; + } +if (!daxctl_dev_is_devdax_mode (dev)) { +fprintf (stderr,"%s is not in devdax mode\n" , devname); +return 1 ; + } + rc =daxctl_dev_disable (dev); +if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , +daxctl_dev_get_devname (dev),strerror (-rc)); +return rc; + } +return 0 ; +} + +static int disable_famfs_device (struct daxctl_dev *dev) +{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev); +int rc; + +if (mem) { +fprintf (stderr,"%s is in system-ram mode\n" , devname); +return 1 ; + } +if (daxctl_dev_is_devdax_mode (dev)) { +fprintf (stderr,"%s is in devdax mode\n" , devname); +return 1 ; + } +if (!daxctl_dev_is_famfs_mode (dev)) { +fprintf (stderr,"%s is not in famfs mode\n" , devname);return 1 ; } rc =daxctl_dev_disable (dev);
@@ -711,6 +753,7 @@ static int disable_devdax_device(struct daxctl_dev *dev)static int reconfig_mode_system_ram (struct daxctl_dev *dev) { +struct daxctl_memory *mem =daxctl_dev_get_memory (dev);const char *devname =daxctl_dev_get_devname (dev);int rc, skip_enable =0 ;
@@ -724,11 +767,21 @@ static int reconfig_mode_system_ram(struct daxctl_dev *dev) }if (daxctl_dev_is_enabled (dev)) { - rc =disable_devdax_device (dev); -if (rc <0 ) -return rc; -if (rc >0 ) +if (mem) { +/* already in system-ram mode */ skip_enable =1 ; + }else if (daxctl_dev_is_famfs_mode (dev)) { + rc =disable_famfs_device (dev); +if (rc) +return rc; + }else if (daxctl_dev_is_devdax_mode (dev)) { + rc =disable_devdax_device (dev); +if (rc) +return rc; + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } }if (!skip_enable) {
@@ -750,7 +803,7 @@ static int disable_system_ram_device(struct daxctl_dev *dev)int rc;if (!mem) { -fprintf (stderr,"%s was already in devdax mode\n" , devname); +fprintf (stderr,"%s is not in system-ram mode\n" , devname);return 1 ; }
@@ -786,12 +839,31 @@ static int disable_system_ram_device(struct daxctl_dev *dev)static int reconfig_mode_devdax (struct daxctl_dev *dev) { +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev);int rc;if (daxctl_dev_is_enabled (dev)) { - rc =disable_system_ram_device (dev); -if (rc) -return rc; +if (mem) { + rc =disable_system_ram_device (dev); +if (rc) +return rc; + }else if (daxctl_dev_is_famfs_mode (dev)) { + rc =disable_famfs_device (dev); +if (rc) +return rc; + }else if (daxctl_dev_is_devdax_mode (dev)) { +/* already in devdax mode, just re-enable */ + rc =daxctl_dev_disable (dev); +if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , + devname,strerror (-rc)); +return rc; + } + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } } rc =daxctl_dev_enable_devdax (dev);
@@ -801,6 +873,43 @@ static int reconfig_mode_devdax(struct daxctl_dev *dev)return 0 ; } +static int reconfig_mode_famfs (struct daxctl_dev *dev) +{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev); +int rc; + +if (daxctl_dev_is_enabled (dev)) { +if (mem) { +fprintf (stderr, +"%s is in system-ram mode; must be in devdax mode to convert to famfs\n" , + devname); +return -EINVAL ; + }else if (daxctl_dev_is_famfs_mode (dev)) { +/* already in famfs mode, just re-enable */ + rc =daxctl_dev_disable (dev); +if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , + devname,strerror (-rc)); +return rc; + } + }else if (daxctl_dev_is_devdax_mode (dev)) { + rc =disable_devdax_device (dev); +if (rc) +return rc; + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } + } + + rc =daxctl_dev_enable_famfs (dev); +if (rc) +return rc; + +return 0 ; +} +static int do_create (struct daxctl_region *region,long long val,struct json_object **jdevs) {
@@ -887,6 +996,9 @@ static int do_reconfig(struct daxctl_dev *dev, enum dev_mode mode,case DAXCTL_DEV_MODE_DEVDAX : rc =reconfig_mode_devdax (dev);break ; +case DAXCTL_DEV_MODE_FAMFS : + rc =reconfig_mode_famfs (dev); +break ;default :fprintf (stderr,"%s: unknown mode requested: %d\n" , devname, mode);
daxctl/json.c +12 -1
@@ -48,8 +48,19 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,if (mem) jobj =json_object_new_string ("system-ram" ); -else +else if (daxctl_dev_is_famfs_mode (dev)) + jobj =json_object_new_string ("famfs" ); +else if (daxctl_dev_is_devdax_mode (dev)) jobj =json_object_new_string ("devdax" ); +else { +/* Legacy condition; if a daxdev is not in any "mode", that +* means no driver is bound. We report that as a disabled +* device in devdax mode. (the disabled modifier is added later +* in this function if applicable) +*/ + jobj =json_object_new_string ("devdax" ); + } +if (jobj)json_object_object_add (jdev,"mode" , jobj);
daxctl/lib/libdaxctl-private.h +2 -0
@@ -21,12 +21,14 @@ static const char *dax_subsystems[] = {enum daxctl_dev_mode {DAXCTL_DEV_MODE_DEVDAX =0 ,DAXCTL_DEV_MODE_RAM , +DAXCTL_DEV_MODE_FAMFS ,DAXCTL_DEV_MODE_END , };static const char *dax_modules[] = { [DAXCTL_DEV_MODE_DEVDAX ] ="device_dax" , [DAXCTL_DEV_MODE_RAM ] ="kmem" , + [DAXCTL_DEV_MODE_FAMFS ] ="fsdev_dax" , };enum memory_op {
daxctl/lib/libdaxctl.c +35 -4
@@ -385,13 +385,13 @@ static bool device_model_is_dax_bus(struct daxctl_dev *dev)return false; } -DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) +static int daxctl_dev_bound_to_module (struct daxctl_dev *dev,const char *mod_name) {const char *devname =daxctl_dev_get_devname (dev);struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev);const char *mod_base;char *mod_path; -char path[200 ]; +char path[PATH_MAX ];const int len =sizeof (path);if (!device_model_is_dax_bus (dev))
@@ -406,11 +406,13 @@ DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) } mod_path =realpath (path,NULL ); -if (!mod_path) +if (!mod_path) { +dbg (ctx,"%s: realpath failed for driver link\n" , devname);return false; + } mod_base =path_basename (mod_path); -if (strcmp (mod_base, dax_modules[DAXCTL_DEV_MODE_RAM ]) ==0 ) { +if (strcmp (mod_base, mod_name) ==0 ) {free (mod_path);return true; }
@@ -419,6 +421,30 @@ DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev)return false; } +DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_RAM ]); +} + +/* +* Check if device is currently in famfs mode (bound to fsdev_dax driver). +* Returns false for disabled devices: the DAX bus does not retain the previous +* driver binding after unbind, so mode cannot be determined without a driver. +*/ +DAXCTL_EXPORT int daxctl_dev_is_famfs_mode(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_FAMFS ]); +} + +/* +* Check if device is currently in devdax mode (bound to device_dax driver). +* Returns false for disabled devices; see daxctl_dev_is_famfs_mode(). +*/ +DAXCTL_EXPORT int daxctl_dev_is_devdax_mode(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_DEVDAX ]); +} +/* * This checks for the device to be in system-ram mode, so calling * daxctl_dev_get_memory() on a devdax mode device will always return NULL.
@@ -983,6 +1009,11 @@ DAXCTL_EXPORT int daxctl_dev_enable_ram(struct daxctl_dev *dev)return daxctl_dev_enable (dev,DAXCTL_DEV_MODE_RAM ); } +DAXCTL_EXPORT int daxctl_dev_enable_famfs(struct daxctl_dev *dev) +{ +return daxctl_dev_enable (dev,DAXCTL_DEV_MODE_FAMFS ); +} + DAXCTL_EXPORT int daxctl_dev_disable(struct daxctl_dev *dev) {const char *devname =daxctl_dev_get_devname (dev);
daxctl/lib/libdaxctl.sym +7 -0
@@ -104,3 +104,10 @@ LIBDAXCTL_10 { global: daxctl_dev_is_system_ram_capable; } LIBDAXCTL_9; + +LIBDAXCTL_11 { +global: + daxctl_dev_enable_famfs; + daxctl_dev_is_famfs_mode; + daxctl_dev_is_devdax_mode; +} LIBDAXCTL_10;
daxctl/libdaxctl.h +3 -0
@@ -72,12 +72,15 @@ int daxctl_dev_is_enabled(struct daxctl_dev *dev);int daxctl_dev_disable (struct daxctl_dev *dev);int daxctl_dev_enable_devdax (struct daxctl_dev *dev);int daxctl_dev_enable_ram (struct daxctl_dev *dev); +int daxctl_dev_enable_famfs (struct daxctl_dev *dev);int daxctl_dev_get_target_node (struct daxctl_dev *dev);int daxctl_dev_will_auto_online_memory (struct daxctl_dev *dev);int daxctl_dev_has_online_memory (struct daxctl_dev *dev);struct daxctl_memory ;int daxctl_dev_is_system_ram_capable (struct daxctl_dev *dev); +int daxctl_dev_is_famfs_mode (struct daxctl_dev *dev); +int daxctl_dev_is_devdax_mode (struct daxctl_dev *dev);struct daxctl_memory *daxctl_dev_get_memory (struct daxctl_dev *dev);struct daxctl_dev *daxctl_memory_get_dev (struct daxctl_memory *mem);const char *daxctl_memory_get_node_path (struct daxctl_memory *mem);
Signature · 1 line
2.53.0
Quoted 24 lines · John Groves
From: John Groves <[email protected]>
Putting a daxdev in famfs mode means binding it to fsdev_dax.ko (
drivers/dax/fsdev.c). Finding a daxdev bound tofsdev_daxmeans it is in famfs mode.A test for this functionality is added in the next commit.
With devdax, famfs, and system-ram modes, the previous logic that assumed 'not in mode X means in mode Y' needed to get slightly more complicated.
Add explicit mode detection functions:
-daxctl_dev_is_famfs_mode(): check if bound tofsdev_daxdriver
-daxctl_dev_is_devdax_mode(): check if bound todevice_daxdriver Both delegate to a shared static helperdaxctl_dev_bound_to_module()to avoid duplicating the driver-symlink lookup, as does the pre-existingdaxctl_dev_is_system_ram_capable().Update mode transition logic in
device.c:
-disable_devdax_device(): verify device is actually in devdax mode
-disable_famfs_device(): verify device is actually in famfs mode
- All reconfig_mode_*() functions explicitly check each mode
- Handle unrecognized mode with an error instead of wrong assumption
Quoted 5 lines
Update
json.cto report fsdev_dax-bound devices as 'famfs' mode. An unbound device continues to be reported as 'devdax' (the legacy default when no driver is bound), to preserve existing behavior.Signed-off-by John Groves <[email protected]>
Quoted 370 lines
--- daxctl/device.c | 132 ++++++++++++++++++++++++++++++--- daxctl/json.c | 13 +++- daxctl/lib/libdaxctl-private.h | 2 + daxctl/lib/libdaxctl.c | 39 +++++++++- daxctl/lib/libdaxctl.sym | 7 ++ daxctl/libdaxctl.h | 3 + 6 files changed, 181 insertions(+), 15 deletions(-)daxctl/device.c +122
-10@@ -42,6 +42,7 @@ enum dev_mode {DAXCTL_DEV_MODE_UNKNOWN ,DAXCTL_DEV_MODE_DEVDAX ,DAXCTL_DEV_MODE_RAM , + DAXCTL_DEV_MODE_FAMFS, }; struct mapping {@@ -471,6 +472,13 @@ static const char *parse_device_options(int argc, const char **argv, "--no-online is incompatible with --mode=devdax\n"); rc = -EINVAL ; } + }else if (strcmp (param.mode,"famfs" ) ==0 ) { + reconfig_mode =DAXCTL_DEV_MODE_FAMFS ; +if (param.no_online) { +fprintf (stderr, +"--no-online is incompatible with --mode=famfs\n" ); + rc = -EINVAL ; + } }break ;case ACTION_CREATE :@@ -696,8 +704,42 @@ static int disable_devdax_device(struct daxctl_dev *dev)int rc;if (mem) { -fprintf (stderr,"%s was already in system-ram mode\n" , - devname); +fprintf (stderr,"%s is in system-ram mode\n" , devname); +return 1 ; + } +if (daxctl_dev_is_famfs_mode (dev)) { +fprintf (stderr,"%s is in famfs mode\n" , devname); +return 1 ; + } +if (!daxctl_dev_is_devdax_mode (dev)) { +fprintf (stderr,"%s is not in devdax mode\n" , devname); +return 1 ; + } + rc =daxctl_dev_disable (dev); +if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , +daxctl_dev_get_devname (dev),strerror (-rc)); +return rc; + } +return 0 ; +} + +static int disable_famfs_device (struct daxctl_dev *dev) +{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev); +int rc; + +if (mem) { +fprintf (stderr,"%s is in system-ram mode\n" , devname); +return 1 ; + } +if (daxctl_dev_is_devdax_mode (dev)) { +fprintf (stderr,"%s is in devdax mode\n" , devname); +return 1 ; + } +if (!daxctl_dev_is_famfs_mode (dev)) { +fprintf (stderr,"%s is not in famfs mode\n" , devname);return 1 ; } rc =daxctl_dev_disable (dev);@@ -711,6 +753,7 @@ static int disable_devdax_device(struct daxctl_dev *dev)static int reconfig_mode_system_ram (struct daxctl_dev *dev) { +struct daxctl_memory *mem =daxctl_dev_get_memory (dev);const char *devname =daxctl_dev_get_devname (dev);int rc, skip_enable =0 ;@@ -724,11 +767,21 @@ static int reconfig_mode_system_ram(struct daxctl_dev *dev) }if (daxctl_dev_is_enabled (dev)) { - rc =disable_devdax_device (dev); -if (rc <0 ) -return rc; -if (rc >0 ) +if (mem) { +/* already in system-ram mode */ skip_enable =1 ; + }else if (daxctl_dev_is_famfs_mode (dev)) { + rc =disable_famfs_device (dev); +if (rc) +return rc; + }else if (daxctl_dev_is_devdax_mode (dev)) { + rc =disable_devdax_device (dev); +if (rc) +return rc; + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } }if (!skip_enable) {@@ -750,7 +803,7 @@ static int disable_system_ram_device(struct daxctl_dev *dev)int rc;if (!mem) { -fprintf (stderr,"%s was already in devdax mode\n" , devname); +fprintf (stderr,"%s is not in system-ram mode\n" , devname);return 1 ; }@@ -786,12 +839,31 @@ static int disable_system_ram_device(struct daxctl_dev *dev)static int reconfig_mode_devdax (struct daxctl_dev *dev) { +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev);int rc;if (daxctl_dev_is_enabled (dev)) { - rc =disable_system_ram_device (dev); -if (rc) -return rc; +if (mem) { + rc =disable_system_ram_device (dev); +if (rc) +return rc; + }else if (daxctl_dev_is_famfs_mode (dev)) { + rc =disable_famfs_device (dev); +if (rc) +return rc; + }else if (daxctl_dev_is_devdax_mode (dev)) { +/* already in devdax mode, just re-enable */ + rc =daxctl_dev_disable (dev); +if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , + devname,strerror (-rc)); +return rc; + } + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } } rc =daxctl_dev_enable_devdax (dev);@@ -801,6 +873,43 @@ static int reconfig_mode_devdax(struct daxctl_dev *dev)return 0 ; } +static int reconfig_mode_famfs (struct daxctl_dev *dev) +{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev); +int rc; + +if (daxctl_dev_is_enabled (dev)) { +if (mem) { +fprintf (stderr, +"%s is in system-ram mode; must be in devdax mode to convert to famfs\n" , + devname); +return -EINVAL ; + }else if (daxctl_dev_is_famfs_mode (dev)) { +/* already in famfs mode, just re-enable */ + rc =daxctl_dev_disable (dev); +if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , + devname,strerror (-rc)); +return rc; + } + }else if (daxctl_dev_is_devdax_mode (dev)) { + rc =disable_devdax_device (dev); +if (rc) +return rc; + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } + } + + rc =daxctl_dev_enable_famfs (dev); +if (rc) +return rc; + +return 0 ; +} +static int do_create (struct daxctl_region *region,long long val,struct json_object **jdevs) {@@ -887,6 +996,9 @@ static int do_reconfig(struct daxctl_dev *dev, enum dev_mode mode,case DAXCTL_DEV_MODE_DEVDAX : rc =reconfig_mode_devdax (dev);break ; +case DAXCTL_DEV_MODE_FAMFS : + rc =reconfig_mode_famfs (dev); +break ;default :fprintf (stderr,"%s: unknown mode requested: %d\n" , devname, mode);daxctl/json.c +12
-1@@ -48,8 +48,19 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,if (mem) jobj =json_object_new_string ("system-ram" ); -else +else if (daxctl_dev_is_famfs_mode (dev)) + jobj =json_object_new_string ("famfs" ); +else if (daxctl_dev_is_devdax_mode (dev)) jobj =json_object_new_string ("devdax" ); +else { +/* Legacy condition; if a daxdev is not in any "mode", that +* means no driver is bound. We report that as a disabled +* device in devdax mode. (the disabled modifier is added later +* in this function if applicable) +*/ + jobj =json_object_new_string ("devdax" ); + } +if (jobj)json_object_object_add (jdev,"mode" , jobj);daxctl/lib/libdaxctl-private.h +2
-0@@ -21,12 +21,14 @@ static const char *dax_subsystems[] = {enum daxctl_dev_mode {DAXCTL_DEV_MODE_DEVDAX =0 ,DAXCTL_DEV_MODE_RAM , +DAXCTL_DEV_MODE_FAMFS ,DAXCTL_DEV_MODE_END , };static const char *dax_modules[] = { [DAXCTL_DEV_MODE_DEVDAX ] ="device_dax" , [DAXCTL_DEV_MODE_RAM ] ="kmem" , + [DAXCTL_DEV_MODE_FAMFS ] ="fsdev_dax" , };enum memory_op {daxctl/lib/libdaxctl.c +35
-4@@ -385,13 +385,13 @@ static bool device_model_is_dax_bus(struct daxctl_dev *dev)return false; } -DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) +static int daxctl_dev_bound_to_module (struct daxctl_dev *dev,const char *mod_name) {const char *devname =daxctl_dev_get_devname (dev);struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev);const char *mod_base;char *mod_path; -char path[200 ]; +char path[PATH_MAX ];const int len =sizeof (path);if (!device_model_is_dax_bus (dev))@@ -406,11 +406,13 @@ DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) } mod_path =realpath (path,NULL ); -if (!mod_path) +if (!mod_path) { +dbg (ctx,"%s: realpath failed for driver link\n" , devname);return false; + } mod_base =path_basename (mod_path); -if (strcmp (mod_base, dax_modules[DAXCTL_DEV_MODE_RAM ]) ==0 ) { +if (strcmp (mod_base, mod_name) ==0 ) {free (mod_path);return true; }@@ -419,6 +421,30 @@ DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev)return false; } +DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_RAM ]); +} + +/* +* Check if device is currently in famfs mode (bound to fsdev_dax driver). +* Returns false for disabled devices: the DAX bus does not retain the previous +* driver binding after unbind, so mode cannot be determined without a driver. +*/ +DAXCTL_EXPORT int daxctl_dev_is_famfs_mode(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_FAMFS ]); +} + +/* +* Check if device is currently in devdax mode (bound to device_dax driver). +* Returns false for disabled devices; see daxctl_dev_is_famfs_mode(). +*/ +DAXCTL_EXPORT int daxctl_dev_is_devdax_mode(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_DEVDAX ]); +} +/* * This checks for the device to be in system-ram mode, so calling * daxctl_dev_get_memory() on a devdax mode device will always return NULL. @@ -983,6 +1009,11 @@ DAXCTL_EXPORT int daxctl_dev_enable_ram(struct daxctl_dev *dev)return daxctl_dev_enable (dev,DAXCTL_DEV_MODE_RAM ); } +DAXCTL_EXPORT int daxctl_dev_enable_famfs(struct daxctl_dev *dev) +{ +return daxctl_dev_enable (dev,DAXCTL_DEV_MODE_FAMFS ); +} + DAXCTL_EXPORT int daxctl_dev_disable(struct daxctl_dev *dev) {const char *devname =daxctl_dev_get_devname (dev);daxctl/lib/libdaxctl.sym +7
-0@@ -104,3 +104,10 @@ LIBDAXCTL_10 { global: daxctl_dev_is_system_ram_capable; } LIBDAXCTL_9; + +LIBDAXCTL_11 { +global: + daxctl_dev_enable_famfs; + daxctl_dev_is_famfs_mode; + daxctl_dev_is_devdax_mode; +} LIBDAXCTL_10;daxctl/libdaxctl.h +3
-0@@ -72,12 +72,15 @@ int daxctl_dev_is_enabled(struct daxctl_dev *dev);int daxctl_dev_disable (struct daxctl_dev *dev);int daxctl_dev_enable_devdax (struct daxctl_dev *dev);int daxctl_dev_enable_ram (struct daxctl_dev *dev); +int daxctl_dev_enable_famfs (struct daxctl_dev *dev);int daxctl_dev_get_target_node (struct daxctl_dev *dev);int daxctl_dev_will_auto_online_memory (struct daxctl_dev *dev);int daxctl_dev_has_online_memory (struct daxctl_dev *dev);struct daxctl_memory ;int daxctl_dev_is_system_ram_capable (struct daxctl_dev *dev); +int daxctl_dev_is_famfs_mode (struct daxctl_dev *dev); +int daxctl_dev_is_devdax_mode (struct daxctl_dev *dev);struct daxctl_memory *daxctl_dev_get_memory (struct daxctl_dev *dev);struct daxctl_dev *daxctl_memory_get_dev (struct daxctl_memory *mem);const char *daxctl_memory_get_node_path (struct daxctl_memory *mem);
Alison Schofield
maintainerQuoted 1 line · John Groves
From: John Groves <[email protected]>
Hi John,
Please add an intro paragraph saying what famfs is, preferably with links to reference material.
This patch doesn't update any docs. Please take a look at what is needed. I think at least this one:Documentation/daxctl/daxctl-reconfigure-device.txt needs to add famfs as a 'mode' option.
Quoted 41 lines
Putting a daxdev in famfs mode means binding it to fsdev_dax.ko (
drivers/dax/fsdev.c). Finding a daxdev bound tofsdev_daxmeans it is in famfs mode.A test for this functionality is added in the next commit.
With devdax, famfs, and system-ram modes, the previous logic that assumed 'not in mode X means in mode Y' needed to get slightly more complicated.
Add explicit mode detection functions:
-daxctl_dev_is_famfs_mode(): check if bound tofsdev_daxdriver
-daxctl_dev_is_devdax_mode(): check if bound todevice_daxdriver Both delegate to a shared static helperdaxctl_dev_bound_to_module()to avoid duplicating the driver-symlink lookup, as does the pre-existingdaxctl_dev_is_system_ram_capable().Update mode transition logic in
device.c:
-disable_devdax_device(): verify device is actually in devdax mode
-disable_famfs_device(): verify device is actually in famfs mode
- All reconfig_mode_*() functions explicitly check each mode
- Handle unrecognized mode with an error instead of wrong assumptionUpdate
json.cto report fsdev_dax-bound devices as 'famfs' mode. An unbound device continues to be reported as 'devdax' (the legacy default when no driver is bound), to preserve existing behavior.Signed-off-by John Groves <[email protected]>--- daxctl/device.c | 132 +++++++++++++++++++++++++++++++++++++---- daxctl/json.c | 13 +++- daxctl/lib/libdaxctl-private.h | 2 + daxctl/lib/libdaxctl.c | 39 ++++++++++-- daxctl/lib/libdaxctl.sym | 7 +++ daxctl/libdaxctl.h | 3 + 6 files changed, 181 insertions(+), 15 deletions(-)daxctl/device.c +0
-0
daxctl/device.c enum dev_mode { · line 46
Quoted 5 lines
daxctl/device.c +1
-0@@ -42,6 +42,7 @@ enum dev_mode {DAXCTL_DEV_MODE_UNKNOWN ,DAXCTL_DEV_MODE_DEVDAX ,DAXCTL_DEV_MODE_RAM , + DAXCTL_DEV_MODE_FAMFS, };
The above enum dev_mode in device.c shares enum names with enum daxctl_dev_mode later in this patch (in libdaxctl-private.h) but assigns different numeric values. The overlap predates this patch, so not something you introduced, but adding FAMFS to both is a good moment to fix it before it gets more entrenched.
Two enums with identical member names but different values is confusing and risks silent cross-assignment bugs with no compiler warning.
Suggest renaming this local enum to enum reconfig_mode with members RECONFIG_MODE_{UNKNOWN,DEVDAX,RAM,FAMFS}. That confines it to the reconfig path. Then the library enum gets unambiguous ownership of DAXCTL_DEV_MODE_*. After that accidental cross-assignments are obvious type mismatches rather than a silent wrong-value bug.
daxctl/device.c static const char *parse_device_options(int argc, const char **argv, · line 480
Quoted 13 lines
daxctl/device.c +6
-0struct mapping {unsigned long long start, end, pgoff;@@ -471,6 +472,13 @@ static const char *parse_device_options(int argc, const char **argv, "--no-online is incompatible with --mode=devdax\n"); rc = -EINVAL ; } + }else if (strcmp (param.mode,"famfs" ) ==0 ) { + reconfig_mode =DAXCTL_DEV_MODE_FAMFS ; +if (param.no_online) { +fprintf (stderr, +"--no-online is incompatible with --mode=famfs\n" ); + rc = -EINVAL ;
rm extra whitespace after =
Quoted 39 lines
daxctl/device.c +30
-2+ } }break ;case ACTION_CREATE :@@ -696,8 +704,42 @@ static int disable_devdax_device(struct daxctl_dev *dev)int rc;if (mem) { -fprintf (stderr,"%s was already in system-ram mode\n" , - devname); +fprintf (stderr,"%s is in system-ram mode\n" , devname); +return 1 ; + } +if (daxctl_dev_is_famfs_mode (dev)) { +fprintf (stderr,"%s is in famfs mode\n" , devname); +return 1 ; + } +if (!daxctl_dev_is_devdax_mode (dev)) { +fprintf (stderr,"%s is not in devdax mode\n" , devname); +return 1 ; + } + rc =daxctl_dev_disable (dev); +if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , +daxctl_dev_get_devname (dev),strerror (-rc)); +return rc; + } +return 0 ; +} + +static int disable_famfs_device (struct daxctl_dev *dev) +{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev); +int rc; + +if (mem) { +fprintf (stderr,"%s is in system-ram mode\n" , devname); +return 1 ;
daxctl/device.c static int disable_devdax_device(struct daxctl_dev *dev) · line 745
Quoted 10 lines
daxctl/device.c +7
-0+ } +if (daxctl_dev_is_devdax_mode (dev)) { +fprintf (stderr,"%s is in devdax mode\n" , devname); +return 1 ; + } +if (!daxctl_dev_is_famfs_mode (dev)) { +fprintf (stderr,"%s is not in famfs mode\n" , devname);return 1 ; } rc =daxctl_dev_disable (dev);
disable_devdax_device() and disable_famfs_device() differ only in which mode they accept vs. reject. With reconfig_mode_* switching on daxctl_dev_get_mode() first, the caller already knows the mode, so the internal mode-sanity checks are redundant.
What's left in each function is daxctl_dev_disable() and an error fprintf, the same code in both, so collapse to a single helper:
static int disable_mode_device(struct daxctl_dev *dev);
No mode parameter: the precondition (caller has matched the mode) means nothing mode-specific remains.
Quoted 22 lines
daxctl/device.c +6
-4@@ -711,6 +753,7 @@ static int disable_devdax_device(struct daxctl_dev *dev)static int reconfig_mode_system_ram (struct daxctl_dev *dev) { +struct daxctl_memory *mem =daxctl_dev_get_memory (dev);const char *devname =daxctl_dev_get_devname (dev);int rc, skip_enable =0 ;@@ -724,11 +767,21 @@ static int reconfig_mode_system_ram(struct daxctl_dev *dev) }if (daxctl_dev_is_enabled (dev)) { - rc =disable_devdax_device (dev); -if (rc <0 ) -return rc; -if (rc >0 ) +if (mem) { +/* already in system-ram mode */ skip_enable =1 ; + }else if (daxctl_dev_is_famfs_mode (dev)) { + rc =disable_famfs_device (dev); +if (rc)
daxctl/device.c static int reconfig_mode_system_ram(struct daxctl_dev *dev) · line 785
Quoted 10 lines
daxctl/device.c +9
-0+return rc; + }else if (daxctl_dev_is_devdax_mode (dev)) { + rc =disable_devdax_device (dev); +if (rc) +return rc; + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } }
This if-else chain is repeated in all three reconfig_mode_*() functions below. Please add a private helper and switch on the result. Something like:
static enum daxctl_dev_mode daxctl_dev_get_mode(struct daxctl_dev *dev)
{
if (daxctl_dev_get_memory(dev))
return DAXCTL_DEV_MODE_RAM;
if (daxctl_dev_is_famfs_mode(dev))
return DAXCTL_DEV_MODE_FAMFS;
if (daxctl_dev_is_devdax_mode(dev))
return DAXCTL_DEV_MODE_DEVDAX;
return DAXCTL_DEV_MODE_UNKNOWN;
}Then each reconfig_mode_* becomes a switch on the current mode. The precedence (system-ram first because it's detected via mem rather than driver binding) lives in one place instead of three.
Quoted 32 lines
daxctl/device.c +14
-4@@ -750,7 +803,7 @@ static int disable_system_ram_device(struct daxctl_dev *dev)int rc;if (!mem) { -fprintf (stderr,"%s was already in devdax mode\n" , devname); +fprintf (stderr,"%s is not in system-ram mode\n" , devname);return 1 ; }@@ -786,12 +839,31 @@ static int disable_system_ram_device(struct daxctl_dev *dev)static int reconfig_mode_devdax (struct daxctl_dev *dev) { +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev);int rc;if (daxctl_dev_is_enabled (dev)) { - rc =disable_system_ram_device (dev); -if (rc) -return rc; +if (mem) { + rc =disable_system_ram_device (dev); +if (rc) +return rc; + }else if (daxctl_dev_is_famfs_mode (dev)) { + rc =disable_famfs_device (dev); +if (rc) +return rc; + }else if (daxctl_dev_is_devdax_mode (dev)) { +/* already in devdax mode, just re-enable */ + rc =daxctl_dev_disable (dev);
daxctl/device.c static int disable_system_ram_device(struct daxctl_dev *dev) · line 867
Quoted 10 lines
daxctl/device.c +9
-0+if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , + devname,strerror (-rc)); +return rc; + } + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } }
Same if-else chain, second copy. See the helper suggestion above.
Quoted 24 lines
daxctl/device.c +19
-0rc =daxctl_dev_enable_devdax (dev);@@ -801,6 +873,43 @@ static int reconfig_mode_devdax(struct daxctl_dev *dev)return 0 ; } +static int reconfig_mode_famfs (struct daxctl_dev *dev) +{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev); +int rc; + +if (daxctl_dev_is_enabled (dev)) { +if (mem) { +fprintf (stderr, +"%s is in system-ram mode; must be in devdax mode to convert to famfs\n" , + devname); +return -EINVAL ; + }else if (daxctl_dev_is_famfs_mode (dev)) { +/* already in famfs mode, just re-enable */ + rc =daxctl_dev_disable (dev); +if (rc) { +fprintf (stderr,"%s: disable failed: %s\n" , + devname,strerror (-rc)); +return rc;
daxctl/device.c static int reconfig_mode_devdax(struct daxctl_dev *dev) · line 904
Quoted 10 lines
daxctl/device.c +10
-0+ } + }else if (daxctl_dev_is_devdax_mode (dev)) { + rc =disable_devdax_device (dev); +if (rc) +return rc; + }else { +fprintf (stderr,"%s: unknown mode\n" , devname); +return -EINVAL ; + } + }
Same if-else chain, third copy.
Quoted 26 lines
daxctl/device.c +11
-0+ + rc =daxctl_dev_enable_famfs (dev); +if (rc) +return rc; + +return 0 ; +} +static int do_create (struct daxctl_region *region,long long val,struct json_object **jdevs) {@@ -887,6 +996,9 @@ static int do_reconfig(struct daxctl_dev *dev, enum dev_mode mode,case DAXCTL_DEV_MODE_DEVDAX : rc =reconfig_mode_devdax (dev);break ; +case DAXCTL_DEV_MODE_FAMFS : + rc =reconfig_mode_famfs (dev); +break ;default :fprintf (stderr,"%s: unknown mode requested: %d\n" , devname, mode);daxctl/json.c +0
-0
daxctl/json.c struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, · line 54
Quoted 8 lines
daxctl/json.c +3
-1@@ -48,8 +48,19 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,if (mem) jobj =json_object_new_string ("system-ram" ); -else +else if (daxctl_dev_is_famfs_mode (dev)) + jobj =json_object_new_string ("famfs" ); +else if (daxctl_dev_is_devdax_mode (dev)) jobj =json_object_new_string ("devdax" );
The 'else if' above, and the 'else' below, both assign "devdax", so the 'else if' is redundant. And once daxctl_dev_get_mode() exists, this becomes a switch on the result with "devdax" as the UNKNOWN fallback.
Quoted 19 lines
daxctl/json.c +9
-0+else { +/* Legacy condition; if a daxdev is not in any "mode", that +* means no driver is bound. We report that as a disabled +* device in devdax mode. (the disabled modifier is added later +* in this function if applicable) +*/ + jobj =json_object_new_string ("devdax" ); + } +if (jobj)json_object_object_add (jdev,"mode" , jobj);daxctl/lib/libdaxctl-private.h +0
-0@@ -21,12 +21,14 @@ static const char *dax_subsystems[] = {enum daxctl_dev_mode {DAXCTL_DEV_MODE_DEVDAX =0 ,
daxctl/lib/libdaxctl-private.h static const char *dax_subsystems[] = { · line 32
Quoted 10 lines
daxctl/lib/libdaxctl-private.h +2
-0DAXCTL_DEV_MODE_RAM , +DAXCTL_DEV_MODE_FAMFS , DAXCTL_DEV_MODE_END, };static const char *dax_modules[] = { [DAXCTL_DEV_MODE_DEVDAX ] ="device_dax" , [DAXCTL_DEV_MODE_RAM ] ="kmem" , + [DAXCTL_DEV_MODE_FAMFS ] ="fsdev_dax" , };
Add a DAXCTL_DEV_MODE_UNKNOWN sentinel here to support the daxctl_dev_get_mode() helper cleanly. Doesn't have to be assigned a value, can reuse END or add it alongside, your call.
Quoted 11 lines
daxctl/lib/libdaxctl-private.h +0
-0enum memory_op {daxctl/lib/libdaxctl.c +1
-1@@ -385,13 +385,13 @@ static bool device_model_is_dax_bus(struct daxctl_dev *dev)return false; } -DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) +static int daxctl_dev_bound_to_module (struct daxctl_dev *dev,const char *mod_name)
daxctl/lib/libdaxctl.c static bool device_model_is_dax_bus(struct daxctl_dev *dev) · line 397
Quoted 10 lines
daxctl/lib/libdaxctl.c +1
-1{const char *devname =daxctl_dev_get_devname (dev);struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev);const char *mod_base;char *mod_path; -char path[200 ]; +char path[PATH_MAX ];const int len =sizeof (path);if (!device_model_is_dax_bus (dev))
Nice!
Quoted 17 lines
daxctl/lib/libdaxctl.c +4
-2@@ -406,11 +406,13 @@ DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) } mod_path =realpath (path,NULL ); -if (!mod_path) +if (!mod_path) { +dbg (ctx,"%s: realpath failed for driver link\n" , devname);return false; + } mod_base =path_basename (mod_path); -if (strcmp (mod_base, dax_modules[DAXCTL_DEV_MODE_RAM ]) ==0 ) { +if (strcmp (mod_base, mod_name) ==0 ) {free (mod_path);return true; }
daxctl/lib/libdaxctl.c DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) · line 427
Quoted 7 lines
daxctl/lib/libdaxctl.c +4
-0@@ -419,6 +421,30 @@ DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev)return false; } +DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_RAM ]); +}
With daxctl_dev_is_famfs_mode() and daxctl_dev_is_devdax_mode() now alongside it, the _capable vs _mode naming split looks inconsistent. Post-refactor all three delegate to daxctl_dev_bound_to_module(), which checks current driver binding.
Either document the semantic distinction more explicitly or consider adding daxctl_dev_is_system_ram_mode() as the preferred interface.
Quoted 9 lines
daxctl/lib/libdaxctl.c +9
-0+ +/* +* Check if device is currently in famfs mode (bound to fsdev_dax driver). +* Returns false for disabled devices: the DAX bus does not retain the previous +* driver binding after unbind, so mode cannot be determined without a driver. +*/ +DAXCTL_EXPORT int daxctl_dev_is_famfs_mode(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_FAMFS ]);
daxctl/lib/libdaxctl.c DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev) · line 446
Quoted 10 lines
daxctl/lib/libdaxctl.c +10
-0+} + +/* +* Check if device is currently in devdax mode (bound to device_dax driver). +* Returns false for disabled devices; see daxctl_dev_is_famfs_mode(). +*/ +DAXCTL_EXPORT int daxctl_dev_is_devdax_mode(struct daxctl_dev *dev) +{ +return daxctl_dev_bound_to_module (dev, dax_modules[DAXCTL_DEV_MODE_DEVDAX ]); +}
These comments claim "Returns false for disabled devices" as if that were unique to these two helpers, but it isn't. daxctl_dev_is_system_ram_capable returns false for disabled devices too. Either drop the comment or move it to to daxctl_dev_bound_to_module().
daxctl/lib/libdaxctl.c DAXCTL_EXPORT int daxctl_dev_enable_ram(struct daxctl_dev *dev) · line 1015
Quoted 12 lines
daxctl/lib/libdaxctl.c +5
-0+/* * This checks for the device to be in system-ram mode, so calling * daxctl_dev_get_memory() on a devdax mode device will always return NULL. @@ -983,6 +1009,11 @@ DAXCTL_EXPORT int daxctl_dev_enable_ram(struct daxctl_dev *dev)return daxctl_dev_enable (dev,DAXCTL_DEV_MODE_RAM ); } +DAXCTL_EXPORT int daxctl_dev_enable_famfs(struct daxctl_dev *dev) +{ +return daxctl_dev_enable (dev,DAXCTL_DEV_MODE_FAMFS ); +}
OK.
Quoted 9 lines
daxctl/lib/libdaxctl.c +1
-0+ DAXCTL_EXPORT int daxctl_dev_disable(struct daxctl_dev *dev) {const char *devname =daxctl_dev_get_devname (dev);daxctl/lib/libdaxctl.sym +0
-0
daxctl/lib/libdaxctl.sym LIBDAXCTL_10 { · line 113
Quoted 10 lines
daxctl/lib/libdaxctl.sym +7
-0@@ -104,3 +104,10 @@ LIBDAXCTL_10 { global: daxctl_dev_is_system_ram_capable; } LIBDAXCTL_9; + +LIBDAXCTL_11 { +global: + daxctl_dev_enable_famfs; + daxctl_dev_is_famfs_mode; + daxctl_dev_is_devdax_mode; +} LIBDAXCTL_10;
If you resolve the _capable/_mode naming inconsistency by adding daxctl_dev_is_system_ram_mode(), please export it here as well.
Quoted 7 lines
daxctl/libdaxctl.h +0
-0@@ -72,12 +72,15 @@ int daxctl_dev_is_enabled(struct daxctl_dev *dev);int daxctl_dev_disable (struct daxctl_dev *dev);int daxctl_dev_enable_devdax (struct daxctl_dev *dev);
daxctl/libdaxctl.h int daxctl_dev_is_enabled(struct daxctl_dev *dev); · line 83
Quoted 10 lines
daxctl/libdaxctl.h +3
-0int daxctl_dev_enable_ram (struct daxctl_dev *dev); +int daxctl_dev_enable_famfs (struct daxctl_dev *dev);int daxctl_dev_get_target_node (struct daxctl_dev *dev);int daxctl_dev_will_auto_online_memory (struct daxctl_dev *dev);int daxctl_dev_has_online_memory (struct daxctl_dev *dev);struct daxctl_memory ;int daxctl_dev_is_system_ram_capable (struct daxctl_dev *dev); +int daxctl_dev_is_famfs_mode (struct daxctl_dev *dev); +int daxctl_dev_is_devdax_mode (struct daxctl_dev *dev);
Mirror whatever you do about _capable vs _mode here. If you add daxctl_dev_get_mode() as a public library function, declare it here too.
Quoted 3 lines
daxctl/libdaxctl.h +0
-0struct daxctl_memory *daxctl_dev_get_memory (struct daxctl_dev *dev);struct daxctl_dev *daxctl_memory_get_dev (struct daxctl_memory *mem);const char *daxctl_memory_get_node_path (struct daxctl_memory *mem);
PATCH v5 2/2 Add test/daxctl-famfs.sh to test famfs mode transitions:
In reply to John GrovesFrom: John Groves <[email protected]>
- devdax <-> famfs mode switches
- Verify famfs -> system-ram is rejected (must go via devdax)
- Test JSON output shows correct mode
- Test error handling for invalid modes
--- test/daxctl-famfs.sh | 253 +++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 255 insertions(+) create mode 100755 test/daxctl-famfs.sh
test/daxctl-famfs.sh new file +253 -0
@@ -0,0 +1,253 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 Micron Technology, Inc. All rights reserved. +# +# Test daxctl famfs mode transitions and mode detection + +rc=77 +. $(dirname $0)/common + +trap 'cleanup $LINENO' ERR + +daxdev="" +original_mode="" + +cleanup() +{ + printf "Error at line %d\n" "$1" + # Try to restore to original mode if we know it + if [[ $daxdev && $original_mode ]]; then + "$DAXCTL" reconfigure-device -f -m "$original_mode" "$daxdev" 2>/dev/null || true + fi + exit $rc +} + +# Check if fsdev_dax module is available +check_fsdev_dax() +{ + if modinfo fsdev_dax &>/dev/null; then + return 0 + fi + if grep -qF "fsdev_dax" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null; then + return 0 + fi + printf "fsdev_dax module not available, skipping\n" + exit 77 +} + +# Check if kmem module is available (needed for system-ram mode tests) +check_kmem() +{ + if modinfo kmem &>/dev/null; then + return 0 + fi + if grep -qF "kmem" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null; then + return 0 + fi + printf "kmem module not available, skipping system-ram tests\n" + return 1 +} + +# Find an existing dax device to test with +find_daxdev() +{ + # Look for any available dax device + daxdev=$("$DAXCTL" list | jq -er '.[0].chardev // empty' 2>/dev/null) || true + + if [[ ! $daxdev ]]; then + printf "No dax device found, skipping\n" + exit 77 + fi + + # Save the original mode so we can restore it + original_mode=$("$DAXCTL" list -d "$daxdev" | jq -er '.[].mode') + + printf "Found dax device: %s (current mode: %s)\n" "$daxdev" "$original_mode" +} + +daxctl_get_mode() +{ + "$DAXCTL" list -d "$1" | jq -er '.[].mode' +} + +# Ensure device is in devdax mode for testing +ensure_devdax_mode() +{ + local mode + mode=$(daxctl_get_mode "$daxdev") + + if [[ "$mode" == "devdax" ]]; then + return 0 + fi + + if [[ "$mode" == "system-ram" ]]; then + printf "Device is in system-ram mode, attempting to convert to devdax...\n" + "$DAXCTL" reconfigure-device -f -m devdax "$daxdev" + elif [[ "$mode" == "famfs" ]]; then + printf "Device is in famfs mode, converting to devdax...\n" + "$DAXCTL" reconfigure-device -m devdax "$daxdev" + else + printf "Device is in unknown mode: %s\n" "$mode" + return 1 + fi + + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] +} + +# +# Test basic mode transitions involving famfs +# +test_famfs_mode_transitions() +{ + printf "\n=== Testing famfs mode transitions ===\n" + + # Ensure starting in devdax mode + ensure_devdax_mode + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + printf "Initial mode: devdax - OK\n" + + # Test: devdax -> famfs + printf "Testing devdax -> famfs... " + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + printf "OK\n" + + # Test: famfs -> famfs (re-enable in same mode) + printf "Testing famfs -> famfs (re-enable)... " + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + printf "OK\n" + + # Test: famfs -> devdax + printf "Testing famfs -> devdax... " + "$DAXCTL" reconfigure-device -m devdax "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + printf "OK\n" + + # Test: devdax -> devdax (re-enable in same mode) + printf "Testing devdax -> devdax (re-enable)... " + "$DAXCTL" reconfigure-device -m devdax "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + printf "OK\n" +} + +# +# Test mode transitions with system-ram (requires kmem) +# +test_system_ram_transitions() +{ + printf "\n=== Testing system-ram transitions with famfs ===\n" + + # Ensure we start in devdax mode + ensure_devdax_mode + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + + # Test: devdax -> system-ram + printf "Testing devdax -> system-ram... " + "$DAXCTL" reconfigure-device -N -m system-ram "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "system-ram" ]] + printf "OK\n" + + # Test: system-ram -> famfs should fail + printf "Testing system-ram -> famfs (should fail)... " + if "$DAXCTL" reconfigure-device -m famfs "$daxdev" 2>/dev/null; then + printf "FAILED - should have been rejected\n" + return 1 + fi + printf "OK (correctly rejected)\n" + + # Test: system-ram -> devdax -> famfs (proper path) + printf "Testing system-ram -> devdax -> famfs... " + "$DAXCTL" reconfigure-device -f -m devdax "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + printf "OK\n" + + # Restore to devdax for subsequent tests + "$DAXCTL" reconfigure-device -m devdax "$daxdev" +} + +# +# Test JSON output shows correct mode +# +test_json_output() +{ + printf "\n=== Testing JSON output for mode field ===\n" + + # Test devdax mode in JSON + ensure_devdax_mode + printf "Testing JSON output for devdax mode... " + mode=$("$DAXCTL" list -d "$daxdev" | jq -er '.[].mode') + [[ "$mode" == "devdax" ]] + printf "OK\n" + + # Test famfs mode in JSON + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + printf "Testing JSON output for famfs mode... " + mode=$("$DAXCTL" list -d "$daxdev" | jq -er '.[].mode') + [[ "$mode" == "famfs" ]] + printf "OK\n" + + # Restore to devdax + "$DAXCTL" reconfigure-device -m devdax "$daxdev" +} + +# +# Test error messages for invalid transitions +# +test_error_handling() +{ + printf "\n=== Testing error handling ===\n" + + # Ensure we're in famfs mode + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + + # Test that invalid mode is rejected + printf "Testing invalid mode rejection... " + if "$DAXCTL" reconfigure-device -m invalidmode "$daxdev" 2>/dev/null; then + printf "FAILED - invalid mode should be rejected\n" + return 1 + fi + printf "OK (correctly rejected)\n" + + # Restore to devdax + "$DAXCTL" reconfigure-device -m devdax "$daxdev" +} + +# +# Main test sequence +# +main() +{ + check_fsdev_dax + find_daxdev + + rc=1 # From here on, failures are real failures + + test_famfs_mode_transitions + test_json_output + test_error_handling + + # System-ram tests require kmem module + if check_kmem; then + # Save and disable online policy for system-ram tests + saved_policy="$(cat /sys/devices/system/memory/auto_online_blocks)" + echo "offline" > /sys/devices/system/memory/auto_online_blocks + + test_system_ram_transitions + + # Restore online policy + echo "$saved_policy" > /sys/devices/system/memory/auto_online_blocks + fi + + # Restore original mode + printf "\nRestoring device to original mode: %s\n" "$original_mode" + "$DAXCTL" reconfigure-device -f -m "$original_mode" "$daxdev" + + printf "\n=== All famfs tests passed ===\n" + + exit 0 +} + +main
test/meson.build +2 -0
@@ -213,6 +213,7 @@ if get_option('destructive').enabled() device_dax_fio = find_program('device-dax-fio.sh') daxctl_devices = find_program('daxctl-devices.sh') daxctl_create = find_program('daxctl-create.sh') + daxctl_famfs = find_program('daxctl-famfs.sh') dm = find_program('dm.sh') mmap_test = find_program('mmap.sh')
@@ -230,6 +231,7 @@ if get_option('destructive').enabled() [ 'device-dax-fio.sh', device_dax_fio, 'dax' ], [ 'daxctl-devices.sh', daxctl_devices, 'dax' ], [ 'daxctl-create.sh', daxctl_create, 'dax' ], + [ 'daxctl-famfs.sh', daxctl_famfs, 'dax' ], [ 'dm.sh', dm, 'dax' ], [ 'mmap.sh', mmap_test, 'dax' ], ]
Signature · 1 line
2.53.0
Dave Jiang
maintainerRe: [PATCH V5 2/2] Add test/daxctl-famfs.sh to test famfs mode transitions:
Quoted 69 lines · John Groves
From: John Groves <[email protected]>
- devdax <-> famfs mode switches
- Verify famfs -> system-ram is rejected (must go via devdax)
- Test JSON output shows correct mode
- Test error handling for invalid modesSigned-off-by John Groves <[email protected]>--- test/daxctl-famfs.sh | 253 +++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 255 insertions(+) create mode 100755 test/daxctl-famfs.shtest/daxctl-famfs.sh new file +49
-0@@ -0,0 +1,253 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 Micron Technology, Inc. All rights reserved. +# +# Test daxctl famfs mode transitions and mode detection + +rc=77 +. $(dirname $0)/common + +trap 'cleanup $LINENO' ERR + +daxdev="" +original_mode="" + +cleanup() +{ + printf "Error at line %d\n" "$1" + # Try to restore to original mode if we know it + if [[ $daxdev && $original_mode ]]; then + "$DAXCTL" reconfigure-device -f -m "$original_mode" "$daxdev" 2>/dev/null || true + fi + exit $rc +} + +# Check if fsdev_dax module is available +check_fsdev_dax() +{ + if modinfo fsdev_dax &>/dev/null; then + return 0 + fi + if grep -qF "fsdev_dax" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null; then + return 0 + fi + printf "fsdev_dax module not available, skipping\n" + exit 77 +} + +# Check if kmem module is available (needed for system-ram mode tests) +check_kmem() +{ + if modinfo kmem &>/dev/null; then + return 0 + fi + if grep -qF "kmem" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null; then + return 0 + fi + printf "kmem module not available, skipping system-ram tests\n" + return 1 +}
test/daxctl-famfs.sh line 59
Quoted 10 lines
test/daxctl-famfs.sh new file +10
-0+ +# Find an existing dax device to test with +find_daxdev() +{ + # Look for any available dax device + daxdev=$("$DAXCTL" list | jq -er '.[0].chardev // empty' 2>/dev/null) || true + + if [[ ! $daxdev ]]; then + printf "No dax device found, skipping\n" + exit 77
Can you use 'do_skip' here?
DJ
Quoted 214 lines
test/daxctl-famfs.sh new file +194
-0+ fi + + # Save the original mode so we can restore it + original_mode=$("$DAXCTL" list -d "$daxdev" | jq -er '.[].mode') + + printf "Found dax device: %s (current mode: %s)\n" "$daxdev" "$original_mode" +} + +daxctl_get_mode() +{ + "$DAXCTL" list -d "$1" | jq -er '.[].mode' +} + +# Ensure device is in devdax mode for testing +ensure_devdax_mode() +{ + local mode + mode=$(daxctl_get_mode "$daxdev") + + if [[ "$mode" == "devdax" ]]; then + return 0 + fi + + if [[ "$mode" == "system-ram" ]]; then + printf "Device is in system-ram mode, attempting to convert to devdax...\n" + "$DAXCTL" reconfigure-device -f -m devdax "$daxdev" + elif [[ "$mode" == "famfs" ]]; then + printf "Device is in famfs mode, converting to devdax...\n" + "$DAXCTL" reconfigure-device -m devdax "$daxdev" + else + printf "Device is in unknown mode: %s\n" "$mode" + return 1 + fi + + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] +} + +# +# Test basic mode transitions involving famfs +# +test_famfs_mode_transitions() +{ + printf "\n=== Testing famfs mode transitions ===\n" + + # Ensure starting in devdax mode + ensure_devdax_mode + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + printf "Initial mode: devdax - OK\n" + + # Test: devdax -> famfs + printf "Testing devdax -> famfs... " + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + printf "OK\n" + + # Test: famfs -> famfs (re-enable in same mode) + printf "Testing famfs -> famfs (re-enable)... " + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + printf "OK\n" + + # Test: famfs -> devdax + printf "Testing famfs -> devdax... " + "$DAXCTL" reconfigure-device -m devdax "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + printf "OK\n" + + # Test: devdax -> devdax (re-enable in same mode) + printf "Testing devdax -> devdax (re-enable)... " + "$DAXCTL" reconfigure-device -m devdax "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + printf "OK\n" +} + +# +# Test mode transitions with system-ram (requires kmem) +# +test_system_ram_transitions() +{ + printf "\n=== Testing system-ram transitions with famfs ===\n" + + # Ensure we start in devdax mode + ensure_devdax_mode + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + + # Test: devdax -> system-ram + printf "Testing devdax -> system-ram... " + "$DAXCTL" reconfigure-device -N -m system-ram "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "system-ram" ]] + printf "OK\n" + + # Test: system-ram -> famfs should fail + printf "Testing system-ram -> famfs (should fail)... " + if "$DAXCTL" reconfigure-device -m famfs "$daxdev" 2>/dev/null; then + printf "FAILED - should have been rejected\n" + return 1 + fi + printf "OK (correctly rejected)\n" + + # Test: system-ram -> devdax -> famfs (proper path) + printf "Testing system-ram -> devdax -> famfs... " + "$DAXCTL" reconfigure-device -f -m devdax "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + printf "OK\n" + + # Restore to devdax for subsequent tests + "$DAXCTL" reconfigure-device -m devdax "$daxdev" +} + +# +# Test JSON output shows correct mode +# +test_json_output() +{ + printf "\n=== Testing JSON output for mode field ===\n" + + # Test devdax mode in JSON + ensure_devdax_mode + printf "Testing JSON output for devdax mode... " + mode=$("$DAXCTL" list -d "$daxdev" | jq -er '.[].mode') + [[ "$mode" == "devdax" ]] + printf "OK\n" + + # Test famfs mode in JSON + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + printf "Testing JSON output for famfs mode... " + mode=$("$DAXCTL" list -d "$daxdev" | jq -er '.[].mode') + [[ "$mode" == "famfs" ]] + printf "OK\n" + + # Restore to devdax + "$DAXCTL" reconfigure-device -m devdax "$daxdev" +} + +# +# Test error messages for invalid transitions +# +test_error_handling() +{ + printf "\n=== Testing error handling ===\n" + + # Ensure we're in famfs mode + "$DAXCTL" reconfigure-device -m famfs "$daxdev" + + # Test that invalid mode is rejected + printf "Testing invalid mode rejection... " + if "$DAXCTL" reconfigure-device -m invalidmode "$daxdev" 2>/dev/null; then + printf "FAILED - invalid mode should be rejected\n" + return 1 + fi + printf "OK (correctly rejected)\n" + + # Restore to devdax + "$DAXCTL" reconfigure-device -m devdax "$daxdev" +} + +# +# Main test sequence +# +main() +{ + check_fsdev_dax + find_daxdev + + rc=1 # From here on, failures are real failures + + test_famfs_mode_transitions + test_json_output + test_error_handling + + # System-ram tests require kmem module + if check_kmem; then + # Save and disable online policy for system-ram tests + saved_policy="$(cat /sys/devices/system/memory/auto_online_blocks)" + echo "offline" > /sys/devices/system/memory/auto_online_blocks + + test_system_ram_transitions + + # Restore online policy + echo "$saved_policy" > /sys/devices/system/memory/auto_online_blocks + fi + + # Restore original mode + printf "\nRestoring device to original mode: %s\n" "$original_mode" + "$DAXCTL" reconfigure-device -f -m "$original_mode" "$daxdev" + + printf "\n=== All famfs tests passed ===\n" + + exit 0 +} + +maintest/meson.build +2
-0@@ -213,6 +213,7 @@ if get_option('destructive').enabled() device_dax_fio = find_program('device-dax-fio.sh') daxctl_devices = find_program('daxctl-devices.sh') daxctl_create = find_program('daxctl-create.sh') + daxctl_famfs = find_program('daxctl-famfs.sh') dm = find_program('dm.sh') mmap_test = find_program('mmap.sh')@@ -230,6 +231,7 @@ if get_option('destructive').enabled() [ 'device-dax-fio.sh', device_dax_fio, 'dax' ], [ 'daxctl-devices.sh', daxctl_devices, 'dax' ], [ 'daxctl-create.sh', daxctl_create, 'dax' ], + [ 'daxctl-famfs.sh', daxctl_famfs, 'dax' ], [ 'dm.sh', dm, 'dax' ], [ 'mmap.sh', mmap_test, 'dax' ], ]
Re: [PATCH V5 2/2] Add test/daxctl-famfs.sh to test famfs mode transitions:
Quoted 85 lines · Dave Jiang
Quoted 69 lines · John Groves
From: John Groves <[email protected]>
- devdax <-> famfs mode switches
- Verify famfs -> system-ram is rejected (must go via devdax)
- Test JSON output shows correct mode
- Test error handling for invalid modesSigned-off-by John Groves <[email protected]>--- test/daxctl-famfs.sh | 253 +++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 255 insertions(+) create mode 100755 test/daxctl-famfs.shtest/daxctl-famfs.sh new file +49
-0@@ -0,0 +1,253 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 Micron Technology, Inc. All rights reserved. +# +# Test daxctl famfs mode transitions and mode detection + +rc=77 +. $(dirname $0)/common + +trap 'cleanup $LINENO' ERR + +daxdev="" +original_mode="" + +cleanup() +{ + printf "Error at line %d\n" "$1" + # Try to restore to original mode if we know it + if [[ $daxdev && $original_mode ]]; then + "$DAXCTL" reconfigure-device -f -m "$original_mode" "$daxdev" 2>/dev/null || true + fi + exit $rc +} + +# Check if fsdev_dax module is available +check_fsdev_dax() +{ + if modinfo fsdev_dax &>/dev/null; then + return 0 + fi + if grep -qF "fsdev_dax" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null; then + return 0 + fi + printf "fsdev_dax module not available, skipping\n" + exit 77 +} + +# Check if kmem module is available (needed for system-ram mode tests) +check_kmem() +{ + if modinfo kmem &>/dev/null; then + return 0 + fi + if grep -qF "kmem" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null; then + return 0 + fi + printf "kmem module not available, skipping system-ram tests\n" + return 1 +}test/daxctl-famfs.sh line 59
Quoted 10 lines
test/daxctl-famfs.sh new file +10
-0+ +# Find an existing dax device to test with +find_daxdev() +{ + # Look for any available dax device + daxdev=$("$DAXCTL" list | jq -er '.[0].chardev // empty' 2>/dev/null) || true + + if [[ ! $daxdev ]]; then + printf "No dax device found, skipping\n" + exit 77Can you use '
do_skip' here?
Quoted 1 line
DJ
Yes! Done in 2 places...
<snip>
Thanks,
John
Alison Schofield
maintainerRe: [PATCH V5 2/2] Add test/daxctl-famfs.sh to test famfs mode transitions:
In reply to John GrovesQuoted 1 line · John Groves
From: John Groves <[email protected]>
Hi John,
Thanks for the famfs mode-transition test. As promised, I took a look at how we can make it work as a unit test in an NDCTL test environment.
The main blocker is the device-selection assumption:
region_id="$("$DAXCTL" list -R |
jq -r ".[] | select(.path | contains(\"cxl_acpi.0\")) | .id")"and then the test grabs whatever happens to be the first dax device on that region. That works in your QEMU setup but not in the ndctl unit-test model. NDCTL tests here are always tied to one of the emulated backends (nfit_test or cxl_test) and build their own test device from a known starting state. They don't scan for "an existing dax device" because there is no such thing in a fresh meson test run. Whatever is there may be leftover state from something else.
So the test as written will either skip (no dax device found) or get tangled up with whatever prior test left the system in. Traditionally DAX has used nfit for its emulated backing, but CXL is a reasonable choice too. I've prepared both examples and appended to the end of this message.
test/daxctl-famfs-nfit.sh
ACPI.NFIT-backed testdev with full devdax/famfs/system-ram coverage
test/daxctl-famfs-cxltest.sh
cxl_test-backed testdev with devdax/famfs only, plus the system-ram -> famfs rejection via -N
The cxl_test version cannot exercise kmem onlining because the memory has no real DRAM backing.
My preference is the nfit version since it exercises the full transition matrix end-to-end, but if FAMFS is primarily a CXL story the cxl_test version is the equivalent. And of course, there is no lock-down here, ie. we can start with nfit and then when DCD support comes around and that is in cxl-test, we can switch completely to CXL or use both nfit and CXL. But - you do need to pick a lane to start in.
Beyond selecting a backend, both versions were also aligned with the existing test style:
- Drop per-step narration as set -x logs commands
- Only emit failure path messages
- Replaced printf with echo
- Suppress reconfigure-device JSON output with >/dev/null.
- Remove restore-to-original-mode cleanup logic; rely on fixture teardown instead.
- Use err helpers for traps and cleanup
- Extend ensure_devdax_mode to handle system-ram start state
- Add check_dmesg "$LINENO" at test completion.
Both versions have been tested, but please verify that the exact coverage and transition matrix still match what you want after my editing.
Please post the selected version as part of the next revision of this series
Patches appended below...
-- Alison
======
test/daxctl-famfs-nfit.sh: test famfs mode transitions on nfit_test
Exercise devdax <-> famfs <-> system-ram transitions and JSON mode reporting on a dax device backed by the emulated ACPI.NFIT bus.
nfit_test was chosen because its pmem ranges have real DRAM backing, so kmem onlining of the system-ram mode works normally and the full matrix of transitions can be tested end-to-end.
--- test/daxctl-famfs-nfit.sh | 215 ++++++++++++++++++++++++++++++++++++++ test/meson.build | 4 +- 2 files changed, 218 insertions(+), 1 deletion(-) create mode 100755 test/daxctl-famfs-nfit.sh
test/daxctl-famfs-nfit.sh new file +215 -0
@@ -0,0 +1,215 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 Micron Technology, Inc. All rights reserved. +# +# Test daxctl famfs mode transitions and mode detection, targeting a +# nfit_test-backed dax device. +# +# nfit_test-backed dax devices have real DRAM backing, so kmem onlining +# works normally. This test exercises the full matrix of transitions +# between devdax, famfs, and system-ram. + +rc=77 +. $(dirname $0)/common + +trap 'cleanup $LINENO' ERR + +testbus="" +testdev="" +daxdev="" + +cleanup() +{ + # Best-effort return to devdax so destroy-namespace can succeed. + if [[ -n $daxdev ]]; then + "$DAXCTL" reconfigure-device -f -m devdax "$daxdev" 2>/dev/null || true + fi + [[ -n $testdev ]] && reset_dev + err "$1" +} + +check_fsdev_dax() +{ + modinfo fsdev_dax &>/dev/null && return 0 + grep -qF "fsdev_dax" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null && return 0 + do_skip "fsdev_dax module not available" +} + +check_kmem() +{ + modinfo kmem &>/dev/null && return 0 + grep -qF "kmem" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null && return 0 + do_skip "kmem module not available" +} + +find_testdev() +{ + testbus="$ACPI_BUS" + + # Ensure the bus has labels, like align.sh / daxctl-devices.sh rely on. + "$NDCTL" disable-region -b "$testbus" all + "$NDCTL" init-labels -f -b "$testbus" all + "$NDCTL" enable-region -b "$testbus" all + + testdev=$("$NDCTL" list -b "$testbus" -Ni | jq -er '.[0].dev | .//""') + [[ $testdev ]] || do_skip "no victim device on $testbus" +} + +setup_dev() +{ + test -n "$testbus" + test -n "$testdev" + + "$NDCTL" destroy-namespace -f -b "$testbus" "$testdev" + # x86_64 memory hotplug can require up to a 2GiB-aligned chunk of + # memory. Create a 4GiB namespace, so enough space is left after + # alignment for kmem + online. + testdev=$("$NDCTL" create-namespace -b "$testbus" -m devdax -fe "$testdev" -s 4G | \ + jq -er '.dev') + test -n "$testdev" + + daxdev=$("$NDCTL" list -n "$testdev" -X | jq -er '.[].daxregion.devices[0].chardev') + test -n "$daxdev" +} + +reset_dev() +{ + "$NDCTL" destroy-namespace -f -b "$testbus" "$testdev" +} + +daxctl_get_mode() +{ + "$DAXCTL" list -d "$1" | jq -er '.[].mode' +} + +save_online_policy() +{ + saved_policy="$(cat /sys/devices/system/memory/auto_online_blocks)" +} + +restore_online_policy() +{ + echo "$saved_policy" > /sys/devices/system/memory/auto_online_blocks +} + +unset_online_policy() +{ + echo "offline" > /sys/devices/system/memory/auto_online_blocks +} + +ensure_devdax_mode() +{ + local mode + mode=$(daxctl_get_mode "$daxdev") + + case "$mode" in + devdax) return 0 ;; + famfs) "$DAXCTL" reconfigure-device -m devdax "$daxdev" >/dev/null ;; + system-ram) "$DAXCTL" reconfigure-device -f -m devdax "$daxdev" >/dev/null ;; + *) + echo "unexpected starting mode: $mode" + return 1 + ;; + esac + + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] +} + +test_famfs_mode_transitions() +{ + ensure_devdax_mode + + # devdax -> famfs + "$DAXCTL" reconfigure-device -m famfs "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + + # famfs -> famfs (re-enable in same mode) + "$DAXCTL" reconfigure-device -m famfs "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + + # famfs -> devdax + "$DAXCTL" reconfigure-device -m devdax "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + + # devdax -> devdax (re-enable in same mode) + "$DAXCTL" reconfigure-device -m devdax "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] +} + +test_json_output() +{ + ensure_devdax_mode + [[ $("$DAXCTL" list -d "$daxdev" | jq -er '.[].mode') == "devdax" ]] + + "$DAXCTL" reconfigure-device -m famfs "$daxdev" >/dev/null + [[ $("$DAXCTL" list -d "$daxdev" | jq -er '.[].mode') == "famfs" ]] + + "$DAXCTL" reconfigure-device -m devdax "$daxdev" >/dev/null +} + +test_error_handling() +{ + "$DAXCTL" reconfigure-device -m famfs "$daxdev" >/dev/null + + # Invalid mode must be rejected + if "$DAXCTL" reconfigure-device -m invalidmode "$daxdev" &>/dev/null; then + echo "FAIL: invalid mode should be rejected" + return 1 + fi + + "$DAXCTL" reconfigure-device -m devdax "$daxdev" >/dev/null +} + +# Full system-ram transitions (real backing, so online_pages() works). +# Turns auto-online off so daxctl drives onlining explicitly. +test_system_ram_transitions() +{ + save_online_policy + unset_online_policy + + ensure_devdax_mode + + # devdax -> system-ram (no-online) + "$DAXCTL" reconfigure-device -N -m system-ram "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "system-ram" ]] + + # system-ram -> famfs must be rejected + if "$DAXCTL" reconfigure-device -m famfs "$daxdev" &>/dev/null; then + echo "FAIL: system-ram -> famfs should be rejected" + restore_online_policy + return 1 + fi + + # system-ram -> devdax -> famfs + "$DAXCTL" reconfigure-device -f -m devdax "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + "$DAXCTL" reconfigure-device -m famfs "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "famfs" ]] + + # Full online cycle: devdax -> system-ram (with online) -> devdax. + "$DAXCTL" reconfigure-device -m devdax "$daxdev" >/dev/null + "$DAXCTL" reconfigure-device -m system-ram "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "system-ram" ]] + "$DAXCTL" reconfigure-device -f -m devdax "$daxdev" >/dev/null + [[ $(daxctl_get_mode "$daxdev") == "devdax" ]] + + restore_online_policy +} + +check_fsdev_dax +check_kmem + +rc=1 + +find_testdev +setup_dev + +test_famfs_mode_transitions +test_json_output +test_error_handling +test_system_ram_transitions + +ensure_devdax_mode +reset_dev + +check_dmesg "$LINENO"
test/meson.build +3 -1
@@ -218,6 +218,7 @@ if get_option('destructive').enabled() daxctl_devices = find_program('daxctl-devices.sh') daxctl_create = find_program('daxctl-create.sh') daxctl_famfs = find_program('daxctl-famfs.sh') + daxctl_famfs_nfit = find_program('daxctl-famfs-nfit.sh') dm = find_program('dm.sh') mmap_test = find_program('mmap.sh')
@@ -235,7 +236,8 @@ if get_option('destructive').enabled() [ 'device-dax-fio.sh', device_dax_fio, 'dax' ], [ 'daxctl-devices.sh', daxctl_devices, 'dax' ], [ 'daxctl-create.sh', daxctl_create, 'dax' ], - [ 'daxctl-famfs.sh', daxctl_famfs, 'dax' ], + [ 'daxctl-famfs.sh', daxctl_famfs, 'dax' ], + [ 'daxctl-famfs-nfit.sh', daxctl_famfs_nfit, 'dax' ], [ 'dm.sh', dm, 'dax' ], [ 'mmap.sh', mmap_test, 'dax' ], ]
Signature · 20 lines
2.37.3 ========= test/daxctl-famfs-cxltest.sh: test famfs mode transitions on cxl_test Exercise devdax <-> famfs transitions and JSON mode reporting on a dax device backed by the emulated cxl_test bus. cxl_test was chosen as an alternative to nfit_test for callers who want the famfs unit test to run against a CXL-backed dax device. Note that cxl_test emulated memory has no real DRAM backing, so this test avoids code paths that online memory through kmem; only the userspace-side rejection of system-ram -> famfs is exercised (via -N, which skips online_pages()). --- test/daxctl-famfs-cxltest.sh | 139 +++++++++++++++++++++++++++++++++++ test/meson.build | 4 +- 2 files changed, 142 insertions(+), 1 deletion(-) create mode 100755 test/daxctl-famfs-cxltest.sh
test/daxctl-famfs-cxltest.sh new file +139 -0
139 lines not on this page · raw message
test/meson.build +3 -1
@@ -219,6 +219,7 @@ if get_option('destructive').enabled() daxctl_create = find_program('daxctl-create.sh') daxctl_famfs = find_program('daxctl-famfs.sh') daxctl_famfs_nfit = find_program('daxctl-famfs-nfit.sh') + daxctl_famfs_cxltest = find_program('daxctl-famfs-cxltest.sh') dm = find_program('dm.sh') mmap_test = find_program('mmap.sh')
@@ -237,7 +238,8 @@ if get_option('destructive').enabled() [ 'daxctl-devices.sh', daxctl_devices, 'dax' ], [ 'daxctl-create.sh', daxctl_create, 'dax' ], [ 'daxctl-famfs.sh', daxctl_famfs, 'dax' ], - [ 'daxctl-famfs-nfit.sh', daxctl_famfs_nfit, 'dax' ], + [ 'daxctl-famfs-nfit.sh', daxctl_famfs_nfit, 'dax' ], + [ 'daxctl-famfs-cxltest.sh', daxctl_famfs_cxltest, 'dax' ], [ 'dm.sh', dm, 'dax' ], [ 'mmap.sh', mmap_test, 'dax' ], ]
Signature · 1 line
2.37.3