Skip to content

Commit eccb3bb

Browse files
committed
refactor: make all quota implementation logic clear
Signed-off-by: Allen Sun <[email protected]>
1 parent bf0d5d0 commit eccb3bb

File tree

9 files changed

+456
-324
lines changed

9 files changed

+456
-324
lines changed

daemon/mgr/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ func (mgr *ContainerManager) updateContainerDiskQuota(ctx context.Context, c *Co
11111111
qid = uint32(id)
11121112
if id < 0 {
11131113
// QuotaID is < 0, it means pouchd alloc a unique quota id.
1114-
qid, err = quota.GetNextQuatoID()
1114+
qid, err = quota.GetNextQuotaID()
11151115
if err != nil {
11161116
return errors.Wrap(err, "failed to get next quota id")
11171117
}
@@ -2236,7 +2236,7 @@ func (mgr *ContainerManager) setMountPointDiskQuota(ctx context.Context, c *Cont
22362236

22372237
// if QuotaID is < 0, it means pouchd alloc a unique quota id.
22382238
if id < 0 {
2239-
qid, err = quota.GetNextQuatoID()
2239+
qid, err = quota.GetNextQuotaID()
22402240
if err != nil {
22412241
return errors.Wrap(err, "failed to get next quota id")
22422242
}

daemon/mgr/spec_hook.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strconv"
1111
"strings"
1212

13+
"github.com/alibaba/pouch/pkg/system"
1314
"github.com/alibaba/pouch/storage/quota"
1415

1516
specs "github.com/opencontainers/runtime-spec/specs-go"
@@ -90,7 +91,7 @@ func setMountTab(ctx context.Context, c *Container, spec *SpecWrapper) error {
9091

9192
// set rootfs mount tab
9293
context := "/ / ext4 rw 0 0\n"
93-
if rootID, e := quota.GetDevID(c.BaseFS); e == nil {
94+
if rootID, e := system.GetDevID(c.BaseFS); e == nil {
9495
_, _, rootFsType := quota.CheckMountpoint(rootID)
9596
if len(rootFsType) > 0 {
9697
context = fmt.Sprintf("/ / %s rw 0 0\n", rootFsType)
@@ -110,7 +111,7 @@ func setMountTab(ctx context.Context, c *Container, spec *SpecWrapper) error {
110111
}
111112

112113
tempLine := fmt.Sprintf("/dev/v%02dd %s ext4 rw 0 0\n", i, m.Destination)
113-
if tmpID, e := quota.GetDevID(m.Source); e == nil {
114+
if tmpID, e := system.GetDevID(m.Source); e == nil {
114115
_, _, fsType := quota.CheckMountpoint(tmpID)
115116
if len(fsType) > 0 {
116117
tempLine = fmt.Sprintf("/dev/v%02dd %s %s rw 0 0\n", i, m.Destination, fsType)

pkg/system/device.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// +build linux
2+
3+
package system
4+
5+
import (
6+
"syscall"
7+
8+
"github.com/sirupsen/logrus"
9+
)
10+
11+
// GetDevID returns device id via syscall according to the input directory.
12+
func GetDevID(dir string) (uint64, error) {
13+
var st syscall.Stat_t
14+
if err := syscall.Stat(dir, &st); err != nil {
15+
logrus.Warnf("failed to get device id of dir %s: %v", dir, err)
16+
return 0, err
17+
}
18+
return st.Dev, nil
19+
}

pkg/system/sysinfo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package system
24

35
import (

0 commit comments

Comments
 (0)