Documentation
¶
Overview ¶
Package disk provides utilities for disk operations.
Index ¶
- func DefaultDeviceTypeFunc(dt string) bool
- func DefaultExt4FsTypeFunc(fsType string) bool
- func DefaultFsTypeFunc(fsType string) bool
- func DefaultMatchFuncDeviceType(deviceType string) bool
- func DefaultMountPointFunc(mountPoint string) bool
- func DefaultNFSFsTypeFunc(fsType string) bool
- func FindFsTypeAndDeviceByMinorNumber(minor int) (string, string, error)
- func FindMntTargetDevice(dir string) (string, string, error)
- type BlockDevice
- type BlockDevices
- type CustomBool
- type CustomUint64
- type DeviceUsage
- type DeviceUsages
- type FindMntOutput
- type FlattenedBlockDevice
- type FlattenedBlockDevices
- type FoundMnt
- type MatchFunc
- type Op
- type OpOption
- type Partition
- type Partitions
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultDeviceTypeFunc ¶ added in v0.5.0
DefaultDeviceTypeFunc returns true for common block device types. This function is used by the disk component to filter which devices to monitor.
Supported device types:
- "disk": Physical disks (HDDs, SSDs, NVMe)
- "part": Disk partitions
- "lvm": Logical Volume Manager volumes
- "raid*": Software RAID devices (raid0, raid1, raid5, raid10, etc.)
- "md*": MD (multiple device) RAID arrays (md, md0, md127, etc.)
RAID/MD support was added to fix https://github.com/leptonai/gpud/issues/1107 where RAID devices containing the root filesystem were being filtered out, causing false "no block device found" warnings.
func DefaultExt4FsTypeFunc ¶ added in v0.5.0
func DefaultFsTypeFunc ¶ added in v0.5.0
DefaultFsTypeFunc returns true for common filesystem types. This function is used by the disk component to filter which filesystems to monitor.
Supported filesystem types:
- "": Empty/unformatted (parent disks)
- "ext4": Most common Linux filesystem
- "xfs": Default for RHEL 7+, CentOS 7+, Rocky Linux, AlmaLinux, Fedora Server
- "vfat": Required for EFI System Partitions (ESP) per UEFI specification
- "LVM2_member": LVM physical volumes
- "linux_raid_member": Software RAID members
- "raid0": RAID-0 devices
- "nfs*": Network File System (e.g., nfs, nfs4)
func DefaultMountPointFunc ¶ added in v0.6.0
func DefaultNFSFsTypeFunc ¶ added in v0.5.0
func FindFsTypeAndDeviceByMinorNumber ¶ added in v0.3.8
FindFsTypeAndDeviceByMinorNumber retrieves the filesystem type and device name for a given minor number. If not found, it returns empty strings.
Types ¶
type BlockDevice ¶
type BlockDevice struct {
Name string `json:"name,omitempty"`
ParentDeviceName string `json:"parent_device_name,omitempty"`
Type string `json:"type,omitempty"`
Size CustomUint64 `json:"size,omitempty"`
Rota CustomBool `json:"rota,omitempty"`
Serial string `json:"serial,omitempty"`
WWN string `json:"wwn,omitempty"`
Vendor string `json:"vendor,omitempty"`
Model string `json:"model,omitempty"`
Rev string `json:"rev,omitempty"`
MountPoint string `json:"mountpoint,omitempty"`
FSType string `json:"fstype,omitempty"`
FSUsed CustomUint64 `json:"fsused,omitempty"`
PartUUID string `json:"partuuid,omitempty"`
PKName string `json:"-"`
Children []BlockDevice `json:"children,omitempty"`
}
BlockDevice represents output of lsblk command for a device
type BlockDevices ¶
type BlockDevices []BlockDevice
func GetBlockDevicesWithLsblk ¶ added in v0.5.0
func GetBlockDevicesWithLsblk(ctx context.Context, opts ...OpOption) (BlockDevices, error)
GetBlockDevicesWithLsblk run "lsblk" command for device and construct BlockDevice struct based on output Receives device path. If device is empty string, info about all devices will be collected Returns slice of BlockDevice structs or error if something went wrong
func (BlockDevices) Flatten ¶ added in v0.5.0
func (blks BlockDevices) Flatten() FlattenedBlockDevices
func (BlockDevices) GetTotalBytes ¶
func (blks BlockDevices) GetTotalBytes() uint64
Returns the total bytes of all block devices.
func (BlockDevices) RenderTable ¶
func (blks BlockDevices) RenderTable(wr io.Writer)
type CustomBool ¶
type CustomBool struct {
Bool bool
}
CustomBool to handle Rota lsblk output - true/false or "1"/"0"
func (CustomBool) MarshalJSON ¶
func (cb CustomBool) MarshalJSON() ([]byte, error)
MarshalJSON customizes rota marshaling
func (*CustomBool) UnmarshalJSON ¶
func (cb *CustomBool) UnmarshalJSON(data []byte) error
UnmarshalJSON customizes string rota unmarshaling
type CustomUint64 ¶ added in v0.5.0
type CustomUint64 struct {
Uint64 uint64
}
CustomUint64 to handle Size lsblk output - 8001563222016 or "8001563222016"
func (*CustomUint64) MarshalJSON ¶ added in v0.5.0
func (ci *CustomUint64) MarshalJSON() ([]byte, error)
MarshalJSON customizes size marshaling
func (*CustomUint64) UnmarshalJSON ¶ added in v0.5.0
func (ci *CustomUint64) UnmarshalJSON(data []byte) error
UnmarshalJSON customizes string size unmarshaling "63.9M" should be parsed to 63.9 million (63900000)
type DeviceUsage ¶ added in v0.5.0
type DeviceUsage struct {
DeviceName string `json:"device_name,omitempty"`
MountPoint string `json:"mountpoint,omitempty"`
TotalBytes uint64 `json:"total_bytes"`
FreeBytes uint64 `json:"free_bytes"`
UsedBytes uint64 `json:"used_bytes"`
}
DeviceUsage is derived from the output of "lsblk" command, and the size and usage information based on its mount point
type DeviceUsages ¶ added in v0.5.0
type DeviceUsages []DeviceUsage
func (DeviceUsages) RenderTable ¶ added in v0.5.0
func (devs DeviceUsages) RenderTable(wr io.Writer)
type FindMntOutput ¶ added in v0.3.6
type FindMntOutput struct {
// The input mount target.
Target string `json:"target"`
Filesystems []FoundMnt `json:"filesystems"`
}
Represents the output of the command "findmnt --target /var/lib/kubelet --json --df". ref. https://man7.org/linux/man-pages/man8/findmnt.8.html
func FindMnt ¶ added in v0.3.6
func FindMnt(ctx context.Context, target string) (*FindMntOutput, error)
Runs "findmnt --target [TARGET] --json --df" and parses the output.
func ParseFindMntOutput ¶ added in v0.3.6
func ParseFindMntOutput(output string) (*FindMntOutput, error)
type FlattenedBlockDevice ¶ added in v0.5.0
type FlattenedBlockDevice struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Size uint64 `json:"size,omitempty"`
Rota bool `json:"rota,omitempty"`
Serial string `json:"serial,omitempty"`
WWN string `json:"wwn,omitempty"`
Vendor string `json:"vendor,omitempty"`
Model string `json:"model,omitempty"`
Rev string `json:"rev,omitempty"`
MountPoint string `json:"mountpoint,omitempty"`
FSType string `json:"fstype,omitempty"`
FSUsed uint64 `json:"fsused,omitempty"`
PartUUID string `json:"partuuid,omitempty"`
Parents []string `json:"parents,omitempty"`
Children []string `json:"children,omitempty"`
}
FlattenedBlockDevice represents the flattened output of lsblk command for a device, meaning the child device is included as its own entry in the device list.
type FlattenedBlockDevices ¶ added in v0.5.0
type FlattenedBlockDevices []FlattenedBlockDevice
func (FlattenedBlockDevices) GetDeviceUsages ¶ added in v0.5.0
func (blks FlattenedBlockDevices) GetDeviceUsages(parts Partitions) DeviceUsages
func (FlattenedBlockDevices) RenderTable ¶ added in v0.5.0
func (blks FlattenedBlockDevices) RenderTable(wr io.Writer)
type FoundMnt ¶ added in v0.3.6
type FoundMnt struct {
// Regardless of the input mount target, this is where the target is mounted.
MountedPoint string `json:"mounted_point"`
// The filesystem may use more block devices.
// This is why findmnt provides SOURCE and SOURCES (pl.) columns.
// ref. https://man7.org/linux/man-pages/man8/findmnt.8.html
Sources []string `json:"sources"`
Fstype string `json:"fstype"`
SizeHumanized string `json:"size_humanized"`
SizeBytes uint64 `json:"size_bytes"`
UsedHumanized string `json:"used_humanized"`
UsedBytes uint64 `json:"used_bytes"`
AvailableHumanized string `json:"available_humanized"`
AvailableBytes uint64 `json:"available_bytes"`
UsedPercentHumanized string `json:"used_percent_humanized"`
UsedPercent float64 `json:"used_percent"`
}
type OpOption ¶
type OpOption func(*Op)
func WithDeviceType ¶
func WithFstype ¶
func WithMountPoint ¶ added in v0.6.0
WithMountPoint is used to filter out devices. This is useful for filtering out devices that are not mounted, such as swap devices.
func WithSkipUsage ¶ added in v0.5.0
func WithSkipUsage() OpOption
func WithStatTimeout ¶ added in v0.6.0
type Partitions ¶
type Partitions []Partition
func GetPartitions ¶
func GetPartitions(ctx context.Context, opts ...OpOption) (Partitions, error)
func (Partitions) GetMountedTotalBytes ¶
func (parts Partitions) GetMountedTotalBytes() uint64
Returns the total bytes of all mounted partitions.
func (Partitions) RenderTable ¶
func (parts Partitions) RenderTable(wr io.Writer)