Skip to content

Commit b3241e9

Browse files
ebblakekevmw
authored andcommitted
null: Switch to byte-based read/write
We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the last few sector-based callbacks in the null-co and null-aio drivers. Note that since the null driver does nothing on writes, it trivially supports the BDRV_REQ_FUA flag (all writes have already landed to the same bit-bucket without needing an extra flush call). Also, since the null driver does just as well with byte-based requests, we can now avoid cycles wasted on read-modify-write by taking advantage of the block layer now defaulting the alignment to 1 instead of 512. Signed-off-by: Eric Blake <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent de7056a commit b3241e9

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

block/null.c

+23-22
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static int null_file_open(BlockDriverState *bs, QDict *options, int flags,
9393
}
9494
s->read_zeroes = qemu_opt_get_bool(opts, NULL_OPT_ZEROES, false);
9595
qemu_opts_del(opts);
96+
bs->supported_write_flags = BDRV_REQ_FUA;
9697
return ret;
9798
}
9899

@@ -116,22 +117,22 @@ static coroutine_fn int null_co_common(BlockDriverState *bs)
116117
return 0;
117118
}
118119

119-
static coroutine_fn int null_co_readv(BlockDriverState *bs,
120-
int64_t sector_num, int nb_sectors,
121-
QEMUIOVector *qiov)
120+
static coroutine_fn int null_co_preadv(BlockDriverState *bs,
121+
uint64_t offset, uint64_t bytes,
122+
QEMUIOVector *qiov, int flags)
122123
{
123124
BDRVNullState *s = bs->opaque;
124125

125126
if (s->read_zeroes) {
126-
qemu_iovec_memset(qiov, 0, 0, nb_sectors * BDRV_SECTOR_SIZE);
127+
qemu_iovec_memset(qiov, 0, 0, bytes);
127128
}
128129

129130
return null_co_common(bs);
130131
}
131132

132-
static coroutine_fn int null_co_writev(BlockDriverState *bs,
133-
int64_t sector_num, int nb_sectors,
134-
QEMUIOVector *qiov)
133+
static coroutine_fn int null_co_pwritev(BlockDriverState *bs,
134+
uint64_t offset, uint64_t bytes,
135+
QEMUIOVector *qiov, int flags)
135136
{
136137
return null_co_common(bs);
137138
}
@@ -186,26 +187,26 @@ static inline BlockAIOCB *null_aio_common(BlockDriverState *bs,
186187
return &acb->common;
187188
}
188189

189-
static BlockAIOCB *null_aio_readv(BlockDriverState *bs,
190-
int64_t sector_num, QEMUIOVector *qiov,
191-
int nb_sectors,
192-
BlockCompletionFunc *cb,
193-
void *opaque)
190+
static BlockAIOCB *null_aio_preadv(BlockDriverState *bs,
191+
uint64_t offset, uint64_t bytes,
192+
QEMUIOVector *qiov, int flags,
193+
BlockCompletionFunc *cb,
194+
void *opaque)
194195
{
195196
BDRVNullState *s = bs->opaque;
196197

197198
if (s->read_zeroes) {
198-
qemu_iovec_memset(qiov, 0, 0, nb_sectors * BDRV_SECTOR_SIZE);
199+
qemu_iovec_memset(qiov, 0, 0, bytes);
199200
}
200201

201202
return null_aio_common(bs, cb, opaque);
202203
}
203204

204-
static BlockAIOCB *null_aio_writev(BlockDriverState *bs,
205-
int64_t sector_num, QEMUIOVector *qiov,
206-
int nb_sectors,
207-
BlockCompletionFunc *cb,
208-
void *opaque)
205+
static BlockAIOCB *null_aio_pwritev(BlockDriverState *bs,
206+
uint64_t offset, uint64_t bytes,
207+
QEMUIOVector *qiov, int flags,
208+
BlockCompletionFunc *cb,
209+
void *opaque)
209210
{
210211
return null_aio_common(bs, cb, opaque);
211212
}
@@ -265,8 +266,8 @@ static BlockDriver bdrv_null_co = {
265266
.bdrv_close = null_close,
266267
.bdrv_getlength = null_getlength,
267268

268-
.bdrv_co_readv = null_co_readv,
269-
.bdrv_co_writev = null_co_writev,
269+
.bdrv_co_preadv = null_co_preadv,
270+
.bdrv_co_pwritev = null_co_pwritev,
270271
.bdrv_co_flush_to_disk = null_co_flush,
271272
.bdrv_reopen_prepare = null_reopen_prepare,
272273

@@ -285,8 +286,8 @@ static BlockDriver bdrv_null_aio = {
285286
.bdrv_close = null_close,
286287
.bdrv_getlength = null_getlength,
287288

288-
.bdrv_aio_readv = null_aio_readv,
289-
.bdrv_aio_writev = null_aio_writev,
289+
.bdrv_aio_preadv = null_aio_preadv,
290+
.bdrv_aio_pwritev = null_aio_pwritev,
290291
.bdrv_aio_flush = null_aio_flush,
291292
.bdrv_reopen_prepare = null_reopen_prepare,
292293

0 commit comments

Comments
 (0)