mirror of
https://github.com/containers/podman.git
synced 2025-06-25 20:26:51 +08:00
Make rm faster
When doing rm, we now parallelize the actual conainter deletions so they can complete faster. This speeds up operations like rm -a. Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
rt "runtime"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
@ -45,6 +46,12 @@ Running containers will not be removed without the -f option.
|
|||||||
|
|
||||||
// saveCmd saves the image to either docker-archive or oci
|
// saveCmd saves the image to either docker-archive or oci
|
||||||
func rmCmd(c *cli.Context) error {
|
func rmCmd(c *cli.Context) error {
|
||||||
|
var (
|
||||||
|
delContainers []*libpod.Container
|
||||||
|
lastError error
|
||||||
|
deleteFuncs []workerInput
|
||||||
|
)
|
||||||
|
|
||||||
ctx := getContext()
|
ctx := getContext()
|
||||||
if err := validateFlags(c, rmFlags); err != nil {
|
if err := validateFlags(c, rmFlags); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -65,8 +72,6 @@ func rmCmd(c *cli.Context) error {
|
|||||||
return errors.Errorf("specify one or more containers to remove")
|
return errors.Errorf("specify one or more containers to remove")
|
||||||
}
|
}
|
||||||
|
|
||||||
var delContainers []*libpod.Container
|
|
||||||
var lastError error
|
|
||||||
if c.Bool("all") {
|
if c.Bool("all") {
|
||||||
delContainers, err = runtime.GetContainers()
|
delContainers, err = runtime.GetContainers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -89,16 +94,26 @@ func rmCmd(c *cli.Context) error {
|
|||||||
delContainers = append(delContainers, container)
|
delContainers = append(delContainers, container)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, container := range delContainers {
|
for _, container := range delContainers {
|
||||||
err = runtime.RemoveContainer(ctx, container, c.Bool("force"))
|
f := func() error {
|
||||||
if err != nil {
|
return runtime.RemoveContainer(ctx, container, c.Bool("force"))
|
||||||
if lastError != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, lastError)
|
|
||||||
}
|
|
||||||
lastError = errors.Wrapf(err, "failed to delete container %v", container.ID())
|
|
||||||
} else {
|
|
||||||
fmt.Println(container.ID())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteFuncs = append(deleteFuncs, workerInput{
|
||||||
|
containerID: container.ID(),
|
||||||
|
parallelFunc: f,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteErrors := parallelExecuteWorkerPool(rt.NumCPU()*3, deleteFuncs)
|
||||||
|
for cid, result := range deleteErrors {
|
||||||
|
if result != nil {
|
||||||
|
fmt.Println(result.Error())
|
||||||
|
lastError = result
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Println(cid)
|
||||||
}
|
}
|
||||||
return lastError
|
return lastError
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user