Implement best-effort mount clean up when using host mount namespace#3118
Implement best-effort mount clean up when using host mount namespace#3118SteeleDesmond wants to merge 2 commits intoopencontainers:mainfrom
Conversation
0651a1a to
c3cf57f
Compare
|
@SteeleDesmond this calls for an integration test (see |
|
@SteeleDesmond please rebase |
cfa1a71 to
389d9f7
Compare
|
@SteeleDesmond ^^^ |
| config := c.Config() | ||
|
|
||
| // Unmount recursive | ||
| err := unix.Unmount(config.Rootfs, unix.MNT_DETACH) |
There was a problem hiding this comment.
NB: this relies on the assumption that Rootfs is a mount point, and that assumption is correct.
|
|
||
| // If recursive unmount fails, try best-effort unmount | ||
| for i := len(config.Mounts) - 1; i >= 0; i-- { | ||
| mountpoint := config.Rootfs + config.Mounts[i].Destination |
| mountpoint := config.Rootfs + config.Mounts[i].Destination | ||
| err := unix.Unmount(mountpoint, unix.MNT_DETACH) | ||
| if err != nil { | ||
| logrus.Warn(err) |
There was a problem hiding this comment.
unix.Unmount errors are bare (e.g. ENOENT), so logging it would not make any sense.
Please use unmount which wraps the error.
| logrus.Warn(err) | ||
| } | ||
| } | ||
| err = unix.Unmount(config.Rootfs, unix.MNT_DETACH) |
kolyshkin
left a comment
There was a problem hiding this comment.
Thank you for your work, @SteeleDesmond!
Aside from a nit about using unmount vs unix.Unmount, this definitely needs a test case (e.g. an integration test, look into tests/integration/mounts.bats).
|
This still needs a rebase (to pick up latest and greatest CI). |
| if !c.config.Namespaces.Contains(configs.NEWNS) || | ||
| c.config.Namespaces.PathOf(configs.NEWNS) != "" { |
There was a problem hiding this comment.
This should use IsPrivate now (introduced by commit 2a7dcbb).
|
@SteeleDesmond do you intend to keep working on this? If yes, I can help with a test case. |
4fb26b3 to
ba14a1c
Compare
Signed-off-by: Steele Ray Desmond <steele@desmond.sh>
ba14a1c to
bd6623a
Compare
Signed-off-by: Steele Ray Desmond <steele@desmond.sh>
bd6623a to
e592a34
Compare
|
@kolyshkin Apologies, I had a change of employment and priorities but I went and took another look at this. Feel free to look it over! |
The goal in the runtime spec is to unmount container mounts created during container create processing.
Below shows an example case where mounts persist on the host after container delete. With this commit, a best-effort clean up is made to remove mounts in LIFO order during container delete when the host mount namespace is used. This is done by matching the container rootfs and mount destination paths given in the container config.
See the references below for similar discussions around this issue.
References:
Issue #2095
Issue #1909
libcontainer: containers with host fs root
Signed-off-by: Steele Ray Desmond steele.desmond@ibm.com