-
Notifications
You must be signed in to change notification settings - Fork 1
/
maintenance.go
55 lines (42 loc) · 923 Bytes
/
maintenance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"time"
)
func (driver sharedVolumeDriver) MaintenanceRoutine() {
lockTicker := time.NewTicker(lockInterval)
cleanupTicker := time.NewTicker(cleanupInterval)
for {
select {
case <-lockTicker.C:
driver.RefreshLocks()
case <-cleanupTicker.C:
driver.Cleanup()
}
}
}
func (driver sharedVolumeDriver) RefreshLocks() {
driver.mutex.Lock()
defer driver.mutex.Unlock()
for _, volume := range driver.volumes {
volume.lock()
}
}
// For each volume remove mounts that
func (driver sharedVolumeDriver) Cleanup() {
driver.mutex.Lock()
defer driver.mutex.Unlock()
for _, volume := range driver.volumes {
locks := volume.getLocks()
for id, lock := range locks {
if ok, _ := lock.tryUnlock(); ok {
delete(locks, id)
}
}
mounts := volume.getMounts()
for _, mount := range mounts {
if _, ok := locks[mount.Hostname]; !ok {
mount.remove()
}
}
}
}