You need to sign in or sign up before continuing.
提交 f5a5ca79 编写于 作者: M Manos Pitsidianakis 提交者: Max Reitz

block: change variable names in BlockDriverState

Change the 'int count' parameter in *pwrite_zeros, *pdiscard related
functions (and some others) to 'int bytes', as they both refer to bytes.
This helps with code legibility.
Signed-off-by: NManos Pitsidianakis <el13635@mail.ntua.gr>
Message-id: 20170609101808.13506-1-el13635@mail.ntua.gr
Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: NMax Reitz <mreitz@redhat.com>
上级 c5f1ad42
...@@ -575,7 +575,7 @@ static int blkdebug_co_flush(BlockDriverState *bs) ...@@ -575,7 +575,7 @@ static int blkdebug_co_flush(BlockDriverState *bs)
} }
static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs, static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int count, int64_t offset, int bytes,
BdrvRequestFlags flags) BdrvRequestFlags flags)
{ {
uint32_t align = MAX(bs->bl.request_alignment, uint32_t align = MAX(bs->bl.request_alignment,
...@@ -586,29 +586,29 @@ static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -586,29 +586,29 @@ static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs,
* preferred alignment (so that we test the fallback to writes on * preferred alignment (so that we test the fallback to writes on
* unaligned portions), and check that the block layer never hands * unaligned portions), and check that the block layer never hands
* us anything unaligned that crosses an alignment boundary. */ * us anything unaligned that crosses an alignment boundary. */
if (count < align) { if (bytes < align) {
assert(QEMU_IS_ALIGNED(offset, align) || assert(QEMU_IS_ALIGNED(offset, align) ||
QEMU_IS_ALIGNED(offset + count, align) || QEMU_IS_ALIGNED(offset + bytes, align) ||
DIV_ROUND_UP(offset, align) == DIV_ROUND_UP(offset, align) ==
DIV_ROUND_UP(offset + count, align)); DIV_ROUND_UP(offset + bytes, align));
return -ENOTSUP; return -ENOTSUP;
} }
assert(QEMU_IS_ALIGNED(offset, align)); assert(QEMU_IS_ALIGNED(offset, align));
assert(QEMU_IS_ALIGNED(count, align)); assert(QEMU_IS_ALIGNED(bytes, align));
if (bs->bl.max_pwrite_zeroes) { if (bs->bl.max_pwrite_zeroes) {
assert(count <= bs->bl.max_pwrite_zeroes); assert(bytes <= bs->bl.max_pwrite_zeroes);
} }
err = rule_check(bs, offset, count); err = rule_check(bs, offset, bytes);
if (err) { if (err) {
return err; return err;
} }
return bdrv_co_pwrite_zeroes(bs->file, offset, count, flags); return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags);
} }
static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs, static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
int64_t offset, int count) int64_t offset, int bytes)
{ {
uint32_t align = bs->bl.pdiscard_alignment; uint32_t align = bs->bl.pdiscard_alignment;
int err; int err;
...@@ -616,29 +616,29 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs, ...@@ -616,29 +616,29 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
/* Only pass through requests that are larger than requested /* Only pass through requests that are larger than requested
* minimum alignment, and ensure that unaligned requests do not * minimum alignment, and ensure that unaligned requests do not
* cross optimum discard boundaries. */ * cross optimum discard boundaries. */
if (count < bs->bl.request_alignment) { if (bytes < bs->bl.request_alignment) {
assert(QEMU_IS_ALIGNED(offset, align) || assert(QEMU_IS_ALIGNED(offset, align) ||
QEMU_IS_ALIGNED(offset + count, align) || QEMU_IS_ALIGNED(offset + bytes, align) ||
DIV_ROUND_UP(offset, align) == DIV_ROUND_UP(offset, align) ==
DIV_ROUND_UP(offset + count, align)); DIV_ROUND_UP(offset + bytes, align));
return -ENOTSUP; return -ENOTSUP;
} }
assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)); assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
assert(QEMU_IS_ALIGNED(count, bs->bl.request_alignment)); assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
if (align && count >= align) { if (align && bytes >= align) {
assert(QEMU_IS_ALIGNED(offset, align)); assert(QEMU_IS_ALIGNED(offset, align));
assert(QEMU_IS_ALIGNED(count, align)); assert(QEMU_IS_ALIGNED(bytes, align));
} }
if (bs->bl.max_pdiscard) { if (bs->bl.max_pdiscard) {
assert(count <= bs->bl.max_pdiscard); assert(bytes <= bs->bl.max_pdiscard);
} }
err = rule_check(bs, offset, count); err = rule_check(bs, offset, bytes);
if (err) { if (err) {
return err; return err;
} }
return bdrv_co_pdiscard(bs->file->bs, offset, count); return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
} }
static void blkdebug_close(BlockDriverState *bs) static void blkdebug_close(BlockDriverState *bs)
......
...@@ -96,10 +96,10 @@ static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs, ...@@ -96,10 +96,10 @@ static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs,
} }
static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs, static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int count, BdrvRequestFlags flags) int64_t offset, int bytes, BdrvRequestFlags flags)
{ {
uint64_t reqid = blkreplay_next_id(); uint64_t reqid = blkreplay_next_id();
int ret = bdrv_co_pwrite_zeroes(bs->file, offset, count, flags); int ret = bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags);
block_request_create(reqid, bs, qemu_coroutine_self()); block_request_create(reqid, bs, qemu_coroutine_self());
qemu_coroutine_yield(); qemu_coroutine_yield();
...@@ -107,10 +107,10 @@ static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -107,10 +107,10 @@ static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs,
} }
static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs, static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs,
int64_t offset, int count) int64_t offset, int bytes)
{ {
uint64_t reqid = blkreplay_next_id(); uint64_t reqid = blkreplay_next_id();
int ret = bdrv_co_pdiscard(bs->file->bs, offset, count); int ret = bdrv_co_pdiscard(bs->file->bs, offset, bytes);
block_request_create(reqid, bs, qemu_coroutine_self()); block_request_create(reqid, bs, qemu_coroutine_self());
qemu_coroutine_yield(); qemu_coroutine_yield();
......
...@@ -1099,9 +1099,9 @@ int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf, ...@@ -1099,9 +1099,9 @@ int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf,
} }
int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int count, BdrvRequestFlags flags) int bytes, BdrvRequestFlags flags)
{ {
return blk_prw(blk, offset, NULL, count, blk_write_entry, return blk_prw(blk, offset, NULL, bytes, blk_write_entry,
flags | BDRV_REQ_ZERO_WRITE); flags | BDRV_REQ_ZERO_WRITE);
} }
...@@ -1311,10 +1311,10 @@ static void blk_aio_pdiscard_entry(void *opaque) ...@@ -1311,10 +1311,10 @@ static void blk_aio_pdiscard_entry(void *opaque)
} }
BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk,
int64_t offset, int count, int64_t offset, int bytes,
BlockCompletionFunc *cb, void *opaque) BlockCompletionFunc *cb, void *opaque)
{ {
return blk_aio_prwv(blk, offset, count, NULL, blk_aio_pdiscard_entry, 0, return blk_aio_prwv(blk, offset, bytes, NULL, blk_aio_pdiscard_entry, 0,
cb, opaque); cb, opaque);
} }
...@@ -1374,14 +1374,14 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf, ...@@ -1374,14 +1374,14 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
return blk_aio_prwv(blk, req, 0, &qiov, blk_aio_ioctl_entry, 0, cb, opaque); return blk_aio_prwv(blk, req, 0, &qiov, blk_aio_ioctl_entry, 0, cb, opaque);
} }
int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int count) int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes)
{ {
int ret = blk_check_byte_request(blk, offset, count); int ret = blk_check_byte_request(blk, offset, bytes);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
return bdrv_co_pdiscard(blk_bs(blk), offset, count); return bdrv_co_pdiscard(blk_bs(blk), offset, bytes);
} }
int blk_co_flush(BlockBackend *blk) int blk_co_flush(BlockBackend *blk)
...@@ -1760,9 +1760,9 @@ void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk, ...@@ -1760,9 +1760,9 @@ void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
} }
int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int count, BdrvRequestFlags flags) int bytes, BdrvRequestFlags flags)
{ {
return blk_co_pwritev(blk, offset, count, NULL, return blk_co_pwritev(blk, offset, bytes, NULL,
flags | BDRV_REQ_ZERO_WRITE); flags | BDRV_REQ_ZERO_WRITE);
} }
...@@ -1789,9 +1789,9 @@ static void blk_pdiscard_entry(void *opaque) ...@@ -1789,9 +1789,9 @@ static void blk_pdiscard_entry(void *opaque)
rwco->ret = blk_co_pdiscard(rwco->blk, rwco->offset, rwco->qiov->size); rwco->ret = blk_co_pdiscard(rwco->blk, rwco->offset, rwco->qiov->size);
} }
int blk_pdiscard(BlockBackend *blk, int64_t offset, int count) int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes)
{ {
return blk_prw(blk, offset, NULL, count, blk_pdiscard_entry, 0); return blk_prw(blk, offset, NULL, bytes, blk_pdiscard_entry, 0);
} }
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
......
...@@ -1485,7 +1485,7 @@ static int aio_worker(void *arg) ...@@ -1485,7 +1485,7 @@ static int aio_worker(void *arg)
static int paio_submit_co(BlockDriverState *bs, int fd, static int paio_submit_co(BlockDriverState *bs, int fd,
int64_t offset, QEMUIOVector *qiov, int64_t offset, QEMUIOVector *qiov,
int count, int type) int bytes, int type)
{ {
RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); RawPosixAIOData *acb = g_new(RawPosixAIOData, 1);
ThreadPool *pool; ThreadPool *pool;
...@@ -1494,22 +1494,22 @@ static int paio_submit_co(BlockDriverState *bs, int fd, ...@@ -1494,22 +1494,22 @@ static int paio_submit_co(BlockDriverState *bs, int fd,
acb->aio_type = type; acb->aio_type = type;
acb->aio_fildes = fd; acb->aio_fildes = fd;
acb->aio_nbytes = count; acb->aio_nbytes = bytes;
acb->aio_offset = offset; acb->aio_offset = offset;
if (qiov) { if (qiov) {
acb->aio_iov = qiov->iov; acb->aio_iov = qiov->iov;
acb->aio_niov = qiov->niov; acb->aio_niov = qiov->niov;
assert(qiov->size == count); assert(qiov->size == bytes);
} }
trace_paio_submit_co(offset, count, type); trace_paio_submit_co(offset, bytes, type);
pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
return thread_pool_submit_co(pool, aio_worker, acb); return thread_pool_submit_co(pool, aio_worker, acb);
} }
static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd, static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd,
int64_t offset, QEMUIOVector *qiov, int count, int64_t offset, QEMUIOVector *qiov, int bytes,
BlockCompletionFunc *cb, void *opaque, int type) BlockCompletionFunc *cb, void *opaque, int type)
{ {
RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); RawPosixAIOData *acb = g_new(RawPosixAIOData, 1);
...@@ -1519,7 +1519,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd, ...@@ -1519,7 +1519,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd,
acb->aio_type = type; acb->aio_type = type;
acb->aio_fildes = fd; acb->aio_fildes = fd;
acb->aio_nbytes = count; acb->aio_nbytes = bytes;
acb->aio_offset = offset; acb->aio_offset = offset;
if (qiov) { if (qiov) {
...@@ -1528,7 +1528,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd, ...@@ -1528,7 +1528,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd,
assert(qiov->size == acb->aio_nbytes); assert(qiov->size == acb->aio_nbytes);
} }
trace_paio_submit(acb, opaque, offset, count, type); trace_paio_submit(acb, opaque, offset, bytes, type);
pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque);
} }
...@@ -2109,26 +2109,26 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, ...@@ -2109,26 +2109,26 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
} }
static coroutine_fn BlockAIOCB *raw_aio_pdiscard(BlockDriverState *bs, static coroutine_fn BlockAIOCB *raw_aio_pdiscard(BlockDriverState *bs,
int64_t offset, int count, int64_t offset, int bytes,
BlockCompletionFunc *cb, void *opaque) BlockCompletionFunc *cb, void *opaque)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
return paio_submit(bs, s->fd, offset, NULL, count, return paio_submit(bs, s->fd, offset, NULL, bytes,
cb, opaque, QEMU_AIO_DISCARD); cb, opaque, QEMU_AIO_DISCARD);
} }
static int coroutine_fn raw_co_pwrite_zeroes( static int coroutine_fn raw_co_pwrite_zeroes(
BlockDriverState *bs, int64_t offset, BlockDriverState *bs, int64_t offset,
int count, BdrvRequestFlags flags) int bytes, BdrvRequestFlags flags)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
if (!(flags & BDRV_REQ_MAY_UNMAP)) { if (!(flags & BDRV_REQ_MAY_UNMAP)) {
return paio_submit_co(bs, s->fd, offset, NULL, count, return paio_submit_co(bs, s->fd, offset, NULL, bytes,
QEMU_AIO_WRITE_ZEROES); QEMU_AIO_WRITE_ZEROES);
} else if (s->discard_zeroes) { } else if (s->discard_zeroes) {
return paio_submit_co(bs, s->fd, offset, NULL, count, return paio_submit_co(bs, s->fd, offset, NULL, bytes,
QEMU_AIO_DISCARD); QEMU_AIO_DISCARD);
} }
return -ENOTSUP; return -ENOTSUP;
...@@ -2560,7 +2560,7 @@ static int fd_open(BlockDriverState *bs) ...@@ -2560,7 +2560,7 @@ static int fd_open(BlockDriverState *bs)
} }
static coroutine_fn BlockAIOCB *hdev_aio_pdiscard(BlockDriverState *bs, static coroutine_fn BlockAIOCB *hdev_aio_pdiscard(BlockDriverState *bs,
int64_t offset, int count, int64_t offset, int bytes,
BlockCompletionFunc *cb, void *opaque) BlockCompletionFunc *cb, void *opaque)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
...@@ -2568,12 +2568,12 @@ static coroutine_fn BlockAIOCB *hdev_aio_pdiscard(BlockDriverState *bs, ...@@ -2568,12 +2568,12 @@ static coroutine_fn BlockAIOCB *hdev_aio_pdiscard(BlockDriverState *bs,
if (fd_open(bs) < 0) { if (fd_open(bs) < 0) {
return NULL; return NULL;
} }
return paio_submit(bs, s->fd, offset, NULL, count, return paio_submit(bs, s->fd, offset, NULL, bytes,
cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV); cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
} }
static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int count, BdrvRequestFlags flags) int64_t offset, int bytes, BdrvRequestFlags flags)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
int rc; int rc;
...@@ -2583,10 +2583,10 @@ static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -2583,10 +2583,10 @@ static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs,
return rc; return rc;
} }
if (!(flags & BDRV_REQ_MAY_UNMAP)) { if (!(flags & BDRV_REQ_MAY_UNMAP)) {
return paio_submit_co(bs, s->fd, offset, NULL, count, return paio_submit_co(bs, s->fd, offset, NULL, bytes,
QEMU_AIO_WRITE_ZEROES|QEMU_AIO_BLKDEV); QEMU_AIO_WRITE_ZEROES|QEMU_AIO_BLKDEV);
} else if (s->discard_zeroes) { } else if (s->discard_zeroes) {
return paio_submit_co(bs, s->fd, offset, NULL, count, return paio_submit_co(bs, s->fd, offset, NULL, bytes,
QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV); QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
} }
return -ENOTSUP; return -ENOTSUP;
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */ #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */
static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int count, BdrvRequestFlags flags); int64_t offset, int bytes, BdrvRequestFlags flags);
void bdrv_parent_drained_begin(BlockDriverState *bs) void bdrv_parent_drained_begin(BlockDriverState *bs)
{ {
...@@ -666,12 +666,12 @@ int bdrv_write(BdrvChild *child, int64_t sector_num, ...@@ -666,12 +666,12 @@ int bdrv_write(BdrvChild *child, int64_t sector_num,
} }
int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
int count, BdrvRequestFlags flags) int bytes, BdrvRequestFlags flags)
{ {
QEMUIOVector qiov; QEMUIOVector qiov;
struct iovec iov = { struct iovec iov = {
.iov_base = NULL, .iov_base = NULL,
.iov_len = count, .iov_len = bytes,
}; };
qemu_iovec_init_external(&qiov, &iov, 1); qemu_iovec_init_external(&qiov, &iov, 1);
...@@ -1212,7 +1212,7 @@ int coroutine_fn bdrv_co_readv(BdrvChild *child, int64_t sector_num, ...@@ -1212,7 +1212,7 @@ int coroutine_fn bdrv_co_readv(BdrvChild *child, int64_t sector_num,
#define MAX_WRITE_ZEROES_BOUNCE_BUFFER (32768 << BDRV_SECTOR_BITS) #define MAX_WRITE_ZEROES_BOUNCE_BUFFER (32768 << BDRV_SECTOR_BITS)
static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int count, BdrvRequestFlags flags) int64_t offset, int bytes, BdrvRequestFlags flags)
{ {
BlockDriver *drv = bs->drv; BlockDriver *drv = bs->drv;
QEMUIOVector qiov; QEMUIOVector qiov;
...@@ -1230,12 +1230,12 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, ...@@ -1230,12 +1230,12 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
assert(alignment % bs->bl.request_alignment == 0); assert(alignment % bs->bl.request_alignment == 0);
head = offset % alignment; head = offset % alignment;
tail = (offset + count) % alignment; tail = (offset + bytes) % alignment;
max_write_zeroes = QEMU_ALIGN_DOWN(max_write_zeroes, alignment); max_write_zeroes = QEMU_ALIGN_DOWN(max_write_zeroes, alignment);
assert(max_write_zeroes >= bs->bl.request_alignment); assert(max_write_zeroes >= bs->bl.request_alignment);
while (count > 0 && !ret) { while (bytes > 0 && !ret) {
int num = count; int num = bytes;
/* Align request. Block drivers can expect the "bulk" of the request /* Align request. Block drivers can expect the "bulk" of the request
* to be aligned, and that unaligned requests do not cross cluster * to be aligned, and that unaligned requests do not cross cluster
...@@ -1245,7 +1245,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, ...@@ -1245,7 +1245,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
/* Make a small request up to the first aligned sector. For /* Make a small request up to the first aligned sector. For
* convenience, limit this request to max_transfer even if * convenience, limit this request to max_transfer even if
* we don't need to fall back to writes. */ * we don't need to fall back to writes. */
num = MIN(MIN(count, max_transfer), alignment - head); num = MIN(MIN(bytes, max_transfer), alignment - head);
head = (head + num) % alignment; head = (head + num) % alignment;
assert(num < max_write_zeroes); assert(num < max_write_zeroes);
} else if (tail && num > alignment) { } else if (tail && num > alignment) {
...@@ -1306,7 +1306,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, ...@@ -1306,7 +1306,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
} }
offset += num; offset += num;
count -= num; bytes -= num;
} }
fail: fail:
...@@ -1658,15 +1658,15 @@ int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num, ...@@ -1658,15 +1658,15 @@ int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num,
} }
int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset,
int count, BdrvRequestFlags flags) int bytes, BdrvRequestFlags flags)
{ {
trace_bdrv_co_pwrite_zeroes(child->bs, offset, count, flags); trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags);
if (!(child->bs->open_flags & BDRV_O_UNMAP)) { if (!(child->bs->open_flags & BDRV_O_UNMAP)) {
flags &= ~BDRV_REQ_MAY_UNMAP; flags &= ~BDRV_REQ_MAY_UNMAP;
} }
return bdrv_co_pwritev(child, offset, count, NULL, return bdrv_co_pwritev(child, offset, bytes, NULL,
BDRV_REQ_ZERO_WRITE | flags); BDRV_REQ_ZERO_WRITE | flags);
} }
...@@ -2248,18 +2248,18 @@ int bdrv_flush(BlockDriverState *bs) ...@@ -2248,18 +2248,18 @@ int bdrv_flush(BlockDriverState *bs)
typedef struct DiscardCo { typedef struct DiscardCo {
BlockDriverState *bs; BlockDriverState *bs;
int64_t offset; int64_t offset;
int count; int bytes;
int ret; int ret;
} DiscardCo; } DiscardCo;
static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque)
{ {
DiscardCo *rwco = opaque; DiscardCo *rwco = opaque;
rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->count); rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->bytes);
} }
int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
int count) int bytes)
{ {
BdrvTrackedRequest req; BdrvTrackedRequest req;
int max_pdiscard, ret; int max_pdiscard, ret;
...@@ -2269,7 +2269,7 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, ...@@ -2269,7 +2269,7 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
return -ENOMEDIUM; return -ENOMEDIUM;
} }
ret = bdrv_check_byte_request(bs, offset, count); ret = bdrv_check_byte_request(bs, offset, bytes);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} else if (bs->read_only) { } else if (bs->read_only) {
...@@ -2294,10 +2294,10 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, ...@@ -2294,10 +2294,10 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
align = MAX(bs->bl.pdiscard_alignment, bs->bl.request_alignment); align = MAX(bs->bl.pdiscard_alignment, bs->bl.request_alignment);
assert(align % bs->bl.request_alignment == 0); assert(align % bs->bl.request_alignment == 0);
head = offset % align; head = offset % align;
tail = (offset + count) % align; tail = (offset + bytes) % align;
bdrv_inc_in_flight(bs); bdrv_inc_in_flight(bs);
tracked_request_begin(&req, bs, offset, count, BDRV_TRACKED_DISCARD); tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_DISCARD);
ret = notifier_with_return_list_notify(&bs->before_write_notifiers, &req); ret = notifier_with_return_list_notify(&bs->before_write_notifiers, &req);
if (ret < 0) { if (ret < 0) {
...@@ -2308,13 +2308,13 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, ...@@ -2308,13 +2308,13 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
align); align);
assert(max_pdiscard >= bs->bl.request_alignment); assert(max_pdiscard >= bs->bl.request_alignment);
while (count > 0) { while (bytes > 0) {
int ret; int ret;
int num = count; int num = bytes;
if (head) { if (head) {
/* Make small requests to get to alignment boundaries. */ /* Make small requests to get to alignment boundaries. */
num = MIN(count, align - head); num = MIN(bytes, align - head);
if (!QEMU_IS_ALIGNED(num, bs->bl.request_alignment)) { if (!QEMU_IS_ALIGNED(num, bs->bl.request_alignment)) {
num %= bs->bl.request_alignment; num %= bs->bl.request_alignment;
} }
...@@ -2358,7 +2358,7 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, ...@@ -2358,7 +2358,7 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
} }
offset += num; offset += num;
count -= num; bytes -= num;
} }
ret = 0; ret = 0;
out: out:
...@@ -2370,13 +2370,13 @@ out: ...@@ -2370,13 +2370,13 @@ out:
return ret; return ret;
} }
int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count) int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
{ {
Coroutine *co; Coroutine *co;
DiscardCo rwco = { DiscardCo rwco = {
.bs = bs, .bs = bs,
.offset = offset, .offset = offset,
.count = count, .bytes = bytes,
.ret = NOT_DONE, .ret = NOT_DONE,
}; };
......
...@@ -1116,14 +1116,14 @@ iscsi_getlength(BlockDriverState *bs) ...@@ -1116,14 +1116,14 @@ iscsi_getlength(BlockDriverState *bs)
} }
static int static int
coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
{ {
IscsiLun *iscsilun = bs->opaque; IscsiLun *iscsilun = bs->opaque;
struct IscsiTask iTask; struct IscsiTask iTask;
struct unmap_list list; struct unmap_list list;
int r = 0; int r = 0;
if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) {
return -ENOTSUP; return -ENOTSUP;
} }
...@@ -1133,7 +1133,7 @@ coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) ...@@ -1133,7 +1133,7 @@ coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count)
} }
list.lba = offset / iscsilun->block_size; list.lba = offset / iscsilun->block_size;
list.num = count / iscsilun->block_size; list.num = bytes / iscsilun->block_size;
iscsi_co_init_iscsitask(iscsilun, &iTask); iscsi_co_init_iscsitask(iscsilun, &iTask);
qemu_mutex_lock(&iscsilun->mutex); qemu_mutex_lock(&iscsilun->mutex);
...@@ -1174,7 +1174,7 @@ retry: ...@@ -1174,7 +1174,7 @@ retry:
} }
iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS); bytes >> BDRV_SECTOR_BITS);
out_unlock: out_unlock:
qemu_mutex_unlock(&iscsilun->mutex); qemu_mutex_unlock(&iscsilun->mutex);
...@@ -1183,7 +1183,7 @@ out_unlock: ...@@ -1183,7 +1183,7 @@ out_unlock:
static int static int
coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
int count, BdrvRequestFlags flags) int bytes, BdrvRequestFlags flags)
{ {
IscsiLun *iscsilun = bs->opaque; IscsiLun *iscsilun = bs->opaque;
struct IscsiTask iTask; struct IscsiTask iTask;
...@@ -1192,7 +1192,7 @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, ...@@ -1192,7 +1192,7 @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
bool use_16_for_ws = iscsilun->use_16_for_rw; bool use_16_for_ws = iscsilun->use_16_for_rw;
int r = 0; int r = 0;
if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) {
return -ENOTSUP; return -ENOTSUP;
} }
...@@ -1215,7 +1215,7 @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, ...@@ -1215,7 +1215,7 @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
} }
lba = offset / iscsilun->block_size; lba = offset / iscsilun->block_size;
nb_blocks = count / iscsilun->block_size; nb_blocks = bytes / iscsilun->block_size;
if (iscsilun->zeroblock == NULL) { if (iscsilun->zeroblock == NULL) {
iscsilun->zeroblock = g_try_malloc0(iscsilun->block_size); iscsilun->zeroblock = g_try_malloc0(iscsilun->block_size);
...@@ -1273,17 +1273,17 @@ retry: ...@@ -1273,17 +1273,17 @@ retry:
if (iTask.status != SCSI_STATUS_GOOD) { if (iTask.status != SCSI_STATUS_GOOD) {
iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS); bytes >> BDRV_SECTOR_BITS);
r = iTask.err_code; r = iTask.err_code;
goto out_unlock; goto out_unlock;
} }
if (flags & BDRV_REQ_MAY_UNMAP) { if (flags & BDRV_REQ_MAY_UNMAP) {
iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS); bytes >> BDRV_SECTOR_BITS);
} else { } else {
iscsi_allocmap_set_allocated(iscsilun, offset >> BDRV_SECTOR_BITS, iscsi_allocmap_set_allocated(iscsilun, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS); bytes >> BDRV_SECTOR_BITS);
} }
out_unlock: out_unlock:
......
...@@ -1063,15 +1063,15 @@ static int64_t coroutine_fn bdrv_mirror_top_get_block_status( ...@@ -1063,15 +1063,15 @@ static int64_t coroutine_fn bdrv_mirror_top_get_block_status(
} }
static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int count, BdrvRequestFlags flags) int64_t offset, int bytes, BdrvRequestFlags flags)
{ {
return bdrv_co_pwrite_zeroes(bs->backing, offset, count, flags); return bdrv_co_pwrite_zeroes(bs->backing, offset, bytes, flags);
} }
static int coroutine_fn bdrv_mirror_top_pdiscard(BlockDriverState *bs, static int coroutine_fn bdrv_mirror_top_pdiscard(BlockDriverState *bs,
int64_t offset, int count) int64_t offset, int bytes)
{ {
return bdrv_co_pdiscard(bs->backing->bs, offset, count); return bdrv_co_pdiscard(bs->backing->bs, offset, bytes);
} }
static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs, QDict *opts) static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs, QDict *opts)
......
...@@ -259,14 +259,14 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, ...@@ -259,14 +259,14 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
} }
int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
int count, BdrvRequestFlags flags) int bytes, BdrvRequestFlags flags)
{ {
ssize_t ret; ssize_t ret;
NBDClientSession *client = nbd_get_client_session(bs); NBDClientSession *client = nbd_get_client_session(bs);
NBDRequest request = { NBDRequest request = {
.type = NBD_CMD_WRITE_ZEROES, .type = NBD_CMD_WRITE_ZEROES,
.from = offset, .from = offset,
.len = count, .len = bytes,
}; };
NBDReply reply; NBDReply reply;
...@@ -316,13 +316,13 @@ int nbd_client_co_flush(BlockDriverState *bs) ...@@ -316,13 +316,13 @@ int nbd_client_co_flush(BlockDriverState *bs)
return -reply.error; return -reply.error;
} }
int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
{ {
NBDClientSession *client = nbd_get_client_session(bs); NBDClientSession *client = nbd_get_client_session(bs);
NBDRequest request = { NBDRequest request = {
.type = NBD_CMD_TRIM, .type = NBD_CMD_TRIM,
.from = offset, .from = offset,
.len = count, .len = bytes,
}; };
NBDReply reply; NBDReply reply;
ssize_t ret; ssize_t ret;
......
...@@ -42,12 +42,12 @@ int nbd_client_init(BlockDriverState *bs, ...@@ -42,12 +42,12 @@ int nbd_client_init(BlockDriverState *bs,
Error **errp); Error **errp);
void nbd_client_close(BlockDriverState *bs); void nbd_client_close(BlockDriverState *bs);
int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int count); int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
int nbd_client_co_flush(BlockDriverState *bs); int nbd_client_co_flush(BlockDriverState *bs);
int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
uint64_t bytes, QEMUIOVector *qiov, int flags); uint64_t bytes, QEMUIOVector *qiov, int flags);
int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
int count, BdrvRequestFlags flags); int bytes, BdrvRequestFlags flags);
int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
uint64_t bytes, QEMUIOVector *qiov, int flags); uint64_t bytes, QEMUIOVector *qiov, int flags);
......
...@@ -2508,16 +2508,16 @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start, ...@@ -2508,16 +2508,16 @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start,
} }
static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int count, BdrvRequestFlags flags) int64_t offset, int bytes, BdrvRequestFlags flags)
{ {
int ret; int ret;
BDRVQcow2State *s = bs->opaque; BDRVQcow2State *s = bs->opaque;
uint32_t head = offset % s->cluster_size; uint32_t head = offset % s->cluster_size;
uint32_t tail = (offset + count) % s->cluster_size; uint32_t tail = (offset + bytes) % s->cluster_size;
trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, count); trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, bytes);
if (offset + count == bs->total_sectors * BDRV_SECTOR_SIZE) { if (offset + bytes == bs->total_sectors * BDRV_SECTOR_SIZE) {
tail = 0; tail = 0;
} }
...@@ -2526,12 +2526,12 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -2526,12 +2526,12 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
uint64_t off; uint64_t off;
unsigned int nr; unsigned int nr;
assert(head + count <= s->cluster_size); assert(head + bytes <= s->cluster_size);
/* check whether remainder of cluster already reads as zero */ /* check whether remainder of cluster already reads as zero */
if (!(is_zero_sectors(bs, cl_start, if (!(is_zero_sectors(bs, cl_start,
DIV_ROUND_UP(head, BDRV_SECTOR_SIZE)) && DIV_ROUND_UP(head, BDRV_SECTOR_SIZE)) &&
is_zero_sectors(bs, (offset + count) >> BDRV_SECTOR_BITS, is_zero_sectors(bs, (offset + bytes) >> BDRV_SECTOR_BITS,
DIV_ROUND_UP(-tail & (s->cluster_size - 1), DIV_ROUND_UP(-tail & (s->cluster_size - 1),
BDRV_SECTOR_SIZE)))) { BDRV_SECTOR_SIZE)))) {
return -ENOTSUP; return -ENOTSUP;
...@@ -2540,7 +2540,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -2540,7 +2540,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
qemu_co_mutex_lock(&s->lock); qemu_co_mutex_lock(&s->lock);
/* We can have new write after previous check */ /* We can have new write after previous check */
offset = cl_start << BDRV_SECTOR_BITS; offset = cl_start << BDRV_SECTOR_BITS;
count = s->cluster_size; bytes = s->cluster_size;
nr = s->cluster_size; nr = s->cluster_size;
ret = qcow2_get_cluster_offset(bs, offset, &nr, &off); ret = qcow2_get_cluster_offset(bs, offset, &nr, &off);
if (ret != QCOW2_CLUSTER_UNALLOCATED && if (ret != QCOW2_CLUSTER_UNALLOCATED &&
...@@ -2553,33 +2553,33 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -2553,33 +2553,33 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
qemu_co_mutex_lock(&s->lock); qemu_co_mutex_lock(&s->lock);
} }
trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, count); trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, bytes);
/* Whatever is left can use real zero clusters */ /* Whatever is left can use real zero clusters */
ret = qcow2_cluster_zeroize(bs, offset, count, flags); ret = qcow2_cluster_zeroize(bs, offset, bytes, flags);
qemu_co_mutex_unlock(&s->lock); qemu_co_mutex_unlock(&s->lock);
return ret; return ret;
} }
static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs, static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,
int64_t offset, int count) int64_t offset, int bytes)
{ {
int ret; int ret;
BDRVQcow2State *s = bs->opaque; BDRVQcow2State *s = bs->opaque;
if (!QEMU_IS_ALIGNED(offset | count, s->cluster_size)) { if (!QEMU_IS_ALIGNED(offset | bytes, s->cluster_size)) {
assert(count < s->cluster_size); assert(bytes < s->cluster_size);
/* Ignore partial clusters, except for the special case of the /* Ignore partial clusters, except for the special case of the
* complete partial cluster at the end of an unaligned file */ * complete partial cluster at the end of an unaligned file */
if (!QEMU_IS_ALIGNED(offset, s->cluster_size) || if (!QEMU_IS_ALIGNED(offset, s->cluster_size) ||
offset + count != bs->total_sectors * BDRV_SECTOR_SIZE) { offset + bytes != bs->total_sectors * BDRV_SECTOR_SIZE) {
return -ENOTSUP; return -ENOTSUP;
} }
} }
qemu_co_mutex_lock(&s->lock); qemu_co_mutex_lock(&s->lock);
ret = qcow2_cluster_discard(bs, offset, count, QCOW2_DISCARD_REQUEST, ret = qcow2_cluster_discard(bs, offset, bytes, QCOW2_DISCARD_REQUEST,
false); false);
qemu_co_mutex_unlock(&s->lock); qemu_co_mutex_unlock(&s->lock);
return ret; return ret;
......
...@@ -1317,7 +1317,7 @@ static int coroutine_fn bdrv_qed_co_writev(BlockDriverState *bs, ...@@ -1317,7 +1317,7 @@ static int coroutine_fn bdrv_qed_co_writev(BlockDriverState *bs,
static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int64_t offset,
int count, int bytes,
BdrvRequestFlags flags) BdrvRequestFlags flags)
{ {
BDRVQEDState *s = bs->opaque; BDRVQEDState *s = bs->opaque;
...@@ -1326,7 +1326,7 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -1326,7 +1326,7 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
/* Fall back if the request is not aligned */ /* Fall back if the request is not aligned */
if (qed_offset_into_cluster(s, offset) || if (qed_offset_into_cluster(s, offset) ||
qed_offset_into_cluster(s, count)) { qed_offset_into_cluster(s, bytes)) {
return -ENOTSUP; return -ENOTSUP;
} }
...@@ -1334,11 +1334,11 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -1334,11 +1334,11 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
* then it will be allocated during request processing. * then it will be allocated during request processing.
*/ */
iov.iov_base = NULL; iov.iov_base = NULL;
iov.iov_len = count; iov.iov_len = bytes;
qemu_iovec_init_external(&qiov, &iov, 1); qemu_iovec_init_external(&qiov, &iov, 1);
return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov, return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov,
count >> BDRV_SECTOR_BITS, bytes >> BDRV_SECTOR_BITS,
QED_AIOCB_WRITE | QED_AIOCB_ZERO); QED_AIOCB_WRITE | QED_AIOCB_ZERO);
} }
......
...@@ -264,7 +264,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, ...@@ -264,7 +264,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
} }
static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs,
int64_t offset, int count, int64_t offset, int bytes,
BdrvRequestFlags flags) BdrvRequestFlags flags)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
...@@ -272,18 +272,18 @@ static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, ...@@ -272,18 +272,18 @@ static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs,
return -EINVAL; return -EINVAL;
} }
offset += s->offset; offset += s->offset;
return bdrv_co_pwrite_zeroes(bs->file, offset, count, flags); return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags);
} }
static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs, static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs,
int64_t offset, int count) int64_t offset, int bytes)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
if (offset > UINT64_MAX - s->offset) { if (offset > UINT64_MAX - s->offset) {
return -EINVAL; return -EINVAL;
} }
offset += s->offset; offset += s->offset;
return bdrv_co_pdiscard(bs->file->bs, offset, count); return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
} }
static int64_t raw_getlength(BlockDriverState *bs) static int64_t raw_getlength(BlockDriverState *bs)
......
...@@ -1065,11 +1065,11 @@ static int qemu_rbd_snap_list(BlockDriverState *bs, ...@@ -1065,11 +1065,11 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
#ifdef LIBRBD_SUPPORTS_DISCARD #ifdef LIBRBD_SUPPORTS_DISCARD
static BlockAIOCB *qemu_rbd_aio_pdiscard(BlockDriverState *bs, static BlockAIOCB *qemu_rbd_aio_pdiscard(BlockDriverState *bs,
int64_t offset, int64_t offset,
int count, int bytes,
BlockCompletionFunc *cb, BlockCompletionFunc *cb,
void *opaque) void *opaque)
{ {
return rbd_start_aio(bs, offset, NULL, count, cb, opaque, return rbd_start_aio(bs, offset, NULL, bytes, cb, opaque,
RBD_AIO_DISCARD); RBD_AIO_DISCARD);
} }
#endif #endif
......
...@@ -2935,7 +2935,7 @@ static int sd_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, ...@@ -2935,7 +2935,7 @@ static int sd_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset,
int count) int bytes)
{ {
SheepdogAIOCB acb; SheepdogAIOCB acb;
BDRVSheepdogState *s = bs->opaque; BDRVSheepdogState *s = bs->opaque;
...@@ -2953,11 +2953,11 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, ...@@ -2953,11 +2953,11 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset,
iov.iov_len = sizeof(zero); iov.iov_len = sizeof(zero);
discard_iov.iov = &iov; discard_iov.iov = &iov;
discard_iov.niov = 1; discard_iov.niov = 1;
if (!QEMU_IS_ALIGNED(offset | count, BDRV_SECTOR_SIZE)) { if (!QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)) {
return -ENOTSUP; return -ENOTSUP;
} }
sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS, sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ); bytes >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ);
sd_co_rw_vector(&acb); sd_co_rw_vector(&acb);
sd_aio_complete(&acb); sd_aio_complete(&acb);
......
...@@ -276,7 +276,7 @@ int bdrv_read(BdrvChild *child, int64_t sector_num, ...@@ -276,7 +276,7 @@ int bdrv_read(BdrvChild *child, int64_t sector_num,
int bdrv_write(BdrvChild *child, int64_t sector_num, int bdrv_write(BdrvChild *child, int64_t sector_num,
const uint8_t *buf, int nb_sectors); const uint8_t *buf, int nb_sectors);
int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
int count, BdrvRequestFlags flags); int bytes, BdrvRequestFlags flags);
int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags);
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes); int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes);
int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov);
...@@ -295,7 +295,7 @@ int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num, ...@@ -295,7 +295,7 @@ int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num,
* because it may allocate memory for the entire region. * because it may allocate memory for the entire region.
*/ */
int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset,
int count, BdrvRequestFlags flags); int bytes, BdrvRequestFlags flags);
BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
const char *backing_file); const char *backing_file);
int bdrv_get_backing_file_depth(BlockDriverState *bs); int bdrv_get_backing_file_depth(BlockDriverState *bs);
...@@ -411,8 +411,8 @@ void bdrv_drain_all(void); ...@@ -411,8 +411,8 @@ void bdrv_drain_all(void);
} \ } \
waited_; }) waited_; })
int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count); int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int count); int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init_1(BlockDriverState *bs);
int bdrv_has_zero_init(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs);
bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs);
......
...@@ -142,7 +142,7 @@ struct BlockDriver { ...@@ -142,7 +142,7 @@ struct BlockDriver {
BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
BlockCompletionFunc *cb, void *opaque); BlockCompletionFunc *cb, void *opaque);
BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs, BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs,
int64_t offset, int count, int64_t offset, int bytes,
BlockCompletionFunc *cb, void *opaque); BlockCompletionFunc *cb, void *opaque);
int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs,
...@@ -163,9 +163,9 @@ struct BlockDriver { ...@@ -163,9 +163,9 @@ struct BlockDriver {
* will be called instead. * will be called instead.
*/ */
int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs, int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs,
int64_t offset, int count, BdrvRequestFlags flags); int64_t offset, int bytes, BdrvRequestFlags flags);
int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs, int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs,
int64_t offset, int count); int64_t offset, int bytes);
/* /*
* Building block for bdrv_block_status[_above]. The driver should * Building block for bdrv_block_status[_above]. The driver should
......
...@@ -130,7 +130,7 @@ BlockBackend *blk_by_dev(void *dev); ...@@ -130,7 +130,7 @@ BlockBackend *blk_by_dev(void *dev);
BlockBackend *blk_by_qdev_id(const char *id, Error **errp); BlockBackend *blk_by_qdev_id(const char *id, Error **errp);
void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque); void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf, int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf,
int count); int bytes);
int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
unsigned int bytes, QEMUIOVector *qiov, unsigned int bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags); BdrvRequestFlags flags);
...@@ -138,13 +138,13 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, ...@@ -138,13 +138,13 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
unsigned int bytes, QEMUIOVector *qiov, unsigned int bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags); BdrvRequestFlags flags);
int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int count, BdrvRequestFlags flags); int bytes, BdrvRequestFlags flags);
BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset, BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int count, BdrvRequestFlags flags, int bytes, BdrvRequestFlags flags,
BlockCompletionFunc *cb, void *opaque); BlockCompletionFunc *cb, void *opaque);
int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags); int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags);
int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count); int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes);
int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count, int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes,
BdrvRequestFlags flags); BdrvRequestFlags flags);
int64_t blk_getlength(BlockBackend *blk); int64_t blk_getlength(BlockBackend *blk);
void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr); void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
...@@ -157,7 +157,7 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, ...@@ -157,7 +157,7 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
BlockCompletionFunc *cb, void *opaque); BlockCompletionFunc *cb, void *opaque);
BlockAIOCB *blk_aio_flush(BlockBackend *blk, BlockAIOCB *blk_aio_flush(BlockBackend *blk,
BlockCompletionFunc *cb, void *opaque); BlockCompletionFunc *cb, void *opaque);
BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int count, BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes,
BlockCompletionFunc *cb, void *opaque); BlockCompletionFunc *cb, void *opaque);
void blk_aio_cancel(BlockAIOCB *acb); void blk_aio_cancel(BlockAIOCB *acb);
void blk_aio_cancel_async(BlockAIOCB *acb); void blk_aio_cancel_async(BlockAIOCB *acb);
...@@ -165,7 +165,7 @@ int blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf); ...@@ -165,7 +165,7 @@ int blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf, BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
BlockCompletionFunc *cb, void *opaque); BlockCompletionFunc *cb, void *opaque);
int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int count); int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes);
int blk_co_flush(BlockBackend *blk); int blk_co_flush(BlockBackend *blk);
int blk_flush(BlockBackend *blk); int blk_flush(BlockBackend *blk);
int blk_commit_all(void); int blk_commit_all(void);
...@@ -220,11 +220,11 @@ int blk_get_open_flags_from_root_state(BlockBackend *blk); ...@@ -220,11 +220,11 @@ int blk_get_open_flags_from_root_state(BlockBackend *blk);
void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk, void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
BlockCompletionFunc *cb, void *opaque); BlockCompletionFunc *cb, void *opaque);
int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int count, BdrvRequestFlags flags); int bytes, BdrvRequestFlags flags);
int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf, int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
int count); int bytes);
int blk_truncate(BlockBackend *blk, int64_t offset, Error **errp); int blk_truncate(BlockBackend *blk, int64_t offset, Error **errp);
int blk_pdiscard(BlockBackend *blk, int64_t offset, int count); int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes);
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
int64_t pos, int size); int64_t pos, int size);
int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size); int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size);
......
...@@ -451,13 +451,13 @@ fail: ...@@ -451,13 +451,13 @@ fail:
} }
static int do_pread(BlockBackend *blk, char *buf, int64_t offset, static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
int64_t count, int64_t *total) int64_t bytes, int64_t *total)
{ {
if (count > INT_MAX) { if (bytes > INT_MAX) {
return -ERANGE; return -ERANGE;
} }
*total = blk_pread(blk, offset, (uint8_t *)buf, count); *total = blk_pread(blk, offset, (uint8_t *)buf, bytes);
if (*total < 0) { if (*total < 0) {
return *total; return *total;
} }
...@@ -465,13 +465,13 @@ static int do_pread(BlockBackend *blk, char *buf, int64_t offset, ...@@ -465,13 +465,13 @@ static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
} }
static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset, static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
int64_t count, int flags, int64_t *total) int64_t bytes, int flags, int64_t *total)
{ {
if (count > INT_MAX) { if (bytes > INT_MAX) {
return -ERANGE; return -ERANGE;
} }
*total = blk_pwrite(blk, offset, (uint8_t *)buf, count, flags); *total = blk_pwrite(blk, offset, (uint8_t *)buf, bytes, flags);
if (*total < 0) { if (*total < 0) {
return *total; return *total;
} }
...@@ -481,7 +481,7 @@ static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset, ...@@ -481,7 +481,7 @@ static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
typedef struct { typedef struct {
BlockBackend *blk; BlockBackend *blk;
int64_t offset; int64_t offset;
int64_t count; int64_t bytes;
int64_t *total; int64_t *total;
int flags; int flags;
int ret; int ret;
...@@ -492,7 +492,7 @@ static void coroutine_fn co_pwrite_zeroes_entry(void *opaque) ...@@ -492,7 +492,7 @@ static void coroutine_fn co_pwrite_zeroes_entry(void *opaque)
{ {
CoWriteZeroes *data = opaque; CoWriteZeroes *data = opaque;
data->ret = blk_co_pwrite_zeroes(data->blk, data->offset, data->count, data->ret = blk_co_pwrite_zeroes(data->blk, data->offset, data->bytes,
data->flags); data->flags);
data->done = true; data->done = true;
if (data->ret < 0) { if (data->ret < 0) {
...@@ -500,23 +500,23 @@ static void coroutine_fn co_pwrite_zeroes_entry(void *opaque) ...@@ -500,23 +500,23 @@ static void coroutine_fn co_pwrite_zeroes_entry(void *opaque)
return; return;
} }
*data->total = data->count; *data->total = data->bytes;
} }
static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int64_t count, int flags, int64_t *total) int64_t bytes, int flags, int64_t *total)
{ {
Coroutine *co; Coroutine *co;
CoWriteZeroes data = { CoWriteZeroes data = {
.blk = blk, .blk = blk,
.offset = offset, .offset = offset,
.count = count, .bytes = bytes,
.total = total, .total = total,
.flags = flags, .flags = flags,
.done = false, .done = false,
}; };
if (count > INT_MAX) { if (bytes > INT_MAX) {
return -ERANGE; return -ERANGE;
} }
...@@ -533,19 +533,19 @@ static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, ...@@ -533,19 +533,19 @@ static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
} }
static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset, static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset,
int64_t count, int64_t *total) int64_t bytes, int64_t *total)
{ {
int ret; int ret;
if (count >> 9 > BDRV_REQUEST_MAX_SECTORS) { if (bytes >> 9 > BDRV_REQUEST_MAX_SECTORS) {
return -ERANGE; return -ERANGE;
} }
ret = blk_pwrite_compressed(blk, offset, buf, count); ret = blk_pwrite_compressed(blk, offset, buf, bytes);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
*total = count; *total = bytes;
return 1; return 1;
} }
...@@ -1701,7 +1701,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) ...@@ -1701,7 +1701,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv)
struct timeval t1, t2; struct timeval t1, t2;
bool Cflag = false, qflag = false; bool Cflag = false, qflag = false;
int c, ret; int c, ret;
int64_t offset, count; int64_t offset, bytes;
while ((c = getopt(argc, argv, "Cq")) != -1) { while ((c = getopt(argc, argv, "Cq")) != -1) {
switch (c) { switch (c) {
...@@ -1727,11 +1727,11 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) ...@@ -1727,11 +1727,11 @@ static int discard_f(BlockBackend *blk, int argc, char **argv)
} }
optind++; optind++;
count = cvtnum(argv[optind]); bytes = cvtnum(argv[optind]);
if (count < 0) { if (bytes < 0) {
print_cvtnum_err(count, argv[optind]); print_cvtnum_err(bytes, argv[optind]);
return 0; return 0;
} else if (count >> BDRV_SECTOR_BITS > BDRV_REQUEST_MAX_SECTORS) { } else if (bytes >> BDRV_SECTOR_BITS > BDRV_REQUEST_MAX_SECTORS) {
printf("length cannot exceed %"PRIu64", given %s\n", printf("length cannot exceed %"PRIu64", given %s\n",
(uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS, (uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS,
argv[optind]); argv[optind]);
...@@ -1739,7 +1739,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) ...@@ -1739,7 +1739,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv)
} }
gettimeofday(&t1, NULL); gettimeofday(&t1, NULL);
ret = blk_pdiscard(blk, offset, count); ret = blk_pdiscard(blk, offset, bytes);
gettimeofday(&t2, NULL); gettimeofday(&t2, NULL);
if (ret < 0) { if (ret < 0) {
...@@ -1750,7 +1750,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) ...@@ -1750,7 +1750,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv)
/* Finally, report back -- -C gives a parsable format */ /* Finally, report back -- -C gives a parsable format */
if (!qflag) { if (!qflag) {
t2 = tsub(t2, t1); t2 = tsub(t2, t1);
print_report("discard", &t2, offset, count, count, 1, Cflag); print_report("discard", &t2, offset, bytes, bytes, 1, Cflag);
} }
out: out:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册