Having single function to read mdmon pid file.
authorNeilBrown <neilb@suse.de>
Thu, 4 Feb 2010 05:47:21 +0000 (16:47 +1100)
committerNeilBrown <neilb@suse.de>
Thu, 4 Feb 2010 05:47:21 +0000 (16:47 +1100)
We don't need three.
One (signal_mdmon) wasn't even being used.

Signed-off-by: NeilBrown <neilb@suse.de>
mdadm.h
mdmon.c
util.c

diff --git a/mdadm.h b/mdadm.h
index 836c64d..eec5c0c 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -883,7 +883,7 @@ extern int open_mddev(char *dev, int report_errors);
 extern int open_container(int fd);
 
 extern int mdmon_running(int devnum);
 extern int open_container(int fd);
 
 extern int mdmon_running(int devnum);
-extern int signal_mdmon(int devnum);
+extern int mdmon_pid(int devnum);
 extern int check_env(char *name);
 extern __u32 random32(void);
 extern int start_mdmon(int devnum);
 extern int check_env(char *name);
 extern __u32 random32(void);
 extern int start_mdmon(int devnum);
diff --git a/mdmon.c b/mdmon.c
index 1cdbde1..d20bb3e 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -148,24 +148,6 @@ int is_container_member(struct mdstat_ent *mdstat, char *container)
        return 1;
 }
 
        return 1;
 }
 
-pid_t devname2mdmon(char *devname)
-{
-       char buf[100];
-       pid_t pid = -1;
-       int fd;
-
-       sprintf(buf, "/var/run/mdadm/%s.pid", devname);
-       fd = open(buf, O_RDONLY|O_NOATIME);
-       if (fd < 0)
-               return -1;
-
-       if (read(fd, buf, sizeof(buf)) > 0)
-               sscanf(buf, "%d\n", &pid);
-       close(fd);
-
-       return pid;
-}
-
 static void try_kill_monitor(pid_t pid, char *devname, int sock)
 {
        char buf[100];
 static void try_kill_monitor(pid_t pid, char *devname, int sock)
 {
        char buf[100];
@@ -373,7 +355,7 @@ static int mdmon(char *devname, int devnum, int must_fork, char *switchroot)
 
                switch (fork()) {
                case 0:
 
                switch (fork()) {
                case 0:
-                       victim = devname2mdmon(devname);
+                       victim = mdmon_pid(devnum);
                        victim_sock = connect_monitor(devname);
                        if (chroot(switchroot) != 0) {
                                fprintf(stderr, "mdmon: failed to chroot to '%s': %s\n",
                        victim_sock = connect_monitor(devname);
                        if (chroot(switchroot) != 0) {
                                fprintf(stderr, "mdmon: failed to chroot to '%s': %s\n",
@@ -511,7 +493,7 @@ static int mdmon(char *devname, int devnum, int must_fork, char *switchroot)
                 * the new root
                 */
                if (switchroot[0] == '/') {
                 * the new root
                 */
                if (switchroot[0] == '/') {
-                       victim = devname2mdmon(container->devname);
+                       victim = mdmon_pid(container->devnum);
                        victim_sock = connect_monitor(container->devname);
                } else {
                        victim = atoi(switchroot);
                        victim_sock = connect_monitor(container->devname);
                } else {
                        victim = atoi(switchroot);
@@ -527,7 +509,7 @@ static int mdmon(char *devname, int devnum, int must_fork, char *switchroot)
                        exit(3);
                }
                /* if there is a pid file, kill whoever is there just in case */
                        exit(3);
                }
                /* if there is a pid file, kill whoever is there just in case */
-               victim = devname2mdmon(container->devname);
+               victim = mdmon_pid(container->devnum);
        }
        if (container->ss->load_super(container, mdfd, devname)) {
                fprintf(stderr, "mdmon: Cannot load metadata for %s\n",
        }
        if (container->ss->load_super(container, mdfd, devname)) {
                fprintf(stderr, "mdmon: Cannot load metadata for %s\n",
diff --git a/util.c b/util.c
index 5feec43..e5b0c1f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1463,14 +1463,14 @@ int fd2devnum(int fd)
        return NoMdDev;
 }
 
        return NoMdDev;
 }
 
-int mdmon_running(int devnum)
+int mdmon_pid(int devnum)
 {
        char path[100];
        char pid[10];
        int fd;
        int n;
        sprintf(path, "/var/run/mdadm/%s.pid", devnum2devname(devnum));
 {
        char path[100];
        char pid[10];
        int fd;
        int n;
        sprintf(path, "/var/run/mdadm/%s.pid", devnum2devname(devnum));
-       fd = open(path, O_RDONLY, 0);
+       fd = open(path, O_RDONLY | O_NOATIME, 0);
 
        if (fd < 0)
                return 0;
 
        if (fd < 0)
                return 0;
@@ -1478,27 +1478,15 @@ int mdmon_running(int devnum)
        close(fd);
        if (n <= 0)
                return 0;
        close(fd);
        if (n <= 0)
                return 0;
-       if (kill(atoi(pid), 0) == 0)
-               return 1;
-       return 0;
+       return atoi(pid);
 }
 
 }
 
-int signal_mdmon(int devnum)
+int mdmon_running(int devnum)
 {
 {
-       char path[100];
-       char pid[10];
-       int fd;
-       int n;
-       sprintf(path, "/var/run/mdadm/%s.pid", devnum2devname(devnum));
-       fd = open(path, O_RDONLY, 0);
-
-       if (fd < 0)
-               return 0;
-       n = read(fd, pid, 9);
-       close(fd);
-       if (n <= 0)
+       int pid = mdmon_pid(devnum);
+       if (pid <= 0)
                return 0;
                return 0;
-       if (kill(atoi(pid), SIGUSR1) == 0)
+       if (kill(pid, 0) == 0)
                return 1;
        return 0;
 }
                return 1;
        return 0;
 }