mirror of
https://github.com/containers/podman.git
synced 2026-10-25 19:29:32 -04:00
libpod: Implement getOnlineCPUs() on FreeBSD
Include an explicit container state check. Otherwise the containers/stats endpoint will return all-zero stats for a stopped container even when in non-streaming mode, which breaks some consumers of the API, particularly nomad's podman driver. Implement the interface by just returning the number of host CPUs. A bit more sophisticated would be to fetch the jail's cpuset, but it's not very important for now. Signed-off-by: Mark Johnston <mark.johnston@klarasystems.com>
This commit is contained in:
1 parent
0215832852
commit
602ba415c6
1 file changed
+6
-1
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/containers/podman/v5/pkg/rctl"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.podman.io/storage/pkg/system"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// getPlatformContainerStats gets the platform-specific running stats
|
||||
@@ -127,5 +128,9 @@ func calculateCPUPercent(currentCPU, previousCPU, now, previousSystem uint64) fl
|
||||
}
|
||||
|
||||
func getOnlineCPUs(container *Container) (int, error) {
|
||||
return 0, nil
|
||||
if container.state.State != define.ContainerStateRunning {
|
||||
return -1, fmt.Errorf("container %s is not running: %w", container.ID(), define.ErrCtrStopped)
|
||||
}
|
||||
n, err := unix.SysctlUint32("hw.ncpu")
|
||||
return int(n), err
|
||||
}
|
||||
Reference in new issue
Block a user