diff options
author | Gonglei <arei.gonglei@huawei.com> | 2014-10-07 16:00:33 +0800 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2014-10-15 10:27:07 +0200 |
commit | 89f0762dde298aac6949e1cefe06ab4ed13b1135 (patch) | |
tree | 212e08b7ea912b7305a0909616fb23b99742aef7 /hw | |
parent | aeb98ddc50defe9479d81fcb2afb9aa0c5b61bc8 (diff) | |
download | qemu-89f0762dde298aac6949e1cefe06ab4ed13b1135.zip qemu-89f0762dde298aac6949e1cefe06ab4ed13b1135.tar.gz qemu-89f0762dde298aac6949e1cefe06ab4ed13b1135.tar.bz2 |
usb-storage: add bootindex to qom property
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 <arei.gonglei@huawei.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/usb/dev-storage.c | 52 |
1 files changed, 52 insertions, 0 deletions
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 = { |