[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v11 29/34] usb-storage: add bootindex to qom propert
From: |
arei.gonglei |
Subject: |
[Qemu-devel] [PATCH v11 29/34] usb-storage: add bootindex to qom property |
Date: |
Tue, 7 Oct 2014 16:00:33 +0800 |
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>
---
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..c9d39d7 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.7.12.4
- [Qemu-devel] [PATCH v11 05/34] bootindex: rework add_boot_device_path function, (continued)
- [Qemu-devel] [PATCH v11 05/34] bootindex: rework add_boot_device_path function, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 04/34] fw_cfg: add fw_cfg_machine_reset function, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 17/34] net: remove bootindex property from qdev to qom, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 28/34] virtio-blk: alias bootindex property explicitly for virt-blk-pci/ccw/s390, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 34/34] bootindex: change fprintf to error_report, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 23/34] isa-fdc: remove bootindexA/B property from qdev to qom, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 25/34] ide: add bootindex to qom property, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 29/34] usb-storage: add bootindex to qom property,
arei.gonglei <=
- [Qemu-devel] [PATCH v11 32/34] bootindex: move calling add_boot_device_patch to bootindex setter function, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 27/34] block: remove bootindex property from qdev to qom, arei.gonglei, 2014/10/07
- Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and take effect after rebooting, Gonglei, 2014/10/08
- Re: [Qemu-devel] [PATCH v11 00/34] modify boot order of guest, and take effect after rebooting, Paolo Bonzini, 2014/10/09