Re: [Question]: Contributing to btrfs

2016-02-21 Thread Philippe Loctaux
On Mon, Feb 22, 2016 at 09:18:04AM +0800, Qu Wenruo wrote:
> https://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git
> For branch, normally I use 'integration-X.X' as base for kernel development.
> 
> And for btrfs-progs,
> https://github.com/kdave/btrfs-progs.git devel

Allright, I'll work from these repos!

Is it fine if I work from Linus's repo?
Will my patches get rejected if I do so?

--
Philippe Loctaux
p...@philippeloctaux.com
--
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: [Question]: Contributing to btrfs

2016-02-21 Thread Qu Wenruo



Philippe Loctaux wrote on 2016/02/22 08:26 +0100:

On Mon, Feb 22, 2016 at 09:18:04AM +0800, Qu Wenruo wrote:

https://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git
For branch, normally I use 'integration-X.X' as base for kernel development.

And for btrfs-progs,
https://github.com/kdave/btrfs-progs.git devel


Allright, I'll work from these repos!

Is it fine if I work from Linus's repo?
Will my patches get rejected if I do so?


It depends.
If it's just small fix, and can be applied on Chris' integration branch, 
that's OK.


In that case, just submit patches to mail list, and if it's OK, 
maintainers like David will pick and rebase them properly.


But for huge modifications, it's recommended to use integration branch, 
as the final pull request is sent to btrfs maintainer Chris, not Linus.


Although all above is just my personal experience, other developers may 
give better advice though.


Thanks,
Qu



--
Philippe Loctaux
p...@philippeloctaux.com





--
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 0/5] btrfs-find-root enhancement for chunk tree corrupted fs

2016-02-21 Thread Qu Wenruo

This patchset can also be fetched from github:
https://github.com/adam900710/btrfs-progs.git syschunk_find_root_20160222

Thanks,
Qu

Qu Wenruo wrote on 2016/02/22 14:59 +0800:

Before this patchset, btrfs-find-root needs valid chunk tree from the
fs.
However for chunk root corrupted case, btrfs-find-root is of no use due
to above limitation.

This patchset will allow open_ctree_fs_info() to return a fs_info
without any valid tree root, but system chunk map from superblock only.
And modify btrfs-find-root along with some infrastructure to do chunk
root search.

Also fix an old bug where btrfs-find-root will always skip the first
chunk, with its corresponding regression test.

This also provides the basis for later "btrfsck --chunk-root" and faster
chunk-recovery enhancement.

Qu Wenruo (5):
   btrfs: volume: Fix a bug causing btrfs-find-root to skip first chunk
   btrfs: Allow open_ctree to return fs_info even chunk tree is corrupted
   btrfs: Add support for tree block operations on fs_info without roots.
   btrfs: find-root: Allow btrfs-find-root to search chunk root even
 chunk root is corrupted
   btrfs: misc-test: Add regression test for find-root gives empty result

  btrfs-corrupt-block.c  |   2 +-
  btrfs-find-root.c  |  17 ++--
  ctree.h|   1 +
  disk-io.c  |  99 +
  disk-io.h  |  35 ++--
  extent-tree.c  |   3 +-
  find-root.c|  10 +--
  find-root.h|   2 +-
  .../first_meta_chunk.btrfs-image   | Bin 0 -> 4096 bytes
  tests/misc-tests/012-find-root-no-result/test.sh   |  20 +
  volumes.c  |  20 +++--
  11 files changed, 147 insertions(+), 62 deletions(-)
  create mode 100644 
tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image
  create mode 100644 tests/misc-tests/012-find-root-no-result/test.sh




--
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/5] btrfs: volume: Fix a bug causing btrfs-find-root to skip first chunk

2016-02-21 Thread Qu Wenruo
There is a small bug from 2011, where btrfs_next_bg (formally
btrfs_next_metadata) function will always skip the first chunk.

That's OK for that time, as there is always 3 empty temporary chunks.
But now, we may ended up with only one metadata or system chunk, with
empty chunk auto-remove from kernel or new mkfs.btrfs.

So fix it by checking the initial value so btrfs_next_bg() will return
the first chunk if its *logical parameter is 0.

Signed-off-by: Qu Wenruo 
---
 volumes.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/volumes.c b/volumes.c
index a94be0e..059c4f4 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1170,14 +1170,23 @@ int btrfs_next_bg(struct btrfs_mapping_tree *map_tree, 
u64 *logical,
 {
struct cache_extent *ce;
struct map_lookup *map;
+   u64 cur = *logical;
 
-   ce = search_cache_extent(&map_tree->cache_tree, *logical);
+   ce = search_cache_extent(&map_tree->cache_tree, cur);
 
while (ce) {
-   ce = next_cache_extent(ce);
-   if (!ce)
-   return -ENOENT;
+   /*
+* only jump to next bg if our cur is not 0
+* As the initial logical for btrfs_next_bg() is 0, and
+* if we jump to next bg, we skipped a valid bg.
+*/
+   if (cur) {
+   ce = next_cache_extent(ce);
+   if (!ce)
+   return -ENOENT;
+   }
 
+   cur = ce->start;
map = container_of(ce, struct map_lookup, ce);
if (map->type & type) {
*logical = ce->start;
-- 
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/5] btrfs: misc-test: Add regression test for find-root gives empty result

2016-02-21 Thread Qu Wenruo
Add regression test for btrfs-find-root gives empty result even the fs
is OK.

Signed-off-by: Qu Wenruo 
---
 .../first_meta_chunk.btrfs-image| Bin 0 -> 4096 bytes
 tests/misc-tests/012-find-root-no-result/test.sh|  20 
 2 files changed, 20 insertions(+)
 create mode 100644 
tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image
 create mode 100644 tests/misc-tests/012-find-root-no-result/test.sh

diff --git 
a/tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image 
b/tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image
new file mode 100644
index 
..7bf6c50916f68ed00dae7627e848a91abf5455bb
GIT binary patch
literal 4096
zcmeH}doa}NAIGsQmda)AQE~}Ity*QRZLQcu=&WiZ6lHm`Zm
zT3n2yw&wS*>oxV$eiHae;D3lf=vz4tvI6I_G|}vcg0qnKG;F%tzx=vT`LU|1Dwm&l
zY#~&S$|xNUb(c-000fdb^0r&8Q5JKLui7G*TFq#n_)U;L@UhyJ+sKX4N}H3BiK-BI
zDrdtrk7@#LFe&y|#|m>6UC%HQ~{*OZBlge
z-LbiY;#jj&ovF$GF$dF!W4(-?XA#+ebabWZrc5i^VH2v|)HRZdF7YYt9r`|c+eH+k
zApcb8LB1QfZ2Yv#ASQuJK
zbCewXJOGlm&%~N98~6}aWNux>7>R@KaBc#FJH=a*g`+JRwkjz3p*J7r>@L#7&5-C4
zNAHIt<%etcS5E8Q9V4-Kwl#Pr58as&{jzq+{?!;oun808q}9qT+w1`tFmU)yK)km?
zVF6zvwO$7S-+Gw`mn?Heipl2YjEO&yusO-wreN%sKBweZueh<8;@^vfh+}O=g=q^z
z5wl+QFP?RNjv0*TcK2@+H1+gF3$P?*jd)BKmEF)jKEp(3gXfuf45m0+oMLH*1LUn|Tv6#oSsXn%(1mlr&lngYz^LSDWtJ
z3$r|~3LNgcW&ND77hb2eLtb0^h4y!GgyM;SI`5k{GGm*Hw`>j}C`4m$khsrk@&^q(
z!DGh)`w>o#aSBbd@vq!5{fU|Cilw%Tr=bAAs7k
zHFtO}c#I1~t~>F~ktrkPP-$Vy{L*WY`yyTx-4
z(Ze~DCf!j&JYLKkM>@SqYyfKm_So7mljhRXQqQU3Q8Wzp6~DCf@w`{aD>!mUvE3G`
z^Xdc)49QUqiI=Gy#S~a>IV9zw)bZr_m0}>K;TES-$}QJYI^%q{=)vr#)+veslWZ}LP`0@EtVskT4=v70rlK7SzFU4QGUHfvO;oaLW}U?_zE0v-fM!|
ziy%HQC8G<*9Rhhzq71(BDT%0_K-Cd@I>@Y--5{4c9uku0%iDjYYM6;{FX>}3c@Y2V
z0HZ_?9kp+kSS03a?(oZoxrx5Ok!)o+Qgmi<-+_woCT2(U?y71IyzKgr{|sagrbsd-
zlTkmgJ-oietEjF6`p`H+rS^lFeJ36%8I#30F6TQyV1X{NIPL>-rqx|iKd==Oa|X`2
zY*h5QSGV;2qx_-ozBntF2R%*cM?t<*j0eU#htLPFIn_QgyDmW8H4WlO>oJXwY8Ruoi%s9?-
zAV$3X75zne`>Cf8M+2cV2m(=!*iT0GIDNjK*CukRD(qd33d7@B2Xy4D%3TM6!uw`S
zjU4N9=k+oPBe@BGXa+B0cBt}>5d652F_K2y;RH$F6UzkL)!PvH1(kV<1<_H?|IHVg
z`i1z=w)fPtRO67)l7;O===i`3RIR7ou4?kPGPfUp_dm%qkZHO_qQ#{kA7?N2RU1Zy
z%Q(S{&BbvCGfF)d(xuYqD{!U9@LJ0U&eAMr>5^WQ19(EKc6g6EKRkwsIG8fX6?JHv
zKB1eiDyD0XXzB-_4f-I;x62S|j#&Pe2cbpdio_?_1Z(Y5dE{Gn4E$n-rk`t%Qfbez
zQ6JaGeZ)y|%j~VPa24fRt?D2?0K5pyvQw#48P|%{;;RKu;K*V
z1}*cwsZi?HUV)Envg_#rx?_N0SWTSSCFdUP&cyJ*G6EA+gAYI|=Uxe+dxO*}UH~^>ejWx*hXq44!tJhd<=FvyzH5wZC
zA}GrL`3QeIdg)w^i(C5r-$jn2OSESOZGFpc5^m2cCgLRjc8Y&wBj@6PxGhttp://vger.kernel.org/majordomo-info.html


[PATCH 2/5] btrfs: Allow open_ctree to return fs_info even chunk tree is corrupted

2016-02-21 Thread Qu Wenruo
Current open_ctree_fs_info() won't return anything if chunk tree root is
corrupted.
This makes some function, like btrfs-find-root unable to find any older
chunk tree root, even it is possible to use system_chunk_array in super
block.

And at least two users in mail list has reported such heavily chunk
corruption.
Although we have 'btrfs rescue chunk-recovery' but it's too time
consuming and sometimes buggy.

This patch adds a new open ctree flag,
OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR, allowing fs_info to be returned from
open_ctree_fs_info() even there is no valid tree root in it.

Also adds a new close_ctree() variant, close_ctree_fs_info() to handle
possible fs_info without any root.

Signed-off-by: Qu Wenruo 
---
 ctree.h   |  1 +
 disk-io.c | 29 -
 disk-io.h | 18 --
 3 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/ctree.h b/ctree.h
index 21b0445..5ab0f4a 100644
--- a/ctree.h
+++ b/ctree.h
@@ -1029,6 +1029,7 @@ struct btrfs_fs_info {
unsigned int quota_enabled:1;
unsigned int suppress_check_block_errors:1;
unsigned int ignore_fsid_mismatch:1;
+   unsigned int ignore_chunk_tree_error:1;
 
int (*free_extent_hook)(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
diff --git a/disk-io.c b/disk-io.c
index bd0444b..3b5a08e 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1168,8 +1168,14 @@ int btrfs_setup_chunk_tree_and_device_map(struct 
btrfs_fs_info *fs_info)
btrfs_super_chunk_root(sb),
blocksize, generation);
if (!extent_buffer_uptodate(fs_info->chunk_root->node)) {
-   fprintf(stderr, "Couldn't read chunk root\n");
-   return -EIO;
+   if (fs_info->ignore_chunk_tree_error) {
+   error("Couldn't read chunk root, continue anyway");
+   fs_info->chunk_root = NULL;
+   return 0;
+   } else {
+   error("Couldn't read chunk rootn");
+   return -EIO;
+   }
}
 
if (!(btrfs_super_flags(sb) & BTRFS_SUPER_FLAG_METADUMP)) {
@@ -1212,6 +1218,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, 
const char *path,
fs_info->suppress_check_block_errors = 1;
if (flags & OPEN_CTREE_IGNORE_FSID_MISMATCH)
fs_info->ignore_fsid_mismatch = 1;
+   if (flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR)
+   fs_info->ignore_chunk_tree_error = 1;
 
ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr,
(flags & OPEN_CTREE_RECOVER_SUPER),
@@ -1260,13 +1268,18 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, 
const char *path,
if (ret)
goto out_chunk;
 
+   /* Chunk tree root is unable to read, return directly */
+   if (!fs_info->chunk_root)
+   return fs_info;
+
eb = fs_info->chunk_root->node;
read_extent_buffer(eb, fs_info->chunk_tree_uuid,
   btrfs_header_chunk_tree_uuid(eb),
   BTRFS_UUID_SIZE);
 
ret = btrfs_setup_all_roots(fs_info, root_tree_bytenr, flags);
-   if (ret && !(flags & __OPEN_CTREE_RETURN_CHUNK_ROOT))
+   if (ret && !(flags & __OPEN_CTREE_RETURN_CHUNK_ROOT) &&
+   !fs_info->ignore_chunk_tree_error)
goto out_chunk;
 
return fs_info;
@@ -1308,6 +1321,8 @@ struct btrfs_root *open_ctree(const char *filename, u64 
sb_bytenr,
 {
struct btrfs_fs_info *info;
 
+   /* This flags may not return fs_info with any valid root */
+   BUG_ON(flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR);
info = open_ctree_fs_info(filename, sb_bytenr, 0, flags);
if (!info)
return NULL;
@@ -1320,6 +1335,9 @@ struct btrfs_root *open_ctree_fd(int fp, const char 
*path, u64 sb_bytenr,
 enum btrfs_open_ctree_flags flags)
 {
struct btrfs_fs_info *info;
+
+   /* This flags may not return fs_info with any valid root */
+   BUG_ON(flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR);
info = __open_ctree_fd(fp, path, sb_bytenr, 0, flags);
if (!info)
return NULL;
@@ -1658,14 +1676,15 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
return ret;
 }
 
-int close_ctree(struct btrfs_root *root)
+int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
 {
int ret;
struct btrfs_trans_handle *trans;
-   struct btrfs_fs_info *fs_info = root->fs_info;
+   struct btrfs_root *root = fs_info->tree_root;
 
if (fs_info->last_trans_committed !=
fs_info->generation) {
+   BUG_ON(!root);
trans = btrfs_start_transaction(root, 1);
btrfs_commit_transaction(trans, root);
trans

[PATCH 4/5] btrfs: find-root: Allow btrfs-find-root to search chunk root even chunk root is corrupted

2016-02-21 Thread Qu Wenruo
Since now open_ctree_fs_info() can even return a valid fs_info with only
system chunk mapping from super block, use this ability to do chunk root
search for heavily damanged fs.

As an fast alternative for time consuming and buggy chunk-recovery.

Signed-off-by: Qu Wenruo 
---
 btrfs-find-root.c | 17 +
 find-root.c   | 10 +-
 find-root.h   |  2 +-
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/btrfs-find-root.c b/btrfs-find-root.c
index fc3812c..3d268cb 100644
--- a/btrfs-find-root.c
+++ b/btrfs-find-root.c
@@ -69,7 +69,6 @@ static void get_root_gen_and_level(u64 objectid, struct 
btrfs_fs_info *fs_info,
case BTRFS_CHUNK_TREE_OBJECTID:
level = btrfs_super_chunk_root_level(super);
gen = btrfs_super_chunk_root_generation(super);
-   printf("Search for chunk root is not supported yet\n");
break;
case BTRFS_TREE_LOG_OBJECTID:
level = btrfs_super_log_root_level(super);
@@ -145,7 +144,7 @@ static void print_find_root_result(struct cache_tree 
*result,
 
 int main(int argc, char **argv)
 {
-   struct btrfs_root *root;
+   struct btrfs_fs_info *fs_info;
struct btrfs_find_root_filter filter = {0};
struct cache_tree result;
struct cache_extent *found;
@@ -192,16 +191,18 @@ int main(int argc, char **argv)
exit(1);
}
 
-   root = open_ctree(argv[optind], 0, OPEN_CTREE_CHUNK_ROOT_ONLY);
-   if (!root) {
-   fprintf(stderr, "Open ctree failed\n");
+   fs_info = open_ctree_fs_info(argv[optind], 0, 0,
+   OPEN_CTREE_CHUNK_ROOT_ONLY |
+   OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR);
+   if (!fs_info) {
+   error("Open ctree failed\n");
exit(1);
}
cache_tree_init(&result);
 
-   get_root_gen_and_level(filter.objectid, root->fs_info,
+   get_root_gen_and_level(filter.objectid, fs_info,
   &filter.match_gen, &filter.match_level);
-   ret = btrfs_find_root_search(root, &filter, &result, &found);
+   ret = btrfs_find_root_search(fs_info, &filter, &result, &found);
if (ret < 0) {
fprintf(stderr, "Fail to search the tree root: %s\n",
strerror(-ret));
@@ -215,7 +216,7 @@ int main(int argc, char **argv)
print_find_root_result(&result, &filter);
 out:
btrfs_find_root_free(&result);
-   close_ctree(root);
+   close_ctree_fs_info(fs_info);
btrfs_close_all_devices();
return ret;
 }
diff --git a/find-root.c b/find-root.c
index f0204c8..823db6a 100644
--- a/find-root.c
+++ b/find-root.c
@@ -101,17 +101,16 @@ static int add_eb_to_result(struct extent_buffer *eb,
  * Return 1 if found root with given gen/level and set *match to it.
  * Return <0 if error happens
  */
-int btrfs_find_root_search(struct btrfs_root *chunk_root,
+int btrfs_find_root_search(struct btrfs_fs_info *fs_info,
   struct btrfs_find_root_filter *filter,
   struct cache_tree *result,
   struct cache_extent **match)
 {
-   struct btrfs_fs_info *fs_info = chunk_root->fs_info;
struct extent_buffer *eb;
u64 chunk_offset = 0;
u64 chunk_size = 0;
u64 offset = 0;
-   u32 leafsize = chunk_root->leafsize;
+   u32 leafsize = btrfs_super_leafsize(fs_info->super_copy);
int suppress_errors = 0;
int ret = 0;
 
@@ -133,8 +132,9 @@ int btrfs_find_root_search(struct btrfs_root *chunk_root,
}
for (offset = chunk_offset;
 offset < chunk_offset + chunk_size;
-offset += chunk_root->leafsize) {
-   eb = read_tree_block(chunk_root, offset, leafsize, 0);
+offset += leafsize) {
+   eb = read_tree_block_fs_info(fs_info, offset, leafsize,
+0);
if (!eb || IS_ERR(eb))
continue;
ret = add_eb_to_result(eb, result, leafsize, filter,
diff --git a/find-root.h b/find-root.h
index 1c67ebc..60d 100644
--- a/find-root.h
+++ b/find-root.h
@@ -65,7 +65,7 @@ struct btrfs_find_root_filter {
 * This *WILL* take *TONS* of extra time.
 */
 };
-int btrfs_find_root_search(struct btrfs_root *chunk_root,
+int btrfs_find_root_search(struct btrfs_fs_info *fs_info,
   struct btrfs_find_root_filter *filter,
   struct cache_tree *result,
   struct cache_extent **match);
-- 
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 3/5] btrfs: Add support for tree block operations on fs_info without roots.

2016-02-21 Thread Qu Wenruo
Since open_ctree_fs_info() now may return a fs_info even without any
roots, modify functions like read_tree_block() to operate with such
fs_info.

This provides the basis for btrfs-find-root to operate on chunk tree
corrupted fs.

Signed-off-by: Qu Wenruo 
---
 btrfs-corrupt-block.c |  2 +-
 disk-io.c | 70 +--
 disk-io.h | 17 ++---
 extent-tree.c |  3 ++-
 volumes.c |  3 ++-
 5 files changed, 58 insertions(+), 37 deletions(-)

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index c908b7e..be5cd7e 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -45,7 +45,7 @@ static struct extent_buffer *debug_corrupt_block(struct 
btrfs_root *root,
int num_copies;
int mirror_num = 1;
 
-   eb = btrfs_find_create_tree_block(root, bytenr, blocksize);
+   eb = btrfs_find_create_tree_block(root->fs_info, bytenr, blocksize);
if (!eb)
return NULL;
 
diff --git a/disk-io.c b/disk-io.c
index 3b5a08e..51a4930 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -51,10 +51,12 @@ static u32 max_nritems(u8 level, u32 nodesize)
sizeof(struct btrfs_key_ptr));
 }
 
-static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
+static int check_tree_block(struct btrfs_fs_info *fs_info,
+   struct extent_buffer *buf)
 {
 
struct btrfs_fs_devices *fs_devices;
+   u32 leafsize = btrfs_super_leafsize(fs_info->super_copy);
int ret = BTRFS_BAD_FSID;
 
if (buf->start != btrfs_header_bytenr(buf))
@@ -62,12 +64,12 @@ static int check_tree_block(struct btrfs_root *root, struct 
extent_buffer *buf)
if (btrfs_header_level(buf) >= BTRFS_MAX_LEVEL)
return BTRFS_BAD_LEVEL;
if (btrfs_header_nritems(buf) > max_nritems(btrfs_header_level(buf),
-   root->nodesize))
+   leafsize))
return BTRFS_BAD_NRITEMS;
 
-   fs_devices = root->fs_info->fs_devices;
+   fs_devices = fs_info->fs_devices;
while (fs_devices) {
-   if (root->fs_info->ignore_fsid_mismatch ||
+   if (fs_info->ignore_fsid_mismatch ||
!memcmp_extent_buffer(buf, fs_devices->fsid,
  btrfs_header_fsid(),
  BTRFS_FSID_SIZE)) {
@@ -79,7 +81,7 @@ static int check_tree_block(struct btrfs_root *root, struct 
extent_buffer *buf)
return ret;
 }
 
-static void print_tree_block_error(struct btrfs_root *root,
+static void print_tree_block_error(struct btrfs_fs_info *fs_info,
struct extent_buffer *eb,
int err)
 {
@@ -92,7 +94,7 @@ static void print_tree_block_error(struct btrfs_root *root,
read_extent_buffer(eb, buf, btrfs_header_fsid(),
   BTRFS_UUID_SIZE);
uuid_unparse(buf, found_uuid);
-   uuid_unparse(root->fs_info->fsid, fs_uuid);
+   uuid_unparse(fs_info->fsid, fs_uuid);
fprintf(stderr, "fsid mismatch, want=%s, have=%s\n",
fs_uuid, found_uuid);
break;
@@ -157,16 +159,22 @@ int verify_tree_block_csum_silent(struct extent_buffer 
*buf, u16 csum_size)
return __csum_tree_block_size(buf, csum_size, 1, 1);
 }
 
-int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
-  int verify)
+static int csum_tree_block_fs_info(struct btrfs_fs_info *fs_info,
+  struct extent_buffer *buf, int verify)
 {
u16 csum_size =
-   btrfs_super_csum_size(root->fs_info->super_copy);
-   if (verify && root->fs_info->suppress_check_block_errors)
+   btrfs_super_csum_size(fs_info->super_copy);
+   if (verify && fs_info->suppress_check_block_errors)
return verify_tree_block_csum_silent(buf, csum_size);
return csum_tree_block_size(buf, csum_size, verify);
 }
 
+int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
+  int verify)
+{
+   return csum_tree_block_fs_info(root->fs_info, buf, verify);
+}
+
 struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
u64 bytenr, u32 blocksize)
 {
@@ -174,11 +182,11 @@ struct extent_buffer *btrfs_find_tree_block(struct 
btrfs_root *root,
  bytenr, blocksize);
 }
 
-struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
-u64 bytenr, u32 blocksize)
+struct extent_buffer *
+btrfs_find_create_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
+u32 blocksize)
 {
-   return alloc_extent_buffer

[PATCH 0/5] btrfs-find-root enhancement for chunk tree corrupted fs

2016-02-21 Thread Qu Wenruo
Before this patchset, btrfs-find-root needs valid chunk tree from the
fs.
However for chunk root corrupted case, btrfs-find-root is of no use due
to above limitation.

This patchset will allow open_ctree_fs_info() to return a fs_info
without any valid tree root, but system chunk map from superblock only.
And modify btrfs-find-root along with some infrastructure to do chunk
root search.

Also fix an old bug where btrfs-find-root will always skip the first
chunk, with its corresponding regression test.

This also provides the basis for later "btrfsck --chunk-root" and faster
chunk-recovery enhancement.

Qu Wenruo (5):
  btrfs: volume: Fix a bug causing btrfs-find-root to skip first chunk
  btrfs: Allow open_ctree to return fs_info even chunk tree is corrupted
  btrfs: Add support for tree block operations on fs_info without roots.
  btrfs: find-root: Allow btrfs-find-root to search chunk root even
chunk root is corrupted
  btrfs: misc-test: Add regression test for find-root gives empty result

 btrfs-corrupt-block.c  |   2 +-
 btrfs-find-root.c  |  17 ++--
 ctree.h|   1 +
 disk-io.c  |  99 +
 disk-io.h  |  35 ++--
 extent-tree.c  |   3 +-
 find-root.c|  10 +--
 find-root.h|   2 +-
 .../first_meta_chunk.btrfs-image   | Bin 0 -> 4096 bytes
 tests/misc-tests/012-find-root-no-result/test.sh   |  20 +
 volumes.c  |  20 +++--
 11 files changed, 147 insertions(+), 62 deletions(-)
 create mode 100644 
tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image
 create mode 100644 tests/misc-tests/012-find-root-no-result/test.sh

-- 
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: [Question]: Contributing to btrfs

2016-02-21 Thread Qu Wenruo



Philippe Loctaux wrote on 2016/02/20 23:40 +0100:

Hello!

I'm new to the mailing list and btrfs in general (I've been using it for
two weeks on my new arch install) and I'd like to contribute to the code :)

I know how to work w/ git and patches, I just wanted to know which
git repo I need to clone to start contributing :)


https://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git
For branch, normally I use 'integration-X.X' as base for kernel development.

And for btrfs-progs,
https://github.com/kdave/btrfs-progs.git devel

Thanks,
Qu


I went on the kernel wiki and I saw some git repos, that confused me,
that's why I'm asking here :)

I'd like to apologize for my english, I'm not english native (french).

I'll wait for your replies, thanks and have a nice day!

--
Phil
p...@philippeloctaux.com
--
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: [RFC - PATCH] btrfs: do not write corrupted metadata blocks to disk

2016-02-21 Thread Filipe Manana
On Sun, Feb 21, 2016 at 3:36 PM, Alex Lyakas  wrote:
> csum_dirty_buffer was issuing a warning in case the extent buffer
> did not look alright, but was still returning success.
> Let's return error in this case, and also add two additional sanity
> checks on the extent buffer header.
>
> We had btrfs metadata corruption, and after looking at the logs we saw
> that WARN_ON(found_start != start) has been triggered. We are still
> investigating

There's a warning for WARN_ON(found_start != start || !PageUptodate(page))

Are you sure it triggered only because of found_start != start and not
because of !PageUptodate(page) (or both)?

> which component trashed the cache page which belonged to btrfs. But btrfs
> only issued a warning, and as a result, the corrupted metadata block went to
> disk.
>
> I think we should return an error in such case that the extent buffer
> doesn't look alright.

I think so too.

> The caller up the chain may BUG_ON on this, for example flush_epd_write_bio
> will,
> but it is better than to have a silent metadata corruption on disk.
>
> Note: this patch has been properly tested on 3.18 kernel only.
>
> Signed-off-by: Alex Lyakas 
> ---
> fs/btrfs/disk-io.c | 14 --
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 4545e2e..701e706 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -508,22 +508,32 @@ static int csum_dirty_buffer(struct btrfs_fs_info
> *fs_info, struct page *page)
> {
> u64 start = page_offset(page);
> u64 found_start;
> struct extent_buffer *eb;
>
> eb = (struct extent_buffer *)page->private;
> if (page != eb->pages[0])
> return 0;
> found_start = btrfs_header_bytenr(eb);
> if (WARN_ON(found_start != start || !PageUptodate(page)))
> -return 0;
> -csum_tree_block(fs_info, eb, 0);
> +return -EUCLEAN;
> +#ifdef CONFIG_BTRFS_ASSERT

A bit odd to surround these with CONFIG_BTRFS_ASSERT if we don't do assertions.
I would remove this #ifdef ... #endif or do the memcmp calls inside ASSERT().

> +if (WARN_ON(memcmp_extent_buffer(eb, fs_info->fsid,
> +(unsigned long)btrfs_header_fsid(), BTRFS_FSID_SIZE)))
> +return -EUCLEAN;
> +if (WARN_ON(memcmp_extent_buffer(eb, fs_info->fsid,
> +(unsigned long)btrfs_header_chunk_tree_uuid(eb),
> +BTRFS_FSID_SIZE)))

This second comparison doesn't seem correct. Second argument to
memcmp_extent_buffer should be fs_info->chunk_tree_uuid, which
shouldn't be the same as the fsid (take a look at utils.c:make_btrfs()
in the tools, both uuids are generated by different calls to
uuid_generate()) - did you make your tests only before adding this
comparison?. Also you should use BTRFS_UUID_SIZE instead of
BTRFS_FSID_SIZE (even if both have the same value).

> +return -EUCLEAN;
> +#endif
> +if (csum_tree_block(fs_info, eb, 0))
> +return -EUCLEAN;

I would just return the real error from csum_tree_block() - currently
it returns 1 for all possible failures instead of its real possible
failures: -ENOMEM or -EINVAL.

Thanks.

> return 0;
> }
>
> static int check_tree_block_fsid(struct btrfs_fs_info *fs_info,
>  struct extent_buffer *eb)
> {
> struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
> u8 fsid[BTRFS_UUID_SIZE];
> int ret = 1;
>
> --
> 1.9.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] Btrfs: ctree: added lines after variable declarations

2016-02-21 Thread Joe Perches
On Mon, 2016-02-22 at 01:31 +0100, Philippe Loctaux wrote:
> Hi,
> I'm really sorry, but I don't understand what you're trying to mean.
> Could you simplify your sentence please (since I'm not english
> native)?
> I'd really apreciate that, thanks :)

Please do not put your reply at the top of the email. (top-post)

This was the only instance I found where your modifications
were inappropriate (just here)

--
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: compression: added line after variable declaration

2016-02-21 Thread Philippe Loctaux
Oh, I see now :)
I'll try your changes and tell if they work or not :)

--
Philippe Loctaux
p...@philippeloctaux.com


On Sun, Feb 21, 2016 at 04:37:54PM -0800, Joe Perches wrote:
> On Mon, 2016-02-22 at 00:26 +0100, Philippe Loctaux wrote:
> > Added line after variable declaration, fixing checkpatch warning.
> []
> > diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> []
> > @@ -522,6 +522,7 @@ static noinline int add_ra_bio_pages(struct inode 
> > *inode,
> >  
> >     if (zero_offset) {
> >     int zeros;
> > +
> >     zeros = PAGE_CACHE_SIZE - zero_offset;
> >     userpage = kmap_atomic(page);
> >     memset(userpage + zero_offset, 0, zeros);
> 
> This zeros temporary is used once.
> Perhaps it should just be removed instead.
> 
> Maybe the userpage declaration should move too.
> 
> Something like:
> ---
>  fs/btrfs/compression.c | 9 -
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index 3346cd8..be41f83 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -517,14 +517,13 @@ static noinline int add_ra_bio_pages(struct inode 
> *inode,
>   free_extent_map(em);
>  
>   if (page->index == end_index) {
> - char *userpage;
>   size_t zero_offset = isize & (PAGE_CACHE_SIZE - 1);
>  
>   if (zero_offset) {
> - int zeros;
> - zeros = PAGE_CACHE_SIZE - zero_offset;
> - userpage = kmap_atomic(page);
> - memset(userpage + zero_offset, 0, zeros);
> + char *userpage = kmap_atomic(page);
> +
> + memset(userpage + zero_offset, 0,
> +    PAGE_CACHE_SIZE - zero_offset);
>   flush_dcache_page(page);
>   kunmap_atomic(userpage);
>   }
> 
> --
> 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: compression: added line after variable declaration

2016-02-21 Thread Joe Perches
On Mon, 2016-02-22 at 00:26 +0100, Philippe Loctaux wrote:
> Added line after variable declaration, fixing checkpatch warning.
[]
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
[]
> @@ -522,6 +522,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
>  
>   if (zero_offset) {
>   int zeros;
> +
>   zeros = PAGE_CACHE_SIZE - zero_offset;
>   userpage = kmap_atomic(page);
>   memset(userpage + zero_offset, 0, zeros);

This zeros temporary is used once.
Perhaps it should just be removed instead.

Maybe the userpage declaration should move too.

Something like:
---
 fs/btrfs/compression.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 3346cd8..be41f83 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -517,14 +517,13 @@ static noinline int add_ra_bio_pages(struct inode *inode,
    free_extent_map(em);
 
    if (page->index == end_index) {
-   char *userpage;
    size_t zero_offset = isize & (PAGE_CACHE_SIZE - 1);
 
    if (zero_offset) {
-   int zeros;
-   zeros = PAGE_CACHE_SIZE - zero_offset;
-   userpage = kmap_atomic(page);
-   memset(userpage + zero_offset, 0, zeros);
+   char *userpage = kmap_atomic(page);
+
+   memset(userpage + zero_offset, 0,
+      PAGE_CACHE_SIZE - zero_offset);
    flush_dcache_page(page);
    kunmap_atomic(userpage);
    }

--
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 2/2] Btrfs: dev-replace: fixed comment blocks coding style issues

2016-02-21 Thread Philippe Loctaux
Makes the comment blocks start with /* on separate lines, and end
with */ on separate lines as well.

Signed-off-by: Philippe Loctaux 
---
 fs/btrfs/dev-replace.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index b89a8c6..0d817aa 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -650,8 +650,10 @@ void btrfs_dev_replace_status(struct btrfs_fs_info 
*fs_info,
struct btrfs_device *srcdev;
 
btrfs_dev_replace_lock(dev_replace);
-   /* even if !dev_replace_is_valid, the values are good enough for
-* the replace_status ioctl */
+   /*
+* even if !dev_replace_is_valid, the values are good enough for
+* the replace_status ioctl
+*/
args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
args->status.replace_state = dev_replace->replace_state;
args->status.time_started = dev_replace->time_started;
@@ -870,8 +872,10 @@ void btrfs_dev_replace_lock(struct btrfs_dev_replace 
*dev_replace)
/* the beginning is just an optimization for the typical case */
if (atomic_read(&dev_replace->nesting_level) == 0) {
 acquire_lock:
-   /* this is not a nested case where the same thread
-* is trying to acqurire the same lock twice */
+   /*
+* this is not a nested case where the same thread
+* is trying to acqurire the same lock twice
+*/
mutex_lock(&dev_replace->lock);
mutex_lock(&dev_replace->lock_management_lock);
dev_replace->lock_owner = current->pid;
-- 
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] Btrfs: ctree: added lines after variable declarations

2016-02-21 Thread Philippe Loctaux
Hi,
I'm really sorry, but I don't understand what you're trying to mean.
Could you simplify your sentence please (since I'm not english native)?
I'd really apreciate that, thanks :)

--
Philippe Loctaux
p...@philippeloctaux.com

On Sun, Feb 21, 2016 at 04:06:03PM -0800, Joe Perches wrote:
> On Mon, 2016-02-22 at 01:01 +0100, Philippe Loctaux wrote:
> > Is there no need of additional blank line here particulary
> > or in all lines that I changed?
> 
> Please don't top post and just here.
> > On Sun, Feb 21, 2016 at 03:53:04PM -0800, Joe Perches wrote:
> > > On Mon, 2016-02-22 at 00:46 +0100, Philippe Loctaux wrote:
> > > > Added lines after variable declarations, fixing 22 checkpatch warnings.
> > > []
> > > > diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> > > []
> > > > @@ -4592,6 +4610,7 @@ void btrfs_truncate_item(struct btrfs_root *root, 
> > > > struct btrfs_path *path,
> > > >       data_end, old_data_start + new_size - 
> > > > data_end);
> > > >     } else {
> > > >     struct btrfs_disk_key disk_key;
> > > > +
> > > >     u64 offset;
> > > 
> > > Overzealous here.
> > > No additional blank line required.
> --
> 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 1/2] Btrfs: dev-replace: Fixed indentation coding style issues

2016-02-21 Thread Philippe Loctaux
Use tabs instead of spaces, fixing 3 checkpatch errors.

Signed-off-by: Philippe Loctaux 
---
 fs/btrfs/dev-replace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index cbb7dbf..b89a8c6 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -378,7 +378,7 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
btrfs_info_in_rcu(root->fs_info,
  "dev_replace from %s (devid %llu) to %s started",
  src_device->missing ? "" :
-   rcu_str_deref(src_device->name),
+ rcu_str_deref(src_device->name),
  src_device->devid,
  rcu_str_deref(tgt_device->name));
 
@@ -525,7 +525,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info 
*fs_info,
btrfs_err_in_rcu(root->fs_info,
  "btrfs_scrub_dev(%s, %llu, %s) failed %d",
  src_device->missing ? "" :
-   rcu_str_deref(src_device->name),
+ rcu_str_deref(src_device->name),
  src_device->devid,
  rcu_str_deref(tgt_device->name), scrub_ret);
btrfs_dev_replace_unlock(dev_replace);
@@ -542,7 +542,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info 
*fs_info,
btrfs_info_in_rcu(root->fs_info,
  "dev_replace from %s (devid %llu) to %s finished",
  src_device->missing ? "" :
-   rcu_str_deref(src_device->name),
+ rcu_str_deref(src_device->name),
  src_device->devid,
  rcu_str_deref(tgt_device->name));
tgt_device->is_tgtdev_for_dev_replace = 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] Btrfs: ctree: added lines after variable declarations

2016-02-21 Thread Philippe Loctaux
Is there no need of additional blank line here particulary
or in all lines that I changed?

--
Philippe Loctaux
p...@philippeloctaux.com

On Sun, Feb 21, 2016 at 03:53:04PM -0800, Joe Perches wrote:
> On Mon, 2016-02-22 at 00:46 +0100, Philippe Loctaux wrote:
> > Added lines after variable declarations, fixing 22 checkpatch warnings.
> []
> > diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> []
> > @@ -4592,6 +4610,7 @@ void btrfs_truncate_item(struct btrfs_root *root, 
> > struct btrfs_path *path,
> >       data_end, old_data_start + new_size - data_end);
> >     } else {
> >     struct btrfs_disk_key disk_key;
> > +
> >     u64 offset;
> 
> Overzealous here.
> No additional blank line required.
> 
> --
> 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: ctree: added lines after variable declarations

2016-02-21 Thread Joe Perches
On Mon, 2016-02-22 at 01:01 +0100, Philippe Loctaux wrote:
> Is there no need of additional blank line here particulary
> or in all lines that I changed?

Please don't top post and just here.
> On Sun, Feb 21, 2016 at 03:53:04PM -0800, Joe Perches wrote:
> > On Mon, 2016-02-22 at 00:46 +0100, Philippe Loctaux wrote:
> > > Added lines after variable declarations, fixing 22 checkpatch warnings.
> > []
> > > diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> > []
> > > @@ -4592,6 +4610,7 @@ void btrfs_truncate_item(struct btrfs_root *root, 
> > > struct btrfs_path *path,
> > >     data_end, old_data_start + new_size - data_end);
> > >   } else {
> > >   struct btrfs_disk_key disk_key;
> > > +
> > >   u64 offset;
> > 
> > Overzealous here.
> > No additional blank line required.
--
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: delayed-inode: Fixed indentation coding style issue

2016-02-21 Thread Philippe Loctaux
Use tabs instead of spaces, fixing checkpatch error.

Signed-off-by: Philippe Loctaux 
---
 fs/btrfs/delayed-inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index b57daa8..2e25aa54 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1802,7 +1802,7 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev)
set_nlink(inode, btrfs_stack_inode_nlink(inode_item));
inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item));
BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item);
-BTRFS_I(inode)->last_trans = btrfs_stack_inode_transid(inode_item);
+   BTRFS_I(inode)->last_trans = btrfs_stack_inode_transid(inode_item);
 
inode->i_version = btrfs_stack_inode_sequence(inode_item);
inode->i_rdev = 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] Btrfs: ctree: added lines after variable declarations

2016-02-21 Thread Joe Perches
On Mon, 2016-02-22 at 00:46 +0100, Philippe Loctaux wrote:
> Added lines after variable declarations, fixing 22 checkpatch warnings.
[]
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
[]
> @@ -4592,6 +4610,7 @@ void btrfs_truncate_item(struct btrfs_root *root, 
> struct btrfs_path *path,
>     data_end, old_data_start + new_size - data_end);
>   } else {
>   struct btrfs_disk_key disk_key;
> +
>   u64 offset;

Overzealous here.
No additional blank line required.

--
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: ctree: added lines after variable declarations

2016-02-21 Thread Philippe Loctaux
Added lines after variable declarations, fixing 22 checkpatch warnings.

Signed-off-by: Philippe Loctaux 
---
 fs/btrfs/ctree.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 769e0ff..c9fd42d 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -45,6 +45,7 @@ static int tree_mod_log_free_eb(struct btrfs_fs_info *fs_info,
 struct btrfs_path *btrfs_alloc_path(void)
 {
struct btrfs_path *path;
+
path = kmem_cache_zalloc(btrfs_path_cachep, GFP_NOFS);
return path;
 }
@@ -56,6 +57,7 @@ struct btrfs_path *btrfs_alloc_path(void)
 noinline void btrfs_set_path_blocking(struct btrfs_path *p)
 {
int i;
+
for (i = 0; i < BTRFS_MAX_LEVEL; i++) {
if (!p->nodes[i] || !p->locks[i])
continue;
@@ -873,6 +875,7 @@ tree_mod_log_eb_move(struct btrfs_fs_info *fs_info, struct 
extent_buffer *dst,
 int dst_offset, int src_offset, int nr_items)
 {
int ret;
+
ret = tree_mod_log_insert_move(fs_info, dst, dst_offset, src_offset,
   nr_items, GFP_NOFS);
BUG_ON(ret < 0);
@@ -943,6 +946,7 @@ tree_mod_log_set_root_pointer(struct btrfs_root *root,
  int log_removal)
 {
int ret;
+
ret = tree_mod_log_insert_root(root->fs_info, root->node,
   new_root_node, GFP_NOFS, log_removal);
BUG_ON(ret < 0);
@@ -1734,6 +1738,7 @@ static inline unsigned int leaf_data_end(struct 
btrfs_root *root,
 struct extent_buffer *leaf)
 {
u32 nr = btrfs_header_nritems(leaf);
+
if (nr == 0)
return BTRFS_LEAF_DATA_SIZE(root);
return btrfs_item_offset_nr(leaf, nr - 1);
@@ -2011,6 +2016,7 @@ static noinline int balance_level(struct 
btrfs_trans_handle *trans,
right = NULL;
} else {
struct btrfs_disk_key right_key;
+
btrfs_node_key(right, &right_key, 0);
tree_mod_log_set_node_key(root->fs_info, parent,
  pslot + 1, 0);
@@ -2056,6 +2062,7 @@ static noinline int balance_level(struct 
btrfs_trans_handle *trans,
} else {
/* update the parent key to reflect our changes */
struct btrfs_disk_key mid_key;
+
btrfs_node_key(mid, &mid_key, 0);
tree_mod_log_set_node_key(root->fs_info, parent,
  pslot, 0);
@@ -2154,6 +2161,7 @@ static noinline int push_nodes_for_insert(struct 
btrfs_trans_handle *trans,
ret = wret;
if (wret == 0) {
struct btrfs_disk_key disk_key;
+
orig_slot += left_nr;
btrfs_node_key(mid, &disk_key, 0);
tree_mod_log_set_node_key(root->fs_info, parent,
@@ -2382,6 +2390,7 @@ static noinline void unlock_up(struct btrfs_path *path, 
int level,
}
if (!no_skips && path->keep_locks) {
u32 nritems;
+
t = path->nodes[i];
nritems = btrfs_header_nritems(t);
if (nritems < 1 || path->slots[i] >= nritems - 1) {
@@ -2529,6 +2538,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans,
   int *write_lock_level)
 {
int ret;
+
if ((p->search_for_split || ins_len > 0) && btrfs_header_nritems(b) >=
BTRFS_NODEPTRS_PER_BLOCK(root) - 3) {
int sret;
@@ -2825,6 +2835,7 @@ cow_done:
 
if (level != 0) {
int dec = 0;
+
if (ret && slot > 0) {
dec = 1;
slot -= 1;
@@ -2993,6 +3004,7 @@ again:
 
if (level != 0) {
int dec = 0;
+
if (ret && slot > 0) {
dec = 1;
slot -= 1;
@@ -3139,6 +3151,7 @@ static void fixup_low_keys(struct btrfs_fs_info *fs_info,
 
for (i = level; i < BTRFS_MAX_LEVEL; i++) {
int tslot = path->slots[i];
+
if (!path->nodes[i])
break;
t = path->nodes[i];
@@ -3574,6 +3587,7 @@ noinline int btrfs_leaf_free_space(struct btrfs_root 
*root,
 {
int nritems = btrfs_header_nritems(leaf);
int ret;
+
ret = BTRFS_LEAF_DATA_SIZE(root) - leaf_space_used(leaf, 0, nritems);
if (ret < 0) {
btrfs_crit(root->fs_info,
@@ -3630,6 +3644,7 @@ static noinline int __push_leaf_right(struct 
btrfs_trans_handle *trans,
break;
if (path->slots[0] == i) {
int

[PATCH] Btrfs: compression: added line after variable declaration

2016-02-21 Thread Philippe Loctaux
Added line after variable declaration, fixing checkpatch warning.

Signed-off-by: Philippe Loctaux 
---
 fs/btrfs/compression.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 3346cd8..5194b6f 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -522,6 +522,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
 
if (zero_offset) {
int zeros;
+
zeros = PAGE_CACHE_SIZE - zero_offset;
userpage = kmap_atomic(page);
memset(userpage + zero_offset, 0, zeros);
-- 
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] Btrfs: check-integrity: fixed comment blocks coding style issues

2016-02-21 Thread Philippe Loctaux
Makes the comment blocks start with /* on separate lines, and end
with */ on separate lines as well.

Signed-off-by: Philippe Loctaux 
---
 fs/btrfs/check-integrity.c | 30 ++
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 861d472..cb5dc04 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -2070,8 +2070,11 @@ again:
goto continue_loop;
}
 
-   /* this is getting ugly for the
-* include_extent_data case... */
+   /*
+* this is getting ugly for the
+* include_extent_data case...
+*/
+
bytenr = 0; /* unknown */
} else {
processed_len = state->metablock_size;
@@ -2180,8 +2183,11 @@ static void btrfsic_bio_end_io(struct bio *bp)
struct btrfsic_block *block = (struct btrfsic_block *)bp->bi_private;
int iodone_w_error;
 
-   /* mutex is not held! This is not save if IO is not yet completed
-* on umount */
+   /*
+* mutex is not held! This is not save if IO is not yet completed
+* on umount
+*/
+
iodone_w_error = 0;
if (bp->bi_error)
iodone_w_error = 1;
@@ -2861,8 +2867,12 @@ int btrfsic_submit_bh(int rw, struct buffer_head *bh)
return submit_bh(rw, bh);
 
mutex_lock(&btrfsic_mutex);
-   /* since btrfsic_submit_bh() might also be called before
-* btrfsic_mount(), this might return NULL */
+
+   /*
+* since btrfsic_submit_bh() might also be called before
+* btrfsic_mount(), this might return NULL
+*/
+
dev_state = btrfsic_dev_state_lookup(bh->b_bdev);
 
/* Only called to write the superblock (incl. FLUSH/FUA) */
@@ -2924,8 +2934,12 @@ static void __btrfsic_submit_bio(int rw, struct bio *bio)
return;
 
mutex_lock(&btrfsic_mutex);
-   /* since btrfsic_submit_bio() is also called before
-* btrfsic_mount(), this might return NULL */
+
+   /*
+* since btrfsic_submit_bio() is also called before
+* btrfsic_mount(), this might return NULL
+*/
+
dev_state = btrfsic_dev_state_lookup(bio->bi_bdev);
if (NULL != dev_state &&
(rw & WRITE) && NULL != bio->bi_io_vec) {
-- 
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] Btrfs: check-integrity: fixed a comment block coding style issue

2016-02-21 Thread Philippe Loctaux
Makes the comment block start with /* on a separate line, and end
with */ on a separate line as well.

Signed-off-by: Philippe Loctaux 
---
 fs/btrfs/check-integrity.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 861d472..92436c7 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -226,8 +226,10 @@ struct btrfsic_block_data_ctx {
void *mem_to_free;
 };
 
-/* This structure is used to implement recursion without occupying
- * any stack space, refer to btrfsic_process_metablock() */
+/*
+ * This structure is used to implement recursion without occupying
+ * any stack space, refer to btrfsic_process_metablock()
+ */
 struct btrfsic_stack_frame {
u32 magic;
u32 nr;
-- 
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] Btrfs: async: fixed a brace coding style issue

2016-02-21 Thread Philippe Loctaux
On Sun, Feb 21, 2016 at 03:08:02PM -0600, Simon Quigley wrote:
> I thought I proposed this exact patch...hmm...

Yes you're right, I wasn't subscribed at the mailing list yet.
The maintainer will probably see it's a duplicate and he'll just ignore
that patch.

--
Philippe Loctaux
p...@philippeloctaux.com
--
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: async: fixed a brace coding style issue

2016-02-21 Thread Simon Quigley



On 02/21/2016 02:50 PM, Philippe Loctaux wrote:

Fixed a coding style issue.

Signed-off-by: Philippe Loctaux 
---
  fs/btrfs/async-thread.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 5fb60ea..7914dd2 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -227,9 +227,9 @@ static inline void thresh_exec_hook(struct 
__btrfs_workqueue *wq)
  out:
spin_unlock(&wq->thres_lock);
  
-	if (need_change) {

+   if (need_change)
workqueue_set_max_active(wq->normal_wq, wq->current_active);
-   }
+
  }
  
  static void run_ordered_work(struct __btrfs_workqueue *wq)

I thought I proposed this exact patch...hmm...
--
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: async: fixed a brace coding style issue

2016-02-21 Thread Philippe Loctaux
Fixed a coding style issue.

Signed-off-by: Philippe Loctaux 
---
 fs/btrfs/async-thread.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 5fb60ea..7914dd2 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -227,9 +227,9 @@ static inline void thresh_exec_hook(struct 
__btrfs_workqueue *wq)
 out:
spin_unlock(&wq->thres_lock);
 
-   if (need_change) {
+   if (need_change)
workqueue_set_max_active(wq->normal_wq, wq->current_active);
-   }
+
 }
 
 static void run_ordered_work(struct __btrfs_workqueue *wq)
-- 
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: random i/o error without error in dmesg

2016-02-21 Thread Philipp Serr

On Mon, 2 Nov 2015 19:26:01 +0100, Szalma László wrote:

Unfortunately the problem with kernel 4.3.0 still exists.



Any news on that issue? I'm currently @ 4.3.3 and the issue persists for 
me, too.


There's one more information I might be able to contribute: In my case 
always the same single file is affected. The issue is triggered mostly 
when backing up a read-only snapshot of the volume using rsync. Once the 
issue occures, the file within the snapshot volume as well as the file 
in the main volume can't be read anymore until reboot (didn't try 
remounting the affected root partition).


--
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: [Question]: Contributing to btrfs

2016-02-21 Thread Duncan
Philippe Loctaux posted on Sat, 20 Feb 2016 23:40:50 +0100 as excerpted:

> I'm new to the mailing list and btrfs in general (I've been using it for
> two weeks on my new arch install) and I'd like to contribute to the code
> :)
> 
> I know how to work w/ git and patches, I just wanted to know which git
> repo I need to clone to start contributing :)
> 
> I went on the kernel wiki and I saw some git repos, that confused me,
> that's why I'm asking here :)

You mention the kernel wiki, but don't mention the btrfs wiki, which is 
on a kernel wiki subdomain, and which has the btrfs-specific information, 
both for users and for developers.  Missing that is thus likely to be the 
source of your confusion, which makes it easy to fix. =:^)

https://btrfs.wiki.kernel.org

More specifically of interest for developers:

https://btrfs.wiki.kernel.org/index.php/Main_Page#Developer_documentation

But as you're a new user as well, and missed the btrfs user docs on the 
wiki, spend some time looking over them as well, as they'll almost 
certainly contain some rather useful user information you missed, as well.


If OTOH, you meant that you read that, and were still confused, as may be 
the case give that I too was a bit confused as a list regular, when I was 
looking for actual development sources, as the kernel.org userspace repo 
only contains releases, the repo.or.cz repo is what I was looking for to 
get the actual under development userspace HEAD code.  Or just do what I 
did and browse around a bit until you figure out which of the listed repos 
you're actually after. =:^)

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman

--
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


[RFC - PATCH] btrfs: do not write corrupted metadata blocks to disk

2016-02-21 Thread Alex Lyakas

csum_dirty_buffer was issuing a warning in case the extent buffer
did not look alright, but was still returning success.
Let's return error in this case, and also add two additional sanity
checks on the extent buffer header.

We had btrfs metadata corruption, and after looking at the logs we saw
that WARN_ON(found_start != start) has been triggered. We are still 
investigating

which component trashed the cache page which belonged to btrfs. But btrfs
only issued a warning, and as a result, the corrupted metadata block went to 
disk.


I think we should return an error in such case that the extent buffer 
doesn't look alright.
The caller up the chain may BUG_ON on this, for example flush_epd_write_bio 
will,

but it is better than to have a silent metadata corruption on disk.

Note: this patch has been properly tested on 3.18 kernel only.

Signed-off-by: Alex Lyakas 
---
fs/btrfs/disk-io.c | 14 --
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 4545e2e..701e706 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -508,22 +508,32 @@ static int csum_dirty_buffer(struct btrfs_fs_info 
*fs_info, struct page *page)

{
u64 start = page_offset(page);
u64 found_start;
struct extent_buffer *eb;

eb = (struct extent_buffer *)page->private;
if (page != eb->pages[0])
return 0;
found_start = btrfs_header_bytenr(eb);
if (WARN_ON(found_start != start || !PageUptodate(page)))
-return 0;
-csum_tree_block(fs_info, eb, 0);
+return -EUCLEAN;
+#ifdef CONFIG_BTRFS_ASSERT
+if (WARN_ON(memcmp_extent_buffer(eb, fs_info->fsid,
+(unsigned long)btrfs_header_fsid(), BTRFS_FSID_SIZE)))
+return -EUCLEAN;
+if (WARN_ON(memcmp_extent_buffer(eb, fs_info->fsid,
+(unsigned long)btrfs_header_chunk_tree_uuid(eb),
+BTRFS_FSID_SIZE)))
+return -EUCLEAN;
+#endif
+if (csum_tree_block(fs_info, eb, 0))
+return -EUCLEAN;
return 0;
}

static int check_tree_block_fsid(struct btrfs_fs_info *fs_info,
 struct extent_buffer *eb)
{
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
u8 fsid[BTRFS_UUID_SIZE];
int ret = 1;

--
1.9.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