diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 71b2f76a52..a622131837 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2081,7 +2081,7 @@ ... <devices> <hostdev mode='subsystem' type='usb'> - <source> + <source startupPolicy='optional'> <vendor id='0x1234'/> <product id='0xbeef'/> </source> @@ -2125,9 +2125,29 @@
The source element describes the device as seen from the host. The USB device can either be addressed by vendor / product id using the vendor and product elements or by the device's - address on the hosts using the address element. - PCI devices on the other hand can only be described by their - address
+ address on the hosts using the address element. PCI devices + on the other hand can only be described by their address. + + Since 0.10.3, the source element + of USB devices may contain startupPolicy attribute which can + be used to define policy what to do if the specified host USB device is + not found. The attribute accepts the following values: + + + + + + + + + + + + + +
mandatory fail if missing for any reason (the default)
requisite fail if missing on boot up, + drop if missing on migrate/restore/revert
optional drop if missing at any start attempt
+
vendor, product
The vendor and product elements each have an id attribute that specifies the USB vendor and product id. diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 2df2efa701..b142716adc 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2785,6 +2785,9 @@ + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 120d82f543..3b07cdf64c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2701,6 +2701,20 @@ virDomainHostdevSubsysUsbDefParseXML(const xmlNodePtr node, int ret = -1; int got_product, got_vendor; xmlNodePtr cur; + char *startupPolicy = NULL; + + if ((startupPolicy = virXMLPropString(node, "startupPolicy"))) { + def->startupPolicy = + virDomainStartupPolicyTypeFromString(startupPolicy); + if (def->startupPolicy <= 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Unknown startup policy '%s'"), + startupPolicy); + VIR_FREE(startupPolicy); + goto out; + } + VIR_FREE(startupPolicy); + } /* Product can validly be 0, so we need some extra help to determine * if it is uninitialized*/ @@ -2964,6 +2978,15 @@ virDomainHostdevPartsParse(xmlNodePtr node, _("Missing element in hostdev device")); goto error; } + + if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && + virXPathBoolean("boolean(./source/@startupPolicy)", ctxt)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Setting startupPolicy is only allowed for USB" + " devices")); + goto error; + } + switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (virDomainHostdevSubsysPciDefParseXML(sourcenode, def, flags) < 0) @@ -12063,7 +12086,14 @@ virDomainHostdevSourceFormat(virBufferPtr buf, unsigned int flags, bool includeTypeInAddr) { - virBufferAddLit(buf, "\n"); + virBufferAddLit(buf, "startupPolicy) { + const char *policy; + policy = virDomainStartupPolicyTypeToString(def->startupPolicy); + virBufferAsprintf(buf, " startupPolicy='%s'", policy); + } + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); switch (def->source.subsys.type) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c41e0cfc28..381860c0a9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -384,6 +384,7 @@ struct _virDomainHostdevSubsys { struct _virDomainHostdevDef { virDomainDeviceDef parent; /* higher level Def containing this */ int mode; /* enum virDomainHostdevMode */ + int startupPolicy; /* enum virDomainStartupPolicy */ unsigned int managed : 1; union { virDomainHostdevSubsys subsys;