Documentation ¶
Overview ¶
Package disko - disk operations
Index ¶
- Constants
- func GUIDToString(bguid GUID) string
- type AttachmentType
- type Disk
- type DiskFilter
- type DiskSet
- type DiskType
- type FreeSpace
- type GUID
- type LV
- type LVFilter
- type LVSet
- type LVType
- type PV
- type PVFilter
- type PVSet
- type PartType
- type Partition
- type PartitionSet
- type Property
- type PropertySet
- type System
- type TableType
- type UdevInfo
- type VG
- type VGFilter
- type VGSet
- type VolumeManager
Constants ¶
const ExtentSize = 4 * Mebibyte
ExtentSize is extent size for lvm
const Mebibyte uint64 = 1024 * 1024
Mebibyte defines 1MiB
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AttachmentType ¶
type AttachmentType int
AttachmentType enumerates the type of device to which the disks are attached to in the system.
const ( // UnknownAttach - indicates an unknown attachment. UnknownAttach AttachmentType = iota // RAID - indicates that the device is attached to RAID card RAID // SCSI - indicates device is attached to scsi, but not a RAID card. SCSI // ATA - indicates that the device is attached to ATA card ATA // PCIE - indicates that the device is attached to PCIE card PCIE // USB - indicates that the device is attached to USB bus USB // VIRTIO - indicates that the device is attached to virtio. VIRTIO // IDE - indicates that the device is attached to IDE. IDE // NBD - a network block device (/dev/nbd0) NBD // LOOP - a loop device (/dev/loop0) LOOP // XENBUS - xen blkfront XENBUS // FILESYSTEM - a file on a filesystem. FILESYSTEM )
func StringToAttachmentType ¶
func StringToAttachmentType(atypeStr string) AttachmentType
StringToAttachmentType - Convert a string to an AttachmentType
func (AttachmentType) MarshalJSON ¶
func (t AttachmentType) MarshalJSON() ([]byte, error)
MarshalJSON - Custom to marshal as a string.
func (AttachmentType) String ¶
func (t AttachmentType) String() string
func (*AttachmentType) UnmarshalJSON ¶
func (t *AttachmentType) UnmarshalJSON(b []byte) error
UnmarshalJSON - reverse of the custom marshler
type Disk ¶
type Disk struct { // Name is the kernel name of the disk. Name string `json:"name"` // Path is the device path of the disk. Path string `json:"path"` // Size is the size of the disk in bytes. Size uint64 `json:"size"` // SectorSize is the sector size of the device, if its unknown or not // applicable it will return 0. SectorSize uint `json:"sectorSize"` // ReadOnly - cannot be written to. ReadOnly bool `json:"read-only"` // Type is the DiskType indicating the type of this disk. This value // can be used to determine if the disk is of a particular media type like // HDD, SSD or NVMe. Type DiskType `json:"type"` // Attachment is the type of storage card this disk is attached to. // For example: RAID, ATA or PCIE. Attachment AttachmentType `json:"attachment"` // Partitions is the set of partitions on this disk. Partitions PartitionSet `json:"partitions"` // TableType is the type of the table Table TableType `json:"table"` // Properties are a set of properties of this disk. Properties PropertySet `json:"properties"` // UdevInfo is the disk's udev information. UdevInfo UdevInfo `json:"udevInfo"` }
Disk wraps the disk level operations. It provides basic information about the disk including name, device path, size etc.
func (*Disk) FreeSpaces ¶
FreeSpaces returns a list of slots of free spaces on the disk. These slots can be used to create new partitions.
func (*Disk) FreeSpacesWithMin ¶
FreeSpacesWithMin returns a list of freespaces that are minSize long or more.
type DiskFilter ¶
DiskFilter is filter function that returns true if the matching disk is accepted false otherwise.
type DiskType ¶
type DiskType int
DiskType enumerates supported disk types.
func StringToDiskType ¶
StringToDiskType - convert a string to a disk type.
func (DiskType) MarshalJSON ¶
MarshalJSON - Custom to marshal as a string.
func (*DiskType) UnmarshalJSON ¶
UnmarshalJSON - custom to read as string or int.
type FreeSpace ¶
FreeSpace indicates a free slot on the disk with a Start and Last offset, where a partition can be created.
type GUID ¶
type GUID [16]byte
GUID - a 16 byte Globally Unique ID
func StringToGUID ¶
StringToGUID - convert a string to a GUID
type LV ¶
type LV struct { // Name is the name of the logical volume. Name string `json:"name"` // UUID for the LV UUID string `json:"uuid"` // Path is the full path of the logical volume. Path string `json:"path"` // Size the size of the logical volume. Size uint64 `json:"size"` // Type is the type of logical volume. Type LVType `json:"type"` // The volume group that this logical volume is part of. VGName string `json:"vgname"` // Encrypted indicates if the logical volume is encrypted. Encrypted bool `json:"encrypted"` // DecryptedLVName is the name of the decrypted logical volume as set by // the CryptOpen call. DecryptedLVName string `json:"decryptedLVName"` // DecryptedLVPath is the full path of the decrypted logical volume. This // is set only for encrypted volumes, using the CryptFormat. DecryptedLVPath string `json:"decryptedLVPath"` }
LV interface wraps the lvm logical volume information and operations. A logical volume partitions a volume group into a slice of capacity that can be used a block device to create a file system.
type LVFilter ¶
LVFilter is filter function that returns true if the matching lv is accepted false otherwise.
type LVType ¶
type LVType int
LVType defines the type of the logical volume.
func (LVType) MarshalJSON ¶
MarshalJSON - serialize to json
func (*LVType) UnmarshalJSON ¶
UnmarshalJSON - custom to read as strings or int
type PV ¶
type PV struct { // Name returns the name of the PV. Name string `json:"name"` // UUID for the PV UUID string `json:"uuid"` // Path returns the device path of the PV. Path string `json:"path"` // Size returns the size of the PV. Size uint64 `json:"size"` // The volume group this PV is part of ("" if none) VGName string `json:"vgname"` // FreeSize returns the free size of the PV. FreeSize uint64 `json:"freeSize"` }
PV wraps a LVM physical volume. A lvm physical volume is the raw block device or other disk like devices that provide storage capacity.
type PVFilter ¶
PVFilter is filter function that returns true if the matching pv is accepted false otherwise.
type PartType ¶
type PartType GUID
PartType represents a GPT Partition GUID
func StringToPartType ¶
StringToPartType - convert a string to a partition type.
type Partition ¶
type Partition struct { // Start is the offset in bytes of the start of this partition. Start uint64 `json:"start"` // Last is the last byte that is part of this partition. Last uint64 `json:"last"` // ID is the partition id. ID GUID `json:"id"` // Type is the partition type. Type PartType `json:"type"` // Name is the name of this partition. Name string `json:"name"` // Number is the number of this partition. Number uint `json:"number"` }
Partition wraps the disk partition information.
func (Partition) MarshalJSON ¶
MarshalJSON - serialize to json
func (*Partition) UnmarshalJSON ¶
UnmarshalJSON - unserialize from json
type PartitionSet ¶
PartitionSet is a map of partition number to the partition.
type Property ¶
type Property string
Property - a property of a disk such
const ( // Ephemeral - A cloud ephemeral disk. Ephemeral Property = "EPHEMERAL" )
type PropertySet ¶
PropertySet - a group of properties of a disk
func (PropertySet) MarshalJSON ¶
func (p PropertySet) MarshalJSON() ([]byte, error)
MarshalJSON - serialize to json
func (PropertySet) String ¶
func (p PropertySet) String() string
func (*PropertySet) UnmarshalJSON ¶
func (p *PropertySet) UnmarshalJSON(b []byte) error
UnmarshalJSON - json unserialize
type System ¶
type System interface { // ScanAllDisks scans the system for all available disks and returns a // set of disks that are accepted by the filter function. Use this function // if you dont know the device paths for the specific disks to be scanned. ScanAllDisks(filter DiskFilter) (DiskSet, error) // ScanDisks scans the system for disks identified by the specified paths // and returns a set of disks that are accepted by the filter function. ScanDisks(filter DiskFilter, paths ...string) (DiskSet, error) // ScanDisk scans the system for a single disk specified by the device path. ScanDisk(path string) (Disk, error) // CreatePartition creates a partition on the is disk with the specified // partition number, type and disk offsets. CreatePartition(Disk, Partition) error // CreatePartitions creates multiple partitions on disk. CreatePartitions(Disk, PartitionSet) error // UpdatePartition updates multiple existing partitions on a disk. UpdatePartition(Disk, Partition) error // UpdatePartitions updates multiple existing partitions on a disk. UpdatePartitions(Disk, PartitionSet) error // DeletePartition deletes the specified partition. DeletePartition(Disk, uint) error // Wipe wipes the disk to make it a clean disk. All partitions and data // on the disk will be lost. Wipe(Disk) error }
System interface provides system level disk and lvm methods that are implemented by the specific system.
type TableType ¶
type TableType int
TableType enumerates the type of device to which the disks are attached to in the system.
func StringToTableType ¶
StringToTableType - Convert a string to an TableType
func (TableType) MarshalJSON ¶
MarshalJSON - Custom to marshal as a string.
func (*TableType) UnmarshalJSON ¶
UnmarshalJSON - reverse of the custom marshler
type UdevInfo ¶
type UdevInfo struct { // Name of the disk Name string `json:"name"` // SysPath is the system path of this device. SysPath string `json:"sysPath"` // Symlinks for the disk. Symlinks []string `json:"symLinks"` // Properties is udev information as a map of key, value pairs. Properties map[string]string `json:"properties"` }
UdevInfo captures the udev information about a disk.
type VG ¶
type VG struct { // Name is the name of the volume group. Name string `json:"name"` // UUID for the VG UUID string `json:"uuid"` // Size is the current size of the volume group. Size uint64 `json:"size"` // Volumes is set of all the volumes in this volume group. Volumes LVSet `json:"volumes"` // FreeSpace is the amount free space left in the volume group. FreeSpace uint64 `json:"freeSpace"` // PVs is the set of PVs that belongs to this VG. PVs PVSet `json:"pvs"` }
VG wraps a LVM volume group. A volume group combines one or more physical volumes into storage pools and provides a unified logical device with combined storage capacity of the underlying physical volumes.
type VGFilter ¶
VGFilter is filter function that returns true if the matching vg is accepted false otherwise.
type VolumeManager ¶
type VolumeManager interface { // ScanPVs scans the system for all the PVs and returns the set of PVs that // are accepted by the filter function. ScanPVs(filter PVFilter) (PVSet, error) // ScanVGs scans the systems for all the VGs and returns the set of VGs that // are accepted by the filter function. ScanVGs(filter VGFilter) (VGSet, error) // CreatePV creates a PV with specified name. CreatePV(diskName string) (PV, error) // DeletePV deletes the specified PV. DeletePV(pv PV) error // HasPV returns true if the pv exists. This indicates that the device // already has an lvm pv header. HasPV(name string) bool // CreateVG creates a VG with specified name and adds the provided pvs to // this vg. CreateVG(name string, pvs ...PV) (VG, error) // ExtendVG extends the volument group storage capacity with the specified // PVs. ExtendVG(vgName string, pvs ...PV) error // Delete deletes this VG and all the LVs in the VG. RemoveVG(vgName string) error // HasVG returns true if the vg exists. HasVG(vgName string) bool // CryptFormat setups up encryption for this volume using the provided key. CryptFormat(vgName string, lvName string, key string) error // CryptOpen opens the encrypted logical volume for use using the provided // key. CryptOpen(vgName string, lvName string, decryptedName string, key string) error // CryptClose close the encrypted logical volume using the provided key. CryptClose(vgName string, lvName string, decryptedName string) error // CreateLV creates a LV with specified name, size and type. CreateLV(vgName string, name string, size uint64, lvType LVType) (LV, error) // RemoveLV removes this LV. RemoveLV(vgName string, lvName string) error // RenameLV renames this LV to newLvName. RenameLV(vgName string, lvName string, newLvName string) error // ExtendLV expands the LV to the requested new size. ExtendLV(vgName string, lvName string, newSize uint64) error // HasVG returns true if the lv exists. HasLV(vgName string, name string) bool }
VolumeManager provides logical volume oprations that allows for creation and management of volume groups, physical volumes and logical volumes.