Skip to contentSkip to conversation

Few config related refactors

PATCH Applied Mariusz Tkaczyk 3 participants 8 messages Mar 23, 2023 – May 8, 2023 MD RAID

lore
Share & tools
lore
#0 lore raw

cover Few config related refactors

Hi Jes,
These patches remove multiple inlines across code and replace them by defines or functions. No functional changes intended. The goal is to make this some code reusable for both config and cmdline (mdadm.c). I next patchset I will start optimizing names verification (extended v2 of previous patchset).

Mariusz Tkaczyk (4):
mdadm: define DEV_MD_DIR
mdadm: define DEV_NUM_PREF
mdadm: define is_devname_ignore()
mdadm: numbered names verification

 Create.c      |  7 +++----
 Detail.c      |  9 ++++-----
 Incremental.c | 10 ++++------
 Monitor.c     | 34 +++++++++++++++++++---------------
 config.c      | 43 +++++++++++++++++++++----------------------
 lib.c         |  4 ++--
 mapfile.c     | 12 ++++++------
 mdadm.c       |  5 ++---
 mdadm.h       | 21 ++++++++++++++++++++-
 mdopen.c      | 16 ++++++++--------
 super-ddf.c   |  2 +-
 super-intel.c |  2 +-
 super1.c      |  3 +--
 sysfs.c       |  2 +-
 util.c        | 44 ++++++++++++++++++++++++++++++++++++++++++++
 15 files changed, 137 insertions(+), 77 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/4 mdadm: define DEV_MD_DIR

It is used many times. Additionally define _LEN to avoid repeated strlen() calls when length is needed.

---
 Create.c      |  7 +++----
 Detail.c      |  9 ++++-----
 Incremental.c |  4 ++--
 Monitor.c     | 32 ++++++++++++++++++--------------
 config.c      | 10 +++++-----
 lib.c         |  2 +-
 mapfile.c     | 12 ++++++------
 mdadm.h       |  8 ++++++++
 mdopen.c      |  6 +++---
 super-ddf.c   |  2 +-
 super-intel.c |  2 +-
 super1.c      |  3 +--
 sysfs.c       |  2 +-
 13 files changed, 54 insertions(+), 45 deletions(-)
Create.c +3 -4
index bbe9e13d..f3a02a2e 100644
@@ -1029,10 +1029,9 @@ int Create(struct supertype *st, char *mddev,
 	 * it could be in conflict with already existing device
 	 * e.g. container, array
 	 */
-	if (strncmp(chosen_name, "/dev/md/", 8) == 0 &&
-	    map_by_name(&map, chosen_name+8) != NULL) {
-		pr_err("Array name %s is in use already.\n",
-			chosen_name);
+	if (strncmp(chosen_name, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0 &&
+	    map_by_name(&map, chosen_name + DEV_MD_DIR_LEN)) {
+		pr_err("Array name %s is in use already.\n", chosen_name);
 		close(mdfd);
 		map_unlock(&map);
 		udev_unblock();
Detail.c +4 -5
index 4ef26460..206d88e3 100644
@@ -254,10 +254,9 @@ int Detail(char *dev, struct context *c)
 			fname_from_uuid(st, info, nbuf, ':');
 			printf("MD_UUID=%s\n", nbuf + 5);
 			mp = map_by_uuid(&map, info->uuid);
-			if (mp && mp->path &&
-			    strncmp(mp->path, "/dev/md/", 8) == 0) {
+			if (mp && mp->path && strncmp(mp->path, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0) {
 				printf("MD_DEVNAME=");
-				print_escape(mp->path + 8);
+				print_escape(mp->path + DEV_MD_DIR_LEN);
 				putchar('\n');
 			}
 
@@ -273,9 +272,9 @@ int Detail(char *dev, struct context *c)
 				printf("MD_UUID=%s\n", nbuf+5);
 			}
 			if (mp && mp->path &&
-			    strncmp(mp->path, "/dev/md/", 8) == 0) {
+			    strncmp(mp->path, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0) {
 				printf("MD_DEVNAME=");
-				print_escape(mp->path+8);
+				print_escape(mp->path + DEV_MD_DIR_LEN);
 				putchar('\n');
 			}
 			map_free(map);
Incremental.c +2 -2
index 09b94b9f..b3dc499a 100644
@@ -460,8 +460,8 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
 			info.array.working_disks ++;
 
 	}
-	if (strncmp(chosen_name, "/dev/md/", 8) == 0)
-		md_devname = chosen_name+8;
+	if (strncmp(chosen_name, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0)
+		md_devname = chosen_name + DEV_MD_DIR_LEN;
 	else
 		md_devname = chosen_name;
 	if (c->export) {
Monitor.c +18 -14
index 44918184..3273f2fb 100644
@@ -36,9 +36,18 @@
 #define EVENT_NAME_MAX 32
 #define AUTOREBUILD_PID_PATH MDMON_DIR "/autorebuild.pid"
 
+/**
+ * struct state - external array or container properties.
+ * @devname: has length of %DEV_MD_DIR + device name + terminating byte
+ * @devnm: to sync with mdstat info
+ * @parent_devnm: or subarray, devnm of parent, for others, ""
+ * @subarray: for a container it is a link to first subarray, for a subarray it is a link to next
+ *	      subarray in the same container
+ * @parent: for a subarray it is a link to its container
+ */
 struct state {
-	char devname[MD_NAME_MAX + sizeof("/dev/md/")];	/* length of "/dev/md/" + device name + terminating byte*/
-	char devnm[MD_NAME_MAX];	/* to sync with mdstat info */
+	char devname[MD_NAME_MAX + sizeof(DEV_MD_DIR)];
+	char devnm[MD_NAME_MAX];
 	unsigned int utime;
 	int err;
 	char *spare_group;
@@ -49,15 +58,10 @@ struct state {
 	int devstate[MAX_DISKS];
 	dev_t devid[MAX_DISKS];
 	int percent;
-	char parent_devnm[MD_NAME_MAX]; /* For subarray, devnm of parent.
-					* For others, ""
-					*/
+	char parent_devnm[MD_NAME_MAX];
 	struct supertype *metadata;
-	struct state *subarray;/* for a container it is a link to first subarray
-				* for a subarray it is a link to next subarray
-				* in the same container */
-	struct state *parent;  /* for a subarray it is a link to its container
-				*/
+	struct state *subarray;
+	struct state *parent;
 	struct state *next;
 };
 
@@ -252,8 +256,8 @@ int Monitor(struct mddev_dev *devlist,
 				continue;
 
 			st = xcalloc(1, sizeof *st);
-			snprintf(st->devname, MD_NAME_MAX + sizeof("/dev/md/"),
-				 "/dev/md/%s", basename(mdlist->devname));
+			snprintf(st->devname, MD_NAME_MAX + sizeof(DEV_MD_DIR), DEV_MD_DIR "%s",
+				 basename(mdlist->devname));
 			st->next = statelist;
 			st->devnm[0] = 0;
 			st->percent = RESYNC_UNKNOWN;
@@ -274,7 +278,7 @@ int Monitor(struct mddev_dev *devlist,
 
 			st = xcalloc(1, sizeof *st);
 			mdlist = conf_get_ident(dv->devname);
-			snprintf(st->devname, MD_NAME_MAX + sizeof("/dev/md/"), "%s", dv->devname);
+			snprintf(st->devname, MD_NAME_MAX + sizeof(DEV_MD_DIR), "%s", dv->devname);
 			st->next = statelist;
 			st->devnm[0] = 0;
 			st->percent = RESYNC_UNKNOWN;
@@ -942,7 +946,7 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist)
 				continue;
 			}
 
-			snprintf(st->devname, MD_NAME_MAX + sizeof("/dev/md/"), "%s", name);
+			snprintf(st->devname, MD_NAME_MAX + sizeof(DEV_MD_DIR), "%s", name);
 			if ((fd = open(st->devname, O_RDONLY)) < 0 ||
 			    md_get_array_info(fd, &array) < 0) {
 				/* no such array */
config.c +5 -5
index eeedd0c6..59d5bfb6 100644
@@ -405,7 +405,7 @@ void arrayline(char *line)
 			 *  or anything that doesn't start '/' or '<'
 			 */
 			if (strcasecmp(w, "<ignore>") == 0 ||
-			    strncmp(w, "/dev/md/", 8) == 0 ||
+			    strncmp(w, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0 ||
 			    (w[0] != '/' && w[0] != '<') ||
 			    (strncmp(w, "/dev/md", 7) == 0 &&
 			     is_number(w + 7)) ||
@@ -1102,13 +1102,13 @@ int devname_matches(char *name, char *match)
 	 *  mdNN with NN
 	 * then just strcmp
 	 */
-	if (strncmp(name, "/dev/md/", 8) == 0)
-		name += 8;
+	if (strncmp(name, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0)
+		name += DEV_MD_DIR_LEN;
 	else if (strncmp(name, "/dev/", 5) == 0)
 		name += 5;
 
-	if (strncmp(match, "/dev/md/", 8) == 0)
-		match += 8;
+	if (strncmp(match, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0)
+		match += DEV_MD_DIR_LEN;
 	else if (strncmp(match, "/dev/", 5) == 0)
 		match += 5;
 
lib.c +1 -1
index e395b28d..65ea51e0 100644
@@ -313,7 +313,7 @@ char *map_dev_preferred(int major, int minor, int create,
 
 	for (p = devlist; p; p = p->next)
 		if (p->major == major && p->minor == minor) {
-			if (strncmp(p->name, "/dev/md/",8) == 0 ||
+			if (strncmp(p->name, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0 ||
 			    (prefer && strstr(p->name, prefer))) {
 				if (preferred == NULL ||
 				    strlen(p->name) < strlen(preferred))
mapfile.c +6 -6
index ac351768..34fea179 100644
@@ -320,9 +320,9 @@ struct map_ent *map_by_name(struct map_ent **map, char *name)
 	for (mp = *map ; mp ; mp = mp->next) {
 		if (!mp->path)
 			continue;
-		if (strncmp(mp->path, "/dev/md/", 8) != 0)
+		if (strncmp(mp->path, DEV_MD_DIR, DEV_MD_DIR_LEN) != 0)
 			continue;
-		if (strcmp(mp->path+8, name) != 0)
+		if (strcmp(mp->path + DEV_MD_DIR_LEN, name) != 0)
 			continue;
 		if (!mddev_busy(mp->devnm)) {
 			mp->bad = 1;
@@ -413,7 +413,7 @@ void RebuildMap(void)
 			devid = devnm2devid(md->devnm);
 			path = map_dev(major(devid), minor(devid), 0);
 			if (path == NULL ||
-			    strncmp(path, "/dev/md/", 8) != 0) {
+			    strncmp(path, DEV_MD_DIR, DEV_MD_DIR_LEN) != 0) {
 				/* We would really like a name that provides
 				 * an MD_DEVNAME for udev.
 				 * The name needs to be unique both in /dev/md/
@@ -434,7 +434,7 @@ void RebuildMap(void)
 				if (match && match->devname && match->devname[0] == '/') {
 					path = match->devname;
 					if (path[0] != '/') {
-						strcpy(namebuf, "/dev/md/");
+						strcpy(namebuf, DEV_MD_DIR);
 						strcat(namebuf, path);
 						path = namebuf;
 					}
@@ -478,10 +478,10 @@ void RebuildMap(void)
 
 					while (conflict) {
 						if (unum >= 0)
-							sprintf(namebuf, "/dev/md/%s%s%d",
+							sprintf(namebuf, DEV_MD_DIR "%s%s%d",
 								name, sep, unum);
 						else
-							sprintf(namebuf, "/dev/md/%s",
+							sprintf(namebuf, DEV_MD_DIR "%s",
 								name);
 						unum++;
 						if (lstat(namebuf, &stb) != 0 &&
mdadm.h +8 -0
index b9127f9a..cb644fd8 100644
@@ -100,6 +100,14 @@ struct dlm_lksb {
 #define DEFAULT_BITMAP_DELAY 5
 #define DEFAULT_MAX_WRITE_BEHIND 256
 
+/* DEV_MD_DIR points to named MD devices directory.
+ * DEV_MD_DIR_LEN is a length with Null byte excluded.
+ */
+#ifndef DEV_MD_DIR
+#define DEV_MD_DIR "/dev/md/"
+#define DEV_MD_DIR_LEN (sizeof(DEV_MD_DIR) - 1)
+#endif /* DEV_MD_DIR */
+
 /* MAP_DIR should be somewhere that persists across the pivotroot
  * from early boot to late boot.
  * /run  seems to have emerged as the best standard.
mdopen.c +3 -3
index d18c9319..ed86df60 100644
@@ -188,12 +188,12 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
 	parts = autof >> 3;
 	autof &= 7;
 
-	strcpy(chosen, "/dev/md/");
+	strcpy(chosen, DEV_MD_DIR);
 	cname = chosen + strlen(chosen);
 
 	if (dev) {
-		if (strncmp(dev, "/dev/md/", 8) == 0) {
-			strcpy(cname, dev+8);
+		if (strncmp(dev, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0) {
+			strcpy(cname, dev + DEV_MD_DIR_LEN);
 		} else if (strncmp(dev, "/dev/", 5) == 0) {
 			char *e = dev + strlen(dev);
 			while (e > dev && isdigit(e[-1]))
super-ddf.c +1 -1
index b86c6acd..7213284e 100644
@@ -1648,7 +1648,7 @@ static void brief_examine_subarrays_ddf(struct supertype *st, int verbose)
 		fname_from_uuid(st, &info, nbuf1, ':');
 		_ddf_array_name(namebuf, ddf, i);
 		printf("ARRAY%s%s container=%s member=%d UUID=%s\n",
-		       namebuf[0] == '\0' ? "" : " /dev/md/", namebuf,
+		       namebuf[0] == '\0' ? "" : " " DEV_MD_DIR, namebuf,
 		       nbuf+5, i, nbuf1+5);
 	}
 }
super-intel.c +1 -1
index e155a8ae..bbbd4dc2 100644
@@ -2270,7 +2270,7 @@ static void brief_examine_subarrays_imsm(struct supertype *st, int verbose)
 		super->current_vol = i;
 		getinfo_super_imsm(st, &info, NULL);
 		fname_from_uuid(st, &info, nbuf1, ':');
-		printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
+		printf("ARRAY " DEV_MD_DIR "%.16s container=%s member=%d UUID=%s\n",
 		       dev->volume, nbuf + 5, i, nbuf1 + 5);
 	}
 }
super1.c +1 -2
index f7020320..d0907370 100644
@@ -642,8 +642,7 @@ static void brief_examine_super1(struct supertype *st, int verbose)
 
 	printf("ARRAY ");
 	if (nm) {
-		printf("/dev/md/");
-		print_escape(nm);
+		printf(DEV_MD_DIR "%s", nm);
 		putchar(' ');
 	}
 	if (verbose && c)
sysfs.c +1 -1
index ca1d888f..94d02f53 100644
@@ -1114,7 +1114,7 @@ void sysfsline(char *line)
 		if (strncasecmp(w, "name=", 5) == 0) {
 			char *devname = w + 5;
 
-			if (strncmp(devname, "/dev/md/", 8) == 0) {
+			if (strncmp(devname, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0) {
 				if (sr->devname)
 					pr_err("Only give one device per SYSFS line: %s\n",
 						devname);
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/4 mdadm: define DEV_NUM_PREF

In reply to Mariusz Tkaczyk

Use define instead of inlines. Add _LEN define.

---
 config.c |  4 ++--
 mdadm.h  |  8 ++++++++
 mdopen.c | 10 +++++-----
 3 files changed, 15 insertions(+), 7 deletions(-)
config.c +2 -2
index 59d5bfb6..f44cc1d3 100644
@@ -407,8 +407,8 @@ void arrayline(char *line)
 			if (strcasecmp(w, "<ignore>") == 0 ||
 			    strncmp(w, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0 ||
 			    (w[0] != '/' && w[0] != '<') ||
-			    (strncmp(w, "/dev/md", 7) == 0 &&
-			     is_number(w + 7)) ||
+			    (strncmp(w, DEV_NUM_PREF, DEV_NUM_PREF_LEN) == 0 &&
+			     is_number(w + DEV_NUM_PREF_LEN)) ||
 			    (strncmp(w, "/dev/md_d", 9) == 0 &&
 			     is_number(w + 9))) {
 				/* This is acceptable */;
mdadm.h +8 -0
index cb644fd8..63ec88a0 100644
@@ -100,6 +100,14 @@ struct dlm_lksb {
 #define DEFAULT_BITMAP_DELAY 5
 #define DEFAULT_MAX_WRITE_BEHIND 256
 
+/* DEV_NUM_PREF is a subpath to numbered MD devices, e.g. /dev/md1 or directory name.
+ * DEV_NUM_PREF_LEN is a length with Null byte excluded.
+ */
+#ifndef DEV_NUM_PREF
+#define DEV_NUM_PREF "/dev/md"
+#define DEV_NUM_PREF_LEN (sizeof(DEV_NUM_PREF) - 1)
+#endif /* DEV_NUM_PREF */
+
 /* DEV_MD_DIR points to named MD devices directory.
  * DEV_MD_DIR_LEN is a length with Null byte excluded.
  */
mdopen.c +5 -5
index ed86df60..b270fdd5 100644
@@ -411,11 +411,11 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
 			make_parts(devname, parts);
 
 		if (strcmp(chosen, devname) != 0) {
-			if (mkdir("/dev/md",0700) == 0) {
-				if (chown("/dev/md", ci->uid, ci->gid))
-					perror("chown /dev/md");
-				if (chmod("/dev/md", ci->mode| ((ci->mode>>2) & 0111)))
-					perror("chmod /dev/md");
+			if (mkdir(DEV_NUM_PREF, 0700) == 0) {
+				if (chown(DEV_NUM_PREF, ci->uid, ci->gid))
+					perror("chown " DEV_NUM_PREF);
+				if (chmod(DEV_NUM_PREF, ci->mode | ((ci->mode >> 2) & 0111)))
+					perror("chmod " DEV_NUM_PREF);
 			}
 
 			if (dev && strcmp(chosen, dev) == 0)
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/4 mdadm: define is_devname_ignore()

In reply to Mariusz Tkaczyk

Use function instead of direct checks across code.

---
 Incremental.c |  6 ++----
 Monitor.c     |  2 +-
 config.c      | 16 ++++++++++++++--
 mdadm.c       |  5 ++---
 mdadm.h       |  1 +
 5 files changed, 20 insertions(+), 10 deletions(-)
Incremental.c +2 -4
index b3dc499a..ebbbd4db 100644
@@ -202,8 +202,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
 	if (!match && rv == 2)
 		goto out;
 
-	if (match && match->devname &&
-	    strcasecmp(match->devname, "<ignore>") == 0) {
+	if (match && match->devname && is_devname_ignore(match->devname) == true) {
 		if (c->verbose >= 0)
 			pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
 				devname);
@@ -1564,8 +1563,7 @@ static int Incremental_container(struct supertype *st, char *devname,
 				break;
 			}
 
-			if (match && match->devname &&
-			    strcasecmp(match->devname, "<ignore>") == 0) {
+			if (match && match->devname && is_devname_ignore(match->devname) == true) {
 				if (c->verbose > 0)
 					pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
 					       match->container, match->member);
Monitor.c +1 -1
index 3273f2fb..ce8d5802 100644
@@ -250,7 +250,7 @@ int Monitor(struct mddev_dev *devlist,
 
 			if (mdlist->devname == NULL)
 				continue;
-			if (strcasecmp(mdlist->devname, "<ignore>") == 0)
+			if (is_devname_ignore(mdlist->devname) == true)
 				continue;
 			if (!is_mddev(mdlist->devname))
 				continue;
config.c +14 -2
index f44cc1d3..e61c0496 100644
@@ -119,6 +119,18 @@ int match_keyword(char *word)
 	return -1;
 }
 
+/**
+ * is_devname_ignore() - check if &devname is a special "<ignore>" keyword.
+ */
+bool is_devname_ignore(char *devname)
+{
+	static const char keyword[] = "<ignore>";
+
+	if (strcasecmp(devname, keyword) == 0)
+		return true;
+	return false;
+}
+
 /**
  * ident_init() - Set defaults.
  * @ident: ident pointer, not NULL.
@@ -404,7 +416,7 @@ void arrayline(char *line)
 			 *  <ignore>
 			 *  or anything that doesn't start '/' or '<'
 			 */
-			if (strcasecmp(w, "<ignore>") == 0 ||
+			if (is_devname_ignore(w) == true ||
 			    strncmp(w, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0 ||
 			    (w[0] != '/' && w[0] != '<') ||
 			    (strncmp(w, DEV_NUM_PREF, DEV_NUM_PREF_LEN) == 0 &&
@@ -571,7 +583,7 @@ void homehostline(char *line)
 	char *w;
 
 	for (w = dl_next(line); w != line; w = dl_next(w)) {
-		if (strcasecmp(w, "<ignore>") == 0)
+		if (is_devname_ignore(w) == true)
 			require_homehost = 0;
 		else if (home_host == NULL) {
 			if (strcasecmp(w, "<none>") == 0)
mdadm.c +2 -3
index 4685ad6b..cae37177 100644
@@ -154,7 +154,7 @@ int main(int argc, char *argv[])
 			continue;
 
 		case HomeHost:
-			if (strcasecmp(optarg, "<ignore>") == 0)
+			if (is_devname_ignore(optarg) == true)
 				c.require_homehost = 0;
 			else
 				c.homehost = optarg;
@@ -1749,8 +1749,7 @@ static int scan_assemble(struct supertype *ss,
 			int r;
 			if (a->assembled)
 				continue;
-			if (a->devname &&
-			    strcasecmp(a->devname, "<ignore>") == 0)
+			if (a->devname && is_devname_ignore(a->devname) == true)
 				continue;
 
 			r = Assemble(ss, a->devname,
mdadm.h +1 -0
index 63ec88a0..87fd4a57 100644
@@ -1648,6 +1648,7 @@ extern void print_escape(char *str);
 extern int use_udev(void);
 extern unsigned long GCD(unsigned long a, unsigned long b);
 extern int conf_name_is_free(char *name);
+extern bool is_devname_ignore(char *devname);
 extern int conf_verify_devnames(struct mddev_ident *array_list);
 extern int devname_matches(char *name, char *match);
 extern struct mddev_ident *conf_match(struct supertype *st,
Signature · 1 line
2.26.2
#4 lore raw

PATCH 4/4 mdadm: numbered names verification

In reply to Mariusz Tkaczyk

New functions added to remove literals and make the code reusable. Use parse_num() instead of is_numer().

---
 config.c | 17 ++---------------
 lib.c    |  2 +-
 mdadm.h  |  4 +++-
 util.c   | 44 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 17 deletions(-)
config.c +2 -15
index e61c0496..450880e3 100644
@@ -385,17 +385,6 @@ void devline(char *line)
 struct mddev_ident *mddevlist = NULL;
 struct mddev_ident **mddevlp = &mddevlist;
 
-static int is_number(char *w)
-{
-	/* check if there are 1 or more digits and nothing else */
-	int digits = 0;
-	while (*w && isdigit(*w)) {
-		digits++;
-		w++;
-	}
-	return (digits && ! *w);
-}
-
 void arrayline(char *line)
 {
 	char *w;
@@ -419,10 +408,8 @@ void arrayline(char *line)
 			if (is_devname_ignore(w) == true ||
 			    strncmp(w, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0 ||
 			    (w[0] != '/' && w[0] != '<') ||
-			    (strncmp(w, DEV_NUM_PREF, DEV_NUM_PREF_LEN) == 0 &&
-			     is_number(w + DEV_NUM_PREF_LEN)) ||
-			    (strncmp(w, "/dev/md_d", 9) == 0 &&
-			     is_number(w + 9))) {
+			    is_devname_md_numbered(w) == true ||
+			    is_devname_md_d_numbered(w) == true) {
 				/* This is acceptable */;
 				if (mis.devname)
 					pr_err("only give one device per ARRAY line: %s and %s\n",
lib.c +1 -1
index 65ea51e0..fe5c8d2c 100644
@@ -570,7 +570,7 @@ void free_line(char *line)
  *
  * Return: 0 on success, 1 otherwise.
  */
-int parse_num(int *dest, char *num)
+int parse_num(int *dest, const char *num)
 {
 	char *c = NULL;
 	long temp;
mdadm.h +3 -1
index 87fd4a57..b5d58448 100644
@@ -1599,7 +1599,7 @@ int default_layout(struct supertype *st, int level, int verbose);
 extern int is_near_layout_10(int layout);
 extern int parse_layout_10(char *layout);
 extern int parse_layout_faulty(char *layout);
-extern int parse_num(int *dest, char *num);
+extern int parse_num(int *dest, const char *num);
 extern int parse_cluster_confirm_arg(char *inp, char **devname, int *slot);
 extern int check_ext2(int fd, char *name);
 extern int check_reiser(int fd, char *name);
@@ -1649,6 +1649,8 @@ extern int use_udev(void);
 extern unsigned long GCD(unsigned long a, unsigned long b);
 extern int conf_name_is_free(char *name);
 extern bool is_devname_ignore(char *devname);
+extern bool is_devname_md_numbered(const char *devname);
+extern bool is_devname_md_d_numbered(const char *devname);
 extern int conf_verify_devnames(struct mddev_ident *array_list);
 extern int devname_matches(char *name, char *match);
 extern struct mddev_ident *conf_match(struct supertype *st,
util.c +44 -0

50 lines not on this page · raw message

Signature · 1 line
2.26.2
Acked-by on the v1 series
#5 lore raw
In reply to Mariusz Tkaczyk
Quoted 31 lines · Mariusz Tkaczyk

Hi Jes,
These patches remove multiple inlines across code and replace them by defines or functions. No functional changes intended. The goal is to make this some code reusable for both config and cmdline (mdadm.c). I next patchset I will start optimizing names verification (extended v2 of previous patchset).

Mariusz Tkaczyk (4):
mdadm: define DEV_MD_DIR
mdadm: define DEV_NUM_PREF
mdadm: define is_devname_ignore()
mdadm: numbered names verification

 Create.c      |  7 +++----
 Detail.c      |  9 ++++-----
 Incremental.c | 10 ++++------
 Monitor.c     | 34 +++++++++++++++++++---------------
 config.c      | 43 +++++++++++++++++++++----------------------
 lib.c         |  4 ++--
 mapfile.c     | 12 ++++++------
 mdadm.c       |  5 ++---
 mdadm.h       | 21 ++++++++++++++++++++-
 mdopen.c      | 16 ++++++++--------
 super-ddf.c   |  2 +-
 super-intel.c |  2 +-
 super1.c      |  3 +--
 sysfs.c       |  2 +-
 util.c        | 44 ++++++++++++++++++++++++++++++++++++++++++++
 15 files changed, 137 insertions(+), 77 deletions(-)
Quoted 3 lines

--
2.26.2

#6 lore raw
Quoted 33 lines · On Fri, 24 Mar 2023 10:13:04 +0800 Xiao Ni <[email protected]> wrote:
Quoted 31 lines · Mariusz Tkaczyk

Hi Jes,
These patches remove multiple inlines across code and replace them by defines or functions. No functional changes intended. The goal is to make this some code reusable for both config and cmdline (mdadm.c). I next patchset I will start optimizing names verification (extended v2 of previous patchset).

Mariusz Tkaczyk (4):
mdadm: define DEV_MD_DIR
mdadm: define DEV_NUM_PREF
mdadm: define is_devname_ignore()
mdadm: numbered names verification

 Create.c      |  7 +++----
 Detail.c      |  9 ++++-----
 Incremental.c | 10 ++++------
 Monitor.c     | 34 +++++++++++++++++++---------------
 config.c      | 43 +++++++++++++++++++++----------------------
 lib.c         |  4 ++--
 mapfile.c     | 12 ++++++------
 mdadm.c       |  5 ++---
 mdadm.h       | 21 ++++++++++++++++++++-
 mdopen.c      | 16 ++++++++--------
 super-ddf.c   |  2 +-
 super-intel.c |  2 +-
 super1.c      |  3 +--
 sysfs.c       |  2 +-
 util.c        | 44 ++++++++++++++++++++++++++++++++++++++++++++
 15 files changed, 137 insertions(+), 77 deletions(-)
Quoted 6 lines
Quoted 3 lines

--
2.26.2

Hi Jes,
Could you please take those patches?
We are working on changes in other areas and the error enum will be useful.

Thanks,
Mariusz

Applied
#7 lore raw
In reply to Mariusz Tkaczyk
Quoted 6 lines · Mariusz Tkaczyk

Hi Jes,
These patches remove multiple inlines across code and replace them by defines or functions. No functional changes intended. The goal is to make this some code reusable for both config and cmdline (mdadm.c). I next patchset I will start optimizing names verification (extended v2 of previous patchset).

Applied!

I'll push the later, I left my key at home.

Thanks,
Jes