Introduce qemuDomainChangeBootIndex api to support update device's bootindex.
These function will be used in following patches to support change device's
(support cdrom, disk and net) bootindex with virsh command like
'virsh update-device <domain> <file> [--flag]'.
Signed-off-by: Jiang Jiacheng <jiangjiacheng(a)huawei.com>
---
src/qemu/qemu_conf.c | 40 ++++++++++++++++++++++++++++++++++++
src/qemu/qemu_conf.h | 5 +++++
src/qemu/qemu_monitor.c | 20 ++++++++++++++++++
src/qemu/qemu_monitor.h | 6 ++++++
src/qemu/qemu_monitor_json.c | 33 +++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 6 ++++++
6 files changed, 110 insertions(+)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index ae5bbcd138..0071a95cb6 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1641,3 +1641,43 @@ qemuHugepageMakeBasedir(virQEMUDriver *driver,
return 0;
}
+
+/**
+ * qemuDomainChangeBootIndex:
+ * @vm: domain object
+ * @devInfo: origin device info
+ * @newBootIndex: new bootIndex
+ *
+ * check the alias and bootindex before send the command
+ *
+ * Returns: 0 on success,
+ * -1 otherwise.
+ */
+int
+qemuDomainChangeBootIndex(virDomainObj *vm,
+ virDomainDeviceInfo *devInfo,
+ int newBootIndex)
+{
+ int ret = -1;
+ int dummyIndex = -1;
+ qemuDomainObjPrivate *priv = vm->privateData;
+
+ if (!devInfo->alias) {
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("cannot 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(vm);
+ /* newBootIndex = 0 means cancel the specified bootIndex, send -1 to qemu instead */
+ if (!newBootIndex)
+ ret = qemuMonitorSetBootIndex(priv->mon, devInfo->alias, dummyIndex);
+ else
+ ret = qemuMonitorSetBootIndex(priv->mon, devInfo->alias, newBootIndex);
+ qemuDomainObjExitMonitor(vm);
+
+ return ret;
+}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 8cf2dd2ec5..e7447191df 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -375,3 +375,8 @@ int qemuGetMemoryBackingPath(virQEMUDriver *driver,
int qemuHugepageMakeBasedir(virQEMUDriver *driver,
virHugeTLBFS *hugepage);
+
+int qemuDomainChangeBootIndex(virDomainObj *vm,
+ virDomainDeviceInfo *devInfo,
+ int newBootIndex)
+ ATTRIBUTE_NONNULL(2);
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 80f262cec7..2b89d9bdae 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4491,3 +4491,23 @@ qemuMonitorGetStatsByQOMPath(virJSONValue *arr,
return NULL;
}
+
+/**
+ * qemuMonitorSetBootIndex:
+ * @mon: monitor object
+ * @alias: device's alias
+ * @bootIndex: new boot index
+ *
+ * Returns data from a call to 'qom-set'
+ */
+int
+qemuMonitorSetBootIndex(qemuMonitor *mon,
+ const char *alias,
+ int bootIndex)
+{
+ VIR_DEBUG("name=%s, bootIndex=%d", alias, bootIndex);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONSetBootIndex(mon, alias, bootIndex);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index c690fc3655..0b9943e1f7 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1568,3 +1568,9 @@ qemuMonitorExtractQueryStats(virJSONValue *info);
virJSONValue *
qemuMonitorGetStatsByQOMPath(virJSONValue *arr,
char *qom_path);
+
+int
+qemuMonitorSetBootIndex(qemuMonitor *mon,
+ const char *alias,
+ int bootIndex)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index f4e942a32f..75de73e61b 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8890,3 +8890,36 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
return virJSONValueObjectStealArray(reply, "return");
}
+
+/**
+ * qemuMonitorSetBootIndex:
+ * @mon: monitor object
+ * @alias: device's alias
+ * @bootIndex: new boot index
+ *
+ * Set the bootindex of device to new bootIndex
+ *
+ * Returns: 0 on success,
+ * -1 otherwise.
+ */
+int
+qemuMonitorJSONSetBootIndex(qemuMonitor *mon,
+ const char *alias,
+ int bootIndex)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("qom-set", "s:path",
alias,
+ "s:property",
"bootindex",
+ "i:value", bootIndex, NULL)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ return -1;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ return -1;
+
+ return 0;
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 93789480c5..30cd92f232 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -824,3 +824,9 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
qemuMonitorQueryStatsTargetType target,
char **vcpus,
GPtrArray *providers);
+
+int
+qemuMonitorJSONSetBootIndex(qemuMonitor *mon,
+ const char *alias,
+ int bootIndex)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
--
2.33.0