diff mbox

[08/17] block: Convert .bdrv_aio_discard() to byte-based

Message ID 1466610674-23157-9-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake June 22, 2016, 3:51 p.m. UTC
Another step towards byte-based interfaces everywhere.  Replace
the sector-based driver callback .bdrv_aio_discard() with a new
byte-based .bdrv_aio_pdiscard().  Only raw-posix and RBD drivers
are affected, so it was not worth splitting into multiple patches.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 include/block/block_int.h |  4 ++--
 block/io.c                |  7 +++----
 block/raw-posix.c         | 18 ++++++++----------
 block/rbd.c               | 15 +++++++--------
 4 files changed, 20 insertions(+), 24 deletions(-)

Comments

Stefan Hajnoczi July 14, 2016, 12:16 p.m. UTC | #1
On Wed, Jun 22, 2016 at 09:51:05AM -0600, Eric Blake wrote:
> Another step towards byte-based interfaces everywhere.  Replace
> the sector-based driver callback .bdrv_aio_discard() with a new
> byte-based .bdrv_aio_pdiscard().  Only raw-posix and RBD drivers
> are affected, so it was not worth splitting into multiple patches.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  include/block/block_int.h |  4 ++--
>  block/io.c                |  7 +++----
>  block/raw-posix.c         | 18 ++++++++----------
>  block/rbd.c               | 15 +++++++--------
>  4 files changed, 20 insertions(+), 24 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox

Patch

diff --git a/include/block/block_int.h b/include/block/block_int.h
index 70931ff..880a6d8 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -142,8 +142,8 @@  struct BlockDriver {
         BlockCompletionFunc *cb, void *opaque);
     BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
         BlockCompletionFunc *cb, void *opaque);
-    BlockAIOCB *(*bdrv_aio_discard)(BlockDriverState *bs,
-        int64_t sector_num, int nb_sectors,
+    BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs,
+        int64_t offset, int count,
         BlockCompletionFunc *cb, void *opaque);

     int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs,
diff --git a/block/io.c b/block/io.c
index 5409679..d8dc014 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2394,7 +2394,7 @@  int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
         return 0;
     }

-    if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_discard) {
+    if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_pdiscard) {
         return 0;
     }

@@ -2435,9 +2435,8 @@  int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
                 .coroutine = qemu_coroutine_self(),
             };

-            acb = bs->drv->bdrv_aio_discard(bs, offset >> BDRV_SECTOR_BITS,
-                                            num >> BDRV_SECTOR_BITS,
-                                            bdrv_co_io_em_complete, &co);
+            acb = bs->drv->bdrv_aio_pdiscard(bs, offset, num,
+                                             bdrv_co_io_em_complete, &co);
             if (acb == NULL) {
                 ret = -EIO;
                 goto out;
diff --git a/block/raw-posix.c b/block/raw-posix.c
index c077811..d4a653d 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1874,14 +1874,13 @@  static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
     return ret | BDRV_BLOCK_OFFSET_VALID | start;
 }

-static coroutine_fn BlockAIOCB *raw_aio_discard(BlockDriverState *bs,
-    int64_t sector_num, int nb_sectors,
+static coroutine_fn BlockAIOCB *raw_aio_pdiscard(BlockDriverState *bs,
+    int64_t offset, int count,
     BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;

-    return paio_submit(bs, s->fd, sector_num << BDRV_SECTOR_BITS, NULL,
-                       nb_sectors << BDRV_SECTOR_BITS,
+    return paio_submit(bs, s->fd, offset, NULL, count,
                        cb, opaque, QEMU_AIO_DISCARD);
 }

@@ -1953,7 +1952,7 @@  BlockDriver bdrv_file = {
     .bdrv_co_preadv         = raw_co_preadv,
     .bdrv_co_pwritev        = raw_co_pwritev,
     .bdrv_aio_flush = raw_aio_flush,
-    .bdrv_aio_discard = raw_aio_discard,
+    .bdrv_aio_pdiscard = raw_aio_pdiscard,
     .bdrv_refresh_limits = raw_refresh_limits,
     .bdrv_io_plug = raw_aio_plug,
     .bdrv_io_unplug = raw_aio_unplug,
@@ -2295,8 +2294,8 @@  static int fd_open(BlockDriverState *bs)
     return -EIO;
 }

-static coroutine_fn BlockAIOCB *hdev_aio_discard(BlockDriverState *bs,
-    int64_t sector_num, int nb_sectors,
+static coroutine_fn BlockAIOCB *hdev_aio_pdiscard(BlockDriverState *bs,
+    int64_t offset, int count,
     BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;
@@ -2304,8 +2303,7 @@  static coroutine_fn BlockAIOCB *hdev_aio_discard(BlockDriverState *bs,
     if (fd_open(bs) < 0) {
         return NULL;
     }
-    return paio_submit(bs, s->fd, sector_num << BDRV_SECTOR_BITS, NULL,
-                       nb_sectors << BDRV_SECTOR_BITS,
+    return paio_submit(bs, s->fd, offset, NULL, count,
                        cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
 }

@@ -2400,7 +2398,7 @@  static BlockDriver bdrv_host_device = {
     .bdrv_co_preadv         = raw_co_preadv,
     .bdrv_co_pwritev        = raw_co_pwritev,
     .bdrv_aio_flush	= raw_aio_flush,
-    .bdrv_aio_discard   = hdev_aio_discard,
+    .bdrv_aio_pdiscard   = hdev_aio_pdiscard,
     .bdrv_refresh_limits = raw_refresh_limits,
     .bdrv_io_plug = raw_aio_plug,
     .bdrv_io_unplug = raw_aio_unplug,
diff --git a/block/rbd.c b/block/rbd.c
index 01cbb63..0106fea 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -930,14 +930,13 @@  static int qemu_rbd_snap_list(BlockDriverState *bs,
 }

 #ifdef LIBRBD_SUPPORTS_DISCARD
-static BlockAIOCB* qemu_rbd_aio_discard(BlockDriverState *bs,
-                                        int64_t sector_num,
-                                        int nb_sectors,
-                                        BlockCompletionFunc *cb,
-                                        void *opaque)
+static BlockAIOCB *qemu_rbd_aio_pdiscard(BlockDriverState *bs,
+                                         int64_t offset,
+                                         int count,
+                                         BlockCompletionFunc *cb,
+                                         void *opaque)
 {
-    return rbd_start_aio(bs, sector_num << BDRV_SECTOR_BITS, NULL,
-                         nb_sectors << BDRV_SECTOR_BITS, cb, opaque,
+    return rbd_start_aio(bs, offset, NULL, count, cb, opaque,
                          RBD_AIO_DISCARD);
 }
 #endif
@@ -1001,7 +1000,7 @@  static BlockDriver bdrv_rbd = {
 #endif

 #ifdef LIBRBD_SUPPORTS_DISCARD
-    .bdrv_aio_discard       = qemu_rbd_aio_discard,
+    .bdrv_aio_pdiscard      = qemu_rbd_aio_pdiscard,
 #endif

     .bdrv_snapshot_create   = qemu_rbd_snap_create,