Common: Add quick access to first boot device
authorDominik Dingel <dingel@linux.vnet.ibm.com>
Fri, 26 Apr 2013 02:12:49 +0000 (02:12 +0000)
committerAlexander Graf <agraf@suse.de>
Fri, 26 Apr 2013 18:18:24 +0000 (20:18 +0200)
Instead of manually parsing the boot_list as character stream,
we can access the nth boot device, specified by the position in the
boot order.

Signed-off-by: Dominik Dingel <dingel@linux.vnet.ibm.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
include/sysemu/sysemu.h
vl.c

index 6578782fc3742c036716eadb4d86aea95ff3ca33..43b961c0f6536f0dfc06d793523d1404a3e1c04f 100644 (file)
@@ -181,6 +181,8 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev,
                           const char *suffix);
 char *get_boot_devices_list(size_t *size);
 
+DeviceState *get_boot_device(uint32_t position);
+
 bool usb_enabled(bool default_usb);
 
 extern QemuOptsList qemu_drive_opts;
diff --git a/vl.c b/vl.c
index 2e0d1a744cf48373a21e74a849c803da2e0a776f..322ea804f9985aaf0fa39f046c7dbe92290b4071 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -1222,6 +1222,24 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev,
     QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
 }
 
+DeviceState *get_boot_device(uint32_t position)
+{
+    uint32_t counter = 0;
+    FWBootEntry *i = NULL;
+    DeviceState *res = NULL;
+
+    if (!QTAILQ_EMPTY(&fw_boot_order)) {
+        QTAILQ_FOREACH(i, &fw_boot_order, link) {
+            if (counter == position) {
+                res = i->dev;
+                break;
+            }
+            counter++;
+        }
+    }
+    return res;
+}
+
 /*
  * This function returns null terminated string that consist of new line
  * separated device paths.