Commit Graph

268 Commits

Author SHA1 Message Date
Paolo Bonzini 96c91bbf60 scsi-disk: support toggling the write cache
Finally, this uses the "plumbing" in the previous patch to
add support for toggling the WCE bit of the caching mode page.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:10 +02:00
Paolo Bonzini 380feaffb0 scsi-disk: parse MODE SELECT commands and parameters
This adds the bulk of the parsing code for MODE SELECT, including
breaking out changes to different mode pages, and checking that only
changeable values are modified.

In order to report errors correctly two passes are made through the
parameters; the first only looks for errors, the second actually
applies the changes to the mode page.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:10 +02:00
Paolo Bonzini 4f588b1511 scsi-disk: fix changeable values for MODE_PAGE_R_W_ERROR
The changeable values were not all-zeros for this mode page, fix it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:10 +02:00
Paolo Bonzini ef40561116 scsi-disk: adjust offsets in MODE SENSE by 2
This will make offsets the same when implementing MODE SELECT.  This is
because MODE SELECT has to deal with both 2-byte and 4-byte headers.
Unfortunately, this means that the offsets are now off by two compared
to the descriptions in the SCSI specs, which include the header.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:09 +02:00
Paolo Bonzini af6d510ddb scsi-disk: support emulated TO_DEV requests
This adds the implementation of write_data for the emulated
command case.  The first time through it asks for more data,
the second time it finishes the processing of the command.

MODE SELECT and MODE SELECT(10) can now be re-enabled, but they
will not do much.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:09 +02:00
Paolo Bonzini 314a329906 scsi-disk: separate read_data/write_data implementation for emulate_reqops
The previous patch only separated the send_command callback.
Use different implementations also for read_data and write_data.
The latter is still unreachable, so it aborts for now.

read_data passes the data buffer that was prepared and completes
the command.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:09 +02:00
Paolo Bonzini b08d0ea044 scsi-disk: split scsi-disk reqops
Only checks for present medium were still done in scsi_send_command
for emulated commands.  So move those to scsi_disk_emulate_command
and return different SCSIReqOps depending on the kind of command.

Checks for present medium can be done unconditionally for the
scsi_disk_dma_reqops case.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:09 +02:00
Paolo Bonzini 101aa85f98 scsi-disk: move all non-DMA commands to scsi_disk_emulate_command
We want to use separate SCSIReqOps for emulated commands needing an
allocated buffer vs. those that are zerocopy when the HBA supports
S/G lists.  Ensure that all of the former are in scsi_disk_emulate_command.

Commands that do not have any parameters are more similar to emulated
commands, so also move them, even if they do I/O.

Finally, MODE SELECT and MODE SELECT(10) are broken because we do not
yet support passing parameter data _to_ emulated commands, so disable
them.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:09 +02:00
Paolo Bonzini c1b3524788 scsi-disk: make discard asynchronous
By making discard asynchronous, we can reuse all the error handling
code that is used for other commands.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:09 +02:00
Dmitry Fleytman 353815aa6d scsi-disk: let the user customize vendor and product name
This patch adds two new properties vendor and product to SCSI disks.
These options let the user customize the inquiry data returned by the
disk.

Signed-off-by: Yan Vugenfirer <yan@ravellosystems.com>
Signed-off-by: Dmitry Fleytman <dmitry.fleytman@ravellosystems.com>
[ Use vendor and product property names, avoid "if" statements. - PB ]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:09 +02:00
Paolo Bonzini 038478370d scsi-block: remove properties that are not relevant for passthrough
scsi-block is a passthrough device and does not allow customization
of vendor, product, removable, DPOFUA, block size or any other piece of
information.  Thus, drop DEFINE_SCSI_DISK_PROPERTIES() from the
list of qdev properties.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-26 17:44:08 +02:00
Markus Armbruster b7eb0c9f95 hw/block-common: Factor out fall back to legacy -drive cyls=...
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-07-17 16:48:32 +02:00
Markus Armbruster 911525dba9 hw/block-common: Factor out fall back to legacy -drive serial=...
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-07-17 16:48:32 +02:00
Markus Armbruster d252df4898 scsi-hd: qdev properties for disk geometry
Geometry needs to be qdev properties, because it belongs to the
disk's guest part.

Maintain backward compatibility exactly like for serial: fall back to
DriveInfo's geometry, set with -drive cyls=...

Do this only for scsi-hd.  scsi-disk is legacy.  scsi-cd doesn't have
a geometry.  scsi-block should get geometry from the host disk.

Bonus: info qtree now shows the geometry.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-07-17 16:48:30 +02:00
Markus Armbruster 1f24d7b47e hd-geometry: Switch to uint32_t to match BlockConf
Best to use the same type, to avoid unwanted truncation or sign
extension.

BlockConf can't use plain int for cyls, heads and secs, because
integer properties require an exact width.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-07-17 16:48:30 +02:00
Markus Armbruster e2f3dc2b6a hd-geometry: Cut out block layer translation middleman
hd_geometry_guess() picks geometry and translation.  Callers can get
the geometry directly, via parameters, but for translation they need
to go through the block layer.

Add a parameter for translation, so it can optionally be gotten just
like geometry.  In preparation of purging translation from the block
layer, which will happen later in this series.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-07-17 16:48:30 +02:00
Markus Armbruster 9db1c0f7a9 hd-geometry: Move disk geometry guessing back from block.c
Commit f3d54fc4 factored it out of hw/ide.c for reuse.  Sensible,
except it was put into block.c.  Device-specific functionality should
be kept in device code, not the block layer.  Move it to
hw/hd-geometry.c, and make stylistic changes required to keep
checkpatch.pl happy.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-07-17 16:48:30 +02:00
Paolo Bonzini 1a4f0c3a06 scsi-disk: implement READ DISC INFORMATION
This command is not necessary for CD-ROM and DVD-ROM, but some versions of
udev trip on its absence.

Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-02 10:18:41 +02:00
Paolo Bonzini 27395add75 scsi: add a qdev property for the disk's WWN
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-02 10:18:41 +02:00
Paolo Bonzini 8257939002 scsi: simplify handling of the VPD page length field
The last four bytes of the thin provisioning page were cut out.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-07-02 10:18:40 +02:00
Crístian Viana 93bfef4c6e Allow machines to configure the QEMU_VERSION that's exposed via hardware
QEMU exposes its version to the guest's hardware and in some cases that is wrong
(e.g. Windows prints messages about driver updates when you switch
the QEMU version).
There is a new field now on the struct QEmuMachine, hw_version, which may
contain the version that the specific machine should report. If that field is
set, then that machine will report that version to the guest.

Signed-off-by: Crístian Viana <vianac@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-06-19 13:36:56 -05:00
Markus Armbruster 137745c5c6 scsi-disk: Don't peek behind the BlockDriverState abstraction
Use the appropriate interface instead.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-06-15 14:03:43 +02:00
Gerd Hoffmann 18eef3bc4e scsi: prepare migration code for usb-storage support
usb-storage can't handle requests in one go as the data transfer can be
splitted into lots of usb packets.  Because of that there can be
normal in-flight requests at savevm time and we need to handle that.
With other scsi hba's this happens only in case i/o is stopped due to
errors and there are pending requests which need to be restarted
(req->retry = true).

So, first we need to save req->retry and then handle the req->retry =
false case.  Write requests are handled fine already.  For read requests
we have to save the buffer as we will not restart the request (and thus
not refill the buffer) on the target host.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-06-07 10:02:21 +02:00
Paolo Bonzini 2a92fbff49 scsi: remove useless debug messages
Optional inquiry information is declared obsolete in the latest versions
of the standard; invalid CDBs or unsupported VPD pages are supported
can be diagnosed with trace_scsi_inquiry.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-05-07 08:44:21 +02:00
Paolo Bonzini 3c3d8a95ca scsi: do not require a minimum allocation length for INQUIRY
The requirements on the INQUIRY buffer size are not in my copy of SPC
(SPC-4 r27) and not observed by LIO.  Rip them out.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-05-07 08:44:21 +02:00
Paolo Bonzini da8365dbab scsi-disk: add dpofua property
Linux expects REQ_FUA to be advertised only if WRITE+FUA is faster than
WRITE+SYNCHRONIZE CACHE, so we should not set the DPOFUA bit.  However,
it is useful to have it for testing purposes, so add a qdev property to
set it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-05-07 08:44:19 +02:00
Paolo Bonzini bfe3d7ac6d scsi: change "removable" field to host many features
It is pointless to add a uint32_t field for every new feature.
Since we will need a new feature soon, convert accesses to "removable"
to look at bit 0 only.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-05-07 08:43:58 +02:00
Paolo Bonzini a5ee908562 scsi: fix WRITE SAME transfer length and direction
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-05-04 10:39:52 +02:00
Paolo Bonzini 31e8fd86f2 scsi: fix refcounting for reads
Recently introduced FUA support also gave us a use-after-free
of the BlockAcctCookie within a SCSIDiskReq, due to unbalanced
reference counting.

The patch fixes this by making scsi_do_read look like a combination
of scsi_*_complete + scsi_*_data.  It does both a ref (like
scsi_read_data) and an unref (like scsi_flush_complete).

Reported-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-05-04 10:39:52 +02:00
Ronnie Sahlberg f644a2904d SCSI emulation: should tell the guest that we actually support thin provisioning
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
[Actually, we should report it only if discard_granularity is nonzero.
 Older SBC drafts assigned 0 to thin provisioning and 1 to thick
 (resource-provisioned, they call it).  Newer drafts assign respectively
 1 and 2 - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 16:26:29 +02:00
Ronnie Sahlberg c9e4d8284e SCSI emulation: Support unmap via WRITE_SAME_10.
This was added in SBC r26 in place of the reserved bits that were
present up to that version.

It is the same as WRITE_SAME_16 as far as QEMU is concerned.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 16:16:05 +02:00
Paolo Bonzini 6a2de0f203 scsi: advertise DPOFUA
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 16:16:05 +02:00
Paolo Bonzini e590ecbed5 scsi: small refactoring of MMC mode-sense
Make DBD a boolean value, and force device-specific parameter to zero.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 16:16:05 +02:00
Paolo Bonzini ac66842646 scsi: support FUA on reads
To force unit access on reads, flush the cache *before* doing the read.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 16:16:05 +02:00
Paolo Bonzini a0e66a699e scsi: add a started field to SCSIDiskReq
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 16:16:05 +02:00
Paolo Bonzini 7f64f8e2c3 scsi: force unit access on VERIFY
Also DMA data from the host, to avoid that the host reports an
underrun.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 16:15:58 +02:00
Paolo Bonzini 7e8c49c561 scsi: add support for FUA on writes
To force unit access, add a flush operation after the actual write.
WRITE AND VERIFY commands always flush according to SBC, so do it
even though we do not perform the reread.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 15:27:20 +02:00
Paolo Bonzini b77912a77a scsi: move scsi_flush_complete around
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 15:27:20 +02:00
Paolo Bonzini 80624c938d scsi: make code more homogeneous in AIO callback functions
First scsi_flush_complete, like scsi_dma_complete, is always called with
an active AIOCB.

Second, always test for "ret < 0" to check for errors.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 15:27:20 +02:00
Paolo Bonzini b8aba8d7e3 scsi: add missing test for cancelled request
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-04-19 15:27:19 +02:00
Paolo Bonzini fd9307912d scsi: copy serial number into VPD page 0x83
Currently QEMU passes the qdev device id to the guest in an ASCII-string
designator in page 0x83.  While this is fine, it does not match what
real hardware does; usually the ASCII-string designator there hosts
another copy of the serial number (there can be other designators,
for example with a world-wide name).  Do the same for QEMU SCSI
disks.

ATAPI does not support VPD pages, so it does not matter there.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-03-19 16:35:17 +01:00
Paolo Bonzini 9bcaf4fe26 scsi-cd: check ready condition before processing several commands
This commit is more or less obvious.  What it caused is less obvious:
SCSI CD drives failed to eject under Linux, though for example the
"change" command worked okay.  This happens because of the autoclose
option in the Linux CD-ROM driver.

The actual chain of events is quite complex and somehow involves
udev helpers; the actual command that matters is READ TOC, though
honestly it's not really clear to me how because it should always be
invoked after autoclose, not before.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-03-19 16:35:17 +01:00
Anthony Liguori 7c1daf341f Merge remote-tracking branch 'qmp/queue/qmp' into staging
* qmp/queue/qmp:
  qmp: add DEVICE_TRAY_MOVED event
  ide: drop ide_tray_state_post_load()
  block: Don't call bdrv_eject() if the tray state didn't change
  block: bdrv_eject(): Make eject_flag a real bool
  block: Rename bdrv_mon_event() & BlockMonEventAction
2012-02-24 09:45:22 -06:00
Paolo Bonzini eaccf49e95 scsi-block: always use scsi_generic_ops for cache != none
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-24 14:54:51 +01:00
Luiz Capitulino d88b1819dd block: Don't call bdrv_eject() if the tray state didn't change
It's not needed. Besides we can then assume that bdrv_eject() is
only called when there's a tray state change, which is useful to
the DEVICE_TRAY_MOVED event (going to be added in a future
commit).

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
2012-02-22 17:23:21 -02:00
Luiz Capitulino 329c0a48a9 block: Rename bdrv_mon_event() & BlockMonEventAction
They are QMP events, not monitor events. Rename them accordingly.

Also, move bdrv_emit_qmp_error_event() up in the file. A new event will
be added soon and it's good to have them next each other.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
2012-02-22 17:22:35 -02:00
Paolo Bonzini 43b978b932 scsi-disk: add migration support
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-22 13:29:08 +01:00
Paolo Bonzini 5d0d246792 scsi-disk: enable scatter/gather functionality
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-22 13:29:08 +01:00
Andreas Färber 83f7d43a9e qom: Unify type registration
Replace device_init() with generalized type_init().

While at it, unify naming convention: type_init([$prefix_]register_types)
Also, type_init() is a function, so add preceding blank line where
necessary and don't put a semicolon after the closing brace.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: malc <av1474@comtv.ru>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-15 09:39:21 -06:00
Anthony Liguori 39bffca203 qdev: register all types natively through QEMU Object Model
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-03 10:41:06 -06:00