Skip to content

[shimV2] refactor SCSI package to unify the interfaces with build tagged files#2666

Open
rawahars wants to merge 3 commits intomicrosoft:mainfrom
rawahars:scsi_refactor
Open

[shimV2] refactor SCSI package to unify the interfaces with build tagged files#2666
rawahars wants to merge 3 commits intomicrosoft:mainfrom
rawahars:scsi_refactor

Conversation

@rawahars
Copy link
Copy Markdown
Contributor

@rawahars rawahars commented Apr 8, 2026

Summary

This pull request refactors the SCSI controller guest interface to use a unified GuestSCSIOps abstraction instead of separate Linux and Windows guest operation interfaces. It also updates the related tests to use a single mock guest implementation and adds new LCOW-specific tests. Additionally, the CI workflow is updated to build and test both LCOW and WCOW tagged packages.

It also moves the Config to the specific lcow or wcow implementation so that only the applicable options are available.

Abstraction and Interface Refactoring:

  • The Controller struct and its constructor now use a single GuestSCSIOps interface for guest operations, replacing the previous LinuxGuestSCSIOps and WindowsGuestSCSIOps fields and parameters. All guest operation calls in the controller are updated to use this unified interface.

Test Suite Updates:

  • The SCSI controller tests are refactored to use a single mockGuestOps implementation, removing the separate mock types for Linux and Windows guest operations. Test helpers and test cases are updated accordingly.

  • Adds a new controller_lcow_test.go file with LCOW-specific tests for guest mount and unmount error handling, using the new mock guest interface.

CI Workflow Enhancements:

  • Updates .github/workflows/ci.yml to build and test LCOW and WCOW tagged packages for shimV2, ensuring both variants are covered in CI.

rawahars added 2 commits April 8, 2026 05:19
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
// GuestSCSIMounter mounts a virtual disk partition inside an LCOW guest.
type GuestSCSIMounter interface {
// AddLCOWMappedVirtualDisk maps a virtual disk partition into the LCOW guest.
AddLCOWMappedVirtualDisk(ctx context.Context, settings guestresource.LCOWMappedVirtualDisk) error
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we propagate the lcow/wcow build tags to internal\vm\guestmanager\scsi*, internal\protocol\guestresource, and related packages so this just becomes:

// 
// internal/controller/device/scsi/mount/mount_lcow.go
// 

type GuestSCSIMounter interface {
	AddMappedVirtualDisk(ctx context.Context, settings guestresource.MappedVirtualDisk) error
}

// 
// internal/controller/device/scsi/mount/mount_wcow.go
// 

// GuestSCSIMounter mounts a virtual disk partition inside an WCOW guest.
type GuestSCSIMounter interface {
	AddMappedVirtualDisk(ctx context.Context, settings guestresource.MappedVirtualDisk) error
	AddMappedVirtualDiskForContainerScratch(ctx context.Context, settings guestresource.MappedVirtualDisk) error
}

(though internal\protocol\ LCOW files would need linux || lcow build tags, and the WCOW guest resources should be moved to hcs\schema2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have propagated the tags to all files under internal\vm\guestmanager.
Though I am skeptical about changing internal\protocol\guestresources as of now. We can perhaps tackle this part later on as we refactor the old shim.

Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Comment on lines +68 to +72
slices.EqualFunc(
slices.SortedFunc(slices.Values(c.Options), cmpFoldCase),
slices.SortedFunc(slices.Values(other.Options), cmpFoldCase),
strings.EqualFold,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
slices.EqualFunc(
slices.SortedFunc(slices.Values(c.Options), cmpFoldCase),
slices.SortedFunc(slices.Values(other.Options), cmpFoldCase),
strings.EqualFold,
)
slices.EqualFunc(
slices.SortFunc(c.Options, cmpFoldCase),
slices.SortFunc(other.Options, cmpFoldCase),
strings.EqualFold,
)

or

Suggested change
slices.EqualFunc(
slices.SortedFunc(slices.Values(c.Options), cmpFoldCase),
slices.SortedFunc(slices.Values(other.Options), cmpFoldCase),
strings.EqualFold,
)
slices.Equal(
slices.Sort(lo.Map(c.Options, strings.ToLower)),
slices.Sort(lo.Map(other.Options, strings.ToLower)),
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants