[sheepdog] Call to sd_truncate()

Liu Yuan namei.unix at gmail.com
Fri Dec 13 17:37:03 CET 2013


On Fri, Dec 13, 2013 at 05:01:42PM +0100, Hadrien KOHL wrote:
> Here we go:
> 
> # qemu-img create -f qcow2 sheepdog:test 10G
> Formatting 'sheepdog:test', fmt=qcow2 size=10737418240 encryption=off
> cluster_size=65536 lazy_refcounts=off
> 
> # qemu-system-x86_64 -machine accel=kvm:tcg -drive
> file=sheepdog:127.0.0.1:7000:test,if=none,id=virtio-disk0,format=qcow2,cache=writeback
> -cdrom /vm/iso/install-amd64-minimal-20131010.iso -device
> virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=virtio-disk0,id=virtio-disk0,bootindex=1
> -boot cd -m 1024 -name test -vnc 172.16.0.11:0 -bios
> /usr/local/share/qemu/bios.bin
> 65798144, 73555968
> qemu-system-x86_64: shrinking is not supported
> 371130368, 379322368
> qemu-system-x86_64: shrinking is not supported
> 455671808, 472121344
> qemu-system-x86_64: shrinking is not supported
> 666042368, 674234368
> qemu-system-x86_64: shrinking is not supported
> 776339456, 791805952
> qemu-system-x86_64: shrinking is not supported
> 796459008, 796471296
> qemu-system-x86_64: shrinking is not supported
> 

Can you try following patch to see if it fixes the problem?

diff --git a/block/sheepdog.c b/block/sheepdog.c
index b4ae50f..e1164a0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2046,13 +2046,14 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
 {
     SheepdogAIOCB *acb;
     int ret;
+    int64_t offset = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE;
+    BDRVSheepdogState *s = bs->opaque;
 
-    if (bs->growable && sector_num + nb_sectors > bs->total_sectors) {
-        ret = sd_truncate(bs, (sector_num + nb_sectors) * BDRV_SECTOR_SIZE);
+    if (bs->growable && offset > s->inode.vdi_size) {
+        ret = sd_truncate(bs, offset);
         if (ret < 0) {
             return ret;
         }
-        bs->total_sectors = sector_num + nb_sectors;
     }
 
     acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors);



More information about the sheepdog mailing list