qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fabrice Bellard <fabrice@bellard.org>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Race condition in VMDK (QCOW*) formats.
Date: Tue, 16 Jan 2007 20:35:26 +0100	[thread overview]
Message-ID: <45AD28FE.9040705@bellard.org> (raw)
In-Reply-To: <64F9B87B6B770947A9F8391472E0321609F7A82B@ehost011-8.exch011.intermedia.net>

Well, it was never said that the QCOW* code was safe if you interrupted 
QEMU at some point.

But I agree that it could be safer to write the sector first and update 
the links after. It could be interesting to analyze the QCOW2 snapshots 
handling too (what if QEMU is stopped during the creation of a snapshot ?).

Regards,

Fabrice.

Igor Lvovsky wrote:
> 
> 
>  Hi all,
> 
> I have doubt about the race condition during the *write operation on 
> snapshot*.
> 
> I think the problem exists in VMDK and QCOW* formats (I didn't checked 
> the others).
> 
>  
> 
> The example from the block_vmdk.c.
> 
>  
> 
> static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
> 
>                      const uint8_t *buf, int nb_sectors)
> 
> {
> 
>     BDRVVmdkState *s = bs->opaque;
> 
>     int ret, index_in_cluster, n;
> 
>     uint64_t cluster_offset;
> 
>  
> 
>     while (nb_sectors > 0) {
> 
>         index_in_cluster = sector_num & (s->cluster_sectors - 1);
> 
>         n = s->cluster_sectors - index_in_cluster;
> 
>         if (n > nb_sectors)
> 
>             n = nb_sectors;
> 
>         cluster_offset = get_cluster_offset(bs, sector_num << 9, 1);
> 
>         if (!cluster_offset)
> 
>             return -1;
> 
>         lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET);
> 
>         ret = write(s->fd, buf, n * 512);
> 
>         if (ret != n * 512)
> 
>             return -1;
> 
>         nb_sectors -= n;
> 
>         sector_num += n;
> 
>         buf += n * 512;
> 
>     }
> 
>     return 0;
> 
> }
> 
>  
> 
> The /get_cluster_offset(…)/ routine update the L2 table of the metadata 
> and return the /cluster_offset. /
> 
> After that the /vmdk_write(…)/ routine/ /actually write the grain at 
> right place.
> 
> So, we have timing hole here.
> 
>  
> 
> Assume, VM that perform write operation will be destroyed at this moment.
> 
> So, we have corrupted image (with updated L2 table, but without the 
> grain itself).
> 
>  
> 
>             Regards,
> 
>                         Igor Lvovsky
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Qemu-devel mailing list
> Qemu-devel@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/qemu-devel

  reply	other threads:[~2007-01-16 20:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-16 13:59 [Qemu-devel] Race condition in VMDK (QCOW*) formats Igor Lvovsky
2007-01-16 19:35 ` Fabrice Bellard [this message]
2007-01-16 19:35 ` Fabrice Bellard
2007-05-13 11:13   ` [Qemu-devel] [PATCH] Fix a race condition and non-leaf images growing in VMDK chains Igor Lvovsky
2007-05-17 13:54     ` Igor Lvovsky
2007-05-19 21:39       ` Thiemo Seufer
2007-05-19 21:42         ` Thiemo Seufer
2007-05-20 11:40           ` Igor Lvovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45AD28FE.9040705@bellard.org \
    --to=fabrice@bellard.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).