Skip to content

Commit 2ecafc6

Browse files
committed
review comments: 1
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
1 parent 448ef71 commit 2ecafc6

5 files changed

Lines changed: 360 additions & 113 deletions

File tree

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,62 @@
11
//go:build windows && !wcow
22

3-
// Package plan9 provides a controller for managing Plan9 file-share devices
3+
// Package plan9 provides a manager for managing Plan9 file-share devices
44
// attached to a Utility VM (UVM).
55
//
6-
// It handles attaching and detaching Plan9 shares to the VM via HCS modify
6+
// It handles adding and removing Plan9 shares on the host side via HCS modify
77
// calls. Guest-side mount operations (mapped-directory requests) are handled
8-
// separately by the mount controller.
8+
// separately by the mount manager.
99
//
10-
// The [Controller] interface is the primary entry point, with [Manager] as its
11-
// concrete implementation. A single [Manager] manages all Plan9 shares for a UVM.
10+
// # Deduplication and Reference Counting
11+
//
12+
// [Manager] deduplicates shares: if two callers add a share with identical
13+
// [AddOptions], the second call reuses the existing share and increments an
14+
// internal reference count rather than issuing a second HCS call. The share is
15+
// only removed from the VM when the last caller invokes [Manager.RemoveFromVM].
1216
//
1317
// # Lifecycle
1418
//
15-
// [Manager] tracks active shares by name in an internal map.
19+
// Each share progresses through the states below.
20+
// The happy path runs down the left column; the error path is on the right.
21+
//
22+
// Allocate entry for the share
23+
// │
24+
// ▼
25+
// ┌─────────────────────┐
26+
// │ sharePending │
27+
// └──────────┬──────────┘
28+
// │
29+
// ┌───────┴────────────────────────────────┐
30+
// │ AddPlan9 succeeds │ AddPlan9 fails
31+
// ▼ ▼
32+
// ┌─────────────────────┐ ┌──────────────────────┐
33+
// │ shareAdded │ │ shareInvalid │
34+
// └──────────┬──────────┘ └──────────────────────┘
35+
// │ RemovePlan9 succeeds (auto-removed from map)
36+
// ▼
37+
// ┌─────────────────────┐
38+
// │ shareRemoved │ ← terminal; entry removed from map
39+
// └─────────────────────┘
40+
//
41+
// State descriptions:
42+
//
43+
// - [sharePending]: entered when a new entry is allocated (by [Manager.ResolveShareName]
44+
// or the first [Manager.AddToVM] call). No HCS call has been made yet.
45+
// - [shareAdded]: entered once [vmPlan9Manager.AddPlan9] succeeds;
46+
// the share is live on the VM.
47+
// - [shareInvalid]: entered when [vmPlan9Manager.AddPlan9] fails;
48+
// the map entry is removed immediately so the next call can retry.
49+
// - [shareRemoved]: terminal state entered once [vmPlan9Manager.RemovePlan9] succeeds.
50+
//
51+
// Method summary:
1652
//
17-
// - [Controller.AddToVM] adds a share and records its name in the map.
18-
// If the HCS call fails, the share is not recorded.
19-
// - [Controller.RemoveFromVM] removes a share and deletes its name from the map.
20-
// If the share is not in the map, the call is a no-op.
53+
// - [Manager.ResolveShareName] pre-allocates a share name for the given [AddOptions]
54+
// without issuing any HCS call. If a matching share is already tracked,
55+
// the existing name is returned. This is useful for resolving downstream
56+
// resource paths (e.g., guest mount paths) before the share is live.
57+
// - [Manager.AddToVM] attaches the share, driving the HCS AddPlan9 call on
58+
// the first caller and incrementing the reference count on subsequent ones.
59+
// If the HCS call fails, the entry is removed so the next call can retry.
60+
// - [Manager.RemoveFromVM] decrements the reference count and tears down the
61+
// share only when the count reaches zero.
2162
package plan9

internal/controller/device/plan9/interface.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)