Use a FIFO(named pipe) for --event-monitor option in CH. Introduce a
new
thread, `virCHEventHandlerLoop`, to continuously monitor and handle
events from cloud-hypervisor.
Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi(a)linux.microsoft.com>
Co-authored-by: Vineeth Pillai <viremana(a)linux.microsoft.com>
---
po/POTFILES | 1 +
src/ch/ch_events.c | 93 +++++++++++++++++++++++++++++++++++++++++++++
src/ch/ch_events.h | 26 +++++++++++++
src/ch/ch_monitor.c | 32 ++++++++++++++--
src/ch/ch_monitor.h | 3 ++
src/ch/meson.build | 2 +
6 files changed, 154 insertions(+), 3 deletions(-)
create mode 100644 src/ch/ch_events.c
create mode 100644 src/ch/ch_events.h
diff --git a/po/POTFILES b/po/POTFILES
index 1ed4086d2c..d53307cec4 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -21,6 +21,7 @@ src/bhyve/bhyve_process.c
src/ch/ch_conf.c
src/ch/ch_domain.c
src/ch/ch_driver.c
+src/ch/ch_events.c
src/ch/ch_interface.c
src/ch/ch_monitor.c
src/ch/ch_process.c
diff --git a/src/ch/ch_events.c b/src/ch/ch_events.c
new file mode 100644
index 0000000000..bb27f340e2
--- /dev/null
+++ b/src/ch/ch_events.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright Microsoft Corp. 2024
+ *
+ * ch_events.c: Handle Cloud-Hypervisor events
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <fcntl.h>
+
+#include "ch_events.h"
+#include "virfile.h"
+#include "virlog.h"
+
+VIR_LOG_INIT("ch.ch_events");
+
+static void virCHEventHandlerLoop(void *data)
+{
+ virCHMonitor *mon = data;
+ virDomainObj *vm = NULL;
+ int event_monitor_fd;
+
+ /* Obtain a vm reference */
+ vm = virObjectRef(mon->vm);
+
+ VIR_DEBUG("%s: Event handler loop thread starting", vm->def->name);
+
+ while ((event_monitor_fd = open(mon->eventmonitorpath, O_RDONLY)) < 0) {
+ if (errno == EINTR) {
+ /* 100 milli seconds */
+ g_usleep(100000);
+ continue;
+ }
+ /* Any other error should be a BUG(kernel/libc/libvirtd)
+ * (ENOMEM can happen on exceeding per-user limits)
+ */
+ VIR_ERROR(_("%1$s: Failed to open the event monitor FIFO(%2$s) read
end!"),
+ vm->def->name, mon->eventmonitorpath);
+ abort();
This sounds too harsh! abort() aborts whole process (libvirtd). If
opening monitor fails then we should just kill the VM and exit from the
thread.
You will find some calls to abort() throughout our code, but those are
cases where memory allocation failed at which point that's the only
reasonable thing to do. But abort()-ing on failed open() is too much.
Michal