Skip to content

[shimV2] add plan9 device controller#2641

Open
rawahars wants to merge 7 commits intomicrosoft:mainfrom
rawahars:plan9-dev-controller
Open

[shimV2] add plan9 device controller#2641
rawahars wants to merge 7 commits intomicrosoft:mainfrom
rawahars:plan9-dev-controller

Conversation

@rawahars
Copy link
Copy Markdown
Contributor

@rawahars rawahars commented Mar 21, 2026

Summary

This change adds the plan9 device controller which can add/remove plan9 shares from a VM. The guest side operations are part of mount controller responsibility.

Whenever a new request for AddToVM comes, we call into HCS to hot-add the path via HcsModifyComputeSystem, where you inject a Plan9Share entry into the VM’s Devices → Plan9 → Shares schema, and HCS plumbs the corresponding endpoints so the guest can mount it using the Plan 9 (9P) protocol.

Note

For the same host path, we add a new share to the UVM. This pattern is similar to the existing pattern.
Ref- https://github.com/microsoft/hcsshim/blob/87708ff3150b7bceca4dbb3f7cdb7147428e42c3/internal/uvm/plan9.go

Imagine that the caller wants to add the same host path at two different guest locations-

Location 1: /tools
Location2: /tools2

If we do not create a new share for the UVM, we are likely to send a second GCS request asking the same share to be mounted at tools2. When the guest receives the GuestRequest of type ResourceTypeMappedDirectory, the handler unconditionally calls plan9.Mount(). This will, regardless of whether the same share name / aname was already mounted, dials a brand new vsock connection to the Plan9 server, opens a file descriptor from it, and performs a fresh unix.Mount(..., "9p", ...) syscall. This leads to error.

If we need to perform refCounting for plan9, it would need changes on both shim and guest side.

@rawahars rawahars requested a review from a team as a code owner March 21, 2026 12:14
rawahars added 2 commits April 5, 2026 06:33
This change adds the plan9 device controller which can add/remove plan9 shares from a VM. The guest side operations are part of mount controller responsibility.

Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
@rawahars rawahars force-pushed the plan9-dev-controller branch from 2ecafc6 to 4a697a8 Compare April 5, 2026 02:05
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
@rawahars rawahars force-pushed the plan9-dev-controller branch from 4a697a8 to b2cff99 Compare April 5, 2026 04:19
rawahars added 3 commits April 7, 2026 08:55
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
…attempts

Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
@rawahars rawahars force-pushed the plan9-dev-controller branch from e289573 to 2d9f924 Compare April 8, 2026 01:50
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
}

m.state = StateMounted
// Note we don't increment the ref count here as the caller of
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.

This comment isnt true. All callers follow the pattern.

Reserve
MountToGuest
UnmountFromGuest

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.

Right. It was unnecessary. Removing it in the revision.

// Share was never added — move directly to removed.
s.state = StateRemoved

case StateAdded:
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.

cant you just say StateAdded, StateInvalid.

Then do the identical code here.

handle the mount if not nil.
Handle the remove.
If remove error set to StateInvalid.

This prevents any new leases to be acquired while in the tearing down state.

If no error, just set to Removed.

The biggest difference is that they reuse the same code, but prevent new leases

@@ -1,12 +1,12 @@
//go:build windows
//go:build windows && lcow
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.

Why is this not just lcow?

return c.HostPath == other.HostPath &&
c.ReadOnly == other.ReadOnly &&
c.Restrict == other.Restrict &&
slices.Equal(c.AllowedNames, other.AllowedNames)
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.

similar to elsewhere, this is order and case sensitive

Comment on lines +41 to +45
vmPlan9 vmPlan9

// linuxGuest is the guest-side interface for LCOW Plan9 operations.
// Immutable after construction.
linuxGuest guestPlan9
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.

linux is probably a redundant/unnecessary prefix

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.

4 participants