@@ -74,7 +74,7 @@ func (d *sshfsDriver) saveState() {
7474 }
7575}
7676
77- func (d * sshfsDriver ) Create (r volume.Request ) volume. Response {
77+ func (d * sshfsDriver ) Create (r * volume.CreateRequest ) error {
7878 logrus .WithField ("method" , "create" ).Debugf ("%#v" , r )
7979
8080 d .Lock ()
@@ -92,131 +92,131 @@ func (d *sshfsDriver) Create(r volume.Request) volume.Response {
9292 case "allow_other" :
9393 v .AllowOther = true
9494 default :
95- return responseError ( fmt . Sprintf ( "unknown option %q=%q" , key , val ) )
95+ return logError ( "unknown option %q=%q" , key , val )
9696 }
9797 }
9898
9999 if v .Sshcmd == "" {
100- return responseError ("'sshcmd' option required" )
100+ return logError ("'sshcmd' option required" )
101101 }
102102 v .Mountpoint = filepath .Join (d .root , fmt .Sprintf ("%x" , md5 .Sum ([]byte (v .Sshcmd ))))
103103
104104 d .volumes [r .Name ] = v
105105
106106 d .saveState ()
107107
108- return volume. Response {}
108+ return nil
109109}
110110
111- func (d * sshfsDriver ) Remove (r volume.Request ) volume. Response {
111+ func (d * sshfsDriver ) Remove (r * volume.RemoveRequest ) error {
112112 logrus .WithField ("method" , "remove" ).Debugf ("%#v" , r )
113113
114114 d .Lock ()
115115 defer d .Unlock ()
116116
117117 v , ok := d .volumes [r .Name ]
118118 if ! ok {
119- return responseError ( fmt . Sprintf ( "volume %s not found" , r .Name ) )
119+ return logError ( "volume %s not found" , r .Name )
120120 }
121121
122122 if v .connections != 0 {
123- return responseError ( fmt . Sprintf ( "volume %s is currently used by a container" , r .Name ) )
123+ return logError ( "volume %s is currently used by a container" , r .Name )
124124 }
125125 if err := os .RemoveAll (v .Mountpoint ); err != nil {
126- return responseError (err .Error ())
126+ return logError (err .Error ())
127127 }
128128 delete (d .volumes , r .Name )
129129 d .saveState ()
130- return volume. Response {}
130+ return nil
131131}
132132
133- func (d * sshfsDriver ) Path (r volume.Request ) volume.Response {
133+ func (d * sshfsDriver ) Path (r * volume.PathRequest ) ( * volume.PathResponse , error ) {
134134 logrus .WithField ("method" , "path" ).Debugf ("%#v" , r )
135135
136136 d .RLock ()
137137 defer d .RUnlock ()
138138
139139 v , ok := d .volumes [r .Name ]
140140 if ! ok {
141- return responseError ( fmt . Sprintf ("volume %s not found" , r .Name ) )
141+ return & volume. PathResponse {}, logError ("volume %s not found" , r .Name )
142142 }
143143
144- return volume.Response {Mountpoint : v .Mountpoint }
144+ return & volume.PathResponse {Mountpoint : v .Mountpoint }, nil
145145}
146146
147- func (d * sshfsDriver ) Mount (r volume.MountRequest ) volume.Response {
147+ func (d * sshfsDriver ) Mount (r * volume.MountRequest ) ( * volume.MountResponse , error ) {
148148 logrus .WithField ("method" , "mount" ).Debugf ("%#v" , r )
149149
150150 d .Lock ()
151151 defer d .Unlock ()
152152
153153 v , ok := d .volumes [r .Name ]
154154 if ! ok {
155- return responseError ( fmt . Sprintf ("volume %s not found" , r .Name ) )
155+ return & volume. MountResponse {}, logError ("volume %s not found" , r .Name )
156156 }
157157
158158 if v .connections == 0 {
159159 fi , err := os .Lstat (v .Mountpoint )
160160 if os .IsNotExist (err ) {
161161 if err := os .MkdirAll (v .Mountpoint , 0755 ); err != nil {
162- return responseError (err .Error ())
162+ return & volume. MountResponse {}, logError (err .Error ())
163163 }
164164 } else if err != nil {
165- return responseError (err .Error ())
165+ return & volume. MountResponse {}, logError (err .Error ())
166166 }
167167
168168 if fi != nil && ! fi .IsDir () {
169- return responseError ( fmt . Sprintf ("%v already exist and it's not a directory" , v .Mountpoint ) )
169+ return & volume. MountResponse {}, logError ("%v already exist and it's not a directory" , v .Mountpoint )
170170 }
171171
172172 if err := d .mountVolume (v ); err != nil {
173- return responseError (err .Error ())
173+ return & volume. MountResponse {}, logError (err .Error ())
174174 }
175175 }
176176
177177 v .connections ++
178178
179- return volume.Response {Mountpoint : v .Mountpoint }
179+ return & volume.MountResponse {Mountpoint : v .Mountpoint }, nil
180180}
181181
182- func (d * sshfsDriver ) Unmount (r volume.UnmountRequest ) volume. Response {
182+ func (d * sshfsDriver ) Unmount (r * volume.UnmountRequest ) error {
183183 logrus .WithField ("method" , "unmount" ).Debugf ("%#v" , r )
184184
185185 d .Lock ()
186186 defer d .Unlock ()
187187 v , ok := d .volumes [r .Name ]
188188 if ! ok {
189- return responseError ( fmt . Sprintf ( "volume %s not found" , r .Name ) )
189+ return logError ( "volume %s not found" , r .Name )
190190 }
191191
192192 v .connections --
193193
194194 if v .connections <= 0 {
195195 if err := d .unmountVolume (v .Mountpoint ); err != nil {
196- return responseError (err .Error ())
196+ return logError (err .Error ())
197197 }
198198 v .connections = 0
199199 }
200200
201- return volume. Response {}
201+ return nil
202202}
203203
204- func (d * sshfsDriver ) Get (r volume.Request ) volume.Response {
204+ func (d * sshfsDriver ) Get (r * volume.GetRequest ) ( * volume.GetResponse , error ) {
205205 logrus .WithField ("method" , "get" ).Debugf ("%#v" , r )
206206
207207 d .Lock ()
208208 defer d .Unlock ()
209209
210210 v , ok := d .volumes [r .Name ]
211211 if ! ok {
212- return responseError ( fmt . Sprintf ("volume %s not found" , r .Name ) )
212+ return & volume. GetResponse {}, logError ("volume %s not found" , r .Name )
213213 }
214214
215- return volume.Response {Volume : & volume.Volume {Name : r .Name , Mountpoint : v .Mountpoint }}
215+ return & volume.GetResponse {Volume : & volume.Volume {Name : r .Name , Mountpoint : v .Mountpoint }}, nil
216216}
217217
218- func (d * sshfsDriver ) List (r volume. Request ) volume.Response {
219- logrus .WithField ("method" , "list" ).Debugf ("%#v" , r )
218+ func (d * sshfsDriver ) List () ( * volume.ListResponse , error ) {
219+ logrus .WithField ("method" , "list" ).Debugf ("" )
220220
221221 d .Lock ()
222222 defer d .Unlock ()
@@ -225,13 +225,13 @@ func (d *sshfsDriver) List(r volume.Request) volume.Response {
225225 for name , v := range d .volumes {
226226 vols = append (vols , & volume.Volume {Name : name , Mountpoint : v .Mountpoint })
227227 }
228- return volume.Response {Volumes : vols }
228+ return & volume.ListResponse {Volumes : vols }, nil
229229}
230230
231- func (d * sshfsDriver ) Capabilities (r volume. Request ) volume.Response {
232- logrus .WithField ("method" , "capabilities" ).Debugf ("%#v" , r )
231+ func (d * sshfsDriver ) Capabilities () * volume.CapabilitiesResponse {
232+ logrus .WithField ("method" , "capabilities" ).Debugf ("" )
233233
234- return volume.Response {Capabilities : volume.Capability {Scope : "local" }}
234+ return & volume.CapabilitiesResponse {Capabilities : volume.Capability {Scope : "local" }}
235235}
236236
237237func (d * sshfsDriver ) mountVolume (v * sshfsVolume ) error {
@@ -256,9 +256,9 @@ func (d *sshfsDriver) unmountVolume(target string) error {
256256 return exec .Command ("sh" , "-c" , cmd ).Run ()
257257}
258258
259- func responseError ( err string ) volume. Response {
260- logrus .Error ( err )
261- return volume. Response { Err : err }
259+ func logError ( format string , args ... interface {}) error {
260+ logrus .Errorf ( format , args ... )
261+ return fmt . Errorf ( format , args )
262262}
263263
264264func main () {
0 commit comments