virtcontainers: Remove unused function

While working on the previous commits, some of the functions become
non-used.  Let's simply remove them.

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
Fabiano Fidêncio 2022-06-27 18:46:11 +02:00
parent 0939f5181b
commit 323271403e
3 changed files with 0 additions and 97 deletions

View File

@ -11,7 +11,6 @@ import (
"fmt" "fmt"
"os" "os"
"runtime" "runtime"
"strconv"
"strings" "strings"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -50,7 +49,6 @@ const (
// MockHypervisor is a mock hypervisor for testing purposes // MockHypervisor is a mock hypervisor for testing purposes
MockHypervisor HypervisorType = "mock" MockHypervisor HypervisorType = "mock"
procMemInfo = "/proc/meminfo"
procCPUInfo = "/proc/cpuinfo" procCPUInfo = "/proc/cpuinfo"
defaultVCPUs = 1 defaultVCPUs = 1
@ -799,39 +797,6 @@ func DeserializeParams(parameters []string) []Param {
return params return params
} }
func GetHostMemorySizeKb(memInfoPath string) (uint64, error) {
f, err := os.Open(memInfoPath)
if err != nil {
return 0, err
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
// Expected format: ["MemTotal:", "1234", "kB"]
parts := strings.Fields(scanner.Text())
// Sanity checks: Skip malformed entries.
if len(parts) < 3 || parts[0] != "MemTotal:" || parts[2] != "kB" {
continue
}
sizeKb, err := strconv.ParseUint(parts[1], 0, 64)
if err != nil {
continue
}
return sizeKb, nil
}
// Handle errors that may have occurred during the reading of the file.
if err := scanner.Err(); err != nil {
return 0, err
}
return 0, fmt.Errorf("unable get MemTotal from %s", memInfoPath)
}
// CheckCmdline checks whether an option or parameter is present in the kernel command line. // CheckCmdline checks whether an option or parameter is present in the kernel command line.
// Search is case-insensitive. // Search is case-insensitive.
// Takes path to file that contains the kernel command line, desired option, and permitted values // Takes path to file that contains the kernel command line, desired option, and permitted values

View File

@ -8,7 +8,6 @@ package virtcontainers
import ( import (
"fmt" "fmt"
"os" "os"
"path/filepath"
"testing" "testing"
ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils" ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
@ -372,55 +371,6 @@ func TestAddKernelParamInvalid(t *testing.T) {
assert.Error(err) assert.Error(err)
} }
func TestGetHostMemorySizeKb(t *testing.T) {
assert := assert.New(t)
type testData struct {
contents string
expectedResult int
expectError bool
}
data := []testData{
{
`
MemTotal: 1 kB
MemFree: 2 kB
SwapTotal: 3 kB
SwapFree: 4 kB
`,
1024,
false,
},
{
`
MemFree: 2 kB
SwapTotal: 3 kB
SwapFree: 4 kB
`,
0,
true,
},
}
dir := t.TempDir()
file := filepath.Join(dir, "meminfo")
_, err := GetHostMemorySizeKb(file)
assert.Error(err)
for _, d := range data {
err = os.WriteFile(file, []byte(d.contents), os.FileMode(0640))
assert.NoError(err)
defer os.Remove(file)
hostMemKb, err := GetHostMemorySizeKb(file)
assert.False((d.expectError && err == nil))
assert.False((!d.expectError && err != nil))
assert.NotEqual(hostMemKb, d.expectedResult)
}
}
func TestCheckCmdline(t *testing.T) { func TestCheckCmdline(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)

View File

@ -302,18 +302,6 @@ func (q *qemu) cpuTopology() govmmQemu.SMP {
return q.arch.cpuTopology(q.config.NumVCPUs, q.config.DefaultMaxVCPUs) return q.arch.cpuTopology(q.config.NumVCPUs, q.config.DefaultMaxVCPUs)
} }
func (q *qemu) hostMemMB() (uint64, error) {
hostMemKb, err := GetHostMemorySizeKb(procMemInfo)
if err != nil {
return 0, fmt.Errorf("Unable to read memory info: %s", err)
}
if hostMemKb == 0 {
return 0, fmt.Errorf("Error host memory size 0")
}
return hostMemKb / 1024, nil
}
func (q *qemu) memoryTopology() (govmmQemu.Memory, error) { func (q *qemu) memoryTopology() (govmmQemu.Memory, error) {
hostMemMb := q.config.DefaultMaxMemorySize hostMemMb := q.config.DefaultMaxMemorySize
memMb := uint64(q.config.MemorySize) memMb := uint64(q.config.MemorySize)