mirror of
https://github.com/containers/podman.git
synced 2025-12-01 10:38:05 +08:00
Fix two bugs in `system df`:
1. The total size was calculated incorrectly as it was creating the sum
of all image sizes but did not consider that a) the same image may
be listed more than once (i.e., for each repo-tag pair), and that
b) images share layers.
The total size is now calculated directly in `libimage` by taking
multi-layer use into account.
2. The reclaimable size was calculated incorrectly. This number
indicates which data we can actually remove which means the total
size minus what containers use (i.e., the "unique" size of the image
in use by containers).
NOTE: The c/storage version is pinned back to the previous commit as it
is buggy. c/common already requires the buggy version, so use a
`replace` to force/pin.
Fixes: #16135
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
const (
|
|
oldMaxSize = uint64(1048576)
|
|
)
|
|
|
|
func getDefaultCgroupsMode() string {
|
|
return "enabled"
|
|
}
|
|
|
|
// getDefaultMachineImage returns the default machine image stream
|
|
// On Linux/Mac, this returns the FCOS stream
|
|
func getDefaultMachineImage() string {
|
|
return "testing"
|
|
}
|
|
|
|
// getDefaultMachineUser returns the user to use for rootless podman
|
|
func getDefaultMachineUser() string {
|
|
return "core"
|
|
}
|
|
|
|
// getDefaultProcessLimits returns the nproc for the current process in ulimits format
|
|
// Note that nfile sometimes cannot be set to unlimited, and the limit is hardcoded
|
|
// to (oldMaxSize) 1048576 (2^20), see: http://stackoverflow.com/a/1213069/1811501
|
|
// In rootless containers this will fail, and the process will just use its current limits
|
|
func getDefaultProcessLimits() []string {
|
|
rlim := unix.Rlimit{Cur: oldMaxSize, Max: oldMaxSize}
|
|
oldrlim := rlim
|
|
// Attempt to set file limit and process limit to pid_max in OS
|
|
dat, err := os.ReadFile("/proc/sys/kernel/pid_max")
|
|
if err == nil {
|
|
val := strings.TrimSuffix(string(dat), "\n")
|
|
max, err := strconv.ParseUint(val, 10, 64)
|
|
if err == nil {
|
|
rlim = unix.Rlimit{Cur: uint64(max), Max: uint64(max)}
|
|
}
|
|
}
|
|
defaultLimits := []string{}
|
|
if err := unix.Setrlimit(unix.RLIMIT_NPROC, &rlim); err == nil {
|
|
defaultLimits = append(defaultLimits, fmt.Sprintf("nproc=%d:%d", rlim.Cur, rlim.Max))
|
|
} else if err := unix.Setrlimit(unix.RLIMIT_NPROC, &oldrlim); err == nil {
|
|
defaultLimits = append(defaultLimits, fmt.Sprintf("nproc=%d:%d", oldrlim.Cur, oldrlim.Max))
|
|
}
|
|
return defaultLimits
|
|
}
|
|
|
|
// getDefaultTmpDir for linux
|
|
func getDefaultTmpDir() string {
|
|
// first check the TMPDIR env var
|
|
if path, found := os.LookupEnv("TMPDIR"); found {
|
|
return path
|
|
}
|
|
return "/var/tmp"
|
|
}
|
|
|
|
func getDefaultLockType() string {
|
|
return "shm"
|
|
}
|
|
|
|
func getLibpodTmpDir() string {
|
|
return "/run/libpod"
|
|
}
|
|
|
|
// getDefaultMachineVolumes returns default mounted volumes (possibly with env vars, which will be expanded)
|
|
func getDefaultMachineVolumes() []string {
|
|
return []string{"$HOME:$HOME"}
|
|
}
|