From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGkqC-00019T-LA for qemu-devel@nongnu.org; Sun, 19 Jul 2015 05:25:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZGkqB-0005Ju-HY for qemu-devel@nongnu.org; Sun, 19 Jul 2015 05:25:00 -0400 Received: from mail-ie0-x231.google.com ([2607:f8b0:4001:c03::231]:35978) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGkqB-0005Ja-Aj for qemu-devel@nongnu.org; Sun, 19 Jul 2015 05:24:59 -0400 Received: by iehx8 with SMTP id x8so20920587ieh.3 for ; Sun, 19 Jul 2015 02:24:58 -0700 (PDT) MIME-Version: 1.0 Date: Sun, 19 Jul 2015 18:24:58 +0900 Message-ID: From: Taeha Kim Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] No change in userland tools after resizing qcow2 image List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?B?6rmA7YOc7ZWY?= , =?UTF-8?B?6rmA7YOc7ZWY?= Hello, There is no change in userland tools after resizing qcow2 image except file utility. For example when resize qcow2 image, the "file" utility is detectable increased size. However, the "ls", =E2=80=9Cstat=E2=80=9D, and =E2=80=9Cdu=E2=80=9D utility= still don't know how many change size of image is changed. The following patch enables to let userland tools - ls, du, stat - know and apply changed size after resizing qcow2 image created by the qemu-img tool. Currently, =E2=80=9Cfile=E2=80=9D utility can only know without this patch. In addtion, "file" utility sometimes don't know qcow2 image format's version as follows. $ file 100G.qcow2 100G.qcow2: QEMU QCOW Image (Unknown) So, user can't have any information about qcow2 image size. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Signed-off-by: Taeha Kim diff --git a/block.c b/block.c index d088ee0..93427f8 100644 --- a/block.c +++ b/block.c @@ -2529,6 +2529,9 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offse= t) if (bs->blk) { blk_dev_resize_cb(bs->blk); } + if (ret =3D=3D 0) { + ret =3D truncate(bs->filename, offset); + } } return ret; } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D $ ./qemu/qemu-img --version qemu-img version 2.3.91, Copyright (c) 2004-2008 Fabrice Bellard The how-to-reproduce is as follows with three reproduction. First let=E2=80=99s say that we create a qcow2 image using qemu-img tool as follows. There is still no problem. $ ./qemu/qemu-img create -f qcow2 -o preallocation=3Dmetadata 100G.qcow2 10= 0G Formatting '100G.qcow2', fmt=3Dqcow2 size=3D107374182400 encryption=3Doff cluster_size=3D65536 preallocation=3D'metadata' lazy_refcounts=3Doff refcount_bits=3D16 $ ./qemu/qemu-img check 100G.qcow2 No errors were found on the image. 1638400/1638400 =3D 100.00% allocated, 0.00% fragmented, 0.00% compressed c= lusters Image end offset: 107390828544 $ ls -l 100G.qcow2 -rw-r--r--. 1 devjames devjames 107390828544 Jul 15 09:55 100G.qcow2 $ stat 100G.qcow2 File: =E2=80=98100G.qcow2=E2=80=99 Size: 107390828544 Blocks: 32408 IO Block: 4096 regular fil= e Device: fd00h/64768d Inode: 5778245 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/devjames) Gid: ( 1000/devjames) Context: unconfined_u:object_r:user_home_t:s0 Access: 2015-07-15 09:55:17.269620129 +0900 Modify: 2015-07-15 09:55:17.269620129 +0900 Change: 2015-07-15 09:55:17.269620129 +0900 Birth: - $ du -bb 100G.qcow2 107390828544 100G.qcow2 $ file 100G.qcow2 100G.qcow2: QEMU QCOW Image (v3), 107374182400 bytes But, from now on there is a problem. Second let=E2=80=99s say we resize the qcow2 image size from 100G to 200G using current qemu-img without the patch. $ ./qemu/qemu-img resize 100G.qcow2 200G Image resized. $ ./qemu/qemu-img check 100G.qcow2 No errors were found on the image. 1638400/3276800 =3D 50.00% allocated, 0.00% fragmented, 0.00% compressed cl= usters Image end offset: 107390894080 $ ls -l 100G.qcow2 -rw-r--r--. 1 devjames devjames 107390832128 Jul 15 10:02 100G.qcow2 $ stat 100G.qcow2 File: =E2=80=98100G.qcow2=E2=80=99 Size: 107390832128 Blocks: 32416 IO Block: 4096 regular fil= e Device: fd00h/64768d Inode: 5778245 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/devjames) Gid: ( 1000/devjames) Context: unconfined_u:object_r:user_home_t:s0 Access: 2015-07-15 10:02:04.842425479 +0900 Modify: 2015-07-15 10:02:04.854425682 +0900 Change: 2015-07-15 10:02:04.854425682 +0900 Birth: - $ du -bb 100G.qcow2 107390832128 100G.qcow2 $ file 100G.qcow2 100G.qcow2: QEMU QCOW Image (v3), 214748364800 bytes We can see that =E2=80=9Cls=E2=80=9D, =E2=80=9Cstat=E2=80=9D, and =E2=80=9C= du=E2=80=9D utilities don=E2=80=99t know change size of qcow2 image except =E2=80=9Cfile=E2=80=9D one. Third let=E2=80=99s say we resize the qcow2 image size from 100G to 200G us= ing qemu-img with the patch. $ ./qemu/qemu-img resize 100G.qcow2 200G Image resized. $ ./qemu/qemu-img check 100G.qcow2 No errors were found on the image. 1638400/3276800 =3D 50.00% allocated, 0.00% fragmented, 0.00% compressed cl= usters Image end offset: 107390894080 $ ls -l 100G.qcow2 -rw-r--r--. 1 devjames devjames 214748364800 Jul 15 10:08 100G.qcow2 $ stat 100G.qcow2 File: =E2=80=98100G.qcow2=E2=80=99 Size: 214748364800 Blocks: 32416 IO Block: 4096 regular fil= e Device: fd00h/64768d Inode: 5778245 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/devjames) Gid: ( 1000/devjames) Context: unconfined_u:object_r:user_home_t:s0 Access: 2015-07-15 10:04:37.595018501 +0900 Modify: 2015-07-15 10:08:01.622484709 +0900 Change: 2015-07-15 10:08:01.622484709 +0900 Birth: - $ du -bb 100G.qcow2 14748364800 100G.qcow2 $ file 100G.qcow2 100G.qcow2: QEMU QCOW Image (v3), 214748364800 bytes Now we can see above all four utilities know change size of qcow2 image. So I made the patch above for the "qemu-img" tool so that "ls", =E2=80=9Cstat=E2=80=9D, and =E2=80=9Cdu=E2=80=9D utility can be applied inc= reased size of the qcow2 image file. I have created a VM using qcow2 image after patching using this patch. The 100G.qcow2 has resized 200G is detected and available. $ qemu-kvm -smp 4 -m 4096 100G.qcow2 -cdrom ../iso/Fedora-Live-Workstation-x86_64-21-5.iso Thanks. Sincerely yours, Taeha Kim Senior Engineer, Network Functions Virtualization Part, Samsung Electronics