[Libguestfs] nbdkit blocksize filter, read-modify-write, and concurrency

Nikolaus Rath nikolaus at rath.org
Sat May 21 12:21:11 UTC 2022


Hi,

How does the blocksize filter take into account writes that end-up overlapping due to read-modify-write cycles?

Specifically, suppose there are two non-overlapping writes handled by two different threads, that, due to blocksize requirements, overlap when expanded. I think there is a risk that one thread may partially undo the work of the other here.

Looking at the code, it seems that writes of unaligned heads and tails are protected with a global lock., 
but writes of aligned data can occur concurrently.

However, does this not miss the case where there is one unaligned write that overlaps with an aligned one? 

For example, with blocksize 10, we could have:

Thread 1: receives write request for offset=0, size=10
Thread 2: receives write request for offset=4, size=16
Thread 1: acquires lock, reads bytes 0-4
Thread 2: does aligned write (no locking needed), writes bytes 0-10
Thread 1: writes bytes 0-10, overwriting data from Thread 2


Best,
-Nikolaus

--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20220521/9dc31f20/attachment.htm>


More information about the Libguestfs mailing list