From 6fb495bf6ff545753518e9b9ed39c2676230c277 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 10 Apr 2013 16:10:53 -0700 Subject: [PATCH] Move the id of volumes to Container (instead of Container.Config) --- container.go | 24 +++++++++++++++++++----- lxc_template.go | 6 +++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/container.go b/container.go index 2edcd6776b..5de931dc43 100644 --- a/container.go +++ b/container.go @@ -48,6 +48,7 @@ type Container struct { runtime *Runtime waitLock chan struct{} + Volumes map[string]string } type Config struct { @@ -399,6 +400,7 @@ func (container *Container) Start() error { log.Printf("WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.\n") container.Config.MemorySwap = -1 } + container.Volumes = make(map[string]string) // Create the requested volumes volumes for volPath := range container.Config.Volumes { @@ -408,11 +410,7 @@ func (container *Container) Start() error { if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil { return nil } - root, err := c.root() - if err != nil { - return err - } - container.Config.Volumes[volPath] = root + container.Volumes[volPath] = c.Id } } @@ -810,6 +808,22 @@ func (container *Container) RootfsPath() string { return path.Join(container.root, "rootfs") } +func (container *Container) GetVolumes() (map[string]string, error) { + ret := make(map[string]string) + for volPath, id := range container.Volumes { + volume, err := container.runtime.volumes.Get(id) + if err != nil { + return nil, err + } + root, err := volume.root() + if err != nil { + return nil, err + } + ret[volPath] = path.Join(root, "layer") + } + return ret, nil +} + func (container *Container) rwPath() string { return path.Join(container.root, "rw") } diff --git a/lxc_template.go b/lxc_template.go index fd6461bb13..e2be3f21cd 100644 --- a/lxc_template.go +++ b/lxc_template.go @@ -79,9 +79,9 @@ lxc.mount.entry = {{.SysInitPath}} {{$ROOTFS}}/sbin/init none bind,ro 0 0 # In order to get a working DNS environment, mount bind (ro) the host's /etc/resolv.conf into the container lxc.mount.entry = {{.ResolvConfPath}} {{$ROOTFS}}/etc/resolv.conf none bind,ro 0 0 -{{if .Config.Volumes}} -{{range $T0, $T1 := .Config.Volumes}} -lxc.mount.entry = {{$T1}}/layer {{$ROOTFS}}/{{$T0}} none bind,rw 0 0 +{{if .Volumes}} +{{range $virtualPath, $realPath := .GetVolumes}} +lxc.mount.entry = {{$realPath}} {{$ROOTFS}}/{{$virtualPath}} none bind,rw 0 0 {{end}} {{end}}