From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAL8R-0000E4-Af for qemu-devel@nongnu.org; Tue, 17 Nov 2009 05:18:07 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAL8J-00008Z-Cy for qemu-devel@nongnu.org; Tue, 17 Nov 2009 05:18:04 -0500 Received: from [199.232.76.173] (port=58239 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAL8J-00008K-45 for qemu-devel@nongnu.org; Tue, 17 Nov 2009 05:17:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13149) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NAL8I-0006tr-Lv for qemu-devel@nongnu.org; Tue, 17 Nov 2009 05:17:58 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAHAHvE0019567 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Nov 2009 05:17:57 -0500 From: Gerd Hoffmann Date: Tue, 17 Nov 2009 11:17:40 +0100 Message-Id: <1258453071-3496-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1258453071-3496-1-git-send-email-kraxel@redhat.com> References: <1258453071-3496-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 04/15] scsi: add scsi_req_init() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Helper function to init SCSIRequest, so scsi-disk and scsi-generic don't duplicate init code for the common bits. Signed-off-by: Gerd Hoffmann --- hw/scsi-bus.c | 9 +++++++++ hw/scsi-disk.c | 9 +++------ hw/scsi-generic.c | 9 +++------ hw/scsi.h | 3 +++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 801922b..c74d085 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -111,3 +111,12 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus) scsi_bus_legacy_add_drive(bus, dinfo, unit); } } + +void scsi_req_init(SCSIRequest *req, SCSIDevice *d, uint32_t tag, uint32_t lun) +{ + req->bus = scsi_bus_from_device(d); + req->dev = d; + req->tag = tag; + req->lun = lun; + req->aiocb = NULL; +} diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2b13635..bb2d68c 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -74,7 +74,7 @@ struct SCSIDiskState /* Global pool of SCSIRequest structures. */ static QTAILQ_HEAD(, SCSIRequest) free_requests = QTAILQ_HEAD_INITIALIZER(free_requests); -static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag) +static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun) { SCSIDiskReq *r; @@ -85,12 +85,9 @@ static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag) r = qemu_malloc(sizeof(SCSIDiskReq)); r->iov.iov_base = qemu_memalign(512, SCSI_DMA_BUF_SIZE); } - r->req.bus = scsi_bus_from_device(d); - r->req.dev = d; - r->req.tag = tag; + scsi_req_init(&r->req, d, tag, lun); r->sector_count = 0; r->iov.iov_len = 0; - r->req.aiocb = NULL; r->status = 0; QTAILQ_INSERT_TAIL(&d->requests, &r->req, next); @@ -360,7 +357,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, } /* ??? Tags are not unique for different luns. We only implement a single lun, so this should not matter. */ - r = scsi_new_request(d, tag); + r = scsi_new_request(d, tag, lun); outbuf = (uint8_t *)r->iov.iov_base; is_write = 0; DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", lun, tag, buf[0]); diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c index 5ca6840..1e1907e 100644 --- a/hw/scsi-generic.c +++ b/hw/scsi-generic.c @@ -79,7 +79,7 @@ struct SCSIGenericState /* Global pool of SCSIGenericReq structures. */ static QTAILQ_HEAD(, SCSIRequest) free_requests = QTAILQ_HEAD_INITIALIZER(free_requests); -static SCSIGenericReq *scsi_new_request(SCSIDevice *d, uint32_t tag) +static SCSIGenericReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun) { SCSIGenericReq *r; @@ -91,14 +91,11 @@ static SCSIGenericReq *scsi_new_request(SCSIDevice *d, uint32_t tag) r->buf = NULL; r->buflen = 0; } - r->req.bus = scsi_bus_from_device(d); - r->req.dev = d; - r->req.tag = tag; + scsi_req_init(&r->req, d, tag, lun); memset(r->cmd, 0, sizeof(r->cmd)); memset(&r->io_header, 0, sizeof(r->io_header)); r->cmdlen = 0; r->len = 0; - r->req.aiocb = NULL; QTAILQ_INSERT_TAIL(&d->requests, &r->req, next); return r; @@ -534,7 +531,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, BADF("Tag 0x%x already in use %p\n", tag, r); scsi_cancel_io(d, tag); } - r = scsi_new_request(d, tag); + r = scsi_new_request(d, tag, lun); memcpy(r->cmd, cmd, cmdlen); r->cmdlen = cmdlen; diff --git a/hw/scsi.h b/hw/scsi.h index a9b846c..85ce8a9 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -20,6 +20,7 @@ typedef struct SCSIRequest { SCSIBus *bus; SCSIDevice *dev; uint32_t tag; + uint32_t lun; BlockDriverAIOCB *aiocb; QTAILQ_ENTRY(SCSIRequest) next; } SCSIRequest; @@ -74,4 +75,6 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit); void scsi_bus_legacy_handle_cmdline(SCSIBus *bus); +void scsi_req_init(SCSIRequest *req, SCSIDevice *d, uint32_t tag, uint32_t lun); + #endif -- 1.6.2.5