moby--moby/runtime/graphdriver
Alexander Larsson 2ffef1b7eb devmapper: Avoid AB-BA deadlock
We currently drop the global lock while holding a per-device lock when
waiting for device removal, and then we re-aquire it when the sleep is done.
This is causing a AB-BA deadlock if anyone at the same time tries to do any
operation on that device like this:

thread A:             thread B
grabs global lock
grabs device lock
releases global lock
sleeps
                      grabs global lock
                      blocks on device lock
wakes up
blocks on global lock

To trigger this you can for instance do:

ID=`docker run -d fedora sleep 5`
cd /var/lib/docker/devicemapper/mnt/$ID
docker wait $ID
docker rm $ID &
docker rm $ID

The unmount will fail due to the mount being busy thus causing the
timeout and the second rm will then trigger the deadlock.

We fix this by adding a lock ordering such that the device locks
are always grabbed before the global lock. This is safe since the
device lookups now have a separate lock.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
2014-04-02 09:05:00 +02:00
..
aufs This patch adds SELinux labeling support. 2014-03-26 15:30:40 -04:00
btrfs This patch adds SELinux labeling support. 2014-03-26 15:30:40 -04:00
devmapper devmapper: Avoid AB-BA deadlock 2014-04-02 09:05:00 +02:00
vfs This patch adds SELinux labeling support. 2014-03-26 15:30:40 -04:00
driver.go Merge pull request #4838 from crosbymichael/btrfs-ftw 2014-03-27 19:55:25 +02:00