Blame SOURCES/kvm-block-Increase-BB.in_flight-for-coroutine-and-sync-i.patch

22c213
From 52cc1d1cd2f695c5761d65baec961d14552a79ed Mon Sep 17 00:00:00 2001
22c213
From: Kevin Wolf <kwolf@redhat.com>
22c213
Date: Wed, 8 Apr 2020 17:29:16 +0100
22c213
Subject: [PATCH 5/6] block: Increase BB.in_flight for coroutine and sync
22c213
 interfaces
22c213
22c213
RH-Author: Kevin Wolf <kwolf@redhat.com>
22c213
Message-id: <20200408172917.18712-6-kwolf@redhat.com>
22c213
Patchwork-id: 94600
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 5/6] block: Increase BB.in_flight for coroutine and sync interfaces
22c213
Bugzilla: 1817621
22c213
RH-Acked-by: Eric Blake <eblake@redhat.com>
22c213
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
22c213
RH-Acked-by: Max Reitz <mreitz@redhat.com>
22c213
22c213
External callers of blk_co_*() and of the synchronous blk_*() functions
22c213
don't currently increase the BlockBackend.in_flight counter, but calls
22c213
from blk_aio_*() do, so there is an inconsistency whether the counter
22c213
has been increased or not.
22c213
22c213
This patch moves the actual operations to static functions that can
22c213
later know they will always be called with in_flight increased exactly
22c213
once, even for external callers using the blk_co_*() coroutine
22c213
interfaces.
22c213
22c213
If the public blk_co_*() interface is unused, remove it.
22c213
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
Message-Id: <20200407121259.21350-3-kwolf@redhat.com>
22c213
Reviewed-by: Max Reitz <mreitz@redhat.com>
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
(cherry picked from commit fbb92b6798894d3bf62fe3578d99fa62c720b242)
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 block/block-backend.c          | 103 ++++++++++++++++++++++++++++++++---------
22c213
 include/sysemu/block-backend.h |   1 -
22c213
 2 files changed, 80 insertions(+), 24 deletions(-)
22c213
22c213
diff --git a/block/block-backend.c b/block/block-backend.c
22c213
index 17b2e87..610dbfa 100644
22c213
--- a/block/block-backend.c
22c213
+++ b/block/block-backend.c
22c213
@@ -1147,9 +1147,10 @@ static void coroutine_fn blk_wait_while_drained(BlockBackend *blk)
22c213
     }
22c213
 }
22c213
 
22c213
-int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
22c213
-                               unsigned int bytes, QEMUIOVector *qiov,
22c213
-                               BdrvRequestFlags flags)
22c213
+/* To be called between exactly one pair of blk_inc/dec_in_flight() */
22c213
+static int coroutine_fn
22c213
+blk_do_preadv(BlockBackend *blk, int64_t offset, unsigned int bytes,
22c213
+              QEMUIOVector *qiov, BdrvRequestFlags flags)
22c213
 {
22c213
     int ret;
22c213
     BlockDriverState *bs;
22c213
@@ -1178,10 +1179,24 @@ int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
22c213
     return ret;
22c213
 }
22c213
 
22c213
-int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
22c213
-                                     unsigned int bytes,
22c213
-                                     QEMUIOVector *qiov, size_t qiov_offset,
22c213
-                                     BdrvRequestFlags flags)
22c213
+int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
22c213
+                               unsigned int bytes, QEMUIOVector *qiov,
22c213
+                               BdrvRequestFlags flags)
22c213
+{
22c213
+    int ret;
22c213
+
22c213
+    blk_inc_in_flight(blk);
22c213
+    ret = blk_do_preadv(blk, offset, bytes, qiov, flags);
22c213
+    blk_dec_in_flight(blk);
22c213
+
22c213
+    return ret;
22c213
+}
22c213
+
22c213
+/* To be called between exactly one pair of blk_inc/dec_in_flight() */
22c213
+static int coroutine_fn
22c213
+blk_do_pwritev_part(BlockBackend *blk, int64_t offset, unsigned int bytes,
22c213
+                    QEMUIOVector *qiov, size_t qiov_offset,
22c213
+                    BdrvRequestFlags flags)
22c213
 {
22c213
     int ret;
22c213
     BlockDriverState *bs;
22c213
@@ -1214,6 +1229,20 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
22c213
     return ret;
22c213
 }
22c213
 
22c213
+int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
22c213
+                                     unsigned int bytes,
22c213
+                                     QEMUIOVector *qiov, size_t qiov_offset,
22c213
+                                     BdrvRequestFlags flags)
22c213
+{
22c213
+    int ret;
22c213
+
22c213
+    blk_inc_in_flight(blk);
22c213
+    ret = blk_do_pwritev_part(blk, offset, bytes, qiov, qiov_offset, flags);
22c213
+    blk_dec_in_flight(blk);
22c213
+
22c213
+    return ret;
22c213
+}
22c213
+
22c213
 int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
22c213
                                 unsigned int bytes, QEMUIOVector *qiov,
22c213
                                 BdrvRequestFlags flags)
22c213
@@ -1234,7 +1263,7 @@ static void blk_read_entry(void *opaque)
22c213
     BlkRwCo *rwco = opaque;
22c213
     QEMUIOVector *qiov = rwco->iobuf;
22c213
 
22c213
-    rwco->ret = blk_co_preadv(rwco->blk, rwco->offset, qiov->size,
22c213
+    rwco->ret = blk_do_preadv(rwco->blk, rwco->offset, qiov->size,
22c213
                               qiov, rwco->flags);
22c213
     aio_wait_kick();
22c213
 }
22c213
@@ -1244,8 +1273,8 @@ static void blk_write_entry(void *opaque)
22c213
     BlkRwCo *rwco = opaque;
22c213
     QEMUIOVector *qiov = rwco->iobuf;
22c213
 
22c213
-    rwco->ret = blk_co_pwritev(rwco->blk, rwco->offset, qiov->size,
22c213
-                               qiov, rwco->flags);
22c213
+    rwco->ret = blk_do_pwritev_part(rwco->blk, rwco->offset, qiov->size,
22c213
+                                    qiov, 0, rwco->flags);
22c213
     aio_wait_kick();
22c213
 }
22c213
 
22c213
@@ -1262,6 +1291,7 @@ static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf,
22c213
         .ret    = NOT_DONE,
22c213
     };
22c213
 
22c213
+    blk_inc_in_flight(blk);
22c213
     if (qemu_in_coroutine()) {
22c213
         /* Fast-path if already in coroutine context */
22c213
         co_entry(&rwco);
22c213
@@ -1270,6 +1300,7 @@ static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf,
22c213
         bdrv_coroutine_enter(blk_bs(blk), co);
22c213
         BDRV_POLL_WHILE(blk_bs(blk), rwco.ret == NOT_DONE);
22c213
     }
22c213
+    blk_dec_in_flight(blk);
22c213
 
22c213
     return rwco.ret;
22c213
 }
22c213
@@ -1394,7 +1425,7 @@ static void blk_aio_read_entry(void *opaque)
22c213
     }
22c213
 
22c213
     assert(qiov->size == acb->bytes);
22c213
-    rwco->ret = blk_co_preadv(rwco->blk, rwco->offset, acb->bytes,
22c213
+    rwco->ret = blk_do_preadv(rwco->blk, rwco->offset, acb->bytes,
22c213
                               qiov, rwco->flags);
22c213
     blk_aio_complete(acb);
22c213
 }
22c213
@@ -1412,8 +1443,8 @@ static void blk_aio_write_entry(void *opaque)
22c213
     }
22c213
 
22c213
     assert(!qiov || qiov->size == acb->bytes);
22c213
-    rwco->ret = blk_co_pwritev(rwco->blk, rwco->offset, acb->bytes,
22c213
-                               qiov, rwco->flags);
22c213
+    rwco->ret = blk_do_pwritev_part(rwco->blk, rwco->offset, acb->bytes,
22c213
+                                    qiov, 0, rwco->flags);
22c213
     blk_aio_complete(acb);
22c213
 }
22c213
 
22c213
@@ -1498,7 +1529,9 @@ void blk_aio_cancel_async(BlockAIOCB *acb)
22c213
     bdrv_aio_cancel_async(acb);
22c213
 }
22c213
 
22c213
-int blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
22c213
+/* To be called between exactly one pair of blk_inc/dec_in_flight() */
22c213
+static int coroutine_fn
22c213
+blk_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
22c213
 {
22c213
     blk_wait_while_drained(blk);
22c213
 
22c213
@@ -1514,8 +1547,7 @@ static void blk_ioctl_entry(void *opaque)
22c213
     BlkRwCo *rwco = opaque;
22c213
     QEMUIOVector *qiov = rwco->iobuf;
22c213
 
22c213
-    rwco->ret = blk_co_ioctl(rwco->blk, rwco->offset,
22c213
-                             qiov->iov[0].iov_base);
22c213
+    rwco->ret = blk_do_ioctl(rwco->blk, rwco->offset, qiov->iov[0].iov_base);
22c213
     aio_wait_kick();
22c213
 }
22c213
 
22c213
@@ -1529,7 +1561,7 @@ static void blk_aio_ioctl_entry(void *opaque)
22c213
     BlkAioEmAIOCB *acb = opaque;
22c213
     BlkRwCo *rwco = &acb->rwco;
22c213
 
22c213
-    rwco->ret = blk_co_ioctl(rwco->blk, rwco->offset, rwco->iobuf);
22c213
+    rwco->ret = blk_do_ioctl(rwco->blk, rwco->offset, rwco->iobuf);
22c213
 
22c213
     blk_aio_complete(acb);
22c213
 }
22c213
@@ -1540,7 +1572,9 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
22c213
     return blk_aio_prwv(blk, req, 0, buf, blk_aio_ioctl_entry, 0, cb, opaque);
22c213
 }
22c213
 
22c213
-int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes)
22c213
+/* To be called between exactly one pair of blk_inc/dec_in_flight() */
22c213
+static int coroutine_fn
22c213
+blk_do_pdiscard(BlockBackend *blk, int64_t offset, int bytes)
22c213
 {
22c213
     int ret;
22c213
 
22c213
@@ -1559,7 +1593,7 @@ static void blk_aio_pdiscard_entry(void *opaque)
22c213
     BlkAioEmAIOCB *acb = opaque;
22c213
     BlkRwCo *rwco = &acb->rwco;
22c213
 
22c213
-    rwco->ret = blk_co_pdiscard(rwco->blk, rwco->offset, acb->bytes);
22c213
+    rwco->ret = blk_do_pdiscard(rwco->blk, rwco->offset, acb->bytes);
22c213
     blk_aio_complete(acb);
22c213
 }
22c213
 
22c213
@@ -1571,12 +1605,23 @@ BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk,
22c213
                         cb, opaque);
22c213
 }
22c213
 
22c213
+int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes)
22c213
+{
22c213
+    int ret;
22c213
+
22c213
+    blk_inc_in_flight(blk);
22c213
+    ret = blk_do_pdiscard(blk, offset, bytes);
22c213
+    blk_dec_in_flight(blk);
22c213
+
22c213
+    return ret;
22c213
+}
22c213
+
22c213
 static void blk_pdiscard_entry(void *opaque)
22c213
 {
22c213
     BlkRwCo *rwco = opaque;
22c213
     QEMUIOVector *qiov = rwco->iobuf;
22c213
 
22c213
-    rwco->ret = blk_co_pdiscard(rwco->blk, rwco->offset, qiov->size);
22c213
+    rwco->ret = blk_do_pdiscard(rwco->blk, rwco->offset, qiov->size);
22c213
     aio_wait_kick();
22c213
 }
22c213
 
22c213
@@ -1585,7 +1630,8 @@ int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes)
22c213
     return blk_prw(blk, offset, NULL, bytes, blk_pdiscard_entry, 0);
22c213
 }
22c213
 
22c213
-int blk_co_flush(BlockBackend *blk)
22c213
+/* To be called between exactly one pair of blk_inc/dec_in_flight() */
22c213
+static int coroutine_fn blk_do_flush(BlockBackend *blk)
22c213
 {
22c213
     blk_wait_while_drained(blk);
22c213
 
22c213
@@ -1601,7 +1647,7 @@ static void blk_aio_flush_entry(void *opaque)
22c213
     BlkAioEmAIOCB *acb = opaque;
22c213
     BlkRwCo *rwco = &acb->rwco;
22c213
 
22c213
-    rwco->ret = blk_co_flush(rwco->blk);
22c213
+    rwco->ret = blk_do_flush(rwco->blk);
22c213
     blk_aio_complete(acb);
22c213
 }
22c213
 
22c213
@@ -1611,10 +1657,21 @@ BlockAIOCB *blk_aio_flush(BlockBackend *blk,
22c213
     return blk_aio_prwv(blk, 0, 0, NULL, blk_aio_flush_entry, 0, cb, opaque);
22c213
 }
22c213
 
22c213
+int coroutine_fn blk_co_flush(BlockBackend *blk)
22c213
+{
22c213
+    int ret;
22c213
+
22c213
+    blk_inc_in_flight(blk);
22c213
+    ret = blk_do_flush(blk);
22c213
+    blk_dec_in_flight(blk);
22c213
+
22c213
+    return ret;
22c213
+}
22c213
+
22c213
 static void blk_flush_entry(void *opaque)
22c213
 {
22c213
     BlkRwCo *rwco = opaque;
22c213
-    rwco->ret = blk_co_flush(rwco->blk);
22c213
+    rwco->ret = blk_do_flush(rwco->blk);
22c213
     aio_wait_kick();
22c213
 }
22c213
 
22c213
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
22c213
index b198dec..9bbdbd6 100644
22c213
--- a/include/sysemu/block-backend.h
22c213
+++ b/include/sysemu/block-backend.h
22c213
@@ -171,7 +171,6 @@ BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes,
22c213
                              BlockCompletionFunc *cb, void *opaque);
22c213
 void blk_aio_cancel(BlockAIOCB *acb);
22c213
 void blk_aio_cancel_async(BlockAIOCB *acb);
22c213
-int blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
22c213
 int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
22c213
 BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
22c213
                           BlockCompletionFunc *cb, void *opaque);
22c213
-- 
22c213
1.8.3.1
22c213