Skip to content

Commit c66dabe

Browse files
wlan0Praveenrajmani
authored andcommitted
XFS quota fixes
1. make set_xfs_quota idempotent 2. restrict xfs managed tree recursion to 0 - This can be done because when we provision new volumes, we always start with a empty directory (i.e. there are no files to traverse through) - When reusing old volumes, we do not call xfs_set_quota Signed-off-by: wlan0 <sidharthamn@gmail.com>
1 parent 823a646 commit c66dabe

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
1313
github.com/golang/protobuf v1.4.3 // indirect
1414
github.com/gopherjs/gopherjs v0.0.0-20190328170749-bb2674552d8f // indirect
15+
github.com/hashicorp/errwrap v1.1.0
1516
github.com/imdario/mergo v0.3.7 // indirect
1617
github.com/jedib0t/go-pretty v4.3.0+incompatible
1718
github.com/jedib0t/go-pretty/v6 v6.0.5

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoP
327327
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
328328
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
329329
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
330+
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
331+
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
330332
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
331333
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
332334
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=

pkg/sys/xfs/xfs_quota.go

+38-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ package xfs
1919
import (
2020
"context"
2121
"encoding/binary"
22+
"errors"
2223
"fmt"
23-
simd "github.com/minio/sha256-simd"
2424
"math"
2525
"os/exec"
2626
"strconv"
2727
"strings"
28+
29+
"github.com/golang/glog"
30+
simd "github.com/minio/sha256-simd"
31+
)
32+
33+
var (
34+
ErrProjNotFound = errors.New("xfs project not found")
2835
)
2936

3037
type XFSQuota struct {
@@ -47,20 +54,35 @@ func getProjectIDHash(id string) string {
4754
// SetQuota creates a projectID and sets the hardlimit for the path
4855
func (xfsq *XFSQuota) SetQuota(ctx context.Context, limit int64) error {
4956

57+
_, err := xfsq.GetVolumeStats(ctx)
58+
// error getting quota value
59+
if err != nil && err != ErrProjNotFound {
60+
return err
61+
}
62+
// this means quota has already been set
63+
if err == nil {
64+
return nil
65+
}
66+
5067
limitInStr := strconv.FormatInt(limit, 10)
5168
pid := getProjectIDHash(xfsq.ProjectID)
5269

53-
cmd := exec.CommandContext(ctx, "xfs_quota", "-x", "-c", fmt.Sprintf("project -s -p %s %s", xfsq.Path, pid))
70+
glog.V(3).Infof("setting prjquota proj_id=%s path=%s", pid, xfsq.Path)
71+
72+
cmd := exec.CommandContext(ctx, "xfs_quota", "-x", "-c", fmt.Sprintf("project -d 0 -s -p %s %s", xfsq.Path, pid))
5473
out, err := cmd.CombinedOutput()
5574
if err != nil {
75+
glog.Errorf("could not set prjquota proj_id=%s path=%s err=%v", pid, xfsq.Path, err)
5676
return fmt.Errorf("SetQuota failed for %s with error: (%v), output: (%s)", xfsq.ProjectID, err, out)
5777
}
5878

5979
cmd = exec.CommandContext(ctx, "xfs_quota", "-x", "-c", fmt.Sprintf("limit -p bhard=%s %s", limitInStr, pid), xfsq.Path)
6080
out, err = cmd.CombinedOutput()
6181
if err != nil {
82+
glog.Errorf("could not set prjquota proj_id=%s path=%s err=%v", pid, xfsq.Path, err)
6283
return fmt.Errorf("xfs_quota failed with error: %v, output: %s", err, out)
6384
}
85+
glog.V(3).Infof("prjquota set successfully proj_id=%s path=%s", pid, xfsq.Path)
6486

6587
return nil
6688
}
@@ -112,12 +134,18 @@ func ParseQuotaList(output, projectID string) (XFSVolumeStats, error) {
112134
var pErr error
113135
var f float64
114136
lines := strings.Split(output, "\n")
115-
for _, line := range lines {
137+
prjFound := false
138+
for _, l := range lines {
139+
line := strings.TrimSpace(l)
116140
if len(line) == 0 {
117141
continue
118142
}
119-
cleanLine := strings.TrimSpace(line)
120-
splits := strings.Split(cleanLine, " ")
143+
if !strings.HasPrefix(line, "#"+projectID) {
144+
continue
145+
}
146+
prjFound = true
147+
148+
splits := strings.Split(line, " ")
121149
var values []string
122150
for _, split := range splits {
123151
tSplit := strings.TrimSpace(split)
@@ -140,6 +168,11 @@ func ParseQuotaList(output, projectID string) (XFSVolumeStats, error) {
140168
totalInBytes = int64(f)
141169
break
142170
}
171+
break
172+
}
173+
174+
if !prjFound {
175+
return XFSVolumeStats{}, ErrProjNotFound
143176
}
144177
return XFSVolumeStats{
145178
AvailableBytes: totalInBytes - usedInBytes,

0 commit comments

Comments
 (0)