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 ¶
- Variables
- func CheckHostPID(readlink func(string) (string, error)) error
- func EncodeTree(es []Entry) []byte
- func Import(ctx context.Context, st *HTTPStore, remote, ref string, depth int) (gitpack.SHA, error)
- func ListenCtlSocket(path string, uid, gid int) (net.Listener, error)
- func Materialize(ctx context.Context, st Store, commit gitpack.SHA, dest, marker string, ...) error
- func MaterializeWith(ctx context.Context, tel Telemetry, st Store, commit gitpack.SHA, ...) error
- func SeedTier2Bytes(n int64)
- func ServeOpHeads(ctx context.Context, s OpHeadsStore, expect int64, heads []string) (api.OpHeads, error)
- func ServeRefs(ctx context.Context, s RefStore, op, name string, expect int64, commit string, ...) (refs []api.Ref, ref *api.Ref, err error)
- func Tier2Bytes() int64
- func UpperBase(c *Cache, root gitpack.SHA) upperdir.BaseTree
- func WithTraceparent(ctx context.Context, traceparent string) context.Context
- type Cache
- func (c *Cache) Blob(ctx context.Context, s gitpack.SHA, next func(yield func(Entry) bool)) (string, error)
- func (c *Cache) CachedTree(sha gitpack.SHA) *Tree
- func (c *Cache) ReadBlob(ctx context.Context, s gitpack.SHA) ([]byte, error)
- func (c *Cache) Tree(ctx context.Context, sha gitpack.SHA) (*Tree, error)
- type ChangeEntry
- type Config
- type Correlation
- type DirtyEntry
- type Entry
- type HTTPStore
- func (s *HTTPStore) Blobs(ctx context.Context, shas []gitpack.SHA) ([][]byte, error)
- func (s *HTTPStore) Calls() int64
- func (s *HTTPStore) Commit(ctx context.Context, sha gitpack.SHA) (gitpack.SHA, time.Time, error)
- func (s *HTTPStore) DeleteRef(ctx context.Context, name string, expect int64) error
- func (s *HTTPStore) GetOp(ctx context.Context, kind, id string) ([]byte, error)
- func (s *HTTPStore) Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)
- func (s *HTTPStore) ImportPack(ctx context.Context, idx, pack []byte) error
- func (s *HTTPStore) Object(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)
- func (s *HTTPStore) OpHeads(ctx context.Context) (api.OpHeads, error)
- func (s *HTTPStore) PutObjects(ctx context.Context, objs []gitpack.Object) error
- func (s *HTTPStore) PutOp(ctx context.Context, kind, id string, data []byte) error
- func (s *HTTPStore) PutWorkspace(ctx context.Context, op, commit string, generation int64) error
- func (s *HTTPStore) Ref(ctx context.Context, name string) (api.Ref, error)
- func (s *HTTPStore) Refs(ctx context.Context) ([]api.Ref, error)
- func (s *HTTPStore) SwapOpHeads(ctx context.Context, expect int64, heads []string) (api.OpHeads, error)
- func (s *HTTPStore) SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)
- func (s *HTTPStore) TreeBulk(ctx context.Context, sha gitpack.SHA, maxEntries int) ([]*Tree, error)
- type HasStore
- type Health
- type HistoryStats
- type HistoryStore
- type MountOpts
- type Node
- func (n *Node) Allocate(ctx context.Context, f fs.FileHandle, off uint64, size uint64, mode uint32) syscall.Errno
- func (n *Node) Create(ctx context.Context, name string, flags uint32, mode uint32, ...) (*fs.Inode, fs.FileHandle, uint32, syscall.Errno)
- func (n *Node) Fsync(ctx context.Context, f fs.FileHandle, flags uint32) syscall.Errno
- func (n *Node) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) (rerr syscall.Errno)
- func (n *Node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (_ *fs.Inode, rerr syscall.Errno)
- func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*fs.Inode, syscall.Errno)
- func (n *Node) Open(ctx context.Context, flags uint32) (_ fs.FileHandle, _ uint32, rerr syscall.Errno)
- func (n *Node) Read(ctx context.Context, f fs.FileHandle, dest []byte, off int64) (res fuse.ReadResult, rerr syscall.Errno)
- func (n *Node) Readdir(ctx context.Context) (_ fs.DirStream, rerr syscall.Errno)
- func (n *Node) Readlink(ctx context.Context) (_ []byte, rerr syscall.Errno)
- func (n *Node) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, ...) syscall.Errno
- func (n *Node) Rmdir(ctx context.Context, name string) syscall.Errno
- func (n *Node) Setattr(ctx context.Context, f fs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) syscall.Errno
- 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 (n *Node) Write(ctx context.Context, f fs.FileHandle, data []byte, off int64) (uint32, syscall.Errno)
- type NodePlugin
- func (p *NodePlugin) GetPluginCapabilities(context.Context, *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error)
- func (p *NodePlugin) GetPluginInfo(context.Context, *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error)
- func (p *NodePlugin) Mounts() int
- func (p *NodePlugin) NodeGetCapabilities(context.Context, *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error)
- func (p *NodePlugin) NodeGetInfo(context.Context, *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error)
- func (p *NodePlugin) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error)
- func (p *NodePlugin) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error)
- func (p *NodePlugin) Probe(context.Context, *csi.ProbeRequest) (*csi.ProbeResponse, error)
- func (p *NodePlugin) SeedCacheSize(dir string)
- func (p *NodePlugin) Serve(ctx context.Context, socket string) error
- type OpHeadsStore
- type OpObjectStore
- type Publication
- type RefConflictError
- type RefStore
- type Store
- type Telemetry
- type Tree
- type VFS
- type WorkspaceStore
Constants ¶
This section is empty.
Variables ¶
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.
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.
var ParsePublication = volattr.ParsePublication
Functions ¶
func CheckHostPID ¶
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 Import ¶
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 ¶
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.
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 (*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 ¶
CachedTree returns a tree only when it is already in memory.
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 ¶
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 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) ImportPack ¶
ImportPack uploads one pack and its v2 index. The pack ID is the SHA-256 of the pack.
func (*HTTPStore) PutObjects ¶
PutObjects uploads objs in requests of at most maxPutBytes and maxPutObjects. One snapshot is one request unless it is larger.
func (*HTTPStore) PutWorkspace ¶
func (*HTTPStore) SwapOpHeads ¶
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.
type HistoryStats ¶
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 Node ¶
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).
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) GetPluginCapabilities ¶
func (p *NodePlugin) GetPluginCapabilities(context.Context, *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error)
func (*NodePlugin) GetPluginInfo ¶
func (p *NodePlugin) GetPluginInfo(context.Context, *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error)
func (*NodePlugin) Mounts ¶
func (p *NodePlugin) Mounts() int
Mounts is the number of workspaces the plugin serves.
func (*NodePlugin) NodeGetCapabilities ¶
func (p *NodePlugin) NodeGetCapabilities(context.Context, *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error)
func (*NodePlugin) NodeGetInfo ¶
func (p *NodePlugin) NodeGetInfo(context.Context, *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error)
func (*NodePlugin) NodePublishVolume ¶
func (p *NodePlugin) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error)
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 ¶
func (p *NodePlugin) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error)
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 (p *NodePlugin) Probe(context.Context, *csi.ProbeRequest) (*csi.ProbeResponse, error)
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.
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 ¶
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 VFS ¶
type VFS struct {
// contains filtered or unexported fields
}
func New ¶
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.
Source Files
¶
- cache.go
- changes.go
- config.go
- csi.go
- csimount.go
- csioverlay.go
- ctl.go
- ctlobjects.go
- ctlsock.go
- file.go
- health.go
- httpstore.go
- importer.go
- importhistory.go
- materialize.go
- mount.go
- mountinfo.go
- node.go
- observe.go
- opheads.go
- opstats.go
- overlayctl.go
- path.go
- readonly.go
- refs.go
- store.go
- syncfs_linux.go
- telemetry.go
- upperbase.go
- vfs.go
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. |