go fmt and aufs support removed
This commit is contained in:
parent
5e1d540209
commit
ebfa24acb0
11 changed files with 124 additions and 396 deletions
|
@ -56,13 +56,13 @@ type APIContainers struct {
|
||||||
|
|
||||||
func (self *APIContainers) ToLegacy() APIContainersOld {
|
func (self *APIContainers) ToLegacy() APIContainersOld {
|
||||||
return APIContainersOld{
|
return APIContainersOld{
|
||||||
ID: self.ID,
|
ID: self.ID,
|
||||||
Image: self.Image,
|
Image: self.Image,
|
||||||
Command: self.Command,
|
Command: self.Command,
|
||||||
Created: self.Created,
|
Created: self.Created,
|
||||||
Status: self.Status,
|
Status: self.Status,
|
||||||
Ports: displayablePorts(self.Ports),
|
Ports: displayablePorts(self.Ports),
|
||||||
SizeRw: self.SizeRw,
|
SizeRw: self.SizeRw,
|
||||||
SizeRootFs: self.SizeRootFs,
|
SizeRootFs: self.SizeRootFs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -566,7 +566,6 @@ func TestPostCommit(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
|
|
||||||
// Create a container and remove a file
|
// Create a container and remove a file
|
||||||
container, err := runtime.Create(
|
container, err := runtime.Create(
|
||||||
&Config{
|
&Config{
|
||||||
|
|
|
@ -84,13 +84,13 @@ func Tar(path string, compression Compression) (io.Reader, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func escapeName(name string) string {
|
func escapeName(name string) string {
|
||||||
escaped := make([]byte,0)
|
escaped := make([]byte, 0)
|
||||||
for i, c := range []byte(name) {
|
for i, c := range []byte(name) {
|
||||||
if i == 0 && c == '/' {
|
if i == 0 && c == '/' {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// all printable chars except "-" which is 0x2d
|
// all printable chars except "-" which is 0x2d
|
||||||
if (0x20 <= c && c <= 0x7E) && c != 0x2d {
|
if (0x20 <= c && c <= 0x7E) && c != 0x2d {
|
||||||
escaped = append(escaped, c)
|
escaped = append(escaped, c)
|
||||||
} else {
|
} else {
|
||||||
escaped = append(escaped, fmt.Sprintf("\\%03o", c)...)
|
escaped = append(escaped, fmt.Sprintf("\\%03o", c)...)
|
||||||
|
@ -102,7 +102,7 @@ func escapeName(name string) string {
|
||||||
// Tar creates an archive from the directory at `path`, only including files whose relative
|
// Tar creates an archive from the directory at `path`, only including files whose relative
|
||||||
// paths are included in `filter`. If `filter` is nil, then all files are included.
|
// paths are included in `filter`. If `filter` is nil, then all files are included.
|
||||||
func TarFilter(path string, compression Compression, filter []string, recursive bool, createFiles []string) (io.Reader, error) {
|
func TarFilter(path string, compression Compression, filter []string, recursive bool, createFiles []string) (io.Reader, error) {
|
||||||
args := []string{"tar", "--numeric-owner", "-f", "-", "-C", path, "-T", "-",}
|
args := []string{"tar", "--numeric-owner", "-f", "-", "-C", path, "-T", "-"}
|
||||||
if filter == nil {
|
if filter == nil {
|
||||||
filter = []string{"."}
|
filter = []string{"."}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func TarFilter(path string, compression Compression, filter []string, recursive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CmdStream(exec.Command(args[0], args[1:]...), &files, func () {
|
return CmdStream(exec.Command(args[0], args[1:]...), &files, func() {
|
||||||
if tmpDir != "" {
|
if tmpDir != "" {
|
||||||
_ = os.RemoveAll(tmpDir)
|
_ = os.RemoveAll(tmpDir)
|
||||||
}
|
}
|
||||||
|
|
116
changes.go
116
changes.go
|
@ -34,82 +34,10 @@ func (change *Change) String() string {
|
||||||
return fmt.Sprintf("%s %s", kind, change.Path)
|
return fmt.Sprintf("%s %s", kind, change.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ChangesAUFS(layers []string, rw string) ([]Change, error) {
|
|
||||||
var changes []Change
|
|
||||||
err := filepath.Walk(rw, func(path string, f os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebase path
|
|
||||||
path, err = filepath.Rel(rw, path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
path = filepath.Join("/", path)
|
|
||||||
|
|
||||||
// Skip root
|
|
||||||
if path == "/" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip AUFS metadata
|
|
||||||
if matched, err := filepath.Match("/.wh..wh.*", path); err != nil || matched {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
change := Change{
|
|
||||||
Path: path,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find out what kind of modification happened
|
|
||||||
file := filepath.Base(path)
|
|
||||||
// If there is a whiteout, then the file was removed
|
|
||||||
if strings.HasPrefix(file, ".wh.") {
|
|
||||||
originalFile := file[len(".wh."):]
|
|
||||||
change.Path = filepath.Join(filepath.Dir(path), originalFile)
|
|
||||||
change.Kind = ChangeDelete
|
|
||||||
} else {
|
|
||||||
// Otherwise, the file was added
|
|
||||||
change.Kind = ChangeAdd
|
|
||||||
|
|
||||||
// ...Unless it already existed in a top layer, in which case, it's a modification
|
|
||||||
for _, layer := range layers {
|
|
||||||
stat, err := os.Stat(filepath.Join(layer, path))
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
// The file existed in the top layer, so that's a modification
|
|
||||||
|
|
||||||
// However, if it's a directory, maybe it wasn't actually modified.
|
|
||||||
// If you modify /foo/bar/baz, then /foo will be part of the changed files only because it's the parent of bar
|
|
||||||
if stat.IsDir() && f.IsDir() {
|
|
||||||
if f.Size() == stat.Size() && f.Mode() == stat.Mode() && f.ModTime() == stat.ModTime() {
|
|
||||||
// Both directories are the same, don't record the change
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Kind = ChangeModify
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Record change
|
|
||||||
changes = append(changes, change)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return changes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
parent *FileInfo
|
parent *FileInfo
|
||||||
name string
|
name string
|
||||||
stat syscall.Stat_t
|
stat syscall.Stat_t
|
||||||
children map[string]*FileInfo
|
children map[string]*FileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,20 +60,20 @@ func (root *FileInfo) LookUp(path string) *FileInfo {
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *FileInfo)path() string {
|
func (info *FileInfo) path() string {
|
||||||
if info.parent == nil {
|
if info.parent == nil {
|
||||||
return "/"
|
return "/"
|
||||||
}
|
}
|
||||||
return filepath.Join(info.parent.path(), info.name)
|
return filepath.Join(info.parent.path(), info.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *FileInfo)unlink() {
|
func (info *FileInfo) unlink() {
|
||||||
if info.parent != nil {
|
if info.parent != nil {
|
||||||
delete(info.parent.children, info.name)
|
delete(info.parent.children, info.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *FileInfo)Remove(path string) bool {
|
func (info *FileInfo) Remove(path string) bool {
|
||||||
child := info.LookUp(path)
|
child := info.LookUp(path)
|
||||||
if child != nil {
|
if child != nil {
|
||||||
child.unlink()
|
child.unlink()
|
||||||
|
@ -154,12 +82,11 @@ func (info *FileInfo)Remove(path string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *FileInfo)isDir() bool {
|
func (info *FileInfo) isDir() bool {
|
||||||
return info.parent == nil || info.stat.Mode&syscall.S_IFDIR == syscall.S_IFDIR
|
return info.parent == nil || info.stat.Mode&syscall.S_IFDIR == syscall.S_IFDIR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
|
||||||
func (info *FileInfo)addChanges(oldInfo *FileInfo, changes *[]Change) {
|
|
||||||
if oldInfo == nil {
|
if oldInfo == nil {
|
||||||
// add
|
// add
|
||||||
change := Change{
|
change := Change{
|
||||||
|
@ -198,7 +125,7 @@ func (info *FileInfo)addChanges(oldInfo *FileInfo, changes *[]Change) {
|
||||||
oldStat.Gid != newStat.Gid ||
|
oldStat.Gid != newStat.Gid ||
|
||||||
oldStat.Rdev != newStat.Rdev ||
|
oldStat.Rdev != newStat.Rdev ||
|
||||||
// Don't look at size for dirs, its not a good measure of change
|
// Don't look at size for dirs, its not a good measure of change
|
||||||
(oldStat.Size != newStat.Size && oldStat.Mode &syscall.S_IFDIR != syscall.S_IFDIR) ||
|
(oldStat.Size != newStat.Size && oldStat.Mode&syscall.S_IFDIR != syscall.S_IFDIR) ||
|
||||||
oldMtime.Sec != newMtime.Sec ||
|
oldMtime.Sec != newMtime.Sec ||
|
||||||
oldMtime.Usec != newMtime.Usec {
|
oldMtime.Usec != newMtime.Usec {
|
||||||
change := Change{
|
change := Change{
|
||||||
|
@ -223,10 +150,9 @@ func (info *FileInfo)addChanges(oldInfo *FileInfo, changes *[]Change) {
|
||||||
*changes = append(*changes, change)
|
*changes = append(*changes, change)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *FileInfo)Changes(oldInfo *FileInfo) []Change {
|
func (info *FileInfo) Changes(oldInfo *FileInfo) []Change {
|
||||||
var changes []Change
|
var changes []Change
|
||||||
|
|
||||||
info.addChanges(oldInfo, &changes)
|
info.addChanges(oldInfo, &changes)
|
||||||
|
@ -234,10 +160,9 @@ func (info *FileInfo)Changes(oldInfo *FileInfo) []Change {
|
||||||
return changes
|
return changes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func newRootFileInfo() *FileInfo {
|
func newRootFileInfo() *FileInfo {
|
||||||
root := &FileInfo {
|
root := &FileInfo{
|
||||||
name: "/",
|
name: "/",
|
||||||
children: make(map[string]*FileInfo),
|
children: make(map[string]*FileInfo),
|
||||||
}
|
}
|
||||||
return root
|
return root
|
||||||
|
@ -299,11 +224,11 @@ func applyLayer(root *FileInfo, layer string) error {
|
||||||
return fmt.Errorf("collectFileInfo: Unexpectedly no parent for %s", relPath)
|
return fmt.Errorf("collectFileInfo: Unexpectedly no parent for %s", relPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
info := &FileInfo {
|
info := &FileInfo{
|
||||||
name: filepath.Base(relPath),
|
name: filepath.Base(relPath),
|
||||||
children: make(map[string]*FileInfo),
|
children: make(map[string]*FileInfo),
|
||||||
parent: parent,
|
parent: parent,
|
||||||
stat: layerStat,
|
stat: layerStat,
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.children[info.name] = info
|
parent.children[info.name] = info
|
||||||
|
@ -314,7 +239,6 @@ func applyLayer(root *FileInfo, layer string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func collectFileInfo(sourceDir string) (*FileInfo, error) {
|
func collectFileInfo(sourceDir string) (*FileInfo, error) {
|
||||||
root := newRootFileInfo()
|
root := newRootFileInfo()
|
||||||
|
|
||||||
|
@ -339,10 +263,10 @@ func collectFileInfo(sourceDir string) (*FileInfo, error) {
|
||||||
return fmt.Errorf("collectFileInfo: Unexpectedly no parent for %s", relPath)
|
return fmt.Errorf("collectFileInfo: Unexpectedly no parent for %s", relPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
info := &FileInfo {
|
info := &FileInfo{
|
||||||
name: filepath.Base(relPath),
|
name: filepath.Base(relPath),
|
||||||
children: make(map[string]*FileInfo),
|
children: make(map[string]*FileInfo),
|
||||||
parent: parent,
|
parent: parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syscall.Lstat(path, &info.stat); err != nil {
|
if err := syscall.Lstat(path, &info.stat); err != nil {
|
||||||
|
@ -365,7 +289,7 @@ func ChangesLayers(newDir string, layers []string) ([]Change, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
oldRoot := newRootFileInfo()
|
oldRoot := newRootFileInfo()
|
||||||
for i := len(layers)-1; i >= 0; i-- {
|
for i := len(layers) - 1; i >= 0; i-- {
|
||||||
layer := layers[i]
|
layer := layers[i]
|
||||||
if err = applyLayer(oldRoot, layer); err != nil {
|
if err = applyLayer(oldRoot, layer); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -803,10 +803,10 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
||||||
// without exec in go we have to do this horrible shell hack...
|
// without exec in go we have to do this horrible shell hack...
|
||||||
shellString :=
|
shellString :=
|
||||||
"mount --make-rprivate /; exec " +
|
"mount --make-rprivate /; exec " +
|
||||||
utils.ShellQuoteArguments(params)
|
utils.ShellQuoteArguments(params)
|
||||||
|
|
||||||
params = []string{
|
params = []string{
|
||||||
"unshare", "-m", "--", "/bin/sh", "-c", shellString,
|
"unshare", "-m", "--", "/bin/sh", "-c", shellString,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ type DeviceSet interface {
|
||||||
|
|
||||||
type DeviceSetWrapper struct {
|
type DeviceSetWrapper struct {
|
||||||
wrapped DeviceSet
|
wrapped DeviceSet
|
||||||
prefix string
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wrapper *DeviceSetWrapper) wrap(hash string) string {
|
func (wrapper *DeviceSetWrapper) wrap(hash string) string {
|
||||||
|
@ -25,7 +25,6 @@ func (wrapper *DeviceSetWrapper) wrap(hash string) string {
|
||||||
return hash
|
return hash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (wrapper *DeviceSetWrapper) AddDevice(hash, baseHash string) error {
|
func (wrapper *DeviceSetWrapper) AddDevice(hash, baseHash string) error {
|
||||||
return wrapper.wrapped.AddDevice(wrapper.wrap(hash), wrapper.wrap(baseHash))
|
return wrapper.wrapped.AddDevice(wrapper.wrap(hash), wrapper.wrap(baseHash))
|
||||||
}
|
}
|
||||||
|
@ -69,7 +68,7 @@ func (wrapper *DeviceSetWrapper) HasActivatedDevice(hash string) bool {
|
||||||
func NewDeviceSetWrapper(wrapped DeviceSet, prefix string) DeviceSet {
|
func NewDeviceSetWrapper(wrapped DeviceSet, prefix string) DeviceSet {
|
||||||
wrapper := &DeviceSetWrapper{
|
wrapper := &DeviceSetWrapper{
|
||||||
wrapped: wrapped,
|
wrapped: wrapped,
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
}
|
}
|
||||||
return wrapper
|
return wrapper
|
||||||
}
|
}
|
||||||
|
|
290
image.go
290
image.go
|
@ -8,9 +8,7 @@ import (
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -141,31 +139,6 @@ func mountPath(root string) string {
|
||||||
return path.Join(root, "mount")
|
return path.Join(root, "mount")
|
||||||
}
|
}
|
||||||
|
|
||||||
func MountAUFS(ro []string, rw string, target string) error {
|
|
||||||
// FIXME: Now mount the layers
|
|
||||||
rwBranch := fmt.Sprintf("%v=rw", rw)
|
|
||||||
roBranches := ""
|
|
||||||
for _, layer := range ro {
|
|
||||||
roBranches += fmt.Sprintf("%v=ro+wh:", layer)
|
|
||||||
}
|
|
||||||
branches := fmt.Sprintf("br:%v:%v", rwBranch, roBranches)
|
|
||||||
|
|
||||||
branches += ",xino=/dev/shm/aufs.xino"
|
|
||||||
|
|
||||||
//if error, try to load aufs kernel module
|
|
||||||
if err := mount("none", target, "aufs", 0, branches); err != nil {
|
|
||||||
log.Printf("Kernel does not support AUFS, trying to load the AUFS module with modprobe...")
|
|
||||||
if err := exec.Command("modprobe", "aufs").Run(); err != nil {
|
|
||||||
return fmt.Errorf("Unable to load the AUFS module")
|
|
||||||
}
|
|
||||||
log.Printf("...module loaded.")
|
|
||||||
if err := mount("none", target, "aufs", 0, branches); err != nil {
|
|
||||||
return fmt.Errorf("Unable to mount using aufs")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TarLayer returns a tar archive of the image's filesystem layer.
|
// TarLayer returns a tar archive of the image's filesystem layer.
|
||||||
func (image *Image) TarLayer(compression Compression) (Archive, error) {
|
func (image *Image) TarLayer(compression Compression) (Archive, error) {
|
||||||
layerPath, err := image.layer()
|
layerPath, err := image.layer()
|
||||||
|
@ -315,7 +288,7 @@ func (image *Image) applyLayer(layer, target string) error {
|
||||||
syscall.NsecToTimeval(srcStat.Mtim.Nano()),
|
syscall.NsecToTimeval(srcStat.Mtim.Nano()),
|
||||||
}
|
}
|
||||||
|
|
||||||
u := TimeUpdate {
|
u := TimeUpdate{
|
||||||
path: targetPath,
|
path: targetPath,
|
||||||
time: ts,
|
time: ts,
|
||||||
}
|
}
|
||||||
|
@ -335,7 +308,7 @@ func (image *Image) applyLayer(layer, target string) error {
|
||||||
update := updateTimes[i]
|
update := updateTimes[i]
|
||||||
|
|
||||||
O_PATH := 010000000 // Not in syscall yet
|
O_PATH := 010000000 // Not in syscall yet
|
||||||
fd, err := syscall.Open(update.path, syscall.O_RDWR | O_PATH | syscall.O_NOFOLLOW, 0600)
|
fd, err := syscall.Open(update.path, syscall.O_RDWR|O_PATH|syscall.O_NOFOLLOW, 0600)
|
||||||
if err == syscall.EISDIR || err == syscall.ELOOP {
|
if err == syscall.EISDIR || err == syscall.ELOOP {
|
||||||
// O_PATH not supported, use Utimes except on symlinks where Utimes doesn't work
|
// O_PATH not supported, use Utimes except on symlinks where Utimes doesn't work
|
||||||
if err != syscall.ELOOP {
|
if err != syscall.ELOOP {
|
||||||
|
@ -411,7 +384,6 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
err = ioutil.WriteFile(path.Join(mountDir, ".docker-id"), []byte(image.ID), 0600)
|
err = ioutil.WriteFile(path.Join(mountDir, ".docker-id"), []byte(image.ID), 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = devices.UnmountDevice(image.ID, mountDir)
|
_ = devices.UnmountDevice(image.ID, mountDir)
|
||||||
|
@ -461,25 +433,7 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (image *Image) Mounted(runtime *Runtime, root, rw string) (bool, error) {
|
func (image *Image) Mounted(runtime *Runtime, root, rw string) (bool, error) {
|
||||||
method := runtime.GetMountMethod()
|
return Mounted(root)
|
||||||
if method == MountMethodFilesystem {
|
|
||||||
if _, err := os.Stat(rw); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
mountedPath := path.Join(rw, ".fs-mounted")
|
|
||||||
if _, err := os.Stat(mountedPath); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
} else {
|
|
||||||
return Mounted(root)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
|
func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
|
||||||
|
@ -492,195 +446,107 @@ func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch runtime.GetMountMethod() {
|
devices, err := runtime.GetDeviceSet()
|
||||||
case MountMethodNone:
|
if err != nil {
|
||||||
return fmt.Errorf("No supported Mount implementation")
|
return err
|
||||||
|
}
|
||||||
|
err = image.ensureImageDevice(devices)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
case MountMethodAUFS:
|
createdDevice := false
|
||||||
if err := os.Mkdir(rw, 0755); err != nil && !os.IsExist(err) {
|
if !devices.HasDevice(id) {
|
||||||
return err
|
utils.Debugf("Creating device %s for container based on image %s", id, image.ID)
|
||||||
}
|
err = devices.AddDevice(id, image.ID)
|
||||||
layers, err := image.layers()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := MountAUFS(layers, rw, root); err != nil {
|
createdDevice = true
|
||||||
return err
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case MountMethodDeviceMapper:
|
utils.Debugf("Mounting container %s at %s for container", id, root)
|
||||||
devices, err := runtime.GetDeviceSet()
|
err = devices.MountDevice(id, root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if createdDevice {
|
||||||
|
err = ioutil.WriteFile(path.Join(root, ".docker-id"), []byte(id), 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = devices.RemoveDevice(image.ID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = image.ensureImageDevice(devices)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
createdDevice := false
|
|
||||||
if !devices.HasDevice(id) {
|
|
||||||
utils.Debugf("Creating device %s for container based on image %s", id, image.ID)
|
|
||||||
err = devices.AddDevice(id, image.ID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
createdDevice = true
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.Debugf("Mounting container %s at %s for container", id, root)
|
|
||||||
err = devices.MountDevice(id, root)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if createdDevice {
|
|
||||||
err = ioutil.WriteFile(path.Join(root, ".docker-id"), []byte(id), 0600)
|
|
||||||
if err != nil {
|
|
||||||
_ = devices.RemoveDevice(image.ID)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case MountMethodFilesystem:
|
|
||||||
if err := os.Mkdir(rw, 0755); err != nil && !os.IsExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
layers, err := image.layers()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := len(layers)-1; i >= 0; i-- {
|
|
||||||
layer := layers[i]
|
|
||||||
if err = image.applyLayer(layer, root); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mountedPath := path.Join(rw, ".fs-mounted")
|
|
||||||
fo, err := os.Create(mountedPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fo.Close()
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (image *Image) Unmount(runtime *Runtime, root string, id string) error {
|
func (image *Image) Unmount(runtime *Runtime, root string, id string) error {
|
||||||
switch runtime.GetMountMethod() {
|
// Try to deactivate the device as generally there is no use for it anymore
|
||||||
case MountMethodNone:
|
devices, err := runtime.GetDeviceSet()
|
||||||
return fmt.Errorf("No supported Unmount implementation")
|
if err != nil {
|
||||||
|
return err
|
||||||
case MountMethodAUFS:
|
|
||||||
return Unmount(root)
|
|
||||||
|
|
||||||
case MountMethodDeviceMapper:
|
|
||||||
// Try to deactivate the device as generally there is no use for it anymore
|
|
||||||
devices, err := runtime.GetDeviceSet()
|
|
||||||
if err != nil {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = devices.UnmountDevice(id, root)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return devices.DeactivateDevice(id)
|
|
||||||
|
|
||||||
case MountMethodFilesystem:
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
err = devices.UnmountDevice(id, root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return devices.DeactivateDevice(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (image *Image) Changes(runtime *Runtime, root, rw, id string) ([]Change, error) {
|
func (image *Image) Changes(runtime *Runtime, root, rw, id string) ([]Change, error) {
|
||||||
switch runtime.GetMountMethod() {
|
devices, err := runtime.GetDeviceSet()
|
||||||
case MountMethodAUFS:
|
if err != nil {
|
||||||
layers, err := image.layers()
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ChangesAUFS(layers, rw)
|
|
||||||
|
|
||||||
case MountMethodDeviceMapper:
|
|
||||||
devices, err := runtime.GetDeviceSet()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.Mkdir(rw, 0755); err != nil && !os.IsExist(err) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
wasActivated := devices.HasActivatedDevice(image.ID)
|
|
||||||
|
|
||||||
// We re-use rw for the temporary mount of the base image as its
|
|
||||||
// not used by device-mapper otherwise
|
|
||||||
err = devices.MountDevice(image.ID, rw)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
changes, err := ChangesDirs(root, rw)
|
|
||||||
_ = devices.UnmountDevice(image.ID, rw)
|
|
||||||
if !wasActivated {
|
|
||||||
_ = devices.DeactivateDevice(image.ID)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return changes, nil
|
|
||||||
|
|
||||||
case MountMethodFilesystem:
|
|
||||||
layers, err := image.layers()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
changes, err := ChangesLayers(root, layers)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return changes, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("No supported Changes implementation")
|
if err := os.Mkdir(rw, 0755); err != nil && !os.IsExist(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
wasActivated := devices.HasActivatedDevice(image.ID)
|
||||||
|
|
||||||
|
// We re-use rw for the temporary mount of the base image as its
|
||||||
|
// not used by device-mapper otherwise
|
||||||
|
err = devices.MountDevice(image.ID, rw)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
changes, err := ChangesDirs(root, rw)
|
||||||
|
_ = devices.UnmountDevice(image.ID, rw)
|
||||||
|
if !wasActivated {
|
||||||
|
_ = devices.DeactivateDevice(image.ID)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return changes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (image *Image) ExportChanges(runtime *Runtime, root, rw, id string) (Archive, error) {
|
func (image *Image) ExportChanges(runtime *Runtime, root, rw, id string) (Archive, error) {
|
||||||
switch runtime.GetMountMethod() {
|
changes, err := image.Changes(runtime, root, rw, id)
|
||||||
case MountMethodAUFS:
|
if err != nil {
|
||||||
return Tar(rw, Uncompressed)
|
return nil, err
|
||||||
|
|
||||||
case MountMethodFilesystem, MountMethodDeviceMapper:
|
|
||||||
changes, err := image.Changes(runtime, root, rw, id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
files := make([]string, 0)
|
|
||||||
deletions := make([]string, 0)
|
|
||||||
for _, change := range changes {
|
|
||||||
if change.Kind == ChangeModify || change.Kind == ChangeAdd {
|
|
||||||
files = append(files, change.Path)
|
|
||||||
}
|
|
||||||
if change.Kind == ChangeDelete {
|
|
||||||
base := filepath.Base(change.Path)
|
|
||||||
dir := filepath.Dir(change.Path)
|
|
||||||
deletions = append(deletions, filepath.Join(dir, ".wh."+base))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TarFilter(root, Uncompressed, files, false, deletions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("No supported Changes implementation")
|
files := make([]string, 0)
|
||||||
}
|
deletions := make([]string, 0)
|
||||||
|
for _, change := range changes {
|
||||||
|
if change.Kind == ChangeModify || change.Kind == ChangeAdd {
|
||||||
|
files = append(files, change.Path)
|
||||||
|
}
|
||||||
|
if change.Kind == ChangeDelete {
|
||||||
|
base := filepath.Base(change.Path)
|
||||||
|
dir := filepath.Dir(change.Path)
|
||||||
|
deletions = append(deletions, filepath.Join(dir, ".wh."+base))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TarFilter(root, Uncompressed, files, false, deletions)
|
||||||
|
}
|
||||||
|
|
||||||
func (image *Image) ShortID() string {
|
func (image *Image) ShortID() string {
|
||||||
return utils.TruncateID(image.ID)
|
return utils.TruncateID(image.ID)
|
||||||
|
|
29
mount.go
29
mount.go
|
@ -1,40 +1,11 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Unmount(target string) error {
|
|
||||||
if err := exec.Command("auplink", target, "flush").Run(); err != nil {
|
|
||||||
utils.Debugf("[warning]: couldn't run auplink before unmount: %s", err)
|
|
||||||
}
|
|
||||||
if err := syscall.Unmount(target, 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Even though we just unmounted the filesystem, AUFS will prevent deleting the mntpoint
|
|
||||||
// for some time. We'll just keep retrying until it succeeds.
|
|
||||||
for retries := 0; retries < 1000; retries++ {
|
|
||||||
err := os.Remove(target)
|
|
||||||
if err == nil {
|
|
||||||
// rm mntpoint succeeded
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
// mntpoint doesn't exist anymore. Success.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// fmt.Printf("(%v) Remove %v returned: %v\n", retries, target, err)
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("Umount: Failed to umount %v", target)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Mounted(mountpoint string) (bool, error) {
|
func Mounted(mountpoint string) (bool, error) {
|
||||||
mntpoint, err := os.Stat(mountpoint)
|
mntpoint, err := os.Stat(mountpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
34
runtime.go
34
runtime.go
|
@ -17,14 +17,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
var defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
||||||
type MountMethod int
|
|
||||||
|
|
||||||
const (
|
|
||||||
MountMethodNone MountMethod = iota
|
|
||||||
MountMethodAUFS
|
|
||||||
MountMethodDeviceMapper
|
|
||||||
MountMethodFilesystem
|
|
||||||
)
|
|
||||||
|
|
||||||
type Capabilities struct {
|
type Capabilities struct {
|
||||||
MemoryLimit bool
|
MemoryLimit bool
|
||||||
|
@ -47,7 +39,6 @@ type Runtime struct {
|
||||||
srv *Server
|
srv *Server
|
||||||
Dns []string
|
Dns []string
|
||||||
deviceSet DeviceSet
|
deviceSet DeviceSet
|
||||||
mountMethod MountMethod
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var sysInitPath string
|
var sysInitPath string
|
||||||
|
@ -109,27 +100,6 @@ func hasFilesystemSupport(fstype string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runtime *Runtime) GetMountMethod() MountMethod {
|
|
||||||
if runtime.mountMethod == MountMethodNone {
|
|
||||||
// Try to automatically pick a method
|
|
||||||
if hasFilesystemSupport("aufs") {
|
|
||||||
utils.Debugf("Using AUFS backend.")
|
|
||||||
runtime.mountMethod = MountMethodAUFS
|
|
||||||
} else {
|
|
||||||
_ = exec.Command("modprobe", "aufs").Run()
|
|
||||||
if hasFilesystemSupport("aufs") {
|
|
||||||
utils.Debugf("Using AUFS backend.")
|
|
||||||
runtime.mountMethod = MountMethodAUFS
|
|
||||||
} else {
|
|
||||||
utils.Debugf("Using device-mapper backend.")
|
|
||||||
runtime.mountMethod = MountMethodDeviceMapper
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return runtime.mountMethod
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runtime *Runtime) GetDeviceSet() (DeviceSet, error) {
|
func (runtime *Runtime) GetDeviceSet() (DeviceSet, error) {
|
||||||
if runtime.deviceSet == nil {
|
if runtime.deviceSet == nil {
|
||||||
return nil, fmt.Errorf("No device set available")
|
return nil, fmt.Errorf("No device set available")
|
||||||
|
@ -288,7 +258,7 @@ func (runtime *Runtime) Destroy(container *Container) error {
|
||||||
if err := os.RemoveAll(container.root); err != nil {
|
if err := os.RemoveAll(container.root); err != nil {
|
||||||
return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err)
|
return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err)
|
||||||
}
|
}
|
||||||
if runtime.GetMountMethod() == MountMethodDeviceMapper && runtime.deviceSet.HasDevice(container.ID) {
|
if runtime.deviceSet.HasDevice(container.ID) {
|
||||||
if err := runtime.deviceSet.RemoveDevice(container.ID); err != nil {
|
if err := runtime.deviceSet.RemoveDevice(container.ID); err != nil {
|
||||||
return fmt.Errorf("Unable to remove device for %v: %v", container.ID, err)
|
return fmt.Errorf("Unable to remove device for %v: %v", container.ID, err)
|
||||||
}
|
}
|
||||||
|
@ -301,7 +271,7 @@ func (runtime *Runtime) DeleteImage(id string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if runtime.GetMountMethod() == MountMethodDeviceMapper && runtime.deviceSet.HasDevice(id) {
|
if runtime.deviceSet.HasDevice(id) {
|
||||||
if err := runtime.deviceSet.RemoveDevice(id); err != nil {
|
if err := runtime.deviceSet.RemoveDevice(id); err != nil {
|
||||||
return fmt.Errorf("Unable to remove device for %v: %v", id, err)
|
return fmt.Errorf("Unable to remove device for %v: %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package docker
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
"github.com/dotcloud/docker/devmapper"
|
"github.com/dotcloud/docker/devmapper"
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -20,13 +20,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
unitTestImageName = "docker-test-image"
|
unitTestImageName = "docker-test-image"
|
||||||
unitTestImageID = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0
|
unitTestImageID = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0
|
||||||
unitTestNetworkBridge = "testdockbr0"
|
unitTestNetworkBridge = "testdockbr0"
|
||||||
unitTestStoreBase = "/var/lib/docker/unit-tests"
|
unitTestStoreBase = "/var/lib/docker/unit-tests"
|
||||||
unitTestStoreDevicesBase = "/var/lib/docker/unit-tests-devices"
|
unitTestStoreDevicesBase = "/var/lib/docker/unit-tests-devices"
|
||||||
testDaemonAddr = "127.0.0.1:4270"
|
testDaemonAddr = "127.0.0.1:4270"
|
||||||
testDaemonProto = "tcp"
|
testDaemonProto = "tcp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -75,7 +75,6 @@ func cleanupLast(runtime *Runtime) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func layerArchive(tarfile string) (io.Reader, error) {
|
func layerArchive(tarfile string) (io.Reader, error) {
|
||||||
// FIXME: need to close f somewhere
|
// FIXME: need to close f somewhere
|
||||||
f, err := os.Open(tarfile)
|
f, err := os.Open(tarfile)
|
||||||
|
|
|
@ -2,11 +2,11 @@ package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"path/filepath"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue