render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
147b37
From 7164bcc8bec5165de244a74f32ca1469c7091d2d Mon Sep 17 00:00:00 2001
147b37
Message-Id: <7164bcc8bec5165de244a74f32ca1469c7091d2d@dist-git>
147b37
From: Jiri Denemark <jdenemar@redhat.com>
147b37
Date: Thu, 22 Feb 2018 13:30:27 +0100
147b37
Subject: [PATCH] Pass oldDev to virDomainDefCompatibleDevice on device update
147b37
MIME-Version: 1.0
147b37
Content-Type: text/plain; charset=UTF-8
147b37
Content-Transfer-Encoding: 8bit
147b37
147b37
When calling virDomainDefCompatibleDevice to check a new device during
147b37
device update, we need to pass the original device which is going to be
147b37
updated in addition to the new device. Otherwise, the function can
147b37
report false conflicts.
147b37
147b37
The new argument is currently ignored by virDomainDefCompatibleDevice,
147b37
but this will change in the following patch.
147b37
147b37
https://bugzilla.redhat.com/show_bug.cgi?id=1546971
147b37
147b37
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
147b37
(cherry picked from commit b6a264e8550d4add3946ec2fd9ae31a76fbf16fe)
147b37
147b37
https://bugzilla.redhat.com/show_bug.cgi?id=1557922
147b37
147b37
Conflicts:
147b37
	src/qemu/qemu_driver.c -- context, qemuDomainUpdateDeviceLive
147b37
            requires connection pointer in RHEL
147b37
147b37
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
147b37
Reviewed-by: Ján Tomko <jtomko@redhat.com>
147b37
---
147b37
 src/conf/domain_conf.c |  3 ++-
147b37
 src/conf/domain_conf.h |  3 ++-
147b37
 src/lxc/lxc_driver.c   | 15 ++++++++-----
147b37
 src/qemu/qemu_driver.c | 51 +++++++++++++++++++++++++++++++++---------
147b37
 4 files changed, 54 insertions(+), 18 deletions(-)
147b37
147b37
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
147b37
index 031d4b8e55..e9bba70057 100644
147b37
--- a/src/conf/domain_conf.c
147b37
+++ b/src/conf/domain_conf.c
147b37
@@ -27185,7 +27185,8 @@ virDomainDeviceInfoCheckBootIndex(virDomainDefPtr def ATTRIBUTE_UNUSED,
147b37
 
147b37
 int
147b37
 virDomainDefCompatibleDevice(virDomainDefPtr def,
147b37
-                             virDomainDeviceDefPtr dev)
147b37
+                             virDomainDeviceDefPtr dev,
147b37
+                             virDomainDeviceDefPtr oldDev ATTRIBUTE_UNUSED)
147b37
 {
147b37
     virDomainDeviceInfoPtr info = virDomainDeviceGetInfo(dev);
147b37
 
147b37
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
147b37
index 3817887322..fb09496e89 100644
147b37
--- a/src/conf/domain_conf.h
147b37
+++ b/src/conf/domain_conf.h
147b37
@@ -3006,7 +3006,8 @@ typedef enum {
147b37
 } virDomainDeviceAction;
147b37
 
147b37
 int virDomainDefCompatibleDevice(virDomainDefPtr def,
147b37
-                                 virDomainDeviceDefPtr dev);
147b37
+                                 virDomainDeviceDefPtr dev,
147b37
+                                 virDomainDeviceDefPtr oldDev);
147b37
 
147b37
 void virDomainRNGDefFree(virDomainRNGDefPtr def);
147b37
 
147b37
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
147b37
index 7829ef8618..fe2405d08b 100644
147b37
--- a/src/lxc/lxc_driver.c
147b37
+++ b/src/lxc/lxc_driver.c
147b37
@@ -3579,6 +3579,7 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
147b37
 {
147b37
     int ret = -1;
147b37
     virDomainNetDefPtr net;
147b37
+    virDomainDeviceDef oldDev = { .type = dev->type };
147b37
     int idx;
147b37
 
147b37
     switch (dev->type) {
147b37
@@ -3587,8 +3588,11 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
147b37
         if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
147b37
             goto cleanup;
147b37
 
147b37
-        virDomainNetDefFree(vmdef->nets[idx]);
147b37
+        oldDev.data.net = vmdef->nets[idx];
147b37
+        if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev) < 0)
147b37
+            return -1;
147b37
 
147b37
+        virDomainNetDefFree(vmdef->nets[idx]);
147b37
         vmdef->nets[idx] = net;
147b37
         dev->data.net = NULL;
147b37
         ret = 0;
147b37
@@ -4791,7 +4795,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
147b37
         if (!vmdef)
147b37
             goto endjob;
147b37
 
147b37
-        if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
147b37
+        if (virDomainDefCompatibleDevice(vmdef, dev, NULL) < 0)
147b37
             goto endjob;
147b37
 
147b37
         if ((ret = lxcDomainAttachDeviceConfig(vmdef, dev)) < 0)
147b37
@@ -4799,7 +4803,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
147b37
     }
147b37
 
147b37
     if (flags & VIR_DOMAIN_AFFECT_LIVE) {
147b37
-        if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
147b37
+        if (virDomainDefCompatibleDevice(vm->def, dev_copy, NULL) < 0)
147b37
             goto endjob;
147b37
 
147b37
         if ((ret = lxcDomainAttachDeviceLive(dom->conn, driver, vm, dev_copy)) < 0)
147b37
@@ -4902,9 +4906,8 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
147b37
         if (!vmdef)
147b37
             goto endjob;
147b37
 
147b37
-        if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
147b37
-            goto endjob;
147b37
-
147b37
+        /* virDomainDefCompatibleDevice call is delayed until we know the
147b37
+         * device we're going to update. */
147b37
         if ((ret = lxcDomainUpdateDeviceConfig(vmdef, dev)) < 0)
147b37
             goto endjob;
147b37
     }
147b37
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
147b37
index b8022a06ba..3bd2d983a2 100644
147b37
--- a/src/qemu/qemu_driver.c
147b37
+++ b/src/qemu/qemu_driver.c
147b37
@@ -7830,6 +7830,7 @@ qemuDomainChangeDiskLive(virConnectPtr conn,
147b37
 {
147b37
     virDomainDiskDefPtr disk = dev->data.disk;
147b37
     virDomainDiskDefPtr orig_disk = NULL;
147b37
+    virDomainDeviceDef oldDev = { .type = dev->type };
147b37
     int ret = -1;
147b37
 
147b37
     if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
147b37
@@ -7847,6 +7848,10 @@ qemuDomainChangeDiskLive(virConnectPtr conn,
147b37
         goto cleanup;
147b37
     }
147b37
 
147b37
+    oldDev.data.disk = orig_disk;
147b37
+    if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev) < 0)
147b37
+        goto cleanup;
147b37
+
147b37
     if (!qemuDomainDiskChangeSupported(disk, orig_disk))
147b37
         goto cleanup;
147b37
 
147b37
@@ -7890,19 +7895,36 @@ qemuDomainUpdateDeviceLive(virConnectPtr conn,
147b37
                            bool force)
147b37
 {
147b37
     virQEMUDriverPtr driver = dom->conn->privateData;
147b37
+    virDomainDeviceDef oldDev = { .type = dev->type };
147b37
     int ret = -1;
147b37
+    int idx;
147b37
 
147b37
     switch ((virDomainDeviceType) dev->type) {
147b37
     case VIR_DOMAIN_DEVICE_DISK:
147b37
         qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL);
147b37
         ret = qemuDomainChangeDiskLive(conn, vm, dev, driver, force);
147b37
         break;
147b37
+
147b37
     case VIR_DOMAIN_DEVICE_GRAPHICS:
147b37
+        if ((idx = qemuDomainFindGraphicsIndex(vm->def, dev->data.graphics) >= 0)) {
147b37
+            oldDev.data.graphics = vm->def->graphics[idx];
147b37
+            if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev) < 0)
147b37
+                return -1;
147b37
+        }
147b37
+
147b37
         ret = qemuDomainChangeGraphics(driver, vm, dev->data.graphics);
147b37
         break;
147b37
+
147b37
     case VIR_DOMAIN_DEVICE_NET:
147b37
+        if ((idx = virDomainNetFindIdx(vm->def, dev->data.net)) >= 0) {
147b37
+            oldDev.data.net = vm->def->nets[idx];
147b37
+            if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev) < 0)
147b37
+                return -1;
147b37
+        }
147b37
+
147b37
         ret = qemuDomainChangeNet(driver, vm, dev);
147b37
         break;
147b37
+
147b37
     case VIR_DOMAIN_DEVICE_FS:
147b37
     case VIR_DOMAIN_DEVICE_INPUT:
147b37
     case VIR_DOMAIN_DEVICE_SOUND:
147b37
@@ -8317,6 +8339,7 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
147b37
     virDomainDiskDefPtr newDisk;
147b37
     virDomainGraphicsDefPtr newGraphics;
147b37
     virDomainNetDefPtr net;
147b37
+    virDomainDeviceDef oldDev = { .type = dev->type };
147b37
     int pos;
147b37
 
147b37
     switch ((virDomainDeviceType) dev->type) {
147b37
@@ -8328,6 +8351,10 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
147b37
             return -1;
147b37
         }
147b37
 
147b37
+        oldDev.data.disk = vmdef->disks[pos];
147b37
+        if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev) < 0)
147b37
+            return -1;
147b37
+
147b37
         virDomainDiskDefFree(vmdef->disks[pos]);
147b37
         vmdef->disks[pos] = newDisk;
147b37
         dev->data.disk = NULL;
147b37
@@ -8343,8 +8370,11 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
147b37
             return -1;
147b37
         }
147b37
 
147b37
-        virDomainGraphicsDefFree(vmdef->graphics[pos]);
147b37
+        oldDev.data.graphics = vmdef->graphics[pos];
147b37
+        if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev) < 0)
147b37
+            return -1;
147b37
 
147b37
+        virDomainGraphicsDefFree(vmdef->graphics[pos]);
147b37
         vmdef->graphics[pos] = newGraphics;
147b37
         dev->data.graphics = NULL;
147b37
         break;
147b37
@@ -8354,8 +8384,11 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
147b37
         if ((pos = virDomainNetFindIdx(vmdef, net)) < 0)
147b37
             return -1;
147b37
 
147b37
-        virDomainNetDefFree(vmdef->nets[pos]);
147b37
+        oldDev.data.net = vmdef->nets[pos];
147b37
+        if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev) < 0)
147b37
+            return -1;
147b37
 
147b37
+        virDomainNetDefFree(vmdef->nets[pos]);
147b37
         vmdef->nets[pos] = net;
147b37
         dev->data.net = NULL;
147b37
         break;
147b37
@@ -8443,7 +8476,7 @@ qemuDomainAttachDeviceLiveAndConfig(virConnectPtr conn,
147b37
         if (!vmdef)
147b37
             goto cleanup;
147b37
 
147b37
-        if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
147b37
+        if (virDomainDefCompatibleDevice(vmdef, dev, NULL) < 0)
147b37
             goto cleanup;
147b37
         if ((ret = qemuDomainAttachDeviceConfig(vmdef, dev, conn, caps,
147b37
                                                 parse_flags,
147b37
@@ -8452,7 +8485,7 @@ qemuDomainAttachDeviceLiveAndConfig(virConnectPtr conn,
147b37
     }
147b37
 
147b37
     if (flags & VIR_DOMAIN_AFFECT_LIVE) {
147b37
-        if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
147b37
+        if (virDomainDefCompatibleDevice(vm->def, dev_copy, NULL) < 0)
147b37
             goto cleanup;
147b37
 
147b37
         if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, conn, driver)) < 0)
147b37
@@ -8592,9 +8625,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
147b37
         if (!vmdef)
147b37
             goto endjob;
147b37
 
147b37
-        if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
147b37
-            goto endjob;
147b37
-
147b37
+        /* virDomainDefCompatibleDevice call is delayed until we know the
147b37
+         * device we're going to update. */
147b37
         if ((ret = qemuDomainUpdateDeviceConfig(vmdef, dev, caps,
147b37
                                                 parse_flags,
147b37
                                                 driver->xmlopt)) < 0)
147b37
@@ -8602,9 +8634,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
147b37
     }
147b37
 
147b37
     if (flags & VIR_DOMAIN_AFFECT_LIVE) {
147b37
-        if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
147b37
-            goto endjob;
147b37
-
147b37
+        /* virDomainDefCompatibleDevice call is delayed until we know the
147b37
+         * device we're going to update. */
147b37
         if ((ret = qemuDomainUpdateDeviceLive(dom->conn, vm, dev_copy, dom, force)) < 0)
147b37
             goto endjob;
147b37
         /*
147b37
-- 
147b37
2.17.0
147b37