From 4cd8e71b358ab00a4f3955f7bcfeb6a7f42ed6cd Mon Sep 17 00:00:00 2001 From: Amit Barve Date: Fri, 7 May 2021 15:27:43 -0700 Subject: [PATCH] Fix bug with VSMB & SCSI mounts on the same host path When mounting a VHD at host path `C:\data\test.vhdx` into the container over SCSI and also sharing the same VHD inside the container over VSMB the current code just shares the VHD inside the container for both mounts instead of actually SCSI mounting the VHD for one of the mounts. This change fixes that. Signed-off-by: Amit Barve --- internal/hcsoci/hcsdoc_wcow.go | 21 +++++++++------------ internal/hcsoci/resources_wcow.go | 4 +--- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/internal/hcsoci/hcsdoc_wcow.go b/internal/hcsoci/hcsdoc_wcow.go index 439740fe9b..3dad366df9 100644 --- a/internal/hcsoci/hcsdoc_wcow.go +++ b/internal/hcsoci/hcsdoc_wcow.go @@ -37,9 +37,7 @@ func createMountsConfig(ctx context.Context, coi *createOptionsInternal) (*mount // TODO: Mapped pipes to add in v2 schema. var config mountsConfig for _, mount := range coi.Spec.Mounts { - if mount.Type != "" { - return nil, fmt.Errorf("invalid container spec - Mount.Type '%s' must not be set", mount.Type) - } + if uvm.IsPipe(mount.Source) { src, dst := uvm.GetContainerPipeMapping(coi.HostingSystem, mount) config.mpsv1 = append(config.mpsv1, schema1.MappedPipe{HostPath: src, ContainerPipeName: dst}) @@ -63,18 +61,17 @@ func createMountsConfig(ctx context.Context, coi *createOptionsInternal) (*mount return nil, fmt.Errorf("failed to eval symlinks for mount source %q: %s", mount.Source, err) } mdv2.HostPath = src + } else if mount.Type == "virtual-disk" || mount.Type == "physical-disk" { + uvmPath, err := coi.HostingSystem.GetScsiUvmPath(ctx, mount.Source) + if err != nil { + return nil, err + } + mdv2.HostPath = uvmPath } else { + // vsmb mount uvmPath, err := coi.HostingSystem.GetVSMBUvmPath(ctx, mount.Source, readOnly) if err != nil { - if err == uvm.ErrNotAttached { - // It could also be a scsi mount. - uvmPath, err = coi.HostingSystem.GetScsiUvmPath(ctx, mount.Source) - if err != nil { - return nil, err - } - } else { - return nil, err - } + return nil, err } mdv2.HostPath = uvmPath } diff --git a/internal/hcsoci/resources_wcow.go b/internal/hcsoci/resources_wcow.go index f2984a423b..0b09edc579 100644 --- a/internal/hcsoci/resources_wcow.go +++ b/internal/hcsoci/resources_wcow.go @@ -111,7 +111,7 @@ func setupMounts(ctx context.Context, coi *createOptionsInternal, r *resources.R // Validate each of the mounts. If this is a V2 Xenon, we have to add them as // VSMB shares to the utility VM. For V1 Xenon and Argons, there's nothing for // us to do as it's done by HCS. - for i, mount := range coi.Spec.Mounts { + for _, mount := range coi.Spec.Mounts { if mount.Destination == "" || mount.Source == "" { return fmt.Errorf("invalid OCI spec - a mount must have both source and a destination: %+v", mount) } @@ -139,7 +139,6 @@ func setupMounts(ctx context.Context, coi *createOptionsInternal, r *resources.R if err != nil { return errors.Wrapf(err, "adding SCSI physical disk mount %+v", mount) } - coi.Spec.Mounts[i].Type = "" r.Add(scsiMount) } else if mount.Type == "virtual-disk" { l.Debug("hcsshim::allocateWindowsResources Hot-adding SCSI virtual disk for OCI mount") @@ -147,7 +146,6 @@ func setupMounts(ctx context.Context, coi *createOptionsInternal, r *resources.R if err != nil { return errors.Wrapf(err, "adding SCSI virtual disk mount %+v", mount) } - coi.Spec.Mounts[i].Type = "" r.Add(scsiMount) } else { if uvm.IsPipe(mount.Source) {