From 0733161bf46a279f11e20f9ffd34e0136c13a884 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 13 Mar 2023 18:52:51 -0600 Subject: btrfs: io3_btree.go: De-nest populateTreeUUIDs --- lib/btrfs/io3_btree.go | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'lib/btrfs') diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go index 426e4a1..db4e42c 100644 --- a/lib/btrfs/io3_btree.go +++ b/lib/btrfs/io3_btree.go @@ -28,28 +28,29 @@ var _ btrfstree.NodeSource = (*FS)(nil) // btrfstree.NodeFile ////////////////////////////////////////////////////////// func (fs *FS) populateTreeUUIDs(ctx context.Context) { - if fs.cacheObjID2UUID == nil || fs.cacheUUID2ObjID == nil || fs.cacheTreeParent == nil { - fs.cacheObjID2UUID = make(map[btrfsprim.ObjID]btrfsprim.UUID) - fs.cacheUUID2ObjID = make(map[btrfsprim.UUID]btrfsprim.ObjID) - fs.cacheTreeParent = make(map[btrfsprim.ObjID]btrfsprim.UUID) - fs.TreeWalk(ctx, btrfsprim.ROOT_TREE_OBJECTID, - func(err *btrfstree.TreeError) { - // do nothing - }, - btrfstree.TreeWalkHandler{ - Item: func(_ btrfstree.TreePath, item btrfstree.Item) error { - itemBody, ok := item.Body.(*btrfsitem.Root) - if !ok { - return nil - } - fs.cacheObjID2UUID[item.Key.ObjectID] = itemBody.UUID - fs.cacheTreeParent[item.Key.ObjectID] = itemBody.ParentUUID - fs.cacheUUID2ObjID[itemBody.UUID] = item.Key.ObjectID + if fs.cacheObjID2UUID != nil && fs.cacheUUID2ObjID != nil && fs.cacheTreeParent != nil { + return + } + fs.cacheObjID2UUID = make(map[btrfsprim.ObjID]btrfsprim.UUID) + fs.cacheUUID2ObjID = make(map[btrfsprim.UUID]btrfsprim.ObjID) + fs.cacheTreeParent = make(map[btrfsprim.ObjID]btrfsprim.UUID) + fs.TreeWalk(ctx, btrfsprim.ROOT_TREE_OBJECTID, + func(err *btrfstree.TreeError) { + // do nothing + }, + btrfstree.TreeWalkHandler{ + Item: func(_ btrfstree.TreePath, item btrfstree.Item) error { + itemBody, ok := item.Body.(*btrfsitem.Root) + if !ok { return nil - }, + } + fs.cacheObjID2UUID[item.Key.ObjectID] = itemBody.UUID + fs.cacheTreeParent[item.Key.ObjectID] = itemBody.ParentUUID + fs.cacheUUID2ObjID[itemBody.UUID] = item.Key.ObjectID + return nil }, - ) - } + }, + ) } // ParentTree implements btrfstree.NodeFile. -- cgit v1.2.3-2-g168b