1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

go fmt and aufs support removed

This commit is contained in:
Victor Vieux 2013-09-26 15:40:13 +00:00
parent 5e1d540209
commit ebfa24acb0
11 changed files with 124 additions and 396 deletions

View file

@ -566,7 +566,6 @@ func TestPostCommit(t *testing.T) {
srv := &Server{runtime: runtime}
// Create a container and remove a file
container, err := runtime.Create(
&Config{

View file

@ -102,7 +102,7 @@ func escapeName(name string) string {
// 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.
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 {
filter = []string{"."}
}

View file

@ -34,78 +34,6 @@ func (change *Change) String() string {
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 {
parent *FileInfo
name string
@ -158,7 +86,6 @@ func (info *FileInfo)isDir() bool {
return info.parent == nil || info.stat.Mode&syscall.S_IFDIR == syscall.S_IFDIR
}
func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
if oldInfo == nil {
// add
@ -223,7 +150,6 @@ func (info *FileInfo)addChanges(oldInfo *FileInfo, changes *[]Change) {
*changes = append(*changes, change)
}
}
func (info *FileInfo) Changes(oldInfo *FileInfo) []Change {
@ -234,7 +160,6 @@ func (info *FileInfo)Changes(oldInfo *FileInfo) []Change {
return changes
}
func newRootFileInfo() *FileInfo {
root := &FileInfo{
name: "/",
@ -314,7 +239,6 @@ func applyLayer(root *FileInfo, layer string) error {
return err
}
func collectFileInfo(sourceDir string) (*FileInfo, error) {
root := newRootFileInfo()

View file

@ -25,7 +25,6 @@ func (wrapper *DeviceSetWrapper) wrap(hash string) string {
return hash
}
func (wrapper *DeviceSetWrapper) AddDevice(hash, baseHash string) error {
return wrapper.wrapped.AddDevice(wrapper.wrap(hash), wrapper.wrap(baseHash))
}

136
image.go
View file

@ -8,9 +8,7 @@ import (
"github.com/dotcloud/docker/utils"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
@ -141,31 +139,6 @@ func mountPath(root string) string {
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.
func (image *Image) TarLayer(compression Compression) (Archive, error) {
layerPath, err := image.layer()
@ -411,7 +384,6 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
return err
}
err = ioutil.WriteFile(path.Join(mountDir, ".docker-id"), []byte(image.ID), 0600)
if err != nil {
_ = devices.UnmountDevice(image.ID, mountDir)
@ -461,26 +433,8 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
}
func (image *Image) Mounted(runtime *Runtime, root, rw string) (bool, error) {
method := runtime.GetMountMethod()
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 {
if mounted, _ := image.Mounted(runtime, root, rw); mounted {
@ -492,23 +446,6 @@ func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
return err
}
switch runtime.GetMountMethod() {
case MountMethodNone:
return fmt.Errorf("No supported Mount implementation")
case MountMethodAUFS:
if err := os.Mkdir(rw, 0755); err != nil && !os.IsExist(err) {
return err
}
layers, err := image.layers()
if err != nil {
return err
}
if err := MountAUFS(layers, rw, root); err != nil {
return err
}
case MountMethodDeviceMapper:
devices, err := runtime.GetDeviceSet()
if err != nil {
return err
@ -541,47 +478,14 @@ func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
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
}
func (image *Image) Unmount(runtime *Runtime, root string, id string) error {
switch runtime.GetMountMethod() {
case MountMethodNone:
return fmt.Errorf("No supported Unmount implementation")
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;
return err
}
err = devices.UnmountDevice(id, root)
@ -590,24 +494,9 @@ func (image *Image) Unmount(runtime *Runtime, root string, id string) error {
}
return devices.DeactivateDevice(id)
case MountMethodFilesystem:
return nil
}
return nil
}
func (image *Image) Changes(runtime *Runtime, root, rw, id string) ([]Change, error) {
switch runtime.GetMountMethod() {
case MountMethodAUFS:
layers, err := image.layers()
if err != nil {
return nil, err
}
return ChangesAUFS(layers, rw)
case MountMethodDeviceMapper:
devices, err := runtime.GetDeviceSet()
if err != nil {
return nil, err
@ -635,28 +524,9 @@ func (image *Image) Changes(runtime *Runtime, root, rw, id string) ([]Change, er
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")
}
func (image *Image) ExportChanges(runtime *Runtime, root, rw, id string) (Archive, error) {
switch runtime.GetMountMethod() {
case MountMethodAUFS:
return Tar(rw, Uncompressed)
case MountMethodFilesystem, MountMethodDeviceMapper:
changes, err := image.Changes(runtime, root, rw, id)
if err != nil {
return nil, err
@ -678,10 +548,6 @@ func (image *Image) ExportChanges(runtime *Runtime, root, rw, id string) (Archiv
return TarFilter(root, Uncompressed, files, false, deletions)
}
return nil, fmt.Errorf("No supported Changes implementation")
}
func (image *Image) ShortID() string {
return utils.TruncateID(image.ID)
}

View file

@ -1,40 +1,11 @@
package docker
import (
"fmt"
"github.com/dotcloud/docker/utils"
"os"
"os/exec"
"path/filepath"
"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) {
mntpoint, err := os.Stat(mountpoint)
if err != nil {

View file

@ -17,14 +17,6 @@ import (
)
var defaultDns = []string{"8.8.8.8", "8.8.4.4"}
type MountMethod int
const (
MountMethodNone MountMethod = iota
MountMethodAUFS
MountMethodDeviceMapper
MountMethodFilesystem
)
type Capabilities struct {
MemoryLimit bool
@ -47,7 +39,6 @@ type Runtime struct {
srv *Server
Dns []string
deviceSet DeviceSet
mountMethod MountMethod
}
var sysInitPath string
@ -109,27 +100,6 @@ func hasFilesystemSupport(fstype string) bool {
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) {
if runtime.deviceSet == nil {
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 {
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 {
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 {
return err
}
if runtime.GetMountMethod() == MountMethodDeviceMapper && runtime.deviceSet.HasDevice(id) {
if runtime.deviceSet.HasDevice(id) {
if err := runtime.deviceSet.RemoveDevice(id); err != nil {
return fmt.Errorf("Unable to remove device for %v: %v", id, err)
}

View file

@ -3,8 +3,8 @@ package docker
import (
"bytes"
"fmt"
"github.com/dotcloud/docker/utils"
"github.com/dotcloud/docker/devmapper"
"github.com/dotcloud/docker/utils"
"io"
"io/ioutil"
"log"
@ -75,7 +75,6 @@ func cleanupLast(runtime *Runtime) error {
return nil
}
func layerArchive(tarfile string) (io.Reader, error) {
// FIXME: need to close f somewhere
f, err := os.Open(tarfile)

View file

@ -2,11 +2,11 @@ package docker
import (
"github.com/dotcloud/docker/utils"
"path/filepath"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"testing"
)