summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-12-14 16:19:07 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2022-12-20 20:03:44 -0700
commit94a86a763157327ac969c98e19d7770db477a6a3 (patch)
treef2395593d4d4cfd12b26ba2030bb94930fe4ba56 /lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go
parent1674500388d1e0837103a870f0b96f1f1dab2206 (diff)
Migrate existing progress logs to textui.NewProgress
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go')
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go
index 9174035..3575534 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go
@@ -6,6 +6,8 @@ package rebuildnodes
import (
"context"
+ "fmt"
+ "time"
"github.com/datawire/dlib/dlog"
@@ -17,6 +19,7 @@ import (
"git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect/rebuildnodes/uuidmap"
"git.lukeshu.com/btrfs-progs-ng/lib/containers"
"git.lukeshu.com/btrfs-progs-ng/lib/maps"
+ "git.lukeshu.com/btrfs-progs-ng/lib/textui"
)
type scanResult struct {
@@ -24,6 +27,16 @@ type scanResult struct {
nodeGraph *graph.Graph
}
+type scanStats struct {
+ N, D int
+}
+
+func (s scanStats) String() string {
+ return fmt.Sprintf("... %v%% (%v/%v)",
+ int(100*float64(s.N)/float64(s.D)),
+ s.N, s.D)
+}
+
func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.ScanDevicesResult) (*scanResult, error) {
dlog.Infof(ctx, "Reading node data from FS...")
@@ -32,16 +45,11 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.Sca
return nil, err
}
- lastPct := -1
total := countNodes(scanResults)
done := 0
+ progressWriter := textui.NewProgress[scanStats](ctx, dlog.LogLevelInfo, 1*time.Second)
progress := func(done, total int) {
- pct := int(100 * float64(done) / float64(total))
- if pct != lastPct || done == total {
- dlog.Infof(ctx, "... %v%% (%v/%v)",
- pct, done, total)
- lastPct = pct
- }
+ progressWriter.Set(scanStats{N: done, D: total})
}
ret := &scanResult{
@@ -69,10 +77,10 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.Sca
progress(done, total)
}
}
-
if done != total {
panic("should not happen")
}
+ progressWriter.Done()
missing := ret.uuidMap.MissingRootItems()
if len(missing) > 0 {
@@ -81,10 +89,12 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.Sca
dlog.Info(ctx, "... done reading node data")
+ progressWriter = textui.NewProgress[scanStats](ctx, dlog.LogLevelInfo, 1*time.Second)
dlog.Infof(ctx, "Checking keypointers for dead-ends...")
if err := ret.nodeGraph.FinalCheck(fs, *sb, progress); err != nil {
return nil, err
}
+ progressWriter.Done()
dlog.Info(ctx, "... done checking keypointers")
return ret, nil