Introduce qemuCheckBootIndex to check whether the device's bootIndex can be changed or need to be changed. Only bootindex of devices whose bootIndexSpecified is true can be changed. Signed-off-by: Jiang Jiacheng <jiangjiacheng@xxxxxxxxxx> --- src/qemu/qemu_domain.c | 32 ++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5c05032ce3..6ec3be14c0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12277,3 +12277,35 @@ qemuDomainSchedCoreStop(qemuDomainObjPrivate *priv) priv->schedCoreChildPID = -1; } } + +/** + * qemuCheckBootIndex: + * @devInfo: origin device info + * @new_bootindex: new bootIndex + * + * Check whether the device's bootIndex can be changed or need to + * be changed. Only devices with bootIndex specified before can be + * changed with @new_bootindex. + * + * Returns: 1 on need to change + * 0 on no need to change + * -1 on could not change with an error + */ +int +qemuCheckBootIndex(virDomainDeviceInfo *devInfo, + const int new_bootindex) +{ + if (new_bootindex && !devInfo->bootIndexSpecified) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("this device does not set boot index, cannot change it.")); + return -1; + } + + /* if the new bootindex is different from the old bootindex, + * we will update the bootindex. */ + if (devInfo->bootIndex != new_bootindex) { + return 1; + } + + return 0; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 2f027fad87..5869771a0d 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1140,3 +1140,7 @@ qemuDomainSchedCoreStart(virQEMUDriverConfig *cfg, void qemuDomainSchedCoreStop(qemuDomainObjPrivate *priv); + +int +qemuCheckBootIndex(virDomainDeviceInfo *devInfo, + const int new_bootindex); -- 2.33.0