Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
agent: add GetGuestDetails gRPC function
Browse files Browse the repository at this point in the history
To get memory hotplug align boundary, need read
/sys/devices/system/memory/block_size_bytes in guest.
Add a function to do this and we can also extend to
get other details in the future.

Fixes #354

Signed-off-by: Zichang Lin <[email protected]>
  • Loading branch information
linzichang committed Sep 11, 2018
1 parent e3eb9ce commit 7e8e20b
Show file tree
Hide file tree
Showing 5 changed files with 502 additions and 153 deletions.
15 changes: 15 additions & 0 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,3 +1303,18 @@ func (a *agentGRPC) OnlineCPUMem(ctx context.Context, req *pb.OnlineCPUMemReques
func (a *agentGRPC) ReseedRandomDev(ctx context.Context, req *pb.ReseedRandomDevRequest) (*gpb.Empty, error) {
return emptyResp, reseedRNG(req.Data)
}

func (a *agentGRPC) GetGuestDetails(ctx context.Context, req *pb.GuestDetailsRequest) (*pb.GuestDetailsResponse, error) {
var details pb.GuestDetailsResponse
if req.MemBlockSize {
data, err := ioutil.ReadFile("/sys/devices/system/memory/block_size_bytes")
if err != nil {
return nil, err
}
details.MemBlockSizeBytes, err = strconv.ParseUint(string(data[:len(data)-1]), 16, 64)
if err != nil {
return nil, err
}
}
return &details, nil
}
25 changes: 25 additions & 0 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"strconv"
"sync"
)

Expand Down Expand Up @@ -620,3 +621,27 @@ func TestMultiWaitProcess(t *testing.T) {

wg.Wait()
}

func TestGetGuestDetails(t *testing.T) {
assert := assert.New(t)
a := &agentGRPC{
sandbox: &sandbox{
containers: make(map[string]*container),
},
}

req := &pb.GuestDetailsRequest{
MemBlockSize: true,
}

resp, err := a.GetGuestDetails(context.TODO(), req)
assert.NoError(err)

data, err := ioutil.ReadFile("/sys/devices/system/memory/block_size_bytes")
assert.NoError(err)

size, err := strconv.ParseUint(string(data[:len(data)-1]), 16, 64)
assert.NoError(err)

assert.Equal(resp.MemBlockSizeBytes, size)
}
Loading

0 comments on commit 7e8e20b

Please sign in to comment.