From: Purna Pavan Chandra Aekkaladevi Date: Mon, 11 Mar 2024 09:44:05 +0000 (+0000) Subject: ch_driver: Add additional validation for save/restore X-Git-Tag: v10.2.0-rc1~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bcd567faa2a8cf84898f08b688fa5f6db8243aeb;p=thirdparty%2Flibvirt.git ch_driver: Add additional validation for save/restore Save & Restore are supported without any network and hostdev config defined. So, add a validation for it before performing save. Signed-off-by: Purna Pavan Chandra Aekkaladevi Reviewed-by: Michal Privoznik --- diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 0237dfc477..7308f40249 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -679,6 +679,26 @@ chDomainDestroy(virDomainPtr dom) return chDomainDestroyFlags(dom, 0); } +static int +chDomainSaveAdditionalValidation(virDomainDef *vmdef) +{ + /* + SAVE and RESTORE are functional only without any networking and + device passthrough configuration + */ + if (vmdef->nnets > 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot save domain with network interfaces")); + return -1; + } + if (vmdef->nhostdevs > 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot save domain with host devices")); + return -1; + } + return 0; +} + /** * chDoDomainSave: * @driver: pointer to driver structure @@ -701,13 +721,17 @@ chDoDomainSave(virCHDriver *driver, g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver); virCHDomainObjPrivate *priv = vm->privateData; CHSaveXMLHeader hdr; + virDomainState domainState; g_autofree char *to = NULL; g_autofree char *xml = NULL; uint32_t xml_len; VIR_AUTOCLOSE fd = -1; int ret = -1; - virDomainState domainState = virDomainObjGetState(vm, NULL); + if (chDomainSaveAdditionalValidation(vm->def) < 0) + goto end; + + domainState = virDomainObjGetState(vm, NULL); if (domainState == VIR_DOMAIN_RUNNING) { if (virCHMonitorSuspendVM(priv->monitor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s",