Skip to content

Commit 5ac6b08

Browse files
committed
Initial support for NFS only to create directories within root share based on datavol name - Issue #72
1 parent c75ef01 commit 5ac6b08

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = 0.20
1+
VERSION = 0.30
22
GO_FMT = gofmt -s -w -l .
33
GO_XC = goxc -os="linux" -bc="linux,amd64" -tasks-="rmbin"
44

netshare/drivers/driver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ func (v volumeDriver) Create(r volume.Request) volume.Response {
3232
if err := createDest(dest); err != nil {
3333
return volume.Response{Err: err.Error()}
3434
}
35+
3536
v.mountm.Create(r.Name, dest, r.Options)
37+
//if v.mountm.GetOption(r.Name, ShareOpt) != "" && v.mountm.GetOptionAsBool(r.Name, CreateOpt) {
38+
// log.Debugf("Create volume -> name: %s, creating option found, creating: %s", r.Name, r.Options)
39+
//
40+
//}
3641
return volume.Response{}
3742
}
3843

netshare/drivers/mounts.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"errors"
55
log "github.com/Sirupsen/logrus"
66
"github.com/docker/go-plugins-helpers/volume"
7+
"strings"
78
)
89

910
const (
1011
ShareOpt = "share"
12+
CreateOpt = "create"
1113
)
1214

1315
type mount struct {
@@ -66,6 +68,14 @@ func (m *mountManager) GetOption(name, key string) string {
6668
return ""
6769
}
6870

71+
func (m *mountManager) GetOptionAsBool(name, key string) bool {
72+
rv := strings.ToLower(m.GetOption(name, key))
73+
if rv == "yes" || rv == "true" {
74+
return true
75+
}
76+
return false
77+
}
78+
6979
func (m *mountManager) IsActiveMount(name string) bool {
7080
c, found := m.mounts[name]
7181
return found && c.connections > 0
@@ -88,12 +98,15 @@ func (m *mountManager) Add(name, hostdir string) {
8898
}
8999
}
90100

91-
func (m *mountManager) Create(name, hostdir string, opts map[string]string) {
101+
func (m *mountManager) Create(name, hostdir string, opts map[string]string) *mount {
92102
c, found := m.mounts[name]
93103
if found && c.connections > 0 {
94104
c.opts = opts
105+
return c
95106
} else {
96-
m.mounts[name] = &mount{name: name, hostdir: hostdir, managed: true, opts: opts, connections: 0}
107+
mnt := &mount{name: name, hostdir: hostdir, managed: true, opts: opts, connections: 0}
108+
m.mounts[name] = mnt
109+
return mnt
97110
}
98111
}
99112

netshare/drivers/nfs.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/docker/go-plugins-helpers/volume"
77
"os"
88
"strings"
9+
"path/filepath"
910
)
1011

1112
const (
@@ -40,6 +41,8 @@ func (n nfsDriver) Mount(r volume.MountRequest) volume.Response {
4041
log.Debugf("Entering Mount: %v", r)
4142
n.m.Lock()
4243
defer n.m.Unlock()
44+
45+
4346
hostdir := mountpoint(n.root, r.Name)
4447
source := n.fixSource(r.Name, r.ID)
4548

@@ -63,6 +66,16 @@ func (n nfsDriver) Mount(r volume.MountRequest) volume.Response {
6366
return volume.Response{Err: err.Error()}
6467
}
6568
n.mountm.Add(r.Name, hostdir)
69+
70+
if n.mountm.GetOption(r.Name, ShareOpt) != "" && n.mountm.GetOptionAsBool(r.Name, CreateOpt) {
71+
log.Infof("Mount: Share and Create options enabled - using %s as sub-dir mount", r.Name)
72+
datavol := filepath.Join(hostdir, r.Name)
73+
if err := createDest(filepath.Join(hostdir, r.Name)); err != nil {
74+
return volume.Response{Err: err.Error()}
75+
}
76+
hostdir = datavol
77+
}
78+
6679
return volume.Response{Mountpoint: hostdir}
6780
}
6881

netshare/drivers/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func createDest(dest string) error {
2525
return nil
2626
}
2727

28-
func mountpoint(root, name string) string {
29-
return filepath.Join(root, name)
28+
func mountpoint(elem ...string) string {
29+
return filepath.Join(elem...)
3030
}
3131

3232
func run(cmd string) error {

0 commit comments

Comments
 (0)