mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-19 06:47:51 +00:00
The PodmanOptionsKey is never used anywhere so it is pointless to add this. Second having several functions to return the same context makes no sense so fold them all into one. Lastly create the context once and always return the same one instead of having to nil check each time. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
94 lines
3 KiB
Go
94 lines
3 KiB
Go
package containers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/containers/podman/v5/cmd/podman/common"
|
|
"github.com/containers/podman/v5/cmd/podman/registry"
|
|
"github.com/containers/podman/v5/cmd/podman/utils"
|
|
"github.com/containers/podman/v5/cmd/podman/validate"
|
|
"github.com/containers/podman/v5/pkg/domain/entities"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
var (
|
|
description = `Container storage increments a mount counter each time a container is mounted.
|
|
|
|
When a container is unmounted, the mount counter is decremented. The container's root filesystem is physically unmounted only when the mount counter reaches zero indicating no other processes are using the mount.
|
|
|
|
An unmount can be forced with the --force flag.
|
|
`
|
|
unmountCommand = &cobra.Command{
|
|
Annotations: map[string]string{registry.EngineMode: registry.ABIMode},
|
|
Use: "unmount [options] CONTAINER [CONTAINER...]",
|
|
Aliases: []string{"umount"},
|
|
Short: "Unmount working container's root filesystem",
|
|
Long: description,
|
|
RunE: unmount,
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
return validate.CheckAllLatestAndIDFile(cmd, args, false, "")
|
|
},
|
|
ValidArgsFunction: common.AutocompleteContainers,
|
|
Example: `podman unmount ctrID
|
|
podman unmount ctrID1 ctrID2 ctrID3
|
|
podman unmount --all`,
|
|
}
|
|
|
|
containerUnmountCommand = &cobra.Command{
|
|
Annotations: unmountCommand.Annotations,
|
|
Use: unmountCommand.Use,
|
|
Short: unmountCommand.Short,
|
|
Aliases: unmountCommand.Aliases,
|
|
Long: unmountCommand.Long,
|
|
RunE: unmountCommand.RunE,
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
return validate.CheckAllLatestAndIDFile(cmd, args, false, "")
|
|
},
|
|
ValidArgsFunction: common.AutocompleteContainers,
|
|
Example: `podman container unmount ctrID
|
|
podman container unmount ctrID1 ctrID2 ctrID3
|
|
podman container unmount --all`,
|
|
}
|
|
)
|
|
|
|
var (
|
|
unmountOpts entities.ContainerUnmountOptions
|
|
)
|
|
|
|
func unmountFlags(flags *pflag.FlagSet) {
|
|
flags.BoolVarP(&unmountOpts.All, "all", "a", false, "Unmount all of the currently mounted containers")
|
|
flags.BoolVarP(&unmountOpts.Force, "force", "f", false, "Force the complete unmount of the specified mounted containers")
|
|
}
|
|
|
|
func init() {
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Command: unmountCommand,
|
|
})
|
|
unmountFlags(unmountCommand.Flags())
|
|
validate.AddLatestFlag(unmountCommand, &unmountOpts.Latest)
|
|
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Command: containerUnmountCommand,
|
|
Parent: containerCmd,
|
|
})
|
|
unmountFlags(containerUnmountCommand.Flags())
|
|
validate.AddLatestFlag(containerUnmountCommand, &unmountOpts.Latest)
|
|
}
|
|
|
|
func unmount(cmd *cobra.Command, args []string) error {
|
|
var errs utils.OutputErrors
|
|
args = utils.RemoveSlash(args)
|
|
reports, err := registry.ContainerEngine().ContainerUnmount(registry.Context(), args, unmountOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, r := range reports {
|
|
if r.Err == nil {
|
|
fmt.Println(r.Id)
|
|
} else {
|
|
errs = append(errs, r.Err)
|
|
}
|
|
}
|
|
return errs.PrintErrors()
|
|
}
|