Some attributes in the guest config are only valid at runtime.
Although the XML parser/formatter are careful to avoid outputting
these attributes at the wrong time, there is still a risk that
the driver code may accidentally use them internally. We can
solve this by explicitly clearing all values
* src/conf/domain_conf.h, src/conf/domain_conf.c,
src/libvirt_private.syms: Add virDomainDefClearDynamicValues
* src/lxc/lxc_driver.c, src/qemu/qemu_driver.c,
src/uml/uml_driver.c: Call virDomainDefClearDynamicValues() when
any guest shuts down.
---
src/conf/domain_conf.c | 36 ++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 2 ++
src/libvirt_private.syms | 2 ++
src/lxc/lxc_driver.c | 2 ++
src/qemu/qemu_driver.c | 2 ++
src/uml/uml_driver.c | 2 ++
6 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a1eeb06..533a1b0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5286,6 +5286,42 @@ error:
return NULL;
}
+static void virDomainDeviceAddressClearDynamicValues(virDomainDeviceAddressPtr addr)
+{
+ if (addr->mode == VIR_DOMAIN_DEVICE_ADDRESS_MODE_DYNAMIC)
+ memset(addr, 0, sizeof(*addr));
+}
+
+void virDomainDefClearDynamicValues(virDomainDefPtr def)
+{
+ int i;
+
+ def->id = -1;
+
+ for (i = 0; i < def->ngraphics ; i++) {
+ if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+ def->graphics[i]->data.vnc.autoport)
+ def->graphics[i]->data.vnc.port = -1;
+ else if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP &&
+ def->graphics[i]->data.rdp.autoport)
+ def->graphics[i]->data.rdp.port = -1;
+ }
+
+ for (i = 0 ; i < def->ndisks ; i++) {
+ virDomainDeviceAddressClearDynamicValues(&def->disks[i]->addr);
+ }
+ for (i = 0 ; i < def->nhostdevs ; i++) {
+ virDomainDeviceAddressClearDynamicValues(&def->hostdevs[i]->addr);
+ }
+ for (i = 0 ; i < def->nnets ; i++) {
+ virDomainDeviceAddressClearDynamicValues(&def->nets[i]->addr);
+ }
+
+ if (def->seclabel.type == VIR_DOMAIN_SECLABEL_DYNAMIC) {
+ VIR_FREE(def->seclabel.label);
+ VIR_FREE(def->seclabel.imagelabel);
+ }
+}
#ifndef PROXY
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f06c2dc..c93aed6 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -775,6 +775,8 @@ char *virDomainObjFormat(virConnectPtr conn,
virDomainObjPtr obj,
int flags);
+void virDomainDefClearDynamicValues(virDomainDefPtr def);
+
int virDomainCpuSetParse(virConnectPtr conn,
const char **str,
char sep,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 49df15c..285715d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -161,6 +161,8 @@ virDomainDeviceAddressIsValid;
virDomainDevicePCIAddressIsValid;
virDomainDeviceUSBAddressIsValid;
virDomainDeviceAddressClear;
+virDomainDeviceAddressTypeToString;
+virDomainDefClearDynamicValues;
# domain_event.h
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index c8e2dca..6a2fefb 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -749,6 +749,8 @@ static int lxcVmCleanup(virConnectPtr conn,
vm->newDef = NULL;
}
+ virDomainDefClearDynamicValues(vm->def);
+
return rc;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index da4fae7..85cbaf7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2617,6 +2617,8 @@ retry:
vm->def->id = -1;
vm->newDef = NULL;
}
+
+ virDomainDefClearDynamicValues(vm->def);
}
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 48ef103..44d937f 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -962,6 +962,8 @@ static void umlShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
vm->def->id = -1;
vm->newDef = NULL;
}
+
+ virDomainDefClearDynamicValues(vm->def);
}
--
1.6.5.2