mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Lock waits: - platform.LockFile and LockFileShared take a platform.Waiting, called once they find the lock held, never when it's free, whose end they call once the wait ends; LockFileWaiting, LockFileSharedWaiting and their delays (ShareNote, OCINote, WaitNote, groupsNote, makingNote) go. - msg.Waiting makes one from a Reporter's Status and a label; msg.WithStatus and msg.StatusOf carry the run's Status in its context for the two packages that take no Reporter, internal/state and internal/trust, which cli's execute sets; forbidigo keeps StatusOf to them, and AGENTS.md says so. - Every lock that waits shows its own label: vm_state_waiting (a VM's state, its deletion), claims_waiting, layout_waiting, git_lock_waiting, ca_waiting, packages_waiting, rebuilds_waiting, ubuntu_pin_waiting, custom_secrets_waiting, forwarder_waiting, agent_store_waiting, and the waits that printed a line after a delay, which now show theirs as a status line: share_waiting, oci_waiting, image_build_waiting, group_waiting, making_waiting. - An agent's login file's lock (agentlogin's lockLogin, a folder's flock that a VM's proxy holds while it refreshes the login) tries first without waiting and shows agentlogin.File's Waiting (agent_login_waiting) while it waits; secrets fills it from its Reporter, for SaveLogins, Claude Code's logins folder and every File. - The structure test's status-lines rule counts a LockFile or LockFileShared whose waiting is nil as slow work; the build port's record, a file just made that never waits, is listed in statusSites. - Without a terminal, or with -v, a status line draws nothing, so the waits that printed an info line after a delay no longer print it there; the CHANGELOG and the troubleshooting page say so. from.txtar's check that a free conversion lock printed no wait goes, as TestLockOCI checks it. The layout's migration runs under a status line (layout_migrating), only when there are migrations to run. Backend calls outside a launch: TestCommandStatusLines runs devvm ls, ports, size, network, tools, git-protect, history export, stop and rm on a running and a stopped VM and fails on a backend call with no status line showing, with a control that each makes one. A project folder devvm can't open and read (vm_folder_unreadable) was taken for another folder's VM (vm_other_folder, which offers rm and adopt, and adopt went on); the finder now keeps why (target.unread), and every command on the folder's VM, from the folder or a subfolder of it, names the folder and why; devvm rm VM run elsewhere goes by the VM's name as before. platform.UniqueFolderID had no caller but its test: FolderStat.Unique, from the open folder, replaced it; it goes, and its test checks StatFolder's Unique instead. Tests: TestLockFileWaiting (rewritten: called only when held, its end once got or given up, shared too), TestVMLockWaits, TestCheckLayoutWaits, TestCheckLayout (migrations under layout_migrating, nothing shown otherwise), TestLockGroups, TestLockShare, TestMaking, TestLockOCI and the build lock's test (status lines, not info lines), TestLockLogin, TestInitCACancelled (ca_waiting), the status-lines rule's lock cases, TestCommandStatusLines, TestUnreadableFolder (a subfolder of it too), TestStatFolderUnique. Docs: Contributing's CLI page (Status lines) and structure page, the cli and codebase-standards skills (the guards), AGENTS.md's Go conventions, internals/images.md and design.md (the waits), using/troubleshooting.md, using/vms.md (a folder devvm can't read); CHANGELOG. Co-Authored-By: Claude Opus 5.5 <[email protected]>
102 lines
4.8 KiB
Go
102 lines
4.8 KiB
Go
package platform
|
|
|
|
import "strings"
|
|
|
|
// A folder's volume is what identifies the volume it's on whatever device number the system
|
|
// gives that volume: its kind and value, "uuid:<VolumeUUID>" on macOS (VolumeUUID), or
|
|
// "fsid:<f_fsid>" on Linux for a file system that derives f_fsid from itself (FolderStat). A
|
|
// state records it bound to the folder's inode and birth time (VolumeOf), so a record that an
|
|
// older devvm left beside a folder it moved names no volume (RecordedVolume). With it, a folder
|
|
// that moved and whose disk was numbered anew since is still recognised (MovedFolder), and a
|
|
// renumbered disk isn't taken for an unmounted one (OnRecordedDisk).
|
|
|
|
// VolumeOf is vol, a volume's kind and value, bound to the folder whose FolderID is id: vol,
|
|
// then id's inode and birth time, as a state records it; "" when either is missing.
|
|
func VolumeOf(vol, id string) string {
|
|
rest := folderRest(id)
|
|
if vol == "" || rest == "" || strings.Count(vol, ":") != 1 {
|
|
return ""
|
|
}
|
|
return vol + ":" + rest
|
|
}
|
|
|
|
// folderRest is a FolderID's inode and birth time, "" for one without a birth time.
|
|
func folderRest(id string) string {
|
|
dev, rest, ok := strings.Cut(id, ":")
|
|
if !ok || !digits(dev) || strings.Count(rest, ":") != 1 {
|
|
return ""
|
|
}
|
|
return rest
|
|
}
|
|
|
|
// RecordedVolume is the volume (kind and value) that recorded, a state's folder volume
|
|
// (VolumeOf), names for the folder whose recorded FolderID is id, when it's bound to that
|
|
// folder's inode and birth time; "" otherwise.
|
|
func RecordedVolume(id, recorded string) string {
|
|
rest := folderRest(id)
|
|
if rest == "" || !strings.HasSuffix(recorded, ":"+rest) {
|
|
return ""
|
|
}
|
|
vol := strings.TrimSuffix(recorded, ":"+rest)
|
|
if strings.Count(vol, ":") != 1 {
|
|
return ""
|
|
}
|
|
return vol
|
|
}
|
|
|
|
// MovedFolder reports whether now, a folder at another path than the one recorded as wasID on
|
|
// the volume recorded (VolumeOf), is that folder, on a disk numbered anew since: its volume,
|
|
// vol (now's, as VolumeUUID or FolderStat gives it), is the recorded one, it has the recorded
|
|
// inode and birth time, and they're its alone (Unique), on a volume mounted for writing, never
|
|
// a snapshot. A folder whose ID is the recorded one is SameFolder's.
|
|
func MovedFolder(wasID, recorded string, now FolderStat, vol string) bool {
|
|
return MayHaveMoved(wasID, recorded, now) && vol == RecordedVolume(wasID, recorded)
|
|
}
|
|
|
|
// MayHaveMoved reports whether now could be the folder recorded as wasID, on the volume
|
|
// recorded, at another path (MovedFolder), from what costs nothing to compare: a volume bound
|
|
// to it, and its inode and birth time, its alone, on a volume mounted for writing. Only then is
|
|
// now's volume worth looking up.
|
|
func MayHaveMoved(wasID, recorded string, now FolderStat) bool {
|
|
return RecordedVolume(wasID, recorded) != "" && now.Unique && !now.ReadOnly && folderRest(now.ID) == folderRest(wasID)
|
|
}
|
|
|
|
// OnRecordedDisk reports whether a folder whose device is dev and whose volume is vol ("" when
|
|
// it can't be told) is on the disk that the folder recorded as wasID, on the volume recorded,
|
|
// was on: the same volume when both are known, else the same device, or any disk for a record
|
|
// that names no device, which can't tell another.
|
|
func OnRecordedDisk(wasID, recorded, dev, vol string) bool {
|
|
if was := RecordedVolume(wasID, recorded); was != "" && vol != "" {
|
|
return vol == was
|
|
}
|
|
return folderDevice(wasID) == "" || dev == folderDevice(wasID)
|
|
}
|
|
|
|
// KeepsVolume reports whether vol, the volume of the folder at the path recorded for the folder
|
|
// recorded as wasID, which SameFolder took for it, is the volume recorded with it, as a launch
|
|
// checks it on a disk numbered anew since (Renumbered), for a record whose volume is unchecked,
|
|
// and on Linux at every launch: the same volume, or none to compare, as for a state that records
|
|
// none bound to it or a volume that can't be told ("" ), where the device's rule alone decides.
|
|
// On another volume it's another folder that has the inode and birth time, such as a clone of
|
|
// the disk mounted at the folder's own path.
|
|
func KeepsVolume(wasID, recorded, vol string) bool {
|
|
was := RecordedVolume(wasID, recorded)
|
|
return was == "" || vol == "" || vol == was
|
|
}
|
|
|
|
// FolderStat is what identifies a folder and its volume, read from the folder opened with no
|
|
// link on its path (StatFolder): its FolderID; whether that's its alone (uniqueFS);
|
|
// whether its volume is mounted read-only, or is a snapshot; its mount point and the device
|
|
// mounted there, by name (macOS, for VolumeUUID); its volume, read in the process where the
|
|
// system gives it ("fsid:…" on Linux's ext4, btrfs and ZFS), "" otherwise; and its owner's
|
|
// user ID, from the same read, so a folder's owner is never another folder's.
|
|
type FolderStat struct {
|
|
ID string
|
|
Unique bool
|
|
ReadOnly bool
|
|
Mount string
|
|
Device string
|
|
Volume string
|
|
Owner uint32
|
|
}
|