Skip to contentSkip to conversation

block/truncate: qcow2’s resize status is not showed to

PATCH Kevin Wolf 1 participant 1 message Jul 15, 2015 1 message not in the archive

lore
Share & tools
lore

Kevin Wolf

author
#1 lore raw
In reply to a message not in the archive

Am 15.07.2015 um 03:57 hat 김태하 geschrieben:

Quoted 5 lines

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.

Even your goal is already wrong. For any image format other than raw, the file size doesn't represent the virtual disk size. It's just the size that the image file actually takes on the host, and that's something entirely different.

The correct way to check the virtual disk size is 'qemu-img info'.

Quoted 9 lines

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

block.c +0 -0
index 5e80336..277adf3 100644

block.c int bdrv_truncate(BlockDriverState *bs, int64_t offset) · line 2481

Quoted 9 lines
block.c +3 -0
@@ -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;
 }

Even if your goal were right, this wouldn't work because images don't have to be local files.

And to be clear: Truncating the image file is not only misguided and unnecessary, but it will actively corrupt image files, because qcow2 images can be larger than the virtual disk size (e.g. if you have taken some snapshots). In this case you would destroy the image by throwing away part of it.

Kevin