1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #27472 from dnephin/move-graphdriver-quota

Move graphdriver quota
This commit is contained in:
Kenfe-Mickaël Laventure 2016-10-18 09:09:09 -07:00 committed by GitHub
commit f5c21faf88
2 changed files with 14 additions and 13 deletions

View file

@ -17,6 +17,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/daemon/graphdriver/quota"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/chrootarchive"
"github.com/docker/docker/pkg/directory"
@ -79,7 +80,7 @@ const (
type overlayOptions struct {
overrideKernelCheck bool
quota graphdriver.Quota
quota quota.Quota
}
// Driver contains information about the home directory and the list of active mounts that are created using this driver.
@ -88,7 +89,7 @@ type Driver struct {
uidMaps []idtools.IDMap
gidMaps []idtools.IDMap
ctr *graphdriver.RefCounter
quotaCtl *graphdriver.QuotaCtl
quotaCtl *quota.Control
options overlayOptions
}
@ -163,7 +164,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
if backingFs == "xfs" {
// Try to enable project quota support over xfs.
if d.quotaCtl, err = graphdriver.NewQuotaCtl(home); err == nil {
if d.quotaCtl, err = quota.NewControl(home); err == nil {
projectQuotaSupported = true
}
}

View file

@ -9,7 +9,7 @@
// for both xfs/ext4 for kernel version >= v4.5
//
package graphdriver
package quota
/*
#include <stdlib.h>
@ -66,15 +66,15 @@ type Quota struct {
Size uint64
}
// QuotaCtl - Context to be used by storage driver (e.g. overlay)
// Control - Context to be used by storage driver (e.g. overlay)
// who wants to apply project quotas to container dirs
type QuotaCtl struct {
type Control struct {
backingFsBlockDev string
nextProjectID uint32
quotas map[string]uint32
}
// NewQuotaCtl - initialize project quota support.
// NewControl - initialize project quota support.
// Test to make sure that quota can be set on a test dir and find
// the first project id to be used for the next container create.
//
@ -96,7 +96,7 @@ type QuotaCtl struct {
// on it. If that works, continue to scan existing containers to map allocated
// project ids.
//
func NewQuotaCtl(basePath string) (*QuotaCtl, error) {
func NewControl(basePath string) (*Control, error) {
//
// Get project id of parent dir as minimal id to be used by driver
//
@ -125,7 +125,7 @@ func NewQuotaCtl(basePath string) (*QuotaCtl, error) {
return nil, err
}
q := QuotaCtl{
q := Control{
backingFsBlockDev: backingFsBlockDev,
nextProjectID: minProjectID + 1,
quotas: make(map[string]uint32),
@ -139,13 +139,13 @@ func NewQuotaCtl(basePath string) (*QuotaCtl, error) {
return nil, err
}
logrus.Debugf("NewQuotaCtl(%s): nextProjectID = %d", basePath, q.nextProjectID)
logrus.Debugf("NewControl(%s): nextProjectID = %d", basePath, q.nextProjectID)
return &q, nil
}
// SetQuota - assign a unique project id to directory and set the quota limits
// for that project id
func (q *QuotaCtl) SetQuota(targetPath string, quota Quota) error {
func (q *Control) SetQuota(targetPath string, quota Quota) error {
projectID, ok := q.quotas[targetPath]
if !ok {
@ -196,7 +196,7 @@ func setProjectQuota(backingFsBlockDev string, projectID uint32, quota Quota) er
}
// GetQuota - get the quota limits of a directory that was configured with SetQuota
func (q *QuotaCtl) GetQuota(targetPath string, quota *Quota) error {
func (q *Control) GetQuota(targetPath string, quota *Quota) error {
projectID, ok := q.quotas[targetPath]
if !ok {
@ -268,7 +268,7 @@ func setProjectID(targetPath string, projectID uint32) error {
// findNextProjectID - find the next project id to be used for containers
// by scanning driver home directory to find used project ids
func (q *QuotaCtl) findNextProjectID(home string) error {
func (q *Control) findNextProjectID(home string) error {
files, err := ioutil.ReadDir(home)
if err != nil {
return fmt.Errorf("read directory failed : %s", home)