[pve-devel] Default cache mode for VM hard drives

Wolfgang Bumiller w.bumiller at proxmox.com
Thu May 28 15:34:08 CEST 2015


> On May 28, 2015 at 3:17 PM Eneko Lacunza <elacunza at binovo.es> wrote:
> On 28/05/15 15:01, Stanislav German-Evtushenko wrote:
> >> Note that without O_DIRECT you won't get a "correct" result either; disk
> >> may end not containing the data in the buffer when write was called.
> >> Softmirror data will be identically uncertain :)
> > You are right. That is why I suppose there is a bug (operations with
> > buffer are not ensured to be thread-safe) in QEMU-KVM.
> >
> What does it mean that operations with buffer are not ensured to be 
> thread-safe in qemu?
> 
> O_DIRECT doesn't guarantee that buffer reading is finished when write 
> returns if I read "man -s 2 open" correctly.

No, within a single thread write() will return only after the buffer
was read. Otherwise we'd see the same bug in a simple single-threaded
code like:

char buffer[4096];
char byte = 0;
do {
  memset(buffer, byte++, 4096);
  write(fd, buffer, 4096);
} while(count--);

However this does NOT produce the same bug. It does not guarantee
that the data was *written*, but you still get the usual guarantee
that it was at least *read* from userspace. Otherwise it wouldn't be a
concurrency issue, but would simply be broken. Just broken, as you
could then never know how long you'd have to keep your buffer around
and unchanged before you're allowed to use it again.

> So this means the only 
> cache modes in QEMU that are "predictable" to use are writethrough and 
> writeback. All others use O_DIRECT (excluding "unsafe" for obvious reasons).
> 
> I have a feeling that this is what you are trying to tell from the 
> beginning? :)



More information about the pve-devel mailing list