From acaf371fc05725637bf4afe0ad05f5eccc7f4aa3 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 13 Aug 2023 17:29:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=93=E5=AD=98=E7=A3=81?= =?UTF-8?q?=E7=9B=98=E6=80=BB=E4=BD=93=E7=BB=9F=E8=AE=A1=E6=97=B6=E5=90=8C?= =?UTF-8?q?=E5=88=86=E5=8C=BA=E9=87=8D=E5=A4=8D=E7=BB=9F=E8=AE=A1=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/manager.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/caches/manager.go b/internal/caches/manager.go index a4cde69..b5b5714 100644 --- a/internal/caches/manager.go +++ b/internal/caches/manager.go @@ -1,6 +1,7 @@ package caches import ( + "fmt" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" teaconst "github.com/TeaOSLab/EdgeNode/internal/const" @@ -8,6 +9,7 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/types" + "golang.org/x/sys/unix" "strconv" "sync" ) @@ -176,8 +178,30 @@ func (this *Manager) TotalDiskSize() int64 { defer this.locker.RUnlock() var total = int64(0) + var sidMap = map[string]bool{} // partition sid => bool for _, storage := range this.storageMap { - total += storage.TotalDiskSize() + // 这里不能直接用 storage.TotalDiskSize() 相加,因为多个缓存策略缓存目录可能处在同一个分区目录下 + fileStorage, ok := storage.(*FileStorage) + if ok { + var options = fileStorage.options // copy + if options != nil { + var dir = options.Dir // copy + if len(dir) == 0 { + continue + } + var stat = &unix.Statfs_t{} + err := unix.Statfs(dir, stat) + if err != nil { + continue + } + var sid = fmt.Sprintf("%d_%d", stat.Fsid.Val[0], stat.Fsid.Val[1]) + if sidMap[sid] { + continue + } + sidMap[sid] = true + total += int64(stat.Blocks-stat.Bfree) * int64(stat.Bsize) // we add extra int64() for darwin + } + } } if total < 0 {