Skip to content

Commit

Permalink
virtcontainers: Remove unused function
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fidencio committed Jun 28, 2022
1 parent 0939f51 commit 3232714
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 97 deletions.
35 changes: 0 additions & 35 deletions src/runtime/virtcontainers/hypervisor.go
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
"os"
"runtime"
"strconv"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -50,7 +49,6 @@ const (
// MockHypervisor is a mock hypervisor for testing purposes
MockHypervisor HypervisorType = "mock"

procMemInfo = "/proc/meminfo"
procCPUInfo = "/proc/cpuinfo"

defaultVCPUs = 1
Expand Down Expand Up @@ -799,39 +797,6 @@ func DeserializeParams(parameters []string) []Param {
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.
// Search is case-insensitive.
// Takes path to file that contains the kernel command line, desired option, and permitted values
Expand Down
50 changes: 0 additions & 50 deletions src/runtime/virtcontainers/hypervisor_test.go
Expand Up @@ -8,7 +8,6 @@ package virtcontainers
import (
"fmt"
"os"
"path/filepath"
"testing"

ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
Expand Down Expand Up @@ -372,55 +371,6 @@ func TestAddKernelParamInvalid(t *testing.T) {
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) {
assert := assert.New(t)

Expand Down
12 changes: 0 additions & 12 deletions src/runtime/virtcontainers/qemu.go
Expand Up @@ -302,18 +302,6 @@ func (q *qemu) cpuTopology() govmmQemu.SMP {
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) {
hostMemMb := q.config.DefaultMaxMemorySize
memMb := uint64(q.config.MemorySize)
Expand Down

0 comments on commit 3232714

Please sign in to comment.