diff options
-rw-r--r-- | libpod/container_internal.go | 6 | ||||
-rw-r--r-- | libpod/healthcheck_linux.go | 2 | ||||
-rw-r--r-- | pkg/api/handlers/compat/system.go | 2 | ||||
-rw-r--r-- | pkg/domain/infra/abi/system.go | 18 | ||||
-rw-r--r-- | test/apiv2/45-system.at | 18 | ||||
-rw-r--r-- | test/system/220-healthcheck.bats | 6 | ||||
-rw-r--r-- | test/system/320-system-df.bats | 2 |
7 files changed, 30 insertions, 24 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index a7ea3c5c5..994243805 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1286,6 +1286,12 @@ func (c *Container) stop(timeout uint) error { c.lock.Unlock() } + if c.config.HealthCheckConfig != nil { + if err := c.removeTransientFiles(context.Background()); err != nil { + logrus.Error(err.Error()) + } + } + stopErr := c.ociRuntime.StopContainer(c, timeout, all) if !c.batched { diff --git a/libpod/healthcheck_linux.go b/libpod/healthcheck_linux.go index 3fb6dfb91..6948f976a 100644 --- a/libpod/healthcheck_linux.go +++ b/libpod/healthcheck_linux.go @@ -70,7 +70,7 @@ func (c *Container) startTimer() error { startFile := fmt.Sprintf("%s.service", c.ID()) startChan := make(chan string) - if _, err := conn.StartUnitContext(context.Background(), startFile, "fail", startChan); err != nil { + if _, err := conn.RestartUnitContext(context.Background(), startFile, "fail", startChan); err != nil { return err } if err := systemdOpSuccessful(startChan); err != nil { diff --git a/pkg/api/handlers/compat/system.go b/pkg/api/handlers/compat/system.go index 97bc9eac2..23f116d16 100644 --- a/pkg/api/handlers/compat/system.go +++ b/pkg/api/handlers/compat/system.go @@ -76,7 +76,7 @@ func GetDiskUsage(w http.ResponseWriter, r *http.Request) { Scope: "local", Status: nil, UsageData: &docker.VolumeUsageData{ - RefCount: 1, + RefCount: int64(o.Links), Size: o.Size, }, } diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index 3389abd88..da903df9e 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -11,7 +11,6 @@ import ( "github.com/containers/common/pkg/cgroups" "github.com/containers/common/pkg/config" - cutil "github.com/containers/common/pkg/util" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities/reports" @@ -321,19 +320,9 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System return nil, err } - running, err := ic.Libpod.GetRunningContainers() - if err != nil { - return nil, err - } - runningContainers := make([]string, 0, len(running)) - for _, c := range running { - runningContainers = append(runningContainers, c.ID()) - } - dfVolumes := make([]*entities.SystemDfVolumeReport, 0, len(vols)) for _, v := range vols { var reclaimableSize uint64 - var consInUse int mountPoint, err := v.MountPoint() if err != nil { return nil, err @@ -355,14 +344,9 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System if len(inUse) == 0 { reclaimableSize = volSize } - for _, viu := range inUse { - if cutil.StringInSlice(viu, runningContainers) { - consInUse++ - } - } report := entities.SystemDfVolumeReport{ VolumeName: v.Name(), - Links: consInUse, + Links: len(inUse), Size: int64(volSize), ReclaimableSize: int64(reclaimableSize), } diff --git a/test/apiv2/45-system.at b/test/apiv2/45-system.at index 364b87c56..096df5516 100644 --- a/test/apiv2/45-system.at +++ b/test/apiv2/45-system.at @@ -25,6 +25,24 @@ t GET system/df 200 '.Volumes[0].Name=foo1' t GET libpod/system/df 200 '.Volumes[0].VolumeName=foo1' +# Verify that no containers reference the volume +t GET system/df 200 '.Volumes[0].UsageData.RefCount=0' + +# Make a container using the volume +podman pull $IMAGE &>/dev/null +t POST containers/create Image=$IMAGE Volumes='{"/test":{}}' HostConfig='{"Binds":["foo1:/test"]}' 201 \ + .Id~[0-9a-f]\\{64\\} +cid=$(jq -r '.Id' <<<"$output") + +# Verify that one container references the volume +t GET system/df 200 '.Volumes[0].UsageData.RefCount=1' + +# Remove the container +t DELETE containers/$cid?v=true 204 + +# Verify that no containers reference the volume +t GET system/df 200 '.Volumes[0].UsageData.RefCount=0' + # Create two more volumes to test pruneing t POST libpod/volumes/create \ Name=foo2 \ diff --git a/test/system/220-healthcheck.bats b/test/system/220-healthcheck.bats index 00ec1dd79..a1b24d293 100644 --- a/test/system/220-healthcheck.bats +++ b/test/system/220-healthcheck.bats @@ -106,8 +106,7 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\" # healthcheck should now fail, with exit status 1 and 'unhealthy' output run_podman 1 healthcheck run $ctr - # FIXME: #15691 - `healthcheck run` may emit an error log that the timer already exists - is "$output" ".*unhealthy.*" "output from 'podman healthcheck run'" + is "$output" "unhealthy" "output from 'podman healthcheck run'" run_podman inspect $ctr --format "{{.State.Status}} {{.Config.HealthcheckOnFailureAction}}" if [[ $policy == "restart" ]];then @@ -118,8 +117,7 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\" # Container is still running and health check still broken is "$output" "running $policy" "container continued running" run_podman 1 healthcheck run $ctr - # FIXME: #15691 - `healthcheck run` may emit an error log that the timer already exists - is "$output" ".*unhealthy.*" "output from 'podman healthcheck run'" + is "$output" "unhealthy" "output from 'podman healthcheck run'" else # kill and stop yield the container into a non-running state is "$output" ".* $policy" "container was stopped/killed" diff --git a/test/system/320-system-df.bats b/test/system/320-system-df.bats index 217357b37..35e121c62 100644 --- a/test/system/320-system-df.bats +++ b/test/system/320-system-df.bats @@ -27,7 +27,7 @@ function teardown() { run_podman system df --format '{{ .Type }}:{{ .Total }}:{{ .Active }}' is "${lines[0]}" "Images:1:1" "system df : Images line" is "${lines[1]}" "Containers:2:1" "system df : Containers line" - is "${lines[2]}" "Local Volumes:2:1" "system df : Volumes line" + is "${lines[2]}" "Local Volumes:2:2" "system df : Volumes line" # Try -v. (Grrr. No way to specify individual formats) # |