moby--moby/devmapper/driver.go

78 lines
1.5 KiB
Go
Raw Normal View History

package devmapper
import (
"fmt"
2013-11-04 23:22:34 +00:00
"github.com/dotcloud/docker/graphdriver"
"os"
"path"
)
2013-11-04 23:22:34 +00:00
func init() {
graphdriver.Register("devicemapper", Init)
}
// Placeholder interfaces, to be replaced
// at integration.
// End of placeholder interfaces.
2013-11-04 17:22:43 +00:00
type Driver struct {
*DeviceSet
home string
}
2013-11-04 23:22:34 +00:00
func Init(home string) (graphdriver.Driver, error) {
deviceSet, err := NewDeviceSet(home)
if err != nil {
return nil, err
}
2013-11-04 17:22:43 +00:00
d := &Driver{
DeviceSet: deviceSet,
2013-11-04 23:22:34 +00:00
home: home,
}
2013-11-04 17:22:43 +00:00
return d, nil
}
func (d *Driver) String() string {
return "devicemapper"
}
2013-11-04 17:22:43 +00:00
func (d *Driver) Cleanup() error {
return d.DeviceSet.Shutdown()
}
func (d *Driver) Create(id string, parent string) error {
return d.DeviceSet.AddDevice(id, parent)
}
func (d *Driver) Remove(id string) error {
return d.DeviceSet.RemoveDevice(id)
2013-11-02 21:25:06 +00:00
}
func (d *Driver) Get(id string) (string, error) {
mp := path.Join(d.home, "mnt", id)
if err := d.mount(id, mp); err != nil {
return "", err
}
return mp, nil
}
func (d *Driver) Size(id string) (int64, error) {
return -1, fmt.Errorf("Not implemented")
}
func (d *Driver) mount(id, mountPoint string) error {
// Create the target directories if they don't exist
if err := os.MkdirAll(mountPoint, 0755); err != nil && !os.IsExist(err) {
return err
}
// If mountpoint is already mounted, do nothing
if mounted, err := Mounted(mountPoint); err != nil {
return fmt.Errorf("Error checking mountpoint: %s", err)
} else if mounted {
return nil
}
// Mount the device
return d.DeviceSet.MountDevice(id, mountPoint, false)
}