Skip to contentSkip to conversation

Btrfs: Abstract similar code for btrfs_block_rsv_add{, _noflush}()

PATCH In review Miao Xie 2 participants 3 messages Nov 10, 2011 – Nov 11, 2011 Btrfs file system

lore
Share & tools
lore

Miao Xie

author
#0 lore raw

PATCH 1/6 Btrfs: Abstract similar code for btrfs_block_rsv_add{, _noflush}()

btrfs_block_rsv_add{, _noflush}() have similar code, so abstract that code.

---
 fs/btrfs/extent-tree.c |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)
fs/btrfs/extent-tree.c +12 -16
index 1311beb..6703a43 100644
@@ -3796,16 +3796,16 @@ void btrfs_free_block_rsv(struct btrfs_root *root,
 	kfree(rsv);
 }
 
-int btrfs_block_rsv_add(struct btrfs_root *root,
-			struct btrfs_block_rsv *block_rsv,
-			u64 num_bytes)
+static inline int __block_rsv_add(struct btrfs_root *root,
+				  struct btrfs_block_rsv *block_rsv,
+				  u64 num_bytes, int flush)
 {
 	int ret;
 
 	if (num_bytes == 0)
 		return 0;
 
-	ret = reserve_metadata_bytes(root, block_rsv, num_bytes, 1);
+	ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
 	if (!ret) {
 		block_rsv_add_bytes(block_rsv, num_bytes, 1);
 		return 0;
@@ -3814,22 +3814,18 @@ int btrfs_block_rsv_add(struct btrfs_root *root,
 	return ret;
 }
 
+int btrfs_block_rsv_add(struct btrfs_root *root,
+			struct btrfs_block_rsv *block_rsv,
+			u64 num_bytes)
+{
+	return __block_rsv_add(root, block_rsv, num_bytes, 1);
+}
+
 int btrfs_block_rsv_add_noflush(struct btrfs_root *root,
 				struct btrfs_block_rsv *block_rsv,
 				u64 num_bytes)
 {
-	int ret;
-
-	if (num_bytes == 0)
-		return 0;
-
-	ret = reserve_metadata_bytes(root, block_rsv, num_bytes, 0);
-	if (!ret) {
-		block_rsv_add_bytes(block_rsv, num_bytes, 1);
-		return 0;
-	}
-
-	return ret;
+	return __block_rsv_add(root, block_rsv, num_bytes, 0);
 }
 
 int btrfs_block_rsv_check(struct btrfs_root *root,
Signature · 1 line
1.7.6.4
author
#1 lore raw

The mail of PATCH 0 was always rejected, so I try to send it as the reply of PATCH 1.
====================
Title: [PATCH 0/6] Random fix of the space relocation

This patchset fixes 5 bugs of the space relocation, one fixes the problem that we forgot to reserve space for writing out i-node cache, one fixes that the path is not released, this problem may cause the deadlock. one fixes the no-cow problem, this problem will break the meta-data. one fixes the deadlock that caused by the race between the relocation and the snapshot creation, the last one fixes BUG_ON() which is triggered by the orphan back-ref nodes.

NOTE: This patchset is based on the danger branch.

Miao Xie (6):
Btrfs: Abstract similar code for btrfs_block_rsv_add{, _noflush}()
Btrfs: fix no reserved space for writing out inode cache
Btrfs: fix unreleased path in btrfs_orphan_cleanup()
Btrfs: fix nocow when deleting the item
Btrfs: fix deadlock caused by the race between relocation and snapshot creation
Btrfs: fix orphan backref nodes

 fs/btrfs/extent-tree.c |   28 ++++++++++++----------------
 fs/btrfs/inode-map.c   |   28 ++++++++++++++++++++++++----
 fs/btrfs/inode.c       |    3 +++
 fs/btrfs/relocation.c  |    2 ++
 fs/btrfs/transaction.c |    4 ++--
 fs/btrfs/volumes.c     |    5 ++++-
 6 files changed, 47 insertions(+), 23 deletions(-)
Quoted 63 lines · Miao Xie

btrfs_block_rsv_add{, _noflush}() have similar code, so abstract that code.

---
 fs/btrfs/extent-tree.c |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)
fs/btrfs/extent-tree.c +12 -16
index 1311beb..6703a43 100644
@@ -3796,16 +3796,16 @@ void btrfs_free_block_rsv(struct btrfs_root *root,
 	kfree(rsv);
 }
 
-int btrfs_block_rsv_add(struct btrfs_root *root,
-			struct btrfs_block_rsv *block_rsv,
-			u64 num_bytes)
+static inline int __block_rsv_add(struct btrfs_root *root,
+				  struct btrfs_block_rsv *block_rsv,
+				  u64 num_bytes, int flush)
 {
 	int ret;
 
 	if (num_bytes == 0)
 		return 0;
 
-	ret = reserve_metadata_bytes(root, block_rsv, num_bytes, 1);
+	ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
 	if (!ret) {
 		block_rsv_add_bytes(block_rsv, num_bytes, 1);
 		return 0;
@@ -3814,22 +3814,18 @@ int btrfs_block_rsv_add(struct btrfs_root *root,
 	return ret;
 }
 
+int btrfs_block_rsv_add(struct btrfs_root *root,
+			struct btrfs_block_rsv *block_rsv,
+			u64 num_bytes)
+{
+	return __block_rsv_add(root, block_rsv, num_bytes, 1);
+}
+
 int btrfs_block_rsv_add_noflush(struct btrfs_root *root,
 				struct btrfs_block_rsv *block_rsv,
 				u64 num_bytes)
 {
-	int ret;
-
-	if (num_bytes == 0)
-		return 0;
-
-	ret = reserve_metadata_bytes(root, block_rsv, num_bytes, 0);
-	if (!ret) {
-		block_rsv_add_bytes(block_rsv, num_bytes, 1);
-		return 0;
-	}
-
-	return ret;
+	return __block_rsv_add(root, block_rsv, num_bytes, 0);
 }
 
 int btrfs_block_rsv_check(struct btrfs_root *root,
#2 lore raw
Quoted 13 lines · Miao Xie

The mail of PATCH 0 was always rejected, so I try to send it as the reply of PATCH 1.
====================
Title: [PATCH 0/6] Random fix of the space relocation

This patchset fixes 5 bugs of the space relocation, one fixes the problem that we forgot to reserve space for writing out i-node cache, one fixes that the path is not released, this problem may cause the deadlock. one fixes the no-cow problem, this problem will break the meta-data. one fixes the deadlock that caused by the race between the relocation and the snapshot creation, the last one fixes BUG_ON() which is triggered by the orphan back-ref nodes.

Quoted 1 line

NOTE: This patchset is based on the danger branch.

Thanks! For future patches, please use the for-linus branch instead. danger still has the subtransid code, which we need to fix

-chris