k3s/pkg/util/mount
Jan Safranek 220163f67d Fixed races in Cinder volume attach/detach.
Add a mutex to guard SetUpAt() and TearDownAt() calls - they should not
run in parallel.  There is a race in these calls when there are two pods
using the same volume, one of them is dying and the other one starting.

TearDownAt() checks that a volume is not needed by any pods and detaches the
volume. It does so by counting how many times is the volume mounted
(GetMountRefs() call below).

When SetUpAt() of the starting pod already attached the volume and did not mount
it yet, TearDownAt() of the dying pod will detach it - GetMountRefs() does not
count with this volume.

These two threads run in parallel:

 dying pod.TearDownAt("myVolume")          starting pod.SetUpAt("myVolume")
   |                                       |
   |                                       AttachDisk("myVolume")
   refs, err := mount.GetMountRefs()       |
   Unmount("myDir")                        |
   if refs == 1 {                          |
   |  |                                    Mount("myVolume", "myDir")
   |  |                                    |
   |  DetachDisk("myVolume")               |
   |                                       start containers - OOPS! The volume is detached!
   |
   finish the pod cleanup


Also, add some logs to cinder plugin for easier debugging in the future, add
a test and update the fake mounter to know about bind mounts.
2016-02-02 14:38:49 +01:00
..
doc.go Make copyright ownership statement generic 2015-05-01 17:49:56 -04:00
fake.go Fixed races in Cinder volume attach/detach. 2016-02-02 14:38:49 +01:00
mount.go Merge pull request #16948 from swagiaal/move-formatAndMount 2015-12-04 10:37:33 -08:00
mount_linux.go Use constants for fsck return values 2015-12-08 10:51:12 -05:00
mount_linux_test.go Make copyright ownership statement generic 2015-05-01 17:49:56 -04:00
mount_unsupported.go move formatAndMount and diskLooksUnformatted to mount_linux 2015-11-06 15:37:46 -05:00
nsenter_mount.go Update some flags 2015-11-20 11:47:31 -08:00
nsenter_mount_unsupported.go Rename IsMountPoint to IsLikelyNotMountPoint 2015-08-14 18:45:43 -04:00
safe_format_and_mount_test.go Merge pull request #19585 from smarterclayton/skip_mount 2016-01-14 17:03:44 -08:00