[PATCHv2 2/2] Document the `type` attribute for mac addresses

2020-07-13 Thread Bastien Orivel
Signed-off-by: Bastien Orivel 
---
 docs/drvesx.html.in | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/docs/drvesx.html.in b/docs/drvesx.html.in
index ac7bc645d1..70b7066861 100644
--- a/docs/drvesx.html.in
+++ b/docs/drvesx.html.in
@@ -427,6 +427,13 @@ error: invalid argument in libvirt was built without the 
'esx' driver
 
 ethernet0.checkMACAddress = "false"
 
+
+Since 6.6.0, one can force libvirt to keep 
the
+provided MAC address when it's in the reserved VMware range by adding a
+type="static" attribute to the mac/ 
element.
+Note that this attribute is useless if the provided MAC address is 
outisde of
+the reserved VMWare ranges.
+
 
 
 Available hardware
-- 
2.20.1



[PATCHv2 1/2] Add a type attribute on the mac address element

2020-07-13 Thread Bastien Orivel
This is only used in the ESX driver where, when set to "static", it will
ignore all the checks libvirt does about the origin of the MAC address
(whether or not it's in a VMWare OUI) and forward the original one to
the ESX server telling it not to check it either.

This allows keeping a deterministic MAC address which can be useful for
licensed software which might dislike changes.

Signed-off-by: Bastien Orivel 
---
 NEWS.rst  |  6 
 docs/schemas/domaincommon.rng |  8 +
 src/conf/domain_conf.c| 26 -
 src/conf/domain_conf.h| 11 +++
 src/vmx/vmx.c |  8 +++--
 .../network-interface-mac-type.xml| 29 +++
 tests/genericxml2xmltest.c|  2 ++
 7 files changed, 86 insertions(+), 4 deletions(-)
 create mode 100644 tests/genericxml2xmlindata/network-interface-mac-type.xml

diff --git a/NEWS.rst b/NEWS.rst
index 1928220854..2c6c628c61 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -18,6 +18,12 @@ v6.6.0 (unreleased)
 Libvirt allows configuring ACPI Heterogeneous Memory Attribute Table to
 hint software running inside the guest on optimization.
 
+  * esx: Add a ``type`` attribute for mac addresses.
+
+This attribute allows (when set to ``static``) ignoring VMWare checks of 
the
+MAC addresses that would generate a new one if they were in its OUI
+(00:0c:29).
+
 * **Improvements**
 
   * esx: Change the NIC limit for recent virtualHW versions
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 4b4aa60c66..a810f569c6 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3179,6 +3179,14 @@
   
 
   
+  
+
+  
+generated
+static
+  
+
+  
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d14485f18d..93e203de23 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -611,6 +611,13 @@ VIR_ENUM_IMPL(virDomainChrDeviceState,
   "disconnected",
 );
 
+VIR_ENUM_IMPL(virDomainNetMacType,
+  VIR_DOMAIN_NET_MAC_TYPE_LAST,
+  "",
+  "generated",
+  "static",
+);
+
 VIR_ENUM_IMPL(virDomainChrSerialTarget,
   VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST,
   "none",
@@ -11904,6 +11911,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 virDomainChrSourceReconnectDef reconnect = {0};
 int rv, val;
 g_autofree char *macaddr = NULL;
+g_autofree char *macaddr_type = NULL;
 g_autofree char *type = NULL;
 g_autofree char *network = NULL;
 g_autofree char *portgroup = NULL;
@@ -11984,6 +11992,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 if (!macaddr && virXMLNodeNameEqual(cur, "mac")) {
 macaddr = virXMLPropString(cur, "address");
+macaddr_type = virXMLPropString(cur, "type");
 } else if (!network &&
def->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
virXMLNodeNameEqual(cur, "source")) {
@@ -12173,6 +12182,18 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 def->mac_generated = true;
 }
 
+if (macaddr_type) {
+virDomainNetMacType tmp;
+if ((tmp = virDomainNetMacTypeTypeFromString(macaddr_type)) <= 0) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("invalid mac address check value: '%s'. Valid "
+ "values are \"generated\" and \"static\"."),
+   macaddr_type);
+goto error;
+}
+def->mac_type = tmp;
+}
+
 if (virDomainDeviceInfoParseXML(xmlopt, node, >info,
 flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT
 | VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) < 0) {
@@ -26468,8 +26489,11 @@ virDomainNetDefFormat(virBufferPtr buf,
 virBufferAddLit(buf, ">\n");
 
 virBufferAdjustIndent(buf, 2);
-virBufferAsprintf(buf, "\n",
+virBufferAsprintf(buf, "mac, macstr));
+if (def->mac_type)
+virBufferAsprintf(buf, " type='%s'", 
virDomainNetMacTypeTypeToString(def->mac_type));
+virBufferAddLit(buf, "/>\n");
 
 if (publicActual) {
 /* when there is a virDomainActualNetDef, and we haven't been
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6a737591e2..7b754f959d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -921,6 +921,15 @@ t

[PATCHv2 0/2] Add a type attribute on the mac address element

2020-07-13 Thread Bastien Orivel
Changed:
- Split the commit in two to separate the documentation from the
  code changes.
- Change the attribute name from check (tri state bool) to type
  (static/generated).

This time with the patches too...

Bastien Orivel (2):
  Add a type attribute on the mac address element
  Document the `type` attribute for mac addresses

 NEWS.rst  |  6 
 docs/drvesx.html.in   |  7 +
 docs/schemas/domaincommon.rng |  8 +
 src/conf/domain_conf.c| 26 -
 src/conf/domain_conf.h| 11 +++
 src/vmx/vmx.c |  8 +++--
 .../network-interface-mac-type.xml| 29 +++
 tests/genericxml2xmltest.c|  2 ++
 8 files changed, 93 insertions(+), 4 deletions(-)
 create mode 100644 tests/genericxml2xmlindata/network-interface-mac-type.xml

-- 
2.20.1



[PATCHv2 0/2] Add a type attribute on the mac address element

2020-07-13 Thread Bastien Orivel
Changed:
- Split the commit in two to separate the documentation from the
  code changes.
- Change the attribute name from check (tri state bool) to type
  (static/generated).

Bastien Orivel (2):
  Add a type attribute on the mac address element
  Document the `type` attribute for mac addresses

 NEWS.rst  |  6 
 docs/drvesx.html.in   |  7 +
 docs/schemas/domaincommon.rng |  8 +
 src/conf/domain_conf.c| 26 -
 src/conf/domain_conf.h| 11 +++
 src/vmx/vmx.c |  8 +++--
 .../network-interface-mac-type.xml| 29 +++
 tests/genericxml2xmltest.c|  2 ++
 8 files changed, 93 insertions(+), 4 deletions(-)
 create mode 100644 tests/genericxml2xmlindata/network-interface-mac-type.xml

-- 
2.20.1



Re: [PATCH] Add a check attribute on the mac address element

2020-07-13 Thread Bastien Orivel



On 13/07/2020 13:41, Michal Privoznik wrote:
> On 7/13/20 11:44 AM, Bastien Orivel wrote:
>> This is only used in the ESX driver where, when set to "no", it will
>> ignore all the checks libvirt does about the origin of the MAC address
>> (whether or not it's in a VMWare OUI) and forward the original one to
>> the ESX server telling it not to check it either.
>>
>> This allows keeping a deterministic MAC address which can be useful for
>> licensed software which might dislike changes.
>>
>
> While you get bonus points for remembering to document this change, it
> should go into a separate patch, because keeping it in a single one
> usually leads to conflicts on backports.
Oops, didn't know about that, will split in a v2 once we resolved the
other question.

> But anyway, looking at virVMXFormatEthernet() - why don't we set all
> MACs 'static'? Alternatively, we can use @mac_generated member to
> determine whether the MAC address was provided by user or
> automagically generated (and use static/generated addressType
> accrodingly)?

Mostly because I didn't want to break any existing script/setup that
relies on the fact that libvirt would set the address type to what it is
right now. For example, right now, providing a MAC address in the
@00:0c:29@ range makes the ESXi server generate a new MAC address on
define. I can imagine that some people outside always provide the same
MAC address to define their machine and rely on libvirt/ESXi to generate
a new one in that range for them.



Bastien




[PATCH] Add a check attribute on the mac address element

2020-07-13 Thread Bastien Orivel
This is only used in the ESX driver where, when set to "no", it will
ignore all the checks libvirt does about the origin of the MAC address
(whether or not it's in a VMWare OUI) and forward the original one to
the ESX server telling it not to check it either.

This allows keeping a deterministic MAC address which can be useful for
licensed software which might dislike changes.

Signed-off-by: Bastien Orivel 
---
 NEWS.rst  |  6 
 docs/drvesx.html.in   |  5 
 docs/schemas/domaincommon.rng |  3 ++
 src/conf/domain_conf.c| 18 +++-
 src/conf/domain_conf.h|  1 +
 src/vmx/vmx.c |  9 +-
 .../network-interface-mac-check.xml   | 29 +++
 tests/genericxml2xmltest.c|  2 ++
 8 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 tests/genericxml2xmlindata/network-interface-mac-check.xml

diff --git a/NEWS.rst b/NEWS.rst
index 1928220854..ac4de4360d 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -18,6 +18,12 @@ v6.6.0 (unreleased)
 Libvirt allows configuring ACPI Heterogeneous Memory Attribute Table to
 hint software running inside the guest on optimization.
 
+  * esx: Add a ``check`` attribute for mac addresses.
+
+This attribute allows (when set to ``no``) ignoring VMWare checks of the
+MAC addresses that would generate a new one if they were in its OUI
+(00:0c:29).
+
 * **Improvements**
 
   * esx: Change the NIC limit for recent virtualHW versions
diff --git a/docs/drvesx.html.in b/docs/drvesx.html.in
index ac7bc645d1..90f368e4f5 100644
--- a/docs/drvesx.html.in
+++ b/docs/drvesx.html.in
@@ -427,6 +427,11 @@ error: invalid argument in libvirt was built without the 
'esx' driver
 
 ethernet0.checkMACAddress = "false"
 
+
+Since 6.6.0, one can force libvirt to keep 
the
+provided MAC address when it's in the reserved VMware range by adding a
+check="no" attribute to the mac/ 
element.
+
 
 
 Available hardware
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 4b4aa60c66..b926b752fe 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3179,6 +3179,9 @@
   
 
   
+  
+
+  
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d14485f18d..aa1417c4d8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11904,6 +11904,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 virDomainChrSourceReconnectDef reconnect = {0};
 int rv, val;
 g_autofree char *macaddr = NULL;
+g_autofree char *macaddr_check = NULL;
 g_autofree char *type = NULL;
 g_autofree char *network = NULL;
 g_autofree char *portgroup = NULL;
@@ -11984,6 +11985,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 if (!macaddr && virXMLNodeNameEqual(cur, "mac")) {
 macaddr = virXMLPropString(cur, "address");
+macaddr_check = virXMLPropString(cur, "check");
 } else if (!network &&
def->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
virXMLNodeNameEqual(cur, "source")) {
@@ -12173,6 +12175,17 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 def->mac_generated = true;
 }
 
+if (macaddr_check) {
+int tmpCheck;
+if ((tmpCheck = virTristateBoolTypeFromString(macaddr_check)) < 0) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("invalid mac address check value: '%s'"),
+   macaddr_check);
+goto error;
+}
+def->mac_check = tmpCheck;
+}
+
 if (virDomainDeviceInfoParseXML(xmlopt, node, >info,
 flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT
 | VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) < 0) {
@@ -26468,8 +26481,11 @@ virDomainNetDefFormat(virBufferPtr buf,
 virBufferAddLit(buf, ">\n");
 
 virBufferAdjustIndent(buf, 2);
-virBufferAsprintf(buf, "\n",
+virBufferAsprintf(buf, "mac, macstr));
+if (def->mac_check != VIR_TRISTATE_BOOL_ABSENT)
+virBufferAsprintf(buf, " check='%s'", 
virTristateBoolTypeToString(def->mac_check));
+virBufferAddLit(buf, "/>\n");
 
 if (publicActual) {
 /* when there is a virDomainActualNetDef, and we haven't been
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6a737591e2..f2bcd62857 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -972,6 +972,7 @@ struct _virDomainNetDef {
 virDomainNetType type;
 virMacA

[PATCHv2] Add a changelog entry for the esx NIC limit changes

2020-07-09 Thread Bastien Orivel
This was forgotten in 4bd375b6ce3a4c134bab19cd7c9a7a83609547c8

Signed-off-by: Bastien Orivel 
---
 NEWS.rst | 5 +
 1 file changed, 5 insertions(+)

diff --git a/NEWS.rst b/NEWS.rst
index cc35cb26b2..1928220854 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -20,6 +20,11 @@ v6.6.0 (unreleased)
 
 * **Improvements**
 
+  * esx: Change the NIC limit for recent virtualHW versions
+
+Specifying a virtualHW version greater or equal to 7 (ESXi 4.0) will allow
+you to use up to 10 NICs instead of 4 as it was previously.
+
 * **Bug fixes**
 
 
-- 
2.20.1



Re: [PATCH] Add a changelog entry for the esx NIC limit changes

2020-07-09 Thread Bastien Orivel



On 09/07/2020 12:10, Andrea Bolognani wrote:
> On Thu, 2020-07-09 at 11:25 +0200, Bastien Orivel wrote:
>> This was forgotten in 4bd375b6ce3a4c134bab19cd7c9a7a83609547c8
> You're missing the Signed-off-by tag...
Sorry, not used to using that git feature.
>
>>  * **Improvements**
>>  
>> +   * esx: Change the NIC limit for recent virtualHW versions
>> +
>> +   Specifying a virtualHW version greater or equal to 7 (ESXi 4.0) will 
>> allow
>> +   you to use up to 10 NICs instead of 4 as it was previously.
> ... and indentation is off (see existing entries for comparison).
>
> I can fix both before pushing if you're okay with that, or you could
> repost, whatever is better for you.
>
If you can fix it for me it'll avoid me battling git send-email for a
while to find out how to send updated patches.




[PATCH] Add a changelog entry for the esx NIC limit changes

2020-07-09 Thread Bastien Orivel
This was forgotten in 4bd375b6ce3a4c134bab19cd7c9a7a83609547c8
---
 NEWS.rst | 5 +
 1 file changed, 5 insertions(+)

diff --git a/NEWS.rst b/NEWS.rst
index cc35cb26b2..ce5d227068 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -20,6 +20,11 @@ v6.6.0 (unreleased)
 
 * **Improvements**
 
+   * esx: Change the NIC limit for recent virtualHW versions
+
+   Specifying a virtualHW version greater or equal to 7 (ESXi 4.0) will allow
+   you to use up to 10 NICs instead of 4 as it was previously.
+
 * **Bug fixes**
 
 
-- 
2.20.1



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

2020-07-08 Thread Bastien Orivel



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 
>> ---
>>   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] ->
>> 
>> +    ethernet[0..9] -> 
>>     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, ) < 0)
>> +    if (virVMXFormatEthernet(def->nets[i], i, ,
>> 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



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

2020-07-07 Thread Bastien Orivel
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 
---
 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] -> 
+ethernet[0..9] -> 
 
 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, ) < 0)
+if (virVMXFormatEthernet(def->nets[i], i, , 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