Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/fs/zfs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func GetZfsStats(poolName string) (uint64, uint64, uint64, error) {
// parseZfsListUsage parses one line of
// `zfs list -Hp -o used,available,usedbydataset` output (tab-separated). A "-"
// value is treated as 0 (matching go-zfs's setUint). It returns
// (capacity, free, available) preserving cAdvisor's original arithmetic.
// (capacity, free, available). The usedbydataset value is parsed for validation
// but not added to capacity because it is already included in used.
func parseZfsListUsage(out []byte) (uint64, uint64, uint64, error) {
fields := strings.Fields(string(out))
if len(fields) != 3 {
Expand All @@ -51,11 +52,10 @@ func parseZfsListUsage(out []byte) (uint64, uint64, uint64, error) {
if err != nil {
return 0, 0, 0, err
}
usedByDataset, err := parseZfsUint(fields[2])
if err != nil {
if _, err := parseZfsUint(fields[2]); err != nil {
return 0, 0, 0, err
}
return used + avail + usedByDataset, avail, avail, nil
return used + avail, avail, avail, nil
}

func parseZfsUint(s string) (uint64, error) {
Expand Down
6 changes: 3 additions & 3 deletions lib/fs/zfs/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestParseZfsListUsage(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if want := uint64(123456 + 789012 + 654321); capacity != want {
if want := uint64(123456 + 789012); capacity != want {
t.Errorf("capacity = %d, want %d", capacity, want)
}
if free != 789012 || avail != 789012 {
Expand All @@ -34,8 +34,8 @@ func TestParseZfsListUsage(t *testing.T) {
if err != nil {
t.Fatalf("dash value: unexpected error: %v", err)
}
if capacity != 150 {
t.Errorf("capacity with dash = %d, want 150", capacity)
if capacity != 100 {
t.Errorf("capacity with dash = %d, want 100", capacity)
}

// Wrong field count must error rather than silently misparse.
Expand Down