Skip to content

Commit 751abbf

Browse files
committed
CWCOW: Handle container remove request
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
1 parent 9df3a80 commit 751abbf

File tree

3 files changed

+53
-31
lines changed

3 files changed

+53
-31
lines changed

internal/gcs-sidecar/handlers.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -646,33 +646,37 @@ func (b *Bridge) modifySettings(req *request) (err error) {
646646
return nil
647647

648648
case guestresource.ResourceTypeCWCOWCombinedLayers:
649-
650-
if modifyGuestSettingsRequest.RequestType == guestrequest.RequestTypeRemove {
651-
return fmt.Errorf("not implemented")
652-
}
653-
654649
settings := modifyGuestSettingsRequest.Settings.(*guestresource.CWCOWCombinedLayers)
655-
containerID := settings.ContainerID
656-
log.G(ctx).Tracef("CWCOWCombinedLayers:: ContainerID: %v, ContainerRootPath: %v, Layers: %v, ScratchPath: %v",
657-
containerID, settings.CombinedLayers.ContainerRootPath, settings.CombinedLayers.Layers, settings.CombinedLayers.ScratchPath)
650+
switch modifyGuestSettingsRequest.RequestType {
651+
case guestrequest.RequestTypeAdd:
652+
containerID := settings.ContainerID
653+
log.G(ctx).Tracef("CWCOWCombinedLayers:: ContainerID: %v, ContainerRootPath: %v, Layers: %v, ScratchPath: %v",
654+
containerID, settings.CombinedLayers.ContainerRootPath, settings.CombinedLayers.Layers, settings.CombinedLayers.ScratchPath)
655+
656+
//Since unencrypted scratch is not an option, always pass true
657+
if err := b.hostState.securityOptions.PolicyEnforcer.EnforceScratchMountPolicy(ctx, settings.CombinedLayers.ContainerRootPath, true); err != nil {
658+
return fmt.Errorf("scratch mounting denied by policy: %w", err)
659+
}
660+
// The following two folders are expected to be present in the scratch.
661+
// But since we have just formatted the scratch we would need to
662+
// create them manually.
663+
sandboxStateDirectory := filepath.Join(settings.CombinedLayers.ContainerRootPath, sandboxStateDirName)
664+
err = os.Mkdir(sandboxStateDirectory, 0777)
665+
if err != nil {
666+
return fmt.Errorf("failed to create sandboxStateDirectory: %w", err)
667+
}
658668

659-
//Since unencrypted scratch is not an option, always pass true
660-
if err := b.hostState.securityOptions.PolicyEnforcer.EnforceScratchMountPolicy(ctx, settings.CombinedLayers.ContainerRootPath, true); err != nil {
661-
return fmt.Errorf("scratch mounting denied by policy: %w", err)
662-
}
663-
// The following two folders are expected to be present in the scratch.
664-
// But since we have just formatted the scratch we would need to
665-
// create them manually.
666-
sandboxStateDirectory := filepath.Join(settings.CombinedLayers.ContainerRootPath, sandboxStateDirName)
667-
err = os.Mkdir(sandboxStateDirectory, 0777)
668-
if err != nil {
669-
return fmt.Errorf("failed to create sandboxStateDirectory: %w", err)
670-
}
669+
hivesDirectory := filepath.Join(settings.CombinedLayers.ContainerRootPath, hivesDirName)
670+
err = os.Mkdir(hivesDirectory, 0777)
671+
if err != nil {
672+
return fmt.Errorf("failed to create hivesDirectory: %w", err)
673+
}
671674

672-
hivesDirectory := filepath.Join(settings.CombinedLayers.ContainerRootPath, hivesDirName)
673-
err = os.Mkdir(hivesDirectory, 0777)
674-
if err != nil {
675-
return fmt.Errorf("failed to create hivesDirectory: %w", err)
675+
case guestrequest.RequestTypeRemove:
676+
log.G(ctx).Tracef("CWCOWCombinedLayers: Remove")
677+
if err := b.hostState.securityOptions.PolicyEnforcer.EnforceScratchUnmountPolicy(ctx, settings.CombinedLayers.ContainerRootPath); err != nil {
678+
return fmt.Errorf("scratch unmounting denied by policy: %w", err)
679+
}
676680
}
677681

678682
// Reconstruct WCOWCombinedLayers{} req before forwarding to GCS

internal/uvm/cimfs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (umb *UVMMountedBlockCIMs) MountedVolumePath() string {
3535
}
3636

3737
func (umb *UVMMountedBlockCIMs) Release(ctx context.Context) error {
38+
log.G(ctx).Tracef("UVMWCOWBlockCIMs : Release")
3839
umb.host.blockCIMMountLock.Lock()
3940
defer umb.host.blockCIMMountLock.Unlock()
4041

internal/uvm/combine_layers.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,32 @@ func (uvm *UtilityVM) CombineLayersLCOW(ctx context.Context, containerID string,
8585
//
8686
// NOTE: `rootfsPath` is the path from within the UVM.
8787
func (uvm *UtilityVM) RemoveCombinedLayersWCOW(ctx context.Context, rootfsPath string) error {
88-
msr := &hcsschema.ModifySettingRequest{
89-
GuestRequest: guestrequest.ModificationRequest{
90-
ResourceType: guestresource.ResourceTypeCombinedLayers,
91-
RequestType: guestrequest.RequestTypeRemove,
92-
Settings: guestresource.WCOWCombinedLayers{
93-
ContainerRootPath: rootfsPath,
88+
var msr *hcsschema.ModifySettingRequest
89+
90+
if uvm.HasConfidentialPolicy() {
91+
msr = &hcsschema.ModifySettingRequest{
92+
GuestRequest: guestrequest.ModificationRequest{
93+
ResourceType: guestresource.ResourceTypeCWCOWCombinedLayers,
94+
RequestType: guestrequest.RequestTypeRemove,
95+
Settings: guestresource.CWCOWCombinedLayers{
96+
CombinedLayers: guestresource.WCOWCombinedLayers{
97+
ContainerRootPath: rootfsPath,
98+
},
99+
},
94100
},
95-
},
101+
}
102+
} else {
103+
msr = &hcsschema.ModifySettingRequest{
104+
GuestRequest: guestrequest.ModificationRequest{
105+
ResourceType: guestresource.ResourceTypeCombinedLayers,
106+
RequestType: guestrequest.RequestTypeRemove,
107+
Settings: guestresource.WCOWCombinedLayers{
108+
ContainerRootPath: rootfsPath,
109+
},
110+
},
111+
}
96112
}
113+
97114
return uvm.modify(ctx, msr)
98115
}
99116

0 commit comments

Comments
 (0)