mirror of
https://github.com/minio/minio.git
synced 2026-02-04 18:00:15 -05:00
fix: optimize DiskInfo() call avoid metrics when not needed (#17763)
This commit is contained in:
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFree(t *testing.T) {
|
||||
di, err := disk.GetInfo(t.TempDir())
|
||||
di, err := disk.GetInfo(t.TempDir(), true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, _ bool) (info Info, err error) {
|
||||
s := syscall.Statfs_t{}
|
||||
err = syscall.Statfs(path, &s)
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, _ bool) (info Info, err error) {
|
||||
s := syscall.Statfs_t{}
|
||||
err = syscall.Statfs(path, &s)
|
||||
if err != nil {
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
)
|
||||
|
||||
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, firstTime bool) (info Info, err error) {
|
||||
s := syscall.Statfs_t{}
|
||||
err = syscall.Statfs(path, &s)
|
||||
if err != nil {
|
||||
@@ -68,23 +68,25 @@ func GetInfo(path string) (info Info, err error) {
|
||||
}
|
||||
info.Used = info.Total - info.Free
|
||||
|
||||
bfs, err := blockdevice.NewDefaultFS()
|
||||
if err == nil {
|
||||
diskstats, _ := bfs.ProcDiskstats()
|
||||
for _, dstat := range diskstats {
|
||||
// ignore all loop devices
|
||||
if strings.HasPrefix(dstat.DeviceName, "loop") {
|
||||
continue
|
||||
}
|
||||
qst, err := bfs.SysBlockDeviceQueueStats(dstat.DeviceName)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
rot := qst.Rotational == 1 // Rotational is '1' if the device is HDD
|
||||
if dstat.MajorNumber == info.Major && dstat.MinorNumber == info.Minor {
|
||||
info.Name = dstat.DeviceName
|
||||
info.Rotational = &rot
|
||||
break
|
||||
if firstTime {
|
||||
bfs, err := blockdevice.NewDefaultFS()
|
||||
if err == nil {
|
||||
diskstats, _ := bfs.ProcDiskstats()
|
||||
for _, dstat := range diskstats {
|
||||
// ignore all loop devices
|
||||
if strings.HasPrefix(dstat.DeviceName, "loop") {
|
||||
continue
|
||||
}
|
||||
qst, err := bfs.SysBlockDeviceQueueStats(dstat.DeviceName)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
rot := qst.Rotational == 1 // Rotational is '1' if the device is HDD
|
||||
if dstat.MajorNumber == info.Major && dstat.MinorNumber == info.Minor {
|
||||
info.Name = dstat.DeviceName
|
||||
info.Rotational = &rot
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func getFSType(ftype int32) string {
|
||||
}
|
||||
|
||||
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, _ bool) (info Info, err error) {
|
||||
s := syscall.Statfs_t{}
|
||||
err = syscall.Statfs(path, &s)
|
||||
if err != nil {
|
||||
|
||||
@@ -58,7 +58,7 @@ func getFSType(ftype uint32) string {
|
||||
}
|
||||
|
||||
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, _ bool) (info Info, err error) {
|
||||
s := syscall.Statfs_t{}
|
||||
err = syscall.Statfs(path, &s)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, _ bool) (info Info, err error) {
|
||||
s := unix.Statvfs_t{}
|
||||
if err = unix.Statvfs(path, &s); err != nil {
|
||||
return Info{}, err
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, _ bool) (info Info, err error) {
|
||||
s := syscall.Statfs_t{}
|
||||
err = syscall.Statfs(path, &s)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, _ bool) (info Info, err error) {
|
||||
s := unix.Statvfs_t{}
|
||||
if err = unix.Statvfs(path, &s); err != nil {
|
||||
return Info{}, err
|
||||
|
||||
@@ -48,7 +48,7 @@ var (
|
||||
// It returns free space available to the user (including quota limitations)
|
||||
//
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
|
||||
func GetInfo(path string) (info Info, err error) {
|
||||
func GetInfo(path string, _ bool) (info Info, err error) {
|
||||
// Stat to know if the path exists.
|
||||
if _, err = os.Stat(path); err != nil {
|
||||
return Info{}, err
|
||||
|
||||
Reference in New Issue
Block a user