]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: create ident_init()
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Wed, 21 Dec 2022 11:50:17 +0000 (12:50 +0100)
committerJes Sorensen <jes@trained-monkey.org>
Wed, 28 Dec 2022 15:04:12 +0000 (10:04 -0500)
Add a wrapper for repeated initializations in mdadm.c and config.c.
Move includes up.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
config.c
mdadm.c
mdadm.h

index dc1620c12b3bc41ce4176c1f4f5895a855da22e8..eeedd0c6cde966db0aa31b4f92f629692a0b8ee3 100644 (file)
--- a/config.c
+++ b/config.c
@@ -119,6 +119,34 @@ int match_keyword(char *word)
        return -1;
 }
 
+/**
+ * ident_init() - Set defaults.
+ * @ident: ident pointer, not NULL.
+ */
+inline void ident_init(struct mddev_ident *ident)
+{
+       assert(ident);
+
+       ident->assembled = false;
+       ident->autof = 0;
+       ident->bitmap_fd = -1;
+       ident->bitmap_file = NULL;
+       ident->container = NULL;
+       ident->devices = NULL;
+       ident->devname = NULL;
+       ident->level = UnSet;
+       ident->member = NULL;
+       ident->name[0] = 0;
+       ident->next = NULL;
+       ident->raid_disks = UnSet;
+       ident->spare_group = NULL;
+       ident->spare_disks = 0;
+       ident->st = NULL;
+       ident->super_minor = UnSet;
+       ident->uuid[0] = 0;
+       ident->uuid_set = 0;
+}
+
 struct conf_dev {
        struct conf_dev *next;
        char *name;
@@ -363,22 +391,7 @@ void arrayline(char *line)
        struct mddev_ident mis;
        struct mddev_ident *mi;
 
-       mis.uuid_set = 0;
-       mis.super_minor = UnSet;
-       mis.level = UnSet;
-       mis.raid_disks = UnSet;
-       mis.spare_disks = 0;
-       mis.devices = NULL;
-       mis.devname = NULL;
-       mis.spare_group = NULL;
-       mis.autof = 0;
-       mis.next = NULL;
-       mis.st = NULL;
-       mis.bitmap_fd = -1;
-       mis.bitmap_file = NULL;
-       mis.name[0] = 0;
-       mis.container = NULL;
-       mis.member = NULL;
+       ident_init(&mis);
 
        for (w = dl_next(line); w != line; w = dl_next(w)) {
                if (w[0] == '/' || strchr(w, '=') == NULL) {
diff --git a/mdadm.c b/mdadm.c
index 972adb524dfb2c3a5b94d7c1f1129f0b13aa03e1..74fdec31aa8f527cce10f3a62d3846b3c070c7de 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -107,25 +107,13 @@ int main(int argc, char *argv[])
 
        srandom(time(0) ^ getpid());
 
-       ident.uuid_set = 0;
-       ident.level = UnSet;
-       ident.raid_disks = UnSet;
-       ident.super_minor = UnSet;
-       ident.devices = 0;
-       ident.spare_group = NULL;
-       ident.autof = 0;
-       ident.st = NULL;
-       ident.bitmap_fd = -1;
-       ident.bitmap_file = NULL;
-       ident.name[0] = 0;
-       ident.container = NULL;
-       ident.member = NULL;
-
        if (get_linux_version() < 2006015) {
                pr_err("This version of mdadm does not support kernels older than 2.6.15\n");
                exit(1);
        }
 
+       ident_init(&ident);
+
        while ((option_index = -1),
               (opt = getopt_long(argc, argv, shortopt, long_options,
                                  &option_index)) != -1) {
diff --git a/mdadm.h b/mdadm.h
index 3673494e560b9624b95e3d854ca8a95ee28a1104..23ffe97748ab147602a068f8ba671c312a143cf7 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -33,8 +33,10 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 # endif
 #endif
 
+#include       <assert.h>
 #include       <sys/types.h>
 #include       <sys/stat.h>
+#include       <stdarg.h>
 #include       <stdint.h>
 #include       <stdlib.h>
 #include       <time.h>
@@ -1552,6 +1554,8 @@ extern void enable_fds(int devices);
 extern void manage_fork_fds(int close_all);
 extern int continue_via_systemd(char *devnm, char *service_name);
 
+extern void ident_init(struct mddev_ident *ident);
+
 extern int parse_auto(char *str, char *msg, int config);
 extern struct mddev_ident *conf_get_ident(char *dev);
 extern struct mddev_dev *conf_get_devs(void);
@@ -1779,8 +1783,7 @@ static inline sighandler_t signal_s(int sig, sighandler_t handler)
 #define dprintf_cont(fmt, arg...) \
         ({ if (0) fprintf(stderr, fmt, ##arg); 0; })
 #endif
-#include <assert.h>
-#include <stdarg.h>
+
 static inline int xasprintf(char **strp, const char *fmt, ...) {
        va_list ap;
        int ret;