Cleanup mounts if we fail to mount one element of rootfs
Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
parent
8b365117a2
commit
300f083127
@ -72,6 +72,11 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
|||||||
// what was actually done rather than what should have been
|
// what was actually done rather than what should have been
|
||||||
// done.
|
// done.
|
||||||
nrRootMounts := 0
|
nrRootMounts := 0
|
||||||
|
cleanupMounts := func() {
|
||||||
|
if err2 := mount.UnmountN(rootfs, 0, nrRootMounts); err2 != nil {
|
||||||
|
log.G(context).WithError(err2).Warn("Failed to cleanup rootfs mount")
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, rm := range r.Rootfs {
|
for _, rm := range r.Rootfs {
|
||||||
m := &mount.Mount{
|
m := &mount.Mount{
|
||||||
Type: rm.Type,
|
Type: rm.Type,
|
||||||
@ -79,15 +84,11 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
|||||||
Options: rm.Options,
|
Options: rm.Options,
|
||||||
}
|
}
|
||||||
if err := m.Mount(rootfs); err != nil {
|
if err := m.Mount(rootfs); err != nil {
|
||||||
|
cleanupMounts()
|
||||||
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m)
|
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m)
|
||||||
}
|
}
|
||||||
nrRootMounts++
|
nrRootMounts++
|
||||||
}
|
}
|
||||||
cleanupMounts := func() {
|
|
||||||
if err2 := mount.UnmountN(rootfs, 0, nrRootMounts); err2 != nil {
|
|
||||||
log.G(context).WithError(err2).Warn("Failed to cleanup rootfs mount")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
runtime := &runc.Runc{
|
runtime := &runc.Runc{
|
||||||
Command: r.Runtime,
|
Command: r.Runtime,
|
||||||
Log: filepath.Join(path, "log.json"),
|
Log: filepath.Join(path, "log.json"),
|
||||||
|
Loading…
Reference in New Issue
Block a user