runtime: add hugepages support

Add hugepages support, port from:
b486387cba

Signed-off-by: Pradipta Banerjee <pradipta.banerjee@gmail.com>
Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
bin
2021-12-23 14:02:11 +08:00
parent 7df677c01e
commit 81a8baa5e5
9 changed files with 168 additions and 11 deletions

View File

@@ -96,11 +96,12 @@ const (
procDeviceIndex = iota
procPathIndex
procTypeIndex
procOptionIndex
)
// GetDevicePathAndFsType gets the device for the mount point and the file system type
// of the mount.
func GetDevicePathAndFsType(mountPoint string) (devicePath, fsType string, err error) {
// GetDevicePathAndFsTypeOptions gets the device for the mount point, the file system type
// and mount options
func GetDevicePathAndFsTypeOptions(mountPoint string) (devicePath, fsType string, fsOptions []string, err error) {
if mountPoint == "" {
err = fmt.Errorf("Mount point cannot be empty")
return
@@ -134,6 +135,7 @@ func GetDevicePathAndFsType(mountPoint string) (devicePath, fsType string, err e
if mountPoint == fields[procPathIndex] {
devicePath = fields[procDeviceIndex]
fsType = fields[procTypeIndex]
fsOptions = strings.Split(fields[procOptionIndex], ",")
return
}
}

View File

@@ -6,7 +6,10 @@
package utils
import (
"bytes"
"errors"
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -34,20 +37,31 @@ func TestFindContextID(t *testing.T) {
assert.Error(err)
}
func TestGetDevicePathAndFsTypeEmptyMount(t *testing.T) {
func TestGetDevicePathAndFsTypeOptionsEmptyMount(t *testing.T) {
assert := assert.New(t)
_, _, err := GetDevicePathAndFsType("")
_, _, _, err := GetDevicePathAndFsTypeOptions("")
assert.Error(err)
}
func TestGetDevicePathAndFsTypeSuccessful(t *testing.T) {
func TestGetDevicePathAndFsTypeOptionsSuccessful(t *testing.T) {
assert := assert.New(t)
path, fstype, err := GetDevicePathAndFsType("/proc")
cmdStr := "grep ^proc /proc/mounts"
cmd := exec.Command("sh", "-c", cmdStr)
output, err := cmd.Output()
assert.NoError(err)
data := bytes.Split(output, []byte(" "))
fstypeOut := string(data[2])
optsOut := strings.Split(string(data[3]), ",")
path, fstype, fsOptions, err := GetDevicePathAndFsTypeOptions("/proc")
assert.NoError(err)
assert.Equal(path, "proc")
assert.Equal(fstype, "proc")
assert.Equal(fstype, fstypeOut)
assert.Equal(fsOptions, optsOut)
}
func TestIsAPVFIOMediatedDeviceFalse(t *testing.T) {