Skip to content

Commit e032f44

Browse files
Vineeth Pillaibryteise
authored andcommitted
ch_monitor: Add support for cloud-hypervisor --monitor-fd option.
cloud-hypervisor has a new option to pass in a filedescriptor through which we can listen for VM state change events. Add support for --monitor-fd option. This would be used in later patches to track VM's threads. Signed-off-by: Vineeth Pillai <[email protected]>
1 parent 3465a60 commit e032f44

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/ch/ch_monitor.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <config.h>
2222

2323
#include <stdio.h>
24+
#include <unistd.h>
25+
2426
#include <curl/curl.h>
2527

2628
#include "ch_conf.h"
@@ -595,14 +597,15 @@ virCHMonitorOpen(virDomainObjPtr vm, virCHDriverPtr driver)
595597
virCHMonitorPtr
596598
virCHMonitorNew(virDomainObjPtr vm, virCHDriverPtr driver)
597599
{
598-
virCHDomainObjPrivatePtr priv = vm->privateData;
599600
g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver);
601+
virCHDomainObjPrivatePtr priv = vm->privateData;
600602
virCHMonitorPtr ret = NULL;
601603
virCHMonitorPtr mon = NULL;
602604
virCommandPtr cmd = NULL;
603-
int i;
605+
int monitor_fds[2];
604606
int pings = 0;
605607
int rv;
608+
int i;
606609

607610
if (virCHMonitorInitialize() < 0)
608611
goto cleanup;
@@ -629,6 +632,17 @@ virCHMonitorNew(virDomainObjPtr vm, virCHDriverPtr driver)
629632
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
630633
}
631634

635+
/* Monitor fd to listen for VM state changes */
636+
if (pipe(monitor_fds) < 0) {
637+
virReportSystemError(errno, "%s",
638+
_("Cannot create monitor fd pipe"));
639+
goto cleanup;
640+
}
641+
mon->monitor_fd = monitor_fds[0];
642+
virCommandAddArg(cmd, "--monitor-fd");
643+
virCommandAddArgFormat(cmd, "%d", monitor_fds[1]);
644+
virCommandPassFD(cmd, monitor_fds[1], VIR_COMMAND_PASS_FD_CLOSE_PARENT);
645+
632646
/* TODO enable */
633647
virCommandSetPidFile(cmd, priv->pidfile);
634648
virCommandDaemonize(cmd);
@@ -726,6 +740,10 @@ void virCHMonitorClose(virCHMonitorPtr mon)
726740
VIR_FREE(mon->socketpath);
727741
}
728742

743+
if (mon->monitor_fd) {
744+
close(mon->monitor_fd);
745+
}
746+
729747
virObjectUnref(mon);
730748
if (mon->vm)
731749
virObjectUnref(mon->vm);

src/ch/ch_monitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ struct _virCHMonitor {
9595

9696
char *socketpath;
9797

98+
int monitor_fd;
99+
98100
pid_t pid;
99101

100102
virDomainObjPtr vm;

0 commit comments

Comments
 (0)