strategy

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 15 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 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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func (Kernel) MountOverlay(lowers []string, upper, work, target string) error

MountOverlay mounts target as the overlay of upper on lowers, with work as its scratch.

func (Kernel) Unmount

func (Kernel) Unmount(target string) error

Unmount unmounts target; one already unmounted is not an error.

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.

func (Lifted) Drop

func (lifted Lifted) Drop()

Drop removes what is left of the workspace once its upper directory was moved away.

func (Lifted) Restore

func (lifted Lifted) Restore() error

Restore puts the .git back and mounts the workspace again, as it was before Lift.

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

func Detect(want Name, state string, roots []string, mounters ...Mounter) (Maker, string)

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"
)

func FromProto

func FromProto(strategy gitdv1.Strategy) Name

FromProto is the name a request's strategy asks for; unspecified is "".

func (Name) Proto

func (name Name) Proto() gitdv1.Strategy

Proto is the name as the contract carries it.

type OverlayMaker

type OverlayMaker struct {
	Layers  string
	Mounter Mounter
}

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) Name

func (maker *OverlayMaker) Name() Name

Name is Overlay.

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.

func (*OverlayMaker) Unmake

func (maker *OverlayMaker) Unmake(_ context.Context, dest string) error

Unmake unmounts dest and removes its layer.

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.

func (Record) Lowers

func (record Record) Lowers() []string

Lowers are the record's read-only layers, the topmost first.

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.

func (ReflinkMaker) Name

func (ReflinkMaker) Name() Name

Name is Reflink.

func (ReflinkMaker) Unmake

func (ReflinkMaker) Unmake(_ context.Context, dest string) error

Unmake removes the clone.

Jump to

Keyboard shortcuts

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