Skip to content

Commit d6dd825

Browse files
author
Kathryn Baldauf
authored
Merge pull request microsoft#1597 from katiewasnothere/kabaldau/cleanup_shared_scratch_root_dir
Add logic to cleanup the oci bundle root dir on container delete
2 parents 793fcc5 + b74c09e commit d6dd825

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

internal/guest/runtime/hcsv2/container.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ type Container struct {
4848
id string
4949
vsock transport.Transport
5050

51-
spec *oci.Spec
52-
isSandbox bool
51+
spec *oci.Spec
52+
ociBundlePath string
53+
isSandbox bool
5354

5455
container runtime.Container
5556
initProcess *containerProcess
@@ -211,6 +212,14 @@ func (c *Container) Delete(ctx context.Context) error {
211212
}
212213
}
213214

215+
if err := os.RemoveAll(c.ociBundlePath); err != nil {
216+
if retErr != nil {
217+
retErr = fmt.Errorf("errors deleting container oci bundle dir, %s & %s", retErr, err)
218+
} else {
219+
retErr = err
220+
}
221+
}
222+
214223
return retErr
215224
}
216225

internal/guest/runtime/hcsv2/uvm.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
232232
id: id,
233233
vsock: h.vsock,
234234
spec: settings.OCISpecification,
235+
ociBundlePath: settings.OCIBundlePath,
235236
isSandbox: criType == "sandbox",
236237
exitType: prot.NtUnexpectedExit,
237238
processes: make(map[uint32]*containerProcess),
@@ -269,7 +270,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
269270
}
270271
defer func() {
271272
if err != nil {
272-
_ = os.RemoveAll(spec.SandboxRootDir(id))
273+
_ = os.RemoveAll(settings.OCIBundlePath)
273274
}
274275
}()
275276

@@ -295,7 +296,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
295296
}
296297
defer func() {
297298
if err != nil {
298-
_ = os.RemoveAll(getWorkloadRootDir(id))
299+
_ = os.RemoveAll(settings.OCIBundlePath)
299300
}
300301
}()
301302
if err := policy.ExtendPolicyWithNetworkingMounts(sandboxID, h.securityPolicyEnforcer, settings.OCISpecification); err != nil {
@@ -312,7 +313,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
312313
}
313314
defer func() {
314315
if err != nil {
315-
_ = os.RemoveAll(getStandaloneRootDir(id))
316+
_ = os.RemoveAll(settings.OCIBundlePath)
316317
}
317318
}()
318319
}

internal/guest/runtime/hcsv2/workload_container.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ import (
2121
"github.com/Microsoft/hcsshim/pkg/annotations"
2222
)
2323

24-
func getWorkloadRootDir(id string) string {
25-
return filepath.Join(guestpath.LCOWRootPrefixInUVM, id)
26-
}
27-
2824
// os.MkdirAll combines the given permissions with the running process's
2925
// umask. By default this causes 0777 to become 0755.
3026
// Temporarily set the umask of this process to 0 so that we can actually

0 commit comments

Comments
 (0)