From c25d2c04df9801d78e3ca0b7a49e5ab8f4649880 Mon Sep 17 00:00:00 2001 From: Michael Wan Date: Wed, 2 May 2018 04:39:56 -0400 Subject: [PATCH] bugfix: set container env failed Invalid cross-device link Signed-off-by: Michael Wan --- daemon/mgr/spec_hook.go | 28 +++++++++++++++------------- storage/quota/quota.go | 7 ++++--- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/daemon/mgr/spec_hook.go b/daemon/mgr/spec_hook.go index 6dbe43fcb..18bbc8d90 100644 --- a/daemon/mgr/spec_hook.go +++ b/daemon/mgr/spec_hook.go @@ -52,23 +52,25 @@ func setupHook(ctx context.Context, c *ContainerMeta, specWrapper *SpecWrapper) // setup diskquota hook, if rootFSQuota not set skip this part. rootFSQuota := quota.GetDefaultQuota(c.Config.DiskQuota) - if rootFSQuota != "" { - qid := "0" - if c.Config.QuotaID != "" { - qid = c.Config.QuotaID - } + if rootFSQuota == "" { + return nil + } - target, err := os.Readlink(filepath.Join("/proc", strconv.Itoa(os.Getpid()), "exe")) - if err != nil { - return err - } + qid := "0" + if c.Config.QuotaID != "" { + qid = c.Config.QuotaID + } - s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{ - Path: target, - Args: []string{"set-diskquota", c.BaseFS, rootFSQuota, qid}, - }) + target, err := os.Readlink(filepath.Join("/proc", strconv.Itoa(os.Getpid()), "exe")) + if err != nil { + return err } + s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{ + Path: target, + Args: []string{"set-diskquota", c.BaseFS, rootFSQuota, qid}, + }) + return nil } diff --git a/storage/quota/quota.go b/storage/quota/quota.go index 7cc9021ac..5f81ff0f8 100644 --- a/storage/quota/quota.go +++ b/storage/quota/quota.go @@ -164,12 +164,13 @@ func SetRootfsDiskQuota(basefs, size string, quotaID uint32) error { return fmt.Errorf("failed to set subtree: %v", err) } - err = SetDiskQuota(dir, size, quotaID) - if err != nil { + if err := SetDiskQuota(dir, size, quotaID); err != nil { return fmt.Errorf("failed to set disk quota: %v", err) } - return setQuotaForDir(dir, quotaID) + if err := setQuotaForDir(dir, quotaID); err != nil { + return fmt.Errorf("failed to set dir quota: %v", err) + } } return nil