Re: FS gives kernel UPS on attempt to create snapshot and after running balance it's unmountable.

2017-02-15 Thread Qu Wenruo



At 02/15/2017 10:11 PM, Tomasz Kusmierz wrote:

So guys, any help here ? I’m kinda stuck now with system just idling and doing 
nothing while I wait for some feedback ...


Sorry for the late reply.

Busying debugging a kernel bug.


On 14 Feb 2017, at 19:38, Tomasz Kusmierz  wrote:

[root@server ~]#  btrfs-show-super -af /dev/sdc
superblock: bytenr=65536, device=/dev/sdc
-
csum_type   0 (crc32c)
csum_size   4
csum0x17d56ce0 [match]


This superblock is good.


bytenr  65536
flags   0x1
   ( WRITTEN )
magic   _BHRfS_M [match]
fsid0576d577-8954-4a60-a02b-9492b3c29318
label   main_pool
generation  150682
root5223857717248
sys_array_size  321
chunk_root_generation   150678
root_level  1
chunk_root  8669488005120
chunk_root_level1
log_root0
log_root_transid0
log_root_level  0
total_bytes 16003191472128
bytes_used  6411278503936
sectorsize  4096
nodesize16384
leafsize16384
stripesize  4096
root_dir6
num_devices 8
compat_flags0x0
compat_ro_flags 0x0
incompat_flags  0x161
   ( MIXED_BACKREF |
 BIG_METADATA |
 EXTENDED_IREF |
 SKINNY_METADATA )
cache_generation150682
uuid_tree_generation150679
dev_item.uuid   46abffa8-7afe-451f-93c6-abb8e589c4e8
dev_item.fsid   0576d577-8954-4a60-a02b-9492b3c29318 [match]
dev_item.type   0
dev_item.total_bytes2000398934016
dev_item.bytes_used 1647136735232
dev_item.io_align   4096
dev_item.io_width   4096
dev_item.sector_size4096
dev_item.devid  1
dev_item.dev_group  0
dev_item.seek_speed 0
dev_item.bandwidth  0
dev_item.generation 0
sys_chunk_array[2048]:
   item 0 key (FIRST_CHUNK_TREE CHUNK_ITEM 8669487824896)
   length 67108864 owner 2 stripe_len 65536 type SYSTEM|RAID10
   io_align 65536 io_width 65536 sector_size 4096
   num_stripes 8 sub_stripes 2
   stripe 0 devid 7 offset 1083674984448
   dev_uuid 566fb8a3-d6de-4230-8b70-a5fda0a120f6
   stripe 1 devid 8 offset 1083674984448
   dev_uuid 845aefb2-e0a6-479a-957b-a82fb7207d6c
   stripe 2 devid 1 offset 1365901312
   dev_uuid 46abffa8-7afe-451f-93c6-abb8e589c4e8
   stripe 3 devid 3 offset 1345978368
   dev_uuid 95921633-2fc1-479f-a3ba-e6e5a1989755
   stripe 4 devid 4 offset 1345978368
   dev_uuid 20828f0e-4661-4987-ac11-72814c1e423a
   stripe 5 devid 5 offset 1345978368
   dev_uuid 2c3cd71f-5178-48e7-8032-6b6eec023197
   stripe 6 devid 6 offset 1345978368
   dev_uuid 806a47e5-cac4-41c9-abb9-5c49506459e1
   stripe 7 devid 2 offset 1345978368
   dev_uuid e1358e0e-edaf-4505-9c71-ed0862c45841


And I didn't see anything wrong in sys_chunk_array.


Would you please try to mount the fs with latest kernel?
Better later than v4.9, as in that version extra kernel messages are 
introduced to give more details about what's going wrong.


Thanks,
Qu


backup_roots[4]:
   backup 0:
   backup_tree_root:   5223857717248   gen: 150680 level: 1
   backup_chunk_root:  8669488005120   gen: 150678 level: 1
   backup_extent_root: 5223867383808   gen: 150680 level: 2
   backup_fs_root: 0   gen: 0  level: 0
   backup_dev_root:5224791523328   gen: 150680 level: 1
   backup_csum_root:   5224802140160   gen: 150680 level: 3
   backup_total_bytes: 16003191472128
   backup_bytes_used:  6411278503936
   backup_num_devices: 8

   backup 1:
   backup_tree_root:   5224155807744   gen: 150681 level: 1
   backup_chunk_root:  8669488005120   gen: 150678 level: 1
   backup_extent_root: 5224156233728   gen: 150681 level: 2
   backup_fs_root: 0   gen: 0  level: 0
   backup_dev_root:5224633155584   gen: 150681 level: 1
   backup_csum_root:   5224634941440   gen: 150681 level: 3
   backup_total_bytes: 16003191472128
   backup_bytes_used:  6411278503936
   backup_num_devices: 8

   backup 2:
   backup_tree_root:   

Re: [PATCH] btrfs: Handle btrfs_reloc_clone_csums error correctly to avoid deadlock

2017-02-15 Thread Qu Wenruo



At 02/15/2017 11:59 PM, Filipe Manana wrote:

On Wed, Feb 15, 2017 at 8:49 AM, Qu Wenruo  wrote:

If run btrfs/125 with nospace_cache or space_cache=v2 mount option,
btrfs will block with the following backtrace:

Call Trace:
 __schedule+0x2d4/0xae0
 schedule+0x3d/0x90
 btrfs_start_ordered_extent+0x160/0x200 [btrfs]
 ? wake_atomic_t_function+0x60/0x60
 btrfs_run_ordered_extent_work+0x25/0x40 [btrfs]
 btrfs_scrubparity_helper+0x1c1/0x620 [btrfs]
 btrfs_flush_delalloc_helper+0xe/0x10 [btrfs]
 process_one_work+0x2af/0x720
 ? process_one_work+0x22b/0x720
 worker_thread+0x4b/0x4f0
 kthread+0x10f/0x150
 ? process_one_work+0x720/0x720
 ? kthread_create_on_node+0x40/0x40
 ret_from_fork+0x2e/0x40

The direct cause is the error handler in run_delalloc_nocow() doesn't
handle error from btrfs_reloc_clone_csums() well.

The related part call path will be:
__extent_writepage
|- writepage_delalloc()
|  |- run_delalloc_range()
| |- run_delalloc_nocow()
||- btrfs_add_ordered_extent()
||  Now one ordered extent for file range, e.g [0, 1M) is inserted
||
||- btrfs_reloc_clone_csums()
||  Fails with -EIO, as RAID5/6 doesn't repair some csum tree
||  blocks
||
||- extent_clear_unlock_delalloc()
|   Error routine, unlock and clear page DIRTY, end page writeback
|   So the remaining 255 pages will not go through writeback
|
|- __extent_writepage_io()
   |- writepage_end_io_hook()
  |- btrfs_dev_test_ordered_pending()
 Reduce ordered_extent->bytes_left by 4K.
 Still have (1M - 4K) to finish.

While the remaining 255 pages will not go through IO nor trigger
writepage_end_io_hook(), the ordered extent for [0, 1M) will
never finish, and blocking current transaction forever.

Although the root cause is still in RAID5/6, it won't hurt to fix the
error routine first.

This patch will cleanup the ordered extent in error routine, so at least
we won't cause deadlock.

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/extent_io.c|  1 -
 fs/btrfs/inode.c| 10 --
 fs/btrfs/ordered-data.c | 25 +
 fs/btrfs/ordered-data.h | 10 ++
 4 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 4ac383a3a649..a14d1b0840c5 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3258,7 +3258,6 @@ static noinline_for_stack int writepage_delalloc(struct 
inode *inode,
   delalloc_end,
   _started,
   nr_written);
-   /* File system has been set read-only */
if (ret) {
SetPageError(page);
/* fill_delalloc should be return < 0 for error
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1e861a063721..3c3ade58afd7 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1052,8 +1052,11 @@ static noinline int cow_file_range(struct inode *inode,
BTRFS_DATA_RELOC_TREE_OBJECTID) {
ret = btrfs_reloc_clone_csums(inode, start,
  cur_alloc_size);
-   if (ret)
+   if (ret) {
+   btrfs_clean_ordered_extent(inode, start,
+  ram_size);
goto out_drop_extent_cache;
+   }
}

btrfs_dec_block_group_reservations(fs_info, ins.objectid);
@@ -1538,7 +1541,7 @@ static noinline int run_delalloc_nocow(struct inode 
*inode,
if (!ret)
ret = err;

-   if (ret && cur_offset < end)
+   if (ret && cur_offset < end) {
extent_clear_unlock_delalloc(inode, cur_offset, end, end,
 locked_page, EXTENT_LOCKED |
 EXTENT_DELALLOC | EXTENT_DEFRAG |
@@ -1546,6 +1549,9 @@ static noinline int run_delalloc_nocow(struct inode 
*inode,
 PAGE_CLEAR_DIRTY |
 PAGE_SET_WRITEBACK |
 PAGE_END_WRITEBACK);
+   btrfs_clean_ordered_extent(inode, cur_offset,
+  end - cur_offset + 1);


So this is partially correct only.
First here you can have 0, 1 or more ordered extents that were created
in the while loop. So your new function must find and process all
ordered extents within the delalloc range and not just the last one
that was created.


OK, I found that only btrfs_reloc_clone_csums() will need to cleanup 
ordered extent, and there is no other case which can cause error after 
adding ordered extent.


So what about moving the 

Re: [PATCH 29/29] btrfs: remove unused parameter from adjust_slots_upwards

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:50AM +0100, David Sterba wrote:
> Never used.
> 
Looks good.

Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/qgroup.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 6d106e623604..4ef513a392a7 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -1589,8 +1589,7 @@ int btrfs_qgroup_trace_leaf_items(struct 
> btrfs_trans_handle *trans,
>   * If we increment the root nodes slot counter past the number of
>   * elements, 1 is returned to signal completion of the search.
>   */
> -static int adjust_slots_upwards(struct btrfs_root *root,
> - struct btrfs_path *path, int root_level)
> +static int adjust_slots_upwards(struct btrfs_path *path, int root_level)
>  {
>   int level = 0;
>   int nr, slot;
> @@ -1731,7 +1730,7 @@ int btrfs_qgroup_trace_subtree(struct 
> btrfs_trans_handle *trans,
>   goto out;
>  
>   /* Nonzero return here means we completed our search */
> - ret = adjust_slots_upwards(root, path, root_level);
> + ret = adjust_slots_upwards(path, root_level);
>   if (ret)
>   break;
>  
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 25/29] btrfs: remove unused parameter from clone_copy_inline_extent

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:38AM +0100, David Sterba wrote:
> Never used.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ioctl.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 1f13f8416d29..b9e6f8a4f760 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -3383,8 +3383,7 @@ static void clone_update_extent_map(struct inode *inode,
>   * data into the destination inode's inline extent if the later is greater 
> then
>   * the former.
>   */
> -static int clone_copy_inline_extent(struct inode *src,
> - struct inode *dst,
> +static int clone_copy_inline_extent(struct inode *dst,
>   struct btrfs_trans_handle *trans,
>   struct btrfs_path *path,
>   struct btrfs_key *new_key,
> @@ -3763,7 +3762,7 @@ static int btrfs_clone(struct inode *src, struct inode 
> *inode,
>   size -= skip + trim;
>   datal -= skip + trim;
>  
> - ret = clone_copy_inline_extent(src, inode,
> + ret = clone_copy_inline_extent(inode,
>  trans, path,
>  _key,
>  drop_start,
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 26/29] btrfs: remove unused parameter from __add_inode_ref

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:41AM +0100, David Sterba wrote:
> Unused since the helper has been split, eb used in the caller.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/tree-log.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
> index 62dd138018b5..3806853cde08 100644
> --- a/fs/btrfs/tree-log.c
> +++ b/fs/btrfs/tree-log.c
> @@ -994,7 +994,6 @@ static inline int __add_inode_ref(struct 
> btrfs_trans_handle *trans,
> struct btrfs_root *log_root,
> struct btrfs_inode *dir,
> struct btrfs_inode *inode,
> -   struct extent_buffer *eb,
> u64 inode_objectid, u64 parent_objectid,
> u64 ref_index, char *name, int namelen,
> int *search_done)
> @@ -1310,7 +1309,7 @@ static noinline int add_inode_ref(struct 
> btrfs_trans_handle *trans,
>   if (!search_done) {
>   ret = __add_inode_ref(trans, root, path, log,
> BTRFS_I(dir),
> -   BTRFS_I(inode), eb,
> +   BTRFS_I(inode),
> inode_objectid,
> parent_objectid,
> ref_index, name, namelen,
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/8] btrfs: free-space-cache, clean up unnecessary root arguments

2017-02-15 Thread Jeff Mahoney
On 2/15/17 4:28 PM, je...@suse.com wrote:
> From: Jeff Mahoney 
> 
> The free space cache APIs accept a root but always use the tree root.
> 
> Also, btrfs_truncate_free_space_cache accepts a root AND an inode but
> the inode always points to the root anyway, so let's just pass the inode.

This one has minor conflicts with Dave's patchset that removes path and
objectid.

-Jeff

> Signed-off-by: Jeff Mahoney 
> ---
>  fs/btrfs/extent-tree.c  |  9 +
>  fs/btrfs/free-space-cache.c | 25 +++--
>  fs/btrfs/free-space-cache.h |  7 +++
>  fs/btrfs/inode-map.c|  2 +-
>  fs/btrfs/relocation.c   |  5 ++---
>  5 files changed, 22 insertions(+), 26 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 20bedc7..a557249 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -3372,7 +3372,7 @@ static int cache_save_setup(struct 
> btrfs_block_group_cache *block_group,
>   if (trans->aborted)
>   return 0;
>  again:
> - inode = lookup_free_space_inode(root, block_group, path);
> + inode = lookup_free_space_inode(fs_info, block_group, path);
>   if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) {
>   ret = PTR_ERR(inode);
>   btrfs_release_path(path);
> @@ -3386,7 +3386,8 @@ static int cache_save_setup(struct 
> btrfs_block_group_cache *block_group,
>   if (block_group->ro)
>   goto out_free;
>  
> - ret = create_free_space_inode(root, trans, block_group, path);
> + ret = create_free_space_inode(fs_info, trans, block_group,
> +   path);
>   if (ret)
>   goto out_free;
>   goto again;
> @@ -3428,7 +3429,7 @@ static int cache_save_setup(struct 
> btrfs_block_group_cache *block_group,
>   if (ret)
>   goto out_put;
>  
> - ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode);
> + ret = btrfs_truncate_free_space_cache(trans, NULL, inode);
>   if (ret)
>   goto out_put;
>   }
> @@ -10319,7 +10320,7 @@ int btrfs_remove_block_group(struct 
> btrfs_trans_handle *trans,
>* get the inode first so any iput calls done for the io_list
>* aren't the final iput (no unlinks allowed now)
>*/
> - inode = lookup_free_space_inode(tree_root, block_group, path);
> + inode = lookup_free_space_inode(fs_info, block_group, path);
>  
>   mutex_lock(>transaction->cache_write_mutex);
>   /*
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 7015892..61a72fb 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -94,12 +94,11 @@ static struct inode *__lookup_free_space_inode(struct 
> btrfs_root *root,
>   return inode;
>  }
>  
> -struct inode *lookup_free_space_inode(struct btrfs_root *root,
> +struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info,
> struct btrfs_block_group_cache
> *block_group, struct btrfs_path *path)
>  {
>   struct inode *inode = NULL;
> - struct btrfs_fs_info *fs_info = root->fs_info;
>   u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW;
>  
>   spin_lock(_group->lock);
> @@ -109,7 +108,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root 
> *root,
>   if (inode)
>   return inode;
>  
> - inode = __lookup_free_space_inode(root, path,
> + inode = __lookup_free_space_inode(fs_info->tree_root, path,
> block_group->key.objectid);
>   if (IS_ERR(inode))
>   return inode;
> @@ -192,7 +191,7 @@ static int __create_free_space_inode(struct btrfs_root 
> *root,
>   return 0;
>  }
>  
> -int create_free_space_inode(struct btrfs_root *root,
> +int create_free_space_inode(struct btrfs_fs_info *fs_info,
>   struct btrfs_trans_handle *trans,
>   struct btrfs_block_group_cache *block_group,
>   struct btrfs_path *path)
> @@ -200,11 +199,11 @@ int create_free_space_inode(struct btrfs_root *root,
>   int ret;
>   u64 ino;
>  
> - ret = btrfs_find_free_objectid(root, );
> + ret = btrfs_find_free_objectid(fs_info->tree_root, );
>   if (ret < 0)
>   return ret;
>  
> - return __create_free_space_inode(root, trans, path, ino,
> + return __create_free_space_inode(fs_info->tree_root, trans, path, ino,
>block_group->key.objectid);
>  }
>  
> @@ -227,11 +226,11 @@ int btrfs_check_trunc_cache_free_space(struct 
> btrfs_fs_info *fs_info,
>   return ret;
>  }
>  
> -int btrfs_truncate_free_space_cache(struct btrfs_root *root,
> - struct 

Re: [PATCH 5/8] btrfs: btrfs_wait_cache_io_root doesn't use path argument

2017-02-15 Thread Jeff Mahoney
On 2/15/17 4:28 PM, je...@suse.com wrote:
> From: Jeff Mahoney 
> 
> Signed-off-by: Jeff Mahoney 

This one is obsoleted by Dave's patch:
[PATCH 28/29] btrfs: remove unused parameters from __btrfs_write_out_cache

-Jeff


> ---
>  fs/btrfs/free-space-cache.c | 11 +++
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 61a72fb..a1e15f6 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -42,10 +42,6 @@ static int link_free_space(struct btrfs_free_space_ctl 
> *ctl,
>  struct btrfs_free_space *info);
>  static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
> struct btrfs_free_space *info);
> -static int btrfs_wait_cache_io_root(struct btrfs_root *root,
> -  struct btrfs_trans_handle *trans,
> -  struct btrfs_io_ctl *io_ctl,
> -  struct btrfs_path *path);
>  
>  static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
>  struct btrfs_path *path,
> @@ -1234,8 +1230,7 @@ static int __btrfs_write_out_cache(struct btrfs_root 
> *root, struct inode *inode,
>  struct btrfs_free_space_ctl *ctl,
>  struct btrfs_block_group_cache *block_group,
>  struct btrfs_io_ctl *io_ctl,
> -struct btrfs_trans_handle *trans,
> -struct btrfs_path *path, u64 offset)
> +struct btrfs_trans_handle *trans, u64 offset)
>  {
>   struct btrfs_fs_info *fs_info = root->fs_info;
>   struct extent_state *cached_state = NULL;
> @@ -1393,7 +1388,7 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
>  
>   ret = __btrfs_write_out_cache(fs_info->tree_root, inode, ctl,
> block_group, _group->io_ctl, trans,
> -   path, block_group->key.objectid);
> +   block_group->key.objectid);
>   if (ret) {
>  #ifdef DEBUG
>   btrfs_err(fs_info,
> @@ -3541,7 +3536,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
>  
>   memset(_ctl, 0, sizeof(io_ctl));
>   ret = __btrfs_write_out_cache(root, inode, ctl, NULL, _ctl,
> -   trans, path, 0);
> +   trans, 0);
>   if (!ret) {
>   /*
>* At this point writepages() didn't error out, so our metadata
> 


-- 
Jeff Mahoney
SUSE Labs



signature.asc
Description: OpenPGP digital signature


Re: [PATCH v2] Btrfs: fix btrfs_decompress_buf2page()

2017-02-15 Thread Omar Sandoval
On Wed, Feb 15, 2017 at 11:32:06AM +0800, Anand Jain wrote:
>  Thanks Omar for nailing this down. How about a test case for this ?

Yeah, I'll put together a test case using your new compressible data
helper, thanks for adding that.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 27/29] btrfs: remove unused parameter from cleanup_write_cache_enospc

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:44AM +0100, David Sterba wrote:
> bitmap_list is unused since the io_ctl framework.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/free-space-cache.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 437580e84d9d..0d02599d22bc 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -1128,8 +1128,7 @@ cleanup_bitmap_list(struct list_head *bitmap_list)
>  static void noinline_for_stack
>  cleanup_write_cache_enospc(struct inode *inode,
>  struct btrfs_io_ctl *io_ctl,
> -struct extent_state **cached_state,
> -struct list_head *bitmap_list)
> +struct extent_state **cached_state)
>  {
>   io_ctl_drop_pages(io_ctl);
>   unlock_extent_cached(_I(inode)->io_tree, 0,
> @@ -1365,7 +1364,7 @@ static int __btrfs_write_out_cache(struct btrfs_root 
> *root, struct inode *inode,
>   mutex_unlock(>cache_writeout_mutex);
>  
>  out_nospc:
> - cleanup_write_cache_enospc(inode, io_ctl, _state, _list);
> + cleanup_write_cache_enospc(inode, io_ctl, _state);
>  
>   if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA))
>   up_write(_group->data_rwsem);
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 23/29] btrfs: remove unused parameter from __add_inline_refs

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:31AM +0100, David Sterba wrote:
> Never used.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/backref.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
> index db706595e631..7699e16784d3 100644
> --- a/fs/btrfs/backref.c
> +++ b/fs/btrfs/backref.c
> @@ -956,8 +956,7 @@ static int __add_delayed_refs(struct 
> btrfs_delayed_ref_head *head, u64 seq,
>  /*
>   * add all inline backrefs for bytenr to the list
>   */
> -static int __add_inline_refs(struct btrfs_fs_info *fs_info,
> -  struct btrfs_path *path, u64 bytenr,
> +static int __add_inline_refs(struct btrfs_path *path, u64 bytenr,
>int *info_level, struct list_head *prefs,
>struct ref_root *ref_tree,
>u64 *total_refs, u64 inum)
> @@ -1354,7 +1353,7 @@ static int find_parent_nodes(struct btrfs_trans_handle 
> *trans,
>   if (key.objectid == bytenr &&
>   (key.type == BTRFS_EXTENT_ITEM_KEY ||
>key.type == BTRFS_METADATA_ITEM_KEY)) {
> - ret = __add_inline_refs(fs_info, path, bytenr,
> + ret = __add_inline_refs(path, bytenr,
>   _level, ,
>   ref_tree, _refs,
>   inum);
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/29] btrfs: remove unused parameter from init_first_rw_device

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:22AM +0100, David Sterba wrote:
> The 'device' used to be added in that function, but now it's done by the
> caller.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/volumes.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index d234625e4e02..1fac98728814 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -134,8 +134,7 @@ const int btrfs_raid_mindev_error[BTRFS_NR_RAID_TYPES] = {
>  };
>  
>  static int init_first_rw_device(struct btrfs_trans_handle *trans,
> - struct btrfs_fs_info *fs_info,
> - struct btrfs_device *device);
> + struct btrfs_fs_info *fs_info);
>  static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info);
>  static void __btrfs_reset_dev_stats(struct btrfs_device *dev);
>  static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev);
> @@ -2440,7 +2439,7 @@ int btrfs_init_new_device(struct btrfs_fs_info 
> *fs_info, char *device_path)
>  
>   if (seeding_dev) {
>   mutex_lock(_info->chunk_mutex);
> - ret = init_first_rw_device(trans, fs_info, device);
> + ret = init_first_rw_device(trans, fs_info);
>   mutex_unlock(_info->chunk_mutex);
>   if (ret) {
>   btrfs_abort_transaction(trans, ret);
> @@ -5012,8 +5011,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
>  }
>  
>  static noinline int init_first_rw_device(struct btrfs_trans_handle *trans,
> -  struct btrfs_fs_info *fs_info,
> -  struct btrfs_device *device)
> +  struct btrfs_fs_info *fs_info)
>  {
>   struct btrfs_root *extent_root = fs_info->extent_root;
>   u64 chunk_offset;
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 22/29] btrfs: remove unused parameters from scrub_setup_wr_ctx

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:29AM +0100, David Sterba wrote:
> Never used.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/scrub.c | 10 +++---
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 9a94670536a6..f7dffacf61fa 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -282,9 +282,7 @@ static void scrub_remap_extent(struct btrfs_fs_info 
> *fs_info,
>  u64 *extent_physical,
>  struct btrfs_device **extent_dev,
>  int *extent_mirror_num);
> -static int scrub_setup_wr_ctx(struct scrub_ctx *sctx,
> -   struct scrub_wr_ctx *wr_ctx,
> -   struct btrfs_fs_info *fs_info,
> +static int scrub_setup_wr_ctx(struct scrub_wr_ctx *wr_ctx,
> struct btrfs_device *dev,
> int is_dev_replace);
>  static void scrub_free_wr_ctx(struct scrub_wr_ctx *wr_ctx);
> @@ -501,7 +499,7 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device 
> *dev, int is_dev_replace)
>   spin_lock_init(>stat_lock);
>   init_waitqueue_head(>list_wait);
>  
> - ret = scrub_setup_wr_ctx(sctx, >wr_ctx, fs_info,
> + ret = scrub_setup_wr_ctx(>wr_ctx,
>fs_info->dev_replace.tgtdev, is_dev_replace);
>   if (ret) {
>   scrub_free_ctx(sctx);
> @@ -4084,9 +4082,7 @@ static void scrub_remap_extent(struct btrfs_fs_info 
> *fs_info,
>   btrfs_put_bbio(bbio);
>  }
>  
> -static int scrub_setup_wr_ctx(struct scrub_ctx *sctx,
> -   struct scrub_wr_ctx *wr_ctx,
> -   struct btrfs_fs_info *fs_info,
> +static int scrub_setup_wr_ctx(struct scrub_wr_ctx *wr_ctx,
> struct btrfs_device *dev,
> int is_dev_replace)
>  {
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 19/29] btrfs: remove unused parameter from __btrfs_alloc_chunk

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:19AM +0100, David Sterba wrote:
> We grab fs_info from other parameters.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/volumes.c | 10 --
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 3c3c69c0eee4..d234625e4e02 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -4584,8 +4584,7 @@ static void check_raid56_incompat_flag(struct 
> btrfs_fs_info *info, u64 type)
>   / sizeof(struct btrfs_stripe) + 1)
>  
>  static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
> -struct btrfs_fs_info *fs_info, u64 start,
> -u64 type)
> +u64 start, u64 type)
>  {
>   struct btrfs_fs_info *info = trans->fs_info;
>   struct btrfs_fs_devices *fs_devices = info->fs_devices;
> @@ -5009,7 +5008,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
>  
>   ASSERT(mutex_is_locked(_info->chunk_mutex));
>   chunk_offset = find_next_chunk(fs_info);
> - return __btrfs_alloc_chunk(trans, fs_info, chunk_offset, type);
> + return __btrfs_alloc_chunk(trans, chunk_offset, type);
>  }
>  
>  static noinline int init_first_rw_device(struct btrfs_trans_handle *trans,
> @@ -5024,14 +5023,13 @@ static noinline int init_first_rw_device(struct 
> btrfs_trans_handle *trans,
>  
>   chunk_offset = find_next_chunk(fs_info);
>   alloc_profile = btrfs_get_alloc_profile(extent_root, 0);
> - ret = __btrfs_alloc_chunk(trans, fs_info, chunk_offset, alloc_profile);
> + ret = __btrfs_alloc_chunk(trans, chunk_offset, alloc_profile);
>   if (ret)
>   return ret;
>  
>   sys_chunk_offset = find_next_chunk(fs_info);
>   alloc_profile = btrfs_get_alloc_profile(fs_info->chunk_root, 0);
> - ret = __btrfs_alloc_chunk(trans, fs_info, sys_chunk_offset,
> -   alloc_profile);
> + ret = __btrfs_alloc_chunk(trans, sys_chunk_offset, alloc_profile);
>   return ret;
>  }
>  
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 18/29] btrfs: remove unused parameter from btrfs_fill_super

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:16AM +0100, David Sterba wrote:
> Never used for anything meaningful since we have our own superblock
> filler.
> 
Looks good.

Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/super.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 93ed29c2a38b..da687dc79cce 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -1114,7 +1114,7 @@ static int get_default_subvol_objectid(struct 
> btrfs_fs_info *fs_info, u64 *objec
>  
>  static int btrfs_fill_super(struct super_block *sb,
>   struct btrfs_fs_devices *fs_devices,
> - void *data, int silent)
> + void *data)
>  {
>   struct inode *inode;
>   struct btrfs_fs_info *fs_info = btrfs_sb(sb);
> @@ -1611,8 +1611,7 @@ static struct dentry *btrfs_mount(struct 
> file_system_type *fs_type, int flags,
>   } else {
>   snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev);
>   btrfs_sb(s)->bdev_holder = fs_type;
> - error = btrfs_fill_super(s, fs_devices, data,
> -  flags & MS_SILENT ? 1 : 0);
> + error = btrfs_fill_super(s, fs_devices, data);
>   }
>   if (error) {
>   deactivate_locked_super(s);
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/8] btrfs: convert btrfs_inc_block_group_ro to accept fs_info

2017-02-15 Thread jeffm
From: Jeff Mahoney 

btrfs_inc_block_group_ro is either passed the extent root or the dev
root, but it doesn't do anything with the dev tree.  Let's convert
to passing an fs_info and using the extent root.

Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/ctree.h   | 2 +-
 fs/btrfs/extent-tree.c | 5 ++---
 fs/btrfs/relocation.c  | 2 +-
 fs/btrfs/scrub.c   | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 6a82371..49f520c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2724,7 +2724,7 @@ int btrfs_cond_migrate_bytes(struct btrfs_fs_info 
*fs_info,
 void btrfs_block_rsv_release(struct btrfs_fs_info *fs_info,
 struct btrfs_block_rsv *block_rsv,
 u64 num_bytes);
-int btrfs_inc_block_group_ro(struct btrfs_root *root,
+int btrfs_inc_block_group_ro(struct btrfs_fs_info *fs_info,
 struct btrfs_block_group_cache *cache);
 void btrfs_dec_block_group_ro(struct btrfs_block_group_cache *cache);
 void btrfs_put_block_group_cache(struct btrfs_fs_info *info);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index b005378..20bedc7 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -9363,17 +9363,16 @@ static int inc_block_group_ro(struct 
btrfs_block_group_cache *cache, int force)
return ret;
 }
 
-int btrfs_inc_block_group_ro(struct btrfs_root *root,
+int btrfs_inc_block_group_ro(struct btrfs_fs_info *fs_info,
 struct btrfs_block_group_cache *cache)
 
 {
-   struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_trans_handle *trans;
u64 alloc_flags;
int ret;
 
 again:
-   trans = btrfs_join_transaction(root);
+   trans = btrfs_join_transaction(fs_info->extent_root);
if (IS_ERR(trans))
return PTR_ERR(trans);
 
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 3797110..2e9deb9 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4334,7 +4334,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info 
*fs_info, u64 group_start)
rc->block_group = btrfs_lookup_block_group(fs_info, group_start);
BUG_ON(!rc->block_group);
 
-   ret = btrfs_inc_block_group_ro(extent_root, rc->block_group);
+   ret = btrfs_inc_block_group_ro(fs_info, rc->block_group);
if (ret) {
err = ret;
goto out;
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 9a94670..3a9607dc 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3584,7 +3584,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 * -> btrfs_scrub_pause()
 */
scrub_pause_on(fs_info);
-   ret = btrfs_inc_block_group_ro(root, cache);
+   ret = btrfs_inc_block_group_ro(fs_info, cache);
if (!ret && is_dev_replace) {
/*
 * If we are doing a device replace wait for any tasks
-- 
2.7.1

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


[PATCH 0/8] btrfs: cleanup patches

2017-02-15 Thread jeffm
From: Jeff Mahoney 

Hi all -

Here's another around of cleanup patches.  The first 7 cleanup API
blemishes with unused arguments and/or root -> fs_info conversion.  The
last converts the pr_debug in btrfs_abort_transaction to use btrfs_debug.

-Jeff

Jeff Mahoney (8):
  btrfs: pass fs_info to (more) routines that are only called with
extent_root
  btrfs: flush_space always takes fs_info->fs_root
  btrfs: convert btrfs_inc_block_group_ro to accept fs_info
  btrfs: free-space-cache, clean up unnecessary root arguments
  btrfs: btrfs_wait_cache_io_root doesn't use path argument
  btrfs: btrfs_truncate_free_space_cache always allocates path
  btrfs: drop unused extent_op arg from btrfs_add_delayed_data_ref
  btrfs: use btrfs_debug instead of pr_debug in transaction abort

 fs/btrfs/ctree.h|   5 +-
 fs/btrfs/delayed-ref.c  |   6 +-
 fs/btrfs/delayed-ref.h  |   3 +-
 fs/btrfs/extent-tree.c  | 144 ++--
 fs/btrfs/free-space-cache.c |  49 ++-
 fs/btrfs/free-space-cache.h |   7 +--
 fs/btrfs/inode-map.c|   2 +-
 fs/btrfs/relocation.c   |   7 +--
 fs/btrfs/scrub.c|   2 +-
 9 files changed, 107 insertions(+), 118 deletions(-)

-- 
2.7.1

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


[PATCH 1/8] btrfs: pass fs_info to (more) routines that are only called with extent_root

2017-02-15 Thread jeffm
From: Jeff Mahoney 

Outside of interactions with qgroups, the roots passed in extent-tree.c
are usually passed to ensure that we don't do refcounts on log trees or
to get the allocation profile for an allocation request.  Otherwise, it
operates on the extent root.  This patch converts some more routines in
extent-tree.c that are always called with the extent root to accept
an fs_info instead.

Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/extent-tree.c | 103 +
 1 file changed, 53 insertions(+), 50 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index dcd2e79..d4c0f8a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1035,10 +1035,11 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle 
*trans,
 
 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
 static int convert_extent_item_v0(struct btrfs_trans_handle *trans,
- struct btrfs_root *root,
+ struct btrfs_fs_info *fs_info,
  struct btrfs_path *path,
  u64 owner, u32 extra_size)
 {
+   struct btrfs_root *root = fs_info->extent_root;
struct btrfs_extent_item *item;
struct btrfs_extent_item_v0 *ei0;
struct btrfs_extent_ref_v0 *ref0;
@@ -1092,7 +1093,7 @@ static int convert_extent_item_v0(struct 
btrfs_trans_handle *trans,
return ret;
BUG_ON(ret); /* Corruption */
 
-   btrfs_extend_item(root->fs_info, path, new_size);
+   btrfs_extend_item(fs_info, path, new_size);
 
leaf = path->nodes[0];
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
@@ -1151,12 +1152,13 @@ static int match_extent_data_ref(struct extent_buffer 
*leaf,
 }
 
 static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
-  struct btrfs_root *root,
+  struct btrfs_fs_info *fs_info,
   struct btrfs_path *path,
   u64 bytenr, u64 parent,
   u64 root_objectid,
   u64 owner, u64 offset)
 {
+   struct btrfs_root *root = fs_info->extent_root;
struct btrfs_key key;
struct btrfs_extent_data_ref *ref;
struct extent_buffer *leaf;
@@ -1238,12 +1240,13 @@ static noinline int lookup_extent_data_ref(struct 
btrfs_trans_handle *trans,
 }
 
 static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
-  struct btrfs_root *root,
+  struct btrfs_fs_info *fs_info,
   struct btrfs_path *path,
   u64 bytenr, u64 parent,
   u64 root_objectid, u64 owner,
   u64 offset, int refs_to_add)
 {
+   struct btrfs_root *root = fs_info->extent_root;
struct btrfs_key key;
struct extent_buffer *leaf;
u32 size;
@@ -1317,7 +1320,7 @@ static noinline int insert_extent_data_ref(struct 
btrfs_trans_handle *trans,
 }
 
 static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans,
-  struct btrfs_root *root,
+  struct btrfs_fs_info *fs_info,
   struct btrfs_path *path,
   int refs_to_drop, int *last_ref)
 {
@@ -1354,7 +1357,7 @@ static noinline int remove_extent_data_ref(struct 
btrfs_trans_handle *trans,
num_refs -= refs_to_drop;
 
if (num_refs == 0) {
-   ret = btrfs_del_item(trans, root, path);
+   ret = btrfs_del_item(trans, fs_info->extent_root, path);
*last_ref = 1;
} else {
if (key.type == BTRFS_EXTENT_DATA_REF_KEY)
@@ -1416,11 +1419,12 @@ static noinline u32 extent_data_ref_count(struct 
btrfs_path *path,
 }
 
 static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans,
- struct btrfs_root *root,
+ struct btrfs_fs_info *fs_info,
  struct btrfs_path *path,
  u64 bytenr, u64 parent,
  u64 root_objectid)
 {
+   struct btrfs_root *root = fs_info->extent_root;
struct btrfs_key key;
int ret;
 
@@ -1449,7 +1453,7 @@ static noinline int lookup_tree_block_ref(struct 
btrfs_trans_handle *trans,
 }
 
 static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans,
- struct btrfs_root *root,
+ 

[PATCH 7/8] btrfs: drop unused extent_op arg from btrfs_add_delayed_data_ref

2017-02-15 Thread jeffm
From: Jeff Mahoney 

btrfs_add_delayed_data_ref is always called with a NULL extent_op,
so let's drop the argument.

Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/delayed-ref.c | 6 ++
 fs/btrfs/delayed-ref.h | 3 +--
 fs/btrfs/extent-tree.c | 7 +++
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index ef724a5..c66f487 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -829,15 +829,13 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info 
*fs_info,
   struct btrfs_trans_handle *trans,
   u64 bytenr, u64 num_bytes,
   u64 parent, u64 ref_root,
-  u64 owner, u64 offset, u64 reserved, int action,
-  struct btrfs_delayed_extent_op *extent_op)
+  u64 owner, u64 offset, u64 reserved, int action)
 {
struct btrfs_delayed_data_ref *ref;
struct btrfs_delayed_ref_head *head_ref;
struct btrfs_delayed_ref_root *delayed_refs;
struct btrfs_qgroup_extent_record *record = NULL;
 
-   BUG_ON(extent_op && !extent_op->is_data);
ref = kmem_cache_alloc(btrfs_delayed_data_ref_cachep, GFP_NOFS);
if (!ref)
return -ENOMEM;
@@ -859,7 +857,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info 
*fs_info,
}
}
 
-   head_ref->extent_op = extent_op;
+   head_ref->extent_op = NULL;
 
delayed_refs = >transaction->delayed_refs;
spin_lock(_refs->lock);
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index 50947b5..8a0220f 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -250,8 +250,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info 
*fs_info,
   struct btrfs_trans_handle *trans,
   u64 bytenr, u64 num_bytes,
   u64 parent, u64 ref_root,
-  u64 owner, u64 offset, u64 reserved, int action,
-  struct btrfs_delayed_extent_op *extent_op);
+  u64 owner, u64 offset, u64 reserved, int action);
 int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes,
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index a557249..65507ec 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2095,7 +2095,7 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr,
num_bytes, parent, root_objectid,
owner, offset, 0,
-   BTRFS_ADD_DELAYED_REF, NULL);
+   BTRFS_ADD_DELAYED_REF);
}
return ret;
 }
@@ -7249,7 +7249,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
num_bytes,
parent, root_objectid, owner,
offset, 0,
-   BTRFS_DROP_DELAYED_REF, NULL);
+   BTRFS_DROP_DELAYED_REF);
}
return ret;
 }
@@ -8198,8 +8198,7 @@ int btrfs_alloc_reserved_file_extent(struct 
btrfs_trans_handle *trans,
ret = btrfs_add_delayed_data_ref(fs_info, trans, ins->objectid,
 ins->offset, 0,
 root_objectid, owner, offset,
-ram_bytes, BTRFS_ADD_DELAYED_EXTENT,
-NULL);
+ram_bytes, BTRFS_ADD_DELAYED_EXTENT); 
return ret;
 }
 
-- 
2.7.1

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


[PATCH 5/8] btrfs: btrfs_wait_cache_io_root doesn't use path argument

2017-02-15 Thread jeffm
From: Jeff Mahoney 

Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/free-space-cache.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 61a72fb..a1e15f6 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -42,10 +42,6 @@ static int link_free_space(struct btrfs_free_space_ctl *ctl,
   struct btrfs_free_space *info);
 static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
  struct btrfs_free_space *info);
-static int btrfs_wait_cache_io_root(struct btrfs_root *root,
-struct btrfs_trans_handle *trans,
-struct btrfs_io_ctl *io_ctl,
-struct btrfs_path *path);
 
 static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
   struct btrfs_path *path,
@@ -1234,8 +1230,7 @@ static int __btrfs_write_out_cache(struct btrfs_root 
*root, struct inode *inode,
   struct btrfs_free_space_ctl *ctl,
   struct btrfs_block_group_cache *block_group,
   struct btrfs_io_ctl *io_ctl,
-  struct btrfs_trans_handle *trans,
-  struct btrfs_path *path, u64 offset)
+  struct btrfs_trans_handle *trans, u64 offset)
 {
struct btrfs_fs_info *fs_info = root->fs_info;
struct extent_state *cached_state = NULL;
@@ -1393,7 +1388,7 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
 
ret = __btrfs_write_out_cache(fs_info->tree_root, inode, ctl,
  block_group, _group->io_ctl, trans,
- path, block_group->key.objectid);
+ block_group->key.objectid);
if (ret) {
 #ifdef DEBUG
btrfs_err(fs_info,
@@ -3541,7 +3536,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
 
memset(_ctl, 0, sizeof(io_ctl));
ret = __btrfs_write_out_cache(root, inode, ctl, NULL, _ctl,
- trans, path, 0);
+ trans, 0);
if (!ret) {
/*
 * At this point writepages() didn't error out, so our metadata
-- 
2.7.1

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


[PATCH 6/8] btrfs: btrfs_truncate_free_space_cache always allocates path

2017-02-15 Thread jeffm
From: Jeff Mahoney 

btrfs_truncate_free_space_cache always allocates a btrfs_path structure
but only uses it when the caller passes a block group.  Let's move the
allocation and free into the conditional.

Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/free-space-cache.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index a1e15f6..5240163 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -228,15 +228,14 @@ int btrfs_truncate_free_space_cache(struct 
btrfs_trans_handle *trans,
 {
struct btrfs_root *root = BTRFS_I(inode)->root;
int ret = 0;
-   struct btrfs_path *path = btrfs_alloc_path();
bool locked = false;
 
-   if (!path) {
-   ret = -ENOMEM;
-   goto fail;
-   }
-
if (block_group) {
+   struct btrfs_path *path = btrfs_alloc_path();
+   if (!path) {
+   ret = -ENOMEM;
+   goto fail;
+   }
locked = true;
mutex_lock(>transaction->cache_write_mutex);
if (!list_empty(_group->io_list)) {
@@ -253,8 +252,8 @@ int btrfs_truncate_free_space_cache(struct 
btrfs_trans_handle *trans,
spin_lock(_group->lock);
block_group->disk_cache_state = BTRFS_DC_CLEAR;
spin_unlock(_group->lock);
+   btrfs_free_path(path);
}
-   btrfs_free_path(path);
 
btrfs_i_size_write(inode, 0);
truncate_pagecache(inode, 0);
-- 
2.7.1

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


[PATCH 8/8] btrfs: use btrfs_debug instead of pr_debug in transaction abort

2017-02-15 Thread jeffm
From: Jeff Mahoney 

Commit e5d6b12fe14 (Btrfs: don't WARN() in btrfs_transaction_abort() for
IO errors) added a pr_debug call to be printed when a transaction is
aborted with -EIO instead of WARN.  btrfs_debug prints which file system
the message is associated with so let's use that instead.

Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/ctree.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 49f520c..0b92432 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3447,7 +3447,8 @@ do {  
\
"BTRFS: Transaction aborted (error %d)\n",  \
(errno));   \
} else {\
-   pr_debug("BTRFS: Transaction aborted (error %d)\n", \
+   btrfs_debug((trans)->fs_info,   \
+   "Transaction aborted (error %d)\n", \
  (errno)); \
}   \
}   \
-- 
2.7.1

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


[PATCH 4/8] btrfs: free-space-cache, clean up unnecessary root arguments

2017-02-15 Thread jeffm
From: Jeff Mahoney 

The free space cache APIs accept a root but always use the tree root.

Also, btrfs_truncate_free_space_cache accepts a root AND an inode but
the inode always points to the root anyway, so let's just pass the inode.

Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/extent-tree.c  |  9 +
 fs/btrfs/free-space-cache.c | 25 +++--
 fs/btrfs/free-space-cache.h |  7 +++
 fs/btrfs/inode-map.c|  2 +-
 fs/btrfs/relocation.c   |  5 ++---
 5 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 20bedc7..a557249 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3372,7 +3372,7 @@ static int cache_save_setup(struct 
btrfs_block_group_cache *block_group,
if (trans->aborted)
return 0;
 again:
-   inode = lookup_free_space_inode(root, block_group, path);
+   inode = lookup_free_space_inode(fs_info, block_group, path);
if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) {
ret = PTR_ERR(inode);
btrfs_release_path(path);
@@ -3386,7 +3386,8 @@ static int cache_save_setup(struct 
btrfs_block_group_cache *block_group,
if (block_group->ro)
goto out_free;
 
-   ret = create_free_space_inode(root, trans, block_group, path);
+   ret = create_free_space_inode(fs_info, trans, block_group,
+ path);
if (ret)
goto out_free;
goto again;
@@ -3428,7 +3429,7 @@ static int cache_save_setup(struct 
btrfs_block_group_cache *block_group,
if (ret)
goto out_put;
 
-   ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode);
+   ret = btrfs_truncate_free_space_cache(trans, NULL, inode);
if (ret)
goto out_put;
}
@@ -10319,7 +10320,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle 
*trans,
 * get the inode first so any iput calls done for the io_list
 * aren't the final iput (no unlinks allowed now)
 */
-   inode = lookup_free_space_inode(tree_root, block_group, path);
+   inode = lookup_free_space_inode(fs_info, block_group, path);
 
mutex_lock(>transaction->cache_write_mutex);
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 7015892..61a72fb 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -94,12 +94,11 @@ static struct inode *__lookup_free_space_inode(struct 
btrfs_root *root,
return inode;
 }
 
-struct inode *lookup_free_space_inode(struct btrfs_root *root,
+struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info,
  struct btrfs_block_group_cache
  *block_group, struct btrfs_path *path)
 {
struct inode *inode = NULL;
-   struct btrfs_fs_info *fs_info = root->fs_info;
u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW;
 
spin_lock(_group->lock);
@@ -109,7 +108,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root 
*root,
if (inode)
return inode;
 
-   inode = __lookup_free_space_inode(root, path,
+   inode = __lookup_free_space_inode(fs_info->tree_root, path,
  block_group->key.objectid);
if (IS_ERR(inode))
return inode;
@@ -192,7 +191,7 @@ static int __create_free_space_inode(struct btrfs_root 
*root,
return 0;
 }
 
-int create_free_space_inode(struct btrfs_root *root,
+int create_free_space_inode(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group,
struct btrfs_path *path)
@@ -200,11 +199,11 @@ int create_free_space_inode(struct btrfs_root *root,
int ret;
u64 ino;
 
-   ret = btrfs_find_free_objectid(root, );
+   ret = btrfs_find_free_objectid(fs_info->tree_root, );
if (ret < 0)
return ret;
 
-   return __create_free_space_inode(root, trans, path, ino,
+   return __create_free_space_inode(fs_info->tree_root, trans, path, ino,
 block_group->key.objectid);
 }
 
@@ -227,11 +226,11 @@ int btrfs_check_trunc_cache_free_space(struct 
btrfs_fs_info *fs_info,
return ret;
 }
 
-int btrfs_truncate_free_space_cache(struct btrfs_root *root,
-   struct btrfs_trans_handle *trans,
+int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group,
struct inode *inode)
 {
+   struct btrfs_root *root = 

[PATCH 2/8] btrfs: flush_space always takes fs_info->fs_root

2017-02-15 Thread jeffm
From: Jeff Mahoney 

We don't need to pass a root to flush_space since it always uses
the fs_root.

Signed-off-by: Jeff Mahoney 
---
 fs/btrfs/extent-tree.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d4c0f8a..b005378 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4791,11 +4791,10 @@ static void shrink_delalloc(struct btrfs_root *root, 
u64 to_reclaim, u64 orig,
  * get us somewhere and then commit the transaction if it does.  Otherwise it
  * will return -ENOSPC.
  */
-static int may_commit_transaction(struct btrfs_root *root,
+static int may_commit_transaction(struct btrfs_fs_info *fs_info,
  struct btrfs_space_info *space_info,
  u64 bytes, int force)
 {
-   struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_block_rsv *delayed_rsv = _info->delayed_block_rsv;
struct btrfs_trans_handle *trans;
 
@@ -4827,7 +4826,7 @@ static int may_commit_transaction(struct btrfs_root *root,
spin_unlock(_rsv->lock);
 
 commit:
-   trans = btrfs_join_transaction(root);
+   trans = btrfs_join_transaction(fs_info->fs_root);
if (IS_ERR(trans))
return -ENOSPC;
 
@@ -4841,11 +4840,11 @@ struct reserve_ticket {
wait_queue_head_t wait;
 };
 
-static int flush_space(struct btrfs_root *root,
+static int flush_space(struct btrfs_fs_info *fs_info,
   struct btrfs_space_info *space_info, u64 num_bytes,
   u64 orig_bytes, int state)
 {
-   struct btrfs_fs_info *fs_info = root->fs_info;
+   struct btrfs_root *root = fs_info->fs_root;
struct btrfs_trans_handle *trans;
int nr;
int ret = 0;
@@ -4885,7 +4884,8 @@ static int flush_space(struct btrfs_root *root,
ret = 0;
break;
case COMMIT_TRANS:
-   ret = may_commit_transaction(root, space_info, orig_bytes, 0);
+   ret = may_commit_transaction(fs_info, space_info,
+orig_bytes, 0);
break;
default:
ret = -ENOSPC;
@@ -4997,8 +4997,8 @@ static void btrfs_async_reclaim_metadata_space(struct 
work_struct *work)
struct reserve_ticket *ticket;
int ret;
 
-   ret = flush_space(fs_info->fs_root, space_info, to_reclaim,
-   to_reclaim, flush_state);
+   ret = flush_space(fs_info, space_info, to_reclaim, to_reclaim,
+ flush_state);
spin_lock(_info->lock);
if (list_empty(_info->tickets)) {
space_info->flush = 0;
@@ -5053,8 +5053,8 @@ static void priority_reclaim_metadata_space(struct 
btrfs_fs_info *fs_info,
spin_unlock(_info->lock);
 
do {
-   flush_space(fs_info->fs_root, space_info, to_reclaim,
-   to_reclaim, flush_state);
+   flush_space(fs_info, space_info, to_reclaim, to_reclaim,
+   flush_state);
flush_state++;
spin_lock(_info->lock);
if (ticket->bytes == 0) {
-- 
2.7.1

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


Re: [PATCH 16/29] btrfs: remove unused parameter from add_pending_csums

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:10AM +0100, David Sterba wrote:
> Never used.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/inode.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 7ed693294498..3ac7474f921d 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -1961,8 +1961,7 @@ static int btrfs_submit_bio_hook(struct inode *inode, 
> struct bio *bio,
>   * at IO completion time based on sums calculated at bio submission time.
>   */
>  static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
> -  struct inode *inode, u64 file_offset,
> -  struct list_head *list)
> +  struct inode *inode, struct list_head *list)
>  {
>   struct btrfs_ordered_sum *sum;
>  
> @@ -2956,8 +2955,7 @@ static int btrfs_finish_ordered_io(struct 
> btrfs_ordered_extent *ordered_extent)
>   goto out_unlock;
>   }
>  
> - add_pending_csums(trans, inode, ordered_extent->file_offset,
> -   _extent->list);
> + add_pending_csums(trans, inode, _extent->list);
>  
>   btrfs_ordered_update_i_size(inode, 0, ordered_extent);
>   ret = btrfs_update_inode_fallback(trans, root, inode);
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 15/29] btrfs: remove unused parameter from update_nr_written

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:07AM +0100, David Sterba wrote:
> The logic has been updated in "Btrfs: make mapping->writeback_index
> point to the last written page" (a91326679f2a0a4c2) and page is not
> needed anymore.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/extent_io.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 00f3be5c4f2d..f683fa5a4b91 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -3203,7 +3203,7 @@ int extent_read_full_page(struct extent_io_tree *tree, 
> struct page *page,
>   return ret;
>  }
>  
> -static void update_nr_written(struct page *page, struct writeback_control 
> *wbc,
> +static void update_nr_written(struct writeback_control *wbc,
> unsigned long nr_written)
>  {
>   wbc->nr_to_write -= nr_written;
> @@ -3341,7 +3341,7 @@ static noinline_for_stack int 
> __extent_writepage_io(struct inode *inode,
>   else
>   redirty_page_for_writepage(wbc, page);
>  
> - update_nr_written(page, wbc, nr_written);
> + update_nr_written(wbc, nr_written);
>   unlock_page(page);
>   return 1;
>   }
> @@ -3351,7 +3351,7 @@ static noinline_for_stack int 
> __extent_writepage_io(struct inode *inode,
>* we don't want to touch the inode after unlocking the page,
>* so we update the mapping writeback index now
>*/
> - update_nr_written(page, wbc, nr_written + 1);
> + update_nr_written(wbc, nr_written + 1);
>  
>   end = page_end;
>   if (i_size <= start) {
> @@ -3764,7 +3764,7 @@ static noinline_for_stack int write_one_eb(struct 
> extent_buffer *eb,
>   break;
>   }
>   offset += PAGE_SIZE;
> - update_nr_written(p, wbc, 1);
> + update_nr_written(wbc, 1);
>   unlock_page(p);
>   }
>  
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 12/29] btrfs: remove unused parameter from tree_move_down

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:58AM +0100, David Sterba wrote:
> Never needed.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ctree.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index b98e90a3eee7..a981c2acd6fa 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -5241,7 +5241,7 @@ int btrfs_search_forward(struct btrfs_root *root, 
> struct btrfs_key *min_key,
>  
>  static int tree_move_down(struct btrfs_fs_info *fs_info,
>  struct btrfs_path *path,
> -int *level, int root_level)
> +int *level)
>  {
>   struct extent_buffer *eb;
>  
> @@ -5299,7 +5299,7 @@ static int tree_advance(struct btrfs_fs_info *fs_info,
>   ret = tree_move_next_or_upnext(fs_info, path, level,
>  root_level);
>   } else {
> - ret = tree_move_down(fs_info, path, level, root_level);
> + ret = tree_move_down(fs_info, path, level);
>   }
>   if (ret >= 0) {
>   if (*level == 0)
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 13/29] btrfs: remove unused parameter from tree_move_next_or_upnext

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:34:01AM +0100, David Sterba wrote:
> Not needed.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ctree.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index a981c2acd6fa..1192bc7d2ee7 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -5256,8 +5256,7 @@ static int tree_move_down(struct btrfs_fs_info *fs_info,
>   return 0;
>  }
>  
> -static int tree_move_next_or_upnext(struct btrfs_fs_info *fs_info,
> - struct btrfs_path *path,
> +static int tree_move_next_or_upnext(struct btrfs_path *path,
>   int *level, int root_level)
>  {
>   int ret = 0;
> @@ -5296,8 +5295,7 @@ static int tree_advance(struct btrfs_fs_info *fs_info,
>   int ret;
>  
>   if (*level == 0 || !allow_down) {
> - ret = tree_move_next_or_upnext(fs_info, path, level,
> -root_level);
> + ret = tree_move_next_or_upnext(path, level, root_level);
>   } else {
>   ret = tree_move_down(fs_info, path, level);
>   }
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 10/29] btrfs: remove unused parameter from btrfs_prepare_extent_commit

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:52AM +0100, David Sterba wrote:
> Added but never used.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ctree.h   | 3 +--
>  fs/btrfs/extent-tree.c | 3 +--
>  fs/btrfs/transaction.c | 2 +-
>  3 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 0f5b85772023..e7dbda3dd3b8 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -2630,8 +2630,7 @@ int btrfs_free_reserved_extent(struct btrfs_fs_info 
> *fs_info,
>  u64 start, u64 len, int delalloc);
>  int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info,
>  u64 start, u64 len);
> -void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans,
> -  struct btrfs_fs_info *fs_info);
> +void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info);
>  int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
>  struct btrfs_fs_info *fs_info);
>  int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index b33e2c8325c8..2500e3df3250 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -6558,8 +6558,7 @@ static int btrfs_free_reserved_bytes(struct 
> btrfs_block_group_cache *cache,
>   spin_unlock(_info->lock);
>   return ret;
>  }
> -void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans,
> - struct btrfs_fs_info *fs_info)
> +void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info)
>  {
>   struct btrfs_caching_control *next;
>   struct btrfs_caching_control *caching_ctl;
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index 7d1d71259cd0..8bfb5e2c31f9 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -2211,7 +2211,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle 
> *trans)
>   goto scrub_continue;
>   }
>  
> - btrfs_prepare_extent_commit(trans, fs_info);
> + btrfs_prepare_extent_commit(fs_info);
>  
>   cur_trans = fs_info->running_transaction;
>  
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 08/29] btrfs: remove unused parameter from __push_leaf_left

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:45AM +0100, David Sterba wrote:
> Unused since long ago.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ctree.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index 2283f92b5484..b98e90a3eee7 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -3825,8 +3825,7 @@ static int push_leaf_right(struct btrfs_trans_handle 
> *trans, struct btrfs_root
>   * item at 'max_slot' won't be touched.  Use (u32)-1 to make us do all the
>   * items
>   */
> -static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,
> -  struct btrfs_fs_info *fs_info,
> +static noinline int __push_leaf_left(struct btrfs_fs_info *fs_info,
>struct btrfs_path *path, int data_size,
>int empty, struct extent_buffer *left,
>int free_space, u32 right_nritems,
> @@ -4035,7 +4034,7 @@ static int push_leaf_left(struct btrfs_trans_handle 
> *trans, struct btrfs_root
>   goto out;
>   }
>  
> - return __push_leaf_left(trans, fs_info, path, min_data_size,
> + return __push_leaf_left(fs_info, path, min_data_size,
>  empty, left, free_space, right_nritems,
>  max_slot);
>  out:
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 09/29] btrfs: remove unused parameter from btrfs_subvolume_release_metadata

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:49AM +0100, David Sterba wrote:
> Unused since qgroup refactoring that split data and metadata accounting,
> the btrfs_qgroup_free helper.
> 
Reviewed-by: Liu Bo 

Thanks,

-liubo
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ctree.h   |  3 +--
>  fs/btrfs/extent-tree.c |  3 +--
>  fs/btrfs/ioctl.c   | 11 ---
>  3 files changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 1692ebb05955..0f5b85772023 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -2703,8 +2703,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root 
> *root,
>int nitems,
>u64 *qgroup_reserved, bool use_global_rsv);
>  void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info,
> -   struct btrfs_block_rsv *rsv,
> -   u64 qgroup_reserved);
> +   struct btrfs_block_rsv *rsv);
>  int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes);
>  void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes);
>  int btrfs_delalloc_reserve_space(struct inode *inode, u64 start, u64 len);
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 9e8d6c2e7a64..b33e2c8325c8 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -5826,8 +5826,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root 
> *root,
>  }
>  
>  void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info,
> -   struct btrfs_block_rsv *rsv,
> -   u64 qgroup_reserved)
> +   struct btrfs_block_rsv *rsv)
>  {
>   btrfs_block_rsv_release(fs_info, rsv, (u64)-1);
>  }
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 77f93a1e65c7..e8c7c313c113 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -487,8 +487,7 @@ static noinline int create_subvol(struct inode *dir,
>   trans = btrfs_start_transaction(root, 0);
>   if (IS_ERR(trans)) {
>   ret = PTR_ERR(trans);
> - btrfs_subvolume_release_metadata(fs_info, _rsv,
> -  qgroup_reserved);
> + btrfs_subvolume_release_metadata(fs_info, _rsv);
>   goto fail_free;
>   }
>   trans->block_rsv = _rsv;
> @@ -613,7 +612,7 @@ static noinline int create_subvol(struct inode *dir,
>   kfree(root_item);
>   trans->block_rsv = NULL;
>   trans->bytes_reserved = 0;
> - btrfs_subvolume_release_metadata(fs_info, _rsv, qgroup_reserved);
> + btrfs_subvolume_release_metadata(fs_info, _rsv);
>  
>   if (async_transid) {
>   *async_transid = trans->transid;
> @@ -753,9 +752,7 @@ static int create_snapshot(struct btrfs_root *root, 
> struct inode *dir,
>   d_instantiate(dentry, inode);
>   ret = 0;
>  fail:
> - btrfs_subvolume_release_metadata(fs_info,
> -  _snapshot->block_rsv,
> -  pending_snapshot->qgroup_reserved);
> + btrfs_subvolume_release_metadata(fs_info, _snapshot->block_rsv);
>  dec_and_free:
>   if (atomic_dec_and_test(>will_be_snapshoted))
>   wake_up_atomic_t(>will_be_snapshoted);
> @@ -2555,7 +2552,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct 
> file *file,
>   err = ret;
>   inode->i_flags |= S_DEAD;
>  out_release:
> - btrfs_subvolume_release_metadata(fs_info, _rsv, qgroup_reserved);
> + btrfs_subvolume_release_metadata(fs_info, _rsv);
>  out_up_write:
>   up_write(_info->subvol_sem);
>   if (err) {
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 07/29] btrfs: remove unused parameter from __push_leaf_right

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:42AM +0100, David Sterba wrote:
> Unused since long ago.

Reviewed-by: Liu Bo 

Thanks,

-liubo
> 
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ctree.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index 4c5d7c40c8bf..2283f92b5484 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -3595,8 +3595,7 @@ noinline int btrfs_leaf_free_space(struct btrfs_fs_info 
> *fs_info,
>   * min slot controls the lowest index we're willing to push to the
>   * right.  We'll push up to and including min_slot, but no lower
>   */
> -static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
> -   struct btrfs_fs_info *fs_info,
> +static noinline int __push_leaf_right(struct btrfs_fs_info *fs_info,
> struct btrfs_path *path,
> int data_size, int empty,
> struct extent_buffer *right,
> @@ -3810,7 +3809,7 @@ static int push_leaf_right(struct btrfs_trans_handle 
> *trans, struct btrfs_root
>   return 0;
>   }
>  
> - return __push_leaf_right(trans, fs_info, path, min_data_size, empty,
> + return __push_leaf_right(fs_info, path, min_data_size, empty,
>   right, free_space, left_nritems, min_slot);
>  out_unlock:
>   btrfs_tree_unlock(right);
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 03/29] btrfs: remove unused parameter from clean_tree_block

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:30AM +0100, David Sterba wrote:
> Added but never needed.

Reviewed-by: Liu Bo 

Thanks,

-liubo
> 
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ctree.c   | 16 
>  fs/btrfs/disk-io.c |  3 +--
>  fs/btrfs/disk-io.h |  3 +--
>  fs/btrfs/extent-tree.c |  4 ++--
>  fs/btrfs/free-space-tree.c |  2 +-
>  fs/btrfs/qgroup.c  |  2 +-
>  fs/btrfs/tree-log.c|  6 +++---
>  7 files changed, 17 insertions(+), 19 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index 35e22349c139..d509dafdb20c 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -1074,7 +1074,7 @@ static noinline int update_ref_for_cow(struct 
> btrfs_trans_handle *trans,
>   ret = btrfs_dec_ref(trans, root, buf, 1);
>   BUG_ON(ret); /* -ENOMEM */
>   }
> - clean_tree_block(trans, fs_info, buf);
> + clean_tree_block(fs_info, buf);
>   *last_ref = 1;
>   }
>   return 0;
> @@ -1938,7 +1938,7 @@ static noinline int balance_level(struct 
> btrfs_trans_handle *trans,
>  
>   path->locks[level] = 0;
>   path->nodes[level] = NULL;
> - clean_tree_block(trans, fs_info, mid);
> + clean_tree_block(fs_info, mid);
>   btrfs_tree_unlock(mid);
>   /* once for the path */
>   free_extent_buffer(mid);
> @@ -1999,7 +1999,7 @@ static noinline int balance_level(struct 
> btrfs_trans_handle *trans,
>   if (wret < 0 && wret != -ENOSPC)
>   ret = wret;
>   if (btrfs_header_nritems(right) == 0) {
> - clean_tree_block(trans, fs_info, right);
> + clean_tree_block(fs_info, right);
>   btrfs_tree_unlock(right);
>   del_ptr(root, path, level + 1, pslot + 1);
>   root_sub_used(root, right->len);
> @@ -2043,7 +2043,7 @@ static noinline int balance_level(struct 
> btrfs_trans_handle *trans,
>   BUG_ON(wret == 1);
>   }
>   if (btrfs_header_nritems(mid) == 0) {
> - clean_tree_block(trans, fs_info, mid);
> + clean_tree_block(fs_info, mid);
>   btrfs_tree_unlock(mid);
>   del_ptr(root, path, level + 1, pslot);
>   root_sub_used(root, mid->len);
> @@ -3705,7 +3705,7 @@ static noinline int __push_leaf_right(struct 
> btrfs_trans_handle *trans,
>   if (left_nritems)
>   btrfs_mark_buffer_dirty(left);
>   else
> - clean_tree_block(trans, fs_info, left);
> + clean_tree_block(fs_info, left);
>  
>   btrfs_mark_buffer_dirty(right);
>  
> @@ -3717,7 +3717,7 @@ static noinline int __push_leaf_right(struct 
> btrfs_trans_handle *trans,
>   if (path->slots[0] >= left_nritems) {
>   path->slots[0] -= left_nritems;
>   if (btrfs_header_nritems(path->nodes[0]) == 0)
> - clean_tree_block(trans, fs_info, path->nodes[0]);
> + clean_tree_block(fs_info, path->nodes[0]);
>   btrfs_tree_unlock(path->nodes[0]);
>   free_extent_buffer(path->nodes[0]);
>   path->nodes[0] = right;
> @@ -3946,7 +3946,7 @@ static noinline int __push_leaf_left(struct 
> btrfs_trans_handle *trans,
>   if (right_nritems)
>   btrfs_mark_buffer_dirty(right);
>   else
> - clean_tree_block(trans, fs_info, right);
> + clean_tree_block(fs_info, right);
>  
>   btrfs_item_key(right, _key, 0);
>   fixup_low_keys(fs_info, path, _key, 1);
> @@ -5009,7 +5009,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, 
> struct btrfs_root *root,
>   btrfs_set_header_level(leaf, 0);
>   } else {
>   btrfs_set_path_blocking(path);
> - clean_tree_block(trans, fs_info, leaf);
> + clean_tree_block(fs_info, leaf);
>   btrfs_del_leaf(trans, root, path, leaf);
>   }
>   } else {
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 89cd597883fd..48846d215e97 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -1248,8 +1248,7 @@ struct extent_buffer *read_tree_block(struct 
> btrfs_fs_info *fs_info, u64 bytenr,
>  
>  }
>  
> -void clean_tree_block(struct btrfs_trans_handle *trans,
> -   struct btrfs_fs_info *fs_info,
> +void clean_tree_block(struct btrfs_fs_info *fs_info,
> struct extent_buffer *buf)
>  {
>   if (btrfs_header_generation(buf) ==
> diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
> index 44dcd9af6b7c..1864e7ce9c70 100644
> --- a/fs/btrfs/disk-io.h
> +++ b/fs/btrfs/disk-io.h
> @@ -52,8 +52,7 @@ int reada_tree_block_flagged(struct btrfs_fs_info *fs_info, 
> u64 bytenr,
>  struct extent_buffer 

Re: [PATCH 06/29] btrfs: merge two superblock writing helpers

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:39AM +0100, David Sterba wrote:
> write_all_supers and write_ctree_super are almost equal, the parameter
> 'trans' is unused so we can drop it and have just one helper.

Reviewed-by: Liu Bo 

Thanks,

-liubo
> 
> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/disk-io.c | 8 +---
>  fs/btrfs/disk-io.h | 3 +--
>  fs/btrfs/transaction.c | 2 +-
>  fs/btrfs/tree-log.c| 2 +-
>  4 files changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 43e71457c193..441a62cd0351 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -3695,7 +3695,7 @@ int btrfs_calc_num_tolerated_disk_barrier_failures(
>   return num_tolerated_disk_barrier_failures;
>  }
>  
> -static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
> +int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
>  {
>   struct list_head *head;
>   struct btrfs_device *dev;
> @@ -3789,12 +3789,6 @@ static int write_all_supers(struct btrfs_fs_info 
> *fs_info, int max_mirrors)
>   return 0;
>  }
>  
> -int write_ctree_super(struct btrfs_trans_handle *trans,
> -   struct btrfs_fs_info *fs_info, int max_mirrors)
> -{
> - return write_all_supers(fs_info, max_mirrors);
> -}
> -
>  /* Drop a fs root from the radix tree and free it. */
>  void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
> struct btrfs_root *root)
> diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
> index 1864e7ce9c70..0be2d4fe705b 100644
> --- a/fs/btrfs/disk-io.h
> +++ b/fs/btrfs/disk-io.h
> @@ -57,8 +57,7 @@ int open_ctree(struct super_block *sb,
>  struct btrfs_fs_devices *fs_devices,
>  char *options);
>  void close_ctree(struct btrfs_fs_info *fs_info);
> -int write_ctree_super(struct btrfs_trans_handle *trans,
> -   struct btrfs_fs_info *fs_info, int max_mirrors);
> +int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors);
>  struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
>  int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
>   struct buffer_head **bh_ret);
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index 48aabb367f73..7d1d71259cd0 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -2261,7 +2261,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle 
> *trans)
>   goto scrub_continue;
>   }
>  
> - ret = write_ctree_super(trans, fs_info, 0);
> + ret = write_all_supers(fs_info, 0);
>   if (ret) {
>   mutex_unlock(_info->tree_log_mutex);
>   goto scrub_continue;
> diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
> index cea93ba1f099..62dd138018b5 100644
> --- a/fs/btrfs/tree-log.c
> +++ b/fs/btrfs/tree-log.c
> @@ -2961,7 +2961,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
>* the running transaction open, so a full commit can't hop
>* in and cause problems either.
>*/
> - ret = write_ctree_super(trans, fs_info, 1);
> + ret = write_all_supers(fs_info, 1);
>   if (ret) {
>   btrfs_set_log_full_commit(fs_info, trans);
>   btrfs_abort_transaction(trans, ret);
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] btrfs-progs: RAID5:Inject data stripe corruption and verify scrub fixes it.

2017-02-15 Thread Lakshmipathi.G
On Wed, Feb 15, 2017 at 05:29:33PM +0800, Qu Wenruo wrote:
> 
> 
> At 02/15/2017 05:03 PM, Lakshmipathi.G wrote:
> >Signed-off-by: Lakshmipathi.G 
> >---
> > .../020-raid5-datastripe-corruption/test.sh| 224 
> > +
> > 1 file changed, 224 insertions(+)
> > create mode 100755 tests/misc-tests/020-raid5-datastripe-corruption/test.sh
> >
> >diff --git a/tests/misc-tests/020-raid5-datastripe-corruption/test.sh 
> >b/tests/misc-tests/020-raid5-datastripe-corruption/test.sh
> >new file mode 100755
> >index 000..d04c430
> >--- /dev/null
> >+++ b/tests/misc-tests/020-raid5-datastripe-corruption/test.sh
> >@@ -0,0 +1,224 @@
> >+#!/bin/bash
> >+#
> >+# Raid5: Inject data stripe corruption and fix them using scrub.
> >+#
> >+# Script will perform the following:
> >+# 1) Create Raid5 using 3 loopback devices.
> >+# 2) Ensure file layout is created in a predictable manner.
> >+#Each data stripe(64KB) should uniquely start with 'DN',
> >+#where N represents the data stripe number.(ex:D0,D1 etc)
> 
> If you want really predictable layout, you could just upload compressed
> images for this purpose.
> 
> Which makes things super easy, and unlike fstests, btrfs-progs self-test
> accepts such images.
> 
> >+# 3) Once file is created with specific layout, gather data stripe details
> >+#like devicename, position and actual on-disk data.
> >+# 4) Now use 'dd' to verify the data-stripe against its expected value
> >+#and inject corruption by zero'ing out contents.
> >+# 5) After injecting corruption, running online-scrub is expected to fix
> >+#the corrupted data stripe with the help of parity block and
> >+#corresponding data stripe.
> 
> You should also verify parity stripe is not corrupted.
> It's already known that RAID5/6 will corrupted parity while recovering data
> stripe.
> 
> Kernel patch for this, with detailed bug info.
> https://patchwork.kernel.org/patch/9553581/
> 
> >+# 6) Finally, validate the data stripe has original un-corrupted value.
> >+#
> >+#  Note: This script doesn't handle parity block corruption.
> 
> Normally such test case should belong to xfstests (renamed to fstests
> recently) as we're verifying kernel behavior, not btrfs-progs behavior.
> 
> But since fstests test case should be as generic as possible, and we don't
> have a good enough tool to corrupt given data/parity stripe, my previously
> submitted test case is rejected.
> 
> Personally speaking, this seems to be a dilemma for me.
> 
> We really need a test case for this, bugs has been spotted that RAID5/6
> scrub will corrupt P/Q while recovering data stripe.
> But we need to enhance btrfs-corrupt-block to a better shape to make fstests
> to accept it, and it won't take a short time.
> 
> So I really have no idea what should we do for such test.
> 
> Thanks,
> Qu

Will check compressed images for parity strpe testing. I assume at the moment,
we currently support single static compressed image. Adding more than one static
compressed images like disk1.img disk2.img disk3.img for RAID is supported in
existing test framework?

Using compressed images for checking parity seems little easier than computing
via scripting.

Looked into patch description:

After scrubbing dev3 only:
0xcdcd (Good)  |  0xcdcd  | 0xcdcd (Bad) 
(D1)  (D2)(P) 

So the Parity stripe (P) always get replaced by exact content of D1/D2 
(data-stripe)
or by random  data? If it always  get replaced by exact value from either
D1 or D2.  I think current script can be modified to detect that bug. If parity 
gets
replaced by random value, then it will the make task more difficult.

Yes, without better support for RAID with tools like btrfs-corrupt-block, it 
will be
hard to play-around with RAID to create test scripts.

Cheers.
Lakshmipathi.G
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] btrfs-progs: misc-tests: Superblock corruption and recovery using backup.

2017-02-15 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G 
---
 .../019-fix-superblock-corruption/test.sh  | 38 ++
 1 file changed, 38 insertions(+)
 create mode 100755 tests/misc-tests/019-fix-superblock-corruption/test.sh

diff --git a/tests/misc-tests/019-fix-superblock-corruption/test.sh 
b/tests/misc-tests/019-fix-superblock-corruption/test.sh
new file mode 100755
index 000..55159dc
--- /dev/null
+++ b/tests/misc-tests/019-fix-superblock-corruption/test.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Corrupt primary superblock and restore it using backup superblock.
+#
+
+source $TOP/tests/common
+
+check_prereq btrfs-select-super
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+FIRST_SUPERBLOCK_OFFSET=65536
+
+test_superblock_restore()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+   # Corrupt superblock checksum
+dd if=/dev/zero of=$TEST_DEV seek=$FIRST_SUPERBLOCK_OFFSET bs=1 \
+count=4  conv=notrunc &> /dev/null
+   
+   # Run btrfs check to detect corruption
+   $TOP/btrfs check $TEST_DEV >& /dev/null && \
+   _fail "btrfs check should detect corruption"
+
+   # Copy backup superblock to primary
+   run_check $TOP/btrfs-select-super -s 1 $TEST_DEV
+   
+   echo "Performing btrfs check" &>> $RESULTS
+   $TOP/btrfs check $TEST_DEV &>> $RESULTS
+if [ $? -ne 0 ]; then
+   _fail "Failed to fix superblock."
+fi 
+}
+
+test_superblock_restore
-- 
2.7.4

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


Re: [PATCH 04/29] btrfs: remove unused parameter from split_item

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:33AM +0100, David Sterba wrote:
> Never used.
> 

Reviewed-by: Liu Bo 

> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/ctree.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index d509dafdb20c..4c5d7c40c8bf 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -4413,8 +4413,7 @@ static noinline int setup_leaf_for_split(struct 
> btrfs_trans_handle *trans,
>   return ret;
>  }
>  
> -static noinline int split_item(struct btrfs_trans_handle *trans,
> -struct btrfs_fs_info *fs_info,
> +static noinline int split_item(struct btrfs_fs_info *fs_info,
>  struct btrfs_path *path,
>  const struct btrfs_key *new_key,
>  unsigned long split_offset)
> @@ -4511,7 +4510,7 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,
>   if (ret)
>   return ret;
>  
> - ret = split_item(trans, root->fs_info, path, new_key, split_offset);
> + ret = split_item(root->fs_info, path, new_key, split_offset);
>   return ret;
>  }
>  
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Thanks,

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


Re: [PATCH 02/29] btrfs: remove unused parameter from check_async_write

2017-02-15 Thread Liu Bo
On Mon, Feb 13, 2017 at 10:33:27AM +0100, David Sterba wrote:
> Added but never used.
>

Reviewed-by: Liu Bo 

> Signed-off-by: David Sterba 
> ---
>  fs/btrfs/disk-io.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 18004169552c..89cd597883fd 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -1005,7 +1005,7 @@ static int __btree_submit_bio_done(struct inode *inode, 
> struct bio *bio,
>   return ret;
>  }
>  
> -static int check_async_write(struct inode *inode, unsigned long bio_flags)
> +static int check_async_write(unsigned long bio_flags)
>  {
>   if (bio_flags & EXTENT_BIO_TREE_LOG)
>   return 0;
> @@ -1021,7 +1021,7 @@ static int btree_submit_bio_hook(struct inode *inode, 
> struct bio *bio,
>u64 bio_offset)
>  {
>   struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
> - int async = check_async_write(inode, bio_flags);
> + int async = check_async_write(bio_flags);
>   int ret;
>  
>   if (bio_op(bio) != REQ_OP_WRITE) {
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 17/29] btrfs: remove unused parameter from extent_write_cache_pages

2017-02-15 Thread Liu Bo
On Wed, Feb 15, 2017 at 04:30:46PM +0100, David Sterba wrote:
> On Tue, Feb 14, 2017 at 11:35:11AM -0800, Liu Bo wrote:
> > On Mon, Feb 13, 2017 at 10:34:13AM +0100, David Sterba wrote:
> > > The 'tree' was used to call locking hook that does not exist anymore.
> > > 
> > > Signed-off-by: David Sterba 
> > > ---
> > >  fs/btrfs/extent_io.c | 6 ++
> > >  1 file changed, 2 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> > > index f683fa5a4b91..22a2f2fa62c7 100644
> > > --- a/fs/btrfs/extent_io.c
> > > +++ b/fs/btrfs/extent_io.c
> > > @@ -3916,8 +3916,7 @@ int btree_write_cache_pages(struct address_space 
> > > *mapping,
> > >   * WB_SYNC_ALL then we were called for data integrity and we must wait 
> > > for
> > >   * existing IO to complete.
> > >   */
> > > -static int extent_write_cache_pages(struct extent_io_tree *tree,
> > > -  struct address_space *mapping,
> > > +static int extent_write_cache_pages(struct address_space *mapping,
> > >struct writeback_control *wbc,
> > >writepage_t writepage, void *data,
> > >void (*flush_fn)(void *))
> > > @@ -4158,8 +4157,7 @@ int extent_writepages(struct extent_io_tree *tree,
> > >   .bio_flags = 0,
> > >   };
> > >  
> > > - ret = extent_write_cache_pages(tree, mapping, wbc,
> > > -__extent_writepage, ,
> > > + ret = extent_write_cache_pages(mapping, wbc, __extent_writepage, ,
> > >  flush_write_bio);
> > 
> > Are we going to leave {btrfs,extent}_{read,write}pages untouched?
> 
> Yes, because extent_writepages uses 'tree', it's stored in the
> extent_page_data, and some if not all callbacks do utilize it.
> 
> 4140 int extent_writepages(struct extent_io_tree *tree,
> 4141   struct address_space *mapping,
> 4142   get_extent_t *get_extent,
> 4143   struct writeback_control *wbc)
> 4144 {
> 4145 int ret = 0;
> 4146 struct extent_page_data epd = {
> 4147 .bio = NULL,
> 4148 .tree = tree,
> 
> 4149 .get_extent = get_extent,
> 4150 .extent_locked = 0,
> 4151 .sync_io = wbc->sync_mode == WB_SYNC_ALL,
> 4152 .bio_flags = 0,
> 4153 };
> 
> btrfs_readpages
>   extent_readpages
> __extent_readpages
>   __do_contiguous_readpages
>   lock_extent
> 
> and btrfs_writepages calls extent_writepages.

OK, I see.

Reviewed-by: Liu Bo 

Thanks,

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


[PATCH v2] Btrfs: fix data loss after truncate when using the no-holes feature

2017-02-15 Thread fdmanana
From: Filipe Manana 

If we have a file with an implicit hole (NO_HOLES feature enabled) that
has an extent following the hole, delayed writes against regions of the
file behind the hole happened before but were not yet flushed and then
we truncate the file to a smaller size that lies inside the hole, we
end up persisting a wrong disk_i_size value for our inode that leads to
data loss after umounting and mounting again the filesystem or after
the inode is evicted and loaded again.

This happens because at inode.c:btrfs_truncate_inode_items() we end up
setting last_size to the offset of the extent that we deleted and that
followed the hole. We then pass that value to btrfs_ordered_update_i_size()
which updates the inode's disk_i_size to a value smaller then the offset
of the buffered (delayed) writes.

Example reproducer:

 $ mkfs.btrfs -f /dev/sdb
 $ mount /dev/sdb /mnt

 $ xfs_io -f -c "pwrite -S 0x01 0K 32K" /mnt/foo
 $ xfs_io -d -c "pwrite -S 0x02 -b 32K 64K 32K" /mnt/foo
 $ xfs_io -c "truncate 60K" /mnt/foo
   --> inode's disk_i_size updated to 0

 $ md5sum /mnt/foo
 3c5ca3c3ab42f4b04d7e7eb0b0d4d806  /mnt/foo

 $ umount /dev/sdb
 $ mount /dev/sdb /mnt

 $ md5sum /mnt/foo
 d41d8cd98f00b204e9800998ecf8427e  /mnt/foo
   --> Empty file, all data lost!

Cc:   # 3.14+
Fixes: 16e7549f045d ("Btrfs: incompatible format change to remove hole extents")
Signed-off-by: Filipe Manana 
---

V2: Do the update of last_size only if no error happened, which is specially
important when we're called by inode eviction and err is -eagain.
Added an assertion and removed so no longer needed code from the loop.

 fs/btrfs/inode.c | 19 ++-
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 8eb6703..a9db345 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4508,19 +4508,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle 
*trans,
if (found_type > min_type) {
del_item = 1;
} else {
-   if (item_end < new_size) {
-   /*
-* With NO_HOLES mode, for the following mapping
-*
-* [0-4k][hole][8k-12k]
-*
-* if truncating isize down to 6k, it ends up
-* isize being 8k.
-*/
-   if (btrfs_fs_incompat(root->fs_info, NO_HOLES))
-   last_size = new_size;
+   if (item_end < new_size)
break;
-   }
if (found_key.offset >= new_size)
del_item = 1;
else
@@ -4703,8 +4692,12 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle 
*trans,
btrfs_abort_transaction(trans, ret);
}
 error:
-   if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
+   if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
+   ASSERT(last_size >= new_size);
+   if (!err && last_size > new_size)
+   last_size = new_size;
btrfs_ordered_update_i_size(inode, last_size, NULL);
+   }
 
btrfs_free_path(path);
 
-- 
2.7.0.rc3

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


Re: stat(2) returning device ID not existing in mountinfo

2017-02-15 Thread Goffredo Baroncelli
(Resended because I don saw it in the mailing lists)

-
Hi,

I want to highlight this bug another time.

I encountered this bug, when I was looking to a problem with find. I my machine 
find took an huge quantity of memory (up to 3GB) when used by updatedb.


http://lists.gnu.org/archive/html/findutils-patches/2016-12/msg0.html

The root of the problem was a leak memory in find. What was strange however is 
that the findutils developers weren't unable to reproduce this bug. They find 
the leak, but not a so high memory usage.

After some email, it was discovered that find (when used in updatedb) checks if 
the filesystem is changed during the tree walking. They checked the device-id 
returned by stat against the one returned by mountinfo.

For btrfs these differ, and the check is repeat each time. Because the memory 
leak was per "filesystem check", using find on a btrfs filesystem caused a huge 
leak.

I hope that some btrfs developer could address this, because I suspect that a 
lot of tools compare the device id returned by /proc/self/mountinfo against the 
one returned by stat(2).


BR
G.Baroncelli




On 2016-09-20 15:15, Jeff Mahoney wrote:
> On 9/16/16 4:28 PM, Tomasz Sterna wrote:
>> Hi.
>>
>> I have spotted an issue with stat(2) call on files on btrfs.
>> It is giving me dev_t st_dev number that does not correspond to any
>> mounted filesystem in proc's mountinfo.
> 
> That's by design.  Your particular file system may only use one device
> but, internally, btrfs uses virtualized storage that may be spread
> across multiple devices.  To make things more complicated, snapshots
> mean that:
> 
> sled1a:/mnt # btrfs sub list .
> ID 257 gen 14 top level 5 path a
> ID 258 gen 14 top level 5 path b
> 
> sled1a:/mnt # ls -laRi
> .:
> total 16
> 256 drwxr-xr-x 1 root root   4 Sep 20 09:08 .
> 256 drwxr-xr-x 1 root root 220 Sep 16 09:49 ..
> 256 drwxr-xr-x 1 root root   8 Sep 14 10:24 a
> 256 drwxr-xr-x 1 root root   8 Sep 14 10:24 b
> 
> ./a:
> total 4112
> 256 drwxr-xr-x 1 root root   8 Sep 14 10:24 .
> 256 drwxr-xr-x 1 root root   4 Sep 20 09:08 ..
> 257 -rw-r--r-- 1 root root 4194304 Sep 14 10:24 file
> 
> ./b:
> total 4112
> 256 drwxr-xr-x 1 root root   8 Sep 14 10:24 .
> 256 drwxr-xr-x 1 root root   4 Sep 20 09:08 ..
> 257 -rw-r--r-- 1 root root 4194304 Sep 14 10:24 file
> 
> Under normal circumstances those are two files with the same st_dev and
> the same inode number.  That would normally correspond to a hard link,
> but the files do not (necessarily) correspond to the same file.
> 
> ... but because we use anonymous device numbers for each subvolume, we
> have different device numbers for each one.
> 
> sled1a:/mnt # stat --format "%n st_dev=%d" {a,b}/file
> a/file st_dev=69
> b/file st_dev=70
> 
> It's a pretty big usability wart that we don't consistently report the
> device number.  We do it correctly in stat() but there are other places
> in the code that assume that inode->i_sb->s_dev will work.  In the SUSE
> kernels, we have patches that add a super_operation to report the
> correct device number everywhere, but even that is a hack.
> 
>> I already attempted a illinformed-patch in fs/btrfs/super.c:
>>
>> @@ -1127,6 +1127,7 @@ static int btrfs_fill_super(struct super_block *sb,
>>  goto fail_close;
>>  }
>>  
>> +sb->s_dev = inode->i_sb->s_dev;
>>  sb->s_root = d_make_root(inode);
>>  if (!sb->s_root) {
>>  err = -ENOMEM;
>>
>> but it didn't help.
> 
> It wouldn't.  That is assigning a variable to itself.
> 
>> I would like to dig deeper and fix it, but first I have to ask:
>> - Which number is wrong?
>>   The one returned by stat() or the one in mountinfo?
> 
> The one in mountinfo, but then that means that the user only sees the
> anonymous devices in mount(8), which isn't what we want either.
> 
> I'm afraid the correct fix is very involved and requires non-trivial
> changes in the VFS layer as well.  It's on my long-term TODO list.  I
> currently have some patches that do the magic with vfsmounts but it's
> far from being usable.
> 
> -Jeff
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli 
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5

-- 
gpg @keyserver.linux.it: Goffredo Baroncelli 
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: How to dump/find parity of RAID-5 file?

2017-02-15 Thread Goffredo Baroncelli
On 2017-02-14 21:09, Lakshmipathi.G wrote:
> On Mon, Feb 06, 2017 at 09:40:47PM +0100, Goffredo Baroncelli wrote:
>>
>> IIRC, the parity is spread across the disk stripes of the chunk.
>>
>> So first you have to find the logical-offset [LO] where the the file begins. 
>> Then you have to map this offset to the chunk which holds the data. The 
>> chunk has the following info:
>> - chunk start [CS], chunk length [CL]
>> - for each stripe:
>>  where the stripe starts
>>
>> If you subtract the chunk-start from the logical-offset [ CO == LO-CS], you 
>> will find the offset where the data belongs in the chunk.
>>
>> As stated above, the PARITY is spread across the chunk stripes. So 
>> (supposing that the stripe size is 64K, the raid level is 5, the disks are 
>> three), 
>>
>> - the first 64k of stripe 0, is data [0..64K)
>> - the first 64k of stripe 1, is data [64..128K)
>> - the first 64k of stripe 2 is parity, 
>>
>> - the 2nd 64k of stripe 0 is parity, 
>> - the 2nd 64k of stripe 1, is data [128..196K)
>> - the 2nd 64k of stripe 2, is data [192..256K)
>>
>> - the 3rd 64k of stripe 0, is data [256..320K)
>> - the 3rd 64k of stripe 1 is parity, 
>> - the 3rd 64k of stripe 2, is data [320..384K)
>> and so on,
>>
>> To find the data, You have to compare the CO to the data [...) range.
>>
>> If you look to an my old patch (unfinished :-( ), you can find some example 
>> to dump the different stripe
>>
>> [BTRFS-PROGS][PATCH][V2] Add two new commands: 'btrfs insp physical-find' 
>> and 'btrfs insp physical-dump'
>>
>>
> Sorry for the delay, I was offline. Thanks for the details. I can understood 
> "partiy spread across the chunk stripes" part.
> But unable to figure-out the first part regarding calculations.
> 
> Raid5 With 3-devices each 512MB. Create single 128KB file("print 
> 'Ab'+'a'*65534+'aB'+'b'*65533"). 'debug-tree' shows chunk tree as:
> 
>   item 5 key (FIRST_CHUNK_TREE CHUNK_ITEM 145096704) itemoff 15557 
> itemsize 144
>   length 134217728 owner 2 stripe_len 65536 type DATA|RAID5
>   io_align 65536 io_width 65536 sector_size 4096
>   num_stripes 3 sub_stripes 0
>   stripe 0 devid 3 offset 6368
>   dev_uuid 9a2a18f1-6193-44b9-aafc-23d161d66110
>   stripe 1 devid 2 offset 6368
>   dev_uuid e45ab907-c3a8-4dff-af9f-2ae5fd38ffd6
>   stripe 2 devid 1 offset 83034112
>   dev_uuid 428c04d9-37da-454a-b7b2-f6fe88580de2
> and fs-tree shows:
>   item 13 key (145227776 EXTENT_ITEM 131072) itemoff 15788 itemsize 53
>   extent refs 1 gen 7 flags DATA
>   extent data backref root 5 objectid 257 offset 0 count 1
> 
>>From above, I assume: 
> LO=145227776  CS=145096704 and CL=134217728
> CO=145227776 - 145096704  => CO = 131072
> 
> Quite confused from here :s  I'll look into your patches to understand more. 
> I hope sometime in future we will 
> have your finished patches :) 'physical-find' and 'physical-find' commands 
> will be really useful for debugging/testing and 
> learning purposes. thanks.

The chunk-tree maps the logical address [145096704...145096704+134217728) 
[size=128MB] to the physical ones 
devid3 : [6368..6368+67108864) [size=64MB]
devid1 : [6368..6368+67108864) [size=64MB]
devid2 : [83034112..83034112+67108864) [size=64MB]

So because the logical address is divided in pieces of 64k, interleaved by the 
parity, we know that:
* first 128kb
logical address [145096704  ..145096704+64k)   -> devid1, [6368
..6368+64k)
logical address [145096704+64k  ..145096704+2x64k) -> devid2, [83034112
..83034112+64k)
parity:-> devid3, [6368
..6368+64k)
* second 128kb
logical address [145096704+2x64k..145096704+3x64k) -> devid2, 
[83034112+64k..83034112+2x64k)
logical address [145096704+3x64k..145096704+4x64k) -> devid3, 
[6368+64k..6368+2x64k)
parity:-> devid1, 
[6368+64k..6368+2x64k)
And so on...

(NB: 145096704+2x64k == 145227776)

The fs-tree, maps the file content [0..131072) [size=128k] to the logical 
address [145227776..145227776+131072) [size=128k]

So the file content is stored starting from the disk devid2, at 
83034112+64k=83099648 (first 64k). The second 64k is placed in disk devid3 at 
6368+64k=63176704; the parity is stored at disk1, 6368+64k = 63176704


BR
G.Baroncelli

> 
> Cheers.
> Lakshmipathi.G
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli 
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] btrfs: Handle btrfs_reloc_clone_csums error correctly to avoid deadlock

2017-02-15 Thread Filipe Manana
On Wed, Feb 15, 2017 at 8:49 AM, Qu Wenruo  wrote:
> If run btrfs/125 with nospace_cache or space_cache=v2 mount option,
> btrfs will block with the following backtrace:
>
> Call Trace:
>  __schedule+0x2d4/0xae0
>  schedule+0x3d/0x90
>  btrfs_start_ordered_extent+0x160/0x200 [btrfs]
>  ? wake_atomic_t_function+0x60/0x60
>  btrfs_run_ordered_extent_work+0x25/0x40 [btrfs]
>  btrfs_scrubparity_helper+0x1c1/0x620 [btrfs]
>  btrfs_flush_delalloc_helper+0xe/0x10 [btrfs]
>  process_one_work+0x2af/0x720
>  ? process_one_work+0x22b/0x720
>  worker_thread+0x4b/0x4f0
>  kthread+0x10f/0x150
>  ? process_one_work+0x720/0x720
>  ? kthread_create_on_node+0x40/0x40
>  ret_from_fork+0x2e/0x40
>
> The direct cause is the error handler in run_delalloc_nocow() doesn't
> handle error from btrfs_reloc_clone_csums() well.
>
> The related part call path will be:
> __extent_writepage
> |- writepage_delalloc()
> |  |- run_delalloc_range()
> | |- run_delalloc_nocow()
> ||- btrfs_add_ordered_extent()
> ||  Now one ordered extent for file range, e.g [0, 1M) is inserted
> ||
> ||- btrfs_reloc_clone_csums()
> ||  Fails with -EIO, as RAID5/6 doesn't repair some csum tree
> ||  blocks
> ||
> ||- extent_clear_unlock_delalloc()
> |   Error routine, unlock and clear page DIRTY, end page writeback
> |   So the remaining 255 pages will not go through writeback
> |
> |- __extent_writepage_io()
>|- writepage_end_io_hook()
>   |- btrfs_dev_test_ordered_pending()
>  Reduce ordered_extent->bytes_left by 4K.
>  Still have (1M - 4K) to finish.
>
> While the remaining 255 pages will not go through IO nor trigger
> writepage_end_io_hook(), the ordered extent for [0, 1M) will
> never finish, and blocking current transaction forever.
>
> Although the root cause is still in RAID5/6, it won't hurt to fix the
> error routine first.
>
> This patch will cleanup the ordered extent in error routine, so at least
> we won't cause deadlock.
>
> Signed-off-by: Qu Wenruo 
> ---
>  fs/btrfs/extent_io.c|  1 -
>  fs/btrfs/inode.c| 10 --
>  fs/btrfs/ordered-data.c | 25 +
>  fs/btrfs/ordered-data.h | 10 ++
>  4 files changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 4ac383a3a649..a14d1b0840c5 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -3258,7 +3258,6 @@ static noinline_for_stack int writepage_delalloc(struct 
> inode *inode,
>delalloc_end,
>_started,
>nr_written);
> -   /* File system has been set read-only */
> if (ret) {
> SetPageError(page);
> /* fill_delalloc should be return < 0 for error
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 1e861a063721..3c3ade58afd7 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -1052,8 +1052,11 @@ static noinline int cow_file_range(struct inode *inode,
> BTRFS_DATA_RELOC_TREE_OBJECTID) {
> ret = btrfs_reloc_clone_csums(inode, start,
>   cur_alloc_size);
> -   if (ret)
> +   if (ret) {
> +   btrfs_clean_ordered_extent(inode, start,
> +  ram_size);
> goto out_drop_extent_cache;
> +   }
> }
>
> btrfs_dec_block_group_reservations(fs_info, ins.objectid);
> @@ -1538,7 +1541,7 @@ static noinline int run_delalloc_nocow(struct inode 
> *inode,
> if (!ret)
> ret = err;
>
> -   if (ret && cur_offset < end)
> +   if (ret && cur_offset < end) {
> extent_clear_unlock_delalloc(inode, cur_offset, end, end,
>  locked_page, EXTENT_LOCKED |
>  EXTENT_DELALLOC | EXTENT_DEFRAG |
> @@ -1546,6 +1549,9 @@ static noinline int run_delalloc_nocow(struct inode 
> *inode,
>  PAGE_CLEAR_DIRTY |
>  PAGE_SET_WRITEBACK |
>  PAGE_END_WRITEBACK);
> +   btrfs_clean_ordered_extent(inode, cur_offset,
> +  end - cur_offset + 1);

So this is partially correct only.
First here you can have 0, 1 or more ordered extents that were created
in the while loop. So your new function must find and process all
ordered extents within the delalloc range and not just the last one
that was created.

Also, for any created ordered extent, you 

[PATCH 8/7] btrfs: ulist: rename ulist_fini to ulist_release

2017-02-15 Thread David Sterba
Change the name so it matches the naming we already use eg. for
btrfs_path.

Suggested-by: Qu Wenruo 
Signed-off-by: David Sterba 
---
 fs/btrfs/qgroup.c |  8 
 fs/btrfs/ulist.c  | 10 +-
 fs/btrfs/ulist.h  |  2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 052f1410dc14..5d53e948a28d 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2834,7 +2834,7 @@ int btrfs_qgroup_reserve_data(struct inode *inode, u64 
start, u64 len)
if (ret < 0)
goto cleanup;
 
-   ulist_fini(_changed);
+   ulist_release(_changed);
return ret;
 
 cleanup:
@@ -2844,7 +2844,7 @@ int btrfs_qgroup_reserve_data(struct inode *inode, u64 
start, u64 len)
clear_extent_bit(_I(inode)->io_tree, unode->val,
 unode->aux, EXTENT_QGROUP_RESERVED, 0, 0, NULL,
 GFP_NOFS);
-   ulist_fini(_changed);
+   ulist_release(_changed);
return ret;
 }
 
@@ -2871,7 +2871,7 @@ static int __btrfs_qgroup_release_data(struct inode 
*inode, u64 start, u64 len,
trace_btrfs_qgroup_release_data(inode, start, len,
changeset.bytes_changed, trace_op);
 out:
-   ulist_fini(_changed);
+   ulist_release(_changed);
return ret;
 }
 
@@ -2986,5 +2986,5 @@ void btrfs_qgroup_check_reserved_leak(struct inode *inode)
changeset.bytes_changed);
 
}
-   ulist_fini(_changed);
+   ulist_release(_changed);
 }
diff --git a/fs/btrfs/ulist.c b/fs/btrfs/ulist.c
index 5deee56434fc..d8edf164f81c 100644
--- a/fs/btrfs/ulist.c
+++ b/fs/btrfs/ulist.c
@@ -52,13 +52,13 @@ void ulist_init(struct ulist *ulist)
 }
 
 /**
- * ulist_fini - free up additionally allocated memory for the ulist
+ * ulist_release - free up additionally allocated memory for the ulist
  * @ulist: the ulist from which to free the additional memory
  *
  * This is useful in cases where the base 'struct ulist' has been statically
  * allocated.
  */
-void ulist_fini(struct ulist *ulist)
+void ulist_release(struct ulist *ulist)
 {
struct ulist_node *node;
struct ulist_node *next;
@@ -79,7 +79,7 @@ void ulist_fini(struct ulist *ulist)
  */
 void ulist_reinit(struct ulist *ulist)
 {
-   ulist_fini(ulist);
+   ulist_release(ulist);
ulist_init(ulist);
 }
 
@@ -105,13 +105,13 @@ struct ulist *ulist_alloc(gfp_t gfp_mask)
  * ulist_free - free dynamically allocated ulist
  * @ulist: ulist to free
  *
- * It is not necessary to call ulist_fini before.
+ * It is not necessary to call ulist_release before.
  */
 void ulist_free(struct ulist *ulist)
 {
if (!ulist)
return;
-   ulist_fini(ulist);
+   ulist_release(ulist);
kfree(ulist);
 }
 
diff --git a/fs/btrfs/ulist.h b/fs/btrfs/ulist.h
index 1a4130443d7e..53c913632733 100644
--- a/fs/btrfs/ulist.h
+++ b/fs/btrfs/ulist.h
@@ -44,7 +44,7 @@ struct ulist {
 };
 
 void ulist_init(struct ulist *ulist);
-void ulist_fini(struct ulist *ulist);
+void ulist_release(struct ulist *ulist);
 void ulist_reinit(struct ulist *ulist);
 struct ulist *ulist_alloc(gfp_t gfp_mask);
 void ulist_free(struct ulist *ulist);
-- 
2.10.1

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


Re: [PATCH 17/29] btrfs: remove unused parameter from extent_write_cache_pages

2017-02-15 Thread David Sterba
On Tue, Feb 14, 2017 at 11:35:11AM -0800, Liu Bo wrote:
> On Mon, Feb 13, 2017 at 10:34:13AM +0100, David Sterba wrote:
> > The 'tree' was used to call locking hook that does not exist anymore.
> > 
> > Signed-off-by: David Sterba 
> > ---
> >  fs/btrfs/extent_io.c | 6 ++
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> > index f683fa5a4b91..22a2f2fa62c7 100644
> > --- a/fs/btrfs/extent_io.c
> > +++ b/fs/btrfs/extent_io.c
> > @@ -3916,8 +3916,7 @@ int btree_write_cache_pages(struct address_space 
> > *mapping,
> >   * WB_SYNC_ALL then we were called for data integrity and we must wait for
> >   * existing IO to complete.
> >   */
> > -static int extent_write_cache_pages(struct extent_io_tree *tree,
> > -struct address_space *mapping,
> > +static int extent_write_cache_pages(struct address_space *mapping,
> >  struct writeback_control *wbc,
> >  writepage_t writepage, void *data,
> >  void (*flush_fn)(void *))
> > @@ -4158,8 +4157,7 @@ int extent_writepages(struct extent_io_tree *tree,
> > .bio_flags = 0,
> > };
> >  
> > -   ret = extent_write_cache_pages(tree, mapping, wbc,
> > -  __extent_writepage, ,
> > +   ret = extent_write_cache_pages(mapping, wbc, __extent_writepage, ,
> >flush_write_bio);
> 
> Are we going to leave {btrfs,extent}_{read,write}pages untouched?

Yes, because extent_writepages uses 'tree', it's stored in the
extent_page_data, and some if not all callbacks do utilize it.

4140 int extent_writepages(struct extent_io_tree *tree,
4141   struct address_space *mapping,
4142   get_extent_t *get_extent,
4143   struct writeback_control *wbc)
4144 {
4145 int ret = 0;
4146 struct extent_page_data epd = {
4147 .bio = NULL,
4148 .tree = tree,

4149 .get_extent = get_extent,
4150 .extent_locked = 0,
4151 .sync_io = wbc->sync_mode == WB_SYNC_ALL,
4152 .bio_flags = 0,
4153 };

btrfs_readpages
  extent_readpages
__extent_readpages
  __do_contiguous_readpages
lock_extent

and btrfs_writepages calls extent_writepages.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 14/29] btrfs: remove unused parameter from submit_extent_page

2017-02-15 Thread David Sterba
On Tue, Feb 14, 2017 at 11:10:32AM -0800, Liu Bo wrote:
> @pnr is only used here, it can be removed, too.
> 
> So does @max_nr.

Right, thanks. Patch udpated. I've tried if this can be caught by
'-Wunused-but-set-variable', strangely only max_nr is reported:

fs/btrfs/extent_io.c: In function ‘__extent_writepage_io’:
fs/btrfs/extent_io.c:3368:17: warning: variable ‘max_nr’ set but not used 
[-Wunused-but-set-variable]
   unsigned long max_nr;
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: FS gives kernel UPS on attempt to create snapshot and after running balance it's unmountable.

2017-02-15 Thread Tomasz Kusmierz
So guys, any help here ? I’m kinda stuck now with system just idling and doing 
nothing while I wait for some feedback ...
> On 14 Feb 2017, at 19:38, Tomasz Kusmierz  wrote:
> 
> [root@server ~]#  btrfs-show-super -af /dev/sdc
> superblock: bytenr=65536, device=/dev/sdc
> -
> csum_type   0 (crc32c)
> csum_size   4
> csum0x17d56ce0 [match]
> bytenr  65536
> flags   0x1
>( WRITTEN )
> magic   _BHRfS_M [match]
> fsid0576d577-8954-4a60-a02b-9492b3c29318
> label   main_pool
> generation  150682
> root5223857717248
> sys_array_size  321
> chunk_root_generation   150678
> root_level  1
> chunk_root  8669488005120
> chunk_root_level1
> log_root0
> log_root_transid0
> log_root_level  0
> total_bytes 16003191472128
> bytes_used  6411278503936
> sectorsize  4096
> nodesize16384
> leafsize16384
> stripesize  4096
> root_dir6
> num_devices 8
> compat_flags0x0
> compat_ro_flags 0x0
> incompat_flags  0x161
>( MIXED_BACKREF |
>  BIG_METADATA |
>  EXTENDED_IREF |
>  SKINNY_METADATA )
> cache_generation150682
> uuid_tree_generation150679
> dev_item.uuid   46abffa8-7afe-451f-93c6-abb8e589c4e8
> dev_item.fsid   0576d577-8954-4a60-a02b-9492b3c29318 [match]
> dev_item.type   0
> dev_item.total_bytes2000398934016
> dev_item.bytes_used 1647136735232
> dev_item.io_align   4096
> dev_item.io_width   4096
> dev_item.sector_size4096
> dev_item.devid  1
> dev_item.dev_group  0
> dev_item.seek_speed 0
> dev_item.bandwidth  0
> dev_item.generation 0
> sys_chunk_array[2048]:
>item 0 key (FIRST_CHUNK_TREE CHUNK_ITEM 8669487824896)
>length 67108864 owner 2 stripe_len 65536 type SYSTEM|RAID10
>io_align 65536 io_width 65536 sector_size 4096
>num_stripes 8 sub_stripes 2
>stripe 0 devid 7 offset 1083674984448
>dev_uuid 566fb8a3-d6de-4230-8b70-a5fda0a120f6
>stripe 1 devid 8 offset 1083674984448
>dev_uuid 845aefb2-e0a6-479a-957b-a82fb7207d6c
>stripe 2 devid 1 offset 1365901312
>dev_uuid 46abffa8-7afe-451f-93c6-abb8e589c4e8
>stripe 3 devid 3 offset 1345978368
>dev_uuid 95921633-2fc1-479f-a3ba-e6e5a1989755
>stripe 4 devid 4 offset 1345978368
>dev_uuid 20828f0e-4661-4987-ac11-72814c1e423a
>stripe 5 devid 5 offset 1345978368
>dev_uuid 2c3cd71f-5178-48e7-8032-6b6eec023197
>stripe 6 devid 6 offset 1345978368
>dev_uuid 806a47e5-cac4-41c9-abb9-5c49506459e1
>stripe 7 devid 2 offset 1345978368
>dev_uuid e1358e0e-edaf-4505-9c71-ed0862c45841
> backup_roots[4]:
>backup 0:
>backup_tree_root:   5223857717248   gen: 150680 level: 
> 1
>backup_chunk_root:  8669488005120   gen: 150678 level: 
> 1
>backup_extent_root: 5223867383808   gen: 150680 level: 
> 2
>backup_fs_root: 0   gen: 0  level: 0
>backup_dev_root:5224791523328   gen: 150680 level: 
> 1
>backup_csum_root:   5224802140160   gen: 150680 level: 
> 3
>backup_total_bytes: 16003191472128
>backup_bytes_used:  6411278503936
>backup_num_devices: 8
> 
>backup 1:
>backup_tree_root:   5224155807744   gen: 150681 level: 
> 1
>backup_chunk_root:  8669488005120   gen: 150678 level: 
> 1
>backup_extent_root: 5224156233728   gen: 150681 level: 
> 2
>backup_fs_root: 0   gen: 0  level: 0
>backup_dev_root:5224633155584   gen: 150681 level: 
> 1
>backup_csum_root:   5224634941440   gen: 150681 level: 
> 3
>backup_total_bytes: 16003191472128
>backup_bytes_used:  6411278503936
>backup_num_devices: 8
> 
>backup 2:
>backup_tree_root:   5223857717248   gen: 150682 level: 
> 1
>backup_chunk_root:  8669488005120   gen: 150678 level: 
> 1
>

Re: [PATCH] btrfs-progs: misc-tests: Primary Superblock corruption and recovery using backup Superblock.

2017-02-15 Thread Lakshmipathi.G
On Wed, Feb 15, 2017 at 09:36:03AM +0800, Qu Wenruo wrote:
> 
> 
> >+# Corrupt superblock checksum
> >+dd if=/dev/zero of=$TEST_DEV seek=$superblock_offset bs=1 \
> >+count=4  conv=notrunc &> /dev/null
> >+run_check_stdout $SUDO_HELPER mount $TEST_DEV $TEST_MNT | \
> >+grep -q 'wrong fs type'
> 
> What about using btrfs check instead of trying to mount it?
> 
> This could emit the need to use $SUDO_HELPER, and could catch super error
> more accurate.
> 
> >+if [ $? -ne 0 ]; then
> >+_fail "Failed to corrupt superblock."
> >+fi
> >+
> >+# Copy backup superblock to primary
> >+run_check $TOP/btrfs-select-super -s 1 $TEST_DEV
> >+run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT
> Same here.
I started with 'btrfs check' and 'btrfs check --repair' but it seems like
--repair don't fix the corruption. So just moved away from using it.

After you mentioned, now I see 'btrfs check' will be helpful. Will make
these changes. 

Cheers.
Lakshmipathi.G
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] btrfs-progs: RAID5:Inject data stripe corruption and verify scrub fixes it.

2017-02-15 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G 
---
 .../020-raid5-datastripe-corruption/test.sh| 224 +
 1 file changed, 224 insertions(+)
 create mode 100755 tests/misc-tests/020-raid5-datastripe-corruption/test.sh

diff --git a/tests/misc-tests/020-raid5-datastripe-corruption/test.sh 
b/tests/misc-tests/020-raid5-datastripe-corruption/test.sh
new file mode 100755
index 000..d04c430
--- /dev/null
+++ b/tests/misc-tests/020-raid5-datastripe-corruption/test.sh
@@ -0,0 +1,224 @@
+#!/bin/bash
+#
+# Raid5: Inject data stripe corruption and fix them using scrub.
+# 
+# Script will perform the following:
+# 1) Create Raid5 using 3 loopback devices.
+# 2) Ensure file layout is created in a predictable manner. 
+#Each data stripe(64KB) should uniquely start with 'DN',   
+#where N represents the data stripe number.(ex:D0,D1 etc)
+# 3) Once file is created with specific layout, gather data stripe details 
+#like devicename, position and actual on-disk data.
+# 4) Now use 'dd' to verify the data-stripe against its expected value
+#and inject corruption by zero'ing out contents.
+# 5) After injecting corruption, running online-scrub is expected to fix 
+#the corrupted data stripe with the help of parity block and 
+#corresponding data stripe.
+# 6) Finally, validate the data stripe has original un-corrupted value.
+#
+#  Note: This script doesn't handle parity block corruption.
+
+source $TOP/tests/common
+
+check_prereq btrfs
+check_prereq mkfs.btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+ndevs=3
+declare -a devs
+device_name=""
+stripe_offset=""
+stripe_content=""
+
+LAYOUT_TMP=$(mktemp --tmpdir btrfs-progs-raid5-file.layoutXX)
+STRIPEINFO_TMP=$(mktemp --tmpdir btrfs-progs-raid5-file.infoXX)
+
+prepare_devices()
+{
+   for i in `seq $ndevs`; do
+   touch img$i
+   chmod a+rw img$i
+   truncate -s0 img$i
+   truncate -s512M img$i
+   devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show 
img$i`
+   done
+}
+
+cleanup_devices()
+{
+   for dev in ${devs[@]}; do
+   run_check $SUDO_HELPER losetup -d $dev
+   done
+   for i in `seq $ndevs`; do
+   truncate -s0 img$i
+   done
+   run_check $SUDO_HELPER losetup --all
+}
+
+test_do_mkfs()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f   \
+   $@
+}
+
+test_mkfs_multi()
+{
+   test_do_mkfs $@ ${devs[@]}
+}
+
+#$1 Filename
+#$2 Expected no.of data stripes for the file.
+create_layout(){
+   fname=$1
+   size=$(( $2 * 65536 ))
+   n=0
+   bs_value=1
+   stripe=0
+   while (( $n < $size ))
+   do
+   if [ $(( $n % 65536 )) -eq 0 ]; then
+   val='D'$stripe
+   echo -n $val
+   stripe=$(( $stripe+1 ))
+   # ensure proper value   
+   bs_value=`echo "${#val}"` 
+   else
+   echo -n 'x'
+   bs_value=1
+   fi
+n=$(( $n+$bs_value ))
+   done | dd of="$TEST_MNT"/$fname bs=$bs_value conv=notrunc &> /dev/null
+}
+
+find_data_stripe_details(){
+   for dev in ${devs[@]}; do
+   echo $dev >> $LAYOUT_TMP
+   $SUDO_HELPER cat $dev | hexdump -e '"%010_ad|" 16/1 "%_p" 
"|\n"' |
+   grep -P 'D[0-9]+xx'  >> $LAYOUT_TMP
+   done
+}
+
+#Collect data stripe information in a readable manner.
+save_data_stripe_details(){
+   devname=""
+   for entry in `cat $LAYOUT_TMP`; do  
+   echo $entry | grep -q '^\/dev\/loop' > /dev/null
+
+   if [ $? -eq 0 ]; then
+   devname=$entry  
+   else
+   echo $devname"|"$entry >> $STRIPEINFO_TMP
+   fi
+   done
+   #Order by data stripe. D0 comes before D1.
+   sort -t'|'  -k3 $STRIPEINFO_TMP -o $STRIPEINFO_TMP
+}
+
+#Corrupt given data stripe
+corrupt_data_stripe(){
+
+   data_stripe_num=$1
+   data_stripe_entry="D"${data_stripe_num}""
+   stripe_entry=`grep "${data_stripe_entry}" $STRIPEINFO_TMP`
+
+   #Each entry will have format like "device|position|16-byte content"
+   #Example: /dev/loop1|0063176704|D0xx|
+   device_name=$(echo $stripe_entry | awk -F"|" '{print $1}')
+   stripe_offset=$(echo $stripe_entry | awk -F"|" '{print $2}')
+   #Remove leading zeros
+   stripe_offset=$(echo $stripe_offset | sed 's/^0*//')
+   stripe_content=$(echo $stripe_entry | awk -F"|" '{print $3}')
+
+   echo "Corrupting $device_name at position $stripe_offset \
+   which has $stripe_content" >> "$RESULTS"
+
+   #verify the value at this position 
+   original_value=$($SUDO_HELPER dd 2>/dev/null if=$device_name bs=1 \
+   count=16 skip=$stripe_offset)
+
+   if [ $original_value != $stripe_content 

[PATCH] btrfs: Handle btrfs_reloc_clone_csums error correctly to avoid deadlock

2017-02-15 Thread Qu Wenruo
If run btrfs/125 with nospace_cache or space_cache=v2 mount option,
btrfs will block with the following backtrace:

Call Trace:
 __schedule+0x2d4/0xae0
 schedule+0x3d/0x90
 btrfs_start_ordered_extent+0x160/0x200 [btrfs]
 ? wake_atomic_t_function+0x60/0x60
 btrfs_run_ordered_extent_work+0x25/0x40 [btrfs]
 btrfs_scrubparity_helper+0x1c1/0x620 [btrfs]
 btrfs_flush_delalloc_helper+0xe/0x10 [btrfs]
 process_one_work+0x2af/0x720
 ? process_one_work+0x22b/0x720
 worker_thread+0x4b/0x4f0
 kthread+0x10f/0x150
 ? process_one_work+0x720/0x720
 ? kthread_create_on_node+0x40/0x40
 ret_from_fork+0x2e/0x40

The direct cause is the error handler in run_delalloc_nocow() doesn't
handle error from btrfs_reloc_clone_csums() well.

The related part call path will be:
__extent_writepage
|- writepage_delalloc()
|  |- run_delalloc_range()
| |- run_delalloc_nocow()
||- btrfs_add_ordered_extent()
||  Now one ordered extent for file range, e.g [0, 1M) is inserted
||
||- btrfs_reloc_clone_csums()
||  Fails with -EIO, as RAID5/6 doesn't repair some csum tree
||  blocks
||
||- extent_clear_unlock_delalloc()
|   Error routine, unlock and clear page DIRTY, end page writeback
|   So the remaining 255 pages will not go through writeback
|
|- __extent_writepage_io()
   |- writepage_end_io_hook()  
  |- btrfs_dev_test_ordered_pending()
 Reduce ordered_extent->bytes_left by 4K.
 Still have (1M - 4K) to finish.

While the remaining 255 pages will not go through IO nor trigger
writepage_end_io_hook(), the ordered extent for [0, 1M) will
never finish, and blocking current transaction forever.

Although the root cause is still in RAID5/6, it won't hurt to fix the
error routine first.

This patch will cleanup the ordered extent in error routine, so at least
we won't cause deadlock.

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/extent_io.c|  1 -
 fs/btrfs/inode.c| 10 --
 fs/btrfs/ordered-data.c | 25 +
 fs/btrfs/ordered-data.h | 10 ++
 4 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 4ac383a3a649..a14d1b0840c5 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3258,7 +3258,6 @@ static noinline_for_stack int writepage_delalloc(struct 
inode *inode,
   delalloc_end,
   _started,
   nr_written);
-   /* File system has been set read-only */
if (ret) {
SetPageError(page);
/* fill_delalloc should be return < 0 for error
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1e861a063721..3c3ade58afd7 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1052,8 +1052,11 @@ static noinline int cow_file_range(struct inode *inode,
BTRFS_DATA_RELOC_TREE_OBJECTID) {
ret = btrfs_reloc_clone_csums(inode, start,
  cur_alloc_size);
-   if (ret)
+   if (ret) {
+   btrfs_clean_ordered_extent(inode, start,
+  ram_size);
goto out_drop_extent_cache;
+   }
}
 
btrfs_dec_block_group_reservations(fs_info, ins.objectid);
@@ -1538,7 +1541,7 @@ static noinline int run_delalloc_nocow(struct inode 
*inode,
if (!ret)
ret = err;
 
-   if (ret && cur_offset < end)
+   if (ret && cur_offset < end) {
extent_clear_unlock_delalloc(inode, cur_offset, end, end,
 locked_page, EXTENT_LOCKED |
 EXTENT_DELALLOC | EXTENT_DEFRAG |
@@ -1546,6 +1549,9 @@ static noinline int run_delalloc_nocow(struct inode 
*inode,
 PAGE_CLEAR_DIRTY |
 PAGE_SET_WRITEBACK |
 PAGE_END_WRITEBACK);
+   btrfs_clean_ordered_extent(inode, cur_offset,
+  end - cur_offset + 1);
+   }
btrfs_free_path(path);
return ret;
 }
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 041c3326d109..dba1cf3464a7 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -650,6 +650,31 @@ void btrfs_remove_ordered_extent(struct inode *inode,
wake_up(>wait);
 }
 
+void btrfs_clean_ordered_extent(struct inode *inode, u64 file_offset,
+   u64 ram_len)
+{
+   struct btrfs_ordered_extent *entry;
+   struct btrfs_root *root = BTRFS_I(inode)->root;
+
+   entry =