Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.
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
10 changes: 1 addition & 9 deletions daemon/graphdriver/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

package copy // import "github.com/docker/docker/daemon/graphdriver/copy"

/*
#include <linux/fs.h>

#ifndef FICLONE
#define FICLONE _IOW(0x94, 9, int)
#endif
*/
import "C"
import (
"container/list"
"fmt"
Expand Down Expand Up @@ -50,7 +42,7 @@ func copyRegular(srcPath, dstPath string, fileinfo os.FileInfo, copyWithFileRang
defer dstFile.Close()

if *copyWithFileClone {
_, _, err = unix.Syscall(unix.SYS_IOCTL, dstFile.Fd(), C.FICLONE, srcFile.Fd())
err = fiClone(srcFile, dstFile)
if err == nil {
return nil
}
Expand Down
22 changes: 22 additions & 0 deletions daemon/graphdriver/copy/copy_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build linux,cgo

package copy // import "github.com/docker/docker/daemon/graphdriver/copy"

/*
#include <linux/fs.h>

#ifndef FICLONE
#define FICLONE _IOW(0x94, 9, int)
#endif
*/
import "C"
import (
"os"

"golang.org/x/sys/unix"
)

func fiClone(srcFile, dstFile *os.File) error {
_, _, err := unix.Syscall(unix.SYS_IOCTL, dstFile.Fd(), C.FICLONE, srcFile.Fd())
return err
}
13 changes: 13 additions & 0 deletions daemon/graphdriver/copy/copy_nocgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build linux,!cgo

package copy // import "github.com/docker/docker/daemon/graphdriver/copy"

import (
"os"

"golang.org/x/sys/unix"
)

func fiClone(srcFile, dstFile *os.File) error {
return unix.ENOSYS
}
27 changes: 10 additions & 17 deletions daemon/graphdriver/quota/projectquota.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux
// +build linux,!exclude_disk_quota

//
// projectquota.go - implements XFS project quota controls
Expand Down Expand Up @@ -63,19 +63,6 @@ import (
"golang.org/x/sys/unix"
)

// Quota limit params - currently we only control blocks hard limit
type Quota struct {
Size uint64
}

// Control - Context to be used by storage driver (e.g. overlay)
// who wants to apply project quotas to container dirs
type Control struct {
backingFsBlockDev string
nextProjectID uint32
quotas map[string]uint32
}

// 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.
Expand Down Expand Up @@ -166,21 +153,24 @@ func NewControl(basePath string) (*Control, error) {
// SetQuota - assign a unique project id to directory and set the quota limits
// for that project id
func (q *Control) SetQuota(targetPath string, quota Quota) error {

q.RLock()
projectID, ok := q.quotas[targetPath]
q.RUnlock()
if !ok {
q.Lock()
projectID = q.nextProjectID

//
// assign project id to new container directory
//
err := setProjectID(targetPath, projectID)
if err != nil {
q.Unlock()
return err
}

q.quotas[targetPath] = projectID
q.nextProjectID++
q.Unlock()
}

//
Expand Down Expand Up @@ -217,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
func (q *Control) GetQuota(targetPath string, quota *Quota) error {

q.RLock()
projectID, ok := q.quotas[targetPath]
q.RUnlock()
if !ok {
return errors.Errorf("quota not found for path: %s", targetPath)
}
Expand Down Expand Up @@ -289,6 +280,8 @@ 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 *Control) findNextProjectID(home string) error {
q.Lock()
defer q.Unlock()
files, err := ioutil.ReadDir(home)
if err != nil {
return errors.Errorf("read directory failed: %s", home)
Expand Down
18 changes: 18 additions & 0 deletions daemon/graphdriver/quota/projectquota_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build linux,exclude_disk_quota

package quota // import "github.com/docker/docker/daemon/graphdriver/quota"

func NewControl(basePath string) (*Control, error) {
return nil, ErrQuotaNotSupported
}

// SetQuota - assign a unique project id to directory and set the quota limits
// for that project id
func (q *Control) SetQuota(targetPath string, quota Quota) error {
return ErrQuotaNotSupported
}

// GetQuota - get the quota limits of a directory that was configured with SetQuota
func (q *Control) GetQuota(targetPath string, quota *Quota) error {
return ErrQuotaNotSupported
}
19 changes: 19 additions & 0 deletions daemon/graphdriver/quota/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// +build linux

package quota // import "github.com/docker/docker/daemon/graphdriver/quota"

import "sync"

// Quota limit params - currently we only control blocks hard limit
type Quota struct {
Size uint64
}

// Control - Context to be used by storage driver (e.g. overlay)
// who wants to apply project quotas to container dirs
type Control struct {
backingFsBlockDev string
sync.RWMutex // protect nextProjectID and quotas map
nextProjectID uint32
quotas map[string]uint32
}
17 changes: 5 additions & 12 deletions daemon/stats/collector_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ import (
"strings"

"github.com/opencontainers/runc/libcontainer/system"
"golang.org/x/sys/unix"
)

/*
#include <unistd.h>
*/
import "C"

// platformNewStatsCollector performs platform specific initialisation of the
// Collector structure.
func platformNewStatsCollector(s *Collector) {
Expand Down Expand Up @@ -70,13 +66,10 @@ func (s *Collector) getSystemCPUUsage() (uint64, error) {
}

func (s *Collector) getNumberOnlineCPUs() (uint32, error) {
i, err := C.sysconf(C._SC_NPROCESSORS_ONLN)
// According to POSIX - errno is undefined after successful
// sysconf, and can be non-zero in several cases, so look for
// error in returned value not in errno.
// (https://sourceware.org/bugzilla/show_bug.cgi?id=21536)
if i == -1 {
var cpuset unix.CPUSet
err := unix.SchedGetaffinity(0, &cpuset)
if err != nil {
return 0, err
}
return uint32(i), nil
return uint32(cpuset.Count()), nil
}