[PATCH] Change the virtual NICs limit for the ESX driver

Bastien Orivel posted 1 patch 3 years, 9 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200707140433.3292-1-bastien.orivel@diateam.net
src/vmx/vmx.c | 20 ++++++++++++++------
src/vmx/vmx.h |  2 +-
2 files changed, 15 insertions(+), 7 deletions(-)
[PATCH] Change the virtual NICs limit for the ESX driver
Posted by Bastien Orivel 3 years, 9 months ago
Since the ESX virtual hardware version 4.0, virtual machines support up
to 10 virtual NICs instead of 4 previously. This changes the limit
accordingly based on the provided `virtualHW.version`.

Signed-off-by: Bastien Orivel <bastien.orivel@diateam.net>
---
 src/vmx/vmx.c | 20 ++++++++++++++------
 src/vmx/vmx.h |  2 +-
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 67bbe27fde..afe6fe0a1a 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -290,7 +290,7 @@ def->fss[0]...                    <=>   sharedFolder0.present = "true"
 ################################################################################
 ## nets ########################################################################
 
-                                        ethernet[0..3] -> <controller>
+                                        ethernet[0..9] -> <controller>
 
                                         ethernet0.present = "true"              # defaults to "false"
                                         ethernet0.startConnected = "true"       # defaults to "true"
@@ -3376,7 +3376,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
 
     /* def:nets */
     for (i = 0; i < def->nnets; ++i) {
-        if (virVMXFormatEthernet(def->nets[i], i, &buffer) < 0)
+        if (virVMXFormatEthernet(def->nets[i], i, &buffer, virtualHW_version) < 0)
             goto cleanup;
     }
 
@@ -3732,15 +3732,23 @@ virVMXFormatFileSystem(virDomainFSDefPtr def, int number, virBufferPtr buffer)
 
 int
 virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
-                     virBufferPtr buffer)
+                     virBufferPtr buffer, int virtualHW_version)
 {
     char mac_string[VIR_MAC_STRING_BUFLEN];
     unsigned int prefix, suffix;
 
-    if (controller < 0 || controller > 3) {
+    /*
+     * Machines older than virtualHW.version = 7 (ESXi 4.0) only support up to 4
+     * virtual NICs. New machines support up to 10.
+     */
+    int controller_limit = 4;
+    if (virtualHW_version >= 7)
+        controller_limit = 10;
+
+    if (controller < 0 || controller > controller_limit) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Ethernet controller index %d out of [0..3] range"),
-                       controller);
+                       _("Ethernet controller index %d out of [0..%d] range"),
+                       controller, controller_limit - 1);
         return -1;
     }
 
diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h
index 63f47822fb..7069a50b6e 100644
--- a/src/vmx/vmx.h
+++ b/src/vmx/vmx.h
@@ -131,7 +131,7 @@ int virVMXFormatFileSystem(virDomainFSDefPtr def, int number,
                            virBufferPtr buffer);
 
 int virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
-                         virBufferPtr buffer);
+                         virBufferPtr buffer, int virtualHW_version);
 
 int virVMXFormatSerial(virVMXContext *ctx, virDomainChrDefPtr def,
                        virBufferPtr buffer);
-- 
2.20.1

Re: [PATCH] Change the virtual NICs limit for the ESX driver
Posted by Michal Privoznik 3 years, 9 months ago
On 7/7/20 4:04 PM, Bastien Orivel wrote:
> Since the ESX virtual hardware version 4.0, virtual machines support up
> to 10 virtual NICs instead of 4 previously. This changes the limit
> accordingly based on the provided `virtualHW.version`.
> 
> Signed-off-by: Bastien Orivel <bastien.orivel@diateam.net>
> ---
>   src/vmx/vmx.c | 20 ++++++++++++++------
>   src/vmx/vmx.h |  2 +-
>   2 files changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
> index 67bbe27fde..afe6fe0a1a 100644
> --- a/src/vmx/vmx.c
> +++ b/src/vmx/vmx.c
> @@ -290,7 +290,7 @@ def->fss[0]...                    <=>   sharedFolder0.present = "true"
>   ################################################################################
>   ## nets ########################################################################
>   
> -                                        ethernet[0..3] -> <controller>
> +                                        ethernet[0..9] -> <controller>
>   
>                                           ethernet0.present = "true"              # defaults to "false"
>                                           ethernet0.startConnected = "true"       # defaults to "true"
> @@ -3376,7 +3376,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
>   
>       /* def:nets */
>       for (i = 0; i < def->nnets; ++i) {
> -        if (virVMXFormatEthernet(def->nets[i], i, &buffer) < 0)
> +        if (virVMXFormatEthernet(def->nets[i], i, &buffer, virtualHW_version) < 0)
>               goto cleanup;
>       }
>   
> @@ -3732,15 +3732,23 @@ virVMXFormatFileSystem(virDomainFSDefPtr def, int number, virBufferPtr buffer)
>   
>   int
>   virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
> -                     virBufferPtr buffer)
> +                     virBufferPtr buffer, int virtualHW_version)
>   {
>       char mac_string[VIR_MAC_STRING_BUFLEN];
>       unsigned int prefix, suffix;
>   
> -    if (controller < 0 || controller > 3) {
> +    /*
> +     * Machines older than virtualHW.version = 7 (ESXi 4.0) only support up to 4
> +     * virtual NICs. New machines support up to 10.
> +     */
> +    int controller_limit = 4;
> +    if (virtualHW_version >= 7)
> +        controller_limit = 10;
> +
> +    if (controller < 0 || controller > controller_limit) {

This allows 4 nics for the old ESX version (if controller = 4 then this 
would be reported, but with your patch it isn't anymore), and 11 nics 
for the new EXS (if controller = 10, then this again is not caught 
properly). We need to decrease those 4 and 10 and ..

>           virReportError(VIR_ERR_INTERNAL_ERROR,
> -                       _("Ethernet controller index %d out of [0..3] range"),
> -                       controller);
> +                       _("Ethernet controller index %d out of [0..%d] range"),
> +                       controller, controller_limit - 1);

.. drop this -1.

No need to send v2, I can fix it just before pushing, if you agree with 
suggested change.

Michal

Re: [PATCH] Change the virtual NICs limit for the ESX driver
Posted by Bastien Orivel 3 years, 9 months ago

On 08/07/2020 17:32, Michal Privoznik wrote:
> On 7/7/20 4:04 PM, Bastien Orivel wrote:
>> Since the ESX virtual hardware version 4.0, virtual machines support up
>> to 10 virtual NICs instead of 4 previously. This changes the limit
>> accordingly based on the provided `virtualHW.version`.
>>
>> Signed-off-by: Bastien Orivel <bastien.orivel@diateam.net>
>> ---
>>   src/vmx/vmx.c | 20 ++++++++++++++------
>>   src/vmx/vmx.h |  2 +-
>>   2 files changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
>> index 67bbe27fde..afe6fe0a1a 100644
>> --- a/src/vmx/vmx.c
>> +++ b/src/vmx/vmx.c
>> @@ -290,7 +290,7 @@ def->fss[0]...                    <=>  
>> sharedFolder0.present = "true"
>>  
>> ################################################################################
>>   ## nets
>> ########################################################################
>>   -                                        ethernet[0..3] ->
>> <controller>
>> +                                        ethernet[0..9] -> <controller>
>>                                             ethernet0.present =
>> "true"              # defaults to "false"
>>                                           ethernet0.startConnected =
>> "true"       # defaults to "true"
>> @@ -3376,7 +3376,7 @@ virVMXFormatConfig(virVMXContext *ctx,
>> virDomainXMLOptionPtr xmlopt, virDomainDe
>>         /* def:nets */
>>       for (i = 0; i < def->nnets; ++i) {
>> -        if (virVMXFormatEthernet(def->nets[i], i, &buffer) < 0)
>> +        if (virVMXFormatEthernet(def->nets[i], i, &buffer,
>> virtualHW_version) < 0)
>>               goto cleanup;
>>       }
>>   @@ -3732,15 +3732,23 @@ virVMXFormatFileSystem(virDomainFSDefPtr
>> def, int number, virBufferPtr buffer)
>>     int
>>   virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
>> -                     virBufferPtr buffer)
>> +                     virBufferPtr buffer, int virtualHW_version)
>>   {
>>       char mac_string[VIR_MAC_STRING_BUFLEN];
>>       unsigned int prefix, suffix;
>>   -    if (controller < 0 || controller > 3) {
>> +    /*
>> +     * Machines older than virtualHW.version = 7 (ESXi 4.0) only
>> support up to 4
>> +     * virtual NICs. New machines support up to 10.
>> +     */
>> +    int controller_limit = 4;
>> +    if (virtualHW_version >= 7)
>> +        controller_limit = 10;
>> +
>> +    if (controller < 0 || controller > controller_limit) {
>
> This allows 4 nics for the old ESX version (if controller = 4 then
> this would be reported, but with your patch it isn't anymore), and 11
> nics for the new EXS (if controller = 10, then this again is not
> caught properly). We need to decrease those 4 and 10 and ..
>
Oof. Nice catch.
>>           virReportError(VIR_ERR_INTERNAL_ERROR,
>> -                       _("Ethernet controller index %d out of [0..3]
>> range"),
>> -                       controller);
>> +                       _("Ethernet controller index %d out of
>> [0..%d] range"),
>> +                       controller, controller_limit - 1);
>
> .. drop this -1.
>
> No need to send v2, I can fix it just before pushing, if you agree
> with suggested change.
Sounds good to me.
>
> Michal
>
Bastien

Re: [PATCH] Change the virtual NICs limit for the ESX driver
Posted by Michal Privoznik 3 years, 9 months ago
On 7/8/20 5:37 PM, Bastien Orivel wrote:
> 
> 
> On 08/07/2020 17:32, Michal Privoznik wrote:
>> On 7/7/20 4:04 PM, Bastien Orivel wrote:
>>> Since the ESX virtual hardware version 4.0, virtual machines support up
>>> to 10 virtual NICs instead of 4 previously. This changes the limit
>>> accordingly based on the provided `virtualHW.version`.
>>>
>>> Signed-off-by: Bastien Orivel <bastien.orivel@diateam.net>
>>> ---
>>>    src/vmx/vmx.c | 20 ++++++++++++++------
>>>    src/vmx/vmx.h |  2 +-
>>>    2 files changed, 15 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
>>> index 67bbe27fde..afe6fe0a1a 100644
>>> --- a/src/vmx/vmx.c
>>> +++ b/src/vmx/vmx.c
>>> @@ -290,7 +290,7 @@ def->fss[0]...                    <=>
>>> sharedFolder0.present = "true"
>>>   
>>> ################################################################################
>>>    ## nets
>>> ########################################################################
>>>    -                                        ethernet[0..3] ->
>>> <controller>
>>> +                                        ethernet[0..9] -> <controller>
>>>                                              ethernet0.present =
>>> "true"              # defaults to "false"
>>>                                            ethernet0.startConnected =
>>> "true"       # defaults to "true"
>>> @@ -3376,7 +3376,7 @@ virVMXFormatConfig(virVMXContext *ctx,
>>> virDomainXMLOptionPtr xmlopt, virDomainDe
>>>          /* def:nets */
>>>        for (i = 0; i < def->nnets; ++i) {
>>> -        if (virVMXFormatEthernet(def->nets[i], i, &buffer) < 0)
>>> +        if (virVMXFormatEthernet(def->nets[i], i, &buffer,
>>> virtualHW_version) < 0)
>>>                goto cleanup;
>>>        }
>>>    @@ -3732,15 +3732,23 @@ virVMXFormatFileSystem(virDomainFSDefPtr
>>> def, int number, virBufferPtr buffer)
>>>      int
>>>    virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
>>> -                     virBufferPtr buffer)
>>> +                     virBufferPtr buffer, int virtualHW_version)
>>>    {
>>>        char mac_string[VIR_MAC_STRING_BUFLEN];
>>>        unsigned int prefix, suffix;
>>>    -    if (controller < 0 || controller > 3) {
>>> +    /*
>>> +     * Machines older than virtualHW.version = 7 (ESXi 4.0) only
>>> support up to 4
>>> +     * virtual NICs. New machines support up to 10.
>>> +     */
>>> +    int controller_limit = 4;
>>> +    if (virtualHW_version >= 7)
>>> +        controller_limit = 10;
>>> +
>>> +    if (controller < 0 || controller > controller_limit) {
>>
>> This allows 4 nics for the old ESX version (if controller = 4 then
>> this would be reported, but with your patch it isn't anymore), and 11
>> nics for the new EXS (if controller = 10, then this again is not
>> caught properly). We need to decrease those 4 and 10 and ..
>>
> Oof. Nice catch.
>>>            virReportError(VIR_ERR_INTERNAL_ERROR,
>>> -                       _("Ethernet controller index %d out of [0..3]
>>> range"),
>>> -                       controller);
>>> +                       _("Ethernet controller index %d out of
>>> [0..%d] range"),
>>> +                       controller, controller_limit - 1);
>>
>> .. drop this -1.
>>
>> No need to send v2, I can fix it just before pushing, if you agree
>> with suggested change.
> Sounds good to me.

Done.

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

and pushed. Congratulations on your first libvirt contribution!

Michal

Re: [PATCH] Change the virtual NICs limit for the ESX driver
Posted by Andrea Bolognani 3 years, 9 months ago
On Wed, 2020-07-08 at 17:47 +0200, Michal Privoznik wrote:
> On 7/8/20 5:37 PM, Bastien Orivel wrote:
> > On 08/07/2020 17:32, Michal Privoznik wrote:
> > > No need to send v2, I can fix it just before pushing, if you agree
> > > with suggested change.
> > > 
> > Sounds good to me.
> 
> Done.
> 
> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
> 
> and pushed. Congratulations on your first libvirt contribution!

Congratulations indeed :)

As a follow-up to your contribution, would you mind posting a patch
in which the release notes (NEWS.rst) are updated with a line of two
describing the change?

Thanks!

-- 
Andrea Bolognani / Red Hat / Virtualization