Introduce qemuCheckBootIndex to check the new bootindex and is it nessary
to update the bootindex. Introduce qemuChangeDiskBootIndex to support update
disk's bootindex according to different disks' type.
Signed-off-by: Jiang Jiacheng <jiangjiacheng(a)huawei.com>
---
src/qemu/qemu_conf.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_conf.h | 7 +++++++
2 files changed, 52 insertions(+)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index b653f44f25..3255632254 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1595,3 +1595,48 @@ qemuDomainChangeBootIndex(virDomainObj *vm,
return ret;
}
+
+int
+qemuCheckBootIndex(const int orig_bootindex,
+ const int new_bootindex)
+{
+ if ((new_bootindex == -1) && ((orig_bootindex == 0) || (orig_bootindex ==
-1))) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("this device does not set boot index, cannot cancel
it."));
+ return -1;
+ }
+
+ /* if the new bootindex is different from the old bootindex and not
+ * equal to 0, we will update the old bootindex.
+ */
+ if (new_bootindex && (orig_bootindex != new_bootindex)) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+qemuChangeDiskBootIndex(virDomainObj *vm,
+ virDomainDiskDef *orig_disk,
+ virDomainDiskDef *disk)
+{
+ switch (disk->device) {
+ case VIR_DOMAIN_DISK_DEVICE_CDROM:
+ case VIR_DOMAIN_DISK_DEVICE_DISK:
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ if (qemuDomainChangeBootIndex(vm, &orig_disk->info,
+ disk->info.bootIndex) < 0)
+ return -1;
+
+ orig_disk->info.bootIndex = disk->info.bootIndex;
+ break;
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("The boot index of disk bus '%s' cannot be
updated."),
+ virDomainDiskBusTypeToString(disk->bus));
+ return -1;
+ }
+ return 0;
+}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 4e2cd84fe5..43197afb7d 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -364,3 +364,10 @@ int qemuDomainChangeBootIndex(virDomainObj *vm,
virDomainDeviceInfo *devInfo,
int newBootIndex)
ATTRIBUTE_NONNULL(2);
+
+int qemuCheckBootIndex(const int orig_bootindex,
+ const int new_bootindex);
+
+int qemuChangeDiskBootIndex(virDomainObj *vm,
+ virDomainDiskDef *orig_disk,
+ virDomainDiskDef *disk);
--
2.33.0