Skip to contentSkip to conversation

do not reuse objectid of deleted snapshot/subvol

PATCH New Yan, Zheng 1 participant 1 message Aug 25, 2009 Btrfs file system

lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

PATCH 3/4 do not reuse objectid of deleted snapshot/subvol

The new back refernece format does not allow reusing objectid of deleted snapshot/subvol. So use ++highest_objectid to allocate objectid for new snapshot/subvol.

Since we use ++highest_objectid to allocate objectid for both new inode and new snapshot/subvol, This patch also removes 'find hole' code in btrfs_find_free_objectid.

---

fs/btrfs/ctree.h +2 -2
diff -urp 3/fs/btrfs/ctree.h 4/fs/btrfs/ctree.h
@@ -998,8 +998,8 @@ struct btrfs_root {
 	u32 stripesize;
 
 	u32 type;
-	u64 highest_inode;
-	u64 last_inode_alloc;
+
+	u64 highest_objectid;
 	int ref_cows;
 	int track_dirty;
 	u64 defrag_trans_start;
fs/btrfs/disk-io.c +14 -25
diff -urp 3/fs/btrfs/disk-io.c 4/fs/btrfs/disk-io.c
@@ -893,8 +893,7 @@ static int __setup_root(u32 nodesize, u3
 	root->fs_info = fs_info;
 	root->objectid = objectid;
 	root->last_trans = 0;
-	root->highest_inode = 0;
-	root->last_inode_alloc = 0;
+	root->highest_objectid = 0;
 	root->name = NULL;
 	root->in_sysfs = 0;
 	root->inode_tree.rb_node = NULL;
@@ -1093,7 +1092,6 @@ struct btrfs_root *btrfs_read_fs_root_no
 	struct btrfs_fs_info *fs_info = tree_root->fs_info;
 	struct btrfs_path *path;
 	struct extent_buffer *l;
-	u64 highest_inode;
 	u64 generation;
 	u32 blocksize;
 	int ret = 0;
@@ -1108,7 +1106,7 @@ struct btrfs_root *btrfs_read_fs_root_no
 			kfree(root);
 			return ERR_PTR(ret);
 		}
-		goto insert;
+		goto out;
 	}
 
 	__setup_root(tree_root->nodesize, tree_root->leafsize,
@@ -1118,39 +1116,30 @@ struct btrfs_root *btrfs_read_fs_root_no
 	path = btrfs_alloc_path();
 	BUG_ON(!path);
 	ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0);
-	if (ret != 0) {
-		if (ret > 0)
-			ret = -ENOENT;
-		goto out;
+	if (ret == 0) {
+		l = path->nodes[0];
+		read_extent_buffer(l, &root->root_item,
+				btrfs_item_ptr_offset(l, path->slots[0]),
+				sizeof(root->root_item));
+		memcpy(&root->root_key, location, sizeof(*location));
 	}
-	l = path->nodes[0];
-	read_extent_buffer(l, &root->root_item,
-	       btrfs_item_ptr_offset(l, path->slots[0]),
-	       sizeof(root->root_item));
-	memcpy(&root->root_key, location, sizeof(*location));
-	ret = 0;
-out:
-	btrfs_release_path(root, path);
 	btrfs_free_path(path);
 	if (ret) {
-		kfree(root);
+		if (ret > 0)
+			ret = -ENOENT;
 		return ERR_PTR(ret);
 	}
+
 	generation = btrfs_root_generation(&root->root_item);
 	blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
 	root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
 				     blocksize, generation);
 	root->commit_root = btrfs_root_node(root);
 	BUG_ON(!root->node);
-insert:
-	if (location->objectid != BTRFS_TREE_LOG_OBJECTID) {
+out:
+	if (location->objectid != BTRFS_TREE_LOG_OBJECTID)
 		root->ref_cows = 1;
-		ret = btrfs_find_highest_inode(root, &highest_inode);
-		if (ret == 0) {
-			root->highest_inode = highest_inode;
-			root->last_inode_alloc = highest_inode;
-		}
-	}
+
 	return root;
 }
 
fs/btrfs/inode.c +0 -3
diff -urp 3/fs/btrfs/inode.c 4/fs/btrfs/inode.c
@@ -3675,9 +3675,6 @@ static struct inode *btrfs_new_inode(str
 	if (ret != 0)
 		goto fail;
 
-	if (objectid > root->highest_inode)
-		root->highest_inode = objectid;
-
 	inode->i_uid = current_fsuid();
 
 	if (dir && (dir->i_mode & S_ISGID)) {
fs/btrfs/inode-item.c +0 -2
diff -urp 3/fs/btrfs/inode-item.c 4/fs/btrfs/inode-item.c
@@ -177,8 +177,6 @@ int btrfs_insert_empty_inode(struct btrf
 
 	ret = btrfs_insert_empty_item(trans, root, path, &key,
 				      sizeof(struct btrfs_inode_item));
-	if (ret == 0 && objectid > root->highest_inode)
-		root->highest_inode = objectid;
 	return ret;
 }
 
fs/btrfs/inode-map.c +16 -78

116 lines not on this page · raw message

fs/btrfs/tree-log.c +0 -6
diff -urp 3/fs/btrfs/tree-log.c 4/fs/btrfs/tree-log.c
@@ -2959,7 +2959,6 @@ int btrfs_recover_log_trees(struct btrfs
 	struct btrfs_key tmp_key;
 	struct btrfs_root *log;
 	struct btrfs_fs_info *fs_info = log_root_tree->fs_info;
-	u64 highest_inode;
 	struct walk_control wc = {
 		.process_func = process_one_buffer,
 		.stage = 0,
@@ -3018,11 +3017,6 @@ again:
 						      path);
 			BUG_ON(ret);
 		}
-		ret = btrfs_find_highest_inode(wc.replay_dest, &highest_inode);
-		if (ret == 0) {
-			wc.replay_dest->highest_inode = highest_inode;
-			wc.replay_dest->last_inode_alloc = highest_inode;
-		}
 
 		key.offset = found_key.offset - 1;
 		wc.replay_dest->log_root = NULL;