diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-12 22:36:30 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-12 22:36:30 -0600 |
commit | ec6929e40ca17cacb6a4ba23508d2b724b9201c1 (patch) | |
tree | df5180c4880fe88cfd5c18996da327af07d17900 /lib | |
parent | d250398e68fae70bd765a7f90389b58a4eeb4ee2 (diff) |
Don't have .Superblock() return a reference
Diffstat (limited to 'lib')
-rw-r--r-- | lib/btrfs/io1_pv.go | 8 | ||||
-rw-r--r-- | lib/btrfs/io2_lv.go | 20 | ||||
-rw-r--r-- | lib/btrfs/io3_btree.go | 24 | ||||
-rw-r--r-- | lib/btrfs/types_node.go | 2 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/mount.go | 6 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/print_tree.go | 18 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/recoverchunks.go | 4 |
7 files changed, 41 insertions, 41 deletions
diff --git a/lib/btrfs/io1_pv.go b/lib/btrfs/io1_pv.go index 4a69e12..44a8d76 100644 --- a/lib/btrfs/io1_pv.go +++ b/lib/btrfs/io1_pv.go @@ -17,7 +17,7 @@ type Device struct { *os.File cacheSuperblocks []*util.Ref[btrfsvol.PhysicalAddr, Superblock] - cacheSuperblock *util.Ref[btrfsvol.PhysicalAddr, Superblock] + cacheSuperblock *Superblock } var _ util.File[btrfsvol.PhysicalAddr] = (*Device)(nil) @@ -75,7 +75,7 @@ func (dev *Device) Superblocks() ([]*util.Ref[btrfsvol.PhysicalAddr, Superblock] return ret, nil } -func (dev *Device) Superblock() (*util.Ref[btrfsvol.PhysicalAddr, Superblock], error) { +func (dev *Device) Superblock() (*Superblock, error) { if dev.cacheSuperblock != nil { return dev.cacheSuperblock, nil } @@ -95,6 +95,6 @@ func (dev *Device) Superblock() (*util.Ref[btrfsvol.PhysicalAddr, Superblock], e } } - dev.cacheSuperblock = sbs[0] - return sbs[0], nil + dev.cacheSuperblock = &sbs[0].Data + return &sbs[0].Data, nil } diff --git a/lib/btrfs/io2_lv.go b/lib/btrfs/io2_lv.go index b36796b..eee58d5 100644 --- a/lib/btrfs/io2_lv.go +++ b/lib/btrfs/io2_lv.go @@ -23,7 +23,7 @@ type FS struct { LV btrfsvol.LogicalVolume[*Device] cacheSuperblocks []*util.Ref[btrfsvol.PhysicalAddr, Superblock] - cacheSuperblock *util.Ref[btrfsvol.PhysicalAddr, Superblock] + cacheSuperblock *Superblock } var _ util.File[btrfsvol.LogicalAddr] = (*FS)(nil) @@ -33,12 +33,12 @@ func (fs *FS) AddDevice(ctx context.Context, dev *Device) error { if err != nil { return err } - if err := fs.LV.AddPhysicalVolume(sb.Data.DevItem.DevID, dev); err != nil { + if err := fs.LV.AddPhysicalVolume(sb.DevItem.DevID, dev); err != nil { return err } fs.cacheSuperblocks = nil fs.cacheSuperblock = nil - if err := fs.initDev(sb); err != nil { + if err := fs.initDev(*sb); err != nil { dlog.Errorf(ctx, "error: AddDevice: %q: %v", dev.Name(), err) } return nil @@ -52,7 +52,7 @@ func (fs *FS) Name() string { if err != nil { return fmt.Sprintf("fs_uuid=%v", "(unreadable)") } - name := fmt.Sprintf("fs_uuid=%v", sb.Data.FSUUID) + name := fmt.Sprintf("fs_uuid=%v", sb.FSUUID) fs.LV.SetName(name) return name } @@ -92,7 +92,7 @@ func (fs *FS) Superblocks() ([]*util.Ref[btrfsvol.PhysicalAddr, Superblock], err return ret, nil } -func (fs *FS) Superblock() (*util.Ref[btrfsvol.PhysicalAddr, Superblock], error) { +func (fs *FS) Superblock() (*Superblock, error) { if fs.cacheSuperblock != nil { return fs.cacheSuperblock, nil } @@ -129,8 +129,8 @@ func (fs *FS) Superblock() (*util.Ref[btrfsvol.PhysicalAddr, Superblock], error) } } - fs.cacheSuperblock = sbs[0] - return sbs[0], nil + fs.cacheSuperblock = &sbs[0].Data + return &sbs[0].Data, nil } func (fs *FS) ReInit() error { @@ -140,15 +140,15 @@ func (fs *FS) ReInit() error { if err != nil { return fmt.Errorf("file %q: %w", dev.Name(), err) } - if err := fs.initDev(sb); err != nil { + if err := fs.initDev(*sb); err != nil { return fmt.Errorf("file %q: %w", dev.Name(), err) } } return nil } -func (fs *FS) initDev(sb *util.Ref[btrfsvol.PhysicalAddr, Superblock]) error { - syschunks, err := sb.Data.ParseSysChunkArray() +func (fs *FS) initDev(sb Superblock) error { + syschunks, err := sb.ParseSysChunkArray() if err != nil { return err } diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go index a02a857..4d2e556 100644 --- a/lib/btrfs/io3_btree.go +++ b/lib/btrfs/io3_btree.go @@ -146,30 +146,30 @@ func (fs *FS) lookupTree(treeID ObjID) (*treeRoot, error) { case ROOT_TREE_OBJECTID: return &treeRoot{ TreeID: treeID, - RootNode: sb.Data.RootTree, - Level: sb.Data.RootLevel, - Generation: sb.Data.Generation, // XXX: same generation as LOG_TREE? + RootNode: sb.RootTree, + Level: sb.RootLevel, + Generation: sb.Generation, // XXX: same generation as LOG_TREE? }, nil case CHUNK_TREE_OBJECTID: return &treeRoot{ TreeID: treeID, - RootNode: sb.Data.ChunkTree, - Level: sb.Data.ChunkLevel, - Generation: sb.Data.ChunkRootGeneration, + RootNode: sb.ChunkTree, + Level: sb.ChunkLevel, + Generation: sb.ChunkRootGeneration, }, nil case TREE_LOG_OBJECTID: return &treeRoot{ TreeID: treeID, - RootNode: sb.Data.LogTree, - Level: sb.Data.LogLevel, - Generation: sb.Data.Generation, // XXX: same generation as ROOT_TREE? + RootNode: sb.LogTree, + Level: sb.LogLevel, + Generation: sb.Generation, // XXX: same generation as ROOT_TREE? }, nil case BLOCK_GROUP_TREE_OBJECTID: return &treeRoot{ TreeID: treeID, - RootNode: sb.Data.BlockGroupRoot, - Level: sb.Data.BlockGroupRootLevel, - Generation: sb.Data.BlockGroupRootGeneration, + RootNode: sb.BlockGroupRoot, + Level: sb.BlockGroupRootLevel, + Generation: sb.BlockGroupRootGeneration, }, nil default: rootItem, err := fs.TreeSearch(ROOT_TREE_OBJECTID, func(key Key) int { diff --git a/lib/btrfs/types_node.go b/lib/btrfs/types_node.go index 34151c9..fc12a00 100644 --- a/lib/btrfs/types_node.go +++ b/lib/btrfs/types_node.go @@ -406,7 +406,7 @@ func (fs *FS) ReadNode(addr btrfsvol.LogicalAddr) (*util.Ref[btrfsvol.LogicalAdd return nil, fmt.Errorf("btrfs.FS.ReadNode: %w", err) } - return ReadNode[btrfsvol.LogicalAddr](fs, sb.Data, addr, func(claimAddr btrfsvol.LogicalAddr) error { + return ReadNode[btrfsvol.LogicalAddr](fs, *sb, addr, func(claimAddr btrfsvol.LogicalAddr) error { if claimAddr != addr { return fmt.Errorf("read from laddr=%v but claims to be at laddr=%v", addr, claimAddr) diff --git a/lib/btrfsprogs/btrfsinspect/mount.go b/lib/btrfsprogs/btrfsinspect/mount.go index 641bc64..9cb28dc 100644 --- a/lib/btrfsprogs/btrfsinspect/mount.go +++ b/lib/btrfsprogs/btrfsinspect/mount.go @@ -205,9 +205,9 @@ func (sv *subvolume) StatFS(_ context.Context, op *fuseops.StatFSOp) error { return err } - op.IoSize = sb.Data.SectorSize - op.BlockSize = sb.Data.SectorSize - op.Blocks = sb.Data.TotalBytes / uint64(sb.Data.SectorSize) // TODO: adjust for RAID type + op.IoSize = sb.SectorSize + op.BlockSize = sb.SectorSize + op.Blocks = sb.TotalBytes / uint64(sb.SectorSize) // TODO: adjust for RAID type //op.BlocksFree = TODO // btrfs doesn't have a fixed number of inodes diff --git a/lib/btrfsprogs/btrfsinspect/print_tree.go b/lib/btrfsprogs/btrfsinspect/print_tree.go index 2de9818..6c4f550 100644 --- a/lib/btrfsprogs/btrfsinspect/print_tree.go +++ b/lib/btrfsprogs/btrfsinspect/print_tree.go @@ -27,19 +27,19 @@ func DumpTrees(ctx context.Context, out io.Writer, fs *btrfs.FS) { return } - if superblock.Data.RootTree != 0 { + if superblock.RootTree != 0 { fmt.Fprintf(out, "root tree\n") printTree(ctx, out, fs, btrfs.ROOT_TREE_OBJECTID) } - if superblock.Data.ChunkTree != 0 { + if superblock.ChunkTree != 0 { fmt.Fprintf(out, "chunk tree\n") printTree(ctx, out, fs, btrfs.CHUNK_TREE_OBJECTID) } - if superblock.Data.LogTree != 0 { + if superblock.LogTree != 0 { fmt.Fprintf(out, "log root tree\n") printTree(ctx, out, fs, btrfs.TREE_LOG_OBJECTID) } - if superblock.Data.BlockGroupRoot != 0 { + if superblock.BlockGroupRoot != 0 { fmt.Fprintf(out, "block group tree\n") printTree(ctx, out, fs, btrfs.BLOCK_GROUP_TREE_OBJECTID) } @@ -82,9 +82,9 @@ func DumpTrees(ctx context.Context, out io.Writer, fs *btrfs.FS) { }, }, ) - fmt.Fprintf(out, "total bytes %v\n", superblock.Data.TotalBytes) - fmt.Fprintf(out, "bytes used %v\n", superblock.Data.BytesUsed) - fmt.Fprintf(out, "uuid %v\n", superblock.Data.FSUUID) + fmt.Fprintf(out, "total bytes %v\n", superblock.TotalBytes) + fmt.Fprintf(out, "bytes used %v\n", superblock.BytesUsed) + fmt.Fprintf(out, "uuid %v\n", superblock.FSUUID) } // printTree mimics btrfs-progs @@ -199,7 +199,7 @@ func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfs.Ob // // TODO case btrfsitem.ExtentCSum: sb, _ := fs.Superblock() - sectorSize := btrfsvol.AddrDelta(sb.Data.SectorSize) + sectorSize := btrfsvol.AddrDelta(sb.SectorSize) start := btrfsvol.LogicalAddr(item.Key.Offset) itemSize := btrfsvol.AddrDelta(len(body.Sums)) * sectorSize @@ -214,7 +214,7 @@ func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfs.Ob } else { fmt.Fprintf(out, " ") } - fmt.Fprintf(out, "[%d] 0x%s", pos, sum.Fmt(sb.Data.ChecksumType)) + fmt.Fprintf(out, "[%d] 0x%s", pos, sum.Fmt(sb.ChecksumType)) pos = pos.Add(sectorSize) } fmt.Fprintf(out, "\n") diff --git a/lib/btrfsprogs/btrfsinspect/recoverchunks.go b/lib/btrfsprogs/btrfsinspect/recoverchunks.go index aae46b0..9f97b45 100644 --- a/lib/btrfsprogs/btrfsinspect/recoverchunks.go +++ b/lib/btrfsprogs/btrfsinspect/recoverchunks.go @@ -84,10 +84,10 @@ func (found ScanOneDevResult) AddToLV(ctx context.Context, fs *btrfs.FS, dev *bt if err := fs.LV.AddMapping(btrfsvol.Mapping{ LAddr: laddr, PAddr: btrfsvol.QualifiedPhysicalAddr{ - Dev: sb.Data.DevItem.DevID, + Dev: sb.DevItem.DevID, Addr: paddr, }, - Size: btrfsvol.AddrDelta(sb.Data.NodeSize), + Size: btrfsvol.AddrDelta(sb.NodeSize), SizeLocked: false, Flags: nil, }); err != nil { |