Skip to content

Commit a0708ee

Browse files
authored
Merge pull request #3351 from fusida/fix-nfs
fix performance degradation of NFS
2 parents 248756c + 51dfa4c commit a0708ee

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

fs/fs.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ func (i *RealFsInfo) GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, error
386386
if err != nil {
387387
return nil, err
388388
}
389+
nfsInfo := make(map[string]Fs, 0)
389390
for device, partition := range i.partitions {
390391
_, hasMount := mountSet[partition.mountpoint]
391392
_, hasDevice := deviceSet[device]
@@ -394,7 +395,11 @@ func (i *RealFsInfo) GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, error
394395
err error
395396
fs Fs
396397
)
397-
switch partition.fsType {
398+
fsType := partition.fsType
399+
if strings.HasPrefix(partition.fsType, "nfs") {
400+
fsType = "nfs"
401+
}
402+
switch fsType {
398403
case DeviceMapper.String():
399404
fs.Capacity, fs.Free, fs.Available, err = getDMStats(device, partition.blockSize)
400405
klog.V(5).Infof("got devicemapper fs capacity stats: capacity: %v free: %v available: %v:", fs.Capacity, fs.Free, fs.Available)
@@ -407,6 +412,22 @@ func (i *RealFsInfo) GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, error
407412
}
408413
// if /dev/zfs is not present default to VFS
409414
fallthrough
415+
case NFS.String():
416+
if !utils.FileExists(partition.mountpoint) {
417+
klog.V(4).Infof("the file system type is %s, partition mountpoint does not exist: %v", partition.fsType, partition.mountpoint)
418+
break
419+
}
420+
devId := fmt.Sprintf("%d:%d", partition.major, partition.minor)
421+
if v, ok := nfsInfo[devId]; ok {
422+
fs = v
423+
break
424+
}
425+
var inodes, inodesFree uint64
426+
fs.Capacity, fs.Free, fs.Available, inodes, inodesFree, err = getVfsStats(partition.mountpoint)
427+
fs.Inodes = &inodes
428+
fs.InodesFree = &inodesFree
429+
fs.Type = VFS
430+
nfsInfo[devId] = fs
410431
default:
411432
var inodes, inodesFree uint64
412433
if utils.FileExists(partition.mountpoint) {

fs/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const (
5757
ZFS FsType = "zfs"
5858
DeviceMapper FsType = "devicemapper"
5959
VFS FsType = "vfs"
60+
NFS FsType = "nfs"
6061
)
6162

6263
type Fs struct {

0 commit comments

Comments
 (0)