The ephemeral flag helps support migration with PCI-passthrough. An ephemeral hostdev is automatically unplugged before migration and replugged (if one is available on the destination) after migration. --- docs/schemas/domaincommon.rng | 16 +++++++++++++ src/conf/domain_conf.c | 23 ++++++++++++++++++- src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 1 + .../qemuxml2argv-hostdev-pci-address.xml | 2 +- .../qemuxml2argv-hostdev-usb-address.xml | 2 +- .../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml | 4 +- 8 files changed, 44 insertions(+), 7 deletions(-) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 0e85739..29fc382 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1694,6 +1694,14 @@ </choice> </attribute> </optional> + <optional> + <attribute name="ephemeral"> + <choice> + <value>yes</value> + <value>no</value> + </choice> + </attribute> + </optional> <interleave> <element name="source"> <optional> @@ -2836,6 +2844,14 @@ </choice> </attribute> </optional> + <optional> + <attribute name="ephemeral"> + <choice> + <value>yes</value> + <value>no</value> + </choice> + </attribute> + </optional> <group> <element name="source"> <optional> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2ca608f..d0142f7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2958,6 +2958,7 @@ virDomainHostdevPartsParse(xmlNodePtr node, { xmlNodePtr sourcenode; char *managed = NULL; + char *ephemeral = NULL; int ret = -1; /* @mode is passed in separately from the caller, since an @@ -2984,6 +2985,16 @@ virDomainHostdevPartsParse(xmlNodePtr node, def->managed = 1; } + /* @ephemeral can be read from the xml document - it is always an + * attribute of the toplevel element, no matter what type of + * element that might be (pure hostdev, or higher level device + * (e.g. <interface>) with type='hostdev') + */ + if ((ephemeral = virXMLPropString(node, "ephemeral"))!= NULL) { + if (STREQ(ephemeral,"yes")) + def->ephemeral = 1; + } + /* @type is passed in from the caller rather than read from the * xml document, because it is specified in different places for * different kinds of defs - it is an attribute of @@ -12428,6 +12439,10 @@ virDomainActualNetDefFormat(virBufferPtr buf, def->data.hostdev.def.managed) { virBufferAddLit(buf, " managed='yes'"); } + if (def->type == VIR_DOMAIN_NET_TYPE_HOSTDEV && + def->data.hostdev.def.ephemeral) { + virBufferAddLit(buf, " ephemeral='yes'"); + } virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); @@ -12498,6 +12513,10 @@ virDomainNetDefFormat(virBufferPtr buf, def->data.hostdev.def.managed) { virBufferAddLit(buf, " managed='yes'"); } + if (def->type == VIR_DOMAIN_NET_TYPE_HOSTDEV && + def->data.hostdev.def.ephemeral) { + virBufferAddLit(buf, " ephemeral='yes'"); + } virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 6); @@ -13473,8 +13492,8 @@ virDomainHostdevDefFormat(virBufferPtr buf, return -1; } - virBufferAsprintf(buf, " <hostdev mode='%s' type='%s' managed='%s'>\n", - mode, type, def->managed ? "yes" : "no"); + virBufferAsprintf(buf, " <hostdev mode='%s' type='%s' managed='%s' ephemeral='%s'>\n", + mode, type, def->managed ? "yes" : "no", def->ephemeral ? "yes" : "no"); virBufferAdjustIndent(buf, 6); if (virDomainHostdevSourceFormat(buf, def, flags, false) < 0) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4ab15e9..597480f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -390,6 +390,7 @@ struct _virDomainHostdevDef { int startupPolicy; /* enum virDomainStartupPolicy */ unsigned int managed : 1; unsigned int missing : 1; + unsigned int ephemeral : 1; union { virDomainHostdevSubsys subsys; struct { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7736575..1b20d23 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7729,6 +7729,7 @@ qemuParseCommandLinePCI(const char *val) def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; def->managed = 1; + def->ephemeral = 1; def->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; def->source.subsys.u.pci.bus = bus; def->source.subsys.u.pci.slot = slot; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml index 3c69f83..fc7ea5c 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml @@ -21,7 +21,7 @@ </disk> <controller type='usb' index='0'/> <controller type='ide' index='0'/> - <hostdev mode='subsystem' type='pci' managed='yes'> + <hostdev mode='subsystem' type='pci' managed='yes' ephemeral='yes'> <source> <address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/> </source> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml index 811e987..d07dbe3 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml @@ -21,7 +21,7 @@ </disk> <controller type='usb' index='0'/> <controller type='ide' index='0'/> - <hostdev mode='subsystem' type='usb' managed='no'> + <hostdev mode='subsystem' type='usb' managed='no' ephemeral='no'> <source> <address bus='14' device='6'/> </source> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml index 81f70d0..54aa5e6 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml @@ -21,7 +21,7 @@ </disk> <controller type='usb' index='0'/> <controller type='ide' index='0'/> - <interface type='hostdev' managed='yes'> + <interface type='hostdev' managed='yes' ephemeral='yes'> <mac address='00:11:22:33:44:55'/> <source> <address type='pci' domain='0x0002' bus='0x03' slot='0x07' function='0x1'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml b/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml index 371835d..cce0d7f 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml @@ -31,13 +31,13 @@ <model type='virtio'/> <rom file='/etc/fake/bootrom.bin'/> </interface> - <hostdev mode='subsystem' type='pci' managed='yes'> + <hostdev mode='subsystem' type='pci' managed='yes' ephemeral='no'> <source> <address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/> </source> <rom bar='off'/> </hostdev> - <hostdev mode='subsystem' type='pci' managed='yes'> + <hostdev mode='subsystem' type='pci' managed='yes' ephemeral='no'> <source> <address domain='0x0000' bus='0x06' slot='0x12' function='0x6'/> </source> -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list