You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package mount
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/hanwen/go-fuse/v2/fuse"
  6. "github.com/seaweedfs/seaweedfs/weed/glog"
  7. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  8. "math"
  9. "time"
  10. )
  11. const blockSize = 512
  12. type statsCache struct {
  13. filer_pb.StatisticsResponse
  14. lastChecked int64 // unix time in seconds
  15. }
  16. func (wfs *WFS) StatFs(cancel <-chan struct{}, in *fuse.InHeader, out *fuse.StatfsOut) (code fuse.Status) {
  17. // glog.V(4).Infof("reading fs stats")
  18. if wfs.stats.lastChecked < time.Now().Unix()-20 {
  19. err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  20. request := &filer_pb.StatisticsRequest{
  21. Collection: wfs.option.Collection,
  22. Replication: wfs.option.Replication,
  23. Ttl: fmt.Sprintf("%ds", wfs.option.TtlSec),
  24. DiskType: string(wfs.option.DiskType),
  25. }
  26. glog.V(4).Infof("reading filer stats: %+v", request)
  27. resp, err := client.Statistics(context.Background(), request)
  28. if err != nil {
  29. glog.V(0).Infof("reading filer stats %v: %v", request, err)
  30. return err
  31. }
  32. glog.V(4).Infof("read filer stats: %+v", resp)
  33. wfs.stats.TotalSize = resp.TotalSize
  34. wfs.stats.UsedSize = resp.UsedSize
  35. wfs.stats.FileCount = resp.FileCount
  36. wfs.stats.lastChecked = time.Now().Unix()
  37. return nil
  38. })
  39. if err != nil {
  40. glog.V(0).Infof("filer Statistics: %v", err)
  41. return fuse.OK
  42. }
  43. }
  44. totalDiskSize := wfs.stats.TotalSize
  45. usedDiskSize := wfs.stats.UsedSize
  46. actualFileCount := wfs.stats.FileCount
  47. if wfs.option.Quota > 0 && totalDiskSize > uint64(wfs.option.Quota) {
  48. totalDiskSize = uint64(wfs.option.Quota)
  49. if usedDiskSize > totalDiskSize {
  50. totalDiskSize = usedDiskSize
  51. }
  52. }
  53. // Compute the total number of available blocks
  54. out.Blocks = totalDiskSize / blockSize
  55. // Compute the number of used blocks
  56. numBlocks := uint64(usedDiskSize / blockSize)
  57. // Report the number of free and available blocks for the block size
  58. out.Bfree = out.Blocks - numBlocks
  59. out.Bavail = out.Blocks - numBlocks
  60. out.Bsize = uint32(blockSize)
  61. // Report the total number of possible files in the file system (and those free)
  62. out.Files = math.MaxInt64
  63. out.Ffree = math.MaxInt64 - actualFileCount
  64. // Report the maximum length of a name and the minimum fragment size
  65. out.NameLen = 1024
  66. out.Frsize = uint32(blockSize)
  67. return fuse.OK
  68. }