Skip to content

Commit 451c5f4

Browse files
committed
CWCOW: Handle container remove request
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
1 parent 4338ebe commit 451c5f4

File tree

3 files changed

+54
-31
lines changed

3 files changed

+54
-31
lines changed

internal/gcs-sidecar/handlers.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -653,33 +653,38 @@ func (b *Bridge) modifySettings(req *request) (err error) {
653653
return nil
654654

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

666-
//Since unencrypted scratch is not an option, always pass true
667-
if err := b.hostState.securityPolicyEnforcer.EnforceScratchMountPolicy(ctx, settings.CombinedLayers.ContainerRootPath, true); err != nil {
668-
return fmt.Errorf("scratch mounting denied by policy: %w", err)
669-
}
670-
// The following two folders are expected to be present in the scratch.
671-
// But since we have just formatted the scratch we would need to
672-
// create them manually.
673-
sandboxStateDirectory := filepath.Join(settings.CombinedLayers.ContainerRootPath, sandboxStateDirName)
674-
err = os.Mkdir(sandboxStateDirectory, 0777)
675-
if err != nil {
676-
return fmt.Errorf("failed to create sandboxStateDirectory: %w", err)
677-
}
676+
hivesDirectory := filepath.Join(settings.CombinedLayers.ContainerRootPath, hivesDirName)
677+
err = os.Mkdir(hivesDirectory, 0777)
678+
if err != nil {
679+
return fmt.Errorf("failed to create hivesDirectory: %w", err)
680+
}
681+
682+
case guestrequest.RequestTypeRemove:
683+
log.G(ctx).Tracef("CWCOWCombinedLayers: Remove")
684+
if err := b.hostState.securityPolicyEnforcer.EnforceScratchUnmountPolicy(ctx, settings.CombinedLayers.ContainerRootPath); err != nil {
685+
return fmt.Errorf("scratch unmounting denied by policy: %w", err)
686+
}
678687

679-
hivesDirectory := filepath.Join(settings.CombinedLayers.ContainerRootPath, hivesDirName)
680-
err = os.Mkdir(hivesDirectory, 0777)
681-
if err != nil {
682-
return fmt.Errorf("failed to create hivesDirectory: %w", err)
683688
}
684689

685690
// 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)