From f7701686ccdb294e3a67f24a3b333342925e89bc Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 20 Dec 2022 21:17:21 -0700 Subject: rebuildnodes: rebuild_graph.go: Have Root items want their UUIDs --- lib/btrfs/btrfsitem/item_uuid.go | 10 +++++++++- .../btrfsinspect/rebuildnodes/rebuild_graph.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/btrfs/btrfsitem/item_uuid.go b/lib/btrfs/btrfsitem/item_uuid.go index 451ccae..e1a6cf9 100644 --- a/lib/btrfs/btrfsitem/item_uuid.go +++ b/lib/btrfs/btrfsitem/item_uuid.go @@ -24,6 +24,14 @@ type UUIDMap struct { // UUID_SUBVOL=251 UUID_RECEIVED_SUBVOL=252 func KeyToUUID(key btrfsprim.Key) btrfsprim.UUID { var uuid btrfsprim.UUID binary.LittleEndian.PutUint64(uuid[:8], uint64(key.ObjectID)) - binary.LittleEndian.PutUint64(uuid[8:], uint64(key.Offset)) + binary.LittleEndian.PutUint64(uuid[8:], key.Offset) return uuid } + +func UUIDToKey(uuid btrfsprim.UUID) btrfsprim.Key { + return btrfsprim.Key{ + ObjectID: btrfsprim.ObjID(binary.LittleEndian.Uint64(uuid[:8])), + ItemType: UUID_SUBVOL_KEY, + Offset: binary.LittleEndian.Uint64(uuid[8:]), + } +} diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go index 976716d..db7a7a5 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go @@ -269,6 +269,22 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID, btrfsitem.INODE_ITEM_KEY, 0) } + if body.UUID != (btrfsprim.UUID{}) { + key := btrfsitem.UUIDToKey(body.UUID) + o.wantOff(dlog.WithField(ctx, "wants", "uuid"), + btrfsprim.UUID_TREE_OBJECTID, + key.ObjectID, + key.ItemType, + key.Offset) + } + if body.ParentUUID != (btrfsprim.UUID{}) { + key := btrfsitem.UUIDToKey(body.ParentUUID) + o.wantOff(dlog.WithField(ctx, "wants", "parent uuid"), + btrfsprim.UUID_TREE_OBJECTID, + key.ObjectID, + key.ItemType, + key.Offset) + } case btrfsitem.RootRef: var otherType btrfsprim.ItemType var parent, child btrfsprim.ObjID -- cgit v1.2.3-2-g168b