]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Fix all the confusion over directories once and for all.
authorDoug Ledford <dledford@redhat.com>
Tue, 20 Jul 2010 16:15:37 +0000 (12:15 -0400)
committerDoug Ledford <dledford@redhat.com>
Thu, 22 Jul 2010 14:16:30 +0000 (10:16 -0400)
We now have 3 directory definitions: mdmon directory for its pid and
sock files (compile time define, not changable at run time), mdmonitor
directory which is for the mdadm monitor mode pid file (can only be
passed in via command line at the time mdadm is invoked in monitor mode),
and the directory for the mdadm incremental assembly map file (compile
time define, not changable at run time).  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.  Re-use of similar
sounding defines that actually didn't denote their actual usage at
compile time made it more difficult for a person to know what affect
changing the compile time defines would have on the resulting programs.

This patch renames the various defines to clearly identify which item
the define affects.  It also reduces the number of various directories
which will be searched for these files as this has lead to confusion
in mdadm and mdmon in terms of which files should take precedence when
files exist in multiple locations, etc.  It's best if the person
compiling the program intentionally and with planning selects the
right directories to be used for the various purposes.  Which directory
is right depends on which items you are talking about and what boot
loader your system uses and what initramfs generation program your
system uses.  Because of the inter-dependency of all these items it
would typically be up to the distribution that mdadm is being integrated
into to select the correct values for these defines.

Signed-off-by: Doug Ledford <dledford@redhat.com>
Makefile
mapfile.c
mdadm.h
mdmon.c
msg.c
util.c

index 0f42f8829a30a8cdb9a9c8e41f382924aea83d13..5dd0e4048baa6b2b4e3397ec3877f733e5a2a68f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -64,16 +64,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/mdadm
-ALT_MAPFILE = map
-VAR_RUN = /var/run/mdadm
-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)
 
 # The glibc TLS ABI requires applications that call clone(2) to set up
 # TLS data structures, use pthreads until mdmon implements this support
index ffe8e16f1ef582023467844d7bdbb1c44462b99e..79a6bd80cb70bb4e33c84617cce5b8469a0e17ff 100644 (file)
--- a/mapfile.c
+++ b/mapfile.c
 #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;
diff --git a/mdadm.h b/mdadm.h
index f1fe24f3c03184eec1ec3200545c89154c1d858a..b95c9c9a078955e28e17c73c39220b60db660b43 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -68,28 +68,30 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 #define DEFAULT_BITMAP_DELAY 5
 #define DEFAULT_MAX_WRITE_BEHIND 256
 
-/* VAR_RUN is where pid and socket files used for communicating
- * with mdmon normally live.  It should be /var/run, but if
- * it is too hard to remount /var/run as read-only rather than
- * unmounting it at shutdown time, then it should be
- * redefined to some place that comfortably persists until
- * final shutdown, possibly in /dev if that is a tmpfs.
- * Note: VAR_RUN does not need to be writable at shutdown,
- * only during boot when "mdmon --takeover" is run.
- */
-#ifndef VAR_RUN
-#define VAR_RUN "/var/run/mdadm"
-#endif /* VAR_RUN */
-/* ALT_RUN should be somewhere that persists across the pivotroot
+/* MAP_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
  */
-#ifndef ALT_RUN
-#define ALT_RUN "/lib/init/rw/mdadm"
-#endif /* ALT_RUN */
-#ifndef ALT_MAPFILE
-#define ALT_MAPFILE "map"
-#endif /* ALT_MAPFILE */
+#ifndef MAP_DIR
+#define MAP_DIR "/lib/init/rw/mdadm"
+#endif /* MAP_DIR */
+/* MAP_FILE is what we name the map file we put in MAP_DIR, in case you
+ * want something other than the default of "map"
+ */
+#ifndef MAP_FILE
+#define MAP_FILE "map"
+#endif /* MAP_FILE */
+/* MDMON_DIR is where pid and socket files used for communicating
+ * with mdmon normally live.  It *should* be /var/run, but when
+ * mdmon is needed at early boot then it needs to write there prior
+ * to /var/run being mounted read/write, and it also then needs to
+ * persist beyond when /var/run is mounter read-only.  So, to be
+ * safe, the default is somewhere that is read/write early in the
+ * boot process and stays up as long as possible during shutdown.
+ */
+#ifndef MDMON_DIR
+#define MDMON_DIR "/lib/init/rw/mdmon"
+#endif /* MDMON_DIR */
 
 #include       "md_u.h"
 #include       "md_p.h"
@@ -934,7 +936,6 @@ int is_container_active(char *devname);
 extern int open_subarray(char *dev, struct supertype *st, int quiet);
 extern struct superswitch *version_to_superswitch(char *vers);
 
-extern char *pid_dir;
 extern int mdmon_running(int devnum);
 extern int mdmon_pid(int devnum);
 extern int check_env(char *name);
diff --git a/mdmon.c b/mdmon.c
index c4c0181a8b81bd800b640e515a323f2b80c60b1b..75fdcaad2fb047141b9e6f7715a8c2b7807a4c87 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -147,10 +147,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)
@@ -204,13 +204,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)
@@ -223,7 +220,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)
@@ -459,12 +456,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);
 
@@ -488,16 +480,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);
 
diff --git a/msg.c b/msg.c
index d2d844589a1c565efe1b1686cced5e8d55395eee..aabfa8f566072b64d900b91c8e50cfaf0fde0057 100644 (file)
--- a/msg.c
+++ b/msg.c
@@ -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, '/');
diff --git a/util.c b/util.c
index 1ce6a7a93b56d405aac63bb8dbea7a19e8f1a021..8935ceb94776301c5400a44bbe1023b2cf9397a1 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1666,8 +1666,6 @@ int fd2devnum(int fd)
        return NoMdDev;
 }
 
-char *pid_dir = VAR_RUN;
-
 int mdmon_pid(int devnum)
 {
        char path[100];
@@ -1676,7 +1674,7 @@ int mdmon_pid(int devnum)
        int n;
        char *devname = devnum2devname(devnum);
 
-       sprintf(path, "%s/%s.pid", pid_dir, devname);
+       sprintf(path, "%s/%s.pid", MDMON_DIR, devname);
        free(devname);
 
        fd = open(path, O_RDONLY | O_NOATIME, 0);