Skip to contentSkip to conversation

sheepdog: fix dynamic grow for running qcow2 format

PATCH Applied Liu Yuan 2 participants 2 messages Dec 13, 2013 – Dec 16, 2013 Block layer

lore
Share & tools
lore

Liu Yuan

author
#0 lore raw

PATCH 1/1 sheepdog: fix dynamic grow for running qcow2 format

When running qcow2 over sheepdog, we might meet following problem

qemu-system-x86_64: shrinking is not supported

And cause IO errors to Guest. This is because we abuse bs->total_sectors, which is manipulated by generic block layer and race with sheepdog code.

We should directly check if offset > vdi_size to dynamically enlarge the volume instead of 'offset > bs->total_sectors', which will cause problem when following case happens:

vdi_size > offset > bs->total_sectors

   # then trigger sd_truncate() to shrink the volume wrongly.
---
 block/sheepdog.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
block/sheepdog.c +4 -3
index d1c812d..ba451a9 100644
@@ -2048,13 +2048,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);
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 15 lines · Liu Yuan

When running qcow2 over sheepdog, we might meet following problem

qemu-system-x86_64: shrinking is not supported

And cause IO errors to Guest. This is because we abuse bs->total_sectors, which is manipulated by generic block layer and race with sheepdog code.

We should directly check if offset > vdi_size to dynamically enlarge the volume instead of 'offset > bs->total_sectors', which will cause problem when following case happens:

vdi_size > offset > bs->total_sectors

   # then trigger sd_truncate() to shrink the volume wrongly.
Quoted 8 lines
---
 block/sheepdog.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

block.c already updates bs->total_sectors if bs->growable so this patch is safe.

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan