Skip to content

Commit

Permalink
Expose xs_qm_dquot_unused XFS counter
Browse files Browse the repository at this point in the history
Add support for exposing the xs_qm_dquot_unused XFS statistic which appears in
Linux 4.20 and later.

Signed-off-by: Steven Kreuzer <[email protected]>
  • Loading branch information
skreuzer authored and discordianfish committed Feb 4, 2020
1 parent 522e93c commit 584181f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
18 changes: 14 additions & 4 deletions xfs/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,15 @@ func extendedPrecisionStats(us []uint64) (ExtendedPrecisionStats, error) {
}

func quotaManagerStats(us []uint32) (QuotaManagerStats, error) {
if l := len(us); l < 8 {
return QuotaManagerStats{}, fmt.Errorf("insufficient number of values for XFS quota stats expecting at least 8, got: %d", l)
// The "Unused" attribute first appears in Linux 4.20
// As a result either 8 or 9 elements may appear in this slice depending on
// the kernel version.
l := len(us)
if l != 8 && l != 9 {
return QuotaManagerStats{}, fmt.Errorf("incorrect number of values for XFS quota stats: %d", l)
}

return QuotaManagerStats{
s := QuotaManagerStats{
Reclaims: us[0],
ReclaimMisses: us[1],
DquoteDups: us[2],
Expand All @@ -394,7 +398,13 @@ func quotaManagerStats(us []uint32) (QuotaManagerStats, error) {
Wants: us[5],
ShakeReclaims: us[6],
InactReclaims: us[7],
}, nil
}

if l > 8 {
s.Unused = us[8]
}

return s, nil
}

func debugStats(us []uint32) (DebugStats, error) {
Expand Down
22 changes: 22 additions & 0 deletions xfs/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ func TestParseStats(t *testing.T) {
s: "qm 1 2 3 4 5 6 7",
invalid: true,
},
{
name: "qm bad",
s: "qm 1 2 3 4 5 6 7 8 9 10",
invalid: true,
},
{
name: "qm OK",
s: "qm 1 2 3 4 5 6 7 8",
Expand All @@ -384,6 +389,23 @@ func TestParseStats(t *testing.T) {
},
},
},
{
name: "qm OK",
s: "qm 1 2 3 4 5 6 7 8 9",
stats: &xfs.Stats{
QuotaManager: xfs.QuotaManagerStats{
Reclaims: 1,
ReclaimMisses: 2,
DquoteDups: 3,
CacheMisses: 4,
CacheHits: 5,
Wants: 6,
ShakeReclaims: 7,
InactReclaims: 8,
Unused: 9,
},
},
},
{
name: "abtb2 bad",
s: "abtb2 1 2 3 4 5 6",
Expand Down
1 change: 1 addition & 0 deletions xfs/xfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ type QuotaManagerStats struct {
Wants uint32
ShakeReclaims uint32
InactReclaims uint32
Unused uint32
}

// XstratStats contains statistics regarding bytes processed by the XFS daemon.
Expand Down

0 comments on commit 584181f

Please sign in to comment.