diff --git a/Add-and-initialize-the-stratovirt-driver.patch b/Add-and-initialize-the-stratovirt-driver.patch new file mode 100644 index 0000000000000000000000000000000000000000..d18ef24623648eacefc3cd43fa2617f23c603e1f --- /dev/null +++ b/Add-and-initialize-the-stratovirt-driver.patch @@ -0,0 +1,1612 @@ +From 9d8a8ba270a0aba180eb3ea812cd29bd045d3629 Mon Sep 17 00:00:00 2001 +From: mayunlong +Date: Thu, 11 Aug 2022 16:57:12 +0800 +Subject: [PATCH 1/3] Add and initialize the stratovirt driver. + +--- + configure.ac | 4 + + include/libvirt/virterror.h | 1 + + libvirt.spec.in | 29 ++ + m4/virt-driver-stratovirt.m4 | 17 + + po/POTFILES.in | 4 + + src/Makefile.am | 1 + + src/remote/remote_daemon.c | 4 + + src/remote/remote_daemon_dispatch.c | 3 +- + src/stratovirt/Makefile.inc.am | 52 +++ + src/stratovirt/stratovirt_conf.c | 284 ++++++++++++++ + src/stratovirt/stratovirt_conf.h | 69 ++++ + src/stratovirt/stratovirt_domain.c | 143 +++++++ + src/stratovirt/stratovirt_domain.h | 65 +++ + src/stratovirt/stratovirt_driver.c | 587 ++++++++++++++++++++++++++++ + src/stratovirt/stratovirt_driver.h | 25 ++ + src/stratovirt/stratovirt_process.c | 33 ++ + src/stratovirt/stratovirt_process.h | 32 ++ + src/util/virerror.c | 1 + + tools/virsh.c | 3 + + 19 files changed, 1356 insertions(+), 1 deletion(-) + create mode 100644 m4/virt-driver-stratovirt.m4 + create mode 100644 src/stratovirt/Makefile.inc.am + create mode 100644 src/stratovirt/stratovirt_conf.c + create mode 100644 src/stratovirt/stratovirt_conf.h + create mode 100644 src/stratovirt/stratovirt_domain.c + create mode 100644 src/stratovirt/stratovirt_domain.h + create mode 100644 src/stratovirt/stratovirt_driver.c + create mode 100644 src/stratovirt/stratovirt_driver.h + create mode 100644 src/stratovirt/stratovirt_process.c + create mode 100644 src/stratovirt/stratovirt_process.h + +diff --git a/configure.ac b/configure.ac +index cb62e5aac8..4219018c90 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -249,6 +249,7 @@ if test "$with_libvirtd" = "no" ; then + with_lxc=no + with_libxl=no + with_vbox=no ++ with_stratovirt=no + fi + + # Check for compiler and library settings. +@@ -467,6 +468,7 @@ LIBVIRT_DRIVER_ARG_REMOTE + LIBVIRT_DRIVER_ARG_LIBVIRTD + LIBVIRT_DRIVER_ARG_NETWORK + LIBVIRT_DRIVER_ARG_INTERFACE ++LIBVIRT_DRIVER_ARG_STRATOVIRT + + LIBVIRT_DRIVER_CHECK_QEMU + LIBVIRT_DRIVER_CHECK_OPENVZ +@@ -483,6 +485,7 @@ LIBVIRT_DRIVER_CHECK_REMOTE + LIBVIRT_DRIVER_CHECK_LIBVIRTD + LIBVIRT_DRIVER_CHECK_NETWORK + LIBVIRT_DRIVER_CHECK_INTERFACE ++LIBVIRT_DRIVER_CHECK_STRATOVIRT + + + dnl +@@ -956,6 +959,7 @@ LIBVIRT_DRIVER_RESULT_REMOTE + LIBVIRT_DRIVER_RESULT_NETWORK + LIBVIRT_DRIVER_RESULT_LIBVIRTD + LIBVIRT_DRIVER_RESULT_INTERFACE ++LIBVIRT_DRIVER_RESULT_STRATOVIRT + AC_MSG_NOTICE([]) + AC_MSG_NOTICE([Storage Drivers]) + AC_MSG_NOTICE([]) +diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h +index 0f1c32283d..49a7b0c9ef 100644 +--- a/include/libvirt/virterror.h ++++ b/include/libvirt/virterror.h +@@ -136,6 +136,7 @@ typedef enum { + + VIR_FROM_TPM = 70, /* Error from TPM */ + VIR_FROM_BPF = 71, /* Error from BPF code */ ++ VIR_FROM_STRATOVIRT = 72, /* Error from StratoVirt */ + + # ifdef VIR_ENUM_SENTINELS + VIR_ERR_DOMAIN_LAST +diff --git a/libvirt.spec.in b/libvirt.spec.in +index efeeac31b9..cd0df7e08a 100644 +--- a/libvirt.spec.in ++++ b/libvirt.spec.in +@@ -22,6 +22,7 @@ + %define with_lxc 0%{!?_without_lxc:1} + %define with_libxl 0%{!?_without_libxl:1} + %define with_vbox 0%{!?_without_vbox:1} ++%define with_stratovirt 0%{!?_without_stratovirt:1} + + %define with_qemu_tcg %{with_qemu} + +@@ -239,6 +240,9 @@ Requires: libvirt-daemon-driver-lxc = %{version}-%{release} + %if %{with_qemu} + Requires: libvirt-daemon-driver-qemu = %{version}-%{release} + %endif ++%if %{with_stratovirt} ++Requires: libvirt-daemon-driver-stratovirt = %{version}-%{release} ++%endif + # We had UML driver, but we've removed it. + Obsoletes: libvirt-daemon-driver-uml <= 5.0.0 + Obsoletes: libvirt-daemon-uml <= 5.0.0 +@@ -747,6 +751,19 @@ an implementation of the hypervisor driver APIs using + QEMU + %endif + ++%if %{with_stratovirt} ++%package daemon-driver-stratovirt ++Summary: StratoVirt driver plugin for the libvirtd daemon ++Requires: libvirt-daemon = %{version}-%{release} ++Requires: libvirt-libs = %{version}-%{release} ++Requires: stratovirt ++Requires: systemd-container ++ ++%description daemon-driver-stratovirt ++The stratovirt driver plugin for the libvirtd daemon, providing ++an implementation of the hypervisor driver APIs using ++StratoVirt ++%endif + + %if %{with_lxc} + %package daemon-driver-lxc +@@ -1006,6 +1023,12 @@ exit 1 + %define arg_qemu --without-qemu + %endif + ++%if %{with_stratovirt} ++ %define arg_stratovirt --with-stratovirt ++%else ++ %define arg_stratovirt --without-stratovirt ++%endif ++ + %if %{with_openvz} + %define arg_openvz --with-openvz + %else +@@ -1151,6 +1174,7 @@ cd %{_vpath_builddir} + %{?arg_lxc} \ + %{?arg_vbox} \ + %{?arg_libxl} \ ++ %{?arg_stratovirt} \ + --with-sasl \ + --with-polkit \ + --with-libvirtd \ +@@ -1751,6 +1775,11 @@ exit 0 + %{_mandir}/man1/virt-qemu-run.1* + %endif + ++%if %{with_stratovirt} ++%files daemon-driver-stratovirt ++%{_libdir}/%{name}/connection-driver/libvirt_driver_stratovirt.so ++%endif ++ + %if %{with_lxc} + %files daemon-driver-lxc + %config(noreplace) %{_sysconfdir}/libvirt/virtlxcd.conf +diff --git a/m4/virt-driver-stratovirt.m4 b/m4/virt-driver-stratovirt.m4 +new file mode 100644 +index 0000000000..5ed83dd3d5 +--- /dev/null ++++ b/m4/virt-driver-stratovirt.m4 +@@ -0,0 +1,17 @@ ++AC_DEFUN([LIBVIRT_DRIVER_ARG_STRATOVIRT], [ ++ LIBVIRT_ARG_WITH_FEATURE([STRATOVIRT], [QEMU/KVM], [yes]) ++]) ++ ++AC_DEFUN([LIBVIRT_DRIVER_CHECK_STRATOVIRT], [ ++ if test "$with_stratovirt" = "yes"; then ++ AC_DEFINE_UNQUOTED([WITH_STRATOVIRT], 1, [whether STRATOVIRT driver is enabled]) ++ fi ++ AM_CONDITIONAL([WITH_STRATOVIRT], [test "$with_stratovirt" = "yes"]) ++ ++ AC_DEFINE_UNQUOTED([STRATOVIRT_USER], ["root"], [STRATOVIRT user account]) ++ AC_DEFINE_UNQUOTED([STRATOVIRT_GROUP], ["root"], [STRATOVIRT group account]) ++]) ++ ++AC_DEFUN([LIBVIRT_DRIVER_RESULT_STRATOVIRT], [ ++ LIBVIRT_RESULT([STRATOVIRT], [$with_stratovirt]) ++]) +diff --git a/po/POTFILES.in b/po/POTFILES.in +index 197ff2f3d3..8217d82db9 100644 +--- a/po/POTFILES.in ++++ b/po/POTFILES.in +@@ -173,6 +173,10 @@ + @SRCDIR@/src/qemu/qemu_vhost_user.c + @SRCDIR@/src/qemu/qemu_vhost_user_gpu.c + @SRCDIR@/src/qemu/qemu_virtiofs.c ++@SRCDIR@/src/stratovirt/stratovirt_driver.c ++@SRCDIR@/src/stratovirt/stratovirt_conf.c ++@SRCDIR@/src/stratovirt/stratovirt_domain.c ++@SRCDIR@/src/stratovirt/stratovirt_process.c + @SRCDIR@/src/remote/remote_daemon.c + @SRCDIR@/src/remote/remote_daemon_config.c + @SRCDIR@/src/remote/remote_daemon_dispatch.c +diff --git a/src/Makefile.am b/src/Makefile.am +index 12dd6b80e1..97f5074077 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -127,6 +127,7 @@ include node_device/Makefile.inc.am + include secret/Makefile.inc.am + include storage/Makefile.inc.am + include remote/Makefile.inc.am ++include stratovirt/Makefile.inc.am + + + SECDRIVER_CFLAGS = +diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c +index a1552800e9..88c423f540 100644 +--- a/src/remote/remote_daemon.c ++++ b/src/remote/remote_daemon.c +@@ -169,6 +169,10 @@ static int daemonInitialize(void) + if (virDriverLoadModule("qemu", "qemuRegister", false) < 0) + return -1; + # endif ++# ifdef WITH_STRATOVIRT ++ if (virDriverLoadModule("stratovirt", "stratovirtRegister", false) < 0) ++ return -1; ++# endif + # ifdef WITH_LXC + if (virDriverLoadModule("lxc", "lxcRegister", false) < 0) + return -1; +diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c +index d2652e3231..258840d584 100644 +--- a/src/remote/remote_daemon_dispatch.c ++++ b/src/remote/remote_daemon_dispatch.c +@@ -2116,7 +2116,8 @@ remoteDispatchConnectOpen(virNetServerPtr server G_GNUC_UNUSED, + STREQ(type, "VBOX") || + STREQ(type, "bhyve") || + STREQ(type, "vz") || +- STREQ(type, "Parallels")) { ++ STREQ(type, "Parallels") || ++ STREQ(type, "StratoVirt")) { + VIR_DEBUG("Hypervisor driver found, setting URIs for secondary drivers"); + if (getuid() == 0) { + priv->interfaceURI = "interface:///system"; +diff --git a/src/stratovirt/Makefile.inc.am b/src/stratovirt/Makefile.inc.am +new file mode 100644 +index 0000000000..4d3fb259a4 +--- /dev/null ++++ b/src/stratovirt/Makefile.inc.am +@@ -0,0 +1,52 @@ ++# vim: filetype=automake ++ ++STRATOVIRT_DRIVER_SOURCES = \ ++ stratovirt/stratovirt_driver.c \ ++ stratovirt/stratovirt_driver.h \ ++ stratovirt/stratovirt_conf.c \ ++ stratovirt/stratovirt_conf.h \ ++ stratovirt/stratovirt_domain.c \ ++ stratovirt/stratovirt_domain.h \ ++ stratovirt/stratovirt_process.h \ ++ stratovirt/stratovirt_process.c \ ++ $(NULL) ++ ++DRIVER_SOURCE_FILES += $(addprefix $(srcdir)/,$(STRATOVIRT_DRIVER_SOURCES)) ++STATEFUL_SOURCE_FILES = $(addprefix $(srcdir)/,$(STRATOVIRT_DRIVER_SOURCES)) ++EXTRA_DIST += $(STRATOVIRT_DRIVER_SOURCES) ++ ++if WITH_STRATOVIRT ++noinst_LTLIBRARIES += libvirt_driver_stratovirt_impl.la ++libvirt_driver_stratovirt_la_SOURCES = ++libvirt_driver_stratovirt_la_LIBADD = \ ++ libvirt_driver_stratovirt_impl.la \ ++ libvirt.la \ ++ libvirt_driver_qemu.la\ ++ $(GLIB_LIBS) \ ++ $(NULL) ++ ++mod_LTLIBRARIES += libvirt_driver_stratovirt.la ++libvirt_driver_stratovirt_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF) ++ ++libvirt_driver_stratovirt_impl_la_CFLAGS = \ ++ $(SELINUX_CFLAGS) \ ++ $(XDR_CFLAGS) \ ++ -I$(srcdir)/conf \ ++ -I$(srcdir)/stratovirt \ ++ -I$(srcdir)/access \ ++ -I$(builddir)/access \ ++ -I$(srcdir)/hypervisor \ ++ -I$(srcdir)/secret \ ++ -I$(srcdir)/qemu \ ++ $(AM_CFLAGS) \ ++ $(NULL) ++ ++libvirt_driver_stratovirt_impl_la_SOURCES = $(STRATOVIRT_DRIVER_SOURCES) ++libvirt_driver_stratovirt_impl_la_LDFLAGS = $(AM_LDFLAGS) ++libvirt_driver_stratovirt_impl_la_LIBADD = \ ++ $(DLOPEN_LIBS) \ ++ $(SELINUX_LIBS) \ ++ $(LIBXML_LIBS) \ ++ $(NULL) ++ ++endif WITH_STRATOVIRT +diff --git a/src/stratovirt/stratovirt_conf.c b/src/stratovirt/stratovirt_conf.c +new file mode 100644 +index 0000000000..ef48ec2474 +--- /dev/null ++++ b/src/stratovirt/stratovirt_conf.c +@@ -0,0 +1,284 @@ ++/* ++ * huawei_stratovirt_conf.c: huawei stratovirt conf functions ++ * Manage configuration parameters. ++ * ++ * Copyright (C) 2022-2022 HUAWEI, Inc. ++ * ++ * 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 ++ * . ++ * ++ */ ++ ++#include ++ ++#include "stratovirt_conf.h" ++#include "stratovirt_process.h" ++ ++#include "configmake.h" ++#include "virlog.h" ++#include "virutil.h" ++#include "viralloc.h" ++ ++VIR_LOG_INIT("stratovirt.stratovirt_conf"); ++ ++#define STRATOVIRT_REMOTE_PORT_MIN 5900 ++#define STRATOVIRT_REMOTE_PORT_MAX 65535 ++ ++#define STRATOVIRT_WEBSOCKET_PORT_MIN 5700 ++#define STRATOVIRT_WEBSOCKET_PORT_MAX 65535 ++ ++static virClassPtr virStratoVirtDriverConfigClass; ++static void virStratoVirtDriverConfigDispose(void *obj); ++ ++static int virStratoVirtConfigOnceInit(void) ++{ ++ if (!VIR_CLASS_NEW(virStratoVirtDriverConfig, virClassForObject())) ++ return -1; ++ ++ return 0; ++} ++ ++VIR_ONCE_GLOBAL_INIT(virStratoVirtConfig); ++ ++static virCapsPtr virStratoVirtCapsInit(void) ++{ ++ virCapsPtr caps; ++ virCapsGuest *guest; ++ ++ if ((caps = virCapabilitiesNew(virArchFromHost(), ++ false, false)) == NULL) ++ goto error; ++ ++ if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) ++ goto error; ++ ++ if (virCapabilitiesInitCaches(caps) < 0) ++ goto error; ++ ++ guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, ++ caps->host.arch, NULL, NULL, 0, NULL); ++ ++ virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, NULL, NULL, 0, NULL); ++ ++ return caps; ++ ++ error: ++ virObjectUnref(caps); ++ return NULL; ++} ++ ++virCapsPtr ++virStratoVirtDriverGetCapabilities(virStratoVirtDriverPtr driver, bool refresh) ++{ ++ virCapsPtr ret = NULL; ++ if (refresh) { ++ virCapsPtr caps = NULL; ++ if ((caps = virStratoVirtCapsInit()) == NULL) ++ return NULL; ++ ++ stratovirtDriverLock(driver); ++ virObjectUnref(driver->caps); ++ driver->caps = caps; ++ } else { ++ stratovirtDriverLock(driver); ++ ++ if (driver->caps == NULL || driver->caps->nguests == 0) { ++ stratovirtDriverUnlock(driver); ++ return virStratoVirtDriverGetCapabilities(driver, true); ++ } ++ } ++ ++ ret = virObjectRef(driver->caps); ++ stratovirtDriverUnlock(driver); ++ return ret; ++} ++ ++virStratoVirtDriverConfigPtr virStratoVirtDriverConfigNew(bool privileged) ++{ ++ virStratoVirtDriverConfigPtr cfg = NULL; ++ ++ if (virStratoVirtConfigInitialize() < 0) ++ return NULL; ++ ++ if (!(cfg = virObjectNew(virStratoVirtDriverConfigClass))) ++ return NULL; ++ ++ cfg->uri = g_strdup("stratovirt:///system"); ++ ++ if (privileged) { ++ if (virGetUserID(STRATOVIRT_USER, &cfg->user) < 0) ++ return NULL; ++ if (virGetGroupID(STRATOVIRT_GROUP, &cfg->group) < 0) ++ return NULL; ++ } else { ++ cfg->user = (uid_t)-1; ++ cfg->group = (gid_t)-1; ++ } ++ cfg->dynamicOwnership = privileged; ++ cfg->rememberOwner = privileged; ++ ++ cfg->cgroupControllers = -1; ++ ++ if (privileged) { ++ cfg->logDir = g_strdup_printf("%s/log/libvirt/stratovirt", LOCALSTATEDIR); ++ ++ cfg->configBaseDir = g_strdup(SYSCONFDIR "/libvirt"); ++ ++ cfg->stateDir = g_strdup_printf("%s/libvirt/stratovirt", RUNSTATEDIR); ++ ++ cfg->cacheDir = g_strdup_printf("%s/cache/libvirt/stratovirt", LOCALSTATEDIR); ++ ++ cfg->libDir = g_strdup_printf("%s/lib/libvirt/stratovirt", LOCALSTATEDIR); ++ ++ cfg->saveDir = g_strdup_printf("%s/save", cfg->libDir); ++ ++ cfg->snapshotDir = g_strdup_printf("%s/snapshot", cfg->libDir); ++ ++ cfg->checkpointDir = g_strdup_printf("%s/checkpoint", cfg->libDir); ++ ++ cfg->autoDumpPath = g_strdup_printf("%s/dump", cfg->libDir); ++ ++ cfg->channelTargetDir = g_strdup_printf("%s/channel/target", cfg->libDir); ++ ++ cfg->memoryBackingDir = g_strdup_printf("%s/ram", cfg->libDir); ++ ++ } else { ++ g_autofree char *rundir = NULL; ++ g_autofree char *cachedir = NULL; ++ ++ cachedir = virGetUserCacheDirectory(); ++ ++ cfg->logDir = g_strdup_printf("%s/stratovirt/log", cachedir); ++ cfg->cacheDir = g_strdup_printf("%s/stratovirt/cache", cachedir); ++ ++ rundir = virGetUserRuntimeDirectory(); ++ cfg->stateDir = g_strdup_printf("%s/stratovirt/run", rundir); ++ ++ cfg->configBaseDir = virGetUserConfigDirectory(); ++ ++ cfg->libDir = g_strdup_printf("%s/stratovirt/lib", cfg->configBaseDir); ++ cfg->saveDir = g_strdup_printf("%s/stratovirt/save", cfg->configBaseDir); ++ cfg->snapshotDir = g_strdup_printf("%s/stratovirt/snapshot", cfg->configBaseDir); ++ cfg->checkpointDir = g_strdup_printf("%s/stratovirt/checkpoint", ++ cfg->configBaseDir); ++ cfg->autoDumpPath = g_strdup_printf("%s/stratovirt/dump", cfg->configBaseDir); ++ cfg->channelTargetDir = g_strdup_printf("%s/stratovirt/channel/target", ++ cfg->configBaseDir); ++ cfg->memoryBackingDir = g_strdup_printf("%s/stratovirt/ram", cfg->configBaseDir); ++ } ++ ++ cfg->configDir = g_strdup_printf("%s/stratovirt", cfg->configBaseDir); ++ ++ cfg->remotePortMin = STRATOVIRT_REMOTE_PORT_MIN; ++ cfg->remotePortMax = STRATOVIRT_REMOTE_PORT_MAX; ++ ++ cfg->webSocketPortMin = STRATOVIRT_WEBSOCKET_PORT_MIN; ++ cfg->webSocketPortMax = STRATOVIRT_WEBSOCKET_PORT_MAX; ++ ++ if (privileged && ++ virFileFindHugeTLBFS(&cfg->hugetlbfs, &cfg->nhugetlbfs) < 0) { ++ if (virGetLastErrorCode() != VIR_ERR_NO_SUPPORT) ++ return NULL; ++ } ++ ++ cfg->securityDefaultConfined = true; ++ cfg->securityRequireConfined = false; ++ ++ cfg->keepAliveInterval = 5; ++ cfg->keepAliveCount = 5; ++ cfg->seccompSandbox = -1; ++ ++ cfg->logTimestamp = true; ++ cfg->glusterDebugLevel = 4; ++ cfg->stdioLogD = true; ++ ++ if (!(cfg->namespaces = virBitmapNew(1))) ++ return NULL; ++ ++ if (privileged && ++ stratovirtDom.stratovirtDomainNamespaceAvailable(0) && ++ virBitmapSetBit(cfg->namespaces, 0) < 0) ++ return NULL; ++ ++ return g_steal_pointer(&cfg); ++} ++ ++static void virStratoVirtDriverConfigDispose(void *obj) ++{ ++ virStratoVirtDriverConfigPtr cfg = obj; ++ ++ virBitmapFree(cfg->namespaces); ++ VIR_FREE(cfg->uri); ++ VIR_FREE(cfg->configBaseDir); ++ VIR_FREE(cfg->configDir); ++ VIR_FREE(cfg->logDir); ++ VIR_FREE(cfg->stateDir); ++ VIR_FREE(cfg->libDir); ++ VIR_FREE(cfg->cacheDir); ++ VIR_FREE(cfg->saveDir); ++ VIR_FREE(cfg->snapshotDir); ++ VIR_FREE(cfg->checkpointDir); ++ VIR_FREE(cfg->channelTargetDir); ++ ++ while (cfg->nhugetlbfs) { ++ cfg->nhugetlbfs--; ++ VIR_FREE(cfg->hugetlbfs[cfg->nhugetlbfs].mnt_dir); ++ } ++ VIR_FREE(cfg->hugetlbfs); ++ VIR_FREE(cfg->autoDumpPath); ++ VIR_FREE(cfg->memoryBackingDir); ++} ++ ++virStratoVirtDriverConfigPtr virStratoVirtDriverGetConfig(virStratoVirtDriverPtr driver) ++{ ++ virStratoVirtDriverConfigPtr conf; ++ stratovirtDriverLock(driver); ++ conf = virObjectRef(driver->config); ++ stratovirtDriverUnlock(driver); ++ return conf; ++} ++ ++static virDomainXMLPrivateDataCallbacks *virStratoVirtDriverPrivateDataCallbacks(void) { ++ return &virQEMUDriverPrivateDataCallbacks; ++} ++ ++virDomainXMLOptionPtr stratovirtDomainXMLConfInit(virStratoVirtDriverPtr driver) ++{ ++ virStratoVirtDriverDomainDefParserConfig.priv = driver; ++ return virDomainXMLOptionNew(&virStratoVirtDriverDomainDefParserConfig, ++ virStratoVirtDriverPrivateDataCallbacks(), ++ NULL, NULL, NULL); ++} ++ ++char * ++stratovirtGetBaseHugepagePath(virHugeTLBFSPtr hugepage) ++{ ++ char *ret; ++ ++ ret = g_strdup_printf("%s/libvirt/stratovirt", hugepage->mnt_dir); ++ ++ return ret; ++} ++ ++void ++stratovirtGetMemoryBackingBasePath(virStratoVirtDriverConfigPtr cfg, ++ char **path) ++{ ++ *path = g_strdup_printf("%s/libvirt/stratovirt", cfg->memoryBackingDir); ++} ++ ++virStratoVirtConf stratovirtconf = { ++ .stratovirtSharedDeviceEntryFree = qemuSharedDeviceEntryFree, ++ .virStratoVirtCapsCacheNew = virQEMUCapsCacheNew, ++}; +diff --git a/src/stratovirt/stratovirt_conf.h b/src/stratovirt/stratovirt_conf.h +new file mode 100644 +index 0000000000..e82b81b55e +--- /dev/null ++++ b/src/stratovirt/stratovirt_conf.h +@@ -0,0 +1,69 @@ ++/* ++ * huawei_stratovirt_conf.h: huawei stratovirt conf functions ++ * Manage configuration parameters. ++ * ++ * Copyright (C) 2022-2022 HUAWEI, Inc. ++ * ++ * 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 ++ * . ++ * ++ */ ++ ++#pragma once ++ ++#include "qemu_migration.h" ++ ++#define STRATOVIRT_DRIVER_NAME "StratoVirt" ++#define STRATOVIRT_CMD "stratovirt" ++ ++#define stratovirtSecurityGetNested virSecurityManagerGetNested ++#define stratovirtSecurityNew virSecurityManagerNew ++#define stratovirtSecurityNewStack virSecurityManagerNewStack ++#define stratovirtSecurityStackAddNested virSecurityManagerStackAddNested ++ ++typedef virQEMUDriver virStratoVirtDriver; ++typedef virStratoVirtDriver *virStratoVirtDriverPtr; ++ ++typedef virQEMUDriverConfig virStratoVirtDriverConfig; ++typedef virStratoVirtDriverConfig *virStratoVirtDriverConfigPtr; ++G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStratoVirtDriverConfig, virObjectUnref); ++ ++virCapsPtr virStratoVirtDriverGetCapabilities(virStratoVirtDriverPtr driver,bool refresh); ++virStratoVirtDriverConfigPtr virStratoVirtDriverConfigNew(bool privileged); ++virStratoVirtDriverConfigPtr virStratoVirtDriverGetConfig(virStratoVirtDriverPtr driver); ++virDomainXMLOptionPtr stratovirtDomainXMLConfInit(virStratoVirtDriverPtr driver); ++ ++static inline void stratovirtDriverLock(virStratoVirtDriverPtr driver) ++{ ++ virMutexLock(&driver->lock); ++} ++ ++static inline void stratovirtDriverUnlock(virStratoVirtDriverPtr driver) ++{ ++ virMutexUnlock(&driver->lock); ++} ++ ++char *stratovirtGetBaseHugepagePath(virHugeTLBFSPtr hugepage); ++void stratovirtGetMemoryBackingBasePath(virStratoVirtDriverConfigPtr cfg, ++ char **path); ++ ++typedef struct StratoVirtConf { ++ void (*stratovirtSharedDeviceEntryFree)(void *payload); ++ virFileCachePtr (*virStratoVirtCapsCacheNew)(const char *libDir, ++ const char *cacheDir, ++ uid_t runUid, ++ gid_t runGid); ++} virStratoVirtConf; ++ ++extern virStratoVirtConf stratovirtconf; +diff --git a/src/stratovirt/stratovirt_domain.c b/src/stratovirt/stratovirt_domain.c +new file mode 100644 +index 0000000000..4ebe71a03b +--- /dev/null ++++ b/src/stratovirt/stratovirt_domain.c +@@ -0,0 +1,143 @@ ++/* ++ * huawei_stratovirt_domain.c: huawei stratovirt domain functions ++ * Manage domain state. ++ * ++ * Copyright (C) 2022-2022 HUAWEI, Inc. ++ * ++ * 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 ++ * . ++ * ++ */ ++ ++#include ++ ++#include "stratovirt_domain.h" ++#include "viralloc.h" ++#include "virlog.h" ++#include "virstring.h" ++ ++#define VIR_FROM_THIS VIR_FROM_STRATOVIRT ++ ++VIR_LOG_INIT("stratovirt.stratovirt_domain"); ++ ++ ++static int virStratoVirtDomainPostParseBasic(virDomainDefPtr def, ++ void * opaque G_GNUC_UNUSED) ++{ ++ if (!def->emulator) { ++ if (!(def->emulator = g_find_program_in_path(STRATOVIRT_CMD))) { ++ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", ++ _("No emulator found for stratovirt")); ++ return 1; ++ } ++ } ++ return 0; ++} ++ ++static int virStratoVirtDomainPostParse(virDomainDefPtr def, ++ unsigned int parseFlags G_GNUC_UNUSED, ++ void * opaque, ++ void *parseOpaue G_GNUC_UNUSED) ++{ ++ virStratoVirtDriverPtr driver = opaque; ++ g_autoptr(virCaps) caps = virStratoVirtDriverGetCapabilities(driver, false); ++ ++ if (!caps) ++ return -1; ++ ++ if (!virCapabilitiesDomainSupported(caps, def->os.type, ++ def->os.arch, ++ def->virtType)) ++ return -1; ++ ++ return 0; ++} ++ ++static int virStratoVirtValidateDeviceDef(const virDomainDeviceDef* dev, ++ const virDomainDef *def G_GNUC_UNUSED, ++ void *opaque G_GNUC_UNUSED) ++{ ++ switch ((virDomainDeviceType)dev->type) { ++ case VIR_DOMAIN_DEVICE_DISK: ++ case VIR_DOMAIN_DEVICE_NET: ++ case VIR_DOMAIN_DEVICE_MEMORY: ++ case VIR_DOMAIN_DEVICE_VSOCK: ++ case VIR_DOMAIN_DEVICE_CONTROLLER: ++ case VIR_DOMAIN_DEVICE_CHR: ++ case VIR_DOMAIN_DEVICE_MEMBALLOON: ++ case VIR_DOMAIN_DEVICE_HOSTDEV: ++ case VIR_DOMAIN_DEVICE_RNG: ++ case VIR_DOMAIN_DEVICE_SHMEM: ++ break; ++ ++ case VIR_DOMAIN_DEVICE_LEASE: ++ case VIR_DOMAIN_DEVICE_FS: ++ case VIR_DOMAIN_DEVICE_INPUT: ++ case VIR_DOMAIN_DEVICE_SOUND: ++ case VIR_DOMAIN_DEVICE_VIDEO: ++ case VIR_DOMAIN_DEVICE_WATCHDOG: ++ case VIR_DOMAIN_DEVICE_GRAPHICS: ++ case VIR_DOMAIN_DEVICE_HUB: ++ case VIR_DOMAIN_DEVICE_REDIRDEV: ++ case VIR_DOMAIN_DEVICE_SMARTCARD: ++ case VIR_DOMAIN_DEVICE_NVRAM: ++ case VIR_DOMAIN_DEVICE_TPM: ++ case VIR_DOMAIN_DEVICE_PANIC: ++ case VIR_DOMAIN_DEVICE_IOMMU: ++ case VIR_DOMAIN_DEVICE_NONE: ++ case VIR_DOMAIN_DEVICE_LAST: ++ default: ++ virReportEnumRangeError(virDomainDeviceType, dev->type); ++ return -1; ++ } ++ return 0; ++} ++ ++virDomainDefParserConfig virStratoVirtDriverDomainDefParserConfig = { ++ .domainPostParseBasicCallback = virStratoVirtDomainPostParseBasic, ++ .domainPostParseCallback = virStratoVirtDomainPostParse, ++ .deviceValidateCallback = virStratoVirtValidateDeviceDef, ++}; ++ ++void stratovirtProcessEventFree(stratovirtProcessEventPtr event) ++{ ++ if (!event) ++ return; ++ ++ switch (event->eventType) { ++ case STRATOVIRT_PROCESS_EVENT_GUESTPANIC: ++ case STRATOVIRT_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED: ++ break; ++ case STRATOVIRT_PROCESS_EVENT_WATCHDOG: ++ case STRATOVIRT_PROCESS_EVENT_DEVICE_DELETED: ++ case STRATOVIRT_PROCESS_EVENT_NIC_RX_FILTER_CHANGED: ++ case STRATOVIRT_PROCESS_EVENT_SERIAL_CHANGED: ++ case STRATOVIRT_PROCESS_EVENT_BLOCK_JOB: ++ case STRATOVIRT_PROCESS_EVENT_MONITOR_EOF: ++ case STRATOVIRT_PROCESS_EVENT_GUEST_CRASHLOADED: ++ VIR_FREE(event->data); ++ break; ++ case STRATOVIRT_PROCESS_EVENT_JOB_STATUS_CHANGE: ++ virObjectUnref(event->data); ++ break; ++ case STRATOVIRT_PROCESS_EVENT_PR_DISCONNECT: ++ case STRATOVIRT_PROCESS_EVENT_LAST: ++ break; ++ } ++ VIR_FREE(event); ++} ++ ++virStratoVirtDomain stratovirtDom = { ++ .stratovirtDomainNamespaceAvailable = qemuDomainNamespaceAvailable, ++}; +diff --git a/src/stratovirt/stratovirt_domain.h b/src/stratovirt/stratovirt_domain.h +new file mode 100644 +index 0000000000..801c697414 +--- /dev/null ++++ b/src/stratovirt/stratovirt_domain.h +@@ -0,0 +1,65 @@ ++/* ++ * huawei_stratovirt_domain.h: huawei stratovirt domain functions ++ * Manage domain state. ++ * ++ * Copyright (C) 2022-2022 HUAWEI, Inc. ++ * ++ * 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 ++ * . ++ * ++ */ ++ ++#pragma once ++ ++#include "stratovirt_conf.h" ++ ++#include "qemu_hotplug.h" ++ ++typedef enum { ++ STRATOVIRT_PROCESS_EVENT_WATCHDOG = 0, ++ STRATOVIRT_PROCESS_EVENT_GUESTPANIC, ++ STRATOVIRT_PROCESS_EVENT_DEVICE_DELETED, ++ STRATOVIRT_PROCESS_EVENT_NIC_RX_FILTER_CHANGED, ++ STRATOVIRT_PROCESS_EVENT_SERIAL_CHANGED, ++ STRATOVIRT_PROCESS_EVENT_BLOCK_JOB, ++ STRATOVIRT_PROCESS_EVENT_JOB_STATUS_CHANGE, ++ STRATOVIRT_PROCESS_EVENT_MONITOR_EOF, ++ STRATOVIRT_PROCESS_EVENT_PR_DISCONNECT, ++ STRATOVIRT_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED, ++ STRATOVIRT_PROCESS_EVENT_GUEST_CRASHLOADED, ++ ++ STRATOVIRT_PROCESS_EVENT_LAST ++} stratovirtProcessEventType; ++ ++typedef struct _stratovirtProcessEvent stratovirtProcessEvent; ++typedef stratovirtProcessEvent *stratovirtProcessEventPtr; ++typedef qemuDomainNamespace stratovirtDomainNamespace; ++ ++void stratovirtProcessEventFree(stratovirtProcessEventPtr event); ++ ++struct _stratovirtProcessEvent { ++ virDomainObjPtr vm; ++ stratovirtProcessEventType eventType; ++ int action; ++ int status; ++ void *data; ++}; ++ ++extern virDomainDefParserConfig virStratoVirtDriverDomainDefParserConfig; ++ ++typedef struct StratoVirtDomain { ++ bool (*stratovirtDomainNamespaceAvailable)(stratovirtDomainNamespace ns G_GNUC_UNUSED); ++} virStratoVirtDomain; ++ ++extern virStratoVirtDomain stratovirtDom; +diff --git a/src/stratovirt/stratovirt_driver.c b/src/stratovirt/stratovirt_driver.c +new file mode 100644 +index 0000000000..f7ca80f0af +--- /dev/null ++++ b/src/stratovirt/stratovirt_driver.c +@@ -0,0 +1,587 @@ ++/* ++ * huawei_stratovirt_driver.c: huawei stratovirt driver functions ++ * Manage stratovirt driver and the lifecycle of domains. ++ * ++ * Copyright (C) 2022-2022 HUAWEI, Inc. ++ * ++ * 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 ++ * . ++ * ++ */ ++ ++#include ++ ++#include "stratovirt_driver.h" ++#include "stratovirt_conf.h" ++#include "stratovirt_domain.h" ++#include "stratovirt_process.h" ++ ++#include "virerror.h" ++#include "virlog.h" ++#include "virdomaincheckpointobjlist.h" ++#include "viralloc.h" ++#include "virpidfile.h" ++#include "virtime.h" ++#include "virstring.h" ++#include "virdomainsnapshotobjlist.h" ++#include "virutil.h" ++#include "viraccessapicheck.h" ++#include "domain_audit.h" ++#include "locking/domain_lock.h" ++ ++#define VIR_FROM_THIS VIR_FROM_STRATOVIRT ++ ++VIR_LOG_INIT("stratovirt.stratovirt_driver"); ++ ++static virStratoVirtDriverPtr stratovirt_driver; ++ ++static int ++stratovirtConnectURIProbe(char **uri) ++{ ++ if (stratovirt_driver == NULL) ++ return 0; ++ ++ *uri = g_strdup("stratovirt:///system"); ++ ++ return 1; ++} ++ ++static virDrvOpenStatus stratovirtConnectOpen(virConnectPtr conn, ++ virConnectAuthPtr auth G_GNUC_UNUSED, ++ virConfPtr conf G_GNUC_UNUSED, ++ unsigned int flags) ++{ ++ virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); ++ ++ /* uri is good but driver isn't */ ++ if (stratovirt_driver == NULL) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", ++ _("stratovirt state driver is not active")); ++ return VIR_DRV_OPEN_ERROR; ++ } ++ ++ if (virConnectOpenEnsureACL(conn) < 0) ++ return VIR_DRV_OPEN_ERROR; ++ ++ conn->privateData = stratovirt_driver; ++ ++ return VIR_DRV_OPEN_SUCCESS; ++} ++ ++static int stratovirtConnectClose(virConnectPtr conn) ++{ ++ conn->privateData = NULL; ++ return 0; ++} ++ ++static const char *stratovirtConnectGetType(virConnectPtr conn) ++{ ++ if (virConnectGetTypeEnsureACL(conn) < 0) ++ return NULL; ++ ++ return "StratoVirt"; ++} ++ ++static int stratovirtParseVersion(unsigned long *version, ++ const char *str) ++{ ++ unsigned int major, minor = 0, micro = 0; ++ char *tmp; ++ ++ if (virStrToLong_ui(str, &tmp, 10, &major) < 0) ++ return -1; ++ ++ if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, &minor) < 0) ++ return -1; ++ ++ if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, µ) < 0) ++ return -1; ++ ++ if (major > UINT_MAX / 1000000 || minor > 999 || micro > 999) ++ return -1; ++ ++ *version = 1000000 * major + 1000 * minor + micro; ++ return 0; ++} ++ ++static int stratovirtConnectGetVersion(virConnectPtr conn, unsigned long *version) ++{ ++ g_autofree char *help = NULL; ++ char *tmp = NULL; ++ g_autofree char *stratovirt_cmd = g_find_program_in_path(STRATOVIRT_CMD); ++ g_autoptr(virCommand) cmd = NULL; ++ ++ if (virConnectGetVersionEnsureACL(conn) < 0) ++ return -1; ++ ++ if (!stratovirt_cmd) ++ return -2; ++ ++ /* get version information */ ++ cmd = virCommandNewArgList(stratovirt_cmd, "-V", NULL); ++ virCommandAddEnvString(cmd, "LC_ALL=C"); ++ virCommandSetOutputBuffer(cmd, &help); ++ ++ if (virCommandRun(cmd, NULL) < 0) ++ return -1; ++ ++ tmp = help; ++ ++ if ((tmp = STRSKIP(tmp, "StratoVirt ")) == NULL) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", ++ _("Unexpected output of StratoVirt binary")); ++ return -1; ++ } ++ ++ if (stratovirtParseVersion(version, tmp) < 0) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Unable to parse StratoVirt version: %s"), tmp); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static char *stratovirtConnectGetHostname(virConnectPtr conn) ++{ ++ if (virConnectGetHostnameEnsureACL(conn) < 0) ++ return NULL; ++ ++ return virGetHostname(); ++} ++ ++static int stratovirtConnectNumOfDomains(virConnectPtr conn) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ ++ if (virConnectNumOfDomainsEnsureACL(conn) < 0) ++ return -1; ++ ++ return virDomainObjListNumOfDomains(driver->domains, true, ++ virConnectNumOfDomainsCheckACL, conn); ++ ++} ++ ++static int stratovirtConnectListDomains(virConnectPtr conn, int *ids, int nids) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ ++ if (virConnectListDomainsEnsureACL(conn) < 0) ++ return -1; ++ ++ return virDomainObjListGetActiveIDs(driver->domains, ids, nids, ++ virConnectListDomainsCheckACL, conn); ++ ++} ++ ++static int ++stratovirtConnectListAllDomains(virConnectPtr conn, ++ virDomainPtr **domains, ++ unsigned int flags) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ ++ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1); ++ ++ if (virConnectListAllDomainsEnsureACL(conn) < 0) ++ return -1; ++ ++ return virDomainObjListExport(driver->domains, conn, domains, ++ virConnectListAllDomainsCheckACL, flags); ++} ++ ++ ++static char *stratovirtConnectGetCapabilities(virConnectPtr conn) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ g_autoptr(virCaps) caps = NULL; ++ char *xml; ++ ++ if (virConnectGetCapabilitiesEnsureACL(conn) < 0) ++ return NULL; ++ ++ if (!(caps = virStratoVirtDriverGetCapabilities(driver, true))) ++ return NULL; ++ ++ xml = virCapabilitiesFormatXML(caps); ++ virObjectUnref(caps); ++ return xml; ++} ++ ++static int stratovirtSecurityInit(virStratoVirtDriverPtr driver) ++{ ++ char **names; ++ virSecurityManagerPtr mgr = NULL; ++ virSecurityManagerPtr stack = NULL; ++ g_autoptr(virStratoVirtDriverConfig) cfg = virStratoVirtDriverGetConfig(driver); ++ unsigned int flags = 0; ++ ++ if (cfg->securityDefaultConfined) ++ flags |= VIR_SECURITY_MANAGER_DEFAULT_CONFINED; ++ if (cfg->securityRequireConfined) ++ flags |= VIR_SECURITY_MANAGER_REQUIRE_CONFINED; ++ if (driver->privileged) ++ flags |= VIR_SECURITY_MANAGER_PRIVILEGED; ++ ++ if (cfg->securityDriverNames && ++ cfg->securityDriverNames[0]) { ++ names = cfg->securityDriverNames; ++ while (names && *names) { ++ if (!(mgr = stratovirtSecurityNew(*names, ++ STRATOVIRT_DRIVER_NAME, ++ flags))) ++ goto error; ++ if (!stack) { ++ if (!(stack = stratovirtSecurityNewStack(mgr))) ++ goto error; ++ } else { ++ if (stratovirtSecurityStackAddNested(stack, mgr) < 0) ++ goto error; ++ } ++ mgr = NULL; ++ names++; ++ } ++ } else { ++ if (!(mgr = stratovirtSecurityNew(NULL, ++ STRATOVIRT_DRIVER_NAME, ++ flags))) ++ goto error; ++ if (!(stack = stratovirtSecurityNewStack(mgr))) ++ goto error; ++ mgr = NULL; ++ } ++ ++ driver->securityManager = stack; ++ return 0; ++ ++ error: ++ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", ++ _("Failed to initialize security drivers")); ++ virObjectUnref(stack); ++ virObjectUnref(mgr); ++ return -1; ++} ++ ++static void stratovirtProcessEventHandler(void *data, void *opaque G_GNUC_UNUSED) ++{ ++ stratovirtProcessEventPtr processEvent = data; ++ virDomainObjPtr vm = processEvent->vm; ++ ++ VIR_DEBUG("vm=%p, event=%d", vm, processEvent->eventType); ++ ++ virObjectLock(vm); ++ ++ virDomainObjEndAPI(&vm); ++ stratovirtProcessEventFree(processEvent); ++} ++ ++/** ++ * stratovirtStateCleanup: ++ * ++ * Release resources allocated by StratoVirt driver ++ */ ++static int ++stratovirtStateCleanup(void) ++{ ++ if (!stratovirt_driver) ++ return -1; ++ ++ virObjectUnref(stratovirt_driver->closeCallbacks); ++ virLockManagerPluginUnref(stratovirt_driver->lockManager); ++ virSysinfoDefFree(stratovirt_driver->hostsysinfo); ++ virPortAllocatorRangeFree(stratovirt_driver->webSocketPorts); ++ virPortAllocatorRangeFree(stratovirt_driver->remotePorts); ++ virHashFree(stratovirt_driver->sharedDevices); ++ virObjectUnref(stratovirt_driver->hostdevMgr); ++ virObjectUnref(stratovirt_driver->securityManager); ++ virObjectUnref(stratovirt_driver->domainEventState); ++ virObjectUnref(stratovirt_driver->qemuCapsCache); ++ virObjectUnref(stratovirt_driver->xmlopt); ++ virCPUDefFree(stratovirt_driver->hostcpu); ++ virCapabilitiesHostNUMAUnref(stratovirt_driver->hostnuma); ++ virObjectUnref(stratovirt_driver->caps); ++ ebtablesContextFree(stratovirt_driver->ebtables); ++ virObjectUnref(stratovirt_driver->domains); ++ virThreadPoolFree(stratovirt_driver->workerPool); ++ ++ if (stratovirt_driver->lockFD != -1) ++ virPidFileRelease(stratovirt_driver->config->stateDir, "driver", stratovirt_driver->lockFD); ++ ++ virObjectUnref(stratovirt_driver->config); ++ virMutexDestroy(&stratovirt_driver->lock); ++ VIR_FREE(stratovirt_driver); ++ ++ return 0; ++} ++ ++/** ++ * stratovirtStateInitialize: ++ * ++ * Initialization function for the StratoVirt daemon ++ */ ++static int ++stratovirtStateInitialize(bool privileged, ++ const char *root, ++ virStateInhibitCallback callback, ++ void *opaque) ++{ ++ g_autofree char *driverConf = NULL; ++ virStratoVirtDriverConfigPtr cfg; ++ uid_t run_uid = -1; ++ gid_t run_gid = -1; ++ g_autofree char *memoryBackingPath = NULL; ++ bool autostart = true; ++ size_t i; ++ g_autofree virSecurityManagerPtr *sec_managers = NULL; ++ ++ if (VIR_ALLOC(stratovirt_driver) < 0) ++ return VIR_DRV_STATE_INIT_ERROR; ++ ++ stratovirt_driver->lockFD = -1; ++ ++ if (virMutexInit(&stratovirt_driver->lock) < 0) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", ++ _("cannot initialize mutex")); ++ VIR_FREE(stratovirt_driver); ++ return VIR_DRV_STATE_INIT_ERROR; ++ } ++ ++ if (root != NULL) { ++ virReportError(VIR_ERR_INVALID_ARG, "%s", ++ _("Driver only support root user.")); ++ return -1; ++ } ++ ++ stratovirt_driver->inhibitCallback = callback; ++ stratovirt_driver->inhibitOpaque = opaque; ++ ++ stratovirt_driver->privileged = privileged; ++ stratovirt_driver->hostarch = virArchFromHost(); ++ ++ if (!(stratovirt_driver->domains = virDomainObjListNew())) ++ goto error; ++ ++ stratovirt_driver->domainEventState = virObjectEventStateNew(); ++ if (!stratovirt_driver->domainEventState) ++ goto error; ++ ++ if (privileged) ++ stratovirt_driver->hostsysinfo = virSysinfoRead(); ++ ++ if (!(stratovirt_driver->config = cfg = virStratoVirtDriverConfigNew(privileged))) ++ goto error; ++ ++ if (!(driverConf = g_strdup_printf("%s/stratovirt.conf", cfg->configBaseDir))) ++ goto error; ++ ++ if (virFileMakePath(cfg->stateDir) < 0) { ++ virReportSystemError(errno, _("Failed to create state dir %s"), ++ cfg->stateDir); ++ goto error; ++ } ++ if (virFileMakePath(cfg->libDir) < 0) { ++ virReportSystemError(errno, _("Failed to create lib dir %s"), ++ cfg->libDir); ++ goto error; ++ } ++ if (virFileMakePath(cfg->cacheDir) < 0) { ++ virReportSystemError(errno, _("Failed to create cache dir %s"), ++ cfg->cacheDir); ++ goto error; ++ } ++ if (virFileMakePath(cfg->saveDir) < 0) { ++ virReportSystemError(errno, _("Failed to create save dir %s"), ++ cfg->saveDir); ++ goto error; ++ } ++ if (virFileMakePath(cfg->snapshotDir) < 0) { ++ virReportSystemError(errno, _("Failed to create snapshot dir %s"), ++ cfg->snapshotDir); ++ goto error; ++ } ++ if (virFileMakePath(cfg->checkpointDir) < 0) { ++ virReportSystemError(errno, _("Failed to create checkpoint dir %s"), ++ cfg->checkpointDir); ++ goto error; ++ } ++ if (virFileMakePath(cfg->autoDumpPath) < 0) { ++ virReportSystemError(errno, _("Failed to create dump dir %s"), ++ cfg->autoDumpPath); ++ goto error; ++ } ++ if (virFileMakePath(cfg->channelTargetDir) < 0) { ++ virReportSystemError(errno, _("Failed to create channel target dir %s"), ++ cfg->channelTargetDir); ++ goto error; ++ } ++ if (virFileMakePath(cfg->memoryBackingDir) < 0) { ++ virReportSystemError(errno, _("Failed to create memory backing dir %s"), ++ cfg->memoryBackingDir); ++ goto error; ++ } ++ ++ if ((stratovirt_driver->lockFD = ++ virPidFileAcquire(cfg->stateDir, "driver", false, getpid())) < 0) ++ goto error; ++ ++ if (!(stratovirt_driver->lockManager = ++ virLockManagerPluginNew(cfg->lockManagerName ? ++ cfg->lockManagerName : "nop", ++ "stratovirt", ++ cfg->configBaseDir, ++ 0))) ++ goto error; ++ ++ if (cfg->macFilter) { ++ if (!(stratovirt_driver->ebtables = ebtablesContextNew("stratovirt"))) { ++ virReportSystemError(errno, ++ _("failed to enable mac filter in '%s'"), ++ __FILE__); ++ goto error; ++ } ++ ++ if (ebtablesAddForwardPolicyReject(stratovirt_driver->ebtables) < 0) ++ goto error; ++ } ++ ++ if ((stratovirt_driver->remotePorts = ++ virPortAllocatorRangeNew(_("display"), ++ cfg->remotePortMin, ++ cfg->remotePortMax)) == NULL) ++ goto error; ++ ++ if ((stratovirt_driver->webSocketPorts = ++ virPortAllocatorRangeNew(_("webSocket"), ++ cfg->webSocketPortMin, ++ cfg->webSocketPortMax)) == NULL) ++ goto error; ++ ++ if (stratovirtSecurityInit(stratovirt_driver) < 0) ++ goto error; ++ ++ if (!(stratovirt_driver->hostdevMgr = virHostdevManagerGetDefault())) ++ goto error; ++ ++ if (!(stratovirt_driver->sharedDevices = virHashCreate(30, stratovirtconf.stratovirtSharedDeviceEntryFree))) ++ goto error; ++ ++ stratovirt_driver->qemuCapsCache = stratovirtconf.virStratoVirtCapsCacheNew(cfg->libDir, ++ cfg->cacheDir, ++ run_uid, ++ run_gid); ++ if (!stratovirt_driver->qemuCapsCache) ++ goto error; ++ ++ if (!(sec_managers = stratovirtSecurityGetNested(stratovirt_driver->securityManager))) ++ goto error; ++ ++ if (!(stratovirt_driver->xmlopt = stratovirtDomainXMLConfInit(stratovirt_driver))) ++ goto error; ++ ++ for (i = 0; i < cfg->nhugetlbfs; i++) { ++ g_autofree char *hugepagePath = NULL; ++ ++ hugepagePath = stratovirtGetBaseHugepagePath(&cfg->hugetlbfs[i]); ++ ++ if (!hugepagePath) ++ goto error; ++ ++ if (virFileMakePath(hugepagePath) < 0) { ++ virReportSystemError(errno, ++ _("unable to create hugepage path %s"), ++ hugepagePath); ++ goto error; ++ } ++ if (privileged && ++ virFileUpdatePerm(cfg->hugetlbfs[i].mnt_dir, ++ 0, S_IXGRP | S_IXOTH) < 0) ++ goto error; ++ } ++ ++ stratovirtGetMemoryBackingBasePath(cfg, &memoryBackingPath); ++ ++ if (virFileMakePath(memoryBackingPath) < 0) { ++ virReportSystemError(errno, ++ _("unable to create memory backing path %s"), ++ memoryBackingPath); ++ goto error; ++ } ++ ++ if (privileged && ++ virFileUpdatePerm(memoryBackingPath, ++ 0, S_IXGRP | S_IXOTH) < 0) ++ goto error; ++ ++ if (!(stratovirt_driver->closeCallbacks = virCloseCallbacksNew())) ++ goto error; ++ ++ if (virDomainObjListLoadAllConfigs(stratovirt_driver->domains, ++ cfg->stateDir, ++ NULL, true, ++ stratovirt_driver->xmlopt, ++ NULL, NULL) < 0) ++ goto error; ++ ++ stratovirt_driver->workerPool = virThreadPoolNewFull(0, 1, 0, stratovirtProcessEventHandler, ++ "stratovirt-event", stratovirt_driver); ++ if (!stratovirt_driver->workerPool) ++ goto error; ++ ++ stratovirtPro.stratovirtProcessReconnectAll(stratovirt_driver); ++ ++ if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0) ++ goto error; ++ ++ return VIR_DRV_STATE_INIT_COMPLETE; ++ ++ error: ++ stratovirtStateCleanup(); ++ return VIR_DRV_STATE_INIT_ERROR; ++} ++ ++static virHypervisorDriver stratovirtHypervisorDriver = { ++ .name = STRATOVIRT_DRIVER_NAME, ++ .connectURIProbe = stratovirtConnectURIProbe, ++ .connectOpen = stratovirtConnectOpen, /* 2.2.0 */ ++ .connectClose = stratovirtConnectClose, /* 2.2.0 */ ++ .connectGetType = stratovirtConnectGetType, /* 2.2.0 */ ++ .connectGetVersion = stratovirtConnectGetVersion, /* 2.2.0 */ ++ .connectGetHostname = stratovirtConnectGetHostname, /* 2.2.0 */ ++ .connectListDomains = stratovirtConnectListDomains, /* 2.2.0 */ ++ .connectNumOfDomains = stratovirtConnectNumOfDomains, /* 2.2.0 */ ++ .connectListAllDomains = stratovirtConnectListAllDomains, /* 2.2.0 */ ++ .connectGetCapabilities = stratovirtConnectGetCapabilities, /* 2.2.0 */ ++}; ++ ++static virConnectDriver stratovirtConnectDriver = { ++ .localOnly = true, ++ .uriSchemes = (const char *[]){ "stratovirt", NULL }, ++ .hypervisorDriver = &stratovirtHypervisorDriver, ++}; ++ ++static virStateDriver stratovirtStateDriver = { ++ .name = "StratoVirt", ++ .stateInitialize = stratovirtStateInitialize, ++ .stateCleanup = stratovirtStateCleanup, ++}; ++ ++int stratovirtRegister(void) ++{ ++ if (virRegisterConnectDriver(&stratovirtConnectDriver, ++ true) < 0) ++ return -1; ++ if (virRegisterStateDriver(&stratovirtStateDriver) < 0) ++ return -1; ++ return 0; ++} +diff --git a/src/stratovirt/stratovirt_driver.h b/src/stratovirt/stratovirt_driver.h +new file mode 100644 +index 0000000000..a157b2d717 +--- /dev/null ++++ b/src/stratovirt/stratovirt_driver.h +@@ -0,0 +1,25 @@ ++/* ++ * huawei_stratovirt_driver.h: huawei stratovirt driver functions ++ * Manage stratovirt driver and the lifecycle of domains. ++ * ++ * Copyright (C) 2022-2022 HUAWEI, Inc. ++ * ++ * 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 ++ * . ++ * ++ */ ++ ++#pragma once ++ ++int stratovirtRegister(void); +diff --git a/src/stratovirt/stratovirt_process.c b/src/stratovirt/stratovirt_process.c +new file mode 100644 +index 0000000000..8a67c5a31b +--- /dev/null ++++ b/src/stratovirt/stratovirt_process.c +@@ -0,0 +1,33 @@ ++/* ++ * huawei_stratovirt_process.c: huawei stratovirt process functions ++ * Manage process. ++ * ++ * Copyright (C) 2022-2022 HUAWEI, Inc. ++ * ++ * 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 ++ * . ++ * ++ */ ++ ++#include "stratovirt_process.h" ++ ++#include "virlog.h" ++ ++#define VIR_FROM_THIS VIR_FROM_STRATOVIRT ++ ++VIR_LOG_INIT("stratovirt.stratovirt_process"); ++ ++virStratoVirtProcess stratovirtPro = { ++ .stratovirtProcessReconnectAll = qemuProcessReconnectAll, ++}; +diff --git a/src/stratovirt/stratovirt_process.h b/src/stratovirt/stratovirt_process.h +new file mode 100644 +index 0000000000..942dd34330 +--- /dev/null ++++ b/src/stratovirt/stratovirt_process.h +@@ -0,0 +1,32 @@ ++/* ++ * huawei_stratovirt_process.h: huawei stratovirt process functions ++ * Manage process ++ * ++ * Copyright (C) 2022-2022 HUAWEI, Inc. ++ * ++ * 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 ++ * . ++ * ++ */ ++ ++#pragma once ++ ++#include "stratovirt_domain.h" ++#include "qemu_process.h" ++ ++typedef struct StratoVirtProcess { ++ void (*stratovirtProcessReconnectAll)(virStratoVirtDriverPtr driver); ++} virStratoVirtProcess; ++ ++extern virStratoVirtProcess stratovirtPro; +diff --git a/src/util/virerror.c b/src/util/virerror.c +index 774c36bca3..5592cef69f 100644 +--- a/src/util/virerror.c ++++ b/src/util/virerror.c +@@ -144,6 +144,7 @@ VIR_ENUM_IMPL(virErrorDomain, + + "TPM", /* 70 */ + "BPF", ++ "StratoVirt Driver", + ); + + +diff --git a/tools/virsh.c b/tools/virsh.c +index 197a90636d..41fe5b1b1e 100644 +--- a/tools/virsh.c ++++ b/tools/virsh.c +@@ -501,6 +501,9 @@ virshShowVersion(vshControl *ctl G_GNUC_UNUSED) + #ifdef WITH_QEMU + vshPrint(ctl, " QEMU/KVM"); + #endif ++#ifdef WITH_STRATOVIRT ++ vshPrint(ctl, " StratoVirt"); ++#endif + #ifdef WITH_LXC + vshPrint(ctl, " LXC"); + #endif +-- +2.25.1 + diff --git a/Add-command-virsh-list-virsh-suspend-virsh-resume-an.patch b/Add-command-virsh-list-virsh-suspend-virsh-resume-an.patch new file mode 100644 index 0000000000000000000000000000000000000000..6934fd06e464384a9749c05d7c6f30b23d2fda95 --- /dev/null +++ b/Add-command-virsh-list-virsh-suspend-virsh-resume-an.patch @@ -0,0 +1,340 @@ +From a61a9bd333e714d5d856094588f18c678cc8adbe Mon Sep 17 00:00:00 2001 +From: mayunlong +Date: Fri, 12 Aug 2022 20:46:29 +0800 +Subject: [PATCH 3/3] Add command "virsh list","virsh suspend","virsh resume" + and "virsh console". + +--- + src/stratovirt/stratovirt_domain.c | 13 ++ + src/stratovirt/stratovirt_domain.h | 5 + + src/stratovirt/stratovirt_driver.c | 195 ++++++++++++++++++++++++++++ + src/stratovirt/stratovirt_process.c | 4 +- + src/stratovirt/stratovirt_process.h | 8 ++ + 5 files changed, 224 insertions(+), 1 deletion(-) + +diff --git a/src/stratovirt/stratovirt_domain.c b/src/stratovirt/stratovirt_domain.c +index 4efc987509..4ed9250d1e 100644 +--- a/src/stratovirt/stratovirt_domain.c ++++ b/src/stratovirt/stratovirt_domain.c +@@ -156,8 +156,21 @@ virDomainObjPtr stratovirtDomainObjFromDomain(virDomainPtr domain) + return vm; + } + ++void ++stratovirtDomainUpdateCurrentMemorySize(virDomainObjPtr vm) ++{ ++ if (!virDomainObjIsActive(vm)) ++ return; ++ ++ /* if no balloning is available, the current size equals to the current ++ * full memory size */ ++ if (!virDomainDefHasMemballoon(vm->def)) ++ vm->def->mem.cur_balloon = virDomainDefGetMemoryTotal(vm->def); ++} ++ + virStratoVirtDomain stratovirtDom = { + .stratovirtDomainNamespaceAvailable = qemuDomainNamespaceAvailable, + .stratovirtDomainRemoveInactive = qemuDomainRemoveInactive, + .stratovirtDomainObjEndJob = qemuDomainObjEndJob, ++ .stratovirtDomainObjBeginJob = qemuDomainObjBeginJob, + }; +diff --git a/src/stratovirt/stratovirt_domain.h b/src/stratovirt/stratovirt_domain.h +index da653eb13a..405d55d547 100644 +--- a/src/stratovirt/stratovirt_domain.h ++++ b/src/stratovirt/stratovirt_domain.h +@@ -45,6 +45,7 @@ typedef enum { + typedef struct _stratovirtProcessEvent stratovirtProcessEvent; + typedef stratovirtProcessEvent *stratovirtProcessEventPtr; + typedef qemuDomainNamespace stratovirtDomainNamespace; ++typedef qemuDomainJob stratovirtDomainJob; + + void stratovirtProcessEventFree(stratovirtProcessEventPtr event); + +@@ -62,6 +63,7 @@ typedef qemuDomainObjPrivate stratovirtDomainObjPrivate; + typedef stratovirtDomainObjPrivate *stratovirtDomainObjPrivatePtr; + + virDomainObjPtr stratovirtDomainObjFromDomain(virDomainPtr domain); ++void stratovirtDomainUpdateCurrentMemorySize(virDomainObjPtr vm); + + typedef struct StratoVirtDomain { + bool (*stratovirtDomainNamespaceAvailable)(stratovirtDomainNamespace ns G_GNUC_UNUSED); +@@ -69,6 +71,9 @@ typedef struct StratoVirtDomain { + virDomainObjPtr vm); + void (*stratovirtDomainObjEndJob)(virStratoVirtDriverPtr driver, + virDomainObjPtr obj); ++ int (*stratovirtDomainObjBeginJob)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr obj, ++ stratovirtDomainJob job); + } virStratoVirtDomain; + + extern virStratoVirtDomain stratovirtDom; +diff --git a/src/stratovirt/stratovirt_driver.c b/src/stratovirt/stratovirt_driver.c +index ac00c35349..abd99bc8ea 100644 +--- a/src/stratovirt/stratovirt_driver.c ++++ b/src/stratovirt/stratovirt_driver.c +@@ -45,9 +45,13 @@ + VIR_LOG_INIT("stratovirt.stratovirt_driver"); + + #define STRATOVIRT_ASYNC_JOB_NONE 0 ++#define STRATOVIRT_ASYNC_JOB_MIGRATION_OUT 1 + #define STRATOVIRT_ASYNC_JOB_MIGRATION_IN 2 ++#define STRATOVIRT_ASYNC_JOB_SNAPSHOT 5 + #define STRATOVIRT_ASYNC_JOB_START 6 + #define STRATOVIRT_JOB_DESTROY 2 ++#define STRATOVIRT_JOB_SUSPEND 3 ++#define STRATOVIRT_JOB_MODIFY 4 + #define VIR_STRATOVIRT_PROCESS_START_COLD 1 + #define VIR_STRATOVIRT_PROCESS_STOP_MIGRATED 1 + +@@ -295,6 +299,114 @@ static virDomainPtr stratovirtDomainCreateXML(virConnectPtr conn, + return dom; + } + ++static int stratovirtDomainSuspend(virDomainPtr dom) ++{ ++ virStratoVirtDriverPtr driver = dom->conn->privateData; ++ virDomainObjPtr vm; ++ int ret = -1; ++ stratovirtDomainObjPrivatePtr priv; ++ virDomainPausedReason reason; ++ int state; ++ g_autoptr(virStratoVirtDriverConfig) cfg = virStratoVirtDriverGetConfig(driver); ++ ++ if (!(vm = stratovirtDomainObjFromDomain(dom))) ++ return -1; ++ ++ if (virDomainSuspendEnsureACL(dom->conn, vm->def) < 0) ++ goto cleanup; ++ ++ priv = vm->privateData; ++ ++ if (stratovirtDom.stratovirtDomainObjBeginJob(driver, vm, STRATOVIRT_JOB_SUSPEND) < 0) ++ goto cleanup; ++ ++ if (virDomainObjCheckActive(vm) < 0) ++ goto endjob; ++ ++ if (priv->job.asyncJob == STRATOVIRT_ASYNC_JOB_MIGRATION_OUT) ++ reason = VIR_DOMAIN_PAUSED_MIGRATION; ++ else if (priv->job.asyncJob == STRATOVIRT_ASYNC_JOB_SNAPSHOT) ++ reason = VIR_DOMAIN_PAUSED_SNAPSHOT; ++ else ++ reason = VIR_DOMAIN_PAUSED_USER; ++ ++ state = virDomainObjGetState(vm, NULL); ++ if (state == VIR_DOMAIN_PMSUSPENDED) { ++ virReportError(VIR_ERR_OPERATION_INVALID, ++ "%s", _("domain is pmsuspended")); ++ goto endjob; ++ } else if (state != VIR_DOMAIN_PAUSED) { ++ if (stratovirtPro.stratovirtProcessStopCPUs(driver, vm, reason, STRATOVIRT_ASYNC_JOB_NONE) < 0) ++ goto endjob; ++ } ++ if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) ++ goto endjob; ++ ++ ret = 0; ++ ++endjob: ++ stratovirtDom.stratovirtDomainObjEndJob(driver, vm); ++ ++cleanup: ++ virDomainObjEndAPI(&vm); ++ ++ return ret; ++} ++ ++static int stratovirtDomainResume(virDomainPtr dom) ++{ ++ virStratoVirtDriverPtr driver = dom->conn->privateData; ++ virDomainObjPtr vm; ++ int ret = -1; ++ int state; ++ int reason; ++ g_autoptr(virStratoVirtDriverConfig) cfg = virStratoVirtDriverGetConfig(driver); ++ ++ if (!(vm = stratovirtDomainObjFromDomain(dom))) ++ return -1; ++ ++ if (virDomainResumeEnsureACL(dom->conn, vm->def) < 0) ++ goto cleanup; ++ ++ if (stratovirtDom.stratovirtDomainObjBeginJob(driver, vm, STRATOVIRT_JOB_MODIFY) < 0) ++ goto cleanup; ++ ++ if (virDomainObjCheckActive(vm) < 0) ++ goto endjob; ++ ++ state = virDomainObjGetState(vm, &reason); ++ if (state == VIR_DOMAIN_PMSUSPENDED) { ++ virReportError(VIR_ERR_OPERATION_INVALID, ++ "%s", _("domain is pmsuspended")); ++ goto endjob; ++ } else if (state == VIR_DOMAIN_RUNNING) { ++ virReportError(VIR_ERR_OPERATION_INVALID, ++ "%s", _("domain is already running")); ++ goto endjob; ++ } else if ((state == VIR_DOMAIN_CRASHED && ++ reason == VIR_DOMAIN_CRASHED_PANICKED) || ++ state == VIR_DOMAIN_PAUSED) { ++ if (stratovirtPro.stratovirtProcessStartCPUs(driver, vm, ++ VIR_DOMAIN_RUNNING_UNPAUSED, ++ STRATOVIRT_ASYNC_JOB_NONE) < 0) { ++ if (virGetLastErrorCode() == VIR_ERR_OK) ++ virReportError(VIR_ERR_OPERATION_FAILED, ++ "%s", _("resume operation failed")); ++ goto endjob; ++ } ++ } ++ if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) ++ goto endjob; ++ ret = 0; ++ ++ endjob: ++ stratovirtDom.stratovirtDomainObjEndJob(driver, vm); ++ ++ cleanup: ++ virDomainObjEndAPI(&vm); ++ return ret; ++} ++ + static int + stratovirtDomainDestroyFlags(virDomainPtr dom, + unsigned int flags) +@@ -364,6 +476,85 @@ static int stratovirtDomainDestroy(virDomainPtr dom) + return stratovirtDomainDestroyFlags(dom, 0); + } + ++static int stratovirtDomainOpenConsole(virDomainPtr dom, ++ const char *dev_name G_GNUC_UNUSED, ++ virStreamPtr st, ++ unsigned int flags) ++{ ++ virDomainObjPtr vm = NULL; ++ int ret = -1; ++ virDomainChrDefPtr chr = NULL; ++ stratovirtDomainObjPrivatePtr priv; ++ ++ virCheckFlags(VIR_DOMAIN_CONSOLE_SAFE | VIR_DOMAIN_CONSOLE_FORCE, -1); ++ ++ if (!(vm = stratovirtDomainObjFromDomain(dom))) ++ goto cleanup; ++ ++ if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0) ++ goto cleanup; ++ ++ if (virDomainObjCheckActive(vm) < 0) ++ goto cleanup; ++ ++ priv = vm->privateData; ++ ++ if (vm->def->nconsoles) ++ chr = vm->def->consoles[0]; ++ else if (vm->def->nserials) ++ chr = vm->def->serials[0]; ++ ++ if (!chr) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", ++ _("cannot find character device")); ++ goto cleanup; ++ } ++ ++ if (chr->source->type != VIR_DOMAIN_CHR_TYPE_PTY) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("character device %s is not using a PTY"), ++ NULLSTR(chr->info.alias)); ++ goto cleanup; ++ } ++ ++ ret = virChrdevOpen(priv->devs, chr->source, st, ++ (flags & VIR_DOMAIN_CONSOLE_FORCE) != 0); ++ ++ if (ret == 1) { ++ virReportError(VIR_ERR_OPERATION_FAILED, "%s", ++ _("Active console session exists for this domain")); ++ ret = -1; ++ } ++ ++cleanup: ++ virDomainObjEndAPI(&vm); ++ return ret; ++} ++ ++static int stratovirtDomainGetState(virDomainPtr dom, ++ int *state, ++ int *reason, ++ unsigned int flags) ++{ ++ virDomainObjPtr vm; ++ int ret = -1; ++ ++ virCheckFlags(0, -1); ++ ++ if (!(vm = stratovirtDomainObjFromDomain(dom))) ++ goto cleanup; ++ ++ if (virDomainGetStateEnsureACL(dom->conn, vm->def) < 0) ++ goto cleanup; ++ ++ *state = virDomainObjGetState(vm, reason); ++ ret = 0; ++ ++cleanup: ++ virDomainObjEndAPI(&vm); ++ return ret; ++} ++ + static virDomainPtr stratovirtDomainLookupByID(virConnectPtr conn, + int id) + { +@@ -785,11 +976,15 @@ static virHypervisorDriver stratovirtHypervisorDriver = { + .connectListAllDomains = stratovirtConnectListAllDomains, /* 2.2.0 */ + .connectGetCapabilities = stratovirtConnectGetCapabilities, /* 2.2.0 */ + .domainCreateXML = stratovirtDomainCreateXML, /* 2.2.0 */ ++ .domainSuspend =stratovirtDomainSuspend, /* 2.2.0 */ ++ .domainResume = stratovirtDomainResume, /* 2.2.0 */ ++ .domainGetState = stratovirtDomainGetState, /* 2.2.0 */ + .domainLookupByID = stratovirtDomainLookupByID, /* 2.2.0 */ + .domainLookupByUUID = stratovirtDomainLookupByUUID, /* 2.2.0 */ + .domainLookupByName = stratovirtDomainLookupByName, /* 2.2.0 */ + .domainDestroy = stratovirtDomainDestroy, /* 2.2.0 */ + .domainDestroyFlags = stratovirtDomainDestroyFlags, /* 2.2.0 */ ++ .domainOpenConsole = stratovirtDomainOpenConsole, /* 2.2.0 */ + }; + + static virConnectDriver stratovirtConnectDriver = { +diff --git a/src/stratovirt/stratovirt_process.c b/src/stratovirt/stratovirt_process.c +index a292b3b027..9eb2291cc0 100644 +--- a/src/stratovirt/stratovirt_process.c ++++ b/src/stratovirt/stratovirt_process.c +@@ -35,4 +35,6 @@ virStratoVirtProcess stratovirtPro = { + .stratovirtProcessEndJob = qemuProcessEndJob, + .stratovirtProcessBeginStopJob = qemuProcessBeginStopJob, + .stratovirtProcessStop = qemuProcessStop, +-}; ++ .stratovirtProcessStopCPUs = qemuProcessStopCPUs, ++ .stratovirtProcessStartCPUs = qemuProcessStartCPUs, ++}; +\ No newline at end of file +diff --git a/src/stratovirt/stratovirt_process.h b/src/stratovirt/stratovirt_process.h +index f0676f0480..d429e4a598 100644 +--- a/src/stratovirt/stratovirt_process.h ++++ b/src/stratovirt/stratovirt_process.h +@@ -56,6 +56,14 @@ typedef struct StratoVirtProcess { + virDomainShutoffReason reason, + stratovirtDomainAsyncJob asyncjob, + unsigned int flags); ++ int (*stratovirtProcessStopCPUs)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm, ++ virDomainPausedReason reason, ++ stratovirtDomainAsyncJob asyncJob); ++ int (*stratovirtProcessStartCPUs)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm, ++ virDomainRunningReason reason, ++ stratovirtDomainAsyncJob asyncJob); + } virStratoVirtProcess; + + extern virStratoVirtProcess stratovirtPro; +-- +2.25.1 + diff --git a/Add-the-function-of-create-and-destroy-domains-by-st.patch b/Add-the-function-of-create-and-destroy-domains-by-st.patch new file mode 100644 index 0000000000000000000000000000000000000000..0bf4c114b32e074852aae2105018b2edf706a0f2 --- /dev/null +++ b/Add-the-function-of-create-and-destroy-domains-by-st.patch @@ -0,0 +1,379 @@ +From 56ce5315182d09270d3461fe7eaaa5b697aff9c8 Mon Sep 17 00:00:00 2001 +From: mayunlong +Date: Fri, 12 Aug 2022 20:24:18 +0800 +Subject: [PATCH 2/3] Add the function of create and destroy domains by + stratovirt_driver. + +--- + src/stratovirt/stratovirt_domain.c | 20 +++ + src/stratovirt/stratovirt_domain.h | 9 ++ + src/stratovirt/stratovirt_driver.c | 228 ++++++++++++++++++++++++++++ + src/stratovirt/stratovirt_process.c | 5 + + src/stratovirt/stratovirt_process.h | 29 ++++ + 5 files changed, 291 insertions(+) + +diff --git a/src/stratovirt/stratovirt_domain.c b/src/stratovirt/stratovirt_domain.c +index 4ebe71a03b..4efc987509 100644 +--- a/src/stratovirt/stratovirt_domain.c ++++ b/src/stratovirt/stratovirt_domain.c +@@ -138,6 +138,26 @@ void stratovirtProcessEventFree(stratovirtProcessEventPtr event) + VIR_FREE(event); + } + ++virDomainObjPtr stratovirtDomainObjFromDomain(virDomainPtr domain) ++{ ++ virDomainObjPtr vm; ++ virStratoVirtDriverPtr driver = domain->conn->privateData; ++ char uuidstr[VIR_UUID_STRING_BUFLEN]; ++ ++ vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); ++ if (!vm) { ++ virUUIDFormat(domain->uuid, uuidstr); ++ virReportError(VIR_ERR_NO_DOMAIN, ++ _("no domain with matching uuid '%s' (%s)"), ++ uuidstr, domain->name); ++ return NULL; ++ } ++ ++ return vm; ++} ++ + virStratoVirtDomain stratovirtDom = { + .stratovirtDomainNamespaceAvailable = qemuDomainNamespaceAvailable, ++ .stratovirtDomainRemoveInactive = qemuDomainRemoveInactive, ++ .stratovirtDomainObjEndJob = qemuDomainObjEndJob, + }; +diff --git a/src/stratovirt/stratovirt_domain.h b/src/stratovirt/stratovirt_domain.h +index 801c697414..da653eb13a 100644 +--- a/src/stratovirt/stratovirt_domain.h ++++ b/src/stratovirt/stratovirt_domain.h +@@ -58,8 +58,17 @@ struct _stratovirtProcessEvent { + + extern virDomainDefParserConfig virStratoVirtDriverDomainDefParserConfig; + ++typedef qemuDomainObjPrivate stratovirtDomainObjPrivate; ++typedef stratovirtDomainObjPrivate *stratovirtDomainObjPrivatePtr; ++ ++virDomainObjPtr stratovirtDomainObjFromDomain(virDomainPtr domain); ++ + typedef struct StratoVirtDomain { + bool (*stratovirtDomainNamespaceAvailable)(stratovirtDomainNamespace ns G_GNUC_UNUSED); ++ void (*stratovirtDomainRemoveInactive)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm); ++ void (*stratovirtDomainObjEndJob)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr obj); + } virStratoVirtDomain; + + extern virStratoVirtDomain stratovirtDom; +diff --git a/src/stratovirt/stratovirt_driver.c b/src/stratovirt/stratovirt_driver.c +index f7ca80f0af..ac00c35349 100644 +--- a/src/stratovirt/stratovirt_driver.c ++++ b/src/stratovirt/stratovirt_driver.c +@@ -44,6 +44,13 @@ + + VIR_LOG_INIT("stratovirt.stratovirt_driver"); + ++#define STRATOVIRT_ASYNC_JOB_NONE 0 ++#define STRATOVIRT_ASYNC_JOB_MIGRATION_IN 2 ++#define STRATOVIRT_ASYNC_JOB_START 6 ++#define STRATOVIRT_JOB_DESTROY 2 ++#define VIR_STRATOVIRT_PROCESS_START_COLD 1 ++#define VIR_STRATOVIRT_PROCESS_STOP_MIGRATED 1 ++ + static virStratoVirtDriverPtr stratovirt_driver; + + static int +@@ -219,6 +226,221 @@ static char *stratovirtConnectGetCapabilities(virConnectPtr conn) + return xml; + } + ++/** ++ * stratovirtDomainCreateXML: ++ * @conn: pointer to connection ++ * @xml: XML definition of domain ++ * @flags: bitwise-OR of supported virDomainCreateFlags ++ * ++ * Creates a domain based on xml and starts it ++ * ++ * Returns a new domain object or NULL in case of failure. ++ */ ++static virDomainPtr stratovirtDomainCreateXML(virConnectPtr conn, ++ const char *xml, ++ unsigned int flags) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ virDomainDefPtr def = NULL; ++ virDomainObjPtr vm = NULL; ++ virDomainPtr dom = NULL; ++ unsigned int start_flags = VIR_STRATOVIRT_PROCESS_START_COLD; ++ unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | ++ VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; ++ ++ virCheckFlags(VIR_DOMAIN_START_PAUSED | ++ VIR_DOMAIN_START_AUTODESTROY | ++ VIR_DOMAIN_START_VALIDATE, NULL); ++ ++ if (flags & VIR_DOMAIN_START_VALIDATE) ++ parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; ++ ++ if (!(def = virDomainDefParseString(xml, driver->xmlopt, ++ NULL, parse_flags))) ++ goto cleanup; ++ ++ if (virDomainCreateXMLEnsureACL(conn, def) < 0) ++ goto cleanup; ++ ++ if (!(vm = virDomainObjListAdd(driver->domains, def, ++ driver->xmlopt, ++ VIR_DOMAIN_OBJ_LIST_ADD_LIVE | ++ VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, ++ NULL))) ++ goto cleanup; ++ def = NULL; ++ ++ if (stratovirtPro.stratovirtProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START, ++ flags) < 0){ ++ goto cleanup; ++ } ++ ++ if (stratovirtPro.stratovirtProcessStart(conn, driver, vm, NULL, STRATOVIRT_ASYNC_JOB_START, ++ NULL, -1, NULL, NULL, ++ VIR_NETDEV_VPORT_PROFILE_OP_CREATE, ++ start_flags) < 0) { ++ virDomainAuditStart(vm, "booted", false); ++ stratovirtDom.stratovirtDomainRemoveInactive(driver, vm); ++ stratovirtPro.stratovirtProcessEndJob(driver, vm); ++ goto cleanup; ++ } ++ ++ virDomainAuditStart(vm, "booted", true); ++ dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); ++ stratovirtPro.stratovirtProcessEndJob(driver, vm); ++ ++ cleanup: ++ virDomainDefFree(def); ++ virDomainObjEndAPI(&vm); ++ return dom; ++} ++ ++static int ++stratovirtDomainDestroyFlags(virDomainPtr dom, ++ unsigned int flags) ++{ ++ virStratoVirtDriverPtr driver = dom->conn->privateData; ++ virDomainObjPtr vm; ++ int ret = -1; ++ stratovirtDomainObjPrivatePtr priv; ++ unsigned int stopFlags = 0; ++ int state; ++ int reason; ++ bool starting; ++ ++ virCheckFlags(VIR_DOMAIN_DESTROY_GRACEFUL, -1); ++ ++ if (!(vm = stratovirtDomainObjFromDomain(dom))) ++ return -1; ++ ++ priv = vm->privateData; ++ ++ if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0) ++ goto cleanup; ++ ++ if (virDomainObjCheckActive(vm) < 0) ++ goto cleanup; ++ ++ state = virDomainObjGetState(vm, &reason); ++ starting = (state == VIR_DOMAIN_PAUSED && ++ reason == VIR_DOMAIN_PAUSED_STARTING_UP && ++ !priv->beingDestroyed); ++ ++ if (stratovirtPro.stratovirtProcessBeginStopJob(driver, vm, STRATOVIRT_JOB_DESTROY, ++ !(flags & VIR_DOMAIN_DESTROY_GRACEFUL)) < 0) ++ goto cleanup; ++ ++ if (!virDomainObjIsActive(vm)) { ++ if (starting) { ++ VIR_DEBUG("Domain %s is not running anymore", vm->def->name); ++ ret = 0; ++ } else { ++ virReportError(VIR_ERR_OPERATION_INVALID, ++ "%s", _("domain is not running")); ++ } ++ goto endjob; ++ } ++ ++ if (priv->job.asyncJob == STRATOVIRT_ASYNC_JOB_MIGRATION_IN) ++ stopFlags |= VIR_STRATOVIRT_PROCESS_STOP_MIGRATED; ++ ++ stratovirtPro.stratovirtProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED, ++ STRATOVIRT_ASYNC_JOB_NONE, stopFlags); ++ virDomainAuditStop(vm, "destroyed"); ++ ++ ret = 0; ++ endjob: ++ if (ret == 0) ++ stratovirtDom.stratovirtDomainRemoveInactive(driver, vm); ++ stratovirtDom.stratovirtDomainObjEndJob(driver, vm); ++ ++ cleanup: ++ virDomainObjEndAPI(&vm); ++ return ret; ++} ++ ++static int stratovirtDomainDestroy(virDomainPtr dom) ++{ ++ return stratovirtDomainDestroyFlags(dom, 0); ++} ++ ++static virDomainPtr stratovirtDomainLookupByID(virConnectPtr conn, ++ int id) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ virDomainObjPtr vm; ++ virDomainPtr dom = NULL; ++ ++ vm = virDomainObjListFindByID(driver->domains, id); ++ ++ if (!vm) { ++ virReportError(VIR_ERR_NO_DOMAIN, ++ _("no domain with matching id %d"), id); ++ goto cleanup; ++ } ++ ++ if (virDomainLookupByIDEnsureACL(conn, vm->def) < 0) ++ goto cleanup; ++ ++ dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); ++ ++ cleanup: ++ virDomainObjEndAPI(&vm); ++ return dom; ++} ++ ++static virDomainPtr stratovirtDomainLookupByUUID(virConnectPtr conn, ++ const unsigned char *uuid) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ virDomainObjPtr vm; ++ virDomainPtr dom = NULL; ++ ++ vm = virDomainObjListFindByUUID(driver->domains, uuid); ++ ++ if (!vm) { ++ char uuidstr[VIR_UUID_STRING_BUFLEN]; ++ virUUIDFormat(uuid, uuidstr); ++ virReportError(VIR_ERR_NO_DOMAIN, ++ _("no domain with matching uuid '%s'"), uuidstr); ++ goto cleanup; ++ } ++ ++ if (virDomainLookupByUUIDEnsureACL(conn, vm->def) < 0) ++ goto cleanup; ++ ++ dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); ++ ++ cleanup: ++ virDomainObjEndAPI(&vm); ++ return dom; ++} ++ ++static virDomainPtr stratovirtDomainLookupByName(virConnectPtr conn, ++ const char *name) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ virDomainObjPtr vm; ++ virDomainPtr dom = NULL; ++ ++ vm = virDomainObjListFindByName(driver->domains, name); ++ ++ if (!vm) { ++ virReportError(VIR_ERR_NO_DOMAIN, ++ _("no domain with matching name '%s'"), name); ++ goto cleanup; ++ } ++ ++ if (virDomainLookupByNameEnsureACL(conn, vm->def) < 0) ++ goto cleanup; ++ ++ dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); ++ ++ cleanup: ++ virDomainObjEndAPI(&vm); ++ return dom; ++} ++ + static int stratovirtSecurityInit(virStratoVirtDriverPtr driver) + { + char **names; +@@ -562,6 +784,12 @@ static virHypervisorDriver stratovirtHypervisorDriver = { + .connectNumOfDomains = stratovirtConnectNumOfDomains, /* 2.2.0 */ + .connectListAllDomains = stratovirtConnectListAllDomains, /* 2.2.0 */ + .connectGetCapabilities = stratovirtConnectGetCapabilities, /* 2.2.0 */ ++ .domainCreateXML = stratovirtDomainCreateXML, /* 2.2.0 */ ++ .domainLookupByID = stratovirtDomainLookupByID, /* 2.2.0 */ ++ .domainLookupByUUID = stratovirtDomainLookupByUUID, /* 2.2.0 */ ++ .domainLookupByName = stratovirtDomainLookupByName, /* 2.2.0 */ ++ .domainDestroy = stratovirtDomainDestroy, /* 2.2.0 */ ++ .domainDestroyFlags = stratovirtDomainDestroyFlags, /* 2.2.0 */ + }; + + static virConnectDriver stratovirtConnectDriver = { +diff --git a/src/stratovirt/stratovirt_process.c b/src/stratovirt/stratovirt_process.c +index 8a67c5a31b..a292b3b027 100644 +--- a/src/stratovirt/stratovirt_process.c ++++ b/src/stratovirt/stratovirt_process.c +@@ -30,4 +30,9 @@ VIR_LOG_INIT("stratovirt.stratovirt_process"); + + virStratoVirtProcess stratovirtPro = { + .stratovirtProcessReconnectAll = qemuProcessReconnectAll, ++ .stratovirtProcessBeginJob = qemuProcessBeginJob, ++ .stratovirtProcessStart = qemuProcessStart, ++ .stratovirtProcessEndJob = qemuProcessEndJob, ++ .stratovirtProcessBeginStopJob = qemuProcessBeginStopJob, ++ .stratovirtProcessStop = qemuProcessStop, + }; +diff --git a/src/stratovirt/stratovirt_process.h b/src/stratovirt/stratovirt_process.h +index 942dd34330..f0676f0480 100644 +--- a/src/stratovirt/stratovirt_process.h ++++ b/src/stratovirt/stratovirt_process.h +@@ -25,8 +25,37 @@ + #include "stratovirt_domain.h" + #include "qemu_process.h" + ++typedef qemuDomainAsyncJob stratovirtDomainAsyncJob; ++typedef qemuDomainJob stratovirtDomainJob; ++ + typedef struct StratoVirtProcess { + void (*stratovirtProcessReconnectAll)(virStratoVirtDriverPtr driver); ++ int (*stratovirtProcessBeginJob)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm, ++ virDomainJobOperation operation, ++ unsigned long apiFlags); ++ int (*stratovirtProcessStart)(virConnectPtr conn, ++ virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm, ++ virCPUDefPtr updatedCPU, ++ stratovirtDomainAsyncJob asyncJob, ++ const char *migrateFrom, ++ int migrateFd, ++ const char *migratePath, ++ virDomainMomentObjPtr snapshot, ++ virNetDevVPortProfileOp vmop, ++ unsigned int flags); ++ void (*stratovirtProcessEndJob)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm); ++ int (*stratovirtProcessBeginStopJob)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm, ++ stratovirtDomainJob job, ++ bool forcekill); ++ void (*stratovirtProcessStop)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm, ++ virDomainShutoffReason reason, ++ stratovirtDomainAsyncJob asyncjob, ++ unsigned int flags); + } virStratoVirtProcess; + + extern virStratoVirtProcess stratovirtPro; +-- +2.25.1 + diff --git a/libvirt.spec b/libvirt.spec index 84334570a00243f51fb40e638a343bd5b8600778..6ce883bc3798f7265eef95d293a135a832dd580e 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -10,6 +10,7 @@ %define with_lxc 0%{!?_without_lxc:0} %define with_libxl 0%{!?_without_libxl:0} %define with_vbox 0%{!?_without_vbox:0} +%define with_stratovirt 0%{!?_without_stratovirt:1} %define with_qemu_tcg %{with_qemu} @@ -101,7 +102,7 @@ Summary: Library providing a simple virtualization API Name: libvirt Version: 6.2.0 -Release: 41 +Release: 42 License: LGPLv2+ URL: https://libvirt.org/ @@ -251,6 +252,9 @@ Patch0138: sw_64-Add-sw64-architecture-support.patch Patch0139: src-workaround-warning-triggered-in-glib-2.69.patch Patch0140: nwfilter-fix-crash-when-counting-number-of-network-f.patch Patch0141: apibuild-Fix-self.waring-method-call.patch +Patch0142: Add-and-initialize-the-stratovirt-driver.patch +Patch0143: Add-the-function-of-create-and-destroy-domains-by-st.patch +Patch0144: Add-command-virsh-list-virsh-suspend-virsh-resume-an.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -264,6 +268,9 @@ Requires: libvirt-daemon-driver-lxc = %{version}-%{release} %if %{with_qemu} Requires: libvirt-daemon-driver-qemu = %{version}-%{release} %endif +%if %{with_stratovirt} +Requires: libvirt-daemon-driver-stratovirt = %{version}-%{release} +%endif # We had UML driver, but we've removed it. Obsoletes: libvirt-daemon-driver-uml <= 5.0.0 Obsoletes: libvirt-daemon-uml <= 5.0.0 @@ -749,6 +756,19 @@ an implementation of the hypervisor driver APIs using QEMU %endif +%if %{with_stratovirt} +%package daemon-driver-stratovirt +Summary: StratoVirt driver plugin for the libvirtd daemon +Requires: libvirt-daemon = %{version}-%{release} +Requires: libvirt-libs = %{version}-%{release} +Requires: stratovirt +Requires: systemd-container + +%description daemon-driver-stratovirt +The stratovirt driver plugin for the libvirtd daemon, providing +an implementation of the hypervisor driver APIs using +StratoVirt +%endif %if %{with_lxc} %package daemon-driver-lxc @@ -1001,6 +1021,12 @@ Libvirt plugin for NSS for translating domain names into IP addresses. %define arg_qemu --without-qemu %endif +%if %{with_stratovirt} + %define arg_stratovirt --with-stratovirt +%else + %define arg_stratovirt --without-stratovirt +%endif + %if %{with_openvz} %define arg_openvz --with-openvz %else @@ -1164,6 +1190,7 @@ cd %{_vpath_builddir} %{?arg_lxc} \ %{?arg_vbox} \ %{?arg_libxl} \ + %{?arg_stratovirt} \ --with-sasl \ --with-polkit \ --with-libvirtd \ @@ -1761,6 +1788,11 @@ exit 0 %{_mandir}/man1/virt-qemu-run.1* %endif +%if %{with_stratovirt} +%files daemon-driver-stratovirt +%{_libdir}/%{name}/connection-driver/libvirt_driver_stratovirt.so +%endif + %if %{with_lxc} %files daemon-driver-lxc %config(noreplace) %{_sysconfdir}/libvirt/virtlxcd.conf @@ -1985,6 +2017,9 @@ exit 0 %changelog +* Sat Aug 20 2022 mayunlong - 6.2.0-42 +- add stratovirt driver + * Thu Aug 11 2022 yezengruan - 6.2.0-41 - apibuild: Fix self.waring method call