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