From: Laine Stump Date: Mon, 30 Nov 2015 22:40:44 +0000 (-0500) Subject: qemu: add bootindex option to hostdev network interface commandline X-Git-Tag: v1.3.1-rc1~189 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8e3247e650fc280920cfd4b0b809d521e161348;p=thirdparty%2Flibvirt.git qemu: add bootindex option to hostdev network interface commandline when appropriate, of course. If the config for a domain specifies boot order with elements, e.g.: ... Then the first disk device in the config will have ",bootindex=1" appended to its qemu commandline -device options, and the first (and *only* the first) network interface device will get ",bootindex=2". However, if the first network interface device is a "hostdev" device (an SRIOV Virtual Function (VF) being assigned to the domain with vfio), then the bootindex option will *not* be appended. This happens because the bootindex=n option corresponding to the order of "" is added to the -device for the first network device when network device commandline args are constructed, but if it's a hostdev network device, its commandline arg is instead constructed in the loop for hostdevs. This patch fixes that omission by noticing (in bootHostdevNet) if the first network device was a hostdev, and if so passing on the proper bootindex to the commandline generator for hostdev devices - the result is that ",bootindex=2" will be properly appended to the first "network" device in the config even if it is really a hostdev (including if it is assigned from a libvirt network pool). (note that this is only the case if there is no element in the config ("-boot menu-on" in qemu) , since the two are mutually exclusive - when the bootmenu is enabled, the individual per-device bootindex options can't be used by qemu, and we revert to using "-boot order=xyz" instead). If a greater level of control over boot order is desired (e.g., more than one network device should be tried, or a network device other than the first one encountered in the config), then in the element should not be used; instead, the individual device elements in the config should be given a " Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1278421 --- diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d2f37e408b..1f612b41d0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6084,6 +6084,7 @@ qemuOpenPCIConfig(virDomainHostdevDefPtr dev) char * qemuBuildPCIHostdevDevStr(virDomainDefPtr def, virDomainHostdevDefPtr dev, + int bootIndex, /* used iff dev->info->bootIndex == 0 */ const char *configfd, virQEMUCapsPtr qemuCaps) { @@ -6126,7 +6127,9 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def, pcisrc->addr.function); virBufferAsprintf(&buf, ",id=%s", dev->info->alias); if (dev->info->bootIndex) - virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex); + bootIndex = dev->info->bootIndex; + if (bootIndex) + virBufferAsprintf(&buf, ",bootindex=%d", bootIndex); if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0) goto error; if (qemuBuildRomStr(&buf, dev->info, qemuCaps) < 0) @@ -9291,7 +9294,8 @@ qemuBuildCommandLine(virConnectPtr conn, char *boot_order_str = NULL, *boot_opts_str = NULL; virBuffer fdc_opts = VIR_BUFFER_INITIALIZER; char *fdc_opts_str = NULL; - int bootCD = 0, bootFloppy = 0, bootDisk = 0; + int bootCD = 0, bootFloppy = 0, bootDisk = 0, bootHostdevNet = 0; + VIR_DEBUG("conn=%p driver=%p def=%p mon=%p json=%d " "qemuCaps=%p migrateURI=%s snapshot=%p vmop=%d", @@ -10279,6 +10283,16 @@ qemuBuildCommandLine(virConnectPtr conn, goto error; last_good_net = i; + /* if this interface is a type='hostdev' interface and we + * haven't yet added a "bootindex" parameter to an + * emulated network device, save the bootindex - hostdev + * interface commandlines will be built later on when we + * cycle through all the hostdevs, and we'll use it then. + */ + if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV && + bootHostdevNet == 0) { + bootHostdevNet = bootNet; + } bootNet = 0; } } @@ -11005,6 +11019,16 @@ qemuBuildCommandLine(virConnectPtr conn, if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { char *configfd_name = NULL; + int bootIndex = hostdev->info->bootIndex; + + /* bootNet will be non-0 if boot order was set and no other + * net devices were encountered + */ + if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET && + bootIndex == 0) { + bootIndex = bootHostdevNet; + bootHostdevNet = 0; + } if ((backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) && virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_CONFIGFD)) { int configfd = qemuOpenPCIConfig(hostdev); @@ -11020,7 +11044,8 @@ qemuBuildCommandLine(virConnectPtr conn, } } virCommandAddArg(cmd, "-device"); - devstr = qemuBuildPCIHostdevDevStr(def, hostdev, configfd_name, qemuCaps); + devstr = qemuBuildPCIHostdevDevStr(def, hostdev, bootIndex, + configfd_name, qemuCaps); VIR_FREE(configfd_name); if (!devstr) goto error; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index f0d6900b46..a96e57d70a 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -180,6 +180,7 @@ char *qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev, /* Current, best practice */ char *qemuBuildPCIHostdevDevStr(virDomainDefPtr def, virDomainHostdevDefPtr dev, + int bootIndex, const char *configfd, virQEMUCapsPtr qemuCaps); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index a88c2f2de7..d2395fe025 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1327,8 +1327,8 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver, goto error; } - if (!(devstr = qemuBuildPCIHostdevDevStr(vm->def, hostdev, configfd_name, - priv->qemuCaps))) + if (!(devstr = qemuBuildPCIHostdevDevStr(vm->def, hostdev, 0, + configfd_name, priv->qemuCaps))) goto error; qemuDomainObjEnterMonitor(driver, vm);