From: Alex Pyrgiotis <apyrgio@arrikto.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH 6/9] scsi-generic: Make request execution buf-specific
Date: Wed, 16 Dec 2015 18:55:14 +0200	[thread overview]
Message-ID: <1450284917-10508-7-git-send-email-apyrgio@arrikto.com> (raw)
In-Reply-To: <1450284917-10508-1-git-send-email-apyrgio@arrikto.com>
Move the request execution logic from execute_command() to
scsi_buf_do_request(), since the way the io header is initialized and
the ioctl is performed is used only for requests that use an
intermediate buffer.
For now, the above is the only request type, but we need to pave the way
for the support of requests with scatter-gather lists.
Signed-off-by: Alex Pyrgiotis <apyrgio@arrikto.com>
Signed-off-by: Dimitris Aragiorgis <dimara@arrikto.com>
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 71c0110..8e2058d 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -175,20 +175,6 @@ static void scsi_command_complete(void *opaque, int ret)
     scsi_command_complete_noio(r, ret);
 }
 
-static int execute_command(BlockBackend *blk,
-                           SCSIGenericReq *r, int direction,
-                           BlockCompletionFunc *complete)
-{
-    scsi_buf_init_io_header(r, direction);
-
-    r->req.aiocb = blk_aio_ioctl(blk, SG_IO, &r->io_header, complete, r);
-    if (r->req.aiocb == NULL) {
-        return -EIO;
-    }
-
-    return 0;
-}
-
 static void scsi_buf_read_complete(void *opaque, int ret)
 {
     SCSIGenericReq *r = (SCSIGenericReq *)opaque;
@@ -242,12 +228,33 @@ static void scsi_buf_read_complete(void *opaque, int ret)
     scsi_req_unref(&r->req);
 }
 
+/*
+ * Execute the request using an intermediate buffer.
+ *
+ * This function does the following:
+ *
+ * a. Initialize the io header for the ioctl request.
+ * b. Perform the ioctl request using blk_aio_ioctl().
+ */
+static void scsi_buf_do_request(SCSIGenericReq *r, int direction,
+        BlockCompletionFunc *complete)
+{
+    SCSIDevice *s = r->req.dev;
+
+    scsi_buf_init_io_header(r, direction);
+
+    r->req.aiocb = blk_aio_ioctl(s->conf.blk, SG_IO,
+            &r->io_header, complete, r);
+
+    if (!r->req.aiocb) {
+        scsi_command_complete_noio(r, -EIO);
+    }
+}
+
 /* Read more data from scsi device into buffer.  */
 static void scsi_buf_read_data(SCSIRequest *req)
 {
     SCSIGenericReq *r = DO_UPCAST(SCSIGenericReq, req, req);
-    SCSIDevice *s = r->req.dev;
-    int ret;
 
     DPRINTF("scsi_buf_read_data 0x%x\n", req->tag);
 
@@ -258,11 +265,7 @@ static void scsi_buf_read_data(SCSIRequest *req)
         return;
     }
 
-    ret = execute_command(s->conf.blk, r, SG_DXFER_FROM_DEV,
-                          scsi_buf_read_complete);
-    if (ret < 0) {
-        scsi_command_complete_noio(r, ret);
-    }
+    scsi_buf_do_request(r, SG_DXFER_FROM_DEV, scsi_buf_read_complete);
 }
 
 static void scsi_common_read_data(SCSIRequest *req)
@@ -299,8 +302,6 @@ static void scsi_buf_write_complete(void *opaque, int ret)
 static void scsi_buf_write_data(SCSIRequest *req)
 {
     SCSIGenericReq *r = DO_UPCAST(SCSIGenericReq, req, req);
-    SCSIDevice *s = r->req.dev;
-    int ret;
 
     DPRINTF("scsi_buf_write_data 0x%x\n", req->tag);
     if (r->len == 0) {
@@ -311,11 +312,8 @@ static void scsi_buf_write_data(SCSIRequest *req)
 
     /* The request is used as the AIO opaque value, so add a ref.  */
     scsi_req_ref(&r->req);
-    ret = execute_command(s->conf.blk, r, SG_DXFER_TO_DEV,
-            scsi_buf_write_complete);
-    if (ret < 0) {
-        scsi_command_complete_noio(r, ret);
-    }
+
+    scsi_buf_do_request(r, SG_DXFER_TO_DEV, scsi_buf_write_complete);
 }
 
 static void scsi_common_write_data(SCSIRequest *req)
@@ -339,8 +337,6 @@ static uint8_t *scsi_get_buf(SCSIRequest *req)
 static int32_t scsi_common_send_command(SCSIRequest *req, uint8_t *cmd)
 {
     SCSIGenericReq *r = DO_UPCAST(SCSIGenericReq, req, req);
-    SCSIDevice *s = r->req.dev;
-    int ret;
 
 #ifdef DEBUG_SCSI
     {
@@ -358,12 +354,7 @@ static int32_t scsi_common_send_command(SCSIRequest *req, uint8_t *cmd)
         r->buf = NULL;
         /* The request is used as the AIO opaque value, so add a ref.  */
         scsi_req_ref(&r->req);
-        ret = execute_command(s->conf.blk, r, SG_DXFER_NONE,
-                              scsi_command_complete);
-        if (ret < 0) {
-            scsi_command_complete_noio(r, ret);
-            return 0;
-        }
+        scsi_buf_do_request(r, SG_DXFER_NONE, scsi_command_complete);
         return 0;
     }
 
-- 
2.6.2
next prev parent reply	other threads:[~2015-12-16 16:55 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-16 16:55 [Qemu-devel] [PATCH 0/9] Add full scatter-gather support for SCSI generic devices Alex Pyrgiotis
2015-12-16 16:55 ` [Qemu-devel] [PATCH 1/9] dma-helpers: Expose the sg mapping logic Alex Pyrgiotis
2016-02-11 11:17   ` Paolo Bonzini
2016-02-19 11:50     ` Alex Pyrgiotis
2016-02-22 10:43       ` Paolo Bonzini
2016-02-25 10:10         ` Alex Pyrgiotis
2016-02-25 10:22           ` Paolo Bonzini
2016-02-25 11:19             ` Alex Pyrgiotis
2016-02-25 13:01               ` Paolo Bonzini
2016-02-26  9:20           ` Kevin Wolf
2015-12-16 16:55 ` [Qemu-devel] [PATCH 2/9] dma-helpers: Add support for ioctl operations Alex Pyrgiotis
2015-12-16 16:55 ` [Qemu-devel] [PATCH 3/9] dma-helpers: Do not truncate small qiovs Alex Pyrgiotis
2016-02-11 11:08   ` Paolo Bonzini
2015-12-16 16:55 ` [Qemu-devel] [PATCH 4/9] scsi-generic: Add common functions Alex Pyrgiotis
2015-12-16 16:55 ` [Qemu-devel] [PATCH 5/9] scsi-generic: Separate `sg_io_hdr' initializations Alex Pyrgiotis
2015-12-16 16:55 ` Alex Pyrgiotis [this message]
2015-12-16 16:55 ` [Qemu-devel] [PATCH 7/9] scsi-generic: Make data-copying logic clearer Alex Pyrgiotis
2015-12-16 16:55 ` [Qemu-devel] [PATCH 8/9] scsi-generic: Factor out response interception Alex Pyrgiotis
2015-12-16 16:55 ` [Qemu-devel] [PATCH 9/9] scsi-generic: Allow full scatter-gather support Alex Pyrgiotis
2015-12-16 18:16 ` [Qemu-devel] [PATCH 0/9] Add full scatter-gather support for SCSI generic devices Paolo Bonzini
2015-12-17  8:47   ` Alex Pyrgiotis
2015-12-17 10:31     ` Paolo Bonzini
2015-12-17 13:10       ` Alex Pyrgiotis
2015-12-17 13:13         ` Paolo Bonzini
2015-12-21 10:58           ` Alex Pyrgiotis
2016-01-11 13:30           ` Alex Pyrgiotis
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=1450284917-10508-7-git-send-email-apyrgio@arrikto.com \
    --to=apyrgio@arrikto.com \
    --cc=pbonzini@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).