forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate devmapper and aufs into the common "graphdriver" framework.
aufs is still enabled by default, no mechanism for switching drivers yet.
- Loading branch information
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/graphdriver" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path" | ||
) | ||
|
||
type AufsDriver struct { | ||
} | ||
|
||
// New returns a new AUFS driver. | ||
// An error is returned if AUFS is not supported. | ||
func New() (*AufsDriver, error) { | ||
return &AufsDriver{}, nil | ||
} | ||
|
||
func (a *AufsDriver) Mount(img graphdriver.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 *AufsDriver) 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 *AufsDriver) Mounted(root string) (bool, error) { | ||
return Mounted(path.Join(root, "rootfs")) | ||
} | ||
|
||
func (a *AufsDriver) 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 graphdriver | ||
|
||
type Image interface { | ||
Layers() ([]string, error) | ||
} | ||
|
||
type Driver 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.