summaryrefslogtreecommitdiff
path: root/libpod/container.go
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2017-11-22 10:46:47 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-22 18:23:19 +0000
commit40dce698d3359a6bf89ed954a483454daf2e9fb2 (patch)
treecf74dab73a15c54f021f6a131da1dcfe8cbe3cbe /libpod/container.go
parent34ba0cb8a922347364afaa14f199409ad7dc2451 (diff)
downloadpodman-40dce698d3359a6bf89ed954a483454daf2e9fb2.tar.gz
podman-40dce698d3359a6bf89ed954a483454daf2e9fb2.tar.bz2
podman-40dce698d3359a6bf89ed954a483454daf2e9fb2.zip
Update kpod mount and umount to use the new state
The new state for containers has been added moved kpod mount and umount over to use it Signed-off-by: Urvashi Mohnani <umohnani@redhat.com> Closes: #57 Approved by: rhatdan
Diffstat (limited to 'libpod/container.go')
-rw-r--r--libpod/container.go71
1 files changed, 69 insertions, 2 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 8ad0bb10d..f0a6d58eb 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -194,6 +194,18 @@ func (c *Container) PID() (int, error) {
return c.state.PID, nil
}
+// MountPoint returns the mount point of the continer
+func (c *Container) MountPoint() (string, error) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if err := c.runtime.state.UpdateContainer(c); err != nil {
+ return "", errors.Wrapf(err, "error updating container %s state", c.ID())
+ }
+
+ return c.state.Mountpoint, nil
+}
+
// The path to the container's root filesystem - where the OCI spec will be
// placed, amongst other things
func (c *Container) bundlePath() string {
@@ -463,8 +475,63 @@ func (c *Container) Attach(noStdin bool, keys string, attached chan<- bool) erro
// Mount mounts a container's filesystem on the host
// The path where the container has been mounted is returned
-func (c *Container) Mount() (string, error) {
- return "", ErrNotImplemented
+func (c *Container) Mount(label string) (string, error) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if err := c.syncContainer(); err != nil {
+ return "", err
+ }
+
+ // return mountpoint if container already mounted
+ if c.state.Mounted {
+ return c.state.Mountpoint, nil
+ }
+
+ mountLabel := label
+ if label == "" {
+ mountLabel = c.config.MountLabel
+ }
+ mountPoint, err := c.runtime.store.Mount(c.ID(), mountLabel)
+ if err != nil {
+ return "", err
+ }
+ c.state.Mountpoint = mountPoint
+ c.state.Mounted = true
+ c.config.MountLabel = mountLabel
+
+ if err := c.runtime.state.SaveContainer(c); err != nil {
+ return "", errors.Wrapf(err, "error saving container %s state", c.ID())
+ }
+
+ return mountPoint, nil
+}
+
+// Unmount unmounts a container's filesystem on the host
+func (c *Container) Unmount() error {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if err := c.syncContainer(); err != nil {
+ return err
+ }
+
+ if c.state.State == ContainerStateRunning || c.state.State == ContainerStatePaused {
+ return errors.Wrapf(ErrCtrStateInvalid, "cannot remove storage for container %s as it is running or paused", c.ID())
+ }
+
+ if !c.state.Mounted {
+ return nil
+ }
+
+ err := c.runtime.store.Unmount(c.ID())
+ if err != nil {
+ return errors.Wrapf(err, "error unmounting container %q", c.ID())
+ }
+ c.state.Mountpoint = ""
+ c.state.Mounted = false
+
+ return c.runtime.state.SaveContainer(c)
}
// Pause pauses a container