Skip to content

Commit 7f125d4

Browse files
committed
Update LCOW and WCOW paths to include pod identifiers in container root directories
For LCOWs, Prior to this change, the container root directory path was of the format- '<Root Dir>/c/<CONTAINER_ID>' We are changing it now to- '<Root Dir>/pods/<SANDBOX_ID>/<CONTAINER_ID>' For WCOWs, the only directory which is of our interest is 'C:\\SandboxMounts'. After our change, it would be of format- 'C:\\SandboxMounts\\<SANDBOX_ID>' Signed-off-by: Harsh Rawat <[email protected]>
1 parent 169c6ef commit 7f125d4

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

cmd/containerd-shim-runhcs-v1/pod.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func createPod(ctx context.Context, events publisher, req *task.CreateTaskReques
309309
}
310310
// LCOW (and WCOW Process Isolated for the time being) requires a real
311311
// task for the sandbox.
312-
lt, err := newHcsTask(ctx, events, parent, true, req, s)
312+
lt, err := newHcsTask(ctx, events, parent, true, req, s, req.ID)
313313
if err != nil {
314314
return nil, err
315315
}
@@ -408,7 +408,7 @@ func (p *pod) CreateTask(ctx context.Context, req *task.CreateTaskRequest, s *sp
408408
sid)
409409
}
410410

411-
st, err := newHcsTask(ctx, p.events, p.host, false, req, s)
411+
st, err := newHcsTask(ctx, p.events, p.host, false, req, s, p.id)
412412
if err != nil {
413413
return nil, err
414414
}

cmd/containerd-shim-runhcs-v1/task_hcs.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func newHcsStandaloneTask(ctx context.Context, events publisher, req *task.Creat
105105
return nil, errors.Wrap(errdefs.ErrFailedPrecondition, "oci spec does not contain WCOW or LCOW spec")
106106
}
107107

108-
shim, err := newHcsTask(ctx, events, parent, true, req, s)
108+
shim, err := newHcsTask(ctx, events, parent, true, req, s, req.ID)
109109
if err != nil {
110110
if parent != nil {
111111
parent.Close()
@@ -126,6 +126,7 @@ func createContainer(
126126
parent *uvm.UtilityVM,
127127
shimOpts *runhcsopts.Options,
128128
rootfs []*types.Mount,
129+
sandboxID string,
129130
) (cow.Container, *resources.Resources, error) {
130131
var (
131132
err error
@@ -157,6 +158,7 @@ func createContainer(
157158
} else {
158159
opts := &hcsoci.CreateOptions{
159160
ID: id,
161+
SandboxID: sandboxID,
160162
Owner: owner,
161163
Spec: s,
162164
HostingSystem: parent,
@@ -186,7 +188,9 @@ func newHcsTask(
186188
parent *uvm.UtilityVM,
187189
ownsParent bool,
188190
req *task.CreateTaskRequest,
189-
s *specs.Spec) (_ shimTask, err error) {
191+
s *specs.Spec,
192+
sandboxID string,
193+
) (_ shimTask, err error) {
190194
log.G(ctx).WithFields(logrus.Fields{
191195
"tid": req.ID,
192196
"ownsParent": ownsParent,
@@ -219,7 +223,7 @@ func newHcsTask(
219223
return nil, err
220224
}
221225

222-
container, resources, err := createContainer(ctx, req.ID, owner, netNS, s, parent, shimOpts, req.Rootfs)
226+
container, resources, err := createContainer(ctx, req.ID, owner, netNS, s, parent, shimOpts, req.Rootfs, sandboxID)
223227
if err != nil {
224228
return nil, err
225229
}

internal/guestpath/paths.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package guestpath
33
const (
44
// LCOWRootPrefixInUVM is the path inside UVM where LCOW container's root
55
// file system will be mounted
6-
LCOWRootPrefixInUVM = "/run/gcs/c"
6+
LCOWRootPrefixInUVM = "/run/gcs/pods"
77
// WCOWRootPrefixInUVM is the path inside UVM where WCOW container's root
88
// file system will be mounted
99
WCOWRootPrefixInUVM = `C:\c`

internal/hcsoci/create.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
var (
34-
lcowRootInUVM = guestpath.LCOWRootPrefixInUVM + "/%s"
34+
lcowRootInUVM = guestpath.LCOWRootPrefixInUVM + "/%s/%s"
3535
wcowRootInUVM = guestpath.WCOWRootPrefixInUVM + "/%s"
3636
)
3737

@@ -43,6 +43,7 @@ var (
4343
type CreateOptions struct {
4444
// Common parameters
4545
ID string // Identifier for the container
46+
SandboxID string // Identifier for the pod of this container.
4647
Owner string // Specifies the owner. Defaults to executable name.
4748
Spec *specs.Spec // Definition of the container or utility VM being created
4849
SchemaVersion *hcsschema.Version // Requested Schema Version. Defaults to v2 for RS5, v1 for RS1..RS4
@@ -205,7 +206,9 @@ func CreateContainer(ctx context.Context, createOptions *CreateOptions) (_ cow.C
205206

206207
if coi.HostingSystem != nil {
207208
if coi.Spec.Linux != nil {
208-
r.SetContainerRootInUVM(fmt.Sprintf(lcowRootInUVM, coi.ID))
209+
// The container root within the UVM would be as below-
210+
// <Root Dir>/pods/<PodID>/<ContainerID>
211+
r.SetContainerRootInUVM(fmt.Sprintf(lcowRootInUVM, coi.SandboxID, coi.ID))
209212
} else {
210213
n := coi.HostingSystem.ContainerCounter()
211214
r.SetContainerRootInUVM(fmt.Sprintf(wcowRootInUVM, strconv.FormatUint(n, 16)))

internal/hcsoci/hcsdoc_wcow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func createMountsConfig(ctx context.Context, coi *createOptionsInternal) (*mount
7373
continue
7474
} else if strings.HasPrefix(mount.Source, guestpath.SandboxMountPrefix) {
7575
// Convert to the path in the guest that was asked for.
76-
mdv2.HostPath = convertToWCOWSandboxMountPath(mount.Source)
76+
mdv2.HostPath = convertToWCOWSandboxMountPath(coi.SandboxID, mount.Source)
7777
} else {
7878
// vsmb mount
7979
uvmPath, err := coi.HostingSystem.GetVSMBUvmPath(ctx, mount.Source, readOnly)

internal/hcsoci/resources_wcow.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/Microsoft/hcsshim/internal/uvm/scsi"
2828
)
2929

30-
const wcowSandboxMountPath = "C:\\SandboxMounts"
30+
const wcowSandboxMountPath = "C:\\SandboxMounts\\%s"
3131

3232
func allocateWindowsResources(ctx context.Context, coi *createOptionsInternal, r *resources.Resources, isSandbox bool) error {
3333
if coi.Spec.Root == nil {
@@ -193,7 +193,7 @@ func setupMounts(ctx context.Context, coi *createOptionsInternal, r *resources.R
193193
// - sandbox:///a/dirInUvm destination:C:\\dirInContainer.
194194
//
195195
// so first convert to a path in the sandboxmounts path itself.
196-
sandboxPath := convertToWCOWSandboxMountPath(mount.Source)
196+
sandboxPath := convertToWCOWSandboxMountPath(coi.SandboxID, mount.Source)
197197

198198
// Now we need to exec a process in the vm that will make these directories as theres
199199
// no functionality in the Windows gcs to create an arbitrary directory.
@@ -238,7 +238,8 @@ func setupMounts(ctx context.Context, coi *createOptionsInternal, r *resources.R
238238
return nil
239239
}
240240

241-
func convertToWCOWSandboxMountPath(source string) string {
241+
func convertToWCOWSandboxMountPath(sandboxID string, source string) string {
242242
subPath := strings.TrimPrefix(source, guestpath.SandboxMountPrefix)
243-
return filepath.Join(wcowSandboxMountPath, subPath)
243+
wcowSandboxMountPathPrefix := fmt.Sprintf(wcowSandboxMountPath, sandboxID)
244+
return filepath.Join(wcowSandboxMountPathPrefix, subPath)
244245
}

0 commit comments

Comments
 (0)