From f5a5ca796932d04cb2a1cb9382a55f72795b3e06 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 9 Jun 2017 13:18:08 +0300 Subject: [PATCH 1/6] 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: Manos Pitsidianakis Message-id: 20170609101808.13506-1-el13635@mail.ntua.gr Reviewed-by: Stefan Hajnoczi Signed-off-by: Max Reitz --- block/blkdebug.c | 36 ++++++++++++------------- block/blkreplay.c | 8 +++--- block/block-backend.c | 22 ++++++++-------- block/file-posix.c | 34 ++++++++++++------------ block/io.c | 48 +++++++++++++++++----------------- block/iscsi.c | 20 +++++++------- block/mirror.c | 8 +++--- block/nbd-client.c | 8 +++--- block/nbd-client.h | 4 +-- block/qcow2.c | 28 ++++++++++---------- block/qed.c | 8 +++--- block/raw-format.c | 8 +++--- block/rbd.c | 4 +-- block/sheepdog.c | 6 ++--- include/block/block.h | 8 +++--- include/block/block_int.h | 6 ++--- include/sysemu/block-backend.h | 20 +++++++------- qemu-io-cmds.c | 46 ++++++++++++++++---------------- 18 files changed, 161 insertions(+), 161 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 0618fc71c6..6431962d7e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -575,7 +575,7 @@ static int blkdebug_co_flush(BlockDriverState *bs) } static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int count, + int64_t offset, int bytes, BdrvRequestFlags flags) { uint32_t align = MAX(bs->bl.request_alignment, @@ -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 * unaligned portions), and check that the block layer never hands * us anything unaligned that crosses an alignment boundary. */ - if (count < align) { + if (bytes < 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 + count, align)); + DIV_ROUND_UP(offset + bytes, align)); return -ENOTSUP; } assert(QEMU_IS_ALIGNED(offset, align)); - assert(QEMU_IS_ALIGNED(count, align)); + assert(QEMU_IS_ALIGNED(bytes, align)); 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) { 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, - int64_t offset, int count) + int64_t offset, int bytes) { uint32_t align = bs->bl.pdiscard_alignment; int err; @@ -616,29 +616,29 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs, /* Only pass through requests that are larger than requested * minimum alignment, and ensure that unaligned requests do not * cross optimum discard boundaries. */ - if (count < bs->bl.request_alignment) { + if (bytes < bs->bl.request_alignment) { 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 + count, align)); + DIV_ROUND_UP(offset + bytes, align)); return -ENOTSUP; } assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)); - assert(QEMU_IS_ALIGNED(count, bs->bl.request_alignment)); - if (align && count >= align) { + assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment)); + if (align && bytes >= align) { assert(QEMU_IS_ALIGNED(offset, align)); - assert(QEMU_IS_ALIGNED(count, align)); + assert(QEMU_IS_ALIGNED(bytes, align)); } 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) { 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) diff --git a/block/blkreplay.c b/block/blkreplay.c index 6aa5fd4156..61e44a1949 100755 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -96,10 +96,10 @@ static int coroutine_fn blkreplay_co_pwritev(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(); - 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()); qemu_coroutine_yield(); @@ -107,10 +107,10 @@ static int coroutine_fn blkreplay_co_pwrite_zeroes(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(); - 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()); qemu_coroutine_yield(); diff --git a/block/block-backend.c b/block/block-backend.c index a2bbae90b1..0df3457a09 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -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 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); } @@ -1311,10 +1311,10 @@ static void blk_aio_pdiscard_entry(void *opaque) } BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, - int64_t offset, int count, + int64_t offset, int bytes, 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); } @@ -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); } -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) { 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) @@ -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 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); } @@ -1789,9 +1789,9 @@ static void blk_pdiscard_entry(void *opaque) 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, diff --git a/block/file-posix.c b/block/file-posix.c index de2d3a2e3c..3927fabf06 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1485,7 +1485,7 @@ static int aio_worker(void *arg) static int paio_submit_co(BlockDriverState *bs, int fd, int64_t offset, QEMUIOVector *qiov, - int count, int type) + int bytes, int type) { RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); ThreadPool *pool; @@ -1494,22 +1494,22 @@ static int paio_submit_co(BlockDriverState *bs, int fd, acb->aio_type = type; acb->aio_fildes = fd; - acb->aio_nbytes = count; + acb->aio_nbytes = bytes; acb->aio_offset = offset; if (qiov) { acb->aio_iov = qiov->iov; 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)); return thread_pool_submit_co(pool, aio_worker, acb); } 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) { RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); @@ -1519,7 +1519,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd, acb->aio_type = type; acb->aio_fildes = fd; - acb->aio_nbytes = count; + acb->aio_nbytes = bytes; acb->aio_offset = offset; if (qiov) { @@ -1528,7 +1528,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd, 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)); 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, } static coroutine_fn BlockAIOCB *raw_aio_pdiscard(BlockDriverState *bs, - int64_t offset, int count, + int64_t offset, int bytes, BlockCompletionFunc *cb, void *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); } static int coroutine_fn raw_co_pwrite_zeroes( BlockDriverState *bs, int64_t offset, - int count, BdrvRequestFlags flags) + int bytes, BdrvRequestFlags flags) { BDRVRawState *s = bs->opaque; 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); } 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); } return -ENOTSUP; @@ -2560,7 +2560,7 @@ static int fd_open(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) { BDRVRawState *s = bs->opaque; @@ -2568,12 +2568,12 @@ static coroutine_fn BlockAIOCB *hdev_aio_pdiscard(BlockDriverState *bs, if (fd_open(bs) < 0) { 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); } 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; int rc; @@ -2583,10 +2583,10 @@ static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, return rc; } 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); } 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); } return -ENOTSUP; diff --git a/block/io.c b/block/io.c index 132bcbbd7a..9bba730a7e 100644 --- a/block/io.c +++ b/block/io.c @@ -35,7 +35,7 @@ #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */ 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) { @@ -666,12 +666,12 @@ int bdrv_write(BdrvChild *child, int64_t sector_num, } int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, - int count, BdrvRequestFlags flags) + int bytes, BdrvRequestFlags flags) { QEMUIOVector qiov; struct iovec iov = { .iov_base = NULL, - .iov_len = count, + .iov_len = bytes, }; qemu_iovec_init_external(&qiov, &iov, 1); @@ -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) 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; QEMUIOVector qiov; @@ -1230,12 +1230,12 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, assert(alignment % bs->bl.request_alignment == 0); head = offset % alignment; - tail = (offset + count) % alignment; + tail = (offset + bytes) % alignment; max_write_zeroes = QEMU_ALIGN_DOWN(max_write_zeroes, alignment); assert(max_write_zeroes >= bs->bl.request_alignment); - while (count > 0 && !ret) { - int num = count; + while (bytes > 0 && !ret) { + int num = bytes; /* Align request. Block drivers can expect the "bulk" of the request * 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, /* Make a small request up to the first aligned sector. For * convenience, limit this request to max_transfer even if * 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; assert(num < max_write_zeroes); } else if (tail && num > alignment) { @@ -1306,7 +1306,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, } offset += num; - count -= num; + bytes -= num; } fail: @@ -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 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)) { 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); } @@ -2248,18 +2248,18 @@ int bdrv_flush(BlockDriverState *bs) typedef struct DiscardCo { BlockDriverState *bs; int64_t offset; - int count; + int bytes; int ret; } DiscardCo; static void coroutine_fn bdrv_pdiscard_co_entry(void *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 count) + int bytes) { BdrvTrackedRequest req; int max_pdiscard, ret; @@ -2269,7 +2269,7 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, return -ENOMEDIUM; } - ret = bdrv_check_byte_request(bs, offset, count); + ret = bdrv_check_byte_request(bs, offset, bytes); if (ret < 0) { return ret; } else if (bs->read_only) { @@ -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); assert(align % bs->bl.request_alignment == 0); head = offset % align; - tail = (offset + count) % align; + tail = (offset + bytes) % align; 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); if (ret < 0) { @@ -2308,13 +2308,13 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, align); assert(max_pdiscard >= bs->bl.request_alignment); - while (count > 0) { + while (bytes > 0) { int ret; - int num = count; + int num = bytes; if (head) { /* 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)) { num %= bs->bl.request_alignment; } @@ -2358,7 +2358,7 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, } offset += num; - count -= num; + bytes -= num; } ret = 0; out: @@ -2370,13 +2370,13 @@ out: return ret; } -int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count) +int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { Coroutine *co; DiscardCo rwco = { .bs = bs, .offset = offset, - .count = count, + .bytes = bytes, .ret = NOT_DONE, }; diff --git a/block/iscsi.c b/block/iscsi.c index b5f7a228b9..54067e2620 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1116,14 +1116,14 @@ iscsi_getlength(BlockDriverState *bs) } 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; struct IscsiTask iTask; struct unmap_list list; int r = 0; - if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { + if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) { return -ENOTSUP; } @@ -1133,7 +1133,7 @@ coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) } list.lba = offset / iscsilun->block_size; - list.num = count / iscsilun->block_size; + list.num = bytes / iscsilun->block_size; iscsi_co_init_iscsitask(iscsilun, &iTask); qemu_mutex_lock(&iscsilun->mutex); @@ -1174,7 +1174,7 @@ retry: } iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - count >> BDRV_SECTOR_BITS); + bytes >> BDRV_SECTOR_BITS); out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -1183,7 +1183,7 @@ out_unlock: static int coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, - int count, BdrvRequestFlags flags) + int bytes, BdrvRequestFlags flags) { IscsiLun *iscsilun = bs->opaque; struct IscsiTask iTask; @@ -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; int r = 0; - if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { + if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) { return -ENOTSUP; } @@ -1215,7 +1215,7 @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, } lba = offset / iscsilun->block_size; - nb_blocks = count / iscsilun->block_size; + nb_blocks = bytes / iscsilun->block_size; if (iscsilun->zeroblock == NULL) { iscsilun->zeroblock = g_try_malloc0(iscsilun->block_size); @@ -1273,17 +1273,17 @@ retry: if (iTask.status != SCSI_STATUS_GOOD) { iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - count >> BDRV_SECTOR_BITS); + bytes >> BDRV_SECTOR_BITS); r = iTask.err_code; goto out_unlock; } if (flags & BDRV_REQ_MAY_UNMAP) { iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - count >> BDRV_SECTOR_BITS); + bytes >> BDRV_SECTOR_BITS); } else { iscsi_allocmap_set_allocated(iscsilun, offset >> BDRV_SECTOR_BITS, - count >> BDRV_SECTOR_BITS); + bytes >> BDRV_SECTOR_BITS); } out_unlock: diff --git a/block/mirror.c b/block/mirror.c index 19afcc6f1a..68744a17e8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -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, - 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, - 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) diff --git a/block/nbd-client.c b/block/nbd-client.c index d64e775385..02e928142e 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -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 count, BdrvRequestFlags flags) + int bytes, BdrvRequestFlags flags) { ssize_t ret; NBDClientSession *client = nbd_get_client_session(bs); NBDRequest request = { .type = NBD_CMD_WRITE_ZEROES, .from = offset, - .len = count, + .len = bytes, }; NBDReply reply; @@ -316,13 +316,13 @@ int nbd_client_co_flush(BlockDriverState *bs) 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); NBDRequest request = { .type = NBD_CMD_TRIM, .from = offset, - .len = count, + .len = bytes, }; NBDReply reply; ssize_t ret; diff --git a/block/nbd-client.h b/block/nbd-client.h index 891ba44a20..49636bc621 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -42,12 +42,12 @@ int nbd_client_init(BlockDriverState *bs, Error **errp); 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_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags); 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, uint64_t bytes, QEMUIOVector *qiov, int flags); diff --git a/block/qcow2.c b/block/qcow2.c index 088ffe1673..2f94f0326e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2508,16 +2508,16 @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start, } 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; BDRVQcow2State *s = bs->opaque; 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); - if (offset + count == bs->total_sectors * BDRV_SECTOR_SIZE) { + trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, bytes); + if (offset + bytes == bs->total_sectors * BDRV_SECTOR_SIZE) { tail = 0; } @@ -2526,12 +2526,12 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, uint64_t off; unsigned int nr; - assert(head + count <= s->cluster_size); + assert(head + bytes <= s->cluster_size); /* check whether remainder of cluster already reads as zero */ if (!(is_zero_sectors(bs, cl_start, 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), BDRV_SECTOR_SIZE)))) { return -ENOTSUP; @@ -2540,7 +2540,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, qemu_co_mutex_lock(&s->lock); /* We can have new write after previous check */ offset = cl_start << BDRV_SECTOR_BITS; - count = s->cluster_size; + bytes = s->cluster_size; nr = s->cluster_size; ret = qcow2_get_cluster_offset(bs, offset, &nr, &off); if (ret != QCOW2_CLUSTER_UNALLOCATED && @@ -2553,33 +2553,33 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, 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 */ - ret = qcow2_cluster_zeroize(bs, offset, count, flags); + ret = qcow2_cluster_zeroize(bs, offset, bytes, flags); qemu_co_mutex_unlock(&s->lock); return ret; } static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs, - int64_t offset, int count) + int64_t offset, int bytes) { int ret; BDRVQcow2State *s = bs->opaque; - if (!QEMU_IS_ALIGNED(offset | count, s->cluster_size)) { - assert(count < s->cluster_size); + if (!QEMU_IS_ALIGNED(offset | bytes, s->cluster_size)) { + assert(bytes < s->cluster_size); /* Ignore partial clusters, except for the special case of the * complete partial cluster at the end of an unaligned file */ 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; } } 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); qemu_co_mutex_unlock(&s->lock); return ret; diff --git a/block/qed.c b/block/qed.c index c073baa340..385381a78a 100644 --- a/block/qed.c +++ b/block/qed.c @@ -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, int64_t offset, - int count, + int bytes, BdrvRequestFlags flags) { BDRVQEDState *s = bs->opaque; @@ -1326,7 +1326,7 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, /* Fall back if the request is not aligned */ if (qed_offset_into_cluster(s, offset) || - qed_offset_into_cluster(s, count)) { + qed_offset_into_cluster(s, bytes)) { return -ENOTSUP; } @@ -1334,11 +1334,11 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, * then it will be allocated during request processing. */ iov.iov_base = NULL; - iov.iov_len = count; + iov.iov_len = bytes; qemu_iovec_init_external(&qiov, &iov, 1); return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov, - count >> BDRV_SECTOR_BITS, + bytes >> BDRV_SECTOR_BITS, QED_AIOCB_WRITE | QED_AIOCB_ZERO); } diff --git a/block/raw-format.c b/block/raw-format.c index 36e65036f0..0d185fe41b 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -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, - int64_t offset, int count, + int64_t offset, int bytes, BdrvRequestFlags flags) { BDRVRawState *s = bs->opaque; @@ -272,18 +272,18 @@ static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, return -EINVAL; } 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, - int64_t offset, int count) + int64_t offset, int bytes) { BDRVRawState *s = bs->opaque; if (offset > UINT64_MAX - s->offset) { return -EINVAL; } 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) diff --git a/block/rbd.c b/block/rbd.c index ff44e5f437..9da02cdceb 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1065,11 +1065,11 @@ static int qemu_rbd_snap_list(BlockDriverState *bs, #ifdef LIBRBD_SUPPORTS_DISCARD static BlockAIOCB *qemu_rbd_aio_pdiscard(BlockDriverState *bs, int64_t offset, - int count, + int bytes, BlockCompletionFunc *cb, 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); } #endif diff --git a/block/sheepdog.c b/block/sheepdog.c index c9236679c6..a87ee5facd 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -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, - int count) + int bytes) { SheepdogAIOCB acb; BDRVSheepdogState *s = bs->opaque; @@ -2953,11 +2953,11 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, iov.iov_len = sizeof(zero); discard_iov.iov = &iov; discard_iov.niov = 1; - if (!QEMU_IS_ALIGNED(offset | count, BDRV_SECTOR_SIZE)) { + if (!QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)) { return -ENOTSUP; } 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_aio_complete(&acb); diff --git a/include/block/block.h b/include/block/block.h index 623e7fca97..85e4be7462 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -276,7 +276,7 @@ int bdrv_read(BdrvChild *child, int64_t sector_num, int bdrv_write(BdrvChild *child, int64_t sector_num, const uint8_t *buf, int nb_sectors); 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_pread(BdrvChild *child, int64_t offset, void *buf, int bytes); 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, * because it may allocate memory for the entire region. */ 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, const char *backing_file); int bdrv_get_backing_file_depth(BlockDriverState *bs); @@ -411,8 +411,8 @@ void bdrv_drain_all(void); } \ waited_; }) -int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count); -int bdrv_co_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 bytes); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 748970055e..15fa602150 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -142,7 +142,7 @@ struct BlockDriver { BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs, - int64_t offset, int count, + int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, @@ -163,9 +163,9 @@ struct BlockDriver { * will be called instead. */ 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, - int64_t offset, int count); + int64_t offset, int bytes); /* * Building block for bdrv_block_status[_above]. The driver should diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 999eb2333a..1e05281fff 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -130,7 +130,7 @@ BlockBackend *blk_by_dev(void *dev); BlockBackend *blk_by_qdev_id(const char *id, Error **errp); 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 count); + int bytes); int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); @@ -138,13 +138,13 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); 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, - int count, BdrvRequestFlags flags, + int bytes, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags); -int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count); -int blk_pwrite(BlockBackend *blk, int64_t offset, const 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 bytes, BdrvRequestFlags flags); int64_t blk_getlength(BlockBackend *blk); void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr); @@ -157,7 +157,7 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_flush(BlockBackend *blk, 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); void blk_aio_cancel(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); int blk_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); -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_flush(BlockBackend *blk); int blk_commit_all(void); @@ -220,11 +220,11 @@ int blk_get_open_flags_from_root_state(BlockBackend *blk); void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk, BlockCompletionFunc *cb, void *opaque); 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 count); + int bytes); 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, int64_t pos, int size); int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 4b2278f040..b0ea327024 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -451,13 +451,13 @@ fail: } 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; } - *total = blk_pread(blk, offset, (uint8_t *)buf, count); + *total = blk_pread(blk, offset, (uint8_t *)buf, bytes); if (*total < 0) { return *total; } @@ -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, - 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; } - *total = blk_pwrite(blk, offset, (uint8_t *)buf, count, flags); + *total = blk_pwrite(blk, offset, (uint8_t *)buf, bytes, flags); if (*total < 0) { return *total; } @@ -481,7 +481,7 @@ static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset, typedef struct { BlockBackend *blk; int64_t offset; - int64_t count; + int64_t bytes; int64_t *total; int flags; int ret; @@ -492,7 +492,7 @@ static void coroutine_fn co_pwrite_zeroes_entry(void *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->done = true; if (data->ret < 0) { @@ -500,23 +500,23 @@ static void coroutine_fn co_pwrite_zeroes_entry(void *opaque) return; } - *data->total = data->count; + *data->total = data->bytes; } 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; CoWriteZeroes data = { .blk = blk, .offset = offset, - .count = count, + .bytes = bytes, .total = total, .flags = flags, .done = false, }; - if (count > INT_MAX) { + if (bytes > INT_MAX) { return -ERANGE; } @@ -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, - int64_t count, int64_t *total) + int64_t bytes, int64_t *total) { int ret; - if (count >> 9 > BDRV_REQUEST_MAX_SECTORS) { + if (bytes >> 9 > BDRV_REQUEST_MAX_SECTORS) { return -ERANGE; } - ret = blk_pwrite_compressed(blk, offset, buf, count); + ret = blk_pwrite_compressed(blk, offset, buf, bytes); if (ret < 0) { return ret; } - *total = count; + *total = bytes; return 1; } @@ -1701,7 +1701,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) struct timeval t1, t2; bool Cflag = false, qflag = false; int c, ret; - int64_t offset, count; + int64_t offset, bytes; while ((c = getopt(argc, argv, "Cq")) != -1) { switch (c) { @@ -1727,11 +1727,11 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) } optind++; - count = cvtnum(argv[optind]); - if (count < 0) { - print_cvtnum_err(count, argv[optind]); + bytes = cvtnum(argv[optind]); + if (bytes < 0) { + print_cvtnum_err(bytes, argv[optind]); 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", (uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS, argv[optind]); @@ -1739,7 +1739,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) } gettimeofday(&t1, NULL); - ret = blk_pdiscard(blk, offset, count); + ret = blk_pdiscard(blk, offset, bytes); gettimeofday(&t2, NULL); if (ret < 0) { @@ -1750,7 +1750,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) /* Finally, report back -- -C gives a parsable format */ if (!qflag) { t2 = tsub(t2, t1); - print_report("discard", &t2, offset, count, count, 1, Cflag); + print_report("discard", &t2, offset, bytes, bytes, 1, Cflag); } out: From 4172a00373b2c81374293becc02b16b7f8c76659 Mon Sep 17 00:00:00 2001 From: "sochin.jiang" Date: Thu, 15 Jun 2017 14:47:33 +0800 Subject: [PATCH 2/6] fix: avoid an infinite loop or a dangling pointer problem in img_commit img_commit could fall into an infinite loop calling run_block_job() if its blockjob fails on any I/O error, fix this already known problem. Signed-off-by: sochin.jiang Message-id: 1497509253-28941-1-git-send-email-sochin.jiang@huawei.com Signed-off-by: Max Reitz --- blockjob.c | 4 ++-- include/block/blockjob.h | 18 ++++++++++++++++++ qemu-img.c | 20 +++++++++++++------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/blockjob.c b/blockjob.c index a0d7e29b83..70a78188b7 100644 --- a/blockjob.c +++ b/blockjob.c @@ -139,7 +139,7 @@ static void block_job_resume(BlockJob *job) block_job_enter(job); } -static void block_job_ref(BlockJob *job) +void block_job_ref(BlockJob *job) { ++job->refcnt; } @@ -148,7 +148,7 @@ static void block_job_attached_aio_context(AioContext *new_context, void *opaque); static void block_job_detach_aio_context(void *opaque); -static void block_job_unref(BlockJob *job) +void block_job_unref(BlockJob *job) { if (--job->refcnt == 0) { BlockDriverState *bs = blk_bs(job->blk); diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 09c7c694b5..67c0968fa5 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -320,6 +320,24 @@ void block_job_iostatus_reset(BlockJob *job); */ BlockJobTxn *block_job_txn_new(void); +/** + * block_job_ref: + * + * Add a reference to BlockJob refcnt, it will be decreased with + * block_job_unref, and then be freed if it comes to be the last + * reference. + */ +void block_job_ref(BlockJob *job); + +/** + * block_job_unref: + * + * Release a reference that was previously acquired with block_job_ref + * or block_job_create. If it's the last reference to the object, it will be + * freed. + */ +void block_job_unref(BlockJob *job); + /** * block_job_txn_unref: * diff --git a/qemu-img.c b/qemu-img.c index 0ad698d7f1..e70d5155e4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -887,22 +887,28 @@ static void common_block_job_cb(void *opaque, int ret) static void run_block_job(BlockJob *job, Error **errp) { AioContext *aio_context = blk_get_aio_context(job->blk); + int ret = 0; - /* FIXME In error cases, the job simply goes away and we access a dangling - * pointer below. */ aio_context_acquire(aio_context); + block_job_ref(job); do { aio_poll(aio_context, true); qemu_progress_print(job->len ? ((float)job->offset / job->len * 100.f) : 0.0f, 0); - } while (!job->ready); + } while (!job->ready && !job->completed); - block_job_complete_sync(job, errp); + if (!job->completed) { + ret = block_job_complete_sync(job, errp); + } else { + ret = job->ret; + } + block_job_unref(job); aio_context_release(aio_context); - /* A block job may finish instantaneously without publishing any progress, - * so just signal completion here */ - qemu_progress_print(100.f, 0); + /* publish completion progress only when success */ + if (!ret) { + qemu_progress_print(100.f, 0); + } } static int img_commit(int argc, char **argv) From de81d72d3d13a19edf4d461be3b0f5a877be0234 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Tue, 13 Jun 2017 19:20:05 +0200 Subject: [PATCH 3/6] blkdebug: Catch bs->exact_filename overflow The bs->exact_filename field may not be sufficient to store the full blkdebug node filename. In this case, we should not generate a filename at all instead of an unusable one. Cc: qemu-stable@nongnu.org Reported-by: Qu Wenruo Signed-off-by: Max Reitz Message-id: 20170613172006.19685-2-mreitz@redhat.com Reviewed-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Signed-off-by: Max Reitz --- block/blkdebug.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 6431962d7e..a1b24b9b0d 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -839,9 +839,13 @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) } if (!force_json && bs->file->bs->exact_filename[0]) { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), - "blkdebug:%s:%s", s->config_file ?: "", - bs->file->bs->exact_filename); + int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "blkdebug:%s:%s", s->config_file ?: "", + bs->file->bs->exact_filename); + if (ret >= sizeof(bs->exact_filename)) { + /* An overflow makes the filename unusable, so do not report any */ + bs->exact_filename[0] = 0; + } } opts = qdict_new(); From 05cc758a3dfc79488d0a8eb7f5830a41871e78d0 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Tue, 13 Jun 2017 19:20:06 +0200 Subject: [PATCH 4/6] blkverify: Catch bs->exact_filename overflow The bs->exact_filename field may not be sufficient to store the full blkverify node filename. In this case, we should not generate a filename at all instead of an unusable one. Cc: qemu-stable@nongnu.org Reported-by: Qu Wenruo Signed-off-by: Max Reitz Message-id: 20170613172006.19685-3-mreitz@redhat.com Reviewed-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Signed-off-by: Max Reitz --- block/blkverify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/block/blkverify.c b/block/blkverify.c index 6b0a603cf0..06369f9eac 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -301,10 +301,14 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options) if (bs->file->bs->exact_filename[0] && s->test_file->bs->exact_filename[0]) { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), - "blkverify:%s:%s", - bs->file->bs->exact_filename, - s->test_file->bs->exact_filename); + int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "blkverify:%s:%s", + bs->file->bs->exact_filename, + s->test_file->bs->exact_filename); + if (ret >= sizeof(bs->exact_filename)) { + /* An overflow makes the filename unusable, so do not report any */ + bs->exact_filename[0] = 0; + } } } From f69165a8feca055cf4a37d13ab0fc5beec3cb372 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Tue, 13 Jun 2017 22:57:26 +0200 Subject: [PATCH 5/6] block: Do not strcmp() with NULL uri->scheme uri_parse(...)->scheme may be NULL. In fact, probably every field may be NULL, and the callers do test this for all of the other fields but not for scheme (except for block/gluster.c; block/vxhs.c does not access that field at all). We can easily fix this by using g_strcmp0() instead of strcmp(). Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Message-id: 20170613205726.13544-1-mreitz@redhat.com Reviewed-by: Stefan Hajnoczi Signed-off-by: Max Reitz --- block/nbd.c | 6 +++--- block/nfs.c | 2 +- block/sheepdog.c | 6 +++--- block/ssh.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index e946ea944d..d529305330 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -64,11 +64,11 @@ static int nbd_parse_uri(const char *filename, QDict *options) } /* transport */ - if (!strcmp(uri->scheme, "nbd")) { + if (!g_strcmp0(uri->scheme, "nbd")) { is_unix = false; - } else if (!strcmp(uri->scheme, "nbd+tcp")) { + } else if (!g_strcmp0(uri->scheme, "nbd+tcp")) { is_unix = false; - } else if (!strcmp(uri->scheme, "nbd+unix")) { + } else if (!g_strcmp0(uri->scheme, "nbd+unix")) { is_unix = true; } else { ret = -EINVAL; diff --git a/block/nfs.c b/block/nfs.c index 6b8b5b653d..c3c5de0113 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -82,7 +82,7 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp) error_setg(errp, "Invalid URI specified"); goto out; } - if (strcmp(uri->scheme, "nfs") != 0) { + if (g_strcmp0(uri->scheme, "nfs") != 0) { error_setg(errp, "URI scheme must be 'nfs'"); goto out; } diff --git a/block/sheepdog.c b/block/sheepdog.c index a87ee5facd..08d7b11e9d 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1046,11 +1046,11 @@ static void sd_parse_uri(SheepdogConfig *cfg, const char *filename, } /* transport */ - if (!strcmp(uri->scheme, "sheepdog")) { + if (!g_strcmp0(uri->scheme, "sheepdog")) { is_unix = false; - } else if (!strcmp(uri->scheme, "sheepdog+tcp")) { + } else if (!g_strcmp0(uri->scheme, "sheepdog+tcp")) { is_unix = false; - } else if (!strcmp(uri->scheme, "sheepdog+unix")) { + } else if (!g_strcmp0(uri->scheme, "sheepdog+unix")) { is_unix = true; } else { error_setg(&err, "URI scheme must be 'sheepdog', 'sheepdog+tcp'," diff --git a/block/ssh.c b/block/ssh.c index bac3453c3e..52964416da 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -204,7 +204,7 @@ static int parse_uri(const char *filename, QDict *options, Error **errp) return -EINVAL; } - if (strcmp(uri->scheme, "ssh") != 0) { + if (g_strcmp0(uri->scheme, "ssh") != 0) { error_setg(errp, "URI scheme must be 'ssh'"); goto err; } From 2a245709099e98bca638694c182f1e5627567df7 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Mon, 19 Jun 2017 16:00:02 +0100 Subject: [PATCH 6/6] qemu-img: don't shadow opts variable in img_dd() It's confusing when two different variables have the same name in one function. Cc: Reda Sallahi Signed-off-by: Stefan Hajnoczi Message-id: 20170619150002.3033-1-stefanha@redhat.com Signed-off-by: Max Reitz --- qemu-img.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e70d5155e4..91ad6bebbf 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4255,15 +4255,12 @@ static int img_dd(int argc, char **argv) case 'U': force_share = true; break; - case OPTION_OBJECT: { - QemuOpts *opts; - opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { + case OPTION_OBJECT: + if (!qemu_opts_parse_noisily(&qemu_object_opts, optarg, true)) { ret = -1; goto out; } - } break; + break; case OPTION_IMAGE_OPTS: image_opts = true; break;