Policy based reconfiguration for daxctl
Subsystems (3)
Vishal Verma
maintainerv2 cover Policy based reconfiguration for daxctl
Changes since v1[1]:
- Collect review tags
- Fix 'make clean' removing the reconfigure script from the source tree (Fenghua, Qi)
- Documentation wordsmithing (Dan)
- Fix line break after declarations in parse-configs.c (Dan)
- Move daxctl config files to its own directory, /etc/daxctl/ (Dan)
- Improve failure mode in the absence of a configs directory
- Rename {nd,dax}ctl_{get|set}_configs to {nd,dax}ctl_{get|set}_configs_dir
- Exit with success if -C is specified, but no matching config section is found.
- Refuse to proceed if CLI options are passed in along with -C (Dan)
- In the config file, rename: s/[auto-online foo]/[reconfigure-device foo/ and s/uuid/nvdimm.uuid/ (Dan)
- Teach device.c to accept /dev/daxX.Y instead of only daxX.Y and thus remove the need for a wrapper script that systemd invokes (Dan)
These patches add policy (config file) support to daxctl. The introductory user is daxctl-reconfigure-device. Sysadmins may wish to use daxctl devices as system-ram, but it may be cumbersome to automate the reconfiguration step for every device upon boot.
Introduce a new option for daxctl-reconfigure-device, --check-config. This is at the heart of policy based reconfiguration, as it allows daxctl to look up reconfiguration parameters for a given device from the config system instead of the command line.
Some systemd and udev glue then automates this for every new dax device that shows up, providing a way for the administrator to simply list all the 'system-ram' UUIDs in a config file, and not have to worry about anything else.
An example config file can be:
# cat /etc/ndctl/daxctl.conf
[reconfigure-device unique_identifier_foo] nvdimm.uuid = 48d8e42c-a2f0-4312-9e70-a837faafe862 mode = system-ram
online = true
movable = false
Any file under '/etc/ndctl/' can be used - all files with a '.conf' suffix will be considered when looking for matches.
These patches depend on the initial config file support from Qi Fuli[2].
I've re-rolled Qi's original patches as the first five patches in this series because of a change I made for graceful handling in the case of a missing configs directory, and also to incorporate review feedback that applied to the dependant patches. Patch 6 onwards is the actual v2 of the daxctl policy work.
A branch containing these patches is available at [3].
[1]: https://lore.kernel.org/nvdimm/[email protected]/
[2]: https://lore.kernel.org/nvdimm/[email protected]/
[3]: https://github.com/pmem/ndctl/tree/vv/daxctl_config_v2
QI Fuli (5):
ndctl, util: add iniparser helper
ndctl, util: add parse-configs helper
ndctl: make ndctl support configuration files
ndctl, config: add the default ndctl configuration file ndctl, monitor: refator monitor for supporting multiple config files
Vishal Verma (7):
ndctl: Update ndctl.spec.in for 'ndctl.conf'
daxctl: Documentation updates for persistent reconfiguration util/parse-config: refactor filter_conf_files into util/
daxctl: add basic config parsing support util/parse-configs: add a key/value search helper daxctl/device.c: add an option for getting params from a config file
daxctl: add systemd service and udev rule for automatic
reconfiguration
.../daxctl/daxctl-reconfigure-device.txt | 75 ++ Documentation/ndctl/ndctl-monitor.txt | 8 +- configure.ac | 18 +- Makefile.am | 8 +- ndctl/lib/private.h | 1 + daxctl/lib/libdaxctl.c | 39 + ndctl/lib/libndctl.c | 39 + daxctl/libdaxctl.h | 2 + ndctl/libndctl.h | 2 + util/dictionary.h | 175 ++++ util/iniparser.h | 360 ++++++++ util/parse-configs.h | 53 ++ daxctl/daxctl.c | 1 + daxctl/device.c | 174 +++- ndctl/monitor.c | 73 +- ndctl/ndctl.c | 1 + util/dictionary.c | 383 ++++++++ util/iniparser.c | 838 ++++++++++++++++++ util/parse-configs.c | 150 ++++ Documentation/daxctl/Makefile.am | 11 +- Documentation/ndctl/Makefile.am | 2 +- daxctl/90-daxctl-device.rules | 1 + daxctl/Makefile.am | 9 + daxctl/[email protected] | 8 + daxctl/lib/Makefile.am | 6 + daxctl/lib/libdaxctl.sym | 2 + ndctl.spec.in | 4 + ndctl/Makefile.am | 9 +- ndctl/lib/Makefile.am | 6 + ndctl/lib/libndctl.sym | 2 + ndctl/ndctl.conf | 56 ++ 31 files changed, 2467 insertions(+), 49 deletions(-) create mode 100644 util/dictionary.h create mode 100644 util/iniparser.h create mode 100644 util/parse-configs.h create mode 100644 util/dictionary.c create mode 100644 util/iniparser.c create mode 100644 util/parse-configs.c create mode 100644 daxctl/90-daxctl-device.rules create mode 100644 daxctl/[email protected] create mode 100644 ndctl/ndctl.conf
base-commit: 4e646fa490ba4b782afa188dd8818b94c419924e
Signature · 1 line
2.33.1
Vishal Verma
maintainerPATCH v2 1/12 ndctl, util: add iniparser helper
From: QI Fuli <[email protected]>
Add iniparser[1] helper for parsing ndctl global configuration files.
[1] https://github.com/ndevilla/iniparser
--- Makefile.am | 6 +- util/dictionary.h | 175 ++++++++++ util/iniparser.h | 360 ++++++++++++++++++++ util/dictionary.c | 383 +++++++++++++++++++++ util/iniparser.c | 838 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1761 insertions(+), 1 deletion(-) create mode 100644 util/dictionary.h create mode 100644 util/iniparser.h create mode 100644 util/dictionary.c create mode 100644 util/iniparser.c
Makefile.am +5 -1
@@ -85,6 +85,10 @@ libutil_a_SOURCES = \ util/size.h \ util/main.h \ util/filter.h \ - util/bitmap.h + util/bitmap.h \ + util/dictionary.c \ + util/dictionary.h \ + util/iniparser.c \ + util/iniparser.h nobase_include_HEADERS = daxctl/libdaxctl.h
util/dictionary.h new file +175 -0
175 lines not on this page · raw message
util/iniparser.h new file +360 -0
360 lines not on this page · raw message
util/dictionary.c new file +383 -0
383 lines not on this page · raw message
util/iniparser.c new file +838 -0
838 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [ndctl PATCH v2 01/12] ndctl, util: add iniparser helper
Quoted 5 lines · Vishal Verma
From: QI Fuli <[email protected]>
Add iniparser[1] helper for parsing ndctl global configuration files.
[1] https://github.com/ndevilla/iniparser
Is there a reason this is being copied rather than linked? The ccan code was copied because no distribution packaged it up into library form, but iniparser ships in Fedora and Ubuntu. Unless ndctl needs to maintain a fork I would prefer to link just like json-c is linked. Even if ndctl needs a fork I would expect that to be called out here with a plan to eventually get that forked feature into the upstream iniparser project.
Verma, Vishal L
maintainerRe: [ndctl PATCH v2 01/12] ndctl, util: add iniparser helper
Quoted 7 lines · Dan Williams
Quoted 5 lines · Vishal Verma
From: QI Fuli <[email protected]>
Add iniparser[1] helper for parsing ndctl global configuration files.
[1] https://github.com/ndevilla/iniparser
Quoted 7 lines
Is there a reason this is being copied rather than linked? The ccan code was copied because no distribution packaged it up into library form, but iniparser ships in Fedora and Ubuntu. Unless ndctl needs to maintain a fork I would prefer to link just like json-c is linked. Even if ndctl needs a fork I would expect that to be called out here with a plan to eventually get that forked feature into the upstream iniparser project.
Ah I didn't realize it was packaged. I don't think we needed any changes to the core package - I'll change it to a linked dependency and remove the fork.
Vishal Verma
maintainerPATCH v2 2/12 ndctl, util: add parse-configs helper
In reply to Vishal VermaFrom: QI Fuli <[email protected]>
Add parse-config util to help ndctl commands parse ndctl global configuration files.
--- Makefile.am | 2 ++ util/parse-configs.h | 34 ++++++++++++++++++ util/parse-configs.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 util/parse-configs.h create mode 100644 util/parse-configs.c
Makefile.am +2 -0
@@ -70,6 +70,8 @@ noinst_LIBRARIES += libutil.a libutil_a_SOURCES = \ util/parse-options.c \ util/parse-options.h \ + util/parse-configs.c \ + util/parse-configs.h \ util/usage.c \ util/size.c \ util/main.c \
util/parse-configs.h new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2021, FUJITSU LIMITED. ALL rights reserved. + +#include <stdbool.h> +#include <stdint.h> +#include <util/util.h> + +enum parse_conf_type { +CONFIG_STRING , +CONFIG_END , +MONITOR_CALLBACK , +}; + +struct config ; +typedef int parse_conf_cb (const struct config *,const char *config_file); + +struct config { +enum parse_conf_type type; +const char *key; +void *value; +void *defval; +parse_conf_cb *callback; +}; + +#define check_vtype (v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) + +#define CONF_END () { .type = CONFIG_END } +#define CONF_STR (k,v,d) \ + { .type = CONFIG_STRING, .key = (k), .value = check_vtype(v, const char **), .defval = (d) } +#define CONF_MONITOR (k,f) \ + { .type = MONITOR_CALLBACK, .key = (k), .callback = (f)} + +int parse_configs_prefix (const char *__config_file,const char *prefix, +const struct config *configs);
util/parse-configs.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [ndctl PATCH v2 02/12] ndctl, util: add parse-configs helper
Quoted 5 lines · Vishal Verma
From: QI Fuli <[email protected]>
Add parse-config util to help ndctl commands parse ndctl global configuration files.
Can this add a bit more description / quick summary of how these APIs are used?
Quoted 2 lines
This link is pointing to the original posting I would expect that this gets deleted and replaced with the final Link: to the version of the patch that eventually gets applied. I assume you just pulled the patches down and this link get appended in the resend.
Quoted 154 lines
Signed-off-by QI Fuli <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- Makefile.am | 2 ++ util/parse-configs.h | 34 ++++++++++++++++++ util/parse-configs.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 util/parse-configs.h create mode 100644 util/parse-configs.cMakefile.am +2
-0@@ -70,6 +70,8 @@ noinst_LIBRARIES += libutil.a libutil_a_SOURCES = \ util/parse-options.c \ util/parse-options.h \ + util/parse-configs.c \ + util/parse-configs.h \ util/usage.c \ util/size.c \ util/main.c \util/parse-configs.h new file +34
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2021, FUJITSU LIMITED. ALL rights reserved. + +#include <stdbool.h> +#include <stdint.h> +#include <util/util.h> + +enum parse_conf_type { +CONFIG_STRING , +CONFIG_END , +MONITOR_CALLBACK , +}; + +struct config ; +typedef int parse_conf_cb (const struct config *,const char *config_file); + +struct config { +enum parse_conf_type type; +const char *key; +void *value; +void *defval; +parse_conf_cb *callback; +}; + +#define check_vtype (v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) + +#define CONF_END () { .type = CONFIG_END } +#define CONF_STR (k,v,d) \ + { .type = CONFIG_STRING, .key = (k), .value = check_vtype(v, const char **), .defval = (d) } +#define CONF_MONITOR (k,f) \ + { .type = MONITOR_CALLBACK, .key = (k), .callback = (f)} + +int parse_configs_prefix (const char *__config_file,const char *prefix, +const struct config *configs);util/parse-configs.c new file +82
-1@@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2021, FUJITSU LIMITED. ALL rights reserved. + +#include <errno.h> +#include <util/parse-configs.h> +#include <util/strbuf.h> +#include <util/iniparser.h> + +static void set_str_val (const char **value,const char *val) +{ +struct strbuf buf =STRBUF_INIT ; +size_t len = *value ?strlen (*value) :0 ; + +if (!val) +return ; + +if (len) { +strbuf_add (&buf, *value, len); +strbuf_addstr (&buf," " ); + } +strbuf_addstr (&buf, val); + *value =strbuf_detach (&buf,NULL ); +} + +static int parse_config_file (const char *config_file, +const struct config *configs) +{ +dictionary *dic; + + dic =iniparser_load (config_file); +if (!dic) +return -errno; + +for (; configs->type !=CONFIG_END ; configs++) { +switch (configs->type) { +case CONFIG_STRING : +set_str_val ((const char **)configs->value, +iniparser_getstring (dic, + configs->key, configs->defval)); +break ; +case MONITOR_CALLBACK : +case CONFIG_END : +break ; + } + } + +iniparser_freedict (dic); +return 0 ; +} + +int parse_configs_prefix (const char *__config_files,const char *prefix, +const struct config *configs) +{ +char *config_files, *save; +const char *config_file; +int rc; + + config_files =strdup (__config_files); +if (!config_files) +return -ENOMEM ; + +for (config_file =strtok_r (config_files," " , &save); config_file; + config_file =strtok_r (NULL ," " , &save)) { + +if (strncmp (config_file,"./" ,2 ) !=0 ) +fix_filename (prefix, &config_file); + +if ((configs->type ==MONITOR_CALLBACK ) && + (strcmp (config_file, configs->key) ==0 )) + rc = configs->callback (configs, configs->key); +else + rc =parse_config_file (config_file, configs); + +if (rc) + goto end; + } + + end: +free (config_files); +return rc; + +} --2.33.1
Vishal Verma
maintainerPATCH v2 3/12 ndctl: make ndctl support configuration files
In reply to Vishal VermaFrom: QI Fuli <[email protected]>
Add ndctl_configs to ndctl_ctx for supporting ndctl global configuration files. All files with .conf suffix under {sysconfdir}/ndctl can be regarded as global configuration files that all ndctl commands can refer to. Add ndctl_set_configs() public function for setting ndctl default configuration files' path. Add ndctl_get_configs() public function for getting ndctl configuration files' path form ndctl_ctx.
--- configure.ac | 4 ++-- ndctl/lib/private.h | 1 + ndctl/lib/libndctl.c | 54 ++++++++++++++++++++++++++++++++++++++++++ ndctl/libndctl.h | 2 ++ ndctl/ndctl.c | 1 + ndctl/Makefile.am | 5 ++-- ndctl/lib/Makefile.am | 4 ++++ ndctl/lib/libndctl.sym | 2 ++ 8 files changed, 69 insertions(+), 4 deletions(-)
configure.ac +2 -2
@@ -171,9 +171,9 @@ fi AC_SUBST([systemd_unitdir]) AM_CONDITIONAL([ENABLE_SYSTEMD_UNITS], [test "x$with_systemd" = "xyes"]) -ndctl_monitorconfdir=${sysconfdir}/ndctl +ndctl_confdir=${sysconfdir}/ndctl ndctl_monitorconf=monitor.conf -AC_SUBST([ndctl_monitorconfdir]) +AC_SUBST([ndctl_confdir]) AC_SUBST([ndctl_monitorconf]) daxctl_modprobe_datadir=${datadir}/daxctl
ndctl/lib/private.h +1 -0
@@ -129,6 +129,7 @@ struct ndctl_ctx {int regions_init;void *userdata;struct list_head busses; +const char *configs;int busses_init;struct udev *udev;struct udev_queue *udev_queue;
ndctl/lib/libndctl.c +54 -0
72 lines not on this page · raw message
ndctl/libndctl.h +2 -0
@@ -92,6 +92,8 @@ int ndctl_get_log_priority(struct ndctl_ctx *ctx);void ndctl_set_log_priority (struct ndctl_ctx *ctx,int priority);void ndctl_set_userdata (struct ndctl_ctx *ctx,void *userdata);void *ndctl_get_userdata (struct ndctl_ctx *ctx); +void ndctl_set_configs_dir (struct ndctl_ctx **ctx,char *conf_dir); +const char *ndctl_get_configs_dir (struct ndctl_ctx *ctx);enum ndctl_persistence_domain {PERSISTENCE_NONE =0 ,
ndctl/ndctl.c +1 -0
@@ -125,6 +125,7 @@ int main(int argc, const char **argv) rc =ndctl_new (&ctx);if (rc) goto out; +ndctl_set_configs_dir (&ctx,NDCTL_CONF_DIR );main_handle_internal_command (argc, argv, ctx, commands,ARRAY_SIZE (commands),PROG_NDCTL );ndctl_unref (ctx);
ndctl/Makefile.am +3 -2
@@ -7,8 +7,9 @@ BUILT_SOURCES = config.h config.h: $(srcdir)/Makefile.am $(AM_V_GEN) echo "/* Autogenerated by ndctl/Makefile.am */" >$@ && \ echo '#define NDCTL_CONF_FILE \ - "$(ndctl_monitorconfdir)/$(ndctl_monitorconf)"' >>$@ + "$(ndctl_confdir)/$(ndctl_monitorconf)"' >>$@ $(AM_V_GEN) echo '#define NDCTL_KEYS_DIR "$(ndctl_keysdir)"' >>$@ + $(AM_V_GEN) echo '#define NDCTL_CONF_DIR "$(ndctl_confdir)"' >>$@ ndctl_SOURCES = ndctl.c \ builtin.h \
@@ -73,7 +74,7 @@ ndctl_SOURCES += ../test/libndctl.c \ test.c endif -monitor_configdir = $(ndctl_monitorconfdir) +monitor_configdir = $(ndctl_confdir) monitor_config_DATA = $(ndctl_monitorconf) if ENABLE_SYSTEMD_UNITS
ndctl/lib/Makefile.am +4 -0
@@ -14,6 +14,10 @@ libndctl_la_SOURCES =\ ../../util/log.h \ ../../util/sysfs.c \ ../../util/sysfs.h \ + ../../util/strbuf.h \ + ../../util/strbuf.c \ + ../../util/wrapper.c \ + ../../util/usage.c \ ../../util/fletcher.h \ dimm.c \ inject.c \
ndctl/lib/libndctl.sym +2 -0
@@ -454,4 +454,6 @@ LIBNDCTL_25 { LIBNDCTL_26 { ndctl_bus_nfit_translate_spa; + ndctl_set_configs_dir; + ndctl_get_configs_dir; } LIBNDCTL_25;
Signature · 1 line
2.33.1
Re: [ndctl PATCH v2 03/12] ndctl: make ndctl support configuration files
Quoted 5 lines · Vishal Verma
From: QI Fuli <[email protected]>
Add
ndctl_configstondctl_ctxfor supporting ndctl global configuration files. All files with .conf suffix under {sysconfdir}/ndctl can be
I expect this should be named a ".d" directory to match expectations of when a directory supports multiple config-file snippets. Either "{sysconfdir}/ndctl/ndctl.d", "{sysconfdir}/ndctl/conf.d", ""{sysconfdir}/ndctl.d" would be ok with me. "{sysconfdir}/ndctl" is still needed for the security keys.
Quoted 4 lines
regarded as global configuration files that all ndctl commands can refer to. Add
ndctl_set_configs()public function for setting ndctl default configuration files' path. Addndctl_get_configs()public function for getting ndctl configuration files' path formndctl_ctx.
s/form/from/
Lets those ndctl_{get,set}_config_path().
Quoted 56 lines
Signed-off-by QI Fuli <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- configure.ac | 4 ++-- ndctl/lib/private.h | 1 + ndctl/lib/libndctl.c | 54 ++++++++++++++++++++++++++++++++++++++++++ ndctl/libndctl.h | 2 ++ ndctl/ndctl.c | 1 + ndctl/Makefile.am | 5 ++-- ndctl/lib/Makefile.am | 4 ++++ ndctl/lib/libndctl.sym | 2 ++ 8 files changed, 69 insertions(+), 4 deletions(-)configure.ac +2
-2@@ -171,9 +171,9 @@ fi AC_SUBST([systemd_unitdir]) AM_CONDITIONAL([ENABLE_SYSTEMD_UNITS], [test "x$with_systemd" = "xyes"]) -ndctl_monitorconfdir=${sysconfdir}/ndctl +ndctl_confdir=${sysconfdir}/ndctl ndctl_monitorconf=monitor.conf -AC_SUBST([ndctl_monitorconfdir]) +AC_SUBST([ndctl_confdir]) AC_SUBST([ndctl_monitorconf]) daxctl_modprobe_datadir=${datadir}/daxctlndctl/lib/private.h +1
-0@@ -129,6 +129,7 @@ struct ndctl_ctx {int regions_init;void *userdata;struct list_head busses; +const char *configs;int busses_init;struct udev *udev;struct udev_queue *udev_queue;ndctl/lib/libndctl.c +1
-0@@ -24,6 +24,7 @@#include <util/util.h> #include <util/size.h> #include <util/sysfs.h> +#include <util/strbuf.h> #include <ndctl/libndctl.h> #include <ndctl/namespace.h> #include <daxctl/libdaxctl.h>
ndctl/lib/libndctl.c NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) · line 275
Quoted 10 lines
ndctl/lib/libndctl.c +7
-0@@ -265,6 +266,58 @@ NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) ctx->userdata = userdata; } +static int filter_conf (const struct dirent *dir) +{ +if (!dir) +return 0 ; + +if (dir->d_type ==DT_REG ) { +const char *ext =strrchr (dir->d_name,'.' );
Oh, I guess clang-format does not insert line breaks between declarations and code.
ndctl/lib/libndctl.c NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) · line 285
Quoted 10 lines
ndctl/lib/libndctl.c +10
-0+if ((!ext) || (ext == dir->d_name)) +return 0 ; +if (strcmp (ext,".conf" ) ==0 ) +return 1 ; + } + +return 0 ; +} + +NDCTL_EXPORT void ndctl_set_configs_dir(struct ndctl_ctx **ctx, char *conf_dir)
ndctl_set_config_path
Why is ctx a 'struct ndctl_ctx **' instead of a 'struct ndctl_ctx *'?
ndctl/lib/libndctl.c NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) · line 291
Quoted 6 lines
ndctl/lib/libndctl.c +6
-0+{ +struct dirent **namelist; +struct strbuf value =STRBUF_INIT ; +int rc; + +if ((!ctx) || (!conf_dir))
I think this function needs to return an error. If someone does:ndctl_set_config_path(NULL, "/path") nothing will notify them that /path is not established as the config directory. The ENOENT check is helpful, but why not tell the caller?
Quoted 8 lines
ndctl/lib/libndctl.c +8
-0+return ; + + rc =scandir (conf_dir, &namelist, filter_conf, alphasort); +if (rc ==-1 ) { +if (errno !=ENOENT ) +err (*ctx,"scandir for configs failed: %s\n" , +strerror (errno)); +return ;
ndctl/lib/libndctl.c NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) · line 309
Quoted 10 lines
ndctl/lib/libndctl.c +10
-0+ } + +while (rc--) { +if (value.len) +strbuf_addstr (&value," " ); +strbuf_addstr (&value, conf_dir); +strbuf_addstr (&value,"/" ); +strbuf_addstr (&value, namelist[rc]->d_name); +free (namelist[rc]); + }
Any reason this needs to be converted to a space separated list? What if there are spaces in the path name?
This could just cache the scandir result in the ctx directly and skip the strbuf usage.
Quoted 15 lines
ndctl/lib/libndctl.c +11
-0+ (*ctx)->configs =strbuf_detach (&value,NULL ); +free (namelist); +} + +NDCTL_EXPORT const char *ndctl_get_configs_dir(struct ndctl_ctx *ctx) +{ +if (ctx ==NULL ) +return NULL ; +return ctx->configs; +} +/** * ndctl_new - instantiate a new library context * @ctx: context to establish
ndctl/lib/libndctl.c NDCTL_EXPORT int ndctl_new(struct ndctl_ctx **ctx) · line 387
Quoted 4 lines
ndctl/lib/libndctl.c +1
-0@@ -331,6 +384,7 @@ NDCTL_EXPORT int ndctl_new(struct ndctl_ctx **ctx) c->daxctl_ctx = daxctl_ctx;return 0 ; +
Unnecessary newline.
Quoted 21 lines
ndctl/lib/libndctl.c +0
-0err_ctx:daxctl_unref (daxctl_ctx); err_daxctl:ndctl/libndctl.h +2
-0@@ -92,6 +92,8 @@ int ndctl_get_log_priority(struct ndctl_ctx *ctx);void ndctl_set_log_priority (struct ndctl_ctx *ctx,int priority);void ndctl_set_userdata (struct ndctl_ctx *ctx,void *userdata);void *ndctl_get_userdata (struct ndctl_ctx *ctx); +void ndctl_set_configs_dir (struct ndctl_ctx **ctx,char *conf_dir); +const char *ndctl_get_configs_dir (struct ndctl_ctx *ctx);enum ndctl_persistence_domain {PERSISTENCE_NONE =0 ,ndctl/ndctl.c +0
-0
ndctl/ndctl.c int main(int argc, const char **argv) · line 128
Quoted 4 lines
ndctl/ndctl.c +1
-0@@ -125,6 +125,7 @@ int main(int argc, const char **argv) rc =ndctl_new (&ctx);if (rc) goto out; +ndctl_set_configs_dir (&ctx,NDCTL_CONF_DIR );
I expect this to happen by default in ndctl_new().
In fact, ndctl_new() might want to grow a config path argument to override the default.
Quoted 32 lines
ndctl/ndctl.c +0
-0main_handle_internal_command (argc, argv, ctx, commands,ARRAY_SIZE (commands),PROG_NDCTL );ndctl_unref (ctx);ndctl/Makefile.am +3
-2@@ -7,8 +7,9 @@ BUILT_SOURCES = config.h config.h: $(srcdir)/Makefile.am $(AM_V_GEN) echo "/* Autogenerated by ndctl/Makefile.am */" >$@ && \ echo '#define NDCTL_CONF_FILE \ - "$(ndctl_monitorconfdir)/$(ndctl_monitorconf)"' >>$@ + "$(ndctl_confdir)/$(ndctl_monitorconf)"' >>$@ $(AM_V_GEN) echo '#define NDCTL_KEYS_DIR "$(ndctl_keysdir)"' >>$@ + $(AM_V_GEN) echo '#define NDCTL_CONF_DIR "$(ndctl_confdir)"' >>$@ ndctl_SOURCES = ndctl.c \ builtin.h \@@ -73,7 +74,7 @@ ndctl_SOURCES += ../test/libndctl.c \ test.c endif -monitor_configdir = $(ndctl_monitorconfdir) +monitor_configdir = $(ndctl_confdir) monitor_config_DATA = $(ndctl_monitorconf) if ENABLE_SYSTEMD_UNITSndctl/lib/Makefile.am +0
-0
ndctl/lib/Makefile.am libndctl_la_SOURCES =\ · line 20
Quoted 7 lines
ndctl/lib/Makefile.am +4
-0@@ -14,6 +14,10 @@ libndctl_la_SOURCES =\ ../../util/log.h \ ../../util/sysfs.c \ ../../util/sysfs.h \ + ../../util/strbuf.h \ + ../../util/strbuf.c \ + ../../util/wrapper.c \ + ../../util/usage.c \
Seems this new utility code linking is not necessary per the above recommendation to just cache the scandir results in the ctx.
Quoted 17 lines
ndctl/lib/Makefile.am +0
-0../../util/fletcher.h \ dimm.c \ inject.c \ndctl/lib/libndctl.sym +2
-1@@ -454,4 +454,6 @@ LIBNDCTL_25 { LIBNDCTL_26 { ndctl_bus_nfit_translate_spa; + ndctl_set_configs_dir; + ndctl_get_configs_dir; } LIBNDCTL_25; --2.33.1
Verma, Vishal L
maintainerRe: [ndctl PATCH v2 03/12] ndctl: make ndctl support configuration files
Quoted 4 lines · Dan Williams
Quoted 3 lines · Vishal Verma
From: QI Fuli <[email protected]>
Quoted 8 lines
Quoted 2 lines
Add
ndctl_configstondctl_ctxfor supporting ndctl global configuration files. All files with .conf suffix under {sysconfdir}/ndctl can beI expect this should be named a ".d" directory to match expectations of when a directory supports multiple config-file snippets. Either "{sysconfdir}/ndctl/ndctl.d", "{sysconfdir}/ndctl/conf.d", ""{sysconfdir}/ndctl.d" would be ok with me. "{sysconfdir}/ndctl" is still needed for the security keys.
".d" sounds good - I prefer "{sysconfdir}/ndctl.d" or even something like "{sysconfdir}/ndctl.conf.d" to make it explicit that this is for config files.
Quoted 70 lines
Quoted 5 lines
regarded as global configuration files that all ndctl commands can refer to. Add
ndctl_set_configs()public function for setting ndctl default configuration files' path. Addndctl_get_configs()public function for getting ndctl configuration files' path formndctl_ctx.s/form/from/
Lets those ndctl_{get,set}_config_path().
Quoted 59 lines
Signed-off-by QI Fuli <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- configure.ac | 4 ++-- ndctl/lib/private.h | 1 + ndctl/lib/libndctl.c | 54 ++++++++++++++++++++++++++++++++++++++++++ ndctl/libndctl.h | 2 ++ ndctl/ndctl.c | 1 + ndctl/Makefile.am | 5 ++-- ndctl/lib/Makefile.am | 4 ++++ ndctl/lib/libndctl.sym | 2 ++ 8 files changed, 69 insertions(+), 4 deletions(-)configure.ac +2
-2@@ -171,9 +171,9 @@ fi AC_SUBST([systemd_unitdir]) AM_CONDITIONAL([ENABLE_SYSTEMD_UNITS], [test "x$with_systemd" = "xyes"]) -ndctl_monitorconfdir=${sysconfdir}/ndctl +ndctl_confdir=${sysconfdir}/ndctl ndctl_monitorconf=monitor.conf -AC_SUBST([ndctl_monitorconfdir]) +AC_SUBST([ndctl_confdir]) AC_SUBST([ndctl_monitorconf]) daxctl_modprobe_datadir=${datadir}/daxctlndctl/lib/private.h +1
-0@@ -129,6 +129,7 @@ struct ndctl_ctx {int regions_init;void *userdata;struct list_head busses; +const char *configs;int busses_init;struct udev *udev;struct udev_queue *udev_queue;ndctl/lib/libndctl.c +1
-0@@ -24,6 +24,7 @@#include <util/util.h> #include <util/size.h> #include <util/sysfs.h> +#include <util/strbuf.h> #include <ndctl/libndctl.h> #include <ndctl/namespace.h> #include <daxctl/libdaxctl.h> @@ -265,6 +266,58 @@ NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) ctx->userdata = userdata; }
Quoted 10 lines
ndctl/lib/libndctl.c NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) · line 275
Quoted 7 lines
ndctl/lib/libndctl.c +7
-0+static int filter_conf (const struct dirent *dir) +{ +if (!dir) +return 0 ; + +if (dir->d_type ==DT_REG ) { +const char *ext =strrchr (dir->d_name,'.' );Oh, I guess clang-format does not insert line breaks between declarations and code.
Oh, I'd fixed this, but I guess only in my future patch that moves this function elsewhere. Since I'm modifying Qi's patches anyway now, I'll squash that move patch into this, and make sure that fix is picked up too.
Quoted 13 lines
ndctl/lib/libndctl.c NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) · line 285
Quoted 11 lines
ndctl/lib/libndctl.c +10
-0+if ((!ext) || (ext == dir->d_name)) +return 0 ; +if (strcmp (ext,".conf" ) ==0 ) +return 1 ; + } + +return 0 ; +} + +NDCTL_EXPORT void ndctl_set_configs_dir(struct ndctl_ctx **ctx, char *conf_dir)
ndctl_set_config_path
Sounds good.
Quoted 2 lines
Why is ctx a 'struct
ndctl_ctx**' instead of a 'structndctl_ctx*'?
Heh I'd noticed this too but forgot to fix it, will do now.
Quoted 12 lines
ndctl/lib/libndctl.c NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) · line 291
Quoted 7 lines
ndctl/lib/libndctl.c +6
-0+{ +struct dirent **namelist; +struct strbuf value =STRBUF_INIT ; +int rc; + +if ((!ctx) || (!conf_dir))I think this function needs to return an error. If someone does:
ndctl_set_config_path(NULL, "/path")nothing will notify them that /path is not established as the config directory. The ENOENT check is helpful, but why not tell the caller?
Yes agreed, I'll change this.
Quoted 23 lines
Quoted 9 lines
ndctl/lib/libndctl.c +8
-0+return ; + + rc =scandir (conf_dir, &namelist, filter_conf, alphasort); +if (rc ==-1 ) { +if (errno !=ENOENT ) +err (*ctx,"scandir for configs failed: %s\n" , +strerror (errno)); +return ;ndctl/lib/libndctl.c NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) · line 309
Quoted 10 lines
ndctl/lib/libndctl.c +10
-0+ } + +while (rc--) { +if (value.len) +strbuf_addstr (&value," " ); +strbuf_addstr (&value, conf_dir); +strbuf_addstr (&value,"/" ); +strbuf_addstr (&value, namelist[rc]->d_name); +free (namelist[rc]); + }Any reason this needs to be converted to a space separated list? What if there are spaces in the path name?
Quoted 2 lines
This could just cache the scandir result in the ctx directly and skip the strbuf usage.
Hm I hadn't looked too closely at this before, but makes sense, and good point on paths with spaces. I'll fix.
Quoted 51 lines
Quoted 16 lines
ndctl/lib/libndctl.c +11
-0+ (*ctx)->configs =strbuf_detach (&value,NULL ); +free (namelist); +} + +NDCTL_EXPORT const char *ndctl_get_configs_dir(struct ndctl_ctx *ctx) +{ +if (ctx ==NULL ) +return NULL ; +return ctx->configs; +} +/** * ndctl_new - instantiate a new library context * @ctx: context to establish ndctl/lib/libndctl.c NDCTL_EXPORT int ndctl_new(struct ndctl_ctx **ctx) · line 387
Quoted 4 lines
ndctl/lib/libndctl.c +1
-0@@ -331,6 +384,7 @@ NDCTL_EXPORT int ndctl_new(struct ndctl_ctx **ctx) c->daxctl_ctx = daxctl_ctx;return 0 ; +Unnecessary newline.
Quoted 21 lines
ndctl/lib/libndctl.c +0
-0err_ctx:daxctl_unref (daxctl_ctx); err_daxctl:ndctl/libndctl.h +2
-0@@ -92,6 +92,8 @@ int ndctl_get_log_priority(struct ndctl_ctx *ctx);void ndctl_set_log_priority (struct ndctl_ctx *ctx,int priority);void ndctl_set_userdata (struct ndctl_ctx *ctx,void *userdata);void *ndctl_get_userdata (struct ndctl_ctx *ctx); +void ndctl_set_configs_dir (struct ndctl_ctx **ctx,char *conf_dir); +const char *ndctl_get_configs_dir (struct ndctl_ctx *ctx);enum ndctl_persistence_domain {PERSISTENCE_NONE =0 ,ndctl/ndctl.c +0
-0ndctl/ndctl.c int main(int argc, const char **argv) · line 128
Quoted 4 lines
ndctl/ndctl.c +1
-0@@ -125,6 +125,7 @@ int main(int argc, const char **argv) rc =ndctl_new (&ctx);if (rc) goto out; +ndctl_set_configs_dir (&ctx,NDCTL_CONF_DIR );I expect this to happen by default in
ndctl_new().
Quoted 2 lines
In fact,
ndctl_new()might want to grow a config path argument to override the default.
Happening by default in ndctl_new sounds good.
However since ndctl_new() is an exported API, we can't just add a new argument to it, can we? Do we expect callers to want custom paths, outside of what a distro may set via NDCTL_CONF_DIR during build?
Quoted 27 lines
Quoted 27 lines
ndctl/ndctl.c +0
-0main_handle_internal_command (argc, argv, ctx, commands,ARRAY_SIZE (commands),PROG_NDCTL );ndctl_unref (ctx);ndctl/Makefile.am +3
-2@@ -7,8 +7,9 @@ BUILT_SOURCES = config.h config.h: $(srcdir)/Makefile.am $(AM_V_GEN) echo "/* Autogenerated by ndctl/Makefile.am */" >$@ && \ echo '#define NDCTL_CONF_FILE \ - "$(ndctl_monitorconfdir)/$(ndctl_monitorconf)"' >>$@ + "$(ndctl_confdir)/$(ndctl_monitorconf)"' >>$@ $(AM_V_GEN) echo '#define NDCTL_KEYS_DIR "$(ndctl_keysdir)"' >>$@ + $(AM_V_GEN) echo '#define NDCTL_CONF_DIR "$(ndctl_confdir)"' >>$@ ndctl_SOURCES = ndctl.c \ builtin.h \@@ -73,7 +74,7 @@ ndctl_SOURCES += ../test/libndctl.c \ test.c endif -monitor_configdir = $(ndctl_monitorconfdir) +monitor_configdir = $(ndctl_confdir) monitor_config_DATA = $(ndctl_monitorconf)
Quoted 16 lines
ndctl/lib/Makefile.am libndctl_la_SOURCES =\ · line 20
Quoted 13 lines
ndctl/Makefile.am +0
-0if ENABLE_SYSTEMD_UNITSndctl/lib/Makefile.am +4
-0@@ -14,6 +14,10 @@ libndctl_la_SOURCES =\ ../../util/log.h \ ../../util/sysfs.c \ ../../util/sysfs.h \ + ../../util/strbuf.h \ + ../../util/strbuf.c \ + ../../util/wrapper.c \ + ../../util/usage.c \Seems this new utility code linking is not necessary per the above recommendation to just cache the scandir results in the ctx.
Yep makes sense.
Quoted 18 lines
Quoted 18 lines
ndctl/lib/Makefile.am +0
-0../../util/fletcher.h \ dimm.c \ inject.c \ndctl/lib/libndctl.sym +2
-1@@ -454,4 +454,6 @@ LIBNDCTL_25 { LIBNDCTL_26 { ndctl_bus_nfit_translate_spa; + ndctl_set_configs_dir; + ndctl_get_configs_dir; } LIBNDCTL_25; --2.33.1
Re: [ndctl PATCH v2 03/12] ndctl: make ndctl support configuration files
Quoted 15 lines · Vishal L
Quoted 4 lines · Dan Williams
Quoted 3 lines · Vishal Verma
From: QI Fuli <[email protected]>
Quoted 8 lines
Quoted 2 lines
Add
ndctl_configstondctl_ctxfor supporting ndctl global configuration files. All files with .conf suffix under {sysconfdir}/ndctl can beI expect this should be named a ".d" directory to match expectations of when a directory supports multiple config-file snippets. Either "{sysconfdir}/ndctl/ndctl.d", "{sysconfdir}/ndctl/conf.d", ""{sysconfdir}/ndctl.d" would be ok with me. "{sysconfdir}/ndctl" is still needed for the security keys.
Quoted 3 lines
".d" sounds good - I prefer "{sysconfdir}/ndctl.d" or even something like "{sysconfdir}/ndctl.conf.d" to make it explicit that this is for config files.
Sure, that works too. I note that modprobe.d is full of ".conf" files, but I see no harm in including ".conf" in the directory name. Since yum.repos.d is full of ".repo" files as a counter example in the naming scheme.
[..]
Quoted 9 lines
Quoted 5 lines
I expect this to happen by default in
ndctl_new().In fact,
ndctl_new()might want to grow a config path argument to override the default.Happening by default in
ndctl_newsounds good.
However sincendctl_new()is an exported API, we can't just add a new argument to it, can we?
Oh, yeah, it would need to be a new ndctl_new(). No worries we can cross that bridge later.
Quoted 2 lines
Do we expect callers to want custom paths,
outside of what a distro may set viaNDCTL_CONF_DIRduring build?
I was thinking it would be like mdadm where you can override the location of the configuration file(s) on the command line. We can always add that later, no need for feature creep right now.
Vishal Verma
maintainerPATCH v2 4/12 ndctl, config: add the default ndctl configuration file
In reply to Vishal VermaFrom: QI Fuli <[email protected]>
Install ndctl/ndctl.conf as the default ndctl configuration file.
--- configure.ac | 2 ++ ndctl/Makefile.am | 4 +++- ndctl/ndctl.conf | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 ndctl/ndctl.conf
configure.ac +2 -0
@@ -172,8 +172,10 @@ AC_SUBST([systemd_unitdir]) AM_CONDITIONAL([ENABLE_SYSTEMD_UNITS], [test "x$with_systemd" = "xyes"]) ndctl_confdir=${sysconfdir}/ndctl +ndctl_conf=ndctl.conf ndctl_monitorconf=monitor.conf AC_SUBST([ndctl_confdir]) +AC_SUBST([ndctl_conf]) AC_SUBST([ndctl_monitorconf]) daxctl_modprobe_datadir=${datadir}/daxctl
ndctl/Makefile.am +3 -1
@@ -43,7 +43,7 @@ keys_configdir = $(ndctl_keysdir) keys_config_DATA = $(ndctl_keysreadme) endif -EXTRA_DIST += keys.readme monitor.conf ndctl-monitor.service +EXTRA_DIST += keys.readme monitor.conf ndctl-monitor.service ndctl.conf if ENABLE_DESTRUCTIVE ndctl_SOURCES += ../test/blk_namespaces.c \
@@ -74,6 +74,8 @@ ndctl_SOURCES += ../test/libndctl.c \ test.c endif +ndctl_configdir = $(ndctl_confdir) +ndctl_config_DATA = $(ndctl_conf) monitor_configdir = $(ndctl_confdir) monitor_config_DATA = $(ndctl_monitorconf)
ndctl/ndctl.conf new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [ndctl PATCH v2 04/12] ndctl, config: add the default ndctl configuration file
Quoted 8 lines · Vishal Verma
From: QI Fuli <[email protected]>
Install
ndctl/ndctl.confas the default ndctl configuration file.Signed-off-by QI Fuli <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Couple small fixups, otherwise:
Quoted 50 lines
--- configure.ac | 2 ++ ndctl/Makefile.am | 4 +++- ndctl/ndctl.conf | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 ndctl/ndctl.confconfigure.ac +2
-0@@ -172,8 +172,10 @@ AC_SUBST([systemd_unitdir]) AM_CONDITIONAL([ENABLE_SYSTEMD_UNITS], [test "x$with_systemd" = "xyes"]) ndctl_confdir=${sysconfdir}/ndctl +ndctl_conf=ndctl.conf ndctl_monitorconf=monitor.conf AC_SUBST([ndctl_confdir]) +AC_SUBST([ndctl_conf]) AC_SUBST([ndctl_monitorconf]) daxctl_modprobe_datadir=${datadir}/daxctlndctl/Makefile.am +3
-1@@ -43,7 +43,7 @@ keys_configdir = $(ndctl_keysdir) keys_config_DATA = $(ndctl_keysreadme) endif -EXTRA_DIST += keys.readme monitor.conf ndctl-monitor.service +EXTRA_DIST += keys.readme monitor.conf ndctl-monitor.service ndctl.conf if ENABLE_DESTRUCTIVE ndctl_SOURCES += ../test/blk_namespaces.c \@@ -74,6 +74,8 @@ ndctl_SOURCES += ../test/libndctl.c \ test.c endif +ndctl_configdir = $(ndctl_confdir) +ndctl_config_DATA = $(ndctl_conf) monitor_configdir = $(ndctl_confdir) monitor_config_DATA = $(ndctl_monitorconf)ndctl/ndctl.conf new file +0
-0
ndctl/ndctl.conf line 4
Quoted 4 lines
ndctl/ndctl.conf new file +4
-0@@ -0,0 +1,56 @@ +# This is the default ndctl configuration file. It contains the +# configuration directives that give ndctl instructions. +# Ndctl supports multiple configuration files. All files with the +# .conf suffix under {sysconfdir}/ndctl can be regarded as ndctl
Looks good, just the fixup to rename this to {sysconfdir}/ndctl.conf.d
...does the install process replace {sysconfdir} with /etc?
Meson makes file substitutions based on config fairly painless, so this could wait to be fixed until after that conversion. Another future item would be to get "man ndctl.conf" to give an overview of ndctl configuration options.
Quoted 41 lines
ndctl/ndctl.conf new file +41
-0+# configuration files. + +# In this file, lines starting with a hash (#) are comments. +# The configurations should be in a [section] and follow <key> = <value> +# style. Multiple space-separated values are allowed, but except the +# following characters: : ? / \ % " ' $ & ! * { } [ ] ( ) = < > @ + +[core] +# The values in [core] section work for all ndctl sub commands. +# dimm = all +# bus = all +# region = all +# namespace = all + +[monitor] +# The values in [monitor] section work for ndctl monitor. +# You can change the configuration of ndctl monitor by editing this +# file or use [--config-file=<file>] option to override this one. +# The changed value will work after restart ndctl monitor service. + +# The objects to monitor are filtered via dimm's name by setting key "dimm". +# If this value is different from the value of [--dimm=<value>] option, +# both of the values will work. +# dimm = all + +# The objects to monitor are filtered via its parent bus by setting key "bus". +# If this value is different from the value of [--bus=<value>] option, +# both of the values will work. +# bus = all + +# The objects to monitor are filtered via region by setting key "region". +# If this value is different from the value of [--region=<value>] option, +# both of the values will work. +# region = all + +# The objects to monitor are filtered via namespace by setting key "namespace". +# If this value is different from the value of [--namespace=<value>] option, +# both of the values will work. +# namespace = all + +# The DIMM events to monitor are filtered via event type by setting key
ndctl/ndctl.conf line 55
Quoted 10 lines
ndctl/ndctl.conf new file +10
-0+# "dimm-event". If this value is different from the value of +# [--dimm-event=<value>] option, both of the values will work. +# dimm-event = all + +# Users can choose to output the notifications to syslog (log=syslog), +# to standard output (log=standard) or to write into a special file (log=<file>) +# by setting key "log". If this value is in conflict with the value of +# [--log=<value>] option, this value will be ignored. +# Note: Setting value to "standard" or relative path for <file> will not work +# when running moniotr as a daemon.
s/moniotr/monitor/
Quoted 4 lines
ndctl/ndctl.conf new file +1
-1+# log = /var/log/ndctl/monitor.log --2.33.1
Vishal Verma
maintainerPATCH v2 5/12 ndctl, monitor: refator monitor for supporting multiple config files
In reply to Vishal VermaFrom: QI Fuli <[email protected]>
Refactor ndctl monitor by using parse-configs helper to support multiple configuration files.
--- Documentation/ndctl/ndctl-monitor.txt | 8 +-- ndctl/monitor.c | 73 ++++++++++++++------------- Documentation/ndctl/Makefile.am | 2 +- 3 files changed, 44 insertions(+), 39 deletions(-)
Documentation/ndctl/ndctl-monitor.txt +4 -4
@@ -21,8 +21,8 @@ objects and dumping the json format notifications to syslog, standard output or a logfile. The objects to monitor and smart events to notify can be selected by -setting options and/or the configuration file at -{ndctl_monitorconfdir}/{ndctl_monitorconf} +setting options and/or configuration files with .conf suffix under +{ndctl_confdir} Both, the values in configuration file and in options will work. If there is a conflict, the values in options will override the values in
@@ -81,8 +81,8 @@ will not work if "--daemon" is specified. -c:: --config-file=:: - Provide the config file to use. This overrides the default config - typically found in {ndctl_monitorconfdir} + Provide the config file(s) to use. This overrides the default config + typically found in {ndctl_confdir} --daemon:: Run a monitor as a daemon.
ndctl/monitor.c +39 -34
139 lines not on this page · raw message
Documentation/ndctl/Makefile.am +1 -1
@@ -59,7 +59,7 @@ CLEANFILES = $(man1_MANS) .ONESHELL: attrs.adoc: $(srcdir)/Makefile.am $(AM_V_GEN) cat <<- EOF >$@ - :ndctl_monitorconfdir: $(ndctl_monitorconfdir) + :ndctl_confdir: $(ndctl_confdir) :ndctl_monitorconf: $(ndctl_monitorconf) :ndctl_keysdir: $(ndctl_keysdir) EOF
Signature · 1 line
2.33.1
Re: [ndctl PATCH v2 05/12] ndctl, monitor: refator monitor for supporting multiple config files
Quoted 9 lines · Vishal Verma
From: QI Fuli <[email protected]>
Refactor ndctl monitor by using parse-configs helper to support multiple configuration files.
Signed-off-by QI Fuli <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Look ok to me, perhaps a global s/configs/config_path/, but otherwise:
Quoted 199 lines
--- Documentation/ndctl/ndctl-monitor.txt | 8 +-- ndctl/monitor.c | 73 ++++++++++++++------------- Documentation/ndctl/Makefile.am | 2 +- 3 files changed, 44 insertions(+), 39 deletions(-)Documentation/ndctl/ndctl-monitor.txt +4
-4@@ -21,8 +21,8 @@ objects and dumping the json format notifications to syslog, standard output or a logfile. The objects to monitor and smart events to notify can be selected by -setting options and/or the configuration file at -{ndctl_monitorconfdir}/{ndctl_monitorconf} +setting options and/or configuration files with .conf suffix under +{ndctl_confdir} Both, the values in configuration file and in options will work. If there is a conflict, the values in options will override the values in@@ -81,8 +81,8 @@ will not work if "--daemon" is specified. -c:: --config-file=:: - Provide the config file to use. This overrides the default config - typically found in {ndctl_monitorconfdir} + Provide the config file(s) to use. This overrides the default config + typically found in {ndctl_confdir} --daemon:: Run a monitor as a daemon.ndctl/monitor.c +39
-34@@ -10,6 +10,7 @@#include <util/filter.h> #include <util/util.h> #include <util/parse-options.h> +#include <util/parse-configs.h> #include <util/strbuf.h> #include <ndctl/config.h> #include <ndctl/ndctl.h> @@ -28,7 +29,7 @@ static struct monitor { const char *log; - const char *config_file; + const char *configs; const char *dimm_event; FILE *log_file; bool daemon;@@ -463,7 +464,7 @@ out:return rc; } -static void parse_config (const char **arg,char *key,char *val,char *ident) +static void set_monitor_conf (const char **arg,char *key,char *val,char *ident) {struct strbuf value =STRBUF_INIT ;size_t arg_len = *arg ?strlen (*arg) :0 ;@@ -479,39 +480,25 @@ static void parse_config(const char **arg, char *key, char *val, char *ident) *arg =strbuf_detach (&value,NULL ); } -static int read_config_file (struct ndctl_ctx *ctx,struct monitor *_monitor, -struct util_filter_params *_param) +static int parse_monitor_config (const struct config *configs, +const char *config_file) {FILE *f;size_t len =0 ;int line =0 , rc =0 ; -char *buf =NULL , *seek, *value, *config_file; - -if (_monitor->config_file) - config_file =strdup (_monitor->config_file); -else - config_file =strdup (NDCTL_CONF_FILE ); -if (!config_file) { -fail ("strdup default config file failed\n" ); - rc = -ENOMEM ; - goto out; - } +char *buf =NULL , *seek, *value; buf =malloc (BUF_SIZE );if (!buf) {fail ("malloc read config-file buf error\n" ); - rc = -ENOMEM ; - goto out; +return -ENOMEM ; } seek = buf; f =fopen (config_file,"r" );if (!f) { -if (_monitor->config_file) { -err (&monitor,"config-file: %s cannot be opened\n" , - config_file); - rc = -errno; - } +err (&monitor,"%s cannot be opened\n" , config_file); + rc = -errno; goto out; }@@ -554,19 +541,18 @@ static int read_config_file(struct ndctl_ctx *ctx, struct monitor *_monitor,if (len ==0 )continue ; -parse_config (&_param->bus,"bus" , value, seek); -parse_config (&_param->dimm,"dimm" , value, seek); -parse_config (&_param->region,"region" , value, seek); -parse_config (&_param->namespace,"namespace" , value, seek); -parse_config (&_monitor->dimm_event,"dimm-event" , value, seek); +set_monitor_conf (¶m.bus,"bus" , value, seek); +set_monitor_conf (¶m.dimm,"dimm" , value, seek); +set_monitor_conf (¶m.region,"region" , value, seek); +set_monitor_conf (¶m.namespace,"namespace" , value, seek); +set_monitor_conf (&monitor.dimm_event,"dimm-event" , value, seek); -if (!_monitor->log) -parse_config (&_monitor->log,"log" , value, seek); +if (!monitor.log) +set_monitor_conf (&monitor.log,"log" , value, seek); }fclose (f); out:free (buf); -free (config_file);return rc; }@@ -585,8 +571,8 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)OPT_FILENAME ('l' ,"log" , &monitor.log,"<file> | syslog | standard" ,"where to output the monitor's notification" ), -OPT_FILENAME ('c' ,"config-file" , &monitor.config_file, -"config-file" ,"override the default config" ), +OPT_STRING ('c' ,"config-file" , &monitor.configs, +"config-file" ,"override default configs" ),OPT_BOOLEAN ('\0' ,"daemon" , &monitor.daemon,"run ndctl monitor as a daemon" ), OPT_BOOLEAN('u', "human", &monitor.human,@@ -601,7 +587,20 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)"ndctl monitor [<options>]" ,NULL }; -const char *prefix ="./" ; +const struct config configs[] = { +CONF_MONITOR (NDCTL_CONF_FILE , parse_monitor_config), +CONF_STR ("core:bus" , ¶m.bus,NULL ), +CONF_STR ("core:region" , ¶m.region,NULL ), +CONF_STR ("core:dimm" , ¶m.dimm,NULL ), +CONF_STR ("core:namespace" , ¶m.namespace,NULL ), +CONF_STR ("monitor:bus" , ¶m.bus,NULL ), +CONF_STR ("monitor:region" , ¶m.region,NULL ), +CONF_STR ("monitor:dimm" , ¶m.dimm,NULL ), +CONF_STR ("monitor:namespace" , ¶m.namespace,NULL ), +CONF_STR ("monitor:dimm-event" , &monitor.dimm_event,NULL ), +CONF_END (), + }; +const char *prefix ="./" , *ndctl_configs;struct util_filter_ctx fctx = {0 };struct monitor_filter_arg mfa = {0 };int i, rc;@@ -621,7 +620,13 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)else monitor.ctx.log_priority =LOG_INFO ; - rc =read_config_file (ctx, &monitor, ¶m); + ndctl_configs =ndctl_get_configs_dir (ctx); +if (monitor.configs) + rc =parse_configs_prefix (monitor.configs, prefix, configs); +else if (ndctl_configs) + rc =parse_configs_prefix (ndctl_configs, prefix, configs); +else + rc =0 ;if (rc) goto out;Documentation/ndctl/Makefile.am +1
-2@@ -59,7 +59,7 @@ CLEANFILES = $(man1_MANS) .ONESHELL: attrs.adoc: $(srcdir)/Makefile.am $(AM_V_GEN) cat <<- EOF >$@ - :ndctl_monitorconfdir: $(ndctl_monitorconfdir) + :ndctl_confdir: $(ndctl_confdir) :ndctl_monitorconf: $(ndctl_monitorconf) :ndctl_keysdir: $(ndctl_keysdir) EOF --2.33.1
Vishal Verma
maintainerPATCH v2 6/12 ndctl: Update ndctl.spec.in for 'ndctl.conf'
In reply to Vishal VermaThe new config system introduces and installs a sample config file called ndctl.conf. Update the RPM spec to include this in the %files section for ndctl.
--- ndctl.spec.in | 1 + 1 file changed, 1 insertion(+)
ndctl.spec.in +1 -0
@@ -118,6 +118,7 @@ make check %{_sysconfdir}/modprobe.d/nvdimm-security.conf %config(noreplace) %{_sysconfdir}/ndctl/monitor.conf +%config(noreplace) %{_sysconfdir}/ndctl/ndctl.conf %files -n daxctl %defattr(-,root,root)
Signature · 1 line
2.33.1
Re: [ndctl PATCH v2 06/12] ndctl: Update ndctl.spec.in for 'ndctl.conf'
Quoted 4 lines · Vishal Verma
The new config system introduces and installs a sample config file called ndctl.conf. Update the RPM spec to include this in the %files section for ndctl.
Modulo new ndctl.conf.d directory name:
Quoted 23 lines
Cc QI Fuli <[email protected]>Reviewed-by QI Fuli <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- ndctl.spec.in | 1 + 1 file changed, 1 insertion(+)ndctl.spec.in +1
-1@@ -118,6 +118,7 @@ make check %{_sysconfdir}/modprobe.d/nvdimm-security.conf %config(noreplace) %{_sysconfdir}/ndctl/monitor.conf +%config(noreplace) %{_sysconfdir}/ndctl/ndctl.conf %files -n daxctl %defattr(-,root,root) --2.33.1
Vishal Verma
maintainerPATCH v2 7/12 daxctl: Documentation updates for persistent reconfiguration
In reply to Vishal VermaAdd a man page update describing how daxctl-reconfigure-device(1) can be used for persistent reconfiguration of a daxctl device using a config file.
--- .../daxctl/daxctl-reconfigure-device.txt | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+)
Documentation/daxctl/daxctl-reconfigure-device.txt +67 -0
@@ -162,6 +162,15 @@ include::region-option.txt[] brought online automatically and immediately with the 'online_movable' policy. Use this option to disable the automatic onlining behavior. +-C:: +--check-config:: + Get reconfiguration parameters from the global daxctl config file. + This is typically used when daxctl-reconfigure-device is called from + a systemd-udevd device unit file. The reconfiguration proceeds only + if the match parameters in a 'reconfigure-device' section of the + config match the dax device specified on the command line. See the + 'PERSISTENT RECONFIGURATION' section for more details. + include::movable-options.txt[] -f::
@@ -183,6 +192,64 @@ include::human-option.txt[] include::verbose-option.txt[] +PERSISTENT RECONFIGURATION +-------------------------- + +The 'mode' of a daxctl device is not persistent across reboots by default. This +is because the device itself does not hold any metadata that hints at what mode +it was set to, or is intended to be used. The default mode for such a device +on boot is 'devdax'. + +The administrator may set policy such that certain dax devices are always +reconfigured into a target configuration every boot. This is accomplished via a +daxctl config file. + +The config file may have multiple sections influencing different aspects of +daxctl operation. The section of interest for persistent reconfiguration is +'reconfigure-device'. The format of this is as follows: + +---- +[reconfigure-device <unique_subsection_name>] +nvdimm.uuid = <NVDIMM namespace uuid> +mode = <desired reconfiguration mode> (default: system-ram) +online = <true|false> (default: true) +movable = <true|false> (default: true) +---- + +Here is an example of a config snippet for managing three devdax namespaces, +one is left in devdax mode, the second is changed to system-ram mode with +default options (online, movable), and the third is set to system-ram mode, +the memory is onlined, but not movable. + +Note that the 'subsection name' can be arbitrary, and is only used to +identify a specific config section. It does not have to match the 'device +name' (e.g. 'dax0.0' etc). + +---- +[reconfigure-device dax0] +nvdimm.uuid = ed93e918-e165-49d8-921d-383d7b9660c5 +mode = devdax + +[reconfigure-device dax1] +nvdimm.uuid = f36d02ff-1d9f-4fb9-a5b9-8ceb10a00fe3 +mode = system-ram + +[reconfigure-device dax2] +nvdimm.uuid = f36d02ff-1d9f-4fb9-a5b9-8ceb10a00fe3 +mode = system-ram +online = true +movable = false +---- + +The following example can be used to create a devdax mode namespace, and +simultaneously add the newly created namespace to the config file for +system-ram conversion. + +---- +ndctl create-namespace --mode=devdax | \ + jq -r "\"[reconfigure-device $(uuidgen)]\", \"nvdimm.uuid = \(.uuid)\", \"mode = system-ram\"" >> $config_path +---- + include::../copyright.txt[] SEE ALSO
Signature · 1 line
2.33.1
Re: [ndctl PATCH v2 07/12] daxctl: Documentation updates for persistent reconfiguration
Quoted 4 lines · Vishal Verma
Add a man page update describing how daxctl-reconfigure-device(1) can be used for persistent reconfiguration of a daxctl device using a config file.
Looks good, although this makes me think we need to immediately proceed to make an attempt at populating a /dev/dax/by-path that works across both NVDIMM dax devices and soft-reserved dax devices.
You can add:
Vishal Verma
maintainerPATCH v2 8/12 util/parse-config: refactor filter_conf_files into util/
In reply to Vishal VermaMove filter_conf() into util/parse-configs.c as filter_conf_files() so that it can be reused by the config parser in daxctl.
--- ndctl/lib/libndctl.c | 19 ++----------------- util/parse-configs.h | 4 ++++ util/parse-configs.c | 17 +++++++++++++++++ daxctl/lib/Makefile.am | 2 ++ ndctl/lib/Makefile.am | 2 ++ 5 files changed, 27 insertions(+), 17 deletions(-)
ndctl/lib/libndctl.c +2 -17
@@ -25,6 +25,7 @@#include <util/size.h> #include <util/sysfs.h> #include <util/strbuf.h> +#include <util/parse-configs.h> #include <ndctl/libndctl.h> #include <ndctl/namespace.h> #include <daxctl/libdaxctl.h>
@@ -266,22 +267,6 @@ NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata) ctx->userdata = userdata; } -static int filter_conf (const struct dirent *dir) -{ -if (!dir) -return 0 ; - -if (dir->d_type ==DT_REG ) { -const char *ext =strrchr (dir->d_name,'.' ); -if ((!ext) || (ext == dir->d_name)) -return 0 ; -if (strcmp (ext,".conf" ) ==0 ) -return 1 ; - } - -return 0 ; -} - NDCTL_EXPORT void ndctl_set_configs_dir(struct ndctl_ctx **ctx, char *conf_dir) {struct dirent **namelist;
@@ -291,7 +276,7 @@ NDCTL_EXPORT void ndctl_set_configs_dir(struct ndctl_ctx **ctx, char *conf_dir)if ((!ctx) || (!conf_dir))return ; - rc =scandir (conf_dir, &namelist, filter_conf, alphasort); + rc =scandir (conf_dir, &namelist, filter_conf_files, alphasort);if (rc ==-1 ) {if (errno !=ENOENT ) err(*ctx, "scandir for configs failed: %s\n",
util/parse-configs.h +4 -0
@@ -1,8 +1,10 @@// SPDX-License-Identifier: GPL-2.0 // Copyright (C) 2021, FUJITSU LIMITED. ALL rights reserved. +#include <dirent.h> #include <stdbool.h> #include <stdint.h> +#include <string.h> #include <util/util.h> enum parse_conf_type {
@@ -11,6 +13,8 @@ enum parse_conf_type { MONITOR_CALLBACK, }; +int filter_conf_files (const struct dirent *dir); +struct config ;typedef int parse_conf_cb (const struct config *,const char *config_file);
util/parse-configs.c +17 -0
@@ -6,6 +6,23 @@#include <util/strbuf.h> #include <util/iniparser.h> +int filter_conf_files (const struct dirent *dir) +{ +if (!dir) +return 0 ; + +if (dir->d_type ==DT_REG ) { +const char *ext =strrchr (dir->d_name,'.' ); + +if ((!ext) || (ext == dir->d_name)) +return 0 ; +if (strcmp (ext,".conf" ) ==0 ) +return 1 ; + } + +return 0 ; +} +static void set_str_val (const char **value,const char *val) {struct strbuf buf =STRBUF_INIT ;
daxctl/lib/Makefile.am +2 -0
@@ -15,6 +15,8 @@ libdaxctl_la_SOURCES =\ ../../util/sysfs.h \ ../../util/log.c \ ../../util/log.h \ + ../../util/parse-configs.h \ + ../../util/parse-configs.c \ libdaxctl.c libdaxctl_la_LIBADD =\
ndctl/lib/Makefile.am +2 -0
@@ -19,6 +19,8 @@ libndctl_la_SOURCES =\ ../../util/wrapper.c \ ../../util/usage.c \ ../../util/fletcher.h \ + ../../util/parse-configs.h \ + ../../util/parse-configs.c \ dimm.c \ inject.c \ nfit.c \
Signature · 1 line
2.33.1
Re: [ndctl PATCH v2 08/12] util/parse-config: refactor filter_conf_files into util/
Quoted 7 lines · Vishal Verma
Move
filter_conf()intoutil/parse-configs.casfilter_conf_files()so that it can be reused by the config parser in daxctl.Cc QI Fuli <[email protected]>Reviewed-by QI Fuli <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Looks good.
Vishal Verma
maintainerPATCH v2 9/12 daxctl: add basic config parsing support
In reply to Vishal VermaAdd support similar to ndctl and libndctl for parsing config files. This allows storing a config file path/list in the daxctl_ctx, and adds APIs for setting and retrieving it.
--- .../daxctl/daxctl-reconfigure-device.txt | 8 ++++ configure.ac | 3 ++ daxctl/lib/libdaxctl.c | 39 +++++++++++++++++++ daxctl/libdaxctl.h | 2 + Documentation/daxctl/Makefile.am | 11 +++++- daxctl/Makefile.am | 1 + daxctl/lib/Makefile.am | 4 ++ daxctl/lib/libdaxctl.sym | 2 + 8 files changed, 69 insertions(+), 1 deletion(-)
Documentation/daxctl/daxctl-reconfigure-device.txt +8 -0
@@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +include::attrs.adoc[] + daxctl-reconfigure-device(1) ============================
@@ -250,6 +252,12 @@ ndctl create-namespace --mode=devdax | \ jq -r "\"[reconfigure-device $(uuidgen)]\", \"nvdimm.uuid = \(.uuid)\", \"mode = system-ram\"" >> $config_path ---- +The default location for daxctl config files is under {daxctl_confdir}/, +and any file with a '.conf' suffix at this location is considered. It is +acceptable to have multiple files containing ini-style config sections, +but the {section, subsection} tuple must be unique across all config files +under {daxctl_confdir}/. + include::../copyright.txt[] SEE ALSO
configure.ac +3 -0
@@ -178,6 +178,9 @@ AC_SUBST([ndctl_confdir]) AC_SUBST([ndctl_conf]) AC_SUBST([ndctl_monitorconf]) +daxctl_confdir=${sysconfdir}/daxctl +AC_SUBST([daxctl_confdir]) + daxctl_modprobe_datadir=${datadir}/daxctl daxctl_modprobe_data=daxctl.conf AC_SUBST([daxctl_modprobe_datadir])
daxctl/lib/libdaxctl.c +39 -0
@@ -17,6 +17,8 @@#include <util/log.h> #include <util/sysfs.h> #include <util/iomem.h> +#include <util/strbuf.h> +#include <util/parse-configs.h> #include <daxctl/libdaxctl.h> #include "libdaxctl-private.h"
@@ -37,6 +39,7 @@ struct daxctl_ctx {struct log_ctx ctx;int refcount;void *userdata; +const char *configs;int regions_init;struct list_head regions;struct kmod_ctx *kmod_ctx;
@@ -68,6 +71,42 @@ DAXCTL_EXPORT void daxctl_set_userdata(struct daxctl_ctx *ctx, void *userdata) ctx->userdata = userdata; } +DAXCTL_EXPORT void daxctl_set_configs_dir(struct daxctl_ctx **ctx, char *conf_dir) +{ +struct dirent **namelist; +struct strbuf value =STRBUF_INIT ; +int rc; + +if ((!ctx) || (!conf_dir)) +return ; + + rc =scandir (conf_dir, &namelist, filter_conf_files, alphasort); +if (rc ==-1 ) { +if (errno !=ENOENT ) +err (*ctx,"scandir for configs failed: %s\n" , +strerror (errno)); +return ; + } + +while (rc--) { +if (value.len) +strbuf_addstr (&value," " ); +strbuf_addstr (&value, conf_dir); +strbuf_addstr (&value,"/" ); +strbuf_addstr (&value, namelist[rc]->d_name); +free (namelist[rc]); + } + (*ctx)->configs =strbuf_detach (&value,NULL ); +free (namelist); +} + +DAXCTL_EXPORT const char *daxctl_get_configs_dir(struct daxctl_ctx *ctx) +{ +if (ctx ==NULL ) +return NULL ; +return ctx->configs; +} +/** * daxctl_new - instantiate a new library context * @ctx: context to establish
daxctl/libdaxctl.h +2 -0
@@ -28,6 +28,8 @@ int daxctl_get_log_priority(struct daxctl_ctx *ctx);void daxctl_set_log_priority (struct daxctl_ctx *ctx,int priority);void daxctl_set_userdata (struct daxctl_ctx *ctx,void *userdata);void *daxctl_get_userdata (struct daxctl_ctx *ctx); +void daxctl_set_configs_dir (struct daxctl_ctx **ctx,char *conf_dir); +const char *daxctl_get_configs_dir (struct daxctl_ctx *ctx);struct daxctl_region ; struct daxctl_region *daxctl_new_region(struct daxctl_ctx *ctx, int id,
Documentation/daxctl/Makefile.am +10 -1
@@ -33,11 +33,20 @@ EXTRA_DIST = $(man1_MANS) CLEANFILES = $(man1_MANS) +.ONESHELL: +attrs.adoc: $(srcdir)/Makefile.am + $(AM_V_GEN) cat <<- EOF >$@ + :daxctl_confdir: $(daxctl_confdir) + :daxctl_conf: $(daxctl_conf) + :ndctl_keysdir: $(ndctl_keysdir) + EOF + XML_DEPS = \ ../../version.m4 \ ../copyright.txt \ Makefile \ - $(CONFFILE) + $(CONFFILE) \ + attrs.adoc RM ?= rm -f
daxctl/Makefile.am +1 -0
@@ -10,6 +10,7 @@ config.h: $(srcdir)/Makefile.am "$(daxctl_modprobe_datadir)/$(daxctl_modprobe_data)"' >>$@ && \ echo '#define DAXCTL_MODPROBE_INSTALL \ "$(sysconfdir)/modprobe.d/$(daxctl_modprobe_data)"' >>$@ + $(AM_V_GEN) echo '#define DAXCTL_CONF_DIR "$(daxctl_confdir)"' >>$@ daxctl_SOURCES =\ daxctl.c \
daxctl/lib/Makefile.am +4 -0
@@ -13,6 +13,10 @@ libdaxctl_la_SOURCES =\ ../../util/iomem.h \ ../../util/sysfs.c \ ../../util/sysfs.h \ + ../../util/strbuf.h \ + ../../util/strbuf.c \ + ../../util/wrapper.c \ + ../../util/usage.c \ ../../util/log.c \ ../../util/log.h \ ../../util/parse-configs.h \
daxctl/lib/libdaxctl.sym +2 -0
@@ -96,4 +96,6 @@ LIBDAXCTL_9 { global: daxctl_dev_will_auto_online_memory; daxctl_dev_has_online_memory; + daxctl_set_configs_dir; + daxctl_get_configs_dir; } LIBDAXCTL_8;
Signature · 1 line
2.33.1
Vishal Verma
maintainerPATCH v2 10/12 util/parse-configs: add a key/value search helper
In reply to Vishal VermaAdd a new config query type called CONFIG_SEARCH_SECTION, which searches all loaded config files based on a query criteria of: specified section name, specified key/value pair within that section, and can return other key/values from the section that matched the search criteria.
This allows for multiple named subsections, where a subsection name is of the type: '[section subsection]'.
--- util/parse-configs.h | 15 +++++++++++++ util/parse-configs.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
util/parse-configs.h +15 -0
@@ -9,6 +9,7 @@enum parse_conf_type {CONFIG_STRING , +CONFIG_SEARCH_SECTION ,CONFIG_END ,MONITOR_CALLBACK , };
@@ -20,6 +21,10 @@ typedef int parse_conf_cb(const struct config *, const char *config_file);struct config {enum parse_conf_type type; +const char *section; +const char *search_key; +const char *search_val; +const char *get_key;const char *key;void *value;void *defval;
@@ -31,6 +36,16 @@ struct config {#define CONF_END () { .type = CONFIG_END }#define CONF_STR (k,v,d) \ { .type = CONFIG_STRING, .key = (k), .value = check_vtype(v, const char **), .defval = (d) } +#define CONF_SEARCH (s, sk, sv, gk, v, d) \ +{ \ + .type = CONFIG_SEARCH_SECTION, \ + .section = (s), \ + .search_key = (sk), \ + .search_val = (sv), \ + .get_key = (gk), \ + .value = check_vtype(v, const char **), \ + .defval = (d) \ +}#define CONF_MONITOR (k,f) \ { .type = MONITOR_CALLBACK, .key = (k), .callback = (f)}
util/parse-configs.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.33.1
Vishal Verma
maintainerPATCH v2 11/12 daxctl/device.c: add an option for getting params from a config file
In reply to Vishal VermaAdd a new option to daxctl-reconfigure-device that allows it to comprehend the new global config system in ndctl/daxctl. With this, the reconfigure-device command can query the config to match a specific device UUID, and operate using the parameters supplied in that INI section.
This is in preparation to make daxctl device reconfiguration (usually as system-ram) policy based, so that reconfiguration can happen automatically on boot.
--- daxctl/daxctl.c | 1 + daxctl/device.c | 174 ++++++++++++++++++++++++++++++++++++++++++++- daxctl/Makefile.am | 1 + 3 files changed, 174 insertions(+), 2 deletions(-)
daxctl/daxctl.c +1 -0
@@ -95,6 +95,7 @@ int main(int argc, const char **argv) rc =daxctl_new (&ctx);if (rc) goto out; +daxctl_set_configs_dir (&ctx,DAXCTL_CONF_DIR );main_handle_internal_command (argc, argv, ctx, commands,ARRAY_SIZE (commands),PROG_DAXCTL );daxctl_unref (ctx);
daxctl/device.c +172 -2
226 lines not on this page · raw message
daxctl/Makefile.am +1 -0
@@ -23,6 +23,7 @@ daxctl_SOURCES =\ daxctl_LDADD =\ lib/libdaxctl.la \ + ../ndctl/lib/libndctl.la \ ../libutil.a \ $(UUID_LIBS) \ $(KMOD_LIBS) \
Signature · 1 line
2.33.1
Vishal Verma
maintainerPATCH v2 12/12 daxctl: add systemd service and udev rule for automatic reconfiguration
In reply to Vishal VermaInstall a systemd service that calls "daxctl-reconfigure-device --check-config" with a daxctl device passed in to it via the environment.
Install a udev rule that is triggered for every daxctl device, and triggers the above oneshot systemd service.
On boot, whenever a daxctl device is found, udev triggers a device-specific systemd service called, for example:
This initiates a daxctl-reconfigure-device with a config lookup for the 'dax0.0' device. If the config has a '[reconfigure-device <unique_id>]' section, it uses the information in that to set the operating mode of the device.
If any device is in an unexpected status, 'journalctl' can be used to view the reconfiguration log for that device, for example:
journalctl --unit [email protected]
Update the RPM spec file to include the newly added files to the RPM build.
--- configure.ac | 9 ++++++++- daxctl/90-daxctl-device.rules | 1 + daxctl/Makefile.am | 7 +++++++ daxctl/[email protected] | 8 ++++++++ ndctl.spec.in | 3 +++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 daxctl/90-daxctl-device.rules create mode 100644 daxctl/[email protected]
configure.ac +8 -1
@@ -160,7 +160,7 @@ AC_CHECK_FUNCS([ \ AC_ARG_WITH([systemd], AS_HELP_STRING([--with-systemd], - [Enable systemd functionality (monitor). @<:@default=yes@:>@]), + [Enable systemd functionality. @<:@default=yes@:>@]), [], [with_systemd=yes]) if test "x$with_systemd" = "xyes"; then
@@ -186,6 +186,13 @@ daxctl_modprobe_data=daxctl.conf AC_SUBST([daxctl_modprobe_datadir]) AC_SUBST([daxctl_modprobe_data]) +AC_ARG_WITH(udevrulesdir, + [AS_HELP_STRING([--with-udevrulesdir=DIR], [udev rules.d directory])], + [UDEVRULESDIR="$withval"], + [UDEVRULESDIR='${prefix}/lib/udev/rules.d'] +) +AC_SUBST(UDEVRULESDIR) + AC_ARG_WITH([keyutils], AS_HELP_STRING([--with-keyutils], [Enable keyutils functionality (security). @<:@default=yes@:>@]), [], [with_keyutils=yes])
daxctl/90-daxctl-device.rules new file +1 -0
@@ -0,0 +1 @@ +ACTION=="add", SUBSYSTEM=="dax", TAG+="systemd", ENV{SYSTEMD_WANTS}="daxdev-reconfigure@$env{DEVNAME}.service"
daxctl/Makefile.am +7 -0
@@ -28,3 +28,10 @@ daxctl_LDADD =\ $(UUID_LIBS) \ $(KMOD_LIBS) \ $(JSON_LIBS) + +udevrulesdir = $(UDEVRULESDIR) +udevrules_DATA = 90-daxctl-device.rules + +if ENABLE_SYSTEMD_UNITS +systemd_unit_DATA = [email protected] +endif
daxctl/[email protected] new file +8 -0
@@ -0,0 +1,8 @@ +[Unit] +Description=Automatic daxctl device reconfiguration +Documentation=man:daxctl-reconfigure-device(1) + +[Service] +Type=forking +GuessMainPID=false +ExecStart=/bin/sh -c "exec daxctl reconfigure-device --check-config %I"
ndctl.spec.in +3 -0
@@ -26,6 +26,7 @@ BuildRequires: pkgconfig(json-c) BuildRequires: pkgconfig(bash-completion) BuildRequires: pkgconfig(systemd) BuildRequires: keyutils-libs-devel +BuildRequires: systemd-rpm-macros %description Utility library for managing the "libnvdimm" subsystem. The "libnvdimm"
@@ -126,6 +127,8 @@ make check %{_bindir}/daxctl %{_mandir}/man1/daxctl* %{_datadir}/daxctl/daxctl.conf +%{_unitdir}/[email protected] +%config %{_udevrulesdir}/90-daxctl-device.rules %files -n LNAME %defattr(-,root,root)
Signature · 1 line
2.33.1
Verma, Vishal L
maintainerQuoted 28 lines · Vishal Verma
Changes since v1[1]:
- Collect review tags
- Fix 'make clean' removing the reconfigure script from the source tree (Fenghua, Qi)
- Documentation wordsmithing (Dan)
- Fix line break after declarations inparse-configs.c(Dan)
- Move daxctl config files to its own directory,/etc/daxctl/(Dan)
- Improve failure mode in the absence of a configs directory
- Rename {nd,dax}ctl_{get|set}_configs to {nd,dax}ctl_{get|set}_configs_dir
- Exit with success if -C is specified, but no matching config section is found.
- Refuse to proceed if CLI options are passed in along with -C (Dan)
- In the config file, rename: s/[auto-online foo]/[reconfigure-device foo/ and s/uuid/nvdimm.uuid/ (Dan)
- Teachdevice.cto accept/dev/daxX.Yinstead of only daxX.Y and thus remove the need for a wrapper script that systemd invokes (Dan)These patches add policy (config file) support to daxctl. The introductory user is daxctl-reconfigure-device. Sysadmins may wish to use daxctl devices as system-ram, but it may be cumbersome to automate the reconfiguration step for every device upon boot.
Introduce a new option for daxctl-reconfigure-device, --check-config. This is at the heart of policy based reconfiguration, as it allows daxctl to look up reconfiguration parameters for a given device from the config system instead of the command line.
Quoted 8 lines
Some systemd and udev glue then automates this for every new dax device that shows up, providing a way for the administrator to simply list all the 'system-ram' UUIDs in a config file, and not have to worry about anything else.
An example config file can be:
# cat /etc/ndctl/daxctl.conf
Missed updating this, it should be /etc/daxctl/daxctl.conf
Quoted 8 lines
[reconfigure-device
unique_identifier_foo] nvdimm.uuid = 48d8e42c-a2f0-4312-9e70-a837faafe862 mode = system-ram
online = true
movable = falseAny file under '
/etc/ndctl/' can be used - all files with a '.conf' suffix
And this should be '/etc/daxctl/'
Quoted 77 lines
will be considered when looking for matches.
These patches depend on the initial config file support from Qi Fuli[2].
I've re-rolled Qi's original patches as the first five patches in this series because of a change I made for graceful handling in the case of a missing configs directory, and also to incorporate review feedback that applied to the dependant patches. Patch 6 onwards is the actual v2 of the daxctl policy work.
A branch containing these patches is available at [3].
[1]: https://lore.kernel.org/nvdimm/[email protected]/
[2]: https://lore.kernel.org/nvdimm/[email protected]/
[3]: https://github.com/pmem/ndctl/tree/vv/daxctl_config_v2QI Fuli (5):
ndctl, util: add iniparser helper
ndctl, util: add parse-configs helper
ndctl: make ndctl support configuration files
ndctl, config: add the default ndctl configuration file ndctl, monitor: refator monitor for supporting multiple config filesVishal Verma (7):
ndctl: Update ndctl.spec.in for 'ndctl.conf'
daxctl: Documentation updates for persistent reconfiguration util/parse-config: refactorfilter_conf_filesinto util/
daxctl: add basic config parsing support util/parse-configs: add a key/value search helperdaxctl/device.c: add an option for getting params from a config file
daxctl: add systemd service and udev rule for automatic
reconfiguration.../daxctl/daxctl-reconfigure-device.txt | 75 ++ Documentation/ndctl/ndctl-monitor.txt | 8 +- configure.ac | 18 +- Makefile.am | 8 +- ndctl/lib/private.h | 1 + daxctl/lib/libdaxctl.c | 39 + ndctl/lib/libndctl.c | 39 + daxctl/libdaxctl.h | 2 + ndctl/libndctl.h | 2 + util/dictionary.h | 175 ++++ util/iniparser.h | 360 ++++++++ util/parse-configs.h | 53 ++ daxctl/daxctl.c | 1 + daxctl/device.c | 174 +++- ndctl/monitor.c | 73 +- ndctl/ndctl.c | 1 + util/dictionary.c | 383 ++++++++ util/iniparser.c | 838 ++++++++++++++++++ util/parse-configs.c | 150 ++++ Documentation/daxctl/Makefile.am | 11 +- Documentation/ndctl/Makefile.am | 2 +- daxctl/90-daxctl-device.rules | 1 + daxctl/Makefile.am | 9 + daxctl/[email protected] | 8 + daxctl/lib/Makefile.am | 6 + daxctl/lib/libdaxctl.sym | 2 + ndctl.spec.in | 4 + ndctl/Makefile.am | 9 +- ndctl/lib/Makefile.am | 6 + ndctl/lib/libndctl.sym | 2 + ndctl/ndctl.conf | 56 ++ 31 files changed, 2467 insertions(+), 49 deletions(-) create mode 100644 util/dictionary.h create mode 100644 util/iniparser.h create mode 100644 util/parse-configs.h create mode 100644 util/dictionary.c create mode 100644 util/iniparser.c create mode 100644 util/parse-configs.c create mode 100644 daxctl/90-daxctl-device.rules create mode 100644 daxctl/[email protected] create mode 100644 ndctl/ndctl.confbase-commit:
4e646fa490ba4b782afa188dd8818b94c419924e
Quoted 49 lines
Subject: Re: [ndctl PATCH v2 00/12] Policy based reconfiguration for daxctl
Quoted 28 lines · Vishal Verma
Changes since v1[1]:
- Collect review tags
- Fix 'make clean' removing the reconfigure script from the source tree (Fenghua, Qi)
- Documentation wordsmithing (Dan)
- Fix line break after declarations inparse-configs.c(Dan)
- Move daxctl config files to its own directory,/etc/daxctl/(Dan)
- Improve failure mode in the absence of a configs directory
- Rename {nd,dax}ctl_{get|set}_configs to {nd,dax}ctl_{get|set}_configs_dir
- Exit with success if -C is specified, but no matching config section is found.
- Refuse to proceed if CLI options are passed in along with -C (Dan)
- In the config file, rename: s/[auto-online foo]/[reconfigure-device foo/ and s/uuid/nvdimm.uuid/ (Dan)
- Teachdevice.cto accept/dev/daxX.Yinstead of only daxX.Y and thus remove the need for a wrapper script that systemd invokes (Dan)These patches add policy (config file) support to daxctl. The introductory user is daxctl-reconfigure-device. Sysadmins may wish to use daxctl devices as system-ram, but it may be cumbersome to automate the reconfiguration step for every device upon boot.
Introduce a new option for daxctl-reconfigure-device, --check-config. This is at the heart of policy based reconfiguration, as it allows daxctl to look up reconfiguration parameters for a given device from the config system instead of the command line.
Quoted 8 lines
Some systemd and udev glue then automates this for every new dax device that shows up, providing a way for the administrator to simply list all the 'system-ram' UUIDs in a config file, and not have to worry about anything else.
An example config file can be:
# cat /etc/ndctl/daxctl.confMissed updating this, it should be
/etc/daxctl/daxctl.confQuoted 7 lines
[reconfigure-device
unique_identifier_foo] nvdimm.uuid = 48d8e42c-a2f0-4312-9e70-a837faafe862 mode = system-ram
online = true
movable = false
Quoted 31 lines
Quoted 2 lines
Any file under '
/etc/ndctl/' can be used - all files with a '.conf' suffixAnd this should be '
/etc/daxctl/'Quoted 26 lines
will be considered when looking for matches.
These patches depend on the initial config file support from Qi Fuli[2].
I've re-rolled Qi's original patches as the first five patches in this series because of a change I made for graceful handling in the case of a missing configs directory, and also to incorporate review feedback that applied to the dependant patches. Patch 6 onwards is the actual v2 of the daxctl policy work.
A branch containing these patches is available at [3].
[1]:
https://lore.kernel.org/nvdimm/20210831090459.2306727-1-vishal.l.verma
@intel.com/
[2]:
https://lore.kernel.org/nvdimm/20210824095106.104808-1-qi.fuli@fujitsu
.com/
[3]: https://github.com/pmem/ndctl/tree/vv/daxctl_config_v2QI Fuli (5):
ndctl, util: add iniparser helper
ndctl, util: add parse-configs helper
ndctl: make ndctl support configuration files
ndctl, config: add the default ndctl configuration file ndctl, monitor: refator monitor for supporting multiple config files
Hi Vishal,
Thank you very for the work.
I made a patch[1] to fix test/monitor.sh for the new style config file. Could you please also pick it?
[1] https://lore.kernel.org/all/[email protected]/
Best,
QI Fuli
Quoted 53 lines
Quoted 21 lines
Vishal Verma (7):
ndctl: Update ndctl.spec.in for 'ndctl.conf'
daxctl: Documentation updates for persistent reconfiguration util/parse-config: refactorfilter_conf_filesinto util/
daxctl: add basic config parsing support util/parse-configs: add a key/value search helperdaxctl/device.c: add an option for getting params from a config file
daxctl: add systemd service and udev rule for automatic
reconfiguration.../daxctl/daxctl-reconfigure-device.txt | 75 ++ Documentation/ndctl/ndctl-monitor.txt | 8 +- configure.ac | 18 +- Makefile.am | 8 +- ndctl/lib/private.h | 1 + daxctl/lib/libdaxctl.c | 39 + ndctl/lib/libndctl.c | 39 + daxctl/libdaxctl.h | 2 + ndctl/libndctl.h | 2 + util/dictionary.h | 175 ++++Quoted 8 lines
util/iniparser.h | 360 ++++++++ util/parse-configs.h | 53 ++ daxctl/daxctl.c | 1 + daxctl/device.c | 174 +++- ndctl/monitor.c | 73 +- ndctl/ndctl.c | 1 + util/dictionary.c | 383 ++++++++ util/iniparser.c | 838++++++++++++++++++
Quoted 23 lines
util/parse-configs.c | 150 ++++ Documentation/daxctl/Makefile.am | 11 +- Documentation/ndctl/Makefile.am | 2 +- daxctl/90-daxctl-device.rules | 1 + daxctl/Makefile.am | 9 + daxctl/[email protected] | 8 + daxctl/lib/Makefile.am | 6 + daxctl/lib/libdaxctl.sym | 2 + ndctl.spec.in | 4 + ndctl/Makefile.am | 9 +- ndctl/lib/Makefile.am | 6 + ndctl/lib/libndctl.sym | 2 + ndctl/ndctl.conf | 56 ++ 31 files changed, 2467 insertions(+), 49 deletions(-) create mode100644
util/dictionary.hcreate mode 100644util/iniparser.hcreate mode 100644util/parse-configs.hcreate mode 100644util/dictionary.ccreate mode 100644util/iniparser.ccreate mode 100644util/parse-configs.ccreate mode 100644 daxctl/90-daxctl-device.rules create mode 100644 daxctl/[email protected]create mode 100644 ndctl/ndctl.confbase-commit:
4e646fa490ba4b782afa188dd8818b94c419924e