From nobody Sat Feb 7 05:49:32 2026 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.zoho.com; dkim=fail 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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498743275409721.6125821290657; Thu, 29 Jun 2017 06:34:35 -0700 (PDT) Received: from localhost ([::1]:39393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZaX-0003kn-U9 for importer@patchew.org; Thu, 29 Jun 2017 09:34:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUF-0005jh-Et for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUE-0001LO-I5 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:27:59 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:34606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUE-0001KI-Bw; Thu, 29 Jun 2017 09:27:58 -0400 Received: by mail-wr0-x243.google.com with SMTP id k67so36687139wrc.1; Thu, 29 Jun 2017 06:27:58 -0700 (PDT) Received: from localhost.localdomain (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id i22sm4087691wrb.30.2017.06.29.06.27.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2ofn5mafspPfKMfrmyUrwHUxyf4r9kXdbN4S+5It7R4=; b=fJPH7KWyefC12kj2lRdHfEgbir8O5ZSKmn+VSJ9mwpOvX+wp2T8UDfyiYDXzJmbia+ JYVTvc1dz9GciLjvK4g9/DvtrhzBYDerKHCIwijS3H+suFI8KGUcXcdQ6Ojr7gyOBl28 vdY+54BTG5jBenL1DPTpVAYUWbigaQfkV9hcCQdx7+rXjy5qQCiddsBCq4H210qGNicK lomg1hO6h+O++7Mpu0zha9DIXtkQn1U6qg+41ELTXA+Ty8zoZUWwnevciZJCcDg1pYjK zXjvVag0F9b/12fDACz1hskEqSak2zWsZ2poCK5Pu6h//ZRmQDp5SHfIStbcHIeAfyv/ hAUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=2ofn5mafspPfKMfrmyUrwHUxyf4r9kXdbN4S+5It7R4=; b=El4tTQNz0AUBiQ8BcaxhxpuTfmA2MHTWimHmwXjCNBEUzW4k1Lr9fgw09nGSam6WQX mgV+RbZpGO0P25WZnfN17vUPzeMPGkH7jSQMywn9A/MbJVlejnESy/8xtuMfim7neKvp GHp4dvq5Dir0IRA1oHmioyhveLII/rViiP/T5rAnzlKZhQ/8hMB7jWBVvGnj88JfE7CU Te1evADy/ai7gfHWHvLFgrvqTm5sajdzn9T1Nt4yRunBBvCZxPmW2DrqYaKGsz3c7Z99 2jZz75D4qNu2GKiw9hRg7ZO4S6119TWm8XWw1DPRK716uApqSJqxwbteLoAwEK0jrstT LU9A== X-Gm-Message-State: AKS2vOwscj0qEnP+YBqn6JaepVR/NAiXSHE4qT+E5YAx60txlU6K/egn dbTDXgoaQSGLAv5o57M= X-Received: by 10.223.169.117 with SMTP id u108mr23388955wrc.17.1498742877219; Thu, 29 Jun 2017 06:27:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:42 +0200 Message-Id: <20170629132749.997-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170629132749.997-1-pbonzini@redhat.com> References: <20170629132749.997-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH 04/11] vpc: make it thread-safe 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, qemu-block@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/vpc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 4240ba9d1c..0ff686540a 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -496,12 +496,6 @@ static inline int64_t get_image_offset(BlockDriverStat= e *bs, uint64_t offset, return block_offset; } =20 -static inline int64_t get_sector_offset(BlockDriverState *bs, - int64_t sector_num, bool write) -{ - return get_image_offset(bs, sector_num * BDRV_SECTOR_SIZE, write); -} - /* * Writes the footer to the end of the image file. This is needed when the * file grows as it overwrites the old footer @@ -696,6 +690,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(Blo= ckDriverState *bs, VHDFooter *footer =3D (VHDFooter*) s->footer_buf; int64_t start, offset; bool allocated; + int64_t ret; int n; =20 if (be32_to_cpu(footer->type) =3D=3D VHD_FIXED) { @@ -705,10 +700,13 @@ static int64_t coroutine_fn vpc_co_get_block_status(B= lockDriverState *bs, (sector_num << BDRV_SECTOR_BITS); } =20 - offset =3D get_sector_offset(bs, sector_num, 0); + qemu_co_mutex_lock(&s->lock); + + offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, 0); start =3D offset; allocated =3D (offset !=3D -1); *pnum =3D 0; + ret =3D 0; =20 do { /* All sectors in a block are contiguous (without using the bitmap= ) */ @@ -723,15 +721,17 @@ static int64_t coroutine_fn vpc_co_get_block_status(B= lockDriverState *bs, * sectors since there is always a bitmap in between. */ if (allocated) { *file =3D bs->file->bs; - return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + break; } if (nb_sectors =3D=3D 0) { break; } - offset =3D get_sector_offset(bs, sector_num, 0); + offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, 0); } while (offset =3D=3D -1); =20 - return 0; + qemu_co_mutex_unlock(&s->lock); + return ret; } =20 /* --=20 2.13.0