summaryrefslogtreecommitdiff
path: root/libpod/image/image.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-07-29 04:30:01 -0400
committerGitHub <noreply@github.com>2020-07-29 04:30:01 -0400
commit7f0c0941e84eece3d0e6cc62acc257e1ed33ef2a (patch)
tree3a1fd54f215a73957c21d1b8817b082edd79e473 /libpod/image/image.go
parent539bb4c59208c9369cb034aa458b3ba89b8bdd3b (diff)
parent6979d140f1c531fd32e885542be27407105ebf90 (diff)
downloadpodman-7f0c0941e84eece3d0e6cc62acc257e1ed33ef2a.tar.gz
podman-7f0c0941e84eece3d0e6cc62acc257e1ed33ef2a.tar.bz2
podman-7f0c0941e84eece3d0e6cc62acc257e1ed33ef2a.zip
Merge pull request #6851 from rhatdan/mount
Add podman image mount
Diffstat (limited to 'libpod/image/image.go')
-rw-r--r--libpod/image/image.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go
index 14ffad4bf..8b2aa318f 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -1593,6 +1593,63 @@ func (i *Image) newImageEvent(status events.Status) {
}
}
+// Mount mounts a image's filesystem on the host
+// The path where the image has been mounted is returned
+func (i *Image) Mount(options []string, mountLabel string) (string, error) {
+ defer i.newImageEvent(events.Mount)
+ return i.mount(options, mountLabel)
+}
+
+// Unmount unmounts a image's filesystem on the host
+func (i *Image) Unmount(force bool) error {
+ defer i.newImageEvent(events.Unmount)
+ return i.unmount(force)
+}
+
+// Mounted returns whether the image is mounted and the path it is mounted
+// at (if it is mounted).
+// If the image is not mounted, no error is returned, and the mountpoint
+// will be set to "".
+func (i *Image) Mounted() (bool, string, error) {
+ mountedTimes, err := i.imageruntime.store.Mounted(i.TopLayer())
+ if err != nil {
+ return false, "", err
+ }
+
+ if mountedTimes > 0 {
+ layer, err := i.imageruntime.store.Layer(i.TopLayer())
+ if err != nil {
+ return false, "", err
+ }
+ return true, layer.MountPoint, nil
+ }
+
+ return false, "", nil
+}
+
+// mount mounts the container's root filesystem
+func (i *Image) mount(options []string, mountLabel string) (string, error) {
+ mountPoint, err := i.imageruntime.store.MountImage(i.ID(), options, mountLabel)
+ if err != nil {
+ return "", errors.Wrapf(err, "error mounting storage for image %s", i.ID())
+ }
+ mountPoint, err = filepath.EvalSymlinks(mountPoint)
+ if err != nil {
+ return "", errors.Wrapf(err, "error resolving storage path for image %s", i.ID())
+ }
+ return mountPoint, nil
+}
+
+// unmount unmounts the image's root filesystem
+func (i *Image) unmount(force bool) error {
+ // Also unmount storage
+ if _, err := i.imageruntime.store.UnmountImage(i.ID(), force); err != nil {
+ return errors.Wrapf(err, "error unmounting image %s root filesystem", i.ID())
+ }
+
+ return nil
+}
+
// LayerInfo keeps information of single layer
type LayerInfo struct {
// Layer ID