01ff50
From 7fcbfd7c620e2dcd3b539d18e93cb503ee3a8a62 Mon Sep 17 00:00:00 2001
01ff50
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
01ff50
Date: Wed, 21 Dec 2022 12:50:17 +0100
01ff50
Subject: [PATCH 66/83] mdadm: create ident_init()
01ff50
01ff50
Add a wrapper for repeated initializations in mdadm.c and config.c.
01ff50
Move includes up.
01ff50
01ff50
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
01ff50
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
01ff50
---
01ff50
 config.c | 45 +++++++++++++++++++++++++++++----------------
01ff50
 mdadm.c  | 16 ++--------------
01ff50
 mdadm.h  |  7 +++++--
01ff50
 3 files changed, 36 insertions(+), 32 deletions(-)
01ff50
01ff50
diff --git a/config.c b/config.c
01ff50
index dc1620c1..eeedd0c6 100644
01ff50
--- a/config.c
01ff50
+++ b/config.c
01ff50
@@ -119,6 +119,34 @@ int match_keyword(char *word)
01ff50
 	return -1;
01ff50
 }
01ff50
 
01ff50
+/**
01ff50
+ * ident_init() - Set defaults.
01ff50
+ * @ident: ident pointer, not NULL.
01ff50
+ */
01ff50
+inline void ident_init(struct mddev_ident *ident)
01ff50
+{
01ff50
+	assert(ident);
01ff50
+
01ff50
+	ident->assembled = false;
01ff50
+	ident->autof = 0;
01ff50
+	ident->bitmap_fd = -1;
01ff50
+	ident->bitmap_file = NULL;
01ff50
+	ident->container = NULL;
01ff50
+	ident->devices = NULL;
01ff50
+	ident->devname = NULL;
01ff50
+	ident->level = UnSet;
01ff50
+	ident->member = NULL;
01ff50
+	ident->name[0] = 0;
01ff50
+	ident->next = NULL;
01ff50
+	ident->raid_disks = UnSet;
01ff50
+	ident->spare_group = NULL;
01ff50
+	ident->spare_disks = 0;
01ff50
+	ident->st = NULL;
01ff50
+	ident->super_minor = UnSet;
01ff50
+	ident->uuid[0] = 0;
01ff50
+	ident->uuid_set = 0;
01ff50
+}
01ff50
+
01ff50
 struct conf_dev {
01ff50
 	struct conf_dev *next;
01ff50
 	char *name;
01ff50
@@ -363,22 +391,7 @@ void arrayline(char *line)
01ff50
 	struct mddev_ident mis;
01ff50
 	struct mddev_ident *mi;
01ff50
 
01ff50
-	mis.uuid_set = 0;
01ff50
-	mis.super_minor = UnSet;
01ff50
-	mis.level = UnSet;
01ff50
-	mis.raid_disks = UnSet;
01ff50
-	mis.spare_disks = 0;
01ff50
-	mis.devices = NULL;
01ff50
-	mis.devname = NULL;
01ff50
-	mis.spare_group = NULL;
01ff50
-	mis.autof = 0;
01ff50
-	mis.next = NULL;
01ff50
-	mis.st = NULL;
01ff50
-	mis.bitmap_fd = -1;
01ff50
-	mis.bitmap_file = NULL;
01ff50
-	mis.name[0] = 0;
01ff50
-	mis.container = NULL;
01ff50
-	mis.member = NULL;
01ff50
+	ident_init(&mis;;
01ff50
 
01ff50
 	for (w = dl_next(line); w != line; w = dl_next(w)) {
01ff50
 		if (w[0] == '/' || strchr(w, '=') == NULL) {
01ff50
diff --git a/mdadm.c b/mdadm.c
01ff50
index 972adb52..74fdec31 100644
01ff50
--- a/mdadm.c
01ff50
+++ b/mdadm.c
01ff50
@@ -107,25 +107,13 @@ int main(int argc, char *argv[])
01ff50
 
01ff50
 	srandom(time(0) ^ getpid());
01ff50
 
01ff50
-	ident.uuid_set = 0;
01ff50
-	ident.level = UnSet;
01ff50
-	ident.raid_disks = UnSet;
01ff50
-	ident.super_minor = UnSet;
01ff50
-	ident.devices = 0;
01ff50
-	ident.spare_group = NULL;
01ff50
-	ident.autof = 0;
01ff50
-	ident.st = NULL;
01ff50
-	ident.bitmap_fd = -1;
01ff50
-	ident.bitmap_file = NULL;
01ff50
-	ident.name[0] = 0;
01ff50
-	ident.container = NULL;
01ff50
-	ident.member = NULL;
01ff50
-
01ff50
 	if (get_linux_version() < 2006015) {
01ff50
 		pr_err("This version of mdadm does not support kernels older than 2.6.15\n");
01ff50
 		exit(1);
01ff50
 	}
01ff50
 
01ff50
+	ident_init(&ident);
01ff50
+
01ff50
 	while ((option_index = -1),
01ff50
 	       (opt = getopt_long(argc, argv, shortopt, long_options,
01ff50
 				  &option_index)) != -1) {
01ff50
diff --git a/mdadm.h b/mdadm.h
01ff50
index 3673494e..23ffe977 100644
01ff50
--- a/mdadm.h
01ff50
+++ b/mdadm.h
01ff50
@@ -33,8 +33,10 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
01ff50
 # endif
01ff50
 #endif
01ff50
 
01ff50
+#include	<assert.h>
01ff50
 #include	<sys/types.h>
01ff50
 #include	<sys/stat.h>
01ff50
+#include	<stdarg.h>
01ff50
 #include	<stdint.h>
01ff50
 #include	<stdlib.h>
01ff50
 #include	<time.h>
01ff50
@@ -1552,6 +1554,8 @@ extern void enable_fds(int devices);
01ff50
 extern void manage_fork_fds(int close_all);
01ff50
 extern int continue_via_systemd(char *devnm, char *service_name);
01ff50
 
01ff50
+extern void ident_init(struct mddev_ident *ident);
01ff50
+
01ff50
 extern int parse_auto(char *str, char *msg, int config);
01ff50
 extern struct mddev_ident *conf_get_ident(char *dev);
01ff50
 extern struct mddev_dev *conf_get_devs(void);
01ff50
@@ -1779,8 +1783,7 @@ static inline sighandler_t signal_s(int sig, sighandler_t handler)
01ff50
 #define dprintf_cont(fmt, arg...) \
01ff50
         ({ if (0) fprintf(stderr, fmt, ##arg); 0; })
01ff50
 #endif
01ff50
-#include <assert.h>
01ff50
-#include <stdarg.h>
01ff50
+
01ff50
 static inline int xasprintf(char **strp, const char *fmt, ...) {
01ff50
 	va_list ap;
01ff50
 	int ret;
01ff50
-- 
01ff50
2.38.1
01ff50