From nobody Wed Feb 11 02:07:20 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 1496224420480721.0533780476749; Wed, 31 May 2017 02:53:40 -0700 (PDT) Received: from localhost ([::1]:58188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0Jt-0001ym-Dn for importer@patchew.org; Wed, 31 May 2017 05:53:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AH-0002SI-GD for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AG-0001k3-NR for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:41 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34754) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AG-0001jQ-HK; Wed, 31 May 2017 05:43:40 -0400 Received: by mail-wm0-x242.google.com with SMTP id d127so2256862wmf.1; Wed, 31 May 2017 02:43:40 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:38 -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=T+wmK7N/Uznc2VxhwtB68JCCGo4695Z7O886C/vuOEY=; b=ltILr/jPvwiZ+VICpZrauf7AO4yT5xj36mGbjp1e8m0W+pSW63GHzSpwcK4E5xb9Co LjAluf7As+sO0kMwy1gkhMjhRZ7i/TJojjJVyOJzarf+BlX9Lhd2SdK5hXSlKgel49bg GmLbKg/clhYN32XrG5+uNWJyqsTPtLaTX9U7k9fVGQ1GFsRf7beTJr4mwU3EBXCh+c2v CTqqZH13gjJFMWE3qMNV1rFABUwLfZA8oAA4dB77LO4cBWJ08jJGHb2NaOLwlVGbYP4y 7jBCeTigl9iD9XNccwfhik96XHfj4pb+eEMns2aY+mJDSUegbsGxKIdX/gJATUoi72qv z7qw== 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=T+wmK7N/Uznc2VxhwtB68JCCGo4695Z7O886C/vuOEY=; b=hH/vUUqZVDFHqxaVHO56W8yCdifsS+6UBwIerEOtiaYOEiwYZ8qaPSFjWIbf4KRf2B WCvcQ1Mon9R0NuIMy2QOat9B1ntoB1IC11sjCPs/HL3Xsva+uLicfNXiNKaAQTiTDAkF JRxxqDzBQgCqkzwlJgCdpoh5XpJ9K2P07AlIw64dZ09bgUrFQaibTNWB062IFWddgtRs jmtgZNAN0aUXv6w4GXTeHTe7dVaGtlCMYZijYu4gb3Izs9ozYZ8Dptdhz4sERPXRp7n5 eMOVwPDHKPjt/yVf9GrPGxVc47baxh12KXzFJFJlEFp5VgsI+jOXlJmPvQqDGbrOCVF6 PCfQ== X-Gm-Message-State: AODbwcA7eJzKqwKim6dHlNo/ZSjJ3KFK7aNU6lkiI3GIojlMwiiEGyKg EQv7FfC5lAOBFhMvn/8= X-Received: by 10.28.197.11 with SMTP id v11mr4531562wmf.84.1496223819273; Wed, 31 May 2017 02:43:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:23 +0200 Message-Id: <20170531094330.1808-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@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" Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake --- block/vpc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index ecfee77149..d61754d4d5 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