diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2014-10-15 21:03:28 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2014-10-16 09:24:45 +0100 |
commit | 605c690b1b0e4f36c1e3f427322bdfaa80b9dcbe (patch) | |
tree | a4dd575a77b7038d237124f3b91c6b9bb4d7ab5e /hw/usb/dev-storage.c | |
parent | 89b516d8b9444ece8ccabb322a9389587c7a7b83 (diff) | |
parent | 54086fe5d2c562a3173126d9991bd064faf1e884 (diff) |
Merge remote-tracking branch 'remotes/kraxel/tags/pull-bootindex-20141015-1' into staging
allow changing bootorder via monitor at runtime,
by making bootindex a writable qom property.
* remotes/kraxel/tags/pull-bootindex-20141015-1: (34 commits)
bootindex: change fprintf to error_report
bootindex: delete bootindex when device is removed
bootindex: move calling add_boot_device_patch to bootindex setter function
ide: add calling add_boot_device_patch in bootindex setter function
nvma: ide: add bootindex to qom property
usb-storage: add bootindex to qom property
virtio-blk: alias bootindex property explicitly for virt-blk-pci/ccw/s390
block: remove bootindex property from qdev to qom
virtio-blk: add bootindex to qom property
ide: add bootindex to qom property
scsi: add bootindex to qom property
isa-fdc: remove bootindexA/B property from qdev to qom
redirect: remove bootindex property from qdev to qom
vfio: remove bootindex property from qdev to qom
pci-assign: remove bootindex property from qdev to qom
host-libusb: remove bootindex property from qdev to qom
virtio-net: alias bootindex property explicitly for virt-net-pci/ccw/s390
net: remove bootindex property from qdev to qom
usb-net: add bootindex to qom property
vmxnet3: add bootindex to qom property
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/usb/dev-storage.c')
-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 b005783fdf..5bfc72ca45 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 { @@ -633,6 +635,7 @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp) return; } usb_msd_handle_reset(dev); + s->scsi_dev = scsi_dev; if (bdrv_key_required(bs)) { if (cur_mon) { @@ -765,6 +768,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 = { |