Documentation ¶
Overview ¶
Package zfs enables ZFS pool and dataset management by wrapping "zfs" and "zpool" CLI commands.
All interactions with ZFS are done through Manager.
Index ¶
- Constants
- Variables
- func Join(parts ...string) string
- type CreateDatasetOptions
- type CreatePoolOptions
- type Dataset
- func (p *Dataset) Atime() (bool, bool)
- func (p *Dataset) Available() (uint64, bool)
- func (p *Dataset) CanMount() (bool, bool)
- func (p *Dataset) Checksum() (string, bool)
- func (p *Dataset) CompressRatio() (float64, bool)
- func (p *Dataset) Compression() (string, bool)
- func (p *Dataset) Copies() (uint64, bool)
- func (p *Dataset) Creation() (time.Time, bool)
- func (p *Dataset) Devices() (bool, bool)
- func (p *Dataset) Exec() (bool, bool)
- func (p *Dataset) LogicalReferenced() (uint64, bool)
- func (p *Dataset) LogicalUsed() (uint64, bool)
- func (p *Dataset) Mountpoint() (string, bool)
- func (p *Dataset) Quota() (uint64, bool)
- func (p *Dataset) ReadOnly() (bool, bool)
- func (p *Dataset) RefCompressRatio() (float64, bool)
- func (p *Dataset) RefQuota() (uint64, bool)
- func (p *Dataset) RefReservation() (uint64, bool)
- func (p *Dataset) RelAtime() (bool, bool)
- func (p *Dataset) Reservation() (uint64, bool)
- func (p *Dataset) SetUID() (bool, bool)
- func (p *Dataset) Sync() (string, bool)
- func (p *Dataset) Type() (DatasetType, bool)
- func (p *Dataset) Used() (uint64, bool)
- func (p *Dataset) UsedByChildren() (uint64, bool)
- func (p *Dataset) UsedByDataset() (uint64, bool)
- func (p *Dataset) UsedByRefReservation() (uint64, bool)
- func (p *Dataset) UsedBySnapshots() (uint64, bool)
- func (p *Dataset) VolSize() (uint64, bool)
- type DatasetType
- type DestroyDatasetFlag
- type ImportPoolOptions
- type Manager
- func (m *Manager) CreateDataset(ctx context.Context, options *CreateDatasetOptions) error
- func (m *Manager) CreatePool(ctx context.Context, options *CreatePoolOptions) error
- func (m *Manager) DestroyDataset(ctx context.Context, name string, flags ...DestroyDatasetFlag) error
- func (m *Manager) DestroyPool(ctx context.Context, name string, force bool) error
- func (m *Manager) ExportPool(ctx context.Context, name string, force bool) error
- func (m *Manager) GetDataset(ctx context.Context, name string, properties ...string) (*Dataset, error)
- func (m *Manager) GetDatasetProperty(ctx context.Context, name string, property string) (string, error)
- func (m *Manager) GetPool(ctx context.Context, name string, properties ...string) (*Pool, error)
- func (m *Manager) GetPoolProperty(ctx context.Context, name string, property string) (string, error)
- func (m *Manager) ImportPool(ctx context.Context, options *ImportPoolOptions) error
- func (m *Manager) InheritDatasetProperty(ctx context.Context, name string, property string, recursive bool) error
- func (m *Manager) ListDatasetNames(ctx context.Context, filter string, depth uint64, typ DatasetType) ([]string, error)
- func (m *Manager) ListDatasets(ctx context.Context, filter string, depth uint64, typ DatasetType, ...) ([]*Dataset, error)
- func (m *Manager) ListPoolNames(ctx context.Context) ([]string, error)
- func (m *Manager) ListPools(ctx context.Context, properties ...string) ([]*Pool, error)
- func (m *Manager) SetDatasetProperties(ctx context.Context, name string, properties map[string]string) error
- func (m *Manager) SetDatasetProperty(ctx context.Context, name string, property string, value string) error
- func (m *Manager) SetPoolProperties(ctx context.Context, name string, properties map[string]string) error
- func (m *Manager) SetPoolProperty(ctx context.Context, name string, property string, value string) error
- type Pool
- func (p *Pool) Allocated() (uint64, bool)
- func (p *Pool) Capacity() (uint64, bool)
- func (p *Pool) Fragmentation() (uint64, bool)
- func (p *Pool) Free() (uint64, bool)
- func (p *Pool) Freeing() (uint64, bool)
- func (p *Pool) Health() (string, bool)
- func (p *Pool) Leaked() (uint64, bool)
- func (p *Pool) ReadOnly() (bool, bool)
- func (p *Pool) Size() (uint64, bool)
- type Properties
- func (p Properties) Bool(property string) (bool, bool)
- func (p Properties) Bytes(property string) (uint64, bool)
- func (p Properties) Percent(property string) (uint64, bool)
- func (p Properties) Ratio(property string) (float64, bool)
- func (p Properties) String(property string) (string, bool)
- func (p Properties) Time(property string) (time.Time, bool)
- func (p Properties) Uint64(property string) (uint64, bool)
- type Property
Constants ¶
const ( HealthDegraded = "DEGRADED" HealthFaulted = "FAULTED" HealthOffline = "OFFLINE" HealthOnline = "ONLINE" HealthRemoved = "REMOVED" )
Variables ¶
var ( Err = errors.New("") ErrZFS = fmt.Errorf("%wzfs", Err) ErrZpool = fmt.Errorf("%wzpool", Err) ErrNotFound = fmt.Errorf("%wnot found", Err) ErrInvalidName = fmt.Errorf("%winvalid name", Err) ErrInvalidProperty = fmt.Errorf("%winvalid property", Err) ErrInvalidCreateOptions = fmt.Errorf("%winvalid create options", Err) )
Functions ¶
Types ¶
type CreateDatasetOptions ¶
type CreateDatasetOptions struct { // Name of the dataset. (required) Name string // Properties is a map of properties (-o) to set on the dataset. Properties map[string]string // CreateParents indicates whether to create any missing parent datasets by // passing the -p flag. CreateParents bool // Unmounted indicates whether to create the dataset without mounting it by // passing the -u flag. // // Ignored when VolumeSize is set. Unmounted bool // VolumeSize indicates we are creating a volume dataset instead of a // filesystem dataset. Hence to create a filesystem, VolumeSize must be // empty. VolumeSize string // BlockSize is the block size to use for the volume dataset by passing the // -b flag. // // Ignored when VolumeSize is empty. BlockSize string // Sparse indicates whether to create a sparse volume by passing the -s // flag. // // Ignored when VolumeSize is empty. Sparse bool }
CreateDatasetOptions are options for creating a new dataset.
type CreatePoolOptions ¶
type CreatePoolOptions struct { // Name of the pool. (required) Name string // Vdevs is a list of vdevs to pass to zpool create. (required) Vdevs []string // Properties is a map of properties (-o) to set on the pool. Properties map[string]string // FilesystemProperties is a map of filesystem properties (-O) to set on the // pool. FilesystemProperties map[string]string // Mountpoint is the mountpoint (-m) for the pool. Mountpoint string // Root is the root (-R) for the pool. Root string // Force indicates whether to force flag (-f) should be set. Force bool // DisableFeatures indicates whether to disable features flag (-d) should be // set. DisableFeatures bool // Args is a list of additional arguments to pass to zpool create. Args []string }
CreatePoolOptions are options for creating a new zpool.
type Dataset ¶
type Dataset struct { Properties Name string }
func NewDataset ¶
func NewDataset(name string, properties Properties) *Dataset
func (*Dataset) Atime ¶
Atime return the value of the "atime" property as a bool.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Available ¶
Available returns the value of the "free" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) CanMount ¶
CanMount return the value of the "canmount" property as a bool.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Checksum ¶
Checksum returns the value of the "checksum" property.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) CompressRatio ¶
CompressRatio returns the value of the "compressratio" property as a float64.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Compression ¶
Compression returns the value of the "compression" property.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Copies ¶
Copies returns the value of the "copies" property as a uint64.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Creation ¶
Creation returns the value of the "creation" property as a time.Time.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Devices ¶
Devices return the value of the "devices" property as a bool.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Exec ¶
Exec returns the value of the "exec" property as a bool.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) LogicalReferenced ¶
LogicalReferenced returns the value of the "logicalreferenced" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) LogicalUsed ¶
LogicalUsed returns the value of the "logicalused" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Mountpoint ¶
Mountpoint returns the value of the "mountpoint" property.
The second return value indicates if the property is present in the Dataset instance. If the raw mountpoint value is "none", an empty string will be returned instead of "none".
func (*Dataset) Quota ¶
Quota returns the value of the "quota" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) ReadOnly ¶
ReadOnly returns the value of the "readonly" property as a bool.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) RefCompressRatio ¶
RefCompressRatio returns the value of the "refcompressratio" property as a float64.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) RefQuota ¶
RefQuota returns the value of the "refquota" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) RefReservation ¶
RefReservation returns the value of the "refreservation" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) RelAtime ¶
RelAtime returns the value of the "relatime" property as a bool.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Reservation ¶
Reservation returns the value of the "reservation" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) SetUID ¶
SetUID sets the value of the "setuid" property as a bool.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Sync ¶
Sync returns the value of the "sync" property.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Type ¶
func (p *Dataset) Type() (DatasetType, bool)
Type returns the value of the "type" property as a DatasetType.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) Used ¶
Used returns the value of the "used" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) UsedByChildren ¶
UsedByChildren returns the value of the "usedbychildren" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) UsedByDataset ¶
UsedByDataset returns the value of the "usedbydataset" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) UsedByRefReservation ¶
UsedByRefreservation returns the value of the "usedbyrefreservation" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
func (*Dataset) UsedBySnapshots ¶
UsedBySnapshots returns the value of the "usedbysnapshots" property as number of bytes.
The second return value indicates if the property is present in the Dataset instance.
type DatasetType ¶
type DatasetType string
const ( AllTypes DatasetType = "all" BookmarkType DatasetType = "bookmark" FilesystemType DatasetType = "filesystem" SnapshotType DatasetType = "snapshot" VolumeType DatasetType = "volume" )
func JoinTypes ¶
func JoinTypes(types ...DatasetType) DatasetType
JoinTypes combines the given dataset types into a DatasetType value which can be used to query for datasets of multiple types.
type DestroyDatasetFlag ¶
type DestroyDatasetFlag int
DestroyDatasetFlag is a value that is passed to DestroyDataset to specify the destruction behavior for datasets.
const ( // DestroyRecursive indicates that the -r flag should be passed to zfs // destroy. // // When destroying filesystems and volumes: // // Recursively destroy all children. // // When destroying snapshots: // // Destroy (or mark for deferred deletion) all snapshots with this name // in descendent file systems. DestroyRecursive DestroyDatasetFlag = iota + 1 // DestroyRecursiveClones indicates that the -R flag should be passed to zfs // destroy. // // When destroying filesystems and volumes: // // Recursively destroy all dependents, including cloned file systems // outside the target hierarchy. // // When destroying snapshots: // // Recursively destroy all clones of these snapshots, including the // clones, snapshots, and children. If this flag is specified, // DestroyDeferDeletion will have no effect. DestroyRecursiveClones // DestroyDeferDeletion indicates that the -d flag should be passed to zfs // destroy. // // Destroy immediately. If a snapshot cannot be destroyed now, mark // it for deferred destruction. // // Only valid when destroying snapshots. DestroyDeferDeletion // DestroyForceUnmount indicates that the -f flag should be passed to zfs // destroy. // // Force an unmount of any file systems using the unmount -f command. This // option has no effect on non-filesystems or unmounted filesystems. DestroyForceUnmount )
type ImportPoolOptions ¶
type ImportPoolOptions struct { // Name of the pool to import. Name string // Properties is a map of properties (-o) to set on the pool. Properties map[string]string // Force indicates whether to force flag (-f) should be set. Force bool // Args is a list of additional arguments to pass to zpool import. Args []string // DirOrDevice is a list of directories or devices, each passed with the -d // flag to zpool import. DirOrDevice []string }
ImportPoolOptions are options for importing a pool.
type Manager ¶
type Manager struct {
Runner runner.Runner
}
Manager is used to perform all zfs and zpool operations.
A runner.Runner is used to execute all commands. You can use a custom runner to modify the behavior of the executed commands. The runner package for example provides a "Sudo" runner struct that executes all commands via sudo.
func New ¶
func New() *Manager
New returns a new Manager instance which is used to perform all zfs and zpool operations.
The default Runner assigned will execute all zfs and zpool commands on the local host machine, without sudo. As zfs operations typically need to be performed as root, you most likely need to run the Go application as root, or use a runner.Sudo instance to execute zfs and zpool commands via sudo.
func (*Manager) CreateDataset ¶
func (m *Manager) CreateDataset( ctx context.Context, options *CreateDatasetOptions, ) error
CreateDataset creates a new dataset with the given options.
func (*Manager) CreatePool ¶
func (m *Manager) CreatePool( ctx context.Context, options *CreatePoolOptions, ) error
CreatePool create a new pool with the given options.
func (*Manager) DestroyDataset ¶
func (m *Manager) DestroyDataset( ctx context.Context, name string, flags ...DestroyDatasetFlag, ) error
DestroyDataset destroys the named dataset.
func (*Manager) DestroyPool ¶
DestroyPool destroys the named pool, optionally passing the force flag (-f) to zpool destroy.
func (*Manager) ExportPool ¶
ExportPool exports the named pool, optionally passing the force flag (-f) to zpool export.
func (*Manager) GetDataset ¶
func (m *Manager) GetDataset( ctx context.Context, name string, properties ...string, ) (*Dataset, error)
GetDataset returns a *Dataset instance for named dataset.
If properties are specified, only those properties are returned for the dataset, otherwise all properties are returned.
func (*Manager) GetDatasetProperty ¶
func (m *Manager) GetDatasetProperty( ctx context.Context, name string, property string, ) (string, error)
GetDatasetProperty returns the value of the given property for the given dataset.
func (*Manager) GetPool ¶
GetPool returns a *Pool instance for named pool.
If properties are specified, only those properties are returned for the pool, otherwise all properties are returned.
func (*Manager) GetPoolProperty ¶
func (m *Manager) GetPoolProperty( ctx context.Context, name string, property string, ) (string, error)
GetProperty returns the value of property on zpool with name.
func (*Manager) ImportPool ¶
func (m *Manager) ImportPool( ctx context.Context, options *ImportPoolOptions, ) error
ImportPool imports the named pool based on the given options.
func (*Manager) InheritDatasetProperty ¶
func (m *Manager) InheritDatasetProperty( ctx context.Context, name string, property string, recursive bool, ) error
InheritDatasetProperty sets property to inherit from parent dataset.
func (*Manager) ListDatasetNames ¶
func (m *Manager) ListDatasetNames( ctx context.Context, filter string, depth uint64, typ DatasetType, ) ([]string, error)
ListDatasetNames returns a string slice of dataset names matching the given arguments.
func (*Manager) ListDatasets ¶
func (m *Manager) ListDatasets( ctx context.Context, filter string, depth uint64, typ DatasetType, properties ...string, ) ([]*Dataset, error)
ListDatasets returns a slice of *Dataset instances based on the given arguments.
If properties are specified, only those properties are returned for each dataset, otherwise all properties are returned.
func (*Manager) ListPoolNames ¶
ListPoolNames returns a string slice of all pool names.
func (*Manager) ListPools ¶
ListPools returns a slice of *Pool instances for all pools.
If properties are specified, only those properties are returned for each pool, otherwise all properties are returned.
func (*Manager) SetDatasetProperties ¶
func (m *Manager) SetDatasetProperties( ctx context.Context, name string, properties map[string]string, ) error
SetDatasetProperties sets given properties on dataset with name.
func (*Manager) SetDatasetProperty ¶
func (m *Manager) SetDatasetProperty( ctx context.Context, name string, property string, value string, ) error
SetDatasetProperty sets property to value on dataset with name.
type Pool ¶
type Pool struct { // Name of the pool. Name string // Properties of the pool. Properties }
func (*Pool) Allocated ¶
Allocated returns the value of the "allocated" property as number of bytes.
The second return value indicates if the property is present in the Pool instance.
func (*Pool) Capacity ¶
Capacity returns the value of the "capacity" property as number of bytes.
The second return value indicates if the property is present in the Pool instance.
func (*Pool) Fragmentation ¶
Fragmentation returns the value of the "fragmentation" property as number of bytes.
The second return value indicates if the property is present in the Pool instance.
func (*Pool) Free ¶
Free returns the value of the "free" property as number of bytes.
The second return value indicates if the property is present in the Pool instance.
func (*Pool) Freeing ¶
Freeing returns the value of the "freeing" property as number of bytes.
The second return value indicates if the property is present in the Pool instance.
func (*Pool) Health ¶
Health returns the value of the "health" property.
The second return value indicates if the property is present in the Pool instance.
func (*Pool) Leaked ¶
Leaked returns the value of the "leaked" property as number of bytes.
The second return value indicates if the property is present in the Pool instance.
type Properties ¶
Properties is a collection of ZFS properties, that includes typed accessor helper methods.
func (Properties) Bool ¶
func (p Properties) Bool(property string) (bool, bool)
Bool returns the value of the given property as a bool. Only "on" and "enabled" are considered true, all other value return false.
The second return value indicates if the property is present and could successfully be parsed.
func (Properties) Bytes ¶
func (p Properties) Bytes(property string) (uint64, bool)
Bytes returns the value of the given property as number of bytes.
The second return value indicates if the property is present and could successfully be parsed.
func (Properties) Percent ¶
func (p Properties) Percent(property string) (uint64, bool)
Percent returns the value of the given property as a uint64. It will strip any trailing "%" before parsing it as a uint64, ensuring it can handle percent-based values like "1%" and "42%".
The second return value indicates if the property is present and could successfully be parsed.
func (Properties) Ratio ¶
func (p Properties) Ratio(property string) (float64, bool)
Ratio returns the value of the given property as a float64. It will strip any trailing "x" before parsing it as a float64, ensuring it can handle ratio-based values like "1x" and "0.5x".
The second return value indicates if the property is present and could successfully be parsed.
func (Properties) String ¶
func (p Properties) String(property string) (string, bool)
String returns the value of the given property.
The second return value indicates if the property is present and could successfully be parsed.
func (Properties) Time ¶
func (p Properties) Time(property string) (time.Time, bool)
Time returns the value of the given property as a time.Time. It can handle both unix timestamp values from ZFS (-p flag) and human readable time values.
The second return value indicates if the property is present and could successfully be parsed.
type Property ¶
type Property struct { // Name is the name of the ZFS pool/dataset that the property belongs to. Name string // Property is the name of the property itself. Property string // Value is the value of the property. Value string // Source is the source of the property. Source string }
Property represents a single ZFS property.
Directories ¶
Path | Synopsis |
---|---|
Package zfsprops is a helper package that privides a list of string constants for zfs native properties.
|
Package zfsprops is a helper package that privides a list of string constants for zfs native properties. |
Package zpoolprops is a helper package that privides a list of string constants for zpool properties.
|
Package zpoolprops is a helper package that privides a list of string constants for zpool properties. |