QEMU supported to set device's boot index online recently(since QEMU 2.2.0).
This patch implements the disk's boot index update lively.
If boot order is not specified in the new xml, we take it as canceling boot
index. So pass "value":-1 to qmp command("qom-set") to cancel boot
index.
Signed-off-by: Wang Rui <moon.wangrui(a)huawei.com>
Signed-off-by: Zhou Yimin <zhouyimin(a)huawei.com>
---
src/qemu/qemu_driver.c | 64 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 55 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 673d8a6..9615fe4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7048,6 +7048,7 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
{
virDomainDiskDefPtr disk = dev->data.disk;
virDomainDiskDefPtr orig_disk = NULL;
+ int oldBootIndex = -1;
int ret = -1;
if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
@@ -7056,16 +7057,25 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
if (qemuDomainDetermineDiskChain(driver, vm, disk, false, true) < 0)
goto end;
+ if (!(orig_disk = virDomainDiskFindByBusAndDst(vm->def,
+ disk->bus, disk->dst))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("No device with bus '%s' and target
'%s'"),
+ virDomainDiskBusTypeToString(disk->bus),
+ disk->dst);
+ goto end;
+ }
+
switch (disk->device) {
case VIR_DOMAIN_DISK_DEVICE_CDROM:
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
- if (!(orig_disk = virDomainDiskFindByBusAndDst(vm->def,
- disk->bus, disk->dst))) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("No device with bus '%s' and target
'%s'"),
- virDomainDiskBusTypeToString(disk->bus),
- disk->dst);
- goto end;
+ if (orig_disk->info.bootIndex != disk->info.bootIndex) {
+ oldBootIndex = orig_disk->info.bootIndex;
+ if (qemuDomainChangeBootIndex(driver, vm, &orig_disk->info,
+ disk->info.bootIndex ?
+ disk->info.bootIndex : -1) < 0)
+ goto end;
+ orig_disk->info.bootIndex = disk->info.bootIndex;
}
/* Add the new disk src into shared disk hash table */
@@ -7075,6 +7085,16 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
if (qemuDomainChangeEjectableMedia(driver, conn, vm,
orig_disk, dev->data.disk->src, force)
< 0) {
ignore_value(qemuRemoveSharedDisk(driver, dev->data.disk,
vm->def->name));
+
+ /* Change media failed. Boot index should be changed back to original. */
+ if (oldBootIndex >= 0) {
+ if (qemuDomainChangeBootIndex(driver, vm, &orig_disk->info,
+ oldBootIndex ? oldBootIndex : -1) < 0)
{
+ VIR_WARN("Change Boot index back to original failed");
+ goto end;
+ }
+ orig_disk->info.bootIndex = oldBootIndex;
+ }
goto end;
}
@@ -7082,6 +7102,22 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
ret = 0;
break;
+ case VIR_DOMAIN_DISK_DEVICE_DISK:
+ if (orig_disk->info.bootIndex != disk->info.bootIndex) {
+ if (qemuDomainChangeBootIndex(driver, vm, &orig_disk->info,
+ disk->info.bootIndex ?
+ disk->info.bootIndex : -1) < 0)
+ goto end;
+ orig_disk->info.bootIndex = disk->info.bootIndex;
+ ret = 0;
+ break;
+ } else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("disk bus '%s' cannot be updated except boot
index."),
+ virDomainDiskBusTypeToString(disk->bus));
+ goto end;
+ }
+
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk bus '%s' cannot be updated."),
@@ -7413,8 +7449,17 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
return -1;
}
orig = vmdef->disks[pos];
- if (!(orig->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
- !(orig->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)) {
+ if (orig->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
+ if (orig->info.bootIndex != disk->info.bootIndex) {
+ orig->info.bootIndex = disk->info.bootIndex;
+ break;
+ } else {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("this disk doesn't support update except boot
index"));
+ return -1;
+ }
+ } else if (!(orig->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
+ !(orig->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("this disk doesn't support update"));
return -1;
@@ -7436,6 +7481,7 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
orig->src->format = disk->src->format;
disk->src->path = NULL;
orig->startupPolicy = disk->startupPolicy;
+ orig->info.bootIndex = disk->info.bootIndex;
break;
case VIR_DOMAIN_DEVICE_GRAPHICS:
--
1.7.12.4