All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: <nvdimm@lists.linux.dev>
Cc: Dan Williams <dan.j.williams@intel.com>,
	QI Fuli <qi.fuli@jp.fujitsu.com>,
	fenghua.hu@intel.com, Vishal Verma <vishal.l.verma@intel.com>,
	QI Fuli <qi.fuli@fujitsu.com>
Subject: [ndctl PATCH v3 07/11] daxctl: add basic config parsing support
Date: Fri, 10 Dec 2021 15:34:36 -0700	[thread overview]
Message-ID: <20211210223440.3946603-8-vishal.l.verma@intel.com> (raw)
In-Reply-To: <20211210223440.3946603-1-vishal.l.verma@intel.com>

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 <qi.fuli@fujitsu.com>
Reviewed-by: QI Fuli <qi.fuli@jp.fujitsu.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 .../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


  parent reply	other threads:[~2021-12-10 22:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10 22:34 [ndctl PATCH v3 00/11] Policy based reconfiguration for daxctl Vishal Verma
2021-12-10 22:34 ` [ndctl PATCH v3 01/11] ndctl, util: add parse-configs helper Vishal Verma
2021-12-16 21:42   ` Dan Williams
2021-12-17 21:31     ` Verma, Vishal L
2021-12-21 12:54   ` Joao Martins
2021-12-10 22:34 ` [ndctl PATCH v3 02/11] ndctl: make ndctl support configuration files Vishal Verma
2021-12-16 21:47   ` Dan Williams
2021-12-10 22:34 ` [ndctl PATCH v3 03/11] ndctl, config: add the default ndctl configuration file Vishal Verma
2021-12-10 22:34 ` [ndctl PATCH v3 04/11] ndctl, monitor: refator monitor for supporting multiple config files Vishal Verma
2021-12-10 22:34 ` [ndctl PATCH v3 05/11] ndctl: Update ndctl.spec.in for 'ndctl.conf' Vishal Verma
2021-12-10 22:34 ` [ndctl PATCH v3 06/11] daxctl: Documentation updates for persistent reconfiguration Vishal Verma
2021-12-10 22:34 ` Vishal Verma [this message]
2021-12-16 22:37   ` [ndctl PATCH v3 07/11] daxctl: add basic config parsing support Dan Williams
2021-12-10 22:34 ` [ndctl PATCH v3 08/11] util/parse-configs: add a key/value search helper Vishal Verma
2021-12-16 22:44   ` Dan Williams
2021-12-10 22:34 ` [ndctl PATCH v3 09/11] daxctl/device.c: add an option for getting params from a config file Vishal Verma
2021-12-16 22:45   ` Dan Williams
2021-12-10 22:34 ` [ndctl PATCH v3 10/11] daxctl: add systemd service and udev rule for automatic reconfiguration Vishal Verma
2021-12-16 23:03   ` Dan Williams
2021-12-10 22:34 ` [ndctl PATCH v3 11/11] daxctl: add and install an example config file Vishal Verma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211210223440.3946603-8-vishal.l.verma@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=fenghua.hu@intel.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=qi.fuli@fujitsu.com \
    --cc=qi.fuli@jp.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.