mirror of
https://github.com/containers/podman.git
synced 2025-12-02 19:28:58 +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
1.4 KiB
Go
77 lines
1.4 KiB
Go
package machine
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/containers/common/pkg/config"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// TODO: change name to MachineMarker since package is already called machine
|
|
//
|
|
//nolint:revive
|
|
type MachineMarker struct {
|
|
Enabled bool
|
|
Type string
|
|
}
|
|
|
|
const (
|
|
markerFile = "/etc/containers/podman-machine"
|
|
Wsl = "wsl"
|
|
Qemu = "qemu"
|
|
)
|
|
|
|
var (
|
|
markerSync sync.Once
|
|
machineMarker *MachineMarker
|
|
)
|
|
|
|
func loadMachineMarker(file string) {
|
|
var kind string
|
|
|
|
// Support deprecated config value for compatibility
|
|
enabled := isLegacyConfigSet()
|
|
|
|
if content, err := os.ReadFile(file); err == nil {
|
|
enabled = true
|
|
kind = strings.TrimSpace(string(content))
|
|
}
|
|
|
|
machineMarker = &MachineMarker{enabled, kind}
|
|
}
|
|
|
|
func isLegacyConfigSet() bool {
|
|
config, err := config.Default()
|
|
if err != nil {
|
|
logrus.Warnf("could not obtain container configuration")
|
|
return false
|
|
}
|
|
|
|
//nolint:staticcheck //lint:ignore SA1019 deprecated call
|
|
return config.Engine.MachineEnabled
|
|
}
|
|
|
|
func IsPodmanMachine() bool {
|
|
return GetMachineMarker().Enabled
|
|
}
|
|
|
|
// TODO: change name to HostType since package is already called machine
|
|
//
|
|
//nolint:revive
|
|
func MachineHostType() string {
|
|
return GetMachineMarker().Type
|
|
}
|
|
|
|
func IsGvProxyBased() bool {
|
|
return IsPodmanMachine() && MachineHostType() != Wsl
|
|
}
|
|
|
|
func GetMachineMarker() *MachineMarker {
|
|
markerSync.Do(func() {
|
|
loadMachineMarker(markerFile)
|
|
})
|
|
return machineMarker
|
|
}
|