Btrfs: Update nodatacow mode to support cloned single files and resizing

Before, nodatacow only checked to make sure multiple roots didn't have
references on a single extent.  This check makes sure that multiple
inodes don't have references.

nodatacow needed an extra check to see if the block group was currently
readonly.  This way cows forced by the chunk relocation code are honored.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 8e69b5a..30a5094 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -721,12 +721,14 @@
 
 u32 btrfs_count_snapshots_in_path(struct btrfs_root *root,
 				  struct btrfs_path *count_path,
+				  u64 expected_owner,
 				  u64 first_extent)
 {
 	struct btrfs_root *extent_root = root->fs_info->extent_root;
 	struct btrfs_path *path;
 	u64 bytenr;
 	u64 found_objectid;
+	u64 found_owner;
 	u64 root_objectid = root->root_key.objectid;
 	u32 total_count = 0;
 	u32 cur_count;
@@ -792,6 +794,13 @@
 			total_count = 2;
 			goto out;
 		}
+		if (level == -1) {
+			found_owner = btrfs_ref_objectid(l, ref_item);
+			if (found_owner != expected_owner) {
+				total_count = 2;
+				goto out;
+			}
+		}
 		total_count = 1;
 		path->slots[0]++;
 	}