Skip to content

Commit 2a5e4c4

Browse files
Skip rootfs unmount when no mounts are provided
Co-authored-by: Julia Nedialkova <julianedialkova@hotmail.com> Signed-off-by: Georgi Sabev <georgethebeatle@gmail.com>
1 parent e7b6fea commit 2a5e4c4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

runtime/v1/linux/proc/init.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,12 @@ func (p *Init) delete(ctx context.Context) error {
304304
}
305305
p.io.Close()
306306
}
307-
if err2 := mount.UnmountAll(p.Rootfs, 0); err2 != nil {
308-
log.G(ctx).WithError(err2).Warn("failed to cleanup rootfs mount")
309-
if err == nil {
310-
err = errors.Wrap(err2, "failed rootfs umount")
307+
if p.Rootfs != "" {
308+
if err2 := mount.UnmountAll(p.Rootfs, 0); err2 != nil {
309+
log.G(ctx).WithError(err2).Warn("failed to cleanup rootfs mount")
310+
if err == nil {
311+
err = errors.Wrap(err2, "failed rootfs umount")
312+
}
311313
}
312314
}
313315
return err

runtime/v1/shim/service.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (_ *
138138
Options: r.Options,
139139
}
140140
rootfs := filepath.Join(r.Bundle, "rootfs")
141-
defer func() {
141+
defer func(rootfs string) {
142142
if err != nil {
143143
if err2 := mount.UnmountAll(rootfs, 0); err2 != nil {
144144
log.G(ctx).WithError(err2).Warn("Failed to cleanup rootfs mount")
145145
}
146146
}
147-
}()
147+
}(rootfs)
148148
for _, rm := range mounts {
149149
m := &mount.Mount{
150150
Type: rm.Type,
@@ -159,6 +159,10 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (_ *
159159
s.mu.Lock()
160160
defer s.mu.Unlock()
161161

162+
if len(mounts) == 0 {
163+
rootfs = ""
164+
}
165+
162166
process, err := newInit(
163167
ctx,
164168
s.config.Path,
@@ -169,6 +173,7 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (_ *
169173
s.config.SystemdCgroup,
170174
s.platform,
171175
config,
176+
rootfs,
172177
)
173178
if err != nil {
174179
return nil, errdefs.ToGRPC(err)
@@ -632,7 +637,7 @@ func getTopic(ctx context.Context, e interface{}) string {
632637
return runtime.TaskUnknownTopic
633638
}
634639

635-
func newInit(ctx context.Context, path, workDir, runtimeRoot, namespace, criu string, systemdCgroup bool, platform rproc.Platform, r *proc.CreateConfig) (*proc.Init, error) {
640+
func newInit(ctx context.Context, path, workDir, runtimeRoot, namespace, criu string, systemdCgroup bool, platform rproc.Platform, r *proc.CreateConfig, rootfs string) (*proc.Init, error) {
636641
var options runctypes.CreateOptions
637642
if r.Options != nil {
638643
v, err := typeurl.UnmarshalAny(r.Options)
@@ -642,7 +647,6 @@ func newInit(ctx context.Context, path, workDir, runtimeRoot, namespace, criu st
642647
options = *v.(*runctypes.CreateOptions)
643648
}
644649

645-
rootfs := filepath.Join(path, "rootfs")
646650
runtime := proc.NewRunc(runtimeRoot, path, namespace, r.Runtime, criu, systemdCgroup)
647651
p := proc.New(r.ID, runtime, rproc.Stdio{
648652
Stdin: r.Stdin,

0 commit comments

Comments
 (0)