qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 04/15] scsi: add scsi_req_init()
Date: Tue, 17 Nov 2009 11:17:40 +0100	[thread overview]
Message-ID: <1258453071-3496-5-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1258453071-3496-1-git-send-email-kraxel@redhat.com>

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 <kraxel@redhat.com>
---
 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

  parent reply	other threads:[~2009-11-17 10:18 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-17 10:17 [Qemu-devel] [PATCH 00/15] scsi: data structures and cleanups Gerd Hoffmann
2009-11-17 10:17 ` [Qemu-devel] [PATCH 01/15] scsi: add/fix header protection Gerd Hoffmann
2009-11-17 11:11   ` Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 02/15] scsi: create common SCSIRequest structure Gerd Hoffmann
2009-11-17 11:12   ` Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 03/15] scsi: move request lists to QTAILQ Gerd Hoffmann
2009-11-17 11:15   ` Christoph Hellwig
2009-11-17 11:59   ` Paul Brook
2009-11-17 12:39     ` Gerd Hoffmann
2009-11-18  9:44       ` Gerd Hoffmann
2009-11-17 10:17 ` Gerd Hoffmann [this message]
2009-11-17 11:16   ` [Qemu-devel] [PATCH 04/15] scsi: add scsi_req_init() Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 05/15] scsi: move scsi command from SCSIGenericReq to SCSIRequest Gerd Hoffmann
2009-11-17 11:17   ` Christoph Hellwig
2009-11-17 11:55   ` Paul Brook
2009-11-17 12:45     ` Gerd Hoffmann
2009-11-17 10:17 ` [Qemu-devel] [PATCH 06/15] scsi: move blocksize from SCSIGenericState to SCSIDevice Gerd Hoffmann
2009-11-17 11:34   ` Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 07/15] scsi: add scsi-defs.h Gerd Hoffmann
2009-11-17 11:35   ` Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 08/15] scsi: move type from SCSIGenericState to SCSIDevice Gerd Hoffmann
2009-11-17 11:36   ` Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 09/15] scsi: move scsi request parsing into generic code Gerd Hoffmann
2009-11-17 11:50   ` Christoph Hellwig
2009-11-17 12:27     ` Paul Brook
2009-11-17 12:51       ` Gerd Hoffmann
2009-11-17 13:43         ` Paul Brook
2009-11-17 10:17 ` [Qemu-devel] [PATCH 10/15] scsi: use command defines in scsi-disk.c Gerd Hoffmann
2009-11-17 11:51   ` Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 11/15] scsi: add xfer mode Gerd Hoffmann
2009-11-17 11:53   ` Christoph Hellwig
2009-11-17 11:58   ` Paul Brook
2009-11-17 10:17 ` [Qemu-devel] [PATCH 12/15] scsi: move sense to SCSIDevice, create SCSISense struct Gerd Hoffmann
2009-11-17 11:54   ` Christoph Hellwig
2009-11-17 12:54     ` Gerd Hoffmann
2009-11-17 10:17 ` [Qemu-devel] [PATCH 13/15] scsi: move dinfo to SCSIDevice Gerd Hoffmann
2009-11-17 12:00   ` Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 14/15] scsi: move status to SCSIRequest Gerd Hoffmann
2009-11-17 12:01   ` Christoph Hellwig
2009-11-17 10:17 ` [Qemu-devel] [PATCH 15/15] scsi: add scsi_req_print() Gerd Hoffmann
2009-11-17 12:02   ` Christoph Hellwig
2009-11-17 12:56     ` Gerd Hoffmann
2009-11-17 13:19 ` [Qemu-devel] Re: [PATCH 00/15] scsi: data structures and cleanups Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1258453071-3496-5-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).