
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