[PATCH 6/9] btrfs: add definitions and read support for the garbage collection tree
From: Josef Bacik <josef@toxicpanda.com>
Date: 2021-12-15 20:43:57
Subsystem:
btrfs file system, filesystems (vfs and infrastructure), the rest · Maintainers:
Chris Mason, David Sterba, Alexander Viro, Christian Brauner, Linus Torvalds
This adds the on disk definitions for the garbage collection tree and the code to load it on mount. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- fs/btrfs/disk-io.c | 6 ++++++ fs/btrfs/print-tree.c | 4 ++++ include/uapi/linux/btrfs_tree.h | 6 ++++++ 3 files changed, 16 insertions(+)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 2a70f61345aa..98b37850d614 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c@@ -2668,6 +2668,12 @@ static int load_global_roots(struct btrfs_root *tree_root) ret = load_global_roots_objectid(tree_root, path, BTRFS_FREE_SPACE_TREE_OBJECTID, "free space"); + if (ret) + goto out; + if (!btrfs_fs_incompat(tree_root->fs_info, EXTENT_TREE_V2)) + goto out; + ret = load_global_roots_objectid(tree_root, path, + BTRFS_GC_TREE_OBJECTID, "gc"); out: btrfs_free_path(path); return ret;
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 524fdb0ddd74..7fa202105e97 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c@@ -24,6 +24,7 @@ static const struct root_name_map root_map[] = { { BTRFS_UUID_TREE_OBJECTID, "UUID_TREE" }, { BTRFS_FREE_SPACE_TREE_OBJECTID, "FREE_SPACE_TREE" }, { BTRFS_BLOCK_GROUP_TREE_OBJECTID, "BLOCK_GROUP_TREE" }, + { BTRFS_GC_TREE_OBJECTID, "GC_TREE" }, { BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" }, };
@@ -348,6 +349,9 @@ void btrfs_print_leaf(struct extent_buffer *l) print_uuid_item(l, btrfs_item_ptr_offset(l, i), btrfs_item_size(l, i)); break; + case BTRFS_GC_INODE_ITEM_KEY: + pr_info("\t\tgc inode item\n"); + break; } } }
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index 854df92520a1..690b01e0138b 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h@@ -56,6 +56,9 @@ /* holds the block group items for extent tree v2. */ #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL +/* holds the garbage collection itesm for extent tree v2. */ +#define BTRFS_GC_TREE_OBJECTID 12ULL + /* device stats in the device tree */ #define BTRFS_DEV_STATS_OBJECTID 0ULL
@@ -147,6 +150,9 @@ #define BTRFS_ORPHAN_ITEM_KEY 48 /* reserve 2-15 close to the inode for later flexibility */ +/* The garbage collection items. */ +#define BTRFS_GC_INODE_ITEM_KEY 49 + /* * dir items are the name -> inode pointers in a directory. There is one * for every name in a directory. BTRFS_DIR_LOG_ITEM_KEY is no longer used
--
2.26.3