-
Notifications
You must be signed in to change notification settings - Fork 10
/
limits.go
62 lines (50 loc) · 976 Bytes
/
limits.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
56
57
58
59
60
61
62
package fsquota
import "sync"
// Limits contains quota limits
type Limits struct {
// Byte usage limits
Bytes Limit
// File count limits
Files Limit
}
// Limit represents a combined hard and soft limit
type Limit struct {
mu sync.Mutex
soft *uint64
hard *uint64
}
// SetHard sets the hard limit
func (l *Limit) SetHard(limit uint64) {
l.mu.Lock()
defer l.mu.Unlock()
l.hard = &limit
}
// GetHard retrieves the hard limit
func (l *Limit) GetHard() (limit uint64) {
limit, _, _ = l.getValues()
return
}
// SetSoft sets the soft limit
func (l *Limit) SetSoft(limit uint64) {
l.mu.Lock()
defer l.mu.Unlock()
l.soft = &limit
}
// GetSoft retrieves the soft limit
func (l *Limit) GetSoft() (limit uint64) {
_, limit, _ = l.getValues()
return
}
func (l *Limit) getValues() (hard, soft uint64, ok bool) {
l.mu.Lock()
defer l.mu.Unlock()
if l.hard != nil {
hard = *l.hard
ok = true
}
if l.soft != nil {
soft = *l.soft
ok = true
}
return
}