提交 f1a89a8b 编写于 作者: C Cole Robinson

domain: conf: Don't validate VM ostype/arch at daemon startup

When parsing XML, we validate the passed ostype + arch combo against
the detected hypervisor capabilities. This has led to the following
problem:

- Define x86 qemu guest
- qemu is inadvertently removed from the host
- libvirtd is restarted. fails to parse VM config since arch is removed
- 'virsh list --all' is now empty, user is wondering where their VMs went

Add a new internal flag VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS. Use
it when loading VM and snapshot configs from disk.

https://bugzilla.redhat.com/show_bug.cgi?id=1043572
上级 3700c065
......@@ -14655,17 +14655,8 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error;
}
if (!virCapabilitiesSupportsGuestOSType(caps, def->os.type)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("no support found for os <type> '%s'"),
def->os.type);
goto error;
}
tmp = virXPathString("string(./os/type[1]/@arch)", ctxt);
if (tmp) {
def->os.arch = virArchFromString(tmp);
if (!def->os.arch) {
if (tmp && !(def->os.arch = virArchFromString(tmp))) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown architecture %s"),
tmp);
......@@ -14673,6 +14664,17 @@ virDomainDefParseXML(xmlDocPtr xml,
}
VIR_FREE(tmp);
def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt);
if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)) {
if (!virCapabilitiesSupportsGuestOSType(caps, def->os.type)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("no support found for os <type> '%s'"),
def->os.type);
goto error;
}
if (def->os.arch) {
if (!virCapabilitiesSupportsGuestArch(caps, def->os.arch)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("No guest options available for arch '%s'"),
......@@ -14701,7 +14703,6 @@ virDomainDefParseXML(xmlDocPtr xml,
}
}
def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt);
if (!def->os.machine) {
const char *defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
def->os.type,
......@@ -14710,6 +14711,8 @@ virDomainDefParseXML(xmlDocPtr xml,
if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
goto error;
}
}
/*
* Booting options for different OS types....
......@@ -21591,7 +21594,8 @@ virDomainObjListLoadConfig(virDomainObjListPtr doms,
goto error;
if (!(def = virDomainDefParseFile(configFile, caps, xmlopt,
expectedVirtTypes,
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)))
goto error;
if ((autostartLink = virDomainConfigFile(autostartDir, name)) == NULL)
......@@ -21641,7 +21645,8 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms,
VIR_DOMAIN_DEF_PARSE_STATUS |
VIR_DOMAIN_DEF_PARSE_ACTUAL_NET |
VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES |
VIR_DOMAIN_DEF_PARSE_CLOCK_ADJUST)))
VIR_DOMAIN_DEF_PARSE_CLOCK_ADJUST |
VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)))
goto error;
virUUIDFormat(obj->def->uuid, uuidstr);
......
......@@ -2530,6 +2530,10 @@ typedef enum {
/* parse only source half of <disk> */
VIR_DOMAIN_DEF_PARSE_DISK_SOURCE = 1 << 7,
VIR_DOMAIN_DEF_PARSE_VALIDATE = 1 << 8,
/* don't validate os.type and arch against capabilities. Prevents
* VMs from disappearing when qemu is removed and libvirtd is restarted
*/
VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS = 1 << 9,
} virDomainDefParseFlags;
typedef enum {
......
......@@ -270,6 +270,9 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
* clients will have to decide between best effort
* initialization or outright failure. */
if ((tmp = virXPathString("string(./domain/@type)", ctxt))) {
int domainflags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL)
domainflags |= VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS;
xmlNodePtr domainNode = virXPathNode("./domain", ctxt);
VIR_FREE(tmp);
......@@ -280,8 +283,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
}
def->dom = virDomainDefParseNode(ctxt->node->doc, domainNode,
caps, xmlopt,
expectedVirtTypes,
VIR_DOMAIN_DEF_PARSE_INACTIVE);
expectedVirtTypes, domainflags);
if (!def->dom)
goto cleanup;
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册