zfs

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidName = errors.New("zfs: invalid dataset or snapshot name")

	ErrDatasetNotFound  = errors.New("zfs: dataset does not exist")
	ErrDatasetExists    = errors.New("zfs: dataset already exists")
	ErrSnapshotNotFound = errors.New("zfs: snapshot does not exist")
	ErrSnapshotExists   = errors.New("zfs: snapshot already exists")
	ErrSnapshotHeld     = errors.New("zfs: snapshot has holds and cannot be destroyed")
	ErrHasClones        = errors.New("zfs: dataset has dependent clones")
	ErrPoolNotFound     = errors.New("zfs: pool does not exist")
	ErrPoolFaulted      = errors.New("zfs: pool is in faulted state")

	ErrPermission      = errors.New("zfs: permission denied")
	ErrBusy            = errors.New("zfs: dataset is busy")
	ErrPoolFull        = errors.New("zfs: pool is full")
	ErrNoSpace         = errors.New("zfs: no space left on device")
	ErrCommandNotFound = errors.New("zfs: zfs/zpool command not found")

	// Backward-compatible coarse sentinels.
	ErrNotFound      = errors.New("zfs: object does not exist")
	ErrAlreadyExists = errors.New("zfs: object already exists")
)

Functions

func ValidateDevicePath

func ValidateDevicePath(path string) error

func ValidateHoldTag

func ValidateHoldTag(tag string) error

func ValidateMountpoint

func ValidateMountpoint(path string) error

func ValidateName

func ValidateName(name string) error

func ValidatePoolName

func ValidatePoolName(name string) error

func ValidatePropertyName

func ValidatePropertyName(name string) error

func ValidateSnapshotFullName

func ValidateSnapshotFullName(name string) error

func ValidateSnapshotName

func ValidateSnapshotName(name string) error

Types

type CLIManager

type CLIManager struct {
	// contains filtered or unexported fields
}

CLIManager implements ZFSManager by shelling out to zfs/zpool commands.

func NewCLIManager

func NewCLIManager(opts ...CLIOption) (*CLIManager, error)

func (*CLIManager) CloneFromSnapshot

func (m *CLIManager) CloneFromSnapshot(ctx context.Context, snapshot, newDataset string) error

func (*CLIManager) CreateDataset

func (m *CLIManager) CreateDataset(ctx context.Context, name string, opts DatasetOptions) error

func (*CLIManager) CreateSnapshot

func (m *CLIManager) CreateSnapshot(ctx context.Context, dataset, snapName string) (*SnapshotInfo, error)

func (*CLIManager) DatasetExists

func (m *CLIManager) DatasetExists(ctx context.Context, name string) (bool, error)

func (*CLIManager) DestroyDataset

func (m *CLIManager) DestroyDataset(ctx context.Context, name string, opts DestroyOptions) error

func (*CLIManager) DestroySnapshot

func (m *CLIManager) DestroySnapshot(ctx context.Context, dataset, snapName string) error

func (*CLIManager) EstimateSendSize

func (m *CLIManager) EstimateSendSize(ctx context.Context, snapshot string, opts SendOptions) (int64, error)

func (*CLIManager) ExportPool

func (m *CLIManager) ExportPool(ctx context.Context, pool string) error

func (*CLIManager) GetDatasetInfo

func (m *CLIManager) GetDatasetInfo(ctx context.Context, name string) (*DatasetInfo, error)

func (*CLIManager) GetMountpoint

func (m *CLIManager) GetMountpoint(ctx context.Context, dataset string) (string, error)

func (*CLIManager) HoldSnapshot

func (m *CLIManager) HoldSnapshot(ctx context.Context, dataset, snapName, tag string) error

func (*CLIManager) ImportPool

func (m *CLIManager) ImportPool(ctx context.Context, pool, device string) error

func (*CLIManager) ListDatasets

func (m *CLIManager) ListDatasets(ctx context.Context, parent string) ([]DatasetInfo, error)

func (*CLIManager) ListSnapshots

func (m *CLIManager) ListSnapshots(ctx context.Context, dataset string) ([]SnapshotInfo, error)

func (*CLIManager) PoolSpace

func (m *CLIManager) PoolSpace(ctx context.Context, pool string) (*PoolSpace, error)

func (*CLIManager) PoolStatus

func (m *CLIManager) PoolStatus(ctx context.Context, pool string) (*PoolStatus, error)

func (*CLIManager) Receive

func (m *CLIManager) Receive(ctx context.Context, dataset string, r io.Reader) error

func (*CLIManager) ReleaseSnapshot

func (m *CLIManager) ReleaseSnapshot(ctx context.Context, dataset, snapName, tag string) error

func (*CLIManager) Rollback

func (m *CLIManager) Rollback(ctx context.Context, dataset, snapName string, opts RollbackOptions) error

func (*CLIManager) Send

func (m *CLIManager) Send(ctx context.Context, snapshot string, opts SendOptions, w io.Writer) error

func (*CLIManager) SetMountpoint

func (m *CLIManager) SetMountpoint(ctx context.Context, dataset, mountpoint string) error

func (*CLIManager) SetProperty

func (m *CLIManager) SetProperty(ctx context.Context, dataset, property, value string) error

func (*CLIManager) SnapshotExists

func (m *CLIManager) SnapshotExists(ctx context.Context, dataset, snapName string) (bool, error)

type CLIOption

type CLIOption func(*CLIManager)

func WithDefaultCommandTimeout

func WithDefaultCommandTimeout(timeout time.Duration) CLIOption

func WithLogger

func WithLogger(logger *slog.Logger) CLIOption

func WithMetadataCommandTimeout

func WithMetadataCommandTimeout(timeout time.Duration) CLIOption

func WithPool

func WithPool(pool string) CLIOption

func WithSudo

func WithSudo(sudo bool) CLIOption

func WithTransferCommandTimeout

func WithTransferCommandTimeout(timeout time.Duration) CLIOption

func WithZFSPath

func WithZFSPath(path string) CLIOption

func WithZPoolPath

func WithZPoolPath(path string) CLIOption

type DatasetInfo

type DatasetInfo struct {
	Name       string
	Mountpoint string
	Used       int64
	Available  int64
	Referenced int64
	Origin     string
	Creation   time.Time
}

type DatasetOptions

type DatasetOptions struct {
	Mountpoint string
	Properties map[string]string
	Quota      int64
}

type DestroyOptions

type DestroyOptions struct {
	Recursive       bool
	Force           bool
	DependentClones bool
}

type MockManager

type MockManager struct {
	// contains filtered or unexported fields
}

MockManager implements ZFSManager in-memory for tests.

func NewMockManager

func NewMockManager() *MockManager

func (*MockManager) ClearError

func (m *MockManager) ClearError(op string)

func (*MockManager) CloneFromSnapshot

func (m *MockManager) CloneFromSnapshot(_ context.Context, snapshot, newDataset string) error

func (*MockManager) CreateDataset

func (m *MockManager) CreateDataset(_ context.Context, name string, opts DatasetOptions) error

func (*MockManager) CreateSnapshot

func (m *MockManager) CreateSnapshot(_ context.Context, dataset, snapName string) (*SnapshotInfo, error)

func (*MockManager) DatasetExists

func (m *MockManager) DatasetExists(ctx context.Context, name string) (bool, error)

func (*MockManager) DestroyDataset

func (m *MockManager) DestroyDataset(_ context.Context, name string, opts DestroyOptions) error

func (*MockManager) DestroySnapshot

func (m *MockManager) DestroySnapshot(_ context.Context, dataset, snapName string) error

func (*MockManager) EstimateSendSize

func (m *MockManager) EstimateSendSize(_ context.Context, snapshot string, opts SendOptions) (int64, error)

func (*MockManager) ExportPool

func (m *MockManager) ExportPool(_ context.Context, pool string) error

func (*MockManager) GetDatasetInfo

func (m *MockManager) GetDatasetInfo(_ context.Context, name string) (*DatasetInfo, error)

func (*MockManager) GetMountpoint

func (m *MockManager) GetMountpoint(_ context.Context, dataset string) (string, error)

func (*MockManager) HoldSnapshot

func (m *MockManager) HoldSnapshot(_ context.Context, dataset, snapName, tag string) error

func (*MockManager) ImportPool

func (m *MockManager) ImportPool(_ context.Context, pool, device string) error

func (*MockManager) ListDatasets

func (m *MockManager) ListDatasets(_ context.Context, parent string) ([]DatasetInfo, error)

func (*MockManager) ListSnapshots

func (m *MockManager) ListSnapshots(_ context.Context, dataset string) ([]SnapshotInfo, error)

func (*MockManager) PoolSpace

func (m *MockManager) PoolSpace(_ context.Context, pool string) (*PoolSpace, error)

func (*MockManager) PoolStatus

func (m *MockManager) PoolStatus(_ context.Context, pool string) (*PoolStatus, error)

func (*MockManager) Receive

func (m *MockManager) Receive(_ context.Context, dataset string, r io.Reader) error

func (*MockManager) ReleaseSnapshot

func (m *MockManager) ReleaseSnapshot(_ context.Context, dataset, snapName, tag string) error

func (*MockManager) Rollback

func (m *MockManager) Rollback(_ context.Context, dataset, snapName string, opts RollbackOptions) error

func (*MockManager) Send

func (m *MockManager) Send(_ context.Context, snapshot string, opts SendOptions, w io.Writer) error

func (*MockManager) SetError

func (m *MockManager) SetError(op string, err error)

func (*MockManager) SetMountpoint

func (m *MockManager) SetMountpoint(_ context.Context, dataset, mountpoint string) error

func (*MockManager) SetProperty

func (m *MockManager) SetProperty(_ context.Context, dataset, property, value string) error

func (*MockManager) SnapshotExists

func (m *MockManager) SnapshotExists(_ context.Context, dataset, snapName string) (bool, error)

type PoolSpace

type PoolSpace struct {
	Pool          string
	Size          int64
	Allocated     int64
	Free          int64
	Capacity      float64
	Fragmentation float64
}

type PoolState

type PoolState string
const (
	PoolOnline   PoolState = "ONLINE"
	PoolDegraded PoolState = "DEGRADED"
	PoolFaulted  PoolState = "FAULTED"
	PoolOffline  PoolState = "OFFLINE"
	PoolRemoved  PoolState = "REMOVED"
	PoolUnavail  PoolState = "UNAVAIL"
)

type PoolStatus

type PoolStatus struct {
	Name   string
	State  PoolState
	Scan   string
	Errors string
}

type RollbackOptions

type RollbackOptions struct {
	DestroyLater bool
}

type SendOptions

type SendOptions struct {
	Incremental string
	Raw         bool
	Compressed  bool
	LargeBlocks bool
}

type SnapshotInfo

type SnapshotInfo struct {
	Name     string
	Dataset  string
	Used     int64
	Refer    int64
	Creation time.Time
	Holds    int
}

type ZFSError

type ZFSError struct {
	Op       string
	Command  string
	Dataset  string
	ExitCode int
	Stderr   string
	Err      error
}

ZFSError wraps a zfs/zpool command failure with structured context.

func (*ZFSError) Error

func (e *ZFSError) Error() string

func (*ZFSError) Unwrap

func (e *ZFSError) Unwrap() error

type ZFSManager

type ZFSManager interface {
	// Dataset operations.
	CreateDataset(ctx context.Context, name string, opts DatasetOptions) error
	CloneFromSnapshot(ctx context.Context, snapshot, newDataset string) error
	DestroyDataset(ctx context.Context, name string, opts DestroyOptions) error
	GetMountpoint(ctx context.Context, dataset string) (string, error)
	SetMountpoint(ctx context.Context, dataset, mountpoint string) error
	SetProperty(ctx context.Context, dataset, property, value string) error
	GetDatasetInfo(ctx context.Context, name string) (*DatasetInfo, error)
	ListDatasets(ctx context.Context, parent string) ([]DatasetInfo, error)
	DatasetExists(ctx context.Context, name string) (bool, error)

	// Snapshot operations.
	CreateSnapshot(ctx context.Context, dataset, snapName string) (*SnapshotInfo, error)
	Rollback(ctx context.Context, dataset, snapName string, opts RollbackOptions) error
	ListSnapshots(ctx context.Context, dataset string) ([]SnapshotInfo, error)
	DestroySnapshot(ctx context.Context, dataset, snapName string) error
	HoldSnapshot(ctx context.Context, dataset, snapName, tag string) error
	ReleaseSnapshot(ctx context.Context, dataset, snapName, tag string) error
	SnapshotExists(ctx context.Context, dataset, snapName string) (bool, error)

	// Pool operations.
	PoolStatus(ctx context.Context, pool string) (*PoolStatus, error)
	PoolSpace(ctx context.Context, pool string) (*PoolSpace, error)
	ImportPool(ctx context.Context, pool, device string) error
	ExportPool(ctx context.Context, pool string) error

	// Transfer operations.
	EstimateSendSize(ctx context.Context, snapshot string, opts SendOptions) (int64, error)
	Send(ctx context.Context, snapshot string, opts SendOptions, w io.Writer) error
	Receive(ctx context.Context, dataset string, r io.Reader) error
}

ZFSManager provides operations on ZFS datasets, snapshots, and pools. All methods are safe for concurrent use.

Jump to

Keyboard shortcuts

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