[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 29/34] usb-storage: add bootindex to qom property
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PULL 29/34] usb-storage: add bootindex to qom property |
Date: |
Wed, 15 Oct 2014 11:06:02 +0200 |
From: Gonglei <address@hidden>
Add a qom property with the same name 'bootindex',
when we remove it form qdev property, things will
continue to work just fine, and we can use qom features
which are not supported by qdev property.
Because usb-storage rely on scsi-disk which is created
in usb_msg_realize_storage(), so we should store the SCSIDevice
pointer in MSDState struct. Only in this way, we can change
the global boot_order_list when we want to change the bootindex
during vm rebooting by calling object_property_set_int(Object(SCSIDevice),).
Signed-off-by: Gonglei <address@hidden>
Signed-off-by: Gerd Hoffmann <address@hidden>
---
hw/usb/dev-storage.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index bd7cc53..7406fdd 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -17,6 +17,7 @@
#include "monitor/monitor.h"
#include "sysemu/sysemu.h"
#include "sysemu/blockdev.h"
+#include "qapi/visitor.h"
//#define DEBUG_MSD
@@ -59,6 +60,7 @@ typedef struct {
/* usb-storage only */
BlockConf conf;
uint32_t removable;
+ SCSIDevice *scsi_dev;
} MSDState;
struct usb_msd_cbw {
@@ -634,6 +636,7 @@ static void usb_msd_realize_storage(USBDevice *dev, Error
**errp)
}
s->bus.qbus.allow_hotplug = 0;
usb_msd_handle_reset(dev);
+ s->scsi_dev = scsi_dev;
if (bdrv_key_required(bs)) {
if (cur_mon) {
@@ -767,6 +770,54 @@ static void usb_msd_class_initfn_storage(ObjectClass
*klass, void *data)
usb_msd_class_initfn_common(klass);
}
+static void usb_msd_get_bootindex(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ USBDevice *dev = USB_DEVICE(obj);
+ MSDState *s = DO_UPCAST(MSDState, dev, dev);
+
+ visit_type_int32(v, &s->conf.bootindex, name, errp);
+}
+
+static void usb_msd_set_bootindex(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ USBDevice *dev = USB_DEVICE(obj);
+ MSDState *s = DO_UPCAST(MSDState, dev, dev);
+ int32_t boot_index;
+ Error *local_err = NULL;
+
+ visit_type_int32(v, &boot_index, name, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ /* check whether bootindex is present in fw_boot_order list */
+ check_boot_index(boot_index, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ /* change bootindex to a new one */
+ s->conf.bootindex = boot_index;
+
+ if (s->scsi_dev) {
+ object_property_set_int(OBJECT(s->scsi_dev), boot_index, "bootindex",
+ &error_abort);
+ }
+
+out:
+ if (local_err) {
+ error_propagate(errp, local_err);
+ }
+}
+
+static void usb_msd_instance_init(Object *obj)
+{
+ object_property_add(obj, "bootindex", "int32",
+ usb_msd_get_bootindex,
+ usb_msd_set_bootindex, NULL, NULL, NULL);
+ object_property_set_int(obj, -1, "bootindex", NULL);
+}
+
static void usb_msd_class_initfn_bot(ObjectClass *klass, void *data)
{
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
@@ -780,6 +831,7 @@ static const TypeInfo msd_info = {
.parent = TYPE_USB_DEVICE,
.instance_size = sizeof(MSDState),
.class_init = usb_msd_class_initfn_storage,
+ .instance_init = usb_msd_instance_init,
};
static const TypeInfo bot_info = {
--
1.8.3.1
- [Qemu-devel] [PULL 30/34] nvma: ide: add bootindex to qom property, (continued)
- [Qemu-devel] [PULL 30/34] nvma: ide: add bootindex to qom property, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 32/34] bootindex: move calling add_boot_device_patch to bootindex setter function, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 34/34] bootindex: change fprintf to error_report, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 05/34] bootindex: rework add_boot_device_path function, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 28/34] virtio-blk: alias bootindex property explicitly for virt-blk-pci/ccw/s390, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 10/34] eepro100: add bootindex to qom property, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 16/34] usb-net: add bootindex to qom property, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 20/34] pci-assign: remove bootindex property from qdev to qom, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 19/34] host-libusb: remove bootindex property from qdev to qom, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 27/34] block: remove bootindex property from qdev to qom, Gerd Hoffmann, 2014/10/15
- [Qemu-devel] [PULL 29/34] usb-storage: add bootindex to qom property,
Gerd Hoffmann <=
- Re: [Qemu-devel] [PULL 00/34] allow changing bootorder via monitor, Peter Maydell, 2014/10/16