From nobody Mon Apr 29 02:27:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579374834; cv=none; d=zohomail.com; s=zohoarc; b=DAAXuGORjFWpudtDrXY70lo978h+B1xmZIkwTDwoGHYKn2b3va3aTlQJRxf3DuzU0KxOB+uPEIXwJhSfs5R881xwxt7mp/7VC2rx1CcQBjln69dsyVQ6vANYdZOuYnAXR0zZDVq/UzI6u5TZO81nqQW0zs086XbZ1GyuI18nGaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579374834; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tU0tqKTyF6mG4OdZGy/YoITFRev2rTHsJBdgq0mqCIQ=; b=IKjh9fJwGkzFze65Fe0P6ieJpr3QWhf5sOR5nPen+1RfCNI4B9Rug/mHJtj7jJWSFk0mVLUHRts3ML63qwD0rjxZYR2Ga1yvMTOZdsN8DOLpfZnyxFCOpeyl0N2SIeP15b4HIis9j+vlr/0KnCmoXUB/3R0FZbqe7bedQeeNvO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579374833911310.2578942550282; Sat, 18 Jan 2020 11:13:53 -0800 (PST) Received: from localhost ([::1]:43888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istXc-00069o-Mq for importer@patchew.org; Sat, 18 Jan 2020 14:13:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48549) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istTt-0001UJ-8w for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1istTs-0004PG-4k for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:01 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:48327) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1istTr-0004N5-Nt; Sat, 18 Jan 2020 14:10:00 -0500 Received: from [80.30.177.7] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1istTn-000659-9d; Sat, 18 Jan 2020 20:09:55 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1istTW-0002JV-Ob; Sat, 18 Jan 2020 20:09:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=tU0tqKTyF6mG4OdZGy/YoITFRev2rTHsJBdgq0mqCIQ=; b=pgoRITyVH0dH6Xi56ZsgyXrA/+ibRZcHdokopw/ATnTXtPrD0rwkg70u49oQnw+fSStZnrCXVjiVkLE217W6v494CmW9mvgwsBzdLiH95jYLZexG+kDRBfmjzVw1vZ+9KlmcmjSb3vlXZV7DtrduyUolK0zaupQIak05g3kq3aCJcsmQ4c9KZyUJHMzSo30/m1ULP0VBdfrPQpV03ARSVVs/ik2uRfuh320ESBEpv3aO+AxtNcTE5vY7Uq9y9K2pJybSAfqytzw0rAdRUNkuqQz9ExZS5fvbm56ghTahAstvMjNoJzTZaG5ffS0aavllxJl/ucmK462J/6H89JNPOg==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v3 1/5] qcow2: Don't round the L1 table allocation up to the sector size Date: Sat, 18 Jan 2020 20:09:26 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Nir Soffer Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The L1 table is read from disk using the byte-based bdrv_pread() and is never accessed beyond its last element, so there's no need to allocate more memory than that. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 5 ++--- block/qcow2-refcount.c | 2 +- block/qcow2-snapshot.c | 3 +-- block/qcow2.c | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8982b7b762..932fc48919 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -124,12 +124,11 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_= t min_size, #endif =20 new_l1_size2 =3D sizeof(uint64_t) * new_l1_size; - new_l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(new_l1_size2, 512)); + new_l1_table =3D qemu_try_blockalign(bs->file->bs, new_l1_size2); if (new_l1_table =3D=3D NULL) { return -ENOMEM; } - memset(new_l1_table, 0, ROUND_UP(new_l1_size2, 512)); + memset(new_l1_table, 0, new_l1_size2); =20 if (s->l1_size) { memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t)); diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index f67ac6b2d8..c963bc8de1 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1262,7 +1262,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, * l1_table_offset when it is the current s->l1_table_offset! Be caref= ul * when changing this! */ if (l1_table_offset !=3D s->l1_table_offset) { - l1_table =3D g_try_malloc0(ROUND_UP(l1_size2, 512)); + l1_table =3D g_try_malloc0(l1_size2); if (l1_size2 && l1_table =3D=3D NULL) { ret =3D -ENOMEM; goto fail; diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 5ab64da1ec..82c32d4c9b 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -1024,8 +1024,7 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, return ret; } new_l1_bytes =3D sn->l1_size * sizeof(uint64_t); - new_l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(new_l1_bytes, 512)); + new_l1_table =3D qemu_try_blockalign(bs->file->bs, new_l1_bytes); if (new_l1_table =3D=3D NULL) { return -ENOMEM; } diff --git a/block/qcow2.c b/block/qcow2.c index cef9d72b3a..ba71a815b6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1492,7 +1492,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, =20 if (s->l1_size > 0) { s->l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(s->l1_size * sizeof(uint64_t), 512)); + s->l1_size * sizeof(uint64_t)); if (s->l1_table =3D=3D NULL) { error_setg(errp, "Could not allocate L1 table"); ret =3D -ENOMEM; --=20 2.20.1 From nobody Mon Apr 29 02:27:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579374724; cv=none; d=zohomail.com; s=zohoarc; b=c5iGchN2CoQJ2svw59HiyRX21yrbv96iXmSWyjmj4PqjtmhskxbjWrg7tNnZce4Iu31wLk/At9dQho7cIJyCm6INJhrYjRBY/RTlscZQ2gditlJjHcaaQNAql3iZvWiRw8HH0A/DQWPmmq11w7xUVuE/WMSX90mAn/K4coBLDS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579374724; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m9u8SBcxUh+7uhuAIPbMfHUfenn9UwZvCzhHkBhyjA8=; b=ZNaHPbz7GSSQF232+7nPsI8uZMbAj+3lUnJcSgiitIlqmMYIwLw+H+j1oZJ/i0dgxob1fbPfQ/XdwF47UlvL+XimDSMCqKfLViYOLI9vWBeQSH5kJuiGdgiLVjlLk0QpTE4beNpy5aAgfqcVS+tlLZIr4AyJrAnQfk/Ae9JJH2o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579374723063174.63324448692686; Sat, 18 Jan 2020 11:12:03 -0800 (PST) Received: from localhost ([::1]:43832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istVp-0003Hd-8k for importer@patchew.org; Sat, 18 Jan 2020 14:12:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48519) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istTs-0001S0-9J for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1istTr-0004Od-7S for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:00 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:48332) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1istTq-0004N6-5G; Sat, 18 Jan 2020 14:09:59 -0500 Received: from [80.30.177.7] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1istTn-000658-4r; Sat, 18 Jan 2020 20:09:55 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1istTW-0002JX-PY; Sat, 18 Jan 2020 20:09:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=m9u8SBcxUh+7uhuAIPbMfHUfenn9UwZvCzhHkBhyjA8=; b=j0okyTSf3Wyt1lgbyvesdjmiZe49WNahJpOBPpnRee5yLq3MIkPC//swAuGIcuYm8XJIKf5/BSzGhhusIgEEqvBsVDxdJG11QrMmYrvKqPxAcmPfzZ2K3ZjafVdq56xsGVKBz073eMCTLQQ0YgwwUgge0epBKJvIhzqycyZYEpq6OG5sU8SrJNUQS0JqLUS/SlXf5/PN2oZSahp7yszKbXfdZqK1xSXhMO1V7NN5slOKQh9nESyR5juEVPgmR5RdBU6f7z0KnHc6WmyB9vjp7dXpXI0XKi6hMJ7o8SJNI0mDGtv8OGKtfvVfqUU/T7sHr4six1GNzl2ViGanHhDOZQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v3 2/5] qcow2: Tighten cluster_offset alignment assertions Date: Sat, 18 Jan 2020 20:09:27 +0100 Message-Id: <558ba339965f858bede4c73ce3f50f0c0493597d.1579374329.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Nir Soffer Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qcow2_alloc_cluster_offset() and qcow2_get_cluster_offset() always return offsets that are cluster-aligned so don't just check that they are sector-aligned. The check in qcow2_co_preadv_task() is also replaced by an assertion for the same reason. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index ba71a815b6..100393fd3b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2168,10 +2168,7 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDr= iverState *bs, offset, bytes, qiov, qiov_offset= ); =20 case QCOW2_CLUSTER_NORMAL: - if ((file_cluster_offset & 511) !=3D 0) { - return -EIO; - } - + assert(offset_into_cluster(s, file_cluster_offset) =3D=3D 0); if (bs->encrypted) { return qcow2_co_preadv_encrypted(bs, file_cluster_offset, offset, bytes, qiov, qiov_off= set); @@ -2507,7 +2504,7 @@ static coroutine_fn int qcow2_co_pwritev_part( goto out_locked; } =20 - assert((cluster_offset & 511) =3D=3D 0); + assert(offset_into_cluster(s, cluster_offset) =3D=3D 0); =20 ret =3D qcow2_pre_write_overlap_check(bs, 0, cluster_offset + offset_in_clu= ster, @@ -3897,7 +3894,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs, goto fail; } =20 - assert((cluster_offset & 511) =3D=3D 0); + assert(offset_into_cluster(s, cluster_offset) =3D=3D 0); =20 ret =3D qcow2_pre_write_overlap_check(bs, 0, cluster_offset + offset_in_cluster, cur_bytes, true); --=20 2.20.1 From nobody Mon Apr 29 02:27:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579374726; cv=none; d=zohomail.com; s=zohoarc; b=UDHteiL+O1jOi7XJ7Hk0VuyrkFHGn5W7C8Y38xISNH8JRKyYq0gLButsZ+hRPpk2T8f+9Y8ip1YzNyYGTz1xoYL5B/t/nsg+MGS7HVuSZIHBhnc+DUhTEBboPBkchio/0JA4K8183oBY4uW2cl8WfB+k4cKx+RWCMAor9F7/YcI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579374726; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bb2ZOgFSlgK1sgntakipNlk6DfTQcGMMCLiGx3ZcCbM=; b=c/ubG295kxOS03owk060BtfV1/oET3HEgr414Cnu2arFvN3sjKP7GAWvbcxXVz/McPZ7BA06U6dqdu2QODYTnHVOI/G2GXuOLaDfqsBHCQLnFZCMl2KGBjgBujoISHI3lJDUzw4JGMySVHyZr7NLaeXANADB43tyL7skENvmPlc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579374726469714.9191582368321; Sat, 18 Jan 2020 11:12:06 -0800 (PST) Received: from localhost ([::1]:43840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istVs-0003Ne-VN for importer@patchew.org; Sat, 18 Jan 2020 14:12:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48522) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istTs-0001SK-CZ for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1istTr-0004OT-74 for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:00 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:48325) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1istTq-0004N3-J2; Sat, 18 Jan 2020 14:09:59 -0500 Received: from [80.30.177.7] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1istTn-00065B-CI; Sat, 18 Jan 2020 20:09:55 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1istTW-0002JZ-R2; Sat, 18 Jan 2020 20:09:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=bb2ZOgFSlgK1sgntakipNlk6DfTQcGMMCLiGx3ZcCbM=; b=aQI480eK1SD/LfIRjHtbIeLn89genUdPEO+1XHFdru9yY7J56vSdGNYPY2g1YGdrwXCDAwDr+E2RF3oKSSxJ3E9ZYyT5kqmeF1aQagZ0o89X8Q6PmOvT/CrI/It/kLxj3fsP3Ufu4anQtKXSOSp5yqlGQKpeWxeCTKIqRLHTLo8ZEiEqNyODr7OQpHxgt+PRdjSxmrALqdq5Ofyd+V1xscZvOKIbt7lqBl2c3ZqQNSOepR5dk3I3mZ2B73gZo8I/mose1w5UybuvdRbeBsUCIFkmhIbfXq40waRUOQ9CCaFG0o2CpFOdZZkmZQ8Em+oqdlqZBBLldi2OYtiI+TSeTQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v3 3/5] qcow2: Use bs->bl.request_alignment when updating an L1 entry Date: Sat, 18 Jan 2020 20:09:28 +0100 Message-Id: <71f34d4ae4b367b32fb36134acbf4f4f7ee681f4.1579374329.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Nir Soffer Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When updating an L1 entry the qcow2 driver writes a (512-byte) sector worth of data to avoid a read-modify-write cycle. Instead of always writing 512 bytes we should follow the alignment requirements of the storage backend. (the only exception is when the alignment is larger than the cluster size because then we could be overwriting data after the L1 table) Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 932fc48919..f1b5535b04 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -216,26 +216,31 @@ static int l2_load(BlockDriverState *bs, uint64_t off= set, } =20 /* - * Writes one sector of the L1 table to the disk (can't update single entr= ies - * and we really don't want bdrv_pread to perform a read-modify-write) + * Writes an L1 entry to disk (note that depending on the alignment + * requirements this function may write more that just one entry in + * order to prevent bdrv_pwrite from performing a read-modify-write) */ -#define L1_ENTRIES_PER_SECTOR (512 / 8) int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index) { BDRVQcow2State *s =3D bs->opaque; - uint64_t buf[L1_ENTRIES_PER_SECTOR] =3D { 0 }; int l1_start_index; int i, ret; + int bufsize =3D MAX(sizeof(uint64_t), + MIN(bs->file->bs->bl.request_alignment, s->cluster_s= ize)); + int nentries =3D bufsize / sizeof(uint64_t); + g_autofree uint64_t *buf =3D g_try_new0(uint64_t, nentries); =20 - l1_start_index =3D l1_index & ~(L1_ENTRIES_PER_SECTOR - 1); - for (i =3D 0; i < L1_ENTRIES_PER_SECTOR && l1_start_index + i < s->l1_= size; - i++) - { + if (buf =3D=3D NULL) { + return -ENOMEM; + } + + l1_start_index =3D QEMU_ALIGN_DOWN(l1_index, nentries); + for (i =3D 0; i < MIN(nentries, s->l1_size - l1_start_index); i++) { buf[i] =3D cpu_to_be64(s->l1_table[l1_start_index + i]); } =20 ret =3D qcow2_pre_write_overlap_check(bs, QCOW2_OL_ACTIVE_L1, - s->l1_table_offset + 8 * l1_start_index, sizeof(buf), false); + s->l1_table_offset + 8 * l1_start_index, bufsize, false); if (ret < 0) { return ret; } @@ -243,7 +248,7 @@ int qcow2_write_l1_entry(BlockDriverState *bs, int l1_i= ndex) BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); ret =3D bdrv_pwrite_sync(bs->file, s->l1_table_offset + 8 * l1_start_index, - buf, sizeof(buf)); + buf, bufsize); if (ret < 0) { return ret; } --=20 2.20.1 From nobody Mon Apr 29 02:27:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579374722; cv=none; d=zohomail.com; s=zohoarc; b=L8DCZTuMtIfSGuwvlR2cNXyi031i2u2rwBrR9wvFseHwYzOGjXl3bDJz739ZGn+wRwBzGGEJjZ3XWVLVlitAP4g85ZwGwHtQBXL2MDOAZXDllA/6ykLXoFBU12ZYYGpv/7/DokwCIrWw1GxRXW4gkf02BlQQokkvFIe8vuu/XdU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579374722; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pw2TwbK9Mz/rKuQHrtIpjSRKPh4TtO2hbBolc7OPVq0=; b=Hii9YruYNV9MeY74YzRBwdys3f2qDL+UT+vz/hiiQrLLuVlJkARl8JSjH9BEUNeST3IrYdN9o8ZYPhl6O5WAJjHcsLBczU516jQYRWxftV5C0Ew2U111jXQLOyxz7YT4+q19nWaTrOrdFxHXyD5zKImcPGNMwxm/o1ZdiQEjPBo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579374721600593.9415408403859; Sat, 18 Jan 2020 11:12:01 -0800 (PST) Received: from localhost ([::1]:43828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istVm-0003EY-0i for importer@patchew.org; Sat, 18 Jan 2020 14:11:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48512) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istTs-0001RI-5n for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1istTr-0004OZ-76 for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:00 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:48331) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1istTq-0004N1-Ql; Sat, 18 Jan 2020 14:09:59 -0500 Received: from [80.30.177.7] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1istTn-00065C-Bs; Sat, 18 Jan 2020 20:09:55 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1istTW-0002Jb-Rl; Sat, 18 Jan 2020 20:09:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=pw2TwbK9Mz/rKuQHrtIpjSRKPh4TtO2hbBolc7OPVq0=; b=hAfqtAio/7/6coZ1KGphyNULa/THKp2sZ5WO13W2YLMsN7OmTLsMD+ccB3Vyx5anjfO9fZkxz3SKmPTupdljWQDcVU4rX8F/41no/R89r+P276ZMeJdJn+TANVeRlBenjG7BWCJ7cuVTWYvNI0f8yLi/jnm3si9AK7ZIL5g9o+65NvTE9YjG0zANRwORdfmWKM/x65uPA7/R2otzCadIwO8x8/f4wUfXG0ypOgk7URjICRBuJgEVLYwknzo4nh1vlGRuwVeRR/qOPyBSkmbITwCw9QSyPS2cnJY6WZ4PmOHQuW1URxksK4qaHTPvSaDnQ0qM6mxAGuTn2SfO7V1hCw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v3 4/5] qcow2: Don't require aligned offsets in qcow2_co_copy_range_from() Date: Sat, 18 Jan 2020 20:09:29 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Nir Soffer Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qemu-img's convert_co_copy_range() operates at the sector level and block_copy() operates at the cluster level so this condition is always true, but it is not necessary to restrict this here, so let's leave it to the driver implementation return an error if there is any. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 100393fd3b..a6b0d4ee1d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3829,10 +3829,6 @@ qcow2_co_copy_range_from(BlockDriverState *bs, case QCOW2_CLUSTER_NORMAL: child =3D s->data_file; copy_offset +=3D offset_into_cluster(s, src_offset); - if ((copy_offset & 511) !=3D 0) { - ret =3D -EIO; - goto out; - } break; =20 default: --=20 2.20.1 From nobody Mon Apr 29 02:27:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579374830; cv=none; d=zohomail.com; s=zohoarc; b=UX04YK9KxCEVpOzqaQIdSq++VX8tf5R5KjJabSpQISyyqEfZ9TosR8xBsXcTTWU+zaagdATjZaAl57pawXuLe/oaG1SRRpXxOZXHoWXitgYO9R7qwHOIEj58mEreE9z/8Pi07Ch42eBJr3jkKj2HnHQIy/9y4APxLYrIISKU+BE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579374830; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BZKfhQ5ZLUQf4N/TkgPawId09t6hU5S5JwF1mA9yA/I=; b=CLMe5iacvOVTdbq6V9ZDqaC/OAkM4fn1KPwR5Wa7LSK2pBvzecRCX6MMWbcMxwN0cPOBQFUS5aa6jVP99ABFdqs7B2iCVX97qx2SyHGgwRa305Mwni38IizTRbA3mKu3Lq1EBco6UjyV+8NOCr0BVLbVjzBzPXTctkg5F6MLds0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579374830609284.6026288820634; Sat, 18 Jan 2020 11:13:50 -0800 (PST) Received: from localhost ([::1]:43884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istXZ-000657-F5 for importer@patchew.org; Sat, 18 Jan 2020 14:13:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48518) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1istTs-0001Rv-8d for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1istTr-0004OO-6u for qemu-devel@nongnu.org; Sat, 18 Jan 2020 14:10:00 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:48323) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1istTq-0004N2-JA; Sat, 18 Jan 2020 14:09:59 -0500 Received: from [80.30.177.7] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1istTn-00065A-D9; Sat, 18 Jan 2020 20:09:55 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1istTW-0002Jd-Sb; Sat, 18 Jan 2020 20:09:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=BZKfhQ5ZLUQf4N/TkgPawId09t6hU5S5JwF1mA9yA/I=; b=dTXZtkbEyE9mopPGlMbZ8IzDbmcBGqWyUj8RWUv681G48QNo0SJTBhD2yRXeYQVemmwd0p2jc+DAq6mjv7uUaub2A6q7jxCijZU3r88j8cfuxl/uPwUVTda5ly/DBpya/3yI+ncjDxamt52xUB00uZQgC9IndhyruAHmZ+fDEHCdNhrjUDP/jJTFP3l2reprXzEP7rg259WSKbZHiZ4np+zJquYZJRI5rGhqCoSvdbZRQWf4/mTulmOQtgvpwVBt2mtsr/hm0vnOr00bbbX/NVZocze4qhU3JGXXSTc17mXNqOPyIjqnoGOXis0g8gVs0kHe4MqfA9MIUwfQNFqQyQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v3 5/5] qcow2: Use BDRV_SECTOR_SIZE instead of the hardcoded value Date: Sat, 18 Jan 2020 20:09:30 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Nir Soffer Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This replaces all remaining instances in the qcow2 code. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index a6b0d4ee1d..6cc13e388c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3273,7 +3273,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) =20 /* Validate options and set default values */ if (!QEMU_IS_ALIGNED(qcow2_opts->size, BDRV_SECTOR_SIZE)) { - error_setg(errp, "Image size must be a multiple of 512 bytes"); + error_setg(errp, "Image size must be a multiple of %u bytes", + (unsigned) BDRV_SECTOR_SIZE); ret =3D -EINVAL; goto out; } @@ -3947,8 +3948,9 @@ static int coroutine_fn qcow2_co_truncate(BlockDriver= State *bs, int64_t offset, return -ENOTSUP; } =20 - if (offset & 511) { - error_setg(errp, "The new size must be a multiple of 512"); + if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { + error_setg(errp, "The new size must be a multiple of %u", + (unsigned) BDRV_SECTOR_SIZE); return -EINVAL; } =20 --=20 2.20.1