Skip to content

Commit

Permalink
Fix for mountstats error due to multiline "impl_id" on FreeNAS (#339)
Browse files Browse the repository at this point in the history
* Fix for mountstats error due to multiline "impl_id" on FreeNAS
This commit fixes an error happening when trying to parse data from FreeNAS NFS
mount point. "impl_id" is printed in multiple lines, which triggers "not enough
information for NFS stats" error.

Signed-off-by: Jakub Wesolowski <[email protected]>
  • Loading branch information
JakubWes authored Dec 14, 2020
1 parent 910e685 commit 7b52fa5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
15 changes: 12 additions & 3 deletions mountstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,12 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e
if len(ss) == 0 {
break
}
if len(ss) < 2 {
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
}

switch ss[0] {
case fieldOpts:
if len(ss) < 2 {
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
}
if stats.Opts == nil {
stats.Opts = map[string]string{}
}
Expand All @@ -356,6 +356,9 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e
}
}
case fieldAge:
if len(ss) < 2 {
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
}
// Age integer is in seconds
d, err := time.ParseDuration(ss[1] + "s")
if err != nil {
Expand All @@ -364,13 +367,19 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e

stats.Age = d
case fieldBytes:
if len(ss) < 2 {
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
}
bstats, err := parseNFSBytesStats(ss[1:])
if err != nil {
return nil, err
}

stats.Bytes = *bstats
case fieldEvents:
if len(ss) < 2 {
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
}
estats, err := parseNFSEventsStats(ss[1:])
if err != nil {
return nil, err
Expand Down
22 changes: 21 additions & 1 deletion mountstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestMountStats(t *testing.T) {
},
{
name: "NFSv4 device with too little info",
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nhello",
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nopts:",
invalid: true,
},
{
Expand Down Expand Up @@ -253,6 +253,26 @@ func TestMountStats(t *testing.T) {
},
}},
},
{
name: "NFS4.1 device with multiline impl_id OK",
s: "device 192.168.0.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nopts: rw,vers=4.1,rsize=131072,wsize=131072,namlen=255,acregmin=3,acregmax=60,acdirmin=30,acdirmax=60,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.0.2,fsc,local_lock=none\nage: 1234567\nimpl_id: name='FreeBSD 11.2-STABLE #0 r325575+c9231c7d6bd(HEAD): Mon Nov 18 22:46:47 UTC 2019\nuser@host:/path/to/something'\n,domain='something.org',date='1293840000,0'",
mounts: []*Mount{{
Device: "192.168.0.1:/srv",
Mount: "/mnt/nfs",
Type: "nfs4",
Stats: &MountStatsNFS{
StatVersion: "1.1",
Opts: map[string]string{"rw": "", "vers": "4.1",
"rsize": "131072", "wsize": "131072", "namlen": "255", "acregmin": "3",
"acregmax": "60", "acdirmin": "30", "acdirmax": "60", "fsc": "", "hard": "",
"proto": "tcp", "timeo": "600", "retrans": "2",
"sec": "sys", "clientaddr": "192.168.0.2",
"local_lock": "none",
},
Age: 1234567 * time.Second,
},
}},
},
{
name: "fixtures/proc OK",
mounts: []*Mount{
Expand Down

0 comments on commit 7b52fa5

Please sign in to comment.