Skip to contentSkip to conversation

Clean up the directory mess

PATCH New Doug Ledford 1 participant 1 message Apr 2, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Clean up the directory mess

The confusion over directories in mdadm/mdmon is a nightmare. Clean it up some and leave it to distributions to pick a suitable directory for use and the stick with it.

Signature · 6 lines
Doug Ledford <[email protected]>
              GPG KeyID: CFBFF194
	      http://people.redhat.com/dledford

Infiniband specific RPMs available at
	      http://people.redhat.com/dledford/Infiniband

commit df3e08eaa7ee07528968bb7152dfaaeebd3c97cb

Author: Doug Ledford <[email protected]>
Date:   Fri Apr 2 10:53:47 2010 -0400

Fix all the confusion over directories once and for all. We now have 3 directory definitions: mdmon directory for its pid and sock files, mdmonitor directory which is for the mdadm monitor mode pid file and can only be passed in via command line, and the directory for the mdadm map file. Only the mdadm map file still hunts multiple locations, and the number of locations has been reduced to /var/run and the compile time specified location. I could see lowering that to just 1 location, but I didn't do that with this patch.

Makefile +9 -9
index 2aafad0..30e52a7 100644
@@ -58,16 +58,16 @@ CONFFILE = $(SYSCONFDIR)/mdadm.conf
 CONFFILE2 = $(SYSCONFDIR)/mdadm/mdadm.conf
 MAILCMD =/usr/sbin/sendmail -t
 CONFFILEFLAGS = -DCONFFILE=\"$(CONFFILE)\" -DCONFFILE2=\"$(CONFFILE2)\"
-# ALT_RUN should be somewhere that persists across the pivotroot
-# from early boot to late boot.
+# Both MAP_DIR and MDMON_DIR should be somewhere that persists across the
+# pivotroot from early boot to late boot.
 # If you don't have /lib/init/rw you might want to use /dev/.something
-#  e.g. make ALT_RUN=/dev/.mdadm
-ALT_RUN = /lib/init/rw
-ALT_MAPFILE = map
-VAR_RUN = /var/run
-ALTFLAGS = -DALT_RUN=\"$(ALT_RUN)\" -DALT_MAPFILE=\"$(ALT_MAPFILE)\"
-VARFLAGS = -DVAR_RUN=\"$(VAR_RUN)\"
-CFLAGS = $(CWFLAGS) $(CXFLAGS) -DSendmail=\""$(MAILCMD)"\" $(CONFFILEFLAGS) $(ALTFLAGS) $(VARFLAGS)
+#  e.g. make MAP_DIR=/dev/.mdadm
+MAP_DIR = /lib/init/rw/mdadm
+MAP_FILE = map
+MDMON_DIR = /lib/init/rw/mdmon
+DIRFLAGS = -DMAP_DIR=\"$(MAP_DIR)\" -DMAP_FILE=\"$(MAP_FILE)\"
+DIRFLAGS += -DMDMON_DIR=\"$(MDMON_DIR)\"
+CFLAGS = $(CWFLAGS) $(CXFLAGS) -DSendmail=\""$(MAILCMD)"\" $(CONFFILEFLAGS) $(DIRFLAGS)
 
 # If you want a static binary, you might uncomment these
 # LDFLAGS = -static
mapfile.c +8 -10
index d47fde1..f4339db 100644
@@ -52,28 +52,26 @@
 #include	<ctype.h>
 
 #define mapnames(base) { base, base ".new", base ".lock"}
-char *mapname[3][3] = {
-	mapnames(VAR_RUN "/map"),
-	mapnames("/var/run/mdadm.map"),
-	mapnames(ALT_RUN "/" ALT_MAPFILE)
+char *mapname[2][3] = {
+	mapnames(MAP_DIR "/" MAP_FILE),
+	mapnames("/var/run/mdadm.map")
 };
-char *mapdir[3] = { VAR_RUN, NULL, ALT_RUN };
+char *mapdir[2] = { MAP_DIR, NULL };
 
-int mapmode[3] = { O_RDONLY, O_RDWR|O_CREAT, O_RDWR|O_CREAT | O_TRUNC };
+int mapmode[3] = { O_RDONLY, O_RDWR|O_CREAT, O_RDWR|O_CREAT|O_TRUNC };
 char *mapsmode[3] = { "r", "w", "w"};
 
 FILE *open_map(int modenum, int *choice)
 {
 	int i;
 
-	for (i = 0 ; i < 3 ; i++) {
+	for (i = 0 ; i < 2 ; i++) {
 		int fd;
-		if ((mapmode[modenum] & O_CREAT) &&
-		    mapdir[modenum])
+		if ((mapmode[modenum] & O_CREAT) && mapdir[i])
 			/* Attempt to create directory, don't worry about
 			 * failure.
 			 */
-			mkdir(mapdir[modenum], 0755);
+			mkdir(mapdir[i], 0755);
 		fd = open(mapname[i][modenum], mapmode[modenum], 0600);
 		if (fd >= 0) {
 			*choice = i;
mdadm.h +21 -20

56 lines not on this page · raw message

mdmon.c +6 -22
index 69c320e..cbb72cc 100644
@@ -120,10 +120,10 @@ static int make_pidfile(char *devname)
 	int fd;
 	int n;
 
-	if (mkdir(pid_dir, 0700) < 0 &&
+	if (mkdir(MDMON_DIR, 0755) < 0 &&
 	    errno != EEXIST)
 		return -errno;
-	sprintf(path, "%s/%s.pid", pid_dir, devname);
+	sprintf(path, "%s/%s.pid", MDMON_DIR, devname);
 
 	fd = open(path, O_RDWR|O_CREAT|O_EXCL, 0600);
 	if (fd < 0)
@@ -189,13 +189,10 @@ void remove_pidfile(char *devname)
 {
 	char buf[100];
 
-	sprintf(buf, "%s/%s.pid", pid_dir, devname);
+	sprintf(buf, "%s/%s.pid", MDMON_DIR, devname);
 	unlink(buf);
-	sprintf(buf, "%s/%s.sock", pid_dir, devname);
+	sprintf(buf, "%s/%s.sock", MDMON_DIR, devname);
 	unlink(buf);
-	if (strcmp(pid_dir, ALT_RUN) == 0)
-		/* try to clean up when we are finished with this dir */
-		rmdir(pid_dir);
 }
 
 static int make_control_sock(char *devname)
@@ -208,7 +205,7 @@ static int make_control_sock(char *devname)
 	if (sigterm)
 		return -1;
 
-	sprintf(path, "%s/%s.sock", pid_dir, devname);
+	sprintf(path, "%s/%s.sock", MDMON_DIR, devname);
 	unlink(path);
 	sfd = socket(PF_LOCAL, SOCK_STREAM, 0);
 	if (sfd < 0)
@@ -445,12 +442,7 @@ static int mdmon(char *devname, int devnum, int must_fork, int takeover)
 	act.sa_handler = SIG_IGN;
 	sigaction(SIGPIPE, &act, NULL);
 
-	pid_dir = VAR_RUN;
 	victim = mdmon_pid(container->devnum);
-	if (victim < 0) {
-		pid_dir = ALT_RUN;
-		victim = mdmon_pid(container->devnum);
-	}
 	if (victim >= 0)
 		victim_sock = connect_monitor(container->devname);
 
@@ -474,16 +466,8 @@ static int mdmon(char *devname, int devnum, int must_fork, int takeover)
 	 */
 	if (victim > 0)
 		remove_pidfile(devname);
-	pid_dir = VAR_RUN;
 	if (make_pidfile(devname) < 0) {
-		/* Try the alternate */
-		pid_dir = ALT_RUN;
-		if (make_pidfile(devname) < 0) {
-			fprintf(stderr, "mdmon: Neither %s nor %s are writable\n"
-				"       cannot create .pid or .sock files.  Aborting\n",
-				VAR_RUN, ALT_RUN);
-			exit(3);
-		}
+		exit(3);
 	}
 	container->sock = make_control_sock(devname);
 
msg.c +1 -1
index d2d8445..aabfa8f 100644
@@ -147,7 +147,7 @@ int connect_monitor(char *devname)
 	int pos;
 	char *c;
 
-	pos = sprintf(path, "%s/", pid_dir);
+	pos = sprintf(path, "%s/", MDMON_DIR);
 	if (is_subarray(devname)) {
 		devname++;
 		c = strchr(devname, '/');
util.c +1 -3
index 79d2b0f..bdb19f9 100644
@@ -1499,15 +1499,13 @@ int fd2devnum(int fd)
 	return NoMdDev;
 }
 
-char *pid_dir = VAR_RUN;
-
 int mdmon_pid(int devnum)
 {
 	char path[100];
 	char pid[10];
 	int fd;
 	int n;
-	sprintf(path, "%s/%s.pid", pid_dir, devnum2devname(devnum));
+	sprintf(path, "%s/%s.pid", MDMON_DIR, devnum2devname(devnum));
 	fd = open(path, O_RDONLY | O_NOATIME, 0);
 
 	if (fd < 0)