Skip to content

Commit

Permalink
Issue #22 - add -v to NFS portion of driver, source formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gondor committed Apr 4, 2016
1 parent 3330bad commit 7201cbb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions netshare/drivers/cifs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ func (s cifsDriver) Path(r volume.Request) volume.Response {

func (s cifsDriver) Get(r volume.Request) volume.Response {
log.Debugf("Get for %s is at %s", r.Name, mountpoint(s.root, r.Name))
return volume.Response{ Volume: &volume.Volume{Name: r.Name, Mountpoint: mountpoint(s.root, r.Name)}}
return volume.Response{Volume: &volume.Volume{Name: r.Name, Mountpoint: mountpoint(s.root, r.Name)}}
}

func (s cifsDriver) List(r volume.Request) volume.Response {
log.Debugf("List Volumes")
return volume.Response{ Volumes: s.mountm.GetVolumes(s.root) }
return volume.Response{Volumes: s.mountm.GetVolumes(s.root)}
}

func (s cifsDriver) Mount(r volume.Request) volume.Response {
Expand Down
6 changes: 3 additions & 3 deletions netshare/drivers/efs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func (e efsDriver) Path(r volume.Request) volume.Response {

func (s efsDriver) Get(r volume.Request) volume.Response {
log.Debugf("Get for %s is at %s", r.Name, mountpoint(s.root, r.Name))
return volume.Response{ Volume: &volume.Volume{Name: r.Name, Mountpoint: mountpoint(s.root, r.Name)}}
return volume.Response{Volume: &volume.Volume{Name: r.Name, Mountpoint: mountpoint(s.root, r.Name)}}
}

func (s efsDriver) List(r volume.Request) volume.Response {
log.Debugf("List Volumes")
return volume.Response{ Volumes: s.mountm.GetVolumes(s.root) }
return volume.Response{Volumes: s.mountm.GetVolumes(s.root)}
}

func (e efsDriver) Mount(r volume.Request) volume.Response {
Expand Down Expand Up @@ -162,4 +162,4 @@ func (e efsDriver) mountVolume(source, dest string) error {
cmd := fmt.Sprintf("mount -t nfs4 %s %s", source, dest)
log.Debugf("exec: %s\n", cmd)
return run(cmd)
}
}
1 change: 1 addition & 0 deletions netshare/drivers/mounts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package drivers

import "github.com/docker/go-plugins-helpers/volume"

type mount struct {
Expand Down
26 changes: 16 additions & 10 deletions netshare/drivers/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
NfsOptions = "nfsopts"
NfsOptions = "nfsopts"
DefaultNfsV3 = "port=2049,nolock,proto=tcp"
)

Expand All @@ -19,14 +19,13 @@ type nfsDriver struct {
version int
mountm *mountManager
m *sync.Mutex
opts map[string]string
opts map[string]string
}

var (
EmptyMap = map[string]string{}
)


func NewNFSDriver(root string, version int, options string) nfsDriver {
d := nfsDriver{
root: root,
Expand Down Expand Up @@ -63,12 +62,12 @@ func (n nfsDriver) Path(r volume.Request) volume.Response {

func (s nfsDriver) Get(r volume.Request) volume.Response {
log.Debugf("Get for %s is at %s", r.Name, mountpoint(s.root, r.Name))
return volume.Response{ Volume: &volume.Volume{Name: r.Name, Mountpoint: mountpoint(s.root, r.Name)}}
return volume.Response{Volume: &volume.Volume{Name: r.Name, Mountpoint: mountpoint(s.root, r.Name)}}
}

func (s nfsDriver) List(r volume.Request) volume.Response {
log.Debugf("List Volumes")
return volume.Response{ Volumes: s.mountm.GetVolumes(s.root) }
return volume.Response{Volumes: s.mountm.GetVolumes(s.root)}
}

func (n nfsDriver) Mount(r volume.Request) volume.Response {
Expand Down Expand Up @@ -140,31 +139,38 @@ func (n nfsDriver) mountVolume(source, dest string, version int) error {
if val, ok := options[NfsOptions]; ok {
opts = val
}

mountCmd := "mount"

if log.GetLevel() == log.DebugLevel {
mountCmd = mountCmd + " -v"
}

switch version {
case 3:
log.Debugf("Mounting with NFSv3 - src: %s, dest: %s", source, dest)
if len(opts) < 1 {
opts = DefaultNfsV3
}
cmd = fmt.Sprintf("mount -o %s %s %s", opts, source, dest)
cmd = fmt.Sprintf("%s -o %s %s %s", mountCmd, opts, source, dest)
default:
log.Debugf("Mounting with NFSv4 - src: %s, dest: %s", source, dest)
if len(opts) > 0 {
cmd = fmt.Sprintf("mount -t nfs4 -o %s %s %s", opts, source, dest)
cmd = fmt.Sprintf("%s -t nfs4 -o %s %s %s", mountCmd, opts, source, dest)
} else {
cmd = fmt.Sprintf("mount -t nfs4 %s %s", source, dest)
cmd = fmt.Sprintf("%s -t nfs4 %s %s", mountCmd, source, dest)
}
}
log.Debugf("exec: %s\n", cmd)
return run(cmd)
}

func (n nfsDriver) mountOptions(src map[string]string) map[string]string {
if (len(n.opts) == 0 && len(src) == 0) {
if len(n.opts) == 0 && len(src) == 0 {
return EmptyMap
}

dst := map[string]string {}
dst := map[string]string{}
for k, v := range n.opts {
dst[k] = v
}
Expand Down

0 comments on commit 7201cbb

Please sign in to comment.