Skip to content

Commit 0b9fd3f

Browse files
Fam Zhengkevmw
Fam Zheng
authored andcommitted
block: Use BdrvChild to discard
Other I/O functions are already using a BdrvChild pointer in the API, so make discard do the same. It makes it possible to initiate the same permission checks before doing I/O, and much easier to share the helper functions for this, which will be added and used by write, truncate and copy range paths. Signed-off-by: Fam Zheng <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent ecc983a commit 0b9fd3f

11 files changed

+20
-20
lines changed

block/blkdebug.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
625625
return err;
626626
}
627627

628-
return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
628+
return bdrv_co_pdiscard(bs->file, offset, bytes);
629629
}
630630

631631
static int coroutine_fn blkdebug_co_block_status(BlockDriverState *bs,

block/blklogwrites.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static int coroutine_fn blk_log_writes_co_do_file_flush(BlkLogWritesFileReq *fr)
486486
static int coroutine_fn
487487
blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileReq *fr)
488488
{
489-
return bdrv_co_pdiscard(fr->bs->file->bs, fr->offset, fr->bytes);
489+
return bdrv_co_pdiscard(fr->bs->file, fr->offset, fr->bytes);
490490
}
491491

492492
static int coroutine_fn

block/blkreplay.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs,
113113
int64_t offset, int bytes)
114114
{
115115
uint64_t reqid = blkreplay_next_id();
116-
int ret = bdrv_co_pdiscard(bs->file->bs, offset, bytes);
116+
int ret = bdrv_co_pdiscard(bs->file, offset, bytes);
117117
block_request_create(reqid, bs, qemu_coroutine_self());
118118
qemu_coroutine_yield();
119119

block/block-backend.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes)
15601560
return ret;
15611561
}
15621562

1563-
return bdrv_co_pdiscard(blk_bs(blk), offset, bytes);
1563+
return bdrv_co_pdiscard(blk->root, offset, bytes);
15641564
}
15651565

15661566
int blk_co_flush(BlockBackend *blk)

block/copy-on-read.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int coroutine_fn cor_co_pwrite_zeroes(BlockDriverState *bs,
116116
static int coroutine_fn cor_co_pdiscard(BlockDriverState *bs,
117117
int64_t offset, int bytes)
118118
{
119-
return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
119+
return bdrv_co_pdiscard(bs->file, offset, bytes);
120120
}
121121

122122

block/io.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ int bdrv_flush(BlockDriverState *bs)
26332633
}
26342634

26352635
typedef struct DiscardCo {
2636-
BlockDriverState *bs;
2636+
BdrvChild *child;
26372637
int64_t offset;
26382638
int bytes;
26392639
int ret;
@@ -2642,17 +2642,17 @@ static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque)
26422642
{
26432643
DiscardCo *rwco = opaque;
26442644

2645-
rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->bytes);
2645+
rwco->ret = bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes);
26462646
}
26472647

2648-
int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
2649-
int bytes)
2648+
int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int bytes)
26502649
{
26512650
BdrvTrackedRequest req;
26522651
int max_pdiscard, ret;
26532652
int head, tail, align;
2653+
BlockDriverState *bs = child->bs;
26542654

2655-
if (!bs->drv) {
2655+
if (!bs || !bs->drv) {
26562656
return -ENOMEDIUM;
26572657
}
26582658

@@ -2763,11 +2763,11 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
27632763
return ret;
27642764
}
27652765

2766-
int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
2766+
int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes)
27672767
{
27682768
Coroutine *co;
27692769
DiscardCo rwco = {
2770-
.bs = bs,
2770+
.child = child,
27712771
.offset = offset,
27722772
.bytes = bytes,
27732773
.ret = NOT_DONE,
@@ -2778,8 +2778,8 @@ int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
27782778
bdrv_pdiscard_co_entry(&rwco);
27792779
} else {
27802780
co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
2781-
bdrv_coroutine_enter(bs, co);
2782-
BDRV_POLL_WHILE(bs, rwco.ret == NOT_DONE);
2781+
bdrv_coroutine_enter(child->bs, co);
2782+
BDRV_POLL_WHILE(child->bs, rwco.ret == NOT_DONE);
27832783
}
27842784

27852785
return rwco.ret;

block/mirror.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ static int coroutine_fn bdrv_mirror_top_do_write(BlockDriverState *bs,
13331333
break;
13341334

13351335
case MIRROR_METHOD_DISCARD:
1336-
ret = bdrv_co_pdiscard(bs->backing->bs, offset, bytes);
1336+
ret = bdrv_co_pdiscard(bs->backing, offset, bytes);
13371337
break;
13381338

13391339
default:

block/qcow2-refcount.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ void qcow2_process_discards(BlockDriverState *bs, int ret)
734734

735735
/* Discard is optional, ignore the return value */
736736
if (ret >= 0) {
737-
bdrv_pdiscard(bs->file->bs, d->offset, d->bytes);
737+
bdrv_pdiscard(bs->file, d->offset, d->bytes);
738738
}
739739

740740
g_free(d);

block/raw-format.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs,
297297
if (ret) {
298298
return ret;
299299
}
300-
return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
300+
return bdrv_co_pdiscard(bs->file, offset, bytes);
301301
}
302302

303303
static int64_t raw_getlength(BlockDriverState *bs)

block/throttle.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int coroutine_fn throttle_co_pdiscard(BlockDriverState *bs,
149149
ThrottleGroupMember *tgm = bs->opaque;
150150
throttle_group_co_io_limits_intercept(tgm, bytes, true);
151151

152-
return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
152+
return bdrv_co_pdiscard(bs->file, offset, bytes);
153153
}
154154

155155
static int throttle_co_flush(BlockDriverState *bs)

include/block/block.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ AioWait *bdrv_get_aio_wait(BlockDriverState *bs);
418418
bdrv_get_aio_context(bs_), \
419419
cond); })
420420

421-
int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
422-
int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
421+
int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes);
422+
int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int bytes);
423423
int bdrv_has_zero_init_1(BlockDriverState *bs);
424424
int bdrv_has_zero_init(BlockDriverState *bs);
425425
bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs);

0 commit comments

Comments
 (0)