Browse code

Prevent multiple parallel SystemDiskUsage call

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

Kenfe-Mickael Laventure authored on 2017/04/13 05:59:59
Showing 2 changed files
... ...
@@ -111,6 +111,12 @@ type Daemon struct {
111 111
 
112 112
 	seccompProfile     []byte
113 113
 	seccompProfilePath string
114
+
115
+	diskUsageRunning       int32
116
+	containersPruneRunning int32
117
+	volumesPruneRunning    int32
118
+	imagesPruneRunning     int32
119
+	networksPruneRunning   int32
114 120
 }
115 121
 
116 122
 // HasExperimental returns whether the experimental features of the daemon are enabled or not
... ...
@@ -2,6 +2,7 @@ package daemon
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"sync/atomic"
5 6
 
6 7
 	"golang.org/x/net/context"
7 8
 
... ...
@@ -37,6 +38,11 @@ func (daemon *Daemon) getLayerRefs() map[layer.ChainID]int {
37 37
 
38 38
 // SystemDiskUsage returns information about the daemon data disk usage
39 39
 func (daemon *Daemon) SystemDiskUsage(ctx context.Context) (*types.DiskUsage, error) {
40
+	if !atomic.CompareAndSwapInt32(&daemon.diskUsageRunning, 0, 1) {
41
+		return nil, fmt.Errorf("a disk usage operation is already running")
42
+	}
43
+	defer atomic.StoreInt32(&daemon.diskUsageRunning, 0)
44
+
40 45
 	// Retrieve container list
41 46
 	allContainers, err := daemon.Containers(&types.ContainerListOptions{
42 47
 		Size: true,