On 1/10/20 11:34 AM, Daniel P. Berrangé wrote:
The previous "QEMU shim" proof of concept was taking an
approach of only
caring about initial spawning of the QEMU process. It was then
registered with the libvirtd daemon who took over management of it. The
intent was that later libvirtd would be refactored so that the shim
retained control over the QEMU monitor and libvirt just forwarded APIs
to each shim as needed. This forwarding of APIs would require quite alot
of significant refactoring of libvirtd to achieve.
This impl thus takes a quite different approach, explicitly deciding to
keep the VMs completely separate from those seen & managed by libvirtd.
Instead it uses the new "qemu:///embed" URI scheme to embed the entire
QEMU driver in the shim, running with a custom root directory.
Once the driver is initialization, the shim starts a VM and then waits
to shutdown automatically when QEMU shuts down, or should kill QEMU if
it is terminated itself. This ought to use the AUTO_DESTROY feature but
that is not yet available in embedded mode, so we rely on installing a
few signal handlers to gracefully kill QEMU. This isn't reliable if
we crash of course, but you can restart with the same root dir.
Note this program does not expose any way to manage the QEMU process,
since there's no RPC interface enabled. It merely starts the VM and
cleans up when the guest shuts down at the end. This program is
installed to /usr/bin/virt-qemu-run enabling direct use by end users.
Most use cases will probably want to integrate the concept directly
into their respective application codebases. This standalone binary
serves as a nice demo though, and also provides a way to measure
performance of the startup process quite simply.
Reviewed-by: Michal Privoznik <mprivozn(a)redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
build-aux/syntax-check.mk | 2 +-
docs/Makefile.am | 5 +
docs/manpages/index.rst | 1 +
docs/manpages/virt-qemu-run.rst | 114 +++++++++++
libvirt.spec.in | 2 +
src/Makefile.am | 1 +
src/qemu/Makefile.inc.am | 13 ++
src/qemu/qemu_shim.c | 322 ++++++++++++++++++++++++++++++++
8 files changed, 459 insertions(+), 1 deletion(-)
create mode 100644 docs/manpages/virt-qemu-run.rst
create mode 100644 src/qemu/qemu_shim.c
--- /dev/null
+++ b/src/qemu/qemu_shim.c
+int main(int argc, char **argv)
+{
+ GThread *eventLoopThread = NULL;
+ virConnectPtr conn = NULL;
+ virConnectPtr sconn = NULL;
+ g_autofree char *xml = NULL;
+ g_autofree char *uri = NULL;
+ g_autofree char *suri = NULL;
+ char *root = NULL;
+ bool tmproot = false;
+ int ret = 1;
+ g_autoptr(GError) error = NULL;
+ g_auto(GStrv) secrets = NULL;
+ gboolean verbose = false;
+ gboolean debug = false;
+ GStrv tmpsecrets;
+ GOptionContext *ctx;
+ GOptionEntry entries[] = {
+ { "secret", 's', 0, G_OPTION_ARG_STRING_ARRAY, &secrets,
"Load secret file", "SECRET-XML-FILE,SECRET-VALUE-FILE" },
+ { "root", 'r', 0, G_OPTION_ARG_STRING, &root, "Root
directory", "DIR"},
+ { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Debug
output", NULL },
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Verbose output", NULL },
+ { NULL }
s/NULL/0/ to make clang happy. It's complaining, that the rest of struct
members are not initialzied.
Michal