Documentation
¶
Overview ¶
Package util common tools
* Copyright (c) 2020 Tencent Serverless * All rights reserved * Author: jiangdu * Date: 2020-06-15
Index ¶
- Constants
- Variables
- func AttachVFIODriver(ctx context.Context, pciBus string) error
- func BindDriver(ctx context.Context, pciBus string, driver string) error
- func Contains(val string, slice []string) bool
- func ContainsError(err error, keys string) bool
- func CopyFile(ctx context.Context, src, dst string) error
- func Decode(body string, req interface{}) error
- func DenExist(path string) (bool, error)
- func DetachVFIODriver(ctx context.Context, pciBus string) error
- func DetachVirtioDevice(ctx context.Context, pciBus string) error
- func Exec(arg string, timeout time.Duration) (string, string, error)
- func ExecBin(name string, args []string, timeout time.Duration) (string, string, error)
- func ExecBinCtx(ctx context.Context, name string, args []string) (string, string, error)
- func ExecV(argv []string, timeout time.Duration) (string, string, error)
- func ExecVCtx(ctx context.Context, argv []string) (string, string, error)
- func FileExistAndValid(path string) (bool, error)
- func FileExistWithSize(path string) (bool, int64, error)
- func GenGatewayIP(ip string, subnetMask string) net.IP
- func GenLocalMAC(ipStr string) string
- func GenerateID() string
- func GetAllDirname(pathname string) ([]string, error)
- func GetBodyData(rsp *http.Response, object any) error
- func GetDeviceIdleRatio(path string) (uint64, uint64, error)
- func GetDiskCap(path string) (uint64, uint64, error)
- func GetInstanceID() (string, error)
- func GetLocalIpv4() (string, error)
- func GetLoopNameByBackendFile(file string) (string, error)
- func GetMountNumByBackendFile(file string) (int, error)
- func GetMountNumByLoopName(loop string) (int, error)
- func GetProjectID() int
- func GetRegion() (string, error)
- func GetSha256Value(image string) (string, error)
- func GetShortInstanceType() (string, error)
- func GetSubNetID(mac string) (string, error)
- func GetTruncatedID(id, prefix string) string
- func GetVPCIDByMAC(mac string) (string, error)
- func HashCode(dimension string) uint32
- func InStringSlice(ss []string, str string) bool
- func InetAtoNv4(ip string) (uint, error)
- func InetNtoAv4(ip uint) string
- func InitDriverId(ctx context.Context, driver string) error
- func Int32ToBytes(n int32) []byte
- func Int64ToBytes(n int64) []byte
- func InterfaceToString(obj interface{}) string
- func IsDebug() bool
- func IsDriverAttached(ctx context.Context, pciBus string, driver string) (eq bool, exist bool, err error)
- func IsEmpty(dirname string) (bool, error)
- func IsInteger(s string) bool
- func IsLikelyNotMountPoint(file string) (bool, error)
- func IsMountLoop(backendFile string) bool
- func IsMountPoint(dst string) (bool, error)
- func IsNotFound(err error) bool
- func LazyUnmount(dest string) error
- func MakeBoltDBOption() *bolt.Options
- func MapKeys[K comparable, V any](m map[K]V) []K
- func MaxCommonPrefix(arrays []string) string
- func MergeStringSlices(a []string, b []string) []string
- func Min(arg int, args ...int) int
- func MountSqfs(src, dst string, timeout time.Duration) error
- func NormalizeRepoDigest(repoDigests []string) (repo, digest string)
- func NormalizeRepoTagPair(repoTags []string, imageName string) (repoTagPairs [][]string)
- func OrderedBy[T any](less ...lessFunc[T]) *multiSorter[T]
- func ParseImageDigestAndTag(name string) (repoTag string, repoDigest string, err error)
- func PipeExecV(argv []string, timeout time.Duration) (string, string, error)
- func ProcessExists(ctx context.Context, pid int) bool
- func QuotaDir(ctx context.Context, dir string, quota uint64, projectID int) error
- func QuotaDirScale(ctx context.Context, limit uint64, projectID int) error
- func ReadAtMost(r io.Reader, limit int64) ([]byte, error)
- func ReadIPFromStrInterface(i interface{}) net.IP
- func Recover() error
- func RemoveStringPrefix(arrays []string, prefix string) []string
- func SafeCopyFile(dst, src string) (err error)
- func SafeJoinPath(baseDir, untrusted string) (string, error)
- func SkipCI(t testing.TB)
- func String2Slice(s string) []byte
- func ValidateBDF(bdf string) bool
- func WriteStrToFile(path, msg string) error
- type BlockGroupDescriptor
- type CubeStore
- func (cs *CubeStore) Close() error
- func (cs *CubeStore) Delete(bucket, key string) (err error)
- func (cs *CubeStore) DeleteBs(key string, buckets ...[]byte) (err error)
- func (cs *CubeStore) DeleteWithTx(bucket, key string, callback func() error) (err error)
- func (cs *CubeStore) Get(bucket, key string) (result []byte, err error)
- func (cs *CubeStore) GetBs(key string, buckets ...[]byte) (result []byte, err error)
- func (cs *CubeStore) ReadAll(bucket string) (all map[string][]byte, _ error)
- func (cs *CubeStore) ReadAllBs(buckets ...[]byte) (all map[string][]byte, _ error)
- func (cs *CubeStore) Set(bucket, key string, value []byte) (err error)
- func (cs *CubeStore) SetBs(key string, value []byte, buckets ...[]byte) (err error)
- func (cs *CubeStore) SetWithTx(bucket, key string, value []byte, callback func() error) (err error)
- type HostIdentity
- type Less
- type Queue
- type ResMutex
- type ResourceLocks
- type Superblock
Examples ¶
Constants ¶
View Source
const ( Vfio_pci = "vfio-pci" Virtio_pci = "virtio-pci" )
View Source
const DefaultTimeout = time.Second * 3
View Source
const (
SuperblockOffset = 1024
)
Variables ¶
View Source
var ( ErrorKeyNotFound = fmt.Errorf("key %w", errdefs.ErrNotFound) ErrorBucketNotFound = fmt.Errorf("bucket %w", errdefs.ErrNotFound) )
View Source
var ErrLimitReached = errors.New("the read limit is reached")
View Source
var ErrMetadataUnsupported = errors.New("cloud metadata is not available in the opensource cubelet build")
View Source
var JSONTool = jsoniter.ConfigCompatibleWithStandardLibrary
Functions ¶
func ContainsError ¶
func Exec ¶
Exec runs the given string through /usr/bin/bash -lc, so the argument goes through full shell parsing. It is intended only for trusted internal callers (never concatenate external input into arg). The validation below still rejects NUL and control characters to catch obvious injection attempts and accidental misuse.
func ExecBinCtx ¶
func FileExistAndValid ¶
func GenLocalMAC ¶
func GenerateID ¶
func GenerateID() string
func GetAllDirname ¶
func GetInstanceID ¶
func GetLocalIpv4 ¶
func GetMountNumByLoopName ¶
func GetProjectID ¶
func GetProjectID() int
func GetSha256Value ¶
func GetShortInstanceType ¶
func GetSubNetID ¶
func GetTruncatedID ¶
func GetVPCIDByMAC ¶
func InStringSlice ¶
func InetAtoNv4 ¶
func InetNtoAv4 ¶
func Int32ToBytes ¶
func Int64ToBytes ¶
func InterfaceToString ¶
func InterfaceToString(obj interface{}) string
func IsDriverAttached ¶
func IsLikelyNotMountPoint ¶
func IsMountLoop ¶
func IsMountPoint ¶
func IsNotFound ¶
func LazyUnmount ¶
func MakeBoltDBOption ¶
func MapKeys ¶
func MapKeys[K comparable, V any](m map[K]V) []K
func MaxCommonPrefix ¶
func MergeStringSlices ¶
func NormalizeRepoDigest ¶
func NormalizeRepoTagPair ¶
func ParseImageDigestAndTag ¶
func ReadIPFromStrInterface ¶
func RemoveStringPrefix ¶
func SafeCopyFile ¶
func SafeJoinPath ¶
SafeJoinPath joins baseDir with the untrusted component and verifies the resulting path stays within baseDir (prevents path traversal attacks). Returns an error if the resolved path escapes the base directory.
func String2Slice ¶
func ValidateBDF ¶
func WriteStrToFile ¶
Types ¶
type BlockGroupDescriptor ¶
type BlockGroupDescriptor struct {
BlockBitmap uint32
InodeBitmap uint32
InodeTable uint32
FreeBlocksCount uint16
FreeInodesCount uint16
UsedDirsCount uint16
Flags uint16
ExcludeBitmapLo uint32
BlockBitmapCsumLo uint16
InodeBitmapCsumLo uint16
ItableUnused uint16
Checksum uint16
}
func GetExt4BlockGroupDescriptor ¶
func GetExt4BlockGroupDescriptor(device string) (*BlockGroupDescriptor, error)
type CubeStore ¶
type CubeStore struct {
// contains filtered or unexported fields
}
func NewCubeStoreExt ¶
func (*CubeStore) DeleteWithTx ¶
type HostIdentity ¶
func GetHostIdentity ¶
func GetHostIdentity() (HostIdentity, error)
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Example ¶
q := NewQueue[Tap]()
q.Enqueue(&Tap{Name: "1"})
q.Enqueue(&Tap{Name: "2"})
q.Enqueue(&Tap{Name: "3"})
fmt.Println(q.Dequeue())
fmt.Println(q.Dequeue())
fmt.Println(q.Dequeue())
type ResourceLocks ¶
type ResourceLocks struct {
// contains filtered or unexported fields
}
func NewResourceLocks ¶
func NewResourceLocks() *ResourceLocks
func (*ResourceLocks) Len ¶
func (r *ResourceLocks) Len() int
func (*ResourceLocks) Lock ¶
func (r *ResourceLocks) Lock(resource string) func()
type Superblock ¶
type Superblock struct {
InodesCount uint32
BlocksCount uint32
RBlocksCount uint32
FreeBlocksCount uint32
FreeInodesCount uint32
FirstDataBlock uint32
LogBlockSize uint32
LogFragSize uint32
BlocksPerGroup uint32
FragsPerGroup uint32
InodesPerGroup uint32
Mtime uint32
Wtime uint32
MntCount uint16
MaxMntCount uint16
Magic uint16
}
Click to show internal directories.
Click to hide internal directories.