[libvirt] [PATCH] esx: Explictly declare VMX file content as UTF-8
by Matthias Bolte
---
src/esx/esx_vmx.c | 3 +++
tests/xml2vmxdata/xml2vmx-annotation.vmx | 1 +
tests/xml2vmxdata/xml2vmx-cdrom-ide-device.vmx | 1 +
tests/xml2vmxdata/xml2vmx-cdrom-ide-file.vmx | 1 +
tests/xml2vmxdata/xml2vmx-cdrom-scsi-device.vmx | 1 +
tests/xml2vmxdata/xml2vmx-cdrom-scsi-file.vmx | 1 +
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-1.vmx | 1 +
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-2.vmx | 1 +
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-3.vmx | 1 +
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-4.vmx | 1 +
tests/xml2vmxdata/xml2vmx-ethernet-bridged.vmx | 1 +
tests/xml2vmxdata/xml2vmx-ethernet-custom.vmx | 1 +
tests/xml2vmxdata/xml2vmx-ethernet-e1000.vmx | 1 +
tests/xml2vmxdata/xml2vmx-ethernet-generated.vmx | 1 +
tests/xml2vmxdata/xml2vmx-ethernet-other.vmx | 1 +
tests/xml2vmxdata/xml2vmx-ethernet-static.vmx | 1 +
tests/xml2vmxdata/xml2vmx-ethernet-vmxnet2.vmx | 1 +
tests/xml2vmxdata/xml2vmx-ethernet-vpx.vmx | 1 +
tests/xml2vmxdata/xml2vmx-floppy-device.vmx | 1 +
tests/xml2vmxdata/xml2vmx-floppy-file.vmx | 1 +
tests/xml2vmxdata/xml2vmx-graphics-vnc.vmx | 1 +
tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-1.vmx | 1 +
tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-2.vmx | 1 +
tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-3.vmx | 1 +
tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-4.vmx | 1 +
tests/xml2vmxdata/xml2vmx-harddisk-ide-file.vmx | 1 +
tests/xml2vmxdata/xml2vmx-harddisk-scsi-file.vmx | 1 +
tests/xml2vmxdata/xml2vmx-minimal-64bit.vmx | 1 +
tests/xml2vmxdata/xml2vmx-minimal.vmx | 1 +
tests/xml2vmxdata/xml2vmx-parallel-device.vmx | 1 +
tests/xml2vmxdata/xml2vmx-parallel-file.vmx | 1 +
tests/xml2vmxdata/xml2vmx-scsi-driver.vmx | 1 +
tests/xml2vmxdata/xml2vmx-scsi-writethrough.vmx | 1 +
tests/xml2vmxdata/xml2vmx-serial-device.vmx | 1 +
tests/xml2vmxdata/xml2vmx-serial-file.vmx | 1 +
.../xml2vmxdata/xml2vmx-serial-network-client.vmx | 1 +
.../xml2vmxdata/xml2vmx-serial-network-server.vmx | 1 +
tests/xml2vmxdata/xml2vmx-serial-pipe.vmx | 1 +
38 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index e17e1e7..7dc8e60 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -2475,6 +2475,9 @@ esxVMX_FormatConfig(esxVMX_Context *ctx, virCapsPtr caps, virDomainDefPtr def,
return NULL;
}
+ /* vmx:.encoding */
+ virBufferAddLit(&buffer, ".encoding = \"UTF-8\"\n");
+
/* vmx:config.version */
virBufferAddLit(&buffer, "config.version = \"8\"\n");
diff --git a/tests/xml2vmxdata/xml2vmx-annotation.vmx b/tests/xml2vmxdata/xml2vmx-annotation.vmx
index 5754c31..3a3e0c9 100644
--- a/tests/xml2vmxdata/xml2vmx-annotation.vmx
+++ b/tests/xml2vmxdata/xml2vmx-annotation.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-device.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-ide-device.vmx
index 2db1bcb..13b91b4 100644
--- a/tests/xml2vmxdata/xml2vmx-cdrom-ide-device.vmx
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-device.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-file.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-ide-file.vmx
index 1adf995..d9b602d 100644
--- a/tests/xml2vmxdata/xml2vmx-cdrom-ide-file.vmx
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-file.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-device.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-device.vmx
index d7f1201..705b31b 100644
--- a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-device.vmx
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-device.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-file.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-file.vmx
index bc6d0f7..178f1e1 100644
--- a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-file.vmx
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-file.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-1.vmx b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-1.vmx
index 5e78a3b..e72ca80 100644
--- a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-1.vmx
+++ b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-1.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-2.vmx b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-2.vmx
index 44db410..68f069b 100644
--- a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-2.vmx
+++ b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-2.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other-64"
diff --git a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-3.vmx b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-3.vmx
index 5bdf40b..e09c694 100644
--- a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-3.vmx
+++ b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-3.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other-64"
diff --git a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-4.vmx b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-4.vmx
index 7decab6..627fcfb 100644
--- a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-4.vmx
+++ b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-4.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-bridged.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-bridged.vmx
index 7d8e59b..6effe4a 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-bridged.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-bridged.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-custom.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-custom.vmx
index 2b96c40..ad4f1d6 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-custom.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-custom.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-e1000.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-e1000.vmx
index fb3c755..0c56810 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-e1000.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-e1000.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-generated.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-generated.vmx
index 3c0aa9e..4f5c47b 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-generated.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-generated.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-other.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-other.vmx
index 017cd0b..dd4caa4 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-other.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-other.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-static.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-static.vmx
index a8a2ffb..7d41239 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-static.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-static.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-vmxnet2.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-vmxnet2.vmx
index 27b302f..807040b 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-vmxnet2.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-vmxnet2.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-vpx.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-vpx.vmx
index f9a0112..dd9ae8d 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-vpx.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-vpx.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-floppy-device.vmx b/tests/xml2vmxdata/xml2vmx-floppy-device.vmx
index b0bb348..add97cf 100644
--- a/tests/xml2vmxdata/xml2vmx-floppy-device.vmx
+++ b/tests/xml2vmxdata/xml2vmx-floppy-device.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-floppy-file.vmx b/tests/xml2vmxdata/xml2vmx-floppy-file.vmx
index 22a7e03..11ffb01 100644
--- a/tests/xml2vmxdata/xml2vmx-floppy-file.vmx
+++ b/tests/xml2vmxdata/xml2vmx-floppy-file.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-graphics-vnc.vmx b/tests/xml2vmxdata/xml2vmx-graphics-vnc.vmx
index f233e7b..caab06a 100644
--- a/tests/xml2vmxdata/xml2vmx-graphics-vnc.vmx
+++ b/tests/xml2vmxdata/xml2vmx-graphics-vnc.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-1.vmx b/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-1.vmx
index 3ad8a94..48476d6 100644
--- a/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-1.vmx
+++ b/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-1.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-2.vmx b/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-2.vmx
index 88dac5d..757083a 100644
--- a/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-2.vmx
+++ b/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-2.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-3.vmx b/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-3.vmx
index 06eac3a..74cd47d 100644
--- a/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-3.vmx
+++ b/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-3.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-4.vmx b/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-4.vmx
index 718ac48..c9da229 100644
--- a/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-4.vmx
+++ b/tests/xml2vmxdata/xml2vmx-gsx-in-the-wild-4.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-harddisk-ide-file.vmx b/tests/xml2vmxdata/xml2vmx-harddisk-ide-file.vmx
index daff969..700b242 100644
--- a/tests/xml2vmxdata/xml2vmx-harddisk-ide-file.vmx
+++ b/tests/xml2vmxdata/xml2vmx-harddisk-ide-file.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-harddisk-scsi-file.vmx b/tests/xml2vmxdata/xml2vmx-harddisk-scsi-file.vmx
index 150aeaf..95b9cf3 100644
--- a/tests/xml2vmxdata/xml2vmx-harddisk-scsi-file.vmx
+++ b/tests/xml2vmxdata/xml2vmx-harddisk-scsi-file.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-minimal-64bit.vmx b/tests/xml2vmxdata/xml2vmx-minimal-64bit.vmx
index a1118de..b5eef75 100644
--- a/tests/xml2vmxdata/xml2vmx-minimal-64bit.vmx
+++ b/tests/xml2vmxdata/xml2vmx-minimal-64bit.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other-64"
diff --git a/tests/xml2vmxdata/xml2vmx-minimal.vmx b/tests/xml2vmxdata/xml2vmx-minimal.vmx
index 38004f8..3aba6d6 100644
--- a/tests/xml2vmxdata/xml2vmx-minimal.vmx
+++ b/tests/xml2vmxdata/xml2vmx-minimal.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-parallel-device.vmx b/tests/xml2vmxdata/xml2vmx-parallel-device.vmx
index 065cf1d..4da65f6 100644
--- a/tests/xml2vmxdata/xml2vmx-parallel-device.vmx
+++ b/tests/xml2vmxdata/xml2vmx-parallel-device.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-parallel-file.vmx b/tests/xml2vmxdata/xml2vmx-parallel-file.vmx
index d46de16..0618109 100644
--- a/tests/xml2vmxdata/xml2vmx-parallel-file.vmx
+++ b/tests/xml2vmxdata/xml2vmx-parallel-file.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-scsi-driver.vmx b/tests/xml2vmxdata/xml2vmx-scsi-driver.vmx
index b58dbe6..0b03634 100644
--- a/tests/xml2vmxdata/xml2vmx-scsi-driver.vmx
+++ b/tests/xml2vmxdata/xml2vmx-scsi-driver.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-scsi-writethrough.vmx b/tests/xml2vmxdata/xml2vmx-scsi-writethrough.vmx
index 9b08c57..ef6b07a 100644
--- a/tests/xml2vmxdata/xml2vmx-scsi-writethrough.vmx
+++ b/tests/xml2vmxdata/xml2vmx-scsi-writethrough.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-serial-device.vmx b/tests/xml2vmxdata/xml2vmx-serial-device.vmx
index 2f86e83..940e82c 100644
--- a/tests/xml2vmxdata/xml2vmx-serial-device.vmx
+++ b/tests/xml2vmxdata/xml2vmx-serial-device.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-serial-file.vmx b/tests/xml2vmxdata/xml2vmx-serial-file.vmx
index aae79f1..11c1194 100644
--- a/tests/xml2vmxdata/xml2vmx-serial-file.vmx
+++ b/tests/xml2vmxdata/xml2vmx-serial-file.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-serial-network-client.vmx b/tests/xml2vmxdata/xml2vmx-serial-network-client.vmx
index d10f403..00ed186 100644
--- a/tests/xml2vmxdata/xml2vmx-serial-network-client.vmx
+++ b/tests/xml2vmxdata/xml2vmx-serial-network-client.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "7"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-serial-network-server.vmx b/tests/xml2vmxdata/xml2vmx-serial-network-server.vmx
index b5d77f4..ff2384f 100644
--- a/tests/xml2vmxdata/xml2vmx-serial-network-server.vmx
+++ b/tests/xml2vmxdata/xml2vmx-serial-network-server.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "7"
guestOS = "other"
diff --git a/tests/xml2vmxdata/xml2vmx-serial-pipe.vmx b/tests/xml2vmxdata/xml2vmx-serial-pipe.vmx
index 64462f6..ce6a356 100644
--- a/tests/xml2vmxdata/xml2vmx-serial-pipe.vmx
+++ b/tests/xml2vmxdata/xml2vmx-serial-pipe.vmx
@@ -1,3 +1,4 @@
+.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] Fix warning about a non-literal format string in qemu_driver.c
by Laine Stump
I just committed this under the obvious fix rule.
---
src/qemu/qemu_driver.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 16f34f7..0ce2d40 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10385,7 +10385,7 @@ qemuDomainIsMigratable(virDomainDefPtr def)
{
if (def->nhostdevs > 0) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
- _("Domain with assigned host devices cannot be migrated"));
+ "%s", _("Domain with assigned host devices cannot be migrated"));
return false;
}
--
1.7.3.1
14 years, 1 month
[libvirt] [PATCH v2] Make sure that filedescriptors are only closed once
by Stefan Berger
V2:
also the path where close() failed needs to be corrected;
-> time for a VIR_CLOSE() ?
Setting fd=-1 in these places makes sure that the fd is not closed twice
later on in 'clean:'. This is of course a recipe for disaster in a
multi-threaded system where the filedescriptor can belong to something
else right away.
At least we have a pattern...
(looks like I can close the augeas bug as well...)
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/conf/domain_conf.c | 5 ++++-
src/conf/network_conf.c | 5 ++++-
src/conf/nwfilter_conf.c | 10 ++++++++--
src/conf/storage_conf.c | 5 ++++-
4 files changed, 20 insertions(+), 5 deletions(-)
Index: libvirt-acl/src/conf/domain_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/domain_conf.c
+++ libvirt-acl/src/conf/domain_conf.c
@@ -6802,13 +6802,16 @@ int virDomainSaveXML(const char *configD
virReportSystemError(errno,
_("cannot save config file '%s'"),
configFile);
- goto cleanup;
+ goto cleanup_free;
}
+ fd = -1;
+
ret = 0;
cleanup:
if (fd != -1)
close(fd);
+ cleanup_free:
VIR_FREE(configFile);
return ret;
}
Index: libvirt-acl/src/conf/network_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/network_conf.c
+++ libvirt-acl/src/conf/network_conf.c
@@ -691,15 +691,18 @@ int virNetworkSaveXML(const char *config
virReportSystemError(errno,
_("cannot save config file '%s'"),
configFile);
- goto cleanup;
+ goto cleanup_free;
}
+ fd = -1;
+
ret = 0;
cleanup:
if (fd != -1)
close(fd);
+ cleanup_free:
VIR_FREE(configFile);
return ret;
Index: libvirt-acl/src/conf/nwfilter_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.c
+++ libvirt-acl/src/conf/nwfilter_conf.c
@@ -2197,15 +2197,18 @@ int virNWFilterSaveXML(const char *confi
virReportSystemError(errno,
_("cannot save config file '%s'"),
configFile);
- goto cleanup;
+ goto cleanup_free;
}
+ fd = -1;
+
ret = 0;
cleanup:
if (fd != -1)
close(fd);
+ cleanup_free:
VIR_FREE(configFile);
return ret;
@@ -2608,15 +2611,18 @@ virNWFilterPoolObjSaveDef(virNWFilterDri
virReportSystemError(errno,
_("cannot save config file %s"),
pool->configFile);
- goto cleanup;
+ goto cleanup_free;
}
+ fd = -1;
+
ret = 0;
cleanup:
if (fd != -1)
close(fd);
+ cleanup_free:
VIR_FREE(xml);
return ret;
Index: libvirt-acl/src/conf/storage_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/storage_conf.c
+++ libvirt-acl/src/conf/storage_conf.c
@@ -1564,15 +1564,18 @@ virStoragePoolObjSaveDef(virStorageDrive
virReportSystemError(errno,
_("cannot save config file %s"),
pool->configFile);
- goto cleanup;
+ goto cleanup_free;
}
+ fd = -1;
+
ret = 0;
cleanup:
if (fd != -1)
close(fd);
+ cleanup_free:
VIR_FREE(xml);
return ret;
14 years, 1 month
[libvirt] [PATCH] build: skip xenapi driver when building for RHEL
by Eric Blake
https://bugzilla.redhat.com/show_bug.cgi?id=643118
* libvirt.spec.in: Provide xenapi conditionals.
---
Hmm - there's probably other things we could do to sync libvirt.spec.in
back with RHEL builds; for example, the fact that RHEL 6.0 beta builds
ESX by default needs to be updated here.
libvirt.spec.in | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index a58be54..e8126b4 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -37,6 +37,7 @@
%define with_lxc 0%{!?_without_lxc:%{server_drivers}}
%define with_vbox 0%{!?_without_vbox:%{server_drivers}}
%define with_uml 0%{!?_without_uml:%{server_drivers}}
+%define with_xenapi 0%{!?_without_xenapi:%{server_drivers}}
# XXX this shouldn't be here, but it mistakenly links into libvirtd
%define with_one 0%{!?_without_one:%{server_drivers}}
@@ -83,7 +84,8 @@
%define with_numactl 0
%endif
-# RHEL doesn't ship OpenVZ, VBox, UML, OpenNebula, PowerHypervisor or ESX
+# RHEL doesn't ship OpenVZ, VBox, UML, OpenNebula, PowerHypervisor, ESX,
+# or libxenserver (xenapi)
%if 0%{?rhel}
%define with_openvz 0
%define with_vbox 0
@@ -91,6 +93,7 @@
%define with_one 0
%define with_phyp 0
%define with_esx 0
+%define with_xenapi 0
%endif
# RHEL-5 has restricted QEMU to x86_64 only and is too old for LXC
@@ -445,6 +448,10 @@ of recent versions of Linux (and other OSes).
%define _without_vbox --without-vbox
%endif
+%if ! %{with_xenapi}
+%define _without_xenapi --without-xenapi
+%endif
+
%if ! %{with_sasl}
%define _without_sasl --without-sasl
%endif
@@ -550,6 +557,7 @@ of recent versions of Linux (and other OSes).
%{?_without_openvz} \
%{?_without_lxc} \
%{?_without_vbox} \
+ %{?_without_xenapi} \
%{?_without_sasl} \
%{?_without_avahi} \
%{?_without_polkit} \
--
1.7.2.3
14 years, 1 month
[libvirt] libvirt & cgroup support - why are vm cgroups created under libvirt cgroup?
by Nikola Ciprich
Hello,
I'd like to use cgroups for resources counting and management, but I'd like
to use blkio-cgroup controller as well. I created simple patch for libvirt adding
support for it (and I'd like to submit the patch once it's tested properly).
But it seems that blkio-cgroup controller doesn't support cgroups inside cgroups
(the way libvirt uses them - /cgroup/libvirt/vmxxx).
Is there some possibility libvirt would be adjusted to support separate toplevel
cgroup for each vm so blkio-cgroup could be used?
Or is there some important reason for the way it works now?
thanks a lot in advance for any reply
with best regards
nik
--
-------------------------------------
Ing. Nikola CIPRICH
LinuxBox.cz, s.r.o.
28. rijna 168, 709 01 Ostrava
tel.: +420 596 603 142
fax: +420 596 621 273
mobil: +420 777 093 799
www.linuxbox.cz
mobil servis: +420 737 238 656
email servis: servis(a)linuxbox.cz
-------------------------------------
14 years, 1 month
Re: [libvirt] [virt-tools-list] [PATCH] add AM_MAINTAINER_MODE macro
by Eric Blake
[adding libvir-list]
On 10/15/2010 06:06 AM, Eric Blake wrote:
> On 10/15/2010 05:29 AM, Guido Günther wrote:
>> Hi,
>> On Wed, Sep 29, 2010 at 04:46:23PM +0200, Guido Günther wrote:
>
> Odd - I cannot find the original mail, even when looking in the archives:
> https://www.redhat.com/archives/libvir-list/2010-September/date.html
Oh, I see why - I was looking on the wrong list. Libvirt patches should
generally be sent to libvir-list.
>
>>> Hi,
>>> Please add the AM_MAINTAINER_MODE macro to configure.ac for
>>> virt-manager. This allows downstream distributions to disable this
>>> feature so no autotools are required to build the package. The patch
>>> doesn't change behaviour for upstream:
>>>
>>> http://www.gnu.org/software/hello/manual/automake/maintainer_002dmode.html
>>>
>
> The automake manual recommends against maintainer mode:
> http://www.gnu.org/software/automake/manual/automake.html#maintainer_002d...
>
>
>> Several years ago François Pinard pointed out several arguments
>> against this AM_MAINTAINER_MODE macro. Most of them relate to
>> insecurity. By removing dependencies you get non-dependable builds:
>> changes to sources files can have no effect on generated files and
>> this can be very confusing when unnoticed. He adds that security
>> shouldn't be reserved to maintainers (what --enable-maintainer-mode
>> suggests), on the contrary. If one user has to modify a Makefile.am,
>> then either Makefile.in should be updated or a warning should be
>> output (this is what Automake uses missing for) but the last thing you
>> want is that nothing happens and the user doesn't notice it (this is
>> what happens when rebuild rules are disabled by AM_MAINTAINER_MODE).
>>
>> Jim Meyering, the inventor of the AM_MAINTAINER_MODE macro was swayed
>> by François's arguments, and got rid of AM_MAINTAINER_MODE in all of
>> his packages.
>
> Furthermore, downstream distributions should not require autotools to
> build a package if they do not make any changes to any of the
> configure.ac/Makefile.am source files in the first place; and
> conversely, if you ARE patching those files, then you WANT to rerun the
> autotools and not silently disable them.
>
>>> AM_INIT_AUTOMAKE([-Wno-portability])
>>> +AM_MAINTAINER_MODE([enable])
>>>
>>
>> Any chance this gets applied?
>
> I'm very reluctant to make this change without a better demonstration
> why you think it is needed, and only after exhausting other attempts to
> fix the root cause problem that you are really hitting.
>
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
14 years, 1 month
[libvirt] usage of PKG_CHECK_ in libvirt
by Alejandro Mery
hi,
I want to try to add some basic support for (linux-)vserver to libvirt
and after reading some old mail threads I noticed you vanished
PKG_CHECK_EXISTS back in 2008. is it still not welcomed in libvirt?
PKG_CHECK_MODULES also?
Thanks,
Alejandro Mery
14 years, 1 month
[libvirt] [PATCH] Make sure that filedescriptors are only closed once
by Stefan Berger
Setting fd=-1 in these places makes sure that the fd is not closed
twice later on in 'clean:'. This is of course a recipe for disaster in a
multi-threaded system where the filedescriptor can belong to something
else right away.
At least we have a pattern...
(looks like I can close the augeas bug as well...)
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/conf/domain_conf.c | 2 ++
src/conf/network_conf.c | 2 ++
src/conf/nwfilter_conf.c | 4 ++++
src/conf/storage_conf.c | 2 ++
4 files changed, 10 insertions(+)
Index: libvirt-acl/src/conf/domain_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/domain_conf.c
+++ libvirt-acl/src/conf/domain_conf.c
@@ -6805,6 +6805,8 @@ int virDomainSaveXML(const char *configD
goto cleanup;
}
+ fd = -1;
+
ret = 0;
cleanup:
if (fd != -1)
Index: libvirt-acl/src/conf/network_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/network_conf.c
+++ libvirt-acl/src/conf/network_conf.c
@@ -694,6 +694,8 @@ int virNetworkSaveXML(const char *config
goto cleanup;
}
+ fd = -1;
+
ret = 0;
cleanup:
Index: libvirt-acl/src/conf/nwfilter_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.c
+++ libvirt-acl/src/conf/nwfilter_conf.c
@@ -2200,6 +2200,8 @@ int virNWFilterSaveXML(const char *confi
goto cleanup;
}
+ fd = -1;
+
ret = 0;
cleanup:
@@ -2611,6 +2613,8 @@ virNWFilterPoolObjSaveDef(virNWFilterDri
goto cleanup;
}
+ fd = -1;
+
ret = 0;
cleanup:
Index: libvirt-acl/src/conf/storage_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/storage_conf.c
+++ libvirt-acl/src/conf/storage_conf.c
@@ -1567,6 +1567,8 @@ virStoragePoolObjSaveDef(virStorageDrive
goto cleanup;
}
+ fd = -1;
+
ret = 0;
cleanup:
14 years, 1 month
[libvirt] [PATCH] esx: Handle name escaping properly
by Matthias Bolte
VMware uses a mix of percent-, pipe- and base64-encoding in
different combinations in different places.
Add a testcase for this.
---
src/esx/README | 25 ++++
src/esx/esx_driver.c | 72 ++++++-----
src/esx/esx_storage_driver.c | 42 ++++++-
src/esx/esx_util.c | 198 ++++++++++++++++++++++++++++++
src/esx/esx_util.h | 18 +++
src/esx/esx_vi.c | 6 +
src/esx/esx_vmx.c | 88 +++++---------
tests/esxutilstest.c | 51 ++++++++
tests/xml2vmxdata/xml2vmx-annotation.vmx | 2 +-
9 files changed, 405 insertions(+), 97 deletions(-)
diff --git a/src/esx/README b/src/esx/README
index 9ae93b1..b7a5865 100644
--- a/src/esx/README
+++ b/src/esx/README
@@ -86,3 +86,28 @@ It tries to cancel the blocked task, but this may not be possible, because
there are task like the power-on task that is marked as non-cancelable. So the
driver may leave blocked tasks behind if automatic question handling is
disabled.
+
+
+
+Different escaping schemes used in different places
+===================================================
+
+A domain name in the vSphere API has [%/\] escaped as %XX (percent-encoding),
+where XX is the ASCII code of the escaped char in hex.
+
+A domainName entry in a VMX config file is percent-encoded and has [|"] escaped
+as |XX (pipe-encoding).
+
+A annotation entry in a VMX config file is pipe-encoded.
+
+A datastore item name has the special Windows path characters ["*<>:|?]
+replaced by underscores (_). The result is escaped using percent-encoding and
+base64-encoding. This isn't a bijective encoding. Therefore, escaped datastore
+item names cannot be unescaped completely.
+
+For base64-encoding sequences of chars that don't match [a-zA-Z0-9'(),. _-]
+are replaced by their base64 form (the padding is omitted). An encoded sequence
+begins with a plus (+), ends with a minus (-) and can contain a plus (+). The
+minus (-) is omitted if the string ends in a base64-encoded sequence. VMware
+uses the comma (,) instead of the slash (/) in the base64 alphabet to avoid
+conflicts with the slash as path separator.
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index e959be2..8bc3be2 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2708,7 +2708,6 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachineList = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
- esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_VirtualMachinePowerState powerState;
int count = 0;
int i;
@@ -2745,27 +2744,15 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
continue;
}
- for (dynamicProperty = virtualMachine->propSet;
- dynamicProperty != NULL;
- dynamicProperty = dynamicProperty->_next) {
- if (STREQ(dynamicProperty->name, "name")) {
- if (esxVI_AnyType_ExpectType(dynamicProperty->val,
- esxVI_Type_String) < 0) {
- goto cleanup;
- }
-
- names[count] = strdup(dynamicProperty->val->string);
+ names[count] = NULL;
- if (names[count] == NULL) {
- virReportOOMError();
- goto cleanup;
- }
-
- count++;
- break;
- }
+ if (esxVI_GetVirtualMachineIdentity(virtualMachine, NULL, &names[count],
+ NULL) < 0) {
+ goto cleanup;
}
+ ++count;
+
if (count >= maxnames) {
break;
}
@@ -2864,14 +2851,18 @@ esxDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
return result;
}
+
+
static int
esxDomainCreate(virDomainPtr domain)
{
return esxDomainCreateWithFlags(domain, 0);
}
+
+
static virDomainPtr
-esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
+esxDomainDefineXML(virConnectPtr conn, const char *xml)
{
esxPrivate *priv = conn->privateData;
virDomainDefPtr def = NULL;
@@ -2883,6 +2874,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
esxVMX_Data data;
char *datastoreName = NULL;
char *directoryName = NULL;
+ char *escapedName = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *url = NULL;
char *datastoreRelatedPath = NULL;
@@ -2912,6 +2904,13 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
goto cleanup;
}
+ if (virtualMachine == NULL &&
+ esxVI_LookupVirtualMachineByName(priv->primary, def->name, NULL,
+ &virtualMachine,
+ esxVI_Occurrence_OptionalItem) < 0) {
+ goto cleanup;
+ }
+
if (virtualMachine != NULL) {
/* FIXME */
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2992,7 +2991,13 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
virBufferAddChar(&buffer, '/');
}
- virBufferURIEncodeString(&buffer, def->name);
+ escapedName = esxUtil_EscapeDatastoreItem(def->name);
+
+ if (escapedName == NULL) {
+ goto cleanup;
+ }
+
+ virBufferURIEncodeString(&buffer, escapedName);
virBufferAddLit(&buffer, ".vmx?dcPath=");
virBufferURIEncodeString(&buffer, priv->primary->datacenter->name);
virBufferAddLit(&buffer, "&dsName=");
@@ -3005,29 +3010,31 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
url = virBufferContentAndReset(&buffer);
+ /* Check, if VMX file already exists */
+ /* FIXME */
+
+ /* Upload VMX file */
+ VIR_DEBUG("Uploading .vmx config, url='%s' vmx='%s'", url, vmx);
+
+ if (esxVI_Context_UploadFile(priv->primary, url, vmx) < 0) {
+ goto cleanup;
+ }
+
+ /* Register the domain */
if (directoryName != NULL) {
if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName,
- directoryName, def->name) < 0) {
+ directoryName, escapedName) < 0) {
virReportOOMError();
goto cleanup;
}
} else {
if (virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName,
- def->name) < 0) {
+ escapedName) < 0) {
virReportOOMError();
goto cleanup;
}
}
- /* Check, if VMX file already exists */
- /* FIXME */
-
- /* Upload VMX file */
- if (esxVI_Context_UploadFile(priv->primary, url, vmx) < 0) {
- goto cleanup;
- }
-
- /* Register the domain */
if (esxVI_RegisterVM_Task(priv->primary, priv->primary->datacenter->vmFolder,
datastoreRelatedPath, NULL, esxVI_Boolean_False,
priv->primary->computeResource->resourcePool,
@@ -3061,6 +3068,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
VIR_FREE(vmx);
VIR_FREE(datastoreName);
VIR_FREE(directoryName);
+ VIR_FREE(escapedName);
VIR_FREE(url);
VIR_FREE(datastoreRelatedPath);
esxVI_ObjectContent_Free(&virtualMachine);
diff --git a/src/esx/esx_storage_driver.c b/src/esx/esx_storage_driver.c
index 329020b..72e0d7a 100644
--- a/src/esx/esx_storage_driver.c
+++ b/src/esx/esx_storage_driver.c
@@ -915,9 +915,13 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
virStoragePoolDef poolDef;
virStorageVolDefPtr def = NULL;
char *tmp;
- char *datastorePath = NULL;
+ char *unescapedDatastorePath = NULL;
+ char *unescapedDirectoryName = NULL;
+ char *unescapedDirectoryAndFileName = NULL;
char *directoryName = NULL;
+ char *fileName = NULL;
char *datastorePathWithoutFileName = NULL;
+ char *datastorePath = NULL;
esxVI_FileInfo *fileInfo = NULL;
esxVI_FileBackedVirtualDiskSpec *virtualDiskSpec = NULL;
esxVI_ManagedObjectReference *task = NULL;
@@ -995,15 +999,30 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
goto cleanup;
}
- if (virAsprintf(&datastorePath, "[%s] %s", pool->name, def->name) < 0) {
+ if (virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name,
+ def->name) < 0) {
virReportOOMError();
goto cleanup;
}
if (def->target.format == VIR_STORAGE_FILE_VMDK) {
- /* Create directory, if it doesn't exist yet */
- if (esxUtil_ParseDatastorePath(datastorePath, NULL, &directoryName,
- NULL) < 0) {
+ /* Parse and escape datastore path */
+ if (esxUtil_ParseDatastorePath(unescapedDatastorePath, NULL,
+ &unescapedDirectoryName,
+ &unescapedDirectoryAndFileName) < 0) {
+ goto cleanup;
+ }
+
+ directoryName = esxUtil_EscapeDatastoreItem(unescapedDirectoryName);
+
+ if (directoryName == NULL) {
+ goto cleanup;
+ }
+
+ fileName = esxUtil_EscapeDatastoreItem(unescapedDirectoryAndFileName +
+ strlen(unescapedDirectoryName) + 1);
+
+ if (fileName == NULL) {
goto cleanup;
}
@@ -1013,6 +1032,13 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
goto cleanup;
}
+ if (virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName,
+ fileName) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ /* Create directory, if it doesn't exist yet */
if (esxVI_LookupFileInfoByDatastorePath
(priv->primary, datastorePathWithoutFileName, true, &fileInfo,
esxVI_Occurrence_OptionalItem) < 0) {
@@ -1115,9 +1141,13 @@ esxStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc,
esxVI_ObjectContent_Free(&datastore);
esxVI_DatastoreInfo_Free(&datastoreInfo);
virStorageVolDefFree(def);
- VIR_FREE(datastorePath);
+ VIR_FREE(unescapedDatastorePath);
+ VIR_FREE(unescapedDirectoryName);
+ VIR_FREE(unescapedDirectoryAndFileName);
VIR_FREE(directoryName);
+ VIR_FREE(fileName);
VIR_FREE(datastorePathWithoutFileName);
+ VIR_FREE(datastorePath);
esxVI_FileInfo_Free(&fileInfo);
esxVI_FileBackedVirtualDiskSpec_Free(&virtualDiskSpec);
esxVI_ManagedObjectReference_Free(&task);
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 99cc4f6..5fe72fc 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -24,6 +24,7 @@
#include <config.h>
+#include <c-ctype.h>
#include <netdb.h>
#include "internal.h"
@@ -621,3 +622,200 @@ esxUtil_ReformatUuid(const char *input, char *output)
return 0;
}
+
+
+
+char *
+esxUtil_EscapeHex(const char *string, char escape, const char *special)
+{
+ char *escaped = NULL;
+ size_t length = 1; /* 1 byte for termination */
+ const char *tmp1 = string;
+ char *tmp2;
+
+ /* Calculate length of escaped string */
+ while (*tmp1 != '\0') {
+ if (*tmp1 == escape || strspn(tmp1, special) > 0) {
+ length += 2;
+ }
+
+ ++tmp1;
+ ++length;
+ }
+
+ if (VIR_ALLOC_N(escaped, length) < 0) {
+ virReportOOMError();
+ return NULL;
+ }
+
+ tmp1 = string; /* reading from this one */
+ tmp2 = escaped; /* writing to this one */
+
+ /* Escape to 'cXX' where c is the escape char and X is a hex digit */
+ while (*tmp1 != '\0') {
+ if (*tmp1 == escape || strspn(tmp1, special) > 0) {
+ *tmp2++ = escape;
+
+ snprintf(tmp2, 3, "%02x", (unsigned int)*tmp1);
+
+ tmp2 += 2;
+ } else {
+ *tmp2++ = *tmp1;
+ }
+
+ ++tmp1;
+ }
+
+ *tmp2 = '\0';
+
+ return escaped;
+}
+
+
+
+int
+esxUtil_UnescapeHex(char *string, char escape)
+{
+ char *tmp1 = string; /* reading from this one */
+ char *tmp2 = string; /* writing to this one */
+
+ /* Unescape from 'cXX' where c is the escape char and X is a hex digit */
+ while (*tmp1 != '\0') {
+ if (*tmp1 == escape) {
+ if (!c_isxdigit(tmp1[1]) || !c_isxdigit(tmp1[2])) {
+ return -1;
+ }
+
+ *tmp2++ = virHexToBin(tmp1[1]) * 16 + virHexToBin(tmp1[2]);
+ tmp1 += 3;
+ } else {
+ *tmp2++ = *tmp1++;
+ }
+ }
+
+ *tmp2 = '\0';
+
+ return 0;
+}
+
+
+
+char *
+esxUtil_EscapeBase64(const char *string)
+{
+ /* 'normal' characters don't get base64 encoded */
+ static const char *normal =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'(),. _-";
+
+ /* VMware uses ',' instead of the path separator '/' in the base64 alphabet */
+ static const char *base64 =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
+
+ virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ const char *tmp1 = string;
+ size_t length;
+ unsigned char c1, c2, c3;
+
+ /* Escape sequences of non-'normal' characters as base64 without padding */
+ while (*tmp1 != '\0') {
+ length = strspn(tmp1, normal);
+
+ if (length > 0) {
+ virBufferAdd(&buffer, tmp1, length);
+
+ tmp1 += length;
+ } else {
+ length = strcspn(tmp1, normal);
+
+ virBufferAddChar(&buffer, '+');
+
+ while (length > 0) {
+ c1 = *tmp1++;
+ c2 = length > 1 ? *tmp1++ : 0;
+ c3 = length > 2 ? *tmp1++ : 0;
+
+ virBufferAddChar(&buffer, base64[(c1 >> 2) & 0x3f]);
+ virBufferAddChar(&buffer, base64[((c1 << 4) + (c2 >> 4)) & 0x3f]);
+
+ if (length > 1) {
+ virBufferAddChar(&buffer, base64[((c2 << 2) + (c3 >> 6)) & 0x3f]);
+ }
+
+ if (length > 2) {
+ virBufferAddChar(&buffer, base64[c3 & 0x3f]);
+ }
+
+ length -= length > 3 ? 3 : length;
+ }
+
+ if (*tmp1 != '\0') {
+ virBufferAddChar(&buffer, '-');
+ }
+ }
+ }
+
+ if (virBufferError(&buffer)) {
+ virReportOOMError();
+ virBufferFreeAndReset(&buffer);
+
+ return NULL;
+ }
+
+ return virBufferContentAndReset(&buffer);
+}
+
+
+
+void
+esxUtil_ReplaceSpecialWindowsPathChars(char *string)
+{
+ /* '/' and '\\' are missing on purpose */
+ static const char *specials = "\"*<>:|?";
+
+ char *tmp = string;
+ size_t length;
+
+ while (*tmp != '\0') {
+ length = strspn(tmp, specials);
+
+ while (length > 0) {
+ *tmp++ = '_';
+ --length;
+ }
+
+ if (*tmp != '\0') {
+ ++tmp;
+ }
+ }
+}
+
+
+
+char *
+esxUtil_EscapeDatastoreItem(const char *string)
+{
+ char *replaced = strdup(string);
+ char *escaped1;
+ char *escaped2 = NULL;
+
+ if (replaced == NULL) {
+ virReportOOMError();
+ return NULL;
+ }
+
+ esxUtil_ReplaceSpecialWindowsPathChars(replaced);
+
+ escaped1 = esxUtil_EscapeHexPercent(replaced);
+
+ if (escaped1 == NULL) {
+ goto cleanup;
+ }
+
+ escaped2 = esxUtil_EscapeBase64(escaped1);
+
+ cleanup:
+ VIR_FREE(replaced);
+ VIR_FREE(escaped1);
+
+ return escaped2;
+}
diff --git a/src/esx/esx_util.h b/src/esx/esx_util.h
index 650f145..669a4f2 100644
--- a/src/esx/esx_util.h
+++ b/src/esx/esx_util.h
@@ -71,4 +71,22 @@ int esxUtil_GetConfigBoolean(virConfPtr conf, const char *name, bool *boolean_,
int esxUtil_ReformatUuid(const char *input, char *output);
+char *esxUtil_EscapeHex(const char *string, char escape, const char *special);
+
+# define esxUtil_EscapeHexPipe(_string) esxUtil_EscapeHex(_string, '|', "\"")
+
+# define esxUtil_EscapeHexPercent(_string) esxUtil_EscapeHex(_string, '%', "/\\")
+
+int esxUtil_UnescapeHex(char *string, char escape);
+
+# define esxUtil_UnescapeHexPipe(_string) esxUtil_UnescapeHex(_string, '|')
+
+# define esxUtil_UnescapeHexPercent(_string) esxUtil_UnescapeHex(_string, '%')
+
+char *esxUtil_EscapeBase64(const char *string);
+
+void esxUtil_ReplaceSpecialWindowsPathChars(char *string);
+
+char *esxUtil_EscapeDatastoreItem(const char *string);
+
#endif /* __ESX_UTIL_H__ */
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index d361f01..c450730 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -2014,6 +2014,12 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
goto failure;
}
+ if (esxUtil_UnescapeHexPercent(*name) < 0) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Domain name contains invalid escape sequence"));
+ goto failure;
+ }
+
break;
}
}
diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index ece16b2..e17e1e7 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -876,8 +876,6 @@ esxVMX_ParseConfig(esxVMX_Context *ctx, virCapsPtr caps, const char *vmx,
long long numvcpus = 0;
char *sched_cpu_affinity = NULL;
char *guestOS = NULL;
- char *tmp1;
- char *tmp2;
int controller;
int bus;
int port;
@@ -982,34 +980,28 @@ esxVMX_ParseConfig(esxVMX_Context *ctx, virCapsPtr caps, const char *vmx,
goto cleanup;
}
+ if (def->name != NULL) {
+ if (esxUtil_UnescapeHexPercent(def->name) < 0 ||
+ esxUtil_UnescapeHexPipe(def->name) < 0) {
+ ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("VMX entry 'name' contains invalid escape sequence"));
+ goto cleanup;
+ }
+ }
+
/* vmx:annotation -> def:description */
if (esxUtil_GetConfigString(conf, "annotation", &def->description,
true) < 0) {
goto cleanup;
}
- /* Unescape '|XX' where X is a hex digit */
if (def->description != NULL) {
- tmp1 = def->description; /* reading from this one */
- tmp2 = def->description; /* writing to this one */
-
- while (*tmp1 != '\0') {
- if (*tmp1 == '|') {
- if (!c_isxdigit(tmp1[1]) || !c_isxdigit(tmp1[2])) {
- ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("VMX entry 'annotation' contains invalid "
- "escape sequence"));
- goto cleanup;
- }
-
- *tmp2++ = virHexToBin(tmp1[1]) * 16 + virHexToBin(tmp1[2]);
- tmp1 += 3;
- } else {
- *tmp2++ = *tmp1++;
- }
+ if (esxUtil_UnescapeHexPipe(def->description) < 0) {
+ ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("VMX entry 'annotation' contains invalid escape "
+ "sequence"));
+ goto cleanup;
}
-
- *tmp2 = '\0';
}
/* vmx:memsize -> def:mem.max_balloon */
@@ -2460,9 +2452,8 @@ esxVMX_FormatConfig(esxVMX_Context *ctx, virCapsPtr caps, virDomainDefPtr def,
int sched_cpu_affinity_length;
unsigned char zero[VIR_UUID_BUFLEN];
virBuffer buffer = VIR_BUFFER_INITIALIZER;
- size_t length;
- char *tmp1;
- char *tmp2;
+ char *preliminaryDisplayName = NULL;
+ char *displayName = NULL;
char *annotation = NULL;
bool scsi_present[4] = { false, false, false, false };
int scsi_virtualDev[4] = { -1, -1, -1, -1 };
@@ -2536,44 +2527,23 @@ esxVMX_FormatConfig(esxVMX_Context *ctx, virCapsPtr caps, virDomainDefPtr def,
}
/* def:name -> vmx:displayName */
- virBufferVSprintf(&buffer, "displayName = \"%s\"\n", def->name);
-
- /* def:description -> vmx:annotation */
- if (def->description != NULL) {
- /* Escape '"' as '|22' and '|' as '|7C' */
- length = 1; /* 1 byte for termination */
- tmp1 = def->description;
-
- while (*tmp1 != '\0') {
- if (*tmp1 == '"' || *tmp1 == '|') {
- length += 2;
- }
-
- ++tmp1;
- ++length;
- }
+ preliminaryDisplayName = esxUtil_EscapeHexPipe(def->name);
- if (VIR_ALLOC_N(annotation, length) < 0) {
- virReportOOMError();
- goto cleanup;
- }
+ if (preliminaryDisplayName == NULL) {
+ goto cleanup;
+ }
- tmp1 = def->description; /* reading from this one */
- tmp2 = annotation; /* writing to this one */
+ displayName = esxUtil_EscapeHexPercent(preliminaryDisplayName);
- while (*tmp1 != '\0') {
- if (*tmp1 == '"') {
- *tmp2++ = '|'; *tmp2++ = '2'; *tmp2++ = '2';
- } else if (*tmp1 == '|') {
- *tmp2++ = '|'; *tmp2++ = '7'; *tmp2++ = 'C';
- } else {
- *tmp2++ = *tmp1;
- }
+ if (displayName == NULL) {
+ goto cleanup;
+ }
- ++tmp1;
- }
+ virBufferVSprintf(&buffer, "displayName = \"%s\"\n", displayName);
- *tmp2 = '\0';
+ /* def:description -> vmx:annotation */
+ if (def->description != NULL) {
+ annotation = esxUtil_EscapeHexPipe(def->description);
virBufferVSprintf(&buffer, "annotation = \"%s\"\n", annotation);
}
@@ -2780,6 +2750,8 @@ esxVMX_FormatConfig(esxVMX_Context *ctx, virCapsPtr caps, virDomainDefPtr def,
virBufferFreeAndReset(&buffer);
}
+ VIR_FREE(preliminaryDisplayName);
+ VIR_FREE(displayName);
VIR_FREE(annotation);
return vmx;
diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index 4906ad4..c9a59c7 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -227,6 +227,56 @@ testConvertDateTimeToCalendarTime(const void *data ATTRIBUTE_UNUSED)
+struct testDatastoreItem {
+ const char *string;
+ const char *escaped;
+};
+
+static struct testDatastoreItem datastoreItems[] = {
+ { "normal", "normal" },
+ { "Aä1ö2ü3ß4#5~6!7§8/9%Z",
+ "A+w6Q-1+w7Y-2+w7w-3+w58-4+Iw-5+fg-6+IQ-7+wqc-8+JQ-2f9+JQ-25Z" },
+ { "Z~6!7§8/9%0#1\"2'3`4&A",
+ "Z+fg-6+IQ-7+wqc-8+JQ-2f9+JQ-250+Iw-1_2'3+YA-4+Jg-A" },
+ { "標準語", "+5qiZ5rqW6Kqe" },
+ { "!\"#$%&'()*+,-./0123456789:;<=>?",
+ "+IQ-_+IyQl-25+Jg-'()_+Kw-,-.+JQ-2f0123456789_+Ow-_+PQ-__" },
+ { "A Z[\\]^_B", "A Z+WyU-5c+XV4-_B" },
+ { "A`B@{|}~DEL", "A+YA-B+QHs-_+fX4-DEL" },
+ { "hÀÁÂÃÄÅH", "h+w4DDgcOCw4PDhMOF-H" },
+ { "A쿀Z", "A+7L+A-Z" },
+ { "!쿀A", "+Iey,gA-A" },
+ { "~~~", "+fn5+" },
+ { "~~~A", "+fn5+-A" },
+ { "K%U/H\\Z", "K+JQ-25U+JQ-2fH+JQ-5cZ" },
+};
+
+static int
+testEscapeDatastoreItem(const void *data ATTRIBUTE_UNUSED)
+{
+ int i;
+ char *escaped = NULL;
+
+ for (i = 0; i < ARRAY_CARDINALITY(datastoreItems); ++i) {
+ VIR_FREE(escaped);
+
+ escaped = esxUtil_EscapeDatastoreItem(datastoreItems[i].string);
+
+ if (escaped == NULL) {
+ return -1;
+ }
+
+ if (STRNEQ(datastoreItems[i].escaped, escaped)) {
+ VIR_FREE(escaped);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
+
static int
mymain(int argc, char **argv)
{
@@ -258,6 +308,7 @@ mymain(int argc, char **argv)
DO_TEST(DiskNameToIndex);
DO_TEST(ParseDatastorePath);
DO_TEST(ConvertDateTimeToCalendarTime);
+ DO_TEST(EscapeDatastoreItem);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/xml2vmxdata/xml2vmx-annotation.vmx b/tests/xml2vmxdata/xml2vmx-annotation.vmx
index 47d060d..5754c31 100644
--- a/tests/xml2vmxdata/xml2vmx-annotation.vmx
+++ b/tests/xml2vmxdata/xml2vmx-annotation.vmx
@@ -3,7 +3,7 @@ virtualHW.version = "4"
guestOS = "other"
uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
displayName = "annotation"
-annotation = "Some |7Ctext|7C to test the |22escaping|22: |7C|7C|22|22|7C|7C|22|7C Unescaped!"
+annotation = "Some |7ctext|7c to test the |22escaping|22: |7c|7c|22|22|7c|7c|22|7c Unescaped!"
memsize = "4"
numvcpus = "1"
floppy0.present = "false"
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] nwfilter: prevent multiple filters with different name but same UUID
by Stefan Berger
Patch to prevent multiple nwfilters with different name but same UUID.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/conf/nwfilter_conf.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
Index: libvirt-acl/src/conf/nwfilter_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.c
+++ libvirt-acl/src/conf/nwfilter_conf.c
@@ -2399,6 +2399,20 @@ virNWFilterPoolObjAssignDef(virConnectPt
{
virNWFilterPoolObjPtr pool;
+ pool = virNWFilterPoolObjFindByUUID(pools, def->uuid);
+
+ if (pool) {
+ if (!STREQ(def->name, pool->def->name)) {
+ virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
+ _("filter with same UUID but different
name "
+ "('%s') already exists"),
+ pool->def->name);
+ virNWFilterPoolObjUnlock(pool);
+ return NULL;
+ }
+ virNWFilterPoolObjUnlock(pool);
+ }
+
if (virNWFilterDefLoopDetect(conn, pools, def)) {
virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
"%s", _("filter would introduce a loop"));
14 years, 1 month