Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-11-12 Thread Anirban Chakraborty


On 11/12/14, 2:53 AM, "Michal Privoznik"  wrote:

>On 11.11.2014 23:45, Anirban Chakraborty wrote:
>> 
>> 
>> On 11/10/14, 3:13 PM, "Eric Blake"  wrote:
>> 
>>> On 11/10/2014 03:41 PM, Anirban Chakraborty wrote:
>>>
> BTW: it would be nice if you can version you patches. I mean, this is
> what, 4th or 5th version? Say that in subject explicitly please. You
> know, in the prefix: [PATCH v5] network: ...
>>>
>>> Using 'git send-email -v5' will do that for you.
>> 
>> Thanks.
>>>

 I was doing it earlier and then dropped it. I¹ll resin the patch
 addressing all your comments and send it out. However, please let me
 know
 if I should move the above functions (virNetDevBandwidthSet etc.) in
 src/util/virnetdevbandwidth.* and add #include "conf/domain_conf.h" in
 virnetdevbandwidth.h file.
>>>
>>> If it needs to reference structs defined in conf/, then the logical
>>> place for the functions is in conf/ (possibly a new file).  That way,
>>>it
>>> can still be shared between lxc and qemu.
>> 
>> I’m planning to have this function in src/conf/netdev_bandwidth_conf.*,
>> however, an initial compilation yields following undefined reference
>>from
>> qemu_process.c:
>> 
>> Making all in tests
>> make[2]: Entering directory `/home/ubuntu/libvirt-ups/tests'
>>CCLD domaincapstest
>> 
>>../src/.libs/libvirt_driver_qemu_impl.a(libvirt_driver_qemu_impl_la-qemu_
>>pr
>> ocess.o): In function `qemuProcessStop':
>> /home/ubuntu/libvirt-ups/src/qemu/qemu_process.c:4847: undefined
>>reference
>> to `virDomainClearNetBandwidth'
>> collect2: error: ld returned 1 exit status
>> 
>
>This message comes from the linker. So you're not exporting the
>virDomainClearNetBandwidth anywhere. I mean, you need to add it to the
>src/libvirt_private.syms and the error will go away.

Thanks a lot for the tip. It works now. I wasn’t aware of the existence of
a symbol export file.

Anirban


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

Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-11-12 Thread Michal Privoznik
On 11.11.2014 23:45, Anirban Chakraborty wrote:
> 
> 
> On 11/10/14, 3:13 PM, "Eric Blake"  wrote:
> 
>> On 11/10/2014 03:41 PM, Anirban Chakraborty wrote:
>>
 BTW: it would be nice if you can version you patches. I mean, this is
 what, 4th or 5th version? Say that in subject explicitly please. You
 know, in the prefix: [PATCH v5] network: ...
>>
>> Using 'git send-email -v5' will do that for you.
> 
> Thanks.
>>
>>>
>>> I was doing it earlier and then dropped it. I¹ll resin the patch
>>> addressing all your comments and send it out. However, please let me
>>> know
>>> if I should move the above functions (virNetDevBandwidthSet etc.) in
>>> src/util/virnetdevbandwidth.* and add #include "conf/domain_conf.h" in
>>> virnetdevbandwidth.h file.
>>
>> If it needs to reference structs defined in conf/, then the logical
>> place for the functions is in conf/ (possibly a new file).  That way, it
>> can still be shared between lxc and qemu.
> 
> I’m planning to have this function in src/conf/netdev_bandwidth_conf.*,
> however, an initial compilation yields following undefined reference from
> qemu_process.c:
> 
> Making all in tests
> make[2]: Entering directory `/home/ubuntu/libvirt-ups/tests'
>CCLD domaincapstest
> ../src/.libs/libvirt_driver_qemu_impl.a(libvirt_driver_qemu_impl_la-qemu_pr
> ocess.o): In function `qemuProcessStop':
> /home/ubuntu/libvirt-ups/src/qemu/qemu_process.c:4847: undefined reference
> to `virDomainClearNetBandwidth'
> collect2: error: ld returned 1 exit status
> 

This message comes from the linker. So you're not exporting the
virDomainClearNetBandwidth anywhere. I mean, you need to add it to the
src/libvirt_private.syms and the error will go away.

Michal

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

Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-11-11 Thread Eric Blake
On 11/11/2014 08:01 PM, Chen, Hanxiao wrote:
> 
> 
>> -Original Message-
>> From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
>> On Behalf Of Eric Blake
>> Sent: Tuesday, November 11, 2014 7:13 AM
>> To: Anirban Chakraborty; Michal Privoznik; libvir-list@redhat.com
>> Subject: Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet
>> interface
>>
>> On 11/10/2014 03:41 PM, Anirban Chakraborty wrote:
>>
>>>> BTW: it would be nice if you can version you patches. I mean, this is
>>>> what, 4th or 5th version? Say that in subject explicitly please. You
>>>> know, in the prefix: [PATCH v5] network: ...
>>
>> Using 'git send-email -v5' will do that for you.
> 
> Should it be 'git format-patch -v5'?

Either one.  git send-email understands ALL options of git format-patch
(I hate that the man page doesn't mention it, and have even reported
that to upstream git developers, but so far it's fallen on deaf ears as
a low-priority patch that no one has time to write).

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-11-11 Thread Chen, Hanxiao


> -Original Message-
> From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
> On Behalf Of Eric Blake
> Sent: Tuesday, November 11, 2014 7:13 AM
> To: Anirban Chakraborty; Michal Privoznik; libvir-list@redhat.com
> Subject: Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet
> interface
> 
> On 11/10/2014 03:41 PM, Anirban Chakraborty wrote:
> 
> >> BTW: it would be nice if you can version you patches. I mean, this is
> >> what, 4th or 5th version? Say that in subject explicitly please. You
> >> know, in the prefix: [PATCH v5] network: ...
> 
> Using 'git send-email -v5' will do that for you.

Should it be 'git format-patch -v5'?

Thanks,

- Chen

> 
> >
> > I was doing it earlier and then dropped it. I¹ll resin the patch
> > addressing all your comments and send it out. However, please let me know
> > if I should move the above functions (virNetDevBandwidthSet etc.) in
> > src/util/virnetdevbandwidth.* and add #include "conf/domain_conf.h" in
> > virnetdevbandwidth.h file.
> 
> If it needs to reference structs defined in conf/, then the logical
> place for the functions is in conf/ (possibly a new file).  That way, it
> can still be shared between lxc and qemu.
> 
> --
> Eric Blake   eblake redhat com+1-919-301-3266
> Libvirt virtualization library http://libvirt.org


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

Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-11-11 Thread Anirban Chakraborty


On 11/10/14, 3:13 PM, "Eric Blake"  wrote:

>On 11/10/2014 03:41 PM, Anirban Chakraborty wrote:
>
>>> BTW: it would be nice if you can version you patches. I mean, this is
>>> what, 4th or 5th version? Say that in subject explicitly please. You
>>> know, in the prefix: [PATCH v5] network: ...
>
>Using 'git send-email -v5' will do that for you.

Thanks.
>
>> 
>> I was doing it earlier and then dropped it. I¹ll resin the patch
>> addressing all your comments and send it out. However, please let me
>>know
>> if I should move the above functions (virNetDevBandwidthSet etc.) in
>> src/util/virnetdevbandwidth.* and add #include "conf/domain_conf.h" in
>> virnetdevbandwidth.h file.
>
>If it needs to reference structs defined in conf/, then the logical
>place for the functions is in conf/ (possibly a new file).  That way, it
>can still be shared between lxc and qemu.

I’m planning to have this function in src/conf/netdev_bandwidth_conf.*,
however, an initial compilation yields following undefined reference from
qemu_process.c:

Making all in tests
make[2]: Entering directory `/home/ubuntu/libvirt-ups/tests'
  CCLD domaincapstest
../src/.libs/libvirt_driver_qemu_impl.a(libvirt_driver_qemu_impl_la-qemu_pr
ocess.o): In function `qemuProcessStop':
/home/ubuntu/libvirt-ups/src/qemu/qemu_process.c:4847: undefined reference
to `virDomainClearNetBandwidth'
collect2: error: ld returned 1 exit status


What am I missing here? All I did was to add virDomainClearNetBandwidth()
to netdev_bandwidth_conf.c (and to .h for function prototype). I have
tried moving this function to domain_conf.c as well, however, didn’t see
any difference in behavior. All other functions from
netdev_bandwidth_conf.c/domain_conf.c are perfectly visible during
compilation.
I have attached the full patch.

Thanks,
Anirban



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

Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-11-10 Thread Eric Blake
On 11/10/2014 03:41 PM, Anirban Chakraborty wrote:

>> BTW: it would be nice if you can version you patches. I mean, this is
>> what, 4th or 5th version? Say that in subject explicitly please. You
>> know, in the prefix: [PATCH v5] network: ...

Using 'git send-email -v5' will do that for you.

> 
> I was doing it earlier and then dropped it. I¹ll resin the patch
> addressing all your comments and send it out. However, please let me know
> if I should move the above functions (virNetDevBandwidthSet etc.) in
> src/util/virnetdevbandwidth.* and add #include "conf/domain_conf.h" in
> virnetdevbandwidth.h file.

If it needs to reference structs defined in conf/, then the logical
place for the functions is in conf/ (possibly a new file).  That way, it
can still be shared between lxc and qemu.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-11-10 Thread Anirban Chakraborty


On 11/3/14, 2:58 AM, "Michal Privoznik"  wrote:

>On 30.10.2014 00:56, Anirban Chakraborty wrote:
>>
>>
>> +static inline bool virNetDevSupportBandwidth(virDomainNetType type)
>> +{
>> +switch (type) {
>> +case VIR_DOMAIN_NET_TYPE_BRIDGE:
>> +case VIR_DOMAIN_NET_TYPE_NETWORK:
>> +case VIR_DOMAIN_NET_TYPE_DIRECT:
>> +case VIR_DOMAIN_NET_TYPE_ETHERNET:
>> +return true;
>> +case VIR_DOMAIN_NET_TYPE_USER:
>> +case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
>> +case VIR_DOMAIN_NET_TYPE_SERVER:
>> +case VIR_DOMAIN_NET_TYPE_CLIENT:
>> +case VIR_DOMAIN_NET_TYPE_MCAST:
>> +case VIR_DOMAIN_NET_TYPE_INTERNAL:
>> +case VIR_DOMAIN_NET_TYPE_HOSTDEV:
>> +case VIR_DOMAIN_NET_TYPE_LAST:
>> +break;
>> +}
>> +return false;
>> +}
>> +
>
>I've got a feeling that this should go to src/util/virnetdevbandwidth*
>among with the rest of virNetDevBandwitdh functions.

I thought about moving this and the qemuDomainClearNetBandwidth() to
src/util/virnetdevbandwidth.h earlier, however, these functions need
reference to virDomainNetType and virDomainObjPtr which are defined in
conf/domain_conf.h and apparently src/util/*.h can not have any reference
to files from conf/.

>
>>   #endif /* __DOMAIN_CONF_H */
>> diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
>> index 979382b..8a21af4 100644
>> --- a/src/lxc/lxc_driver.c
>> +++ b/src/lxc/lxc_driver.c
>> @@ -72,6 +72,7 @@
>>   #include "viraccessapicheck.h"
>>   #include "viraccessapichecklxc.h"
>>   #include "virhostdev.h"
>> +#include "qemu/qemu_command.h"
>
>This is not allowed. In case somebody is building with LXC but without
>QEMU ..

Thanks for pointing it out.

>
>>
>>   #define VIR_FROM_THIS VIR_FROM_LXC
>>
>> @@ -4634,6 +4635,8 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
>>
>>   detach = vm->def->nets[detachidx];
>>
>> +qemuDomainClearNetBandwidth(vm);
>> +
>
>.. this is going to be an undefined reference.
>
>>   switch (virDomainNetGetActualType(detach)) {
>>   case VIR_DOMAIN_NET_TYPE_BRIDGE:
>>   case VIR_DOMAIN_NET_TYPE_NETWORK:
>> diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
>> index ed30c37..3192011 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;
>> -
>
>
>No, this function is called from two places:
>1) when domain is starting up
>2) on NIC hotplug
>
>you are covering 1) but removing already working 2). We can't lose that
>functionality.

Got it. Thanks.

>
>>   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,14 +325,13 @@ 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)
>> +cfg->stateDir, 0) < 0)
>>   goto cleanup;
>>
>
>Same comment applies here.

Thanks.

>
>>   ret = res_ifname;
>> @@ -450,6 +445,11 @@ static int
>>virLXCProcessSetupInterfaces(virConnectPtr conn,
>>   goto cleanup;
>>   }
>>
>> +/* set network bandwidth */
>> +if (virNetDevBandwidthSet(def->nets[i]->ifname,
>> +virDomainNetGetActualBandwidth(def->nets[i]), false) <
>>0)
>> +   goto cleanup;
>> +
>
>Shouldn't this be guarded with virNetDevSupportBandwidth()? The problem
>is, there's a switch() just before this where all the unsupported NIC
>types are rejected (ETHERNET is rejected too btw). What will come
>through is DIRECT type. I'm not saying that we should not set bandwidth
>there, but this patch aims at ethernet.

Agreed. Will take care of it next version of the patch.

>
>>   (*veths)[(*nveths)-1] = veth;
>>
>>   /* Make sure all net definitions will have a name in the
>>container */
>> diff --git

Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-11-03 Thread Michal Privoznik

On 30.10.2014 00:56, Anirban Chakraborty wrote:

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.

 
   
   
   
   
   
 
 
   
 

Signed-off-by: Anirban Chakraborty 
---
  src/conf/domain_conf.h  | 21 +
  src/lxc/lxc_driver.c|  3 +++
  src/lxc/lxc_process.c   | 18 +-
  src/qemu/qemu_command.c | 25 +++--
  src/qemu/qemu_command.h |  2 ++
  src/qemu/qemu_driver.c  |  3 +++
  src/qemu/qemu_hotplug.c | 12 
  src/qemu/qemu_process.c |  3 +++
  src/util/virnetdevmacvlan.c | 10 --
  src/util/virnetdevmacvlan.h |  1 -
  10 files changed, 72 insertions(+), 26 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9908d88..40e85d9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2848,4 +2848,25 @@ int virDomainObjSetMetadata(virDomainObjPtr vm,
  bool virDomainDefNeedsPlacementAdvice(virDomainDefPtr def)
  ATTRIBUTE_NONNULL(1);

+static inline bool virNetDevSupportBandwidth(virDomainNetType type)
+{
+switch (type) {
+case VIR_DOMAIN_NET_TYPE_BRIDGE:
+case VIR_DOMAIN_NET_TYPE_NETWORK:
+case VIR_DOMAIN_NET_TYPE_DIRECT:
+case VIR_DOMAIN_NET_TYPE_ETHERNET:
+return true;
+case VIR_DOMAIN_NET_TYPE_USER:
+case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
+case VIR_DOMAIN_NET_TYPE_SERVER:
+case VIR_DOMAIN_NET_TYPE_CLIENT:
+case VIR_DOMAIN_NET_TYPE_MCAST:
+case VIR_DOMAIN_NET_TYPE_INTERNAL:
+case VIR_DOMAIN_NET_TYPE_HOSTDEV:
+case VIR_DOMAIN_NET_TYPE_LAST:
+break;
+}
+return false;
+}
+


I've got a feeling that this should go to src/util/virnetdevbandwidth* 
among with the rest of virNetDevBandwitdh functions.



  #endif /* __DOMAIN_CONF_H */
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 979382b..8a21af4 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -72,6 +72,7 @@
  #include "viraccessapicheck.h"
  #include "viraccessapichecklxc.h"
  #include "virhostdev.h"
+#include "qemu/qemu_command.h"


This is not allowed. In case somebody is building with LXC but without 
QEMU ..




  #define VIR_FROM_THIS VIR_FROM_LXC

@@ -4634,6 +4635,8 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,

  detach = vm->def->nets[detachidx];

+qemuDomainClearNetBandwidth(vm);
+


.. this is going to be an undefined reference.


  switch (virDomainNetGetActualType(detach)) {
  case VIR_DOMAIN_NET_TYPE_BRIDGE:
  case VIR_DOMAIN_NET_TYPE_NETWORK:
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index ed30c37..3192011 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;
-



No, this function is called from two places:
1) when domain is starting up
2) on NIC hotplug

you are covering 1) but removing already working 2). We can't lose that 
functionality.



  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,14 +325,13 @@ 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)
+cfg->stateDir, 0) < 0)
  goto cleanup;



Same comment applies here.


  ret = res_ifname;
@@ -450,6 +445,11 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
  goto cleanup;
  }

+/* set network bandwidth */
+if (virNetDevBandwidthSet(def->nets[i]->ifname,
+virDomainNetGetActualBandwidth(def->nets[i]), false) < 0)
+   goto cleanup;
+


Shouldn't this be guarded with virNetDevSupportBandwidth()? The problem 
is, there's a switch() just before this 

Re: [libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-10-31 Thread Anirban Chakraborty
Ping ?

On 10/29/14, 4:56 PM, "Anirban Chakraborty"  wrote:

>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.
>
>
>  
>  
>  
>  
>  
>
>
>  
>
>
>Signed-off-by: Anirban Chakraborty 
>---
> src/conf/domain_conf.h  | 21 +
> src/lxc/lxc_driver.c|  3 +++
> src/lxc/lxc_process.c   | 18 +-
> src/qemu/qemu_command.c | 25 +++--
> src/qemu/qemu_command.h |  2 ++
> src/qemu/qemu_driver.c  |  3 +++
> src/qemu/qemu_hotplug.c | 12 
> src/qemu/qemu_process.c |  3 +++
> src/util/virnetdevmacvlan.c | 10 --
> src/util/virnetdevmacvlan.h |  1 -
> 10 files changed, 72 insertions(+), 26 deletions(-)
>
>diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
>index 9908d88..40e85d9 100644
>--- a/src/conf/domain_conf.h
>+++ b/src/conf/domain_conf.h
>@@ -2848,4 +2848,25 @@ int virDomainObjSetMetadata(virDomainObjPtr vm,
> bool virDomainDefNeedsPlacementAdvice(virDomainDefPtr def)
> ATTRIBUTE_NONNULL(1);
>
>+static inline bool virNetDevSupportBandwidth(virDomainNetType type)
>+{
>+switch (type) {
>+case VIR_DOMAIN_NET_TYPE_BRIDGE:
>+case VIR_DOMAIN_NET_TYPE_NETWORK:
>+case VIR_DOMAIN_NET_TYPE_DIRECT:
>+case VIR_DOMAIN_NET_TYPE_ETHERNET:
>+return true;
>+case VIR_DOMAIN_NET_TYPE_USER:
>+case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
>+case VIR_DOMAIN_NET_TYPE_SERVER:
>+case VIR_DOMAIN_NET_TYPE_CLIENT:
>+case VIR_DOMAIN_NET_TYPE_MCAST:
>+case VIR_DOMAIN_NET_TYPE_INTERNAL:
>+case VIR_DOMAIN_NET_TYPE_HOSTDEV:
>+case VIR_DOMAIN_NET_TYPE_LAST:
>+break;
>+}
>+return false;
>+}
>+
> #endif /* __DOMAIN_CONF_H */
>diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
>index 979382b..8a21af4 100644
>--- a/src/lxc/lxc_driver.c
>+++ b/src/lxc/lxc_driver.c
>@@ -72,6 +72,7 @@
> #include "viraccessapicheck.h"
> #include "viraccessapichecklxc.h"
> #include "virhostdev.h"
>+#include "qemu/qemu_command.h"
>
> #define VIR_FROM_THIS VIR_FROM_LXC
>
>@@ -4634,6 +4635,8 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
>
> detach = vm->def->nets[detachidx];
>
>+qemuDomainClearNetBandwidth(vm);
>+
> switch (virDomainNetGetActualType(detach)) {
> case VIR_DOMAIN_NET_TYPE_BRIDGE:
> case VIR_DOMAIN_NET_TYPE_NETWORK:
>diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
>index ed30c37..3192011 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,14 +325,13 @@ 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)
>+cfg->stateDir, 0) < 0)
> goto cleanup;
>
> ret = res_ifname;
>@@ -450,6 +445,11 @@ static int
>virLXCProcessSetupInterfaces(virConnectPtr conn,
> goto cleanup;
> }
>
>+/* set network bandwidth */
>+if (virNetDevBandwidthSet(def->nets[i]->ifname,
>+virDomainNetGetActualBandwidth(def->nets[i]), false) < 0)
>+   goto cleanup;
>+
> (*veths)[(*nveths)-1] = veth;
>
> /* Make sure all net definitions will have a name in the
>container */
>diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
>index 2e5af4f..7922672 100644
>--- a/src/qemu/qemu_command.c
>+++ b/src/qemu/qemu_command.c
>@@ -191,7 +191,6 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
> virDomainNetGetActualVirtPortProfile(net),
> &res_ifname,
> vmop, cfg->stateDir,
>-virDomainNetGetActualBandwidth(net),
> m

[libvirt] [PATCH] network: Add bandwidth support to ethernet interface

2014-10-29 Thread Anirban Chakraborty
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.


  
  
  
  
  


  


Signed-off-by: Anirban Chakraborty 
---
 src/conf/domain_conf.h  | 21 +
 src/lxc/lxc_driver.c|  3 +++
 src/lxc/lxc_process.c   | 18 +-
 src/qemu/qemu_command.c | 25 +++--
 src/qemu/qemu_command.h |  2 ++
 src/qemu/qemu_driver.c  |  3 +++
 src/qemu/qemu_hotplug.c | 12 
 src/qemu/qemu_process.c |  3 +++
 src/util/virnetdevmacvlan.c | 10 --
 src/util/virnetdevmacvlan.h |  1 -
 10 files changed, 72 insertions(+), 26 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9908d88..40e85d9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2848,4 +2848,25 @@ int virDomainObjSetMetadata(virDomainObjPtr vm,
 bool virDomainDefNeedsPlacementAdvice(virDomainDefPtr def)
 ATTRIBUTE_NONNULL(1);

+static inline bool virNetDevSupportBandwidth(virDomainNetType type)
+{
+switch (type) {
+case VIR_DOMAIN_NET_TYPE_BRIDGE:
+case VIR_DOMAIN_NET_TYPE_NETWORK:
+case VIR_DOMAIN_NET_TYPE_DIRECT:
+case VIR_DOMAIN_NET_TYPE_ETHERNET:
+return true;
+case VIR_DOMAIN_NET_TYPE_USER:
+case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
+case VIR_DOMAIN_NET_TYPE_SERVER:
+case VIR_DOMAIN_NET_TYPE_CLIENT:
+case VIR_DOMAIN_NET_TYPE_MCAST:
+case VIR_DOMAIN_NET_TYPE_INTERNAL:
+case VIR_DOMAIN_NET_TYPE_HOSTDEV:
+case VIR_DOMAIN_NET_TYPE_LAST:
+break;
+}
+return false;
+}
+
 #endif /* __DOMAIN_CONF_H */
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 979382b..8a21af4 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -72,6 +72,7 @@
 #include "viraccessapicheck.h"
 #include "viraccessapichecklxc.h"
 #include "virhostdev.h"
+#include "qemu/qemu_command.h"

 #define VIR_FROM_THIS VIR_FROM_LXC

@@ -4634,6 +4635,8 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,

 detach = vm->def->nets[detachidx];

+qemuDomainClearNetBandwidth(vm);
+
 switch (virDomainNetGetActualType(detach)) {
 case VIR_DOMAIN_NET_TYPE_BRIDGE:
 case VIR_DOMAIN_NET_TYPE_NETWORK:
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index ed30c37..3192011 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,14 +325,13 @@ 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)
+cfg->stateDir, 0) < 0)
 goto cleanup;

 ret = res_ifname;
@@ -450,6 +445,11 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
 goto cleanup;
 }

+/* set network bandwidth */
+if (virNetDevBandwidthSet(def->nets[i]->ifname,
+virDomainNetGetActualBandwidth(def->nets[i]), false) < 0)
+   goto cleanup;
+
 (*veths)[(*nveths)-1] = veth;

 /* Make sure all net definitions will have a name in the container */
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2e5af4f..7922672 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -191,7 +191,6 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
 virDomainNetGetActualVirtPortProfile(net),
 &res_ifname,
 vmop, cfg->stateDir,
-virDomainNetGetActualBandwidth(net),
 macvlan_create_flags);
 if (rc >= 0) {
 virDomainAuditNetDevice(def, net, res_ifname, true);
@@ -371,11 +370,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
   &ne