From e9d785ce3f02c223100f4dd01813e192ccd83948 Mon Sep 17 00:00:00 2001 From: Shijiang Wei Date: Mon, 17 Sep 2018 17:10:42 +0800 Subject: [PATCH] enhance storage-opt validation logic in overlay2 driver Signed-off-by: Shijiang Wei --- daemon/graphdriver/overlay2/overlay.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/daemon/graphdriver/overlay2/overlay.go b/daemon/graphdriver/overlay2/overlay.go index 66c3861ba2..71b904d690 100644 --- a/daemon/graphdriver/overlay2/overlay.go +++ b/daemon/graphdriver/overlay2/overlay.go @@ -300,23 +300,23 @@ func (d *Driver) Cleanup() error { // CreateReadWrite creates a layer that is writable for use as a container // file system. func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - if opts != nil && len(opts.StorageOpt) != 0 && !projectQuotaSupported { - return fmt.Errorf("--storage-opt is supported only for overlay over xfs with 'pquota' mount option") - } - if opts == nil { opts = &graphdriver.CreateOpts{ - StorageOpt: map[string]string{}, + StorageOpt: make(map[string]string), } + } else if opts.StorageOpt == nil { + opts.StorageOpt = make(map[string]string) } - if _, ok := opts.StorageOpt["size"]; !ok { - if opts.StorageOpt == nil { - opts.StorageOpt = map[string]string{} - } + // Merge daemon default config. + if _, ok := opts.StorageOpt["size"]; !ok && d.options.quota.Size != 0 { opts.StorageOpt["size"] = strconv.FormatUint(d.options.quota.Size, 10) } + if _, ok := opts.StorageOpt["size"]; ok && !projectQuotaSupported { + return fmt.Errorf("--storage-opt is supported only for overlay over xfs with 'pquota' mount option") + } + return d.create(id, parent, opts) }