diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-20 12:29:20 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-23 18:24:47 -0600 |
commit | bbabc9ab42accbd37072735419cc0552dc8917ee (patch) | |
tree | c4c5cb71e673d4f8a194013ce31123f98d52a20c /lib | |
parent | ba8fd9042ad4a5da3f5d2e3db6350793666ea403 (diff) |
btrfs: Subvolume: Use LookupTreeRoot
Diffstat (limited to 'lib')
-rw-r--r-- | lib/btrfs/btrfstree/btree_forrest.go | 3 | ||||
-rw-r--r-- | lib/btrfs/io4_fs.go | 31 |
2 files changed, 19 insertions, 15 deletions
diff --git a/lib/btrfs/btrfstree/btree_forrest.go b/lib/btrfs/btrfstree/btree_forrest.go index 197edc2..38a2721 100644 --- a/lib/btrfs/btrfstree/btree_forrest.go +++ b/lib/btrfs/btrfstree/btree_forrest.go @@ -21,6 +21,8 @@ type TreeRoot struct { RootNode btrfsvol.LogicalAddr Level uint8 Generation btrfsprim.Generation + + RootInode btrfsprim.ObjID // only for subvolume trees } // LookupTreeRoot is a utility function to help with implementing the @@ -70,6 +72,7 @@ func LookupTreeRoot(_ context.Context, fs TreeOperator, sb Superblock, treeID bt RootNode: rootItemBody.ByteNr, Level: rootItemBody.Level, Generation: rootItemBody.Generation, + RootInode: rootItemBody.RootDirID, }, nil case *btrfsitem.Error: return nil, fmt.Errorf("malformed ROOT_ITEM for tree %v: %w", treeID, rootItemBody.Err) diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go index 0445441..4a68695 100644 --- a/lib/btrfs/io4_fs.go +++ b/lib/btrfs/io4_fs.go @@ -5,6 +5,7 @@ package btrfs import ( + "context" "fmt" "io" "path/filepath" @@ -62,7 +63,8 @@ type File struct { } type Subvolume struct { - fs interface { + ctx context.Context //nolint:containedctx // don't have an option while keeping the same API + fs interface { btrfstree.TreeOperator Superblock() (*btrfstree.Superblock, error) diskio.ReaderAt[btrfsvol.LogicalAddr] @@ -70,8 +72,8 @@ type Subvolume struct { TreeID btrfsprim.ObjID noChecksums bool - rootVal btrfsitem.Root - rootErr error + rootInfo btrfstree.TreeRoot + rootErr error bareInodeCache containers.ARCache[btrfsprim.ObjID, *BareInode] fullInodeCache containers.ARCache[btrfsprim.ObjID, *FullInode] @@ -80,6 +82,7 @@ type Subvolume struct { } func NewSubvolume( + ctx context.Context, fs interface { btrfstree.TreeOperator Superblock() (*btrfstree.Superblock, error) @@ -94,19 +97,17 @@ func NewSubvolume( noChecksums: noChecksums, } - root, err := sv.fs.TreeSearch(btrfsprim.ROOT_TREE_OBJECTID, btrfstree.SearchRootItem(sv.TreeID)) + sb, err := sv.fs.Superblock() if err != nil { sv.rootErr = err - } else { - switch rootBody := root.Body.(type) { - case *btrfsitem.Root: - sv.rootVal = rootBody.Clone() - case *btrfsitem.Error: - sv.rootErr = fmt.Errorf("FS_TREE ROOT_ITEM has malformed body: %w", rootBody.Err) - default: - panic(fmt.Errorf("should not happen: ROOT_ITEM has unexpected item type: %T", rootBody)) - } + return sv + } + rootInfo, err := btrfstree.LookupTreeRoot(ctx, sv.fs, *sb, sv.TreeID) + if err != nil { + sv.rootErr = err + return sv } + sv.rootInfo = *rootInfo sv.bareInodeCache.MaxLen = textui.Tunable(128) sv.fullInodeCache.MaxLen = textui.Tunable(128) @@ -117,11 +118,11 @@ func NewSubvolume( } func (sv *Subvolume) NewChildSubvolume(childID btrfsprim.ObjID) *Subvolume { - return NewSubvolume(sv.fs, childID, sv.noChecksums) + return NewSubvolume(sv.ctx, sv.fs, childID, sv.noChecksums) } func (sv *Subvolume) GetRootInode() (btrfsprim.ObjID, error) { - return sv.rootVal.RootDirID, sv.rootErr + return sv.rootInfo.RootInode, sv.rootErr } func (sv *Subvolume) LoadBareInode(inode btrfsprim.ObjID) (*BareInode, error) { |