make ndctl support global configuration files
Subsystems (3)
v2 cover make ndctl support global configuration files
From: QI Fuli <[email protected]>
This patch set is used to make ndctl support global configuration files. All files with .conf suffix under {sysconfdir}/ndctl can be regarded as ndctl global configuration files that all ndctl commands can refer to.
v1 -> v2:
- Update the version of iniparser helper
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
Documentation/ndctl/Makefile.am | 2 +- Documentation/ndctl/ndctl-monitor.txt | 8 +- Makefile.am | 8 +- configure.ac | 6 +- ndctl/Makefile.am | 9 +- ndctl/lib/Makefile.am | 4 + ndctl/lib/libndctl.c | 52 ++ ndctl/lib/libndctl.sym | 2 + ndctl/lib/private.h | 1 + ndctl/libndctl.h | 2 + ndctl/monitor.c | 69 ++- ndctl/ndctl.c | 1 + ndctl/ndctl.conf | 56 ++ util/dictionary.c | 383 ++++++++++++ util/dictionary.h | 175 ++++++ util/iniparser.c | 838 ++++++++++++++++++++++++++ util/iniparser.h | 360 +++++++++++ util/parse-configs.c | 82 +++ util/parse-configs.h | 34 ++ 19 files changed, 2048 insertions(+), 44 deletions(-) create mode 100644 ndctl/ndctl.conf create mode 100644 util/dictionary.c create mode 100644 util/dictionary.h create mode 100644 util/iniparser.c create mode 100644 util/iniparser.h create mode 100644 util/parse-configs.c create mode 100644 util/parse-configs.h
Signature · 1 line
2.31.1
PATCH v2 1/5 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.c | 383 +++++++++++++++++++++ util/dictionary.h | 175 ++++++++++ util/iniparser.c | 838 ++++++++++++++++++++++++++++++++++++++++++++++ util/iniparser.h | 360 ++++++++++++++++++++ 5 files changed, 1761 insertions(+), 1 deletion(-) create mode 100644 util/dictionary.c create mode 100644 util/dictionary.h create mode 100644 util/iniparser.c create mode 100644 util/iniparser.h
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.c new file +383 -0
383 lines not on this page · raw message
util/dictionary.h new file +175 -0
175 lines not on this page · raw message
util/iniparser.c new file +838 -0
838 lines not on this page · raw message
util/iniparser.h new file +360 -0
360 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 2/5 ndctl, util: add parse-configs helper
In reply to QI FuliFrom: QI Fuli <[email protected]>
Add parse-config util to help ndctl commands parse ndctl global configuration files.
--- Makefile.am | 2 ++ util/parse-configs.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ util/parse-configs.h | 34 ++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 util/parse-configs.c create mode 100644 util/parse-configs.h
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.c new file +82 -0
82 lines not on this page · raw message
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);
Signature · 1 line
2.31.1
PATCH v2 3/5 ndctl: make ndctl support configuration files
In reply to QI FuliFrom: 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/Makefile.am | 5 ++-- ndctl/lib/Makefile.am | 4 ++++ ndctl/lib/libndctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 2 ++ ndctl/lib/private.h | 1 + ndctl/libndctl.h | 2 ++ ndctl/ndctl.c | 1 + 8 files changed, 67 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/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.c +52 -0
70 lines not on this page · raw message
ndctl/lib/libndctl.sym +2 -0
@@ -454,4 +454,6 @@ LIBNDCTL_25 { LIBNDCTL_26 { ndctl_bus_nfit_translate_spa; + ndctl_set_configs; + ndctl_get_configs; } LIBNDCTL_25;
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/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 (struct ndctl_ctx **ctx,char *conf_dir); +const char *ndctl_get_configs (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 (&ctx,NDCTL_CONF_DIR );main_handle_internal_command (argc, argv, ctx, commands,ARRAY_SIZE (commands),PROG_NDCTL );ndctl_unref (ctx);
Signature · 1 line
2.31.1
PATCH v2 4/5 ndctl, config: add the default ndctl configuration file
In reply to QI FuliFrom: 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.31.1
PATCH v2 5/5 ndctl, monitor: refator monitor for supporting multiple config files
In reply to QI FuliFrom: QI Fuli <[email protected]>
Refactor ndctl monitor by using parse-configs helper to support multiple configuration files.
--- Documentation/ndctl/Makefile.am | 2 +- Documentation/ndctl/ndctl-monitor.txt | 8 ++-- ndctl/monitor.c | 69 ++++++++++++++------------- 3 files changed, 41 insertions(+), 38 deletions(-)
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
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 +36 -33
135 lines not on this page · raw message
Signature · 1 line
2.31.1