All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Btrfs: do not abort transaction in prealloc case
@ 2012-07-04 13:52 Liu Bo
  2012-07-04 13:52 ` [PATCH 2/4] Btrfs: fix a bug of writting free space cache with nodatacow option Liu Bo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Liu Bo @ 2012-07-04 13:52 UTC (permalink / raw)
  To: linux-btrfs

During disk balance, we prealloc new file extent for file data relocation,
but we may fail in 'no available space' case, and only under this case can
the error be reported to userspace, so we do not need to abort transaction
here.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
---
 fs/btrfs/ctree.h       |    8 ++++----
 fs/btrfs/extent-tree.c |   13 +++++++------
 fs/btrfs/inode.c       |    8 ++++----
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 84ac723..821a556 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2564,10 +2564,10 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
 				   u64 root_objectid, u64 owner, u64 offset,
 				   struct btrfs_key *ins);
 int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
-				  struct btrfs_root *root,
-				  u64 num_bytes, u64 min_alloc_size,
-				  u64 empty_size, u64 hint_byte,
-				  struct btrfs_key *ins, u64 data);
+			 struct btrfs_root *root,
+			 u64 num_bytes, u64 min_alloc_size,
+			 u64 empty_size, u64 hint_byte,
+			 struct btrfs_key *ins, u64 data, int abort_on_enospc);
 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		  struct extent_buffer *buf, int full_backref, int for_cow);
 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 5775dc4..bbe79ab 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5419,7 +5419,7 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
 				     struct btrfs_root *orig_root,
 				     u64 num_bytes, u64 empty_size,
 				     u64 hint_byte, struct btrfs_key *ins,
-				     u64 data)
+				     u64 data, int abort_on_enospc)
 {
 	int ret = 0;
 	struct btrfs_root *root = orig_root->fs_info->extent_root;
@@ -5778,8 +5778,9 @@ loop:
 						     2 * 1024 * 1024, data,
 						     CHUNK_ALLOC_LIMITED);
 				if (ret < 0) {
-					btrfs_abort_transaction(trans,
-								root, ret);
+					if (abort_on_enospc)
+						btrfs_abort_transaction(trans,
+								    root, ret);
 					goto out;
 				}
 				allowed_chunk_alloc = 0;
@@ -5864,7 +5865,7 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
 			 struct btrfs_root *root,
 			 u64 num_bytes, u64 min_alloc_size,
 			 u64 empty_size, u64 hint_byte,
-			 struct btrfs_key *ins, u64 data)
+			 struct btrfs_key *ins, u64 data, int abort_on_enospc)
 {
 	bool final_tried = false;
 	int ret;
@@ -5887,7 +5888,7 @@ again:
 
 	WARN_ON(num_bytes < root->sectorsize);
 	ret = find_free_extent(trans, root, num_bytes, empty_size,
-			       hint_byte, ins, data);
+			       hint_byte, ins, data, abort_on_enospc);
 
 	if (ret == -ENOSPC) {
 		if (!final_tried) {
@@ -6294,7 +6295,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
 		return ERR_CAST(block_rsv);
 
 	ret = btrfs_reserve_extent(trans, root, blocksize, blocksize,
-				   empty_size, hint, &ins, 0);
+				   empty_size, hint, &ins, 0, 1);
 	if (ret) {
 		unuse_block_rsv(root->fs_info, block_rsv, blocksize);
 		return ERR_PTR(ret);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 9f07bd1..1f72817 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -662,7 +662,7 @@ retry:
 			ret = btrfs_reserve_extent(trans, root,
 					   async_extent->compressed_size,
 					   async_extent->compressed_size,
-					   0, alloc_hint, &ins, 1);
+					   0, alloc_hint, &ins, 1, 1);
 			if (ret)
 				btrfs_abort_transaction(trans, root, ret);
 			btrfs_end_transaction(trans, root);
@@ -888,7 +888,7 @@ static noinline int cow_file_range(struct inode *inode,
 		cur_alloc_size = disk_num_bytes;
 		ret = btrfs_reserve_extent(trans, root, cur_alloc_size,
 					   root->sectorsize, 0, alloc_hint,
-					   &ins, 1);
+					   &ins, 1, 1);
 		if (ret < 0) {
 			btrfs_abort_transaction(trans, root, ret);
 			goto out_unlock;
@@ -5643,7 +5643,7 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode,
 
 	alloc_hint = get_extent_allocation_hint(inode, start, len);
 	ret = btrfs_reserve_extent(trans, root, len, root->sectorsize, 0,
-				   alloc_hint, &ins, 1);
+				   alloc_hint, &ins, 1, 1);
 	if (ret) {
 		em = ERR_PTR(ret);
 		goto out;
@@ -7540,7 +7540,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
 		}
 
 		ret = btrfs_reserve_extent(trans, root, num_bytes, min_size,
-					   0, *alloc_hint, &ins, 1);
+					   0, *alloc_hint, &ins, 1, 0);
 		if (ret) {
 			if (own_trans)
 				btrfs_end_transaction(trans, root);
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] Btrfs: fix a bug of writting free space cache with nodatacow option
  2012-07-04 13:52 [PATCH 1/4] Btrfs: do not abort transaction in prealloc case Liu Bo
@ 2012-07-04 13:52 ` Liu Bo
  2012-07-04 13:52 ` [PATCH 3/4] Btrfs: add ro notification to dump_space_info Liu Bo
  2012-07-04 13:52 ` [PATCH 4/4] Btrfs: do not count in readonly bytes Liu Bo
  2 siblings, 0 replies; 4+ messages in thread
From: Liu Bo @ 2012-07-04 13:52 UTC (permalink / raw)
  To: linux-btrfs

We can set a block group readonly when we relocate the block group.

If the block group covers the disk offset where our free space
cache inode is going to write, it will force the free space cache
inode into cow_file_range(), which is not allowed due to free space
cache design.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
---
 fs/btrfs/inode.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1f72817..4892396 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1245,7 +1245,11 @@ next_slot:
 				goto out_check;
 			if (extent_type == BTRFS_FILE_EXTENT_REG && !force)
 				goto out_check;
-			if (btrfs_extent_readonly(root, disk_bytenr))
+			/*
+			 * nolock means that we're free space cache inode, and
+			 * free space cache inode cannot go to cow_file_range().
+			 */
+			if (btrfs_extent_readonly(root, disk_bytenr) && !nolock)
 				goto out_check;
 			if (btrfs_cross_ref_exist(trans, root, ino,
 						  found_key.offset -
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] Btrfs: add ro notification to dump_space_info
  2012-07-04 13:52 [PATCH 1/4] Btrfs: do not abort transaction in prealloc case Liu Bo
  2012-07-04 13:52 ` [PATCH 2/4] Btrfs: fix a bug of writting free space cache with nodatacow option Liu Bo
@ 2012-07-04 13:52 ` Liu Bo
  2012-07-04 13:52 ` [PATCH 4/4] Btrfs: do not count in readonly bytes Liu Bo
  2 siblings, 0 replies; 4+ messages in thread
From: Liu Bo @ 2012-07-04 13:52 UTC (permalink / raw)
  To: linux-btrfs

Block group has ro attributes, make dump_space_info show it.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
---
 fs/btrfs/extent-tree.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index bbe79ab..f29859b 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5847,12 +5847,13 @@ again:
 	list_for_each_entry(cache, &info->block_groups[index], list) {
 		spin_lock(&cache->lock);
 		printk(KERN_INFO "block group %llu has %llu bytes, %llu used "
-		       "%llu pinned %llu reserved\n",
+		       "%llu pinned %llu reserved %s\n",
 		       (unsigned long long)cache->key.objectid,
 		       (unsigned long long)cache->key.offset,
 		       (unsigned long long)btrfs_block_group_used(&cache->item),
 		       (unsigned long long)cache->pinned,
-		       (unsigned long long)cache->reserved);
+		       (unsigned long long)cache->reserved,
+		       cache->ro ? "[readonly]" : "");
 		btrfs_dump_free_space(cache, bytes);
 		spin_unlock(&cache->lock);
 	}
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] Btrfs: do not count in readonly bytes
  2012-07-04 13:52 [PATCH 1/4] Btrfs: do not abort transaction in prealloc case Liu Bo
  2012-07-04 13:52 ` [PATCH 2/4] Btrfs: fix a bug of writting free space cache with nodatacow option Liu Bo
  2012-07-04 13:52 ` [PATCH 3/4] Btrfs: add ro notification to dump_space_info Liu Bo
@ 2012-07-04 13:52 ` Liu Bo
  2 siblings, 0 replies; 4+ messages in thread
From: Liu Bo @ 2012-07-04 13:52 UTC (permalink / raw)
  To: linux-btrfs

If a block group is ro, do not count its entries in when we dump space info.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
---
 fs/btrfs/free-space-cache.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index a70c54e..2d5b42e 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1967,7 +1967,7 @@ void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
 
 	for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) {
 		info = rb_entry(n, struct btrfs_free_space, offset_index);
-		if (info->bytes >= bytes)
+		if (info->bytes >= bytes && !block_group->ro)
 			count++;
 		printk(KERN_CRIT "entry offset %llu, bytes %llu, bitmap %s\n",
 		       (unsigned long long)info->offset,
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-04 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-04 13:52 [PATCH 1/4] Btrfs: do not abort transaction in prealloc case Liu Bo
2012-07-04 13:52 ` [PATCH 2/4] Btrfs: fix a bug of writting free space cache with nodatacow option Liu Bo
2012-07-04 13:52 ` [PATCH 3/4] Btrfs: add ro notification to dump_space_info Liu Bo
2012-07-04 13:52 ` [PATCH 4/4] Btrfs: do not count in readonly bytes Liu Bo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.