Skip to contentSkip to conversation

btrfs: drop nonvaring variable, instead define it

PATCH Superseded Anand Jain 2 participants 4 messages Feb 26, 2018 – Mar 7, 2018 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

PATCH 1/1 btrfs: drop nonvaring variable, instead define it

btrfs_defrag_leaves() has min_trans = 0 which doesn't vary. Defining it makes sense.

---
 fs/btrfs/ctree.h       | 2 ++
 fs/btrfs/tree-defrag.c | 5 ++---
 2 files changed, 4 insertions(+), 3 deletions(-)
fs/btrfs/ctree.h +2 -0
index cb6c1ecb3cb0..295c6cf85d0f 100644
@@ -66,6 +66,8 @@ struct btrfs_ordered_sum;
 
 #define BTRFS_MAX_LEVEL 8
 
+#define BTRFS_OLDEST_GENERATION	0ULL
+
 #define BTRFS_COMPAT_EXTENT_TREE_V0
 
 /*
fs/btrfs/tree-defrag.c +2 -3
index cb65089127cc..c09dbe4bd6e7 100644
@@ -39,7 +39,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 	int level;
 	int next_key_ret = 0;
 	u64 last_ret = 0;
-	u64 min_trans = 0;
 
 	if (root->fs_info->extent_root == root) {
 		/*
@@ -81,7 +80,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 
 	path->keep_locks = 1;
 
-	ret = btrfs_search_forward(root, &key, path, min_trans);
+	ret = btrfs_search_forward(root, &key, path, BTRFS_OLDEST_GENERATION);
 	if (ret < 0)
 		goto out;
 	if (ret > 0) {
@@ -130,7 +129,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 	 */
 	path->slots[1] = btrfs_header_nritems(path->nodes[1]);
 	next_key_ret = btrfs_find_next_key(root, path, &key, 1,
-					   min_trans);
+					   BTRFS_OLDEST_GENERATION);
 	if (next_key_ret == 0) {
 		memcpy(&root->defrag_progress, &key, sizeof(key));
 		ret = -EAGAIN;
Signature · 1 line
2.15.0
#1 lore raw
Quoted 2 lines · Anand Jain

btrfs_defrag_leaves() has min_trans = 0 which doesn't vary. Defining it makes sense.

Defining the oldest transaction makes sense and it can be used in more calls to btrfs_search_forward, please update the patch.

author
#2 lore raw

PATCH v2 1/1 btrfs: drop nonvaring variable, instead define it

btrfs_defrag_leaves() declares min_trans = 0; as variable, but doesn't vary it, so define it.

---
v2->v1: Use BTRFS_OLDEST_GENERATION at more places where needed.

 fs/btrfs/ctree.h       | 2 ++
 fs/btrfs/ioctl.c       | 2 +-
 fs/btrfs/tree-defrag.c | 5 ++---
 fs/btrfs/uuid-tree.c   | 2 +-
 fs/btrfs/volumes.c     | 2 +-
 5 files changed, 7 insertions(+), 6 deletions(-)
fs/btrfs/ctree.h +2 -0
index d688430f9be1..7c408062b6a5 100644
@@ -66,6 +66,8 @@ struct btrfs_ordered_sum;
 
 #define BTRFS_MAX_LEVEL 8
 
+#define BTRFS_OLDEST_GENERATION	0ULL
+
 #define BTRFS_COMPAT_EXTENT_TREE_V0
 
 /*
fs/btrfs/ioctl.c +1 -1
index c5a559105949..ba403c00982c 100644
@@ -2600,7 +2600,7 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
 			range->len = (u64)-1;
 		}
 		ret = btrfs_defrag_file(file_inode(file), file,
-					range, 0, 0);
+					range, BTRFS_OLDEST_GENERATION, 0);
 		if (ret > 0)
 			ret = 0;
 		kfree(range);
fs/btrfs/tree-defrag.c +2 -3
index cb65089127cc..c09dbe4bd6e7 100644
@@ -39,7 +39,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 	int level;
 	int next_key_ret = 0;
 	u64 last_ret = 0;
-	u64 min_trans = 0;
 
 	if (root->fs_info->extent_root == root) {
 		/*
@@ -81,7 +80,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 
 	path->keep_locks = 1;
 
-	ret = btrfs_search_forward(root, &key, path, min_trans);
+	ret = btrfs_search_forward(root, &key, path, BTRFS_OLDEST_GENERATION);
 	if (ret < 0)
 		goto out;
 	if (ret > 0) {
@@ -130,7 +129,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 	 */
 	path->slots[1] = btrfs_header_nritems(path->nodes[1]);
 	next_key_ret = btrfs_find_next_key(root, path, &key, 1,
-					   min_trans);
+					   BTRFS_OLDEST_GENERATION);
 	if (next_key_ret == 0) {
 		memcpy(&root->defrag_progress, &key, sizeof(key));
 		ret = -EAGAIN;
fs/btrfs/uuid-tree.c +1 -1
index 726f928238d0..9916f03430bc 100644
@@ -282,7 +282,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info,
 	key.offset = 0;
 
 again_search_slot:
-	ret = btrfs_search_forward(root, &key, path, 0);
+	ret = btrfs_search_forward(root, &key, path, BTRFS_OLDEST_GENERATION);
 	if (ret) {
 		if (ret > 0)
 			ret = 0;
fs/btrfs/volumes.c +1 -1
index b4ada8f50f3c..328b97801836 100644
@@ -4206,7 +4206,7 @@ static int btrfs_uuid_scan_kthread(void *data)
 	key.offset = 0;
 
 	while (1) {
-		ret = btrfs_search_forward(root, &key, path, 0);
+		ret = btrfs_search_forward(root, &key, path, BTRFS_OLDEST_GENERATION);
 		if (ret) {
 			if (ret > 0)
 				ret = 0;
Signature · 1 line
2.15.0
Reviewed-by on v2 1/1
#3 lore raw
Quoted 4 lines · Anand Jain

btrfs_defrag_leaves() declares min_trans = 0; as variable, but doesn't vary it, so define it.

Quoted 2 lines

---
v2->v1: Use BTRFS_OLDEST_GENERATION at more places where needed.

I've updated to reflect the change as the new define is the interesting part, removing min_trans in defrag_leaf is only collateral in this case.