@@ -9,19 +9,34 @@ import (
99 "sync"
1010)
1111
12+ const (
13+ NfsOptions = "nfsopts"
14+ DefaultNfsV3 = "port=2049,nolock,proto=tcp"
15+ )
16+
1217type nfsDriver struct {
1318 root string
1419 version int
1520 mountm * mountManager
1621 m * sync.Mutex
22+ opts map [string ]string
1723}
1824
19- func NewNFSDriver (root string , version int ) nfsDriver {
25+ var (
26+ EmptyMap = map [string ]string {}
27+ )
28+
29+
30+ func NewNFSDriver (root string , version int , options string ) nfsDriver {
2031 d := nfsDriver {
2132 root : root ,
2233 version : version ,
2334 mountm : NewVolumeManager (),
2435 m : & sync.Mutex {},
36+ opts : map [string ]string {},
37+ }
38+ if len (options ) > 0 {
39+ d .opts [NfsOptions ] = options
2540 }
2641 return d
2742}
@@ -74,7 +89,7 @@ func (n nfsDriver) Mount(r volume.Request) volume.Response {
7489 return volume.Response {Err : err .Error ()}
7590 }
7691
77- if err := mountVolume (source , dest , n .version ); err != nil {
92+ if err := n . mountVolume (source , dest , n .version ); err != nil {
7893 return volume.Response {Err : err .Error ()}
7994 }
8095 n .mountm .Add (dest , r .Name )
@@ -115,14 +130,42 @@ func (n nfsDriver) fixSource(name string) string {
115130 return strings .Join (source , "/" )
116131}
117132
118- func mountVolume (source , dest string , version int ) error {
133+ func ( n nfsDriver ) mountVolume (source , dest string , version int ) error {
119134 var cmd string
135+
136+ options := n .mountOptions (n .mountm .GetOptions (dest ))
137+ opts := ""
138+ if val , ok := options [NfsOptions ]; ok {
139+ opts = val
140+ }
120141 switch version {
121142 case 3 :
122- cmd = fmt .Sprintf ("mount -o port=2049,nolock,proto=tcp %s %s" , source , dest )
143+ if len (opts ) < 1 {
144+ opts = DefaultNfsV3
145+ }
146+ cmd = fmt .Sprintf ("mount -o %s %s %s" , opts , source , dest )
123147 default :
124- cmd = fmt .Sprintf ("mount -t nfs4 %s %s" , source , dest )
148+ if len (opts ) > 0 {
149+ cmd = fmt .Sprintf ("mount -t nfs4 -o %s %s %s" , opts , source , dest )
150+ } else {
151+ cmd = fmt .Sprintf ("mount -t nfs4 %s %s" , source , dest )
152+ }
125153 }
126154 log .Debugf ("exec: %s\n " , cmd )
127155 return run (cmd )
128156}
157+
158+ func (n nfsDriver ) mountOptions (src map [string ]string ) map [string ]string {
159+ if (len (n .opts ) == 0 && len (src ) == 0 ) {
160+ return EmptyMap
161+ }
162+
163+ dst := map [string ]string {}
164+ for k , v := range n .opts {
165+ dst [k ] = v
166+ }
167+ for k , v := range src {
168+ dst [k ] = v
169+ }
170+ return dst
171+ }
0 commit comments