Support to update the disk's bootindex using 'virsh update-device'.
Using flag --config or --persistent to change the boot index and the
change will be affected after reboot. With --persistent, we can get
the result of change immediently, but it still takes effect after reboot.
Currently, support update bootindex of disk type as cdrom or disk.
Signed-off-by: Jiang Jiacheng <jiangjiacheng(a)huawei.com>
---
src/qemu/qemu_domain.c | 3 ++-
src/qemu/qemu_driver.c | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index fe3ce023a4..f7ee7b7844 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8121,7 +8121,8 @@ qemuDomainDiskChangeSupported(virDomainDiskDef *disk,
/* device alias is checked already in virDomainDefCompatibleDevice */
- CHECK_EQ(info.bootIndex, "boot order", true);
+ if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
+ CHECK_EQ(info.bootIndex, "boot order", true);
CHECK_EQ(rawio, "rawio", true);
CHECK_EQ(sgio, "sgio", true);
CHECK_EQ(discard, "discard", true);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 707f4cc1bb..38cc5d0229 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7027,6 +7027,7 @@ qemuDomainChangeDiskLive(virDomainObj *vm,
virDomainDiskDef *orig_disk = NULL;
virDomainStartupPolicy origStartupPolicy;
virDomainDeviceDef oldDev = { .type = dev->type };
+ int needChangeIndex = 0;
if (!(orig_disk = virDomainDiskByTarget(vm->def, disk->dst))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -7044,6 +7045,10 @@ qemuDomainChangeDiskLive(virDomainObj *vm,
if (!qemuDomainDiskChangeSupported(disk, orig_disk))
return -1;
+ if ((needChangeIndex = qemuCheckBootIndex(orig_disk->info.bootIndex,
+ disk->info.bootIndex)) < 0)
+ return -1;
+
if (!virStorageSourceIsSameLocation(disk->src, orig_disk->src)) {
/* Disk source can be changed only for removable devices */
if (disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM &&
@@ -7067,6 +7072,11 @@ qemuDomainChangeDiskLive(virDomainObj *vm,
dev->data.disk->src = NULL;
}
+ if (needChangeIndex) {
+ if (qemuChangeDiskBootIndex(vm, orig_disk, disk) < 0)
+ return -1;
+ }
+
/* in case when we aren't updating disk source we update startup policy here */
orig_disk->startupPolicy = dev->data.disk->startupPolicy;
orig_disk->snapshot = dev->data.disk->snapshot;
@@ -7762,6 +7772,24 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef,
false) < 0)
return -1;
+ switch (vmdef->disks[pos]->device) {
+ case VIR_DOMAIN_DISK_DEVICE_CDROM:
+ case VIR_DOMAIN_DISK_DEVICE_DISK:
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ if (qemuCheckBootIndex(newDisk->info.bootIndex,
+ vmdef->disks[pos]->info.bootIndex) < 0)
+ return -1;
+ break;
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
+ if ((newDisk->info.bootIndex) &&
+ (vmdef->disks[pos]->info.bootIndex != newDisk->info.bootIndex))
{
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("this disk doesn't support update"));
+ return -1;
+ }
+ }
+
virDomainDiskDefFree(vmdef->disks[pos]);
vmdef->disks[pos] = newDisk;
dev->data.disk = NULL;
--
2.33.0