summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-12 16:19:20 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-12 16:19:20 -0700
commita29f4c3421cd8deb2b0f578acb195442569236b7 (patch)
treeb06361fac5ae74630187c55c4174e8011256b398
parentc55326b0cb6994bb802cf6aac4a296acfb0e41ff (diff)
parented69c917c47435007ad72dc83a2db31c19699846 (diff)
Merge branch 'lukeshu/build-sys'
-rw-r--r--Makefile2
-rwxr-xr-xscripts/diff-dump-tree.sh13
-rwxr-xr-xscripts/main.sh60
-rwxr-xr-xscripts/mount.sh18
-rwxr-xr-xscripts/run-check.sh6
-rwxr-xr-xscripts/run-chunk-recover.sh7
-rwxr-xr-xscripts/run-clear-nodes.sh5
-rwxr-xr-xscripts/run-fsck.sh9
8 files changed, 59 insertions, 61 deletions
diff --git a/Makefile b/Makefile
index 07cb57d..8c78285 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
# main
build:
- go build -o bin/ ./cmd/...
+ go build -trimpath -o bin/ ./cmd/...
.PHONY: build
check:
diff --git a/scripts/diff-dump-tree.sh b/scripts/diff-dump-tree.sh
index 3d560d9..c3de337 100755
--- a/scripts/diff-dump-tree.sh
+++ b/scripts/diff-dump-tree.sh
@@ -1,4 +1,8 @@
#!/bin/bash
+readonly image=../scratch/new.img
+
+######################################################################
+
set -e
(
cd ../btrfs-progs
@@ -12,14 +16,19 @@ set -e
fi
make
)
+
+make build
+
+######################################################################
+
diff -u \
- <(../btrfs-progs/btrfs inspect dump-tree --noscan --csum-items ../scratch/new.img |
+ <(../btrfs-progs/btrfs inspect dump-tree --noscan --csum-items "$image" |
sed -e 's/ UNKNOWN.0 / UNTYPED /g' \
-e 's/\b18446744073709551615\b/-1/g' \
-e 's/INODE_REF 6)/INODE_REF ROOT_TREE_DIR)/g' \
-e 's/ROOT_BACKREF 5)/ROOT_BACKREF FS_TREE)/g' \
) \
- <(go run ./cmd/btrfs-rec/ inspect dump-trees --pv=../scratch/new.img |
+ <(./bin/btrfs-rec inspect dump-trees --pv="$image" |
sed -E \
-e 's/([0-9]),/\1/g' \
)
diff --git a/scripts/main.sh b/scripts/main.sh
index d89f387..365862f 100755
--- a/scripts/main.sh
+++ b/scripts/main.sh
@@ -1,30 +1,40 @@
#!/bin/bash
+readonly image=../scratch/dump-zero.img
+
+######################################################################
+
set -e
-b=../scratch/dump-zero
-gen() (
+
+run-btrfs-rec() {
local tgt=$1; shift
local log=${tgt%.*}.log
if test -s "$tgt"; then
return
fi
- { set -x; command time --verbose "$@"; } \
- >"$tgt" \
- 2> >(tee >&2 "$log")
-)
+ {
+ set -x;
+ command time --verbose \
+ ./bin/btrfs-rec \
+ --pv="$image" \
+ --profile.cpu="${tgt%.*}.cpu.pprof" \
+ --profile.allocs="${tgt%.*}.allocs.pprof" \
+ "$@"
+ } >"$tgt" 2> >(tee >&2 "$log")
+}
set -x
-CGO_ENABLED=0 go build -trimpath ./cmd/btrfs-rec
-mkdir -p "$b.gen"
+make build
+gendir="${image%.img}.gen"
+mkdir -p "$gendir"
+export GOMEMLIMIT="$(awk '/^MemTotal:/{ print $2 "KiB" }' </proc/meminfo)"
{ set +x; } &>/dev/null
-export GOMEMLIMIT="$(awk '/^MemTotal:/{ print $2 "KiB" }' </proc/meminfo)"
+######################################################################
-gen $b.gen/0.scandevices.json \
- ./btrfs-rec --pv=$b.img \
+run-btrfs-rec $gendir/0.scandevices.json \
inspect scandevices
-gen $b.gen/1.mappings.json \
- ./btrfs-rec --pv=$b.img \
- inspect rebuild-mappings $b.gen/0.scandevices.json
+run-btrfs-rec $gendir/1.mappings.json \
+ inspect rebuild-mappings $gendir/0.scandevices.json
# 1.mappings.log says:
#
@@ -44,19 +54,19 @@ gen $b.gen/1.mappings.json \
#
# And then run that through `rebuild-mappings` again to fill in the
# flags and normalize it.
-gen $b.gen/2.mappings.json \
- ./btrfs-rec --pv=$b.img --mappings=<(sed <$b.gen/1.mappings.json \
+run-btrfs-rec $gendir/2.mappings.json \
+ --mappings=<(sed <$gendir/1.mappings.json \
-e '2a{"LAddr":5242880,"PAddr":{"Dev":1,"Addr":5242880},"Size":1},' \
-e '2a{"LAddr":13631488,"PAddr":{"Dev":1,"Addr":13631488},"Size":1},') \
- inspect rebuild-mappings $b.gen/0.scandevices.json
+ inspect rebuild-mappings $gendir/0.scandevices.json
-gen $b.gen/3.nodes.json \
- ./btrfs-rec --pv=$b.img --mappings=$b.gen/2.mappings.json \
- inspect rebuild-nodes $b.gen/0.scandevices.json
+run-btrfs-rec $gendir/3.nodes.json \
+ --mappings=$gendir/2.mappings.json \
+ inspect rebuild-nodes $gendir/0.scandevices.json
-# gen $b.gen/4.ls-files.txt \
-# ./btrfs-rec --pv=$b.img --mappings=$b.gen/2.mappings.json \
+# run-btrfs-rec $gendir/4.ls-files.txt \
+# --mappings=$gendir/2.mappings.json \
# inspect ls-files
-# gen $b.gen/4.ls-trees.txt \
-# ./btrfs-rec --pv=$b.img --mappings=$b.gen/2.mappings.json \
-# inspect ls-trees --scandevices=$b.gen/0.scandevices.json
+# run-btrfs-rec $gendir/4.ls-trees.txt \
+# --mappings=$gendir/2.mappings.json \
+# inspect ls-trees --scandevices=$gendir/0.scandevices.json
diff --git a/scripts/mount.sh b/scripts/mount.sh
index f75f403..bf84163 100755
--- a/scripts/mount.sh
+++ b/scripts/mount.sh
@@ -1,14 +1,20 @@
#!/bin/bash
+readonly image=../scratch/dump-zero.img
+
+######################################################################
+
set -e
set -x
-go build ./cmd/btrfs-rec
+make build
-mkdir -p ../scratch/dump-zero.mnt
+gendir="${image%.img}.gen"
+mountpoint="${image%.img}.mnt"
+mkdir -p "$mountpoint"
-sudo ./btrfs-rec \
- --pv ../scratch/dump-zero.img \
- --mappings=../scratch/dump-zero.gen/2.mappings.json \
+sudo ./bin/btrfs-rec \
+ --pv="$image"
+ --mappings="$gendir/2.mappings.json" \
inspect mount \
--skip-filesums \
- ../scratch/dump-zero.mnt
+ "$mountpoint"
diff --git a/scripts/run-check.sh b/scripts/run-check.sh
deleted file mode 100755
index 6301305..0000000
--- a/scripts/run-check.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-set -e
-rm -f ../scratch/dump-check.img
-cp --reflink=always ../scratch/dump-{clearnodes,check}.img
-make -C ../btrfs-progs
-time ../btrfs-progs/btrfs check --progress --repair ../scratch/dump-check.img
diff --git a/scripts/run-chunk-recover.sh b/scripts/run-chunk-recover.sh
deleted file mode 100755
index f9a93d3..0000000
--- a/scripts/run-chunk-recover.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-set -e
-rm -f ../scratch/dump-scratch.img
-cp --reflink=always ../scratch/dump-{zero,scratch}.img
-chmod 600 ../scratch/dump-scratch.img
-make -C ../btrfs-progs
-time ../btrfs-progs/btrfs rescue chunk-recover ../scratch/dump-scratch.img
diff --git a/scripts/run-clear-nodes.sh b/scripts/run-clear-nodes.sh
deleted file mode 100755
index 48186f8..0000000
--- a/scripts/run-clear-nodes.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-set -e
-rm -f ../scratch/dump-clearnodes.img
-cp --reflink=always ../scratch/dump-{scratch,clearnodes}.img
-time go run ./cmd/btrfs-rec repair clear-bad-nodes --pv=../scratch/dump-clearnodes.img
diff --git a/scripts/run-fsck.sh b/scripts/run-fsck.sh
deleted file mode 100755
index 7fca6c0..0000000
--- a/scripts/run-fsck.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-set -e
-rm -f ../scratch/dump-scratch.img
-cp --reflink=always ../scratch/dump-{zero,scratch}.img
-chmod 600 ../scratch/dump-scratch.img
-time go run ./cmd/btrfs-fsck ../scratch/dump-scratch.img
-#make -C ../btrfs-progs
-#time ../btrfs-progs/btrfs rescue chunk-recover ../scratch/dump-scratch.img
-#time ../btrfs-progs/btrfs check ../scratch/dump-scratch.img