@@ -24,6 +24,7 @@ import (
2424 "github.com/docker/docker/pkg/parsers"
2525 "github.com/docker/docker/pkg/parsers/kernel"
2626 "github.com/docker/docker/pkg/system"
27+ "github.com/docker/go-units"
2728 "github.com/opencontainers/runc/libcontainer/label"
2829)
2930
@@ -75,15 +76,25 @@ const (
7576 idLength = 26
7677)
7778
79+ type overlayOptions struct {
80+ overrideKernelCheck bool
81+ quota graphdriver.Quota
82+ }
83+
7884// Driver contains information about the home directory and the list of active mounts that are created using this driver.
7985type Driver struct {
80- home string
81- uidMaps []idtools.IDMap
82- gidMaps []idtools.IDMap
83- ctr * graphdriver.RefCounter
86+ home string
87+ uidMaps []idtools.IDMap
88+ gidMaps []idtools.IDMap
89+ ctr * graphdriver.RefCounter
90+ quotaCtl * graphdriver.QuotaCtl
91+ options overlayOptions
8492}
8593
86- var backingFs = "<unknown>"
94+ var (
95+ backingFs = "<unknown>"
96+ projectQuotaSupported = false
97+ )
8798
8899func init () {
89100 graphdriver .Register (driverName , Init )
@@ -151,11 +162,16 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
151162 ctr : graphdriver .NewRefCounter (graphdriver .NewFsChecker (graphdriver .FsMagicOverlay )),
152163 }
153164
154- return d , nil
155- }
165+ if backingFs == "xfs" {
166+ // Try to enable project quota support over xfs.
167+ if d .quotaCtl , err = graphdriver .NewQuotaCtl (home ); err == nil {
168+ projectQuotaSupported = true
169+ }
170+ }
156171
157- type overlayOptions struct {
158- overrideKernelCheck bool
172+ logrus .Debugf ("backingFs=%s, projectQuotaSupported=%v" , backingFs , projectQuotaSupported )
173+
174+ return d , nil
159175}
160176
161177func parseOptions (options []string ) (* overlayOptions , error ) {
@@ -172,6 +188,7 @@ func parseOptions(options []string) (*overlayOptions, error) {
172188 if err != nil {
173189 return nil , err
174190 }
191+
175192 default :
176193 return nil , fmt .Errorf ("overlay2: Unknown option %s\n " , key )
177194 }
@@ -254,8 +271,8 @@ func (d *Driver) CreateReadWrite(id, parent, mountLabel string, storageOpt map[s
254271// The parent filesystem is used to configure these directories for the overlay.
255272func (d * Driver ) Create (id , parent , mountLabel string , storageOpt map [string ]string ) (retErr error ) {
256273
257- if len (storageOpt ) != 0 {
258- return fmt .Errorf ("--storage-opt is not supported for overlay" )
274+ if len (storageOpt ) != 0 && ! projectQuotaSupported {
275+ return fmt .Errorf ("--storage-opt is supported only for overlay over xfs with 'pquota' mount option " )
259276 }
260277
261278 dir := d .dir (id )
@@ -278,6 +295,20 @@ func (d *Driver) Create(id, parent, mountLabel string, storageOpt map[string]str
278295 }
279296 }()
280297
298+ if len (storageOpt ) > 0 {
299+ driver := & Driver {}
300+ if err := d .parseStorageOpt (storageOpt , driver ); err != nil {
301+ return err
302+ }
303+
304+ if driver .options .quota .Size > 0 {
305+ // Set container disk quota limit
306+ if err := d .quotaCtl .SetQuota (dir , driver .options .quota ); err != nil {
307+ return err
308+ }
309+ }
310+ }
311+
281312 if err := idtools .MkdirAs (path .Join (dir , "diff" ), 0755 , rootUID , rootGID ); err != nil {
282313 return err
283314 }
@@ -317,6 +348,26 @@ func (d *Driver) Create(id, parent, mountLabel string, storageOpt map[string]str
317348 return nil
318349}
319350
351+ // Parse overlay storage options
352+ func (d * Driver ) parseStorageOpt (storageOpt map [string ]string , driver * Driver ) error {
353+ // Read size to set the disk project quota per container
354+ for key , val := range storageOpt {
355+ key := strings .ToLower (key )
356+ switch key {
357+ case "size" :
358+ size , err := units .RAMInBytes (val )
359+ if err != nil {
360+ return err
361+ }
362+ driver .options .quota .Size = uint64 (size )
363+ default :
364+ return fmt .Errorf ("Unknown option %s" , key )
365+ }
366+ }
367+
368+ return nil
369+ }
370+
320371func (d * Driver ) getLower (parent string ) (string , error ) {
321372 parentDir := d .dir (parent )
322373
0 commit comments