|
1 | 1 | //go:build windows && !wcow |
2 | 2 |
|
3 | | -// Package plan9 provides a controller for managing Plan9 file-share devices |
| 3 | +// Package plan9 provides a manager for managing Plan9 file-share devices |
4 | 4 | // attached to a Utility VM (UVM). |
5 | 5 | // |
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 |
7 | 7 | // calls. Guest-side mount operations (mapped-directory requests) are handled |
8 | | -// separately by the mount controller. |
| 8 | +// separately by the mount manager. |
9 | 9 | // |
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]. |
12 | 16 | // |
13 | 17 | // # Lifecycle |
14 | 18 | // |
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: |
16 | 52 | // |
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. |
21 | 62 | package plan9 |
0 commit comments