]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdmon.c
imsm: update num_data_stripes according to dev_size
[thirdparty/mdadm.git] / mdmon.c
diff --git a/mdmon.c b/mdmon.c
index 8cd53d8b24be4cf0936f90943e397cbe1d1ae97e..ff985d291ee9045ede3daf68c1184af3ee0384eb 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -67,6 +67,8 @@
 #include       "mdadm.h"
 #include       "mdmon.h"
 
+char const Name[] = "mdmon";
+
 struct active_array *discard_this;
 struct active_array *pending_discard;
 
@@ -169,6 +171,7 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
        int fd;
        int n;
        long fl;
+       int rv;
 
        /* first rule of survival... don't off yourself */
        if (pid == getpid())
@@ -199,9 +202,16 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
        fl &= ~O_NONBLOCK;
        fcntl(sock, F_SETFL, fl);
        n = read(sock, buf, 100);
-       /* Ignore result, it is just the wait that
-        * matters
-        */
+
+       /* If there is I/O going on it might took some time to get to
+        * clean state. Wait for monitor to exit fully to avoid races.
+        * Ping it with SIGUSR1 in case that it is sleeping  */
+       for (n = 0; n < 25; n++) {
+               rv = kill(pid, SIGUSR1);
+               if (rv < 0)
+                       break;
+               usleep(200000);
+       }
 }
 
 void remove_pidfile(char *devname)
@@ -232,7 +242,8 @@ static int make_control_sock(char *devname)
 
        addr.sun_family = PF_LOCAL;
        strcpy(addr.sun_path, path);
-       if (bind(sfd, &addr, sizeof(addr)) < 0) {
+       umask(077); /* ensure no world write access */
+       if (bind(sfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
                close(sfd);
                return -1;
        }
@@ -405,10 +416,6 @@ static int mdmon(char *devnm, int must_fork, int takeover)
                pr_err("%s: %s\n", devnm, strerror(errno));
                return 1;
        }
-       if (md_get_version(mdfd) < 0) {
-               pr_err("%s: Not an md device\n", devnm);
-               return 1;
-       }
 
        /* Fork, and have the child tell us when they are ready */
        if (must_fork) {
@@ -429,6 +436,7 @@ static int mdmon(char *devnm, int must_fork, int takeover)
                                wait(&status);
                                status = WEXITSTATUS(status);
                        }
+                       close(pfd[0]);
                        return status;
                }
        } else
@@ -516,10 +524,12 @@ static int mdmon(char *devnm, int must_fork, int takeover)
        container->sock = make_control_sock(devnm);
 
        status = 0;
-       if (write(pfd[1], &status, sizeof(status)) < 0)
-               pr_err("failed to notify our parent: %d\n",
-                       getppid());
-       close(pfd[1]);
+       if (pfd[1] >= 0) {
+               if (write(pfd[1], &status, sizeof(status)) < 0)
+                       pr_err("failed to notify our parent: %d\n",
+                              getppid());
+               close(pfd[1]);
+       }
 
        mlockall(MCL_CURRENT | MCL_FUTURE);
 
@@ -574,11 +584,6 @@ int restore_stripes(int *dest, unsigned long long *offsets,
        return 1;
 }
 
-void abort_reshape(struct mdinfo *sra)
-{
-       return;
-}
-
 int save_stripes(int *source, unsigned long long *offsets,
                 int raid_disks, int chunk_size, int level, int layout,
                 int nwrites, int *dest,
@@ -587,3 +592,10 @@ int save_stripes(int *source, unsigned long long *offsets,
 {
        return 0;
 }
+
+struct superswitch super0 = {
+       .name = "0.90",
+};
+struct superswitch super1 = {
+       .name = "1.x",
+};