[libvirt] [PATCH] Add domain type checking
by Matthias Bolte
The drivers were accepting domain configs without checking if those
were actually meant for them. For example the LXC driver happily
accepts configs with type QEMU.
For convenience add an optional check for the domain type for the
virDomainDefParse* functions. It's optional because in some places
virDomainDefParse* is used to parse a config without caring about
it's type. Also the QEMU driver has to accept 4 different types and
does this checking own it's own.
---
src/conf/domain_conf.c | 48 ++++++++++++++++++++++++++++++----------
src/conf/domain_conf.h | 5 ++++
src/esx/esx_driver.c | 5 ++-
src/libxl/libxl_driver.c | 14 ++++++-----
src/lxc/lxc_controller.c | 2 +-
src/lxc/lxc_driver.c | 13 ++++++-----
src/openvz/openvz_driver.c | 2 +
src/phyp/phyp_driver.c | 1 +
src/qemu/qemu_domain.c | 26 ++++++++++++++++++++-
src/qemu/qemu_domain.h | 8 +++++-
src/qemu/qemu_driver.c | 34 ++++++++++++++++++++--------
src/qemu/qemu_migration.c | 12 +++++-----
src/security/virt-aa-helper.c | 2 +-
src/test/test_driver.c | 11 ++++++--
src/uml/uml_driver.c | 8 +++---
src/vbox/vbox_tmpl.c | 2 +-
src/vmware/vmware_driver.c | 2 +
src/xen/xen_driver.c | 5 +--
src/xen/xend_internal.c | 5 ++-
src/xen/xm_internal.c | 2 +-
src/xenapi/xenapi_driver.c | 7 ++++-
tests/define-dev-segfault | 2 +-
tests/qemuxml2argvtest.c | 11 ++++++++-
tests/qemuxml2xmltest.c | 13 +++++++++-
tests/xmconfigtest.c | 2 +-
tests/xml2sexprtest.c | 2 +-
tests/xml2vmxtest.c | 3 +-
27 files changed, 176 insertions(+), 71 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7bcdcaf..69200ee 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1257,7 +1257,7 @@ virDomainObjSetDefTransient(virCapsPtr caps,
if (!(xml = virDomainDefFormat(domain->def, VIR_DOMAIN_XML_WRITE_FLAGS)))
goto out;
- if (!(newDef = virDomainDefParseString(caps, xml,
+ if (!(newDef = virDomainDefParseString(caps, xml, -1,
VIR_DOMAIN_XML_READ_FLAGS)))
goto out;
@@ -5760,7 +5760,8 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
xmlDocPtr xml,
xmlNodePtr root,
xmlXPathContextPtr ctxt,
- int flags)
+ int expectedVirtType,
+ unsigned int flags)
{
xmlNodePtr *nodes = NULL, node = NULL;
char *tmp = NULL;
@@ -5796,6 +5797,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
}
VIR_FREE(tmp);
+ if (expectedVirtType >= 0 && def->virtType != expectedVirtType) {
+ virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected domain type %s, should be %s"),
+ virDomainVirtTypeToString(def->virtType),
+ virDomainVirtTypeToString(expectedVirtType));
+ goto error;
+ }
+
/* Extract domain name */
if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
virDomainReportError(VIR_ERR_NO_NAME, NULL);
@@ -6704,6 +6713,7 @@ no_memory:
static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
xmlDocPtr xml,
xmlXPathContextPtr ctxt,
+ int expectedVirtType,
unsigned int flags)
{
char *tmp = NULL;
@@ -6727,7 +6737,8 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
oldnode = ctxt->node;
ctxt->node = config;
- obj->def = virDomainDefParseXML(caps, xml, config, ctxt, flags);
+ obj->def = virDomainDefParseXML(caps, xml, config, ctxt, expectedVirtType,
+ flags);
ctxt->node = oldnode;
if (!obj->def)
goto error;
@@ -6801,13 +6812,15 @@ static virDomainDefPtr
virDomainDefParse(const char *xmlStr,
const char *filename,
virCapsPtr caps,
+ int expectedVirtType,
int flags)
{
xmlDocPtr xml;
virDomainDefPtr def = NULL;
if ((xml = virXMLParse(filename, xmlStr, "domain.xml"))) {
- def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml), flags);
+ def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml),
+ expectedVirtType, flags);
xmlFreeDoc(xml);
}
@@ -6816,22 +6829,25 @@ virDomainDefParse(const char *xmlStr,
virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
const char *xmlStr,
+ int expectedVirtType,
unsigned int flags)
{
- return virDomainDefParse(xmlStr, NULL, caps, flags);
+ return virDomainDefParse(xmlStr, NULL, caps, expectedVirtType, flags);
}
virDomainDefPtr virDomainDefParseFile(virCapsPtr caps,
const char *filename,
+ int expectedVirtType,
unsigned int flags)
{
- return virDomainDefParse(NULL, filename, caps, flags);
+ return virDomainDefParse(NULL, filename, caps, expectedVirtType, flags);
}
virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
xmlDocPtr xml,
xmlNodePtr root,
+ int expectedVirtType,
unsigned int flags)
{
xmlXPathContextPtr ctxt = NULL;
@@ -6850,7 +6866,7 @@ virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
}
ctxt->node = root;
- def = virDomainDefParseXML(caps, xml, root, ctxt, flags);
+ def = virDomainDefParseXML(caps, xml, root, ctxt, expectedVirtType, flags);
cleanup:
xmlXPathFreeContext(ctxt);
@@ -6862,6 +6878,7 @@ static virDomainObjPtr
virDomainObjParseNode(virCapsPtr caps,
xmlDocPtr xml,
xmlNodePtr root,
+ int expectedVirtType,
unsigned int flags)
{
xmlXPathContextPtr ctxt = NULL;
@@ -6880,7 +6897,7 @@ virDomainObjParseNode(virCapsPtr caps,
}
ctxt->node = root;
- obj = virDomainObjParseXML(caps, xml, ctxt, flags);
+ obj = virDomainObjParseXML(caps, xml, ctxt, expectedVirtType, flags);
cleanup:
xmlXPathFreeContext(ctxt);
@@ -6890,6 +6907,7 @@ cleanup:
virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
const char *filename,
+ int expectedVirtType,
unsigned int flags)
{
xmlDocPtr xml;
@@ -6897,7 +6915,8 @@ virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
if ((xml = virXMLParseFile(filename))) {
obj = virDomainObjParseNode(caps, xml,
- xmlDocGetRootElement(xml), flags);
+ xmlDocGetRootElement(xml),
+ expectedVirtType, flags);
xmlFreeDoc(xml);
}
@@ -10075,6 +10094,7 @@ static virDomainObjPtr virDomainLoadConfig(virCapsPtr caps,
const char *configDir,
const char *autostartDir,
const char *name,
+ int expectedVirtType,
virDomainLoadConfigNotify notify,
void *opaque)
{
@@ -10086,7 +10106,7 @@ static virDomainObjPtr virDomainLoadConfig(virCapsPtr caps,
if ((configFile = virDomainConfigFile(configDir, name)) == NULL)
goto error;
- if (!(def = virDomainDefParseFile(caps, configFile,
+ if (!(def = virDomainDefParseFile(caps, configFile, expectedVirtType,
VIR_DOMAIN_XML_INACTIVE)))
goto error;
@@ -10131,6 +10151,7 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
virDomainObjListPtr doms,
const char *statusDir,
const char *name,
+ int expectedVirtType,
virDomainLoadConfigNotify notify,
void *opaque)
{
@@ -10141,7 +10162,7 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
if ((statusFile = virDomainConfigFile(statusDir, name)) == NULL)
goto error;
- if (!(obj = virDomainObjParseFile(caps, statusFile,
+ if (!(obj = virDomainObjParseFile(caps, statusFile, expectedVirtType,
VIR_DOMAIN_XML_INTERNAL_STATUS)))
goto error;
@@ -10176,6 +10197,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
const char *configDir,
const char *autostartDir,
int liveStatus,
+ int expectedVirtType,
virDomainLoadConfigNotify notify,
void *opaque)
{
@@ -10210,6 +10232,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
doms,
configDir,
entry->d_name,
+ expectedVirtType,
notify,
opaque);
else
@@ -10218,6 +10241,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
configDir,
autostartDir,
entry->d_name,
+ expectedVirtType,
notify,
opaque);
if (dom) {
@@ -11037,7 +11061,7 @@ virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom)
if (!xml)
return NULL;
- ret = virDomainDefParseString(caps, xml, VIR_DOMAIN_XML_READ_FLAGS);
+ ret = virDomainDefParseString(caps, xml, -1, VIR_DOMAIN_XML_READ_FLAGS);
VIR_FREE(xml);
return ret;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ddfe18e..26656f4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1381,17 +1381,21 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps,
unsigned int flags);
virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
const char *xmlStr,
+ int expectedVirtType,
unsigned int flags);
virDomainDefPtr virDomainDefParseFile(virCapsPtr caps,
const char *filename,
+ int expectedVirtType,
unsigned int flags);
virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
xmlDocPtr doc,
xmlNodePtr root,
+ int expectedVirtType,
unsigned int flags);
virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
const char *filename,
+ int expectedVirtType,
unsigned int flags);
bool virDomainDefCheckABIStability(virDomainDefPtr src,
@@ -1466,6 +1470,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
const char *configDir,
const char *autostartDir,
int liveStatus,
+ int expectedVirtType,
virDomainLoadConfigNotify notify,
void *opaque);
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index a6e47a4..85da3ff 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2855,7 +2855,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
return NULL;
}
- def = virDomainDefParseString(priv->caps, domainXml, 0);
+ def = virDomainDefParseString(priv->caps, domainXml,
+ VIR_DOMAIN_VIRT_VMWARE, 0);
if (def == NULL) {
return NULL;
@@ -3068,7 +3069,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
}
/* Parse domain XML */
- def = virDomainDefParseString(priv->caps, xml,
+ def = virDomainDefParseString(priv->caps, xml, VIR_DOMAIN_VIRT_VMWARE,
VIR_DOMAIN_XML_INACTIVE);
if (def == NULL) {
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index ade69d8..4f3b8ec 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -281,6 +281,7 @@ libxlSaveImageOpen(libxlDriverPrivatePtr driver, const char *from,
}
if (!(def = virDomainDefParseString(driver->caps, xml,
+ VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE)))
goto error;
@@ -994,7 +995,7 @@ libxlStartup(int privileged) {
&libxl_driver->domains,
libxl_driver->stateDir,
libxl_driver->autostartDir,
- 1, NULL, NULL) < 0)
+ 1, VIR_DOMAIN_VIRT_XEN, NULL, NULL) < 0)
goto error;
libxlReconnectDomains(libxl_driver);
@@ -1004,7 +1005,7 @@ libxlStartup(int privileged) {
&libxl_driver->domains,
libxl_driver->configDir,
libxl_driver->autostartDir,
- 0, NULL, NULL) < 0)
+ 0, VIR_DOMAIN_VIRT_XEN, NULL, NULL) < 0)
goto error;
virHashForEach(libxl_driver->domains.objs, libxlAutostartDomain,
@@ -1037,7 +1038,7 @@ libxlReload(void)
&libxl_driver->domains,
libxl_driver->configDir,
libxl_driver->autostartDir,
- 1, NULL, libxl_driver);
+ 1, VIR_DOMAIN_VIRT_XEN, NULL, libxl_driver);
virHashForEach(libxl_driver->domains.objs, libxlAutostartDomain,
libxl_driver);
@@ -1206,7 +1207,7 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
virCheckFlags(VIR_DOMAIN_START_PAUSED, NULL);
libxlDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
+ if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
@@ -2566,7 +2567,8 @@ libxlDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
goto cleanup;
}
- if (!(def = virDomainDefParseString(driver->caps, domainXml, 0)))
+ if (!(def = virDomainDefParseString(driver->caps, domainXml,
+ VIR_DOMAIN_VIRT_XEN, 0)))
goto cleanup;
if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major)))
@@ -2667,7 +2669,7 @@ libxlDomainDefineXML(virConnectPtr conn, const char *xml)
int dupVM;
libxlDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
+ if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 31c7d4f..e9f709e 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -925,7 +925,7 @@ int main(int argc, char *argv[])
name)) == NULL)
goto cleanup;
- if ((def = virDomainDefParseFile(caps, configFile,
+ if ((def = virDomainDefParseFile(caps, configFile, VIR_DOMAIN_VIRT_LXC,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index ffcfe4d..e16cfc8 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -408,11 +408,11 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml)
int dupVM;
lxcDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
+ if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_LXC,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
- if ((dupVM = virDomainObjIsDuplicate(&driver->domains, def, 0)) < 0)
+ if ((dupVM = virDomainObjIsDuplicate(&driver->domains, def, 0)) < 0)
goto cleanup;
if ((def->nets != NULL) && !(driver->have_netns)) {
@@ -1750,7 +1750,7 @@ lxcDomainCreateAndStart(virConnectPtr conn,
virCheckFlags(0, NULL);
lxcDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
+ if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_LXC,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
@@ -2138,7 +2138,7 @@ static int lxcStartup(int privileged)
&lxc_driver->domains,
lxc_driver->stateDir,
NULL,
- 1, NULL, NULL) < 0)
+ 1, VIR_DOMAIN_VIRT_LXC, NULL, NULL) < 0)
goto cleanup;
virHashForEach(lxc_driver->domains.objs, lxcReconnectVM, lxc_driver);
@@ -2148,7 +2148,7 @@ static int lxcStartup(int privileged)
&lxc_driver->domains,
lxc_driver->configDir,
lxc_driver->autostartDir,
- 0, NULL, NULL) < 0)
+ 0, VIR_DOMAIN_VIRT_LXC, NULL, NULL) < 0)
goto cleanup;
lxcDriverUnlock(lxc_driver);
@@ -2193,7 +2193,8 @@ lxcReload(void) {
&lxc_driver->domains,
lxc_driver->configDir,
lxc_driver->autostartDir,
- 0, lxcNotifyLoadDomain, lxc_driver);
+ 0, VIR_DOMAIN_VIRT_LXC,
+ lxcNotifyLoadDomain, lxc_driver);
lxcDriverUnlock(lxc_driver);
lxcAutostartConfigs(lxc_driver);
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index c13f346..82f4428 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -887,6 +887,7 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
openvzDriverLock(driver);
if ((vmdef = virDomainDefParseString(driver->caps, xml,
+ VIR_DOMAIN_VIRT_OPENVZ,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
@@ -966,6 +967,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
openvzDriverLock(driver);
if ((vmdef = virDomainDefParseString(driver->caps, xml,
+ VIR_DOMAIN_VIRT_OPENVZ,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index a9a9a21..b057b55 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -3611,6 +3611,7 @@ phypDomainCreateAndStart(virConnectPtr conn,
virCheckFlags(0, NULL);
if (!(def = virDomainDefParseString(phyp_driver->caps, xml,
+ VIR_DOMAIN_VIRT_PHYP,
VIR_DOMAIN_XML_SECURE)))
goto err;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 4b65d87..0af26ab 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -700,10 +700,32 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
ignore_value(virDomainObjUnref(obj));
}
+virDomainDefPtr qemuDomainDefParseXML(struct qemud_driver *driver,
+ const char *xml,
+ unsigned int flags)
+{
+ virDomainDefPtr def;
+
+ if (!(def = virDomainDefParseString(driver->caps, xml, -1, flags)))
+ return NULL;
+
+ if (def->virtType != VIR_DOMAIN_VIRT_QEMU &&
+ def->virtType != VIR_DOMAIN_VIRT_KQEMU &&
+ def->virtType != VIR_DOMAIN_VIRT_KVM &&
+ def->virtType != VIR_DOMAIN_VIRT_XEN) {
+ qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unexpected domain type %s"),
+ virDomainVirtTypeToString(def->virtType));
+ virDomainDefFree(def);
+ def = NULL;
+ }
+
+ return def;
+}
char *qemuDomainDefFormatXML(struct qemud_driver *driver,
virDomainDefPtr def,
- int flags)
+ unsigned int flags)
{
char *ret = NULL;
virCPUDefPtr cpu = NULL;
@@ -735,7 +757,7 @@ cleanup:
char *qemuDomainFormatXML(struct qemud_driver *driver,
virDomainObjPtr vm,
- int flags)
+ unsigned int flags)
{
virDomainDefPtr def;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f282df2..ca57ee8 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -125,13 +125,17 @@ void qemuDomainObjEnterRemoteWithDriver(struct qemud_driver *driver,
void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
virDomainObjPtr obj);
+virDomainDefPtr qemuDomainDefParseXML(struct qemud_driver *driver,
+ const char *xml,
+ unsigned int flags);
+
char *qemuDomainDefFormatXML(struct qemud_driver *driver,
virDomainDefPtr vm,
- int flags);
+ unsigned int flags);
char *qemuDomainFormatXML(struct qemud_driver *driver,
virDomainObjPtr vm,
- int flags);
+ unsigned int flags);
void qemuDomainObjTaint(struct qemud_driver *driver,
virDomainObjPtr obj,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 52b7dfd..55bad8a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -363,6 +363,19 @@ cleanup:
virDomainObjUnlock(vm);
}
+static void qemudNotifyLoadDomainCheckVirtType(virDomainObjPtr vm,
+ int newVM ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ if (vm->def->virtType != VIR_DOMAIN_VIRT_QEMU &&
+ vm->def->virtType != VIR_DOMAIN_VIRT_KQEMU &&
+ vm->def->virtType != VIR_DOMAIN_VIRT_KVM &&
+ vm->def->virtType != VIR_DOMAIN_VIRT_XEN) {
+ VIR_ERROR(_("unexpected domain type %s"),
+ virDomainVirtTypeToString(vm->def->virtType));
+ }
+}
+
/**
* qemudStartup:
*
@@ -612,7 +625,8 @@ qemudStartup(int privileged) {
&qemu_driver->domains,
qemu_driver->stateDir,
NULL,
- 1, NULL, NULL) < 0)
+ 1, -1, qemudNotifyLoadDomainCheckVirtType,
+ qemu_driver) < 0)
goto error;
conn = virConnectOpen(qemu_driver->privileged ?
@@ -626,7 +640,8 @@ qemudStartup(int privileged) {
&qemu_driver->domains,
qemu_driver->configDir,
qemu_driver->autostartDir,
- 0, NULL, NULL) < 0)
+ 0, -1, qemudNotifyLoadDomainCheckVirtType,
+ qemu_driver) < 0)
goto error;
@@ -663,6 +678,8 @@ static void qemudNotifyLoadDomain(virDomainObjPtr vm, int newVM, void *opaque)
{
struct qemud_driver *driver = opaque;
+ qemudNotifyLoadDomainCheckVirtType(vm, newVM, opaque);
+
if (newVM) {
virDomainEventPtr event =
virDomainEventNewFromObj(vm,
@@ -689,7 +706,7 @@ qemudReload(void) {
&qemu_driver->domains,
qemu_driver->configDir,
qemu_driver->autostartDir,
- 0, qemudNotifyLoadDomain, qemu_driver);
+ 0, -1, qemudNotifyLoadDomain, qemu_driver);
qemuDriverUnlock(qemu_driver);
qemuAutostartDomains(qemu_driver);
@@ -1251,8 +1268,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
VIR_DOMAIN_START_AUTODESTROY, NULL);
qemuDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
- VIR_DOMAIN_XML_INACTIVE)))
+ if (!(def = qemuDomainDefParseXML(driver, xml, VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (virSecurityManagerVerify(driver->securityManager, def) < 0)
@@ -3605,8 +3621,7 @@ qemuDomainSaveImageOpen(struct qemud_driver *driver,
}
/* Create a domain from this XML */
- if (!(def = virDomainDefParseString(driver->caps, xml,
- VIR_DOMAIN_XML_INACTIVE)))
+ if (!(def = qemuDomainDefParseXML(driver, xml, VIR_DOMAIN_XML_INACTIVE)))
goto error;
VIR_FREE(xml);
@@ -3923,7 +3938,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
goto cleanup;
}
- def = virDomainDefParseString(driver->caps, xmlData, 0);
+ def = qemuDomainDefParseXML(driver, xmlData, 0);
if (!def)
goto cleanup;
@@ -4220,8 +4235,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
int dupVM;
qemuDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
- VIR_DOMAIN_XML_INACTIVE)))
+ if (!(def = qemuDomainDefParseXML(driver, xml, VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (virSecurityManagerVerify(driver->securityManager, def) < 0)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d7b27a0..1770a10 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1018,8 +1018,8 @@ char *qemuMigrationBegin(struct qemud_driver *driver,
goto cleanup;
if (xmlin) {
- if (!(def = virDomainDefParseString(driver->caps, xmlin,
- VIR_DOMAIN_XML_INACTIVE)))
+ if (!(def = qemuDomainDefParseXML(driver, xmlin,
+ VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (!virDomainDefCheckABIStability(def, vm->def))
@@ -1077,8 +1077,8 @@ qemuMigrationPrepareTunnel(struct qemud_driver *driver,
return -1;
/* Parse the domain XML. */
- if (!(def = virDomainDefParseString(driver->caps, dom_xml,
- VIR_DOMAIN_XML_INACTIVE)))
+ if (!(def = qemuDomainDefParseXML(driver, dom_xml,
+ VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (!qemuMigrationIsAllowed(def))
@@ -1312,8 +1312,8 @@ qemuMigrationPrepareDirect(struct qemud_driver *driver,
VIR_DEBUG("Generated uri_out=%s", *uri_out);
/* Parse the domain XML. */
- if (!(def = virDomainDefParseString(driver->caps, dom_xml,
- VIR_DOMAIN_XML_INACTIVE)))
+ if (!(def = qemuDomainDefParseXML(driver, dom_xml,
+ VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (!qemuMigrationIsAllowed(def))
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index afc0d33..fb54dc5 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -725,7 +725,7 @@ get_definition(vahControl * ctl, const char *xmlStr)
goto exit;
}
- ctl->def = virDomainDefParseString(ctl->caps, xmlStr,
+ ctl->def = virDomainDefParseString(ctl->caps, xmlStr, -1,
VIR_DOMAIN_XML_INACTIVE);
if (ctl->def == NULL) {
vah_error(ctl, 0, _("could not parse XML"));
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 18f6a52..d228c99 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -544,10 +544,11 @@ static int testOpenDefault(virConnectPtr conn) {
privconn->nextDomID = 1;
- if (!(domdef = virDomainDefParseString(privconn->caps,
- defaultDomainXML,
+ if (!(domdef = virDomainDefParseString(privconn->caps, defaultDomainXML,
+ VIR_DOMAIN_VIRT_TEST,
VIR_DOMAIN_XML_INACTIVE)))
goto error;
+
if (testDomainGenerateIfnames(domdef) < 0)
goto error;
if (!(domobj = virDomainAssignDef(privconn->caps,
@@ -889,12 +890,14 @@ static int testOpenFromFile(virConnectPtr conn,
goto error;
}
def = virDomainDefParseFile(privconn->caps, absFile,
+ VIR_DOMAIN_VIRT_TEST,
VIR_DOMAIN_XML_INACTIVE);
VIR_FREE(absFile);
if (!def)
goto error;
} else {
if ((def = virDomainDefParseNode(privconn->caps, xml, domains[i],
+ VIR_DOMAIN_VIRT_TEST,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto error;
}
@@ -1288,6 +1291,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml,
testDriverLock(privconn);
if ((def = virDomainDefParseString(privconn->caps, xml,
+ VIR_DOMAIN_VIRT_TEST,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
@@ -1867,7 +1871,7 @@ static int testDomainRestore(virConnectPtr conn,
xml[len] = '\0';
testDriverLock(privconn);
- def = virDomainDefParseString(privconn->caps, xml,
+ def = virDomainDefParseString(privconn->caps, xml, VIR_DOMAIN_VIRT_TEST,
VIR_DOMAIN_XML_INACTIVE);
if (!def)
goto cleanup;
@@ -2416,6 +2420,7 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn,
testDriverLock(privconn);
if ((def = virDomainDefParseString(privconn->caps, xml,
+ VIR_DOMAIN_VIRT_TEST,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index f0f053b..43bd101 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -443,7 +443,7 @@ umlStartup(int privileged)
¨_driver->domains,
uml_driver->configDir,
uml_driver->autostartDir,
- 0, NULL, NULL) < 0)
+ 0, VIR_DOMAIN_VIRT_UML, NULL, NULL) < 0)
goto error;
umlAutostartConfigs(uml_driver);
@@ -480,7 +480,7 @@ umlReload(void) {
¨_driver->domains,
uml_driver->configDir,
uml_driver->autostartDir,
- 0, NULL, NULL);
+ 0, VIR_DOMAIN_VIRT_UML, NULL, NULL);
umlAutostartConfigs(uml_driver);
umlDriverUnlock(uml_driver);
@@ -1272,7 +1272,7 @@ static virDomainPtr umlDomainCreate(virConnectPtr conn, const char *xml,
virCheckFlags(0, NULL);
umlDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
+ if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_UML,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
@@ -1645,7 +1645,7 @@ static virDomainPtr umlDomainDefine(virConnectPtr conn, const char *xml) {
virDomainPtr dom = NULL;
umlDriverLock(driver);
- if (!(def = virDomainDefParseString(driver->caps, xml,
+ if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_UML,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 37fe248..2cf08af 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -4802,7 +4802,7 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
#endif
nsresult rc;
- if (!(def = virDomainDefParseString(data->caps, xml,
+ if (!(def = virDomainDefParseString(data->caps, xml, VIR_DOMAIN_VIRT_VBOX,
VIR_DOMAIN_XML_INACTIVE))) {
goto cleanup;
}
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 52582d6..faf0086 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -255,6 +255,7 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml)
vmwareDriverLock(driver);
if ((vmdef = virDomainDefParseString(driver->caps, xml,
+ VIR_DOMAIN_VIRT_VMWARE,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
@@ -508,6 +509,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
vmwareDriverLock(driver);
if ((vmdef = virDomainDefParseString(driver->caps, xml,
+ VIR_DOMAIN_VIRT_VMWARE,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 88febba..4886070 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1325,9 +1325,8 @@ xenUnifiedDomainXMLToNative(virConnectPtr conn,
goto cleanup;
}
- if (!(def = virDomainDefParseString(priv->caps,
- xmlData,
- 0)))
+ if (!(def = virDomainDefParseString(priv->caps, xmlData,
+ VIR_DOMAIN_VIRT_XEN, 0)))
goto cleanup;
if (STREQ(format, XEN_CONFIG_FORMAT_XM)) {
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index d0eb32a0..71b64be 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2596,8 +2596,8 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc,
priv = (xenUnifiedPrivatePtr) conn->privateData;
- if (!(def = virDomainDefParseString(priv->caps,
- xmlDesc,
+ if (!(def = virDomainDefParseString(priv->caps, xmlDesc,
+ VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE)))
return (NULL);
@@ -3346,6 +3346,7 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
return(NULL);
if (!(def = virDomainDefParseString(priv->caps, xmlDesc,
+ VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE))) {
virXendError(VIR_ERR_XML_ERROR,
"%s", _("failed to parse domain description"));
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 530b0d4..7d5af65 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -1105,7 +1105,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml)
return (NULL);
}
- if (!(def = virDomainDefParseString(priv->caps, xml,
+ if (!(def = virDomainDefParseString(priv->caps, xml, VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE))) {
xenUnifiedUnlock(priv);
return (NULL);
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 0a618ab..fed999b 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -516,7 +516,8 @@ xenapiDomainCreateXML (virConnectPtr conn,
virCheckFlags(0, NULL);
- virDomainDefPtr defPtr = virDomainDefParseString(caps, xmlDesc, flags);
+ virDomainDefPtr defPtr = virDomainDefParseString(caps, xmlDesc,
+ VIR_DOMAIN_VIRT_XEN, flags);
createVMRecordFromXml(conn, defPtr, &record, &vm);
virDomainDefFree(defPtr);
if (record) {
@@ -1635,9 +1636,11 @@ xenapiDomainDefineXML (virConnectPtr conn, const char *xml)
virCapsPtr caps = ((struct _xenapiPrivate *)(conn->privateData))->caps;
if (!caps)
return NULL;
- virDomainDefPtr defPtr = virDomainDefParseString(caps, xml, 0);
+ virDomainDefPtr defPtr = virDomainDefParseString(caps, xml,
+ VIR_DOMAIN_VIRT_XEN, 0);
if (!defPtr)
return NULL;
+
if (createVMRecordFromXml(conn, defPtr, &record, &vm) != 0) {
if (!session->ok)
xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL);
diff --git a/tests/define-dev-segfault b/tests/define-dev-segfault
index 19d4e67..3feff46 100755
--- a/tests/define-dev-segfault
+++ b/tests/define-dev-segfault
@@ -17,7 +17,7 @@ fail=0
# Domain definition from Cole Robinson.
cat <<\EOF > D.xml || fail=1
-<domain type='kvm'>
+<domain type='test'>
<name>D</name>
<uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid>
<memory>262144</memory>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index ec1f4b5..1607387 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -50,10 +50,19 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (len && expectargv[len - 1] == '\n')
expectargv[len - 1] = '\0';
- if (!(vmdef = virDomainDefParseFile(driver.caps, xml,
+ if (!(vmdef = virDomainDefParseFile(driver.caps, xml, -1,
VIR_DOMAIN_XML_INACTIVE)))
goto fail;
+ if (vmdef->virtType != VIR_DOMAIN_VIRT_QEMU &&
+ vmdef->virtType != VIR_DOMAIN_VIRT_KQEMU &&
+ vmdef->virtType != VIR_DOMAIN_VIRT_KVM &&
+ vmdef->virtType != VIR_DOMAIN_VIRT_XEN) {
+ fprintf(stderr, "unexpected domain type %s",
+ virDomainVirtTypeToString(vmdef->virtType));
+ goto fail;
+ }
+
/*
* For test purposes, we may want to fake emulator's output by providing
* our own script instead of a real emulator. For this to work we need to
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 2a3e75a..499796b 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -31,10 +31,19 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
- if (!(def = virDomainDefParseString(driver.caps, inXmlData,
- VIR_DOMAIN_XML_INACTIVE)))
+ if (!(def = virDomainDefParseString(driver.caps, inXmlData, -1,
+ VIR_DOMAIN_XML_INACTIVE)))
goto fail;
+ if (def->virtType != VIR_DOMAIN_VIRT_QEMU &&
+ def->virtType != VIR_DOMAIN_VIRT_KQEMU &&
+ def->virtType != VIR_DOMAIN_VIRT_KVM &&
+ def->virtType != VIR_DOMAIN_VIRT_XEN) {
+ fprintf(stderr, "unexpected domain type %s",
+ virDomainVirtTypeToString(def->virtType));
+ goto fail;
+ }
+
if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
goto fail;
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index a15a7ff..4bbce24 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -68,7 +68,7 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
priv.caps = caps;
conn->privateData = &priv;
- if (!(def = virDomainDefParseString(caps, xmlData,
+ if (!(def = virDomainDefParseString(caps, xmlData, VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE)))
goto fail;
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index d8cdcbb..203e951 100644
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -31,7 +31,7 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
if (virtTestLoadFile(sexpr, &sexprData) < 0)
goto fail;
- if (!(def = virDomainDefParseString(caps, xmlData,
+ if (!(def = virDomainDefParseString(caps, xmlData, VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE)))
goto fail;
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index 66ed53d..5d0b899 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -80,7 +80,8 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
goto failure;
}
- def = virDomainDefParseString(caps, xmlData, VIR_DOMAIN_XML_INACTIVE);
+ def = virDomainDefParseString(caps, xmlData, VIR_DOMAIN_VIRT_VMWARE,
+ VIR_DOMAIN_XML_INACTIVE);
if (def == NULL) {
goto failure;
--
1.7.4.1
13 years, 5 months
[libvirt] [Fwd: bug virt-viewer was Re: [virt-tools-list] virt-viewer 0.2.0, as listed on virt-manager download page]
by Jason Helfman
Any ideas on this issue with virt-viewer?
Thanks!
-jgh
---------------------------- Original Message ----------------------------
Subject: bug virt-viewer was Re: [virt-tools-list] virt-viewer 0.2.0, as
listed on virt-manager download page
From: "Jason Helfman" <jhelfman(a)e-e.com>
Date: Mon, July 11, 2011 12:23 pm
To: "Jason Helfman" <jhelfman(a)e-e.com>
Cc: virt-tools-list(a)redhat.com
--------------------------------------------------------------------------
On Mon, Jul 11, 2011 at 11:31:06AM -0700, Jason Helfman thus spake:
>On Mon, Jul 11, 2011 at 02:43:52PM +0100, Richard W.M. Jones thus spake:
>>On Sat, Jul 09, 2011 at 12:02:00PM -0700, Jason Helfman wrote:
>>> Hi,
>>>
>>> Is this the most recent "official" release, as listed on the webpage for
>>> download on virt-manager.org?
>>>
>>> According to the sources directory there is a newer release:
>>> virt-viewer-0.3.1
>>
>>The web page is wrong. The latest version does appear to be 0.3.1.
>>
>>Rich.
>>
>
>Thanks! And for some reason, I am unable to configure the build of the tool
>to install locale data to /usr/local/share/locale.
>It keeps wanting to go to /usr/local/lib/locale.
>
>Any ideas?
>
>-jgh
>
>
I've gotten around this with a post-build patch of po/Makefile, however even
if I --disable-nls, it still makes and installs the locales.
-jgh
--
Jason Helfman
System Administrator
experts-exchange.com
http://www.experts-exchange.com/M_4830110.html
E4AD 7CF1 1396 27F6 79DD 4342 5E92 AD66 8C8C FBA5
13 years, 5 months
[libvirt] make failure in HEAD
by Dave Allan
I'm seeing:
/usr/bin/ld: libvirt_lxc-domain_conf.o: undefined reference
to symbol 'log2@(a)GLIBC_2.2.5'
when building the git HEAD just now.
It appears to be the result of:
aa14709a src/conf/domain_conf.c (Matthias Bolte 2011-07-11
19:29:09 +0200 5868)
virDomainVirtTypeToString(log2(expectedVirtTypes)));
I don't have time to look into it, but thought I should mention it.
Dave
13 years, 5 months
[libvirt] [PATCH] Remove code no longer used after commit df0b57a9
by Jim Fehlig
---
daemon/libvirtd.h | 30 ------------------------------
1 files changed, 0 insertions(+), 30 deletions(-)
diff --git a/daemon/libvirtd.h b/daemon/libvirtd.h
index 8e1843c..6c9b9c3 100644
--- a/daemon/libvirtd.h
+++ b/daemon/libvirtd.h
@@ -27,10 +27,6 @@
# include <config.h>
-# if HAVE_POLKIT0
-# include <dbus/dbus.h>
-# endif
-
# include <rpc/types.h>
# include <rpc/xdr.h>
# include "remote_protocol.h"
@@ -91,30 +87,4 @@ extern virNetSASLContextPtr saslCtxt;
extern virNetServerProgramPtr remoteProgram;
extern virNetServerProgramPtr qemuProgram;
-/* Main server state */
-struct qemud_server {
- int privileged;
-
- int sigread;
- int sigwrite;
- char *logDir;
- pthread_t eventThread;
- unsigned int hasEventThread :1;
- unsigned int quitEventThread :1;
-# ifdef HAVE_AVAHI
- struct libvirtd_mdns *mdns;
-# endif
-# if HAVE_SASL
- char **saslUsernameWhitelist;
-# endif
-# if HAVE_POLKIT0
- DBusConnection *sysbus;
-# endif
-};
-
-
-# if HAVE_POLKIT
-int qemudGetSocketIdentity(int fd, uid_t *uid, pid_t *pid);
-# endif
-
#endif
--
1.7.5.4
13 years, 5 months
[libvirt] [RFC] exporting KVM host power saving capabilities through libvirt
by Vaidyanathan Srinivasan
Hi,
Linux host systems running KVM support various power management
capabilities. Most of the features like DVFS and sleep states can be
independently exploited by the host system itself based on system
utilisation subject to policies set by the administrator.
However, system-wide low power states like S3 and S4 would require
external communication and interaction with the systems management
stack in order to be used. The first steps in this direction would be
to allow systems management stack to discover host power saving
capabilities like S3 and S4 along with various other host CPU
capabilities.
Libvirt seems to be the main glue layer between the platform and the
systems-management stack. Adding host power savings capabilities as
part of libvirt host discovery mechanism seems to be one possible
approach without addition of any new APIs or agents.
libvirt has virConnectGetCapabilities() that would export an XML file
describing the capabilities of the host platform and guest features.
KVM hypervisor's capability to support S3 can be exported as a host
feature in the XML as follows:
<host>
<uuid>94a3492f-2635-2491-8c87-8de976fad119</uuid>
<cpu>
<arch>x86_64</arch>
<features> <<<=== New host feature fields
<S3/>
<S4/>
</features>
<model>Westmere</model>
<vendor>Intel</vendor>
<topology sockets='1' cores='2' threads='2'/>
<feature name='rdtscp'/>
<feature name='xtpr'/>
<feature name='tm2'/>
<feature name='est'/>
<feature name='vmx'/> <<<= These are host CPU features
System management software that works through libvirt, already queries
this capabilities XML file and hence no new API is needed.
As simple discovery mechanism can be added to libvirt as follows:
Index: libvirt-0.9.0/src/qemu/qemu_capabilities.c
===================================================================
--- libvirt-0.9.0.orig/src/qemu/qemu_capabilities.c
+++ libvirt-0.9.0/src/qemu/qemu_capabilities.c
@@ -738,6 +738,14 @@ virCapsPtr qemuCapsInit(virCapsPtr old_c
virCapabilitiesAddHostMigrateTransport(caps,
"tcp");
+ /* Add host energy management host capabilities */
+
+ /* if "pm-is-supported --suspend" == 0 */
+ virCapabilitiesAddHostFeature(caps, "S3");
+
+ /* if "pm-is-supported --hibernate" == 0 */
+ virCapabilitiesAddHostFeature(caps, "S4");
+
/* First the pure HVM guests */
for (i = 0 ; i < ARRAY_CARDINALITY(arch_info_hvm) ; i++)
if (qemuCapsInitGuest(caps, old_caps,
Please let me know your comments, I will code a working prototype
shortly and post for review/discussion.
Thanks,
Vaidy
13 years, 5 months
[libvirt] [PATCH] remote: Fix memory leak
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
Detected in valgrind run:
==9184== 1 bytes in 1 blocks are definitely lost in loss record 1 of 19
==9184== at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==9184== by 0x3073715F78: xdr_array (xdr_array.c:97)
==9184== by 0x4CF97C9: xdr_remote_domain_get_security_label_ret (remote_protocol.c:1696)
==9184== by 0x4D08741: virNetMessageDecodePayload (virnetmessage.c:286)
==9184== by 0x4D00F78: virNetClientProgramCall (virnetclientprogram.c:318)
==9184== by 0x4CE3887: call (remote_driver.c:3933)
==9184== by 0x4CF71C6: remoteDomainGetSecurityLabel (remote_driver.c:1580)
==9184== by 0x4CCA480: virDomainGetSecurityLabel (libvirt.c:7340)
==9184== by 0x41993A: cmdDominfo (virsh.c:2414)
==9184== by 0x411E92: vshCommandRun (virsh.c:12730)
==9184== by 0x4211ED: main (virsh.c:14076)
==9184==
==9184== 2 bytes in 1 blocks are definitely lost in loss record 2 of 19
==9184== at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==9184== by 0x3073715F78: xdr_array (xdr_array.c:97)
==9184== by 0x4CF974F: xdr_remote_node_get_security_model_ret (remote_protocol.c:1713)
==9184== by 0x4D08741: virNetMessageDecodePayload (virnetmessage.c:286)
==9184== by 0x4D00F78: virNetClientProgramCall (virnetclientprogram.c:318)
==9184== by 0x4CE3887: call (remote_driver.c:3933)
==9184== by 0x4CF6F96: remoteNodeGetSecurityModel (remote_driver.c:1648)
==9184== by 0x4CBF799: virNodeGetSecurityModel (libvirt.c:7382)
==9184== by 0x4197D7: cmdDominfo (virsh.c:2394)
==9184== by 0x411E92: vshCommandRun (virsh.c:12730)
==9184== by 0x4211ED: main (virsh.c:14076)
==9184==
==9184== 8 bytes in 1 blocks are definitely lost in loss record 3 of 19
==9184== at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==9184== by 0x3073715F78: xdr_array (xdr_array.c:97)
==9184== by 0x4CF9729: xdr_remote_node_get_security_model_ret (remote_protocol.c:1710)
==9184== by 0x4D08741: virNetMessageDecodePayload (virnetmessage.c:286)
==9184== by 0x4D00F78: virNetClientProgramCall (virnetclientprogram.c:318)
==9184== by 0x4CE3887: call (remote_driver.c:3933)
==9184== by 0x4CF6F96: remoteNodeGetSecurityModel (remote_driver.c:1648)
==9184== by 0x4CBF799: virNodeGetSecurityModel (libvirt.c:7382)
==9184== by 0x4197D7: cmdDominfo (virsh.c:2394)
==9184== by 0x411E92: vshCommandRun (virsh.c:12730)
==9184== by 0x4211ED: main (virsh.c:14076)
==9184==
==9184== LEAK SUMMARY:
==9184== definitely lost: 11 bytes in 3 blocks
* src/remote/remote_driver.c: Avoid leak on remoteDomainGetSecurityLabel
and remoteNodeGetSecurityModel.
---
src/remote/remote_driver.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 8dff6a8..5c0457e 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1587,7 +1587,7 @@ remoteDomainGetSecurityLabel (virDomainPtr domain, virSecurityLabelPtr seclabel)
if (strlen (ret.label.label_val) >= sizeof seclabel->label) {
remoteError(VIR_ERR_RPC, _("security label exceeds maximum: %zd"),
sizeof seclabel->label - 1);
- goto done;
+ goto cleanup;
}
strcpy (seclabel->label, ret.label.label_val);
seclabel->enforcing = ret.enforcing;
@@ -1595,6 +1595,9 @@ remoteDomainGetSecurityLabel (virDomainPtr domain, virSecurityLabelPtr seclabel)
rv = 0;
+cleanup:
+ xdr_free((xdrproc_t) xdr_remote_domain_get_security_label_ret, (char *)&ret);
+
done:
remoteDriverUnlock(priv);
return rv;
@@ -1655,7 +1658,7 @@ remoteNodeGetSecurityModel (virConnectPtr conn, virSecurityModelPtr secmodel)
if (strlen (ret.model.model_val) >= sizeof secmodel->model) {
remoteError(VIR_ERR_RPC, _("security model exceeds maximum: %zd"),
sizeof secmodel->model - 1);
- goto done;
+ goto cleanup;
}
strcpy (secmodel->model, ret.model.model_val);
}
@@ -1664,13 +1667,16 @@ remoteNodeGetSecurityModel (virConnectPtr conn, virSecurityModelPtr secmodel)
if (strlen (ret.doi.doi_val) >= sizeof secmodel->doi) {
remoteError(VIR_ERR_RPC, _("security doi exceeds maximum: %zd"),
sizeof secmodel->doi - 1);
- goto done;
+ goto cleanup;
}
strcpy (secmodel->doi, ret.doi.doi_val);
}
rv = 0;
+cleanup:
+ xdr_free((xdrproc_t) xdr_remote_node_get_security_model_ret, (char *)&ret);
+
done:
remoteDriverUnlock(priv);
return rv;
--
1.7.1
13 years, 5 months
[libvirt] [PATCH] Skip some xen tests if xend is not running
by Jim Fehlig
Currently, the xen statstest and reconnect tests are only compiled
if xend is running. Compile them unconditionally if xen headers
are present, but skip the tests at runtime if xend is not running.
This is in response to Eric's suggestion here
https://www.redhat.com/archives/libvir-list/2011-July/msg00367.html
---
configure.ac | 24 ------------------------
tests/Makefile.am | 12 ++++--------
tests/reconnect.c | 11 +++++++++++
tests/statstest.c | 12 ++++++++++++
4 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/configure.ac b/configure.ac
index aa589d6..ae747fb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1982,30 +1982,6 @@ AM_CONDITIONAL([WITH_PYTHON], [test "$with_python" = "yes"])
AC_SUBST([PYTHON_VERSION])
AC_SUBST([PYTHON_INCLUDES])
-
-
-AC_MSG_CHECKING([whether this host is running a Xen kernel])
-RUNNING_XEN=
-if test -d /proc/sys/xen
-then
- RUNNING_XEN=yes
-else
- RUNNING_XEN=no
-fi
-AC_MSG_RESULT($RUNNING_XEN)
-
-AC_MSG_CHECKING([If XenD UNIX socket /var/run/xend/xmlrpc.sock is accessible])
-RUNNING_XEND=
-if test -S /var/run/xend/xmlrpc.sock
-then
- RUNNING_XEND=yes
-else
- RUNNING_XEND=no
-fi
-AC_MSG_RESULT($RUNNING_XEND)
-
-AM_CONDITIONAL([ENABLE_XEN_TESTS], [test "$RUNNING_XEN" != "no" && test "$RUNNING_XEND" != "no"])
-
AC_ARG_ENABLE([test-coverage],
AC_HELP_STRING([--enable-test-coverage], [turn on code coverage instrumentation @<:@default=no@:>@]),
[case "${enableval}" in
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 48f9faa..528b88e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -93,10 +93,7 @@ ssh_LDADD = $(COVERAGE_LDFLAGS)
if WITH_XEN
check_PROGRAMS += xml2sexprtest sexpr2xmltest \
- xmconfigtest xencapstest
-if ENABLE_XEN_TESTS
-check_PROGRAMS += statstest reconnect
-endif
+ xmconfigtest xencapstest statstest reconnect
endif
if WITH_QEMU
check_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest qemuhelptest
@@ -216,10 +213,9 @@ if WITH_XEN
TESTS += xml2sexprtest \
sexpr2xmltest \
xmconfigtest \
- xencapstest
-if ENABLE_XEN_TESTS
-TESTS += reconnect statstest
-endif
+ xencapstest \
+ reconnect \
+ statstest
endif
if WITH_QEMU
diff --git a/tests/reconnect.c b/tests/reconnect.c
index 63877fc..4bc092f 100644
--- a/tests/reconnect.c
+++ b/tests/reconnect.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include "internal.h"
+#include "command.h"
static void errorHandler(void *userData ATTRIBUTE_UNUSED,
virErrorPtr error ATTRIBUTE_UNUSED) {
@@ -14,6 +15,16 @@ int main(void) {
int ro = 0;
virConnectPtr conn;
virDomainPtr dom;
+ int status;
+ virCommandPtr cmd;
+
+ /* skip test if xend is not running */
+ cmd = virCommandNewArgList("/usr/sbin/xend", "status", NULL);
+ if (virCommandRun(cmd, &status) == 0 && status != 0) {
+ virCommandFree(cmd);
+ return 77;
+ }
+ virCommandFree(cmd);
virSetErrorFunc(NULL, errorHandler);
diff --git a/tests/statstest.c b/tests/statstest.c
index c989992..7074914 100644
--- a/tests/statstest.c
+++ b/tests/statstest.c
@@ -8,6 +8,7 @@
#include "internal.h"
#include "xen/block_stats.h"
#include "testutils.h"
+#include "command.h"
static void testQuietError(void *userData ATTRIBUTE_UNUSED,
virErrorPtr error ATTRIBUTE_UNUSED)
@@ -44,6 +45,17 @@ static int
mymain(void)
{
int ret = 0;
+ int status;
+ virCommandPtr cmd;
+
+ /* skip test if xend is not running */
+ cmd = virCommandNewArgList("/usr/sbin/xend", "status", NULL);
+ if (virCommandRun(cmd, &status) == 0 && status != 0) {
+ virCommandFree(cmd);
+ return 77;
+ }
+ virCommandFree(cmd);
+
/* Some of our tests delibrately test failure cases, so
* register a handler to stop error messages cluttering
* up display
--
1.7.5.4
13 years, 5 months
[libvirt] [PATCH V2] Do not drop kernel cmdline for xen pv domains
by Jim Fehlig
Kernel cmdline args can be passed to xen pv domains even when a
bootloader is specified. The current config-to-sxpr mapping
ignores cmdline when bootloader is present.
Since the xend sub-driver is used with many xen toolstack versions,
this patch takes conservative approach of adding an else block to
existing !def->os.bootloader, and only appends sxpr if def->os.cmdline
is non-NULL.
V2: Fix existing testcase broken by this patch and add new testcases
---
src/xenxs/xen_sxpr.c | 6 ++++
.../sexpr2xml-pv-bootloader-cmdline.sexpr | 5 +++
.../sexpr2xml-pv-bootloader-cmdline.xml | 27 ++++++++++++++++++++
tests/sexpr2xmltest.c | 1 +
.../xml2sexpr-disk-block-shareable.sexpr | 1 +
.../xml2sexpr-pv-bootloader-cmdline.sexpr | 5 +++
.../xml2sexpr-pv-bootloader-cmdline.xml | 22 ++++++++++++++++
tests/xml2sexprtest.c | 1 +
8 files changed, 68 insertions(+), 0 deletions(-)
create mode 100644 tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.sexpr
create mode 100644 tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.xml
create mode 100644 tests/xml2sexprdata/xml2sexpr-pv-bootloader-cmdline.sexpr
create mode 100644 tests/xml2sexprdata/xml2sexpr-pv-bootloader-cmdline.xml
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 13ca015..bd770bc 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -2261,6 +2261,12 @@ xenFormatSxpr(virConnectPtr conn,
}
virBufferAddLit(&buf, "))");
+ } else {
+ /* PV domains accept kernel cmdline args */
+ if (def->os.cmdline) {
+ virBufferEscapeSexpr(&buf, "(image (linux (args '%s')))",
+ def->os.cmdline);
+ }
}
for (i = 0 ; i < def->ndisks ; i++)
diff --git a/tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.sexpr b/tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.sexpr
new file mode 100644
index 0000000..dde37fc
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.sexpr
@@ -0,0 +1,5 @@
+(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)\
+(uuid '596a5d2171f48fb2e068e2386a5c413e')(bootloader '/usr/bin/pygrub')\
+(bootloader_args '-q')(image (linux (args ' xenfb.video=8,1280,1024 ')))\
+(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')\
+(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
diff --git a/tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.xml b/tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.xml
new file mode 100644
index 0000000..7bc99d8
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.xml
@@ -0,0 +1,27 @@
+<domain type='xen' id='6'>
+ <name>pvtest</name>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
+ <memory>430080</memory>
+ <currentMemory>430080</currentMemory>
+ <vcpu>2</vcpu>
+ <bootloader>/usr/bin/pygrub</bootloader>
+ <bootloader_args>-q</bootloader_args>
+ <os>
+ <type>linux</type>
+ <cmdline> xenfb.video=8,1280,1024 </cmdline>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='file'/>
+ <source file='/root/some.img'/>
+ <target dev='xvda' bus='xen'/>
+ </disk>
+ <console type='pty'>
+ <target type='xen' port='0'/>
+ </console>
+ </devices>
+</domain>
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
index f393935..26a987d 100644
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -134,6 +134,7 @@ mymain(void)
DO_TEST("pv-vfb-type-crash", "pv-vfb-type-crash", 3);
DO_TEST("fv-autoport", "fv-autoport", 3);
DO_TEST("pv-bootloader", "pv-bootloader", 1);
+ DO_TEST("pv-bootloader-cmdline", "pv-bootloader-cmdline", 1);
DO_TEST("pv-vcpus", "pv-vcpus", 1);
DO_TEST("disk-file", "disk-file", 2);
diff --git a/tests/xml2sexprdata/xml2sexpr-disk-block-shareable.sexpr b/tests/xml2sexprdata/xml2sexpr-disk-block-shareable.sexpr
index 8c0b1cd..b8387e5 100644
--- a/tests/xml2sexprdata/xml2sexpr-disk-block-shareable.sexpr
+++ b/tests/xml2sexprdata/xml2sexpr-disk-block-shareable.sexpr
@@ -1,6 +1,7 @@
(vm (name 'pvtest')(memory 384)(maxmem 512)(vcpus 1)\
(uuid '49a0c6ff-c066-5392-6498-3632d093c2e7')(bootloader '/usr/bin/pygrub')\
(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')\
+(image (linux (args 'ro root=/dev/VolGroup00/LogVol00')))\
(device (tap (dev 'xvda')(uname 'tap:aio:/var/lib/xen/images/rhel5pv.img')\
(mode 'w!')))(device (vif (mac '00:16:3e:23:9e:eb')(bridge 'xenbr0')\
(script 'vif-bridge'))))\
diff --git a/tests/xml2sexprdata/xml2sexpr-pv-bootloader-cmdline.sexpr b/tests/xml2sexprdata/xml2sexpr-pv-bootloader-cmdline.sexpr
new file mode 100644
index 0000000..c3ed727
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-pv-bootloader-cmdline.sexpr
@@ -0,0 +1,5 @@
+(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)\
+(uuid '596a5d21-71f4-8fb2-e068-e2386a5c413e')(bootloader '/usr/bin/pygrub')\
+(bootloader_args '-q')(on_poweroff 'destroy')(on_reboot 'destroy')\
+(on_crash 'destroy')(image (linux (args ' xenfb.video=8,1280,1024 ')))\
+(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))\
diff --git a/tests/xml2sexprdata/xml2sexpr-pv-bootloader-cmdline.xml b/tests/xml2sexprdata/xml2sexpr-pv-bootloader-cmdline.xml
new file mode 100644
index 0000000..983b7ce
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-pv-bootloader-cmdline.xml
@@ -0,0 +1,22 @@
+<domain type='xen' id='15'>
+ <name>pvtest</name>
+ <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <bootloader>/usr/bin/pygrub</bootloader>
+ <bootloader_args>-q</bootloader_args>
+ <os>
+ <type>linux</type>
+ <cmdline> xenfb.video=8,1280,1024 </cmdline>
+ </os>
+ <memory>430080</memory>
+ <vcpu>2</vcpu>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <source file='/root/some.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <console tty='/dev/pts/4'/>
+ </devices>
+</domain>
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index d8cdcbb..e068e69 100644
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -116,6 +116,7 @@ mymain(void)
DO_TEST("pv-vfb-new", "pv-vfb-new", "pvtest", 3);
DO_TEST("pv-vfb-new-auto", "pv-vfb-new-auto", "pvtest", 3);
DO_TEST("pv-bootloader", "pv-bootloader", "pvtest", 1);
+ DO_TEST("pv-bootloader-cmdline", "pv-bootloader-cmdline", "pvtest", 1);
DO_TEST("pv-vcpus", "pv-vcpus", "pvtest", 1);
DO_TEST("disk-file", "disk-file", "pvtest", 2);
--
1.7.5.4
13 years, 5 months