Documentation ¶
Index ¶
- Constants
- Variables
- func BuildSocketPath(elements ...string) (string, error)
- func CalculateMilliCPUs(quota int64, period uint64) uint32
- func CalculateVCpusFromMilliCpus(mCPU uint32) uint32
- func CleanupFds(fds []*os.File, numFds int)
- func ConstraintsToVCPUs(quota int64, period uint64) uint
- func DeepCompare(foo, bar interface{}) bool
- func FileCopy(srcPath, dstPath string) error
- func FindContextID() (*os.File, uint64, error)
- func GenerateRandomBytes(n int) ([]byte, error)
- func GetDevicePathAndFsType(mountPoint string) (devicePath, fsType string, err error)
- func GetSCSIAddress(index int) (string, error)
- func GetSCSIIdLun(index int) (int, int, error)
- func GetVirtDriveName(index int) (string, error)
- func Ioctl(fd uintptr, request, data uintptr) error
- func MakeNameID(namedType, id string, maxLen int) string
- func ReverseString(s string) string
- func SupportsVsocks() bool
- func WriteToFile(path string, data []byte) error
- type MemUnit
- type Proc
- type ProgramLogger
Constants ¶
const ( Byte MemUnit = 1 KiB = Byte << 10 MiB = KiB << 10 GiB = MiB << 10 )
const LoggerBinaryName = "systemd-cat"
Binary to use to log program output
const MaxSocketPathLen = 107
MaxSocketPathLen is the effective maximum Unix domain socket length.
See unix(7).
const MibToBytesShift = 20
MibToBytesShift the number to shift needed to convert MiB to Bytes
Variables ¶
var StartCmd = func(c *exec.Cmd) error {
return c.Start()
}
StartCmd pointer to a function to start a command. Defined this way to allow mock testing.
var VHostVSockDevicePath = "/dev/vhost-vsock"
VHostVSockDevicePath path to vhost-vsock device
Functions ¶
func BuildSocketPath ¶
BuildSocketPath concatenates the provided elements into a path and returns it. If the resulting path is longer than the maximum permitted socket path on Linux, it will return an error.
func CalculateMilliCPUs ¶
CalculateMilliCPUs converts CPU quota and period to milli-CPUs
func CalculateVCpusFromMilliCpus ¶
CalculateVCpusFromMilliCpus converts from mCPU to CPU, taking the ceiling value when necessary
func CleanupFds ¶
CleanupFds closed bundles of open fds in batch
func ConstraintsToVCPUs ¶
ConstraintsToVCPUs converts CPU quota and period to vCPUs
func FindContextID ¶
FindContextID finds a unique context ID by generating a random number between 3 and max unsigned int (maxUint). Using the ioctl VHOST_VSOCK_SET_GUEST_CID, findContextID asks to the kernel if the given context ID (N) is available, when the context ID is not available, incrementing by 1 findContextID iterates from N to maxUint until an available context ID is found, otherwise decrementing by 1 findContextID iterates from N to 3 until an available context ID is found, this is the last chance to find a context ID available. On success vhost file and a context ID greater or equal than 3 are returned, otherwise 0 and an error are returned. vhost file can be used to send vhost file decriptor to QEMU. It's the caller's responsibility to close vhost file descriptor.
Benefits of using random context IDs:
- Reduce the probability of a *DoS attack*, since other processes don't know whatis the initial context ID used by findContextID to find a context ID available
func GenerateRandomBytes ¶
GenerateRandomBytes generate n random bytes
func GetDevicePathAndFsType ¶
GetDevicePathAndFsType gets the device for the mount point and the file system type of the mount.
func GetSCSIAddress ¶
GetSCSIAddress gets scsiID and lun from index, and combined them into a scsi ID
func GetSCSIIdLun ¶
GetSCSIIdLun gets the SCSI id and lun, based on the index of the drive being inserted. qemu code suggests that scsi-id can take values from 0 to 255 inclusive, while lun can take values from 0 to 16383 inclusive. But lun values over 255 do not seem to follow consistent SCSI addressing. Hence we limit to 255.
func GetVirtDriveName ¶
GetVirtDriveName returns the disk name format for virtio-blk Reference: https://github.com/torvalds/linux/blob/master/drivers/block/virtio_blk.c @c0aa3e0916d7e531e69b02e426f7162dfb1c6c0
func MakeNameID ¶
MakeNameID is generic function for creating a named-id for passing on the hypervisor commandline
func SupportsVsocks ¶
func SupportsVsocks() bool
SupportsVsocks returns true if vsocks are supported, otherwise false
func WriteToFile ¶
WriteToFile opens a file in write only mode and writes bytes to it
Types ¶
type MemUnit ¶
type MemUnit uint64
type ProgramLogger ¶
type ProgramLogger struct {
// contains filtered or unexported fields
}
func NewProgramLogger ¶
func NewProgramLogger(loggerLabel string) ProgramLogger
func (*ProgramLogger) StartLogger ¶
func (p *ProgramLogger) StartLogger(output io.ReadCloser) error
func (ProgramLogger) String ¶
func (p ProgramLogger) String() string