Skip to content

Commit dcd13dd

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

File tree

11 files changed

+499
-346
lines changed

11 files changed

+499
-346
lines changed

apis/swagger.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,12 @@ definitions:
19641964
description: "Initial script executed in container. The script will be executed before entrypoint or command"
19651965
DiskQuota:
19661966
type: "object"
1967-
description: "Set disk quota for container"
1967+
description: |
1968+
Set disk quota for container.
1969+
Key is the dir in container.
1970+
Value is disk quota size for the dir.
1971+
/ means rootfs dir in container.
1972+
.* includes rootfs dir and all volume dir.
19681973
x-nullable: true
19691974
additionalProperties:
19701975
type: "string"
@@ -1975,7 +1980,10 @@ definitions:
19751980
type: "string"
19761981
QuotaID:
19771982
type: "string"
1978-
description: "set disk quota by specified quota id, if id < 0, it means pouchd alloc a unique quota id"
1983+
description: |
1984+
Set disk quota by specified quota id.
1985+
If QuotaID <= 0, it means pouchd should allocate a unique quota id by sequence automatically.
1986+
By default, a quota ID is mapped to only one container. And one quota ID can include several mountpoint.
19791987
NetPriority:
19801988
description: "net priority."
19811989
type: "integer"

apis/types/container_config.go

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

daemon/mgr/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ func (mgr *ContainerManager) updateContainerDiskQuota(ctx context.Context, c *Co
10951095
qid = uint32(id)
10961096
if id < 0 {
10971097
// QuotaID is < 0, it means pouchd alloc a unique quota id.
1098-
qid, err = quota.GetNextQuatoID()
1098+
qid, err = quota.GetNextQuotaID()
10991099
if err != nil {
11001100
return errors.Wrap(err, "failed to get next quota id")
11011101
}
@@ -2250,7 +2250,7 @@ func (mgr *ContainerManager) setMountPointDiskQuota(ctx context.Context, c *Cont
22502250

22512251
// if QuotaID is < 0, it means pouchd alloc a unique quota id.
22522252
if id < 0 {
2253-
qid, err = quota.GetNextQuatoID()
2253+
qid, err = quota.GetNextQuotaID()
22542254
if err != nil {
22552255
return errors.Wrap(err, "failed to get next quota id")
22562256
}

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"
@@ -98,7 +99,7 @@ func setMountTab(ctx context.Context, c *Container, spec *SpecWrapper) error {
9899

99100
// set rootfs mount tab
100101
context := "/ / ext4 rw 0 0\n"
101-
if rootID, e := quota.GetDevID(c.BaseFS); e == nil {
102+
if rootID, e := system.GetDevID(c.BaseFS); e == nil {
102103
_, _, rootFsType := quota.CheckMountpoint(rootID)
103104
if len(rootFsType) > 0 {
104105
context = fmt.Sprintf("/ / %s rw 0 0\n", rootFsType)
@@ -118,7 +119,7 @@ func setMountTab(ctx context.Context, c *Container, spec *SpecWrapper) error {
118119
}
119120

120121
tempLine := fmt.Sprintf("/dev/v%02dd %s ext4 rw 0 0\n", i, m.Destination)
121-
if tmpID, e := quota.GetDevID(m.Source); e == nil {
122+
if tmpID, e := system.GetDevID(m.Source); e == nil {
122123
_, _, fsType := quota.CheckMountpoint(tmpID)
123124
if len(fsType) > 0 {
124125
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)