block: Add flags parameter to blk_*_pdiscard()
All existing callers pass 0, but we need a way to pass BDRV_REQ_NO_QUEUE for discard requests. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-ID: <20260421161132.99878-4-kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Kevin Wolf committed
Apr 21, 2026 at 18:11 UTC
53074ba0330ae8831abbae2521c012e1d9072ed3
7 files changed
+15
-14
block/block-backend.c
+6
-5
@@ -1803,12 +1803,13 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
1803
1804
/* To be called between exactly one pair of blk_inc/dec_in_flight() */
1805
static int coroutine_fn
1806
-blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes)
1806
+blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes,
1807
+ BdrvRequestFlags flags)
1808
{
1809
int ret;
1810
IO_CODE();
1811
1811
- blk_wait_while_drained(blk, 0);
1812
+ blk_wait_while_drained(blk, flags);
1813
GRAPH_RDLOCK_GUARD();
1814
1815
ret = blk_check_byte_request(blk, offset, bytes);
@@ -1824,7 +1825,7 @@ static void coroutine_fn blk_aio_pdiscard_entry(void *opaque)
1825
BlkAioEmAIOCB *acb = opaque;
1826
BlkRwCo *rwco = &acb->rwco;
1827
1827
- rwco->ret = blk_co_do_pdiscard(rwco->blk, rwco->offset, acb->bytes);
1828
+ rwco->ret = blk_co_do_pdiscard(rwco->blk, rwco->offset, acb->bytes, 0);
1829
blk_aio_complete(acb);
1830
}
1831
@@ -1838,13 +1839,13 @@ BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk,
1839
}
1840
1841
int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
1841
- int64_t bytes)
1842
+ int64_t bytes, BdrvRequestFlags flags)
1843
{
1844
int ret;
1845
IO_OR_GS_CODE();
1846
1847
blk_inc_in_flight(blk);
1847
- ret = blk_co_do_pdiscard(blk, offset, bytes);
1848
+ ret = blk_co_do_pdiscard(blk, offset, bytes, flags);
1849
blk_dec_in_flight(blk);
1850
1851
return ret;
block/export/virtio-blk-handler.c
+1
-1
@@ -122,7 +122,7 @@ virtio_blk_discard_write_zeroes(VirtioBlkHandler *handler, struct iovec *iov,
122
}
123
124
if (blk_co_pdiscard(blk, sector << VIRTIO_BLK_SECTOR_BITS,
125
- bytes) == 0) {
125
+ bytes, 0) == 0) {
126
return VIRTIO_BLK_S_OK;
127
}
128
}
block/mirror.c
+2
-2
@@ -454,7 +454,7 @@ static void coroutine_fn mirror_co_discard(void *opaque)
454
*op->bytes_handled = op->bytes;
455
op->is_in_flight = true;
456
457
- ret = blk_co_pdiscard(op->s->target, op->offset, op->bytes);
457
+ ret = blk_co_pdiscard(op->s->target, op->offset, op->bytes, 0);
458
mirror_write_complete(op, ret);
459
}
460
@@ -1532,7 +1532,7 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMethod method,
1532
zero_bitmap_end - zero_bitmap_offset);
1533
}
1534
assert(!qiov);
1535
- ret = blk_co_pdiscard(job->target, offset, bytes);
1535
+ ret = blk_co_pdiscard(job->target, offset, bytes, 0);
1536
break;
1537
1538
default:
include/system/block-backend-io.h
+2
-2
@@ -218,9 +218,9 @@ int co_wrapper_mixed blk_zone_append(BlockBackend *blk, int64_t *offset,
218
BdrvRequestFlags flags);
219
220
int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset,
221
- int64_t bytes);
221
+ int64_t bytes, BdrvRequestFlags flags);
222
int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
223
- int64_t bytes);
223
+ int64_t bytes, BdrvRequestFlags flags);
224
225
int co_wrapper_mixed blk_flush(BlockBackend *blk);
226
int coroutine_fn blk_co_flush(BlockBackend *blk);
nbd/server.c
+1
-1
@@ -2990,7 +2990,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
2990
"flush failed", errp);
2991
2992
case NBD_CMD_TRIM:
2993
- ret = blk_co_pdiscard(exp->common.blk, request->from, request->len);
2993
+ ret = blk_co_pdiscard(exp->common.blk, request->from, request->len, 0);
2994
if (ret >= 0 && request->flags & NBD_CMD_FLAG_FUA) {
2995
ret = blk_co_flush(exp->common.blk);
2996
}
qemu-io-cmds.c
+1
-1
@@ -2201,7 +2201,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv)
2201
}
2202
2203
clock_gettime(CLOCK_MONOTONIC, &t1);
2204
- ret = blk_pdiscard(blk, offset, bytes);
2204
+ ret = blk_pdiscard(blk, offset, bytes, 0);
2205
clock_gettime(CLOCK_MONOTONIC, &t2);
2206
2207
if (ret < 0) {
tests/unit/test-block-iothread.c
+2
-2
@@ -270,11 +270,11 @@ static void test_sync_op_blk_pdiscard(BlockBackend *blk)
270
int ret;
271
272
/* Early success: UNMAP not supported */
273
- ret = blk_pdiscard(blk, 0, 512);
273
+ ret = blk_pdiscard(blk, 0, 512, 0);
274
g_assert_cmpint(ret, ==, 0);
275
276
/* Early error: Negative offset */
277
- ret = blk_pdiscard(blk, -2, 512);
277
+ ret = blk_pdiscard(blk, -2, 512, 0);
278
g_assert_cmpint(ret, ==, -EIO);
279
}
280