summaryrefslogtreecommitdiffstats
path: root/hw/scsi-bus.c
Commit message (Collapse)AuthorAgeFilesLines
* scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULLJim Meyering2012-10-051-6/+2
| | | | | | | | | | | | | Use g_strdup rather than strdup, because the sole caller (qdev_get_fw_dev_path_helper) assumes it gets non-NULL, and dereferences it. Besides, in that caller, the allocated buffer is already freed with g_free, so it's better to allocate with a matching g_strdup. In one case, (scsi-bus.c) it was trivial, so I replaced an snprintf+ g_strdup combination with an equivalent g_strdup_printf use. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* scsi: introduce scsi_cdb_length and scsi_data_cdb_lengthPaolo Bonzini2012-09-211-5/+18
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: fix warningGerd Hoffmann2012-08-181-0/+2
| | | | | | | | | | | | hw/scsi-bus.c:758: warning: ‘xfer’ may be used uninitialized in this function Isn't true, but older gcc versions (for example 4.1 as shipped in rhel5) are not clever enougth to figure, so sprinkle in a default: line to make them happy. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* scsi-bus: remove overlapping entryBlue Swirl2012-08-091-1/+0
| | | | | | | | | | | LOAD_UNLOAD and START_STOP have same value, so the table entry is initialized twice. Spotted by Clang compiler. Remove LOAD_UNLOAD entry since START_STOP entry already represents both. Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* scsi: add support for ATA_PASSTHROUGH_xx scsi commandCong Meng2012-08-031-3/+85
| | | | | | | | Correct the command names of opcode 0x85 and 0xa1, and calculate their xfer size from CDB. Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* SCSI: Update the sense code for PREVENT REMOVAL errorsRonnie Sahlberg2012-08-031-2/+2
| | | | | | | | | | | | | Change the sense codes for failures to eject a device that is locked by PREVENT_ALLOW_MEDIUM_REMOVAL from the generic MEDIA_LOAD_OR_EJECT_FAILED to the more specific MEDIUM_REMOVAL_PREVENTED. The second sense code is more accurate, and is also listed in MMC annex F for the recommended sense codes for MMC devices while the first sense code is not. Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: report parameter changes to HBA driversPaolo Bonzini2012-07-271-0/+10
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi-disk: report resized disk via sense codesPaolo Bonzini2012-07-271-0/+5
| | | | | | | Linux will not use these, but a very similar mechanism will be used to report the condition via virtio-scsi events. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: establish precedence levels for unit attentionPaolo Bonzini2012-07-271-1/+51
| | | | | | | | When a device is resized, we will report a unit attention condition for CAPACITY DATA HAS CHANGED. However, we should ensure that this condition does not override a more important unit attention condition. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: introduce hotplug() and hot_unplug() interfaces for SCSI busCong Meng2012-07-271-1/+16
| | | | | | | | | | | Add two interfaces hotplug() and hot_unplug() to scsi bus info. The scsi bus can implement these two interfaces to signal the HBA driver of guest kernel to add/remove the scsi device in question. Signed-off-by: Sen Wang <senwang@linux.vnet.ibm.com> Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com> [ Fixed braces and indentation - Paolo ] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: add tracepoint for scsi_req_cancelPaolo Bonzini2012-07-271-0/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi-disk: Fail medium writes with proper sense for readonly LUNsRonnie Sahlberg2012-07-261-0/+5
| | | | | | | | | Add sense code for DATA_PROTECT/WRITE_PROTECTED and return this error for any WRITE*/WRITE_VERIFY* calls if the device is readonly=on, i.e. write-protected Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi-disk: parse MODE SELECT commands and parametersPaolo Bonzini2012-07-261-0/+10
| | | | | | | | | | | | 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>
* scsi: add free_request callbackPaolo Bonzini2012-07-101-0/+5
| | | | | | | | | | | | | | | | | | | | Most device models have a simple lifecycle for the hba_private field and they can free it when a request is completed or cancelled. However, in some cases it may be simpler to tie the lifetime of hba_private to that of the included SCSIRequest. This patch adds a free_request callback to SCSIBusInfo that lets an HBA device model do exactly that. Normally, device models use req->hba_private == NULL to flag requests that have been completed already. Device models that use free_request will still need to track this using a flag. This is the reason why "converting" existing HBAs to use free_request adds complexity and makes little sense. It is simply an additional convenience that is provided by the SCSI layer. USB-attached storage will be the first user. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
* scsi: Fix transfer length for READ POSITION commands.Christian Hoff2012-07-021-1/+15
| | | | | | | | | | The transfer length depends on the specific service action code, as defined in the SCSI stream commands spec section 7.7. Up to now only the extended form was supported. Signed-off-by: Christian Hoff <christian.hoff@de.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: Add basic support for SCSI media changer commands.Christian Hoff2012-07-021-6/+39
| | | | | | | | | | This adds basic support for SCSI media changer commands. Not all commands are supported as of now, but enough to cover basic functionality. Signed-off-by: Christian Hoff <christian.hoff@de.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: Ensure command and transfer lengths are set for all SCSI devicesPaolo Bonzini2012-07-021-7/+18
| | | | | | | | | scsi-generic relies on those values to be correct, so it is important that those values are initialized properly for all device types. Reported-by: Christian Hoff <christian.hoff@de.ibm.com> Reported-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: Fix LOAD_UNLOADChristian Hoff2012-07-021-3/+3
| | | | | | | | | Change operation code of LOAD_UNLOAD command to 0x1b as described in section 7.3 of the SCSI Stream Commands spec. Signed-off-by: Christian Hoff <christian.hoff@de.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: Fix data length == SCSI_SENSE_BUF_SIZEChristian Hoff2012-07-021-1/+1
| | | | | | | | | | | Fix the edge case where the sense data length is exactly the same as SCSI_SENSE_BUF_SIZE. This makes SCSI requests work that use all of the available 95 byte sense data. Signed-off-by: Christian Hoff <christian.hoff@de.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* Allow machines to configure the QEMU_VERSION that's exposed via hardwareCrístian Viana2012-06-191-1/+1
| | | | | | | | | | | | 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>
* qom: Push error reporting to object_property_find()Paolo Bonzini2012-06-181-1/+1
| | | | | | | | Avoids duplicated error_set(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [AF: Also drop error_set() in object_property_del().] Signed-off-by: Andreas Färber <afaerber@suse.de>
* qdev: Remove qdev_prop_exists()Paolo Bonzini2012-06-181-1/+1
| | | | | | | Can be replaced everywhere with object_property_find(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qbus: Make child devices linksAnthony Liguori2012-06-181-5/+8
| | | | | | | | | | | | Make qbus children show up as link<> properties. There is no stable addressing for qbus children so we use an unstable naming convention. This is okay in QOM though because the composition name is expected to be what's stable. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qdev: Convert busses to QEMU Object ModelAnthony Liguori2012-06-181-7/+16
| | | | | | | | | | | | | | | This is far less interesting than it sounds. We simply add an Object to each BusState and then register the types appropriately. Most of the interesting refactoring will follow in the next patches. Since we're changing fundamental type names (BusInfo -> BusClass), it all needs to convert at once. Fortunately, not a lot of code is affected. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [AF: Made all new bus TypeInfos static const.] [AF: Made qbus_free() call object_delete(), required {qom,glib}_allocated] Signed-off-by: Andreas Färber <afaerber@suse.de>
* qdev: Use wrapper for qdev_get_pathAnthony Liguori2012-06-181-4/+2
| | | | | | | | | This makes it easier to remove it from BusInfo. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [AF: Drop now unnecessary NULL initialization in scsibus_get_dev_path()] Signed-off-by: Andreas Färber <afaerber@suse.de>
* qdev: Move bus properties to abstract superclassesPaolo Bonzini2012-06-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In qdev, each bus in practice identified an abstract superclass, but this was mostly hidden. In QOM, instead, these abstract classes are explicit so we can move bus properties there. All bus property walks are removed, and all device property walks are changed to look along the class hierarchy instead. We would have duplicates if class A defines some properties and its subclass B does not define any, because class_b->props will be left equal to class_a->props. The solution here is to reintroduce the class_base_init TypeInfo callback, that was present in one of the early QOM versions but removed (on my request...) before committing. This breaks global bus properties, an obscure feature when used with the command-line which is actually useful and used when used by backwards-compatible machine types. So this patch also adjusts the global bus properties in hw/pc_piix.c to refer to the abstract class. Globals and other properties must be modified in the same patch to avoid complications related to initialization ordering. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* qdev: Move bus properties to a separate globalPaolo Bonzini2012-06-181-6/+8
| | | | | | | Simple code movement in order to simplify future refactoring. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* scsi: prepare migration code for usb-storage supportGerd Hoffmann2012-06-071-4/+4
| | | | | | | | | | | | | | | | | 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>
* scsi: declare vmstate_info_scsi_requests to be staticJim Meyering2012-05-251-1/+1
| | | | Signed-off-by: Jim Meyering <meyering@redhat.com>
* scsi: Add assertion for use-after-free errorsStefan Weil2012-05-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The QEMU emulation which is currently used with Raspberry PI images (qemu-system-arm -M versatilepb ...) accesses memory which was freed. Valgrind output (extract): ==17857== Invalid write of size 4 ==17857== at 0x24EB06: scsi_req_unref (scsi-bus.c:1273) ==17857== by 0x24FFAE: scsi_read_complete (scsi-disk.c:277) ==17857== by 0x152ACC: bdrv_co_em_bh (block.c:3363) ==17857== by 0x13D49C: qemu_bh_poll (async.c:71) ==17857== by 0x211A8C: main_loop_wait (main-loop.c:503) ==17857== by 0x207954: main_loop (vl.c:1555) ==17857== by 0x20E9C9: main (vl.c:3653) ==17857== Address 0x1c54383c is 12 bytes inside a block of size 260 free'd ==17857== at 0x4824B3A: free (vg_replace_malloc.c:366) ==17857== by 0x20ADFA: free_and_trace (vl.c:2250) ==17857== by 0x4899FC5: g_free (in /lib/libglib-2.0.so.0.2400.1) ==17857== by 0x24EB3B: scsi_req_unref (scsi-bus.c:1277) ==17857== by 0x24F003: scsi_req_complete (scsi-bus.c:1383) ==17857== by 0x25022A: scsi_read_data (scsi-disk.c:334) ==17857== by 0x24EB9F: scsi_req_continue (scsi-bus.c:1289) ==17857== by 0x1C7787: lsi_do_dma (lsi53c895a.c:575) ==17857== by 0x1C8CDA: lsi_execute_script (lsi53c895a.c:1147) ==17857== by 0x1C74EA: lsi_resume_script (lsi53c895a.c:510) ==17857== by 0x1C7ECD: lsi_transfer_data (lsi53c895a.c:746) ==17857== by 0x24EC90: scsi_req_data (scsi-bus.c:1307) (There are some more similar messages.) This patch adds an assertion which also detects those errors: Calling scsi_req_unref is not allowed when the previous call of that function has decremented refcount to 0, because in this case req was freed. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: set VALID bit to 0 in fixed format sense dataPaolo Bonzini2012-05-071-2/+2
| | | | | | | The INFORMATION field (bytes 3..6) is never set by QEMU, so the VALID bit must be 0. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: do not require a minimum allocation length for REQUEST SENSEPaolo Bonzini2012-05-071-5/+2
| | | | | | | The requirements on the REQUEST SENSE 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>
* scsi: do not require a minimum allocation length for INQUIRYPaolo Bonzini2012-05-071-8/+0
| | | | | | | 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>
* scsi: parse 16-byte tape CDBsPaolo Bonzini2012-05-071-0/+10
| | | | | | | The transfer length for these commands is different from the transfer length of the corresponding disk commands, so parse it specially. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: do not report bogus overruns for commands in the 0x00-0x1F rangePaolo Bonzini2012-05-071-6/+10
| | | | | | | | | Interpreting cdb[4] == 0 as a request to transfer 256 blocks is only needed for READ_6 and WRITE_6. No other command in that range needs that special-casing, and the resulting overrun breaks scsi-testsuite's attempt to use command 2 as a known-invalid command. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: Specify the xfer direction for UNMAP and ATA_PASSTHROUGH commandsRonnie Sahlberg2012-05-041-0/+2
| | | | | | | | | | | | | | | | | | | scsi_cmd_xfer_mode() is used to specify the xfer direction for SCSI commands that come in from the guest. If the direction is set incorrectly this will eventually cause QEMU to kernel-panic the guest. Add UNMAP and ATAPASSTHROUGH as commands that send data to the device. Without this change, recent kernels will send both UNMAP as well as ATAPASSTHROUGH commands to any /dev/sg* device, which due to the incorrect xfer direction very quickly causes the guest kernel to crash. Example causing a crash without the patch applied: ./x86_64-softmmu/qemu-system-x86_64 -m 1024 -enable-kvm -cdrom linuxmint-12-gnome-dvd-64bit.iso -drive file=/dev/sg4,if=scsi,bus=0,unit=6 Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: fix WRITE SAME transfer length and directionPaolo Bonzini2012-05-041-6/+8
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: prevent data transfer overflowPaolo Bonzini2012-05-041-12/+26
| | | | | | | Avoid sending more than 2GB of data, as that can cause overflows in int32_t variables. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: add SANITIZE commandPaolo Bonzini2012-04-191-0/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: fix memory leakPaolo Bonzini2012-04-191-2/+5
| | | | | | | scsibus_get_dev_path is leaking id if it is not NULL. Fix it. Reported-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: add get_dev_pathPaolo Bonzini2012-03-191-0/+18
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: fix searching for an empty idPaolo Bonzini2012-02-241-5/+10
| | | | | | | | | | | | | | | | | The conditions for detecting no free target or LUN were wrong. The LUN loop was followed by an "if" condition that is never true, because the loop is exited as soon as lun becomes equal to bus->info->max_lun, and never becomes greater than it. The target loop had a wrong condition (<= instead of <). Once this is fixed, the loop would fail in the same way as the LUN loop. The fix is to see whether scsi_device_find returned the device with the last (channel, target, LUN) pair, and fail if so. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: fix wrong return for target INQUIRYPaolo Bonzini2012-02-241-1/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: add SCSIDevice vmstate definitionsPaolo Bonzini2012-02-221-3/+104
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi-disk: enable scatter/gather functionalityPaolo Bonzini2012-02-221-0/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: add scatter/gather functionalityPaolo Bonzini2012-02-221-2/+26
| | | | | | | | | Scatter/gather functionality uses the newly added DMA helpers. The device can choose between doing DMA itself, or calling scsi_req_data as usual, which will use the newly added DMA helpers to copy piecewise to/from the destination area(s). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* scsi: pass residual amount to command_completePaolo Bonzini2012-02-221-4/+8
| | | | | | | | With the upcoming sglist support, HBAs will not see any transfer_data call and will not have a way to detect short transfers. So pass the residual amount of data upon command completion. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qom: Unify type registrationAndreas Färber2012-02-151-2/+2
| | | | | | | | | | | | | 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>
* qdev: kill off DeviceInfoAnthony Liguori2012-02-031-1/+1
| | | | | | | It is no longer used in the tree since everything is done natively through QEMU Object Model. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qdev: register all types natively through QEMU Object ModelAnthony Liguori2012-02-031-9/+10
| | | | | | | | | | | | | | | | | | | | | 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>
OpenPOWER on IntegriCloud