]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: report error from failing to add timer/FD watches
authorDaniel P. Berrangé <berrange@redhat.com>
Mon, 22 Jul 2024 14:56:03 +0000 (15:56 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 6 Nov 2025 12:04:48 +0000 (12:04 +0000)
The virEventAddHandle/Timeout APIs are unusual in that they do not
report errors on failure, because they call through to function
callbacks which might be provided externally to libvirt and thus
won't be using libvirt's error reporting APIs.

This is a rather unfortunate design characteristic as we can see
most callers forgot about this special behaviour and so we are
lacking error reporting in many cases.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/libxl/libxl_driver.c
src/logging/log_cleaner.c
src/logging/log_handler.c
src/lxc/lxc_controller.c
src/node_device/node_device_udev.c
src/remote/remote_ssh_helper.c
src/rpc/virkeepalive.c
src/rpc/virnetclientstream.c
src/rpc/virnetserverclient.c
src/rpc/virnetserverservice.c

index 308c0372aaf4b96f36c4b22b9f51522ad7f8b423..107477250ab842db09bd85060128e8ad96bb7408 100644 (file)
@@ -170,6 +170,7 @@ libxlFDRegisterEventHook(void *priv,
     info->id = virEventAddHandle(fd, vir_events, libxlFDEventCallback,
                                  info, libxlOSEventHookInfoFree);
     if (info->id < 0) {
+        VIR_WARN("Failed to add event watch for FD %d", fd);
         VIR_FREE(info);
         return -1;
     }
@@ -255,6 +256,7 @@ libxlTimeoutRegisterEventHook(void *priv,
     info->id = virEventAddTimeout(timeout, libxlTimerCallback,
                                   info, libxlOSEventHookInfoFree);
     if (info->id < 0) {
+        VIR_WARN("Failed to add event timer callback");
         VIR_FREE(info);
         return -1;
     }
index d247fdf82971062609d409290df2ccc83e09ea78..7110dfcff69271df2c2a5b9ae20a701376447fd8 100644 (file)
@@ -251,6 +251,10 @@ virLogCleanerInit(virLogHandler *handler)
     handler->cleanup_log_timer = virEventAddTimeout(CLEANER_LOG_TIMEOUT_MS,
                                                     virLogCleanerTimer,
                                                     handler, NULL);
+    if (handler->cleanup_log_timer < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to add log cleanup timer"));
+    }
     return handler->cleanup_log_timer;
 }
 
index 71517bbbe5ff55ed353dca0f0e823059da710c07..6ad3e33ee845c0c43d286e133f88b4cb81e9fd38 100644 (file)
@@ -302,6 +302,8 @@ virLogHandlerNewPostExecRestart(virJSONValue *object,
                                              virLogHandlerDomainLogFileEvent,
                                              handler,
                                              NULL)) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Unable to add watch on log FD %1$d"), file->pipefd);
             VIR_DELETE_ELEMENT(handler->files, handler->nfiles - 1, handler->nfiles);
             goto error;
         }
@@ -386,6 +388,8 @@ virLogHandlerDomainOpenLogFile(virLogHandler *handler,
                                          virLogHandlerDomainLogFileEvent,
                                          handler,
                                          NULL)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to add watch on log FD %1$d"), file->pipefd);
         VIR_DELETE_ELEMENT(handler->files, handler->nfiles - 1, handler->nfiles);
         goto error;
     }
index 3f4c8efdcf68b333e49016fd99a08d36ff295031..f7776534e8a54eb3dde55df50fbc224a33ce4137 100644 (file)
@@ -206,8 +206,11 @@ static virLXCController *virLXCControllerNew(const char *name)
 
     if ((ctrl->timerShutdown = virEventAddTimeout(-1,
                                                   virLXCControllerQuitTimer, ctrl,
-                                                  NULL)) < 0)
+                                                  NULL)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to add shutdown timer"));
         goto error;
+    }
 
  cleanup:
     virLXCControllerDriverFree(driver);
index 30c2ddf56817a0ad8c9e75145caa1aeebc873ca5..27e62febe8e3a0dbf82bd1227813865fb9cc3540 100644 (file)
@@ -2318,6 +2318,9 @@ scheduleMdevctlUpdate(udevEventData *data)
         virEventRemoveTimeout(data->mdevctlTimeout);
     data->mdevctlTimeout = virEventAddTimeout(100, submitMdevctlUpdate,
                                               data, NULL);
+    if (data->mdevctlTimeout < 0) {
+        VIR_WARN("Unable to add mdev update timer");
+    }
 }
 
 
@@ -2609,8 +2612,12 @@ nodeStateInitialize(bool privileged,
     priv->watch = virEventAddHandle(udev_monitor_get_fd(priv->udev_monitor),
                                     VIR_EVENT_HANDLE_READABLE,
                                     udevEventHandleCallback, virObjectRef(priv), virObjectUnref);
-    if (priv->watch == -1)
+    if (priv->watch == -1) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to add watch on udev FD %1$d"),
+                       udev_monitor_get_fd(priv->udev_monitor));
         goto unlock;
+    }
 
     if (mdevctlEnableMonitor(priv) < 0)
         goto unlock;
index 2d332a39b65a3f790248e757eaf50acd62aa3aaa..48896fd5596cadc15ea7faf6a3bddd493f3b1cdf 100644 (file)
@@ -316,15 +316,21 @@ virRemoteSSHHelperRun(virNetSocket *sock)
                                               VIR_EVENT_HANDLE_READABLE,
                                               virRemoteSSHHelperEventOnStdin,
                                               &proxy,
-                                              NULL)) < 0)
+                                              NULL)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to add watch on stdin"));
         goto cleanup;
+    }
 
     if ((proxy.stdoutWatch = virEventAddHandle(STDOUT_FILENO,
                                                0,
                                                virRemoteSSHHelperEventOnStdout,
                                                &proxy,
-                                               NULL)) < 0)
+                                               NULL)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to add watch on stdout"));
         goto cleanup;
+    }
 
     if (virNetSocketAddIOCallback(proxy.sock,
                                   VIR_EVENT_HANDLE_READABLE,
index d96bd347adde1e3499d6edc03152b61d4e137240..690bc08b2e11cb97649e827f879e7b282e286b5b 100644 (file)
@@ -276,8 +276,11 @@ virKeepAliveStart(virKeepAlive *ka,
     ka->intervalStart = now - (ka->interval - timeout);
     ka->timer = virEventAddTimeout(timeout * 1000, virKeepAliveTimer,
                                    ka, virObjectUnref);
-    if (ka->timer < 0)
+    if (ka->timer < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to add keepalive timer"));
         goto cleanup;
+    }
 
     /* the timer now has another reference to this object */
     virObjectRef(ka);
index 98034d737d9ac5a9e29bbe50b815b9c47270f286..380b785869992874445d0f7e040995818554ee79 100644 (file)
@@ -725,6 +725,8 @@ int virNetClientStreamEventAddCallback(virNetClientStream *st,
                             virNetClientStreamEventTimer,
                             st,
                             virObjectUnref)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to add timer to event loop"));
         virObjectUnref(st);
         goto cleanup;
     }
index 355aab4b04de9646b3dc094eba9efba9c3ee0413..e2967e5e1f551ae7db6d49db6e6a720d616cd8ae 100644 (file)
@@ -396,8 +396,11 @@ virNetServerClientNewInternal(unsigned long long id,
 
     client->sockTimer = virEventAddTimeout(-1, virNetServerClientSockTimerFunc,
                                            client, NULL);
-    if (client->sockTimer < 0)
+    if (client->sockTimer < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to add socket timer"));
         goto error;
+    }
 
     /* Prepare one for packet receive */
     if (!(client->rx = virNetMessageNew(true)))
index 682b2091c13173003fc17f68f1973be257bcfe41..babdedee35c1fcfa93b74c21d3110ec3358b0f83 100644 (file)
@@ -154,6 +154,8 @@ virNetServerServiceNewSocket(virNetSocket **socks,
     svc->timer = virEventAddTimeout(-1, virNetServerServiceTimerFunc,
                                     svc, virObjectUnref);
     if (svc->timer < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to add service timer"));
         virObjectUnref(svc);
         goto error;
     }