Re: [libvirt] [PATCH-RFC-V2] qemu: Add network bandwidth setting for ethernet interfaces

2014-10-07 Thread Anirban Chakraborty


On 10/6/14, 3:43 AM, Michal Privoznik mpriv...@redhat.com wrote:

On 18.09.2014 01:33, Anirban Chakraborty wrote:
 V2:
 Consolidate calls to virNetDevBandwidthSet
 Clear bandwidth settings when the interface is detached or domain
destroyed

 V1:
 Ethernet interfaces in libvirt currently do not support bandwidth
setting.
 For example, following xml file for an interface will not apply these
 settings to corresponding qdiscs.

  interface type=ethernet
mac address=02:36:1d:18:2a:e4/
model type=virtio/
script path=/
target dev=tap361d182a-e4/
bandwidth
  inbound average=984 peak=1024 burst=64/
  outbound average=2000 peak=2048 burst=128/
/bandwidth
  /interface

 Signed-off-by: Anirban Chakraborty abc...@juniper.net
 ---
   src/conf/domain_conf.h  |  7 +++
   src/lxc/lxc_process.c   | 27 ++-
   src/qemu/qemu_command.c |  9 -
   src/qemu/qemu_driver.c  | 21 +
   src/qemu/qemu_hotplug.c | 13 +
   src/util/virnetdevmacvlan.c | 10 --
   src/util/virnetdevmacvlan.h |  1 -
   7 files changed, 59 insertions(+), 29 deletions(-)

 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
 index 640a4c5..3c950f1 100644
 --- a/src/conf/domain_conf.h
 +++ b/src/conf/domain_conf.h
 @@ -829,6 +829,13 @@ typedef enum {
   VIR_DOMAIN_NET_TYPE_LAST
   } virDomainNetType;

 +/* check bandwidth configuration for a network interface */
 +#define NETDEVIF_SUPPORT_BANDWIDTH(type) \
 +   ((type == VIR_DOMAIN_NET_TYPE_ETHERNET || \
 + type == VIR_DOMAIN_NET_TYPE_NETWORK  || \
 + type == VIR_DOMAIN_NET_TYPE_BRIDGE   || \
 + type == VIR_DOMAIN_NET_TYPE_DIRECT) ? true : false)
 +

I'd rather turn this into a function (possibly inline function).

Will do.


   /* the backend driver used for virtio interfaces */
   typedef enum {
   VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT, /* prefer kernel, fall back
to user */
 diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
 index ed30c37..5ef91e8 100644
 --- a/src/lxc/lxc_process.c
 +++ b/src/lxc/lxc_process.c
 @@ -274,11 +274,6 @@ char
*virLXCProcessSetupInterfaceBridged(virConnectPtr conn,
   if (virNetDevSetOnline(parentVeth, true)  0)
   goto cleanup;

 -if (virNetDevBandwidthSet(net-ifname,
 -  virDomainNetGetActualBandwidth(net),
 -  false)  0)
 -goto cleanup;
 -

Well, the virLXCProcessSetupInterfaceBridged is used elsewhere in the
code too. For instance after this patch the QoS is not applied on
interfaces hotplugged into an LXC container.

Thanks for pointing it out. I am taking care of it in my next patch.


   if (net-filter 
   virDomainConfNWFilterInstantiate(conn, vm-uuid, net)  0)
   goto cleanup;
 @@ -300,6 +295,7 @@ char
*virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
   virNetDevBandwidthPtr bw;
   virNetDevVPortProfilePtr prof;
   virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
 +const char *linkdev = virDomainNetGetActualDirectDev(net);

   /* XXX how todo bandwidth controls ?
* Since the 'net-ifname' is about to be moved to a different
 @@ -329,16 +325,15 @@ char
*virLXCProcessSetupInterfaceDirect(virConnectPtr conn,

   if (virNetDevMacVLanCreateWithVPortProfile(
   net-ifname, net-mac,
 -virDomainNetGetActualDirectDev(net),
 +linkdev,
   virDomainNetGetActualDirectMode(net),
   false, def-uuid,
 -virDomainNetGetActualVirtPortProfile(net),
 +prof,
   res_ifname,
   VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
   cfg-stateDir,
 -virDomainNetGetActualBandwidth(net), 0)  0)
 +0)  0)
   goto cleanup;
 -
   ret = res_ifname;

cleanup:
 @@ -368,6 +363,7 @@ static int
virLXCProcessSetupInterfaces(virConnectPtr conn,
   int ret = -1;
   size_t i;
   size_t niface = 0;
 +int actualType;

   for (i = 0; i  def-nnets; i++) {
   char *veth = NULL;
 @@ -381,7 +377,8 @@ static int
virLXCProcessSetupInterfaces(virConnectPtr conn,
   if (VIR_EXPAND_N(*veths, *nveths, 1)  0)
   goto cleanup;

 -switch (virDomainNetGetActualType(def-nets[i])) {
 +actualType = virDomainNetGetActualType(def-nets[i]);
 +switch (actualType) {
   case VIR_DOMAIN_NET_TYPE_NETWORK: {
   virNetworkPtr network;
   char *brname = NULL;
 @@ -444,11 +441,15 @@ static int
virLXCProcessSetupInterfaces(virConnectPtr conn,
   case VIR_DOMAIN_NET_TYPE_LAST:
   virReportError(VIR_ERR_INTERNAL_ERROR,
  _(Unsupported network type %s),
 -   virDomainNetTypeToString(
 -   virDomainNetGetActualType(def-nets[i])
 -   

Re: [libvirt] [PATCH-RFC-V2] qemu: Add network bandwidth setting for ethernet interfaces

2014-10-06 Thread Michal Privoznik

On 18.09.2014 01:33, Anirban Chakraborty wrote:

V2:
Consolidate calls to virNetDevBandwidthSet
Clear bandwidth settings when the interface is detached or domain destroyed

V1:
Ethernet interfaces in libvirt currently do not support bandwidth setting.
For example, following xml file for an interface will not apply these
settings to corresponding qdiscs.

 interface type=ethernet
   mac address=02:36:1d:18:2a:e4/
   model type=virtio/
   script path=/
   target dev=tap361d182a-e4/
   bandwidth
 inbound average=984 peak=1024 burst=64/
 outbound average=2000 peak=2048 burst=128/
   /bandwidth
 /interface

Signed-off-by: Anirban Chakraborty abc...@juniper.net
---
  src/conf/domain_conf.h  |  7 +++
  src/lxc/lxc_process.c   | 27 ++-
  src/qemu/qemu_command.c |  9 -
  src/qemu/qemu_driver.c  | 21 +
  src/qemu/qemu_hotplug.c | 13 +
  src/util/virnetdevmacvlan.c | 10 --
  src/util/virnetdevmacvlan.h |  1 -
  7 files changed, 59 insertions(+), 29 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 640a4c5..3c950f1 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -829,6 +829,13 @@ typedef enum {
  VIR_DOMAIN_NET_TYPE_LAST
  } virDomainNetType;

+/* check bandwidth configuration for a network interface */
+#define NETDEVIF_SUPPORT_BANDWIDTH(type) \
+   ((type == VIR_DOMAIN_NET_TYPE_ETHERNET || \
+ type == VIR_DOMAIN_NET_TYPE_NETWORK  || \
+ type == VIR_DOMAIN_NET_TYPE_BRIDGE   || \
+ type == VIR_DOMAIN_NET_TYPE_DIRECT) ? true : false)
+


I'd rather turn this into a function (possibly inline function).


  /* the backend driver used for virtio interfaces */
  typedef enum {
  VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT, /* prefer kernel, fall back to user 
*/
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index ed30c37..5ef91e8 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -274,11 +274,6 @@ char *virLXCProcessSetupInterfaceBridged(virConnectPtr 
conn,
  if (virNetDevSetOnline(parentVeth, true)  0)
  goto cleanup;

-if (virNetDevBandwidthSet(net-ifname,
-  virDomainNetGetActualBandwidth(net),
-  false)  0)
-goto cleanup;
-


Well, the virLXCProcessSetupInterfaceBridged is used elsewhere in the 
code too. For instance after this patch the QoS is not applied on 
interfaces hotplugged into an LXC container.



  if (net-filter 
  virDomainConfNWFilterInstantiate(conn, vm-uuid, net)  0)
  goto cleanup;
@@ -300,6 +295,7 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
  virNetDevBandwidthPtr bw;
  virNetDevVPortProfilePtr prof;
  virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+const char *linkdev = virDomainNetGetActualDirectDev(net);

  /* XXX how todo bandwidth controls ?
   * Since the 'net-ifname' is about to be moved to a different
@@ -329,16 +325,15 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr 
conn,

  if (virNetDevMacVLanCreateWithVPortProfile(
  net-ifname, net-mac,
-virDomainNetGetActualDirectDev(net),
+linkdev,
  virDomainNetGetActualDirectMode(net),
  false, def-uuid,
-virDomainNetGetActualVirtPortProfile(net),
+prof,
  res_ifname,
  VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
  cfg-stateDir,
-virDomainNetGetActualBandwidth(net), 0)  0)
+0)  0)
  goto cleanup;
-
  ret = res_ifname;

   cleanup:
@@ -368,6 +363,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
  int ret = -1;
  size_t i;
  size_t niface = 0;
+int actualType;

  for (i = 0; i  def-nnets; i++) {
  char *veth = NULL;
@@ -381,7 +377,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
  if (VIR_EXPAND_N(*veths, *nveths, 1)  0)
  goto cleanup;

-switch (virDomainNetGetActualType(def-nets[i])) {
+actualType = virDomainNetGetActualType(def-nets[i]);
+switch (actualType) {
  case VIR_DOMAIN_NET_TYPE_NETWORK: {
  virNetworkPtr network;
  char *brname = NULL;
@@ -444,11 +441,15 @@ static int virLXCProcessSetupInterfaces(virConnectPtr 
conn,
  case VIR_DOMAIN_NET_TYPE_LAST:
  virReportError(VIR_ERR_INTERNAL_ERROR,
 _(Unsupported network type %s),
-   virDomainNetTypeToString(
-   virDomainNetGetActualType(def-nets[i])
-   ));
+   virDomainNetTypeToString(actualType));
  goto cleanup;
  }
+/* set network bandwidth */
+if (NETDEVIF_SUPPORT_BANDWIDTH(actualType)  virNetDevBandwidthSet(
+

Re: [libvirt] [PATCH-RFC-V2] qemu: Add network bandwidth setting for ethernet interfaces

2014-09-22 Thread Anirban Chakraborty

On 9/17/14, 4:33 PM, Anirban Chakraborty abc...@juniper.net wrote:

V2:
Consolidate calls to virNetDevBandwidthSet
Clear bandwidth settings when the interface is detached or domain
destroyed

V1:
Ethernet interfaces in libvirt currently do not support bandwidth setting.
For example, following xml file for an interface will not apply these
settings to corresponding qdiscs.

interface type=ethernet
  mac address=02:36:1d:18:2a:e4/
  model type=virtio/
  script path=/
  target dev=tap361d182a-e4/
  bandwidth
inbound average=984 peak=1024 burst=64/
outbound average=2000 peak=2048 burst=128/
  /bandwidth
/interface

Signed-off-by: Anirban Chakraborty abc...@juniper.net

Please let me know if this patch needs more work or ready to merge. Thanks
much.

Anirban

---
 src/conf/domain_conf.h  |  7 +++
 src/lxc/lxc_process.c   | 27 ++-
 src/qemu/qemu_command.c |  9 -
 src/qemu/qemu_driver.c  | 21 +
 src/qemu/qemu_hotplug.c | 13 +
 src/util/virnetdevmacvlan.c | 10 --
 src/util/virnetdevmacvlan.h |  1 -
 7 files changed, 59 insertions(+), 29 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 640a4c5..3c950f1 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -829,6 +829,13 @@ typedef enum {
 VIR_DOMAIN_NET_TYPE_LAST
 } virDomainNetType;

+/* check bandwidth configuration for a network interface */
+#define NETDEVIF_SUPPORT_BANDWIDTH(type) \
+   ((type == VIR_DOMAIN_NET_TYPE_ETHERNET || \
+ type == VIR_DOMAIN_NET_TYPE_NETWORK  || \
+ type == VIR_DOMAIN_NET_TYPE_BRIDGE   || \
+ type == VIR_DOMAIN_NET_TYPE_DIRECT) ? true : false)
+
 /* the backend driver used for virtio interfaces */
 typedef enum {
 VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT, /* prefer kernel, fall back to
user */
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index ed30c37..5ef91e8 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -274,11 +274,6 @@ char
*virLXCProcessSetupInterfaceBridged(virConnectPtr conn,
 if (virNetDevSetOnline(parentVeth, true)  0)
 goto cleanup;

-if (virNetDevBandwidthSet(net-ifname,
-  virDomainNetGetActualBandwidth(net),
-  false)  0)
-goto cleanup;
-
 if (net-filter 
 virDomainConfNWFilterInstantiate(conn, vm-uuid, net)  0)
 goto cleanup;
@@ -300,6 +295,7 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr
conn,
 virNetDevBandwidthPtr bw;
 virNetDevVPortProfilePtr prof;
 virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+const char *linkdev = virDomainNetGetActualDirectDev(net);

 /* XXX how todo bandwidth controls ?
  * Since the 'net-ifname' is about to be moved to a different
@@ -329,16 +325,15 @@ char
*virLXCProcessSetupInterfaceDirect(virConnectPtr conn,

 if (virNetDevMacVLanCreateWithVPortProfile(
 net-ifname, net-mac,
-virDomainNetGetActualDirectDev(net),
+linkdev,
 virDomainNetGetActualDirectMode(net),
 false, def-uuid,
-virDomainNetGetActualVirtPortProfile(net),
+prof,
 res_ifname,
 VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
 cfg-stateDir,
-virDomainNetGetActualBandwidth(net), 0)  0)
+0)  0)
 goto cleanup;
-
 ret = res_ifname;

  cleanup:
@@ -368,6 +363,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr
conn,
 int ret = -1;
 size_t i;
 size_t niface = 0;
+int actualType;

 for (i = 0; i  def-nnets; i++) {
 char *veth = NULL;
@@ -381,7 +377,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr
conn,
 if (VIR_EXPAND_N(*veths, *nveths, 1)  0)
 goto cleanup;

-switch (virDomainNetGetActualType(def-nets[i])) {
+actualType = virDomainNetGetActualType(def-nets[i]);
+switch (actualType) {
 case VIR_DOMAIN_NET_TYPE_NETWORK: {
 virNetworkPtr network;
 char *brname = NULL;
@@ -444,11 +441,15 @@ static int
virLXCProcessSetupInterfaces(virConnectPtr conn,
 case VIR_DOMAIN_NET_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
_(Unsupported network type %s),
-   virDomainNetTypeToString(
-   virDomainNetGetActualType(def-nets[i])
-   ));
+   virDomainNetTypeToString(actualType));
 goto cleanup;
 }
+/* set network bandwidth */
+if (NETDEVIF_SUPPORT_BANDWIDTH(actualType) 
virNetDevBandwidthSet(
+def-nets[i]-ifname, virDomainNetGetActualBandwidth(
+def-nets[i]),
+false)  0)
+   goto cleanup;

 (*veths)[(*nveths)-1] = veth;

diff --git