From nobody Sun May 5 18:22:20 2024 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; 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 1487960507515394.86291939849036; Fri, 24 Feb 2017 10:21:47 -0800 (PST) Received: from localhost ([::1]:39155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKUz-0001Zx-Tm for importer@patchew.org; Fri, 24 Feb 2017 13:21:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQj-0006Dz-8d for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQi-0002fV-CR for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46756) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQe-0002bv-HN; Fri, 24 Feb 2017 13:17:16 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF82C7E9E2; Fri, 24 Feb 2017 18:17:16 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCA015460; Fri, 24 Feb 2017 13:17:15 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:16:52 +0100 Message-Id: <1487960230-18054-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 24 Feb 2017 18:17:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/19] qemu-iotests: Test 137 only supports 'file' protocol 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-devel@nongnu.org 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" From: Jeff Cody Since test 137 make uses of qcow2.py, only local files are supported. Signed-off-by: Jeff Cody Signed-off-by: Kevin Wolf --- tests/qemu-iotests/137 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/137 b/tests/qemu-iotests/137 index e5e30de..eb91e51 100755 --- a/tests/qemu-iotests/137 +++ b/tests/qemu-iotests/137 @@ -39,7 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.qemu =20 _supported_fmt qcow2 -_supported_proto generic +_supported_proto file _supported_os Linux =20 =20 --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487960380715551.3787652644148; Fri, 24 Feb 2017 10:19:40 -0800 (PST) Received: from localhost ([::1]:39130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKSw-0008Lk-B2 for importer@patchew.org; Fri, 24 Feb 2017 13:19:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQj-0006DY-0O for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQi-0002fI-7F for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48944) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQf-0002d1-OC; Fri, 24 Feb 2017 13:17:17 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EBCEBC057FAC; Fri, 24 Feb 2017 18:17:17 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCB015460; Fri, 24 Feb 2017 13:17:16 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:16:53 +0100 Message-Id: <1487960230-18054-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 24 Feb 2017 18:17:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/19] qemu-iotests: add ability to exclude certain protocols from tests 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-devel@nongnu.org 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" From: Jeff Cody Add the ability for shell script tests to exclude specific protocols. This is useful to allow all protocols except ones known to not support a feature used in the test (e.g. .bdrv_create). Signed-off-by: Jeff Cody Signed-off-by: Kevin Wolf --- tests/qemu-iotests/common.rc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index a3d904f..6c0fd4c 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -379,6 +379,18 @@ _supported_proto() _notrun "not suitable for this image protocol: $IMGPROTO" } =20 +# tests whether $IMGPROTO is specified as an unsupported image protocol fo= r a test +# +_unsupported_proto() +{ + for f; do + if [ "$f" =3D "$IMGPROTO" ]; then + _notrun "not suitable for this image protocol: $IMGPROTO" + return + fi + done +} + # tests whether the host OS is one of the supported OSes for a test # _supported_os() --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487960655389411.7616819035618; Fri, 24 Feb 2017 10:24:15 -0800 (PST) Received: from localhost ([::1]:39165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKXN-0003az-Tw for importer@patchew.org; Fri, 24 Feb 2017 13:24:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQk-0006Eq-41 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQj-0002gQ-AO for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59204) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQh-0002du-0a; Fri, 24 Feb 2017 13:17:19 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 418FFC04BD4F; Fri, 24 Feb 2017 18:17:19 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCC015460; Fri, 24 Feb 2017 13:17:18 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:16:54 +0100 Message-Id: <1487960230-18054-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 24 Feb 2017 18:17:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/19] qemu-iotests: redirect nbd server stdout to /dev/null 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-devel@nongnu.org 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" From: Jeff Cody Some iotests (e.g. 174) try to filter the output of _make_test_image by piping the stdout. Pipe the server stdout to /dev/null, so that filter pipe does not need to wait until process completion. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/qemu-iotests/common.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 6c0fd4c..08065dc 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -172,7 +172,7 @@ _make_test_img() =20 # Start an NBD server on the image file, which is what we'll be talkin= g to if [ $IMGPROTO =3D "nbd" ]; then - eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT $TEST_IMG_= FILE &" + eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT $TEST_IMG_= FILE >/dev/null &" sleep 1 # FIXME: qemu-nbd needs to be listening before we continue fi } --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 148796267309950.0948324164973; Fri, 24 Feb 2017 10:57:53 -0800 (PST) Received: from localhost ([::1]:39405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chL3v-00087d-Ps for importer@patchew.org; Fri, 24 Feb 2017 13:57:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQm-0006HH-1F for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQl-0002hh-09 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59214) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQi-0002es-AB; Fri, 24 Feb 2017 13:17:20 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83D80C04D2A4; Fri, 24 Feb 2017 18:17:20 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCD015460; Fri, 24 Feb 2017 13:17:19 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:16:55 +0100 Message-Id: <1487960230-18054-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 24 Feb 2017 18:17:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/19] qemu-img: Do not truncate before preallocation 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-devel@nongnu.org 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" From: Nir Soffer When using file system that does not support fallocate() (e.g. NFS < 4.2), truncating the file only when preallocation=3DOFF speeds up creating raw file. Here is example run, tested on Fedora 24 machine, creating raw file on NFS version 3 server. $ time ./qemu-img-master create -f raw -o preallocation=3Dfalloc mnt/test 1g Formatting 'mnt/test', fmt=3Draw size=3D1073741824 preallocation=3Dfalloc real 0m21.185s user 0m0.022s sys 0m0.574s $ time ./qemu-img-fix create -f raw -o preallocation=3Dfalloc mnt/test 1g Formatting 'mnt/test', fmt=3Draw size=3D1073741824 preallocation=3Dfalloc real 0m11.601s user 0m0.016s sys 0m0.525s $ time dd if=3D/dev/zero of=3Dmnt/test bs=3D1M count=3D1024 oflag=3Ddirect 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 15.6627 s, 68.6 MB/s real 0m16.104s user 0m0.009s sys 0m0.220s Running with strace we can see that without this change we do one pread() and one pwrite() for each block. With this change, we do only one pwrite() per block. $ strace ./qemu-img-master create -f raw -o preallocation=3Dfalloc mnt/test= 8192 ... pread64(9, "\0", 1, 4095) =3D 1 pwrite64(9, "\0", 1, 4095) =3D 1 pread64(9, "\0", 1, 8191) =3D 1 pwrite64(9, "\0", 1, 8191) =3D 1 $ strace ./qemu-img-fix create -f raw -o preallocation=3Dfalloc mnt/test 81= 92 ... pwrite64(9, "\0", 1, 4095) =3D 1 pwrite64(9, "\0", 1, 8191) =3D 1 This happens because posix_fallocate is checking if each block is allocated before writing a byte to the block, and when truncating the file before preallocation, all blocks are unallocated. Signed-off-by: Nir Soffer Signed-off-by: Kevin Wolf --- block/file-posix.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 2134e0e..442f080 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1591,12 +1591,6 @@ static int raw_create(const char *filename, QemuOpts= *opts, Error **errp) #endif } =20 - if (ftruncate(fd, total_size) !=3D 0) { - result =3D -errno; - error_setg_errno(errp, -result, "Could not resize file"); - goto out_close; - } - switch (prealloc) { #ifdef CONFIG_POSIX_FALLOCATE case PREALLOC_MODE_FALLOC: @@ -1636,6 +1630,10 @@ static int raw_create(const char *filename, QemuOpts= *opts, Error **errp) break; } case PREALLOC_MODE_OFF: + if (ftruncate(fd, total_size) !=3D 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not resize file"); + } break; default: result =3D -EINVAL; @@ -1644,7 +1642,6 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) break; } =20 -out_close: if (qemu_close(fd) !=3D 0 && result =3D=3D 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not close the new file"); --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487961085288518.133832345118; Fri, 24 Feb 2017 10:31:25 -0800 (PST) Received: from localhost ([::1]:39220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKeJ-0003CR-KX for importer@patchew.org; Fri, 24 Feb 2017 13:31:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQn-0006J6-LH for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQm-0002iz-Ia for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQj-0002g8-LH; Fri, 24 Feb 2017 13:17:21 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D93B961D17; Fri, 24 Feb 2017 18:17:21 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCE015460; Fri, 24 Feb 2017 13:17:20 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:16:56 +0100 Message-Id: <1487960230-18054-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 24 Feb 2017 18:17:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/19] qemu-img: Add tests for raw image preallocation 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-devel@nongnu.org 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" From: Nir Soffer Add tests for creating raw image with and without the preallocation option. Signed-off-by: Nir Soffer Signed-off-by: Kevin Wolf --- tests/qemu-iotests/175 | 61 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/175.out | 18 ++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 80 insertions(+) create mode 100755 tests/qemu-iotests/175 create mode 100644 tests/qemu-iotests/175.out diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 new file mode 100755 index 0000000..ca56e82 --- /dev/null +++ b/tests/qemu-iotests/175 @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Test creating raw image preallocation mode +# +# Copyright (C) 2017 Nir Soffer +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dnirsof@gmail.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +size=3D1m + +echo +echo "=3D=3D creating image with default preallocation =3D=3D" +_make_test_img $size | _filter_imgfmt +stat -c "size=3D%s, blocks=3D%b" $TEST_IMG + +for mode in off full falloc; do + echo + echo "=3D=3D creating image with preallocation $mode =3D=3D" + IMGOPTS=3Dpreallocation=3D$mode _make_test_img $size | _filter_imgfmt + stat -c "size=3D%s, blocks=3D%b" $TEST_IMG +done + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out new file mode 100644 index 0000000..76c02c6 --- /dev/null +++ b/tests/qemu-iotests/175.out @@ -0,0 +1,18 @@ +QA output created by 175 + +=3D=3D creating image with default preallocation =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +size=3D1048576, blocks=3D0 + +=3D=3D creating image with preallocation off =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Doff +size=3D1048576, blocks=3D0 + +=3D=3D creating image with preallocation full =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Dfull +size=3D1048576, blocks=3D2048 + +=3D=3D creating image with preallocation falloc =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Dfalloc +size=3D1048576, blocks=3D2048 + *** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 985b9a6..1f4bf03 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -167,3 +167,4 @@ 172 auto 173 rw auto 174 auto +175 auto quick --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487962914701388.97133304680665; Fri, 24 Feb 2017 11:01:54 -0800 (PST) Received: from localhost ([::1]:39443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chL7n-0003Zz-4J for importer@patchew.org; Fri, 24 Feb 2017 14:01:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQp-0006Lf-UF for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQn-0002jh-F3 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45034) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQl-0002hK-0e; Fri, 24 Feb 2017 13:17:23 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3392880487; Fri, 24 Feb 2017 18:17:23 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCF015460; Fri, 24 Feb 2017 13:17:22 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:16:57 +0100 Message-Id: <1487960230-18054-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 24 Feb 2017 18:17:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/19] qemu-img: Truncate before full preallocation 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-devel@nongnu.org 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" From: Nir Soffer In a previous commit (qemu-img: Do not truncate before preallocation) we moved truncate to the PREALLOC_MODE_OFF branch to avoid slowdown in posix_fallocate(). However this change is not optimal when using PREALLOC_MODE_FULL, since knowing the final size from the beginning could allow the file system driver to do less allocations and possibly avoid fragmentation of the file. Now we truncate also before doing full preallocation. Signed-off-by: Nir Soffer Signed-off-by: Kevin Wolf --- block/file-posix.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 442f080..d24e34b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1604,6 +1604,17 @@ static int raw_create(const char *filename, QemuOpts= *opts, Error **errp) #endif case PREALLOC_MODE_FULL: { + /* + * Knowing the final size from the beginning could allow the file + * system driver to do less allocations and possibly avoid + * fragmentation of the file. + */ + if (ftruncate(fd, total_size) !=3D 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not resize file"); + goto out_close; + } + int64_t num =3D 0, left =3D total_size; buf =3D g_malloc0(65536); =20 @@ -1642,6 +1653,7 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) break; } =20 +out_close: if (qemu_close(fd) !=3D 0 && result =3D=3D 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not close the new file"); --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487963102679162.63902384086316; Fri, 24 Feb 2017 11:05:02 -0800 (PST) Received: from localhost ([::1]:39457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLAm-0007QK-M5 for importer@patchew.org; Fri, 24 Feb 2017 14:04:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQr-0006Mu-DH for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQq-0002m6-GF for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56322) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQm-0002iB-4p; Fri, 24 Feb 2017 13:17:24 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60C6A4E4CF; Fri, 24 Feb 2017 18:17:24 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCG015460; Fri, 24 Feb 2017 13:17:23 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:16:58 +0100 Message-Id: <1487960230-18054-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 24 Feb 2017 18:17:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/19] qemu-img: Improve documentation for PREALLOC_MODE_FALLOC 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-devel@nongnu.org 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" From: Nir Soffer Now that we are truncating the file in both PREALLOC_MODE_FULL and PREALLOC_MODE_OFF, not truncating in PREALLOC_MODE_FALLOC looks odd. Add a comment explaining why we do not truncate in this case. Signed-off-by: Nir Soffer Signed-off-by: Kevin Wolf --- block/file-posix.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index d24e34b..4de1abd 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1594,9 +1594,14 @@ static int raw_create(const char *filename, QemuOpts= *opts, Error **errp) switch (prealloc) { #ifdef CONFIG_POSIX_FALLOCATE case PREALLOC_MODE_FALLOC: - /* posix_fallocate() doesn't set errno. */ + /* + * Truncating before posix_fallocate() makes it about twice slower= on + * file systems that do not support fallocate(), trying to check i= f a + * block is allocated before allocating it, so don't do that here. + */ result =3D -posix_fallocate(fd, 0, total_size); if (result !=3D 0) { + /* posix_fallocate() doesn't set errno. */ error_setg_errno(errp, -result, "Could not preallocate data for the new file"= ); } --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 14879613650191007.3800258511836; Fri, 24 Feb 2017 10:36:05 -0800 (PST) Received: from localhost ([::1]:39266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKip-0000RZ-Nm for importer@patchew.org; Fri, 24 Feb 2017 13:36:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQs-0006PR-7g for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQr-0002nI-Hh for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51524) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQn-0002jD-IT; Fri, 24 Feb 2017 13:17:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B933281222; Fri, 24 Feb 2017 18:17:25 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCH015460; Fri, 24 Feb 2017 13:17:24 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:16:59 +0100 Message-Id: <1487960230-18054-9-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 24 Feb 2017 18:17:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/19] iotests: Fix another race in 030 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-devel@nongnu.org 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" From: John Snow We can't rely on a non-paused job to be present and running for us. Assume that if the job is not present that it completed already. Signed-off-by: John Snow Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- tests/qemu-iotests/030 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 index 54db54a..0d472d5 100755 --- a/tests/qemu-iotests/030 +++ b/tests/qemu-iotests/030 @@ -547,11 +547,14 @@ class TestEIO(TestErrors): while not completed: for event in self.vm.get_qmp_events(wait=3DTrue): if event['event'] =3D=3D 'BLOCK_JOB_ERROR': + error =3D True self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/operation', 'read') result =3D self.vm.qmp('query-block-jobs') + if result =3D=3D {'return': []}: + # Job finished too quickly + continue self.assert_qmp(result, 'return[0]/paused', False) - error =3D True elif event['event'] =3D=3D 'BLOCK_JOB_COMPLETED': self.assertTrue(error, 'job completed unexpectedly') self.assert_qmp(event, 'data/type', 'stream') --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487960933486190.80138490126615; Fri, 24 Feb 2017 10:28:53 -0800 (PST) Received: from localhost ([::1]:39193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKbs-0000OT-4o for importer@patchew.org; Fri, 24 Feb 2017 13:28:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQs-0006Pj-DH for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQr-0002n5-FU for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45048) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQo-0002kL-Pz; Fri, 24 Feb 2017 13:17:26 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04B5E80484; Fri, 24 Feb 2017 18:17:27 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCI015460; Fri, 24 Feb 2017 13:17:25 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:00 +0100 Message-Id: <1487960230-18054-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 24 Feb 2017 18:17:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/19] blockdev: Use BlockBackend to resize in qmp_block_resize() 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-devel@nongnu.org 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" In order to be able to do permission checking and to keep working with the BdrvChild based bdrv_truncate() that this involves, we need to create a temporary BlockBackend to resize the image. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- blockdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index bbf9d4d..2b2f6ce 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2858,6 +2858,7 @@ void qmp_block_resize(bool has_device, const char *de= vice, int64_t size, Error **errp) { Error *local_err =3D NULL; + BlockBackend *blk =3D NULL; BlockDriverState *bs; AioContext *aio_context; int ret; @@ -2888,10 +2889,13 @@ void qmp_block_resize(bool has_device, const char *= device, goto out; } =20 + blk =3D blk_new(); + blk_insert_bs(blk, bs); + /* complete all in-flight operations before resizing the device */ bdrv_drain_all(); =20 - ret =3D bdrv_truncate(bs, size); + ret =3D blk_truncate(blk, size); switch (ret) { case 0: break; @@ -2913,6 +2917,7 @@ void qmp_block_resize(bool has_device, const char *de= vice, } =20 out: + blk_unref(blk); aio_context_release(aio_context); } =20 --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487961201928208.8891116429046; Fri, 24 Feb 2017 10:33:21 -0800 (PST) Received: from localhost ([::1]:39250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKgC-0006ly-0g for importer@patchew.org; Fri, 24 Feb 2017 13:33:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQt-0006RL-AA for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQs-0002oE-Ed for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59262) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQq-0002l9-1I; Fri, 24 Feb 2017 13:17:28 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 419A0C04BD37; Fri, 24 Feb 2017 18:17:28 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCJ015460; Fri, 24 Feb 2017 13:17:27 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:01 +0100 Message-Id: <1487960230-18054-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 24 Feb 2017 18:17:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/19] qcow2: Use BB for resizing in qcow2_amend_options() 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-devel@nongnu.org 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" In order to able to convert bdrv_truncate() to take a BdrvChild and later to correctly check the resize permission here, we need to use a BlockBackend for resizing the image. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/qcow2.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 3e274bd..254545a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3250,7 +3250,11 @@ static int qcow2_amend_options(BlockDriverState *bs,= QemuOpts *opts, } =20 if (new_size) { - ret =3D bdrv_truncate(bs, new_size); + BlockBackend *blk =3D blk_new(); + blk_insert_bs(blk, bs); + ret =3D blk_truncate(blk, new_size); + blk_unref(blk); + if (ret < 0) { return ret; } --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487963286631981.7122961665094; Fri, 24 Feb 2017 11:08:06 -0800 (PST) Received: from localhost ([::1]:39483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLDo-0002am-Bw for importer@patchew.org; Fri, 24 Feb 2017 14:08:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQy-0006aZ-BG for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQw-0002ra-05 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57042) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQr-0002mX-Bg; Fri, 24 Feb 2017 13:17:29 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F70215552; Fri, 24 Feb 2017 18:17:29 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCK015460; Fri, 24 Feb 2017 13:17:28 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:02 +0100 Message-Id: <1487960230-18054-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 24 Feb 2017 18:17:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/19] mirror: Resize active commit base in mirror_run() 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-devel@nongnu.org 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 is more consistent with the commit block job, and it moves the code to a place where we already have the necessary BlockBackends to resize the base image when bdrv_truncate() is changed to require a BdrvChild. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/mirror.c | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index ca8547b..3d50857 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -662,7 +662,28 @@ static void coroutine_fn mirror_run(void *opaque) if (s->bdev_length < 0) { ret =3D s->bdev_length; goto immediate_exit; - } else if (s->bdev_length =3D=3D 0) { + } + + /* Active commit must resize the base image if its size differs from t= he + * active layer. */ + if (s->base =3D=3D blk_bs(s->target)) { + int64_t base_length; + + base_length =3D blk_getlength(s->target); + if (base_length < 0) { + ret =3D base_length; + goto immediate_exit; + } + + if (s->bdev_length > base_length) { + ret =3D blk_truncate(s->target, s->bdev_length); + if (ret < 0) { + goto immediate_exit; + } + } + } + + if (s->bdev_length =3D=3D 0) { /* Report BLOCK_JOB_READY and wait for complete. */ block_job_event_ready(&s->common); s->synced =3D true; @@ -1063,9 +1084,7 @@ void commit_active_start(const char *job_id, BlockDri= verState *bs, BlockCompletionFunc *cb, void *opaque, Error **er= rp, bool auto_complete) { - int64_t length, base_length; int orig_base_flags; - int ret; Error *local_err =3D NULL; =20 orig_base_flags =3D bdrv_get_flags(base); @@ -1074,31 +1093,6 @@ void commit_active_start(const char *job_id, BlockDr= iverState *bs, return; } =20 - length =3D bdrv_getlength(bs); - if (length < 0) { - error_setg_errno(errp, -length, - "Unable to determine length of %s", bs->filename); - goto error_restore_flags; - } - - base_length =3D bdrv_getlength(base); - if (base_length < 0) { - error_setg_errno(errp, -base_length, - "Unable to determine length of %s", base->filenam= e); - goto error_restore_flags; - } - - if (length > base_length) { - ret =3D bdrv_truncate(base, length); - if (ret < 0) { - error_setg_errno(errp, -ret, - "Top image %s is larger than base image %s, an= d " - "resize of base image failed", - bs->filename, base->filename); - goto error_restore_flags; - } - } - mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0, MIRROR_LEAVE_BACKING_CHAIN, on_error, on_error, true, cb, opaque, &local_err, --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487963464056192.4340394625375; Fri, 24 Feb 2017 11:11:04 -0800 (PST) Received: from localhost ([::1]:39514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLGf-00054B-FV for importer@patchew.org; Fri, 24 Feb 2017 14:11:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKQy-0006ab-BN for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQw-0002rh-0Y for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57046) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQs-0002nr-KY; Fri, 24 Feb 2017 13:17:30 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D71283A76A5; Fri, 24 Feb 2017 18:17:30 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCL015460; Fri, 24 Feb 2017 13:17:29 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:03 +0100 Message-Id: <1487960230-18054-13-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 24 Feb 2017 18:17:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/19] block: Pass BdrvChild to bdrv_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: kwolf@redhat.com, qemu-devel@nongnu.org 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" Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 3 ++- block/blkdebug.c | 2 +- block/block-backend.c | 2 +- block/crypto.c | 2 +- block/parallels.c | 8 ++++---- block/qcow.c | 4 ++-- block/qcow2-refcount.c | 2 +- block/qcow2.c | 4 ++-- block/raw-format.c | 2 +- block/vhdx-log.c | 2 +- block/vhdx.c | 2 +- include/block/block.h | 2 +- 12 files changed, 18 insertions(+), 17 deletions(-) diff --git a/block.c b/block.c index 743c349..d951b5d 100644 --- a/block.c +++ b/block.c @@ -2626,8 +2626,9 @@ exit: /** * Truncate file to 'offset' bytes (needed only for file protocols) */ -int bdrv_truncate(BlockDriverState *bs, int64_t offset) +int bdrv_truncate(BdrvChild *child, int64_t offset) { + BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; int ret; if (!drv) diff --git a/block/blkdebug.c b/block/blkdebug.c index d8eee1b..6117ce5 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -663,7 +663,7 @@ static int64_t blkdebug_getlength(BlockDriverState *bs) =20 static int blkdebug_truncate(BlockDriverState *bs, int64_t offset) { - return bdrv_truncate(bs->file->bs, offset); + return bdrv_truncate(bs->file, offset); } =20 static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) diff --git a/block/block-backend.c b/block/block-backend.c index 819f272..492e71e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1605,7 +1605,7 @@ int blk_truncate(BlockBackend *blk, int64_t offset) return -ENOMEDIUM; } =20 - return bdrv_truncate(blk_bs(blk), offset); + return bdrv_truncate(blk->root, offset); } =20 static void blk_pdiscard_entry(void *opaque) diff --git a/block/crypto.c b/block/crypto.c index 7aa7eb5..e05e4dd 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -383,7 +383,7 @@ static int block_crypto_truncate(BlockDriverState *bs, = int64_t offset) =20 offset +=3D payload_offset; =20 - return bdrv_truncate(bs->file->bs, offset); + return bdrv_truncate(bs->file, offset); } =20 static void block_crypto_close(BlockDriverState *bs) diff --git a/block/parallels.c b/block/parallels.c index 2ccefa7..ac94dfb 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -215,7 +215,7 @@ static int64_t allocate_clusters(BlockDriverState *bs, = int64_t sector_num, s->data_end << BDRV_SECTOR_BITS, space << BDRV_SECTOR_BITS, 0); } else { - ret =3D bdrv_truncate(bs->file->bs, + ret =3D bdrv_truncate(bs->file, (s->data_end + space) << BDRV_SECTOR_BITS); } if (ret < 0) { @@ -449,7 +449,7 @@ static int parallels_check(BlockDriverState *bs, BdrvCh= eckResult *res, size - res->image_end_offset); res->leaks +=3D count; if (fix & BDRV_FIX_LEAKS) { - ret =3D bdrv_truncate(bs->file->bs, res->image_end_offset); + ret =3D bdrv_truncate(bs->file, res->image_end_offset); if (ret < 0) { res->check_errors++; return ret; @@ -681,7 +681,7 @@ static int parallels_open(BlockDriverState *bs, QDict *= options, int flags, goto fail_options; } if (!bdrv_has_zero_init(bs->file->bs) || - bdrv_truncate(bs->file->bs, bdrv_getlength(bs->file->bs)) !=3D= 0) { + bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs)) !=3D 0) { s->prealloc_mode =3D PRL_PREALLOC_MODE_FALLOCATE; } =20 @@ -724,7 +724,7 @@ static void parallels_close(BlockDriverState *bs) } =20 if (bs->open_flags & BDRV_O_RDWR) { - bdrv_truncate(bs->file->bs, s->data_end << BDRV_SECTOR_BITS); + bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS); } =20 g_free(s->bat_dirty_bmap); diff --git a/block/qcow.c b/block/qcow.c index fb738fc..4534515 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -467,7 +467,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, /* round to cluster size */ cluster_offset =3D (cluster_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); - bdrv_truncate(bs->file->bs, cluster_offset + s->cluster_si= ze); + bdrv_truncate(bs->file, cluster_offset + s->cluster_size); /* if encrypted, we must initialize the cluster content which won't be written */ if (bs->encrypted && @@ -909,7 +909,7 @@ static int qcow_make_empty(BlockDriverState *bs) if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table, l1_length) < 0) return -1; - ret =3D bdrv_truncate(bs->file->bs, s->l1_table_offset + l1_length); + ret =3D bdrv_truncate(bs->file, s->l1_table_offset + l1_length); if (ret < 0) return ret; =20 diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3dbde18..9e96f64 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1734,7 +1734,7 @@ static int check_refblocks(BlockDriverState *bs, Bdrv= CheckResult *res, goto resize_fail; } =20 - ret =3D bdrv_truncate(bs->file->bs, offset + s->cluster_si= ze); + ret =3D bdrv_truncate(bs->file, offset + s->cluster_size); if (ret < 0) { goto resize_fail; } diff --git a/block/qcow2.c b/block/qcow2.c index 254545a..3e1172b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2570,7 +2570,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, /* align end of file to a sector boundary to ease reading with sector based I/Os */ cluster_offset =3D bdrv_getlength(bs->file->bs); - return bdrv_truncate(bs->file->bs, cluster_offset); + return bdrv_truncate(bs->file, cluster_offset); } =20 buf =3D qemu_blockalign(bs, s->cluster_size); @@ -2784,7 +2784,7 @@ static int make_completely_empty(BlockDriverState *bs) goto fail; } =20 - ret =3D bdrv_truncate(bs->file->bs, (3 + l1_clusters) * s->cluster_siz= e); + ret =3D bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size); if (ret < 0) { goto fail; } diff --git a/block/raw-format.c b/block/raw-format.c index 8404a82..0ddffbd 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -341,7 +341,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t o= ffset) =20 s->size =3D offset; offset +=3D s->offset; - return bdrv_truncate(bs->file->bs, offset); + return bdrv_truncate(bs->file, offset); } =20 static int raw_media_changed(BlockDriverState *bs) diff --git a/block/vhdx-log.c b/block/vhdx-log.c index 02eb104..67a91c0 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -548,7 +548,7 @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHD= XState *s, if (new_file_size % (1024*1024)) { /* round up to nearest 1MB boundary */ new_file_size =3D ((new_file_size >> 20) + 1) << 20; - bdrv_truncate(bs->file->bs, new_file_size); + bdrv_truncate(bs->file, new_file_size); } } qemu_vfree(desc_entries); diff --git a/block/vhdx.c b/block/vhdx.c index 68db9e0..c67772e 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1165,7 +1165,7 @@ static int vhdx_allocate_block(BlockDriverState *bs, = BDRVVHDXState *s, /* per the spec, the address for a block is in units of 1MB */ *new_offset =3D ROUND_UP(*new_offset, 1024 * 1024); =20 - return bdrv_truncate(bs->file->bs, *new_offset + s->block_size); + return bdrv_truncate(bs->file, *new_offset + s->block_size); } =20 /* diff --git a/include/block/block.h b/include/block/block.h index 4e81f20..a4cd06f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -253,7 +253,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverSt= ate *bs, const char *backing_file); int bdrv_get_backing_file_depth(BlockDriverState *bs); void bdrv_refresh_filename(BlockDriverState *bs); -int bdrv_truncate(BlockDriverState *bs, int64_t offset); +int bdrv_truncate(BdrvChild *child, int64_t offset); int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487961649061398.7011270313443; Fri, 24 Feb 2017 10:40:49 -0800 (PST) Received: from localhost ([::1]:39294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKnP-0005f6-NM for importer@patchew.org; Fri, 24 Feb 2017 13:40:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKR1-0006hd-15 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQy-0002tv-Du for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQt-0002pC-Tl; Fri, 24 Feb 2017 13:17:32 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BE2680F8E; Fri, 24 Feb 2017 18:17:32 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCM015460; Fri, 24 Feb 2017 13:17:31 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:04 +0100 Message-Id: <1487960230-18054-14-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 24 Feb 2017 18:17:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/19] block: Attach bs->file only during .bdrv_open() 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-devel@nongnu.org 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" The way that attaching bs->file worked was a bit unusual in that it was the only child that would be attached to a node which is not opened yet. Because of this, the block layer couldn't know yet which permissions the driver would eventually need. This patch moves the point where bs->file is attached to the beginning of the individual .bdrv_open() implementations, so drivers already know what they are going to do with the child. This is also more consistent with how driver-specific children work. For a moment, bdrv_open() gets its own BdrvChild to perform image probing, but instead of directly assigning this BdrvChild to the BDS, it becomes a temporary one and the node name is passed as an option to the drivers, so that they can simply use bdrv_open_child() to create another reference for their own use. This duplicated child for (the not opened yet) bs is not the final state, a follow-up patch will change the image probing code to use a BlockBackend, which is completely independent of bs. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 35 ++++++++++++++++++++++++----------- block/bochs.c | 6 ++++++ block/cloop.c | 6 ++++++ block/crypto.c | 6 ++++++ block/dmg.c | 6 ++++++ block/parallels.c | 6 ++++++ block/qcow.c | 6 ++++++ block/qcow2.c | 18 +++++++++++++++--- block/qed.c | 18 +++++++++++++++--- block/raw-format.c | 6 ++++++ block/replication.c | 6 ++++++ block/vdi.c | 6 ++++++ block/vhdx.c | 6 ++++++ block/vmdk.c | 6 ++++++ block/vpc.c | 6 ++++++ tests/qemu-iotests/051.out | 4 ++-- tests/qemu-iotests/051.pc.out | 4 ++-- 17 files changed, 130 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index d951b5d..40c4dee 100644 --- a/block.c +++ b/block.c @@ -1103,13 +1103,6 @@ static int bdrv_open_common(BlockDriverState *bs, Bd= rvChild *file, assert(!drv->bdrv_needs_filename || filename !=3D NULL); ret =3D drv->bdrv_file_open(bs, options, open_flags, &local_err); } else { - if (file =3D=3D NULL) { - error_setg(errp, "Can't use '%s' as a block driver for the " - "protocol level", drv->format_name); - ret =3D -EINVAL; - goto free_and_fail; - } - bs->file =3D file; ret =3D drv->bdrv_open(bs, options, open_flags, &local_err); } =20 @@ -1145,7 +1138,6 @@ static int bdrv_open_common(BlockDriverState *bs, Bdr= vChild *file, return 0; =20 free_and_fail: - bs->file =3D NULL; g_free(bs->opaque); bs->opaque =3D NULL; bs->drv =3D NULL; @@ -1368,7 +1360,18 @@ void bdrv_unref_child(BlockDriverState *parent, Bdrv= Child *child) } =20 if (child->bs->inherits_from =3D=3D parent) { - child->bs->inherits_from =3D NULL; + BdrvChild *c; + + /* Remove inherits_from only when the last reference between paren= t and + * child->bs goes away. */ + QLIST_FOREACH(c, &parent->children, next) { + if (c !=3D child && c->bs =3D=3D child->bs) { + break; + } + } + if (c =3D=3D NULL) { + child->bs->inherits_from =3D NULL; + } } =20 bdrv_root_unref_child(child); @@ -1789,13 +1792,20 @@ static BlockDriverState *bdrv_open_inherit(const ch= ar *filename, qdict_del(options, "backing"); } =20 - /* Open image file without format layer */ + /* Open image file without format layer. This BdrvChild is only used f= or + * probing, the block drivers will do their own bdrv_open_child() for = the + * same BDS, which is why we put the node name back into options. */ if ((flags & BDRV_O_PROTOCOL) =3D=3D 0) { + /* FIXME Shouldn't attach a child to a node that isn't opened yet.= */ file =3D bdrv_open_child(filename, options, "file", bs, &child_file, true, &local_err); if (local_err) { goto fail; } + if (file !=3D NULL) { + qdict_put(options, "file", + qstring_from_str(bdrv_get_node_name(file->bs))); + } } =20 /* Image format probing */ @@ -1835,7 +1845,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, goto fail; } =20 - if (file && (bs->file !=3D file)) { + if (file) { bdrv_unref_child(bs, file); file =3D NULL; } @@ -1901,6 +1911,9 @@ fail: if (file !=3D NULL) { bdrv_unref_child(bs, file); } + if (bs->file !=3D NULL) { + bdrv_unref_child(bs, bs->file); + } QDECREF(snapshot_options); QDECREF(bs->explicit_options); QDECREF(bs->options); diff --git a/block/bochs.c b/block/bochs.c index 8c9652e..7dd2ac4 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -104,6 +104,12 @@ static int bochs_open(BlockDriverState *bs, QDict *opt= ions, int flags, struct bochs_header bochs; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + bs->read_only =3D true; /* no write support yet */ =20 ret =3D bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); diff --git a/block/cloop.c b/block/cloop.c index 7b75f7e..877c9b0 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -66,6 +66,12 @@ static int cloop_open(BlockDriverState *bs, QDict *optio= ns, int flags, uint32_t offsets_size, max_compressed_block_size =3D 1, i; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + bs->read_only =3D true; =20 /* read header */ diff --git a/block/crypto.c b/block/crypto.c index e05e4dd..7cb2ff2 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -300,6 +300,12 @@ static int block_crypto_open_generic(QCryptoBlockForma= t format, QCryptoBlockOpenOptions *open_opts =3D NULL; unsigned int cflags =3D 0; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + opts =3D qemu_opts_create(opts_spec, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { diff --git a/block/dmg.c b/block/dmg.c index 58a3ae8..8e387cd 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -413,6 +413,12 @@ static int dmg_open(BlockDriverState *bs, QDict *optio= ns, int flags, int64_t offset; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + block_module_load_one("dmg-bz2"); bs->read_only =3D true; =20 diff --git a/block/parallels.c b/block/parallels.c index ac94dfb..b2ec09f 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -581,6 +581,12 @@ static int parallels_open(BlockDriverState *bs, QDict = *options, int flags, Error *local_err =3D NULL; char *buf; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + ret =3D bdrv_pread(bs->file, 0, &ph, sizeof(ph)); if (ret < 0) { goto fail; diff --git a/block/qcow.c b/block/qcow.c index 4534515..038b05a 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -106,6 +106,12 @@ static int qcow_open(BlockDriverState *bs, QDict *opti= ons, int flags, QCowHeader header; Error *local_err =3D NULL; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + ret =3D bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { goto fail; diff --git a/block/qcow2.c b/block/qcow2.c index 3e1172b..21e6142 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -814,8 +814,8 @@ static int qcow2_update_options(BlockDriverState *bs, Q= Dict *options, return ret; } =20 -static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; unsigned int len, i; @@ -1205,6 +1205,18 @@ static int qcow2_open(BlockDriverState *bs, QDict *o= ptions, int flags, return ret; } =20 +static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) +{ + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + + return qcow2_do_open(bs, options, flags, errp); +} + static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVQcow2State *s =3D bs->opaque; @@ -1785,7 +1797,7 @@ static void qcow2_invalidate_cache(BlockDriverState *= bs, Error **errp) options =3D qdict_clone_shallow(bs->options); =20 flags &=3D ~BDRV_O_INACTIVE; - ret =3D qcow2_open(bs, options, flags, &local_err); + ret =3D qcow2_do_open(bs, options, flags, &local_err); QDECREF(options); if (local_err) { error_propagate(errp, local_err); diff --git a/block/qed.c b/block/qed.c index 0b62c77..62a0a09 100644 --- a/block/qed.c +++ b/block/qed.c @@ -415,8 +415,8 @@ static void bdrv_qed_drain(BlockDriverState *bs) } } =20 -static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +static int bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flag= s, + Error **errp) { BDRVQEDState *s =3D bs->opaque; QEDHeader le_header; @@ -550,6 +550,18 @@ out: return ret; } =20 +static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) +{ + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + + return bdrv_qed_do_open(bs, options, flags, errp); +} + static void bdrv_qed_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVQEDState *s =3D bs->opaque; @@ -1629,7 +1641,7 @@ static void bdrv_qed_invalidate_cache(BlockDriverStat= e *bs, Error **errp) bdrv_qed_close(bs); =20 memset(s, 0, sizeof(BDRVQEDState)); - ret =3D bdrv_qed_open(bs, NULL, bs->open_flags, &local_err); + ret =3D bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err); if (local_err) { error_propagate(errp, local_err); error_prepend(errp, "Could not reopen qed layer: "); diff --git a/block/raw-format.c b/block/raw-format.c index 0ddffbd..ce34d1b 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -384,6 +384,12 @@ static int raw_open(BlockDriverState *bs, QDict *optio= ns, int flags, BDRVRawState *s =3D bs->opaque; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + bs->sg =3D bs->file->bs->sg; bs->supported_write_flags =3D BDRV_REQ_FUA & bs->file->bs->supported_write_flags; diff --git a/block/replication.c b/block/replication.c index 729dd12..eff85c7 100644 --- a/block/replication.c +++ b/block/replication.c @@ -86,6 +86,12 @@ static int replication_open(BlockDriverState *bs, QDict = *options, const char *mode; const char *top_id; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + ret =3D -EINVAL; opts =3D qemu_opts_create(&replication_runtime_opts, NULL, 0, &error_a= bort); qemu_opts_absorb_qdict(opts, options, &local_err); diff --git a/block/vdi.c b/block/vdi.c index 0aeb940..18b4773 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -363,6 +363,12 @@ static int vdi_open(BlockDriverState *bs, QDict *optio= ns, int flags, int ret; Error *local_err =3D NULL; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + logout("\n"); =20 ret =3D bdrv_read(bs->file, 0, (uint8_t *)&header, 1); diff --git a/block/vhdx.c b/block/vhdx.c index c67772e..9918ee9 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -898,6 +898,12 @@ static int vhdx_open(BlockDriverState *bs, QDict *opti= ons, int flags, uint64_t signature; Error *local_err =3D NULL; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + s->bat =3D NULL; s->first_visible_write =3D true; =20 diff --git a/block/vmdk.c b/block/vmdk.c index 393c84d..9d68ec5 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -943,6 +943,12 @@ static int vmdk_open(BlockDriverState *bs, QDict *opti= ons, int flags, uint32_t magic; Error *local_err =3D NULL; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + buf =3D vmdk_read_desc(bs->file, 0, errp); if (!buf) { return -EINVAL; diff --git a/block/vpc.c b/block/vpc.c index ed6353d..d0df2a1 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -220,6 +220,12 @@ static int vpc_open(BlockDriverState *bs, QDict *optio= ns, int flags, int disk_type =3D VHD_DYNAMIC; int ret; =20 + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, + false, errp); + if (!bs->file) { + return -EINVAL; + } + opts =3D qemu_opts_create(&vpc_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index 42bf416..7524c62 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -225,7 +225,7 @@ Testing: -drive driver=3Dnbd QEMU_PROG: -drive driver=3Dnbd: NBD server address missing =20 Testing: -drive driver=3Draw -QEMU_PROG: -drive driver=3Draw: Can't use 'raw' as a block driver for the = protocol level +QEMU_PROG: -drive driver=3Draw: A block device must be specified for "file" =20 Testing: -drive file.driver=3Dfile QEMU_PROG: -drive file.driver=3Dfile: The 'file' block driver requires a f= ile name @@ -234,7 +234,7 @@ Testing: -drive file.driver=3Dnbd QEMU_PROG: -drive file.driver=3Dnbd: NBD server address missing =20 Testing: -drive file.driver=3Draw -QEMU_PROG: -drive file.driver=3Draw: Can't use 'raw' as a block driver for= the protocol level +QEMU_PROG: -drive file.driver=3Draw: A block device must be specified for = "file" =20 Testing: -drive foo=3Dbar QEMU_PROG: -drive foo=3Dbar: Must specify either driver or file diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index f8047a2..e206ad6 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -323,7 +323,7 @@ Testing: -drive driver=3Dnbd QEMU_PROG: -drive driver=3Dnbd: NBD server address missing =20 Testing: -drive driver=3Draw -QEMU_PROG: -drive driver=3Draw: Can't use 'raw' as a block driver for the = protocol level +QEMU_PROG: -drive driver=3Draw: A block device must be specified for "file" =20 Testing: -drive file.driver=3Dfile QEMU_PROG: -drive file.driver=3Dfile: The 'file' block driver requires a f= ile name @@ -332,7 +332,7 @@ Testing: -drive file.driver=3Dnbd QEMU_PROG: -drive file.driver=3Dnbd: NBD server address missing =20 Testing: -drive file.driver=3Draw -QEMU_PROG: -drive file.driver=3Draw: Can't use 'raw' as a block driver for= the protocol level +QEMU_PROG: -drive file.driver=3Draw: A block device must be specified for = "file" =20 Testing: -drive foo=3Dbar QEMU_PROG: -drive foo=3Dbar: Must specify either driver or file --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487963575846385.4124740981266; Fri, 24 Feb 2017 11:12:55 -0800 (PST) Received: from localhost ([::1]:39521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLIU-0006u8-MM for importer@patchew.org; Fri, 24 Feb 2017 14:12:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKR0-0006gt-JO for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQz-0002v9-Gu for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQv-0002qT-8D; Fri, 24 Feb 2017 13:17:33 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D8FDC04D29E; Fri, 24 Feb 2017 18:17:33 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCN015460; Fri, 24 Feb 2017 13:17:32 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:05 +0100 Message-Id: <1487960230-18054-15-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 24 Feb 2017 18:17:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 14/19] block: Factor out bdrv_open_child_bs() 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-devel@nongnu.org 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 is the part of bdrv_open_child() that opens a BDS with option inheritance, but doesn't attach it as a child to the parent yet. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 61 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/block.c b/block.c index 40c4dee..6987400 100644 --- a/block.c +++ b/block.c @@ -1546,28 +1546,12 @@ free_exit: return ret; } =20 -/* - * Opens a disk image whose options are given as BlockdevRef in another bl= ock - * device's options. - * - * If allow_none is true, no image will be opened if filename is false and= no - * BlockdevRef is given. NULL will be returned, but errp remains unset. - * - * bdrev_key specifies the key for the image's BlockdevRef in the options = QDict. - * That QDict has to be flattened; therefore, if the BlockdevRef is a QDict - * itself, all options starting with "${bdref_key}." are considered part o= f the - * BlockdevRef. - * - * The BlockdevRef will be removed from the options QDict. - */ -BdrvChild *bdrv_open_child(const char *filename, - QDict *options, const char *bdref_key, - BlockDriverState* parent, - const BdrvChildRole *child_role, - bool allow_none, Error **errp) +static BlockDriverState * +bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref= _key, + BlockDriverState *parent, const BdrvChildRole *child_ro= le, + bool allow_none, Error **errp) { - BdrvChild *c =3D NULL; - BlockDriverState *bs; + BlockDriverState *bs =3D NULL; QDict *image_options; char *bdref_key_dot; const char *reference; @@ -1594,11 +1578,40 @@ BdrvChild *bdrv_open_child(const char *filename, goto done; } =20 - c =3D bdrv_attach_child(parent, bs, bdref_key, child_role); - done: qdict_del(options, bdref_key); - return c; + return bs; +} + +/* + * Opens a disk image whose options are given as BlockdevRef in another bl= ock + * device's options. + * + * If allow_none is true, no image will be opened if filename is false and= no + * BlockdevRef is given. NULL will be returned, but errp remains unset. + * + * bdrev_key specifies the key for the image's BlockdevRef in the options = QDict. + * That QDict has to be flattened; therefore, if the BlockdevRef is a QDict + * itself, all options starting with "${bdref_key}." are considered part o= f the + * BlockdevRef. + * + * The BlockdevRef will be removed from the options QDict. + */ +BdrvChild *bdrv_open_child(const char *filename, + QDict *options, const char *bdref_key, + BlockDriverState *parent, + const BdrvChildRole *child_role, + bool allow_none, Error **errp) +{ + BlockDriverState *bs; + + bs =3D bdrv_open_child_bs(filename, options, bdref_key, parent, child_= role, + allow_none, errp); + if (bs =3D=3D NULL) { + return NULL; + } + + return bdrv_attach_child(parent, bs, bdref_key, child_role); } =20 static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487963685509275.9031073883169; Fri, 24 Feb 2017 11:14:45 -0800 (PST) Received: from localhost ([::1]:39529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLKF-0008Ik-VU for importer@patchew.org; Fri, 24 Feb 2017 14:14:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKR0-0006h2-MB for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKQz-0002vJ-KV for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQw-0002re-Ij; Fri, 24 Feb 2017 13:17:34 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCF0C61BA5; Fri, 24 Feb 2017 18:17:34 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCO015460; Fri, 24 Feb 2017 13:17:33 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:06 +0100 Message-Id: <1487960230-18054-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 24 Feb 2017 18:17:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 15/19] block: Use BlockBackend for image probing 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-devel@nongnu.org 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 fixes the use of a parent-less BdrvChild in bdrv_open_inherit() by converting it into a BlockBackend. Which is exactly what it should be, image probing is an external, standalone user of a node. The requests can't be considered to originate from the format driver node because that one isn't even opened yet. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/block.c b/block.c index 6987400..5f1e8aa 100644 --- a/block.c +++ b/block.c @@ -588,21 +588,20 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int b= uf_size, return drv; } =20 -static int find_image_format(BdrvChild *file, const char *filename, +static int find_image_format(BlockBackend *file, const char *filename, BlockDriver **pdrv, Error **errp) { - BlockDriverState *bs =3D file->bs; BlockDriver *drv; uint8_t buf[BLOCK_PROBE_BUF_SIZE]; int ret =3D 0; =20 /* Return the raw BlockDriver * to scsi-generic devices or empty drive= s */ - if (bdrv_is_sg(bs) || !bdrv_is_inserted(bs) || bdrv_getlength(bs) =3D= =3D 0) { + if (blk_is_sg(file) || !blk_is_inserted(file) || blk_getlength(file) = =3D=3D 0) { *pdrv =3D &bdrv_raw; return ret; } =20 - ret =3D bdrv_pread(file, 0, buf, sizeof(buf)); + ret =3D blk_pread(file, 0, buf, sizeof(buf)); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read image for determining= its " "format"); @@ -974,7 +973,7 @@ QemuOptsList bdrv_runtime_opts =3D { * * Removes all processed options from *options. */ -static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, +static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, QDict *options, Error **errp) { int ret, open_flags; @@ -1005,7 +1004,7 @@ static int bdrv_open_common(BlockDriverState *bs, Bdr= vChild *file, assert(drv !=3D NULL); =20 if (file !=3D NULL) { - filename =3D file->bs->filename; + filename =3D blk_bs(file)->filename; } else { filename =3D qdict_get_try_str(options, "filename"); } @@ -1707,7 +1706,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, Error **errp) { int ret; - BdrvChild *file =3D NULL; + BlockBackend *file =3D NULL; BlockDriverState *bs; BlockDriver *drv =3D NULL; const char *drvname; @@ -1805,19 +1804,24 @@ static BlockDriverState *bdrv_open_inherit(const ch= ar *filename, qdict_del(options, "backing"); } =20 - /* Open image file without format layer. This BdrvChild is only used f= or + /* Open image file without format layer. This BlockBackend is only use= d for * probing, the block drivers will do their own bdrv_open_child() for = the * same BDS, which is why we put the node name back into options. */ if ((flags & BDRV_O_PROTOCOL) =3D=3D 0) { - /* FIXME Shouldn't attach a child to a node that isn't opened yet.= */ - file =3D bdrv_open_child(filename, options, "file", bs, - &child_file, true, &local_err); + BlockDriverState *file_bs; + + file_bs =3D bdrv_open_child_bs(filename, options, "file", bs, + &child_file, true, &local_err); if (local_err) { goto fail; } - if (file !=3D NULL) { + if (file_bs !=3D NULL) { + file =3D blk_new(); + blk_insert_bs(file, file_bs); + bdrv_unref(file_bs); + qdict_put(options, "file", - qstring_from_str(bdrv_get_node_name(file->bs))); + qstring_from_str(bdrv_get_node_name(file_bs))); } } =20 @@ -1859,7 +1863,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, } =20 if (file) { - bdrv_unref_child(bs, file); + blk_unref(file); file =3D NULL; } =20 @@ -1921,9 +1925,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, return bs; =20 fail: - if (file !=3D NULL) { - bdrv_unref_child(bs, file); - } + blk_unref(file); if (bs->file !=3D NULL) { bdrv_unref_child(bs, bs->file); } --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487963978973177.4750361918151; Fri, 24 Feb 2017 11:19:38 -0800 (PST) Received: from localhost ([::1]:39549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLOz-0003Fv-Ka for importer@patchew.org; Fri, 24 Feb 2017 14:19:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKR2-0006js-FF for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKR1-0002xC-6p for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40326) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQx-0002sn-RG; Fri, 24 Feb 2017 13:17:36 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13E28624B0; Fri, 24 Feb 2017 18:17:36 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCP015460; Fri, 24 Feb 2017 13:17:35 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:07 +0100 Message-Id: <1487960230-18054-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 24 Feb 2017 18:17:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/19] block: Factor out bdrv_open_driver() 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-devel@nongnu.org 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 is a function that doesn't do any option parsing, but just does some basic BlockDriverState setup and calls the .bdrv_open() function of the block driver. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 112 +++++++++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 65 insertions(+), 47 deletions(-) diff --git a/block.c b/block.c index 5f1e8aa..f96d26b 100644 --- a/block.c +++ b/block.c @@ -925,6 +925,67 @@ out: g_free(gen_node_name); } =20 +static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, + const char *node_name, QDict *options, + int open_flags, Error **errp) +{ + Error *local_err =3D NULL; + int ret; + + bdrv_assign_node_name(bs, node_name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return -EINVAL; + } + + bs->drv =3D drv; + bs->opaque =3D g_malloc0(drv->instance_size); + + if (drv->bdrv_file_open) { + assert(!drv->bdrv_needs_filename || bs->filename[0]); + ret =3D drv->bdrv_file_open(bs, options, open_flags, &local_err); + } else { + ret =3D drv->bdrv_open(bs, options, open_flags, &local_err); + } + + if (ret < 0) { + if (local_err) { + error_propagate(errp, local_err); + } else if (bs->filename[0]) { + error_setg_errno(errp, -ret, "Could not open '%s'", bs->filena= me); + } else { + error_setg_errno(errp, -ret, "Could not open image"); + } + goto free_and_fail; + } + + ret =3D refresh_total_sectors(bs, bs->total_sectors); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not refresh total sector count= "); + goto free_and_fail; + } + + bdrv_refresh_limits(bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto free_and_fail; + } + + assert(bdrv_opt_mem_align(bs) !=3D 0); + assert(bdrv_min_mem_align(bs) !=3D 0); + assert(is_power_of_2(bs->bl.request_alignment)); + + return 0; + +free_and_fail: + /* FIXME Close bs first if already opened*/ + g_free(bs->opaque); + bs->opaque =3D NULL; + bs->drv =3D NULL; + return ret; +} + QemuOptsList bdrv_runtime_opts =3D { .name =3D "bdrv_common", .head =3D QTAILQ_HEAD_INITIALIZER(bdrv_runtime_opts.head), @@ -1019,14 +1080,6 @@ static int bdrv_open_common(BlockDriverState *bs, Bl= ockBackend *file, trace_bdrv_open_common(bs, filename ?: "", bs->open_flags, drv->format_name); =20 - node_name =3D qemu_opt_get(opts, "node-name"); - bdrv_assign_node_name(bs, node_name, &local_err); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EINVAL; - goto fail_opts; - } - bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); =20 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) { @@ -1092,54 +1145,19 @@ static int bdrv_open_common(BlockDriverState *bs, B= lockBackend *file, } pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), bs->filename); =20 - bs->drv =3D drv; - bs->opaque =3D g_malloc0(drv->instance_size); - /* Open the image, either directly or using a protocol */ open_flags =3D bdrv_open_flags(bs, bs->open_flags); - if (drv->bdrv_file_open) { - assert(file =3D=3D NULL); - assert(!drv->bdrv_needs_filename || filename !=3D NULL); - ret =3D drv->bdrv_file_open(bs, options, open_flags, &local_err); - } else { - ret =3D drv->bdrv_open(bs, options, open_flags, &local_err); - } - - if (ret < 0) { - if (local_err) { - error_propagate(errp, local_err); - } else if (bs->filename[0]) { - error_setg_errno(errp, -ret, "Could not open '%s'", bs->filena= me); - } else { - error_setg_errno(errp, -ret, "Could not open image"); - } - goto free_and_fail; - } + node_name =3D qemu_opt_get(opts, "node-name"); =20 - ret =3D refresh_total_sectors(bs, bs->total_sectors); + assert(!drv->bdrv_file_open || file =3D=3D NULL); + ret =3D bdrv_open_driver(bs, drv, node_name, options, open_flags, errp= ); if (ret < 0) { - error_setg_errno(errp, -ret, "Could not refresh total sector count= "); - goto free_and_fail; - } - - bdrv_refresh_limits(bs, &local_err); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EINVAL; - goto free_and_fail; + goto fail_opts; } =20 - assert(bdrv_opt_mem_align(bs) !=3D 0); - assert(bdrv_min_mem_align(bs) !=3D 0); - assert(is_power_of_2(bs->bl.request_alignment)); - qemu_opts_del(opts); return 0; =20 -free_and_fail: - g_free(bs->opaque); - bs->opaque =3D NULL; - bs->drv =3D NULL; fail_opts: qemu_opts_del(opts); return ret; --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487963833463836.6992995570585; Fri, 24 Feb 2017 11:17:13 -0800 (PST) Received: from localhost ([::1]:39542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLMd-0001KC-4z for importer@patchew.org; Fri, 24 Feb 2017 14:17:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKR2-0006ju-Fx for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKR1-0002xP-E8 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51628) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKQz-0002uC-3e; Fri, 24 Feb 2017 13:17:37 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 525FF8123E; Fri, 24 Feb 2017 18:17:37 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCQ015460; Fri, 24 Feb 2017 13:17:36 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:08 +0100 Message-Id: <1487960230-18054-18-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 24 Feb 2017 18:17:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 17/19] block: Add bdrv_new_open_driver() 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-devel@nongnu.org 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 function allows to create more or less normal BlockDriverStates even for BlockDrivers that aren't globally registered (e.g. helper filters for block jobs). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 30 +++++++++++++++++++++++++++++- include/block/block.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index f96d26b..1368cf5 100644 --- a/block.c +++ b/block.c @@ -939,13 +939,16 @@ static int bdrv_open_driver(BlockDriverState *bs, Blo= ckDriver *drv, } =20 bs->drv =3D drv; + bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); bs->opaque =3D g_malloc0(drv->instance_size); =20 if (drv->bdrv_file_open) { assert(!drv->bdrv_needs_filename || bs->filename[0]); ret =3D drv->bdrv_file_open(bs, options, open_flags, &local_err); - } else { + } else if (drv->bdrv_open) { ret =3D drv->bdrv_open(bs, options, open_flags, &local_err); + } else { + ret =3D 0; } =20 if (ret < 0) { @@ -986,6 +989,31 @@ free_and_fail: return ret; } =20 +BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_= name, + int flags, Error **errp) +{ + BlockDriverState *bs; + int ret; + + bs =3D bdrv_new(); + bs->open_flags =3D flags; + bs->explicit_options =3D qdict_new(); + bs->options =3D qdict_new(); + bs->opaque =3D NULL; + + update_options_from_flags(bs->options, flags); + + ret =3D bdrv_open_driver(bs, drv, node_name, bs->options, flags, errp); + if (ret < 0) { + QDECREF(bs->explicit_options); + QDECREF(bs->options); + bdrv_unref(bs); + return NULL; + } + + return bs; +} + QemuOptsList bdrv_runtime_opts =3D { .name =3D "bdrv_common", .head =3D QTAILQ_HEAD_INITIALIZER(bdrv_runtime_opts.head), diff --git a/include/block/block.h b/include/block/block.h index a4cd06f..bde5ebd 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -215,6 +215,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict = *parent_options, const char *bdref_key, Error **errp); BlockDriverState *bdrv_open(const char *filename, const char *reference, QDict *options, int flags, Error **errp); +BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_= name, + int flags, Error **errp); BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, int flags); --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487961906431176.8028179740644; Fri, 24 Feb 2017 10:45:06 -0800 (PST) Received: from localhost ([::1]:39319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKrY-0001CD-Vh for importer@patchew.org; Fri, 24 Feb 2017 13:45:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKR4-0006pC-0T for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKR3-0002zY-1j for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKR0-0002vZ-CA; Fri, 24 Feb 2017 13:17:38 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99CD080486; Fri, 24 Feb 2017 18:17:38 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCR015460; Fri, 24 Feb 2017 13:17:37 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:09 +0100 Message-Id: <1487960230-18054-19-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 24 Feb 2017 18:17:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 18/19] vvfat: Use opened node as backing file 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-devel@nongnu.org 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" We should not try to assign a not yet opened node as the backing file, because as soon as the permission system is added it will fail. The just added bdrv_new_open_driver() function is the right tool to open a file with an internal driver, use it. In case anyone wonders whether that magic fake backing file to trigger a special action on 'commit' actually works today: No, not for me. One reason is that we've been adding a raw format driver on top for several years now and raw doesn't support commit. Other reasons include that the backing file isn't writable and the driver doesn't support reopen, and it's also size 0 and the driver doesn't support bdrv_truncate. All of these are easily fixable, but then 'commit' ended up in an infinite loop deep in the vvfat code for me, so I thought I'd best leave it alone. I'm not really sure what it was supposed to do anyway. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/vvfat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index c6bf67e..7f230be 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2968,6 +2968,7 @@ static void write_target_close(BlockDriverState *bs) { =20 static BlockDriver vvfat_write_target =3D { .format_name =3D "vvfat_write_target", + .instance_size =3D sizeof(void*), .bdrv_co_pwritev =3D write_target_commit, .bdrv_close =3D write_target_close, }; @@ -3036,14 +3037,13 @@ static int enable_write_target(BlockDriverState *bs= , Error **errp) unlink(s->qcow_filename); #endif =20 - backing =3D bdrv_new(); + backing =3D bdrv_new_open_driver(&vvfat_write_target, NULL, BDRV_O_ALL= OW_RDWR, + &error_abort); + *(void**) backing->opaque =3D s; + bdrv_set_backing_hd(s->bs, backing); bdrv_unref(backing); =20 - s->bs->backing->bs->drv =3D &vvfat_write_target; - s->bs->backing->bs->opaque =3D g_new(void *, 1); - *(void**)s->bs->backing->bs->opaque =3D s; - return 0; =20 err: --=20 1.8.3.1 From nobody Sun May 5 18:22:20 2024 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; 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 1487964094711912.2131924933775; Fri, 24 Feb 2017 11:21:34 -0800 (PST) Received: from localhost ([::1]:39561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chLQr-0005AR-BC for importer@patchew.org; Fri, 24 Feb 2017 14:21:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKR6-00071b-SB for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chKR4-00030e-5C for qemu-devel@nongnu.org; Fri, 24 Feb 2017 13:17:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47198) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chKR1-0002wx-MU; Fri, 24 Feb 2017 13:17:39 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF0CB3D945; Fri, 24 Feb 2017 18:17:39 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OIHDCS015460; Fri, 24 Feb 2017 13:17:38 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 19:17:10 +0100 Message-Id: <1487960230-18054-20-git-send-email-kwolf@redhat.com> In-Reply-To: <1487960230-18054-1-git-send-email-kwolf@redhat.com> References: <1487960230-18054-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 24 Feb 2017 18:17:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 19/19] tests: Use opened block node for block job tests 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-devel@nongnu.org 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" blk_insert_bs() and block job related functions will soon require an opened block node (permission calculations will involve the block driver), so let our tests be consistent with the real users in this respect. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/test-blockjob-txn.c | 6 +++++- tests/test-blockjob.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index b132e39..f6dfd08 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -96,7 +96,10 @@ static BlockJob *test_block_job_start(unsigned int itera= tions, char job_id[24]; =20 data =3D g_new0(TestBlockJobCBData, 1); - bs =3D bdrv_new(); + + bs =3D bdrv_open("null-co://", NULL, NULL, 0, &error_abort); + g_assert_nonnull(bs); + snprintf(job_id, sizeof(job_id), "job%u", counter++); s =3D block_job_create(job_id, &test_block_job_driver, bs, 0, BLOCK_JOB_DEFAULT, test_block_job_cb, @@ -242,6 +245,7 @@ static void test_pair_jobs_fail_cancel_race(void) int main(int argc, char **argv) { qemu_init_main_loop(&error_abort); + bdrv_init(); =20 g_test_init(&argc, &argv, NULL); g_test_add_func("/single/success", test_single_job_success); diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 60b78a3..068c9e4 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -54,7 +54,10 @@ static BlockJob *do_test_id(BlockBackend *blk, const cha= r *id, static BlockBackend *create_blk(const char *name) { BlockBackend *blk =3D blk_new(); - BlockDriverState *bs =3D bdrv_new(); + BlockDriverState *bs; + + bs =3D bdrv_open("null-co://", NULL, NULL, 0, &error_abort); + g_assert_nonnull(bs); =20 blk_insert_bs(blk, bs); bdrv_unref(bs); @@ -140,6 +143,7 @@ static void test_job_ids(void) int main(int argc, char **argv) { qemu_init_main_loop(&error_abort); + bdrv_init(); =20 g_test_init(&argc, &argv, NULL); g_test_add_func("/blockjob/ids", test_job_ids); --=20 1.8.3.1