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

fsck: ignore dir stats when it's disabled #3831

Merged
merged 2 commits into from
Jun 20, 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
68 changes: 39 additions & 29 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,14 @@ func (m *baseMeta) Check(ctx Context, fpath string, repair bool, recursive bool,
}
}()

format, err := m.Load(false)
if err != nil {
return errors.Wrap(err, "load meta format")
}
if statAll && !format.DirStats {
logger.Warn("dir stats is disabled, flag '--sync-dir-stat' will be ignored")
}

var wg sync.WaitGroup
for i := 0; i < 20; i++ {
wg.Add(1)
Expand Down Expand Up @@ -2027,45 +2035,47 @@ func (m *baseMeta) Check(ctx Context, fpath string, repair bool, recursive bool,
}
}

stat, st := m.en.doGetDirStat(ctx, inode, false)
if st == syscall.ENOENT {
continue
}
if st != 0 {
hasError = true
logger.Errorf("get dir stat for inode %d: %v", inode, st)
continue
}
if stat == nil || stat.space < 0 || stat.inodes < 0 {
logger.Warnf("usage stat of %s is missing or broken", path)
statBroken = true
}

if !repair && statAll {
s, st := m.calcDirStat(ctx, inode)
if format.DirStats {
stat, st := m.en.doGetDirStat(ctx, inode, false)
if st == syscall.ENOENT {
continue
}
if st != 0 {
hasError = true
logger.Errorf("calc dir stat for inode %d: %v", inode, st)
logger.Errorf("get dir stat for inode %d: %v", inode, st)
continue
}
if stat.space != s.space || stat.inodes != s.inodes {
logger.Warnf("usage stat of %s should be %v, but got %v", path, s, stat)
if stat == nil || stat.space < 0 || stat.inodes < 0 {
logger.Warnf("usage stat of %s is missing or broken", path)
statBroken = true
}
}

if repair {
if statBroken || statAll {
if _, st := m.en.doSyncDirStat(ctx, inode); st == 0 || st == syscall.ENOENT {
logger.Debugf("Stat of path %s (inode %d) is successfully synced", path, inode)
} else {
if !repair && statAll {
s, st := m.calcDirStat(ctx, inode)
if st != 0 {
hasError = true
logger.Errorf("Sync stat of path %s inode %d: %s", path, inode, st)
logger.Errorf("calc dir stat for inode %d: %v", inode, st)
continue
}
if stat.space != s.space || stat.inodes != s.inodes {
logger.Warnf("usage stat of %s should be %v, but got %v", path, s, stat)
statBroken = true
}
}
} else if statBroken {
logger.Warnf("Stat of path %s (inode %d) should be synced, please re-run with '--path %s --repair --sync-dir-stat' to fix it", path, inode, path)
hasError = true

if repair {
if statBroken || statAll {
if _, st := m.en.doSyncDirStat(ctx, inode); st == 0 || st == syscall.ENOENT {
logger.Debugf("Stat of path %s (inode %d) is successfully synced", path, inode)
} else {
hasError = true
logger.Errorf("Sync stat of path %s inode %d: %s", path, inode, st)
}
}
} else if statBroken {
logger.Warnf("Stat of path %s (inode %d) should be synced, please re-run with '--path %s --repair --sync-dir-stat' to fix it", path, inode, path)
hasError = true
}
}
}
}()
Expand Down