summaryrefslogtreecommitdiff
path: root/block/sheepdog.c
diff options
context:
space:
mode:
authorLiu Yuan <namei.unix@gmail.com>2013-12-14 01:29:28 +0800
committerStefan Hajnoczi <stefanha@redhat.com>2013-12-20 09:11:57 +0100
commite50d7607f1800c9f9c576229c6119e4c82f456d6 (patch)
tree0e1971bd2eefccd6e372a6f7d8db12961e9790fb /block/sheepdog.c
parentf8251db121c3f051b22a7536b97d160c30bcccd4 (diff)
downloadqemu-e50d7607f1800c9f9c576229c6119e4c82f456d6.zip
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. Cc: qemu-devel@nongnu.org Cc: Kevin Wolf <kwolf@redhat.com> Cc: Stefan Hajnoczi <stefanha@redhat.com> Reported-by: Hadrien KOHL <hadrien.kohl@gmail.com> Signed-off-by: Liu Yuan <namei.unix@gmail.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block/sheepdog.c')
-rw-r--r--block/sheepdog.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/block/sheepdog.c b/block/sheepdog.c
index d1c812df3d..ba451a97a4 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -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);