diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2020-10-29 13:28:01 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2020-11-04 13:52:08 -0500 |
commit | 6ca705bf1af6fd516b14ab043dc922e55eeaf832 (patch) | |
tree | 02cee3832aa7aea4a40913bb9bcba28a0054174e /libpod/runtime_ctr.go | |
parent | ab273a9cbd08e25e3794c606a863644eb3a06e30 (diff) | |
download | podman-6ca705bf1af6fd516b14ab043dc922e55eeaf832.tar.gz podman-6ca705bf1af6fd516b14ab043dc922e55eeaf832.tar.bz2 podman-6ca705bf1af6fd516b14ab043dc922e55eeaf832.zip |
Add support for mounting external containers
Continue progress on use of external containers.
This PR adds the ability to mount, umount and list the
storage containers whether they are in libpod or not.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r-- | libpod/runtime_ctr.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index de73a9ff3..c84268889 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -918,6 +918,56 @@ func (r *Runtime) PruneContainers(filterFuncs []ContainerFilter) (map[string]int return prunedContainers, pruneErrors, nil } +// MountStorageContainer mounts the storage container's root filesystem +func (r *Runtime) MountStorageContainer(id string) (string, error) { + if _, err := r.GetContainer(id); err == nil { + return "", errors.Wrapf(define.ErrCtrExists, "ctr %s is a libpod container", id) + } + container, err := r.store.Container(id) + if err != nil { + return "", err + } + mountPoint, err := r.store.Mount(container.ID, "") + if err != nil { + return "", errors.Wrapf(err, "error mounting storage for container %s", id) + } + return mountPoint, nil +} + +// UnmountStorageContainer unmounts the storage container's root filesystem +func (r *Runtime) UnmountStorageContainer(id string, force bool) (bool, error) { + if _, err := r.GetContainer(id); err == nil { + return false, errors.Wrapf(define.ErrCtrExists, "ctr %s is a libpod container", id) + } + container, err := r.store.Container(id) + if err != nil { + return false, err + } + return r.store.Unmount(container.ID, force) +} + +// MountedStorageContainer returns whether a storage container is mounted +// along with the mount path +func (r *Runtime) IsStorageContainerMounted(id string) (bool, string, error) { + var path string + if _, err := r.GetContainer(id); err == nil { + return false, "", errors.Wrapf(define.ErrCtrExists, "ctr %s is a libpod container", id) + } + + mountCnt, err := r.storageService.MountedContainerImage(id) + if err != nil { + return false, "", err + } + mounted := mountCnt > 0 + if mounted { + path, err = r.storageService.GetMountpoint(id) + if err != nil { + return false, "", err + } + } + return mounted, path, nil +} + // StorageContainers returns a list of containers from containers/storage that // are not currently known to Podman. func (r *Runtime) StorageContainers() ([]storage.Container, error) { |