Prevent multiple parallel SystemDiskUsage call

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2017-04-12 13:59:59 -07:00
parent cf7d246ab0
commit 5a9f2a3ce6
2 changed files with 12 additions and 0 deletions

View file

@ -111,6 +111,12 @@ type Daemon struct {
seccompProfile []byte
seccompProfilePath string
diskUsageRunning int32
containersPruneRunning int32
volumesPruneRunning int32
imagesPruneRunning int32
networksPruneRunning int32
}
// HasExperimental returns whether the experimental features of the daemon are enabled or not

View file

@ -2,6 +2,7 @@ package daemon
import (
"fmt"
"sync/atomic"
"golang.org/x/net/context"
@ -37,6 +38,11 @@ func (daemon *Daemon) getLayerRefs() map[layer.ChainID]int {
// SystemDiskUsage returns information about the daemon data disk usage
func (daemon *Daemon) SystemDiskUsage(ctx context.Context) (*types.DiskUsage, error) {
if !atomic.CompareAndSwapInt32(&daemon.diskUsageRunning, 0, 1) {
return nil, fmt.Errorf("a disk usage operation is already running")
}
defer atomic.StoreInt32(&daemon.diskUsageRunning, 0)
// Retrieve container list
allContainers, err := daemon.Containers(&types.ContainerListOptions{
Size: true,