Documentation ¶
Index ¶
- Constants
- Variables
- func BuildSocketPath(elements ...string) (string, error)
- func CalculateCPUsF(quota int64, period uint64) float32
- func ChownToParent(path string) error
- func CleanupFds(fds []*os.File, numFds int)
- func ConvertAddressFamily(family int32) pbTypes.IPFamily
- 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 GetDevicePathAndFsTypeOptions(mountPoint string) (devicePath, fsType string, fsOptions []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 IsDockerContainer(spec *specs.Spec) bool
- func MakeNameID(namedType, id string, maxLen int) string
- func MkdirAllWithInheritedOwner(path string, perm os.FileMode) error
- func RevertBytes(num uint64) uint64
- func SupportsIfb() (bool, error)
- func SupportsVsocks() (bool, error)
- func WaitLocalProcess(pid int, timeoutSecs uint, initialSignal syscall.Signal, logger *logrus.Entry) error
- func WriteToFile(path string, data []byte) error
- type MemUnit
- type Proc
Constants ¶
const ( Byte MemUnit = 1 KiB = Byte << 10 MiB = KiB << 10 GiB = MiB << 10 )
const DefaultRateLimiterRefillTimeMilliSecs = 1000
The DefaultRateLimiterRefillTime is used for calculating the rate at which a TokenBucket is replinished, in cases where a RateLimiter is applied to either network or disk I/O.
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 CalculateCPUsF ¶
CalculateCPUsF converts CPU quota and period to a fraction number
func ChownToParent ¶
ChownToParent changes the owners of the path to the same of parent directory. The path needs to be absolute and the method doesn't handle symlink.
func CleanupFds ¶
CleanupFds closed bundles of open fds in batch
func ConvertAddressFamily ¶
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 GetDevicePathAndFsTypeOptions ¶
func GetDevicePathAndFsTypeOptions(mountPoint string) (devicePath, fsType string, fsOptions []string, err error)
GetDevicePathAndFsTypeOptions gets the device for the mount point, the file system type and mount options
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 IsDockerContainer ¶
func IsDockerContainer(spec *specs.Spec) bool
IsDockerContainer returns if the container is managed by docker This is done by checking the prestart hook for `libnetwork` arguments.
func MakeNameID ¶
MakeNameID is generic function for creating a named-id for passing on the hypervisor commandline
func MkdirAllWithInheritedOwner ¶
MkdirAllWithInheritedOwner creates a directory named path, along with any necessary parents. It creates the missing directories with the ownership of the last existing parent. The path needs to be absolute and the method doesn't handle symlink.
func RevertBytes ¶
In Cloud Hypervisor, as well as in Firecracker, the crate used by the VMMs accepts the size of rate limiter in scaling factors of 2^10(1024). But in kata-defined rate limiter, for better Human-readability, we prefer scaling factors of 10^3(1000).
func revertBytes reverts num from scaling factors of 1000 to 1024, e.g. 10000000(10MB) to 10485760.
func SupportsIfb ¶
SupportsIfb returns true if ifb are supported, otherwise false
func SupportsVsocks ¶
SupportsVsocks returns true if vsocks are supported, otherwise false
func WaitLocalProcess ¶
func WaitLocalProcess(pid int, timeoutSecs uint, initialSignal syscall.Signal, logger *logrus.Entry) error
WaitLocalProcess waits for the specified process for up to timeoutSecs seconds.
Notes:
- If the initial signal is zero, the specified process is assumed to be attempting to stop itself.
- If the initial signal is not zero, it will be sent to the process before checking if it is running.
- If the process has not ended after the timeout value, it will be forcibly killed.
func WriteToFile ¶
WriteToFile opens a file in write only mode and writes bytes to it