volume

package
v0.8.22 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package volume copies a disk image to another node, sending only the blocks the receiving copy lacks. A local volume follows its instance this way: the new node copies the disk while the app keeps running, then, once the app has stopped, a final pass sends just the blocks written since.

receiver --POST summary of its copy (block -> SHA-256)--> owner
receiver <-- header, differing and zeroed blocks, end --- owner

Holes and all-zero blocks are never sent, so sparse disks stay sparse. Every block carries its hash, which the receiver checks before writing it.

Index

Constants

View Source
const BlockSize = 1 << 20

BlockSize is the unit of comparison and transfer.

Variables

View Source
var ErrBusy = errors.New("the volume is still attached to a running instance")

ErrBusy is the owner's answer to a final pass while the disk is still attached to a running VM.

Functions

func EachBlock

func EachBlock(f *os.File, fn func(i int64, b []byte) error) (int64, error)

EachBlock calls fn, in order, with each block of f that holds data; holes and all-zero blocks are skipped. b is reused between calls. It returns f's size.

func WriteSummary

func WriteSummary(w io.Writer, sum Summary) error

WriteSummary encodes a summary for the owner.

Types

type Puller

type Puller struct {
	Client *http.Client
	URL    string // the owner's endpoint
	Token  string
	Path   string // the local copy, created if needed
	// Progress is told the bytes received so far in the current pass.
	Progress func(int64)
	// contains filtered or unexported fields
}

Puller keeps a local copy of a disk another node serves up to date. It remembers what the copy holds between passes, so later passes only cost the owner's read.

func (*Puller) Pull

func (p *Puller) Pull(ctx context.Context, final bool) (Stats, error)

Pull runs one pass. A final pass asks for a consistent copy, which the owner refuses with ErrBusy while the disk is attached to a running VM.

type Stats

type Stats struct {
	Blocks int   // blocks sent
	Bytes  int64 // their size
	Zeroed int   // blocks the receiver had to clear
}

Stats counts what one pass transferred.

func Receive

func Receive(r io.Reader, dst *os.File, sum Summary, progress func(int64)) (Stats, error)

Receive applies a Send stream to dst and keeps sum, dst's summary, up to date. dst matches the owner's disk only if it returns nil.

func Send

func Send(w io.Writer, have Summary, src *os.File) (Stats, error)

Send writes everything a receiver holding have needs to match src: the header, each block that differs, each block it must clear, and the end marker. src must not change during a final pass.

type Summary

type Summary map[int64][32]byte

Summary maps each block holding data to the SHA-256 of its contents. Blocks not listed are holes or all zeros.

func ReadSummary

func ReadSummary(r io.Reader) (Summary, error)

ReadSummary decodes what a receiver sent.

func Summarize

func Summarize(f *os.File) (Summary, error)

Summarize reads the blocks of a disk image that hold data.

Jump to

Keyboard shortcuts

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