From 2fec63f72ded515dd51b08245f344385adbe34fb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 17 Apr 2023 15:53:20 -0600 Subject: btrfsutil: RebuiltForrest: Have LookupUUID return an error --- lib/btrfsutil/rebuilt_forrest_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/btrfsutil/rebuilt_forrest_test.go') 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 }, } -- cgit v1.2.3-2-g168b From 6b521d08bbb75430432834e5fcd2cb1da3de1e2e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 17 Apr 2023 18:21:04 -0600 Subject: btrfsutil: RebuiltForrest: Have LookupRoot return an error --- lib/btrfsutil/rebuilt_forrest_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/btrfsutil/rebuilt_forrest_test.go') diff --git a/lib/btrfsutil/rebuilt_forrest_test.go b/lib/btrfsutil/rebuilt_forrest_test.go index ef0ed72..86ae9a7 100644 --- a/lib/btrfsutil/rebuilt_forrest_test.go +++ b/lib/btrfsutil/rebuilt_forrest_test.go @@ -20,7 +20,7 @@ import ( 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) + lookupRoot func(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, err error) lookupUUID func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) } @@ -32,7 +32,7 @@ func (cbs rebuiltForrestCallbacks) AddedRoot(ctx context.Context, tree btrfsprim cbs.addedRoot(ctx, tree, root) } -func (cbs rebuiltForrestCallbacks) LookupRoot(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, ok bool) { +func (cbs rebuiltForrestCallbacks) LookupRoot(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, err error) { return cbs.lookupRoot(ctx, tree) } @@ -85,17 +85,17 @@ func TestRebuiltTreeCycles(t *testing.T) { addedRoot: func(ctx context.Context, tree btrfsprim.ObjID, root btrfsvol.LogicalAddr) { // do nothing }, - lookupRoot: func(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, ok bool) { + lookupRoot: func(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, err error) { for _, root := range roots { if root.ID == tree { return root.ParentGen, btrfsitem.Root{ Generation: 2000, UUID: root.UUID, ParentUUID: root.ParentUUID, - }, true + }, nil } } - return 0, btrfsitem.Root{}, false + return 0, btrfsitem.Root{}, btrfstree.ErrNoItem }, lookupUUID: func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) { for _, root := range roots { @@ -194,10 +194,10 @@ func TestRebuiltTreeParentErr(t *testing.T) { addedRoot: func(ctx context.Context, tree btrfsprim.ObjID, root btrfsvol.LogicalAddr) { // do nothing }, - lookupRoot: func(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, ok bool) { + lookupRoot: func(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, err error) { if tree == 304 { // Force a fault. - return 0, btrfsitem.Root{}, false + return 0, btrfsitem.Root{}, btrfstree.ErrNoItem } for _, root := range roots { if root.ID == tree { @@ -205,10 +205,10 @@ func TestRebuiltTreeParentErr(t *testing.T) { Generation: 2000, UUID: root.UUID, ParentUUID: root.ParentUUID, - }, true + }, nil } } - return 0, btrfsitem.Root{}, false + return 0, btrfsitem.Root{}, btrfstree.ErrNoItem }, lookupUUID: func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) { for _, root := range roots { @@ -225,7 +225,7 @@ func TestRebuiltTreeParentErr(t *testing.T) { rfs := NewRebuiltForrest(nil, Graph{}, cbs, false) tree, err := rfs.RebuiltTree(ctx, 305) - assert.EqualError(t, err, `failed to rebuild parent tree: 304: tree does not exist`) + assert.EqualError(t, err, `failed to rebuild parent tree: 304: tree does not exist: item does not exist`) assert.Nil(t, tree) }) -- cgit v1.2.3-2-g168b From 7bd942c1e5f8d4a18f7e1ac866191d8f1aa31d30 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 17 Apr 2023 19:06:26 -0600 Subject: btrfsutil: RebuiltForrest: Fuss with error messages --- lib/btrfsutil/rebuilt_forrest_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/btrfsutil/rebuilt_forrest_test.go') diff --git a/lib/btrfsutil/rebuilt_forrest_test.go b/lib/btrfsutil/rebuilt_forrest_test.go index 86ae9a7..bb7b698 100644 --- a/lib/btrfsutil/rebuilt_forrest_test.go +++ b/lib/btrfsutil/rebuilt_forrest_test.go @@ -225,7 +225,7 @@ func TestRebuiltTreeParentErr(t *testing.T) { rfs := NewRebuiltForrest(nil, Graph{}, cbs, false) tree, err := rfs.RebuiltTree(ctx, 305) - assert.EqualError(t, err, `failed to rebuild parent tree: 304: tree does not exist: item does not exist`) + assert.EqualError(t, err, `tree 305: failed to rebuild parent: tree 304: tree does not exist: item does not exist`) assert.Nil(t, tree) }) -- cgit v1.2.3-2-g168b