From nobody Sat Nov 23 05:48:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682065577; cv=none; d=zohomail.com; s=zohoarc; b=AMZlOfFKCSoJQ6F8s4Fsti0NjZ7ekzaxkM2W+mRwTBWypBSJHf+VNWgJs07l4EJi/NG2SFrO3ZfAQpRGim+C5ZHI6+1q/0zzX9YscJ/CeNt/kQYZoJdK7R3Jw+B/jY0gQSKJ1DHTMMEfc9UZeDCqH+c3jrZkC++p5CMjmomHBgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682065577; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8c8JcQvKd3xwOH0uWgrR0/7ob/bURpjdF6wwNYPPtHE=; b=Fv7LpHmhAFHfHbIPAXTLKH+sIp2Kw9leecxY9o0voOO+Agp5iJnNF6ARl6Ss0dMfZ6rhhqKmrx8dDCvO6WKwUIQPvytTOpRDPcTofdCeUgPLeuHMfBap1dEvuhxsQ1XVyIQTsb7ZoJKP2hYPFd8alQLCce7N5d7y+7nZh5NTUR8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1682065577504717.6325126028568; Fri, 21 Apr 2023 01:26:17 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-607-yBmvrgBsMA2kCx3EyaHV7w-1; Fri, 21 Apr 2023 04:25:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6CAE85A5B1; Fri, 21 Apr 2023 08:25:16 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1C1FC164EF; Fri, 21 Apr 2023 08:25:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B22081946A48; Fri, 21 Apr 2023 08:25:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 290F91946A46 for ; Fri, 21 Apr 2023 08:25:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1E3AD63A51; Fri, 21 Apr 2023 08:25:14 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EDA15AB7A for ; Fri, 21 Apr 2023 08:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682065576; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=8c8JcQvKd3xwOH0uWgrR0/7ob/bURpjdF6wwNYPPtHE=; b=SWygJNRNBFAojEBnh0+GaATAi/47iCTJYvX5c9RV4ozHLJ2nJf2RbbL7+MZVbHVvJk2/9i klbxRgpDyWxjMDgPHLcykqyuug790ExxTi0W+9PyumDRQW8wgaALrEDDN9sdbK5NFBDsVT ziiDTZzacJsCoDSRFqHCDxEcyIwj7BY= X-MC-Unique: yBmvrgBsMA2kCx3EyaHV7w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 03/11] qemu: Move qemuDomainUpdateDeviceLive() into qemu_hotplug.c Date: Fri, 21 Apr 2023 10:25:02 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682065579176100003 Content-Type: text/plain; charset="utf-8"; x-default="true" There is no good reason for qemuDomainUpdateDeviceLive() to live in (ever growing) qemu_driver.c while we have qemu_hotplug.c which already contains the rest of hotplug code. Move the function to its new home. Signed-off-by: Michal Privoznik Reviewed-by: Kristina Hanicova --- src/qemu/qemu_driver.c | 299 ---------------------------------------- src/qemu/qemu_hotplug.c | 299 ++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hotplug.h | 5 + 3 files changed, 304 insertions(+), 299 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index fe1ddb5ade..5ee15bab7a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6671,305 +6671,6 @@ qemuDomainUndefine(virDomainPtr dom) return qemuDomainUndefineFlags(dom, 0); } =20 -static int -qemuDomainChangeDiskLive(virDomainObj *vm, - virDomainDeviceDef *dev, - virQEMUDriver *driver, - bool force) -{ - virDomainDiskDef *disk =3D dev->data.disk; - virDomainDiskDef *orig_disk =3D NULL; - virDomainStartupPolicy origStartupPolicy; - virDomainDeviceDef oldDev =3D { .type =3D dev->type }; - - if (!(orig_disk =3D virDomainDiskByTarget(vm->def, disk->dst))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("disk '%1$s' not found"), disk->dst); - return -1; - } - - oldDev.data.disk =3D orig_disk; - origStartupPolicy =3D orig_disk->startupPolicy; - if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, - VIR_DOMAIN_DEVICE_ACTION_UPDATE, - true) < 0) - return -1; - - if (!qemuDomainDiskChangeSupported(disk, orig_disk)) - return -1; - - if (!virStorageSourceIsSameLocation(disk->src, orig_disk->src)) { - /* Disk source can be changed only for removable devices */ - if (disk->device !=3D VIR_DOMAIN_DISK_DEVICE_CDROM && - disk->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("disk source can be changed only in removable= " - "drives")); - return -1; - } - - /* update startup policy first before updating disk image */ - orig_disk->startupPolicy =3D dev->data.disk->startupPolicy; - - if (qemuDomainChangeEjectableMedia(driver, vm, orig_disk, - dev->data.disk->src, force) < 0= ) { - /* revert startup policy before failing */ - orig_disk->startupPolicy =3D origStartupPolicy; - return -1; - } - - dev->data.disk->src =3D NULL; - } - - /* in case when we aren't updating disk source we update startup polic= y here */ - orig_disk->startupPolicy =3D dev->data.disk->startupPolicy; - orig_disk->snapshot =3D dev->data.disk->snapshot; - - return 0; -} - - -static bool -qemuDomainChangeMemoryLiveValidateChange(const virDomainMemoryDef *oldDef, - const virDomainMemoryDef *newDef) -{ - /* The only thing that is allowed to change is 'requestedsize' for - * virtio-mem model. Check if user isn't trying to sneak in change for - * something else. */ - - switch (oldDef->model) { - case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: - break; - - case VIR_DOMAIN_MEMORY_MODEL_NONE: - case VIR_DOMAIN_MEMORY_MODEL_DIMM: - case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: - case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: - case VIR_DOMAIN_MEMORY_MODEL_LAST: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory of model '%1$s'"), - virDomainMemoryModelTypeToString(oldDef->model)); - return false; - break; - } - - if (oldDef->model !=3D newDef->model) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory model from '%1$s' to '%2$s'= "), - virDomainMemoryModelTypeToString(oldDef->model), - virDomainMemoryModelTypeToString(newDef->model)); - return false; - } - - if (oldDef->access !=3D newDef->access) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory access from '%1$s' to '%2$s= '"), - virDomainMemoryAccessTypeToString(oldDef->access), - virDomainMemoryAccessTypeToString(newDef->access)); - return false; - } - - if (oldDef->discard !=3D newDef->discard) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory discard from '%1$s' to '%2$= s'"), - virTristateBoolTypeToString(oldDef->discard), - virTristateBoolTypeToString(newDef->discard)); - return false; - } - - if (!virBitmapEqual(oldDef->sourceNodes, - newDef->sourceNodes)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("cannot modify memory source nodes")); - return false; - } - - if (oldDef->pagesize !=3D newDef->pagesize) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory pagesize from '%1$llu' to '= %2$llu'"), - oldDef->pagesize, - newDef->pagesize); - return false; - } - - if (STRNEQ_NULLABLE(oldDef->nvdimmPath, newDef->nvdimmPath)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory path from '%1$s' to '%2$s'"= ), - NULLSTR(oldDef->nvdimmPath), - NULLSTR(newDef->nvdimmPath)); - return false; - } - - if (oldDef->alignsize !=3D newDef->alignsize) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory align size from '%1$llu' to= '%2$llu'"), - oldDef->alignsize, newDef->alignsize); - return false; - } - - if (oldDef->nvdimmPmem !=3D newDef->nvdimmPmem) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory pmem from '%1$d' to '%2$d'"= ), - oldDef->nvdimmPmem, newDef->nvdimmPmem); - return false; - } - - if (oldDef->targetNode !=3D newDef->targetNode) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory targetNode from '%1$d' to '= %2$d'"), - oldDef->targetNode, newDef->targetNode); - return false; - } - - if (oldDef->size !=3D newDef->size) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory size from '%1$llu' to '%2$l= lu'"), - oldDef->size, newDef->size); - return false; - } - - if (oldDef->labelsize !=3D newDef->labelsize) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory label size from '%1$llu' to= '%2$llu'"), - oldDef->labelsize, newDef->labelsize); - return false; - } - if (oldDef->blocksize !=3D newDef->blocksize) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("cannot modify memory block size from '%1$llu' to= '%2$llu'"), - oldDef->blocksize, newDef->blocksize); - return false; - } - - /* requestedsize can change */ - - if (oldDef->readonly !=3D newDef->readonly) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("cannot modify memory pmem flag")); - return false; - } - - if ((oldDef->uuid || newDef->uuid) && - !(oldDef->uuid && newDef->uuid && - memcmp(oldDef->uuid, newDef->uuid, VIR_UUID_BUFLEN) =3D=3D 0)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("cannot modify memory UUID")); - return false; - } - - return true; -} - - -static int -qemuDomainChangeMemoryLive(virQEMUDriver *driver G_GNUC_UNUSED, - virDomainObj *vm, - virDomainDeviceDef *dev) -{ - virDomainDeviceDef oldDev =3D { .type =3D VIR_DOMAIN_DEVICE_MEMORY }; - virDomainMemoryDef *newDef =3D dev->data.memory; - virDomainMemoryDef *oldDef =3D NULL; - - oldDef =3D virDomainMemoryFindByDeviceInfo(vm->def, &dev->data.memory-= >info, NULL); - if (!oldDef) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("memory '%1$s' not found"), dev->data.memory->inf= o.alias); - return -1; - } - - oldDev.data.memory =3D oldDef; - - if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, - VIR_DOMAIN_DEVICE_ACTION_UPDATE, - true) < 0) - return -1; - - if (!qemuDomainChangeMemoryLiveValidateChange(oldDef, newDef)) - return -1; - - if (qemuDomainChangeMemoryRequestedSize(vm, newDef->info.alias, - newDef->requestedsize) < 0) - return -1; - - oldDef->requestedsize =3D newDef->requestedsize; - return 0; -} - - -static int -qemuDomainUpdateDeviceLive(virDomainObj *vm, - virDomainDeviceDef *dev, - virQEMUDriver *driver, - bool force) -{ - virDomainDeviceDef oldDev =3D { .type =3D dev->type }; - int idx; - - switch ((virDomainDeviceType)dev->type) { - case VIR_DOMAIN_DEVICE_DISK: - qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL); - return qemuDomainChangeDiskLive(vm, dev, driver, force); - - case VIR_DOMAIN_DEVICE_GRAPHICS: - if ((idx =3D qemuDomainFindGraphicsIndex(vm->def, dev->data.graphi= cs)) >=3D 0) { - oldDev.data.graphics =3D vm->def->graphics[idx]; - if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, - VIR_DOMAIN_DEVICE_ACTION_UPDA= TE, - true) < 0) - return -1; - } - - return qemuDomainChangeGraphics(driver, vm, dev->data.graphics); - - case VIR_DOMAIN_DEVICE_NET: - if ((idx =3D virDomainNetFindIdx(vm->def, dev->data.net)) >=3D 0) { - oldDev.data.net =3D vm->def->nets[idx]; - if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, - VIR_DOMAIN_DEVICE_ACTION_UPDA= TE, - true) < 0) - return -1; - } - - return qemuDomainChangeNet(driver, vm, dev); - - case VIR_DOMAIN_DEVICE_MEMORY: - return qemuDomainChangeMemoryLive(driver, vm, dev); - - 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_HUB: - case VIR_DOMAIN_DEVICE_SMARTCARD: - case VIR_DOMAIN_DEVICE_MEMBALLOON: - case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_RNG: - case VIR_DOMAIN_DEVICE_SHMEM: - case VIR_DOMAIN_DEVICE_LEASE: - case VIR_DOMAIN_DEVICE_HOSTDEV: - case VIR_DOMAIN_DEVICE_CONTROLLER: - case VIR_DOMAIN_DEVICE_REDIRDEV: - case VIR_DOMAIN_DEVICE_CHR: - case VIR_DOMAIN_DEVICE_NONE: - case VIR_DOMAIN_DEVICE_TPM: - case VIR_DOMAIN_DEVICE_PANIC: - case VIR_DOMAIN_DEVICE_IOMMU: - case VIR_DOMAIN_DEVICE_VSOCK: - case VIR_DOMAIN_DEVICE_AUDIO: - case VIR_DOMAIN_DEVICE_CRYPTO: - case VIR_DOMAIN_DEVICE_LAST: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("live update of device '%1$s' is not supported"), - virDomainDeviceTypeToString(dev->type)); - return -1; - } - - return -1; -} - - static int qemuCheckDiskConfigAgainstDomain(const virDomainDef *def, const virDomainDiskDef *disk) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index bd126234fd..f72bb7722d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6910,3 +6910,302 @@ qemuDomainChangeMemoryRequestedSize(virDomainObj *v= m, =20 return rc; } + + +static int +qemuDomainChangeDiskLive(virDomainObj *vm, + virDomainDeviceDef *dev, + virQEMUDriver *driver, + bool force) +{ + virDomainDiskDef *disk =3D dev->data.disk; + virDomainDiskDef *orig_disk =3D NULL; + virDomainStartupPolicy origStartupPolicy; + virDomainDeviceDef oldDev =3D { .type =3D dev->type }; + + if (!(orig_disk =3D virDomainDiskByTarget(vm->def, disk->dst))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("disk '%1$s' not found"), disk->dst); + return -1; + } + + oldDev.data.disk =3D orig_disk; + origStartupPolicy =3D orig_disk->startupPolicy; + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDATE, + true) < 0) + return -1; + + if (!qemuDomainDiskChangeSupported(disk, orig_disk)) + return -1; + + if (!virStorageSourceIsSameLocation(disk->src, orig_disk->src)) { + /* Disk source can be changed only for removable devices */ + if (disk->device !=3D VIR_DOMAIN_DISK_DEVICE_CDROM && + disk->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("disk source can be changed only in removable= " + "drives")); + return -1; + } + + /* update startup policy first before updating disk image */ + orig_disk->startupPolicy =3D dev->data.disk->startupPolicy; + + if (qemuDomainChangeEjectableMedia(driver, vm, orig_disk, + dev->data.disk->src, force) < 0= ) { + /* revert startup policy before failing */ + orig_disk->startupPolicy =3D origStartupPolicy; + return -1; + } + + dev->data.disk->src =3D NULL; + } + + /* in case when we aren't updating disk source we update startup polic= y here */ + orig_disk->startupPolicy =3D dev->data.disk->startupPolicy; + orig_disk->snapshot =3D dev->data.disk->snapshot; + + return 0; +} + + +static bool +qemuDomainChangeMemoryLiveValidateChange(const virDomainMemoryDef *oldDef, + const virDomainMemoryDef *newDef) +{ + /* The only thing that is allowed to change is 'requestedsize' for + * virtio-mem model. Check if user isn't trying to sneak in change for + * something else. */ + + switch (oldDef->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory of model '%1$s'"), + virDomainMemoryModelTypeToString(oldDef->model)); + return false; + break; + } + + if (oldDef->model !=3D newDef->model) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory model from '%1$s' to '%2$s'= "), + virDomainMemoryModelTypeToString(oldDef->model), + virDomainMemoryModelTypeToString(newDef->model)); + return false; + } + + if (oldDef->access !=3D newDef->access) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory access from '%1$s' to '%2$s= '"), + virDomainMemoryAccessTypeToString(oldDef->access), + virDomainMemoryAccessTypeToString(newDef->access)); + return false; + } + + if (oldDef->discard !=3D newDef->discard) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory discard from '%1$s' to '%2$= s'"), + virTristateBoolTypeToString(oldDef->discard), + virTristateBoolTypeToString(newDef->discard)); + return false; + } + + if (!virBitmapEqual(oldDef->sourceNodes, + newDef->sourceNodes)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory source nodes")); + return false; + } + + if (oldDef->pagesize !=3D newDef->pagesize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory pagesize from '%1$llu' to '= %2$llu'"), + oldDef->pagesize, + newDef->pagesize); + return false; + } + + if (STRNEQ_NULLABLE(oldDef->nvdimmPath, newDef->nvdimmPath)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory path from '%1$s' to '%2$s'"= ), + NULLSTR(oldDef->nvdimmPath), + NULLSTR(newDef->nvdimmPath)); + return false; + } + + if (oldDef->alignsize !=3D newDef->alignsize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory align size from '%1$llu' to= '%2$llu'"), + oldDef->alignsize, newDef->alignsize); + return false; + } + + if (oldDef->nvdimmPmem !=3D newDef->nvdimmPmem) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory pmem from '%1$d' to '%2$d'"= ), + oldDef->nvdimmPmem, newDef->nvdimmPmem); + return false; + } + + if (oldDef->targetNode !=3D newDef->targetNode) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory targetNode from '%1$d' to '= %2$d'"), + oldDef->targetNode, newDef->targetNode); + return false; + } + + if (oldDef->size !=3D newDef->size) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory size from '%1$llu' to '%2$l= lu'"), + oldDef->size, newDef->size); + return false; + } + + if (oldDef->labelsize !=3D newDef->labelsize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory label size from '%1$llu' to= '%2$llu'"), + oldDef->labelsize, newDef->labelsize); + return false; + } + if (oldDef->blocksize !=3D newDef->blocksize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory block size from '%1$llu' to= '%2$llu'"), + oldDef->blocksize, newDef->blocksize); + return false; + } + + /* requestedsize can change */ + + if (oldDef->readonly !=3D newDef->readonly) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory pmem flag")); + return false; + } + + if ((oldDef->uuid || newDef->uuid) && + !(oldDef->uuid && newDef->uuid && + memcmp(oldDef->uuid, newDef->uuid, VIR_UUID_BUFLEN) =3D=3D 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory UUID")); + return false; + } + + return true; +} + + +static int +qemuDomainChangeMemoryLive(virQEMUDriver *driver G_GNUC_UNUSED, + virDomainObj *vm, + virDomainDeviceDef *dev) +{ + virDomainDeviceDef oldDev =3D { .type =3D VIR_DOMAIN_DEVICE_MEMORY }; + virDomainMemoryDef *newDef =3D dev->data.memory; + virDomainMemoryDef *oldDef =3D NULL; + + oldDef =3D virDomainMemoryFindByDeviceInfo(vm->def, &dev->data.memory-= >info, NULL); + if (!oldDef) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory '%1$s' not found"), dev->data.memory->inf= o.alias); + return -1; + } + + oldDev.data.memory =3D oldDef; + + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDATE, + true) < 0) + return -1; + + if (!qemuDomainChangeMemoryLiveValidateChange(oldDef, newDef)) + return -1; + + if (qemuDomainChangeMemoryRequestedSize(vm, newDef->info.alias, + newDef->requestedsize) < 0) + return -1; + + oldDef->requestedsize =3D newDef->requestedsize; + return 0; +} + + +int +qemuDomainUpdateDeviceLive(virDomainObj *vm, + virDomainDeviceDef *dev, + virQEMUDriver *driver, + bool force) +{ + virDomainDeviceDef oldDev =3D { .type =3D dev->type }; + int idx; + + switch ((virDomainDeviceType)dev->type) { + case VIR_DOMAIN_DEVICE_DISK: + qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL); + return qemuDomainChangeDiskLive(vm, dev, driver, force); + + case VIR_DOMAIN_DEVICE_GRAPHICS: + if ((idx =3D qemuDomainFindGraphicsIndex(vm->def, dev->data.graphi= cs)) >=3D 0) { + oldDev.data.graphics =3D vm->def->graphics[idx]; + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDA= TE, + true) < 0) + return -1; + } + + return qemuDomainChangeGraphics(driver, vm, dev->data.graphics); + + case VIR_DOMAIN_DEVICE_NET: + if ((idx =3D virDomainNetFindIdx(vm->def, dev->data.net)) >=3D 0) { + oldDev.data.net =3D vm->def->nets[idx]; + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDA= TE, + true) < 0) + return -1; + } + + return qemuDomainChangeNet(driver, vm, dev); + + case VIR_DOMAIN_DEVICE_MEMORY: + return qemuDomainChangeMemoryLive(driver, vm, dev); + + 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_HUB: + case VIR_DOMAIN_DEVICE_SMARTCARD: + case VIR_DOMAIN_DEVICE_MEMBALLOON: + case VIR_DOMAIN_DEVICE_NVRAM: + case VIR_DOMAIN_DEVICE_RNG: + case VIR_DOMAIN_DEVICE_SHMEM: + case VIR_DOMAIN_DEVICE_LEASE: + case VIR_DOMAIN_DEVICE_HOSTDEV: + case VIR_DOMAIN_DEVICE_CONTROLLER: + case VIR_DOMAIN_DEVICE_REDIRDEV: + case VIR_DOMAIN_DEVICE_CHR: + case VIR_DOMAIN_DEVICE_NONE: + case VIR_DOMAIN_DEVICE_TPM: + case VIR_DOMAIN_DEVICE_PANIC: + case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_VSOCK: + case VIR_DOMAIN_DEVICE_AUDIO: + case VIR_DOMAIN_DEVICE_CRYPTO: + case VIR_DOMAIN_DEVICE_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("live update of device '%1$s' is not supported"), + virDomainDeviceTypeToString(dev->type)); + return -1; + } + + return -1; +} diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 74fc3bbd65..d9a5ac1164 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -120,6 +120,11 @@ int qemuDomainDetachDeviceLive(virDomainObj *vm, virQEMUDriver *driver, bool async); =20 +int qemuDomainUpdateDeviceLive(virDomainObj *vm, + virDomainDeviceDef *dev, + virQEMUDriver *driver, + bool force); + void qemuDomainRemoveVcpuAlias(virDomainObj *vm, const char *alias); =20 --=20 2.39.2