Move filter_conf() into util/parse-configs.c as filter_conf_files() so
that it can be reused by the config parser in daxctl.

Cc: QI Fuli <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
---
 ndctl/lib/libndctl.c   | 19 ++-----------------
 util/parse-configs.h   |  4 ++++
 util/parse-configs.c   | 16 ++++++++++++++++
 daxctl/lib/Makefile.am |  2 ++
 ndctl/lib/Makefile.am  |  2 ++
 5 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index db2e38b..a01ac80 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -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(struct ndctl_ctx **ctx, char *conf_dir)
 {
        struct dirent **namelist;
@@ -291,7 +276,7 @@ NDCTL_EXPORT void ndctl_set_configs(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) {
                perror("scandir");
                return;
diff --git a/util/parse-configs.h b/util/parse-configs.h
index f70f58f..491aebb 100644
--- a/util/parse-configs.h
+++ b/util/parse-configs.h
@@ -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);
 
diff --git a/util/parse-configs.c b/util/parse-configs.c
index 44dcff4..72c4913 100644
--- a/util/parse-configs.c
+++ b/util/parse-configs.c
@@ -6,6 +6,22 @@
 #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;
diff --git a/daxctl/lib/Makefile.am b/daxctl/lib/Makefile.am
index 25efd83..db2351e 100644
--- a/daxctl/lib/Makefile.am
+++ b/daxctl/lib/Makefile.am
@@ -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 =\
diff --git a/ndctl/lib/Makefile.am b/ndctl/lib/Makefile.am
index f741c44..8020eb4 100644
--- a/ndctl/lib/Makefile.am
+++ b/ndctl/lib/Makefile.am
@@ -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 \
-- 
2.31.1


Reply via email to