[PATCH 16/19] qemu: monitor: Remove waiting for monitor

Peter Krempa pkrempa at redhat.com
Thu Feb 10 12:45:37 UTC 2022


Now all supported qemus have FD passing for the monitor so all of the
backoff timer infra used to wait for qemu to create the monitor socket
became obsolete and can be removed.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_monitor.c      | 61 ++++++------------------------------
 src/qemu/qemu_monitor.h      |  4 +--
 src/qemu/qemu_process.c      | 29 ++++++-----------
 tests/qemumonitortestutils.c |  2 --
 4 files changed, 19 insertions(+), 77 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 95ed6199b1..a4c6848a80 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -227,14 +227,10 @@ qemuMonitorDispose(void *obj)


 static int
-qemuMonitorOpenUnix(const char *monitor,
-                    pid_t cpid,
-                    bool retry,
-                    unsigned long long timeout)
+qemuMonitorOpenUnix(const char *monitor)
 {
     struct sockaddr_un addr;
     VIR_AUTOCLOSE monfd = -1;
-    virTimeBackOffVar timebackoff;
     int ret = -1;

     if ((monfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
@@ -251,39 +247,11 @@ qemuMonitorOpenUnix(const char *monitor,
         return -1;
     }

-    if (retry) {
-        if (virTimeBackOffStart(&timebackoff, 1, timeout * 1000) < 0)
-            return -1;
-        while (virTimeBackOffWait(&timebackoff)) {
-            ret = connect(monfd, (struct sockaddr *)&addr, sizeof(addr));
-
-            if (ret == 0)
-                break;
-
-            if ((errno == ENOENT || errno == ECONNREFUSED) &&
-                (!cpid || virProcessKill(cpid, 0) == 0)) {
-                /* ENOENT       : Socket may not have shown up yet
-                 * ECONNREFUSED : Leftover socket hasn't been removed yet */
-                continue;
-            }
-
-            virReportSystemError(errno, "%s",
-                                 _("failed to connect to monitor socket"));
-            return -1;
-        }
-
-        if (ret != 0) {
-            virReportSystemError(errno, "%s",
-                                 _("monitor socket did not show up"));
-            return -1;
-        }
-    } else {
-        ret = connect(monfd, (struct sockaddr *) &addr, sizeof(addr));
-        if (ret < 0) {
-            virReportSystemError(errno, "%s",
-                                 _("failed to connect to monitor socket"));
-            return -1;
-        }
+    ret = connect(monfd, (struct sockaddr *) &addr, sizeof(addr));
+    if (ret < 0) {
+        virReportSystemError(errno, "%s",
+                             _("failed to connect to monitor socket"));
+        return -1;
     }

     ret = monfd;
@@ -698,29 +666,21 @@ qemuMonitorOpenInternal(virDomainObj *vm,
 }


-#define QEMU_DEFAULT_MONITOR_WAIT 30
-
 /**
  * qemuMonitorOpen:
  * @vm: domain object
  * @config: monitor configuration
- * @timeout: number of seconds to add to default timeout
  * @cb: monitor event handles
  * @opaque: opaque data for @cb
  *
- * Opens the monitor for running qemu. It may happen that it
- * takes some time for qemu to create the monitor socket (e.g.
- * because kernel is zeroing configured hugepages), therefore we
- * wait up to default + timeout seconds for the monitor to show
- * up after which a failure is claimed.
+ * Opens the monitor for running qemu. We now always pass a pre-opened FD to
+ * qemu so the connection can happen right away.
  *
  * Returns monitor object, NULL on error.
  */
 qemuMonitor *
 qemuMonitorOpen(virDomainObj *vm,
                 virDomainChrSourceDef *config,
-                bool retry,
-                unsigned long long timeout,
                 GMainContext *context,
                 qemuMonitorCallbacks *cb,
                 void *opaque)
@@ -728,8 +688,6 @@ qemuMonitorOpen(virDomainObj *vm,
     VIR_AUTOCLOSE fd = -1;
     qemuMonitor *ret = NULL;

-    timeout += QEMU_DEFAULT_MONITOR_WAIT;
-
     if (config->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unable to handle monitor type: %s"),
@@ -738,8 +696,7 @@ qemuMonitorOpen(virDomainObj *vm,
     }

     virObjectUnlock(vm);
-    fd = qemuMonitorOpenUnix(config->data.nix.path,
-                             vm->pid, retry, timeout);
+    fd = qemuMonitorOpenUnix(config->data.nix.path);
     virObjectLock(vm);

     if (fd < 0)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index efc4721ea9..97ffedea0a 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -464,12 +464,10 @@ struct _qemuMonitorCallbacks {

 qemuMonitor *qemuMonitorOpen(virDomainObj *vm,
                                virDomainChrSourceDef *config,
-                               bool retry,
-                               unsigned long long timeout,
                                GMainContext *context,
                                qemuMonitorCallbacks *cb,
                                void *opaque)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

 void qemuMonitorWatchDispose(void);
 bool qemuMonitorWasDisposed(void);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0b2ebaf123..ae9fcd31b8 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1908,12 +1908,13 @@ qemuProcessInitMonitor(virQEMUDriver *driver,


 static int
-qemuConnectMonitor(virQEMUDriver *driver, virDomainObj *vm, int asyncJob,
-                   bool retry, qemuDomainLogContext *logCtxt)
+qemuConnectMonitor(virQEMUDriver *driver,
+                   virDomainObj *vm,
+                   int asyncJob,
+                   qemuDomainLogContext *logCtxt)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
     qemuMonitor *mon = NULL;
-    unsigned long long timeout = 0;

     if (qemuSecuritySetDaemonSocketLabel(driver->securityManager, vm->def) < 0) {
         VIR_ERROR(_("Failed to set security context for monitor for %s"),
@@ -1921,18 +1922,10 @@ qemuConnectMonitor(virQEMUDriver *driver, virDomainObj *vm, int asyncJob,
         return -1;
     }

-    /* When using hugepages, kernel zeroes them out before
-     * handing them over to qemu. This can be very time
-     * consuming. Therefore, add a second to timeout for each
-     * 1GiB of guest RAM. */
-    timeout = virDomainDefGetMemoryTotal(vm->def) / (1024 * 1024);
-
     ignore_value(virTimeMillisNow(&priv->monStart));

     mon = qemuMonitorOpen(vm,
                           priv->monConfig,
-                          retry,
-                          timeout,
                           virEventThreadGetContext(priv->eventThread),
                           &monitorCallbacks,
                           driver);
@@ -2342,12 +2335,10 @@ qemuProcessWaitForMonitor(virQEMUDriver *driver,
     int ret = -1;
     g_autoptr(GHashTable) info = NULL;
     qemuDomainObjPrivate *priv = vm->privateData;
-    bool retry = false;

-    VIR_DEBUG("Connect monitor to vm=%p name='%s' retry=%d",
-              vm, vm->def->name, retry);
+    VIR_DEBUG("Connect monitor to vm=%p name='%s", vm, vm->def->name);

-    if (qemuConnectMonitor(driver, vm, asyncJob, retry, logCtxt) < 0)
+    if (qemuConnectMonitor(driver, vm, asyncJob, logCtxt) < 0)
         goto cleanup;

     /* Try to get the pty path mappings again via the monitor. This is much more
@@ -8712,7 +8703,6 @@ qemuProcessReconnect(void *opaque)
     size_t i;
     unsigned int stopFlags = 0;
     bool jobStarted = false;
-    bool retry = false;
     bool tryMonReconn = false;

     virIdentitySetCurrent(data->identity);
@@ -8751,13 +8741,12 @@ qemuProcessReconnect(void *opaque)
     if (qemuDomainObjStartWorker(obj) < 0)
         goto error;

-    VIR_DEBUG("Reconnect monitor to def=%p name='%s' retry=%d",
-              obj, obj->def->name, retry);
+    VIR_DEBUG("Reconnect monitor to def=%p name='%s'", obj, obj->def->name);

     tryMonReconn = true;

     /* XXX check PID liveliness & EXE path */
-    if (qemuConnectMonitor(driver, obj, QEMU_ASYNC_JOB_NONE, retry, NULL) < 0)
+    if (qemuConnectMonitor(driver, obj, QEMU_ASYNC_JOB_NONE, NULL) < 0)
         goto error;

     priv->machineName = qemuDomainGetMachineName(obj);
@@ -9354,7 +9343,7 @@ qemuProcessQMPConnectMonitor(qemuProcessQMP *proc)

     proc->vm->pid = proc->pid;

-    if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig, true, 0,
+    if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig,
                                       virEventThreadGetContext(proc->eventThread),
                                       &callbacks, NULL)))
         return -1;
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index ce8e6e1645..d807d9d62c 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -1123,8 +1123,6 @@ qemuMonitorTestNew(virDomainXMLOption *xmlopt,
     test->qapischema = schema;
     if (!(test->mon = qemuMonitorOpen(test->vm,
                                       &src,
-                                      true,
-                                      0,
                                       virEventThreadGetContext(test->eventThread),
                                       &qemuMonitorTestCallbacks,
                                       driver)))
-- 
2.34.1




More information about the libvir-list mailing list