Skip to content

Commit

Permalink
Make a copy of MachineInfo in GetMachineInfo()
Browse files Browse the repository at this point in the history
Signed-off-by: Ted Yu <yuzhihong@gmail.com>
  • Loading branch information
tedyu committed Apr 10, 2020
1 parent 49f4075 commit 2dd055c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
16 changes: 8 additions & 8 deletions machine/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ func TestTopologyWithoutNodes(t *testing.T) {

expectedTopology := `[
{
"node_id":0,
"node_id":1,
"memory":0,
"hugepages":null,
"cores":[
{
"core_id":0,
"core_id":1,
"thread_ids":[
0,
2
1,
3
],
"caches":[
{
Expand All @@ -279,15 +279,15 @@ func TestTopologyWithoutNodes(t *testing.T) {
"caches":null
},
{
"node_id":1,
"node_id":0,
"memory":0,
"hugepages":null,
"cores":[
{
"core_id":1,
"core_id":0,
"thread_ids":[
1,
3
0,
2
],
"caches":[
{
Expand Down
22 changes: 21 additions & 1 deletion manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,27 @@ func (m *manager) GetMachineInfo() (*info.MachineInfo, error) {
m.machineMu.RLock()
defer m.machineMu.RUnlock()
// Copy and return the MachineInfo.
return &m.machineInfo, nil
copy := info.MachineInfo{
NumCores: m.machineInfo.NumCores,
NumPhysicalCores: m.machineInfo.NumPhysicalCores,
NumSockets: m.machineInfo.NumSockets,
CpuFrequency: m.machineInfo.CpuFrequency,
MemoryCapacity: m.machineInfo.MemoryCapacity,
MemoryByType: m.machineInfo.MemoryByType,
NVMInfo: m.machineInfo.NVMInfo,
HugePages: m.machineInfo.HugePages,
MachineID: m.machineInfo.MachineID,
SystemUUID: m.machineInfo.SystemUUID,
BootID: m.machineInfo.BootID,
Filesystems: m.machineInfo.Filesystems,
DiskMap: m.machineInfo.DiskMap,
NetworkDevices: m.machineInfo.NetworkDevices,
Topology: m.machineInfo.Topology,
CloudProvider: m.machineInfo.CloudProvider,
InstanceType: m.machineInfo.InstanceType,
InstanceID: m.machineInfo.InstanceID,
}
return &copy, nil
}

func (m *manager) GetVersionInfo() (*info.VersionInfo, error) {
Expand Down

0 comments on commit 2dd055c

Please sign in to comment.