diff --git a/Makefile b/Makefile index 0f42f88..5dd0e40 100644 --- 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 diff --git a/mapfile.c b/mapfile.c index ffe8e16..79a6bd8 100644 --- a/mapfile.c +++ b/mapfile.c @@ -52,28 +52,26 @@ #include #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 f1fe24f..b95c9c9 100644 --- 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 c4c0181..75fdcaa 100644 --- 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 d2d8445..aabfa8f 100644 --- 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 1ce6a7a..8935ceb 100644 --- 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);