[libvirt] [PATCH v3 2/2] network: Add code for setting network bandwidth for ethernet interfaces
Eric Blake
eblake at redhat.com
Thu Oct 9 03:39:33 UTC 2014
On 10/08/2014 04:10 PM, Anirban Chakraborty wrote:
>> Needs rework after my comments on 1/2. I also wonder if this should
>> just be folded in to that patch, and/or made into a switch statement
>> where the compiler forces us to think about any future
>> VIR_DOMAIN_NET_TYPE_* additions on whether they should return true or
>> false.
>> 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:
>> /* cover all enums to appease the compiler */ ;
>> }
>> return false;
>> }
>
> We could have the function defined with a switch, however, instead of
> listing all the types, I could return false from the default case.
>
> Something like:
> 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;
>
> default;
> return false;
Alas, using a default case means the compiler can no longer tell you
about missed cases. I wrote my example to intentionally spell out ALL
cases without a default, in order to ensure the compiler will loudly
warn if we add another enum in the future.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 539 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20141008/a1a0990c/attachment-0001.sig>
More information about the libvir-list
mailing list