github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/varlinkapi/mount.go (about) 1 // +build varlink 2 3 package varlinkapi 4 5 import iopodman "github.com/containers/podman/v2/pkg/varlink" 6 7 // ListContainerMounts ... 8 func (i *VarlinkAPI) ListContainerMounts(call iopodman.VarlinkCall) error { 9 mounts := make(map[string]string) 10 allContainers, err := i.Runtime.GetAllContainers() 11 if err != nil { 12 return call.ReplyErrorOccurred(err.Error()) 13 } 14 for _, container := range allContainers { 15 mounted, mountPoint, err := container.Mounted() 16 if err != nil { 17 return call.ReplyErrorOccurred(err.Error()) 18 } 19 if mounted { 20 mounts[container.ID()] = mountPoint 21 } 22 } 23 return call.ReplyListContainerMounts(mounts) 24 } 25 26 // MountContainer ... 27 func (i *VarlinkAPI) MountContainer(call iopodman.VarlinkCall, name string) error { 28 container, err := i.Runtime.LookupContainer(name) 29 if err != nil { 30 return call.ReplyErrorOccurred(err.Error()) 31 } 32 path, err := container.Mount() 33 if err != nil { 34 return call.ReplyErrorOccurred(err.Error()) 35 } 36 return call.ReplyMountContainer(path) 37 } 38 39 // UnmountContainer ... 40 func (i *VarlinkAPI) UnmountContainer(call iopodman.VarlinkCall, name string, force bool) error { 41 container, err := i.Runtime.LookupContainer(name) 42 if err != nil { 43 return call.ReplyErrorOccurred(err.Error()) 44 } 45 if err := container.Unmount(force); err != nil { 46 return call.ReplyErrorOccurred(err.Error()) 47 } 48 return call.ReplyUnmountContainer() 49 }