Skip to contentSkip to conversation

btrfs: Add helper function for free_root_pointers()

PATCH Superseded Rashika Kheria 3 participants 4 messages Oct 30, 2013 – Nov 2, 2013 1 message not in the archive Btrfs file system

lore
Share & tools
lore
#1 lore raw

PATCH v3 1/1 btrfs: Add helper function for free_root_pointers()

In reply to a message not in the archive

The function free_root_pointers() in disk-io.h contains redundant code. Therefore, this patch adds a helper function free_root_extent_buffers() to free_root_pointers() to eliminate redundancy.

---

This revision fixes the following issues of the previous revision- Incorrect commit message

 fs/btrfs/disk-io.c |   60 +++++++++++++++++-----------------------------------
 1 file changed, 19 insertions(+), 41 deletions(-)
fs/btrfs/disk-io.c +19 -41
index 4ae17ed..25fb77a 100644
@@ -2012,50 +2012,28 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
 	btrfs_stop_workers(&fs_info->qgroup_rescan_workers);
 }
 
+static void free_root_extent_buffers(struct btrfs_root *root)
+{
+	if (root) {
+		free_extent_buffer(root->node);
+		free_extent_buffer(root->commit_root);
+		root->node = NULL;
+		root->commit_root = NULL;
+	}
+}
+
 /* helper to cleanup tree roots */
 static void free_root_pointers(struct btrfs_fs_info *info, int chunk_root)
 {
-	free_extent_buffer(info->tree_root->node);
-	free_extent_buffer(info->tree_root->commit_root);
-	info->tree_root->node = NULL;
-	info->tree_root->commit_root = NULL;
-
-	if (info->dev_root) {
-		free_extent_buffer(info->dev_root->node);
-		free_extent_buffer(info->dev_root->commit_root);
-		info->dev_root->node = NULL;
-		info->dev_root->commit_root = NULL;
-	}
-	if (info->extent_root) {
-		free_extent_buffer(info->extent_root->node);
-		free_extent_buffer(info->extent_root->commit_root);
-		info->extent_root->node = NULL;
-		info->extent_root->commit_root = NULL;
-	}
-	if (info->csum_root) {
-		free_extent_buffer(info->csum_root->node);
-		free_extent_buffer(info->csum_root->commit_root);
-		info->csum_root->node = NULL;
-		info->csum_root->commit_root = NULL;
-	}
-	if (info->quota_root) {
-		free_extent_buffer(info->quota_root->node);
-		free_extent_buffer(info->quota_root->commit_root);
-		info->quota_root->node = NULL;
-		info->quota_root->commit_root = NULL;
-	}
-	if (info->uuid_root) {
-		free_extent_buffer(info->uuid_root->node);
-		free_extent_buffer(info->uuid_root->commit_root);
-		info->uuid_root->node = NULL;
-		info->uuid_root->commit_root = NULL;
-	}
-	if (chunk_root) {
-		free_extent_buffer(info->chunk_root->node);
-		free_extent_buffer(info->chunk_root->commit_root);
-		info->chunk_root->node = NULL;
-		info->chunk_root->commit_root = NULL;
-	}
+	free_root_extent_buffers(info->tree_root);
+
+	free_root_extent_buffers(info->dev_root);
+	free_root_extent_buffers(info->extent_root);
+	free_root_extent_buffers(info->csum_root);
+	free_root_extent_buffers(info->quota_root);
+	free_root_extent_buffers(info->uuid_root);
+	if (chunk_root)
+		free_root_extent_buffers(info->chunk_root);
 }
 
 static void del_fs_roots(struct btrfs_fs_info *fs_info)
Signature · 1 line
1.7.9.5
Reviewed-by on v3 1/1
#2 lore raw
Quoted 6 lines · Rashika Kheria

The function free_root_pointers() in disk-io.h contains redundant code. Therefore, this patch adds a helper function free_root_extent_buffers() to free_root_pointers() to eliminate redundancy.

(In general, the Reviewed-by goes after the Signed-off-by.)

One minor nit:

Quoted 5 lines
fs/btrfs/disk-io.c +0 -0
@@ -2012,50 +2012,28 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
 	btrfs_stop_workers(&fs_info->qgroup_rescan_workers);
 }

fs/btrfs/disk-io.c static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) · line 2023

Quoted 10 lines
fs/btrfs/disk-io.c +9 -0
 
+static void free_root_extent_buffers(struct btrfs_root *root)
+{
+	if (root) {
+		free_extent_buffer(root->node);
+		free_extent_buffer(root->commit_root);
+		root->node = NULL;
+		root->commit_root = NULL;
+	}
+}

I'd tend to write this with an early return if (!root). In this case it doesn't matter much, but it's a good habit to get into for larger functions with deeper indentation.

- Josh Triplett

#3 lore raw

PATCH v4 1/1 btrfs: Add helper function for free_root_pointers()

In reply to a message not in the archive

The function free_root_pointers() in disk-io.h contains redundant code. Therefore, this patch adds a helper function free_root_extent_buffers() to free_root_pointers() to eliminate redundancy

---

This revision fixes the following issues of the previous revision- Early return when root is NULL

 fs/btrfs/disk-io.c |   60 +++++++++++++++++-----------------------------------
 1 file changed, 19 insertions(+), 41 deletions(-)
fs/btrfs/disk-io.c +19 -41
index 62176ad..f719394 100644
@@ -2013,50 +2013,28 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
 	btrfs_stop_workers(&fs_info->qgroup_rescan_workers);
 }
 
+static void free_root_extent_buffers(struct btrfs_root *root)
+{
+	if (!root)
+		return;
+	free_extent_buffer(root->node);
+	free_extent_buffer(root->commit_root);
+	root->node = NULL;
+	root->commit_root = NULL;
+}
+
 /* helper to cleanup tree roots */
 static void free_root_pointers(struct btrfs_fs_info *info, int chunk_root)
 {
-	free_extent_buffer(info->tree_root->node);
-	free_extent_buffer(info->tree_root->commit_root);
-	info->tree_root->node = NULL;
-	info->tree_root->commit_root = NULL;
-
-	if (info->dev_root) {
-		free_extent_buffer(info->dev_root->node);
-		free_extent_buffer(info->dev_root->commit_root);
-		info->dev_root->node = NULL;
-		info->dev_root->commit_root = NULL;
-	}
-	if (info->extent_root) {
-		free_extent_buffer(info->extent_root->node);
-		free_extent_buffer(info->extent_root->commit_root);
-		info->extent_root->node = NULL;
-		info->extent_root->commit_root = NULL;
-	}
-	if (info->csum_root) {
-		free_extent_buffer(info->csum_root->node);
-		free_extent_buffer(info->csum_root->commit_root);
-		info->csum_root->node = NULL;
-		info->csum_root->commit_root = NULL;
-	}
-	if (info->quota_root) {
-		free_extent_buffer(info->quota_root->node);
-		free_extent_buffer(info->quota_root->commit_root);
-		info->quota_root->node = NULL;
-		info->quota_root->commit_root = NULL;
-	}
-	if (info->uuid_root) {
-		free_extent_buffer(info->uuid_root->node);
-		free_extent_buffer(info->uuid_root->commit_root);
-		info->uuid_root->node = NULL;
-		info->uuid_root->commit_root = NULL;
-	}
-	if (chunk_root) {
-		free_extent_buffer(info->chunk_root->node);
-		free_extent_buffer(info->chunk_root->commit_root);
-		info->chunk_root->node = NULL;
-		info->chunk_root->commit_root = NULL;
-	}
+	free_root_extent_buffers(info->tree_root);
+
+	free_root_extent_buffers(info->dev_root);
+	free_root_extent_buffers(info->extent_root);
+	free_root_extent_buffers(info->csum_root);
+	free_root_extent_buffers(info->quota_root);
+	free_root_extent_buffers(info->uuid_root);
+	if (chunk_root)
+		free_root_extent_buffers(info->chunk_root);
 }
 
 static void del_fs_roots(struct btrfs_fs_info *fs_info)
Signature · 1 line
1.7.9.5
#4 lore raw

I've already pulled v3 into btrfs-next, for this I prefer v3. Thanks,

Josef

Quoted 98 lines · Rashika Kheria

The function free_root_pointers() in disk-io.h contains redundant code. Therefore, this patch adds a helper function free_root_extent_buffers() to free_root_pointers() to eliminate redundancy

---

This revision fixes the following issues of the previous revision- Early return when root is NULL

fs/btrfs/disk-io.c | 60 +++++++++++++++++-----------------------------------

1 file changed, 19 insertions(+), 41 deletions(-)
fs/btrfs/disk-io.c +19 -41
index 62176ad..f719394 100644
@@ -2013,50 +2013,28 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
   btrfs_stop_workers(&fs_info->qgroup_rescan_workers);
 }
 
+static void free_root_extent_buffers(struct btrfs_root *root)
+{
+    if (!root)
+        return;
+    free_extent_buffer(root->node);
+    free_extent_buffer(root->commit_root);
+    root->node = NULL;
+    root->commit_root = NULL;
+}
+
 /* helper to cleanup tree roots */
 static void free_root_pointers(struct btrfs_fs_info *info, int chunk_root)
 {
-    free_extent_buffer(info->tree_root->node);
-    free_extent_buffer(info->tree_root->commit_root);
-    info->tree_root->node = NULL;
-    info->tree_root->commit_root = NULL;
-
-    if (info->dev_root) {
-        free_extent_buffer(info->dev_root->node);
-        free_extent_buffer(info->dev_root->commit_root);
-        info->dev_root->node = NULL;
-        info->dev_root->commit_root = NULL;
-    }
-    if (info->extent_root) {
-        free_extent_buffer(info->extent_root->node);
-        free_extent_buffer(info->extent_root->commit_root);
-        info->extent_root->node = NULL;
-        info->extent_root->commit_root = NULL;
-    }
-    if (info->csum_root) {
-        free_extent_buffer(info->csum_root->node);
-        free_extent_buffer(info->csum_root->commit_root);
-        info->csum_root->node = NULL;
-        info->csum_root->commit_root = NULL;
-    }
-    if (info->quota_root) {
-        free_extent_buffer(info->quota_root->node);
-        free_extent_buffer(info->quota_root->commit_root);
-        info->quota_root->node = NULL;
-        info->quota_root->commit_root = NULL;
-    }
-    if (info->uuid_root) {
-        free_extent_buffer(info->uuid_root->node);
-        free_extent_buffer(info->uuid_root->commit_root);
-        info->uuid_root->node = NULL;
-        info->uuid_root->commit_root = NULL;
-    }
-    if (chunk_root) {
-        free_extent_buffer(info->chunk_root->node);
-        free_extent_buffer(info->chunk_root->commit_root);
-        info->chunk_root->node = NULL;
-        info->chunk_root->commit_root = NULL;
-    }
+    free_root_extent_buffers(info->tree_root);
+
+    free_root_extent_buffers(info->dev_root);
+    free_root_extent_buffers(info->extent_root);
+    free_root_extent_buffers(info->csum_root);
+    free_root_extent_buffers(info->quota_root);
+    free_root_extent_buffers(info->uuid_root);
+    if (chunk_root)
+        free_root_extent_buffers(info->chunk_root);
 }
 
 static void del_fs_roots(struct btrfs_fs_info *fs_info)
Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html