render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Daniel P. Berrange 996d0e
diff -rup libvirt-0.6.0.orig/src/qemu_driver.c libvirt-0.6.0.new/src/qemu_driver.c
Daniel P. Berrange 996d0e
--- libvirt-0.6.0.orig/src/qemu_driver.c	2009-01-31 09:04:18.000000000 +0000
Daniel P. Berrange 996d0e
+++ libvirt-0.6.0.new/src/qemu_driver.c	2009-02-18 11:15:37.000000000 +0000
Daniel P. Berrange 996d0e
@@ -633,6 +633,7 @@ qemudReadMonitorOutput(virConnectPtr con
Daniel P. Berrange 996d0e
 {
Daniel P. Berrange 996d0e
     int got = 0;
Daniel P. Berrange 996d0e
     buf[0] = '\0';
Daniel P. Berrange 996d0e
+    timeout *= 1000; /* poll wants milli seconds */
Daniel P. Berrange 996d0e
 
Daniel P. Berrange 996d0e
     /* Consume & discard the initial greeting */
Daniel P. Berrange 996d0e
     while (got < (buflen-1)) {
Daniel P. Berrange 996d0e
@@ -694,6 +695,56 @@ qemudReadMonitorOutput(virConnectPtr con
Daniel P. Berrange 996d0e
 
Daniel P. Berrange 996d0e
 }
Daniel P. Berrange 996d0e
 
Daniel P. Berrange 996d0e
+
Daniel P. Berrange 996d0e
+/*
Daniel P. Berrange 996d0e
+ * Returns -1 for error, 0 on success
Daniel P. Berrange 996d0e
+ */
Daniel P. Berrange 996d0e
+static int
Daniel P. Berrange 996d0e
+qemudReadLogOutput(virConnectPtr conn,
Daniel P. Berrange 996d0e
+                   virDomainObjPtr vm,
Daniel P. Berrange 996d0e
+                   int fd,
Daniel P. Berrange 996d0e
+                   char *buf,
Daniel P. Berrange 996d0e
+                   int buflen,
Daniel P. Berrange 996d0e
+                   qemudHandlerMonitorOutput func,
Daniel P. Berrange 996d0e
+                   const char *what,
Daniel P. Berrange 996d0e
+                   int timeout)
Daniel P. Berrange 996d0e
+{
Daniel P. Berrange 996d0e
+    int got = 0;
Daniel P. Berrange 996d0e
+    int ret;
Daniel P. Berrange 996d0e
+    int retries = timeout*10;
Daniel P. Berrange 996d0e
+    buf[0] = '\0';
Daniel P. Berrange 996d0e
+
Daniel P. Berrange 996d0e
+    while (retries) {
Daniel P. Berrange 996d0e
+        while((ret = read(fd, buf+got, buflen-got-1)) > 0) {
Daniel P. Berrange 996d0e
+            got += ret;
Daniel P. Berrange 996d0e
+            buf[got] = '\0';
Daniel P. Berrange 996d0e
+            if ((buflen-got-1) == 0) {
Daniel P. Berrange 996d0e
+                qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
Daniel P. Berrange 996d0e
+                                 _("Out of space while reading %s log output"), what);
Daniel P. Berrange 996d0e
+                return -1;
Daniel P. Berrange 996d0e
+            }
Daniel P. Berrange 996d0e
+        }
Daniel P. Berrange 996d0e
+
Daniel P. Berrange 996d0e
+        if (ret < 0 && errno != EINTR) {
Daniel P. Berrange 996d0e
+            virReportSystemError(conn, errno,
Daniel P. Berrange 996d0e
+                                 _("Failure while reading %s log output"),
Daniel P. Berrange 996d0e
+                                 what);
Daniel P. Berrange 996d0e
+            return -1;
Daniel P. Berrange 996d0e
+        }
Daniel P. Berrange 996d0e
+
Daniel P. Berrange 996d0e
+        ret = func(conn, vm, buf, fd);
Daniel P. Berrange 996d0e
+        if (ret <= 0)
Daniel P. Berrange 996d0e
+            return ret;
Daniel P. Berrange 996d0e
+
Daniel P. Berrange 996d0e
+        usleep(100*1000);
Daniel P. Berrange 996d0e
+        retries--;
Daniel P. Berrange 996d0e
+    }
Daniel P. Berrange 996d0e
+    if (retries == 0)
Daniel P. Berrange 996d0e
+        qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
Daniel P. Berrange 996d0e
+                         _("Timed out while reading %s log output"), what);
Daniel P. Berrange 996d0e
+    return -1;
Daniel P. Berrange 996d0e
+}
Daniel P. Berrange 996d0e
+
Daniel P. Berrange 996d0e
 static int
Daniel P. Berrange 996d0e
 qemudCheckMonitorPrompt(virConnectPtr conn ATTRIBUTE_UNUSED,
Daniel P. Berrange 996d0e
                         virDomainObjPtr vm,
Daniel P. Berrange 996d0e
@@ -738,7 +789,7 @@ static int qemudOpenMonitor(virConnectPt
Daniel P. Berrange 996d0e
                                    vm, monfd,
Daniel P. Berrange 996d0e
                                    buf, sizeof(buf),
Daniel P. Berrange 996d0e
                                    qemudCheckMonitorPrompt,
Daniel P. Berrange 996d0e
-                                   "monitor", 10000) <= 0)
Daniel P. Berrange 996d0e
+                                   "monitor", 10) <= 0)
Daniel P. Berrange 996d0e
             ret = -1;
Daniel P. Berrange 996d0e
         else
Daniel P. Berrange 996d0e
             ret = 0;
Daniel P. Berrange 996d0e
@@ -770,6 +821,7 @@ static int qemudOpenMonitor(virConnectPt
Daniel P. Berrange 996d0e
     return ret;
Daniel P. Berrange 996d0e
 }
Daniel P. Berrange 996d0e
 
Daniel P. Berrange 996d0e
+/* Returns -1 for error, 0 success, 1 continue reading */
Daniel P. Berrange 996d0e
 static int qemudExtractMonitorPath(virConnectPtr conn,
Daniel P. Berrange 996d0e
                                    const char *haystack,
Daniel P. Berrange 996d0e
                                    size_t *offset,
Daniel P. Berrange 996d0e
@@ -873,19 +925,16 @@ static int qemudWaitForMonitor(virConnec
Daniel P. Berrange 996d0e
         < 0)
Daniel P. Berrange 996d0e
         return -1;
Daniel P. Berrange 996d0e
 
Daniel P. Berrange 996d0e
-    ret = qemudReadMonitorOutput(conn, vm, logfd, buf, sizeof(buf),
Daniel P. Berrange 996d0e
-                                 qemudFindCharDevicePTYs,
Daniel P. Berrange 996d0e
-                                 "console", 3000);
Daniel P. Berrange 996d0e
+    ret = qemudReadLogOutput(conn, vm, logfd, buf, sizeof(buf),
Daniel P. Berrange 996d0e
+                             qemudFindCharDevicePTYs,
Daniel P. Berrange 996d0e
+                             "console", 3);
Daniel P. Berrange 996d0e
     if (close(logfd) < 0)
Daniel P. Berrange 996d0e
         qemudLog(QEMUD_WARN, _("Unable to close logfile: %s\n"),
Daniel P. Berrange 996d0e
                  strerror(errno));
Daniel P. Berrange 996d0e
 
Daniel P. Berrange 996d0e
-    if (ret == 1) /* Success */
Daniel P. Berrange 996d0e
+    if (ret == 0) /* success */
Daniel P. Berrange 996d0e
         return 0;
Daniel P. Berrange 996d0e
 
Daniel P. Berrange 996d0e
-    if (ret == -1)
Daniel P. Berrange 996d0e
-        return -1;
Daniel P. Berrange 996d0e
-
Daniel P. Berrange 996d0e
     /* Unexpected end of file - inform user of QEMU log data */
Daniel P. Berrange 996d0e
     qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
Daniel P. Berrange 996d0e
                      _("unable to start guest: %s"), buf);