Documentation
¶
Overview ¶
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. It knows the trusted.overlay.* markers (whiteout, opaque, redirect, metacopy) and holds no state.
Index ¶
- Constants
- func ProbeTrusted(dir string) error
- func ProbeTrustedBeside(upper string) error
- func ScanStable(ctx context.Context, fsys FS, root string, base BaseTree, now func() time.Time) ([]Entry, Token, error)
- type BaseEntry
- type BaseTree
- type Blob
- type Dir
- type Dirent
- type Entry
- type FS
- type MemFS
- type MemNode
- type OSFS
- type Token
Constants ¶
const ( KindFile = "file" KindSymlink = "symlink" KindDir = "dir" KindDeleted = "deleted" )
const ( XattrOpaque = "trusted.overlay.opaque" XattrRedirect = "trusted.overlay.redirect" XattrMetacopy = "trusted.overlay.metacopy" )
const SettleWindow = 50 * time.Millisecond
SettleWindow is how long the newest change time must lie before the start of a walk for the walk to be settled. Kernel timestamps are coarse, so a change that lands in the same tick as the walk can leave the fingerprint unchanged.
Variables ¶
This section is empty.
Functions ¶
func ProbeTrusted ¶
ProbeTrusted checks that the process can set and read a trusted.* attribute on the file system of dir, a directory that no overlay references. Without CAP_SYS_ADMIN in the initial user namespace a read of trusted.overlay.* answers no data, and Scan would report a wrong dirty set.
func ProbeTrustedBeside ¶
ProbeTrustedBeside runs ProbeTrusted on a new directory next to the upper directory, on its file system, and removes it. It never writes into the upper directory, which a live overlay can reference. It checks the file system of the parent of upper, which is the file system of upper when no mount point lies at upper.
func ScanStable ¶
func ScanStable(ctx context.Context, fsys FS, root string, base BaseTree, now func() time.Time) ([]Entry, Token, error)
ScanStable reads the token, scans, and reads the token again, and retries when the two differ. An unsettled first token ends it after one scan, because the consumer treats that token as a change. It returns the token read before the winning scan, so an edit made during the scan shows in the next token. After the last try it returns the last scan with an unsettled token, which no other token equals.
Types ¶
type BaseTree ¶
type BaseTree interface {
Lookup(ctx context.Context, path string) (BaseEntry, bool, error)
List(ctx context.Context, dir string) ([]BaseEntry, error)
}
BaseTree reads the base tree. Paths use "/" and the empty path is the root. A submodule is a directory with no entries, as the mount shows it.
type Blob ¶
type Blob struct {
Mode fs.FileMode
Size int64
Data []byte
HasData bool
// Read counts the bytes read from the file, also when Read discards them.
Read int64
}
Blob is one regular file or symlink of a directory, from one inode. Data is the file bytes or the symlink target; a regular file past the limit has none. Size is len(Data) when Data is set.
type Dir ¶
type Dir interface {
// Entries lists the entries with their lstat.
Entries() ([]Dirent, error)
// Stat is the lstat of the directory itself.
Stat() (Dirent, error)
Lstat(name string) (Dirent, error)
// Attr reads an attribute of the directory itself.
Attr(attr string) (value string, ok bool, err error)
// Xattr reads an attribute of a regular file of the directory.
Xattr(name, attr string) (value string, ok bool, err error)
Read(name string, limit int64) (Blob, error)
// Open opens a child directory.
Open(name string) (Dir, error)
Close() error
}
Dir is an open directory. A name is one entry of the directory, never a path.
type Entry ¶
type Entry struct {
Path string
Kind string
Exec bool
Opaque bool
Origin string // base path whose blob is the content, when the upper entry holds none
NoContent bool
}
Entry is one path of the merged view that differs from the base tree.
type FS ¶
FS opens the directories of an upper directory. The empty path is the root, and a missing path answers an error that matches fs.ErrNotExist.
type MemFS ¶
type MemFS struct {
// contains filtered or unexported fields
}
MemFS is an in-memory FS. The root exists and has no entry of its own in the map.
type MemNode ¶
type MemNode struct {
Mode fs.FileMode
Whiteout bool
Size int64
Ctime int64
Ino uint64
Xattr map[string]string
// Data is the content of a regular file, or the target of a symlink.
Data []byte
}
MemNode is one entry of a MemFS.
type OSFS ¶
type OSFS struct {
Dir string
// contains filtered or unexported fields
}
OSFS reads an upper directory on a local file system. The sandbox can change the tree while the walk runs, so OSFS opens the root once and every directory below it one component at a time, and requires the opened inode to be the directory that fstatat found: no read goes through a symlink. A component that turns into a file or a symlink is gone. Attributes are read through a descriptor of the entry, so the walk needs no /proc. Reading the trusted.overlay.* attributes needs CAP_SYS_ADMIN in the initial user namespace.
type Token ¶
type Token struct {
Entries int64
Ctime int64
Bytes int64
SumCtime uint64
SumIno uint64
Settled bool
// contains filtered or unexported fields
}
Token is the fingerprint of an upper directory. The sums of the change times and of the inode numbers catch what the maximum alone misses: a clock that steps back, and a file replaced by another of the same size. An unsettled token carries a number that no other token has.
func Fingerprint ¶
Fingerprint walks the upper directory with lstat only. now is the start of the walk. The root entries that Scan skips do not count. The token does not see a second store through a mapping that is already dirty: the change time moves at the first write fault only.