Documentation
¶
Overview ¶
Package volume defines the shared block-device contract for the go-volumes family: a fixed-size, random-access store that higher layers read and write through, decoupling WHERE the bytes live (a pooled file volume, an S3-backed chunk store, an NBD export, a qcow2/raw image) from the FORMAT layered on top (ext4, xfs, squashfs, an OCI image, …).
The contract is deliberately the intersection of what a real backing already offers: github.com/go-volumes/pool's *Volume satisfies Device verbatim.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Borrowed ¶ added in v0.2.0
type Borrowed interface {
io.ReaderAt // ReadAt(p []byte, off int64) (n int, err error)
io.WriterAt // WriteAt(p []byte, off int64) (n int, err error)
// Size reports the device's current size in bytes.
Size() (int64, error)
// Sync durably commits writes made so far. It may be expensive.
Sync() error
}
Borrowed is a Device on loan: the holder may read, write and sync it, and has NO Close. The lender (the vault, the pool, whoever opened it) owns the lifetime and decides when the device is released, so a library that serves the device (a file server, an image viewer) can never close it from under its owner.
A typical lender is an unlocked encrypted container: it decrypts on the fly, decrypted bytes never leave the lender's process, and the stop order is unmount, server stop, filesystem close, then the lender commits and wipes. That order only holds if the borrower cannot short-circuit it, which is why Close is absent from the method set rather than documented as "do not call".
Ownership contract:
- The borrower MUST NOT close, wipe or otherwise release the device, and MUST NOT type-assert it to io.Closer to do so. Adapters in this package return a type whose method set has no Close.
- The lender MUST keep the device usable until every borrower has stopped (all in-flight calls returned). After the lender releases it, calls return an error; they must not panic and must not touch freed memory.
- Sync may be expensive (a journal write plus several fsyncs for an encrypted container, a network round trip for a remote store). Borrowers should call it when a durability promise to their own client requires it (a flush the client asked for), not after every write. Sync returning nil means every write that returned before the call is durable.
- Size is the current size in bytes; an error means it could not be read and is not a size of zero. The borrower reads it once and passes it on (for example to a filesystem's OpenReader(r, size)) unless the device is known to resize.
Concurrency follows the standard library contract: "Clients of ReadAt can execute parallel ReadAt calls on the same input source" and "Clients of WriteAt can execute parallel WriteAt calls on the same destination if the ranges do not overlap" (https://pkg.go.dev/io#ReaderAt, https://pkg.go.dev/io#WriterAt). Implementations must be safe for those parallel calls. Overlapping writes, or a read overlapping a write, are ordered by the borrower, not the device. Sync and Size may be called concurrently with ReadAt and WriteAt. As in package io, ReadAt and WriteAt must not retain p.
func File ¶ added in v0.2.0
File lends an open *os.File as a Borrowed, for tests and for servers that are handed a path. The caller keeps f and closes it. A file opened read-only makes WriteAt fail with the OS error; it is not a read-only device. Block devices report size 0 through Stat; use a device-aware Borrowed for those.
type Device ¶
type Device interface {
io.ReaderAt // ReadAt(p []byte, off int64) (n int, err error)
io.WriterAt // WriteAt(p []byte, off int64) (n int, err error)
// Size reports the device's current size in bytes.
Size() (int64, error)
// Sync durably commits any buffered writes.
Sync() error
io.Closer // Close releases the device; further use is undefined.
}
Device is a fixed-size, random-access block device. Writes MAY be buffered (a write-back cache, an S3-backed chunk store); Sync durably commits them.
It is the read-write contract a filesystem-format driver writes its on-disk image through, and the shape an S3/NBD/pool backing exposes.
type Discarder ¶
Discarder is a device that can release (TRIM/unmap) a byte range, letting a thin/sparse backing reclaim the space.
type Named ¶
type Named interface {
Name() string
}
Named is a device that carries a stable identifier (e.g. a volume name).
type ReadOnly ¶
ReadOnly is the read-only subset: a file opened read-only, a squashfs/iso9660 blob, a read-only NBD export, an OCI image layer set. Any Device also satisfies it.
type ReadOnlyReporter ¶
type ReadOnlyReporter interface {
ReadOnly() bool
}
ReadOnlyReporter is a device that reports whether it rejects writes.