github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podman/umount.go (about) 1 package main 2 3 import ( 4 "github.com/containers/libpod/cmd/podman/cliconfig" 5 "github.com/containers/libpod/pkg/adapter" 6 "github.com/pkg/errors" 7 "github.com/spf13/cobra" 8 ) 9 10 var ( 11 umountCommand cliconfig.UmountValues 12 13 description = `Container storage increments a mount counter each time a container is mounted. 14 15 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. 16 17 An unmount can be forced with the --force flag. 18 ` 19 _umountCommand = &cobra.Command{ 20 Use: "umount [flags] CONTAINER [CONTAINER...]", 21 Aliases: []string{"unmount"}, 22 Short: "Unmounts working container's root filesystem", 23 Long: description, 24 RunE: func(cmd *cobra.Command, args []string) error { 25 umountCommand.InputArgs = args 26 umountCommand.GlobalFlags = MainGlobalOpts 27 umountCommand.Remote = remoteclient 28 return umountCmd(&umountCommand) 29 }, 30 Args: func(cmd *cobra.Command, args []string) error { 31 return checkAllLatestAndCIDFile(cmd, args, false, false) 32 }, 33 Example: `podman umount ctrID 34 podman umount ctrID1 ctrID2 ctrID3 35 podman umount --all`, 36 } 37 ) 38 39 func init() { 40 umountCommand.Command = _umountCommand 41 umountCommand.SetHelpTemplate(HelpTemplate()) 42 umountCommand.SetUsageTemplate(UsageTemplate()) 43 flags := umountCommand.Flags() 44 flags.BoolVarP(&umountCommand.All, "all", "a", false, "Umount all of the currently mounted containers") 45 flags.BoolVarP(&umountCommand.Force, "force", "f", false, "Force the complete umount all of the currently mounted containers") 46 flags.BoolVarP(&umountCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of") 47 markFlagHiddenForRemoteClient("latest", flags) 48 } 49 50 func umountCmd(c *cliconfig.UmountValues) error { 51 runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand) 52 if err != nil { 53 return errors.Wrapf(err, "error creating runtime") 54 } 55 defer runtime.DeferredShutdown(false) 56 57 ok, failures, err := runtime.UmountRootFilesystems(getContext(), c) 58 if err != nil { 59 return err 60 } 61 return printCmdResults(ok, failures) 62 }