Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: don't update quota in rename if both src & dst are under the same quota #3872

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,10 @@ func (m *baseMeta) getDirParent(ctx Context, inode Ino) (Ino, syscall.Errno) {
return attr.Parent, st
}

func (m *baseMeta) hasDirQuota(ctx Context, inode Ino) bool {
// get inode of the first parent (or myself) with quota
func (m *baseMeta) getQuotaParent(ctx Context, inode Ino) Ino {
if !m.GetFormat().DirStats {
return false
return 0
}
var q *Quota
var st syscall.Errno
Expand All @@ -692,7 +693,7 @@ func (m *baseMeta) hasDirQuota(ctx Context, inode Ino) bool {
q = m.dirQuotas[inode]
m.quotaMu.RUnlock()
if q != nil {
return true
return inode
}
if inode <= RootInode {
break
Expand All @@ -702,7 +703,7 @@ func (m *baseMeta) hasDirQuota(ctx Context, inode Ino) bool {
break
}
}
return false
return 0
}

func (m *baseMeta) checkDirQuota(ctx Context, inode Ino, space, inodes int64) bool {
Expand Down Expand Up @@ -1528,15 +1529,17 @@ func (m *baseMeta) Rename(ctx Context, parentSrc Ino, nameSrc string, parentDst
}
parentSrc = m.checkRoot(parentSrc)
parentDst = m.checkRoot(parentDst)
var quotaSrc bool = !isTrash(parentSrc) && m.hasDirQuota(ctx, parentSrc)
var quotaDst bool
var quotaSrc, quotaDst Ino
if !isTrash(parentSrc) {
quotaSrc = m.getQuotaParent(ctx, parentSrc)
}
if parentSrc == parentDst {
quotaDst = quotaSrc
} else {
quotaDst = m.hasDirQuota(ctx, parentDst)
quotaDst = m.getQuotaParent(ctx, parentDst)
}
var space, inodes int64
if parentSrc != parentDst && (quotaSrc || quotaDst) {
if quotaSrc != quotaDst {
if st := m.Lookup(ctx, parentSrc, nameSrc, inode, attr, false); st != 0 {
return st
}
Expand All @@ -1559,7 +1562,7 @@ func (m *baseMeta) Rename(ctx Context, parentSrc Ino, nameSrc string, parentDst
space, inodes = align4K(attr.Length), 1
}
// TODO: dst exists and is replaced or exchanged
if quotaDst && m.checkDirQuota(ctx, parentDst, space, inodes) {
if quotaDst > 0 && m.checkDirQuota(ctx, parentDst, space, inodes) {
return syscall.EDQUOT
}
}
Expand All @@ -1578,11 +1581,13 @@ func (m *baseMeta) Rename(ctx Context, parentSrc Ino, nameSrc string, parentDst
if parentSrc != parentDst {
m.updateDirStat(ctx, parentSrc, -int64(diffLength), -align4K(diffLength), -1)
m.updateDirStat(ctx, parentDst, int64(diffLength), align4K(diffLength), 1)
if quotaSrc {
m.updateDirQuota(ctx, parentSrc, -space, -inodes)
}
if quotaDst {
m.updateDirQuota(ctx, parentDst, space, inodes)
if quotaSrc != quotaDst {
if quotaSrc > 0 {
m.updateDirQuota(ctx, parentSrc, -space, -inodes)
}
if quotaDst > 0 {
m.updateDirQuota(ctx, parentDst, space, inodes)
}
}
}
if *tinode > 0 && flags != RenameExchange {
Expand All @@ -1595,7 +1600,7 @@ func (m *baseMeta) Rename(ctx Context, parentSrc Ino, nameSrc string, parentDst
diffLength = tattr.Length
}
m.updateDirStat(ctx, parentDst, -int64(diffLength), -align4K(diffLength), -1)
if quotaDst {
if quotaDst > 0 {
m.updateDirQuota(ctx, parentDst, -align4K(diffLength), -1)
}
}
Expand Down