Browse code

graphdriver: change (*Driver).Put signature

There are a couple of drivers that swallow errors that may occur in
their Put() implementation.

This changes the signature of (*Driver).Put for all the drivers implemented.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>

Vincent Batts authored on 2015/01/10 07:14:52
Showing 6 changed files
... ...
@@ -278,7 +278,7 @@ func (a *Driver) Get(id, mountLabel string) (string, error) {
278 278
 	return out, nil
279 279
 }
280 280
 
281
-func (a *Driver) Put(id string) {
281
+func (a *Driver) Put(id string) error {
282 282
 	// Protect the a.active from concurrent access
283 283
 	a.Lock()
284 284
 	defer a.Unlock()
... ...
@@ -293,6 +293,7 @@ func (a *Driver) Put(id string) {
293 293
 		}
294 294
 		delete(a.active, id)
295 295
 	}
296
+	return nil
296 297
 }
297 298
 
298 299
 // Diff produces an archive of the changes between the specified
... ...
@@ -220,9 +220,10 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
220 220
 	return dir, nil
221 221
 }
222 222
 
223
-func (d *Driver) Put(id string) {
223
+func (d *Driver) Put(id string) error {
224 224
 	// Get() creates no runtime resources (like e.g. mounts)
225 225
 	// so this doesn't need to do anything.
226
+	return nil
226 227
 }
227 228
 
228 229
 func (d *Driver) Exists(id string) bool {
... ...
@@ -141,10 +141,12 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
141 141
 	return rootFs, nil
142 142
 }
143 143
 
144
-func (d *Driver) Put(id string) {
145
-	if err := d.DeviceSet.UnmountDevice(id); err != nil {
144
+func (d *Driver) Put(id string) error {
145
+	err := d.DeviceSet.UnmountDevice(id)
146
+	if err != nil {
146 147
 		log.Errorf("Warning: error unmounting device %s: %s", id, err)
147 148
 	}
149
+	return err
148 150
 }
149 151
 
150 152
 func (d *Driver) Exists(id string) bool {
... ...
@@ -40,7 +40,7 @@ type ProtoDriver interface {
40 40
 	Get(id, mountLabel string) (dir string, err error)
41 41
 	// Put releases the system resources for the specified id,
42 42
 	// e.g, unmounting layered filesystem.
43
-	Put(id string)
43
+	Put(id string) error
44 44
 	// Exists returns whether a filesystem layer with the specified
45 45
 	// ID exists on this driver.
46 46
 	Exists(id string) bool
... ...
@@ -299,7 +299,7 @@ func (d *Driver) Get(id string, mountLabel string) (string, error) {
299 299
 	return mount.path, nil
300 300
 }
301 301
 
302
-func (d *Driver) Put(id string) {
302
+func (d *Driver) Put(id string) error {
303 303
 	// Protect the d.active from concurrent access
304 304
 	d.Lock()
305 305
 	defer d.Unlock()
... ...
@@ -307,21 +307,23 @@ func (d *Driver) Put(id string) {
307 307
 	mount := d.active[id]
308 308
 	if mount == nil {
309 309
 		log.Debugf("Put on a non-mounted device %s", id)
310
-		return
310
+		return nil
311 311
 	}
312 312
 
313 313
 	mount.count--
314 314
 	if mount.count > 0 {
315
-		return
315
+		return nil
316 316
 	}
317 317
 
318
+	defer delete(d.active, id)
318 319
 	if mount.mounted {
319
-		if err := syscall.Unmount(mount.path, 0); err != nil {
320
+		err := syscall.Unmount(mount.path, 0)
321
+		if err != nil {
320 322
 			log.Debugf("Failed to unmount %s overlay: %v", id, err)
321 323
 		}
324
+		return err
322 325
 	}
323
-
324
-	delete(d.active, id)
326
+	return nil
325 327
 }
326 328
 
327 329
 func (d *Driver) ApplyDiff(id string, parent string, diff archive.ArchiveReader) (size int64, err error) {
... ...
@@ -83,9 +83,10 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
83 83
 	return dir, nil
84 84
 }
85 85
 
86
-func (d *Driver) Put(id string) {
86
+func (d *Driver) Put(id string) error {
87 87
 	// The vfs driver has no runtime resources (e.g. mounts)
88 88
 	// to clean up, so we don't need anything here
89
+	return nil
89 90
 }
90 91
 
91 92
 func (d *Driver) Exists(id string) bool {