]> xenbits.xensource.com Git - libvirt.git/commitdiff
network: only clear bandwidth if it has been set
authorLaine Stump <laine@laine.org>
Tue, 24 Feb 2015 17:12:56 +0000 (12:12 -0500)
committerLaine Stump <laine@laine.org>
Wed, 25 Feb 2015 18:09:34 +0000 (13:09 -0500)
libvirt was unconditionally calling virNetDevBandwidthClear() for
every interface (and network bridge) of a type that supported
bandwidth, whether it actually had anything set or not. This doesn't
hurt anything (unless ifname == NULL!), but is wasteful.

This patch makes sure that all calls to virNetDevBandwidthClear() are
qualified by checking that the interface really had some bandwidth
setup done, and checks for a null ifname inside
virNetDevBandwidthClear(), silently returning success if it is null
(as well as removing the ATTRIBUTE_NONNULL from that function's
prototype, since we can't guarantee that it is never null,
e.g. sometimes a type='ethernet' interface has no ifname as it is
provided on the fly by qemu).

src/conf/netdev_bandwidth_conf.c
src/lxc/lxc_driver.c
src/network/bridge_driver.c
src/qemu/qemu_hotplug.c
src/util/virnetdevbandwidth.c
src/util/virnetdevbandwidth.h

index c3e0f9f14af59a87197d4de2bf412d6bbdf4e715..fdd5b7faa65cf685fa9c2d278ff6d71dce2ff2e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2014 Red Hat, Inc.
+ * Copyright (C) 2009-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -285,7 +285,8 @@ virDomainClearNetBandwidth(virDomainObjPtr vm)
 
     for (i = 0; i < vm->def->nnets; i++) {
         type = virDomainNetGetActualType(vm->def->nets[i]);
-        if (virNetDevSupportBandwidth(type))
+        if (virDomainNetGetActualBandwidth(vm->def->nets[i]) &&
+            virNetDevSupportBandwidth(type))
             virNetDevBandwidthClear(vm->def->nets[i]->ifname);
     }
 }
index 3adb21db8acd7960727d42a089875846cb702170..3a28dd55e3123b4989017328ff27f685944e3bd7 100644 (file)
@@ -4650,7 +4650,8 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
     actualType = virDomainNetGetActualType(detach);
 
     /* clear network bandwidth */
-    if (virNetDevSupportBandwidth(actualType) &&
+    if (virDomainNetGetActualBandwidth(detach) &&
+        virNetDevSupportBandwidth(actualType) &&
         virNetDevBandwidthClear(detach->ifname))
         goto cleanup;
 
index f240d3bae5a1ad77af40a804206c6cb4fed77dde..1209609a9f71e1277e7f879fb04e86e69e66c1a6 100644 (file)
@@ -2096,7 +2096,8 @@ networkStartNetworkVirtual(virNetworkObjPtr network)
     return 0;
 
  err5:
-    virNetDevBandwidthClear(network->def->bridge);
+    if (network->def->bandwidth)
+       virNetDevBandwidthClear(network->def->bridge);
 
  err4:
     if (!save_err)
@@ -2142,7 +2143,8 @@ networkStartNetworkVirtual(virNetworkObjPtr network)
 
 static int networkShutdownNetworkVirtual(virNetworkObjPtr network)
 {
-    virNetDevBandwidthClear(network->def->bridge);
+    if (network->def->bandwidth)
+        virNetDevBandwidthClear(network->def->bridge);
 
     if (network->radvdPid > 0) {
         char *radvdpidbase;
index 8691c7e8f19aa1358c7303c8a6bb40cfe51e4a33..51f3573f0953bfd666fd9d2765f815f3836261ba 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * qemu_hotplug.c: QEMU device hotplug management
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2015 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -3750,7 +3750,8 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
             goto cleanup;
     }
 
-    if (virNetDevSupportBandwidth(virDomainNetGetActualType(detach)) &&
+    if (virDomainNetGetActualBandwidth(detach) &&
+        virNetDevSupportBandwidth(virDomainNetGetActualType(detach)) &&
         virNetDevBandwidthClear(detach->ifname) < 0)
         VIR_WARN("cannot clear bandwidth setting for device : %s",
                  detach->ifname);
index fbd2a8ddc3be844a2663e098f525e9efb80807f0..c8a90c85227b8feeeb2605ff159acfdeddf605d1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2014 Red Hat, Inc.
+ * Copyright (C) 2009-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -268,6 +268,9 @@ virNetDevBandwidthClear(const char *ifname)
     int dummy; /* for ignoring the exit status */
     virCommandPtr cmd = NULL;
 
+    if (!ifname)
+       return 0;
+
     cmd = virCommandNew(TC);
     virCommandAddArgList(cmd, "qdisc", "del", "dev", ifname, "root", NULL);
 
index 4606a07526408c4a64008d3628f27008e4025342..de289dbe04b6e8ff4369b05a3572a3048c772371 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2013 Red Hat, Inc.
+ * Copyright (C) 2009-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -47,8 +47,7 @@ int virNetDevBandwidthSet(const char *ifname,
                           virNetDevBandwidthPtr bandwidth,
                           bool hierarchical_class)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
-int virNetDevBandwidthClear(const char *ifname)
-    ATTRIBUTE_NONNULL(1);
+int virNetDevBandwidthClear(const char *ifname);
 int virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
                            const virNetDevBandwidth *src)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;