Skip to content

Commit

Permalink
Initial support for NFS only to create directories within root share …
Browse files Browse the repository at this point in the history
…based on datavol name - Issue #72
  • Loading branch information
gondor committed Oct 4, 2016
1 parent c75ef01 commit 5ac6b08
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 0.20
VERSION = 0.30
GO_FMT = gofmt -s -w -l .
GO_XC = goxc -os="linux" -bc="linux,amd64" -tasks-="rmbin"

Expand Down
5 changes: 5 additions & 0 deletions netshare/drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ func (v volumeDriver) Create(r volume.Request) volume.Response {
if err := createDest(dest); err != nil {
return volume.Response{Err: err.Error()}
}

v.mountm.Create(r.Name, dest, r.Options)
//if v.mountm.GetOption(r.Name, ShareOpt) != "" && v.mountm.GetOptionAsBool(r.Name, CreateOpt) {
// log.Debugf("Create volume -> name: %s, creating option found, creating: %s", r.Name, r.Options)
//
//}
return volume.Response{}
}

Expand Down
17 changes: 15 additions & 2 deletions netshare/drivers/mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"errors"
log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
"strings"
)

const (
ShareOpt = "share"
CreateOpt = "create"
)

type mount struct {
Expand Down Expand Up @@ -66,6 +68,14 @@ func (m *mountManager) GetOption(name, key string) string {
return ""
}

func (m *mountManager) GetOptionAsBool(name, key string) bool {
rv := strings.ToLower(m.GetOption(name, key))
if rv == "yes" || rv == "true" {
return true
}
return false
}

func (m *mountManager) IsActiveMount(name string) bool {
c, found := m.mounts[name]
return found && c.connections > 0
Expand All @@ -88,12 +98,15 @@ func (m *mountManager) Add(name, hostdir string) {
}
}

func (m *mountManager) Create(name, hostdir string, opts map[string]string) {
func (m *mountManager) Create(name, hostdir string, opts map[string]string) *mount {
c, found := m.mounts[name]
if found && c.connections > 0 {
c.opts = opts
return c
} else {
m.mounts[name] = &mount{name: name, hostdir: hostdir, managed: true, opts: opts, connections: 0}
mnt := &mount{name: name, hostdir: hostdir, managed: true, opts: opts, connections: 0}
m.mounts[name] = mnt
return mnt
}
}

Expand Down
13 changes: 13 additions & 0 deletions netshare/drivers/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/docker/go-plugins-helpers/volume"
"os"
"strings"
"path/filepath"
)

const (
Expand Down Expand Up @@ -40,6 +41,8 @@ func (n nfsDriver) Mount(r volume.MountRequest) volume.Response {
log.Debugf("Entering Mount: %v", r)
n.m.Lock()
defer n.m.Unlock()


hostdir := mountpoint(n.root, r.Name)
source := n.fixSource(r.Name, r.ID)

Expand All @@ -63,6 +66,16 @@ func (n nfsDriver) Mount(r volume.MountRequest) volume.Response {
return volume.Response{Err: err.Error()}
}
n.mountm.Add(r.Name, hostdir)

if n.mountm.GetOption(r.Name, ShareOpt) != "" && n.mountm.GetOptionAsBool(r.Name, CreateOpt) {
log.Infof("Mount: Share and Create options enabled - using %s as sub-dir mount", r.Name)
datavol := filepath.Join(hostdir, r.Name)
if err := createDest(filepath.Join(hostdir, r.Name)); err != nil {
return volume.Response{Err: err.Error()}
}
hostdir = datavol
}

return volume.Response{Mountpoint: hostdir}
}

Expand Down
4 changes: 2 additions & 2 deletions netshare/drivers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func createDest(dest string) error {
return nil
}

func mountpoint(root, name string) string {
return filepath.Join(root, name)
func mountpoint(elem ...string) string {
return filepath.Join(elem...)
}

func run(cmd string) error {
Expand Down

0 comments on commit 5ac6b08

Please sign in to comment.