From nobody Sun Apr 28 12:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1566770760; cv=none; d=zoho.com; s=zohoarc; b=OxKHD4wkfjbjFkh0PDD4r59lwJeXtLpqMQPWlf/9fWtyUOqVslecuZ/PElXajNwJtTk2kVGBp5oLX5gywdQj30sv6nn3gKVl/GX6GeJ0ucwSBSG1DqmdIwugrPkosIt44L7XEq+HYBLWqPOeA4uXoVRE2syjunVLgfP75veJCzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566770760; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=xV5Uc/r1q2RUVM7UqlbKezyyGHpCUTZy6HjETubTb9M=; b=cmqCr4u5oabbyW2DQAbWeyFpFmhME1EiY6NtD8YaNpb3DBgH5B7gIuWt6aPQiEqPUWPb6o+LZyxU4GJOQjeqXO8K4HdaWfD60B0jsjETFBYFXPQ+AB3X6YYzxbv+axnJya0Zkn6Tt6XsrgJTqAIu7ZQXEcECP3/uwavzTW+TtJc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566770760301658.4613872115801; Sun, 25 Aug 2019 15:06:00 -0700 (PDT) Received: from localhost ([::1]:48382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i20e6-0008At-UI for importer@patchew.org; Sun, 25 Aug 2019 18:05:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33141) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i20br-000721-2l for qemu-devel@nongnu.org; Sun, 25 Aug 2019 18:03:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i20bp-0003td-6C for qemu-devel@nongnu.org; Sun, 25 Aug 2019 18:03:39 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:39149) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i20bo-0003sT-HQ; Sun, 25 Aug 2019 18:03:36 -0400 Received: by mail-wr1-x442.google.com with SMTP id t16so13449933wra.6; Sun, 25 Aug 2019 15:03:36 -0700 (PDT) Received: from localhost.localdomain (93-173-200-237.bb.netvision.net.il. [93.173.200.237]) by smtp.gmail.com with ESMTPSA id f134sm17578257wmg.20.2019.08.25.15.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2019 15:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xV5Uc/r1q2RUVM7UqlbKezyyGHpCUTZy6HjETubTb9M=; b=IHYBLA3EQYJhrbokXC70yQrFdD1SVh3vuSkT6VHGhufgY8+aOKoGy3M9Q7MyMgF9NG Nsp7kvFqutbe2vWYbeX8QEv2tooyoljvMLUsyS3dN3BmYql9nb0PmsJC5DhrlKOc5cAV p9TIoAqvg60oidSSnjrHCLlKb8BER2j2K31d6IZZxxfLTftCzPmGSwzf+bFcfEBw4cg7 RK++By5Cd3bIRW43f4EYrcjGmKAJzyLcqsv5/o8VcNg2VCAhU3gGHI8sACC+mcJZYFbb mgrm09uUZz7lzVvzTYHqHdqKS95EJr7tFduLYXGz5fIEDB+B+1i8/gMCuF73oQKqA+a4 c/ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xV5Uc/r1q2RUVM7UqlbKezyyGHpCUTZy6HjETubTb9M=; b=eX19de0IwHixnAWNg9ghCOKxC18F2iDFimGjtJ1IiceuV7LU+B0QL3SuxdoKaiPoT4 VfCv7SWzuvBNNso4ScYvyCL9PQQpaW8s05LeFIfVilSv6jBQ6sq19cRYV7B3tTWRV1LO nQsb8sfA9N5+cfbUG8dTWz4Rf2CBkHR4wFCyWpLoceSprLccerAteXtNp21TXePxFuN5 nWHgtWC2gzvVnvB9hRmYy+XTj6IX9/ItaiZxuOEwsmfhwY4ecXjzwnNrgJXNgNnbnLNu bJq5tG0ZZ25stUH+1Kry1RJe8LQA0rFdAHF3vWETv+VaI1qebM3SdQwZxAD/63hklqxM 4exw== X-Gm-Message-State: APjAAAW5j1FOpJU+d9nUgeagK5lcehC5d4o68uHBua8p5qLkdbDhDHJ2 OZfH8Sh/TGmTJv367x2ni+3jEwSRNPg= X-Google-Smtp-Source: APXvYqzP7fCtC1i9PMcQcB1xGZlC6rqQYlNiNV4xVaODZaRvILy2rjz9VNjlk/jJFTxU/fcWakslzg== X-Received: by 2002:adf:f507:: with SMTP id q7mr18405597wro.210.1566770614776; Sun, 25 Aug 2019 15:03:34 -0700 (PDT) From: Nir Soffer X-Google-Original-From: Nir Soffer To: qemu-devel@nongnu.org Date: Mon, 26 Aug 2019 01:03:28 +0300 Message-Id: <20190825220329.7942-2-nsoffer@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190825220329.7942-1-nsoffer@redhat.com> References: <20190825220329.7942-1-nsoffer@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v2 1/2] block: posix: Always allocate the first block X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Nir Soffer , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When creating an image with preallocation "off" or "falloc", the first block of the image is typically not allocated. When using Gluster storage backed by XFS filesystem, reading this block using direct I/O succeeds regardless of request length, fooling alignment detection. In this case we fallback to a safe value (4096) instead of the optimal value (512), which may lead to unneeded data copying when aligning requests. Allocating the first block avoids the fallback. Since we allocate the first block even with preallocation=3Doff, we no longer create images with zero disk size: $ ./qemu-img create -f raw test.raw 1g Formatting 'test.raw', fmt=3Draw size=3D1073741824 $ ls -lhs test.raw 4.0K -rw-r--r--. 1 nsoffer nsoffer 1.0G Aug 16 23:48 test.raw And converting the image requires additional cluster: $ ./qemu-img measure -f raw -O qcow2 test.raw required size: 458752 fully allocated size: 1074135040 I did quick performance test for copying disks with qemu-img convert to new raw target image to Gluster storage with sector size of 512 bytes: for i in $(seq 10); do rm -f dst.raw sleep 10 time ./qemu-img convert -f raw -O raw -t none -T none src.raw dst.r= aw done Here is a table comparing the total time spent: Type Before(s) After(s) Diff(%) Reviewed-by: Max Reitz --------------------------------------- real 530.028 469.123 -11.4 user 17.204 10.768 -37.4 sys 17.881 7.011 -60.7 We can see very clear improvement in CPU usage. Signed-off-by: Nir Soffer --- block/file-posix.c | 43 +++++++++++++++++++ tests/qemu-iotests/{150.out =3D> 150.out.qcow2} | 0 tests/qemu-iotests/150.out.raw | 12 ++++++ tests/qemu-iotests/175 | 19 +++++--- tests/qemu-iotests/175.out | 8 ++-- tests/qemu-iotests/178.out.qcow2 | 4 +- tests/qemu-iotests/221.out | 12 ++++-- tests/qemu-iotests/253.out | 12 ++++-- 8 files changed, 90 insertions(+), 20 deletions(-) rename tests/qemu-iotests/{150.out =3D> 150.out.qcow2} (100%) create mode 100644 tests/qemu-iotests/150.out.raw diff --git a/block/file-posix.c b/block/file-posix.c index fbeb0068db..51688ae3fc 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1749,6 +1749,39 @@ static int handle_aiocb_discard(void *opaque) return ret; } =20 +/* + * Help alignment probing by allocating the first block. + * + * When reading with direct I/O from unallocated area on Gluster backed by= XFS, + * reading succeeds regardless of request length. In this case we fallback= to + * safe alignment which is not optimal. Allocating the first block avoids = this + * fallback. + * + * fd may be opened with O_DIRECT, but we don't know the buffer alignment = or + * request alignment, so we use safe values. + * + * Returns: 0 on success, -errno on failure. Since this is an optimization, + * caller may ignore failures. + */ +static int allocate_first_block(int fd, size_t max_size) +{ + size_t write_size =3D MIN(MAX_BLOCKSIZE, max_size); + size_t max_align =3D MAX(MAX_BLOCKSIZE, getpagesize()); + void *buf; + ssize_t n; + + buf =3D qemu_memalign(max_align, write_size); + memset(buf, 0, write_size); + + do { + n =3D pwrite(fd, buf, write_size, 0); + } while (n =3D=3D -1 && errno =3D=3D EINTR); + + qemu_vfree(buf); + + return (n =3D=3D -1) ? -errno : 0; +} + static int handle_aiocb_truncate(void *opaque) { RawPosixAIOData *aiocb =3D opaque; @@ -1788,6 +1821,13 @@ static int handle_aiocb_truncate(void *opaque) /* posix_fallocate() doesn't set errno. */ error_setg_errno(errp, -result, "Could not preallocate new data"); + } else if (current_length =3D=3D 0) { + /* + * Needed only if posix_fallocate() used fallocate(), but = we + * don't have a way to detect that. Optimize future alignm= ent + * probing; ignore failures. + */ + allocate_first_block(fd, offset); } } else { result =3D 0; @@ -1849,6 +1889,9 @@ static int handle_aiocb_truncate(void *opaque) if (ftruncate(fd, offset) !=3D 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not resize file"); + } else if (current_length =3D=3D 0 && offset > current_length) { + /* Optimize future alignment probing; ignore failures. */ + allocate_first_block(fd, offset); } return result; default: diff --git a/tests/qemu-iotests/150.out b/tests/qemu-iotests/150.out.qcow2 similarity index 100% rename from tests/qemu-iotests/150.out rename to tests/qemu-iotests/150.out.qcow2 diff --git a/tests/qemu-iotests/150.out.raw b/tests/qemu-iotests/150.out.raw new file mode 100644 index 0000000000..3cdc7727a5 --- /dev/null +++ b/tests/qemu-iotests/150.out.raw @@ -0,0 +1,12 @@ +QA output created by 150 + +=3D=3D=3D Mapping sparse conversion =3D=3D=3D + +Offset Length File +0 0x1000 TEST_DIR/t.IMGFMT + +=3D=3D=3D Mapping non-sparse conversion =3D=3D=3D + +Offset Length File +0 0x100000 TEST_DIR/t.IMGFMT +*** done diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 index 51e62c8276..d54cb43c39 100755 --- a/tests/qemu-iotests/175 +++ b/tests/qemu-iotests/175 @@ -37,14 +37,16 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 # the file size. This function hides the resulting difference in the # stat -c '%b' output. # Parameter 1: Number of blocks an empty file occupies -# Parameter 2: Image size in bytes +# Parameter 2: Minimal number of blocks in an image +# Parameter 3: Image size in bytes _filter_blocks() { extra_blocks=3D$1 - img_size=3D$2 + min_blocks=3D$2 + img_size=3D$3 =20 - sed -e "s/blocks=3D$extra_blocks\\(\$\\|[^0-9]\\)/nothing allocated/" \ - -e "s/blocks=3D$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)= /everything allocated/" + sed -e "s/blocks=3D$((min_blocks))\\(\$\\|[^0-9]\\)/min allocation/" \ + -e "s/blocks=3D$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)= /max allocation/" } =20 # get standard environment, filters and checks @@ -60,16 +62,21 @@ size=3D$((1 * 1024 * 1024)) touch "$TEST_DIR/empty" extra_blocks=3D$(stat -c '%b' "$TEST_DIR/empty") =20 +# We always write the first byte; check how many blocks this filesystem +# allocates to match empty image alloation. +printf "\0" > "$TEST_DIR/empty" +min_blocks=3D$(stat -c '%b' "$TEST_DIR/empty") + 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 | _filter_blocks $extra_blocks = $size +stat -c "size=3D%s, blocks=3D%b" $TEST_IMG | _filter_blocks $extra_blocks = $min_blocks $size =20 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 | _filter_blocks $extra_blo= cks $size + stat -c "size=3D%s, blocks=3D%b" $TEST_IMG | _filter_blocks $extra_blo= cks $min_blocks $size done =20 # success, all done diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out index 6d9a5ed84e..263e521262 100644 --- a/tests/qemu-iotests/175.out +++ b/tests/qemu-iotests/175.out @@ -2,17 +2,17 @@ QA output created by 175 =20 =3D=3D creating image with default preallocation =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 -size=3D1048576, nothing allocated +size=3D1048576, min allocation =20 =3D=3D creating image with preallocation off =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Doff -size=3D1048576, nothing allocated +size=3D1048576, min allocation =20 =3D=3D creating image with preallocation full =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Dfull -size=3D1048576, everything allocated +size=3D1048576, max allocation =20 =3D=3D creating image with preallocation falloc =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Dfalloc -size=3D1048576, everything allocated +size=3D1048576, max allocation *** done diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.= qcow2 index 55a8dc926f..9e7d8c44df 100644 --- a/tests/qemu-iotests/178.out.qcow2 +++ b/tests/qemu-iotests/178.out.qcow2 @@ -101,7 +101,7 @@ converted image file size in bytes: 196608 =3D=3D raw input image with data (human) =3D=3D =20 Formatting 'TEST_DIR/t.qcow2', fmt=3DIMGFMT size=3D1073741824 -required size: 393216 +required size: 458752 fully allocated size: 1074135040 wrote 512/512 bytes at offset 512 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -257,7 +257,7 @@ converted image file size in bytes: 196608 =20 Formatting 'TEST_DIR/t.qcow2', fmt=3DIMGFMT size=3D1073741824 { - "required": 393216, + "required": 458752, "fully-allocated": 1074135040 } wrote 512/512 bytes at offset 512 diff --git a/tests/qemu-iotests/221.out b/tests/qemu-iotests/221.out index 9f9dd52bb0..dca024a0c3 100644 --- a/tests/qemu-iotests/221.out +++ b/tests/qemu-iotests/221.out @@ -3,14 +3,18 @@ QA output created by 221 =3D=3D=3D Check mapping of unaligned raw image =3D=3D=3D =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D65537 -[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "= offset": OFFSET}] -[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "= offset": OFFSET}] +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, +{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false,= "offset": OFFSET}] +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, +{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false,= "offset": OFFSET}] wrote 1/1 bytes at offset 65536 1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "= offset": OFFSET}, +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, +{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false,= "offset": OFFSET}, { "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, { "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, = "offset": OFFSET}] -[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "= offset": OFFSET}, +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, +{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false,= "offset": OFFSET}, { "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, { "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, = "offset": OFFSET}] *** done diff --git a/tests/qemu-iotests/253.out b/tests/qemu-iotests/253.out index 607c0baa0b..3d08b305d7 100644 --- a/tests/qemu-iotests/253.out +++ b/tests/qemu-iotests/253.out @@ -3,12 +3,16 @@ QA output created by 253 =3D=3D=3D Check mapping of unaligned raw image =3D=3D=3D =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048575 -[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false,= "offset": OFFSET}] -[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false,= "offset": OFFSET}] +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, +{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": fals= e, "offset": OFFSET}] +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, +{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": fals= e, "offset": OFFSET}] wrote 65535/65535 bytes at offset 983040 63.999 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, = "offset": OFFSET}, +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, +{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false= , "offset": OFFSET}, { "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": tru= e, "offset": OFFSET}] -[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, = "offset": OFFSET}, +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "o= ffset": OFFSET}, +{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false= , "offset": OFFSET}, { "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": tru= e, "offset": OFFSET}] *** done --=20 2.20.1 From nobody Sun Apr 28 12:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1566770847; cv=none; d=zoho.com; s=zohoarc; b=JzjArmZRVYVKZ+jaIi8S8H9Oxj+ZN6Fcd0qdXg/QrsVlI4lhe6kMnkw6nKLjP4XFbz6XLHCp1UY7vjS2aziuM7aTGpDj3nD24duCAB3iZBEBPZt7gaEk3BGrT/u7phBR7yO3e/jQsIBJKY81837GYCQ+hRTKZzwL5DGOOZwEArc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566770847; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GCTJEvAcTs97QcMqmmV3RVLZe4+hEjGIEVsWARwdvjo=; b=MvqKo3M3xfkt/yYxbHRJMVzW9HusJfLvGXTxoX7mRSSXeZpUr7yXfFCdM8YB+A5WSkfC0phUhS8ZcDt3B+/JqnsqQqYKUslq16CPDjGKLS/HrhIwZ8xjha+Vx8hCtX1CTeUfYWI8h5XHbmzn+69dvUwQmEQ+6cPFWqsuwhcd/Yw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566770847769696.6405148737072; Sun, 25 Aug 2019 15:07:27 -0700 (PDT) Received: from localhost ([::1]:48396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i20fW-0001sG-Oy for importer@patchew.org; Sun, 25 Aug 2019 18:07:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33146) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i20br-000722-Ff for qemu-devel@nongnu.org; Sun, 25 Aug 2019 18:03:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i20bq-0003u4-Fd for qemu-devel@nongnu.org; Sun, 25 Aug 2019 18:03:39 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:40183) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i20bq-0003tb-A5; Sun, 25 Aug 2019 18:03:38 -0400 Received: by mail-wr1-x443.google.com with SMTP id c3so13436755wrd.7; Sun, 25 Aug 2019 15:03:37 -0700 (PDT) Received: from localhost.localdomain (93-173-200-237.bb.netvision.net.il. [93.173.200.237]) by smtp.gmail.com with ESMTPSA id f134sm17578257wmg.20.2019.08.25.15.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2019 15:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GCTJEvAcTs97QcMqmmV3RVLZe4+hEjGIEVsWARwdvjo=; b=TFxo3CNv+GaDrjjYbPEa6y0HqS21PvOQh4NshegA9coF6sxxrctWZJX880GBm1uO1V Q0GNojZ4d5LkJn4iObqhPJSlQ2EihbdZOCY8q/M2P6tdYiohoK9dEZlTn8XUXOO6qnJB TJQmcsT3TO51c+lHU9OaM7vfLlihGcGwO8QZZNZZv1+SDZ1HVyMdw7nMem41Uqt9GQta Y7sx8W/hPz1P3pdjoNc8RpI/9cOuU8TFbrt5yZPJdL+vU9bBlUuFtOyosMqS6X/oJX0l PEyXHYfiY/VHxaXlAIPuPNBYTTSIPu06ASlIIY657MZtJGUaXAcpRuhFjF+0w3o2ua/J G60w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GCTJEvAcTs97QcMqmmV3RVLZe4+hEjGIEVsWARwdvjo=; b=Q1diSicXm/SlbxGLoX4vSbIfb0alhhtro/hO12tqHKyB/KXXzA/H4ZL4RGF8dDpaUC SpnhdWCNIvPJGrBpoJWXIq5KDay8z+bO7UqZALYPxiatYXZ7tl05IIqK3fp9Mw3kuWGe TJXGwqbLSkLyviJQHzW9jBOPgpIsroLNDkExNYOtoAZeHSOLwr0lVKXQf/oV8UjakTnB 2DsgX+WDWcTQiAv8AHskRaFeFdbMIqASy20HAxOaerEf4oUSBIMZlFJaANlI3pAy2hP/ pnam7i7P/Fq52o+hPZ5GhWL8txXix/KtXKO5sD7XeACaBv/6+Btu0Sh0TuwQ9RKQs0dQ hRPQ== X-Gm-Message-State: APjAAAUm0D75QCw+l10leguvhbbEWgoO5cZfn21HBdh4rsbTNgfP3Qp+ nhxFtQys5jO4oRaZNuPt5OzBfhl+MqM= X-Google-Smtp-Source: APXvYqzTt/LmZ4UFudmBg0nx+z5gn62EHGdOwGaewuez6CPcUqPmg8ZFD/71SxnVTk+gef4wbSh5tw== X-Received: by 2002:a5d:568e:: with SMTP id f14mr17913867wrv.167.1566770616356; Sun, 25 Aug 2019 15:03:36 -0700 (PDT) From: Nir Soffer X-Google-Original-From: Nir Soffer To: qemu-devel@nongnu.org Date: Mon, 26 Aug 2019 01:03:29 +0300 Message-Id: <20190825220329.7942-3-nsoffer@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190825220329.7942-1-nsoffer@redhat.com> References: <20190825220329.7942-1-nsoffer@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v2 2/2] iotests: Test allocate_first_block() with O_DIRECT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Nir Soffer , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Using block_resize we can test allocate_first_block() with file descriptor opened with O_DIRECT, ensuring that it works for any size larger than 4096 bytes. Testing smaller sizes is tricky as the result depends on the filesystem used for testing. For example on NFS any size will work since O_DIRECT does not require any alignment. Reviewed-by: Max Reitz --- tests/qemu-iotests/175 | 25 +++++++++++++++++++++++++ tests/qemu-iotests/175.out | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 index d54cb43c39..60cc251eb2 100755 --- a/tests/qemu-iotests/175 +++ b/tests/qemu-iotests/175 @@ -49,6 +49,23 @@ _filter_blocks() -e "s/blocks=3D$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)= /max allocation/" } =20 +# Resize image using block_resize. +# Parameter 1: image path +# Parameter 2: new size +_block_resize() +{ + local path=3D$1 + local size=3D$2 + + $QEMU -qmp stdio -nographic -nodefaults \ + -blockdev file,node-name=3Dfile,filename=3D$path,cache.direct=3Don= \ + </dev/null + stat -c "size=3D%s, blocks=3D%b" $TEST_IMG | _filter_blocks $extra_blo= cks $min_blocks $new_size +done + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out index 263e521262..39c2ee0f62 100644 --- a/tests/qemu-iotests/175.out +++ b/tests/qemu-iotests/175.out @@ -15,4 +15,12 @@ size=3D1048576, max allocation =3D=3D creating image with preallocation falloc =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Dfalloc size=3D1048576, max allocation + +=3D=3D resize empty image with block_resize =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D0 +size=3D4096, min allocation + +=3D=3D resize empty image with block_resize =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D0 +size=3D1048576, min allocation *** done --=20 2.20.1