NeilBrown: mdmon: simplify try_kill_monitor

Martin F. Krafft madduck at alioth.debian.org
Mon May 24 09:20:49 UTC 2010


Module: mdadm
Branch: upstream
Commit: af7ca334874b86921c7fe76059f33bfddb209296
URL:    http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=af7ca334874b86921c7fe76059f33bfddb209296

Author: NeilBrown <neilb at suse.de>
Date:   Fri Jan 29 11:33:01 2010 +1100

mdmon: simplify try_kill_monitor

After we SIGTERM the monitor we need to wait for it to finish up.
Rather than the complexity of waiting for every md array to be clean,
we can simply read from the sock connected to the monitor.
When the monitor dies, we will get EOF.  Before then we will block.

Signed-off-by: NeilBrown <neilb at suse.de>

---

 mdmon.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/mdmon.c b/mdmon.c
index b2f35c2..c66b06b 100644
--- a/mdmon.c
+++ b/mdmon.c
@@ -179,8 +179,8 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
 {
 	char buf[100];
 	int fd;
-	struct mdstat_ent *mdstat;
 	int n;
+	long fl;
 
 	/* first rule of survival... don't off yourself */
 	if (pid == getpid())
@@ -201,13 +201,12 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
 
 	kill(pid, SIGTERM);
 
-	mdstat = mdstat_read(0, 0);
-	for ( ; mdstat; mdstat = mdstat->next)
-		if (is_container_member(mdstat, devname)) {
-			sprintf(buf, "/dev/%s", mdstat->dev);
-			WaitClean(buf, sock, 0);
-		}
-	free_mdstat(mdstat);
+	/* Wait for monitor to exit by reading from the socket, after
+	 * clearing the non-blocking flag */
+	fl = fcntl(sock, F_GETFL, 0);
+	fl &= ~O_NONBLOCK;
+	fcntl(sock, F_SETFL, fl);
+	read(sock, buf, 100);
 }
 
 void remove_pidfile(char *devname)




More information about the pkg-mdadm-commits mailing list