]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
fix: correct unlocking of map file
authorLukasz Dorau <lukasz.dorau@intel.com>
Sun, 2 Oct 2011 21:55:02 +0000 (08:55 +1100)
committerNeilBrown <neilb@suse.de>
Sun, 2 Oct 2011 21:55:02 +0000 (08:55 +1100)
1. Three missing map_unlock() calls were added.
2. Map file must be unlocked on fork, else child will hold lock.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Grow.c
Incremental.c
mapfile.c
mdadm.h

diff --git a/Grow.c b/Grow.c
index b7234e4517b0632f7731623e601010c56295e02e..90b84d7b7c7082ecb0238de4d176f92f4d42b9b2 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -2265,6 +2265,7 @@ started:
        default:
                return 0;
        case 0:
+               map_fork();
                break;
        }
 
@@ -2421,6 +2422,7 @@ int reshape_container(char *container, char *devname,
                printf(Name ": multi-array reshape continues in background\n");
                return 0;
        case 0: /* child */
+               map_fork();
                break;
        }
 
index 791ad85accfb4e656c40f0ca04f81940e87bfc13..a3e05a7cf5a632b8423c6be4f0dbb466d05c8680 100644 (file)
@@ -1469,6 +1469,7 @@ static int Incremental_container(struct supertype *st, char *devname,
                                        "Cannot activate array(s).\n");
                /* free container data and exit */
                sysfs_free(list);
+               map_unlock(&map);
                return 2;
        }
 
@@ -1532,6 +1533,7 @@ static int Incremental_container(struct supertype *st, char *devname,
                                        fprintf(stderr, Name ": array %s/%s is "
                                                "explicitly ignored by mdadm.conf\n",
                                                match->container, match->member);
+                               map_unlock(&map);
                                return 2;
                        }
                        if (match)
@@ -1547,6 +1549,7 @@ static int Incremental_container(struct supertype *st, char *devname,
                if (mdfd < 0) {
                        fprintf(stderr, Name ": failed to open %s: %s.\n",
                                chosen_name, strerror(errno));
+                       map_unlock(&map);
                        return 2;
                }
 
index ff1e97360dc20cf06e586567e22d58e1c982da97..997f0954ecedb8fcd41764384be89c33a45261e9 100644 (file)
--- a/mapfile.c
+++ b/mapfile.c
@@ -159,6 +159,18 @@ void map_unlock(struct map_ent **melp)
        lf = NULL;
 }
 
+void map_fork(void)
+{
+       /* We are forking, so must close the lock file.
+        * Don't risk flushing anything though.
+        */
+       if (lf) {
+               close(fileno(lf));
+               fclose(lf);
+               lf = NULL;
+       }
+}
+
 void map_add(struct map_ent **melp,
            int devnum, char *metadata, int uuid[4], char *path)
 {
diff --git a/mdadm.h b/mdadm.h
index 8dd37d9b4c6c8e54f6ea1c07582c29c62a2158a9..9165f7ad4eaea5c16bdfd1df72401e9a2daa3cba 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -427,6 +427,7 @@ extern void map_add(struct map_ent **melp,
                    int devnum, char *metadata, int uuid[4], char *path);
 extern int map_lock(struct map_ent **melp);
 extern void map_unlock(struct map_ent **melp);
+extern void map_fork(void);
 
 /* various details can be requested */
 enum sysfs_read_flags {