From 66b28b642ff1de9cb50b6a63737b762352e7f10e Mon Sep 17 00:00:00 2001 From: mayunlong Date: Mon, 29 Aug 2022 15:14:19 +0800 Subject: [PATCH] Add command define/undefine/start/shutdown in stratovirt_driver. bugfix:fix command create flags/undefine flags/capinit. --- ...ne-undefine-start-shutdown-in-strato.patch | 485 ++++++++++++++++++ ...nd-create-flags-undefine-flags-capsi.patch | 235 +++++++++ libvirt.spec | 8 +- 3 files changed, 727 insertions(+), 1 deletion(-) create mode 100644 Add-command-define-undefine-start-shutdown-in-strato.patch create mode 100644 bugfix-fix-command-create-flags-undefine-flags-capsi.patch diff --git a/Add-command-define-undefine-start-shutdown-in-strato.patch b/Add-command-define-undefine-start-shutdown-in-strato.patch new file mode 100644 index 0000000..7b2c554 --- /dev/null +++ b/Add-command-define-undefine-start-shutdown-in-strato.patch @@ -0,0 +1,485 @@ +From d96d44be81e182bcc197717d16a09a78d9f1d6bb Mon Sep 17 00:00:00 2001 +From: mayunlong +Date: Fri, 26 Aug 2022 17:44:21 +0800 +Subject: [PATCH 1/2] Add command define/undefine/start/shutdown in + stratovirt_driver. + +--- + po/POTFILES.in | 1 + + src/stratovirt/Makefile.inc.am | 2 + + src/stratovirt/stratovirt_domain.c | 4 + + src/stratovirt/stratovirt_domain.h | 8 + + src/stratovirt/stratovirt_driver.c | 286 ++++++++++++++++++++++++++++ + src/stratovirt/stratovirt_monitor.c | 32 ++++ + src/stratovirt/stratovirt_monitor.h | 36 ++++ + 7 files changed, 369 insertions(+) + create mode 100644 src/stratovirt/stratovirt_monitor.c + create mode 100644 src/stratovirt/stratovirt_monitor.h + +diff --git a/po/POTFILES.in b/po/POTFILES.in +index 8217d82db9..3ef42afbe7 100644 +--- a/po/POTFILES.in ++++ b/po/POTFILES.in +@@ -177,6 +177,7 @@ + @SRCDIR@/src/stratovirt/stratovirt_conf.c + @SRCDIR@/src/stratovirt/stratovirt_domain.c + @SRCDIR@/src/stratovirt/stratovirt_process.c ++@SRCDIR@/src/stratovirt/stratovirt_monitor.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/stratovirt/Makefile.inc.am b/src/stratovirt/Makefile.inc.am +index 4d3fb259a4..94990b1913 100644 +--- a/src/stratovirt/Makefile.inc.am ++++ b/src/stratovirt/Makefile.inc.am +@@ -9,6 +9,8 @@ STRATOVIRT_DRIVER_SOURCES = \ + stratovirt/stratovirt_domain.h \ + stratovirt/stratovirt_process.h \ + stratovirt/stratovirt_process.c \ ++ stratovirt/stratovirt_monitor.c \ ++ stratovirt/stratovirt_monitor.h \ + $(NULL) + + DRIVER_SOURCE_FILES += $(addprefix $(srcdir)/,$(STRATOVIRT_DRIVER_SOURCES)) +diff --git a/src/stratovirt/stratovirt_domain.c b/src/stratovirt/stratovirt_domain.c +index 4ed9250d1e..b894282ce2 100644 +--- a/src/stratovirt/stratovirt_domain.c ++++ b/src/stratovirt/stratovirt_domain.c +@@ -173,4 +173,8 @@ virStratoVirtDomain stratovirtDom = { + .stratovirtDomainRemoveInactive = qemuDomainRemoveInactive, + .stratovirtDomainObjEndJob = qemuDomainObjEndJob, + .stratovirtDomainObjBeginJob = qemuDomainObjBeginJob, ++ .stratovirtDomainObjEnterMonitor = qemuDomainObjEnterMonitor, ++ .stratovirtDomainObjExitMonitor = qemuDomainObjExitMonitor, ++ .stratovirtDomainSnapshotDiscardAllMetadata = qemuDomainSnapshotDiscardAllMetadata, ++ .stratovirtDomainCheckpointDiscardAllMetadata = qemuCheckpointDiscardAllMetadata, + }; +diff --git a/src/stratovirt/stratovirt_domain.h b/src/stratovirt/stratovirt_domain.h +index 405d55d547..a6abd84420 100644 +--- a/src/stratovirt/stratovirt_domain.h ++++ b/src/stratovirt/stratovirt_domain.h +@@ -74,6 +74,14 @@ typedef struct StratoVirtDomain { + int (*stratovirtDomainObjBeginJob)(virStratoVirtDriverPtr driver, + virDomainObjPtr obj, + stratovirtDomainJob job); ++ void (*stratovirtDomainObjEnterMonitor)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr obj); ++ int (*stratovirtDomainObjExitMonitor)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr obj); ++ int (*stratovirtDomainSnapshotDiscardAllMetadata)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm); ++ int (*stratovirtDomainCheckpointDiscardAllMetadata)(virStratoVirtDriverPtr driver, ++ virDomainObjPtr vm); + } virStratoVirtDomain; + + extern virStratoVirtDomain stratovirtDom; +diff --git a/src/stratovirt/stratovirt_driver.c b/src/stratovirt/stratovirt_driver.c +index abd99bc8ea..d4ba00dac7 100644 +--- a/src/stratovirt/stratovirt_driver.c ++++ b/src/stratovirt/stratovirt_driver.c +@@ -26,6 +26,7 @@ + #include "stratovirt_conf.h" + #include "stratovirt_domain.h" + #include "stratovirt_process.h" ++#include "stratovirt_monitor.h" + + #include "virerror.h" + #include "virlog.h" +@@ -53,6 +54,8 @@ VIR_LOG_INIT("stratovirt.stratovirt_driver"); + #define STRATOVIRT_JOB_SUSPEND 3 + #define STRATOVIRT_JOB_MODIFY 4 + #define VIR_STRATOVIRT_PROCESS_START_COLD 1 ++#define VIR_STRATOVIRT_PROCESS_START_PAUSED 2 ++#define VIR_STRATOVIRT_PROCESS_START_AUTODESTROY 4 + #define VIR_STRATOVIRT_PROCESS_STOP_MIGRATED 1 + + static virStratoVirtDriverPtr stratovirt_driver; +@@ -407,6 +410,273 @@ static int stratovirtDomainResume(virDomainPtr dom) + return ret; + } + ++ ++static int stratovirtDomainShutdownFlags(virDomainPtr dom, ++ unsigned int flags) ++{ ++ virStratoVirtDriverPtr driver = dom->conn->privateData; ++ virDomainObjPtr vm; ++ stratovirtDomainObjPrivatePtr priv; ++ int ret = -1; ++ ++ virCheckFlags(VIR_DOMAIN_SHUTDOWN_DEFAULT, -1); ++ ++ if (!(vm = stratovirtDomainObjFromDomain(dom))) ++ goto cleanup; ++ ++ priv = vm->privateData; ++ ++ if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0) ++ goto cleanup; ++ ++ if (stratovirtDom.stratovirtDomainObjBeginJob(driver, vm, STRATOVIRT_JOB_MODIFY) < 0) ++ goto cleanup; ++ ++ if (virDomainObjCheckActive(vm) < 0) ++ goto endjob; ++ ++ if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING && ++ virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) { ++ virReportError(VIR_ERR_OPERATION_INVALID, "%s", ++ _("only can shutdown running/paused domain")); ++ goto endjob; ++ } ++ ++ stratovirtDom.stratovirtDomainObjEnterMonitor(driver, vm); ++ ret = stratovirtMon.stratovirtMonitorSystemPowerdown(priv->mon); ++ if (stratovirtDom.stratovirtDomainObjExitMonitor(driver, vm) < 0) ++ ret = -1; ++ ++endjob: ++ stratovirtDom.stratovirtDomainObjEndJob(driver, vm); ++ ++cleanup: ++ virDomainObjEndAPI(&vm); ++ return ret; ++} ++ ++static int stratovirtDomainShutdown(virDomainPtr dom) ++{ ++ return stratovirtDomainShutdownFlags(dom, 0); ++} ++ ++static virDomainPtr ++stratovirtDomainDefineXMLFlags(virConnectPtr conn, ++ const char *xml, ++ unsigned int flags) ++{ ++ virStratoVirtDriverPtr driver = conn->privateData; ++ virDomainDefPtr def = NULL; ++ virDomainDefPtr oldDef = NULL; ++ virDomainObjPtr vm = NULL; ++ virDomainPtr dom = NULL; ++ g_autoptr(virStratoVirtDriverConfig) cfg = virStratoVirtDriverGetConfig(driver); ++ unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | ++ VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; ++ ++ virCheckFlags(VIR_DOMAIN_DEFINE_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 (virXMLCheckIllegalChars("names", def->name, "\n") < 0) ++ goto cleanup; ++ ++ if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) ++ goto cleanup; ++ ++ if (!(vm = virDomainObjListAdd(driver->domains, def, ++ driver->xmlopt, ++ 0, &oldDef))) ++ goto cleanup; ++ def = NULL; ++ ++ vm->persistent = 1; ++ ++ if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, ++ driver->xmlopt, cfg->configDir) < 0) { ++ if (oldDef) { ++ /* restore the old backup */ ++ if (virDomainObjIsActive(vm)) ++ vm->newDef = oldDef; ++ else ++ vm->def = oldDef; ++ oldDef = NULL; ++ } else { ++ vm->persistent = 0; ++ stratovirtDom.stratovirtDomainRemoveInactive(driver, vm); ++ } ++ goto cleanup; ++ } ++ ++ dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); ++ ++cleanup: ++ virDomainDefFree(def); ++ virDomainDefFree(oldDef); ++ virDomainObjEndAPI(&vm); ++ return dom; ++} ++ ++static virDomainPtr ++stratovirtDomainDefineXML(virConnectPtr conn, ++ const char *xml) ++{ ++ return stratovirtDomainDefineXMLFlags(conn, xml, 0); ++} ++ ++static int stratovirtDomainCreateWithFlags(virDomainPtr dom, ++ unsigned int flags) ++{ ++ virStratoVirtDriverPtr driver = dom->conn->privateData; ++ virDomainObjPtr vm; ++ unsigned int start_flags = VIR_STRATOVIRT_PROCESS_START_COLD; ++ int ret = -1; ++ ++ virCheckFlags(VIR_DOMAIN_START_PAUSED | ++ VIR_DOMAIN_START_AUTODESTROY, -1); ++ ++ if (flags & VIR_DOMAIN_START_PAUSED) ++ start_flags |= VIR_STRATOVIRT_PROCESS_START_PAUSED; ++ if (flags & VIR_DOMAIN_START_AUTODESTROY) ++ start_flags |= VIR_STRATOVIRT_PROCESS_START_AUTODESTROY; ++ ++ if (!(vm = stratovirtDomainObjFromDomain(dom))) ++ goto cleanup; ++ ++ if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0) ++ goto cleanup; ++ ++ if (stratovirtPro.stratovirtProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START, ++ flags) < 0) ++ goto cleanup; ++ ++ if (virDomainObjIsActive(vm)) { ++ virReportError(VIR_ERR_OPERATION_INVALID, "%s", ++ _("domain is already running")); ++ goto endjob; ++ } ++ ++ if (stratovirtPro.stratovirtProcessStart(dom->conn, driver, vm, NULL, ++ STRATOVIRT_ASYNC_JOB_START, ++ NULL, -1, NULL, NULL, ++ VIR_NETDEV_VPORT_PROFILE_OP_CREATE, start_flags) < 0) ++ goto endjob; ++ ++ dom->id = vm->def->id; ++ ret = 0; ++ ++endjob: ++ stratovirtPro.stratovirtProcessEndJob(driver, vm); ++ ++cleanup: ++ virDomainObjEndAPI(&vm); ++ return ret; ++} ++ ++static int stratovirtDomainCreate(virDomainPtr dom) ++{ ++ return stratovirtDomainCreateWithFlags(dom, 0); ++} ++ ++static int stratovirtDomainIsActive(virDomainPtr dom) ++{ ++ virDomainObjPtr obj; ++ int ret = -1; ++ ++ if (!(obj = stratovirtDomainObjFromDomain(dom))) ++ goto cleanup; ++ ++ if (virDomainIsActiveEnsureACL(dom->conn, obj->def) < 0) ++ goto cleanup; ++ ++ ret = virDomainObjIsActive(obj); ++ ++ cleanup: ++ virDomainObjEndAPI(&obj); ++ return ret; ++} ++ ++static int ++stratovirtDomainUndefineFlags(virDomainPtr dom, ++ unsigned int flags) ++{ ++ virStratoVirtDriverPtr driver = dom->conn->privateData; ++ virDomainObjPtr vm; ++ int ret = -1; ++ int nsnapshots; ++ int ncheckpoints; ++ g_autoptr(virStratoVirtDriverConfig) cfg = virStratoVirtDriverGetConfig(driver); ++ ++ virCheckFlags(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA | ++ VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA ,-1); ++ ++ if (!(vm = stratovirtDomainObjFromDomain(dom))) ++ goto cleanup; ++ ++ if (virDomainUndefineFlagsEnsureACL(dom->conn, vm->def) < 0) ++ goto cleanup; ++ ++ if (!vm->persistent) { ++ virReportError(VIR_ERR_OPERATION_INVALID, "%s", ++ _("Cannot undefine transient domain")); ++ goto cleanup; ++ } ++ ++ if (stratovirtDom.stratovirtDomainObjBeginJob(driver, vm, STRATOVIRT_JOB_MODIFY) < 0) ++ goto cleanup; ++ ++ if (!virDomainObjIsActive(vm) && ++ (nsnapshots = virDomainSnapshotObjListNum(vm->snapshots, NULL, 0))) { ++ if (!(flags & VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)) { ++ virReportError(VIR_ERR_OPERATION_INVALID, ++ _("cannot delete inactive domain with %d snapshots"), ++ nsnapshots); ++ goto endjob; ++ } ++ if (stratovirtDom.stratovirtDomainSnapshotDiscardAllMetadata(driver, vm) < 0) ++ goto endjob; ++ } ++ ++ if (!virDomainObjIsActive(vm) && ++ (ncheckpoints = virDomainListCheckpoints(vm->checkpoints, NULL, dom, ++ NULL, flags)) > 0) { ++ if (!(flags & VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA)) { ++ virReportError(VIR_ERR_OPERATION_INVALID, ++ _("cannot delete inactive domain with %d checkpoints"), ++ ncheckpoints); ++ goto endjob; ++ } ++ if (stratovirtDom.stratovirtDomainCheckpointDiscardAllMetadata(driver, vm) < 0) ++ goto endjob; ++ } ++ ++ if (virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm) < 0) ++ goto cleanup; ++ ++ vm->persistent = 0; ++ if (!virDomainObjIsActive(vm)) ++ stratovirtDom.stratovirtDomainRemoveInactive(driver, vm); ++ ret = 0; ++ ++endjob: ++ stratovirtDom.stratovirtDomainObjEndJob(driver, vm); ++ ++cleanup: ++ virDomainObjEndAPI(&vm); ++ return ret; ++} ++ ++static int ++stratovirtDomainUndefine(virDomainPtr dom) ++{ ++ return stratovirtDomainUndefineFlags(dom, 0); ++} ++ + static int + stratovirtDomainDestroyFlags(virDomainPtr dom, + unsigned int flags) +@@ -946,6 +1216,13 @@ stratovirtStateInitialize(bool privileged, + NULL, NULL) < 0) + goto error; + ++ if (virDomainObjListLoadAllConfigs(stratovirt_driver->domains, ++ cfg->configDir, ++ cfg->autostartDir, false, ++ stratovirt_driver->xmlopt, ++ NULL, NULL) < 0) ++ goto error; ++ + stratovirt_driver->workerPool = virThreadPoolNewFull(0, 1, 0, stratovirtProcessEventHandler, + "stratovirt-event", stratovirt_driver); + if (!stratovirt_driver->workerPool) +@@ -985,6 +1262,15 @@ static virHypervisorDriver stratovirtHypervisorDriver = { + .domainDestroy = stratovirtDomainDestroy, /* 2.2.0 */ + .domainDestroyFlags = stratovirtDomainDestroyFlags, /* 2.2.0 */ + .domainOpenConsole = stratovirtDomainOpenConsole, /* 2.2.0 */ ++ .domainShutdown = stratovirtDomainShutdown, /* 2.2.0 */ ++ .domainShutdownFlags = stratovirtDomainShutdownFlags, /* 2.2.0 */ ++ .domainCreate = stratovirtDomainCreate, /* 2.2.0 */ ++ .domainCreateWithFlags = stratovirtDomainCreateWithFlags, /* 2.2.0 */ ++ .domainDefineXML = stratovirtDomainDefineXML, /* 2.2.0 */ ++ .domainDefineXMLFlags = stratovirtDomainDefineXMLFlags, /* 2.2.0 */ ++ .domainUndefine = stratovirtDomainUndefine, /* 2.2.0 */ ++ .domainUndefineFlags = stratovirtDomainUndefineFlags, /* 2.2.0 */ ++ .domainIsActive = stratovirtDomainIsActive, /* 2.2.0 */ + }; + + static virConnectDriver stratovirtConnectDriver = { +diff --git a/src/stratovirt/stratovirt_monitor.c b/src/stratovirt/stratovirt_monitor.c +new file mode 100644 +index 0000000000..1e828c3ac2 +--- /dev/null ++++ b/src/stratovirt/stratovirt_monitor.c +@@ -0,0 +1,32 @@ ++/* ++ * huawei_stratovirt_monitor.c: huawei stratovirt monitor functions ++ * interaction with stratovirt monitor console. ++ * ++ * 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_monitor.h" ++#include "virlog.h" ++ ++VIR_LOG_INIT("stratovirt.stratovirt_monitor"); ++ ++virStratoVirtMonitor stratovirtMon = { ++ .stratovirtMonitorSystemPowerdown = qemuMonitorSystemPowerdown, ++}; +\ No newline at end of file +diff --git a/src/stratovirt/stratovirt_monitor.h b/src/stratovirt/stratovirt_monitor.h +new file mode 100644 +index 0000000000..0d7580c348 +--- /dev/null ++++ b/src/stratovirt/stratovirt_monitor.h +@@ -0,0 +1,36 @@ ++/* ++ * huawei_stratovirt_monitor.h: huawei stratovirt monitor functions ++ * interaction with stratovirt monitor console. ++ * ++ * 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 "internal.h" ++ ++#include "qemu_monitor.h" ++ ++typedef qemuMonitor stratovirtMonitor; ++typedef stratovirtMonitor *stratovirtMonitorPtr; ++ ++typedef struct StratoVirtMonitor { ++ int (*stratovirtMonitorSystemPowerdown)(stratovirtMonitorPtr mon); ++} virStratoVirtMonitor; ++ ++extern virStratoVirtMonitor stratovirtMon; +\ No newline at end of file +-- +2.25.1 + diff --git a/bugfix-fix-command-create-flags-undefine-flags-capsi.patch b/bugfix-fix-command-create-flags-undefine-flags-capsi.patch new file mode 100644 index 0000000..8b19c33 --- /dev/null +++ b/bugfix-fix-command-create-flags-undefine-flags-capsi.patch @@ -0,0 +1,235 @@ +From 143000e4a91e4f7587359734a001fea1e05ddda5 Mon Sep 17 00:00:00 2001 +From: mayunlong +Date: Sat, 27 Aug 2022 16:36:44 +0800 +Subject: [PATCH 2/2] bugfix: fix command create flags/undefine flags/capsinit + add nvramDir/autostartDir + +--- + src/stratovirt/stratovirt_conf.c | 13 +++++-- + src/stratovirt/stratovirt_domain.c | 10 ++++++ + src/stratovirt/stratovirt_domain.h | 1 + + src/stratovirt/stratovirt_driver.c | 55 +++++++++++++++++++++++++++--- + 4 files changed, 72 insertions(+), 7 deletions(-) + +diff --git a/src/stratovirt/stratovirt_conf.c b/src/stratovirt/stratovirt_conf.c +index ef48ec2474..5c4028616d 100644 +--- a/src/stratovirt/stratovirt_conf.c ++++ b/src/stratovirt/stratovirt_conf.c +@@ -32,6 +32,8 @@ + + VIR_LOG_INIT("stratovirt.stratovirt_conf"); + ++#define VIR_FROM_THIS VIR_FROM_STRATOVIRT ++ + #define STRATOVIRT_REMOTE_PORT_MIN 5900 + #define STRATOVIRT_REMOTE_PORT_MAX 65535 + +@@ -64,7 +66,7 @@ static virCapsPtr virStratoVirtCapsInit(void) + goto error; + + if (virCapabilitiesInitCaches(caps) < 0) +- goto error; ++ VIR_WARN("Failed to get host CPU cache info"); + + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + caps->host.arch, NULL, NULL, 0, NULL); +@@ -151,8 +153,9 @@ virStratoVirtDriverConfigPtr virStratoVirtDriverConfigNew(bool privileged) + + cfg->channelTargetDir = g_strdup_printf("%s/channel/target", cfg->libDir); + +- cfg->memoryBackingDir = g_strdup_printf("%s/ram", cfg->libDir); ++ cfg->nvramDir = g_strdup_printf("%s/nvram", cfg->libDir); + ++ cfg->memoryBackingDir = g_strdup_printf("%s/ram", cfg->libDir); + } else { + g_autofree char *rundir = NULL; + g_autofree char *cachedir = NULL; +@@ -175,10 +178,13 @@ virStratoVirtDriverConfigPtr virStratoVirtDriverConfigNew(bool privileged) + cfg->autoDumpPath = g_strdup_printf("%s/stratovirt/dump", cfg->configBaseDir); + cfg->channelTargetDir = g_strdup_printf("%s/stratovirt/channel/target", + cfg->configBaseDir); ++ cfg->nvramDir = g_strdup_printf("%s/nvram", cfg->configBaseDir); + cfg->memoryBackingDir = g_strdup_printf("%s/stratovirt/ram", cfg->configBaseDir); + } + + cfg->configDir = g_strdup_printf("%s/stratovirt", cfg->configBaseDir); ++ cfg->autostartDir = g_strdup_printf("%s/stratovirt/autostart", cfg->configBaseDir); ++ cfg->dbusStateDir = g_strdup_printf("%s/dubs", cfg->stateDir); + + cfg->remotePortMin = STRATOVIRT_REMOTE_PORT_MIN; + cfg->remotePortMax = STRATOVIRT_REMOTE_PORT_MAX; +@@ -222,14 +228,17 @@ static void virStratoVirtDriverConfigDispose(void *obj) + VIR_FREE(cfg->uri); + VIR_FREE(cfg->configBaseDir); + VIR_FREE(cfg->configDir); ++ VIR_FREE(cfg->autostartDir); + VIR_FREE(cfg->logDir); + VIR_FREE(cfg->stateDir); ++ VIR_FREE(cfg->dbusStateDir); + VIR_FREE(cfg->libDir); + VIR_FREE(cfg->cacheDir); + VIR_FREE(cfg->saveDir); + VIR_FREE(cfg->snapshotDir); + VIR_FREE(cfg->checkpointDir); + VIR_FREE(cfg->channelTargetDir); ++ VIR_FREE(cfg->nvramDir); + + while (cfg->nhugetlbfs) { + cfg->nhugetlbfs--; +diff --git a/src/stratovirt/stratovirt_domain.c b/src/stratovirt/stratovirt_domain.c +index b894282ce2..23b8b8589e 100644 +--- a/src/stratovirt/stratovirt_domain.c ++++ b/src/stratovirt/stratovirt_domain.c +@@ -45,17 +45,27 @@ static int virStratoVirtDomainPostParseBasic(virDomainDefPtr def, + return 0; + } + ++static void stratovirtDomainNVRAMPathGenerate(virStratoVirtDriverConfigPtr cfg, ++ virDomainDefPtr def) ++{ ++ if (virDomainDefHasOldStyleROUEFI(def) && !def->os.loader->nvram) ++ def->os.loader->nvram = g_strdup_printf("%s/%s_VARS.fd", cfg->nvramDir, def->name); ++} ++ + static int virStratoVirtDomainPostParse(virDomainDefPtr def, + unsigned int parseFlags G_GNUC_UNUSED, + void * opaque, + void *parseOpaue G_GNUC_UNUSED) + { + virStratoVirtDriverPtr driver = opaque; ++ g_autoptr(virStratoVirtDriverConfig) cfg = virStratoVirtDriverGetConfig(driver); + g_autoptr(virCaps) caps = virStratoVirtDriverGetCapabilities(driver, false); + + if (!caps) + return -1; + ++ stratovirtDomainNVRAMPathGenerate(cfg, def); ++ + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) +diff --git a/src/stratovirt/stratovirt_domain.h b/src/stratovirt/stratovirt_domain.h +index a6abd84420..9aeea1974e 100644 +--- a/src/stratovirt/stratovirt_domain.h ++++ b/src/stratovirt/stratovirt_domain.h +@@ -25,6 +25,7 @@ + #include "stratovirt_conf.h" + + #include "qemu_hotplug.h" ++#include "qemu_checkpoint.h" + + typedef enum { + STRATOVIRT_PROCESS_EVENT_WATCHDOG = 0, +diff --git a/src/stratovirt/stratovirt_driver.c b/src/stratovirt/stratovirt_driver.c +index d4ba00dac7..a9d9303881 100644 +--- a/src/stratovirt/stratovirt_driver.c ++++ b/src/stratovirt/stratovirt_driver.c +@@ -261,6 +261,10 @@ static virDomainPtr stratovirtDomainCreateXML(virConnectPtr conn, + + if (flags & VIR_DOMAIN_START_VALIDATE) + parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; ++ if (flags & VIR_DOMAIN_START_PAUSED) ++ start_flags |= VIR_STRATOVIRT_PROCESS_START_PAUSED; ++ if (flags & VIR_DOMAIN_START_AUTODESTROY) ++ start_flags |= VIR_STRATOVIRT_PROCESS_START_AUTODESTROY; + + if (!(def = virDomainDefParseString(xml, driver->xmlopt, + NULL, parse_flags))) +@@ -610,10 +614,20 @@ stratovirtDomainUndefineFlags(virDomainPtr dom, + int ret = -1; + int nsnapshots; + int ncheckpoints; ++ g_autofree char *nvram_path = NULL; + g_autoptr(virStratoVirtDriverConfig) cfg = virStratoVirtDriverGetConfig(driver); + + virCheckFlags(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA | +- VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA ,-1); ++ VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA | ++ VIR_DOMAIN_UNDEFINE_NVRAM | ++ VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, -1); ++ ++ if ((flags & VIR_DOMAIN_UNDEFINE_NVRAM) && ++ (flags & VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)) { ++ virReportError(VIR_ERR_OPERATION_INVALID, "%s", ++ _("cannot both keep and delete nvram")); ++ return -1; ++ } + + if (!(vm = stratovirtDomainObjFromDomain(dom))) + goto cleanup; +@@ -655,6 +669,29 @@ stratovirtDomainUndefineFlags(virDomainPtr dom, + goto endjob; + } + ++ if (vm->def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) { ++ nvram_path = g_strdup_printf("%s/%s_VARS.fd", cfg->nvramDir, vm->def->name); ++ } else { ++ if (vm->def->os.loader) ++ nvram_path = g_strdup(vm->def->os.loader->nvram); ++ } ++ ++ ++ if (nvram_path && virFileExists(nvram_path)) { ++ if (flags & VIR_DOMAIN_UNDEFINE_NVRAM) { ++ if (unlink(nvram_path) < 0) { ++ virReportSystemError(errno, ++ _("failed to remove nvram %s"), ++ nvram_path); ++ goto endjob; ++ } ++ } else if (!(flags & VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)) { ++ virReportError(VIR_ERR_OPERATION_INVALID, "%s", ++ _("cannot undefine domain with nvram")); ++ goto endjob; ++ } ++ } ++ + if (virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm) < 0) + goto cleanup; + +@@ -1019,7 +1056,6 @@ stratovirtStateInitialize(bool privileged, + virStateInhibitCallback callback, + void *opaque) + { +- g_autofree char *driverConf = NULL; + virStratoVirtDriverConfigPtr cfg; + uid_t run_uid = -1; + gid_t run_gid = -1; +@@ -1065,9 +1101,6 @@ stratovirtStateInitialize(bool privileged, + 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); +@@ -1108,12 +1141,24 @@ stratovirtStateInitialize(bool privileged, + cfg->channelTargetDir); + goto error; + } ++ if (virFileMakePath(cfg->nvramDir) < 0) { ++ virReportSystemError(errno, _("Failed to create nvram dir %s"), ++ cfg->nvramDir); ++ goto error; ++ } + if (virFileMakePath(cfg->memoryBackingDir) < 0) { + virReportSystemError(errno, _("Failed to create memory backing dir %s"), + cfg->memoryBackingDir); + goto error; + } + ++ if (virDirCreate(cfg->dbusStateDir, 0770, cfg->user, cfg->group, ++ VIR_DIR_CREATE_ALLOW_EXIST) < 0) { ++ virReportSystemError(errno, _("Failed to create dbus state dir %s"), ++ cfg->dbusStateDir); ++ goto error; ++ } ++ + if ((stratovirt_driver->lockFD = + virPidFileAcquire(cfg->stateDir, "driver", false, getpid())) < 0) + goto error; +-- +2.25.1 + diff --git a/libvirt.spec b/libvirt.spec index ad6a115..8ab5bae 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -102,7 +102,7 @@ Summary: Library providing a simple virtualization API Name: libvirt Version: 6.2.0 -Release: 43 +Release: 44 License: LGPLv2+ URL: https://libvirt.org/ @@ -256,6 +256,8 @@ 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 Patch0145: qemu-Add-missing-lock-in-qemuProcessHandleMonitorEOF.patch +Patch0146: Add-command-define-undefine-start-shutdown-in-strato.patch +Patch0147: bugfix-fix-command-create-flags-undefine-flags-capsi.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2018,6 +2020,10 @@ exit 0 %changelog +* Mon Aug 29 2022 mayunlong - 6.2.0-44 +- add command define undefine start shutdown in stratovirt_driver +- bugfix: fix command create flags/undefine flags/capsinit + * Thu Aug 25 2022 yezengruan - 6.2.0-43 - qemu: Add missing lock in qemuProcessHandleMonitorEOF (CVE-2021-3975) -- Gitee