linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: jes@trained-monkey.org, colyli@suse.de
Cc: linux-raid@vger.kernel.org
Subject: [PATCH 1/3] mdadm: create ident_init()
Date: Wed, 21 Dec 2022 12:50:17 +0100	[thread overview]
Message-ID: <20221221115019.26276-2-mariusz.tkaczyk@linux.intel.com> (raw)
In-Reply-To: <20221221115019.26276-1-mariusz.tkaczyk@linux.intel.com>

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>
---
 config.c | 45 +++++++++++++++++++++++++++++----------------
 mdadm.c  | 16 ++--------------
 mdadm.h  |  7 +++++--
 3 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/config.c b/config.c
index dc1620c1..eeedd0c6 100644
--- 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 972adb52..74fdec31 100644
--- 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 3673494e..23ffe977 100644
--- 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;
-- 
2.26.2


  reply	other threads:[~2022-12-21 11:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21 11:50 [PATCH 0/3] Validation for names during creation Mariusz Tkaczyk
2022-12-21 11:50 ` Mariusz Tkaczyk [this message]
2022-12-28 15:05   ` [PATCH 1/3] mdadm: create ident_init() Jes Sorensen
2022-12-21 11:50 ` [PATCH 2/3] mdadm: refactor ident->name handling Mariusz Tkaczyk
2022-12-28 15:07   ` Jes Sorensen
2022-12-29  9:39     ` Mariusz Tkaczyk
2023-01-09 10:51       ` Mariusz Tkaczyk
2023-03-02 14:52       ` Jes Sorensen
2023-03-03 12:04         ` Mariusz Tkaczyk
2023-03-08 19:04           ` Jes Sorensen
2023-03-09  8:02             ` Mariusz Tkaczyk
2023-03-10 14:43               ` Jes Sorensen
2022-12-21 11:50 ` [PATCH 3/3] Limit length and set of characters allowed of devname Mariusz Tkaczyk
2023-03-13 14:22   ` Jes Sorensen
2023-03-14  8:14     ` Mariusz Tkaczyk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221221115019.26276-2-mariusz.tkaczyk@linux.intel.com \
    --to=mariusz.tkaczyk@linux.intel.com \
    --cc=colyli@suse.de \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).