qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-block] [Qemu-devel][PATCH]block/truncate: qcow2’s resize status is


From: 김태하
Subject: [Qemu-block] [Qemu-devel][PATCH]block/truncate: qcow2’s resize status is not showed to
Date: Wed, 15 Jul 2015 01:57:48 +0000 (GMT)

Hello,


To put it briefly, when resize qcow2 image, the "file" tool detected increased size. However, the "ls", “stat”, and “du” utility still don't know increased size. 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, can know only using “file” utility without this patch.


======================

Signed-off-by: Taeha Kim <address@hidden>

diff --git a/block.c b/block.c

index 5e80336..277adf3 100644

--- a/block.c

+++ b/block.c

@@ -2473,6 +2473,9 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)

       if (bs->blk) {

           blk_dev_resize_cb(bs->blk);

       }

+       if (ret == 0) {

+           ret = truncate(bs->filename, offset);

+       }

   }

   return ret;

}

=====================


The commit id is f3a1b5068cea303a55e2a21a97e66d057eaae638. This is the latest master.


$ ./qemu/qemu-img --version

qemu-img version 2.3.90, Copyright (c) 2004-2008 Fabrice Bellard




The how-to-reproduce is as follows with three reproduction.


First let’s 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=metadata 100G.qcow2 100G

Formatting '100G.qcow2', fmt=qcow2 size=107374182400 encryption=off cluster_size=65536 preallocation='metadata' lazy_refcounts=off refcount_bits=16


$ ./qemu/qemu-img check 100G.qcow2

No errors were found on the image.

1638400/1638400 = 100.00% allocated, 0.00% fragmented, 0.00% compressed clusters

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: ‘100G.qcow2’

 Size: 107390828544    Blocks: 32408      IO Block: 4096   regular file

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’s 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 = 50.00% allocated, 0.00% fragmented, 0.00% compressed clusters

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: ‘100G.qcow2’

 Size: 107390832128    Blocks: 32416      IO Block: 4096   regular file

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 “ls”, “stat”, and “du” utilities don’t know change size of qcow2 image except “file” one.


Third let’s say we resize the qcow2 image size from 100G to 200G using 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 = 50.00% allocated, 0.00% fragmented, 0.00% compressed clusters

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: ‘100G.qcow2’

 Size: 214748364800    Blocks: 32416      IO Block: 4096   regular file

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", “stat”, and “du” utility can be applied increased 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 2048 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]