Skip to content

Commit e72bf7a

Browse files
authored
Fix bcachefs parsing (#789)
The earlier test fixture was a few months old. Updated test fixtures and fs version parsing to match latest bcachefs semantics. Signed-off-by: Ananth Bhaskararaman <antsub@gmail.com>
1 parent 56add94 commit e72bf7a

File tree

3 files changed

+58
-36
lines changed

3 files changed

+58
-36
lines changed

bcachefs/get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func parseCounterFile(path string) (CounterStats, error) {
339339
for scanner.Scan() {
340340
line := scanner.Text()
341341
if valueStr, ok := strings.CutPrefix(line, "since mount:"); ok {
342-
value, err := strconv.ParseUint(strings.TrimSpace(valueStr), 10, 64)
342+
value, err := parseHumanReadableBytes(valueStr)
343343
if err != nil {
344344
return CounterStats{}, err
345345
}
@@ -348,7 +348,7 @@ func parseCounterFile(path string) (CounterStats, error) {
348348
continue
349349
}
350350
if valueStr, ok := strings.CutPrefix(line, "since filesystem creation:"); ok {
351-
value, err := strconv.ParseUint(strings.TrimSpace(valueStr), 10, 64)
351+
value, err := parseHumanReadableBytes(valueStr)
352352
if err != nil {
353353
return CounterStats{}, err
354354
}

bcachefs/get_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
package bcachefs
1515

16-
import "testing"
16+
import (
17+
"os"
18+
"path/filepath"
19+
"testing"
20+
)
1721

1822
func TestParseHumanReadableBytes(t *testing.T) {
1923
tests := []struct {
@@ -85,3 +89,32 @@ func TestFSBcachefsStats(t *testing.T) {
8589
t.Fatalf("unexpected io_done read btree: %d", dev.IODone["read"]["btree"])
8690
}
8791
}
92+
93+
func TestParseCounterFileHumanReadable(t *testing.T) {
94+
dir := t.TempDir()
95+
path := filepath.Join(dir, "counter")
96+
if err := os.WriteFile(path, []byte("since mount: 2.05G\nsince filesystem creation: 1.5T\n"), 0o644); err != nil {
97+
t.Fatalf("write counter file: %v", err)
98+
}
99+
100+
got, err := parseCounterFile(path)
101+
if err != nil {
102+
t.Fatalf("parseCounterFile error: %v", err)
103+
}
104+
105+
wantMount, err := parseHumanReadableBytes("2.05G")
106+
if err != nil {
107+
t.Fatalf("parseHumanReadableBytes mount error: %v", err)
108+
}
109+
wantCreation, err := parseHumanReadableBytes("1.5T")
110+
if err != nil {
111+
t.Fatalf("parseHumanReadableBytes creation error: %v", err)
112+
}
113+
114+
if got.SinceMount != wantMount {
115+
t.Fatalf("since mount = %d, want %d", got.SinceMount, wantMount)
116+
}
117+
if got.SinceFilesystemCreation != wantCreation {
118+
t.Fatalf("since filesystem creation = %d, want %d", got.SinceFilesystemCreation, wantCreation)
119+
}
120+
}

testdata/fixtures.ttar

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18232,72 +18232,61 @@ Lines: 1
1823218232
Mode: 644
1823318233
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1823418234
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/btree_write_stats
18235-
Lines: 3
18236-
nr size
18237-
initial: 19088 108k
18238-
journal_reclaim: 541080 405
18235+
Lines: 2
18236+
type count size
18237+
initial: 19088 1.0G
1823918238
Mode: 644
1824018239
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1824118240
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/compression_stats
18242-
Lines: 3
18243-
type compressed uncompressed average extent size
18244-
lz4: 19.3G 67.0G 112k
18245-
incompressible: 5.5G 5.5G 22k
18241+
Lines: 2
18242+
compression compressed uncompressed average
18243+
lz4: 1.0G 2.0G 4k
1824618244
Mode: 644
1824718245
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1824818246
Directory: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/counters
1824918247
Mode: 755
1825018248
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1825118249
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/counters/btree_node_read
1825218250
Lines: 2
18253-
since mount: 12345
18254-
since filesystem creation: 67890
18251+
since mount: 123
18252+
since filesystem creation: 67890
1825518253
Mode: 644
1825618254
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1825718255
Directory: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/dev-1
1825818256
Mode: 755
1825918257
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1826018258
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/dev-1/bucket_size
1826118259
Lines: 1
18262-
1.0M
18260+
128k
1826318261
Mode: 644
1826418262
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1826518263
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/dev-1/durability
1826618264
Lines: 1
18267-
2
18265+
1
1826818266
Mode: 644
1826918267
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1827018268
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/dev-1/io_done
18271-
Lines: 11
18269+
Lines: 6
1827218270
read:
18273-
18274-
sb : 3989504
18275-
btree : 4411097088
18276-
user :5768222552064
18277-
18271+
btree: 4411097088
18272+
data: 0
1827818273
write:
18279-
18280-
sb : 31417344
18281-
btree : 1171456
18282-
user : 39196815360
18274+
btree: 0
18275+
data: 0
1828318276
Mode: 644
1828418277
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1828518278
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/dev-1/io_errors
18286-
Lines: 9
18279+
Lines: 5
1828718280
IO errors since filesystem creation
18288-
18289-
read: 197346
18290-
write: 0
18291-
checksum:0
18292-
18293-
IO errors since 8 y ago
18294-
18295-
read: 197346
18281+
read: 197346
18282+
write: 0
18283+
IO errors since last mount
18284+
read: 0
1829618285
Mode: 644
1829718286
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1829818287
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/dev-1/label
1829918288
Lines: 1
18300-
data0
18289+
testdev
1830118290
Mode: 644
1830218291
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1830318292
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/dev-1/nbuckets
@@ -18312,7 +18301,7 @@ Mode: 644
1831218301
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1831318302
Path: fixtures/sys/fs/bcachefs/deadbeef-1234-5678-9012-abcdefabcdef/errors
1831418303
Lines: 1
18315-
btree_node_read_err 5 1234567890
18304+
btree_node_read_err 5 0
1831618305
Mode: 644
1831718306
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1831818307
Directory: fixtures/sys/fs/btrfs

0 commit comments

Comments
 (0)