From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm0HY-0000Jd-HX for qemu-devel@nongnu.org; Tue, 13 Oct 2015 10:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zm0HU-0003nw-Fj for qemu-devel@nongnu.org; Tue, 13 Oct 2015 10:10:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm0HU-0003nq-B1 for qemu-devel@nongnu.org; Tue, 13 Oct 2015 10:10:20 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id C7A938E690 for ; Tue, 13 Oct 2015 14:10:19 +0000 (UTC) From: Stefan Hajnoczi Date: Tue, 13 Oct 2015 15:10:15 +0100 Message-Id: <1444745415-21718-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [RFC] scsi-disk: add -device scsi-disk, slow=on property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Fam Zheng , Stefan Hajnoczi The 'slow' bool property simulates an 8 second delay in responding to simple SCSI commands that do not transfer data. This means non-READ/WRITE commands will take 8 seconds to complete so slow SCSI LUNs can be simulated. Signed-off-by: Stefan Hajnoczi --- This is a quick hack and probably buggy too. Not worth merging, but I wanted to archive it on the mailing list in case someone wants to use it for debugging in the future. hw/scsi/scsi-disk.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index bada9a7..3aaa215 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -88,6 +88,9 @@ struct SCSIDiskState char *product; bool tray_open; bool tray_locked; + bool is_slow; + QEMUTimer *slow_timer; + SCSIDiskReq *slow_req; }; static int scsi_handle_rw_error(SCSIDiskReq *r, int error); @@ -1833,6 +1836,17 @@ static void scsi_disk_emulate_write_data(SCSIRequest *req) } } +static void scsi_disk_slow_timer_cb(void *opaque) +{ + SCSIDiskState *s = opaque; + SCSIDiskReq *r = s->slow_req; + + s->slow_req = NULL; + + fprintf(stderr, "%s called\n", __func__); + scsi_req_complete(&r->req, GOOD); +} + static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) { SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req); @@ -2092,7 +2106,15 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) assert(!r->req.aiocb); r->iov.iov_len = MIN(r->buflen, req->cmd.xfer); if (r->iov.iov_len == 0) { - scsi_req_complete(&r->req, GOOD); + if (s->is_slow) { + fprintf(stderr, "delaying scsi_req_complete...\n"); + assert(!s->slow_req); + s->slow_req = r; + timer_mod(s->slow_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + 8 * 1000ULL * 1000ULL * 1000ULL); + } else { + scsi_req_complete(&r->req, GOOD); + } } if (r->req.cmd.mode == SCSI_XFER_TO_DEV) { assert(r->iov.iov_len == req->cmd.xfer); @@ -2335,6 +2357,9 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) blk_set_guest_block_size(s->qdev.conf.blk, s->qdev.blocksize); blk_iostatus_enable(s->qdev.conf.blk); + + s->slow_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, + scsi_disk_slow_timer_cb, s); } static void scsi_hd_realize(SCSIDevice *dev, Error **errp) @@ -2773,6 +2798,7 @@ static Property scsi_disk_properties[] = { DEFAULT_MAX_UNMAP_SIZE), DEFINE_PROP_UINT64("max_io_size", SCSIDiskState, max_io_size, DEFAULT_MAX_IO_SIZE), + DEFINE_PROP_BOOL("slow", SCSIDiskState, is_slow, false), DEFINE_PROP_END_OF_LIST(), }; -- 2.4.3