Add 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.
Cc: QI Fuli <[email protected]> Reviewed-by: QI Fuli <[email protected]> Signed-off-by: Vishal Verma <[email protected]> --- .../daxctl/daxctl-reconfigure-device.txt | 8 ++++++++ configure.ac | 3 +++ daxctl/lib/libdaxctl.c | 20 +++++++++++++++++++ daxctl/libdaxctl.h | 2 ++ Documentation/daxctl/Makefile.am | 11 +++++++++- daxctl/Makefile.am | 3 ++- daxctl/lib/Makefile.am | 6 ++++++ daxctl/lib/libdaxctl.sym | 2 ++ 8 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Documentation/daxctl/daxctl-reconfigure-device.txt b/Documentation/daxctl/daxctl-reconfigure-device.txt index aa87d45..09556cc 100644 --- a/Documentation/daxctl/daxctl-reconfigure-device.txt +++ b/Documentation/daxctl/daxctl-reconfigure-device.txt @@ -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 diff --git a/configure.ac b/configure.ac index 3f15a7b..39ad0d4 100644 --- a/configure.ac +++ b/configure.ac @@ -178,6 +178,9 @@ AC_SUBST([ndctl_confdir]) AC_SUBST([ndctl_conf]) AC_SUBST([ndctl_monitorconf]) +daxctl_confdir=${sysconfdir}/daxctl.conf.d +AC_SUBST([daxctl_confdir]) + daxctl_modprobe_datadir=${datadir}/daxctl daxctl_modprobe_data=daxctl.conf AC_SUBST([daxctl_modprobe_datadir]) diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index 860bd9c..f173bbb 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -37,6 +37,7 @@ struct daxctl_ctx { struct log_ctx ctx; int refcount; void *userdata; + const char *config_path; int regions_init; struct list_head regions; struct kmod_ctx *kmod_ctx; @@ -68,6 +69,22 @@ DAXCTL_EXPORT void daxctl_set_userdata(struct daxctl_ctx *ctx, void *userdata) ctx->userdata = userdata; } +DAXCTL_EXPORT int daxctl_set_config_path(struct daxctl_ctx *ctx, + char *config_path) +{ + if ((!ctx) || (!config_path)) + return -EINVAL; + ctx->config_path = config_path; + return 0; +} + +DAXCTL_EXPORT const char *daxctl_get_config_path(struct daxctl_ctx *ctx) +{ + if (ctx == NULL) + return NULL; + return ctx->config_path; +} + /** * daxctl_new - instantiate a new library context * @ctx: context to establish @@ -99,6 +116,9 @@ DAXCTL_EXPORT int daxctl_new(struct daxctl_ctx **ctx) *ctx = c; list_head_init(&c->regions); c->kmod_ctx = kmod_ctx; + rc = daxctl_set_config_path(c, DAXCTL_CONF_DIR); + if (rc) + dbg(c, "Unable to set config path: %s\n", strerror(-rc)); return 0; out: diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h index 683ae9c..6b6c71f 100644 --- a/daxctl/libdaxctl.h +++ b/daxctl/libdaxctl.h @@ -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); +int daxctl_set_config_path(struct daxctl_ctx *ctx, char *config_path); +const char *daxctl_get_config_path(struct daxctl_ctx *ctx); struct daxctl_region; struct daxctl_region *daxctl_new_region(struct daxctl_ctx *ctx, int id, diff --git a/Documentation/daxctl/Makefile.am b/Documentation/daxctl/Makefile.am index 5991731..9c43e61 100644 --- a/Documentation/daxctl/Makefile.am +++ b/Documentation/daxctl/Makefile.am @@ -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 diff --git a/daxctl/Makefile.am b/daxctl/Makefile.am index 9b1313a..7ee65c4 100644 --- a/daxctl/Makefile.am +++ b/daxctl/Makefile.am @@ -25,4 +25,5 @@ daxctl_LDADD =\ ../libutil.a \ $(UUID_LIBS) \ $(KMOD_LIBS) \ - $(JSON_LIBS) + $(JSON_LIBS) \ + -liniparser diff --git a/daxctl/lib/Makefile.am b/daxctl/lib/Makefile.am index 25efd83..3c47a4b 100644 --- a/daxctl/lib/Makefile.am +++ b/daxctl/lib/Makefile.am @@ -3,6 +3,12 @@ include $(top_srcdir)/Makefile.am.in %.pc: %.pc.in Makefile $(SED_PROCESS) +DISTCLEANFILES = config.h +BUILT_SOURCES = config.h +config.h: $(srcdir)/Makefile.am + $(AM_V_GEN) echo "/* Autogenerated by daxctl/Makefile.am */" >$@ && \ + echo '#define DAXCTL_CONF_DIR "$(daxctl_confdir)"' >>$@ + pkginclude_HEADERS = ../libdaxctl.h lib_LTLIBRARIES = libdaxctl.la diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym index a13e93d..fe68fd0 100644 --- a/daxctl/lib/libdaxctl.sym +++ b/daxctl/lib/libdaxctl.sym @@ -96,4 +96,6 @@ LIBDAXCTL_9 { global: daxctl_dev_will_auto_online_memory; daxctl_dev_has_online_memory; + daxctl_set_config_path; + daxctl_get_config_path; } LIBDAXCTL_8; -- 2.33.1
