ioctl

package
v0.0.0-...-3df88f3 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package ioctl provides a pure-Go low-level wrapper around ZFS's ioctl interface and basic wrappers around common ioctls to make them usable from normal Go code.

Index

Constants

View Source
const (
	//	Per-platform (Optional) - 8/128 numbers reserved.
	ZFS_IOC_PLATFORM     = ZFS_IOC_FIRST + 0x80 + iota
	ZFS_IOC_EVENTS_NEXT  // 0x81 (Linux)
	ZFS_IOC_EVENTS_CLEAR // 0x82 (Linux)
	ZFS_IOC_EVENTS_SEEK  // 0x83 (Linux)
	ZFS_IOC_NEXTBOOT     // 0x84 (FreeBSD)
	ZFS_IOC_JAIL         // 0x85 (FreeBSD)
	ZFS_IOC_UNJAIL       // 0x86 (FreeBSD)
	ZFS_IOC_SET_BOOTENV  // 0x87
	ZFS_IOC_GET_BOOTENV  // 0x88
	ZFS_IOC_LAST
)
View Source
const (
	StateUnknown = iota
	StateClosed
	StateOffline
	StateRemoved
	StateCantOpen
	StateFaulted
	StateDegraded
	StateHealthy
)
View Source
const (
	FailWait = iota
	FailContinue
	FailPanic
)
View Source
const (
	ObjectTypeNone = ObjectType(iota)
	ObjectTypeMeta
	ObjectTypeZFS
	ObjectTypeZvol
	ObjectTypeOther
	ObjectTypeAny
	ObjectTypeNumtypes
)
View Source
const (
	ErrorPropClearFailed   = 0x01
	ErrorPropRestoreFailed = 0x02
)

Variables

This section is empty.

Functions

func Bookmark

func Bookmark(snapshotsToBookmarks map[string]string) error

Bookmark creates ZFS bookmarks from snapshots. These are only available on ZoL 0.7+ and currently only used for resumable send/receive, but will eventually be usable as a reference for incremental sends.

func Clone

func Clone(origin string, name string, props *DatasetProps) error

Clone creates a new writable ZFS dataset from the given origin snapshot

func Create

func Create(name string, t ObjectType, props *DatasetProps) error

Create creates a new ZFS dataset

func DatasetListNext

func DatasetListNext(name string, cursor uint64) (string, uint64, DMUObjectSetStats, DatasetPropsWithSource, error)

DatasetListNext lists ZFS datsets under the dataset or zpool given by name. It only returns one dataset and a cursor which can be used to get the next dataset in the list. The cursor value for the first element is 0.

func Destroy

func Destroy(name string, t ObjectType, deferred bool) error

Destroy removes dataset irrevocably. If the deferred flag is given, the function will terminate and the actuall removal will be processed asynchronously.

func DestroySnapshots

func DestroySnapshots(names []string, pool string, defer_ bool) error

DestroySnapshots removes multiple snapshots in the same pool. By setting the defer option the operation will be executed in the background after the function has returned.

func GetSpaceWritten

func GetSpaceWritten(dataset, snapshot string) (uint64, error)

GetSpaceWritten returns the amount of bytes written into a dataset since the given snapshot was taken. Also useful for determining if anything has changed in dataset since the snaphsot was taken.

func InheritProp

func InheritProp(name string, propName string, revertToReceived bool) error

InheritProp makes a prop inherit from its parent or reverts it to the received prop which is being shadowed by a local prop (see PropSource).

func Init

func Init(nodePath string) error

Init optionally creates and opens a ZFS handle, by default at "/dev/zfs", overridable by nodePath

func NvlistIoctl

func NvlistIoctl(fd uintptr, ioctl Ioctl, name string, cmd *Cmd, request interface{}, response interface{}, config interface{}) error

NvlistIoctl issues a low-level ioctl syscall with only some common wrappers. All unsafety is contained in here.

func ObjsetZPLProps

func ObjsetZPLProps(name string) (props interface{}, err error)

ObjsetZPLProps gets all object set props

func PauseScan

func PauseScan(pool string) error

PauseScan pauses an active resilver or scrub operation.

func PoolConfigs

func PoolConfigs() (map[string]interface{}, error)

PoolConfigs gets all pool configs

func PoolCreate

func PoolCreate(name string, features map[string]uint64, config VDev) error

PoolCreate creates a new zpool with the given name, featues and devices

func PoolDestroy

func PoolDestroy(name string) error

PoolDestroy removes a zpool completely

func PoolExport

func PoolExport(name string, force, hardForce bool) error

PoolExport exports a pool

func PoolGetProps

func PoolGetProps(name string) (props interface{}, err error)

PoolGetProps gets all props for a zpool

func PoolImport

func PoolImport(name string, config map[string]interface{}, props map[string]interface{}) (map[string]interface{}, error)

PoolImport imports a pool

func PoolStats

func PoolStats(name string) (map[string]interface{}, error)

PoolStats gets statistics from a pool

func Promote

func Promote(name string) (conflictingSnapshot string, err error)

Promote replaces a ZFS filesystem with a clone of itself.

func RegenerateGUID

func RegenerateGUID(pool string) error

RegenerateGUID assigns a new GUID to the pool. Since this operation needs to write to all devices the pool cannot be degraded or have missing devices.

func Rename

func Rename(oldName, newName string, recursive bool) error

Rename renames a dataset

func Rollback

func Rollback(name string, target string) (actualTarget string, err error)

Rollback rolls back a ZFS dataset to a snapshot taken earlier

func Send

func Send(name string, options SendOptions) (io.ReadCloser, error)

Send generates a stream containing either a full or an incremental snapshot. This function provides some basic convenience wrappers including a fail-fast mode which returns an error directly if it happens before a single byte is sent out and a Read-compatible output stream.

func SendSpace

func SendSpace(name string, options SendSpaceOptions) (uint64, error)

SendSpace determines approximately how big a ZFS send stream will be

func SetProp

func SetProp(name string, props map[string]interface{}, source PropSource) error

SetProp sets one or more props on a ZFS dataset.

func Snapshot

func Snapshot(names []string, pool string, props *DatasetProps) error

Snapshot creates one or more snapshots of datasets on the same zpool. The names are in standard ZFS syntax (dataset/subdataset@snapname).

func StartStopScan

func StartStopScan(pool string, t ScanType) error

StartStopScan starts or stops a scrub or resilver operation. If the ScanType is set to ScanType none, it will stop an active resilver or scrub operation, ScanTypeScrub and ScanTypeResilver will resume or start a new operation (start is not supported for resilver)

Types

type ACLInheritancePolicy

type ACLInheritancePolicy uint64

type CanMount

type CanMount uint64

type Cmd

type Cmd struct {
	Name              [4096]byte
	Nvlist_src        uint64
	Nvlist_src_size   uint64
	Nvlist_dst        uint64
	Nvlist_dst_size   uint64
	Nvlist_dst_filled bool
	Pad_cgo_0         [3]byte
	Pad2              int32
	History           uint64
	Value             [8192]byte
	String            [256]byte
	Guid              uint64
	Nvlist_conf       uint64
	Nvlist_conf_size  uint64
	Cookie            uint64
	Objset_type       uint64
	Perm_action       uint64
	History_len       uint64
	History_offset    uint64
	Obj               uint64
	Iflags            uint64
	Share             Share
	Objset_stats      DMUObjectSetStats
	Begin_record      DRRBegin
	Inject_record     ZInjectRecord
	Defer_destroy     uint32
	Flags             uint32
	Action_handle     uint64
	Cleanup_fd        int32
	Simple            uint8
	Pad               [3]uint8
	Sendobj           uint64
	Fromobj           uint64
	Createtxg         uint64
	Stat              Stat
}

Cmd is the main data exchange struct for all ZFS ioctl()s aside from nvlists. Mostly generated by godefs.

type DMUObjectSetStats

type DMUObjectSetStats struct {
	Num_clones   uint64
	Creation_txg uint64
	Guid         uint64
	Type         uint32
	Is_snapshot  uint8
	Inconsistent uint8
	Origin       [256]byte
	Pad_cgo_0    [2]byte
}

func SnapshotListNext

func SnapshotListNext(name string, cursor uint64, props interface{}) (string, uint64, DMUObjectSetStats, error)

SnapshotListNext lists ZFS snapshots under the dataset or zpool given by name. It works similar to DatsetListNext

type DNodeSize

type DNodeSize uint64

type DRRBegin

type DRRBegin struct {
	Magic         uint64
	Versioninfo   uint64
	Creation_time uint64
	Type          uint32
	Flags         uint32
	Toguid        uint64
	Fromguid      uint64
	Toname        [255]int8
	Pad_cgo_0     [1]byte
}

type DatasetProps

type DatasetProps map[string]interface{}

DatasetProps contains all normal props for a dataset

type DatasetPropsWithSource

type DatasetPropsWithSource map[string]PropWithSource

func ObjsetStats

func ObjsetStats(name string) (props DatasetPropsWithSource, err error)

ObjsetStats gets statistics on object sets

type FailMode

type FailMode uint64

type FilesystemProps

type FilesystemProps struct {
	SnapshotDirectoryEnabled bool                 `nvlist:"snapdir,asuint64"`
	ACLInheritancePolicy     ACLInheritancePolicy `nvlist:"aclinherit,omitempty,default=4"`
	DNodeSize                DNodeSize            `nvlist:"dnodesize,omitempty"`
	Atime                    bool                 `nvlist:"atime,default=true"`
	RelativeAtime            bool                 `nvlist:"relatime"`

	// All props below do nothing here
	Zoned     bool     `nvlist:"zoned"`
	VirusScan bool     `nvlist:"vscan"`
	Overlay   bool     `nvlist:"overlay"`
	CanMount  CanMount `nvlist:"canmount,default=true"`
	Mounted   bool     `nvlist:"mounted"`

	Mountpoint string `nvlist:"mountpoint"`
}

type Ioctl

type Ioctl uint32
const (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_HOLDS
	ZFS_IOC_OBJSET_RECVD_PROPS
	ZFS_IOC_VDEV_SPLIT
	ZFS_IOC_NEXT_OBJ
	ZFS_IOC_DIFF
	ZFS_IOC_TMP_SNAPSHOT
	ZFS_IOC_OBJ_TO_STATS
	ZFS_IOC_SPACE_WRITTEN
	ZFS_IOC_SPACE_SNAPS
	ZFS_IOC_DESTROY_SNAPS
	ZFS_IOC_POOL_REGUID
	ZFS_IOC_POOL_REOPEN
	ZFS_IOC_SEND_PROGRESS
	ZFS_IOC_LOG_HISTORY
	ZFS_IOC_SEND_NEW
	ZFS_IOC_SEND_SPACE
	ZFS_IOC_CLONE
	ZFS_IOC_BOOKMARK
	ZFS_IOC_GET_BOOKMARKS
	ZFS_IOC_DESTROY_BOOKMARKS
	ZFS_IOC_RECV_NEW
	ZFS_IOC_POOL_SYNC
)
const ZFS_IOC_FIRST Ioctl = 'Z' << 8

type ObjectType

type ObjectType int32

type PoolConfig

type PoolConfig struct {
	Version          uint64 `nvlist:"version,omitempty"`
	Name             string `nvlist:"name,omitempty"`
	State            uint64 `nvlist:"state,omitempty"`
	TXG              uint64 `nvlist:"txg,omitempty"`
	GUID             uint64 `nvlist:"pool_guid,omitempty"`
	Errata           uint64 `nvlist:"errata,omitempty"`
	Hostname         string `nvlist:"hostname,omitempty"`
	NumberOfChildren uint64 `nvlist:"vdev_children"`
	VDevTree         *VDev  `nvlist:"vdev_tree"`
	HostID           uint64 `nvlist:"hostid,omitempty"`
	// Delta: -hostid, +top_guid, +guid, +features_for_read
	FeaturesForRead map[string]bool `nvlist:"features_for_read"`
}

type PoolProps

type PoolProps struct {
	Name    string `nvlist:"name,omitempty"`
	Version uint64 `nvlist:"version,omitempty"`
	Comment string `nvlist:"comment,omitempty"`

	// Pool configuration
	AlternativeRoot string   `nvlist:"altroot,omitempty"`
	TemporaryName   string   `nvlist:"tname,omitempty"`
	BootFS          string   `nvlist:"bootfs,omitempty"`
	CacheFile       string   `nvlist:"cachefile,omitempty"`
	ReadOnly        bool     `nvlist:"readonly,omitempty"`
	Multihost       bool     `nvlist:"multihost,omitempty"`
	Failmode        FailMode `nvlist:"failmode,omitempty"`
	DedupDitto      uint64   `nvlist:"dedupditto,omitempty"`
	AlignmentShift  uint64   `nvlist:"ashift,omitempty"`
	Delegation      bool     `nvlist:"delegation,omitempty"`
	Autoreplace     bool     `nvlist:"autoreplace,omitempty"`
	ListSnapshots   bool     `nvlist:"listsnapshots,omitempty"`
	Autoexpand      bool     `nvlist:"autoexpand,omitempty"`
	MaxBlockSize    uint64   `nvlist:"maxblocksize,omitempty"`
	MaxDnodeSize    uint64   `nvlist:"maxdnodesize,omitempty"`

	// Defines props for the root volume for PoolCreate()
	RootProps *DatasetProps `nvlist:"root-props-nvl,omitempty"`

	// All user properties are represented here
	User map[string]string `nvlist:"-,extra,omitempty"`

	// Read-only information
	Size          uint64 `nvlist:"size,ro"`
	Free          uint64 `nvlist:"free,ro"`
	Freeing       uint64 `nvlist:"freeing,ro"`
	Leaked        uint64 `nvlist:"leaked,ro"`
	Allocated     uint64 `nvlist:"allocated,ro"`
	ExpandSize    uint64 `nvlist:"expandsize,ro"`
	Fragmentation uint64 `nvlist:"fragmentation,ro"`
	Capacity      uint64 `nvlist:"capacity,ro"`
	GUID          uint64 `nvlist:"guid,ro"`
	Health        State  `nvlist:"health,ro"`
	DedupRatio    uint64 `nvlist:"dedupratio,ro"`
}

PoolProps represents all properties of a zpool

type PropSource

type PropSource uint64

PropSource represents all possible sources for ZFS props

const (
	PropSourceNone PropSource = 1 << iota
	PropSourceDefault
	PropSourceTemporary
	PropSourceLocal
	PropSourceInherited
	PropSourceReceived
)

All possible values of PropSource

type PropWithSource

type PropWithSource struct {
	Value  interface{} `nvlist:"value"`
	Source string      `nvlist:"source"`
}

PropWithSource repesents a prop with source

type ReceiveError

type ReceiveError struct {
	ReadBytes  uint64           `nvlist:"read_bytes"`
	ErrorFlags uint64           `nvlist:"error_flags"`
	ErrorList  map[string]int32 `nvlist:"errors"`
}

func (ReceiveError) Error

func (e ReceiveError) Error() string

type ReceiveOpts

type ReceiveOpts struct {
	Origin        string        `nvlist:"origin,omitempty"`
	SnapshotName  string        `nvlist:"snapname"`
	ReceivedProps *DatasetProps `nvlist:"props"`
	LocalProps    *DatasetProps `nvlist:"localprops"`
	HiddenArgs    *struct{}     `nvlist:"hidden_args"` // TODO: Key material belongs here

	// Fd should generally not be set by the user, it bypasses all convenience features of Receive()
	// If it is set, BeginRecord also needs to be set to the first currently 312 bytes of the stream
	Fd          int32  `nvlist:"input_fd"`
	BeginRecord []byte `nvlist:"begin_record"`
	CleanupFd   int32  `nvlist:"cleanup_fd,omitempty"` // Operation gets aborted if this Fd is closed

	// The following are options
	Force     bool `nvlist:"force"`
	Resumable bool `nvlist:"resumable"`
}

ReceiveOpts represents all options for the Receive() call

type ReceiveStream

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

func Receive

func Receive(name string, opts ReceiveOpts) (*ReceiveStream, error)

Receive creates a snapshot from a stream generated by Send()

func (*ReceiveStream) WaitAndClose

func (r *ReceiveStream) WaitAndClose() error

WaitAndClose waits for receive process to complete, returns the result and closes everything

func (*ReceiveStream) Write

func (r *ReceiveStream) Write(buf []byte) (int, error)

Write writes data to the receive stream

type ScanType

type ScanType uint64

ScanType represents all possible scan-type operations (resilver or scrub)

const (
	// ScanTypeNone stops an ongoing scan-type operation
	ScanTypeNone ScanType = iota
	// ScanTypeScrub starts or resumes a scrub
	ScanTypeScrub
	// ScanTypeResilver resumes a paused resilver
	ScanTypeResilver
)

type SendOptions

type SendOptions struct {
	// Fd is writable file descriptor and should generally not be set. If it is set, all convenience
	// wrappers will be disabled and the Fd will be directly passed into the kernel.
	Fd int32 `nvlist:"fd"`

	// From can optionally contain an older snapshot for an incremental send
	From string `nvlist:"fromsnap,omitempty"`

	// FromBookmark can optionally contain a bookmark which is used to reduce the amount of data sent
	FromBookmark string `nvlist:"redactbook,omitempty"`

	// These enable individual features for the send stream
	LargeBlocks bool `nvlist:"largeblockok"`
	// Allows DRR_WRITE_EMBEDDED
	Embed bool `nvlist:"embedok"`
	// Allows compressed DRR_WRITE
	Compress bool `nvlist:"compress"`
	// Allows raw encrypted records
	Raw bool `nvlist:"rawok"`
	// Send a partially received snapshot
	Saved bool `nvlist:"savedok"`

	// These can optionally be set to resume a transfer (ZoL 0.7+)
	ResumeObject uint64 `nvlist:"resume_object,omitempty"`
	ResumeOffset uint64 `nvlist:"resume_offset,omitempty"`
}

SendOptions contains all options for the Send function.

type SendSpaceOptions

type SendSpaceOptions struct {
	// From can contain an older snapshot for an incremental transfer
	From string `nvlist:"from,omitempty"`
	// These enable individual features for transfer space estimation
	LargeBlocks bool `nvlist:"largeblockok"`
	Embed       bool `nvlist:"embedok"`
	Compress    bool `nvlist:"compressok"`
}

SendSpaceOptions contains all options for the SendSpace function

type Share

type Share struct {
	Exportdata uint64
	Sharedata  uint64
	Sharetype  uint64
	Sharemax   uint64
}

type Stat

type Stat struct {
	Gen   uint64
	Mode  uint64
	Links uint64
	Ctime [2]uint64
}

type State

type State uint64

type VDev

type VDev struct {
	IsLog               uint64 `nvlist:"is_log"`
	DTL                 uint64 `nvlist:"DTL,omitempty"`
	AlignmentShift      uint64 `nvlist:"ashift,omitempty"`
	AllocatableCapacity uint64 `nvlist:"asize,omitempty"`
	GUID                uint64 `nvlist:"guid,omitempty"`
	ID                  uint64 `nvlist:"id,omitempty"`
	Path                string `nvlist:"path"`
	Type                string `nvlist:"type"`
	Children            []VDev `nvlist:"children,omitempty"`
	L2CacheChildren     []VDev `nvlist:"l2cache,omitempty"`
	SparesChildren      []VDev `nvlist:"spares,omitempty"`
}

type VolumeProps

type VolumeProps struct {
}

type ZInjectRecord

type ZInjectRecord struct {
	Objset    uint64
	Object    uint64
	Start     uint64
	End       uint64
	Guid      uint64
	Level     uint32
	Error     uint32
	Type      uint64
	Freq      uint32
	Failfast  uint32
	Func      [255]int8
	Pad_cgo_0 [1]byte
	Iotype    uint32
	Duration  int32
	Timer     uint64
	Nlanes    uint64
	Cmd       uint32
	Pad       uint32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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