Repository navigation
Description
As I commented on #4036, docker(actually libdevicemapper used by docker) may race with udev on device symlink creating/deleting when dm.use_deferred_removal is turned on , and it eventually leads to a docker start/diff fail.Following is the reproducing procedure:
docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 2
Server Version: 1.11.1
Storage Driver: devicemapper
Pool Name: docker-252:1-58724678-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 883.9 MB
Data Space Total: 107.4 GB
Data Space Available: 35.03 GB
Metadata Space Used: 2.146 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.145 GB
Udev Sync Supported: true
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.107-RHEL7 (2016-06-09)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: host bridge null
Kernel Version: 3.10.0-327.22.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.86 GiB
Name: jzl-dev0010
ID: U4ZX:62TO:YRGL:CNDH:6UZN:VNYX:3R2W:ZCWF:4TJS:54BS:O4AK:NLYY
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/
way to reproduce
make sure all containers removed
# NOTE!!! this command is dangerous, don't execute it on any non-experimental node.
docker rm -f `docker ps -aq`
get image ready
a busybox image would be sufficient, docker pull busybox
get script ready
A Python script is needed to eagerly detect and open any docker created non-init dm devices:
import os
import time
while True:
try:
for line in os.listdir('/dev/mapper'):
if 'init' in line:continue
if len(line) >= 80:
filename=os.path.join('/dev/mapper/',line)
f = open(filename)
print 'got it %s' % filename
time.sleep(3*10**7)
except Exception:
passmake sure all container or image related dm devices removed
run dmsetup info to list all dm devices on your node, and run dmsetup remove <name> to remove all devices whose name starts with docker- and ends with a uuid or <uuid>-init, such as docker-252:1-58724678-3c96b9d15c41b49816eab1faaa0cb6eaa7cdffe5decd45f2bd48ae72f32e16f5
run the script and reproduce the issue
following is one sample of my reproducing logs:
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# dmsetup info
Name: docker-252:1-58724678-pool
State: ACTIVE
Read Ahead: 8192
Tables present: LIVE
Open count: 0
Event number: 0
Major, minor: 253, 0
Number of targets: 1
# python opendm.py &
[1] 3757
# cid=`docker create -it busybox sh`
got it /dev/mapper/docker-252:1-58724678-097a341a6a5f17cc86f9d83ebdff35b8da86fd8ab6d614ac8445f3fabe1d6e25
# docker diff $cid
# docker start $cid
Error response from daemon: open /dev/mapper/docker-252:1-58724678-097a341a6a5f17cc86f9d83ebdff35b8da86fd8ab6d614ac8445f3fabe1d6e25: no such file or directory
Error: failed to start containers: d3cbd8f86704136511b5d4cfdafeb1398a46f962ff9af7389ec7368f8472433ethe essential commands are:
python opendm.py &
docker diff $cid
docker start $cidget the corrupted container back to normal
# kill %1
# dmsetup remove docker-252:1-58724678-097a341a6a5f17cc86f9d83ebdff35b8da86fd8ab6d614ac8445f3fabe1d6e25
[1]+ Terminated python opendm.py
# ls /dev/dm-*
/dev/dm-0
# ls /dev/mapper/
control docker-252:1-58724678-pool
# docker start $cid
d3cbd8f86704136511b5d4cfdafeb1398a46f962ff9af7389ec7368f8472433ethe essential operations to recover the container include:
- kill the background process
python opendm.py - remove the container's dm device.
Activity
jizhilong commentedon Jul 15, 2016
After some digging into code of lvm2 and docker, I got a hypothesis for the cause of the issue:
libdevicemapperchecks the existence of cookie in a dm_task to determine whether or not relying on udev to create/delete device symlink(code is here).dm_task.libdevicemapperwill delete the corresponding symlink , no matter the device-removal is a deferred one or direct one.If it is a deferred device-remove, and the device is busy, kernel will not remove it immediately, once the syscallioctlreturns,/dev/dm-xexists, but the symlink under/dev/mapperis deleted bylibdevicemapper.udevdnorlibdevicemapperwill create the symlink.cancelDeferredRemove, docker will try to mount the device by its symlink, which is already deleted bylibdevicemapperfor the last call toRemoveDeviceDeferred, thus docker will complain on a failureno such file or directory.thaJeztah commentedon Jul 18, 2016
ping @rhvgoyal @runcom PTAL
@jizhilong I see you prepared a PR, but didn't open yet? https://github.com/jizhilong/docker/commit/e1383aad902f0a3af8830698ae55188ce96be72c
jizhilong commentedon Jul 18, 2016
@thaJeztah https://github.com/jizhilong/docker/commit/e1383aad902f0a3af8830698ae55188ce96be72c is not ready at documentation, I'll get it done and open it later.
devmapper: prevent libdevmapper from deleting device symlinks in Remo…
devmapper: prevent libdevmapper from deleting device symlinks in Remo…
devmapper: prevent libdevmapper from deleting device symlinks in Remo…
devmapper: prevent libdevmapper from deleting device symlinks in Remo…
devmapper: prevent libdevmapper from deleting device symlinks in Remo…