Skip to contentSkip to conversation

Spring cleaning

PATCH In review Nikolay Borisov 2 participants 8 messages Jun 19, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover Spring cleaning

Just a couple of patches that remove unneeded code. The first one does away with an always true if construct and the rest remove code which has been #if 0 for quite some time.

Nikolay Borisov (4):
btrfs-progs: Remove redundant if
btrfs-progs: Remove commented code
btrfs: Remove old send implementation
btrfs-progs: check: Remove duplicated and commented functions

 check/main.c  |  69 -------------
 cmds-send.c   |  61 ------------
 extent-tree.c | 270 +-------------------------------------------------
 3 files changed, 5 insertions(+), 395 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/4 btrfs-progs: Remove redundant if

'pin' is always true in __free_extent so there is no point in checking it. Just remove the if and unindent the code.

---
 extent-tree.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
extent-tree.c +5 -8
index c6516b2ba445..7693313c50b3 100644
@@ -2074,7 +2074,6 @@ static int __free_extent(struct btrfs_trans_handle *trans,
 		}
 	} else {
 		int mark_free = 0;
-		int pin = 1;
 
 		if (found_extent) {
 			BUG_ON(is_data && refs_to_drop !=
@@ -2088,13 +2087,11 @@ static int __free_extent(struct btrfs_trans_handle *trans,
 			}
 		}
 
-		if (pin) {
-			ret = pin_down_bytes(trans, bytenr, num_bytes,
-					     is_data);
-			if (ret > 0)
-				mark_free = 1;
-			BUG_ON(ret < 0);
-		}
+		ret = pin_down_bytes(trans, bytenr, num_bytes,
+				     is_data);
+		if (ret > 0)
+			mark_free = 1;
+		BUG_ON(ret < 0);
 
 		ret = btrfs_del_items(trans, extent_root, path, path->slots[0],
 				      num_to_del);
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/4 btrfs-progs: Remove commented code

In reply to Nikolay Borisov

This piece of code has been commented since 2009, given the number of changes that have happened it's unlikely it could be made to work or is needed at all. Just delete it.

---
 extent-tree.c | 257 --------------------------------------------------
 1 file changed, 257 deletions(-)
extent-tree.c +0 -257
index 7693313c50b3..b822eaa28700 100644
@@ -2539,263 +2539,6 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
 	return buf;
 }
 
-#if 0
-
-static int noinline drop_leaf_ref(struct btrfs_trans_handle *trans,
-				  struct btrfs_root *root,
-				  struct extent_buffer *leaf)
-{
-	u64 leaf_owner;
-	u64 leaf_generation;
-	struct btrfs_key key;
-	struct btrfs_file_extent_item *fi;
-	int i;
-	int nritems;
-	int ret;
-
-	BUG_ON(!btrfs_is_leaf(leaf));
-	nritems = btrfs_header_nritems(leaf);
-	leaf_owner = btrfs_header_owner(leaf);
-	leaf_generation = btrfs_header_generation(leaf);
-
-	for (i = 0; i < nritems; i++) {
-		u64 disk_bytenr;
-
-		btrfs_item_key_to_cpu(leaf, &key, i);
-		if (btrfs_key_type(&key) != BTRFS_EXTENT_DATA_KEY)
-			continue;
-		fi = btrfs_item_ptr(leaf, i, struct btrfs_file_extent_item);
-		if (btrfs_file_extent_type(leaf, fi) ==
-		    BTRFS_FILE_EXTENT_INLINE)
-			continue;
-		/*
-		 * FIXME make sure to insert a trans record that
-		 * repeats the snapshot del on crash
-		 */
-		disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
-		if (disk_bytenr == 0)
-			continue;
-		ret = btrfs_free_extent(trans, root, disk_bytenr,
-				btrfs_file_extent_disk_num_bytes(leaf, fi),
-				leaf->start, leaf_owner, leaf_generation,
-				key.objectid, 0);
-		BUG_ON(ret);
-	}
-	return 0;
-}
-
-static void noinline reada_walk_down(struct btrfs_root *root,
-				     struct extent_buffer *node,
-				     int slot)
-{
-	u64 bytenr;
-	u64 last = 0;
-	u32 nritems;
-	u32 refs;
-	u32 blocksize;
-	int ret;
-	int i;
-	int level;
-	int skipped = 0;
-
-	nritems = btrfs_header_nritems(node);
-	level = btrfs_header_level(node);
-	if (level)
-		return;
-
-	for (i = slot; i < nritems && skipped < 32; i++) {
-		bytenr = btrfs_node_blockptr(node, i);
-		if (last && ((bytenr > last && bytenr - last > SZ_32K) ||
-			     (last > bytenr && last - bytenr > SZ_32K))) {
-			skipped++;
-			continue;
-		}
-		blocksize = btrfs_level_size(root, level - 1);
-		if (i != slot) {
-			ret = btrfs_lookup_extent_ref(NULL, root, bytenr,
-						      blocksize, &refs);
-			BUG_ON(ret);
-			if (refs != 1) {
-				skipped++;
-				continue;
-			}
-		}
-		mutex_unlock(&root->fs_info->fs_mutex);
-		ret = readahead_tree_block(root, bytenr, blocksize,
-					   btrfs_node_ptr_generation(node, i));
-		last = bytenr + blocksize;
-		cond_resched();
-		mutex_lock(&root->fs_info->fs_mutex);
-		if (ret)
-			break;
-	}
-}
-
-/*
- * helper function for drop_snapshot, this walks down the tree dropping ref
- * counts as it goes.
- */
-static int noinline walk_down_tree(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root,
-				   struct btrfs_path *path, int *level)
-{
-	u64 root_owner;
-	u64 root_gen;
-	u64 bytenr;
-	u64 ptr_gen;
-	struct extent_buffer *next;
-	struct extent_buffer *cur;
-	struct extent_buffer *parent;
-	u32 blocksize;
-	int ret;
-	u32 refs;
-
-	WARN_ON(*level < 0);
-	WARN_ON(*level >= BTRFS_MAX_LEVEL);
-	ret = btrfs_lookup_extent_ref(trans, root,
-				      path->nodes[*level]->start,
-				      path->nodes[*level]->len, &refs);
-	BUG_ON(ret);
-	if (refs > 1)
-		goto out;
-
-	/*
-	 * walk down to the last node level and free all the leaves
-	 */
-	while(*level >= 0) {
-		WARN_ON(*level < 0);
-		WARN_ON(*level >= BTRFS_MAX_LEVEL);
-		cur = path->nodes[*level];
-
-		if (btrfs_header_level(cur) != *level)
-			WARN_ON(1);
-
-		if (path->slots[*level] >=
-		    btrfs_header_nritems(cur))
-			break;
-		if (*level == 0) {
-			ret = drop_leaf_ref(trans, root, cur);
-			BUG_ON(ret);
-			break;
-		}
-		bytenr = btrfs_node_blockptr(cur, path->slots[*level]);
-		ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]);
-		blocksize = btrfs_level_size(root, *level - 1);
-		ret = btrfs_lookup_extent_ref(trans, root, bytenr, blocksize,
-					      &refs);
-		BUG_ON(ret);
-		if (refs != 1) {
-			parent = path->nodes[*level];
-			root_owner = btrfs_header_owner(parent);
-			root_gen = btrfs_header_generation(parent);
-			path->slots[*level]++;
-			ret = btrfs_free_extent(trans, root, bytenr, blocksize,
-						parent->start, root_owner,
-						root_gen, *level - 1, 0);
-			BUG_ON(ret);
-			continue;
-		}
-		next = btrfs_find_tree_block(root, bytenr, blocksize);
-		if (!next || !btrfs_buffer_uptodate(next, ptr_gen)) {
-			free_extent_buffer(next);
-			reada_walk_down(root, cur, path->slots[*level]);
-			mutex_unlock(&root->fs_info->fs_mutex);
-			next = read_tree_block(root, bytenr, blocksize,
-					       ptr_gen);
-			mutex_lock(&root->fs_info->fs_mutex);
-			if (!extent_buffer_uptodate(next)) {
-				if (IS_ERR(next))
-					ret = PTR_ERR(next);
-				else
-					ret = -EIO;
-				break;
-			}
-		}
-		WARN_ON(*level <= 0);
-		if (path->nodes[*level-1])
-			free_extent_buffer(path->nodes[*level-1]);
-		path->nodes[*level-1] = next;
-		*level = btrfs_header_level(next);
-		path->slots[*level] = 0;
-	}
-out:
-	WARN_ON(*level < 0);
-	WARN_ON(*level >= BTRFS_MAX_LEVEL);
-
-	if (path->nodes[*level] == root->node) {
-		root_owner = root->root_key.objectid;
-		parent = path->nodes[*level];
-	} else {
-		parent = path->nodes[*level + 1];
-		root_owner = btrfs_header_owner(parent);
-	}
-
-	root_gen = btrfs_header_generation(parent);
-	ret = btrfs_free_extent(trans, root, path->nodes[*level]->start,
-				path->nodes[*level]->len, parent->start,
-				root_owner, root_gen, *level, 0);
-	free_extent_buffer(path->nodes[*level]);
-	path->nodes[*level] = NULL;
-	*level += 1;
-	BUG_ON(ret);
-	return 0;
-}
-
-/*
- * helper for dropping snapshots.  This walks back up the tree in the path
- * to find the first node higher up where we haven't yet gone through
- * all the slots
- */
-static int noinline walk_up_tree(struct btrfs_trans_handle *trans,
-				 struct btrfs_root *root,
-				 struct btrfs_path *path, int *level)
-{
-	u64 root_owner;
-	u64 root_gen;
-	struct btrfs_root_item *root_item = &root->root_item;
-	int i;
-	int slot;
-	int ret;
-
-	for(i = *level; i < BTRFS_MAX_LEVEL - 1 && path->nodes[i]; i++) {
-		slot = path->slots[i];
-		if (slot < btrfs_header_nritems(path->nodes[i]) - 1) {
-			struct extent_buffer *node;
-			struct btrfs_disk_key disk_key;
-			node = path->nodes[i];
-			path->slots[i]++;
-			*level = i;
-			WARN_ON(*level == 0);
-			btrfs_node_key(node, &disk_key, path->slots[i]);
-			memcpy(&root_item->drop_progress,
-			       &disk_key, sizeof(disk_key));
-			root_item->drop_level = i;
-			return 0;
-		} else {
-			struct extent_buffer *parent;
-			if (path->nodes[*level] == root->node)
-				parent = path->nodes[*level];
-			else
-				parent = path->nodes[*level + 1];
-
-			root_owner = btrfs_header_owner(parent);
-			root_gen = btrfs_header_generation(parent);
-			ret = btrfs_free_extent(trans, root,
-						path->nodes[*level]->start,
-						path->nodes[*level]->len,
-						parent->start, root_owner,
-						root_gen, *level, 0);
-			BUG_ON(ret);
-			free_extent_buffer(path->nodes[*level]);
-			path->nodes[*level] = NULL;
-			*level = i + 1;
-		}
-	}
-	return 1;
-}
-
-#endif
-
 int btrfs_free_block_groups(struct btrfs_fs_info *info)
 {
 	struct btrfs_space_info *sinfo;
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 2/4] btrfs-progs: Remove commented code

Quoted 3 lines · Nikolay Borisov

This piece of code has been commented since 2009, given the number of changes that have happened it's unlikely it could be made to work or is needed at all. Just delete it.

I has been ifdefed out in the infamous monster commit that changed the format (95d3f20b51e9b2ee2182231), so the removed code is basically the v0 format (I haven't checked closely), and that's been removed recently.

#4 lore raw

PATCH 3/4 btrfs: Remove old send implementation

In reply to Nikolay Borisov

Commit ba23855cdc89 ("btrfs-progs: send: use splice syscall instead of read/write to transfer buffer") changed the send implementation to use splice(). The old read/write implementation hasn't be used for at least 3 years, it's time to remove it.

---
 cmds-send.c | 61 -----------------------------------------------------
 1 file changed, 61 deletions(-)
cmds-send.c +0 -61
index 6496d8e39bbf..1735c35dca74 100644
@@ -207,67 +207,6 @@ static int add_clone_source(struct btrfs_send *sctx, u64 root_id)
 	return 0;
 }
 
-#if 0
-static int write_buf(int fd, const char *buf, size_t size)
-{
-	int ret;
-	size_t pos = 0;
-
-	while (pos < size) {
-		ssize_t wbytes;
-
-		wbytes = write(fd, buf + pos, size - pos);
-		if (wbytes < 0) {
-			ret = -errno;
-			error("failed to dump stream: %s", strerror(-ret));
-			goto out;
-		}
-		if (!wbytes) {
-			ret = -EIO;
-			error("failed to dump stream: %s", strerror(-ret));
-			goto out;
-		}
-		pos += wbytes;
-	}
-	ret = 0;
-
-out:
-	return ret;
-}
-
-static void* read_sent_data_copy(void *arg)
-{
-	int ret;
-	struct btrfs_send *sctx = (struct btrfs_send*)arg;
-	char buf[SEND_BUFFER_SIZE];
-
-	while (1) {
-		ssize_t rbytes;
-
-		rbytes = read(sctx->send_fd, buf, sizeof(buf));
-		if (rbytes < 0) {
-			ret = -errno;
-			error("failed to read stream from kernel: %s",
-				strerror(-ret));
-			goto out;
-		}
-		if (!rbytes) {
-			ret = 0;
-			goto out;
-		}
-		ret = write_buf(sctx->dump_fd, buf, rbytes);
-		if (ret < 0)
-			goto out;
-	}
-
-out:
-	if (ret < 0)
-		exit(-ret);
-
-	return ERR_PTR(ret);
-}
-#endif
-
 static void *read_sent_data(void *arg)
 {
 	int ret;
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 3/4] btrfs: Remove old send implementation

Quoted 4 lines · Nikolay Borisov

Commit ba23855cdc89 ("btrfs-progs: send: use splice syscall instead of read/write to transfer buffer") changed the send implementation to use splice(). The old read/write implementation hasn't be used for at least 3 years, it's time to remove it.

I left it there in case there are problems with splice so we could potentially offer option for the copy mechanism, but time proved it's not necessary.

#6 lore raw

PATCH 4/4 btrfs-progs: check: Remove duplicated and commented functions

In reply to Nikolay Borisov

Commit 756105181e57 ("btrfs-progs: check: supplement extent backref list with rbtree") changed the backref implementation to use rb tree and also commented the old implementations. It's been almost 2 years since that change and it's unlikely the old version will ever be used, so just remove it.

---
 check/main.c | 69 ----------------------------------------------------
 1 file changed, 69 deletions(-)
check/main.c +0 -69
index 731c21d364d7..05ba9819c58e 100644
@@ -4385,36 +4385,6 @@ static int check_block(struct btrfs_root *root,
 	return ret;
 }
 
-#if 0
-static struct tree_backref *find_tree_backref(struct extent_record *rec,
-						u64 parent, u64 root)
-{
-	struct list_head *cur = rec->backrefs.next;
-	struct extent_backref *node;
-	struct tree_backref *back;
-
-	while (cur != &rec->backrefs) {
-		node = to_extent_backref(cur);
-		cur = cur->next;
-		if (node->is_data)
-			continue;
-		back = to_tree_backref(node);
-		if (parent > 0) {
-			if (!node->full_backref)
-				continue;
-			if (parent == back->parent)
-				return back;
-		} else {
-			if (node->full_backref)
-				continue;
-			if (back->root == root)
-				return back;
-		}
-	}
-	return NULL;
-}
-#endif
-
 static struct tree_backref *alloc_tree_backref(struct extent_record *rec,
 						u64 parent, u64 root)
 {
@@ -4434,45 +4404,6 @@ static struct tree_backref *alloc_tree_backref(struct extent_record *rec,
 	return ref;
 }
 
-#if 0
-static struct data_backref *find_data_backref(struct extent_record *rec,
-						u64 parent, u64 root,
-						u64 owner, u64 offset,
-						int found_ref,
-						u64 disk_bytenr, u64 bytes)
-{
-	struct list_head *cur = rec->backrefs.next;
-	struct extent_backref *node;
-	struct data_backref *back;
-
-	while (cur != &rec->backrefs) {
-		node = to_extent_backref(cur);
-		cur = cur->next;
-		if (!node->is_data)
-			continue;
-		back = to_data_backref(node);
-		if (parent > 0) {
-			if (!node->full_backref)
-				continue;
-			if (parent == back->parent)
-				return back;
-		} else {
-			if (node->full_backref)
-				continue;
-			if (back->root == root && back->owner == owner &&
-			    back->offset == offset) {
-				if (found_ref && node->found_ref &&
-				    (back->bytes != bytes ||
-				    back->disk_bytenr != disk_bytenr))
-					continue;
-				return back;
-			}
-		}
-	}
-	return NULL;
-}
-#endif
-
 static struct data_backref *alloc_data_backref(struct extent_record *rec,
 						u64 parent, u64 root,
 						u64 owner, u64 offset,
Signature · 1 line
2.17.1
#7 lore raw
In reply to Nikolay Borisov
Quoted 9 lines · Nikolay Borisov

Just a couple of patches that remove unneeded code. The first one does away with an always true if construct and the rest remove code which has been #if 0 for quite some time.

Nikolay Borisov (4):
btrfs-progs: Remove redundant if
btrfs-progs: Remove commented code
btrfs: Remove old send implementation
btrfs-progs: check: Remove duplicated and commented functions

1-4 applied, thanks.