linux

package
v4.6.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// IscsiConf is configuration file for iscsid daemon
	IscsiConf = "/etc/iscsi/iscsid.conf"

	PingCount        = 5
	PingInterval     = 10 * time.Millisecond
	PingTimeout      = 5 * time.Second
	DefaultIscsiPort = 3260
)
View Source
const (
	// VolumeScope scope of the device is volume
	VolumeScope targetScope = 1
	// GroupScope scope of the device is group
	GroupScope targetScope = 2
)
View Source
const (
	// MultipathConf configuration file for multipathd
	MultipathConf = "/etc/multipath.conf"
	// MultipathBindings bindings file for multipathd
	MultipathBindings = "/etc/multipath/bindings"
)
View Source
const (
	// OsTypeRedhat represents RedHat OS
	OsTypeRedhat = "redhat"
	// OsTypeCentos represents CentOS OS
	OsTypeCentos = "centos"
	// OsTypeOracle represents Oracle Linux OS
	OsTypeOracle = "oracle"
	// OsTypeUbuntu represents Ubuntu OS
	OsTypeUbuntu = "ubuntu"
	// OsTypeSuse represents SuSE OS
	OsTypeSuse = "suse"
	// OsTypeAmazon represents Amazon OS
	OsTypeAmazon = "amazon"
)
View Source
const (

	// ScsiHostPathFormat
	ScsiHostPathFormat = "/sys/class/scsi_host/"
	// ScsiHostScanPathFormat
	ScsiHostScanPathFormat = "/sys/class/scsi_host/%s/scan"
)
View Source
const FcHostLIPNameFormat = "/sys/class/fc_host/host%s/issue_lip"

FcHostLIPNameFormat :

View Source
const Udevadm = "udevadm"

Udevadm udev manager

Variables

View Source
var OsIscsiPackageMap = map[string]string{
	OsTypeUbuntu: openIscsi,
	OsTypeSuse:   openIscsi,
	OsTypeRedhat: iscsiInitiatorUtils,
	OsTypeCentos: iscsiInitiatorUtils,
	OsTypeOracle: iscsiInitiatorUtils,
	OsTypeAmazon: iscsiInitiatorUtils,
}

OsIscsiPackageMap provides mapping of os distribution to iscsi package name

View Source
var OsMultipathPackageMap = map[string]string{
	OsTypeUbuntu: multipathTools,
	OsTypeSuse:   multipathTools,
	OsTypeRedhat: deviceMapperMultipath,
	OsTypeCentos: deviceMapperMultipath,
	OsTypeOracle: deviceMapperMultipath,
	OsTypeAmazon: deviceMapperMultipath,
}

OsMultipathPackageMap provides mapping of os distribution to multipath package name

Functions

func AreFsOptionsCompatible

func AreFsOptionsCompatible(fsOpts *model.FilesystemOpts, existingFsOptions *model.FilesystemOpts) (bool, error)

AreFsOptionsCompatible returns true if the FS options are compatible

func BindMount

func BindMount(path, mountPoint string, rbind bool) error

BindMount mounts a path to a mountPoint. The rbind flag controls recursive binding.

func BindUnmount

func BindUnmount(mountPoint string) error

BindUnmount unmounts a bind mount.

func ChangeMode

func ChangeMode(devicePath, fsMode string) (err error)

ChangeMode on the device with fsMode string

func ChangeOwner

func ChangeOwner(mountPoint, user, group string) (err error)

ChangeOwner on the mountpoint to user:group

func Chcon

func Chcon(context, path string) error

Chcon - chcon -t svirt_sandbox_file_t <mount point>

func CheckFsCreationInProgress

func CheckFsCreationInProgress(device model.Device) (inProgress bool, err error)

CheckFsCreationInProgress checks if mkfs process is using the device using lsof

func CreateFileSystem

func CreateFileSystem(devPath string, fsType string) (err error)

CreateFileSystem : creates file system on the device

func CreateFileSystemOnDevice

func CreateFileSystemOnDevice(serialnumber string, fileSystemType string) (dev *model.Device, err error)

CreateFileSystemOnDevice : create filesystem on device with serialnumber :serialnumber nolint: gocyclo

func CreateFileSystemWithOptions

func CreateFileSystemWithOptions(devPath string, fsType string, options []string) (err error)

CreateFileSystemWithOptions : creates file system on the device with creation options

func CreateLinuxDevices

func CreateLinuxDevices(vols []*model.Volume) (devs []*model.Device, err error)

CreateLinuxDevices : attached and creates linux devices to host

func CreateMountDir

func CreateMountDir(mountPoint string) (isDir bool, err error)

CreateMountDir creates new directory if not exists

func DeleteDevice

func DeleteDevice(dev *model.Device) (err error)

DeleteDevice : delete the multipath device

func EnableService

func EnableService(serviceType string) (err error)

EnableService enables given service type on the system, only iscsi and multipath service types are supported

func ExcludeMountDirFromUpdateDb

func ExcludeMountDirFromUpdateDb(mountDir string) (err error)

ExcludeMountDirFromUpdateDb add mountDir to PRUNEPATHS in updatedb.conf to let mlocate ignore mountDir during file search

func ExpandDevice

func ExpandDevice(targetPath string, volAccessType model.VolumeAccessType) error

ExpandDevice expands device and filesystem at given targetPath to underlying volume size targetPath is /dev/dm-* for block device and mountpoint for filesystem based device

func ExpandFilesystem

func ExpandFilesystem(devPath, mountPath, fsType string) (err error)

ExpandFilesystem : expands filesystem size to underlying device size

func GetAllFcHostPortWWN

func GetAllFcHostPortWWN() (portWWNs []string, err error)

GetAllFcHostPortWWN get all FC host port WWN's on the host

func GetAllFcHostPorts

func GetAllFcHostPorts() (hostPorts []*model.FcHostPort, err error)

GetAllFcHostPorts get all the FC host port details on the host

func GetBlockSizeBytes

func GetBlockSizeBytes(devicePath string) (int64, error)

GetBlockSizeBytes returns the block size in bytes

func GetChapInfo

func GetChapInfo() (chapInfo *model.ChapInfo, err error)

GetChapInfo gets the chap user

func GetDeviceBySerial

func GetDeviceBySerial(serialNumber string) (device *model.Device, err error)

GetNimbleDmDevices : get the scsi device by specified serial

func GetDeviceFromMountPoint

func GetDeviceFromMountPoint(mountPoint string) (string, error)

GetDeviceFromMountPoint returns the device path from /proc/mounts for the mountpoint provided. For example /dev/mapper/mpathd might be returned for /mnt.

func GetDeviceFromVolume

func GetDeviceFromVolume(vol *model.Volume) (*model.Device, error)

GetDeviceFromVolume returns Linux device for given volume info

func GetDistro

func GetDistro() (string, error)

func GetDmDeviceFromSerial

func GetDmDeviceFromSerial(serial string) (*model.Device, error)

GetDmDeviceFromSerial returns populated multipath device object for given serial

func GetFilesystemOptions

func GetFilesystemOptions(device *model.Device, mountPoint string) (*model.FilesystemOpts, error)

GetFilesystemOptions applies the FS options on the filesystem of the device

func GetFilesystemType

func GetFilesystemType(devPath string) (string, error)

GetFilesystemType returns the filesystem type if present else empty string

func GetFsType

func GetFsType(mount model.Mount) (fsType string, err error)

GetFsType returns filesytem type for a given mount object

func GetHostNameAndDomain

func GetHostNameAndDomain() ([]string, error)

GetHostNameAndDomain : get host name and domain

func GetHostPort

func GetHostPort(hostNumber string) (hostPort *model.FcHostPort, err error)

GetHostPort get the host port details for given host number from H:C:T:L of device

func GetIPV4NetworkAddress

func GetIPV4NetworkAddress(ipv4Address, netMask string) (networkAddress string, err error)

GetIPV4NetworkAddress returns network address for given ipv4 address and netmask

func GetIfaces

func GetIfaces() (ifaces []*model.Iface, err error)

GetIfaces return bound ifaces with network information

func GetInitiators

func GetInitiators() ([]*model.Initiator, error)

GetInitiators : get the host initiators

func GetIscsiIfacesPath

func GetIscsiIfacesPath() (ifacesPath string, err error)

GetIscsiIfacesPath returns actual path for iscsi ifaces db

func GetIscsiNodesFromIsciadm

func GetIscsiNodesFromIsciadm() (a model.IscsiTargets, err error)

GetIscsiNodesFromIsciadm retrieves iscsi targets with iscsiadm command

func GetIscsiTargets

func GetIscsiTargets() (a model.IscsiTargets, err error)

GetIscsiTargets gets targets connected on host from /dev/disk/by-path entries NOTE: this will fetch only targets with at-least one device discovered

func GetLinuxDmDevices

func GetLinuxDmDevices(needActivePath bool, vol *model.Volume) (a []*model.Device, err error)

GetLinuxDmDevices : Gets the list of Linux Multipath Devices nolint : gocyclo

func GetLoggedInIscsiTargets

func GetLoggedInIscsiTargets() (targets []string, err error)

GetLoggedInIscsiTargets returns currently logged-in iscsi targets

func GetManufacturer

func GetManufacturer() (manufacturer string, err error)

GetManufacturer return manufacturer name of the system

func GetMountOptions

func GetMountOptions(devPath string, mountPoint string) (options []string, err error)

GetMountOptions : get options used for mount point for the Device

func GetMountOptionsForDevice

func GetMountOptionsForDevice(device *model.Device) (options []string, err error)

GetMountOptionsForDevice : get options used for mount point for the Device

func GetMountPointFromDevice

func GetMountPointFromDevice(devPath string) (string, error)

GetMountPointFromDevice returns the FIRST mountpoint listed in /proc/mounts matching the device. Note that /proc/mounts lists device paths using the device mapper format. For example: /dev/mapper/mpathd

func GetMountPointsForDevices

func GetMountPointsForDevices(devices []*model.Device) ([]*model.Mount, error)

GetMountPointsForDevices : get the mount point for the Device nolint : gocyclo

func GetNetworkInterfaces

func GetNetworkInterfaces() ([]*model.NetworkInterface, error)

GetNetworkInterfaces : get the array of network interfaces

func GetPartitionInfo

func GetPartitionInfo(dev *model.Device) (partInfo []model.DevicePartition, err error)

GetPartitionInfo for the Device dev

func GetProductName

func GetProductName() (productName string, err error)

GetProductName return product name of the system

func GetScsiHosts

func GetScsiHosts() ([]string, error)

GetScsiHosts returns all SCSI adapter host objects

func GetUserFriendlyNameBySerial

func GetUserFriendlyNameBySerial(serial string) (mapname string, err error)

GetUserFriendlyNameBySerial returns user_friendly_name for given serial

func HandleIscsiDiscovery

func HandleIscsiDiscovery(volume *model.Volume) (err error)

HandleIscsiDiscovery performs iscsi target discovery and create sessions as required.

func HashMountID

func HashMountID(s string) string

HashMountID : get hash of the string

func InstallPackage

func InstallPackage(packageType string) error

InstallPackage installs provided package type on the host based on OS distro

func IsBlockDevice

func IsBlockDevice(devicePath string) (bool, error)

IsBlockDevice checks if the given path is a block device

func IsFsOwnerMatch

func IsFsOwnerMatch(fsOwner string, existingFsOwner string) (bool, error)

IsFsOwnerMatch checks if the fsOwner matches with the existing FsOwner info

func IsPackageInstalled

func IsPackageInstalled(packageType string) (bool, error)

IsPackageInstalled returns true if specified package type is installed on host

func IsVirtualMachine

func IsVirtualMachine() (isVM bool, err error)

IsVirtualMachine returns true if system is running as a guest on hypervisor

func MountDevice

func MountDevice(device *model.Device, mountPoint string, options []string) (*model.Mount, error)

MountDevice : mount device on host

func MountDeviceWithFileSystem

func MountDeviceWithFileSystem(devPath string, mountPoint string, options []string) (*model.Mount, error)

MountDeviceWithFileSystem : Mount device with filesystem at the mountPoint, if partitions are present, then largest partition will be mounted

func MountNFSShare

func MountNFSShare(source string, targetPath string, options []string, nfsType string) error

func MultipathdReconfigure

func MultipathdReconfigure() (out string, err error)

MultipathdReconfigure reconfigure multipathd settings

func MultipathdShowMaps

func MultipathdShowMaps(serialNumber string) (a []string, err error)

MultipathdShowMaps output

func MultipathdShowPaths

func MultipathdShowPaths(serialNumber string) (a []string, err error)

MultipathdShowPaths output from Linux

func OfflineDevice

func OfflineDevice(dev *model.Device) (err error)

OfflineDevice : offline all the scsi paths for the multipath device

func PerformDiscovery

func PerformDiscovery(discoveryIPs []string) (a model.IscsiTargets, err error)

PerformDiscovery : adds iscsi targets to iscsi database after performing send targets

func RemountWithOptions

func RemountWithOptions(mountPoint string, options []string) error

RemountWithOptions : Remount mountpoint with options nolint : dupl

func RescanFcTarget

func RescanFcTarget(lunID string) (err error)

RescanFcTarget rescans host ports for new Fibre Channel devices nolint: dupl

func RescanForCapacityUpdates

func RescanForCapacityUpdates(devicePath string) error

RescanSize performs size rescan of all scsi devices on host and updates applicable multipath devices TODO: replace rescan-scsi-bus.sh dependency with manual rescan of scsi devices

func RescanIscsi

func RescanIscsi(lunID string) error

RescanIscsi perform SCSI rescan on iSCSI host ports

func RescanScsiHosts

func RescanScsiHosts(scsiHosts []string, lunID string) (err error)

RescanScsiHosts rescan's all SCSI host adapters

func RetryBindMount

func RetryBindMount(path, mountPoint string, rbind bool) error

RetryBindMount :

func RetryBindUnmount

func RetryBindUnmount(mountPoint string) error

RetryBindUnmount :

func RetryCreateFileSystem

func RetryCreateFileSystem(devPath string, fsType string) (err error)

RetryCreateFileSystem : retry file system create

func RetryCreateFileSystemWithOptions

func RetryCreateFileSystemWithOptions(devPath string, fsType string, options []string) (err error)

RetryCreateFileSystemWithOptions : retry file system create

func SelinuxEnabled

func SelinuxEnabled() bool

SelinuxEnabled runs selinuxenabled if found and returns the result. If its not found, false is returned. From man - It exits with status 0 if SELinux is enabled and 1 if it is not enabled.

func ServiceCommand

func ServiceCommand(serviceType string, operationType string) (err error)

ServiceCommand runs service command on given service, valid service types are iscsi and multipath nolint : gocyclo

func SetFilesystemOptions

func SetFilesystemOptions(devPath string, fsOpts *model.FilesystemOpts) error

SetFilesystemOptions applies the FS options on the filesystem of the device

func SetMountOptions

func SetMountOptions(devPath string, mountPoint string, options []string) error

SetMountOptions : get options used for mount point for the Device

func SetupFilesystem

func SetupFilesystem(device *model.Device, filesystemType string) error

SetupFilesystem writes the given filesystem on the given device. If the requested FS already exists on the device, then it returns success.

func SetupFilesystemWithOptions

func SetupFilesystemWithOptions(device *model.Device, filesystemType string, options []string) error

SetupFilesystemWithOptions writes the given filesystem on the given device using the given options. If the requested FS already exists on the device, then it returns success.

func SetupMount

func SetupMount(device *model.Device, mountPoint string, mountOptions []string) (*model.Mount, error)

SetupMount creates the mountpoint with mount options

func UdevadmReloadRules

func UdevadmReloadRules() (err error)

UdevadmReloadRules trigger udev rules

func UdevadmTrigger

func UdevadmTrigger() (err error)

UdevadmTrigger trigger udev rules

func UnmountDevice

func UnmountDevice(device *model.Device, mountPoint string) (*model.Mount, error)

UnmountDevice : unmount device from host

func UnmountFileSystem

func UnmountFileSystem(mountPoint string) (*model.Mount, error)

UnmountFileSystem : unmount the filesystem nolint: gocyclo

func VmdkAttachDevices

func VmdkAttachDevices(vols []*model.Volume) (devs []*model.Device, err error)

AttachDevices : attached and creates scsi devices to host

func VmdkDeleteDevice

func VmdkDeleteDevice(dev *model.Device) (err error)

DeleteDevice : delete the multipath device

Types

type DeletingDevices

type DeletingDevices struct {
	Devices []string `json:"devices,omitempty"`
	// contains filtered or unexported fields
}

DeletingDevices represents serial numbers of devices being deleted

func GetDeletingDevices

func GetDeletingDevices() (dd *DeletingDevices)

GetDeletingDevices returns device serial numbers in deletion state

type FsType

type FsType int

FsType indicates the filesystem type of mounted device

const (
	// Xfs xfs filesystem type
	Xfs FsType = 1 + iota
	// Btrfs B-Tree filesystem type
	Btrfs
	// Ext2 ext2 filesystem type
	Ext2
	// Ext3 ext3 filesytem type
	Ext3
	// Ext4 ext3 filesytem type
	Ext4
)

func (FsType) String

func (fs FsType) String() string

type Mount

type Mount struct {
	ID         uint64        `json:"id,omitempty"`
	Mountpoint string        `json:"mount_point,omitempty"`
	Device     *model.Device `json:"device,omitempty"`
}

Mount struct

type OsInfo

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

OsInfo represents OS information

func GetOsInfo

func GetOsInfo() (*OsInfo, error)

GetOsInfo returns os information including distro and versions

func (*OsInfo) GetKernelVersion

func (o *OsInfo) GetKernelVersion() string

GetKernelVersion returns OS kernel version

func (*OsInfo) GetOsDistro

func (o *OsInfo) GetOsDistro() string

GetOsDistro will return OS distribution

func (*OsInfo) GetOsMajorVersion

func (o *OsInfo) GetOsMajorVersion() string

GetOsMajorVersion returns OS major version

func (*OsInfo) GetOsMinorVersion

func (o *OsInfo) GetOsMinorVersion() string

GetOsMinorVersion returns OS minor version

func (*OsInfo) GetOsVersion

func (o *OsInfo) GetOsVersion() string

GetOsVersion returns OS release version in major.minor format

func (*OsInfo) IsSystemdSupported

func (o *OsInfo) IsSystemdSupported() bool

IsSystemdSupported returns true if systmed is used as service manager on the system

func (*OsInfo) IsUekKernel

func (o *OsInfo) IsUekKernel() bool

IsUekKernel returns true if Oracle Linux is running with UEK kernel

Jump to

Keyboard shortcuts

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