diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-17 15:53:20 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-17 19:52:26 -0600 |
commit | 2fec63f72ded515dd51b08245f344385adbe34fb (patch) | |
tree | c8567086086d2190cf8cb95257933a02940426b1 /lib | |
parent | a74c2cd52a12614565349577b8a5a6fbdcf337c3 (diff) |
btrfsutil: RebuiltForrest: Have LookupUUID return an error
Diffstat (limited to 'lib')
-rw-r--r-- | lib/btrfsutil/rebuilt_callbacks.go | 12 | ||||
-rw-r--r-- | lib/btrfsutil/rebuilt_forrest.go | 6 | ||||
-rw-r--r-- | lib/btrfsutil/rebuilt_forrest_test.go | 17 |
3 files changed, 18 insertions, 17 deletions
diff --git a/lib/btrfsutil/rebuilt_callbacks.go b/lib/btrfsutil/rebuilt_callbacks.go index 0b51d08..9ed3177 100644 --- a/lib/btrfsutil/rebuilt_callbacks.go +++ b/lib/btrfsutil/rebuilt_callbacks.go @@ -17,7 +17,7 @@ import ( type RebuiltForrestCallbacks interface { AddedRoot(ctx context.Context, tree btrfsprim.ObjID, root btrfsvol.LogicalAddr) LookupRoot(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, ok bool) - LookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool) + LookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) } type RebuiltForrestExtendedCallbacks interface { @@ -54,22 +54,22 @@ func (cb noopRebuiltForrestCallbacks) LookupRoot(ctx context.Context, tree btrfs } } -func (cb noopRebuiltForrestCallbacks) LookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool) { +func (cb noopRebuiltForrestCallbacks) LookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) { uuidTree, err := cb.forrest.ForrestLookup(ctx, btrfsprim.UUID_TREE_OBJECTID) if err != nil { - return 0, false + return 0, err } tgt := btrfsitem.UUIDToKey(uuid) item, err := uuidTree.TreeLookup(ctx, tgt) if err != nil { - return 0, false + return 0, err } defer item.Body.Free() switch itemBody := item.Body.(type) { case *btrfsitem.UUIDMap: - return itemBody.ObjID, true + return itemBody.ObjID, nil case *btrfsitem.Error: - return 0, false + return 0, itemBody.Err default: // This is a panic because the item decoder should not emit UUID_SUBVOL items as anything but // btrfsitem.UUIDMap or btrfsitem.Error without this code also being updated. diff --git a/lib/btrfsutil/rebuilt_forrest.go b/lib/btrfsutil/rebuilt_forrest.go index 5741072..3c53af7 100644 --- a/lib/btrfsutil/rebuilt_forrest.go +++ b/lib/btrfsutil/rebuilt_forrest.go @@ -221,9 +221,9 @@ func (ts *RebuiltForrest) rebuildTree(ctx context.Context, treeID btrfsprim.ObjI ts.trees[treeID].UUID = rootItem.UUID if rootItem.ParentUUID != (btrfsprim.UUID{}) { ts.trees[treeID].ParentGen = rootOff - parentID, ok := ts.cb.LookupUUID(ctx, rootItem.ParentUUID) - if !ok { - err := fmt.Errorf("failed to look up UUID: %v", rootItem.ParentUUID) + parentID, err := ts.cb.LookupUUID(ctx, rootItem.ParentUUID) + if err != nil { + err := fmt.Errorf("failed to look up UUID: %v: %w", rootItem.ParentUUID, err) if ts.laxAncestors { ts.trees[treeID].parentErr = err } else { diff --git a/lib/btrfsutil/rebuilt_forrest_test.go b/lib/btrfsutil/rebuilt_forrest_test.go index 8bbb50a..ef0ed72 100644 --- a/lib/btrfsutil/rebuilt_forrest_test.go +++ b/lib/btrfsutil/rebuilt_forrest_test.go @@ -13,6 +13,7 @@ import ( "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim" + "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfstree" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" ) @@ -20,7 +21,7 @@ type rebuiltForrestCallbacks struct { addedItem func(ctx context.Context, tree btrfsprim.ObjID, key btrfsprim.Key) addedRoot func(ctx context.Context, tree btrfsprim.ObjID, root btrfsvol.LogicalAddr) lookupRoot func(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, ok bool) - lookupUUID func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool) + lookupUUID func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) } func (cbs rebuiltForrestCallbacks) AddedItem(ctx context.Context, tree btrfsprim.ObjID, key btrfsprim.Key) { @@ -35,7 +36,7 @@ func (cbs rebuiltForrestCallbacks) LookupRoot(ctx context.Context, tree btrfspri return cbs.lookupRoot(ctx, tree) } -func (cbs rebuiltForrestCallbacks) LookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool) { +func (cbs rebuiltForrestCallbacks) LookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) { return cbs.lookupUUID(ctx, uuid) } @@ -96,13 +97,13 @@ func TestRebuiltTreeCycles(t *testing.T) { } return 0, btrfsitem.Root{}, false }, - lookupUUID: func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool) { + lookupUUID: func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) { for _, root := range roots { if root.UUID == uuid { - return root.ID, true + return root.ID, nil } } - return 0, false + return 0, btrfstree.ErrNoItem }, } @@ -209,13 +210,13 @@ func TestRebuiltTreeParentErr(t *testing.T) { } return 0, btrfsitem.Root{}, false }, - lookupUUID: func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool) { + lookupUUID: func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) { for _, root := range roots { if root.UUID == uuid { - return root.ID, true + return root.ID, nil } } - return 0, false + return 0, btrfstree.ErrNoItem }, } |