@@ -160,13 +160,19 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
160160 uidMaps : uidMaps ,
161161 gidMaps : gidMaps ,
162162 ctr : graphdriver .NewRefCounter (graphdriver .NewFsChecker (graphdriver .FsMagicOverlay )),
163+ options : * opts ,
163164 }
164165
165166 if backingFs == "xfs" {
166167 // Try to enable project quota support over xfs.
167168 if d .quotaCtl , err = graphdriver .NewQuotaCtl (home ); err == nil {
168169 projectQuotaSupported = true
170+ } else if opts .quota .Size > 0 {
171+ return nil , fmt .Errorf ("Storage option overlay2.size not supported. Filesystem does not support Project Quota: %v" , err )
169172 }
173+ } else if opts .quota .Size > 0 {
174+ // if xfs is not the backing fs then error out if the storage-opt overlay2.size is used.
175+ return nil , fmt .Errorf ("Storage Option overlay2.size only supported for backingFS XFS. Found %v" , backingFs )
170176 }
171177
172178 logrus .Debugf ("backingFs=%s, projectQuotaSupported=%v" , backingFs , projectQuotaSupported )
@@ -188,9 +194,14 @@ func parseOptions(options []string) (*overlayOptions, error) {
188194 if err != nil {
189195 return nil , err
190196 }
191-
197+ case "overlay2.size" :
198+ size , err := units .RAMInBytes (val )
199+ if err != nil {
200+ return nil , err
201+ }
202+ o .quota .Size = uint64 (size )
192203 default :
193- return nil , fmt .Errorf ("overlay2: Unknown option %s\n " , key )
204+ return nil , fmt .Errorf ("overlay2: unknown option %s" , key )
194205 }
195206 }
196207 return o , nil
@@ -270,11 +281,22 @@ func (d *Driver) CreateReadWrite(id, parent, mountLabel string, storageOpt map[s
270281// Create is used to create the upper, lower, and merge directories required for overlay fs for a given id.
271282// The parent filesystem is used to configure these directories for the overlay.
272283func (d * Driver ) Create (id , parent , mountLabel string , storageOpt map [string ]string ) (retErr error ) {
273-
274284 if len (storageOpt ) != 0 && ! projectQuotaSupported {
275285 return fmt .Errorf ("--storage-opt is supported only for overlay over xfs with 'pquota' mount option" )
276286 }
277287
288+ if storageOpt == nil {
289+ storageOpt = map [string ]string {}
290+ }
291+
292+ if _ , ok := storageOpt ["size" ]; ! ok {
293+ storageOpt ["size" ] = strconv .FormatUint (d .options .quota .Size , 10 )
294+ }
295+ return d .create (id , parent , storageOpt )
296+ }
297+
298+ func (d * Driver ) create (id , parent string , storageOpt map [string ]string ) (retErr error ) {
299+
278300 dir := d .dir (id )
279301
280302 rootUID , rootGID , err := idtools .GetRootUIDGID (d .uidMaps , d .gidMaps )
0 commit comments