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>
This commit is contained in:
Kevin Wolf
2026-04-21 18:11:28 +02:00
parent 34a6763776
commit 53074ba033
7 changed files with 15 additions and 14 deletions

View File

@@ -1803,12 +1803,13 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
/* To be called between exactly one pair of blk_inc/dec_in_flight() */ /* To be called between exactly one pair of blk_inc/dec_in_flight() */
static int coroutine_fn static int coroutine_fn
blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes) blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes,
BdrvRequestFlags flags)
{ {
int ret; int ret;
IO_CODE(); IO_CODE();
blk_wait_while_drained(blk, 0); blk_wait_while_drained(blk, flags);
GRAPH_RDLOCK_GUARD(); GRAPH_RDLOCK_GUARD();
ret = blk_check_byte_request(blk, offset, bytes); ret = blk_check_byte_request(blk, offset, bytes);
@@ -1824,7 +1825,7 @@ static void coroutine_fn blk_aio_pdiscard_entry(void *opaque)
BlkAioEmAIOCB *acb = opaque; BlkAioEmAIOCB *acb = opaque;
BlkRwCo *rwco = &acb->rwco; BlkRwCo *rwco = &acb->rwco;
rwco->ret = blk_co_do_pdiscard(rwco->blk, rwco->offset, acb->bytes); rwco->ret = blk_co_do_pdiscard(rwco->blk, rwco->offset, acb->bytes, 0);
blk_aio_complete(acb); blk_aio_complete(acb);
} }
@@ -1838,13 +1839,13 @@ BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk,
} }
int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
int64_t bytes) int64_t bytes, BdrvRequestFlags flags)
{ {
int ret; int ret;
IO_OR_GS_CODE(); IO_OR_GS_CODE();
blk_inc_in_flight(blk); blk_inc_in_flight(blk);
ret = blk_co_do_pdiscard(blk, offset, bytes); ret = blk_co_do_pdiscard(blk, offset, bytes, flags);
blk_dec_in_flight(blk); blk_dec_in_flight(blk);
return ret; return ret;

View File

@@ -122,7 +122,7 @@ virtio_blk_discard_write_zeroes(VirtioBlkHandler *handler, struct iovec *iov,
} }
if (blk_co_pdiscard(blk, sector << VIRTIO_BLK_SECTOR_BITS, if (blk_co_pdiscard(blk, sector << VIRTIO_BLK_SECTOR_BITS,
bytes) == 0) { bytes, 0) == 0) {
return VIRTIO_BLK_S_OK; return VIRTIO_BLK_S_OK;
} }
} }

View File

@@ -454,7 +454,7 @@ static void coroutine_fn mirror_co_discard(void *opaque)
*op->bytes_handled = op->bytes; *op->bytes_handled = op->bytes;
op->is_in_flight = true; op->is_in_flight = true;
ret = blk_co_pdiscard(op->s->target, op->offset, op->bytes); ret = blk_co_pdiscard(op->s->target, op->offset, op->bytes, 0);
mirror_write_complete(op, ret); mirror_write_complete(op, ret);
} }
@@ -1532,7 +1532,7 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMethod method,
zero_bitmap_end - zero_bitmap_offset); zero_bitmap_end - zero_bitmap_offset);
} }
assert(!qiov); assert(!qiov);
ret = blk_co_pdiscard(job->target, offset, bytes); ret = blk_co_pdiscard(job->target, offset, bytes, 0);
break; break;
default: default:

View File

@@ -218,9 +218,9 @@ int co_wrapper_mixed blk_zone_append(BlockBackend *blk, int64_t *offset,
BdrvRequestFlags flags); BdrvRequestFlags flags);
int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset, int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset,
int64_t bytes); int64_t bytes, BdrvRequestFlags flags);
int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
int64_t bytes); int64_t bytes, BdrvRequestFlags flags);
int co_wrapper_mixed blk_flush(BlockBackend *blk); int co_wrapper_mixed blk_flush(BlockBackend *blk);
int coroutine_fn blk_co_flush(BlockBackend *blk); int coroutine_fn blk_co_flush(BlockBackend *blk);

View File

@@ -2990,7 +2990,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
"flush failed", errp); "flush failed", errp);
case NBD_CMD_TRIM: case NBD_CMD_TRIM:
ret = blk_co_pdiscard(exp->common.blk, request->from, request->len); ret = blk_co_pdiscard(exp->common.blk, request->from, request->len, 0);
if (ret >= 0 && request->flags & NBD_CMD_FLAG_FUA) { if (ret >= 0 && request->flags & NBD_CMD_FLAG_FUA) {
ret = blk_co_flush(exp->common.blk); ret = blk_co_flush(exp->common.blk);
} }

View File

@@ -2201,7 +2201,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv)
} }
clock_gettime(CLOCK_MONOTONIC, &t1); clock_gettime(CLOCK_MONOTONIC, &t1);
ret = blk_pdiscard(blk, offset, bytes); ret = blk_pdiscard(blk, offset, bytes, 0);
clock_gettime(CLOCK_MONOTONIC, &t2); clock_gettime(CLOCK_MONOTONIC, &t2);
if (ret < 0) { if (ret < 0) {

View File

@@ -270,11 +270,11 @@ static void test_sync_op_blk_pdiscard(BlockBackend *blk)
int ret; int ret;
/* Early success: UNMAP not supported */ /* Early success: UNMAP not supported */
ret = blk_pdiscard(blk, 0, 512); ret = blk_pdiscard(blk, 0, 512, 0);
g_assert_cmpint(ret, ==, 0); g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */ /* Early error: Negative offset */
ret = blk_pdiscard(blk, -2, 512); ret = blk_pdiscard(blk, -2, 512, 0);
g_assert_cmpint(ret, ==, -EIO); g_assert_cmpint(ret, ==, -EIO);
} }