Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make all quota implementation logic clear #1736

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,12 @@ definitions:
description: "Initial script executed in container. The script will be executed before entrypoint or command"
DiskQuota:
type: "object"
description: "Set disk quota for container"
description: |
Set disk quota for container.
Key is the dir in container.
Value is disk quota size for the dir.
/ means rootfs dir in container.
.* includes rootfs dir and all volume dir.
x-nullable: true
additionalProperties:
type: "string"
Expand All @@ -1975,7 +1980,10 @@ definitions:
type: "string"
QuotaID:
type: "string"
description: "set disk quota by specified quota id, if id < 0, it means pouchd alloc a unique quota id"
description: |
Set disk quota by specified quota id.
If QuotaID <= 0, it means pouchd should allocate a unique quota id by sequence automatically.
By default, a quota ID is mapped to only one container. And one quota ID can include several mountpoint.
NetPriority:
description: "net priority."
type: "integer"
Expand Down
12 changes: 10 additions & 2 deletions apis/types/container_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ func (mgr *ContainerManager) updateContainerDiskQuota(ctx context.Context, c *Co
qid = uint32(id)
if id < 0 {
// QuotaID is < 0, it means pouchd alloc a unique quota id.
qid, err = quota.GetNextQuatoID()
qid, err = quota.GetNextQuotaID()
if err != nil {
return errors.Wrap(err, "failed to get next quota id")
}
Expand Down Expand Up @@ -2250,7 +2250,7 @@ func (mgr *ContainerManager) setMountPointDiskQuota(ctx context.Context, c *Cont

// if QuotaID is < 0, it means pouchd alloc a unique quota id.
if id < 0 {
qid, err = quota.GetNextQuatoID()
qid, err = quota.GetNextQuotaID()
if err != nil {
return errors.Wrap(err, "failed to get next quota id")
}
Expand Down
5 changes: 3 additions & 2 deletions daemon/mgr/spec_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

"github.com/alibaba/pouch/pkg/system"
"github.com/alibaba/pouch/storage/quota"

specs "github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -98,7 +99,7 @@ func setMountTab(ctx context.Context, c *Container, spec *SpecWrapper) error {

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

tempLine := fmt.Sprintf("/dev/v%02dd %s ext4 rw 0 0\n", i, m.Destination)
if tmpID, e := quota.GetDevID(m.Source); e == nil {
if tmpID, e := system.GetDevID(m.Source); e == nil {
_, _, fsType := quota.CheckMountpoint(tmpID)
if len(fsType) > 0 {
tempLine = fmt.Sprintf("/dev/v%02dd %s %s rw 0 0\n", i, m.Destination, fsType)
Expand Down
19 changes: 19 additions & 0 deletions pkg/system/device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// +build linux

package system

import (
"syscall"

"github.com/sirupsen/logrus"
)

// GetDevID returns device id via syscall according to the input directory.
func GetDevID(dir string) (uint64, error) {
var st syscall.Stat_t
if err := syscall.Stat(dir, &st); err != nil {
logrus.Warnf("failed to get device id of dir %s: %v", dir, err)
return 0, err
}
return st.Dev, nil
}
2 changes: 2 additions & 0 deletions pkg/system/sysinfo.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux

package system

import (
Expand Down
Loading