Skip to content

Commit

Permalink
refactor: make all quota implementation logic clear
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Sun <[email protected]>
  • Loading branch information
allencloud committed Jul 13, 2018
1 parent 3a53801 commit 6210a15
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 323 deletions.
4 changes: 2 additions & 2 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,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 @@ -2357,7 +2357,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 @@ -90,7 +91,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 @@ -110,7 +111,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

0 comments on commit 6210a15

Please sign in to comment.