aboutsummaryrefslogtreecommitdiffstats
path: root/hw/scsi-disk.c
AgeCommit message (Collapse)AuthorFilesLines
2011-09-06scsi: improve MODE SENSE emulationPaolo Bonzini1-43/+53
- do not return extra pages when requesting all pages (PAGE CODE = 0x3f) - return correct sense code for PC = 3 (saved parameters not supported) - do not return geometry pages for CD devices Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-09-06scsi: refine constants for READ CAPACITY 16Paolo Bonzini1-3/+3
Rename SERVICE_ACTION_IN to SERVICE_ACTION_IN_16 to distinguish from the 12-byte CDB variant, and add a constant for the subcommand. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-09-06scsi: fix accounting of writesPaolo Bonzini1-6/+8
Writes go through scsi_write_complete at least twice, the first time to get some data without having actually written anything. Because of this, the first time scsi_write_complete is called it will call bdrv_acct_done and account a read incorrectly. Fix this by looking at the aiocb. I am doing the same in scsi_read_complete for symmetry, but it is only needed in the (bogus) case of bdrv_aio_readv returning NULL. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-09-06scsi: execute SYNCHRONIZE_CACHE asynchronouslyPaolo Bonzini1-16/+25
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-25block: explicit I/O accountingChristoph Hellwig1-0/+17
Decouple the I/O accounting from bdrv_aio_readv/writev/flush and make the hardware models call directly into the accounting helpers. This means: - we do not count internal requests from image formats in addition to guest originating I/O - we do not double count I/O ops if the device model handles it chunk wise - we only account I/O once it actuall is done - can extent I/O accounting to synchronous or coroutine I/O easily - implement I/O latency tracking easily (see the next patch) I've conveted the existing device model callers to the new model, device models that are using synchronous I/O and weren't accounted before haven't been updated yet. Also scsi hasn't been converted to the end-to-end accounting as I want to defer that after the pending scsi layer overhaul. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-2/+2
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-20scsi-disk: fix DPRINTFBlue Swirl1-2/+2
The variable 'status' does not exist anymore, adjust DPRINTF accordingly. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2011-08-12scsi: report unit attention on resetPaolo Bonzini1-2/+2
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12scsi: move handling of REQUEST SENSE to common codePaolo Bonzini1-7/+2
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12scsi: move handling of REPORT LUNS and invalid LUNs to common codePaolo Bonzini1-21/+0
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12scsi: move request parsing to common codePaolo Bonzini1-5/+0
Also introduce the first occurrence of "independent" SCSIReqOps, to handle invalid commands in common code. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12scsi: move request-related callbacks from SCSIDeviceInfo to SCSIReqOpsPaolo Bonzini1-18/+6
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12scsi: introduce SCSIReqOpsPaolo Bonzini1-13/+17
This will let allow requests to be dispatched through different callbacks, either common or per-device. This patch adjusts the API, the next one will move members to SCSIReqOps. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12scsi: move sense handling to generic codePaolo Bonzini1-46/+23
With this patch, sense data is stored in the generic data structures for SCSI devices and requests. The SCSI layer takes care of storing sense data in the SCSIDevice for the subsequent REQUEST SENSE command. At the same time, get_sense is removed and scsi_req_get_sense can use an entirely generic implementation. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12scsi: pass status when completingPaolo Bonzini1-11/+4
A small improvement in the SCSI request API. Pass the status at the time the request is completed, so that we can assert that no request is completed twice. This would have detected the problem fixed in the previous patch. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12scsi-disk: no need to call scsi_req_data on a short readPaolo Bonzini1-3/+0
In fact, if the HBA's transfer_data callback goes on with scsi_req_continue the request will be completed successfully instead of showing a failure. It can even cause a segmentation fault. An easy way to trigger it is "eject -f cd" during installation (during media test if the installer does something like that). Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-01scsi-disk: Remove 'drive_kind'Hannes Reinecke1-24/+22
Instead of using its own definitions scsi-disk should be using the device type of the parent device. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-01scsi: Sanitize command definitionsHannes Reinecke1-5/+5
Sanitize SCSI command definitions. Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG, WRITE_LONG, and WRITE_SAME. Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB, WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN, ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16, LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12. Remove invalid definition of WRITE_LONG_2. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-01scsi: Remove REZERO_UNIT emulationHannes Reinecke1-7/+0
REZERO_UNIT command is obsolete. Remove support for it. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-01scsi-disk: Codingstyle fixesHannes Reinecke1-8/+8
Replace tabs with spaces. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
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-19scsi-disk: Mask out serial number EVPDHannes Reinecke1-3/+12
If the serial number is not set we should mask it out in the list of supported VPD pages and mark it as not supported. Signed-off-by: Hannes Reinecke <hare@suse.de> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-19scsi-disk: Fixup debugging statementHannes Reinecke1-1/+1
A debugging statement wasn't converted to the new interface. Signed-off-by: Hannes Reinecke <hare@suse.de> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-19scsi: Add 'hba_private' to SCSIRequestHannes Reinecke1-2/+2
'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-05-26scsi: ignore LUN field in the CDBPaolo Bonzini1-3/+3
The LUN field in the CDB is a historical relic. Ignore it as reserved, which is what modern SCSI specifications actually say. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: make write_data return voidPaolo Bonzini1-4/+2
The return value is unused anyway. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26scsi-disk: add data direction checkingHannes Reinecke1-11/+24
scsi_req_parse() already provides for a data direction setting, so we should be using it to check for correct direction. And we should return the sense code 'INVALID FIELD IN CDB' in these cases. 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: Implement 'get_sense' callbackHannes Reinecke1-0/+11
The get_sense callback copies existing sense information into the provided buffer. This is required if sense information should be transferred together with the command response. 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: do not call send_command directlyPaolo Bonzini1-1/+0
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: Update sense code handlingHannes Reinecke1-43/+39
The SCSI spec has a quite detailed list of sense codes available. It even mandates the use of specific ones for some failure cases. The current implementation just has one type of generic error which is actually a violation of the spec in certain cases. This patch introduces various predefined sense codes to have the sense code reporting more in line with the spec. On top of Hannes's patch I fixed the reply to REQUEST SENSE commands with DESC=0 and a small (<18) length. 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 scsi_req_cancelPaolo Bonzini1-1/+0
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: commonize purging requestsPaolo Bonzini1-16/+2
The code for canceling requests upon reset is already the same. Clean it up and move it to scsi-bus.c. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: Use 'SCSIRequest' directlyHannes Reinecke1-85/+33
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: reference-count requestsPaolo Bonzini1-8/+15
With the next patch, a device may hold SCSIRequest for an indefinite time. Split a rather big patch, and protect against access errors, by reference counting them. There is some ugliness in scsi_send_command implementation due to the need to unref the request when it fails. This will go away with the next patches, which move the unref'ing to the devices. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Cc: Christoph Hellwig <hch@lst.de>
2011-05-26scsi: introduce scsi_req_dataPaolo Bonzini1-4/+4
This abstracts calling the command_complete callback, reducing churn in the following patches. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-19blockdev: Store -drive option media in DriveInfoMarkus Armbruster1-2/+3
DriveInfo is closely tied to -drive, and like -drive, it mixes information about host and guest part of the block device. Unlike DriveInfo, BlockDriverState should be about the host part only. One of the remaining guest bits there is the "type hint". -drive option media sets it, and qdevs "ide-drive", "scsi-disk" and non-qdev IF_XEN devices check it to pick HD vs. CD. Communicate -drive option media via new DriveInfo member media_cd instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-05-19scsi: Split qdev "scsi-disk" into "scsi-hd" and "scsi-cd"Markus Armbruster1-33/+103
A "scsi-disk" is either a hard disk or a CD-ROM, depending on the associated BlockDriverState's type hint. Unclean; disk vs. CD belongs to the guest part, not the host part. Have separate qdevs "scsi-hd" and "scsi-cd" to model disk vs. CD in the guest part. Keep scsi-disk for backward compatibility. Don't copy scsi-disk property removable to scsi-cd. It's not used and always zero(!) there. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-02-14Improve vm_stop reason declarationsJan Kiszka1-1/+1
Define and use dedicated constants for vm_stop reasons, they actually have nothing to do with the EXCP_* defines used so far. At this chance, specify more detailed reasons so that VM state change handlers can evaluate them. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
2011-01-24scsi-disk: Allow overriding SCSI INQUIRY removable bitStefan Hajnoczi1-0/+3
Provide the "removable" qdev property bit to override the SCSI INQUIRY removable (RMB) bit for non-CDROM devices. This will be used by USB Mass Storage Devices, which sometimes have this guest-visible bit set and sometimes do not. They therefore requires a means for user configuration. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-17scsi-disk: support WRITE SAME (16) with unmap bitChristoph Hellwig1-2/+51
Support discards via the WRITE SAME command with the unmap bit set, and tell the initiator about the support for it via the block limit and the new thin provisioning EVPD pages. Also fix the comment which incorrectly describedthe block limits EVPD page. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-11Add bootindex parameter to net/block/fd deviceGleb Natapov1-0/+1
If bootindex is specified on command line a string that describes device in firmware readable way is added into sorted list. Later this list will be passed into firmware to control boot order. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-12-11Introduce fw_name field to DeviceInfo structure.Gleb Natapov1-0/+1
Add "fw_name" to DeviceInfo to use in device path building. In contrast to "name" "fw_name" should refer to functionality device provides instead of particular device model like "name" does. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-11-25scsi-disk: Remove duplicate cdb parsingHannes Reinecke1-53/+21
We parse the CDB twice, which is completely unnecessary. Signed-off-by: Hannes Reinecke <hare@suse.de> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-11-25scsi: Move sense handling into the driverHannes Reinecke1-8/+25
The current sense handling in scsi-bus is only used by the scsi-disk driver; the scsi-generic driver is using its own. So we should move the current sense handling into the scsi-disk driver. Signed-off-by: Hannes Reinecke <hare@suse.de> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-11-25scsi: INQUIRY VPD fixesHannes Reinecke1-4/+14
We should announce and support the block device characterics page only on block devices, not on CDROMs. And the VPD page 0x83 has an off-by-one error. Signed-off-by: Hannes Reinecke <hare@suse.de> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-11-24scsi-disk: Move active request assertsStefan Hajnoczi1-6/+6
SCSI read/write requests should not be re-issued before the current fragment of I/O completes. There are asserts in scsi-disk.c that guard this constraint but they trigger on SPARC Linux 2.4. It turns out that the asserts are too early in the code path and don't allow for read requests to terminate. Only the read assert needs to be moved but move the write assert too for consistency. Reported-by: Nigel Horne <njh@bandsman.co.uk> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-11-04scsi-disk: Fix immediate failure of bdrv_aio_*Kevin Wolf1-5/+6
Fix scsi-disk to use the usual completion paths that involve rerror/werror handling instead of directly completing the requests in cases where bdrv_aio_readv/writev returns NULL. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-11-04scsi-disk: Implement werror for flushesKevin Wolf1-1/+16
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2010-11-04scsi-disk: Complete failed requests in scsi_disk_emulate_commandKevin Wolf1-11/+10
This pulls the request completion for error cases from the caller to scsi_disk_emulate_command. This should not change semantics, but allows to reuse scsi_handle_write_error() for flushes in the next patch. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2010-11-04scsi-disk: Implement rerror optionKevin Wolf1-34/+66
This implements the rerror option for SCSI disks. It also includes minor changes to the write path where the same code is used that was criticized in the review for the changes to the read path required for rerror support. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>