Skip to content

Commit 65bdadf

Browse files
SuperQpgier
authored andcommitted
Fix overflow in mounstats
Don't use time.Duration for mountstats timing data. These values can be large uint64 milliseconds values and easily overflow time.Duration (in64 nanoseconds). Return the raw time in milliseconds. Signed-off-by: Ben Kochie <[email protected]>
1 parent 3cb620a commit 65bdadf

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

fixtures.ttar

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Max realtime timeout unlimited unlimited us
7575
Mode: 644
7676
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7777
Path: fixtures/proc/26231/mountstats
78-
Lines: 19
78+
Lines: 20
7979
device rootfs mounted on / with fstype rootfs
8080
device sysfs mounted on /sys with fstype sysfs
8181
device proc mounted on /proc with fstype proc
@@ -94,6 +94,7 @@ device 192.168.1.1:/srv/test mounted on /mnt/nfs/test with fstype nfs4 statvers=
9494
NULL: 0 0 0 0 0 0 0 0
9595
READ: 1298 1298 0 207680 1210292152 6 79386 79407
9696
WRITE: 0 0 0 0 0 0 0 0
97+
ACCESS: 2927395007 2927394995 0 526931094212 362996810236 18446743919241604546 1667369447 1953587717
9798

9899
Mode: 644
99100
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -120,6 +121,11 @@ SymlinkTo: net:[4026531993]
120121
Path: fixtures/proc/26231/root
121122
SymlinkTo: /
122123
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124+
Path: fixtures/proc/26231/stat
125+
Lines: 1
126+
26231 (vim) R 5392 7446 5392 34835 7446 4218880 32533 309516 26 82 1677 44 158 99 20 0 1 0 82375 56274944 1981 18446744073709551615 4194304 6294284 140736914091744 140736914087944 139965136429984 0 0 12288 1870679807 0 0 0 17 0 0 0 31 0 0 8391624 8481048 16420864 140736914093252 140736914093279 140736914093279 140736914096107 0
127+
Mode: 644
128+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
123129
Path: fixtures/proc/26231/status
124130
Lines: 53
125131

@@ -177,11 +183,6 @@ voluntary_ctxt_switches: 4742839
177183
nonvoluntary_ctxt_switches: 1727500
178184
Mode: 644
179185
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
180-
Path: fixtures/proc/26231/stat
181-
Lines: 1
182-
26231 (vim) R 5392 7446 5392 34835 7446 4218880 32533 309516 26 82 1677 44 158 99 20 0 1 0 82375 56274944 1981 18446744073709551615 4194304 6294284 140736914091744 140736914087944 139965136429984 0 0 12288 1870679807 0 0 0 17 0 0 0 31 0 0 8391624 8481048 16420864 140736914093252 140736914093279 140736914093279 140736914096107 0
183-
Mode: 644
184-
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
185186
Directory: fixtures/proc/26232
186187
Mode: 755
187188
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

mountstats.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ type NFSOperationStats struct {
181181
// Number of bytes received for this operation, including RPC headers and payload.
182182
BytesReceived uint64
183183
// Duration all requests spent queued for transmission before they were sent.
184-
CumulativeQueueTime time.Duration
184+
CumulativeQueueMilliseconds uint64
185185
// Duration it took to get a reply back after the request was transmitted.
186-
CumulativeTotalResponseTime time.Duration
186+
CumulativeTotalResponseMilliseconds uint64
187187
// Duration from when a request was enqueued to when it was completely handled.
188-
CumulativeTotalRequestTime time.Duration
188+
CumulativeTotalRequestMilliseconds uint64
189189
}
190190

191191
// A NFSTransportStats contains statistics for the NFS mount RPC requests and
@@ -204,7 +204,7 @@ type NFSTransportStats struct {
204204
// spent waiting for connections to the server to be established.
205205
ConnectIdleTime uint64
206206
// Duration since the NFS mount last saw any RPC traffic.
207-
IdleTime time.Duration
207+
IdleTimeSeconds uint64
208208
// Number of RPC requests for this mount sent to the NFS server.
209209
Sends uint64
210210
// Number of RPC responses for this mount received from the NFS server.
@@ -524,15 +524,15 @@ func parseNFSOperationStats(s *bufio.Scanner) ([]NFSOperationStats, error) {
524524
}
525525

526526
ops = append(ops, NFSOperationStats{
527-
Operation: strings.TrimSuffix(ss[0], ":"),
528-
Requests: ns[0],
529-
Transmissions: ns[1],
530-
MajorTimeouts: ns[2],
531-
BytesSent: ns[3],
532-
BytesReceived: ns[4],
533-
CumulativeQueueTime: time.Duration(ns[5]) * time.Millisecond,
534-
CumulativeTotalResponseTime: time.Duration(ns[6]) * time.Millisecond,
535-
CumulativeTotalRequestTime: time.Duration(ns[7]) * time.Millisecond,
527+
Operation: strings.TrimSuffix(ss[0], ":"),
528+
Requests: ns[0],
529+
Transmissions: ns[1],
530+
MajorTimeouts: ns[2],
531+
BytesSent: ns[3],
532+
BytesReceived: ns[4],
533+
CumulativeQueueMilliseconds: ns[5],
534+
CumulativeTotalResponseMilliseconds: ns[6],
535+
CumulativeTotalRequestMilliseconds: ns[7],
536536
})
537537
}
538538

@@ -608,7 +608,7 @@ func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats
608608
Bind: ns[1],
609609
Connect: ns[2],
610610
ConnectIdleTime: ns[3],
611-
IdleTime: time.Duration(ns[4]) * time.Second,
611+
IdleTimeSeconds: ns[4],
612612
Sends: ns[5],
613613
Receives: ns[6],
614614
BadTransactionIDs: ns[7],

mountstats_test.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestMountStats(t *testing.T) {
122122
Bind: 2,
123123
Connect: 3,
124124
ConnectIdleTime: 4,
125-
IdleTime: 5 * time.Second,
125+
IdleTimeSeconds: 5,
126126
Sends: 6,
127127
Receives: 7,
128128
BadTransactionIDs: 8,
@@ -150,7 +150,7 @@ func TestMountStats(t *testing.T) {
150150
Bind: 2,
151151
Connect: 0,
152152
ConnectIdleTime: 0,
153-
IdleTime: 0,
153+
IdleTimeSeconds: 0,
154154
Sends: 3,
155155
Receives: 4,
156156
BadTransactionIDs: 5,
@@ -178,7 +178,7 @@ func TestMountStats(t *testing.T) {
178178
Bind: 2,
179179
Connect: 3,
180180
ConnectIdleTime: 4,
181-
IdleTime: 5 * time.Second,
181+
IdleTimeSeconds: 5,
182182
Sends: 6,
183183
Receives: 7,
184184
BadTransactionIDs: 8,
@@ -206,7 +206,7 @@ func TestMountStats(t *testing.T) {
206206
Bind: 2,
207207
Connect: 0, // these three are not
208208
ConnectIdleTime: 0, // present for UDP
209-
IdleTime: 0, //
209+
IdleTimeSeconds: 0, //
210210
Sends: 3,
211211
Receives: 4,
212212
BadTransactionIDs: 5,
@@ -311,24 +311,34 @@ func TestMountStats(t *testing.T) {
311311
Operation: "NULL",
312312
},
313313
{
314-
Operation: "READ",
315-
Requests: 1298,
316-
Transmissions: 1298,
317-
BytesSent: 207680,
318-
BytesReceived: 1210292152,
319-
CumulativeQueueTime: 6 * time.Millisecond,
320-
CumulativeTotalResponseTime: 79386 * time.Millisecond,
321-
CumulativeTotalRequestTime: 79407 * time.Millisecond,
314+
Operation: "READ",
315+
Requests: 1298,
316+
Transmissions: 1298,
317+
BytesSent: 207680,
318+
BytesReceived: 1210292152,
319+
CumulativeQueueMilliseconds: 6,
320+
CumulativeTotalResponseMilliseconds: 79386,
321+
CumulativeTotalRequestMilliseconds: 79407,
322322
},
323323
{
324324
Operation: "WRITE",
325325
},
326+
{
327+
Operation: "ACCESS",
328+
Requests: 2927395007,
329+
Transmissions: 2927394995,
330+
BytesSent: 526931094212,
331+
BytesReceived: 362996810236,
332+
CumulativeQueueMilliseconds: 18446743919241604546,
333+
CumulativeTotalResponseMilliseconds: 1667369447,
334+
CumulativeTotalRequestMilliseconds: 1953587717,
335+
},
326336
},
327337
Transport: NFSTransportStats{
328338
Protocol: "tcp",
329339
Port: 832,
330340
Connect: 1,
331-
IdleTime: 11 * time.Second,
341+
IdleTimeSeconds: 11,
332342
Sends: 6428,
333343
Receives: 6428,
334344
CumulativeActiveRequests: 12154,

0 commit comments

Comments
 (0)