Commit Graph

51 Commits

Author SHA1 Message Date
Hannes Reinecke c5bf71a9a3 scsi: Add 'hba_private' to SCSIRequest
'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-07-19 15:38:58 +02:00
Paolo Bonzini d800040fb4 scsi: fix tracing of scsi requests with simple backend
The simple backend only supports a maximum of 6 arguments.  Split the
scsi_req_parsed event in two parts to cope with the limit.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2011-06-05 15:05:35 +00:00
Paolo Bonzini c6df7102f5 scsi: split command_complete callback in two
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
2011-05-26 12:14:17 +02:00
Hannes Reinecke 74382217ca scsi: Implement 'get_sense' callback
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-26 12:14:16 +02:00
Paolo Bonzini 0c34459b6a scsi: introduce scsi_req_get_buf
... 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-26 12:14:16 +02:00
Paolo Bonzini ad3376cc55 scsi: introduce scsi_req_continue
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
2011-05-26 12:14:16 +02:00
Paolo Bonzini 43a2b33957 scsi: introduce scsi_req_new
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26 12:14:16 +02:00
Paolo Bonzini fc4f0754c7 scsi: do not call send_command directly
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-26 12:14:16 +02:00
Hannes Reinecke a1f0cce2ac scsi: Update sense code handling
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-26 12:14:16 +02:00
Paolo Bonzini 94d3f98a3f scsi: introduce scsi_req_cancel
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-26 12:14:15 +02:00
Paolo Bonzini 19d110ab8a scsi: introduce scsi_req_abort
This covers the case of canceling a request's I/O and still
completing it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26 12:14:15 +02:00
Paolo Bonzini c557e88915 scsi: commonize purging requests
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-26 12:14:15 +02:00
Hannes Reinecke 5c6c0e5136 scsi: Use 'SCSIRequest' directly
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-26 12:14:15 +02:00
Paolo Bonzini ad2d30f79d scsi: reference-count requests
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-26 12:14:15 +02:00
Paolo Bonzini cfdc1bb06e scsi: introduce SCSIBusOps
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-26 12:14:14 +02:00
Paolo Bonzini ab9adc88c8 scsi: introduce scsi_req_data
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-26 12:14:14 +02:00
Paolo Bonzini 5138efecf2 scsi: add tracing of scsi requests
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2011-05-26 12:14:14 +02:00
Stefan Hajnoczi 2d1fd26137 scsi: Allow scsi_bus_legacy_add_drive() to set removable bit
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-24 21:39:22 +01:00
Gleb Natapov db07c0f84b Add get_fw_dev_path callback to scsi bus.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-12-11 21:32:45 +00:00
Hannes Reinecke a6d96eb78b scsi: Move sense handling into the driver
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-25 12:19:28 +01:00
Hannes Reinecke 622b520fb4 scsi: Increase the number of possible devices
The SCSI parallel interface has a limit of 8 devices, but
not the SCSI stack in general. So we should be removing the
hard-coded limit and use MAX_SCSI_DEVS instead.
And we only need to scan those devices which are allocated
by the bus.

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-25 11:57:32 +01:00
Bernhard Kohl a5e3d9ef4d scsi_bus: fix length and xfer_mode for RESERVE and RELEASE commands
For the RESERVE and RELEASE commands the length must be zero
and xfer_mode must be SCSI_XFER_NONE.

Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-09-21 15:39:43 +02:00
Blue Swirl 2446333cd5 Rearrange block headers
Changing block.h or blockdev.h resulted in recompiling most objects.

Move DriveInfo typedef and BlockInterfaceType enum definitions
to qemu-common.h and rearrange blockdev.h use to decrease churn.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-08-24 15:22:24 +00:00
Jan Kiszka e8637c9013 scsi: Dequeue requests before invoking completion callback
The request completion callback of the LSI controller may start the next
request that can use the same tag as the completed one. As the latter is
still enqueued at that point, scsi_send_command will complain about the
tag reuse and cancel the completed request. That will cause a double
free later on when the completion path cleans up as well.

Fix this by dequeuing the request before invoking the callback.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-07-22 05:52:10 +02:00
Markus Armbruster 42e766a24b scsi: Error locations for -drive if=scsi device initialization
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-07-06 17:05:49 +02:00
Markus Armbruster 18846dee1a block: Catch attempt to attach multiple devices to a blockdev
For instance, -device scsi-disk,drive=foo -device scsi-disk,drive=foo
happily creates two SCSI disks connected to the same block device.
It's all downhill from there.

Device usb-storage deliberately attaches twice to the same blockdev,
which fails with the fix in place.  Detach before the second attach
there.

Also catch attempt to delete while a guest device model is attached.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-07-02 13:18:02 +02:00
Markus Armbruster f8b6cc0070 qdev: Decouple qdev_prop_drive from DriveInfo
Make the property point to BlockDriverState, cutting out the DriveInfo
middleman.  This prepares the ground for block devices that don't have
a DriveInfo.

Currently all user-defined ones have a DriveInfo, because the only way
to define one is -drive & friends (they go through drive_init()).
DriveInfo is closely tied to -drive, and like -drive, it mixes
information about host and guest part of the block device.  I'm
working towards a new way to define block devices, with clean
host/guest separation, and I need to get DriveInfo out of the way for
that.

Fortunately, the device models are perfectly happy with
BlockDriverState, except for two places: ide_drive_initfn() and
scsi_disk_initfn() need to check the DriveInfo for a serial number set
with legacy -drive serial=...  Use drive_get_by_blockdev() there.

Device model code should now use DriveInfo only when explicitly
dealing with drives defined the old way, i.e. without -device.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-07-02 13:18:02 +02:00
Markus Armbruster fa66b909f3 scsi: scsi_bus_legacy_handle_cmdline() can fail, fix callers
None of its callers checks for failure.  scsi_hot_add() can crash
because of that:

(qemu) drive_add 4 if=scsi,format=host_device,file=/dev/sg1
scsi-generic: scsi generic interface too old
Segmentation fault (core dumped)

Fix all callers, not just scsi_hot_add().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-07-02 13:18:01 +02:00
Nicholas Bellinger c7126d5b32 scsi-bus: Add MAINTENANCE_IN and MAINTENANCE_OUT SCSIRequest xfer and mode assignments
This patch updates hw/scsi-bus.c to add MAINTENANCE_IN and MAINTENANCE_OUT case in
scsi_req_length() for TYPE_ROM with MMC commands.  It also adds the MAINTENANCE_OUT
case in scsi_req_xfer_mode() to set SCSI_XFER_TO_DEV for outgoing write data.

Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-06-22 14:38:01 +02:00
Nicholas Bellinger 01bedebaaf scsi-bus: Add PERSISTENT_RESERVE_OUT SCSIRequest->cmd.mode setup
This patch updates hw/scsi-bus.c to add the PERSISTENT_RESERVE_OUT cdb
case in scsi_req_xfer_mode() to set SCSI_XFER_TO_DEV for outgoing WRITE data.

Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-06-22 14:38:01 +02:00
Markus Armbruster 666daa6823 blockdev: Collect block device code in new blockdev.c
Anything that moves hundreds of lines out of vl.c can't be all bad.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-06-04 15:20:47 +02:00
Markus Armbruster 1ecda02b24 error: Replace qemu_error() by error_report()
error_report() terminates the message with a newline.  Strip it it
from its arguments.

This fixes a few error messages lacking a newline:
net_handle_fd_param()'s "No file descriptor named %s found", and
tap_open()'s "vnet_hdr=1 requested, but no kernel support for
IFF_VNET_HDR available" (all three versions).

There's one place that passes arguments without newlines
intentionally: load_vmstate().  Fix it up.
2010-03-16 16:58:32 +01:00
Markus Armbruster 2f7920166d error: Move qemu_error & friends into their own header 2010-03-16 16:55:05 +01:00
Blue Swirl 545557d4ab scsi: fix Sparse warning: Initializer entry defined twice
Both REWIND and REZERO_UNIT use 0x01, READ_POSITION and PRE_FETCH
share 0x34.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-12-25 16:11:40 +00:00
Gerd Hoffmann bd536cf330 scsi: add read/write 16 commands.
Add READ_16 + friends to scsi-defs.h, scsi_command_name() and the
request parsing helper functions.

Use them in scsi-disk.c too.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:40 -06:00
Gerd Hoffmann 39ec9a504d scsi-disk: restruct emulation: REPORT_LUNS
Move REPORT_LUNS emulation from scsi_send_command() to
scsi_disk_emulate_command().

Also add REPORT_LUNS to scsi-defs.h and scsi_command_name().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:40 -06:00
Gerd Hoffmann 5dd90e2ad7 scsi-disk: restruct emulation: SERVICE_ACTION_IN
Move SERVICE_ACTION_IN emulation from scsi_send_command() to
scsi_disk_emulate_command().

Also add SERVICE_ACTION_IN to scsi-defs.h and scsi_command_name().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:40 -06:00
Gerd Hoffmann 382155536c scsi-disk: restruct emulation: GET_CONFIGURATION
Move GET_CONFIGURATION emulation from scsi_send_command() to
scsi_disk_emulate_command().

Also add GET_CONFIGURATION to scsi-defs.h and scsi_command_name().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:40 -06:00
Gerd Hoffmann ec76686563 scsi: add scsi_req_print()
Handy for debugging.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:38 -06:00
Gerd Hoffmann ed3a34a3c8 scsi: move status to SCSIRequest.
Also add and use the scsi_req_complete() helper function for calling the
completion callback.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:37 -06:00
Gerd Hoffmann 37659e5104 scsi: move sense to SCSIDevice, create SCSISense struct.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:37 -06:00
Gerd Hoffmann 97a0643567 scsi: add xfer mode
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:37 -06:00
Gerd Hoffmann 2ec749cb82 scsi: add request parsing helpers to common code.
Add helper functions for scsi request parsing to common code.  Getting
command length, transfer size, and linear block address is handled.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:36 -06:00
Gerd Hoffmann 89b08ae154 scsi: move SCSIRequest management to common code.
Create generic functions to allocate, find and release SCSIRequest
structs.  Make scsi-disk and scsi-generic use them.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:36 -06:00
Gerd Hoffmann 9af99d980e scsi: move request lists to QTAILQ.
Changes:
 * Move from open-coded lists to QTAILQ macros.
 * Move the struct elements to the common data structures
   (SCSIDevice + SCSIRequest).
 * Drop free request pools.
 * Fix request cleanup in the destroy callback.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 09:41:36 -06:00
Gerd Hoffmann 43b443b668 scsi: move scsi-disk.h -> scsi.h
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-11-09 08:43:03 -06:00
Markus Armbruster 33e66b86d8 Check return value of qdev_init()
But do so only where it may actually fail.  Leave the rest for the
next commit.

Patchworks-ID: 35167
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-07 08:54:54 -05:00
Gerd Hoffmann cb23117be7 scsi: hotplug windup
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05 09:32:49 -05:00
Gerd Hoffmann 01985dcf38 Implement scsi device destruction
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05 09:32:48 -05:00
Gerd Hoffmann ca9c39faed switch scsi bus to inplace allocation.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05 09:32:46 -05:00