All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, kwolf@redhat.com,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v7 06/19] scsi-disk: Switch to byte-based aio block access
Date: Fri,  6 May 2016 10:26:32 -0600	[thread overview]
Message-ID: <1462552005-4887-7-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1462552005-4887-1-git-send-email-eblake@redhat.com>

Sector-based blk_aio_readv() and blk_aio_writev() should die; switch
to byte-based blk_aio_preadv() and blk_aio_pwritev() instead.

As part of the cleanup, scsi_init_iovec() no longer needs to return
a value, and reword a comment.

Signed-off-by: Eric Blake <eblake@redhat.com>

---
v7: remove more unused 'n', fix comment wording
---
 hw/scsi/scsi-disk.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 1335392..d6bb9ad 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -108,7 +108,7 @@ static void scsi_check_condition(SCSIDiskReq *r, SCSISense sense)
     scsi_req_complete(&r->req, CHECK_CONDITION);
 }

-static uint32_t scsi_init_iovec(SCSIDiskReq *r, size_t size)
+static void scsi_init_iovec(SCSIDiskReq *r, size_t size)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);

@@ -118,7 +118,6 @@ static uint32_t scsi_init_iovec(SCSIDiskReq *r, size_t size)
     }
     r->iov.iov_len = MIN(r->sector_count * 512, r->buflen);
     qemu_iovec_init_external(&r->qiov, &r->iov, 1);
-    return r->qiov.size / 512;
 }

 static void scsi_disk_save_request(QEMUFile *f, SCSIRequest *req)
@@ -316,7 +315,6 @@ done:
 static void scsi_do_read(SCSIDiskReq *r, int ret)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
-    uint32_t n;

     assert (r->req.aiocb == NULL);

@@ -340,11 +338,12 @@ static void scsi_do_read(SCSIDiskReq *r, int ret)
         r->req.aiocb = dma_blk_read(s->qdev.conf.blk, r->req.sg, r->sector,
                                     scsi_dma_complete, r);
     } else {
-        n = scsi_init_iovec(r, SCSI_DMA_BUF_SIZE);
+        scsi_init_iovec(r, SCSI_DMA_BUF_SIZE);
         block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
-                         n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
-        r->req.aiocb = blk_aio_readv(s->qdev.conf.blk, r->sector, &r->qiov, n,
-                                     scsi_read_complete, r);
+                         SCSI_DMA_BUF_SIZE, BLOCK_ACCT_READ);
+        r->req.aiocb = blk_aio_preadv(s->qdev.conf.blk,
+                                      r->sector << BDRV_SECTOR_BITS, &r->qiov,
+                                      0, scsi_read_complete, r);
     }

 done:
@@ -504,7 +503,6 @@ static void scsi_write_data(SCSIRequest *req)
 {
     SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req);
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
-    uint32_t n;

     /* No data transfer may already be in progress */
     assert(r->req.aiocb == NULL);
@@ -544,11 +542,11 @@ static void scsi_write_data(SCSIRequest *req)
         r->req.aiocb = dma_blk_write(s->qdev.conf.blk, r->req.sg, r->sector,
                                      scsi_dma_complete, r);
     } else {
-        n = r->qiov.size / 512;
         block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
-                         n * BDRV_SECTOR_SIZE, BLOCK_ACCT_WRITE);
-        r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, r->sector, &r->qiov, n,
-                                      scsi_write_complete, r);
+                         r->qiov.size, BLOCK_ACCT_WRITE);
+        r->req.aiocb = blk_aio_pwritev(s->qdev.conf.blk,
+                                       r->sector << BDRV_SECTOR_BITS, &r->qiov,
+                                       0, scsi_write_complete, r);
     }
 }

@@ -1730,13 +1728,13 @@ static void scsi_write_same_complete(void *opaque, int ret)
     if (data->iov.iov_len) {
         block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
                          data->iov.iov_len, BLOCK_ACCT_WRITE);
-        /* blk_aio_write doesn't like the qiov size being different from
-         * nb_sectors, make sure they match.
-         */
+        /* Reinitialize qiov, to handle unaligned WRITE SAME request
+         * where final qiov may need smaller size */
         qemu_iovec_init_external(&data->qiov, &data->iov, 1);
-        r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, data->sector,
-                                      &data->qiov, data->iov.iov_len / 512,
-                                      scsi_write_same_complete, data);
+        r->req.aiocb = blk_aio_pwritev(s->qdev.conf.blk,
+                                       data->sector << BDRV_SECTOR_BITS,
+                                       &data->qiov, 0,
+                                       scsi_write_same_complete, data);
         return;
     }

@@ -1803,9 +1801,10 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
     scsi_req_ref(&r->req);
     block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
                      data->iov.iov_len, BLOCK_ACCT_WRITE);
-    r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, data->sector,
-                                  &data->qiov, data->iov.iov_len / 512,
-                                  scsi_write_same_complete, data);
+    r->req.aiocb = blk_aio_pwritev(s->qdev.conf.blk,
+                                   data->sector << BDRV_SECTOR_BITS,
+                                   &data->qiov, 0,
+                                   scsi_write_same_complete, data);
 }

 static void scsi_disk_emulate_write_data(SCSIRequest *req)
-- 
2.5.5

  parent reply	other threads:[~2016-05-06 16:27 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 16:26 [Qemu-devel] [PATCH v7 00/19] block: kill sector-based blk_write/read Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 01/19] block: Allow BDRV_REQ_FUA through blk_pwrite() Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 02/19] block: Switch blk_read_unthrottled() to byte interface Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 03/19] block: Switch blk_*write_zeroes() " Eric Blake
2016-05-23 15:42   ` Kevin Wolf
2016-05-23 16:03     ` Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 04/19] block: Introduce byte-based aio read/write Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 05/19] ide: Switch to byte-based aio block access Eric Blake
2016-05-06 16:26 ` Eric Blake [this message]
2016-05-10  8:55   ` [Qemu-devel] [PATCH v7 06/19] scsi-disk: " Kevin Wolf
2016-05-10 12:56     ` Eric Blake
2016-05-10 14:49       ` Kevin Wolf
2016-05-12 11:25   ` Paolo Bonzini
2016-05-12 11:26     ` Paolo Bonzini
2016-05-12 16:58     ` Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 07/19] virtio: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 08/19] xen_disk: " Eric Blake
2016-05-06 16:26   ` Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 09/19] fdc: Switch to byte-based " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 10/19] nand: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 11/19] onenand: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 12/19] pflash: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 13/19] sd: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 14/19] m25p80: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 15/19] atapi: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 16/19] nbd: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 17/19] qemu-img: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 18/19] qemu-io: " Eric Blake
2016-05-06 16:26 ` [Qemu-devel] [PATCH v7 19/19] block: Kill unused sector-based blk_* functions Eric Blake
2016-05-10  8:56 ` [Qemu-devel] [PATCH v7 00/19] block: kill sector-based blk_write/read Kevin Wolf
2016-05-10 15:06 ` Kevin Wolf

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=1462552005-4887-7-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.