Re: [PATCH v4] btrfs: Fix memory leakage in the tree-log.c

2013-10-10 Thread Stefan Behrens
On Wed,  9 Oct 2013 23:01:35 -0300, Geyslan G. Bem wrote:
 When 'dir' is NULL, after calling extref_get_fields(), add_inode_ref()
 can be returning without freeing the 'name' pointer.
 
 Added kfree when necessary.
 
 Signed-off-by: Geyslan G. Bem geys...@gmail.com
 ---
  fs/btrfs/tree-log.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)
 
 diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
 index 79f057c..63c0b72 100644
 --- a/fs/btrfs/tree-log.c
 +++ b/fs/btrfs/tree-log.c
 @@ -1169,8 +1169,11 @@ static noinline int add_inode_ref(struct 
 btrfs_trans_handle *trans,
*/
   if (!dir)
   dir = read_one_inode(root, parent_objectid);
 - if (!dir)
 + if (!dir) {
 + if (!ret)
 + kfree(name);
   return -ENOENT;
 + }
   } else {
   ret = ref_get_fields(eb, ref_ptr, namelen, name,
ref_index);
 

There are many more places to fix up in this function. We lose up to two inodes 
(if (!ret) return ret; without the iput(dir), iput(inode)) and we can lose 
the memory for name (if ... goto out; and the out path does not contain the 
kfree(name)).

I would prefer the approach with a label at the end of the function that 
handles all cleanup work and which is called from everywhere where a return is 
coded now.

Like this (the code is completely untested since this is just a review comment):

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 964c583..40035db 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -1113,11 +1113,11 @@ static noinline int add_inode_ref(struct 
btrfs_trans_handle *trans,
  struct extent_buffer *eb, int slot,
  struct btrfs_key *key)
 {
-   struct inode *dir;
-   struct inode *inode;
+   struct inode *dir = NULL;
+   struct inode *inode = NULL;
unsigned long ref_ptr;
unsigned long ref_end;
-   char *name;
+   char *name = NULL;
int namelen;
int ret;
int search_done = 0;
@@ -1150,13 +1150,15 @@ static noinline int add_inode_ref(struct 
btrfs_trans_handle *trans,
 * care of the rest
 */
dir = read_one_inode(root, parent_objectid);
-   if (!dir)
-   return -ENOENT;
+   if (!dir) {
+   ret = -ENOENT;
+   goto out;
+   }

inode = read_one_inode(root, inode_objectid);
if (!inode) {
-   iput(dir);
-   return -EIO;
+   ret = -EIO;
+   goto out;
}

while (ref_ptr  ref_end) {
@@ -1169,14 +1171,16 @@ static noinline int add_inode_ref(struct 
btrfs_trans_handle *trans,
 */
if (!dir)
dir = read_one_inode(root, parent_objectid);
-   if (!dir)
-   return -ENOENT;
+   if (!dir) {
+   ret = -ENOENT;
+   goto out;
+   }
} else {
ret = ref_get_fields(eb, ref_ptr, namelen, name,
 ref_index);
}
if (ret)
-   return ret;
+   goto out;

/* if we already have a perfect match, we're done */
if (!inode_in_dir(root, path, btrfs_ino(dir), btrfs_ino(inode),
@@ -1215,6 +1219,7 @@ static noinline int add_inode_ref(struct 
btrfs_trans_handle *trans,

ref_ptr = (unsigned long)(ref_ptr + ref_struct_size) + namelen;
kfree(name);
+   name = NULL;
if (log_ref_ver) {
iput(dir);
dir = NULL;
@@ -1225,6 +1230,7 @@ static noinline int add_inode_ref(struct 
btrfs_trans_handle *trans,
ret = overwrite_item(trans, root, path, eb, slot, key);
 out:
btrfs_release_path(path);
+   kfree(name);
iput(dir);
iput(inode);
return ret;


Could you rework your patch to do something similar to the code above?

This approach is also documented in the file Documentation/CodingStyle in the 
kernel source tree in the section Chapter 7: Centralized exiting of functions.


--
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: BUG relating to fstrim on btrfs partitions

2013-10-10 Thread Duncan
Mike Audia posted on Thu, 10 Oct 2013 06:20:42 -0400 as excerpted:

 I think I found a bug affecting btrfs filesystems and users invoking
 fstrim to discard unused blocks: if I execute a `fstrim -v /` twice, the
 amount trimmed does not change on the 2nd invocation AND it takes just
 as long as the first.  Why do I think this is a bug?  When I do the same
 on an ext4 partition I get different behavior: the output shows 0 B
 trimmed and it does is instantaneously when I run it a 2nd time.  After
 contacting the fstrim developer, he stated that the userspace part
 (fstrim) does only one thing and it is invoke an ioctl (FITRIM); it is
 the job of the filesystem to properly implement this.

This behavior is documented in the fstrim manpage under -v/--verbose:

 When [--verbose is] specified fstrim will output the number of bytes
 passed from the filesystem down the block stack to the device for
 potential discard. This number is a maximum discard amount from the
 storage device's perspective, because FITRIM ioctl called repeated
 will keep sending the same sectors for discard repeatedly.

 fstrim will report the same potential discard bytes each time, but
 only sectors which had been written to between the discards would
 actually be discarded by the storage device.

Why ext4 behavior doesn't conform to that fstrim documentation I can't 
say (except by stating the obvious that the ext4 filesystem 
implementation of that ioctl obviously does it differently, but why... 
you'd have to either ask the ext4 folks or read its docs/sources), but 
given that fstrim documentation, the btrfs behavior is certainly NOTABUG 
as it's simply conforming to the documentation.

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


[PATCH] Btrfs: nuke a bogus rw_devices decrement in __btrfs_close_devices

2013-10-10 Thread Ilya Dryomov
On mount failures, __btrfs_close_devices can be called well before
dev-replace state is read and -is_tgtdev_for_dev_replace is set.  This
leads to a bogus decrement of -rw_devices and sets off a WARN_ON in
__btrfs_close_devices if replace target device happens to be on the
lists and we fail early in the mount sequence.  Fix this by checking
the devid instead of -is_tgtdev_for_dev_replace before the decrement:
for replace targets devid is always equal to BTRFS_DEV_REPLACE_DEVID.

Cc: Stefan Behrens sbehr...@giantdisaster.de
Signed-off-by: Ilya Dryomov idryo...@gmail.com
---
 fs/btrfs/volumes.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 043b215..a306db9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -666,7 +666,8 @@ static int __btrfs_close_devices(struct btrfs_fs_devices 
*fs_devices)
if (device-bdev)
fs_devices-open_devices--;
 
-   if (device-writeable  !device-is_tgtdev_for_dev_replace) {
+   if (device-writeable 
+   device-devid != BTRFS_DEV_REPLACE_DEVID) {
list_del_init(device-dev_alloc_list);
fs_devices-rw_devices--;
}
-- 
1.7.10.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


[PATCH] Btrfs: don't leak ioctl args in btrfs_ioctl_dev_replace

2013-10-10 Thread Ilya Dryomov
struct btrfs_ioctl_dev_replace_args memory is leaked if replace is
requested on a read-only filesystem.  Fix it.

Signed-off-by: Ilya Dryomov idryo...@gmail.com
---
 fs/btrfs/ioctl.c |9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 9d46f60..17bb98e 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3679,9 +3679,10 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root 
*root, void __user *arg)
 
switch (p-cmd) {
case BTRFS_IOCTL_DEV_REPLACE_CMD_START:
-   if (root-fs_info-sb-s_flags  MS_RDONLY)
-   return -EROFS;
-
+   if (root-fs_info-sb-s_flags  MS_RDONLY) {
+   ret = -EROFS;
+   goto out;
+   }
if (atomic_xchg(
root-fs_info-mutually_exclusive_operation_running,
1)) {
@@ -3707,7 +3708,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root 
*root, void __user *arg)
 
if (copy_to_user(arg, p, sizeof(*p)))
ret = -EFAULT;
-
+out:
kfree(p);
return ret;
 }
-- 
1.7.10.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


[PATCH] Btrfs: disallow 'btrfs {balance,replace} cancel' on ro mounts

2013-10-10 Thread Ilya Dryomov
For both balance and replace, cancelling involves changing the on-disk
state and committing a transaction, which is not a good thing to do on
read-only filesystems.

Cc: Stefan Behrens sbehr...@giantdisaster.de
Signed-off-by: Ilya Dryomov idryo...@gmail.com
---
 fs/btrfs/dev-replace.c |3 +++
 fs/btrfs/volumes.c |3 +++
 2 files changed, 6 insertions(+)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 9efb94e..98df261 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -650,6 +650,9 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info 
*fs_info)
u64 result;
int ret;
 
+   if (fs_info-sb-s_flags  MS_RDONLY)
+   return -EROFS;
+
mutex_lock(dev_replace-lock_finishing_cancel_unmount);
btrfs_dev_replace_lock(dev_replace);
switch (dev_replace-replace_state) {
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index a306db9..2630f38 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3424,6 +3424,9 @@ int btrfs_pause_balance(struct btrfs_fs_info *fs_info)
 
 int btrfs_cancel_balance(struct btrfs_fs_info *fs_info)
 {
+   if (fs_info-sb-s_flags  MS_RDONLY)
+   return -EROFS;
+
mutex_lock(fs_info-balance_mutex);
if (!fs_info-balance_ctl) {
mutex_unlock(fs_info-balance_mutex);
-- 
1.7.10.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


Will btrfs scrub clear corrupt filesystem trees?

2013-10-10 Thread Martin
I have 1.5TB of data on a single disk formatted with defaults. There
appears to be only two directory trees of a few MBytes that have
suffered corruption (due to in the past too high a sata speed causing
corruption).

The filesystem mounts fine. But how to clear out the corrupt trees?

At the moment, I have running:

btrfsck --repair --init-extent-tree /dev/sdc

parent transid verify failed on 911904604160 wanted 17448 found 17449
parent transid verify failed on 911904604160 wanted 17448 found 17449
parent transid verify failed on 911904604160 wanted 17448 found 17449
parent transid verify failed on 911904604160 wanted 17448 found 17449
Ignoring transid failure

... And it is still running after over two days now. Looped?


Would a:

btrfs scrub start

clear out the corrupt trees?

Must I wait for the btrfsck to complete if it is recreating an extents
tree?...


Suggestions welcomed...

Martin

--
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: Will btrfs scrub clear corrupt filesystem trees?

2013-10-10 Thread Chris Murphy

On Oct 10, 2013, at 12:27 PM, Martin m_bt...@ml1.co.uk wrote:

 I have 1.5TB of data on a single disk formatted with defaults. There
 appears to be only two directory trees of a few MBytes that have
 suffered corruption (due to in the past too high a sata speed causing
 corruption).
 
 The filesystem mounts fine. But how to clear out the corrupt trees?

If you've already gone through Hugo's list, I think it's a matter of waiting 
for further development for fixing such problems.

 
 
 Would a:
 
 btrfs scrub start
 
 clear out the corrupt trees?

I don't think so.


 
 Must I wait for the btrfsck to complete if it is recreating an extents
 tree?…


Yes because scrub is online/mounted, and btrfsck is offline/unmounted.

Chris Murphy

--
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: Handful of btrfs fixes for 3.11.x stable

2013-10-10 Thread Greg KH
On Mon, Oct 07, 2013 at 04:34:43PM -0400, Josef Bacik wrote:
 On Sat, Oct 05, 2013 at 04:52:18PM -0700, Greg KH wrote:
  On Fri, Sep 20, 2013 at 09:53:02AM -0700, Greg KH wrote:
   On Fri, Sep 20, 2013 at 06:34:39PM +0200, David Sterba wrote:
Hi stable team,

please add the following commits to 3.11 tree, they fix user visible 
problems,
were tested and are now present in 3.12-rc1.

3d05ca371200b3366530621abf73769024581b79
b13a004528c3e5eb060a26eee795f5a0da7bfe9f
7ef67ffda91cc0c56f33937bfdf1d057b9ee96ca
ca6d07c1d74bf7ba3083bc31a9aeeaa1d0ad86aa
  
  These git commit ids don't match up to anything in Linus's tree, where
  did you get them from?
  
Josef Bacik (4):
  Btrfs: reset ret in record_one_backref
  Btrfs: change how we queue blocks for backref checking
  Btrfs: skip subvol entries when checking if we've created a dir 
already
  Btrfs: remove ourselves from the cluster list under lock
  
  I can dig through the tree to find these, but I'd prefer if you could
  provide the correct ids to verify I got them right.
  
  Also, what order do I apply them in?
 
 You can commit them in that order (top to bottom), here are their 
 corresponding
 commits
 
 50f1319cb5f7690e4d9de18d1a75ea89296d0e53
 b6c60c8018c4e9beb2f83fc82c09f9d033766571
 a05254143cd183b18002cbba7759a1e4629aa762
 b8d0c69b9469ffd33df30fee3e990f2d4aa68a09

All now applied, thanks.

greg k-h
--
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: add tests for find_lock_delalloc_range

2013-10-10 Thread Josef Bacik
So both Liu and I made huge messes of find_lock_delalloc_range trying to fix
stuff, me first by fixing extent size, then him by fixing something I broke and
then me again telling him to fix it a different way.  So this is obviously a
candidate for some testing.  This patch adds a pseudo fs so we can allocate fake
inodes for tests that need an inode or pages.  Then it addes a bunch of tests to
make sure find_lock_delalloc_range is acting the way it is supposed to.  With
this patch and all of our previous patches to find_lock_delalloc_range I am sure
it is working as expected now.  Thanks,

Signed-off-by: Josef Bacik jba...@fusionio.com
---
V1-V2: I forgot to inlude tests/btrfs-tests.c
 fs/btrfs/Makefile|   2 +-
 fs/btrfs/ctree.h |   6 +
 fs/btrfs/extent_io.c |   9 +-
 fs/btrfs/extent_io.h |   6 +
 fs/btrfs/super.c |  14 +-
 fs/btrfs/tests/btrfs-tests.c |  68 ++
 fs/btrfs/tests/btrfs-tests.h |  15 +++
 fs/btrfs/tests/extent-io-tests.c | 276 +++
 include/uapi/linux/magic.h   |   2 +-
 9 files changed, 389 insertions(+), 9 deletions(-)
 create mode 100644 fs/btrfs/tests/btrfs-tests.c
 create mode 100644 fs/btrfs/tests/extent-io-tests.c

diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index 4c7dfbf..cac4f2d 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -15,4 +15,4 @@ btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
 btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
 
 btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
-   tests/extent-buffer-tests.o
+   tests/extent-buffer-tests.o tests/btrfs-tests.o tests/extent-io-tests.o
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 9ca15a8..2f39806 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -47,6 +47,12 @@ extern struct kmem_cache *btrfs_path_cachep;
 extern struct kmem_cache *btrfs_free_space_cachep;
 struct btrfs_ordered_sum;
 
+#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
+#define STATIC noinline
+#else
+#define STATIC static noinline
+#endif
+
 #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
 
 #define BTRFS_MAX_MIRRORS 3
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 2bf6f46..c10291cc 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1598,11 +1598,10 @@ done:
  *
  * 1 is returned if we find something, 0 if nothing was in the tree
  */
-static noinline u64 find_lock_delalloc_range(struct inode *inode,
-struct extent_io_tree *tree,
-struct page *locked_page,
-u64 *start, u64 *end,
-u64 max_bytes)
+STATIC u64 find_lock_delalloc_range(struct inode *inode,
+   struct extent_io_tree *tree,
+   struct page *locked_page, u64 *start,
+   u64 *end, u64 max_bytes)
 {
u64 delalloc_start;
u64 delalloc_end;
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 6dbc645..f98602e 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -345,4 +345,10 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 
start,
 int end_extent_writepage(struct page *page, int err, u64 start, u64 end);
 int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
 int mirror_num);
+#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
+noinline u64 find_lock_delalloc_range(struct inode *inode,
+ struct extent_io_tree *tree,
+ struct page *locked_page, u64 *start,
+ u64 *end, u64 max_bytes);
+#endif
 #endif
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 0991fb1..2bdaafd 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1791,10 +1791,20 @@ static int btrfs_run_sanity_tests(void)
 {
int ret;
 
-   ret = btrfs_test_free_space_cache();
+   ret = btrfs_init_test_fs();
if (ret)
return ret;
-   return btrfs_test_extent_buffer_operations();
+
+   ret = btrfs_test_free_space_cache();
+   if (ret)
+   goto out;
+   ret = btrfs_test_extent_buffer_operations();
+   if (ret)
+   goto out;
+   ret = btrfs_test_extent_io();
+out:
+   btrfs_destroy_test_fs();
+   return ret;
 }
 
 static int __init init_btrfs_fs(void)
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
new file mode 100644
index 000..697d527
--- /dev/null
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 Fusion IO.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software 

Re: [PATCH] Btrfs: disallow 'btrfs {balance,replace} cancel' on ro mounts

2013-10-10 Thread Wang Shilong

On 10/11/2013 01:40 AM, Ilya Dryomov wrote:

I have a question in my mind.

Can we reach a state that there is operation in progress when filesystem
has been readonly?If we do cancel operations on a ro filesystem, we should
get No operations in progress .

Thanks,
Wang

For both balance and replace, cancelling involves changing the on-disk
state and committing a transaction, which is not a good thing to do on
read-only filesystems.

Cc: Stefan Behrens sbehr...@giantdisaster.de
Signed-off-by: Ilya Dryomov idryo...@gmail.com
---
  fs/btrfs/dev-replace.c |3 +++
  fs/btrfs/volumes.c |3 +++
  2 files changed, 6 insertions(+)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 9efb94e..98df261 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -650,6 +650,9 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info 
*fs_info)
u64 result;
int ret;
  
+	if (fs_info-sb-s_flags  MS_RDONLY)

+   return -EROFS;
+
mutex_lock(dev_replace-lock_finishing_cancel_unmount);
btrfs_dev_replace_lock(dev_replace);
switch (dev_replace-replace_state) {
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index a306db9..2630f38 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3424,6 +3424,9 @@ int btrfs_pause_balance(struct btrfs_fs_info *fs_info)
  
  int btrfs_cancel_balance(struct btrfs_fs_info *fs_info)

  {
+   if (fs_info-sb-s_flags  MS_RDONLY)
+   return -EROFS;
+
mutex_lock(fs_info-balance_mutex);
if (!fs_info-balance_ctl) {
mutex_unlock(fs_info-balance_mutex);


--
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: add tests for find_lock_delalloc_range

2013-10-10 Thread Liu Bo
On Thu, Oct 10, 2013 at 09:02:57PM -0400, Josef Bacik wrote:
 So both Liu and I made huge messes of find_lock_delalloc_range trying to fix
 stuff, me first by fixing extent size, then him by fixing something I broke 
 and
 then me again telling him to fix it a different way.  So this is obviously a
 candidate for some testing.  This patch adds a pseudo fs so we can allocate 
 fake
 inodes for tests that need an inode or pages.  Then it addes a bunch of tests 
 to
 make sure find_lock_delalloc_range is acting the way it is supposed to.  With
 this patch and all of our previous patches to find_lock_delalloc_range I am 
 sure
 it is working as expected now.  Thanks,
 
 Signed-off-by: Josef Bacik jba...@fusionio.com
 ---
 V1-V2: I forgot to inlude tests/btrfs-tests.c

Oh, when I looked at this yesterday, I thought it was maybe based on btrfs-next
and let it go...

It'd be good to add a V2 in the title.
Others look good to me.

Reviewed-by: Liu Bo bo.li@oracle.com

-liubo

  fs/btrfs/Makefile|   2 +-
  fs/btrfs/ctree.h |   6 +
  fs/btrfs/extent_io.c |   9 +-
  fs/btrfs/extent_io.h |   6 +
  fs/btrfs/super.c |  14 +-
  fs/btrfs/tests/btrfs-tests.c |  68 ++
  fs/btrfs/tests/btrfs-tests.h |  15 +++
  fs/btrfs/tests/extent-io-tests.c | 276 
 +++
  include/uapi/linux/magic.h   |   2 +-
  9 files changed, 389 insertions(+), 9 deletions(-)
  create mode 100644 fs/btrfs/tests/btrfs-tests.c
  create mode 100644 fs/btrfs/tests/extent-io-tests.c
 
 diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
 index 4c7dfbf..cac4f2d 100644
 --- a/fs/btrfs/Makefile
 +++ b/fs/btrfs/Makefile
 @@ -15,4 +15,4 @@ btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
  btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
  
  btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
 - tests/extent-buffer-tests.o
 + tests/extent-buffer-tests.o tests/btrfs-tests.o tests/extent-io-tests.o
 diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
 index 9ca15a8..2f39806 100644
 --- a/fs/btrfs/ctree.h
 +++ b/fs/btrfs/ctree.h
 @@ -47,6 +47,12 @@ extern struct kmem_cache *btrfs_path_cachep;
  extern struct kmem_cache *btrfs_free_space_cachep;
  struct btrfs_ordered_sum;
  
 +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
 +#define STATIC noinline
 +#else
 +#define STATIC static noinline
 +#endif
 +
  #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
  
  #define BTRFS_MAX_MIRRORS 3
 diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
 index 2bf6f46..c10291cc 100644
 --- a/fs/btrfs/extent_io.c
 +++ b/fs/btrfs/extent_io.c
 @@ -1598,11 +1598,10 @@ done:
   *
   * 1 is returned if we find something, 0 if nothing was in the tree
   */
 -static noinline u64 find_lock_delalloc_range(struct inode *inode,
 -  struct extent_io_tree *tree,
 -  struct page *locked_page,
 -  u64 *start, u64 *end,
 -  u64 max_bytes)
 +STATIC u64 find_lock_delalloc_range(struct inode *inode,
 + struct extent_io_tree *tree,
 + struct page *locked_page, u64 *start,
 + u64 *end, u64 max_bytes)
  {
   u64 delalloc_start;
   u64 delalloc_end;
 diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
 index 6dbc645..f98602e 100644
 --- a/fs/btrfs/extent_io.h
 +++ b/fs/btrfs/extent_io.h
 @@ -345,4 +345,10 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 
 start,
  int end_extent_writepage(struct page *page, int err, u64 start, u64 end);
  int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
int mirror_num);
 +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
 +noinline u64 find_lock_delalloc_range(struct inode *inode,
 +   struct extent_io_tree *tree,
 +   struct page *locked_page, u64 *start,
 +   u64 *end, u64 max_bytes);
 +#endif
  #endif
 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
 index 0991fb1..2bdaafd 100644
 --- a/fs/btrfs/super.c
 +++ b/fs/btrfs/super.c
 @@ -1791,10 +1791,20 @@ static int btrfs_run_sanity_tests(void)
  {
   int ret;
  
 - ret = btrfs_test_free_space_cache();
 + ret = btrfs_init_test_fs();
   if (ret)
   return ret;
 - return btrfs_test_extent_buffer_operations();
 +
 + ret = btrfs_test_free_space_cache();
 + if (ret)
 + goto out;
 + ret = btrfs_test_extent_buffer_operations();
 + if (ret)
 + goto out;
 + ret = btrfs_test_extent_io();
 +out:
 + btrfs_destroy_test_fs();
 + return ret;
  }
  
  static int __init init_btrfs_fs(void)
 diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
 new