#include "hw/block/block.h"
#include "sysemu/dma.h"
#include "qemu/cutils.h"
+#include "scsi/scsi.h"
#ifdef __linux
#include <scsi/sg.h>
bool tray_locked;
} SCSIDiskState;
-static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed);
+static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed);
static void scsi_free_request(SCSIRequest *req)
{
return true;
}
- if (ret < 0) {
+ if (ret < 0 || (r->status && *r->status)) {
return scsi_handle_rw_error(r, -ret, acct_failed);
}
- if (r->status && *r->status) {
- if (acct_failed) {
- SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
- block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct);
- }
- scsi_req_complete(&r->req, *r->status);
- return true;
- }
-
return false;
}
}
/*
- * scsi_handle_rw_error has two return values. 0 means that the error
- * must be ignored, 1 means that the error has been processed and the
+ * scsi_handle_rw_error has two return values. False means that the error
+ * must be ignored, true means that the error has been processed and the
* caller should not do anything else for this request. Note that
* scsi_handle_rw_error always manages its reference counts, independent
* of the return value.
*/
-static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)
+static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)
{
bool is_read = (r->req.cmd.mode == SCSI_XFER_FROM_DEV);
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct);
}
switch (error) {
+ case 0:
+ /* The command has run, no need to fake sense. */
+ assert(r->status && *r->status);
+ scsi_req_complete(&r->req, *r->status);
+ break;
case ENOMEDIUM:
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
break;
break;
}
}
+ if (!error) {
+ assert(r->status && *r->status);
+ error = scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.sense));
+
+ if (error == ECANCELED || error == EAGAIN || error == ENOTCONN ||
+ error == 0) {
+ /* These errors are handled by guest. */
+ scsi_req_complete(&r->req, *r->status);
+ return true;
+ }
+ }
+
blk_error_action(s->qdev.conf.blk, action, is_read, error);
if (action == BLOCK_ERROR_ACTION_STOP) {
scsi_req_retry(&r->req);
#ifdef __linux__
static Property scsi_block_properties[] = {
+ DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \
DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.blk),
DEFINE_PROP_END_OF_LIST(),
};