qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Eric Blake <eblake@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL v2 08/25] block: Convert bdrv_discard() to byte-based
Date: Wed, 20 Jul 2016 17:21:05 +0100	[thread overview]
Message-ID: <1469031682-21863-9-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1469031682-21863-1-git-send-email-stefanha@redhat.com>

From: Eric Blake <eblake@redhat.com>

Another step towards byte-based interfaces everywhere.  Replace
the sector-based bdrv_discard() with a new byte-based
bdrv_pdiscard(), which silently ignores any unaligned head
or tail.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1468624988-423-3-git-send-email-eblake@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/block-backend.c  |  3 ++-
 block/io.c             | 19 +++++++++----------
 block/qcow2-refcount.c |  4 +---
 include/block/block.h  |  2 +-
 4 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index d982cf9..83b6407 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1512,7 +1512,8 @@ int blk_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors)
         return ret;
     }
 
-    return bdrv_discard(blk_bs(blk), sector_num, nb_sectors);
+    return bdrv_pdiscard(blk_bs(blk), sector_num << BDRV_SECTOR_BITS,
+                         nb_sectors << BDRV_SECTOR_BITS);
 }
 
 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
diff --git a/block/io.c b/block/io.c
index 14d448d..8d41305 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2391,16 +2391,15 @@ int bdrv_flush(BlockDriverState *bs)
 
 typedef struct DiscardCo {
     BlockDriverState *bs;
-    int64_t sector_num;
-    int nb_sectors;
+    int64_t offset;
+    int count;
     int ret;
 } DiscardCo;
-static void coroutine_fn bdrv_discard_co_entry(void *opaque)
+static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque)
 {
     DiscardCo *rwco = opaque;
 
-    rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->sector_num << BDRV_SECTOR_BITS,
-                                 rwco->nb_sectors << BDRV_SECTOR_BITS);
+    rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->count);
 }
 
 int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
@@ -2495,23 +2494,23 @@ out:
     return ret;
 }
 
-int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
+int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count)
 {
     Coroutine *co;
     DiscardCo rwco = {
         .bs = bs,
-        .sector_num = sector_num,
-        .nb_sectors = nb_sectors,
+        .offset = offset,
+        .count = count,
         .ret = NOT_DONE,
     };
 
     if (qemu_in_coroutine()) {
         /* Fast-path if already in coroutine context */
-        bdrv_discard_co_entry(&rwco);
+        bdrv_pdiscard_co_entry(&rwco);
     } else {
         AioContext *aio_context = bdrv_get_aio_context(bs);
 
-        co = qemu_coroutine_create(bdrv_discard_co_entry, &rwco);
+        co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
         qemu_coroutine_enter(co);
         while (rwco.ret == NOT_DONE) {
             aio_poll(aio_context, true);
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 49b6ce6..cbfb3fe 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -615,9 +615,7 @@ void qcow2_process_discards(BlockDriverState *bs, int ret)
 
         /* Discard is optional, ignore the return value */
         if (ret >= 0) {
-            bdrv_discard(bs->file->bs,
-                         d->offset >> BDRV_SECTOR_BITS,
-                         d->bytes >> BDRV_SECTOR_BITS);
+            bdrv_pdiscard(bs->file->bs, d->offset, d->bytes);
         }
 
         g_free(d);
diff --git a/include/block/block.h b/include/block/block.h
index 4f5cebf..94cabbb 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -341,7 +341,7 @@ void bdrv_drain(BlockDriverState *bs);
 void coroutine_fn bdrv_co_drain(BlockDriverState *bs);
 void bdrv_drain_all(void);
 
-int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
+int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count);
 int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int count);
 int bdrv_has_zero_init_1(BlockDriverState *bs);
 int bdrv_has_zero_init(BlockDriverState *bs);
-- 
2.7.4

  parent reply	other threads:[~2016-07-20 16:21 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20 16:20 [Qemu-devel] [PULL v2 00/25] Block patches Stefan Hajnoczi
2016-07-20 16:20 ` [Qemu-devel] [PULL v2 01/25] block: Fragment reads to max transfer length Stefan Hajnoczi
2016-07-20 16:20 ` [Qemu-devel] [PULL v2 02/25] raw_bsd: Don't advertise flags not supported by protocol layer Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 03/25] block: Fragment writes to max transfer length Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 04/25] nbd: Rely on block layer to break up large requests Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 05/25] nbd: Drop unused offset parameter Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 06/25] iscsi: Rely on block layer to break up large requests Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 07/25] block: Convert bdrv_co_discard() to byte-based Stefan Hajnoczi
2016-07-20 16:21 ` Stefan Hajnoczi [this message]
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 09/25] block: Switch BlockRequest " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 10/25] block: Convert bdrv_aio_discard() " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 11/25] block: Convert BB interface to byte-based discards Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 12/25] raw-posix: Switch paio_submit() to byte-based Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 13/25] rbd: Switch rbd_start_aio() " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 14/25] block: Convert .bdrv_aio_discard() " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 15/25] block: Add .bdrv_co_pdiscard() driver callback Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 16/25] blkreplay: Switch .bdrv_co_discard() to byte-based Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 17/25] gluster: " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 18/25] iscsi: " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 19/25] nbd: " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 20/25] qcow2: " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 21/25] raw_bsd: " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 22/25] sheepdog: " Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 23/25] block: Kill .bdrv_co_discard() Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 24/25] nbd: Convert to byte-based interface Stefan Hajnoczi
2016-07-20 16:21 ` [Qemu-devel] [PULL v2 25/25] raw_bsd: " Stefan Hajnoczi
2016-07-20 21:03 ` [Qemu-devel] [PULL v2 00/25] Block patches Peter Maydell
2016-07-21  9:58   ` Stefan Hajnoczi
2016-07-21 10:47     ` Peter Maydell

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=1469031682-21863-9-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=eblake@redhat.com \
    --cc=peter.maydell@linaro.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 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).