]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Try multiple times to open unix monitor socket
authorCole Robinson <crobinso@redhat.com>
Tue, 14 Jul 2009 22:09:27 +0000 (18:09 -0400)
committerCole Robinson <crobinso@redhat.com>
Thu, 16 Jul 2009 16:52:53 +0000 (12:52 -0400)
Unlike the pty monitor (which we know exists since we scrape its path from
stdout), we have no way of knowing that the unix monitor socket should exist/
be initialized. As a result, some of my KVM guests randomly fail to start on
F10 host.

Try to open the unix socket in a 3 second timeout loop. Ignore EACCES (path
does not exist if a first time run) and ECONNREFUSED (leftover socket from
a previous run hasn't been removed yet). Fixes things for me.

src/qemu_driver.c

index 429235c1969bd7b0fdf16786ce7038e0935a858d..00dc6e5ba7185d200b2a96acc33538727554202d 100644 (file)
@@ -873,6 +873,8 @@ qemudOpenMonitorUnix(virConnectPtr conn,
 {
     struct sockaddr_un addr;
     int monfd;
+    int timeout = 3; /* In seconds */
+    int ret, i;
 
     if ((monfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
         virReportSystemError(conn, errno,
@@ -884,10 +886,28 @@ qemudOpenMonitorUnix(virConnectPtr conn,
     addr.sun_family = AF_UNIX;
     strncpy(addr.sun_path, monitor, sizeof(addr.sun_path));
 
-    if (connect(monfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+    do {
+        ret = connect(monfd, (struct sockaddr *) &addr, sizeof(addr));
+
+        if (ret == 0)
+            break;
+
+        if (errno == EACCES || errno == ECONNREFUSED) {
+            /* EACCES       : Socket may not have shown up yet
+             * ECONNREFUSED : Leftover socket hasn't been removed yet */
+            continue;
+        }
+
         virReportSystemError(conn, errno, "%s",
                              _("failed to connect to monitor socket"));
         goto error;
+
+    } while ((++i <= timeout*5) && (usleep(.2 * 1000000) <= 0));
+
+    if (ret != 0) {
+        virReportSystemError(conn, errno, "%s",
+                             _("monitor socket did not show up."));
+        goto error;
     }
 
     if (qemudOpenMonitorCommon(conn, driver, vm, monfd, reconnect) < 0)