diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-18 01:12:13 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-18 01:55:55 -0600 |
commit | ee0d8981e501c86774f3ec45466d3273464921e8 (patch) | |
tree | 4ae03e4ee5293ca99e7fc9bd8393d810766d90b0 | |
parent | 286db83409b56de7b0ac3a74709018c01de43f44 (diff) |
Get inspect-scandevices to a decent-ish place
-rw-r--r-- | cmd/btrfs-rec/inspect_scandevices.go | 33 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/scandevices.go | 8 | ||||
-rwxr-xr-x | scripts/main.sh | 2 |
3 files changed, 14 insertions, 29 deletions
diff --git a/cmd/btrfs-rec/inspect_scandevices.go b/cmd/btrfs-rec/inspect_scandevices.go index f5caadb..a7a7fb2 100644 --- a/cmd/btrfs-rec/inspect_scandevices.go +++ b/cmd/btrfs-rec/inspect_scandevices.go @@ -6,18 +6,14 @@ package main import ( "bufio" - "context" "os" - "sync" "git.lukeshu.com/go/lowmemjson" - "github.com/datawire/dlib/dgroup" "github.com/datawire/dlib/dlog" "github.com/datawire/ocibuild/pkg/cliutil" "github.com/spf13/cobra" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs" - "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect" ) @@ -35,26 +31,8 @@ func init() { } ctx := cmd.Context() - var resultsMu sync.Mutex - results := make(map[btrfsvol.DeviceID]btrfsinspect.ScanOneDeviceResult) - grp := dgroup.NewGroup(ctx, dgroup.GroupConfig{}) - for _, dev := range fs.LV.PhysicalVolumes() { - dev := dev - grp.Go(dev.Name(), func(ctx context.Context) error { - superblock, err := dev.Superblock() - if err != nil { - return err - } - dlog.Infof(ctx, "dev[%q] Scanning for unreachable nodes...", dev.Name()) - devResult, err := btrfsinspect.ScanOneDevice(ctx, dev, *superblock) - dlog.Infof(ctx, "dev[%q] Finished scanning", dev.Name()) - resultsMu.Lock() - results[superblock.DevItem.DevID] = devResult - resultsMu.Unlock() - return err - }) - } - if err := grp.Wait(); err != nil { + results, err := btrfsinspect.ScanDevices(ctx, fs) + if err != nil { return err } @@ -64,8 +42,11 @@ func init() { maybeSetErr(buffer.Flush()) }() return lowmemjson.Encode(&lowmemjson.ReEncoder{ - Out: buffer, - Indent: "\t", + Out: buffer, + + Indent: "\t", + ForceTrailingNewlines: true, + CompactIfUnder: 16, }, results) }, }) diff --git a/lib/btrfsprogs/btrfsinspect/scandevices.go b/lib/btrfsprogs/btrfsinspect/scandevices.go index 1f1ba80..b0ec0ff 100644 --- a/lib/btrfsprogs/btrfsinspect/scandevices.go +++ b/lib/btrfsprogs/btrfsinspect/scandevices.go @@ -22,7 +22,7 @@ import ( type ScanDevicesResult map[btrfsvol.DeviceID]ScanOneDeviceResult -func ScanDevices(ctx context.Context, fs *btrfs.FS, sb btrfs.Superblock) (ScanDevicesResult, error) { +func ScanDevices(ctx context.Context, fs *btrfs.FS) (ScanDevicesResult, error) { grp := dgroup.NewGroup(ctx, dgroup.GroupConfig{}) var mu sync.Mutex result := make(map[btrfsvol.DeviceID]ScanOneDeviceResult) @@ -30,7 +30,11 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, sb btrfs.Superblock) (ScanDe id := id dev := dev grp.Go(dev.Name(), func(ctx context.Context) error { - devResult, err := ScanOneDevice(ctx, dev, sb) + sb, err := dev.Superblock() + if err != nil { + return err + } + devResult, err := ScanOneDevice(ctx, dev, *sb) if err != nil { return err } diff --git a/scripts/main.sh b/scripts/main.sh index cc03e9f..f357754 100755 --- a/scripts/main.sh +++ b/scripts/main.sh @@ -7,7 +7,7 @@ gen() ( if test -s "$tgt"; then return fi - { set -x; time "$@"; } \ + { set -x; command time --verbose "$@"; } \ >"$tgt" \ 2> >(tee >&2 "$log") ) |