qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/3] Add internal scsi generic block API
Date: Thu, 12 Mar 2009 14:57:10 +0200	[thread overview]
Message-ID: <1236862631-22918-3-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1236862631-22918-1-git-send-email-avi@redhat.com>

Add an internal API for the generic block layer to send scsi generic commands
to block format driver.  This means block format drivers no longer need
to consider overloaded nb_sectors parameters.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 block-raw-posix.c |   30 ++++++++++++++++++++++++++++++
 block.c           |    8 ++++----
 block_int.h       |   10 ++++++++++
 3 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/block-raw-posix.c b/block-raw-posix.c
index 8b28a43..a2ac48a 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -1179,6 +1179,32 @@ static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
 }
 #endif /* !linux */
 
+static int raw_sg_send_command(BlockDriverState *bs, void *buf, int count)
+{
+    return raw_pwrite(bs, -1, buf, count);
+}
+
+static int raw_sg_recv_response(BlockDriverState *bs, void *buf, int count)
+{
+    return raw_pread(bs, -1, buf, count);
+}
+
+static BlockDriverAIOCB *raw_sg_aio_read(BlockDriverState *bs,
+                                         void *buf, int count,
+                                         BlockDriverCompletionFunc *cb,
+                                         void *opaque)
+{
+    return raw_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque);
+}
+
+static BlockDriverAIOCB *raw_sg_aio_write(BlockDriverState *bs,
+                                          void *buf, int count,
+                                          BlockDriverCompletionFunc *cb,
+                                          void *opaque)
+{
+    return raw_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque);
+}
+
 BlockDriver bdrv_host_device = {
     .format_name	= "host_device",
     .instance_size	= sizeof(BDRVRawState),
@@ -1204,4 +1230,8 @@ BlockDriver bdrv_host_device = {
     .bdrv_set_locked	= raw_set_locked,
     /* generic scsi device */
     .bdrv_ioctl		= raw_ioctl,
+    .bdrv_sg_send_command  = raw_sg_send_command,
+    .bdrv_sg_recv_response = raw_sg_recv_response,
+    .bdrv_sg_aio_read      = raw_sg_aio_read,
+    .bdrv_sg_aio_write     = raw_sg_aio_write,
 };
diff --git a/block.c b/block.c
index 39b27b2..e2a75b0 100644
--- a/block.c
+++ b/block.c
@@ -1678,22 +1678,22 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
 
 int bdrv_sg_send_command(BlockDriverState *bs, void *buf, int count)
 {
-    return bdrv_pwrite(bs, -1, buf, count);
+    return bs->drv->bdrv_sg_send_command(bs, buf, count);
 }
 
 int bdrv_sg_recv_response(BlockDriverState *bs, void *buf, int count)
 {
-    return bdrv_pread(bs, -1, buf, count);
+    return bs->drv->bdrv_sg_recv_response(bs, buf, count);
 }
 
 BlockDriverAIOCB *bdrv_sg_aio_read(BlockDriverState *bs, void *buf, int count,
                                    BlockDriverCompletionFunc *cb, void *opaque)
 {
-    return bdrv_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque);
+    return bs->drv->bdrv_sg_aio_read(bs, buf, count, cb, opaque);
 }
 
 BlockDriverAIOCB *bdrv_sg_aio_write(BlockDriverState *bs, void *buf, int count,
                                     BlockDriverCompletionFunc *cb, void *opaque)
 {
-    return bdrv_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque);
+    return bs->drv->bdrv_sg_aio_write(bs, buf, count, cb, opaque);
 }
diff --git a/block_int.h b/block_int.h
index 44eb280..e274293 100644
--- a/block_int.h
+++ b/block_int.h
@@ -84,6 +84,16 @@ struct BlockDriver {
 
     /* to control generic scsi devices */
     int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
+    int (*bdrv_sg_send_command)(BlockDriverState *bs, void *buf, int count);
+    int (*bdrv_sg_recv_response)(BlockDriverState *bs, void *buf, int count);
+    BlockDriverAIOCB *(*bdrv_sg_aio_read)(BlockDriverState *bs,
+                                          void *buf, int count,
+                                          BlockDriverCompletionFunc *cb,
+                                          void *opaque);
+    BlockDriverAIOCB *(*bdrv_sg_aio_write)(BlockDriverState *bs,
+                                           void *buf, int count,
+                                           BlockDriverCompletionFunc *cb,
+                                           void *opaque);
 
     BlockDriverAIOCB *free_aiocb;
     struct BlockDriver *next;
-- 
1.6.0.6

  parent reply	other threads:[~2009-03-12 12:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-12 12:57 [Qemu-devel] [PATCH 0/3] Remove ->bdrv_pread() internal block layer API (v2) Avi Kivity
2009-03-12 12:57 ` [Qemu-devel] [PATCH 1/3] Add specialized block driver scsi generic API Avi Kivity
2009-03-14 14:33   ` Christoph Hellwig
2009-03-15 13:54     ` Avi Kivity
2009-03-15 14:43       ` Christoph Hellwig
2009-03-15 14:57         ` Avi Kivity
2009-03-15 15:06           ` Christoph Hellwig
2009-03-16 17:29           ` Jamie Lokier
2009-03-12 12:57 ` Avi Kivity [this message]
2009-03-12 12:57 ` [Qemu-devel] [PATCH 3/3] Drop internal bdrv_pread()/bdrv_pwrite() APIs Avi Kivity
2009-03-12 19:57 ` [Qemu-devel] Re: [PATCH 0/3] Remove ->bdrv_pread() internal block layer API (v2) Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2009-02-08 17:59 [Qemu-devel] [PATCH 0/3] Remove ->bdrv_pread() internal block layer API Avi Kivity
2009-02-08 17:59 ` [Qemu-devel] [PATCH 2/3] Add internal scsi generic block API Avi Kivity

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=1236862631-22918-3-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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).