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