]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Create arrays via metadata-update
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 4cecd6d0cfdc1f0a357475624ac72195ed871be8..49c36a06cafb43127e5be0214db8f87c4e6c6038 100644 (file)
--- a/util.c
+++ b/util.c
@@ -29,7 +29,9 @@
 
 #include       "mdadm.h"
 #include       "md_p.h"
+#include       <sys/socket.h>
 #include       <sys/utsname.h>
+#include       <sys/un.h>
 #include       <ctype.h>
 #include       <dirent.h>
 #include       <signal.h>
@@ -1065,6 +1067,47 @@ int signal_mdmon(int devnum)
 }
 
 
+int flush_metadata_updates(struct supertype *st)
+{
+       int sfd;
+       if (!st->updates) {
+               st->update_tail = NULL;
+               return -1;
+       }
+
+       sfd = connect_monitor(devnum2devname(st->container_dev));
+       if (sfd < 0)
+               return -1;
+
+       while (st->updates) {
+               struct metadata_update *mu = st->updates;
+               st->updates = mu->next;
+
+               send_message(sfd, mu, 0);
+               wait_reply(sfd, 0);
+               free(mu->buf);
+               free(mu);
+       }
+       ack(sfd, 0);
+       wait_reply(sfd, 0);
+       close(sfd);
+       st->update_tail = NULL;
+       return 0;
+}
+
+void append_metadata_update(struct supertype *st, void *buf, int len)
+{
+
+       struct metadata_update *mu = malloc(sizeof(*mu));
+
+       mu->buf = buf;
+       mu->len = len;
+       mu->space = NULL;
+       mu->next = NULL;
+       *st->update_tail = mu;
+       st->update_tail = &mu->next;
+}
+
 
 #ifdef __TINYC__
 /* tinyc doesn't optimize this check in ioctl.h out ... */