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