mirror of
https://github.com/minio/minio.git
synced 2025-01-23 20:53:18 -05:00
fix: drive rotational calculation status for partitions (#17986)
Fix drive rotational calculation status If a MinIO drive path is mounted to a partition and not a real disk, getting the rotational status would fail because Linux does not expose that status to partition; In other words, /sys/block/drive-partition-name/queue/rotational does not exist; To fix the issue, the code will search for the rotational status of the disk that hosts the partition, and this can be calculated from the real path of /sys/class/block/<drive-partition-name>
This commit is contained in:
parent
bfddbb8b40
commit
b9269151a4
@ -24,6 +24,7 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
@ -71,23 +72,36 @@ func GetInfo(path string, firstTime bool) (info Info, err error) {
|
||||
if firstTime {
|
||||
bfs, err := blockdevice.NewDefaultFS()
|
||||
if err == nil {
|
||||
devName := ""
|
||||
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
|
||||
devName = dstat.DeviceName
|
||||
break
|
||||
}
|
||||
}
|
||||
if devName != "" {
|
||||
info.Name = devName
|
||||
qst, err := bfs.SysBlockDeviceQueueStats(devName)
|
||||
if err != nil { // Mostly not found error
|
||||
// Check if there is a parent device:
|
||||
// e.g. if the mount is based on /dev/nvme0n1p1, let's calculate the
|
||||
// real device name (nvme0n1) to get its sysfs information
|
||||
parentDevPath, e := os.Readlink("/sys/class/block/" + devName)
|
||||
if e == nil {
|
||||
parentDev := filepath.Base(filepath.Dir(parentDevPath))
|
||||
qst, err = bfs.SysBlockDeviceQueueStats(parentDev)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
rot := qst.Rotational == 1 // Rotational is '1' if the device is HDD
|
||||
info.Rotational = &rot
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user