From nobody Thu Apr 25 13:47:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528815924925623.7945110114357; Tue, 12 Jun 2018 08:05:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4027C308A968; Tue, 12 Jun 2018 15:05:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D55F47D8B6; Tue, 12 Jun 2018 15:05:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6FD254CA80; Tue, 12 Jun 2018 15:05:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5CF5IrR025841 for ; Tue, 12 Jun 2018 11:05:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 75168111C4A9; Tue, 12 Jun 2018 15:05:18 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18DDB111C4A2 for ; Tue, 12 Jun 2018 15:05:17 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 12 Jun 2018 17:04:57 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] qemuDomainUpdateDeviceFlags: Parse device as live if needed X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 12 Jun 2018 15:05:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When updating device it's worth parsing live info too as users might want to update it as well. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f0fb806fcd..ab5cc6ea31 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8608,7 +8608,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr d= om, int ret =3D -1; virQEMUDriverConfigPtr cfg =3D NULL; virCapsPtr caps =3D NULL; - unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + unsigned int parse_flags =3D 0; =20 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG | @@ -8630,15 +8630,19 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr= dom, if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; =20 + if (virDomainObjUpdateModificationImpact(vm, &flags) < 0) + goto endjob; + + if ((flags & VIR_DOMAIN_AFFECT_CONFIG) && + !(flags & VIR_DOMAIN_AFFECT_LIVE)) + parse_flags |=3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + dev =3D dev_copy =3D virDomainDeviceDefParse(xml, vm->def, caps, driver->xmlopt, parse_flags); if (dev =3D=3D NULL) goto endjob; =20 - if (virDomainObjUpdateModificationImpact(vm, &flags) < 0) - goto endjob; - if (flags & VIR_DOMAIN_AFFECT_CONFIG && flags & VIR_DOMAIN_AFFECT_LIVE) { /* If we are affecting both CONFIG and LIVE --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 13:47:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528815931229130.1387279694667; Tue, 12 Jun 2018 08:05:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6D1C81DF3; Tue, 12 Jun 2018 15:05:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 983B610694D0; Tue, 12 Jun 2018 15:05:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2F62E4BB78; Tue, 12 Jun 2018 15:05:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5CF5JE4025847 for ; Tue, 12 Jun 2018 11:05:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 171AD111C4A9; Tue, 12 Jun 2018 15:05:19 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF934111C4A2 for ; Tue, 12 Jun 2018 15:05:18 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 12 Jun 2018 17:04:58 +0200 Message-Id: <35a266c10d2c28cd20c4a3edc53b6fe5555094b9.1528815697.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] conf: Forbid device alias change on device-update X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 12 Jun 2018 15:05:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1585108 When updating a live device users might pass different alias than the one the device has. Currently, this is silently ignored which goes against our behaviour for other parts of the device where we explicitly allow only certain changes and error out loudly on anything else. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 12 +++++++++++- src/conf/domain_conf.h | 3 ++- src/lxc/lxc_driver.c | 6 +++--- src/qemu/qemu_driver.c | 16 ++++++++-------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 85f07af46e..91cac75c0a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28195,7 +28195,8 @@ virDomainDeviceInfoCheckBootIndex(virDomainDefPtr d= ef ATTRIBUTE_UNUSED, int virDomainDefCompatibleDevice(virDomainDefPtr def, virDomainDeviceDefPtr dev, - virDomainDeviceDefPtr oldDev) + virDomainDeviceDefPtr oldDev, + bool live) { virDomainCompatibleDeviceData data =3D { .newInfo =3D virDomainDeviceGetInfo(dev), @@ -28205,6 +28206,15 @@ virDomainDefCompatibleDevice(virDomainDefPtr def, if (oldDev) data.oldInfo =3D virDomainDeviceGetInfo(oldDev); =20 + if (live && + ((!!data.newInfo !=3D !!data.oldInfo) || + (data.newInfo && data.oldInfo && + STRNEQ(data.newInfo->alias, data.oldInfo->alias)))) { + virReportError(VIR_ERR_OPERATION_DENIED, "%s", + _("changing device alias is not allowed")); + return -1; + } + if (!virDomainDefHasUSB(def) && def->os.type !=3D VIR_DOMAIN_OSTYPE_EXE && virDomainDeviceIsUSB(dev)) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ea8ddb2b39..c03028efb9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3107,7 +3107,8 @@ typedef enum { =20 int virDomainDefCompatibleDevice(virDomainDefPtr def, virDomainDeviceDefPtr dev, - virDomainDeviceDefPtr oldDev); + virDomainDeviceDefPtr oldDev, + bool live); =20 void virDomainRNGDefFree(virDomainRNGDefPtr def); =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index cfb431488d..fb7c8135e0 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3549,7 +3549,7 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef, goto cleanup; =20 oldDev.data.net =3D vmdef->nets[idx]; - if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev, false) < 0) return -1; =20 virDomainNetDefFree(vmdef->nets[idx]); @@ -4785,7 +4785,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr do= m, if (!vmdef) goto endjob; =20 - if (virDomainDefCompatibleDevice(vmdef, dev, NULL) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev, NULL, false) < 0) goto endjob; =20 if ((ret =3D lxcDomainAttachDeviceConfig(vmdef, dev)) < 0) @@ -4793,7 +4793,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr do= m, } =20 if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virDomainDefCompatibleDevice(vm->def, dev_copy, NULL) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev_copy, NULL, true) < = 0) goto endjob; =20 if ((ret =3D lxcDomainAttachDeviceLive(dom->conn, driver, vm, dev_= copy)) < 0) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ab5cc6ea31..2d4e777b47 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7860,7 +7860,7 @@ qemuDomainChangeDiskLive(virDomainObjPtr vm, } =20 oldDev.data.disk =3D orig_disk; - if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, true) < 0) goto cleanup; =20 if (!qemuDomainDiskChangeSupported(disk, orig_disk)) @@ -7918,7 +7918,7 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm, 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) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, true) = < 0) return -1; } =20 @@ -7928,7 +7928,7 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm, 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) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, true) = < 0) return -1; } =20 @@ -8383,7 +8383,7 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, } =20 oldDev.data.disk =3D vmdef->disks[pos]; - if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev, false) < 0) return -1; =20 virDomainDiskDefFree(vmdef->disks[pos]); @@ -8402,7 +8402,7 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, } =20 oldDev.data.graphics =3D vmdef->graphics[pos]; - if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev, false) < 0) return -1; =20 virDomainGraphicsDefFree(vmdef->graphics[pos]); @@ -8416,7 +8416,7 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, return -1; =20 oldDev.data.net =3D vmdef->nets[pos]; - if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev, false) < 0) return -1; =20 virDomainNetDefFree(vmdef->nets[pos]); @@ -8507,7 +8507,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr v= m, if (!vmdef) goto cleanup; =20 - if (virDomainDefCompatibleDevice(vmdef, dev, NULL) < 0) + if (virDomainDefCompatibleDevice(vmdef, dev, NULL, false) < 0) goto cleanup; if ((ret =3D qemuDomainAttachDeviceConfig(vmdef, dev, caps, parse_flags, @@ -8516,7 +8516,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr v= m, } =20 if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virDomainDefCompatibleDevice(vm->def, dev_copy, NULL) < 0) + if (virDomainDefCompatibleDevice(vm->def, dev_copy, NULL, true) < = 0) goto cleanup; =20 if ((ret =3D qemuDomainAttachDeviceLive(vm, dev_copy, driver)) < 0) --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list