When we attach an interface to a running VM with boot index, we get a
successful result. But in fact the boot index won't take effect. QEMU
supported to set device's boot index online recently(since QEMU 2.2.0).
After this patch, the boot index will take effect after
virDomainAttachDevice(Flags) API returning success.
Signed-off-by: Wang Rui <moon.wangrui(a)huawei.com>
Signed-off-by: Zhou Yimin <zhouyimin(a)huawei.com>
---
src/qemu/qemu_hotplug.c | 33 +++++++++++++++++++++++++++++++++
src/qemu/qemu_hotplug.h | 4 ++++
2 files changed, 37 insertions(+)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7f93b9b..919a061 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1087,6 +1087,14 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
/* link set to down */
}
+ if (net->info.bootIndex > 0) {
+ if (qemuDomainChangeBootIndex(driver, vm, &net->info,
+ net->info.bootIndex) < 0) {
+ virDomainAuditNet(vm, NULL, net, "attach", false);
+ goto try_remove;
+ }
+ }
+
virDomainAuditNet(vm, NULL, net, "attach", true);
ret = 0;
@@ -1853,6 +1861,31 @@ int qemuDomainChangeNetLinkState(virQEMUDriverPtr driver,
}
int
+qemuDomainChangeBootIndex(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDeviceInfoPtr devInfo,
+ int newBootIndex)
+{
+ int ret = -1;
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+
+ if (!devInfo->alias) {
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("can't change boot index: device alias not
found"));
+ return -1;
+ }
+
+ VIR_DEBUG("Change dev: %s boot index from %d to %d", devInfo->alias,
+ devInfo->bootIndex, newBootIndex);
+
+ qemuDomainObjEnterMonitor(driver, vm);
+ ret = qemuMonitorSetBootIndex(priv->mon, devInfo->alias, newBootIndex);
+ qemuDomainObjExitMonitor(driver, vm);
+
+ return ret;
+}
+
+int
qemuDomainChangeNet(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainPtr dom,
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index d13c532..3af0875 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -57,6 +57,10 @@ int qemuDomainAttachHostDevice(virConnectPtr conn,
virDomainHostdevDefPtr hostdev);
int qemuDomainFindGraphicsIndex(virDomainDefPtr def,
virDomainGraphicsDefPtr dev);
+int qemuDomainChangeBootIndex(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDeviceInfoPtr devInfo,
+ int newBootIndex);
int qemuDomainChangeGraphics(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainGraphicsDefPtr dev);
--
1.7.12.4