diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-07-22 21:18:40 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-07-23 00:46:56 -0600 |
commit | 17a9ea959d2f77b1ba55d45ac3feaf918f42f7dd (patch) | |
tree | a9e991125d02004f58bcfdc63b97570dc3d75a73 /cmd | |
parent | 1624c2ef8c5f95e428ad185278c3cba576f9dcb0 (diff) |
rebuildmappings: Include existing mappings in the scan JSON
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/btrfs-rec/inspect/rebuildmappings/scan.go | 5 | ||||
-rw-r--r-- | cmd/btrfs-rec/inspect_rebuildmappings.go | 17 |
2 files changed, 16 insertions, 6 deletions
diff --git a/cmd/btrfs-rec/inspect/rebuildmappings/scan.go b/cmd/btrfs-rec/inspect/rebuildmappings/scan.go index 9454ca0..d689136 100644 --- a/cmd/btrfs-rec/inspect/rebuildmappings/scan.go +++ b/cmd/btrfs-rec/inspect/rebuildmappings/scan.go @@ -25,6 +25,11 @@ import ( // Result types //////////////////////////////////////////////////////////////// +type ScanResult struct { + Mappings []btrfsvol.Mapping + Devices ScanDevicesResult +} + type ScanDevicesResult = map[btrfsvol.DeviceID]ScanOneDeviceResult type ScanOneDeviceResult struct { diff --git a/cmd/btrfs-rec/inspect_rebuildmappings.go b/cmd/btrfs-rec/inspect_rebuildmappings.go index ae2e415..e883b93 100644 --- a/cmd/btrfs-rec/inspect_rebuildmappings.go +++ b/cmd/btrfs-rec/inspect_rebuildmappings.go @@ -70,11 +70,16 @@ func init() { RunE: runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, _ []string) (err error) { ctx := cmd.Context() - scanResults, err := rebuildmappings.ScanDevices(ctx, fs) + devResults, err := rebuildmappings.ScanDevices(ctx, fs) if err != nil { return err } + scanResults := rebuildmappings.ScanResult{ + Mappings: fs.LV.Mappings(), + Devices: devResults, + } + dlog.Info(ctx, "Writing scan results to stdout...") if err := writeJSONFile(os.Stdout, scanResults, lowmemjson.ReEncoderConfig{ Indent: "\t", @@ -97,13 +102,13 @@ func init() { ctx := cmd.Context() dlog.Infof(ctx, "Reading %q...", args[0]) - scanResults, err := readJSONFile[rebuildmappings.ScanDevicesResult](ctx, args[0]) + scanResults, err := readJSONFile[rebuildmappings.ScanResult](ctx, args[0]) if err != nil { return err } dlog.Infof(ctx, "... done reading %q", args[0]) - if err := rebuildmappings.RebuildMappings(ctx, fs, scanResults); err != nil { + if err := rebuildmappings.RebuildMappings(ctx, fs, scanResults.Devices); err != nil { return err } @@ -132,17 +137,17 @@ func init() { RunE: run(func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() - scanResults, err := readJSONFile[rebuildmappings.ScanDevicesResult](ctx, args[0]) + scanResults, err := readJSONFile[rebuildmappings.ScanResult](ctx, args[0]) if err != nil { return err } var cnt int - for _, devResults := range scanResults { + for _, devResults := range scanResults.Devices { cnt += len(devResults.FoundNodes) } set := make(containers.Set[btrfsvol.LogicalAddr], cnt) - for _, devResults := range scanResults { + for _, devResults := range scanResults.Devices { for laddr := range devResults.FoundNodes { set.Insert(laddr) } |