diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/umount.go | 78 |
1 files changed, 69 insertions, 9 deletions
diff --git a/cmd/podman/umount.go b/cmd/podman/umount.go index 803cf034a..0fd7ff144 100644 --- a/cmd/podman/umount.go +++ b/cmd/podman/umount.go @@ -1,17 +1,29 @@ package main import ( + "fmt" + "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" + "github.com/projectatomic/libpod/libpod" + "github.com/sirupsen/logrus" "github.com/urfave/cli" ) var ( + umountFlags = []cli.Flag{ + cli.BoolFlag{ + Name: "all, a", + Usage: "umount all of the currently mounted containers", + }, + } + umountCommand = cli.Command{ Name: "umount", Aliases: []string{"unmount"}, - Usage: "Unmount a working container's root filesystem", - Description: "Unmounts a working container's root filesystem", + Usage: "Unmounts working container's root filesystem", + Description: "Unmounts working container's root filesystem", + Flags: umountFlags, Action: umountCmd, ArgsUsage: "CONTAINER-NAME-OR-ID", } @@ -24,18 +36,66 @@ func umountCmd(c *cli.Context) error { } defer runtime.Shutdown(false) + umountAll := c.Bool("all") args := c.Args() - if len(args) == 0 { + if len(args) == 0 && !umountAll { return errors.Errorf("container ID must be specified") } - if len(args) > 1 { - return errors.Errorf("too many arguments specified") + if len(args) > 0 && umountAll { + return errors.Errorf("when using the --all switch, you may not pass any container IDs") } - ctr, err := runtime.LookupContainer(args[0]) - if err != nil { - return errors.Wrapf(err, "error looking up container %q", args[0]) + umountContainerErrStr := "error unmounting container" + var lastError error + if len(args) > 0 { + for _, name := range args { + ctr, err := runtime.LookupContainer(name) + if err != nil { + if lastError != nil { + logrus.Error(lastError) + } + lastError = errors.Wrapf(err, "%s %s", umountContainerErrStr, name) + continue + } + + if err = unmountContainer(ctr); err != nil { + if lastError != nil { + logrus.Error(lastError) + } + lastError = errors.Wrapf(err, "%s %s", umountContainerErrStr, name) + continue + } + fmt.Printf("%s\n", ctr.ID()) + } + } else { + containers, err := runtime.GetContainers() + if err != nil { + return errors.Wrapf(err, "error reading Containers") + } + for _, ctr := range containers { + ctrState, err := ctr.State() + if ctrState == libpod.ContainerStateRunning || err != nil { + continue + } + + if err = unmountContainer(ctr); err != nil { + if lastError != nil { + logrus.Error(lastError) + } + lastError = errors.Wrapf(err, "%s %s", umountContainerErrStr, ctr.ID()) + continue + } + fmt.Printf("%s\n", ctr.ID()) + } } + return lastError +} - return ctr.Unmount() +func unmountContainer(ctr *libpod.Container) error { + if mounted, err := ctr.Mounted(); mounted { + return ctr.Unmount() + } else { + return err + } + return errors.Errorf("container is not mounted") } |