]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Assemble/Incremental: don't hold O_EXCL on mddev after assembly.
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 12a19e7a5a3ac765bbd088ebc304ebd9bddcaead..e32d97a011e7a791870f1015830a363e19167a0e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1950,3 +1950,17 @@ int in_initrd(void)
                ((unsigned long)s.f_type == TMPFS_MAGIC ||
                 (unsigned long)s.f_type == RAMFS_MAGIC);
 }
+
+void reopen_mddev(int mdfd)
+{
+       /* Re-open without any O_EXCL, but keep
+        * the same fd
+        */
+       char *devnm;
+       int fd;
+       devnm = fd2devnm(mdfd);
+       close(mdfd);
+       fd = open_dev(devnm);
+       if (fd >= 0 && fd != mdfd)
+               dup2(fd, mdfd);
+}