Description
We encountered a volume issue in our production env.
After some debugging, we think it may be issue of getSourceMount. Here is a mini testcase
Steps to reproduce the issue:
# mkdir /testvolume
# mount --bind --make-slave /testvolume /testvolume
# mount --bind --make-shared /testvolume /testvolume
# cat /proc/self/mountinfo | grep testvolume
8217 25 8:1 /testvolume /testvolume rw,relatime master:1 - ext4 /dev/sda1 rw,errors=remount-ro
8379 8217 8:1 /testvolume /testvolume rw,relatime shared:1187 master:1 - ext4 /dev/sda1 rw,errors=remount-ro
# docker run --rm -it -v /testvolume:/testvolume:shared busybox sh
docker: Error response from daemon: path /testvolume is mounted on /testvolume but it is not a shared mount.
Describe the results you received:
docker report error:
docker: Error response from daemon: path /testvolume is mounted on /testvolume but it is not a shared mount.
Describe the results you expected:
docker should not report error.
|
// Get the source mount point of directory passed in as argument. Also return |
|
// optional fields. |
|
func getSourceMount(source string) (string, string, error) { |
|
// Ensure any symlinks are resolved. |
|
sourcePath, err := filepath.EvalSymlinks(source) |
|
if err != nil { |
|
return "", "", err |
|
} |
|
|
|
mi, err := mountinfo.GetMounts(mountinfo.ParentsFilter(sourcePath)) |
|
if err != nil { |
|
return "", "", err |
|
} |
|
if len(mi) < 1 { |
|
return "", "", fmt.Errorf("Can't find mount point of %s", source) |
|
} |
|
|
|
// find the longest mount point |
|
var idx, maxlen int |
|
for i := range mi { |
|
if len(mi[i].Mountpoint) > maxlen { |
|
maxlen = len(mi[i].Mountpoint) |
|
idx = i |
|
} |
|
} |
|
return mi[idx].Mountpoint, mi[idx].Optional, nil |
|
} |
// find the longest mount point
var idx, maxlen int
for i := range mi {
if len(mi[i].Mountpoint) > maxlen {
maxlen = len(mi[i].Mountpoint)
idx = i
}
}
Here should be not only the longest matched mount point, but also the last one if the mount point is mounted multi times.
So I think the L377 should be
len(mi[i].Mountpoint) >= maxlen
It should be >= not > here.
Please help to confirm if this is indeed a bug, if confirmed, feel free to fix it, ^^
Thanks.
Description
We encountered a volume issue in our production env.
After some debugging, we think it may be issue of getSourceMount. Here is a mini testcase
Steps to reproduce the issue:
Describe the results you received:
docker report error:
Describe the results you expected:
docker should not report error.
moby/daemon/oci_linux.go
Lines 377 to 403 in 0da7c60
Here should be not only the longest matched mount point, but also the last one if the mount point is mounted multi times.
So I think the L377 should be
It should be
>=not>here.Please help to confirm if this is indeed a bug, if confirmed, feel free to fix it, ^^
Thanks.