From nobody Wed Nov 5 10:26:02 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=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533663913763844.0562273659876; Tue, 7 Aug 2018 10:45:13 -0700 (PDT) Received: from localhost ([::1]:40218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fn62e-0008VL-CV for importer@patchew.org; Tue, 07 Aug 2018 13:45:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fn60u-0007Tg-5B for qemu-devel@nongnu.org; Tue, 07 Aug 2018 13:43:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fn60q-000216-Vq for qemu-devel@nongnu.org; Tue, 07 Aug 2018 13:43:20 -0400 Received: from relay.sw.ru ([185.231.240.75]:45002) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fn60q-0001xW-Ms; Tue, 07 Aug 2018 13:43:16 -0400 Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fn60m-0003lt-74; Tue, 07 Aug 2018 20:43:12 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 7 Aug 2018 20:43:05 +0300 Message-Id: <20180807174311.32454-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180807174311.32454-1-vsementsov@virtuozzo.com> References: <20180807174311.32454-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/7] qcow2: move qemu_co_mutex_lock below decryption procedure 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: kwolf@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" We are not working with a shared state data in the decruption code and thus this operation is safe. On the other hand this significantly reduces the scope of the lock. Signed-off-by: Denis V. Lunev --- block/qcow2.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index ec9e6238a0..41def07c67 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1880,9 +1880,11 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverS= tate *bs, uint64_t offset, break; =20 case QCOW2_CLUSTER_NORMAL: + qemu_co_mutex_unlock(&s->lock); + if ((cluster_offset & 511) !=3D 0) { ret =3D -EIO; - goto fail; + goto fail_nolock; } =20 if (bs->encrypted) { @@ -1899,7 +1901,7 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverSt= ate *bs, uint64_t offset, * s->cluster_size); if (cluster_data =3D=3D NULL) { ret =3D -ENOMEM; - goto fail; + goto fail_nolock; } } =20 @@ -1909,13 +1911,11 @@ static coroutine_fn int qcow2_co_preadv(BlockDriver= State *bs, uint64_t offset, } =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - qemu_co_mutex_unlock(&s->lock); ret =3D bdrv_co_preadv(bs->file, cluster_offset + offset_in_cluster, cur_bytes, &hd_qiov, 0); - qemu_co_mutex_lock(&s->lock); if (ret < 0) { - goto fail; + goto fail_nolock; } if (bs->encrypted) { assert(s->crypto); @@ -1929,10 +1929,11 @@ static coroutine_fn int qcow2_co_preadv(BlockDriver= State *bs, uint64_t offset, cur_bytes, NULL) < 0) { ret =3D -EIO; - goto fail; + goto fail_nolock; } qemu_iovec_from_buf(qiov, bytes_done, cluster_data, cur_by= tes); } + qemu_co_mutex_lock(&s->lock); break; =20 default: @@ -1950,6 +1951,7 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverSt= ate *bs, uint64_t offset, fail: qemu_co_mutex_unlock(&s->lock); =20 +fail_nolock: qemu_iovec_destroy(&hd_qiov); qemu_vfree(cluster_data); =20 --=20 2.11.1