Block patches
Subsystems (2)
The following changes since commit c25e8bba1f546ea72744ccfab77f8a9e8a323be8:
Merge remote-tracking branch 'remotes/otubo/tags/pull-seccomp-20180601' into staging (2018-06-01 13:11:30 +0100)
are available in the Git repository at:
git://github.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to 21891a5a3011608845b5d7f1f9cce60cdc2bcc62:
main-loop: drop spin_counter (2018-06-01 16:01:29 +0100)
----------------------------------------------------------------
Pull request
* Copy offloading for qemu-img convert (iSCSI, raw, and qcow2)
If the underlying storage supports copy offloading, qemu-img convert will use it instead of performing reads and writes. This avoids data transfers and thus frees up storage bandwidth for other purposes. SCSI EXTENDED COPY and Linux copy_file_range(2) are used to implement this optimization.
* Drop spurious "WARNING: I\/O thread spun for 1000 iterations" warning
----------------------------------------------------------------
Fam Zheng (10):
block: Introduce API for copy offloading
raw: Check byte range uniformly raw: Implement copy offloading qcow2: Implement copy offloading file-posix: Implement bdrv_co_copy_range iscsi: Query and save device designator when opening iscsi: Create and use iscsi_co_wait_for_task iscsi: Implement copy offloading block-backend: Add blk_co_copy_range qemu-img: Convert with copy offloading
Stefan Hajnoczi (1):
main-loop: drop spin_counter
configure | 17 ++ include/block/block.h | 32 ++++ include/block/block_int.h | 38 ++++ include/block/raw-aio.h | 10 +- include/scsi/constants.h | 4 + include/sysemu/block-backend.h | 4 + block/block-backend.c | 18 ++ block/file-posix.c | 98 +++++++++- block/io.c | 97 ++++++++++ block/iscsi.c | 314 +++++++++++++++++++++++++++---- block/qcow2.c | 229 +++++++++++++++++++--- block/raw-format.c | 96 +++++++--- qemu-img.c | 50 ++++- util/main-loop.c | 25 --- tests/qemu-iotests/common.filter | 1 - 15 files changed, 908 insertions(+), 125 deletions(-)
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 02/11] raw: Check byte range uniformly
From: Fam Zheng <[email protected]>
We don't verify the request range against s->size in the I/O callbacks except for raw_co_pwritev. This is inconsistent (especially for raw_co_pwrite_zeroes and raw_co_pdiscard), so fix them, in the meanwhile make the helper reusable by the coming new callbacks.
Note that in most cases the block layer already verifies the request byte range against our reported image length, before invoking the driver callbacks. The exception is during image creating, after blk_set_allow_write_beyond_eof(blk, true) is called. But in that case, the requests are not directly from the user or guest. So there is no visible behavior change in adding the check code.
The int64_t -> uint64_t inconsistency, as shown by the type casting, is pre-existing due to the interface.
Message-id: [email protected]
--- block/raw-format.c | 64 ++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 25 deletions(-)
block/raw-format.c +39 -25
@@ -167,16 +167,37 @@ static void raw_reopen_abort(BDRVReopenState *state) state->opaque =NULL ; } +/* Check and adjust the offset, against 'offset' and 'size' options. */ +static inline int raw_adjust_offset (BlockDriverState *bs,uint64_t *offset, +uint64_t bytes,bool is_write) +{ +BDRVRawState *s = bs->opaque; + +if (s->has_size && (*offset > s->size || bytes > (s->size - *offset))) { +/* There's not enough space for the write, or the read request is +* out-of-range. Don't read/write anything to prevent leaking out of +* the size specified in options. */ +return is_write ? -ENOSPC : -EINVAL ;; + } + +if (*offset >INT64_MAX - s->offset) { +return -EINVAL ; + } + *offset += s->offset; + +return 0 ; +} + static int coroutine_fn raw_co_preadv(BlockDriverState *bs, uint64_t offset,uint64_t bytes,QEMUIOVector *qiov,int flags) { -BDRVRawState *s = bs->opaque; +int ret; -if (offset >UINT64_MAX - s->offset) { -return -EINVAL ; + ret =raw_adjust_offset (bs, &offset, bytes, false); +if (ret) { +return ret; } - offset += s->offset;BLKDBG_EVENT (bs->file,BLKDBG_READ_AIO );return bdrv_co_preadv (bs->file, offset, bytes, qiov, flags);
@@ -186,23 +207,11 @@ static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { - BDRVRawState *s = bs->opaque; void *buf = NULL;BlockDriver *drv;QEMUIOVector local_qiov;int ret; -if (s->has_size && (offset > s->size || bytes > (s->size - offset))) { -/* There's not enough space for the data. Don't write anything and just -* fail to prevent leaking out of the size specified in options. */ -return -ENOSPC ; - } - -if (offset >UINT64_MAX - s->offset) { - ret = -EINVAL ; - goto fail; - } -if (bs->probed && offset <BLOCK_PROBE_BUF_SIZE && bytes) {/* Handling partial writes would be a pain - so we just * require that guests have 512-byte request alignment if
@@ -237,7 +246,10 @@ static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, uint64_t offset, qiov = &local_qiov; } - offset += s->offset; + ret =raw_adjust_offset (bs, &offset, bytes, true); +if (ret) { + goto fail; + }BLKDBG_EVENT (bs->file,BLKDBG_WRITE_AIO ); ret =bdrv_co_pwritev (bs->file, offset, bytes, qiov, flags);
@@ -267,22 +279,24 @@ static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { - BDRVRawState *s = bs->opaque; -if (offset >UINT64_MAX - s->offset) { -return -EINVAL ; + int ret; + + ret =raw_adjust_offset (bs, (uint64_t *)&offset, bytes, true); +if (ret) { +return ret; } - offset += s->offset;return bdrv_co_pwrite_zeroes (bs->file, offset, bytes, flags); } static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs,int64_t offset,int bytes) { -BDRVRawState *s = bs->opaque; -if (offset >UINT64_MAX - s->offset) { -return -EINVAL ; +int ret; + + ret =raw_adjust_offset (bs, (uint64_t *)&offset, bytes, true); +if (ret) { +return ret; } - offset += s->offset;return bdrv_co_pdiscard (bs->file->bs, offset, bytes); }
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 01/11] block: Introduce API for copy offloading
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
Introduce the bdrv_co_copy_range() API for copy offloading. Block drivers implementing this API support efficient copy operations that avoid reading each block from the source device and writing it to the destination devices. Examples of copy offload primitives are SCSI EXTENDED COPY and Linux copy_file_range(2).
Message-id: [email protected]
--- include/block/block.h | 32 +++++++++++++ include/block/block_int.h | 38 +++++++++++++++ block/io.c | 97 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+)
include/block/block.h +32 -0
@@ -611,4 +611,36 @@ bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name,*/ void bdrv_register_buf (BlockDriverState *bs,void *host,size_t size);void bdrv_unregister_buf (BlockDriverState *bs,void *host); + +/** +* +* bdrv_co_copy_range: +* +* Do offloaded copy between two children. If the operation is not implemented +* by the driver, or if the backend storage doesn't support it, a negative +* error code will be returned. +* +* Note: block layer doesn't emulate or fallback to a bounce buffer approach +* because usually the caller shouldn't attempt offloaded copy any more (e.g. +* calling copy_file_range(2)) after the first error, thus it should fall back +* to a read+write path in the caller level. +* +* @src: Source child to copy data from +* @src_offset: offset in @src image to read data +* @dst: Destination child to copy data to +* @dst_offset: offset in @dst image to write data +* @bytes: number of bytes to copy +* @flags: request flags. Must be one of: +* 0 - actually read data from src; +* BDRV_REQ_ZERO_WRITE - treat the @src range as zero data and do zero +* write on @dst as if bdrv_co_pwrite_zeroes is +* called. Used to simplify caller code, or +* during BlockDriver.bdrv_co_copy_range_from() +* recursion. +* +* Returns: 0 if succeeded; negative error code if failed. +**/ +int coroutine_fn bdrv_co_copy_range(BdrvChild *src, uint64_t src_offset, +BdrvChild *dst,uint64_t dst_offset, +uint64_t bytes,BdrvRequestFlags flags);#endif
include/block/block_int.h +38 -0
@@ -204,6 +204,37 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs,int64_t offset,int bytes); +/* Map [offset, offset + nbytes) range onto a child of @bs to copy from, +* and invoke bdrv_co_copy_range_from(child, ...), or invoke +* bdrv_co_copy_range_to() if @bs is the leaf child to copy data from. +* +* See the comment of bdrv_co_copy_range for the parameter and return value +* semantics. +*/ + int coroutine_fn (*bdrv_co_copy_range_from)(BlockDriverState *bs, +BdrvChild *src, +uint64_t offset, +BdrvChild *dst, +uint64_t dst_offset, +uint64_t bytes, +BdrvRequestFlags flags); + +/* Map [offset, offset + nbytes) range onto a child of bs to copy data to, +* and invoke bdrv_co_copy_range_to(child, src, ...), or perform the copy +* operation if @bs is the leaf and @src has the same BlockDriver. Return +* -ENOTSUP if @bs is the leaf but @src has a different BlockDriver. +* +* See the comment of bdrv_co_copy_range for the parameter and return value +* semantics. +*/ + int coroutine_fn (*bdrv_co_copy_range_to)(BlockDriverState *bs, +BdrvChild *src, +uint64_t src_offset, +BdrvChild *dst, +uint64_t dst_offset, +uint64_t bytes, +BdrvRequestFlags flags); +/* * Building block for bdrv_block_status[_above] and * bdrv_is_allocated[_above]. The driver should answer only
@@ -1102,4 +1133,11 @@ void bdrv_dec_in_flight(BlockDriverState *bs);void blockdev_close_all_bdrv_states (void ); +int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, uint64_t src_offset, +BdrvChild *dst,uint64_t dst_offset, +uint64_t bytes,BdrvRequestFlags flags); +int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, uint64_t src_offset, +BdrvChild *dst,uint64_t dst_offset, +uint64_t bytes,BdrvRequestFlags flags); +#endif /* BLOCK_INT_H */
block/io.c +97 -0
100 lines not on this page · raw message
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 03/11] raw: Implement copy offloading
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
Just pass down to ->file.
Message-id: [email protected]
--- block/raw-format.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
block/raw-format.c +32 -0
@@ -497,6 +497,36 @@ static int raw_probe_geometry(BlockDriverState *bs, HDGeometry *geo)return bdrv_probe_geometry (bs->file->bs, geo); } +static int coroutine_fn raw_co_copy_range_from(BlockDriverState *bs, +BdrvChild *src,uint64_t src_offset, +BdrvChild *dst,uint64_t dst_offset, +uint64_t bytes,BdrvRequestFlags flags) +{ +int ret; + + ret =raw_adjust_offset (bs, &src_offset, bytes, false); +if (ret) { +return ret; + } +return bdrv_co_copy_range_from (bs->file, src_offset, dst, dst_offset, + bytes, flags); +} + +static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, +BdrvChild *src,uint64_t src_offset, +BdrvChild *dst,uint64_t dst_offset, +uint64_t bytes,BdrvRequestFlags flags) +{ +int ret; + + ret =raw_adjust_offset (bs, &dst_offset, bytes, true); +if (ret) { +return ret; + } +return bdrv_co_copy_range_to (src, src_offset, bs->file, dst_offset, bytes, + flags); +} +BlockDriver bdrv_raw = { .format_name ="raw" , .instance_size =sizeof (BDRVRawState),
@@ -513,6 +543,8 @@ BlockDriver bdrv_raw = { .bdrv_co_pwrite_zeroes = &raw_co_pwrite_zeroes, .bdrv_co_pdiscard = &raw_co_pdiscard, .bdrv_co_block_status = &raw_co_block_status, + .bdrv_co_copy_range_from = &raw_co_copy_range_from, + .bdrv_co_copy_range_to = &raw_co_copy_range_to, .bdrv_truncate = &raw_truncate, .bdrv_getlength = &raw_getlength, .has_variable_length = true,
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 04/11] qcow2: Implement copy offloading
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
The two callbacks are implemented quite similarly to the read/write
functions: bdrv_co_copy_range_from maps for read and calls into bs->file or bs->backing depending on the allocation status; bdrv_co_copy_range_to maps for write and calls into bs->file.
Message-id: [email protected]
--- block/qcow2.c | 229 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 199 insertions(+), 30 deletions(-)
block/qcow2.c +199 -30
@@ -1761,6 +1761,39 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,return status; } +static coroutine_fn int qcow2_handle_l2meta(BlockDriverState *bs, +QCowL2Meta **pl2meta, +bool link_l2) +{ +int ret =0 ; +QCowL2Meta *l2meta = *pl2meta; + +while (l2meta !=NULL ) { +QCowL2Meta *next; + +if (!ret && link_l2) { + ret =qcow2_alloc_cluster_link_l2 (bs, l2meta); +if (ret) { + goto out; + } + } + +/* Take the request off the list of running requests */ +if (l2meta->nb_clusters !=0 ) { +QLIST_REMOVE (l2meta, next_in_flight); + } + +qemu_co_queue_restart_all (&l2meta->dependent_requests); + + next = l2meta->next; +g_free (l2meta); + l2meta = next; + } +out: + *pl2meta = l2meta; +return ret; +} + static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,uint64_t bytes,QEMUIOVector *qiov,int flags)
@@ -2047,24 +2080,9 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, } } -while (l2meta !=NULL ) { -QCowL2Meta *next; - - ret =qcow2_alloc_cluster_link_l2 (bs, l2meta); -if (ret <0 ) { - goto fail; - } - -/* Take the request off the list of running requests */ -if (l2meta->nb_clusters !=0 ) { -QLIST_REMOVE (l2meta, next_in_flight); - } - -qemu_co_queue_restart_all (&l2meta->dependent_requests); - - next = l2meta->next; -g_free (l2meta); - l2meta = next; + ret =qcow2_handle_l2meta (bs, &l2meta, true); +if (ret) { + goto fail; } bytes -= cur_bytes;
@@ -2075,18 +2093,7 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, ret =0 ; fail: -while (l2meta !=NULL ) { -QCowL2Meta *next; - -if (l2meta->nb_clusters !=0 ) { -QLIST_REMOVE (l2meta, next_in_flight); - } -qemu_co_queue_restart_all (&l2meta->dependent_requests); - - next = l2meta->next; -g_free (l2meta); - l2meta = next; - } +qcow2_handle_l2meta (bs, &l2meta, false);qemu_co_mutex_unlock (&s->lock);
@@ -3273,6 +3280,166 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,return ret; } +static int coroutine_fn +qcow2_co_copy_range_from (BlockDriverState *bs, +BdrvChild *src,uint64_t src_offset, +BdrvChild *dst,uint64_t dst_offset, +uint64_t bytes,BdrvRequestFlags flags) +{ +BDRVQcow2State *s = bs->opaque; +int ret; +unsigned int cur_bytes;/* number of bytes in current iteration */ +BdrvChild *child =NULL ; +BdrvRequestFlags cur_flags; + +assert (!bs->encrypted); +qemu_co_mutex_lock (&s->lock); + +while (bytes !=0 ) { +uint64_t copy_offset =0 ; +/* prepare next request */ + cur_bytes =MIN (bytes,INT_MAX ); + cur_flags = flags; + + ret =qcow2_get_cluster_offset (bs, src_offset, &cur_bytes, ©_offset); +if (ret <0 ) { + goto out; + } + +switch (ret) { +case QCOW2_CLUSTER_UNALLOCATED : +if (bs->backing && bs->backing->bs) { +int64_t backing_length =bdrv_getlength (bs->backing->bs); +if (src_offset >= backing_length) { + cur_flags |=BDRV_REQ_ZERO_WRITE ; + }else { + child = bs->backing; + cur_bytes =MIN (cur_bytes, backing_length - src_offset); + copy_offset = src_offset; + } + }else { + cur_flags |=BDRV_REQ_ZERO_WRITE ; + } +break ; + +case QCOW2_CLUSTER_ZERO_PLAIN : +case QCOW2_CLUSTER_ZERO_ALLOC : + cur_flags |=BDRV_REQ_ZERO_WRITE ; +break ; + +case QCOW2_CLUSTER_COMPRESSED : + ret = -ENOTSUP ; + goto out; +break ; + +case QCOW2_CLUSTER_NORMAL : + child = bs->file; + copy_offset +=offset_into_cluster (s, src_offset); +if ((copy_offset &511 ) !=0 ) { + ret = -EIO ; + goto out; + } +break ; + +default : +abort (); + } +qemu_co_mutex_unlock (&s->lock); + ret =bdrv_co_copy_range_from (child, + copy_offset, + dst, dst_offset, + cur_bytes, cur_flags); +qemu_co_mutex_lock (&s->lock); +if (ret <0 ) { + goto out; + } + + bytes -= cur_bytes; + src_offset += cur_bytes; + dst_offset += cur_bytes; + } + ret =0 ; + +out: +qemu_co_mutex_unlock (&s->lock); +return ret; +} + +static int coroutine_fn +qcow2_co_copy_range_to (BlockDriverState *bs, +BdrvChild *src,uint64_t src_offset, +BdrvChild *dst,uint64_t dst_offset, +uint64_t bytes,BdrvRequestFlags flags) +{ +BDRVQcow2State *s = bs->opaque; +int offset_in_cluster; +int ret; +unsigned int cur_bytes;/* number of sectors in current iteration */ +uint64_t cluster_offset; +uint8_t *cluster_data =NULL ; +QCowL2Meta *l2meta =NULL ; + +assert (!bs->encrypted); + s->cluster_cache_offset =-1 ;/* disable compressed cache */ + +qemu_co_mutex_lock (&s->lock); + +while (bytes !=0 ) { + + l2meta =NULL ; + + offset_in_cluster =offset_into_cluster (s, dst_offset); + cur_bytes =MIN (bytes,INT_MAX ); + +/* TODO: +* If src->bs == dst->bs, we could simply copy by incrementing +* the refcnt, without copying user data. +* Or if src->bs == dst->bs->backing->bs, we could copy by discarding. */ + ret =qcow2_alloc_cluster_offset (bs, dst_offset, &cur_bytes, + &cluster_offset, &l2meta); +if (ret <0 ) { + goto fail; + } + +assert ((cluster_offset &511 ) ==0 ); + + ret =qcow2_pre_write_overlap_check (bs,0 , + cluster_offset + offset_in_cluster, cur_bytes); +if (ret <0 ) { + goto fail; + } + +qemu_co_mutex_unlock (&s->lock); + ret =bdrv_co_copy_range_to (src, src_offset, + bs->file, + cluster_offset + offset_in_cluster, + cur_bytes, flags); +qemu_co_mutex_lock (&s->lock); +if (ret <0 ) { + goto fail; + } + + ret =qcow2_handle_l2meta (bs, &l2meta, true); +if (ret) { + goto fail; + } + + bytes -= cur_bytes; + dst_offset += cur_bytes; + } + ret =0 ; + +fail: +qcow2_handle_l2meta (bs, &l2meta, false); + +qemu_co_mutex_unlock (&s->lock); + +qemu_vfree (cluster_data); +trace_qcow2_writev_done_req (qemu_coroutine_self (), ret); + +return ret; +} +static int qcow2_truncate (BlockDriverState *bs,int64_t offset,PreallocMode prealloc,Error **errp) {
@@ -4521,6 +4688,8 @@ BlockDriver bdrv_qcow2 = { .bdrv_co_pwrite_zeroes = qcow2_co_pwrite_zeroes, .bdrv_co_pdiscard = qcow2_co_pdiscard, + .bdrv_co_copy_range_from = qcow2_co_copy_range_from, + .bdrv_co_copy_range_to = qcow2_co_copy_range_to, .bdrv_truncate = qcow2_truncate, .bdrv_co_pwritev_compressed = qcow2_co_pwritev_compressed, .bdrv_make_empty = qcow2_make_empty,
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 05/11] file-posix: Implement bdrv_co_copy_range
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
With copy_file_range(2), we can implement the bdrv_co_copy_range semantics.
Message-id: [email protected]
--- configure | 17 +++++++ include/block/raw-aio.h | 10 ++++- block/file-posix.c | 98 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 120 insertions(+), 5 deletions(-)
configure +17 -0
@@ -5183,6 +5183,20 @@ if test "$fortify_source" != "no"; then fi fi +############################################### +# Check if copy_file_range is provided by glibc +have_copy_file_range=no +cat > $TMPC << EOF +#include <unistd.h> +int main(void) { + copy_file_range(0, NULL, 0, NULL, 0, 0); + return 0; +} +EOF +if compile_prog "" "" ; then + have_copy_file_range=yes +fi + ########################################## # check if struct fsxattr is available via linux/fs.h
@@ -6286,6 +6300,9 @@ fi if test "$have_fsxattr" = "yes" ; then echo "HAVE_FSXATTR=y" >> $config_host_mak fi +if test "$have_copy_file_range" = "yes" ; then + echo "HAVE_COPY_FILE_RANGE=y" >> $config_host_mak +fi if test "$vte" = "yes" ; then echo "CONFIG_VTE=y" >> $config_host_mak echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
include/block/raw-aio.h +8 -2
@@ -25,9 +25,15 @@#define QEMU_AIO_FLUSH 0x0008#define QEMU_AIO_DISCARD 0x0010#define QEMU_AIO_WRITE_ZEROES 0x0020 +#define QEMU_AIO_COPY_RANGE 0x0040#define QEMU_AIO_TYPE_MASK \ - (QEMU_AIO_READ|QEMU_AIO_WRITE|QEMU_AIO_IOCTL|QEMU_AIO_FLUSH| \ - QEMU_AIO_DISCARD|QEMU_AIO_WRITE_ZEROES) + (QEMU_AIO_READ | \ + QEMU_AIO_WRITE | \ + QEMU_AIO_IOCTL | \ + QEMU_AIO_FLUSH | \ + QEMU_AIO_DISCARD | \ + QEMU_AIO_WRITE_ZEROES | \ + QEMU_AIO_COPY_RANGE)/* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000
block/file-posix.c +95 -3
158 lines not on this page · raw message
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 06/11] iscsi: Query and save device designator when opening
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
The device designator data returned in INQUIRY command will be useful to fill in source/target fields during copy offloading. Do this when connecting to the target and save the data for later use.
Message-id: [email protected]
--- block/iscsi.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
block/iscsi.c +41 -0
@@ -68,6 +68,7 @@ typedef struct IscsiLun {QemuMutex mutex;struct scsi_inquiry_logical_block_provisioning lbp;struct scsi_inquiry_block_limits bl; +struct scsi_inquiry_device_designator *dd;unsigned char *zeroblock;/* The allocmap tracks which clusters (pages) on the iSCSI target are * allocated and which are not. In case a target returns zeros for
@@ -1740,6 +1741,30 @@ static QemuOptsList runtime_opts = { }, }; +static void iscsi_save_designator (IscsiLun *lun, +struct scsi_inquiry_device_identification *inq_di) +{ +struct scsi_inquiry_device_designator *desig, *copy =NULL ; + +for (desig = inq_di->designators; desig; desig = desig->next) { +if (desig->association || + desig->designator_type >SCSI_DESIGNATOR_TYPE_NAA ) { +continue ; + } +/* NAA works better than T10 vendor ID based designator. */ +if (!copy || copy->designator_type < desig->designator_type) { + copy = desig; + } + } +if (copy) { + lun->dd = g_new(struct scsi_inquiry_device_designator, 1); + *lun->dd = *copy; + lun->dd->next =NULL ; + lun->dd->designator =g_malloc (copy->designator_length); +memcpy (lun->dd->designator, copy->designator, copy->designator_length); + } +} +static int iscsi_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) {
@@ -1922,6 +1947,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,struct scsi_task *inq_task;struct scsi_inquiry_logical_block_provisioning *inq_lbp;struct scsi_inquiry_block_limits *inq_bl; +struct scsi_inquiry_device_identification *inq_di;switch (inq_vpd->pages[i]) {case SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING : inq_task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
@@ -1947,6 +1973,17 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, sizeof(struct scsi_inquiry_block_limits));scsi_free_scsi_task (inq_task);break ; +case SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION : + inq_task =iscsi_do_inquiry (iscsilun->iscsi, iscsilun->lun,1 , +SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION , + (void **) &inq_di, errp); +if (inq_task ==NULL ) { + ret = -EINVAL ; + goto out; + } +iscsi_save_designator (iscsilun, inq_di); +scsi_free_scsi_task (inq_task); +break ;default :break ; }
@@ -2003,6 +2040,10 @@ static void iscsi_close(BlockDriverState *bs)iscsi_logout_sync (iscsi); }iscsi_destroy_context (iscsi); +if (iscsilun->dd) { +g_free (iscsilun->dd->designator); +g_free (iscsilun->dd); + }g_free (iscsilun->zeroblock);iscsi_allocmap_free (iscsilun);qemu_mutex_destroy (&iscsilun->mutex);
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 07/11] iscsi: Create and use iscsi_co_wait_for_task
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
This loop is repeated a growing number times. Make a helper.
Message-id: [email protected]
--- block/iscsi.c | 54 ++++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-)
block/iscsi.c +17 -37
@@ -556,6 +556,17 @@ static inline bool iscsi_allocmap_is_valid(IscsiLun *iscsilun, offset / iscsilun->cluster_size) == size); } +static void coroutine_fn iscsi_co_wait_for_task(IscsiTask *iTask, +IscsiLun *iscsilun) +{ +while (!iTask->complete) { +iscsi_set_events (iscsilun); +qemu_mutex_unlock (&iscsilun->mutex); +qemu_coroutine_yield (); +qemu_mutex_lock (&iscsilun->mutex); + } +} + static int coroutine_fniscsi_co_writev (BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *iov,int flags)
@@ -617,12 +628,7 @@ retry:scsi_task_set_iov_out (iTask.task, (struct scsi_iovec *) iov->iov, iov->niov);#endif -while (!iTask.complete) { -iscsi_set_events (iscsilun); -qemu_mutex_unlock (&iscsilun->mutex); -qemu_coroutine_yield (); -qemu_mutex_lock (&iscsilun->mutex); - } +iscsi_co_wait_for_task (&iTask, iscsilun);if (iTask.task !=NULL ) {scsi_free_scsi_task (iTask.task);
@@ -693,13 +699,7 @@ retry: ret = -ENOMEM ; goto out_unlock; } - -while (!iTask.complete) { -iscsi_set_events (iscsilun); -qemu_mutex_unlock (&iscsilun->mutex); -qemu_coroutine_yield (); -qemu_mutex_lock (&iscsilun->mutex); - } +iscsi_co_wait_for_task (&iTask, iscsilun);if (iTask.do_retry) {if (iTask.task !=NULL ) {
@@ -863,13 +863,8 @@ retry:#if LIBISCSI_API_VERSION < (20160603 )scsi_task_set_iov_in (iTask.task, (struct scsi_iovec *) iov->iov, iov->niov);#endif -while (!iTask.complete) { -iscsi_set_events (iscsilun); -qemu_mutex_unlock (&iscsilun->mutex); -qemu_coroutine_yield (); -qemu_mutex_lock (&iscsilun->mutex); - } +iscsi_co_wait_for_task (&iTask, iscsilun);if (iTask.task !=NULL ) {scsi_free_scsi_task (iTask.task); iTask.task =NULL ;
@@ -906,12 +901,7 @@ retry:return -ENOMEM ; } -while (!iTask.complete) { -iscsi_set_events (iscsilun); -qemu_mutex_unlock (&iscsilun->mutex); -qemu_coroutine_yield (); -qemu_mutex_lock (&iscsilun->mutex); - } +iscsi_co_wait_for_task (&iTask, iscsilun);if (iTask.task !=NULL ) {scsi_free_scsi_task (iTask.task);
@@ -1143,12 +1133,7 @@ retry: goto out_unlock; } -while (!iTask.complete) { -iscsi_set_events (iscsilun); -qemu_mutex_unlock (&iscsilun->mutex); -qemu_coroutine_yield (); -qemu_mutex_lock (&iscsilun->mutex); - } +iscsi_co_wait_for_task (&iTask, iscsilun);if (iTask.task !=NULL ) {scsi_free_scsi_task (iTask.task);
@@ -1244,12 +1229,7 @@ retry:return -ENOMEM ; } -while (!iTask.complete) { -iscsi_set_events (iscsilun); -qemu_mutex_unlock (&iscsilun->mutex); -qemu_coroutine_yield (); -qemu_mutex_lock (&iscsilun->mutex); - } +iscsi_co_wait_for_task (&iTask, iscsilun); if (iTask.status == SCSI_STATUS_CHECK_CONDITION && iTask.task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST &&
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 09/11] block-backend: Add blk_co_copy_range
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
It's a BlockBackend wrapper of the BDS interface.
Message-id: [email protected]
--- include/sysemu/block-backend.h | 4 ++++ block/block-backend.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+)
include/sysemu/block-backend.h +4 -0
@@ -232,4 +232,8 @@ void blk_set_force_allow_inactivate(BlockBackend *blk);void blk_register_buf (BlockBackend *blk,void *host,size_t size);void blk_unregister_buf (BlockBackend *blk,void *host); +int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, +BlockBackend *blk_out,int64_t off_out, +int bytes,BdrvRequestFlags flags); +#endif
block/block-backend.c +18 -0
@@ -2211,3 +2211,21 @@ void blk_unregister_buf(BlockBackend *blk, void *host) {bdrv_unregister_buf (blk_bs (blk), host); } + +int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, +BlockBackend *blk_out,int64_t off_out, +int bytes,BdrvRequestFlags flags) +{ +int r; + r =blk_check_byte_request (blk_in, off_in, bytes); +if (r) { +return r; + } + r =blk_check_byte_request (blk_out, off_out, bytes); +if (r) { +return r; + } +return bdrv_co_copy_range (blk_in->root, off_in, + blk_out->root, off_out, + bytes, flags); +}
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 08/11] iscsi: Implement copy offloading
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
Issue EXTENDED COPY (LID1) command to implement the copy_range API.
The parameter data construction code is modified from libiscsi's iscsi-dd.c.
Message-id: [email protected]
--- include/scsi/constants.h | 4 + block/iscsi.c | 219 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+)
include/scsi/constants.h +4 -0
@@ -311,4 +311,8 @@#define MMC_PROFILE_HDDVD_RW_DL 0x005A#define MMC_PROFILE_INVALID 0xFFFF +#define XCOPY_DESC_OFFSET 16 +#define IDENT_DESCR_TGT_DESCR_SIZE 32 +#define XCOPY_BLK2BLK_SEG_DESC_SIZE 28 +#endif
block/iscsi.c +219 -0
237 lines not on this page · raw message
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 10/11] qemu-img: Convert with copy offloading
In reply to Stefan HajnocziFrom: Fam Zheng <[email protected]>
The new blk_co_copy_range interface offers a more efficient way in the case of network based storage. Make use of it to allow faster convert operation.
Since copy offloading cannot do zero detection ('-S') and compression (-c), only try it when these options are not used.
Message-id: [email protected]
--- qemu-img.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-)
qemu-img.c +48 -2
@@ -1547,6 +1547,7 @@ typedef struct ImgConvertState {bool compressed;bool target_has_backing;bool wr_in_order; +bool copy_range;int min_sparse;size_t cluster_sectors;size_t buf_sectors;
@@ -1740,6 +1741,37 @@ static int coroutine_fn convert_co_write(ImgConvertState *s, int64_t sector_num,return 0 ; } +static int coroutine_fn convert_co_copy_range(ImgConvertState *s, int64_t sector_num, +int nb_sectors) +{ +int n, ret; + +while (nb_sectors >0 ) { +BlockBackend *blk; +int src_cur; +int64_t bs_sectors, src_cur_offset; +int64_t offset; + +convert_select_part (s, sector_num, &src_cur, &src_cur_offset); + offset = (sector_num - src_cur_offset) <<BDRV_SECTOR_BITS ; + blk = s->src[src_cur]; + bs_sectors = s->src_sectors[src_cur]; + + n =MIN (nb_sectors, bs_sectors - (sector_num - src_cur_offset)); + + ret =blk_co_copy_range (blk, offset, s->target, + sector_num <<BDRV_SECTOR_BITS , + n <<BDRV_SECTOR_BITS ,0 ); +if (ret <0 ) { +return ret; + } + + sector_num += n; + nb_sectors -= n; + } +return 0 ; +} + static void coroutine_fn convert_co_do_copy(void *opaque) {ImgConvertState *s = opaque;
@@ -1762,6 +1794,7 @@ static void coroutine_fn convert_co_do_copy(void *opaque)int n;int64_t sector_num;enum ImgConvertBlockStatus status; +bool copy_range;qemu_co_mutex_lock (&s->lock);if (s->ret != -EINPROGRESS || s->sector_num >= s->total_sectors) {
@@ -1791,7 +1824,9 @@ static void coroutine_fn convert_co_do_copy(void *opaque) s->allocated_sectors, 0); } -if (status ==BLK_DATA ) { +retry: + copy_range = s->copy_range && s->status ==BLK_DATA ; +if (status ==BLK_DATA && !copy_range) { ret =convert_co_read (s, sector_num, n, buf);if (ret <0 ) { error_report("error while reading sector %" PRId64
@@ -1813,7 +1848,15 @@ static void coroutine_fn convert_co_do_copy(void *opaque) }if (s->ret == -EINPROGRESS ) { - ret =convert_co_write (s, sector_num, n, buf, status); +if (copy_range) { + ret =convert_co_copy_range (s, sector_num, n); +if (ret) { + s->copy_range = false; + goto retry; + } + }else { + ret =convert_co_write (s, sector_num, n, buf, status); + }if (ret <0 ) {error_report ("error while writing sector %" PRId64": %s" , sector_num,strerror (-ret));
@@ -1936,6 +1979,7 @@ static int img_convert(int argc, char **argv)ImgConvertState s = (ImgConvertState ) {/* Need at least 4k of zeros for sparse detection */ .min_sparse =8 , + .copy_range = true, .buf_sectors =IO_BUF_SIZE /BDRV_SECTOR_SIZE , .wr_in_order = true, .num_coroutines =8 ,
@@ -1976,6 +2020,7 @@ static int img_convert(int argc, char **argv)break ;case 'c' : s.compressed = true; + s.copy_range = false;break ;case 'o' :if (!is_valid_option_list (optarg)) {
@@ -2017,6 +2062,7 @@ static int img_convert(int argc, char **argv) } s.min_sparse = sval /BDRV_SECTOR_SIZE ; + s.copy_range = false;break ; }case 'p' :
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 11/11] main-loop: drop spin_counter
In reply to Stefan HajnocziCommit d759c951f3287fad04210a52f2dc93f94cf58c7f ("replay: push replay_mutex_lock up the call tree") removed the !timeout lock optimization in the main loop.
The idea of the optimization was to avoid ping-pongs between threads by keeping the Big QEMU Lock held across non-blocking (!timeout) main loop iterations.
A warning is printed when the main loop spins without releasing BQL for long periods of time. These warnings were supposed to aid debugging but in practice they just alarm users. They are considered noise because the cause of spinning is not shown and is hard to find.
Now that the lock optimization has been removed, there is no danger of hogging the BQL. Drop the spin counter and the infamous warning.
--- util/main-loop.c | 25 ------------------------- tests/qemu-iotests/common.filter | 1 - 2 files changed, 26 deletions(-)
util/main-loop.c +0 -25
@@ -222,36 +222,11 @@ static int os_host_main_loop_wait(int64_t timeout) {GMainContext *context =g_main_context_default ();int ret; -static int spin_counter;g_main_context_acquire (context);glib_pollfds_fill (&timeout); -/* If the I/O thread is very busy or we are incorrectly busy waiting in -* the I/O thread, this can lead to starvation of the BQL such that the -* VCPU threads never run. To make sure we can detect the later case, -* print a message to the screen. If we run into this condition, create -* a fake timeout in order to give the VCPU threads a chance to run. -*/ -if (!timeout && (spin_counter >MAX_MAIN_LOOP_SPIN )) { -static bool notified; - -if (!notified && !qtest_enabled () && !qtest_driver ()) { -warn_report ("I/O thread spun for %d iterations" , -MAX_MAIN_LOOP_SPIN ); - notified = true; - } - - timeout =SCALE_MS ; - } - - -if (timeout) { - spin_counter =0 ; - }else { - spin_counter++; - }qemu_mutex_unlock_iothread ();replay_mutex_unlock ();
tests/qemu-iotests/common.filter +0 -1
@@ -77,7 +77,6 @@ _filter_qemu() { sed -e "s#\\(^\\|(qemu) \\)$(basename $QEMU_PROG):#\1QEMU_PROG:#" \ -e 's#^QEMU [0-9]\+\.[0-9]\+\.[0-9]\+ monitor#QEMU X.Y.Z monitor#' \ - -e '/main-loop: WARNING: I\/O thread spun for [0-9]\+ iterations/d' \ -e $'s#\r##' # QEMU monitor uses \r\n line endings }
Signature · 1 line
2.17.1
Peter Maydell
AppliedQuoted 17 lines · Stefan Hajnoczi
The following changes since commit
c25e8bba1f546ea72744ccfab77f8a9e8a323be8:Merge remote-tracking branch 'remotes/otubo/tags/pull-seccomp-20180601' into staging (2018-06-01 13:11:30 +0100)
are available in the Git repository at:
git://github.com/stefanha/qemu.gittags/block-pull-requestfor you to fetch changes up to
21891a5a3011608845b5d7f1f9cce60cdc2bcc62:main-loop: drop
spin_counter(2018-06-01 16:01:29 +0100)----------------------------------------------------------------
Pull request* Copy offloading for qemu-img convert (iSCSI, raw, and qcow2)
Quoted 8 lines
If the underlying storage supports copy offloading, qemu-img convert will use it instead of performing reads and writes. This avoids data transfers and thus frees up storage bandwidth for other purposes. SCSI EXTENDED COPY and Linux
copy_file_range(2)are used to implement this optimization.* Drop spurious "WARNING: I\/O thread spun for 1000 iterations" warning
----------------------------------------------------------------
Applied, thanks.
-- PMM