[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libvir-list
Subject:    [PATCH V3 1/7] qemu: Introduce qemuDomainChangeBootIndex to update device's bootindex
From:       Jiang Jiacheng <jiangjiacheng () huawei ! com>
Date:       2022-12-24 14:09:18
Message-ID: 20221224140924.581972-2-jiangjiacheng () huawei ! com
[Download RAW message or body]

Introduce qemuDomainChangeBootIndex 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@huawei.com>
---
 src/qemu/qemu_conf.c         | 41 ++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_conf.h         |  5 +++++
 src/qemu/qemu_monitor.c      | 12 +++++++++++
 src/qemu/qemu_monitor.h      |  6 ++++++
 src/qemu/qemu_monitor_json.c | 22 +++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  6 ++++++
 6 files changed, 92 insertions(+)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index ae5bbcd138..601357a7ee 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1641,3 +1641,44 @@ qemuHugepageMakeBasedir(virQEMUDriver *driver,
 
     return 0;
 }
+
+/**
+ * qemuDomainChangeBootIndex:
+ * @vm: domain object
+ * @devInfo: origin device info
+ * @newBootIndex: new bootIndex
+ *
+ * Update the bootIndex of @devInfo with @newBootIndex. Only the devices
+ * whose bootIndexSpecified = true can be updated with @newBootIndex.
+ * BootIndex of 0 means cancel the bootindex setting of @devInfo.
+ *
+ */
+int
+qemuDomainChangeBootIndex(virDomainObj *vm,
+                          virDomainDeviceInfo *devInfo,
+                          int newBootIndex)
+{
+    int ret = -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);
+
+    /* qemu dosen't support multiple bootIndex = 0 and need a negative bootIndex
+     * to delete the device from fw_boot_order. So transmit -1 to qemu when setting
+     * bootIndex = 0 to cancel the bootIndex setting. */
+    if (newBootIndex == 0)
+        newBootIndex = -1;
+
+    qemuDomainObjEnterMonitor(vm);
+    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 734364e070..7866347564 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4493,3 +4493,15 @@ qemuMonitorGetStatsByQOMPath(virJSONValue *arr,
 
     return NULL;
 }
+
+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 906a919f52..fab6f7bcbf 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1569,3 +1569,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 9822097bd7..39a84c8ae6 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8859,3 +8859,25 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
 
     return virJSONValueObjectStealArray(reply, "return");
 }
+
+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 484cb09830..00c04e62d1 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -825,3 +825,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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic