diff --git a/Makefile b/Makefile index 19bf2e5..7558ac1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SOURCES = driver.go main.go paths.go vstorage.go +SOURCES = driver.go main.go paths.go vstorage.go fstype.go WORKPLACE = $(abspath Godeps/_workspace) BIN = docker-volume-ploop diff --git a/driver.go b/driver.go index a142f29..87ad627 100644 --- a/driver.go +++ b/driver.go @@ -29,10 +29,11 @@ import ( */ type volumeOptions struct { - size uint64 // ploop image size, in kilobytes - mode ploop.ImageMode // ploop image format (expanded/prealloc/raw) - clog uint // cluster block log size in 512-byte sectors - tier int8 // Virtuozzo storage tier (-1: use default) + size uint64 // ploop image size, in kilobytes + mode ploop.ImageMode // ploop image format (expanded/prealloc/raw) + clog uint // cluster block log size in 512-byte sectors + tier int8 // Virtuozzo storage tier (-1: use default) + scope string // Volume scope (global/local/auto) } type mount struct { @@ -87,6 +88,12 @@ func (o *volumeOptions) setTier(str string) error { return nil } +func (o *volumeOptions) setScope(str string) error { + // FIXME: check for local/global/auto? + o.scope = str + return nil +} + func newPloopDriver(home string, opts *volumeOptions) *ploopDriver { // home must exist _, err := os.Stat(home) @@ -98,6 +105,16 @@ func newPloopDriver(home string, opts *volumeOptions) *ploopDriver { } } + // Autodetect scope: global if home is on vstorage, local otherwise + if opts.scope == "auto" { + if isOnVstorage(home) { + opts.scope = "global" + } else { + opts.scope = "local" + } + logrus.Infof("Autodetecting driver scope: %s", opts.scope) + } + d := ploopDriver{ home: home, opts: *opts, @@ -346,6 +363,11 @@ func (d *ploopDriver) Path(r volume.Request) volume.Response { // TODO: check if mounted? return volume.Response{Mountpoint: d.mnt(r.Name)} } +func (d *ploopDriver) Capabilities(r volume.Request) volume.Response { + return volume.Response{ + Capabilities: volume.Capability{ + Scope: d.opts.scope}} +} // Check if a given volume exist func (d *ploopDriver) volExist(name string) (bool, error) { diff --git a/main.go b/main.go index 1aca841..22020a9 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( // Options and their default values var ( home = flag.String("home", "/pcs", "Base directory where volumes are created") + scope = flag.String("scope", "auto", "Volumes scope (local or global)") size = flag.String("size", "16GB", "Default image size") mode = flag.String("mode", "expanded", "Default ploop image mode") clog = flag.String("clog", "0", "Cluster block log size in 512-byte sectors") @@ -52,6 +53,9 @@ func main() { if err := opts.setTier(*tier); err != nil { logrus.Fatalf(err.Error()) } + if err := opts.setScope(*scope); err != nil { + logrus.Fatalf(err.Error()) + } // Set log level if *debug { diff --git a/vstorage.go b/vstorage.go index 0cec6c6..f329196 100644 --- a/vstorage.go +++ b/vstorage.go @@ -74,3 +74,14 @@ func vstorageSetTier(path string, tier int8) error { return err } + +// Check if a file/directory is actually on vstorage +func isOnVstorage(path string) bool { + fs, err := GetFilesystemType(path) + if err != nil { + logrus.Errorf("Can't figure %s fs: %v", err) + return false + } + + return fs == "fuse.vstorage" +}