aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio-blk.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2011-11-02 13:19:40 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2011-11-02 07:51:58 -0500
commit5bb23927761db0d48507c60f56c4e28f72f3c2a7 (patch)
tree7947de44ec08258f44c8db4c0553b5946cfde134 /hw/virtio-blk.c
parente072ea2fd8fdceef64159b9596d3c15ce01bea91 (diff)
virtio-blk: pass full status to the guest
When SCSI passthrough is being used by the guest with virtio-blk, the guest is not able to detect disk failures. This is because the status field is expected by the guest driver to include also the msg_status, host_status and driver_status fields, but the device is only passing down the SCSI status. The patch fixes this, and also makes sure that the guest always sees a CHECK_CONDITION status when there is valid sense data. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio-blk.c')
-rw-r--r--hw/virtio-blk.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 2a5d1a92b3..19e89e71ee 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -16,6 +16,7 @@
#include "trace.h"
#include "blockdev.h"
#include "virtio-blk.h"
+#include "scsi-defs.h"
#ifdef __linux__
# include <scsi/sg.h>
#endif
@@ -231,7 +232,20 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
status = VIRTIO_BLK_S_OK;
}
- stl_p(&req->scsi->errors, hdr.status);
+ /*
+ * From SCSI-Generic-HOWTO: "Some lower level drivers (e.g. ide-scsi)
+ * clear the masked_status field [hence status gets cleared too, see
+ * block/scsi_ioctl.c] even when a CHECK_CONDITION or COMMAND_TERMINATED
+ * status has occurred. However they do set DRIVER_SENSE in driver_status
+ * field. Also a (sb_len_wr > 0) indicates there is a sense buffer.
+ */
+ if (hdr.status == 0 && hdr.sb_len_wr > 0) {
+ hdr.status = CHECK_CONDITION;
+ }
+
+ stl_p(&req->scsi->errors,
+ hdr.status | (hdr.msg_status << 8) |
+ (hdr.host_status << 16) | (hdr.driver_status << 24));
stl_p(&req->scsi->residual, hdr.resid);
stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
stl_p(&req->scsi->data_len, hdr.dxfer_len);