|
@@ -153,9 +153,11 @@ func NewControl(basePath string) (*Control, error) {
|
|
// SetQuota - assign a unique project id to directory and set the quota limits
|
|
// SetQuota - assign a unique project id to directory and set the quota limits
|
|
// for that project id
|
|
// for that project id
|
|
func (q *Control) SetQuota(targetPath string, quota Quota) error {
|
|
func (q *Control) SetQuota(targetPath string, quota Quota) error {
|
|
-
|
|
|
|
|
|
+ q.RLock()
|
|
projectID, ok := q.quotas[targetPath]
|
|
projectID, ok := q.quotas[targetPath]
|
|
|
|
+ q.RUnlock()
|
|
if !ok {
|
|
if !ok {
|
|
|
|
+ q.Lock()
|
|
projectID = q.nextProjectID
|
|
projectID = q.nextProjectID
|
|
|
|
|
|
//
|
|
//
|
|
@@ -163,11 +165,12 @@ func (q *Control) SetQuota(targetPath string, quota Quota) error {
|
|
//
|
|
//
|
|
err := setProjectID(targetPath, projectID)
|
|
err := setProjectID(targetPath, projectID)
|
|
if err != nil {
|
|
if err != nil {
|
|
|
|
+ q.Unlock()
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
-
|
|
|
|
q.quotas[targetPath] = projectID
|
|
q.quotas[targetPath] = projectID
|
|
q.nextProjectID++
|
|
q.nextProjectID++
|
|
|
|
+ q.Unlock()
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
//
|
|
@@ -204,8 +207,9 @@ func setProjectQuota(backingFsBlockDev string, projectID uint32, quota Quota) er
|
|
|
|
|
|
// GetQuota - get the quota limits of a directory that was configured with SetQuota
|
|
// GetQuota - get the quota limits of a directory that was configured with SetQuota
|
|
func (q *Control) GetQuota(targetPath string, quota *Quota) error {
|
|
func (q *Control) GetQuota(targetPath string, quota *Quota) error {
|
|
-
|
|
|
|
|
|
+ q.RLock()
|
|
projectID, ok := q.quotas[targetPath]
|
|
projectID, ok := q.quotas[targetPath]
|
|
|
|
+ q.RUnlock()
|
|
if !ok {
|
|
if !ok {
|
|
return errors.Errorf("quota not found for path: %s", targetPath)
|
|
return errors.Errorf("quota not found for path: %s", targetPath)
|
|
}
|
|
}
|
|
@@ -276,6 +280,8 @@ func setProjectID(targetPath string, projectID uint32) error {
|
|
// findNextProjectID - find the next project id to be used for containers
|
|
// findNextProjectID - find the next project id to be used for containers
|
|
// by scanning driver home directory to find used project ids
|
|
// by scanning driver home directory to find used project ids
|
|
func (q *Control) findNextProjectID(home string) error {
|
|
func (q *Control) findNextProjectID(home string) error {
|
|
|
|
+ q.Lock()
|
|
|
|
+ defer q.Unlock()
|
|
files, err := ioutil.ReadDir(home)
|
|
files, err := ioutil.ReadDir(home)
|
|
if err != nil {
|
|
if err != nil {
|
|
return errors.Errorf("read directory failed: %s", home)
|
|
return errors.Errorf("read directory failed: %s", home)
|