diff --git a/daemon/info.go b/daemon/info.go index 4162870042..25b68078bf 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -18,7 +18,6 @@ import ( "github.com/docker/docker/pkg/parsers/operatingsystem" "github.com/docker/docker/pkg/platform" "github.com/docker/docker/pkg/sysinfo" - "github.com/docker/docker/pkg/system" "github.com/docker/docker/registry" metrics "github.com/docker/go-metrics" "github.com/opencontainers/selinux/go-selinux" @@ -252,11 +251,11 @@ func kernelVersion() string { return kernelVersion } -func memInfo() *system.MemInfo { - memInfo, err := system.ReadMemInfo() +func memInfo() *sysinfo.Memory { + memInfo, err := sysinfo.ReadMemInfo() if err != nil { logrus.Errorf("Could not read system memory info: %v", err) - memInfo = &system.MemInfo{} + memInfo = &sysinfo.Memory{} } return memInfo } diff --git a/daemon/stats_collector.go b/daemon/stats_collector.go index 0490b2ea15..3516f44b0b 100644 --- a/daemon/stats_collector.go +++ b/daemon/stats_collector.go @@ -5,7 +5,7 @@ import ( "time" "github.com/docker/docker/daemon/stats" - "github.com/docker/docker/pkg/system" + "github.com/docker/docker/pkg/sysinfo" ) // newStatsCollector returns a new statsCollector that collections @@ -15,7 +15,7 @@ import ( func (daemon *Daemon) newStatsCollector(interval time.Duration) *stats.Collector { // FIXME(vdemeester) move this elsewhere if runtime.GOOS == "linux" { - meminfo, err := system.ReadMemInfo() + meminfo, err := sysinfo.ReadMemInfo() if err == nil && meminfo.MemTotal > 0 { daemon.machineMemory = uint64(meminfo.MemTotal) } diff --git a/pkg/system/meminfo.go b/pkg/sysinfo/meminfo.go similarity index 66% rename from pkg/system/meminfo.go rename to pkg/sysinfo/meminfo.go index 6667eb84dc..7cdd996bfd 100644 --- a/pkg/system/meminfo.go +++ b/pkg/sysinfo/meminfo.go @@ -1,7 +1,7 @@ -package system // import "github.com/docker/docker/pkg/system" +package sysinfo -// MemInfo contains memory statistics of the host system. -type MemInfo struct { +// Memory contains memory statistics of the host system. +type Memory struct { // Total usable RAM (i.e. physical RAM minus a few reserved bits and the // kernel binary code). MemTotal int64 diff --git a/pkg/system/meminfo_linux.go b/pkg/sysinfo/meminfo_linux.go similarity index 83% rename from pkg/system/meminfo_linux.go rename to pkg/sysinfo/meminfo_linux.go index 02a7377c1f..ef4f4ac242 100644 --- a/pkg/system/meminfo_linux.go +++ b/pkg/sysinfo/meminfo_linux.go @@ -1,4 +1,4 @@ -package system // import "github.com/docker/docker/pkg/system" +package sysinfo import ( "bufio" @@ -9,8 +9,8 @@ import ( ) // ReadMemInfo retrieves memory statistics of the host system and returns a -// MemInfo type. -func ReadMemInfo() (*MemInfo, error) { +// Memory type. +func ReadMemInfo() (*Memory, error) { file, err := os.Open("/proc/meminfo") if err != nil { return nil, err @@ -20,10 +20,10 @@ func ReadMemInfo() (*MemInfo, error) { } // parseMemInfo parses the /proc/meminfo file into -// a MemInfo object given an io.Reader to the file. +// a Memory object given an io.Reader to the file. // Throws error if there are problems reading from the file -func parseMemInfo(reader io.Reader) (*MemInfo, error) { - meminfo := &MemInfo{} +func parseMemInfo(reader io.Reader) (*Memory, error) { + meminfo := &Memory{} scanner := bufio.NewScanner(reader) memAvailable := int64(-1) for scanner.Scan() { diff --git a/pkg/system/meminfo_unix_test.go b/pkg/sysinfo/meminfo_unix_test.go similarity index 93% rename from pkg/system/meminfo_unix_test.go rename to pkg/sysinfo/meminfo_unix_test.go index adbc948247..c5b9417c08 100644 --- a/pkg/system/meminfo_unix_test.go +++ b/pkg/sysinfo/meminfo_unix_test.go @@ -1,7 +1,7 @@ //go:build linux || freebsd // +build linux freebsd -package system // import "github.com/docker/docker/pkg/system" +package sysinfo import ( "strings" diff --git a/pkg/sysinfo/meminfo_unsupported.go b/pkg/sysinfo/meminfo_unsupported.go new file mode 100644 index 0000000000..9f977b022a --- /dev/null +++ b/pkg/sysinfo/meminfo_unsupported.go @@ -0,0 +1,11 @@ +//go:build !linux && !windows +// +build !linux,!windows + +package sysinfo + +import "errors" + +// ReadMemInfo is not supported on platforms other than linux and windows. +func ReadMemInfo() (*Memory, error) { + return nil, errors.New("platform and architecture is not supported") +} diff --git a/pkg/system/meminfo_windows.go b/pkg/sysinfo/meminfo_windows.go similarity index 86% rename from pkg/system/meminfo_windows.go rename to pkg/sysinfo/meminfo_windows.go index 124d2c502d..cfc1d059a4 100644 --- a/pkg/system/meminfo_windows.go +++ b/pkg/sysinfo/meminfo_windows.go @@ -1,4 +1,4 @@ -package system // import "github.com/docker/docker/pkg/system" +package sysinfo import ( "unsafe" @@ -27,16 +27,16 @@ type memorystatusex struct { } // ReadMemInfo retrieves memory statistics of the host system and returns a -// MemInfo type. -func ReadMemInfo() (*MemInfo, error) { +// Memory type. +func ReadMemInfo() (*Memory, error) { msi := &memorystatusex{ dwLength: 64, } r1, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msi))) if r1 == 0 { - return &MemInfo{}, nil + return &Memory{}, nil } - return &MemInfo{ + return &Memory{ MemTotal: int64(msi.ullTotalPhys), MemFree: int64(msi.ullAvailPhys), SwapTotal: int64(msi.ullTotalPageFile), diff --git a/pkg/system/meminfo_deprecated.go b/pkg/system/meminfo_deprecated.go new file mode 100644 index 0000000000..00e40352a9 --- /dev/null +++ b/pkg/system/meminfo_deprecated.go @@ -0,0 +1,16 @@ +package system + +import "github.com/docker/docker/pkg/sysinfo" + +// MemInfo contains memory statistics of the host system. +// +// Deprecated: use [sysinfo.Memory]. +type MemInfo = sysinfo.Memory + +// ReadMemInfo retrieves memory statistics of the host system and returns a +// MemInfo type. +// +// Deprecated: use [sysinfo.ReadMemInfo]. +func ReadMemInfo() (*sysinfo.Memory, error) { + return sysinfo.ReadMemInfo() +} diff --git a/pkg/system/meminfo_unsupported.go b/pkg/system/meminfo_unsupported.go deleted file mode 100644 index 207ee58ee6..0000000000 --- a/pkg/system/meminfo_unsupported.go +++ /dev/null @@ -1,9 +0,0 @@ -//go:build !linux && !windows -// +build !linux,!windows - -package system // import "github.com/docker/docker/pkg/system" - -// ReadMemInfo is not supported on platforms other than linux and windows. -func ReadMemInfo() (*MemInfo, error) { - return nil, ErrNotSupportedPlatform -}