Documentation
¶
Overview ¶
Package strategy makes a workspace's directory from a template without writing its files: an overlay layer on top of the template, or a reflink copy of it. Each is a Maker; when none can run, the workspace package makes the workspace by writing its files, as it always has (Copy).
Index ¶
- Variables
- type Kernel
- type Lifted
- type Maker
- type Mounter
- type Name
- type OverlayMaker
- func (maker *OverlayMaker) LayersOf(dest string) (lower, upper, work string, ok bool)
- func (maker *OverlayMaker) Lift(dest string) (Lifted, error)
- func (maker *OverlayMaker) Make(ctx context.Context, template, dest string) error
- func (maker *OverlayMaker) MakeWarm(_ context.Context, template, warm, dest string) error
- func (maker *OverlayMaker) Name() Name
- func (maker *OverlayMaker) RecordOf(dest string) (Record, bool)
- func (maker *OverlayMaker) Records() []Record
- func (maker *OverlayMaker) Remount(ctx context.Context) (int, []error)
- func (maker *OverlayMaker) Sweep() []Record
- func (maker *OverlayMaker) Unmake(_ context.Context, dest string) error
- type Record
- type ReflinkMaker
Constants ¶
This section is empty.
Variables ¶
var ErrHeld = errors.New("the workspace is still mounted elsewhere, as a sandbox binds it: stop what uses it first")
ErrHeld is why a layer is not lifted: its workspace is still mounted somewhere else, as a sandbox binds it, and what the sandbox writes would land in the layer after it was moved.
var ErrUnsupported = errors.New("not supported here")
ErrUnsupported is a strategy this machine, or this path, cannot run.
Functions ¶
This section is empty.
Types ¶
type Kernel ¶
type Kernel struct{}
Kernel mounts with the mount system call, which takes CAP_SYS_ADMIN.
func (Kernel) MountOverlay ¶
MountOverlay mounts target as the overlay of upper on lowers, with work as its scratch.
type Lifted ¶
type Lifted struct {
Upper string
// contains filtered or unexported fields
}
Lifted is an overlay workspace's own layer taken off it, unmounted, without the workspace's .git, which is the workspace's and not what was installed in it. Upper is ready to be moved away; then Drop removes what is left, or Restore, when it was not moved after all, puts the workspace back as it was.
type Maker ¶
type Maker interface {
Name() Name
// Make makes dest, which must not exist, a directory showing the template's files and
// keeping its own writes.
Make(ctx context.Context, template, dest string) error
// Unmake removes the workspace at dest, and whatever Make kept for it elsewhere.
Unmake(ctx context.Context, dest string) error
}
Maker makes workspaces from templates one way.
func Detect ¶
Detect picks how workspaces are made on this machine, from what is wanted — Overlay or Reflink by name, Copy, or "" for the best there is — and says why. A nil Maker is Copy: the workspace package writes the files, as it always has. Nothing fails here: a strategy that cannot run falls back to copy, with the reason.
state is where templates and layers live; roots are where workspaces are made; mounters are tried in order — the kernel's own, then gitd-mount — and the first that mounts a probe overlay in those very places is the one used.
type Mounter ¶
type Mounter interface {
MountOverlay(lowers []string, upper, work, target string) error
Unmount(target string) error
}
Mounter mounts and unmounts overlays. gitd has no privilege to; a mounter is whoever has: the kernel when gitd runs with CAP_SYS_ADMIN (tests, a container given it), and the gitd-mount helper otherwise. lowers are the read-only layers, the topmost first: a template, or a warm layer above its template.
type Name ¶
type Name string
Name names a strategy, as the configuration and the answers say it.
const ( // Copy writes every file of the workspace: no template, always possible. Copy Name = "copy" // Overlay puts a layer of the workspace's own on top of the template. Overlay Name = "overlay" // Reflink copies the template with block cloning: files share blocks until written. Reflink Name = "reflink" )
type OverlayMaker ¶
OverlayMaker makes a workspace by mounting, on the workspace's path, a layer of its own on top of the template. The layer — its upper and work directories — lives under Layers, with a record of which workspace and template it is, so that a restarted gitd can mount it again.
func (*OverlayMaker) LayersOf ¶
func (maker *OverlayMaker) LayersOf(dest string) (lower, upper, work string, ok bool)
LayersOf are the template and the layer of the overlay workspace at dest, when it is one.
func (*OverlayMaker) Lift ¶
func (maker *OverlayMaker) Lift(dest string) (Lifted, error)
Lift unmounts the overlay workspace at dest and sets its .git aside. A workspace still mounted elsewhere once unmounted at dest is put back, and ErrHeld answered.
func (*OverlayMaker) Make ¶
func (maker *OverlayMaker) Make(ctx context.Context, template, dest string) error
Make mounts dest as the template with an empty layer of its own on top.
func (*OverlayMaker) MakeWarm ¶
func (maker *OverlayMaker) MakeWarm(_ context.Context, template, warm, dest string) error
MakeWarm mounts dest as the template, a warm layer above it when warm is set, and an empty layer of its own on top.
func (*OverlayMaker) RecordOf ¶
func (maker *OverlayMaker) RecordOf(dest string) (Record, bool)
RecordOf is the record of the overlay workspace at dest, when it is one.
func (*OverlayMaker) Records ¶
func (maker *OverlayMaker) Records() []Record
Records are the overlay workspaces whose layers are on disk, for mounting them again after a restart.
func (*OverlayMaker) Remount ¶
func (maker *OverlayMaker) Remount(ctx context.Context) (int, []error)
Remount mounts again every recorded workspace whose overlay is not mounted — after a reboot, or after somebody unmounted one — and says how many it mounted and what it could not. A workspace whose directory is gone is left to Sweep; one whose directory holds files is never mounted over, which would hide them.
func (*OverlayMaker) Sweep ¶
func (maker *OverlayMaker) Sweep() []Record
Sweep removes the layers no workspace has any more: those half built, with no record, and those whose workspace directory is gone. It returns the records it removed, so that their templates can be let go. A layer whose workspace is merely unmounted is kept for Remount.
type Record ¶
type Record struct {
Workspace, Template, Warm string
}
Record is one overlay workspace as its layer records it: its template, and the warm layer above it, if any.
type ReflinkMaker ¶
type ReflinkMaker struct{}
ReflinkMaker makes a workspace by cloning every file of the template: the clones share the template's blocks until written, so the copy takes almost no disk. It takes about as long as writing the files would — it saves disk, not time — so it is used only when configured. Modification times are kept, which is what lets git trust the template's index with core.checkStat=minimal.
func (ReflinkMaker) Make ¶
func (ReflinkMaker) Make(ctx context.Context, template, dest string) error
Make clones the template into dest, built aside first by the caller's convention: on any failure dest is removed. Directories are made in order as the template is walked, and its files cloned by cloneWorkers at once, each once its directory exists.