[libvirt] [PATCH] lib: Preserve error around virDomainNetReleaseActualDevice()

Michal Privoznik posted 1 patch 12 weeks ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/aae6b610a5599e2607a6635b8403ca8867b2f90a.1556635334.git.mprivozn@redhat.com
src/libxl/libxl_driver.c | 6 ++++++
src/lxc/lxc_driver.c     | 3 +++
src/lxc/lxc_process.c    | 3 +++
src/qemu/qemu_hotplug.c  | 6 ++++++
4 files changed, 18 insertions(+)

[libvirt] [PATCH] lib: Preserve error around virDomainNetReleaseActualDevice()

Posted by Michal Privoznik 12 weeks ago
This function is calling public API virNetworkLookupByName()
which resets the error. Therefore, if
virDomainNetReleaseActualDevice() is used in cleanup path it
actually resets the original error that got us jump into
'cleanup' label.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

I've found this issue when trying to change QoS on an domain's
<interface/> and I've intentionally entered @floor bigger than
corresponding network's average. Orders bigger.

I mean, with this change the QoS is still kind of broken [1] but at
least I'm getting some sensible error instead of "An error occurred, but
the cause is unknown".

1: Thing is, when an <interface type='network'/> is being updated (virsh
update-device) then a new interface is actually created
(virDomainNetAllocateActualDevice() is called), which is then set up and
the old interface is then released. This works in theory, but for a
fraction of a second we have two interfaces. Therefore the sum of their
@floor-s might exceed the limit (which is MAX(network average, network
peak)) and thus allocating new device will fail. Unfortunately, I don't
have any bright idea around this. Maybe temporary setting
newdev->bandwidth = NULL; then allocating new device and trying to set
new bandwidth ourselves? That is still going to fail until the old
interface is not released. Ideas are welcome.

 src/libxl/libxl_driver.c | 6 ++++++
 src/lxc/lxc_driver.c     | 3 +++
 src/lxc/lxc_process.c    | 3 +++
 src/qemu/qemu_hotplug.c  | 6 ++++++
 4 files changed, 18 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index e7234c1479..2b9c6f1866 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3380,6 +3380,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
     int ret = -1;
     char mac[VIR_MAC_STRING_BUFLEN];
     virConnectPtr conn = NULL;
+    virErrorPtr save_err = NULL;
 
     libxl_device_nic_init(&nic);
 
@@ -3440,6 +3441,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
     ret = 0;
 
  cleanup:
+    virErrorPreserveLast(&save_err);
     libxl_device_nic_dispose(&nic);
     if (!ret) {
         vm->def->nets[vm->def->nnets++] = net;
@@ -3450,6 +3452,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
     }
     virObjectUnref(conn);
     virObjectUnref(cfg);
+    virErrorRestore(&save_err);
     return ret;
 }
 
@@ -3838,6 +3841,7 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
     libxl_device_nic nic;
     char mac[VIR_MAC_STRING_BUFLEN];
     int ret = -1;
+    virErrorPtr save_err = NULL;
 
     libxl_device_nic_init(&nic);
 
@@ -3868,6 +3872,7 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
     ret = 0;
 
  cleanup:
+    virErrorPreserveLast(&save_err);
     libxl_device_nic_dispose(&nic);
     if (!ret) {
         if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
@@ -3882,6 +3887,7 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
         virDomainNetRemove(vm->def, detachidx);
     }
     virObjectUnref(cfg);
+    virErrorRestore(&save_err);
     return ret;
 }
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 1980d0804e..9db2a02dee 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -4337,6 +4337,7 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
     virDomainNetType actualType;
     virDomainNetDefPtr detach = NULL;
     virNetDevVPortProfilePtr vport = NULL;
+    virErrorPtr save_err = NULL;
 
     if ((detachidx = virDomainNetFindIdx(vm->def, dev->data.net)) < 0)
         goto cleanup;
@@ -4396,6 +4397,7 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
     ret = 0;
  cleanup:
     if (!ret) {
+        virErrorPreserveLast(&save_err);
         if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
             virConnectPtr conn = virGetConnectNetwork();
             if (conn) {
@@ -4407,6 +4409,7 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
         }
         virDomainNetRemove(vm->def, detachidx);
         virDomainNetDefFree(detach);
+        virErrorRestore(&save_err);
     }
     return ret;
 }
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 3a33418aca..de4d7c73fb 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -550,6 +550,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
     virDomainNetDefPtr net;
     virDomainNetType type;
     virConnectPtr netconn = NULL;
+    virErrorPtr save_err = NULL;
 
     if (VIR_ALLOC_N(*veths, def->nnets + 1) < 0)
         return -1;
@@ -642,6 +643,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
 
  cleanup:
     if (ret < 0) {
+        virErrorPreserveLast(&save_err);
         for (i = 0; i < def->nnets; i++) {
             virDomainNetDefPtr iface = def->nets[i];
             virNetDevVPortProfilePtr vport = virDomainNetGetActualVirtPortProfile(iface);
@@ -652,6 +654,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
             if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && netconn)
                 virDomainNetReleaseActualDevice(netconn, def, iface);
         }
+        virErrorRestore(&save_err);
     }
     virObjectUnref(netconn);
     return ret;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e199368e8a..f3c5f44a23 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1383,6 +1383,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     bool netdevPlugged = false;
     char *netdev_name;
     virConnectPtr conn = NULL;
+    virErrorPtr save_err = NULL;
 
     /* preallocate new slot for device */
     if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0)
@@ -1678,6 +1679,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     if (!ret) {
         vm->def->nets[vm->def->nnets++] = net;
     } else {
+        virErrorPreserveLast(&save_err);
         if (releaseaddr)
             qemuDomainReleaseDeviceAddress(vm, &net->info);
 
@@ -1706,6 +1708,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
             else
                 VIR_WARN("Unable to release network device '%s'", NULLSTR(net->ifname));
         }
+        virErrorRestore(&save_err);
     }
 
     VIR_FREE(nicstr);
@@ -3756,6 +3759,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
     int ret = -1;
     int changeidx = -1;
     virConnectPtr conn = NULL;
+    virErrorPtr save_err = NULL;
 
     if ((changeidx = virDomainNetFindIdx(vm->def, newdev)) < 0)
         goto cleanup;
@@ -4173,6 +4177,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
 
     ret = 0;
  cleanup:
+    virErrorPreserveLast(&save_err);
     /* When we get here, we will be in one of these two states:
      *
      * 1) newdev has been moved into the domain's list of nets and
@@ -4194,6 +4199,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
     if (newdev && newdev->type == VIR_DOMAIN_NET_TYPE_NETWORK && conn)
         virDomainNetReleaseActualDevice(conn, vm->def, newdev);
     virObjectUnref(conn);
+    virErrorRestore(&save_err);
 
     return ret;
 }
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] lib: Preserve error around virDomainNetReleaseActualDevice()

Posted by Peter Krempa 12 weeks ago
On Tue, Apr 30, 2019 at 16:51:12 +0200, Michal Privoznik wrote:
> This function is calling public API virNetworkLookupByName()
> which resets the error. Therefore, if
> virDomainNetReleaseActualDevice() is used in cleanup path it
> actually resets the original error that got us jump into
> 'cleanup' label.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---

ACK and safe for freeze.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list