* [Qemu-devel] [PATCH] sheepdog: fix dynamic grow for running qcow2 format
@ 2013-12-13 17:29 Liu Yuan
2013-12-16 16:04 ` Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Liu Yuan @ 2013-12-13 17:29 UTC (permalink / raw)
To: sheepdog; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi
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>
---
block/sheepdog.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index d1c812d..ba451a9 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);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] sheepdog: fix dynamic grow for running qcow2 format
2013-12-13 17:29 [Qemu-devel] [PATCH] sheepdog: fix dynamic grow for running qcow2 format Liu Yuan
@ 2013-12-16 16:04 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2013-12-16 16:04 UTC (permalink / raw)
To: Liu Yuan; +Cc: Kevin Wolf, sheepdog, qemu-devel, Stefan Hajnoczi
On Sat, Dec 14, 2013 at 01:29:28AM +0800, Liu Yuan wrote:
> 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>
> ---
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-12-16 16:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-13 17:29 [Qemu-devel] [PATCH] sheepdog: fix dynamic grow for running qcow2 format Liu Yuan
2013-12-16 16:04 ` Stefan Hajnoczi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.