From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776372836667.6279877254111; Thu, 5 Jul 2018 00:39:32 -0700 (PDT) Received: from localhost ([::1]:50783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayrM-0002Ud-Ob for importer@patchew.org; Thu, 05 Jul 2018 03:39:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faypV-0001Su-Aj for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faypU-0000EQ-9P for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39018 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faypR-00005U-8b; Thu, 05 Jul 2018 03:37:25 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCDE4407519F; Thu, 5 Jul 2018 07:37:24 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BDA22156889; Thu, 5 Jul 2018 07:37:20 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:36:53 +0800 Message-Id: <20180705073701.10558-2-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Jul 2018 07:37:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Jul 2018 07:37:24 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 1/9] block: Add copy offloading trace points X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A few trace points that can help reveal what is happening in a copy offloading I/O path. Signed-off-by: Fam Zheng --- block/file-posix.c | 2 ++ block/io.c | 2 ++ block/iscsi.c | 3 +++ block/trace-events | 6 ++++++ 4 files changed, 13 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 829ee538d8..d3b1609410 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1488,6 +1488,8 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIODat= a *aiocb) ssize_t ret =3D copy_file_range(aiocb->aio_fildes, &in_off, aiocb->aio_fd2, &out_off, bytes, 0); + trace_copy_file_range(aiocb->bs, aiocb->aio_fildes, in_off, + aiocb->aio_fd2, out_off, bytes, 0, ret); if (ret =3D=3D 0) { /* No progress (e.g. when beyond EOF), let the caller fall bac= k to * buffer I/O. */ diff --git a/block/io.c b/block/io.c index 1a2272fad3..8cc5ee661d 100644 --- a/block/io.c +++ b/block/io.c @@ -2960,6 +2960,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *s= rc, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offs= et, uint64_t bytes, BdrvRequestFlags = flags) { + trace_bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes,= flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, bytes, flags, true); } @@ -2972,6 +2973,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src= , uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, BdrvRequestFlags fl= ags) { + trace_bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, f= lags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, bytes, flags, false); } diff --git a/block/iscsi.c b/block/iscsi.c index ead2bd5aa7..118555d051 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -44,6 +44,7 @@ #include "qapi/qmp/qstring.h" #include "crypto/secret.h" #include "scsi/utils.h" +#include "trace.h" =20 /* Conflict between scsi/utils.h and libiscsi! :( */ #define SCSI_XFER_NONE ISCSI_XFER_NONE @@ -2396,6 +2397,8 @@ retry: } =20 out_unlock: + + trace_iscsi_xcopy(src_lun, src_offset, dst_lun, dst_offset, bytes, r); g_free(iscsi_task.task); qemu_mutex_unlock(&dst_lun->mutex); g_free(iscsi_task.err_str); diff --git a/block/trace-events b/block/trace-events index c35287b48a..1a25a997f2 100644 --- a/block/trace-events +++ b/block/trace-events @@ -15,6 +15,8 @@ bdrv_co_preadv(void *bs, int64_t offset, int64_t nbytes, = unsigned int flags) "bs bdrv_co_pwritev(void *bs, int64_t offset, int64_t nbytes, unsigned int fla= gs) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int count, int flags) "bs = %p offset %"PRId64" count %d flags 0x%x" bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int= 64_t cluster_offset, int64_t cluster_bytes) "bs %p offset %"PRId64" bytes %= u cluster_offset %"PRId64" cluster_bytes %"PRId64 +bdrv_co_copy_range_from(void *src, uint64_t src_offset, void *dst, uint64_= t dst_offset, uint64_t bytes, int flags) "src %p offset %"PRIu64" dst %p of= fset %"PRIu64" bytes %"PRIu64" flags 0x%x" +bdrv_co_copy_range_to(void *src, uint64_t src_offset, void *dst, uint64_t = dst_offset, uint64_t bytes, int flags) "src %p offset %"PRIu64" dst %p offs= et %"PRIu64" bytes %"PRIu64" flags 0x%x" =20 # block/stream.c stream_one_iteration(void *s, int64_t offset, uint64_t bytes, int is_alloc= ated) "s %p offset %" PRId64 " bytes %" PRIu64 " is_allocated %d" @@ -57,6 +59,7 @@ qmp_block_stream(void *bs, void *job) "bs %p job %p" # block/file-posix.c paio_submit_co(int64_t offset, int count, int type) "offset %"PRId64" coun= t %d type %d" paio_submit(void *acb, void *opaque, int64_t offset, int count, int type) = "acb %p opaque %p offset %"PRId64" count %d type %d" +copy_file_range(void *bs, int src, int64_t src_off, int dst, int64_t dst_o= ff, int64_t bytes, int flags, int64_t ret) "bs %p src_fd %d offset %"PRIu64= " dst_fd %d offset %"PRIu64" bytes %"PRIu64" flags %d ret %"PRId64 =20 # block/qcow2.c qcow2_writev_start_req(void *co, int64_t offset, int bytes) "co %p offset = 0x%" PRIx64 " bytes %d" @@ -150,3 +153,6 @@ nvme_free_req_queue_wait(void *q) "q %p" nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) = "s %p cmd %p req %p qiov %p entries %d" nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"= PRIx64 nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d]= %p pages %d" + +# block/iscsi.c +iscsi_xcopy(void *src_lun, uint64_t src_off, void *dst_lun, uint64_t dst_o= ff, uint64_t bytes, int ret) "src_lun %p offset %"PRIu64" dst_lun %p offset= %"PRIu64" bytes %"PRIu64" ret %d" --=20 2.17.1 From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776390278471.02196823559666; Thu, 5 Jul 2018 00:39:50 -0700 (PDT) Received: from localhost ([::1]:50784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayrd-0002hf-08 for importer@patchew.org; Thu, 05 Jul 2018 03:39:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faypb-0001Wg-Uz for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faypa-0000VJ-Cc for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39456 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faypW-0000IJ-8Q; Thu, 05 Jul 2018 03:37:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5F75401DE81; Thu, 5 Jul 2018 07:37:29 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BF542156889; Thu, 5 Jul 2018 07:37:25 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:36:54 +0800 Message-Id: <20180705073701.10558-3-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 05 Jul 2018 07:37:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 05 Jul 2018 07:37:29 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 2/9] block: Use BdrvChild to discard X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Other I/O functions are already using a BdrvChild pointer in the API, so make discard do the same. It makes it possible to initiate the same permission checks before doing I/O, and much easier to share the helper functions for this, which will be added and used by write, truncate and copy range paths. Signed-off-by: Fam Zheng --- block/blkdebug.c | 2 +- block/blkreplay.c | 2 +- block/block-backend.c | 2 +- block/copy-on-read.c | 2 +- block/io.c | 18 +++++++++--------- block/mirror.c | 2 +- block/qcow2-refcount.c | 2 +- block/raw-format.c | 2 +- block/throttle.c | 2 +- include/block/block.h | 4 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 526af2a808..0457bf5b66 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -625,7 +625,7 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDrive= rState *bs, return err; } =20 - return bdrv_co_pdiscard(bs->file->bs, offset, bytes); + return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 static int coroutine_fn blkdebug_co_block_status(BlockDriverState *bs, diff --git a/block/blkreplay.c b/block/blkreplay.c index b016dbeee7..766150ade6 100755 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -113,7 +113,7 @@ static int coroutine_fn blkreplay_co_pdiscard(BlockDriv= erState *bs, int64_t offset, int bytes) { uint64_t reqid =3D blkreplay_next_id(); - int ret =3D bdrv_co_pdiscard(bs->file->bs, offset, bytes); + int ret =3D bdrv_co_pdiscard(bs->file, offset, bytes); block_request_create(reqid, bs, qemu_coroutine_self()); qemu_coroutine_yield(); =20 diff --git a/block/block-backend.c b/block/block-backend.c index 6b75bca317..dd037b40a2 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1559,7 +1559,7 @@ int blk_co_pdiscard(BlockBackend *blk, int64_t offset= , int bytes) return ret; } =20 - return bdrv_co_pdiscard(blk_bs(blk), offset, bytes); + return bdrv_co_pdiscard(blk->root, offset, bytes); } =20 int blk_co_flush(BlockBackend *blk) diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 1dcdaeed69..a19164f9eb 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -116,7 +116,7 @@ static int coroutine_fn cor_co_pwrite_zeroes(BlockDrive= rState *bs, static int coroutine_fn cor_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { - return bdrv_co_pdiscard(bs->file->bs, offset, bytes); + return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 =20 diff --git a/block/io.c b/block/io.c index 8cc5ee661d..3e00667a2a 100644 --- a/block/io.c +++ b/block/io.c @@ -2590,7 +2590,7 @@ int bdrv_flush(BlockDriverState *bs) } =20 typedef struct DiscardCo { - BlockDriverState *bs; + BdrvChild *child; int64_t offset; int bytes; int ret; @@ -2599,17 +2599,17 @@ static void coroutine_fn bdrv_pdiscard_co_entry(voi= d *opaque) { DiscardCo *rwco =3D opaque; =20 - rwco->ret =3D bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->bytes); + rwco->ret =3D bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); } =20 -int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, - int bytes) +int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int by= tes) { BdrvTrackedRequest req; int max_pdiscard, ret; int head, tail, align; + BlockDriverState *bs =3D child->bs; =20 - if (!bs->drv) { + if (!bs || !bs->drv) { return -ENOMEDIUM; } =20 @@ -2720,11 +2720,11 @@ out: return ret; } =20 -int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) +int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes) { Coroutine *co; DiscardCo rwco =3D { - .bs =3D bs, + .child =3D child, .offset =3D offset, .bytes =3D bytes, .ret =3D NOT_DONE, @@ -2735,8 +2735,8 @@ int bdrv_pdiscard(BlockDriverState *bs, int64_t offse= t, int bytes) bdrv_pdiscard_co_entry(&rwco); } else { co =3D qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, rwco.ret =3D=3D NOT_DONE); + bdrv_coroutine_enter(child->bs, co); + BDRV_POLL_WHILE(child->bs, rwco.ret =3D=3D NOT_DONE); } =20 return rwco.ret; diff --git a/block/mirror.c b/block/mirror.c index 61bd9f3cf1..b48c3f8cf5 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1333,7 +1333,7 @@ static int coroutine_fn bdrv_mirror_top_do_write(Bloc= kDriverState *bs, break; =20 case MIRROR_METHOD_DISCARD: - ret =3D bdrv_co_pdiscard(bs->backing->bs, offset, bytes); + ret =3D bdrv_co_pdiscard(bs->backing, offset, bytes); break; =20 default: diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 18c729aa27..4e1589ad7a 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -734,7 +734,7 @@ void qcow2_process_discards(BlockDriverState *bs, int r= et) =20 /* Discard is optional, ignore the return value */ if (ret >=3D 0) { - bdrv_pdiscard(bs->file->bs, d->offset, d->bytes); + bdrv_pdiscard(bs->file, d->offset, d->bytes); } =20 g_free(d); diff --git a/block/raw-format.c b/block/raw-format.c index b78da564d4..d2c95a0ec6 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -297,7 +297,7 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverStat= e *bs, if (ret) { return ret; } - return bdrv_co_pdiscard(bs->file->bs, offset, bytes); + return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 static int64_t raw_getlength(BlockDriverState *bs) diff --git a/block/throttle.c b/block/throttle.c index f617f23a12..636c9764aa 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -149,7 +149,7 @@ static int coroutine_fn throttle_co_pdiscard(BlockDrive= rState *bs, ThrottleGroupMember *tgm =3D bs->opaque; throttle_group_co_io_limits_intercept(tgm, bytes, true); =20 - return bdrv_co_pdiscard(bs->file->bs, offset, bytes); + return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 static int throttle_co_flush(BlockDriverState *bs) diff --git a/include/block/block.h b/include/block/block.h index e5c7759a0c..901f5faaeb 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -387,8 +387,8 @@ AioWait *bdrv_get_aio_wait(BlockDriverState *bs); bdrv_get_aio_context(bs_), \ cond); }) =20 -int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes); -int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes); +int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes); +int bdrv_co_pdiscard(BdrvChild *child, 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); --=20 2.17.1 From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776519601831.4318714174777; Thu, 5 Jul 2018 00:41:59 -0700 (PDT) Received: from localhost ([::1]:50800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faytq-0004dp-Rl for importer@patchew.org; Thu, 05 Jul 2018 03:41:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faype-0001YF-GW for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faypd-0000ei-Kd for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53266 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faypb-0000WX-9C; Thu, 05 Jul 2018 03:37:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D33EC814F0A5; Thu, 5 Jul 2018 07:37:34 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85B9A2166BA9; Thu, 5 Jul 2018 07:37:30 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:36:55 +0800 Message-Id: <20180705073701.10558-4-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 05 Jul 2018 07:37:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 05 Jul 2018 07:37:34 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 3/9] block: Use uint64_t for BdrvTrackedRequest byte fields X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This matches the types used for bytes in the rest parts of block layer. In the case of bdrv_co_truncate, new_bytes can be the image size which probably doesn't fit in a 32 bit int. Signed-off-by: Fam Zheng --- block/io.c | 2 +- include/block/block_int.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index 3e00667a2a..443a8584c4 100644 --- a/block/io.c +++ b/block/io.c @@ -587,7 +587,7 @@ static void tracked_request_end(BdrvTrackedRequest *req) static void tracked_request_begin(BdrvTrackedRequest *req, BlockDriverState *bs, int64_t offset, - unsigned int bytes, + uint64_t bytes, enum BdrvTrackedRequestType type) { *req =3D (BdrvTrackedRequest){ diff --git a/include/block/block_int.h b/include/block/block_int.h index af71b414be..66c0e50d82 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -69,12 +69,12 @@ enum BdrvTrackedRequestType { typedef struct BdrvTrackedRequest { BlockDriverState *bs; int64_t offset; - unsigned int bytes; + uint64_t bytes; enum BdrvTrackedRequestType type; =20 bool serialising; int64_t overlap_offset; - unsigned int overlap_bytes; + uint64_t overlap_bytes; =20 QLIST_ENTRY(BdrvTrackedRequest) list; Coroutine *co; /* owner, used for deadlock detection */ --=20 2.17.1 From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776520425825.0160911672758; Thu, 5 Jul 2018 00:42:00 -0700 (PDT) Received: from localhost ([::1]:50801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faytr-0004eT-MP for importer@patchew.org; Thu, 05 Jul 2018 03:41:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faypn-0001bx-OW for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faypm-00013i-Fg for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39030 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fayph-0000on-Gi; Thu, 05 Jul 2018 03:37:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1713E407049A; Thu, 5 Jul 2018 07:37:41 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 946672156889; Thu, 5 Jul 2018 07:37:35 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:36:56 +0800 Message-Id: <20180705073701.10558-5-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Jul 2018 07:37:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Jul 2018 07:37:41 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 4/9] block: Extract common write req handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As a mechanical refactoring patch, this is the first step towards unified and more correct write code paths. This is helpful because multiple BlockDriverState fields need to be updated after modifying image data, and it's hard to maintain in multiple places such as copy offload, discard and truncate. Suggested-by: Kevin Wolf Signed-off-by: Fam Zheng --- block/io.c | 70 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/block/io.c b/block/io.c index 443a8584c4..03d9eb0a65 100644 --- a/block/io.c +++ b/block/io.c @@ -1538,6 +1538,48 @@ fail: return ret; } =20 +static inline int coroutine_fn +bdrv_co_write_req_prepare(BdrvChild *child, BdrvTrackedRequest *req, int f= lags) +{ + BlockDriverState *bs =3D child->bs; + bool waited; + int64_t end_sector =3D DIV_ROUND_UP(req->offset + req->bytes, BDRV_SEC= TOR_SIZE); + + if (bs->read_only) { + return -EPERM; + } + assert(!(bs->open_flags & BDRV_O_INACTIVE)); + assert((bs->open_flags & BDRV_O_NO_IO) =3D=3D 0); + assert(!(flags & ~BDRV_REQ_MASK)); + waited =3D wait_serialising_requests(req); + assert(!waited || !req->serialising); + assert(req->overlap_offset <=3D req->offset); + assert(req->offset + req->bytes <=3D req->overlap_offset + req->overla= p_bytes); + if (flags & BDRV_REQ_WRITE_UNCHANGED) { + assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE)); + } else { + assert(child->perm & BLK_PERM_WRITE); + } + assert(end_sector <=3D bs->total_sectors || child->perm & BLK_PERM_RES= IZE); + return notifier_with_return_list_notify(&bs->before_write_notifiers, r= eq); +} + +static inline void coroutine_fn +bdrv_co_write_req_finish(BdrvChild *child, BdrvTrackedRequest *req, int re= t) +{ + int64_t end_sector =3D DIV_ROUND_UP(req->offset + req->bytes, BDRV_SEC= TOR_SIZE); + BlockDriverState *bs =3D child->bs; + + atomic_inc(&bs->write_gen); + bdrv_set_dirty(bs, req->offset, req->bytes); + + stat64_max(&bs->wr_highest_offset, req->offset + req->bytes); + + if (ret =3D=3D 0) { + bs->total_sectors =3D MAX(bs->total_sectors, end_sector); + } +} + /* * Forwards an already correctly aligned write request to the BlockDriver, * after possibly fragmenting it. @@ -1548,10 +1590,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChi= ld *child, { BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; - bool waited; int ret; =20 - int64_t end_sector =3D DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); uint64_t bytes_remaining =3D bytes; int max_transfer; =20 @@ -1567,23 +1607,10 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvCh= ild *child, assert((offset & (align - 1)) =3D=3D 0); assert((bytes & (align - 1)) =3D=3D 0); assert(!qiov || bytes =3D=3D qiov->size); - assert((bs->open_flags & BDRV_O_NO_IO) =3D=3D 0); - assert(!(flags & ~BDRV_REQ_MASK)); max_transfer =3D QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_transfer, INT= _MAX), align); =20 - waited =3D wait_serialising_requests(req); - assert(!waited || !req->serialising); - assert(req->overlap_offset <=3D offset); - assert(offset + bytes <=3D req->overlap_offset + req->overlap_bytes); - if (flags & BDRV_REQ_WRITE_UNCHANGED) { - assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE)); - } else { - assert(child->perm & BLK_PERM_WRITE); - } - assert(end_sector <=3D bs->total_sectors || child->perm & BLK_PERM_RES= IZE); - - ret =3D notifier_with_return_list_notify(&bs->before_write_notifiers, = req); + ret =3D bdrv_co_write_req_prepare(child, req, flags); =20 if (!ret && bs->detect_zeroes !=3D BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF = && !(flags & BDRV_REQ_ZERO_WRITE) && drv->bdrv_co_pwrite_zeroes && @@ -1632,15 +1659,10 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvCh= ild *child, } bdrv_debug_event(bs, BLKDBG_PWRITEV_DONE); =20 - atomic_inc(&bs->write_gen); - bdrv_set_dirty(bs, offset, bytes); - - stat64_max(&bs->wr_highest_offset, offset + bytes); - if (ret >=3D 0) { - bs->total_sectors =3D MAX(bs->total_sectors, end_sector); ret =3D 0; } + bdrv_co_write_req_finish(child, req, ret); =20 return ret; } @@ -1755,10 +1777,6 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, if (!bs->drv) { return -ENOMEDIUM; } - if (bs->read_only) { - return -EPERM; - } - assert(!(bs->open_flags & BDRV_O_INACTIVE)); =20 ret =3D bdrv_check_byte_request(bs, offset, bytes); if (ret < 0) { --=20 2.17.1 From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776658721823.0663399582653; Thu, 5 Jul 2018 00:44:18 -0700 (PDT) Received: from localhost ([::1]:50809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayw3-0006NS-2L for importer@patchew.org; Thu, 05 Jul 2018 03:44:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faypr-0001fh-Nq for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faypq-0001GD-VC for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:51 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35054 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faypm-00011y-HF; Thu, 05 Jul 2018 03:37:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AD8E87A84; Thu, 5 Jul 2018 07:37:46 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB44A2156889; Thu, 5 Jul 2018 07:37:41 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:36:57 +0800 Message-Id: <20180705073701.10558-6-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 05 Jul 2018 07:37:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 05 Jul 2018 07:37:46 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 5/9] block: Fix handling of image enlarging write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Two problems exist when a write request that enlarges the image (i.e. write beyond EOF) finishes: 1) parent is not notified about size change; 2) dirty bitmap is not resized although we try to set the dirty bits; Fix them just like how bdrv_co_truncate works. Reported-by: Kevin Wolf Signed-off-by: Fam Zheng --- block/io.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index 03d9eb0a65..f06978dda0 100644 --- a/block/io.c +++ b/block/io.c @@ -40,6 +40,7 @@ =20 static AioWait drain_all_aio_wait; =20 +static void bdrv_parent_cb_resize(BlockDriverState *bs); static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags); =20 @@ -1571,13 +1572,17 @@ bdrv_co_write_req_finish(BdrvChild *child, BdrvTrac= kedRequest *req, int ret) BlockDriverState *bs =3D child->bs; =20 atomic_inc(&bs->write_gen); - bdrv_set_dirty(bs, req->offset, req->bytes); =20 stat64_max(&bs->wr_highest_offset, req->offset + req->bytes); =20 - if (ret =3D=3D 0) { - bs->total_sectors =3D MAX(bs->total_sectors, end_sector); + if (req->type !=3D BDRV_TRACKED_DISCARD && + ret =3D=3D 0 && + end_sector > bs->total_sectors) { + bs->total_sectors =3D end_sector; + bdrv_parent_cb_resize(bs); + bdrv_dirty_bitmap_truncate(bs, end_sector << BDRV_SECTOR_BITS); } + bdrv_set_dirty(bs, req->offset, req->bytes); } =20 /* --=20 2.17.1 From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776658350165.82682544442685; Thu, 5 Jul 2018 00:44:18 -0700 (PDT) Received: from localhost ([::1]:50810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayw4-0006OC-Il for importer@patchew.org; Thu, 05 Jul 2018 03:44:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faypu-0001j0-P0 for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faypt-0001Oz-QL for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:37:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53274 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faypr-0001Gm-Gy; Thu, 05 Jul 2018 03:37:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17479814F0A5; Thu, 5 Jul 2018 07:37:51 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF51D2156889; Thu, 5 Jul 2018 07:37:46 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:36:58 +0800 Message-Id: <20180705073701.10558-7-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 05 Jul 2018 07:37:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 05 Jul 2018 07:37:51 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 6/9] block: Use common req handling for discard X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reuse the new bdrv_co_write_req_prepare/finish helpers. The variation here is that discard requests don't affect bs->wr_highest_offset. Signed-off-by: Fam Zheng --- block/io.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/block/io.c b/block/io.c index f06978dda0..912fcb962a 100644 --- a/block/io.c +++ b/block/io.c @@ -1582,7 +1582,18 @@ bdrv_co_write_req_finish(BdrvChild *child, BdrvTrack= edRequest *req, int ret) bdrv_parent_cb_resize(bs); bdrv_dirty_bitmap_truncate(bs, end_sector << BDRV_SECTOR_BITS); } - bdrv_set_dirty(bs, req->offset, req->bytes); + if (req->bytes) { + switch (req->type) { + case BDRV_TRACKED_WRITE: + stat64_max(&bs->wr_highest_offset, req->offset + req->bytes); + /* fall through, to set dirty bits */ + case BDRV_TRACKED_DISCARD: + bdrv_set_dirty(bs, req->offset, req->bytes); + break; + default: + break; + } + } } =20 /* @@ -2643,10 +2654,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, = int64_t offset, int bytes) ret =3D bdrv_check_byte_request(bs, offset, bytes); if (ret < 0) { return ret; - } else if (bs->read_only) { - return -EPERM; } - assert(!(bs->open_flags & BDRV_O_INACTIVE)); =20 /* Do nothing if disabled. */ if (!(bs->open_flags & BDRV_O_UNMAP)) { @@ -2670,7 +2678,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int bytes) bdrv_inc_in_flight(bs); tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_DISCARD); =20 - ret =3D notifier_with_return_list_notify(&bs->before_write_notifiers, = &req); + ret =3D bdrv_co_write_req_prepare(child, &req, 0); if (ret < 0) { goto out; } @@ -2736,8 +2744,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int bytes) } ret =3D 0; out: - atomic_inc(&bs->write_gen); - bdrv_set_dirty(bs, req.offset, req.bytes); + bdrv_co_write_req_finish(child, &req, ret); tracked_request_end(&req); bdrv_dec_in_flight(bs); return ret; --=20 2.17.1 From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776513501379.3663737016998; Thu, 5 Jul 2018 00:41:53 -0700 (PDT) Received: from localhost ([::1]:50799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faytk-0004ZG-Nn for importer@patchew.org; Thu, 05 Jul 2018 03:41:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayq1-0001pp-PE for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:38:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fayq0-0001oQ-UZ for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:38:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53276 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faypw-0001WO-K7; Thu, 05 Jul 2018 03:37:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F3AC814F0A5; Thu, 5 Jul 2018 07:37:56 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBF3A2156889; Thu, 5 Jul 2018 07:37:51 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:36:59 +0800 Message-Id: <20180705073701.10558-8-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 05 Jul 2018 07:37:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 05 Jul 2018 07:37:56 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 7/9] block: Use common req handling in copy offloading X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This brings the request handling logic inline with write and discard, fixing write_gen, resize_cb, dirty bitmaps and image size refreshing. The last of these issues broke iotest case 222, which is now fixed. Signed-off-by: Fam Zheng --- block/io.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index 912fcb962a..d07849fa96 100644 --- a/block/io.c +++ b/block/io.c @@ -2962,7 +2962,11 @@ static int coroutine_fn bdrv_co_copy_range_internal(= BdrvChild *src, =20 if (!(flags & BDRV_REQ_NO_SERIALISING)) { wait_serialising_requests(&src_req); - wait_serialising_requests(&dst_req); + } + + ret =3D bdrv_co_write_req_prepare(dst, &dst_req, flags); + if (ret) { + goto out; } if (recurse_src) { ret =3D src->bs->drv->bdrv_co_copy_range_from(src->bs, @@ -2975,6 +2979,8 @@ static int coroutine_fn bdrv_co_copy_range_internal(B= drvChild *src, dst, dst_offset, bytes, flags); } +out: + bdrv_co_write_req_finish(dst, &dst_req, ret); tracked_request_end(&src_req); tracked_request_end(&dst_req); bdrv_dec_in_flight(src->bs); --=20 2.17.1 From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776650322585.1995506698258; Thu, 5 Jul 2018 00:44:10 -0700 (PDT) Received: from localhost ([::1]:50808 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayvx-0006J9-LA for importer@patchew.org; Thu, 05 Jul 2018 03:44:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayq9-0001uj-H2 for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:38:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fayq6-0002AD-CL for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:38:09 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39044 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fayq1-0001po-KS; Thu, 05 Jul 2018 03:38:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EE47407049A; Thu, 5 Jul 2018 07:38:01 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3C002156889; Thu, 5 Jul 2018 07:37:56 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:37:00 +0800 Message-Id: <20180705073701.10558-9-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Jul 2018 07:38:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Jul 2018 07:38:01 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 8/9] block: Fix bdrv_co_truncate overlap check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If we are growing the image and potentially using preallocation for the new area, we need to make sure that no write requests are made to the "preallocated" area which [@old_size, @offset), not [@offset, offset * 2 - @old_size). Signed-off-by: Fam Zheng Reviewed-by: Eric Blake --- block/io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index d07849fa96..ed18eb0ca3 100644 --- a/block/io.c +++ b/block/io.c @@ -3070,7 +3070,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, } =20 bdrv_inc_in_flight(bs); - tracked_request_begin(&req, bs, offset, new_bytes, BDRV_TRACKED_TRUNCA= TE); + tracked_request_begin(&req, bs, offset - new_bytes, new_bytes, + BDRV_TRACKED_TRUNCATE); =20 /* If we are growing the image and potentially using preallocation for= the * new area, we need to make sure that no write requests are made to it --=20 2.17.1 From nobody Tue Nov 4 18:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530776773951556.2402204156127; Thu, 5 Jul 2018 00:46:13 -0700 (PDT) Received: from localhost ([::1]:50826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayxq-00080E-A2 for importer@patchew.org; Thu, 05 Jul 2018 03:46:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fayqC-0001zA-7F for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:38:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fayqA-0002Uv-Vp for qemu-devel@nongnu.org; Thu, 05 Jul 2018 03:38:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39048 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fayq6-0002BQ-W0; Thu, 05 Jul 2018 03:38:07 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 847E4407049A; Thu, 5 Jul 2018 07:38:06 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2C412166BA9; Thu, 5 Jul 2018 07:38:01 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 5 Jul 2018 15:37:01 +0800 Message-Id: <20180705073701.10558-10-famz@redhat.com> In-Reply-To: <20180705073701.10558-1-famz@redhat.com> References: <20180705073701.10558-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Jul 2018 07:38:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Jul 2018 07:38:06 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 9/9] block: Use common write req handling in truncate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, John Snow , Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Truncation is the last to convert from open coded req handling to reusing helpers. This time the permission check in prepare has to adapt to the new caller: it checks a different permission bit, and don't trigger the before write notifier. Also, truncation should always trigger a bs->total_sectors update and in turn call parent resize_cb. Update the condition in finish helper, too. It's intended to do a duplicated bs->read_only check before calling bdrv_co_write_req_prepare() so that we can be more informative with the error message, as bdrv_co_write_req_prepare() doesn't have Error parameter. Signed-off-by: Fam Zheng --- block/io.c | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/block/io.c b/block/io.c index ed18eb0ca3..53f2bf4103 100644 --- a/block/io.c +++ b/block/io.c @@ -1556,13 +1556,22 @@ bdrv_co_write_req_prepare(BdrvChild *child, BdrvTra= ckedRequest *req, int flags) assert(!waited || !req->serialising); assert(req->overlap_offset <=3D req->offset); assert(req->offset + req->bytes <=3D req->overlap_offset + req->overla= p_bytes); - if (flags & BDRV_REQ_WRITE_UNCHANGED) { - assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE)); - } else { - assert(child->perm & BLK_PERM_WRITE); - } assert(end_sector <=3D bs->total_sectors || child->perm & BLK_PERM_RES= IZE); - return notifier_with_return_list_notify(&bs->before_write_notifiers, r= eq); + switch (req->type) { + case BDRV_TRACKED_WRITE: + case BDRV_TRACKED_DISCARD: + if (flags & BDRV_REQ_WRITE_UNCHANGED) { + assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRIT= E)); + } else { + assert(child->perm & BLK_PERM_WRITE); + } + return notifier_with_return_list_notify(&bs->before_write_notifier= s, req); + case BDRV_TRACKED_TRUNCATE: + assert(child->perm & BLK_PERM_RESIZE); + return 0; + default: + abort(); + } } =20 static inline void coroutine_fn @@ -1575,9 +1584,10 @@ bdrv_co_write_req_finish(BdrvChild *child, BdrvTrack= edRequest *req, int ret) =20 stat64_max(&bs->wr_highest_offset, req->offset + req->bytes); =20 - if (req->type !=3D BDRV_TRACKED_DISCARD && - ret =3D=3D 0 && - end_sector > bs->total_sectors) { + if (ret =3D=3D 0 && + (req->type =3D=3D BDRV_TRACKED_TRUNCATE || + (req->type !=3D BDRV_TRACKED_DISCARD && + end_sector > bs->total_sectors))) { bs->total_sectors =3D end_sector; bdrv_parent_cb_resize(bs); bdrv_dirty_bitmap_truncate(bs, end_sector << BDRV_SECTOR_BITS); @@ -3045,7 +3055,6 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, int64_t old_size, new_bytes; int ret; =20 - assert(child->perm & BLK_PERM_RESIZE); =20 /* if bs->drv =3D=3D NULL, bs is closed, so there's nothing to do here= */ if (!drv) { @@ -3078,7 +3087,16 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, * concurrently or they might be overwritten by preallocation. */ if (new_bytes) { mark_request_serialising(&req, 1); - wait_serialising_requests(&req); + } + if (bs->read_only) { + error_setg(errp, "Image is read-only"); + ret =3D -EACCES; + goto out; + } + ret =3D bdrv_co_write_req_prepare(child, &req, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to prepare request for trunca= tion"); + goto out; } =20 if (!drv->bdrv_co_truncate) { @@ -3090,13 +3108,6 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, ret =3D -ENOTSUP; goto out; } - if (bs->read_only) { - error_setg(errp, "Image is read-only"); - ret =3D -EACCES; - goto out; - } - - assert(!(bs->open_flags & BDRV_O_INACTIVE)); =20 ret =3D drv->bdrv_co_truncate(bs, offset, prealloc, errp); if (ret < 0) { @@ -3108,9 +3119,10 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, } else { offset =3D bs->total_sectors * BDRV_SECTOR_SIZE; } - bdrv_dirty_bitmap_truncate(bs, offset); - bdrv_parent_cb_resize(bs); - atomic_inc(&bs->write_gen); + /* It's possible that truncation succeeded but refresh_total_sectors + * failed, but the latter doesn't affect how we should finish the requ= est. + * Pass 0 as the last parameter so that dirty bitmaps etc. are handled= . */ + bdrv_co_write_req_finish(child, &req, 0); =20 out: tracked_request_end(&req); --=20 2.17.1