@@ -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
@@ -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
@@ -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 \
@@ -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,56 @@ 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(struct ndctl_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, alphasort);
+ if (rc == -1) {
+ perror("scandir");
+ 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);
+}
+
+NDCTL_EXPORT const char *ndctl_get_configs(struct ndctl_ctx *ctx)
+{
+ if (ctx == NULL)
+ return NULL;
+ return ctx->configs;
+}
+
/**
* ndctl_new - instantiate a new library context
* @ctx: context to establish
@@ -331,6 +382,7 @@ NDCTL_EXPORT int ndctl_new(struct ndctl_ctx **ctx)
c->daxctl_ctx = daxctl_ctx;
return 0;
+
err_ctx:
daxctl_unref(daxctl_ctx);
err_daxctl:
@@ -454,4 +454,6 @@ LIBNDCTL_25 {
LIBNDCTL_26 {
ndctl_bus_nfit_translate_spa;
+ ndctl_set_configs;
+ ndctl_get_configs;
} LIBNDCTL_25;
@@ -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;
@@ -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,
@@ -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);