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]>
97 lines
3.4 KiB
Go
97 lines
3.4 KiB
Go
package platform
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"slices"
|
|
"strings"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// FolderID returns what identifies the folder at path itself, not its
|
|
// path: its device, inode and birth time. ext4 gives a folder made again
|
|
// the inode number the deleted one had, so the birth time (where the file
|
|
// system keeps one) tells them apart.
|
|
func FolderID(path string) (string, error) {
|
|
st, err := statx(unix.AT_FDCWD, path, 0)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return statxID(&st), nil
|
|
}
|
|
|
|
// openFolder is the open folder f as FolderStat has it, read from f
|
|
// itself, so nothing put at its path since it was opened counts. Its
|
|
// volume is "fsid:<f_fsid>" on a file system whose f_fsid is its own
|
|
// (fsidOwn), mounted for writing, and "" elsewhere.
|
|
func openFolder(f *os.File) (FolderStat, error) {
|
|
st, err := statx(int(f.Fd()), "", unix.AT_EMPTY_PATH)
|
|
if err != nil {
|
|
return FolderStat{}, err
|
|
}
|
|
var fs unix.Statfs_t
|
|
if err := unix.Fstatfs(int(f.Fd()), &fs); err != nil {
|
|
return FolderStat{}, err
|
|
}
|
|
id := statxID(&st)
|
|
s := FolderStat{ID: id, Unique: strings.Count(id, ":") == 2 && uniqueFS(fs.Type), ReadOnly: fs.Flags&unix.ST_RDONLY != 0, Owner: st.Uid}
|
|
if !s.ReadOnly && fs.Fsid.Val != [2]int32{} && slices.Contains(fsidOwn(), fs.Type) {
|
|
s.Volume = fmt.Sprintf("fsid:%08x%08x", uint32(fs.Fsid.Val[0]), uint32(fs.Fsid.Val[1])) //nolint:gosec // G115: the ID's bits as they are, not a number's value
|
|
}
|
|
return s, nil
|
|
}
|
|
|
|
// statx is what statx finds at dirfd, path and flags: its device, inode,
|
|
// birth time and owner.
|
|
func statx(dirfd int, path string, flags int) (unix.Statx_t, error) {
|
|
var st unix.Statx_t
|
|
err := unix.Statx(dirfd, path, flags, unix.STATX_INO|unix.STATX_BTIME|unix.STATX_UID, &st)
|
|
return st, err
|
|
}
|
|
|
|
// statxID is a statx's FolderID.
|
|
func statxID(st *unix.Statx_t) string {
|
|
id := fmt.Sprintf("%d:%d", unix.Mkdev(st.Dev_major, st.Dev_minor), st.Ino)
|
|
if st.Mask&unix.STATX_BTIME != 0 {
|
|
id += fmt.Sprintf(":%d.%09d", st.Btime.Sec, st.Btime.Nsec)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// zfsSuperMagic is OpenZFS's statfs type, which golang.org/x/sys lacks.
|
|
const zfsSuperMagic = 0x2fc12fc1
|
|
|
|
// uniqueFS reports whether a statfs type is a local file system that keeps
|
|
// each inode number for its file's life and reports a birth time through
|
|
// statx: ext4, XFS, Btrfs, tmpfs, OpenZFS, F2FS and bcachefs. On one, a
|
|
// FolderID with the folder's birth time is its alone, never a deleted
|
|
// one's or another file system's (FolderStat.Unique), as an inode number
|
|
// alone is used again; FUSE, network shares and FAT may make inode numbers
|
|
// up.
|
|
func uniqueFS(fsType int64) bool {
|
|
switch fsType {
|
|
case unix.EXT4_SUPER_MAGIC, unix.XFS_SUPER_MAGIC, unix.BTRFS_SUPER_MAGIC, unix.TMPFS_MAGIC,
|
|
zfsSuperMagic, unix.F2FS_SUPER_MAGIC, unix.BCACHEFS_SUPER_MAGIC:
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// HasImmutableFlag reports whether this system has a user-immutable flag:
|
|
// Linux's immutable attribute needs root.
|
|
const HasImmutableFlag = false
|
|
|
|
// FoldsCase reports whether file names here may match whatever their
|
|
// case: not on Linux's file systems, as devvm's project folders use them.
|
|
const FoldsCase = false
|
|
|
|
// Chflags sets file flags: Linux has no unprivileged immutable flag.
|
|
func Chflags(context.Context, string, string) error { return errors.ErrUnsupported }
|
|
|
|
// Immutable reports whether a path has the user-immutable flag: Linux has
|
|
// none.
|
|
func Immutable(string) bool { return false }
|