mirror of
https://github.com/containers/podman.git
synced 2025-12-02 11:08:36 +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>
87 lines
1.5 KiB
Go
87 lines
1.5 KiB
Go
//go:build systemd && cgo
|
|
// +build systemd,cgo
|
|
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/containers/common/pkg/cgroupv2"
|
|
"github.com/containers/storage/pkg/unshare"
|
|
)
|
|
|
|
var (
|
|
systemdOnce sync.Once
|
|
usesSystemd bool
|
|
journaldOnce sync.Once
|
|
usesJournald bool
|
|
)
|
|
|
|
const (
|
|
// DefaultLogDriver is the default type of log files
|
|
DefaultLogDriver = "journald"
|
|
)
|
|
|
|
func defaultCgroupManager() string {
|
|
if !useSystemd() {
|
|
return CgroupfsCgroupsManager
|
|
}
|
|
enabled, err := cgroupv2.Enabled()
|
|
if err == nil && !enabled && unshare.IsRootless() {
|
|
return CgroupfsCgroupsManager
|
|
}
|
|
|
|
return SystemdCgroupsManager
|
|
}
|
|
|
|
func defaultEventsLogger() string {
|
|
if useJournald() {
|
|
return "journald"
|
|
}
|
|
return "file"
|
|
}
|
|
|
|
func defaultLogDriver() string {
|
|
if useJournald() {
|
|
return "journald"
|
|
}
|
|
return "k8s-file"
|
|
}
|
|
|
|
func useSystemd() bool {
|
|
systemdOnce.Do(func() {
|
|
dat, err := os.ReadFile("/proc/1/comm")
|
|
if err == nil {
|
|
val := strings.TrimSuffix(string(dat), "\n")
|
|
usesSystemd = (val == "systemd")
|
|
}
|
|
})
|
|
return usesSystemd
|
|
}
|
|
|
|
func useJournald() bool {
|
|
journaldOnce.Do(func() {
|
|
if !useSystemd() {
|
|
return
|
|
}
|
|
for _, root := range []string{"/run/log/journal", "/var/log/journal"} {
|
|
dirs, err := os.ReadDir(root)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
for _, d := range dirs {
|
|
if d.IsDir() {
|
|
if _, err := os.ReadDir(filepath.Join(root, d.Name())); err == nil {
|
|
usesJournald = true
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return usesJournald
|
|
}
|