[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 1/8] bootindex: add modify_boot_device_path funct
From: |
arei.gonglei |
Subject: |
[Qemu-devel] [PATCH v5 1/8] bootindex: add modify_boot_device_path function |
Date: |
Mon, 4 Aug 2014 20:46:15 +0800 |
From: Gonglei <address@hidden>
When we want to change one device's bootindex, we
should lookup the device and change the bootindex.
it is simply that remove it from the global boot list,
then re-add it, sorted by new bootindex.
If the new bootindex has already used by another device
just throw an error.
Allow changing the existing bootindex entry only,
not support adding new boot entries.
Signed-off-by: Gonglei <address@hidden>
Signed-off-by: Chenliang <address@hidden>
---
include/sysemu/sysemu.h | 2 ++
vl.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+)
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..06e1b72 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -209,6 +209,8 @@ void usb_info(Monitor *mon, const QDict *qdict);
void add_boot_device_path(int32_t bootindex, DeviceState *dev,
const char *suffix);
+void modify_boot_device_path(int32_t bootindex, DeviceState *dev,
+ const char *suffix, Error **errp);
char *get_boot_devices_list(size_t *size, bool ignore_suffixes);
DeviceState *get_boot_device(uint32_t position);
diff --git a/vl.c b/vl.c
index fe451aa..770ad67 100644
--- a/vl.c
+++ b/vl.c
@@ -1248,6 +1248,72 @@ void add_boot_device_path(int32_t bootindex, DeviceState
*dev,
QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
}
+static bool is_same_fw_dev_path(DeviceState *src, DeviceState *dst)
+{
+ bool ret = false;
+ char *devpath_src = qdev_get_fw_dev_path(src);
+ char *devpath_dst = qdev_get_fw_dev_path(dst);
+
+ if (!strcmp(devpath_src, devpath_dst)) {
+ ret = true;
+ }
+
+ g_free(devpath_src);
+ g_free(devpath_dst);
+ return ret;
+}
+
+void modify_boot_device_path(int32_t bootindex, DeviceState *dev,
+ const char *suffix, Error **errp)
+{
+ FWBootEntry *i, *old_entry = NULL;
+
+ assert(dev != NULL || suffix != NULL);
+
+ if (bootindex >= 0) {
+ QTAILQ_FOREACH(i, &fw_boot_order, link) {
+ if (i->bootindex == bootindex) {
+ error_setg(errp, "The bootindex %d has already been used",
+ bootindex);
+ return;
+ }
+ }
+ }
+
+ QTAILQ_FOREACH(i, &fw_boot_order, link) {
+ /*
+ * Delete the same original dev, if devices havn't id property,
+ * we must check they fw_dev_path to identify them.
+ */
+ if ((i->dev->id && !strcmp(i->dev->id, dev->id)) ||
+ (!i->dev->id && is_same_fw_dev_path(i->dev, dev))) {
+ if (!suffix) {
+ QTAILQ_REMOVE(&fw_boot_order, i, link);
+ old_entry = i;
+
+ break;
+ } else if (i->suffix && !strcmp(suffix, i->suffix)) {
+ QTAILQ_REMOVE(&fw_boot_order, i, link);
+ old_entry = i;
+
+ break;
+ }
+ }
+ }
+
+ if (!old_entry) {
+ error_setg(errp, "The device(%s) havn't configured bootindex property"
+ " or suffix don't match", dev->id);
+
+ return;
+ }
+
+ add_boot_device_path(bootindex, dev, old_entry->suffix);
+
+ g_free(old_entry->suffix);
+ g_free(old_entry);
+}
+
DeviceState *get_boot_device(uint32_t position)
{
uint32_t counter = 0;
--
1.7.12.4
- [Qemu-devel] [PATCH v5 0/8] modify boot order of guest, and take effect after rebooting, arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v5 5/8] qmp: add set-bootindex command, arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v5 2/8] bootindex: add del_boot_device_path function, arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v5 4/8] bootindex: delete bootindex when device is removed, arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v5 3/8] fw_cfg: add fw_cfg_machine_reset function, arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v5 1/8] bootindex: add modify_boot_device_path function,
arei.gonglei <=
- [Qemu-devel] [PATCH v5 7/8] qmp: add query-bootindex command, arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v5 8/8] qemu-monitor: add HMP "info-bootindex" command, arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v5 6/8] qemu-monitor: HMP set-bootindex wrapper, arei.gonglei, 2014/08/04
- Re: [Qemu-devel] [PATCH v5 0/8] modify boot order of guest, and take effect after rebooting, Gonglei (Arei), 2014/08/04
- Re: [Qemu-devel] [PATCH v5 0/8] modify boot order of guest, and take effect after rebooting, Gonglei (Arei), 2014/08/07
- Re: [Qemu-devel] [PATCH v5 0/8] modify boot order of guest, and take effect after rebooting, Gerd Hoffmann, 2014/08/26