Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion internal/layers/layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,16 @@ func MountContainerLayers(ctx context.Context, layerFolders []string, guestRoot
if err != nil {
return "", fmt.Errorf("failed to add SCSI scratch VHD: %s", err)
}
containerScratchPathInUVM = scsiMount.UVMPath

// This handles the case where we want to share a scratch disk for multiple containers instead
// of mounting a new one. Pass a unique value for `ScratchPath` to avoid container upper and
// work directories colliding in the UVM.
if scsiMount.RefCount() > 1 && uvm.OS() == "linux" {
scratchFmt := fmt.Sprintf("container_%s", filepath.Base(containerScratchPathInUVM))
containerScratchPathInUVM = ospath.Join("linux", scsiMount.UVMPath, scratchFmt)
Comment thread
katiewasnothere marked this conversation as resolved.
} else {
containerScratchPathInUVM = scsiMount.UVMPath
}

defer func() {
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/uvm/scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ type SCSIMount struct {
refCount uint32
}

// RefCount returns the current refcount for the SCSI mount.
func (sm *SCSIMount) RefCount() uint32 {
return sm.refCount
}

func (sm *SCSIMount) logFormat() logrus.Fields {
return logrus.Fields{
"HostPath": sm.HostPath,
Expand Down
24 changes: 12 additions & 12 deletions test/cri-containerd/container_virtual_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func Test_RunContainer_VirtualDevice_GPU_LCOW(t *testing.T) {
t.Fatalf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatalf("skipping test, host has no assignable nvidia gpu devices")
t.Fatal("skipping test, host has no assignable nvidia gpu devices")
}

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
Expand Down Expand Up @@ -250,7 +250,7 @@ func Test_RunContainer_VirtualDevice_GPU_Multiple_LCOW(t *testing.T) {
t.Fatalf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatalf("skipping test, host has no assignable nvidia gpu devices")
t.Fatal("skipping test, host has no assignable nvidia gpu devices")
}

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
Expand Down Expand Up @@ -295,10 +295,10 @@ func Test_RunContainer_VirtualDevice_GPU_and_NoGPU_LCOW(t *testing.T) {

testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Skipf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
t.Fatalf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Skipf("skipping test, host has no assignable nvidia gpu devices")
t.Fatal("skipping test, host has no assignable nvidia gpu devices")
}

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
Expand Down Expand Up @@ -364,10 +364,10 @@ func Test_RunContainer_VirtualDevice_GPU_Multiple_Removal_LCOW(t *testing.T) {

testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Skipf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
t.Fatalf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Skipf("skipping test, host has no assignable nvidia gpu devices")
t.Fatal("skipping test, host has no assignable nvidia gpu devices")
}

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
Expand Down Expand Up @@ -413,7 +413,7 @@ func Test_RunContainer_VirtualDevice_LocationPath_WCOW_Process(t *testing.T) {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceLocationPath == "" {
t.Fatalf("skipping test, host has no assignable devices")
t.Fatal("skipping test, host has no assignable devices")
}

pullRequiredImages(t, []string{imageWindowsNanoserver})
Expand Down Expand Up @@ -451,7 +451,7 @@ func Test_RunContainer_VirtualDevice_ClassGUID_WCOW_Process(t *testing.T) {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if instanceID == "" {
t.Fatalf("skipping test, host has no assignable devices")
t.Fatal("skipping test, host has no assignable devices")
}

// use fixed GPU class guid
Expand Down Expand Up @@ -495,7 +495,7 @@ func Test_RunContainer_VirtualDevice_GPU_WCOW_Hypervisor(t *testing.T) {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatalf("skipping test, host has no assignable devices")
t.Fatal("skipping test, host has no assignable devices")
}

pullRequiredImages(t, []string{imageWindowsNanoserver})
Expand Down Expand Up @@ -540,7 +540,7 @@ func Test_RunContainer_VirtualDevice_GPU_and_NoGPU_WCOW_Hypervisor(t *testing.T)
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatalf("skipping test, host has no assignable devices")
t.Fatal("skipping test, host has no assignable devices")
}

pullRequiredImages(t, []string{imageWindowsNanoserver})
Expand Down Expand Up @@ -602,7 +602,7 @@ func Test_RunContainer_VirtualDevice_GPU_Multiple_WCOW_Hypervisor(t *testing.T)
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatalf("skipping test, host has no assignable devices")
t.Fatal("skipping test, host has no assignable devices")
}

pullRequiredImages(t, []string{imageWindowsNanoserver})
Expand Down Expand Up @@ -654,7 +654,7 @@ func Test_RunContainer_VirtualDevice_GPU_Multiple_Removal_WCOW_Hypervisor(t *tes
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatalf("skipping test, host has no assignable devices")
t.Fatal("skipping test, host has no assignable devices")
}

pullRequiredImages(t, []string{imageWindowsNanoserver})
Expand Down