summaryrefslogtreecommitdiff
path: root/cmd/btrfs-fsck
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-30 04:14:55 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-30 04:14:55 -0600
commitb78fe1835fed316bd8e9e51c91fcc05422330490 (patch)
treeeb8ed91bf6160aa732229cc4374eaf0c527b50ef /cmd/btrfs-fsck
parent27d2f3a0efe6de94c7720907557e640e8a2f1428 (diff)
lock sizes, use blockgroups
Diffstat (limited to 'cmd/btrfs-fsck')
-rw-r--r--cmd/btrfs-fsck/pass1.go37
1 files changed, 34 insertions, 3 deletions
diff --git a/cmd/btrfs-fsck/pass1.go b/cmd/btrfs-fsck/pass1.go
index a83697f..a7c4a61 100644
--- a/cmd/btrfs-fsck/pass1.go
+++ b/cmd/btrfs-fsck/pass1.go
@@ -116,7 +116,9 @@ func (found pass1ScanOneDevResult) AddToLV(fs *btrfs.FS, dev *btrfs.Device) {
}
// Do the nodes last to avoid bloating the mappings table too
- // much.
+ // much. (Because nodes are numerous and small, while the
+ // others are few and large; so it is likely that many of the
+ // nodes will be subsumed by other things.)
//
// Sort them so that progress numbers are predictable.
laddrs := make([]btrfsvol.LogicalAddr, 0, len(found.FoundNodes))
@@ -136,8 +138,9 @@ func (found pass1ScanOneDevResult) AddToLV(fs *btrfs.FS, dev *btrfs.Device) {
Dev: sb.Data.DevItem.DevID,
Addr: paddr,
},
- Size: btrfsvol.AddrDelta(sb.Data.NodeSize),
- Flags: nil,
+ Size: btrfsvol.AddrDelta(sb.Data.NodeSize),
+ SizeLocked: false,
+ Flags: nil,
}); err != nil {
fmt.Printf("Pass 1: ... error: adding node ident: %v\n", err)
}
@@ -145,6 +148,34 @@ func (found pass1ScanOneDevResult) AddToLV(fs *btrfs.FS, dev *btrfs.Device) {
printProgress()
}
}
+
+ // Use block groups to add missing flags (and as a hint to
+ // combine node entries).
+ for _, bg := range found.FoundBlockGroups {
+ laddr := btrfsvol.LogicalAddr(bg.Key.ObjectID)
+ size := btrfsvol.AddrDelta(bg.Key.Offset)
+
+ otherLAddr, otherPAddr := fs.LV.ResolveAny(laddr, size)
+ if otherLAddr < 0 || otherPAddr.Addr < 0 {
+ continue
+ }
+
+ offsetWithinChunk := otherLAddr.Sub(laddr)
+ flags := bg.BG.Flags
+ mapping := btrfsvol.Mapping{
+ LAddr: laddr,
+ PAddr: btrfsvol.QualifiedPhysicalAddr{
+ Dev: otherPAddr.Dev,
+ Addr: otherPAddr.Addr.Add(-offsetWithinChunk),
+ },
+ Size: size,
+ SizeLocked: true,
+ Flags: &flags,
+ }
+ if err := fs.LV.AddMapping(mapping); err != nil {
+ fmt.Printf("Pass 1: ... error: adding flags from blockgroup: %v\n", err)
+ }
+ }
}
func pass1ScanOneDev(dev *btrfs.Device, superblock btrfs.Superblock) (pass1ScanOneDevResult, error) {