Skip to content

Commit

Permalink
bugfix: fix update container rootfs disk quota recursively timeout
Browse files Browse the repository at this point in the history
Updating disk quota to a running container will set quota ID to all files
and directories under UpperDir in function SetQuotaForDir, which will
take a long while. Because it will costs much time in
getMountpointFstype, CheckRegularFile and filepath.Walk.

Call SetQuotaForDir Asynchronously when updating disk quota .

Signed-off-by: Wang Rui <baijia.wr@antfin.com>
  • Loading branch information
zjumoon01 authored and rudyfly committed Jun 24, 2019
1 parent a43bd5f commit e7226ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ func (mgr *ContainerManager) updateContainerDiskQuota(ctx context.Context, c *Co
}

// set mount point disk quota
if err = mgr.setDiskQuota(ctx, c, false); err != nil {
if err = mgr.setDiskQuota(ctx, c, false, true); err != nil {
return errors.Wrapf(err, "failed to set mount point disk quota")
}

Expand Down
6 changes: 3 additions & 3 deletions daemon/mgr/container_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func checkDupQuotaMap(qms []*quota.QMap, qm *quota.QMap) *quota.QMap {
return nil
}

func (mgr *ContainerManager) setDiskQuota(ctx context.Context, c *Container, mounted bool) error {
func (mgr *ContainerManager) setDiskQuota(ctx context.Context, c *Container, mounted bool, update bool) error {
var (
err error
globalQuotaID uint32
Expand Down Expand Up @@ -629,7 +629,7 @@ func (mgr *ContainerManager) setDiskQuota(ctx context.Context, c *Container, mou
for _, qm := range qms {
if qm.Destination == "/" {
// set rootfs quota
_, err = quota.SetRootfsDiskQuota(qm.Source, qm.Size, qm.QuotaID)
_, err = quota.SetRootfsDiskQuota(qm.Source, qm.Size, qm.QuotaID, update)
if err != nil {
logrus.Warnf("failed to set rootfs quota, mountfs(%s), size(%s), quota id(%d), err(%v)",
qm.Source, qm.Size, qm.QuotaID, err)
Expand Down Expand Up @@ -763,7 +763,7 @@ func (mgr *ContainerManager) initContainerStorage(ctx context.Context, c *Contai
}

// set mount point disk quota
if err = mgr.setDiskQuota(ctx, c, true); err != nil {
if err = mgr.setDiskQuota(ctx, c, true, false); err != nil {
// just ignore failed to set disk quota
logrus.Warnf("failed to set disk quota, err(%v)", err)
}
Expand Down
6 changes: 4 additions & 2 deletions storage/quota/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func GetQuotaID(dir string) (uint32, error) {
}

// SetRootfsDiskQuota is to set container rootfs dir disk quota.
func SetRootfsDiskQuota(basefs, size string, quotaID uint32) (uint32, error) {
func SetRootfsDiskQuota(basefs, size string, quotaID uint32, update bool) (uint32, error) {
overlayMountInfo, err := getOverlayMountInfo(basefs)
if err != nil {
return 0, errors.Wrapf(err, "failed to get overlay(%s) mount info", basefs)
Expand All @@ -211,7 +211,9 @@ func SetRootfsDiskQuota(basefs, size string, quotaID uint32) (uint32, error) {
return 0, errors.Wrapf(err, "failed to set dir(%s) disk quota", dir)
}

if err := SetQuotaForDir(dir, quotaID); err != nil {
if update {
go SetQuotaForDir(dir, quotaID)
} else if err := SetQuotaForDir(dir, quotaID); err != nil {
return 0, errors.Wrapf(err, "failed to set dir(%s) quota recursively", dir)
}
}
Expand Down

0 comments on commit e7226ef

Please sign in to comment.