daxctl: add a new reconfigure-device command
Subsystems (3)
Vishal Verma
maintainerv6 cover daxctl: add a new reconfigure-device command
Changes in v6:
- For memory block online/offline operations, the kernel responds with an EINVAL for both 'real' errors, and if the memory was already in the requested state. Since there is a TOCTOU hole between checking the state and storing it, just perform a second check if the store results in an error. If the check shows the state to be the same as the one we're attempting, it means that another agent (usually udev) won the race, but we don't care so long as the state change happened, so don't report an error. (Fan Du)
Changes in v5:
- device.c: correctly set loglevel for daxctl_ctx for --verbose
- drop the subsys caching, its complexity started to exceed its benefit. dax-class device models will simply error out during reconfigure. (Dan)
- Add a note to the man page for the above.
- Clarify the onlining policy (online_movable) in the man page
- rename "numa_node" to "target_node" in device listings (Dan)
- When printing a device 'mode', assume devdax if !system-ram, avoiding a "mode: unknown" situation which can be confusing. (Dan)
- Add a "state: disabled" attribute to the device listing if a driver is not bound. This is more apt than the previous "mode: unknown" listing.
- add an api to get 'dev->resource' parsing /proc/iomem as a fallback for when the kernel doesn't provide the attribute (Dan)
- convert node_* apis to 'memory_* apis that act on a new daxctl_memory object (Dan)
- online only memory sections belonging to the device in question by cross referencing block indices with the dax device resource (Dan)
- Refuse to reconfigure a device that is already in the target mode. Until now, reconfiguring a system-ram device back to system-ram would result in a 'online memory may not be hot-removed' kernel warning.
- If the device was already in the system-ram mode, skip disabling/enabling, but still try to online the memory unless the --no-online option is in effect.
- In daxctl_unbind, also 'remove_id' to prevent devices automatically binding to the kmem driver on a disable + re-enable, which can be surprising (Dan).
- Rewrite the top half of daxctl/device.c to borrow elements from ndctl/namespace.c so that it can support growing additional commands that operate on devices (online-memory and offline-memory)
- Refactor the bottom half of daxctl/device.c so we only do the disabling/offlining steps if the device was enabled.
- Add new commands to online and offline memory sections (Dan) associated with a given dax device (Dan)
- Add a new test - daxctl-device.sh - to test daxctl reconfigure-device, online-memory, and offline-memory commands.
- Add an example in documentation demonstrating how to use numactl to bind a process to a node surfaced from a dax device (Andy Rudoff)
Changes in v4:
- Don't fail add_dax_dev for kmod failures. Instead fail only when the kmod list is actually used, i.e. during daxctl-reconfigure-device
Changes in v3:
- In daxctl_dev_get_mode(), remove the subsystem warning, detect dax-class and simply make it return devdax
Changes in v2:
- Add examples to the documentation page (Dave Hansen)
- Clarify documentation regarding the conversion from system-ram to devdax
- Remove any references to a persistent config from the documentation - those can be added when the feature is added.
- device.c: validate option compatibility
- daxctl-list: display numa_node for device listings
- daxctl-list: display mode for device listings
- make the options more consistent by adding a '-O' short option for --attempt-offline
Add a new daxctl-reconfigure-device command that lets us reconfigure DAX devices back and forth between 'system-ram' and 'device-dax' modes. It also includes facilities to online any newly hot-plugged memory (default), and attempt to offline memory before converting away from the system-ram mode (not default, requires a --attempt-offline option).
Currently missing from this series is a way to persistently store which devices have been 'marked' for use as system-ram. This depends on a config system overhaul in ndctl, and patches for those will follow separately and are independent of this work.
Example invocations:
1. Reconfigure dax0.0 to system-ram mode, don’t online the memory
# daxctl reconfigure-device --mode=system-ram --no-online dax0.0
[
{
"chardev":"dax0.0",
"size":16777216000,
"target_node":2,
"mode":"system-ram"
}
]2. Reconfigure dax0.0 to devdax mode, attempt to offline the memory
# daxctl reconfigure-device --human --mode=devdax --attempt-offline dax0.0
{
"chardev":"dax0.0",
"size":"15.63 GiB (16.78 GB)",
"target_node":2,
"mode":"devdax"
}3. Reconfigure all dax devices on region0 to system-ram mode
# daxctl reconfigure-device --mode=system-ram --region=0 all
[
{
"chardev":"dax0.0",
"size":16777216000,
"target_node":2,
"mode":"system-ram"
},
{
"chardev":"dax0.1",
"size":16777216000,
"target_node":3,
"mode":"system-ram"
}
]These patches can also be found in the 'kmem-pending' branch on github:
https://github.com/pmem/ndctl/tree/kmem-pending
Vishal Verma (13):
libdaxctl: add interfaces to get ctx and check device state
libdaxctl: add interfaces to enable/disable devices
libdaxctl: add an interface to retrieve the device resource
libdaxctl: add a 'daxctl_memory' object for memory based operations daxctl/list: add target_node for device listings
libdaxctl: add an interface to get the mode for a dax device
daxctl: add a new reconfigure-device command Documentation/daxctl: add a man page for daxctl-reconfigure-device
daxctl: add commands to online and offline memory
Documentation: Add man pages for daxctl-{on,off}line-memory contrib/ndctl: fix region-id completions for daxctl contrib/ndctl: add bash-completion for the new daxctl commands
test: Add a unit test for daxctl-reconfigure-device and friends
Documentation/daxctl/Makefile.am | 5 +- .../daxctl/daxctl-offline-memory.txt | 72 ++ Documentation/daxctl/daxctl-online-memory.txt | 80 +++ .../daxctl/daxctl-reconfigure-device.txt | 139 ++++ Makefile.am | 3 +- contrib/ndctl | 38 +- daxctl/Makefile.am | 2 + daxctl/builtin.h | 3 + daxctl/daxctl.c | 3 + daxctl/device.c | 484 +++++++++++++ daxctl/lib/Makefile.am | 5 +- daxctl/lib/libdaxctl-private.h | 30 + daxctl/lib/libdaxctl.c | 665 ++++++++++++++++++ daxctl/lib/libdaxctl.sym | 19 + daxctl/libdaxctl.h | 23 + test/Makefile.am | 3 +- test/common | 19 +- test/daxctl-devices.sh | 81 +++ util/iomem.c | 37 + util/iomem.h | 12 + util/json.c | 25 + 21 files changed, 1734 insertions(+), 14 deletions(-) create mode 100644 Documentation/daxctl/daxctl-offline-memory.txt create mode 100644 Documentation/daxctl/daxctl-online-memory.txt create mode 100644 Documentation/daxctl/daxctl-reconfigure-device.txt create mode 100644 daxctl/device.c create mode 100755 test/daxctl-devices.sh create mode 100644 util/iomem.c create mode 100644 util/iomem.h
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 1/13 libdaxctl: add interfaces to get ctx and check device state
In preparation for libdaxctl and daxctl to grow operational modes for DAX devices, add the following supporting APIs:
daxctl_dev_get_ctx
daxctl_dev_is_enabled
--- daxctl/lib/libdaxctl.c | 30 ++++++++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 6 ++++++ daxctl/libdaxctl.h | 2 ++ 3 files changed, 38 insertions(+)
daxctl/lib/libdaxctl.c +30 -0
@@ -559,6 +559,36 @@ static void dax_regions_init(struct daxctl_ctx *ctx) } } +static int is_enabled (const char *drvpath) +{ +struct stat st; + +if (lstat (drvpath, &st) <0 || !S_ISLNK (st.st_mode)) +return 0 ; +else +return 1 ; +} + +DAXCTL_EXPORT int daxctl_dev_is_enabled(struct daxctl_dev *dev) +{ +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +char *path = dev->dev_buf; +int len = dev->buf_len; + +if (snprintf (path, len,"%s/driver" , dev->dev_path) >= len) { +err (ctx,"%s: buffer too small!\n" , +daxctl_dev_get_devname (dev)); +return 0 ; + } + +return is_enabled (path); +} + +DAXCTL_EXPORT struct daxctl_ctx *daxctl_dev_get_ctx(struct daxctl_dev *dev) +{ +return dev->region->ctx; +} + DAXCTL_EXPORT struct daxctl_dev *daxctl_dev_get_first(struct daxctl_region *region) {dax_devices_init (region);
daxctl/lib/libdaxctl.sym +6 -0
@@ -50,3 +50,9 @@ LIBDAXCTL_5 { global: daxctl_region_get_path; } LIBDAXCTL_4; + +LIBDAXCTL_6 { +global: + daxctl_dev_get_ctx; + daxctl_dev_is_enabled; +} LIBDAXCTL_5;
daxctl/libdaxctl.h +2 -0
@@ -67,6 +67,8 @@ const char *daxctl_dev_get_devname(struct daxctl_dev *dev);int daxctl_dev_get_major (struct daxctl_dev *dev);int daxctl_dev_get_minor (struct daxctl_dev *dev);unsigned long long daxctl_dev_get_size (struct daxctl_dev *dev); +struct daxctl_ctx *daxctl_dev_get_ctx (struct daxctl_dev *dev); +int daxctl_dev_is_enabled (struct daxctl_dev *dev);#define daxctl_dev_foreach (region, dev) \ for (dev = daxctl_dev_get_first(region); \
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [ndctl PATCH v6 01/13] libdaxctl: add interfaces to get ctx and check device state
Quoted 9 lines · Vishal Verma
In preparation for libdaxctl and daxctl to grow operational modes for DAX devices, add the following supporting APIs:
daxctl_dev_get_ctx
daxctl_dev_is_enabledCc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Looks good,
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 2/13 libdaxctl: add interfaces to enable/disable devices
In reply to Vishal VermaAdd new libdaxctl interfaces to disable a device_dax based device, and to enable it into the given mode. The modes available are 'devdax', and 'system-ram', where devdax is the normal device DAX mode used via a character device, and 'system-ram' uses the kernel's 'kmem' facility to hotplug the device making it usable as normal memory.
This adds the following new interfaces:
daxctl_dev_disable;
daxctl_dev_enable_devdax;
daxctl_dev_enable_ram;
--- daxctl/lib/Makefile.am | 3 +- daxctl/lib/libdaxctl-private.h | 15 +++ daxctl/lib/libdaxctl.c | 234 +++++++++++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 3 + daxctl/libdaxctl.h | 9 ++ 5 files changed, 263 insertions(+), 1 deletion(-)
daxctl/lib/Makefile.am +2 -1
@@ -16,7 +16,8 @@ libdaxctl_la_SOURCES =\ libdaxctl.c libdaxctl_la_LIBADD =\ - $(UUID_LIBS) + $(UUID_LIBS) \ + $(KMOD_LIBS) daxctl_modprobe_data_DATA = daxctl.conf
daxctl/lib/libdaxctl-private.h +15 -0
@@ -13,6 +13,8 @@#ifndef _LIBDAXCTL_PRIVATE_H_#define _LIBDAXCTL_PRIVATE_H_ +#include <libkmod.h> +#define DAXCTL_EXPORT __attribute__ ((visibility("default"))) enum dax_subsystem {
@@ -26,6 +28,11 @@ static const char *dax_subsystems[] = { [DAX_BUS] = "/sys/bus/dax/devices", }; +static const char *dax_modules[] = { + [DAXCTL_DEV_MODE_DEVDAX ] ="device_dax" , + [DAXCTL_DEV_MODE_RAM ] ="kmem" , +}; +/** * struct daxctl_region - container for dax_devices */
@@ -53,6 +60,14 @@ struct daxctl_dev {char *dev_path;struct list_node list;unsigned long long size; +struct kmod_module *module; +struct kmod_list *kmod_list; struct daxctl_region *region; }; + +static inline int check_kmod (struct kmod_ctx *kmod_ctx) +{ +return kmod_ctx ?0 : -ENXIO ; +} +#endif /* _LIBDAXCTL_PRIVATE_H_ */
daxctl/lib/libdaxctl.c +234 -0
302 lines not on this page · raw message
daxctl/lib/libdaxctl.sym +3 -0
@@ -55,4 +55,7 @@ LIBDAXCTL_6 { global: daxctl_dev_get_ctx; daxctl_dev_is_enabled; + daxctl_dev_disable; + daxctl_dev_enable_devdax; + daxctl_dev_enable_ram; } LIBDAXCTL_5;
daxctl/libdaxctl.h +9 -0
@@ -69,6 +69,9 @@ int daxctl_dev_get_minor(struct daxctl_dev *dev);unsigned long long daxctl_dev_get_size (struct daxctl_dev *dev);struct daxctl_ctx *daxctl_dev_get_ctx (struct daxctl_dev *dev);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);#define daxctl_dev_foreach (region, dev) \ for (dev = daxctl_dev_get_first(region); \
@@ -81,6 +84,12 @@ int daxctl_dev_is_enabled(struct daxctl_dev *dev); region !=NULL ; \ region = daxctl_region_get_next(region)) +enum daxctl_dev_mode { +DAXCTL_DEV_MODE_UNKNOWN , +DAXCTL_DEV_MODE_RAM , +DAXCTL_DEV_MODE_DEVDAX , +}; + #ifdef __cplusplus }/* extern "C" */ #endif
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [ndctl PATCH v6 02/13] libdaxctl: add interfaces to enable/disable devices
Quoted 9 lines · Vishal Verma
Add new libdaxctl interfaces to disable a
device_daxbased device, and to enable it into the given mode. The modes available are 'devdax', and 'system-ram', where devdax is the normal device DAX mode used via a character device, and 'system-ram' uses the kernel's 'kmem' facility to hotplug the device making it usable as normal memory.This adds the following new interfaces:
Quoted 7 lines
daxctl_dev_disable;
daxctl_dev_enable_devdax;
daxctl_dev_enable_ram;Cc Dave Hansen <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Looks good,
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 3/13 libdaxctl: add an interface to retrieve the device resource
In reply to Vishal VermaAdd an interface to retrieve the 'resource' attribute for a dax device.
Attempt to retrieve it as usual via sysfs, but since older kernels may be missing this attribute, as a fallback, attempt to retrieve it from /proc/iomem
--- Makefile.am | 3 ++- daxctl/lib/Makefile.am | 2 ++ daxctl/lib/libdaxctl-private.h | 1 + daxctl/lib/libdaxctl.c | 12 +++++++++++ daxctl/lib/libdaxctl.sym | 1 + daxctl/libdaxctl.h | 1 + util/iomem.c | 37 ++++++++++++++++++++++++++++++++++ util/iomem.h | 12 +++++++++++ 8 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 util/iomem.c create mode 100644 util/iomem.h
Makefile.am +2 -1
@@ -74,6 +74,7 @@ libutil_a_SOURCES = \ util/wrapper.c \ util/filter.c \ util/bitmap.c \ - util/abspath.c + util/abspath.c \ + util/iomem.c nobase_include_HEADERS = daxctl/libdaxctl.h
daxctl/lib/Makefile.am +2 -0
@@ -9,6 +9,8 @@ lib_LTLIBRARIES = libdaxctl.la libdaxctl_la_SOURCES =\ ../libdaxctl.h \ libdaxctl-private.h \ + ../../util/iomem.c \ + ../../util/iomem.h \ ../../util/sysfs.c \ ../../util/sysfs.h \ ../../util/log.c \
daxctl/lib/libdaxctl-private.h +1 -0
@@ -59,6 +59,7 @@ struct daxctl_dev {size_t buf_len;char *dev_path;struct list_node list; +unsigned long long resource;unsigned long long size;struct kmod_module *module;struct kmod_list *kmod_list;
daxctl/lib/libdaxctl.c +12 -0
@@ -24,6 +24,7 @@#include <util/log.h> #include <util/sysfs.h> +#include <util/iomem.h> #include <daxctl/libdaxctl.h> #include "libdaxctl-private.h"
@@ -369,6 +370,12 @@ static void *add_dax_dev(void *parent, int id, const char *daxdev_base) dev->major =major (st.st_rdev); dev->minor =minor (st.st_rdev); +sprintf (path,"%s/resource" , daxdev_base); +if (sysfs_read_attr (ctx, path, buf) ==0 ) + dev->resource =strtoull (buf,NULL ,0 ); +else + dev->resource =iomem_get_dev_resource (ctx, daxdev_base); +sprintf (path,"%s/size" , daxdev_base);if (sysfs_read_attr (ctx, path, buf) <0 ) goto err_read;
@@ -878,6 +885,11 @@ DAXCTL_EXPORT int daxctl_dev_get_minor(struct daxctl_dev *dev)return dev->minor; } +DAXCTL_EXPORT unsigned long long daxctl_dev_get_resource (struct daxctl_dev *dev) +{ +return dev->resource; +} +DAXCTL_EXPORT unsigned long long daxctl_dev_get_size (struct daxctl_dev *dev) {return dev->size;
daxctl/lib/libdaxctl.sym +1 -0
@@ -58,4 +58,5 @@ global: daxctl_dev_disable; daxctl_dev_enable_devdax; daxctl_dev_enable_ram; + daxctl_dev_get_resource; } LIBDAXCTL_5;
daxctl/libdaxctl.h +1 -0
@@ -66,6 +66,7 @@ int daxctl_dev_get_id(struct daxctl_dev *dev);const char *daxctl_dev_get_devname (struct daxctl_dev *dev);int daxctl_dev_get_major (struct daxctl_dev *dev);int daxctl_dev_get_minor (struct daxctl_dev *dev); +unsigned long long daxctl_dev_get_resource (struct daxctl_dev *dev);unsigned long long daxctl_dev_get_size (struct daxctl_dev *dev);struct daxctl_ctx *daxctl_dev_get_ctx (struct daxctl_dev *dev);int daxctl_dev_is_enabled (struct daxctl_dev *dev);
util/iomem.c new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2019 Intel Corporation. All rights reserved. */ + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <util/log.h> +#include <util/iomem.h> +#include <util/sysfs.h> + +unsigned long long __iomem_get_dev_resource (struct log_ctx *ctx, +const char *devpath) +{ +const char *devname =devpath_to_devname (devpath); +FILE *fp =fopen ("/proc/iomem" ,"r" ); +unsigned long long res; +char name[256 ]; + +if (fp ==NULL ) { +log_err (ctx,"%s: open /proc/iomem: %s\n" , devname, +strerror (errno)); +return 0 ; + } + +while (fscanf (fp,"%llx-%*x : %254[^\n]\n" , &res, name) ==2 ) { +if (strcmp (name, devname) ==0 ) { +log_dbg (ctx,"%s: got resource via iomem: %#llx\n" , + devname, res); +fclose (fp); +return res; + } + } + +log_dbg (ctx,"%s: not found in iomem\n" , devname); +fclose (fp); +return 0 ; +}
util/iomem.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2019 Intel Corporation. All rights reserved. */ +#ifndef _NDCTL_IOMEM_H_ +#define _NDCTL_IOMEM_H_ + +struct log_ctx ; +unsigned long long __iomem_get_dev_resource (struct log_ctx *ctx, +const char *path); + +#define iomem_get_dev_resource (c, p) __iomem_get_dev_resource(&(c)->ctx, (p)) + +#endif /* _NDCTL_IOMEM_H_ */
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [ndctl PATCH v6 03/13] libdaxctl: add an interface to retrieve the device resource
Quoted 11 lines · Vishal Verma
Add an interface to retrieve the 'resource' attribute for a dax device.
Attempt to retrieve it as usual via sysfs, but since older kernels may be missing this attribute, as a fallback, attempt to retrieve it from
/proc/iomemCc Dan Williams <[email protected]>[fscanf format string problem and diagnosis]Reported-by Tony Luck <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Looks ok, just wish we had added a dax resource sysfs attribute earlier. That fscanf() line is a work of art.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 4/13 libdaxctl: add a 'daxctl_memory' object for memory based operations
In reply to Vishal VermaIntroduce a new 'daxctl_memory' object, which will be used for operations related to managing dax devices in 'system-memory' modes.
Add libdaxctl APIs to get the target_node of a DAX device, and to online, offline, and query the state of hotplugged memory sections associated with a given device.
This adds the following new interfaces:
daxctl_dev_get_target_node
daxctl_dev_get_memory;
daxctl_memory_get_dev;
daxctl_memory_get_node_path;
daxctl_memory_get_block_size;
daxctl_memory_set_online
daxctl_memory_set_offline
daxctl_memory_is_online
--- daxctl/lib/libdaxctl-private.h | 14 ++ daxctl/lib/libdaxctl.c | 352 +++++++++++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 8 + daxctl/libdaxctl.h | 10 + 4 files changed, 384 insertions(+)
daxctl/lib/libdaxctl-private.h +14 -0
@@ -33,6 +33,11 @@ static const char *dax_modules[] = { [DAXCTL_DEV_MODE_RAM] = "kmem", }; +enum memory_state { +MEM_OFFLINE , +MEM_ONLINE , +}; +/** * struct daxctl_region - container for dax_devices */
@@ -64,8 +69,17 @@ struct daxctl_dev {struct kmod_module *module;struct kmod_list *kmod_list;struct daxctl_region *region; +struct daxctl_memory *mem; +int target_node; }; +struct daxctl_memory { +struct daxctl_dev *dev; +char *node_path; +unsigned long block_size; +}; + +static inline int check_kmod (struct kmod_ctx *kmod_ctx) {return kmod_ctx ?0 : -ENXIO ;
daxctl/lib/libdaxctl.c +352 -0
379 lines not on this page · raw message
daxctl/lib/libdaxctl.sym +8 -0
@@ -59,4 +59,12 @@ global: daxctl_dev_enable_devdax; daxctl_dev_enable_ram; daxctl_dev_get_resource; + daxctl_dev_get_target_node; + daxctl_dev_get_memory; + daxctl_memory_get_dev; + daxctl_memory_get_node_path; + daxctl_memory_get_block_size; + daxctl_memory_set_online; + daxctl_memory_set_offline; + daxctl_memory_is_online; } LIBDAXCTL_5;
daxctl/libdaxctl.h +10 -0
@@ -73,6 +73,16 @@ 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_get_target_node (struct daxctl_dev *dev); + +struct daxctl_memory ; +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); +unsigned long daxctl_memory_get_block_size (struct daxctl_memory *mem); +int daxctl_memory_set_online (struct daxctl_memory *mem); +int daxctl_memory_set_offline (struct daxctl_memory *mem); +int daxctl_memory_is_online (struct daxctl_memory *mem);#define daxctl_dev_foreach (region, dev) \ for (dev = daxctl_dev_get_first(region); \
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [ndctl PATCH v6 04/13] libdaxctl: add a 'daxctl_memory' object for memory based operations
A couple minor comments...
Quoted 141 lines · Vishal Verma
Introduce a new '
daxctl_memory' object, which will be used for operations related to managing dax devices in 'system-memory' modes.Add libdaxctl APIs to get the
target_nodeof a DAX device, and to online, offline, and query the state of hotplugged memory sections associated with a given device.This adds the following new interfaces:
daxctl_dev_get_target_node
daxctl_dev_get_memory;
daxctl_memory_get_dev;
daxctl_memory_get_node_path;
daxctl_memory_get_block_size;
daxctl_memory_set_online
daxctl_memory_set_offline
daxctl_memory_is_onlineCc Pavel Tatashin <[email protected]>Cc Dave Hansen <[email protected]>Cc Dan Williams <[email protected]>[for the memblock-already-online TOCTOU hole]Reported-by Fan Du <[email protected]>Tested-by Fan Du <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- daxctl/lib/libdaxctl-private.h | 14 ++ daxctl/lib/libdaxctl.c | 352 +++++++++++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 8 + daxctl/libdaxctl.h | 10 + 4 files changed, 384 insertions(+)daxctl/lib/libdaxctl-private.h +14
-0@@ -33,6 +33,11 @@ static const char *dax_modules[] = { [DAXCTL_DEV_MODE_RAM] = "kmem", }; +enum memory_state { +MEM_OFFLINE , +MEM_ONLINE , +}; +/** * struct daxctl_region - container for dax_devices */ @@ -64,8 +69,17 @@ struct daxctl_dev {struct kmod_module *module;struct kmod_list *kmod_list;struct daxctl_region *region; +struct daxctl_memory *mem; +int target_node; }; +struct daxctl_memory { +struct daxctl_dev *dev; +char *node_path; +unsigned long block_size; +}; + +static inline int check_kmod (struct kmod_ctx *kmod_ctx) {return kmod_ctx ?0 : -ENXIO ;daxctl/lib/libdaxctl.c +45
-0@@ -200,6 +200,12 @@ DAXCTL_EXPORT void daxctl_region_get_uuid(struct daxctl_region *region, uuid_t uuuid_copy (uu, region->uuid); } +static void free_mem (struct daxctl_memory *mem) +{ +free (mem->node_path); +free (mem); +} +static void free_dev (struct daxctl_dev *dev,struct list_head *head) {if (head)@@ -207,6 +213,7 @@ static void free_dev(struct daxctl_dev *dev, struct list_head *head)kmod_module_unref_list (dev->kmod_list);free (dev->dev_buf);free (dev->dev_path); +free_mem (dev->mem);free (dev); }@@ -343,6 +350,44 @@ static struct kmod_list *to_module_list(struct daxctl_ctx *ctx,return list; } +static struct daxctl_memory *daxctl_dev_init_mem (struct daxctl_dev *dev) +{ +const char *size_path ="/sys/devices/system/memory/block_size_bytes" ; +const char *node_base ="/sys/devices/system/node/node" ; +const char *devname =daxctl_dev_get_devname (dev); +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +struct daxctl_memory *mem; +char buf[SYSFS_ATTR_SIZE ]; +int node_num; + + mem =calloc (1 ,sizeof (*mem)); +if (!mem) +return NULL ; + + mem->dev = dev; + +/* +* Everything here is best-effort, we won't fail the device add +* for anything other than the ENOMEM case above. +*/ +if (sysfs_read_attr (ctx, size_path, buf) ==0 ) { + mem->block_size =strtoul (buf,NULL ,16 ); +if (mem->block_size ==0 || mem->block_size ==ULONG_MAX ) { +err (ctx,"%s: Unable to determine memblock size: %s\n" , + devname,strerror (errno)); + mem->block_size =0 ; + } + } + + node_num =daxctl_dev_get_target_node (dev); +if (node_num >=0 ) { +if (asprintf (&mem->node_path,"%s%d" , node_base, node_num) <0 ) +err (ctx,"%s: Unable to set node_path\n" , devname); + } + +return mem; +} +static void *add_dax_dev (void *parent,int id,const char *daxdev_base) {const char *devname =devpath_to_devname (daxdev_base);@@ -398,6 +443,16 @@ static void *add_dax_dev(void *parent, int id, const char *daxdev_base)if (rc ==0 ) dev->kmod_list =to_module_list (ctx, buf);
daxctl/lib/libdaxctl.c static void *add_dax_dev(void *parent, int id, const char *daxdev_base) · line 455
Quoted 10 lines
daxctl/lib/libdaxctl.c +10
-0+sprintf (path,"%s/target_node" , daxdev_base); +if (sysfs_read_attr (ctx, path, buf) ==0 ) + dev->target_node =strtol (buf,NULL ,0 ); +else + dev->target_node =-1 ; + + dev->mem =daxctl_dev_init_mem (dev); +if (!dev->mem) + goto err_read; +
Should this initialization wait until the first daxctl_dev_get_memory() and validate the device is in "system-ram" mode at that point?
I'm otherwise wondering what it means for daxctl_dev_get_memory() to succeed on a device in "device-dax" mode. I think I would naturally use daxctl_dev_get_memory() as a mode check.
Quoted 88 lines
daxctl/lib/libdaxctl.c +81
-0daxctl_dev_foreach(region, dev_dup)if (dev_dup->id == dev->id) {free_dev (dev,NULL );@@ -894,3 +949,300 @@ DAXCTL_EXPORT unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev) {return dev->size; } + +DAXCTL_EXPORT int daxctl_dev_get_target_node(struct daxctl_dev *dev) +{ +return dev->target_node; +} + +DAXCTL_EXPORT struct daxctl_memory *daxctl_dev_get_memory(struct daxctl_dev *dev) +{ +return dev->mem; +} + +DAXCTL_EXPORT struct daxctl_dev *daxctl_memory_get_dev(struct daxctl_memory *mem) +{ +return mem->dev; +} + +DAXCTL_EXPORT const char *daxctl_memory_get_node_path(struct daxctl_memory *mem) +{ +return mem->node_path; +} + +DAXCTL_EXPORT unsigned long daxctl_memory_get_block_size (struct daxctl_memory *mem) +{ +return mem->block_size; +} + +static int online_one_memblock (struct daxctl_dev *dev,char *path) +{ +const char *devname =daxctl_dev_get_devname (dev); +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +const char *mode ="online_movable" ; +char buf[SYSFS_ATTR_SIZE ]; +int rc; + + rc =sysfs_read_attr (ctx, path, buf); +if (rc) { +err (ctx,"%s: Failed to read %s: %s\n" , + devname, path,strerror (-rc)); +return rc; + } + +/* +* if already online, possibly due to kernel config or a udev rule, +* there is nothing to do and we can skip over the memblock +*/ +if (strncmp (buf,"online" ,6 ) ==0 ) +return 1 ; + + rc =sysfs_write_attr_quiet (ctx, path, mode); +if (rc) { +/* +* While we performed an already-online check above, there +* is still a TOCTOU hole where someone (such as a udev rule) +* may have raced to online the memory. In such a case, +* the sysfs store will fail, however we can check for this +* by simply reading the state again. If it changed to the +* desired state, then we don't have to error out. +*/ +if (sysfs_read_attr (ctx, path, buf) ==0 ) { +if (strncmp (buf,"online" ,6 ) ==0 ) +return 1 ; + } +err (ctx,"%s: Failed to online %s: %s\n" , + devname, path,strerror (-rc)); + } +return rc; +} + +static int offline_one_memblock (struct daxctl_dev *dev,char *path) +{ +const char *devname =daxctl_dev_get_devname (dev); +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +const char *mode ="offline" ; +char buf[SYSFS_ATTR_SIZE ]; +int rc; + + rc =sysfs_read_attr (ctx, path, buf); +if (rc) { +err (ctx,"%s: Failed to read %s: %s\n" , + devname, path,strerror (-rc)); +return rc;
daxctl/lib/libdaxctl.c DAXCTL_EXPORT unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev) · line 1042
Quoted 10 lines
daxctl/lib/libdaxctl.c +10
-0+ } + +/* if already offline, there is nothing to do */ +if (strncmp (buf,"offline" ,7 ) ==0 ) +return 1 ; + + rc =sysfs_write_attr_quiet (ctx, path, mode); +if (rc) { +/* Close the TOCTOU hole like in online_one_memblock() above */ +if (sysfs_read_attr (ctx, path, buf) ==0 ) {
Ah, this also copied the missing space between 'if' and '(' my eyes didn't catch it the first time.
Quoted 245 lines
daxctl/lib/libdaxctl.c +206
-0+if (strncmp (buf,"offline" ,7 ) ==0 ) +return 1 ; + } +err (ctx,"%s: Failed to offline %s: %s\n" , + devname, path,strerror (-rc)); + } +return rc; +} + +static bool memblock_in_dev (struct daxctl_dev *dev,const char *memblock) +{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *mem_base ="/sys/devices/system/memory/" ; +unsigned long long memblock_res, dev_start, dev_end; +const char *devname =daxctl_dev_get_devname (dev); +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +unsigned long memblock_size; +char buf[SYSFS_ATTR_SIZE ]; +unsigned long phys_index; +char *index_path; + +if (asprintf (&index_path,"%s/%s/phys_index" , mem_base, memblock) <0 ) +return false; + +if (sysfs_read_attr (ctx, index_path, buf) ==0 ) { + phys_index =strtoul (buf,NULL ,16 ); +if (phys_index ==0 || phys_index ==ULONG_MAX ) { +err (ctx,"%s: %s: Unable to determine phys_index: %s\n" , + devname, memblock,strerror (errno)); + goto out_err; + } + }else { +err (ctx,"%s: %s: Unable to determine phys_index: %s\n" , + devname, memblock,strerror (errno)); + goto out_err; + } + + dev_start =daxctl_dev_get_resource (dev); +if (!dev_start) { +err (ctx,"%s: Unable to determine resource\n" , devname); + goto out_err; + } + dev_end = dev_start +daxctl_dev_get_size (dev); + + memblock_size =daxctl_memory_get_block_size (mem); +if (!memblock_size) { +err (ctx,"%s: Unable to determine memory block size\n" , + devname); + goto out_err; + } + memblock_res = phys_index * memblock_size; + +if (memblock_res >= dev_start && memblock_res <= dev_end) { +free (index_path); +return true; + } + +out_err: +free (index_path); +return false; +} + +static int daxctl_memory_set_state (struct daxctl_memory *mem, +enum memory_state state) +{ +struct daxctl_dev *dev =daxctl_memory_get_dev (mem); +const char *devname =daxctl_dev_get_devname (dev); +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +const char *node_path; +int rc, changed =0 ; +struct dirent *de; +DIR *node_dir; + + node_path =daxctl_memory_get_node_path (mem); +if (!node_path) { +err (ctx,"%s: Failed to get node_path\n" , devname); +return -ENXIO ; + } + + node_dir =opendir (node_path); +if (!node_dir) +return -errno; + + errno =0 ; +while ((de =readdir (node_dir)) !=NULL ) { +char *mem_path; + +if (strncmp (de->d_name,"memory" ,6 ) ==0 ) { +if (!memblock_in_dev (dev, de->d_name)) +continue ; + rc =asprintf (&mem_path,"%s/%s/state" , + node_path, de->d_name); +if (rc <0 ) { + rc = -ENOMEM ; + goto out_dir; + } +if (state ==MEM_ONLINE ) + rc =online_one_memblock (dev, mem_path); +else if (state ==MEM_OFFLINE ) + rc =offline_one_memblock (dev, mem_path); +else + rc = -EINVAL ; +free (mem_path); +if (rc <0 ) + goto out_dir; +if (rc ==0 ) + changed++; + } + errno =0 ; + } +if (errno) { + rc = -errno; + goto out_dir; + } + rc = changed; + +out_dir: +closedir (node_dir); +return rc; +} + +DAXCTL_EXPORT int daxctl_memory_set_online(struct daxctl_memory *mem) +{ +return daxctl_memory_set_state (mem,MEM_ONLINE ); +} + +DAXCTL_EXPORT int daxctl_memory_set_offline(struct daxctl_memory *mem) +{ +return daxctl_memory_set_state (mem,MEM_OFFLINE ); +} + +static int memblock_is_online (struct daxctl_dev *dev,char *path) +{ +const char *devname =daxctl_dev_get_devname (dev); +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +char buf[SYSFS_ATTR_SIZE ]; +int rc; + + rc =sysfs_read_attr (ctx, path, buf); +if (rc) { +err (ctx,"%s: Failed to read %s: %s\n" , + devname, path,strerror (-rc)); +return rc; + } + +if (strncmp (buf,"online" ,6 ) ==0 ) +return 1 ; + +return 0 ; +} + +DAXCTL_EXPORT int daxctl_memory_is_online(struct daxctl_memory *mem) +{ +struct daxctl_dev *dev =daxctl_memory_get_dev (mem); +const char *devname =daxctl_dev_get_devname (dev); +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +int rc, num_online =0 ; +const char *node_path; +struct dirent *de; +DIR *node_dir; + + node_path =daxctl_memory_get_node_path (mem); +if (!node_path) { +err (ctx,"%s: Failed to get node_path\n" , devname); +return -ENXIO ; + } + + node_dir =opendir (node_path); +if (!node_dir) +return -errno; + + errno =0 ; +while ((de =readdir (node_dir)) !=NULL ) { +char *mem_path; + +if (strncmp (de->d_name,"memory" ,6 ) ==0 ) { +if (!memblock_in_dev (dev, de->d_name)) +continue ; + rc =asprintf (&mem_path,"%s/%s/state" , + node_path, de->d_name); +if (rc <0 ) { + rc = -ENOMEM ; + goto out_dir; + } + rc =memblock_is_online (dev, mem_path); +if (rc <0 ) { +err (ctx,"%s: Unable to determine state: %s\n" , + devname, mem_path); + goto out_dir; + } +if (rc >0 ) + num_online++; +free (mem_path); + } + errno =0 ; + } +if (errno) { + rc = -errno; + goto out_dir; + } + rc = num_online; + +out_dir: +closedir (node_dir); +return rc; +}daxctl/lib/libdaxctl.sym +8
-0@@ -59,4 +59,12 @@ global: daxctl_dev_enable_devdax; daxctl_dev_enable_ram; daxctl_dev_get_resource; + daxctl_dev_get_target_node; + daxctl_dev_get_memory; + daxctl_memory_get_dev; + daxctl_memory_get_node_path; + daxctl_memory_get_block_size; + daxctl_memory_set_online; + daxctl_memory_set_offline; + daxctl_memory_is_online; } LIBDAXCTL_5;daxctl/libdaxctl.h +10
-1@@ -73,6 +73,16 @@ 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_get_target_node (struct daxctl_dev *dev); + +struct daxctl_memory ; +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); +unsigned long daxctl_memory_get_block_size (struct daxctl_memory *mem); +int daxctl_memory_set_online (struct daxctl_memory *mem); +int daxctl_memory_set_offline (struct daxctl_memory *mem); +int daxctl_memory_is_online (struct daxctl_memory *mem);#define daxctl_dev_foreach (region, dev) \ for (dev = daxctl_dev_get_first(region); \ --
Quoted 2 lines
2.20.1
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 5/13 daxctl/list: add target_node for device listings
In reply to Vishal VermaThe kernel provides a 'target_node' attribute for dax devices. When converting a dax device to the system-ram mode, the memory is hotplugged into this numa node. It would be helpful to print this in device listings so that it is easy for applications to detect the node to which the new memory belongs.
--- util/json.c | 8 ++++++++ 1 file changed, 8 insertions(+)
util/json.c +8 -0
@@ -271,6 +271,7 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, {const char *devname =daxctl_dev_get_devname (dev);struct json_object *jdev, *jobj; +int node; jdev =json_object_new_object ();if (!devname || !jdev)
@@ -284,6 +285,13 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,if (jobj)json_object_object_add (jdev,"size" , jobj); + node =daxctl_dev_get_target_node (dev); +if (node >=0 ) { + jobj =json_object_new_int (node); +if (jobj) +json_object_object_add (jdev,"target_node" , jobj); + } +return jdev; }
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [ndctl PATCH v6 05/13] daxctl/list: add target_node for device listings
Quoted 27 lines · Vishal Verma
The kernel provides a '
target_node' attribute for dax devices. When converting a dax device to the system-ram mode, the memory is hotplugged into this numa node. It would be helpful to print this in device listings so that it is easy for applications to detect the node to which the new memory belongs.Cc Dan Williams <[email protected]>Cc Dave Hansen <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- util/json.c | 8 ++++++++ 1 file changed, 8 insertions(+)util/json.c +1
-0@@ -271,6 +271,7 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, {const char *devname =daxctl_dev_get_devname (dev);struct json_object *jdev, *jobj; +int node; jdev =json_object_new_object ();if (!devname || !jdev)
util/json.c struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, · line 294
Quoted 10 lines
util/json.c +7
-0@@ -284,6 +285,13 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,if (jobj)json_object_object_add (jdev,"size" , jobj); + node =daxctl_dev_get_target_node (dev); +if (node >=0 ) { + jobj =json_object_new_int (node); +if (jobj) +json_object_object_add (jdev,"target_node" , jobj); + } +
We moved 'numa_node' to the UTIL_JSON_VERBOSE set on "ndctl list" should do the same for target node?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Verma, Vishal L
maintainerRe: [ndctl PATCH v6 05/13] daxctl/list: add target_node for device listings
Quoted 8 lines · Dan Williams
On Wed, Jul 17, 2019 at 3:54 PM Vishal Verma <[email protected]
Quoted 7 lines
wrote:
util/json.c +0
-0@@ -284,6 +285,13 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, if (jobj) json_object_object_add(jdev, "size", jobj);
Quoted 11 lines
util/json.c struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, · line 294
Quoted 8 lines
util/json.c +7
-0+ node =daxctl_dev_get_target_node (dev); +if (node >=0 ) { + jobj =json_object_new_int (node); +if (jobj) +json_object_object_add (jdev,"target_node" , jobj); + } +We moved '
numa_node' to theUTIL_JSON_VERBOSEset on "ndctl list" should do the same for target node?
Hm, true. Arguably, the target_node is much more pertinent in system-ram mode, and /should/ be in the default verbosity?
One option could be to make it always show if the mode is system-ram, but not otherwise - but I don't know if that would cause more confusion as an attribute might seem to magically appear or disappear with the same command options..
Yet another option is, the output right after daxctl-reconfigure-device always sets UTIL_JSON_VERBOSE, but for daxctl-list, it is only done if the user supplies it.
Any preferences on which way to go?
Thanks,
-Vishal
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [ndctl PATCH v6 05/13] daxctl/list: add target_node for device listings
Quoted 30 lines · Vishal L
Quoted 8 lines · Dan Williams
On Wed, Jul 17, 2019 at 3:54 PM Vishal Verma <[email protected]
Quoted 7 lines
wrote:
util/json.c +0
-0@@ -284,6 +285,13 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, if (jobj) json_object_object_add(jdev, "size", jobj);Quoted 11 lines
util/json.c struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, · line 294
Quoted 8 lines
util/json.c +7
-0+ node =daxctl_dev_get_target_node (dev); +if (node >=0 ) { + jobj =json_object_new_int (node); +if (jobj) +json_object_object_add (jdev,"target_node" , jobj); + } +We moved '
numa_node' to theUTIL_JSON_VERBOSEset on "ndctl list" should do the same for target node?Hm, true. Arguably, the
target_nodeis much more pertinent in system-ram mode, and /should/ be in the default verbosity?One option could be to make it always show if the mode is system-ram, but not otherwise - but I don't know if that would cause more confusion as an attribute might seem to magically appear or disappear with the same command options..
Quoted 5 lines
Yet another option is, the output right after daxctl-reconfigure-device always sets
UTIL_JSON_VERBOSE, but for daxctl-list, it is only done if the user supplies it.Any preferences on which way to go?
'verbose after reconfigure' sounds good, but you're right, it's more pertinent in the device-dax case, especially when that might be one of our only identification mechanisms for non-NFIT device-dax. So I'm ok to keep it as is on second thought.
Quoted 3 lines
Thanks,
-Vishal
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 6/13 libdaxctl: add an interface to get the mode for a dax device
In reply to Vishal VermaIn preparation for a reconfigure-device command, add an interface to retrieve the 'mode' of a dax device. This will allow the reconfigure-device command (and via daxctl_dev_to_json(), also daxctl-list) to print the mode in device listings via a 'daxctl-list' command or immediately after a mode change.
Add a 'state' attribute to the json listings for devices, since a device could end up in a state where it is not bound to any driver, and hence, 'disabled'. The state attribute is only displayed for disabled devices.
--- daxctl/lib/libdaxctl.c | 37 +++++++++++++++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 1 + daxctl/libdaxctl.h | 1 + util/json.c | 17 +++++++++++++++++ 4 files changed, 56 insertions(+)
daxctl/lib/libdaxctl.c +37 -0
@@ -12,6 +12,8 @@*/ #include <stdio.h> #include <errno.h> +#include <limits.h> +#include <libgen.h> #include <stdlib.h> #include <dirent.h> #include <unistd.h>
@@ -880,6 +882,41 @@ DAXCTL_EXPORT int daxctl_dev_disable(struct daxctl_dev *dev)return 0 ; } +DAXCTL_EXPORT enum daxctl_dev_mode daxctl_dev_get_mode(struct daxctl_dev *dev) +{ +const char *devname =daxctl_dev_get_devname (dev); +struct daxctl_ctx *ctx =daxctl_dev_get_ctx (dev); +int rc =DAXCTL_DEV_MODE_UNKNOWN ; +char path[200 ]; +const int len =sizeof (path); +char *mod_path, *mod_base; + +if (!daxctl_dev_is_enabled (dev)) +return rc; + +if (snprintf (path, len,"%s/driver/module" , dev->dev_path) >= len) { +err (ctx,"%s: buffer too small!\n" , devname); +return -ENXIO ; + } + + mod_path =realpath (path,NULL ); +if (!mod_path) { + rc = -errno; +err (ctx,"%s: unable to determine module: %s\n" , devname, +strerror (errno)); +return rc; + } + + mod_base =basename (mod_path); +if (strcmp (mod_base, dax_modules[DAXCTL_DEV_MODE_RAM ]) ==0 ) + rc =DAXCTL_DEV_MODE_RAM ; +else if (strcmp (mod_base, dax_modules[DAXCTL_DEV_MODE_DEVDAX ]) ==0 ) + rc =DAXCTL_DEV_MODE_DEVDAX ; + +free (mod_path); +return rc; +} + DAXCTL_EXPORT struct daxctl_ctx *daxctl_dev_get_ctx(struct daxctl_dev *dev) {return dev->region->ctx;
daxctl/lib/libdaxctl.sym +1 -0
@@ -67,4 +67,5 @@ global: daxctl_memory_set_online; daxctl_memory_set_offline; daxctl_memory_is_online; + daxctl_dev_get_mode; } LIBDAXCTL_5;
daxctl/libdaxctl.h +1 -0
@@ -74,6 +74,7 @@ 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_get_target_node (struct daxctl_dev *dev); +enum daxctl_dev_mode daxctl_dev_get_mode (struct daxctl_dev *dev);struct daxctl_memory ;struct daxctl_memory *daxctl_dev_get_memory (struct daxctl_dev *dev);
util/json.c +17 -0
@@ -271,6 +271,7 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, {const char *devname =daxctl_dev_get_devname (dev);struct json_object *jdev, *jobj; +enum daxctl_dev_mode mode;int node; jdev =json_object_new_object ();
@@ -292,6 +293,22 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,json_object_object_add (jdev,"target_node" , jobj); } + mode =daxctl_dev_get_mode (dev); +if (mode >=0 ) { +if (mode ==DAXCTL_DEV_MODE_RAM ) + jobj =json_object_new_string ("system-ram" ); +else + jobj =json_object_new_string ("devdax" ); +if (jobj) +json_object_object_add (jdev,"mode" , jobj); + } + +if (!daxctl_dev_is_enabled (dev)) { + jobj =json_object_new_string ("disabled" ); +if (jobj) +json_object_object_add (jdev,"state" , jobj); + } +return jdev; }
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 7/13 daxctl: add a new reconfigure-device command
In reply to Vishal VermaAdd a new command 'daxctl-reconfigure-device'. This is used to switch the mode of a dax device between regular 'device_dax' and 'system-memory'. The command also uses the memory hotplug sysfs interfaces to online the newly available memory when converting to 'system-ram', and to attempt to offline the memory when converting back to a DAX device.
--- daxctl/Makefile.am | 2 + daxctl/builtin.h | 1 + daxctl/daxctl.c | 1 + daxctl/device.c | 348 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 352 insertions(+) create mode 100644 daxctl/device.c
daxctl/Makefile.am +2 -0
@@ -15,10 +15,12 @@ daxctl_SOURCES =\ daxctl.c \ list.c \ migrate.c \ + device.c \ ../util/json.c daxctl_LDADD =\ lib/libdaxctl.la \ ../libutil.a \ $(UUID_LIBS) \ + $(KMOD_LIBS) \ $(JSON_LIBS)
daxctl/builtin.h +1 -0
@@ -6,4 +6,5 @@struct daxctl_ctx ;int cmd_list (int argc,const char **argv,struct daxctl_ctx *ctx);int cmd_migrate (int argc,const char **argv,struct daxctl_ctx *ctx); +int cmd_reconfig_device (int argc,const char **argv,struct daxctl_ctx *ctx);#endif /* _DAXCTL_BUILTIN_H_ */
daxctl/daxctl.c +1 -0
@@ -71,6 +71,7 @@ static struct cmd_struct commands[] = { { "list", .d_fn = cmd_list }, { "help", .d_fn = cmd_help }, { "migrate-device-model", .d_fn = cmd_migrate }, + { "reconfigure-device", .d_fn = cmd_reconfig_device }, };int main (int argc,const char **argv)
daxctl/device.c new file +348 -0
348 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 164 lines · Vishal Verma
Add a new command 'daxctl-reconfigure-device'. This is used to switch the mode of a dax device between regular '
device_dax' and 'system-memory'. The command also uses the memory hotplug sysfs interfaces to online the newly available memory when converting to 'system-ram', and to attempt to offline the memory when converting back to a DAX device.Cc Pavel Tatashin <[email protected]>Cc Dave Hansen <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- daxctl/Makefile.am | 2 + daxctl/builtin.h | 1 + daxctl/daxctl.c | 1 + daxctl/device.c | 348 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 352 insertions(+) create mode 100644 daxctl/device.cdaxctl/Makefile.am +2
-0@@ -15,10 +15,12 @@ daxctl_SOURCES =\ daxctl.c \ list.c \ migrate.c \ + device.c \ ../util/json.c daxctl_LDADD =\ lib/libdaxctl.la \ ../libutil.a \ $(UUID_LIBS) \ + $(KMOD_LIBS) \ $(JSON_LIBS)daxctl/builtin.h +1
-0@@ -6,4 +6,5 @@struct daxctl_ctx ;int cmd_list (int argc,const char **argv,struct daxctl_ctx *ctx);int cmd_migrate (int argc,const char **argv,struct daxctl_ctx *ctx); +int cmd_reconfig_device (int argc,const char **argv,struct daxctl_ctx *ctx);#endif /* _DAXCTL_BUILTIN_H_ */ daxctl/daxctl.c +1
-0@@ -71,6 +71,7 @@ static struct cmd_struct commands[] = { { "list", .d_fn = cmd_list }, { "help", .d_fn = cmd_help }, { "migrate-device-model", .d_fn = cmd_migrate }, + { "reconfigure-device", .d_fn = cmd_reconfig_device }, };int main (int argc,const char **argv)daxctl/device.c new file +99
-0@@ -0,0 +1,348 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2019 Intel Corporation. All rights reserved. */ +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <syslog.h> +#include <unistd.h> +#include <limits.h> +#include <util/json.h> +#include <util/filter.h> +#include <json-c/json.h> +#include <daxctl/libdaxctl.h> +#include <util/parse-options.h> +#include <ccan/array_size/array_size.h> + +static struct { +const char *dev; +const char *mode; +int region_id; +bool no_online; +bool do_offline; +bool human; +bool verbose; +} param = { + .region_id =-1 , +}; + +static enum daxctl_dev_mode reconfig_mode =DAXCTL_DEV_MODE_UNKNOWN ; +static unsigned long flags; + +enum device_action { +ACTION_RECONFIG , +}; + +#define BASE_OPTIONS () \ +OPT_INTEGER('r', "region", ¶m.region_id, "restrict to the given region"), \ +OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats"), \ +OPT_BOOLEAN('v', "verbose", ¶m.verbose, "emit more debug messages") + +#define RECONFIG_OPTIONS () \ +OPT_STRING('m', "mode", ¶m.mode, "mode", "mode to switch the device to"), \ +OPT_BOOLEAN('N', "no-online", ¶m.no_online, \ + "don't auto-online memory sections"), \ +OPT_BOOLEAN('O', "attempt-offline", ¶m.do_offline, \ + "attempt to offline memory sections") + +static const struct option reconfig_options[] = { +BASE_OPTIONS (), +RECONFIG_OPTIONS (), +OPT_END (), +}; + +static const char *parse_device_options (int argc,const char **argv, +enum device_action action,const struct option *options, +const char *usage,struct daxctl_ctx *ctx) +{ +const char *const u[] = { + usage, +NULL + }; +int i, rc =0 ; + + argc =parse_options (argc, argv, options, u,0 ); + +/* Handle action-agnostic non-option arguments */ +if (argc ==0 ) { +char *action_string; + +switch (action) { +case ACTION_RECONFIG : + action_string ="reconfigure" ; +break ; +default : + action_string ="<>" ; +break ; + } +fprintf (stderr,"specify a device to %s, or \"all\"\n" , + action_string); + rc = -EINVAL ; + } +for (i =1 ; i < argc; i++) { +fprintf (stderr,"unknown extra parameter \"%s\"\n" , argv[i]); + rc = -EINVAL ; + } + +if (rc) { +usage_with_options (u, options); +return NULL ; + } + +/* Handle action-agnostic options */ +if (param.verbose) +daxctl_set_log_priority (ctx,LOG_DEBUG ); +if (param.human) + flags |=UTIL_JSON_HUMAN ; + +/* Handle action-specific options */ +switch (action) { +case ACTION_RECONFIG :
daxctl/device.c line 109
Quoted 10 lines
daxctl/device.c new file +10
-0+if (!param.mode) { +fprintf (stderr,"error: a 'mode' option is required\n" ); +usage_with_options (u, reconfig_options); + rc = -EINVAL ; + } +if (strcmp (param.mode,"system-ram" ) ==0 ) { + reconfig_mode =DAXCTL_DEV_MODE_RAM ; +if (param.do_offline) { +fprintf (stderr, +"can't --attempt-offline for system-ram mode\n" );
I'm not sure I grok the --attempt-offline option. That seems like it belongs to its own command, and is required to succeed before daxctl disable-device. Or is this like a "--force" to disable and cleanup system-ram mode before moving to devdax mode. If it's the latter I'd prefer that was a --force option. Otherwise, the error message "can't --attempt-offline for system-ram mode\n" is confusing because offlining only makes sense for system-ram mode.
daxctl/device.c line 116
Quoted 7 lines
daxctl/device.c new file +7
-0+ rc = -EINVAL ; + } + }else if (strcmp (param.mode,"devdax" ) ==0 ) { + reconfig_mode =DAXCTL_DEV_MODE_DEVDAX ; +if (param.no_online) { +fprintf (stderr, +"can't --no-online for devdax mode\n" );
How about "--no-online option incompatible with --mode=devdax"?
Quoted 18 lines
daxctl/device.c new file +18
-0+ rc = -EINVAL ; + } + } +break ; + } +if (rc) { +usage_with_options (u, options); +return NULL ; + } + +return argv[0 ]; +} + +static int disable_devdax_device (struct daxctl_dev *dev) +{ +const char *devname =daxctl_dev_get_devname (dev); +enum daxctl_dev_mode mode; +int rc;
daxctl/device.c line 144
Quoted 10 lines
daxctl/device.c new file +10
-0+ + mode =daxctl_dev_get_mode (dev); +if (mode <0 ) { +fprintf (stderr,"%s: unable to determine current mode: %s\n" , + devname,strerror (-mode)); +return mode; + } +if (mode ==DAXCTL_DEV_MODE_RAM ) { +fprintf (stderr,"%s is in system-ram mode, nothing to do\n" , + devname);
"Nothing to do" implies "it is already disabled", this is just "not supported" until integrating with v5.3, right?
Quoted 27 lines
daxctl/device.c new file +27
-0+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 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 ; + +if (daxctl_dev_is_enabled (dev)) { + rc =disable_devdax_device (dev); +if (rc <0 ) +return rc; +if (rc >0 ) + skip_enable =1 ; + } + +if (!skip_enable) { + rc =daxctl_dev_enable_ram (dev);
daxctl/device.c line 181
Quoted 10 lines
daxctl/device.c new file +10
-0+if (rc) +return rc; + } + +if (param.no_online) +return 0 ; + + rc =daxctl_memory_set_online (mem); +if (rc <0 ) { + fprintf(stderr, "%s: unable to online memory: %s\n",
s/unable/failed/
I didn't comment earlier, but if it's not too late I think 'daxctl_memory_{on,off}line()' is sufficient, no need for 'set_'.
Quoted 11 lines
daxctl/device.c new file +11
-0+ devname, strerror(-rc)); +return rc; + } +if (param.verbose) +fprintf (stderr,"%s: onlined %d memory sections\n" , + devname, rc); + +return 0 ; +} + +static int disable_system_ram_device (struct daxctl_dev *dev)
daxctl/device.c line 202
Quoted 10 lines
daxctl/device.c new file +10
-0+{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev); +enum daxctl_dev_mode mode; +int rc; + + mode =daxctl_dev_get_mode (dev); +if (mode <0 ) { +fprintf (stderr,"%s: unable to determine current mode: %s\n" , + devname,strerror (-mode));
When would this happen in practice? I can only think it would happen when using the old device model in which case we could fall through to the "already in devdax mode" case.
daxctl/device.c line 214
Quoted 12 lines
daxctl/device.c new file +12
-0+return mode; + } +if (mode ==DAXCTL_DEV_MODE_DEVDAX ) { +fprintf (stderr,"%s: already in devdax mode, nothing to do\n" , + devname); +return 1 ; + } + +if (param.do_offline) { + rc =daxctl_memory_set_offline (mem); +if (rc <0 ) { + fprintf(stderr, "%s: unable to offline memory: %s\n",
s/unable/failed/
...and same comment about dropping '_set'. Is there an api to retrieve the number of memory blocks / sections behind daxctl_memory instance? Then you could also check for the number of sections offlined < total sections case. The most likely case is that a single section is holding up the offline process and someone might want to interrogate which one that is relative to the device instance.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Verma, Vishal L
maintainerQuoted 20 lines · Dan Williams
Quoted 19 lines · Vishal Verma
Add a new command 'daxctl-reconfigure-device'. This is used to switch the mode of a dax device between regular '
device_dax' and 'system-memory'. The command also uses the memory hotplug sysfs interfaces to online the newly available memory when converting to 'system-ram', and to attempt to offline the memory when converting back to a DAX device.Cc Pavel Tatashin <[email protected]>Cc Dave Hansen <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- daxctl/Makefile.am | 2 + daxctl/builtin.h | 1 + daxctl/daxctl.c | 1 + daxctl/device.c | 348 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 352 insertions(+) create mode 100644 daxctl/device.c
[..]
Quoted 12 lines
daxctl/device.c line 109
Quoted 11 lines
daxctl/device.c new file +11
-0+case ACTION_RECONFIG : +if (!param.mode) { +fprintf (stderr,"error: a 'mode' option is required\n" ); +usage_with_options (u, reconfig_options); + rc = -EINVAL ; + } +if (strcmp (param.mode,"system-ram" ) ==0 ) { + reconfig_mode =DAXCTL_DEV_MODE_RAM ; +if (param.do_offline) { +fprintf (stderr, +"can't --attempt-offline for system-ram mode\n" );
Quoted 7 lines
I'm not sure I grok the --attempt-offline option. That seems like it belongs to its own command, and is required to succeed before daxctl disable-device. Or is this like a "--force" to disable and cleanup system-ram mode before moving to devdax mode. If it's the latter I'd prefer that was a --force option. Otherwise, the error message "can't --attempt-offline for system-ram mode\n" is confusing because offlining only makes sense for system-ram mode.
Yes it is like the --force option to other disable/destroy commands - I agree that's clearer. I'll change it.
Quoted 10 lines
daxctl/device.c line 116
Quoted 8 lines
daxctl/device.c new file +7
-0+ rc = -EINVAL ; + } + }else if (strcmp (param.mode,"devdax" ) ==0 ) { + reconfig_mode =DAXCTL_DEV_MODE_DEVDAX ; +if (param.no_online) { +fprintf (stderr, +"can't --no-online for devdax mode\n" );How about "--no-online option incompatible with --mode=devdax"?
Sounds good.
Quoted 24 lines
Quoted 24 lines
daxctl/device.c new file +23
-0+ rc = -EINVAL ; + } + } +break ; + } +if (rc) { +usage_with_options (u, options); +return NULL ; + } + +return argv[0 ]; +} + +static int disable_devdax_device (struct daxctl_dev *dev) +{ +const char *devname =daxctl_dev_get_devname (dev); +enum daxctl_dev_mode mode; +int rc; + + mode =daxctl_dev_get_mode (dev); +if (mode <0 ) { +fprintf (stderr,"%s: unable to determine current mode: %s\n" , + devname,strerror (-mode));
Quoted 8 lines
daxctl/device.c line 144
Quoted 5 lines
daxctl/device.c new file +5
-0+return mode; + } +if (mode ==DAXCTL_DEV_MODE_RAM ) { +fprintf (stderr,"%s is in system-ram mode, nothing to do\n" , + devname);"Nothing to do" implies "it is already disabled", this is just "not supported" until integrating with v5.3, right?
It implies that we are already in system-ram mode when --mode=system-ram was asked, and there really is nothing to do. Except possibly online the memory if it is not online, and we still do that down below. We don't really attempt to detect the v5.3 hot-remove support - if it is not present, the removal will simply fail.
Quoted 41 lines
Quoted 28 lines
daxctl/device.c new file +27
-0+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 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 ; + +if (daxctl_dev_is_enabled (dev)) { + rc =disable_devdax_device (dev); +if (rc <0 ) +return rc; +if (rc >0 ) + skip_enable =1 ; + } + +if (!skip_enable) { + rc =daxctl_dev_enable_ram (dev);daxctl/device.c line 181
Quoted 10 lines
daxctl/device.c new file +10
-0+if (rc) +return rc; + } + +if (param.no_online) +return 0 ; + + rc =daxctl_memory_set_online (mem); +if (rc <0 ) { + fprintf(stderr, "%s: unable to online memory: %s\n",s/unable/failed/
Quoted 2 lines
I didn't comment earlier, but if it's not too late I think 'daxctl_memory_{on,off}line()' is sufficient, no need for '
set_'.
Yep, will change both.
Quoted 18 lines
Quoted 18 lines
daxctl/device.c new file +17
-0+ devname, strerror(-rc)); +return rc; + } +if (param.verbose) +fprintf (stderr,"%s: onlined %d memory sections\n" , + devname, rc); + +return 0 ; +} + +static int disable_system_ram_device (struct daxctl_dev *dev) +{ +struct daxctl_memory *mem =daxctl_dev_get_memory (dev); +const char *devname =daxctl_dev_get_devname (dev); +enum daxctl_dev_mode mode; +int rc; +
Quoted 8 lines
daxctl/device.c line 139
Quoted 4 lines
daxctl/device.c new file +4
-0+ mode =daxctl_dev_get_mode (dev); +if (mode <0 ) { +fprintf (stderr,"%s: unable to determine current mode: %s\n" , + devname,strerror (-mode));When would this happen in practice? I can only think it would happen when using the old device model in which case we could fall through to the "already in devdax mode" case.
Right with the v7 .._get_memory() interface to detect the mode, this goes away.
Quoted 14 lines
daxctl/device.c line 214
Quoted 13 lines
daxctl/device.c new file +12
-0+return mode; + } +if (mode ==DAXCTL_DEV_MODE_DEVDAX ) { +fprintf (stderr,"%s: already in devdax mode, nothing to do\n" , + devname); +return 1 ; + } + +if (param.do_offline) { + rc =daxctl_memory_set_offline (mem); +if (rc <0 ) { + fprintf(stderr, "%s: unable to offline memory: %s\n",
Quoted 8 lines
s/unable/failed/
...and same comment about dropping '
_set'. Is there an api to retrieve the number of memory blocks / sections behinddaxctl_memoryinstance? Then you could also check for the number of sections offlined < total sections case. The most likely case is that a single section is holding up the offline process and someone might want to interrogate which one that is relative to the device instance.
There is not an interface to query the number of blocks directly, but if we fail to online/offline a given memblock, we print it in debug/verbose logging. It wouldn't be too hard to add an interface to get the total number of blocks, but it would still be hard for the daxctl side to determine /which/ block it was, as it is only libdaxctl that loops through all the blocks and sets their state (so to find which one would have to go to the debug logs anyway). I think there is still value in letting the user know that something unexpected happened - I can look into adding that.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 8/13 Documentation/daxctl: add a man page for daxctl-reconfigure-device
In reply to Vishal VermaAdd a man page describing the new daxctl-reconfigure-device command.
--- Documentation/daxctl/Makefile.am | 3 +- .../daxctl/daxctl-reconfigure-device.txt | 139 ++++++++++++++++++ 2 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 Documentation/daxctl/daxctl-reconfigure-device.txt
Documentation/daxctl/Makefile.am +2 -1
@@ -28,7 +28,8 @@ endif man1_MANS = \ daxctl.1 \ daxctl-list.1 \ - daxctl-migrate-device-model.1 + daxctl-migrate-device-model.1 \ + daxctl-reconfigure-device.1 CLEANFILES = $(man1_MANS)
Documentation/daxctl/daxctl-reconfigure-device.txt new file +139 -0
139 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 9/13 daxctl: add commands to online and offline memory
In reply to Vishal VermaAdd two new commands:
daxctl-online-memory
daxctl-offline-memory
to manage the state of hot-plugged memory from the system-ram mode for dax devices. This provides a way for the user to online/offline the memory as a separate step from the reconfiguration. Without this, a user that reconfigures a device into the system-ram mode with the --no-online option, would have no way to later online the memory, and would have to resort to shell scripting to online them manually via sysfs.
--- daxctl/builtin.h | 2 + daxctl/daxctl.c | 2 + daxctl/device.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 141 insertions(+), 1 deletion(-)
daxctl/builtin.h +2 -0
@@ -7,4 +7,6 @@ struct daxctl_ctx;int cmd_list (int argc,const char **argv,struct daxctl_ctx *ctx);int cmd_migrate (int argc,const char **argv,struct daxctl_ctx *ctx);int cmd_reconfig_device (int argc,const char **argv,struct daxctl_ctx *ctx); +int cmd_online_memory (int argc,const char **argv,struct daxctl_ctx *ctx); +int cmd_offline_memory (int argc,const char **argv,struct daxctl_ctx *ctx);#endif /* _DAXCTL_BUILTIN_H_ */
daxctl/daxctl.c +2 -0
@@ -72,6 +72,8 @@ static struct cmd_struct commands[] = { { "help", .d_fn = cmd_help }, { "migrate-device-model", .d_fn = cmd_migrate }, { "reconfigure-device", .d_fn = cmd_reconfig_device }, + { "online-memory", .d_fn = cmd_online_memory }, + { "offline-memory", .d_fn = cmd_offline_memory }, };int main (int argc,const char **argv)
daxctl/device.c +137 -1
184 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 10/13 Documentation: Add man pages for daxctl-{on, off}line-memory
In reply to Vishal VermaAdd man pages for the two new commands: daxctl-online-memory, and daxctl-offline-memory.
--- Documentation/daxctl/Makefile.am | 4 +- .../daxctl/daxctl-offline-memory.txt | 72 +++++++++++++++++ Documentation/daxctl/daxctl-online-memory.txt | 80 +++++++++++++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 Documentation/daxctl/daxctl-offline-memory.txt create mode 100644 Documentation/daxctl/daxctl-online-memory.txt
Documentation/daxctl/Makefile.am +3 -1
@@ -29,7 +29,9 @@ man1_MANS = \ daxctl.1 \ daxctl-list.1 \ daxctl-migrate-device-model.1 \ - daxctl-reconfigure-device.1 + daxctl-reconfigure-device.1 \ + daxctl-online-memory.1 \ + daxctl-offline-memory.1 CLEANFILES = $(man1_MANS)
Documentation/daxctl/daxctl-offline-memory.txt new file +72 -0
72 lines not on this page · raw message
Documentation/daxctl/daxctl-online-memory.txt new file +80 -0
80 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 11/13 contrib/ndctl: fix region-id completions for daxctl
In reply to Vishal VermaThe completion helpers for daxctl assumed the region arguments for specifying daxctl regions were the same as ndctl regions, i.e. "regionX". This is not true - daxctl region arguments are a simple numeric 'id'.
Add a new helper __daxctl_get_regions() to complete daxctl region IDs properly.
While at it, fix a useless use of 'echo' in __daxctl_get_devs() and quoting in __daxctl_comp_options()
--- contrib/ndctl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
contrib/ndctl +10 -4
@@ -531,8 +531,14 @@ _ndctl() __daxctl_get_devs() { - local opts="--devices $*" - echo "$(daxctl list $opts | grep -E "^\s*\"chardev\":" | cut -d\" -f4)" + local opts=("--devices" "$*") + daxctl list "${opts[@]}" | grep -E "^\s*\"chardev\":" | cut -d'"' -f4 +} + +__daxctl_get_regions() +{ + local opts=("--regions" "$*") + daxctl list "${opts[@]}" | grep -E "^\s*\"id\":" | grep -Eo "[0-9]+" } __daxctlcomp()
@@ -561,10 +567,10 @@ __daxctl_comp_options() local cur_arg=${cur##*=} case $cur_subopt in --region) - opts=$(__ndctl_get_regions -i) + opts="$(__daxctl_get_regions -i)" ;; --dev) - opts=$(__daxctl_get_devs -i) + opts="$(__daxctl_get_devs -i)" ;; *) return
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 12/13 contrib/ndctl: add bash-completion for the new daxctl commands
In reply to Vishal VermaAdd bash completion helpers for the new daxctl-reconfigure-device, daxctl-online-memory, and daxctl-offline-memory commands.
--- contrib/ndctl | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
contrib/ndctl +21 -3
@@ -547,7 +547,7 @@ __daxctlcomp() COMPREPLY=( $( compgen -W "$1" -- "$2" ) ) for cword in "${COMPREPLY[@]}"; do - if [[ "$cword" == @(--region|--dev) ]]; then + if [[ "$cword" == @(--region|--dev|--mode) ]]; then COMPREPLY[$i]="${cword}=" else COMPREPLY[$i]="${cword} "
@@ -572,6 +572,9 @@ __daxctl_comp_options() --dev) opts="$(__daxctl_get_devs -i)" ;; + --mode) + opts="system-ram devdax" + ;; *) return ;;
@@ -582,8 +585,23 @@ __daxctl_comp_options() __daxctl_comp_non_option_args() { - # there aren't any commands that accept non option arguments yet - return + local subcmd=$1 + local cur=$2 + local opts + + case $subcmd in + reconfigure-device) + ;& + online-memory) + ;& + offline-memory) + opts="$(__daxctl_get_devs -i) all" + ;; + *) + return + ;; + esac + __daxctlcomp "$opts" "$cur" } __daxctl_main()
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH v6 13/13 test: Add a unit test for daxctl-reconfigure-device and friends
In reply to Vishal VermaAdd a new unit test to test dax device reconfiguration and memory operations. This teaches test/common about daxctl, and adds an ACPI.NFIT bus variable. Since we have to operate on the ACPI.NFIT bus, the test is marked as destructive.
--- test/Makefile.am | 3 +- test/common | 19 ++++++++-- test/daxctl-devices.sh | 81 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 4 deletions(-) create mode 100755 test/daxctl-devices.sh
test/Makefile.am +2 -1
@@ -49,7 +49,8 @@ TESTS +=\ dax.sh \ device-dax \ device-dax-fio.sh \ - mmap.sh + mmap.sh \ + daxctl-devices.sh if ENABLE_KEYUTILS TESTS += security.sh
test/common +16 -3
@@ -15,12 +15,25 @@ else exit 1 fi -# NFIT_TEST_BUS[01] +# DAXCTL # -NFIT_TEST_BUS0=nfit_test.0 -NFIT_TEST_BUS1=nfit_test.1 +if [ -f "../daxctl/daxctl" ] && [ -x "../daxctl/daxctl" ]; then + export DAXCTL=../daxctl/daxctl +elif [ -f "./daxctl/daxctl" ] && [ -x "./daxctl/daxctl" ]; then + export DAXCTL=./daxctl/daxctl +else + echo "Couldn't find an daxctl binary" + exit 1 +fi +# NFIT_TEST_BUS[01] +# +NFIT_TEST_BUS0="nfit_test.0" +NFIT_TEST_BUS1="nfit_test.1" +ACPI_BUS="ACPI.NFIT" +E820_BUS="e820" + # Functions # err
test/daxctl-devices.sh new file +81 -0
81 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm