vfs

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 51 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vfs is the node daemon of the virtual workspace: a lazy read-only file system over one commit of the version control store, the lower layer of a kernel overlay, with the dirty set read from the upper directory, and a checkout writer. The FUSE server builds on Linux only.

Package vfs is the node-local lazy workspace: a git tree served over FUSE as the read-only lower layer of a kernel overlay.

Index

Constants

This section is empty.

Variables

View Source
var ErrGrantRefused = errors.New(volattr.GrantRefused)

ErrGrantRefused is the store answer 403 to a grant: the store holds no read of the repo for the grant, and no retry of the call passes.

View Source
var ErrPackTooLarge = errors.New("vfs: the store refuses the pack as too large")

ErrPackTooLarge is the store refusing a pack for its size, or for the work that verifying it takes.

View Source
var ParsePublication = volattr.ParsePublication

Functions

func CheckHostPID

func CheckHostPID(readlink func(string) (string, error)) error

CheckHostPID refuses to run the overlay mode unless the process shares the PID namespace of the node and has a mount namespace of its own. Without the PID namespace the scan of other pods finds nothing and a stale overlay of a running pod goes unseen. readlink is os.Readlink in production.

func EncodeTree

func EncodeTree(es []Entry) []byte

EncodeTree serializes entries in git order.

func Import

func Import(ctx context.Context, st *HTTPStore, remote, ref string, depth int) (gitpack.SHA, error)

Import fetches ref of the remote with the given history depth (zero is the whole history), packs the objects in one pack and uploads it with an import grant. It returns the commit that ref named.

func ListenCtlSocket

func ListenCtlSocket(path string, uid, gid int) (net.Listener, error)

ListenCtlSocket binds the control socket before a caller mounts. The socket must lie in a directory that only the workspace of this mount can reach: the directory may not be open to others, and the socket is created 0660 and owned by uid and gid, so no other workspace or node process can connect.

func Materialize

func Materialize(ctx context.Context, st Store, commit gitpack.SHA, dest, marker string, uid, gid int) error

Materialize writes the tree of commit below dest, for a workspace that has only a disk. A marker file records a finished checkout; Materialize then changes nothing, whatever commit the marker names, so a restart never overwrites the edits of the workspace. A half-written checkout has no marker, and Materialize removes it and writes it again.

func MaterializeWith

func MaterializeWith(ctx context.Context, tel Telemetry, st Store, commit gitpack.SHA, dest, marker string, uid, gid int) error

MaterializeWith is Materialize under the span vfs.materialize, with the files, bytes and store calls of the checkout.

func SeedTier2Bytes

func SeedTier2Bytes(n int64)

SeedTier2Bytes adds the size of the cache directory at startup to Tier2Bytes.

func ServeOpHeads

func ServeOpHeads(ctx context.Context, s OpHeadsStore, expect int64, heads []string) (api.OpHeads, error)

ServeOpHeads answers the shim op opheads: a read without heads, and a compare-and-swap on the generation expect with them. The error carries the store code, so a shim that loses the race sees vcs_generation_conflict.

func ServeRefs

func ServeRefs(ctx context.Context, s RefStore, op, name string, expect int64, commit string, del bool) (refs []api.Ref, ref *api.Ref, err error)

ServeRefs answers the shim ops refs and swapref. The error carries the store code; a *RefConflictError also carries the stored ref, so the shim that loses the race can retry from the winner.

func Tier2Bytes

func Tier2Bytes() int64

Tier2Bytes is the number of blob bytes that this process wrote to the node cache, plus the size of the cache that SeedTier2Bytes found at startup.

func UpperBase

func UpperBase(c *Cache, root gitpack.SHA) upperdir.BaseTree

UpperBase returns the base tree of a mount for upperdir.Scan. A submodule is a directory with no entries.

func WithTraceparent

func WithTraceparent(ctx context.Context, traceparent string) context.Context

WithTraceparent returns ctx with the remote span context of a W3C traceparent header value. A value that does not parse leaves ctx unchanged.

Types

type Cache

type Cache struct {
	Store       Store
	Dir         string
	BulkEntries int
	PrefetchN   int
	PrefetchB   int64

	BlobHits, BlobMisses, TreeMisses, TreeHits atomic.Int64
	// Tel carries the correlation attributes of the spans of this cache.
	Tel Telemetry
	// contains filtered or unexported fields
}

Cache is tier 1 (decoded trees in memory) and tier 2 (blobs on node-local disk).

func NewCache

func NewCache(st Store, dir string) *Cache

func (*Cache) Blob

func (c *Cache) Blob(ctx context.Context, s gitpack.SHA, next func(yield func(Entry) bool)) (string, error)

Blob returns the path of the blob in the node cache, fetching it (plus read-ahead) if absent. next yields read-ahead candidates after s; it may be nil.

func (*Cache) CachedTree

func (c *Cache) CachedTree(sha gitpack.SHA) *Tree

CachedTree returns a tree only when it is already in memory.

func (*Cache) ReadBlob

func (c *Cache) ReadBlob(ctx context.Context, s gitpack.SHA) ([]byte, error)

ReadBlob returns blob bytes from the node cache.

func (*Cache) Tree

func (c *Cache) Tree(ctx context.Context, sha gitpack.SHA) (*Tree, error)

type ChangeEntry

type ChangeEntry struct {
	Path    string `json:"path"`
	Status  string `json:"status"`
	OldSHA  string `json:"old_sha,omitempty"`
	OldMode uint32 `json:"old_mode,omitempty"`
	OldSize int64  `json:"old_size,omitempty"`
	NewSHA  string `json:"new_sha,omitempty"`
	NewMode uint32 `json:"new_mode,omitempty"`
	Size    int64  `json:"size,omitempty"`
}

ChangeEntry is one file whose content in the view differs from the base tree. The SHAs are git blob names; an absent side has no SHA and mode 0.

type Config

type Config struct {
	Store    Store
	CacheDir string
	// UpperDir is the upper directory of the kernel overlay over the mount. The daemon reads the dirty set there.
	UpperDir string
	CtlSock  string
	Base     gitpack.SHA // commit
	UID, GID uint32
	Cache    *Cache
	NoOpen   bool
	// Clock paces the stats record and the settle test of the upper directory walk. Nil is the real clock.
	Clock     clock.Clock
	Telemetry Telemetry
	// contains filtered or unexported fields
}

Config is what the daemon needs to serve one commit.

type Correlation

type Correlation struct {
	WorkspaceID, Repo, MountID, Mode, Runtime, Node string
	Epoch                                           uint64
}

Correlation names the workspace and the mount in every span and log record of the daemon.

type DirtyEntry

type DirtyEntry struct {
	Path   string `json:"path"`
	Kind   string `json:"kind"` // file, symlink, dir, deleted
	Exec   bool   `json:"exec,omitempty"`
	Opaque bool   `json:"opaque,omitempty"`
}

DirtyEntry is one path that the upper directory changes against the base tree.

func DirtyFromUpper

func DirtyFromUpper(es []upperdir.Entry) []DirtyEntry

DirtyFromUpper converts the entries of upperdir.Scan to the entries of the dirty op.

type Entry

type Entry struct {
	Name string
	Mode uint32
	SHA  gitpack.SHA
	Size int64
}

func (Entry) IsDir

func (e Entry) IsDir() bool

func (Entry) IsExec

func (e Entry) IsExec() bool
func (e Entry) IsGitlink() bool
func (e Entry) IsSymlink() bool

type HTTPStore

type HTTPStore struct {
	BaseURL string
	// Grant returns the bearer grant of each call. A caller whose mount outlives one grant returns a fresh one.
	Grant  func() (string, error)
	Client *http.Client
	// Tel carries the correlation attributes and the logger of the spans and records the client writes.
	Tel Telemetry
	// contains filtered or unexported fields
}

HTTPStore reads and writes the version control store over its /v1/vcs routes.

func (*HTTPStore) Blobs

func (s *HTTPStore) Blobs(ctx context.Context, shas []gitpack.SHA) ([][]byte, error)

func (*HTTPStore) Calls

func (s *HTTPStore) Calls() int64

Calls is the number of store requests made so far.

func (*HTTPStore) Commit

func (s *HTTPStore) Commit(ctx context.Context, sha gitpack.SHA) (gitpack.SHA, time.Time, error)

func (*HTTPStore) DeleteRef

func (s *HTTPStore) DeleteRef(ctx context.Context, name string, expect int64) error

func (*HTTPStore) GetOp

func (s *HTTPStore) GetOp(ctx context.Context, kind, id string) ([]byte, error)

func (*HTTPStore) Has

func (s *HTTPStore) Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)

Has reports which of shas the store holds.

func (*HTTPStore) ImportPack

func (s *HTTPStore) ImportPack(ctx context.Context, idx, pack []byte) error

ImportPack uploads one pack and its v2 index. The pack ID is the SHA-256 of the pack.

func (*HTTPStore) Object

func (s *HTTPStore) Object(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)

Object reads one object of any type.

func (*HTTPStore) OpHeads

func (s *HTTPStore) OpHeads(ctx context.Context) (api.OpHeads, error)

func (*HTTPStore) PutObjects

func (s *HTTPStore) PutObjects(ctx context.Context, objs []gitpack.Object) error

PutObjects uploads objs in requests of at most maxPutBytes and maxPutObjects. One snapshot is one request unless it is larger.

func (*HTTPStore) PutOp

func (s *HTTPStore) PutOp(ctx context.Context, kind, id string, data []byte) error

func (*HTTPStore) PutWorkspace

func (s *HTTPStore) PutWorkspace(ctx context.Context, op, commit string, generation int64) error

func (*HTTPStore) Ref

func (s *HTTPStore) Ref(ctx context.Context, name string) (api.Ref, error)

func (*HTTPStore) Refs

func (s *HTTPStore) Refs(ctx context.Context) ([]api.Ref, error)

func (*HTTPStore) SwapOpHeads

func (s *HTTPStore) SwapOpHeads(ctx context.Context, expect int64, heads []string) (api.OpHeads, error)

func (*HTTPStore) SwapRef

func (s *HTTPStore) SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)

func (*HTTPStore) TreeBulk

func (s *HTTPStore) TreeBulk(ctx context.Context, sha gitpack.SHA, maxEntries int) ([]*Tree, error)

type HasStore

type HasStore interface {
	Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)
}

HasStore reports which objects the store holds, without reading them.

type Health

type Health struct {
	Logger *slog.Logger
	Node   string
	// Mounts returns the number of mounts the process serves.
	Mounts func() int
	Every  time.Duration
	Clock  clock.Clock
	// contains filtered or unexported fields
}

Health logs the vfs.health record of the daemon process: the signal to read when the Go runtime shows up in the hot path of a mount.

func (*Health) Run

func (h *Health) Run(ctx context.Context)

Run writes a record every Every until ctx ends.

type HistoryStats

type HistoryStats struct {
	Uploaded, Skipped int
	Bytes             int64
}

HistoryStats counts the packs of one ImportHistory run.

func ImportHistory

func ImportHistory(ctx context.Context, st HistoryStore, remote, ref string, logf func(format string, args ...any)) (gitpack.SHA, HistoryStats, error)

ImportHistory fetches the whole history of ref and uploads it as packs of at most about 48 MiB. The history is cut along the first-parent chain of the commit: a range holds the commits that its last commit reaches and the commit before the range does not, with their objects, but not a blob over 16 MiB. Each pack is self-contained, so the store verifies it alone. A range whose commits the store all holds is skipped, so a later run uploads only the ranges that gained commits. It returns the commit that ref named.

type HistoryStore

type HistoryStore interface {
	ImportPack(ctx context.Context, idx, pack []byte) error
	Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)
}

HistoryStore is the part of the store that ImportHistory uses.

type MountOpts

type MountOpts struct {
	TTL               time.Duration
	Debug             bool
	DefaultPermission bool
	DirectMount       bool
}

type Node

type Node struct {
	fs.Inode
	// contains filtered or unexported fields
}

func (*Node) Allocate

func (n *Node) Allocate(ctx context.Context, f fs.FileHandle, off uint64, size uint64, mode uint32) syscall.Errno

func (*Node) Create

func (n *Node) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (*fs.Inode, fs.FileHandle, uint32, syscall.Errno)

func (*Node) Fsync

func (n *Node) Fsync(ctx context.Context, f fs.FileHandle, flags uint32) syscall.Errno

Fsync succeeds: the lower layer holds nothing dirty.

func (*Node) Getattr

func (n *Node) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) (rerr syscall.Errno)

func (*Node) Lookup

func (n *Node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (_ *fs.Inode, rerr syscall.Errno)

func (*Node) Mkdir

func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*fs.Inode, syscall.Errno)

func (*Node) Open

func (n *Node) Open(ctx context.Context, flags uint32) (_ fs.FileHandle, _ uint32, rerr syscall.Errno)

func (*Node) Read

func (n *Node) Read(ctx context.Context, f fs.FileHandle, dest []byte, off int64) (res fuse.ReadResult, rerr syscall.Errno)

Read serves handle-less reads when the kernel runs without OPEN (no_open).

func (*Node) Readdir

func (n *Node) Readdir(ctx context.Context) (_ fs.DirStream, rerr syscall.Errno)
func (n *Node) Readlink(ctx context.Context) (_ []byte, rerr syscall.Errno)

func (*Node) Rename

func (n *Node) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, flags uint32) syscall.Errno

func (*Node) Rmdir

func (n *Node) Rmdir(ctx context.Context, name string) syscall.Errno

func (*Node) Setattr

func (n *Node) Setattr(ctx context.Context, f fs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) syscall.Errno

func (*Node) Statfs

func (n *Node) Statfs(ctx context.Context, out *fuse.StatfsOut) (rerr syscall.Errno)
func (n *Node) Symlink(ctx context.Context, target, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno)
func (n *Node) Unlink(ctx context.Context, name string) syscall.Errno

func (*Node) Write

func (n *Node) Write(ctx context.Context, f fs.FileHandle, data []byte, off int64) (uint32, syscall.Errno)

type NodePlugin

type NodePlugin struct {
	csi.UnimplementedIdentityServer
	csi.UnimplementedNodeServer

	DriverName string
	NodeID     string
	// StateDir holds the blob cache of the node and the lower mount point, upper directory and work directory of every
	// volume.
	StateDir string
	// APIURL is the store base URL. Grant signs the node grant of a volume; the plugin calls it for every
	// store call, so a mount outlives any one grant.
	APIURL string
	Grant  func(Publication) string
	UID    uint32
	GID    uint32
	HTTP   *http.Client
	Clock  clock.Clock
	// Logger receives the vfs.stats, vfs.health and error records. SlowOp and StatsEvery tune them; zero is the default.
	Logger     *slog.Logger
	SlowOp     time.Duration
	StatsEvery time.Duration
	// contains filtered or unexported fields
}

NodePlugin is the CSI node plugin of the virtual workspace. NodePublishVolume mounts the tree of one commit for one pod as a kernel overlay over a read-only FUSE lower layer, signs the node grant of the volume and serves the control socket in a directory of that pod. NodeUnpublishVolume unmounts it and removes its volume directory and the socket directory.

func (*NodePlugin) GetPluginInfo

func (*NodePlugin) Mounts

func (p *NodePlugin) Mounts() int

Mounts is the number of workspaces the plugin serves.

func (*NodePlugin) NodeGetInfo

func (*NodePlugin) NodePublishVolume

NodePublishVolume mounts the workspace of the workspace named by the volume attributes at the target path, or binds the control socket directory of the pod for a control socket volume.

func (*NodePlugin) NodeUnpublishVolume

NodeUnpublishVolume unmounts the workspace and deletes its volume directory. A volume this process does not know, for example after a restart, still loses its mount and its volume directory.

func (*NodePlugin) Probe

func (*NodePlugin) SeedCacheSize

func (p *NodePlugin) SeedCacheSize(dir string)

SeedCacheSize adds the size of the blob cache that an earlier process left in dir to the tier-2 figure of vfs.health.

func (*NodePlugin) Serve

func (p *NodePlugin) Serve(ctx context.Context, socket string) error

Serve answers CSI calls on the unix socket until ctx ends.

type OpHeadsStore

type OpHeadsStore interface {
	OpHeads(ctx context.Context) (api.OpHeads, error)
	SwapOpHeads(ctx context.Context, expect int64, heads []string) (api.OpHeads, error)
}

OpHeadsStore reads and swaps the op heads of the workspace that the grant names.

type OpObjectStore

type OpObjectStore interface {
	PutOp(ctx context.Context, kind, id string, data []byte) error
	GetOp(ctx context.Context, kind, id string) ([]byte, error)
}

OpObjectStore keeps the operations and views of the op log of the workspace that the grant names.

type Publication

type Publication = volattr.Publication

Publication and ParsePublication are the volume attributes of a workspace, shared with the sandbox driver.

type RefConflictError

type RefConflictError struct {
	Message string
	Ref     *api.Ref
}

RefConflictError is a lost ref swap or delete. Ref is the stored ref, nil when none exists.

func (*RefConflictError) Error

func (e *RefConflictError) Error() string

type RefStore

type RefStore interface {
	Refs(ctx context.Context) ([]api.Ref, error)
	Ref(ctx context.Context, name string) (api.Ref, error)
	SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)
	DeleteRef(ctx context.Context, name string, expect int64) error
}

RefStore reads and swaps the refs of the native repo that the grant names.

type Store

type Store interface {
	Commit(ctx context.Context, sha gitpack.SHA) (tree gitpack.SHA, when time.Time, err error)
	// TreeBulk returns the tree and its subtrees breadth first until maxEntries entries, with blob sizes.
	TreeBulk(ctx context.Context, sha gitpack.SHA, maxEntries int) ([]*Tree, error)
	Blobs(ctx context.Context, shas []gitpack.SHA) ([][]byte, error)
	PutObjects(ctx context.Context, objs []gitpack.Object) error
	Object(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)
}

Store is what the daemon needs from the version control store. One method is one remote call.

type Telemetry

type Telemetry struct {
	Logger *slog.Logger
	Corr   Correlation
	// SlowOp is the latency above which a FUSE operation emits a span; zero is 50 ms.
	SlowOp time.Duration
	// StatsEvery is the interval of the vfs.stats record; zero is 30 s.
	StatsEvery time.Duration
}

Telemetry configures the spans and log records of one mount. The zero value logs nothing and sends spans to the global provider, which exports none unless the process installed a tracer provider.

type Tree

type Tree struct {
	SHA     gitpack.SHA
	Entries []Entry
	// contains filtered or unexported fields
}

func NewTree

func NewTree(sha gitpack.SHA, es []Entry) *Tree

func (*Tree) Lookup

func (t *Tree) Lookup(name string) (Entry, bool)

type VFS

type VFS struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, cfg Config) (*VFS, error)

New opens the workspace of cfg.Base: it reads the commit and its root tree. It runs under the span vfs.open.

func (*VFS) Close

func (v *VFS) Close()

Close writes the last vfs.stats record. The upper directory stays on disk.

func (*VFS) MountFUSE

func (v *VFS) MountFUSE(ctx context.Context, mnt string, o MountOpts) (*fuse.Server, error)

MountFUSE mounts v at mnt through the host kernel FUSE.

func (*VFS) Root

func (v *VFS) Root() *Node

func (*VFS) ServeCtl

func (v *VFS) ServeCtl(ctx context.Context, l net.Listener) error

func (*VFS) Stats

func (v *VFS) Stats() string

type WorkspaceStore

type WorkspaceStore interface {
	PutWorkspace(ctx context.Context, op, commit string, generation int64) error
}

WorkspaceStore records the head operation and mount commit, ordered by the op-heads generation of the swap.

Directories

Path Synopsis
Package upperdir reads the upper directory of the kernel overlay that serves a mount-mode workspace and reports which paths differ from the base tree that the read-only lower layer serves.
Package upperdir reads the upper directory of the kernel overlay that serves a mount-mode workspace and reports which paths differ from the base tree that the read-only lower layer serves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL