btrfs-progs: print-tree: Do correct offset output for ROOT_ITEM
authorQu Wenruo <wqu@suse.com>
Mon, 19 Mar 2018 10:28:10 +0000 (18:28 +0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Mar 2018 20:15:54 +0000 (22:15 +0200)
Commit Fixes: 8c36786c8198 ("btrfs-progs: print-tree: Print offset as
tree objectid for ROOT_ITEM") changes how we translate offset of
ROOT_ITEM.

However the fact is, even for ROOT_ITEM, we have different meaning of
offset.

For tree reloc tree, it's indeed subvolume id.  But for other trees,
it's the transid of when it's created.

Reported-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
print-tree.c

index 45350fe..2dbed72 100644 (file)
@@ -834,7 +834,16 @@ void btrfs_print_key(struct btrfs_disk_key *disk_key)
         */
        case BTRFS_ROOT_ITEM_KEY:
                printf(" ");
-               print_objectid(stdout, offset, type);
+               /*
+                * Normally offset of ROOT_ITEM should present the generation
+                * of creation time of the root.
+                * However if this is reloc tree, offset is the subvolume
+                * id of its source. Here we do extra check on this.
+                */
+               if (objectid == BTRFS_TREE_RELOC_OBJECTID)
+                       print_objectid(stdout, offset, type);
+               else
+                       printf("%lld", offset);
                printf(")");
                break;
        default: