summaryrefslogtreecommitdiff
path: root/hw/usb-msd.c
AgeCommit message (Collapse)AuthorFilesLines
2012-02-03qdev: register all types natively through QEMU Object ModelAnthony Liguori1-13/+17
This was done in a mostly automated fashion. I did it in three steps and then rebased it into a single step which avoids repeatedly touching every file in the tree. The first step was a sed-based addition of the parent type to the subclass registration functions. The second step was another sed-based removal of subclass registration functions while also adding virtual functions from the base class into a class_init function as appropriate. Finally, a python script was used to convert the DeviceInfo structures and qdev_register_subclass functions to TypeInfo structures, class_init functions, and type_register_static calls. We are almost fully converted to QOM after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03usb: separate out legacy usb registration from type registrationAnthony Liguori1-1/+2
Type registeration is going to get turned into a QOM call so decouple the legacy support. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27usb: convert to QEMU Object ModelAnthony Liguori1-18/+23
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-13usb: track altsetting in USBDeviceGerd Hoffmann1-10/+0
Also handle {GET,SET}_INTERFACE in common code (usb-desc.c). Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-06Merge remote-tracking branch 'stefanha/trivial-patches' into stagingAnthony Liguori1-1/+1
* stefanha/trivial-patches: qemu-nbd: drop loop which can never loop Make python mandatory net/socket.c: Fix fd leak in net_socket_listen_init() error paths gdbstub: Fix fd leak in gdbserver_open() error path configure: Fix test for supported host CPU type configure: CONFIG_QEMU_INTERP_PREFIX only for user mode scsi virtio-blk usb-msd: Clean up device init error messages Strip trailing '\n' from error_report()'s first argument (again) qemu-options.hx: fix tls-channel help text
2012-01-06scsi virtio-blk usb-msd: Clean up device init error messagesMarkus Armbruster1-1/+1
Replace error_report("DEVICE-NAME: MESSAGE"); by just error_report("MESSAGE"); in block device init functions. DEVICE-NAME is bogus in some cases: it's "scsi-disk" for device scsi-hd and scsi-cd, "virtio-blk-pci" for virtio-blk-s390, and "usb-msd" for usb-storage. There is no real need to put a device name in the message, because error_report() points to the offending command line option already: $ qemu-system-x86_64 --nodefaults --enable-kvm -vnc :0 -S -monitor stdio -usb -device virtio-blk-pci upstream-qemu: -device virtio-blk-pci: virtio-blk-pci: drive property not set upstream-qemu: -device virtio-blk-pci: Device 'virtio-blk-pci' could not be initialized And for a monitor command, it's obvious anyway: $ qemu-system-x86_64 --nodefaults --enable-kvm -vnc :0 -S -monitor stdio -usb (qemu) device_add virtio-blk-pci virtio-blk-pci: drive property not set Device 'virtio-blk-pci' could not be initialized Reported-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-01-06usb-storage: cancel I/O on resetGerd Hoffmann1-0/+12
When resetting the usb-storage device we'll have to carefully cancel and clear any requests which might be in flight, otherwise we'll confuse the state machine. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-11-22usb-msd: do not register twice in the boot orderPaolo Bonzini1-2/+2
USB mass storage devices are registered twice in the boot order. To avoid having to keep the two paths in sync, pass the bootindex property down to the scsi-disk device and let it register itself. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-11-21usb-storage: don't try to send the status early.Gerd Hoffmann1-6/+10
Until recently all scsi commands sent to scsi-disk did either transfer data or finished instantly. The correct implementation of SYNCRONIZE_CACHE changed the picture though, and usb-storage needs a fix to handle that case correctly.
2011-11-21usb-storage: drop result from device state.Gerd Hoffmann1-3/+1
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-11-21usb-storage: drop tag from device state.Gerd Hoffmann1-7/+6
scsi keeps track of the tag in SCSIRequest, no need to store a separate copy. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-11-21usb-storage: fill status in complete callback.Gerd Hoffmann1-17/+21
Put status word into device state, fill it in command_complete, have usb_msd_send_status just send it out. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-11-21usb-storage: move status debug message to usb_msd_send_status.Gerd Hoffmann1-2/+2
usb_msd_send_status can be called from different code paths, move the debug message into the function to make sure it is printed unconditionally. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-11-01usb: change VID/PID for usb-hub and usb-msd to prevent conflictRoy Tam1-2/+2
Some USB drivers, for example USBASPI.SYS, will skip different type of device which has same VID/PID. The following patch helps preventing usb-msd being skipped by the driver. Signed-off-by: Roy Tam <roytam@gmail.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-10-28scsi: allow arbitrary LUNsPaolo Bonzini1-1/+2
This only requires changes in two places: in SCSIBus, we need to look for a free LUN if somebody creates a device with a pre-existing scsi-id but the default LUN (-1, meaning "search for a free spot"); in vSCSI, we need to actually parse the LUN according to the SCSI spec. For vSCSI, max_target/max_lun are set according to the logical unit addressing format in SAM. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-10-28scsi: move tcq/ndev to SCSIBusOps (now SCSIBusInfo)Paolo Bonzini1-2/+5
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-10-13usb-storage: fix NULL pointer dereference.Gerd Hoffmann1-1/+4
When a usb packet is canceled we need to check whenever we actually have a scsi request in flight before we try to cancel it. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-06block: Attach non-qdev devices as wellMarkus Armbruster1-1/+1
For now, this just protects against programming errors like having the same drive back multiple non-qdev devices, or untimely bdrv_delete(). Later commits will add other interesting uses. While there, rename BlockDriverState member peer to dev, bdrv_attach() to bdrv_attach_dev(), bdrv_detach() to bdrv_detach_dev(), and bdrv_get_attached() to bdrv_get_attached_dev(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-12scsi: pass cdb already to scsi_req_newPaolo Bonzini1-2/+2
Right now the CDB is not passed to the SCSIBus until scsi_req_enqueue. Passing it to scsi_req_new will let scsi_req_new dispatch common requests through different reqops. Moving the memcpy to scsi_req_new is a hack that will go away as soon as scsi_req_new will also take care of the parsing. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-04usb-storage: iovec supportGerd Hoffmann1-58/+49
Add full iovec support to usb-storage. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-08-04usb: use iovecs in USBPacketGerd Hoffmann1-4/+8
Zap data pointer from USBPacket, add a QEMUIOVector instead. Add a bunch of helper functions to manage USBPacket data. Switch over users to the new interface. Note that USBPacket->len was used for two purposes: First to pass in the buffer size and second to return the number of transfered bytes or the status code on async transfers. There is a new result variable for the latter. A new status code was added to catch uninitialized result. Nobody creates iovecs with more than one element (yet). Some users are (temporarely) limited to iovecs with a single element to keep the patch size as small as possible. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-07-29Merge remote-tracking branch 'kraxel/migration.2' into stagingAnthony Liguori1-0/+12
2011-07-23Correct spelling of licensedMatthew Fernandez1-1/+1
Correct typos of "licenced" to "licensed". Reviewed-by: Stefan Weil <weil@mail.berlios.de> Reviewed-by: Andreas F=E4rber <andreas.faerber@web.de> Signed-off-by: Matthew Fernandez <matthew.fernandez@gmail.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-20usb storage: first migration support bits.Gerd Hoffmann1-0/+12
Tag vmstate as unmigratable for the time being, to be removed when mgration support is finished. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-07-19scsi: Add 'hba_private' to SCSIRequestHannes Reinecke1-8/+1
'tag' is just an abstraction to identify the command from the driver. So we should make that explicit by replacing 'tag' with a driver-defined pointer 'hba_private'. This saves the lookup for driver handling several commands in parallel. 'tag' is still being kept for tracing purposes. Signed-off-by: Hannes Reinecke <hare@suse.de> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-06-23usb-storage: Turn drive serial into a qdev property usb-storage.serialMarkus Armbruster1-3/+11
It needs to be a qdev property, because it belongs to the drive's guest part. Precedence: commit a0fef654 and 6ced55a5. Bonus: info qtree now shows the serial number. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23usb: Proper error propagation for usb_device_attach errorsHans de Goede1-2/+3
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-31Merge remote-tracking branch 'bonzini/scsi.2' into stagingAnthony Liguori1-50/+72
Conflicts: hw/usb-msd.c
2011-05-26scsi: rename arguments to the new callbacksPaolo Bonzini1-5/+5
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Cc: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: split command_complete callback in twoPaolo Bonzini1-30/+41
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Cc: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: introduce scsi_req_get_bufPaolo Bonzini1-1/+1
... and remove some SCSIDevice variables or fields that now become unused. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: introduce scsi_req_continuePaolo Bonzini1-11/+4
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Cc: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: introduce scsi_req_newPaolo Bonzini1-1/+1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: do not call send_command directlyPaolo Bonzini1-1/+1
Move the common part of scsi-disk.c and scsi-generic.c to the SCSI layer. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: introduce scsi_req_cancelPaolo Bonzini1-4/+15
This is for when the request must be dropped in the void, but still memory should be freed. To this end, the devices register a second callback in SCSIBusOps. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: Use 'SCSIRequest' directlyHannes Reinecke1-12/+15
Currently the SCSIRequest structure is abstracted away and cannot accessed directly from the driver. This requires the handler to do a lookup on an abstract 'tag' which identifies the SCSIRequest structure. With this patch the SCSIRequest structure is exposed to the driver. This allows use to use it directly as an argument to the SCSIDeviceInfo callback functions and remove the lookup. A new callback function 'alloc_req' is introduced matching 'free req'; unref'ing to free up resources after use is moved into the scsi_command_complete callbacks. This temporarily introduces a leak of requests that are cancelled, when they are removed from the queue and not from the driver. This is fixed later by introducing scsi_req_cancel. That patch in turn depends on this one, because the argument to scsi_req_cancel is a SCSIRequest. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: introduce SCSIBusOpsPaolo Bonzini1-1/+5
There are more operations than a SCSI bus can handle, besides completing commands. One example, which this series will introduce, is cleaning up after a request is cancelled. More long term, a "SCSI bus" can represent the LUNs attached to a target; in this case, while all commands will ultimately reach a logical unit, it is the target who is in charge of answering REPORT LUNs. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Cc: Christoph Hellwig <hch@lst.de>
2011-05-26usb: move cancel callback to USBDeviceInfoGerd Hoffmann1-5/+3
Remove the cancel callback from the USBPacket struct, move it over to USBDeviceInfo. Zap usb_defer_packet() which is obsolete now. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26usb-storage: don't call usb_packet_complete twiceGerd Hoffmann1-1/+1
usb_msd_copy_data() may cause a recursive call to usb_msd_command_complete() which in turn may complete the packet, setting s->packet to NULL in case it does. Recheck s->packet before calling usb_packet_complete() to fix the double call. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26usb: Pass the packet to the device's handle_control callbackHans de Goede1-3/+3
This allows using the generic usb_generic_handle_packet function from device code which does ASYNC control requests (such as the linux host pass through code). Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-26usb: update config descriptors to identify number of interfacesBrad Hards1-0/+2
Previously we relied on the .bNumInterfaces, but that won't always be accurate after the introduction of grouped interfaces. Signed-off-by: Brad Hards <bradh@frogmouth.net> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-04usb: mass storage fixGerd Hoffmann1-0/+1
Initialize scsi_len with zero when starting a new request, so any stuff leftover from the previous request is cleared out. This may happen in case the data returned by the scsi command doesn't fit into the buffer provided by the guest. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-04usb: move complete callback to port opsGerd Hoffmann1-2/+2
2011-04-16usb: trivial spelling fixesBrad Hards1-2/+2
Signed-off-by: Brad Hards <bradh@frogmouth.net> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-02-01Add bootindex handling into usb storage device.Gleb Natapov1-0/+2
Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-01-31blockdev: Fix drive_add for drives without mediaMarkus Armbruster1-2/+1
Watch this: (qemu) drive_add 0 if=none (qemu) info block none0: type=hd removable=0 [not inserted] (qemu) drive_del none0 Segmentation fault (core dumped) add_init_drive() is confused about drive_init()'s failure modes, and cleans up when it shouldn't. This leaves the DriveInfo with member opts dangling. drive_del attempts to free it, and dies. drive_init() behaves as follows: * If it created a drive with media, it returns its DriveInfo. * If it created a drive without media, it clears *fatal_error and returns NULL. * If it couldn't create a drive, it sets *fatal_error and returns NULL. Of its three callers: * drive_init_func() is correct. * usb_msd_init() assumes drive_init() failed when it returns NULL. This is correct only because it always passes option "file", and "drive without media" can't happen then. * add_init_drive() assumes drive_init() failed when it returns NULL. This is incorrect. Clean up drive_init() to return NULL on failure and only on failure. Drop its parameter fatal_error. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-01-24usb-msd: Propagate removable bit to SCSI deviceStefan Hajnoczi1-1/+3
USB Mass Storage Devices sometimes have the RMB (removable) bit set in the SCSI INQUIRY response. Thumbdrives tend to have the bit set whereas hard disks do not. Operating systems differentiate between removable devices and fixed devices. Under Linux, the anaconda installer looks for removable devices. Under Windows, only fixed devices may have more than one partition and AutoRun is also affected by the removable bit. For these reasons, allow USB Mass Storage Devices to override the removable bit: qemu -usb -drive if=none,file=test.img,cache=none,id=disk0 -device usb-storage,drive=disk0,removable=on The default is off. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-01-24scsi: Allow scsi_bus_legacy_add_drive() to set removable bitStefan Hajnoczi1-1/+1
scsi-disk devices may wish to override the removable bit. Add support for a qdev property on SCSI devices. This is will be used by usb-msd. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-01-11usb storage: handle long responsesGerd Hoffmann1-2/+2
The scsi layer may return us more data than the guests wants to have. Handle this by just ignoring the extra bytes and calling the {read,write}_data callback to finish the request. Seen happening in real life with some extended inquiry command. With this patch applied the linux kernel stops reseting the device once at boot. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11usb storage: fix status reportingGerd Hoffmann1-6/+7
Change usb_msd_send_status() to take a pointer to the status packet instead of writing the status to s->usb_buf which might not point to the correct location. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>