In order to be able to create, modify, and destroy the internal fields that
manage the dependency information in each domain, new primitives are added.
Now, libvirt is able to parse the new <devicedependency> tag in the description
of a domain, and then to create the associated structures.
The QEMU driver is also modified in order to manage this new kind of device.
---
src/conf/domain_conf.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++-
src/conf/domain_conf.h | 2 ++
src/qemu/qemu_driver.c | 10 ++++--
src/qemu/qemu_hotplug.c | 1 +
4 files changed, 92 insertions(+), 4 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7d68096..7f5f623 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -233,7 +233,8 @@ VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST,
"shmem",
"tpm",
"panic",
- "memory")
+ "memory",
+ "domaindependency")
VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST,
"none",
@@ -2064,6 +2065,19 @@ void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def)
VIR_FREE(def);
}
+void virDomainDependencyDefFree(virDomainDependencyDefPtr def)
+{
+ if (!def)
+ return
+ virDomainDeviceInfoClear(&def->info);
+
+ VIR_FREE(def->filePath);
+ VIR_FREE(def->domainName);
+ VIR_FREE(def->domainUuid);
+
+ VIR_FREE(def);
+}
+
void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def)
{
if (!def)
@@ -2326,6 +2340,9 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
case VIR_DOMAIN_DEVICE_MEMORY:
virDomainMemoryDefFree(def->data.memory);
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
+ virDomainDependencyDefFree(def->data.dependency);
+ break;
case VIR_DOMAIN_DEVICE_LAST:
case VIR_DOMAIN_DEVICE_NONE:
break;
@@ -3142,6 +3159,8 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device)
return &device->data.panic->info;
case VIR_DOMAIN_DEVICE_MEMORY:
return &device->data.memory->info;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
+ return &device->data.dependency->info;
/* The following devices do not contain virDomainDeviceInfo */
case VIR_DOMAIN_DEVICE_LEASE:
@@ -3502,6 +3521,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
case VIR_DOMAIN_DEVICE_LAST:
case VIR_DOMAIN_DEVICE_RNG:
case VIR_DOMAIN_DEVICE_MEMORY:
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
break;
}
#endif
@@ -11592,6 +11612,43 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
goto cleanup;
}
+static virDomainDependencyDefPtr
+virDomainDependencyDefParseXML(xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
+ unsigned int flags)
+{
+ xmlNodePtr save = ctxt->node;
+
+ virDomainDependencyDefPtr def;
+ if (VIR_ALLOC(def) < 0) {
+ return NULL;
+ }
+
+ ctxt->node = node;
+
+ def->filePath = NULL;
+ def->domainName = NULL;
+ for (int i = 0; i < VIR_UUID_BUFLEN; ++i) {
+ def->domainUuid[i] = '\0';
+ }
+ def->filePath = virXPathString("string(.)", ctxt);
+
+ if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0) {
+ goto error;
+ }
+
+ ctxt->node = save;
+ return def;
+
+ error:
+ virDomainDependencyDefFree(def);
+ def = NULL;
+ ctxt->node = save;
+ return NULL;
+}
+
+
+
static virDomainNVRAMDefPtr
virDomainNVRAMDefParseXML(xmlNodePtr node,
unsigned int flags)
@@ -12848,6 +12905,10 @@ virDomainDeviceDefParse(const char *xmlStr,
if (!(dev->data.memory = virDomainMemoryDefParseXML(node, ctxt, flags)))
goto error;
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
+ if (!(dev->data.dependency = virDomainDependencyDefParseXML(node, ctxt,
flags)))
+ goto error;
+ break;
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LAST:
break;
@@ -16379,6 +16440,24 @@ virDomainDefParseXML(xmlDocPtr xml,
VIR_FREE(nodes);
}
+ if ((n = virXPathNodeSet("./devices/domaindependency", ctxt, &nodes))
< 0)
+ goto error;
+
+ if (n && VIR_ALLOC_N(def->domaindependencies, n) < 0)
+ goto error;
+
+ def->ndomaindependencies = n;
+ if (n > 0) {
+ for (i = 0; i < n; i++) {
+ virDomainDependencyDefPtr dependency =
virDomainDependencyDefParseXML(nodes[i], ctxt, flags);
+ if (!dependency) {
+ goto error;
+ }
+ def->domaindependencies[i] = dependency;
+ }
+ VIR_FREE(nodes);
+ }
+
/* Parse the RNG devices */
if ((n = virXPathNodeSet("./devices/rng", ctxt, &nodes)) < 0)
goto error;
@@ -18314,6 +18393,7 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_MEMORY:
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
break;
}
#endif
@@ -23806,6 +23886,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
rc = virDomainMemoryDefFormat(&buf, src->data.memory, flags);
break;
case VIR_DOMAIN_DEVICE_NONE:
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
case VIR_DOMAIN_DEVICE_SMARTCARD:
case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index d0b3333..95be6ad 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -176,6 +176,7 @@ typedef enum {
VIR_DOMAIN_DEVICE_TPM,
VIR_DOMAIN_DEVICE_PANIC,
VIR_DOMAIN_DEVICE_MEMORY,
+ VIR_DOMAIN_DEVICE_DEPENDENCY,
VIR_DOMAIN_DEVICE_LAST
} virDomainDeviceType;
@@ -2556,6 +2557,7 @@ int virDomainChrSourceDefCopy(virDomainChrSourceDefPtr src,
void virDomainSoundCodecDefFree(virDomainSoundCodecDefPtr def);
void virDomainSoundDefFree(virDomainSoundDefPtr def);
void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def);
+void virDomainDependencyDefFree(virDomainDependencyDefPtr def);
void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def);
void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);
void virDomainVideoDefFree(virDomainVideoDefPtr def);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a0d6596..37eef7e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7598,6 +7599,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
dev->data.memory = NULL;
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
@@ -7687,7 +7689,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
case VIR_DOMAIN_DEVICE_MEMORY:
ret = qemuDomainDetachMemoryDevice(driver, vm, dev->data.memory);
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
@@ -7811,6 +7813,7 @@ qemuDomainUpdateDeviceLive(virConnectPtr conn,
case VIR_DOMAIN_DEVICE_NET:
ret = qemuDomainChangeNet(driver, vm, dev);
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
@@ -7987,7 +7990,7 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
return -1;
dev->data.memory = NULL;
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
case VIR_DOMAIN_DEVICE_VIDEO:
@@ -8124,6 +8127,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
virDomainMemoryDefFree(virDomainMemoryRemove(vmdef, idx));
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
case VIR_DOMAIN_DEVICE_VIDEO:
@@ -8212,7 +8216,7 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
return -1;
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index b580283..243d0fc 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3319,6 +3319,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
ret = qemuDomainRemoveMemoryDevice(driver, vm, dev->data.memory);
break;
+ case VIR_DOMAIN_DEVICE_DEPENDENCY:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
--
1.9.1