Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work on moving aufs to a subpackage
- Loading branch information
1 parent
3e7b976
commit 699a107
Showing
10 changed files
with
160 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package aufs | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dotcloud/docker/graphbackend" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path" | ||
) | ||
|
||
type AufsBackend struct { | ||
} | ||
|
||
// Return a new AUFS backend | ||
// An error is returned if AUFS is not supported | ||
func NewBackend() (*AufsBackend, error) { | ||
return &AufsBackend{}, nil | ||
} | ||
|
||
func (a *AufsBackend) Mount(img graphbackend.Image, root string) error { | ||
layers, err := img.Layers() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
target := path.Join(root, "rootfs") | ||
rw := path.Join(root, "rw") | ||
|
||
// Create the target directories if they don't exist | ||
if err := os.Mkdir(target, 0755); err != nil && !os.IsExist(err) { | ||
return err | ||
} | ||
if err := os.Mkdir(rw, 0755); err != nil && !os.IsExist(err) { | ||
return err | ||
} | ||
if err := a.aufsMount(layers, rw, target); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (a *AufsBackend) Unmount(root string) error { | ||
target := path.Join(root, "rootfs") | ||
if _, err := os.Stat(target); err != nil { | ||
if os.IsNotExist(err) { | ||
return nil | ||
} | ||
return err | ||
} | ||
return Unmount(target) | ||
} | ||
|
||
func (a *AufsBackend) Mounted(root string) (bool, error) { | ||
return Mounted(path.Join(root, "rootfs")) | ||
} | ||
|
||
func (a *AufsBackend) aufsMount(ro []string, rw, target string) error { | ||
rwBranch := fmt.Sprintf("%v=rw", rw) | ||
roBranches := "" | ||
for _, layer := range ro { | ||
roBranches += fmt.Sprintf("%v=ro+wh:", layer) | ||
} | ||
branches := fmt.Sprintf("br:%v:%v,xino=/dev/shm/aufs.xino", rwBranch, roBranches) | ||
|
||
//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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package docker | ||
package aufs | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package docker | ||
package aufs | ||
|
||
import "errors" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package docker | ||
package aufs | ||
|
||
import "syscall" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package graphbackend | ||
|
||
type Image interface { | ||
Layers() ([]string, error) | ||
} | ||
|
||
type GraphBackend interface { | ||
// Create(img *Image) error | ||
// Delete(img *Image) error | ||
Mount(img Image, root string) error | ||
Unmount(root string) error | ||
Mounted(root string) (bool, error) | ||
// UnmountAll(img *Image) error | ||
// Changes(img *Image, dest string) ([]Change, error) | ||
// Layer(img *Image, dest string) (Archive, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.