aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.h78
-rw-r--r--fs/btrfs/delayed-ref.c38
-rw-r--r--fs/btrfs/delayed-ref.h1
-rw-r--r--fs/btrfs/disk-io.c27
-rw-r--r--fs/btrfs/disk-io.h7
-rw-r--r--fs/btrfs/extent_io.c227
-rw-r--r--fs/btrfs/extent_io.h21
-rw-r--r--fs/btrfs/free-space-cache.c15
-rw-r--r--fs/btrfs/free-space-cache.h1
-rw-r--r--fs/btrfs/inode.c52
-rw-r--r--fs/btrfs/locking.c25
-rw-r--r--fs/btrfs/locking.h2
-rw-r--r--fs/btrfs/ref-cache.c164
-rw-r--r--fs/btrfs/ref-cache.h24
-rw-r--r--fs/btrfs/relocation.c2
-rw-r--r--fs/btrfs/root-tree.c47
-rw-r--r--fs/btrfs/sysfs.c65
-rw-r--r--fs/btrfs/volumes.c19
-rw-r--r--fs/btrfs/volumes.h3
19 files changed, 1 insertions, 817 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index b66216e636c2..e37d441617d2 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1440,26 +1440,12 @@ static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
1440 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); 1440 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
1441} 1441}
1442 1442
1443static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
1444 struct btrfs_chunk *c, int nr,
1445 u64 val)
1446{
1447 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
1448}
1449
1450static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb, 1443static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
1451 struct btrfs_chunk *c, int nr) 1444 struct btrfs_chunk *c, int nr)
1452{ 1445{
1453 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); 1446 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
1454} 1447}
1455 1448
1456static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
1457 struct btrfs_chunk *c, int nr,
1458 u64 val)
1459{
1460 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
1461}
1462
1463/* struct btrfs_block_group_item */ 1449/* struct btrfs_block_group_item */
1464BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, 1450BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
1465 used, 64); 1451 used, 64);
@@ -1517,14 +1503,6 @@ btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
1517 return (struct btrfs_timespec *)ptr; 1503 return (struct btrfs_timespec *)ptr;
1518} 1504}
1519 1505
1520static inline struct btrfs_timespec *
1521btrfs_inode_otime(struct btrfs_inode_item *inode_item)
1522{
1523 unsigned long ptr = (unsigned long)inode_item;
1524 ptr += offsetof(struct btrfs_inode_item, otime);
1525 return (struct btrfs_timespec *)ptr;
1526}
1527
1528BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); 1506BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
1529BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); 1507BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
1530 1508
@@ -1875,33 +1853,6 @@ static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1875 return (u8 *)ptr; 1853 return (u8 *)ptr;
1876} 1854}
1877 1855
1878static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1879{
1880 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1881 return (u8 *)ptr;
1882}
1883
1884static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1885{
1886 unsigned long ptr = offsetof(struct btrfs_header, csum);
1887 return (u8 *)ptr;
1888}
1889
1890static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1891{
1892 return NULL;
1893}
1894
1895static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1896{
1897 return NULL;
1898}
1899
1900static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1901{
1902 return NULL;
1903}
1904
1905static inline int btrfs_is_leaf(struct extent_buffer *eb) 1856static inline int btrfs_is_leaf(struct extent_buffer *eb)
1906{ 1857{
1907 return btrfs_header_level(eb) == 0; 1858 return btrfs_header_level(eb) == 0;
@@ -2055,22 +2006,6 @@ static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
2055 return sb->s_fs_info; 2006 return sb->s_fs_info;
2056} 2007}
2057 2008
2058static inline int btrfs_set_root_name(struct btrfs_root *root,
2059 const char *name, int len)
2060{
2061 /* if we already have a name just free it */
2062 kfree(root->name);
2063
2064 root->name = kmalloc(len+1, GFP_KERNEL);
2065 if (!root->name)
2066 return -ENOMEM;
2067
2068 memcpy(root->name, name, len);
2069 root->name[len] = '\0';
2070
2071 return 0;
2072}
2073
2074static inline u32 btrfs_level_size(struct btrfs_root *root, int level) 2009static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
2075{ 2010{
2076 if (level == 0) 2011 if (level == 0)
@@ -2304,11 +2239,6 @@ static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
2304 2239
2305int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root 2240int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
2306 *root, struct btrfs_key *key, void *data, u32 data_size); 2241 *root, struct btrfs_key *key, void *data, u32 data_size);
2307int btrfs_insert_some_items(struct btrfs_trans_handle *trans,
2308 struct btrfs_root *root,
2309 struct btrfs_path *path,
2310 struct btrfs_key *cpu_key, u32 *data_size,
2311 int nr);
2312int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, 2242int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
2313 struct btrfs_root *root, 2243 struct btrfs_root *root,
2314 struct btrfs_path *path, 2244 struct btrfs_path *path,
@@ -2354,8 +2284,6 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
2354 *item); 2284 *item);
2355int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct 2285int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
2356 btrfs_root_item *item, struct btrfs_key *key); 2286 btrfs_root_item *item, struct btrfs_key *key);
2357int btrfs_search_root(struct btrfs_root *root, u64 search_start,
2358 u64 *found_objectid);
2359int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid); 2287int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid);
2360int btrfs_find_orphan_roots(struct btrfs_root *tree_root); 2288int btrfs_find_orphan_roots(struct btrfs_root *tree_root);
2361int btrfs_set_root_node(struct btrfs_root_item *item, 2289int btrfs_set_root_node(struct btrfs_root_item *item,
@@ -2494,8 +2422,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
2494 u32 min_type); 2422 u32 min_type);
2495 2423
2496int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput); 2424int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput);
2497int btrfs_start_one_delalloc_inode(struct btrfs_root *root, int delay_iput,
2498 int sync);
2499int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, 2425int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
2500 struct extent_state **cached_state); 2426 struct extent_state **cached_state);
2501int btrfs_writepages(struct address_space *mapping, 2427int btrfs_writepages(struct address_space *mapping,
@@ -2579,10 +2505,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
2579/* sysfs.c */ 2505/* sysfs.c */
2580int btrfs_init_sysfs(void); 2506int btrfs_init_sysfs(void);
2581void btrfs_exit_sysfs(void); 2507void btrfs_exit_sysfs(void);
2582int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
2583int btrfs_sysfs_add_root(struct btrfs_root *root);
2584void btrfs_sysfs_del_root(struct btrfs_root *root);
2585void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
2586 2508
2587/* xattr.c */ 2509/* xattr.c */
2588ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); 2510ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index bce28f653899..cb9b9a431fc9 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -281,44 +281,6 @@ again:
281} 281}
282 282
283/* 283/*
284 * This checks to see if there are any delayed refs in the
285 * btree for a given bytenr. It returns one if it finds any
286 * and zero otherwise.
287 *
288 * If it only finds a head node, it returns 0.
289 *
290 * The idea is to use this when deciding if you can safely delete an
291 * extent from the extent allocation tree. There may be a pending
292 * ref in the rbtree that adds or removes references, so as long as this
293 * returns one you need to leave the BTRFS_EXTENT_ITEM in the extent
294 * allocation tree.
295 */
296int btrfs_delayed_ref_pending(struct btrfs_trans_handle *trans, u64 bytenr)
297{
298 struct btrfs_delayed_ref_node *ref;
299 struct btrfs_delayed_ref_root *delayed_refs;
300 struct rb_node *prev_node;
301 int ret = 0;
302
303 delayed_refs = &trans->transaction->delayed_refs;
304 spin_lock(&delayed_refs->lock);
305
306 ref = find_ref_head(&delayed_refs->root, bytenr, NULL);
307 if (ref) {
308 prev_node = rb_prev(&ref->rb_node);
309 if (!prev_node)
310 goto out;
311 ref = rb_entry(prev_node, struct btrfs_delayed_ref_node,
312 rb_node);
313 if (ref->bytenr == bytenr)
314 ret = 1;
315 }
316out:
317 spin_unlock(&delayed_refs->lock);
318 return ret;
319}
320
321/*
322 * helper function to update an extent delayed ref in the 284 * helper function to update an extent delayed ref in the
323 * rbtree. existing and update must both have the same 285 * rbtree. existing and update must both have the same
324 * bytenr and parent 286 * bytenr and parent
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index 946ed71ab84f..e287e3b0eab0 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -166,7 +166,6 @@ int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans,
166 166
167struct btrfs_delayed_ref_head * 167struct btrfs_delayed_ref_head *
168btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr); 168btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr);
169int btrfs_delayed_ref_pending(struct btrfs_trans_handle *trans, u64 bytenr);
170int btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans, 169int btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans,
171 struct btrfs_delayed_ref_head *head); 170 struct btrfs_delayed_ref_head *head);
172int btrfs_find_ref_cluster(struct btrfs_trans_handle *trans, 171int btrfs_find_ref_cluster(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 4084959b36fd..fa287c551ffc 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -650,12 +650,6 @@ unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info)
650 return 256 * limit; 650 return 256 * limit;
651} 651}
652 652
653int btrfs_congested_async(struct btrfs_fs_info *info, int iodone)
654{
655 return atomic_read(&info->nr_async_bios) >
656 btrfs_async_submit_limit(info);
657}
658
659static void run_one_async_start(struct btrfs_work *work) 653static void run_one_async_start(struct btrfs_work *work)
660{ 654{
661 struct async_submit_bio *async; 655 struct async_submit_bio *async;
@@ -1283,21 +1277,6 @@ out:
1283 return root; 1277 return root;
1284} 1278}
1285 1279
1286struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info,
1287 u64 root_objectid)
1288{
1289 struct btrfs_root *root;
1290
1291 if (root_objectid == BTRFS_ROOT_TREE_OBJECTID)
1292 return fs_info->tree_root;
1293 if (root_objectid == BTRFS_EXTENT_TREE_OBJECTID)
1294 return fs_info->extent_root;
1295
1296 root = radix_tree_lookup(&fs_info->fs_roots_radix,
1297 (unsigned long)root_objectid);
1298 return root;
1299}
1300
1301struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, 1280struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info,
1302 struct btrfs_key *location) 1281 struct btrfs_key *location)
1303{ 1282{
@@ -1369,11 +1348,6 @@ fail:
1369 return ERR_PTR(ret); 1348 return ERR_PTR(ret);
1370} 1349}
1371 1350
1372struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
1373 struct btrfs_key *location,
1374 const char *name, int namelen)
1375{
1376 return btrfs_read_fs_root_no_name(fs_info, location);
1377#if 0 1351#if 0
1378 struct btrfs_root *root; 1352 struct btrfs_root *root;
1379 int ret; 1353 int ret;
@@ -1402,7 +1376,6 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
1402 root->in_sysfs = 1; 1376 root->in_sysfs = 1;
1403 return root; 1377 return root;
1404#endif 1378#endif
1405}
1406 1379
1407static int btrfs_congested_fn(void *congested_data, int bdi_bits) 1380static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1408{ 1381{
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 758f3ca614ee..2d75f9e896f6 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -55,11 +55,6 @@ int btrfs_commit_super(struct btrfs_root *root);
55int btrfs_error_commit_super(struct btrfs_root *root); 55int btrfs_error_commit_super(struct btrfs_root *root);
56struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, 56struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
57 u64 bytenr, u32 blocksize); 57 u64 bytenr, u32 blocksize);
58struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info,
59 u64 root_objectid);
60struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
61 struct btrfs_key *location,
62 const char *name, int namelen);
63struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root, 58struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root,
64 struct btrfs_key *location); 59 struct btrfs_key *location);
65struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, 60struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info,
@@ -80,8 +75,6 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
80 unsigned long bio_flags, u64 bio_offset, 75 unsigned long bio_flags, u64 bio_offset,
81 extent_submit_bio_hook_t *submit_bio_start, 76 extent_submit_bio_hook_t *submit_bio_start,
82 extent_submit_bio_hook_t *submit_bio_done); 77 extent_submit_bio_hook_t *submit_bio_done);
83
84int btrfs_congested_async(struct btrfs_fs_info *info, int iodone);
85unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info); 78unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info);
86int btrfs_write_tree_block(struct extent_buffer *buf); 79int btrfs_write_tree_block(struct extent_buffer *buf);
87int btrfs_wait_tree_block_writeback(struct extent_buffer *buf); 80int btrfs_wait_tree_block_writeback(struct extent_buffer *buf);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 9369289ce771..91208296ff2b 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -941,13 +941,6 @@ int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
941 NULL, mask); 941 NULL, mask);
942} 942}
943 943
944static int clear_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
945 gfp_t mask)
946{
947 return clear_extent_bit(tree, start, end, EXTENT_NEW, 0, 0,
948 NULL, mask);
949}
950
951int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, 944int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
952 struct extent_state **cached_state, gfp_t mask) 945 struct extent_state **cached_state, gfp_t mask)
953{ 946{
@@ -963,11 +956,6 @@ static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
963 cached_state, mask); 956 cached_state, mask);
964} 957}
965 958
966int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end)
967{
968 return wait_extent_bit(tree, start, end, EXTENT_WRITEBACK);
969}
970
971/* 959/*
972 * either insert or lock state struct between start and end use mask to tell 960 * either insert or lock state struct between start and end use mask to tell
973 * us if waiting is desired. 961 * us if waiting is desired.
@@ -1028,25 +1016,6 @@ int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask)
1028} 1016}
1029 1017
1030/* 1018/*
1031 * helper function to set pages and extents in the tree dirty
1032 */
1033int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end)
1034{
1035 unsigned long index = start >> PAGE_CACHE_SHIFT;
1036 unsigned long end_index = end >> PAGE_CACHE_SHIFT;
1037 struct page *page;
1038
1039 while (index <= end_index) {
1040 page = find_get_page(tree->mapping, index);
1041 BUG_ON(!page);
1042 __set_page_dirty_nobuffers(page);
1043 page_cache_release(page);
1044 index++;
1045 }
1046 return 0;
1047}
1048
1049/*
1050 * helper function to set both pages and extents in the tree writeback 1019 * helper function to set both pages and extents in the tree writeback
1051 */ 1020 */
1052static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end) 1021static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)
@@ -1819,46 +1788,6 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
1819 bio_put(bio); 1788 bio_put(bio);
1820} 1789}
1821 1790
1822/*
1823 * IO done from prepare_write is pretty simple, we just unlock
1824 * the structs in the extent tree when done, and set the uptodate bits
1825 * as appropriate.
1826 */
1827static void end_bio_extent_preparewrite(struct bio *bio, int err)
1828{
1829 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
1830 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
1831 struct extent_io_tree *tree;
1832 u64 start;
1833 u64 end;
1834
1835 do {
1836 struct page *page = bvec->bv_page;
1837 struct extent_state *cached = NULL;
1838 tree = &BTRFS_I(page->mapping->host)->io_tree;
1839
1840 start = ((u64)page->index << PAGE_CACHE_SHIFT) +
1841 bvec->bv_offset;
1842 end = start + bvec->bv_len - 1;
1843
1844 if (--bvec >= bio->bi_io_vec)
1845 prefetchw(&bvec->bv_page->flags);
1846
1847 if (uptodate) {
1848 set_extent_uptodate(tree, start, end, &cached,
1849 GFP_ATOMIC);
1850 } else {
1851 ClearPageUptodate(page);
1852 SetPageError(page);
1853 }
1854
1855 unlock_extent_cached(tree, start, end, &cached, GFP_ATOMIC);
1856
1857 } while (bvec >= bio->bi_io_vec);
1858
1859 bio_put(bio);
1860}
1861
1862struct bio * 1791struct bio *
1863btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, 1792btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs,
1864 gfp_t gfp_flags) 1793 gfp_t gfp_flags)
@@ -2720,128 +2649,6 @@ int extent_invalidatepage(struct extent_io_tree *tree,
2720} 2649}
2721 2650
2722/* 2651/*
2723 * simple commit_write call, set_range_dirty is used to mark both
2724 * the pages and the extent records as dirty
2725 */
2726int extent_commit_write(struct extent_io_tree *tree,
2727 struct inode *inode, struct page *page,
2728 unsigned from, unsigned to)
2729{
2730 loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
2731
2732 set_page_extent_mapped(page);
2733 set_page_dirty(page);
2734
2735 if (pos > inode->i_size) {
2736 i_size_write(inode, pos);
2737 mark_inode_dirty(inode);
2738 }
2739 return 0;
2740}
2741
2742int extent_prepare_write(struct extent_io_tree *tree,
2743 struct inode *inode, struct page *page,
2744 unsigned from, unsigned to, get_extent_t *get_extent)
2745{
2746 u64 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
2747 u64 page_end = page_start + PAGE_CACHE_SIZE - 1;
2748 u64 block_start;
2749 u64 orig_block_start;
2750 u64 block_end;
2751 u64 cur_end;
2752 struct extent_map *em;
2753 unsigned blocksize = 1 << inode->i_blkbits;
2754 size_t pg_offset = 0;
2755 size_t block_off_start;
2756 size_t block_off_end;
2757 int err = 0;
2758 int iocount = 0;
2759 int ret = 0;
2760 int isnew;
2761
2762 set_page_extent_mapped(page);
2763
2764 block_start = (page_start + from) & ~((u64)blocksize - 1);
2765 block_end = (page_start + to - 1) | (blocksize - 1);
2766 orig_block_start = block_start;
2767
2768 lock_extent(tree, page_start, page_end, GFP_NOFS);
2769 while (block_start <= block_end) {
2770 em = get_extent(inode, page, pg_offset, block_start,
2771 block_end - block_start + 1, 1);
2772 if (IS_ERR_OR_NULL(em))
2773 goto err;
2774
2775 cur_end = min(block_end, extent_map_end(em) - 1);
2776 block_off_start = block_start & (PAGE_CACHE_SIZE - 1);
2777 block_off_end = block_off_start + blocksize;
2778 isnew = clear_extent_new(tree, block_start, cur_end, GFP_NOFS);
2779
2780 if (!PageUptodate(page) && isnew &&
2781 (block_off_end > to || block_off_start < from)) {
2782 void *kaddr;
2783
2784 kaddr = kmap_atomic(page, KM_USER0);
2785 if (block_off_end > to)
2786 memset(kaddr + to, 0, block_off_end - to);
2787 if (block_off_start < from)
2788 memset(kaddr + block_off_start, 0,
2789 from - block_off_start);
2790 flush_dcache_page(page);
2791 kunmap_atomic(kaddr, KM_USER0);
2792 }
2793 if ((em->block_start != EXTENT_MAP_HOLE &&
2794 em->block_start != EXTENT_MAP_INLINE) &&
2795 !isnew && !PageUptodate(page) &&
2796 (block_off_end > to || block_off_start < from) &&
2797 !test_range_bit(tree, block_start, cur_end,
2798 EXTENT_UPTODATE, 1, NULL)) {
2799 u64 sector;
2800 u64 extent_offset = block_start - em->start;
2801 size_t iosize;
2802 sector = (em->block_start + extent_offset) >> 9;
2803 iosize = (cur_end - block_start + blocksize) &
2804 ~((u64)blocksize - 1);
2805 /*
2806 * we've already got the extent locked, but we
2807 * need to split the state such that our end_bio
2808 * handler can clear the lock.
2809 */
2810 set_extent_bit(tree, block_start,
2811 block_start + iosize - 1,
2812 EXTENT_LOCKED, 0, NULL, NULL, GFP_NOFS);
2813 ret = submit_extent_page(READ, tree, page,
2814 sector, iosize, pg_offset, em->bdev,
2815 NULL, 1,
2816 end_bio_extent_preparewrite, 0,
2817 0, 0);
2818 if (ret && !err)
2819 err = ret;
2820 iocount++;
2821 block_start = block_start + iosize;
2822 } else {
2823 struct extent_state *cached = NULL;
2824
2825 set_extent_uptodate(tree, block_start, cur_end, &cached,
2826 GFP_NOFS);
2827 unlock_extent_cached(tree, block_start, cur_end,
2828 &cached, GFP_NOFS);
2829 block_start = cur_end + 1;
2830 }
2831 pg_offset = block_start & (PAGE_CACHE_SIZE - 1);
2832 free_extent_map(em);
2833 }
2834 if (iocount) {
2835 wait_extent_bit(tree, orig_block_start,
2836 block_end, EXTENT_LOCKED);
2837 }
2838 check_page_uptodate(tree, page);
2839err:
2840 /* FIXME, zero out newly allocated blocks on error */
2841 return err;
2842}
2843
2844/*
2845 * a helper for releasepage, this tests for areas of the page that 2652 * a helper for releasepage, this tests for areas of the page that
2846 * are locked or under IO and drops the related state bits if it is safe 2653 * are locked or under IO and drops the related state bits if it is safe
2847 * to drop the page. 2654 * to drop the page.
@@ -2927,33 +2734,6 @@ int try_release_extent_mapping(struct extent_map_tree *map,
2927 return try_release_extent_state(map, tree, page, mask); 2734 return try_release_extent_state(map, tree, page, mask);
2928} 2735}
2929 2736
2930sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
2931 get_extent_t *get_extent)
2932{
2933 struct inode *inode = mapping->host;
2934 struct extent_state *cached_state = NULL;
2935 u64 start = iblock << inode->i_blkbits;
2936 sector_t sector = 0;
2937 size_t blksize = (1 << inode->i_blkbits);
2938 struct extent_map *em;
2939
2940 lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + blksize - 1,
2941 0, &cached_state, GFP_NOFS);
2942 em = get_extent(inode, NULL, 0, start, blksize, 0);
2943 unlock_extent_cached(&BTRFS_I(inode)->io_tree, start,
2944 start + blksize - 1, &cached_state, GFP_NOFS);
2945 if (IS_ERR_OR_NULL(em))
2946 return 0;
2947
2948 if (em->block_start > EXTENT_MAP_LAST_BYTE)
2949 goto out;
2950
2951 sector = (em->block_start + start - em->start) >> inode->i_blkbits;
2952out:
2953 free_extent_map(em);
2954 return sector;
2955}
2956
2957/* 2737/*
2958 * helper function for fiemap, which doesn't want to see any holes. 2738 * helper function for fiemap, which doesn't want to see any holes.
2959 * This maps until we find something past 'last' 2739 * This maps until we find something past 'last'
@@ -3437,13 +3217,6 @@ int clear_extent_buffer_dirty(struct extent_io_tree *tree,
3437 return 0; 3217 return 0;
3438} 3218}
3439 3219
3440int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
3441 struct extent_buffer *eb)
3442{
3443 return wait_on_extent_writeback(tree, eb->start,
3444 eb->start + eb->len - 1);
3445}
3446
3447int set_extent_buffer_dirty(struct extent_io_tree *tree, 3220int set_extent_buffer_dirty(struct extent_io_tree *tree,
3448 struct extent_buffer *eb) 3221 struct extent_buffer *eb)
3449{ 3222{
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index d1c5a57c9984..4e8445a4757c 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -153,15 +153,6 @@ static inline int extent_compress_type(unsigned long bio_flags)
153 153
154struct extent_map_tree; 154struct extent_map_tree;
155 155
156static inline struct extent_state *extent_state_next(struct extent_state *state)
157{
158 struct rb_node *node;
159 node = rb_next(&state->rb_node);
160 if (!node)
161 return NULL;
162 return rb_entry(node, struct extent_state, rb_node);
163}
164
165typedef struct extent_map *(get_extent_t)(struct inode *inode, 156typedef struct extent_map *(get_extent_t)(struct inode *inode,
166 struct page *page, 157 struct page *page,
167 size_t pg_offset, 158 size_t pg_offset,
@@ -237,17 +228,8 @@ int extent_readpages(struct extent_io_tree *tree,
237 struct address_space *mapping, 228 struct address_space *mapping,
238 struct list_head *pages, unsigned nr_pages, 229 struct list_head *pages, unsigned nr_pages,
239 get_extent_t get_extent); 230 get_extent_t get_extent);
240int extent_prepare_write(struct extent_io_tree *tree,
241 struct inode *inode, struct page *page,
242 unsigned from, unsigned to, get_extent_t *get_extent);
243int extent_commit_write(struct extent_io_tree *tree,
244 struct inode *inode, struct page *page,
245 unsigned from, unsigned to);
246sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
247 get_extent_t *get_extent);
248int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 231int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
249 __u64 start, __u64 len, get_extent_t *get_extent); 232 __u64 start, __u64 len, get_extent_t *get_extent);
250int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
251int set_state_private(struct extent_io_tree *tree, u64 start, u64 private); 233int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
252int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private); 234int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
253void set_page_extent_mapped(struct page *page); 235void set_page_extent_mapped(struct page *page);
@@ -284,9 +266,6 @@ void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
284 unsigned long src_offset, unsigned long len); 266 unsigned long src_offset, unsigned long len);
285void memset_extent_buffer(struct extent_buffer *eb, char c, 267void memset_extent_buffer(struct extent_buffer *eb, char c,
286 unsigned long start, unsigned long len); 268 unsigned long start, unsigned long len);
287int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
288 struct extent_buffer *eb);
289int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end);
290int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits); 269int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits);
291int clear_extent_buffer_dirty(struct extent_io_tree *tree, 270int clear_extent_buffer_dirty(struct extent_io_tree *tree,
292 struct extent_buffer *eb); 271 struct extent_buffer *eb);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 48fafcb85b0e..0290b0c7b003 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1685,21 +1685,6 @@ void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
1685 "\n", count); 1685 "\n", count);
1686} 1686}
1687 1687
1688u64 btrfs_block_group_free_space(struct btrfs_block_group_cache *block_group)
1689{
1690 struct btrfs_free_space *info;
1691 struct rb_node *n;
1692 u64 ret = 0;
1693
1694 for (n = rb_first(&block_group->free_space_offset); n;
1695 n = rb_next(n)) {
1696 info = rb_entry(n, struct btrfs_free_space, offset_index);
1697 ret += info->bytes;
1698 }
1699
1700 return ret;
1701}
1702
1703/* 1688/*
1704 * for a given cluster, put all of its extents back into the free 1689 * for a given cluster, put all of its extents back into the free
1705 * space cache. If the block group passed doesn't match the block group 1690 * space cache. If the block group passed doesn't match the block group
diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h
index 65c3b935289f..12b2b5165f8a 100644
--- a/fs/btrfs/free-space-cache.h
+++ b/fs/btrfs/free-space-cache.h
@@ -55,7 +55,6 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group,
55 u64 offset, u64 bytes, u64 empty_size); 55 u64 offset, u64 bytes, u64 empty_size);
56void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group, 56void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
57 u64 bytes); 57 u64 bytes);
58u64 btrfs_block_group_free_space(struct btrfs_block_group_cache *block_group);
59int btrfs_find_space_cluster(struct btrfs_trans_handle *trans, 58int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
60 struct btrfs_root *root, 59 struct btrfs_root *root,
61 struct btrfs_block_group_cache *block_group, 60 struct btrfs_block_group_cache *block_group,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2840989737b7..57122a5e8473 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7185,58 +7185,6 @@ int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput)
7185 return 0; 7185 return 0;
7186} 7186}
7187 7187
7188int btrfs_start_one_delalloc_inode(struct btrfs_root *root, int delay_iput,
7189 int sync)
7190{
7191 struct btrfs_inode *binode;
7192 struct inode *inode = NULL;
7193
7194 spin_lock(&root->fs_info->delalloc_lock);
7195 while (!list_empty(&root->fs_info->delalloc_inodes)) {
7196 binode = list_entry(root->fs_info->delalloc_inodes.next,
7197 struct btrfs_inode, delalloc_inodes);
7198 inode = igrab(&binode->vfs_inode);
7199 if (inode) {
7200 list_move_tail(&binode->delalloc_inodes,
7201 &root->fs_info->delalloc_inodes);
7202 break;
7203 }
7204
7205 list_del_init(&binode->delalloc_inodes);
7206 cond_resched_lock(&root->fs_info->delalloc_lock);
7207 }
7208 spin_unlock(&root->fs_info->delalloc_lock);
7209
7210 if (inode) {
7211 if (sync) {
7212 filemap_write_and_wait(inode->i_mapping);
7213 /*
7214 * We have to do this because compression doesn't
7215 * actually set PG_writeback until it submits the pages
7216 * for IO, which happens in an async thread, so we could
7217 * race and not actually wait for any writeback pages
7218 * because they've not been submitted yet. Technically
7219 * this could still be the case for the ordered stuff
7220 * since the async thread may not have started to do its
7221 * work yet. If this becomes the case then we need to
7222 * figure out a way to make sure that in writepage we
7223 * wait for any async pages to be submitted before
7224 * returning so that fdatawait does what its supposed to
7225 * do.
7226 */
7227 btrfs_wait_ordered_range(inode, 0, (u64)-1);
7228 } else {
7229 filemap_flush(inode->i_mapping);
7230 }
7231 if (delay_iput)
7232 btrfs_add_delayed_iput(inode);
7233 else
7234 iput(inode);
7235 return 1;
7236 }
7237 return 0;
7238}
7239
7240static int btrfs_symlink(struct inode *dir, struct dentry *dentry, 7188static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
7241 const char *symname) 7189 const char *symname)
7242{ 7190{
diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
index 6151f2ea38bb..66fa43dc3f0f 100644
--- a/fs/btrfs/locking.c
+++ b/fs/btrfs/locking.c
@@ -185,31 +185,6 @@ sleep:
185 return 0; 185 return 0;
186} 186}
187 187
188/*
189 * Very quick trylock, this does not spin or schedule. It returns
190 * 1 with the spinlock held if it was able to take the lock, or it
191 * returns zero if it was unable to take the lock.
192 *
193 * After this call, scheduling is not safe without first calling
194 * btrfs_set_lock_blocking()
195 */
196int btrfs_try_tree_lock(struct extent_buffer *eb)
197{
198 if (spin_trylock(&eb->lock)) {
199 if (test_bit(EXTENT_BUFFER_BLOCKING, &eb->bflags)) {
200 /*
201 * we've got the spinlock, but the real owner is
202 * blocking. Drop the spinlock and return failure
203 */
204 spin_unlock(&eb->lock);
205 return 0;
206 }
207 return 1;
208 }
209 /* someone else has the spinlock giveup */
210 return 0;
211}
212
213int btrfs_tree_unlock(struct extent_buffer *eb) 188int btrfs_tree_unlock(struct extent_buffer *eb)
214{ 189{
215 /* 190 /*
diff --git a/fs/btrfs/locking.h b/fs/btrfs/locking.h
index 6c4ce457168c..5c33a560a2f1 100644
--- a/fs/btrfs/locking.h
+++ b/fs/btrfs/locking.h
@@ -21,8 +21,6 @@
21 21
22int btrfs_tree_lock(struct extent_buffer *eb); 22int btrfs_tree_lock(struct extent_buffer *eb);
23int btrfs_tree_unlock(struct extent_buffer *eb); 23int btrfs_tree_unlock(struct extent_buffer *eb);
24
25int btrfs_try_tree_lock(struct extent_buffer *eb);
26int btrfs_try_spin_lock(struct extent_buffer *eb); 24int btrfs_try_spin_lock(struct extent_buffer *eb);
27 25
28void btrfs_set_lock_blocking(struct extent_buffer *eb); 26void btrfs_set_lock_blocking(struct extent_buffer *eb);
diff --git a/fs/btrfs/ref-cache.c b/fs/btrfs/ref-cache.c
index a97314cf6bd6..82d569cb6267 100644
--- a/fs/btrfs/ref-cache.c
+++ b/fs/btrfs/ref-cache.c
@@ -23,56 +23,6 @@
23#include "ref-cache.h" 23#include "ref-cache.h"
24#include "transaction.h" 24#include "transaction.h"
25 25
26/*
27 * leaf refs are used to cache the information about which extents
28 * a given leaf has references on. This allows us to process that leaf
29 * in btrfs_drop_snapshot without needing to read it back from disk.
30 */
31
32/*
33 * kmalloc a leaf reference struct and update the counters for the
34 * total ref cache size
35 */
36struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(struct btrfs_root *root,
37 int nr_extents)
38{
39 struct btrfs_leaf_ref *ref;
40 size_t size = btrfs_leaf_ref_size(nr_extents);
41
42 ref = kmalloc(size, GFP_NOFS);
43 if (ref) {
44 spin_lock(&root->fs_info->ref_cache_lock);
45 root->fs_info->total_ref_cache_size += size;
46 spin_unlock(&root->fs_info->ref_cache_lock);
47
48 memset(ref, 0, sizeof(*ref));
49 atomic_set(&ref->usage, 1);
50 INIT_LIST_HEAD(&ref->list);
51 }
52 return ref;
53}
54
55/*
56 * free a leaf reference struct and update the counters for the
57 * total ref cache size
58 */
59void btrfs_free_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref)
60{
61 if (!ref)
62 return;
63 WARN_ON(atomic_read(&ref->usage) == 0);
64 if (atomic_dec_and_test(&ref->usage)) {
65 size_t size = btrfs_leaf_ref_size(ref->nritems);
66
67 BUG_ON(ref->in_tree);
68 kfree(ref);
69
70 spin_lock(&root->fs_info->ref_cache_lock);
71 root->fs_info->total_ref_cache_size -= size;
72 spin_unlock(&root->fs_info->ref_cache_lock);
73 }
74}
75
76static struct rb_node *tree_insert(struct rb_root *root, u64 bytenr, 26static struct rb_node *tree_insert(struct rb_root *root, u64 bytenr,
77 struct rb_node *node) 27 struct rb_node *node)
78{ 28{
@@ -116,117 +66,3 @@ static struct rb_node *tree_search(struct rb_root *root, u64 bytenr)
116 } 66 }
117 return NULL; 67 return NULL;
118} 68}
119
120int btrfs_remove_leaf_refs(struct btrfs_root *root, u64 max_root_gen,
121 int shared)
122{
123 struct btrfs_leaf_ref *ref = NULL;
124 struct btrfs_leaf_ref_tree *tree = root->ref_tree;
125
126 if (shared)
127 tree = &root->fs_info->shared_ref_tree;
128 if (!tree)
129 return 0;
130
131 spin_lock(&tree->lock);
132 while (!list_empty(&tree->list)) {
133 ref = list_entry(tree->list.next, struct btrfs_leaf_ref, list);
134 BUG_ON(ref->tree != tree);
135 if (ref->root_gen > max_root_gen)
136 break;
137 if (!xchg(&ref->in_tree, 0)) {
138 cond_resched_lock(&tree->lock);
139 continue;
140 }
141
142 rb_erase(&ref->rb_node, &tree->root);
143 list_del_init(&ref->list);
144
145 spin_unlock(&tree->lock);
146 btrfs_free_leaf_ref(root, ref);
147 cond_resched();
148 spin_lock(&tree->lock);
149 }
150 spin_unlock(&tree->lock);
151 return 0;
152}
153
154/*
155 * find the leaf ref for a given extent. This returns the ref struct with
156 * a usage reference incremented
157 */
158struct btrfs_leaf_ref *btrfs_lookup_leaf_ref(struct btrfs_root *root,
159 u64 bytenr)
160{
161 struct rb_node *rb;
162 struct btrfs_leaf_ref *ref = NULL;
163 struct btrfs_leaf_ref_tree *tree = root->ref_tree;
164again:
165 if (tree) {
166 spin_lock(&tree->lock);
167 rb = tree_search(&tree->root, bytenr);
168 if (rb)
169 ref = rb_entry(rb, struct btrfs_leaf_ref, rb_node);
170 if (ref)
171 atomic_inc(&ref->usage);
172 spin_unlock(&tree->lock);
173 if (ref)
174 return ref;
175 }
176 if (tree != &root->fs_info->shared_ref_tree) {
177 tree = &root->fs_info->shared_ref_tree;
178 goto again;
179 }
180 return NULL;
181}
182
183/*
184 * add a fully filled in leaf ref struct
185 * remove all the refs older than a given root generation
186 */
187int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref,
188 int shared)
189{
190 int ret = 0;
191 struct rb_node *rb;
192 struct btrfs_leaf_ref_tree *tree = root->ref_tree;
193
194 if (shared)
195 tree = &root->fs_info->shared_ref_tree;
196
197 spin_lock(&tree->lock);
198 rb = tree_insert(&tree->root, ref->bytenr, &ref->rb_node);
199 if (rb) {
200 ret = -EEXIST;
201 } else {
202 atomic_inc(&ref->usage);
203 ref->tree = tree;
204 ref->in_tree = 1;
205 list_add_tail(&ref->list, &tree->list);
206 }
207 spin_unlock(&tree->lock);
208 return ret;
209}
210
211/*
212 * remove a single leaf ref from the tree. This drops the ref held by the tree
213 * only
214 */
215int btrfs_remove_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref)
216{
217 struct btrfs_leaf_ref_tree *tree;
218
219 if (!xchg(&ref->in_tree, 0))
220 return 0;
221
222 tree = ref->tree;
223 spin_lock(&tree->lock);
224
225 rb_erase(&ref->rb_node, &tree->root);
226 list_del_init(&ref->list);
227
228 spin_unlock(&tree->lock);
229
230 btrfs_free_leaf_ref(root, ref);
231 return 0;
232}
diff --git a/fs/btrfs/ref-cache.h b/fs/btrfs/ref-cache.h
index e2a55cb2072b..24f7001f6387 100644
--- a/fs/btrfs/ref-cache.h
+++ b/fs/btrfs/ref-cache.h
@@ -49,28 +49,4 @@ static inline size_t btrfs_leaf_ref_size(int nr_extents)
49 return sizeof(struct btrfs_leaf_ref) + 49 return sizeof(struct btrfs_leaf_ref) +
50 sizeof(struct btrfs_extent_info) * nr_extents; 50 sizeof(struct btrfs_extent_info) * nr_extents;
51} 51}
52
53static inline void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree)
54{
55 tree->root = RB_ROOT;
56 INIT_LIST_HEAD(&tree->list);
57 spin_lock_init(&tree->lock);
58}
59
60static inline int btrfs_leaf_ref_tree_empty(struct btrfs_leaf_ref_tree *tree)
61{
62 return RB_EMPTY_ROOT(&tree->root);
63}
64
65void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree);
66struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(struct btrfs_root *root,
67 int nr_extents);
68void btrfs_free_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref);
69struct btrfs_leaf_ref *btrfs_lookup_leaf_ref(struct btrfs_root *root,
70 u64 bytenr);
71int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref,
72 int shared);
73int btrfs_remove_leaf_refs(struct btrfs_root *root, u64 max_root_gen,
74 int shared);
75int btrfs_remove_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref);
76#endif 52#endif
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index f7b799b151aa..f726e72dd362 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -507,6 +507,7 @@ static int update_backref_cache(struct btrfs_trans_handle *trans,
507 return 1; 507 return 1;
508} 508}
509 509
510
510static int should_ignore_root(struct btrfs_root *root) 511static int should_ignore_root(struct btrfs_root *root)
511{ 512{
512 struct btrfs_root *reloc_root; 513 struct btrfs_root *reloc_root;
@@ -529,7 +530,6 @@ static int should_ignore_root(struct btrfs_root *root)
529 */ 530 */
530 return 1; 531 return 1;
531} 532}
532
533/* 533/*
534 * find reloc tree by address of tree root 534 * find reloc tree by address of tree root
535 */ 535 */
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 59a94c1d9815..3bcfe5a7c330 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -22,53 +22,6 @@
22#include "print-tree.h" 22#include "print-tree.h"
23 23
24/* 24/*
25 * search forward for a root, starting with objectid 'search_start'
26 * if a root key is found, the objectid we find is filled into 'found_objectid'
27 * and 0 is returned. < 0 is returned on error, 1 if there is nothing
28 * left in the tree.
29 */
30int btrfs_search_root(struct btrfs_root *root, u64 search_start,
31 u64 *found_objectid)
32{
33 struct btrfs_path *path;
34 struct btrfs_key search_key;
35 int ret;
36
37 root = root->fs_info->tree_root;
38 search_key.objectid = search_start;
39 search_key.type = (u8)-1;
40 search_key.offset = (u64)-1;
41
42 path = btrfs_alloc_path();
43 BUG_ON(!path);
44again:
45 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
46 if (ret < 0)
47 goto out;
48 if (ret == 0) {
49 ret = 1;
50 goto out;
51 }
52 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
53 ret = btrfs_next_leaf(root, path);
54 if (ret)
55 goto out;
56 }
57 btrfs_item_key_to_cpu(path->nodes[0], &search_key, path->slots[0]);
58 if (search_key.type != BTRFS_ROOT_ITEM_KEY) {
59 search_key.offset++;
60 btrfs_release_path(path);
61 goto again;
62 }
63 ret = 0;
64 *found_objectid = search_key.objectid;
65
66out:
67 btrfs_free_path(path);
68 return ret;
69}
70
71/*
72 * lookup the root with the highest offset for a given objectid. The key we do 25 * lookup the root with the highest offset for a given objectid. The key we do
73 * find is copied into 'key'. If we find something return 0, otherwise 1, < 0 26 * find is copied into 'key'. If we find something return 0, otherwise 1, < 0
74 * on error. 27 * on error.
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 4ce16ef702a3..ab9633fd72a4 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -189,71 +189,6 @@ static struct kobj_type btrfs_super_ktype = {
189/* /sys/fs/btrfs/ entry */ 189/* /sys/fs/btrfs/ entry */
190static struct kset *btrfs_kset; 190static struct kset *btrfs_kset;
191 191
192int btrfs_sysfs_add_super(struct btrfs_fs_info *fs)
193{
194 int error;
195 char *name;
196 char c;
197 int len = strlen(fs->sb->s_id) + 1;
198 int i;
199
200 name = kmalloc(len, GFP_NOFS);
201 if (!name) {
202 error = -ENOMEM;
203 goto fail;
204 }
205
206 for (i = 0; i < len; i++) {
207 c = fs->sb->s_id[i];
208 if (c == '/' || c == '\\')
209 c = '!';
210 name[i] = c;
211 }
212 name[len] = '\0';
213
214 fs->super_kobj.kset = btrfs_kset;
215 error = kobject_init_and_add(&fs->super_kobj, &btrfs_super_ktype,
216 NULL, "%s", name);
217 kfree(name);
218 if (error)
219 goto fail;
220
221 return 0;
222
223fail:
224 printk(KERN_ERR "btrfs: sysfs creation for super failed\n");
225 return error;
226}
227
228int btrfs_sysfs_add_root(struct btrfs_root *root)
229{
230 int error;
231
232 error = kobject_init_and_add(&root->root_kobj, &btrfs_root_ktype,
233 &root->fs_info->super_kobj,
234 "%s", root->name);
235 if (error)
236 goto fail;
237
238 return 0;
239
240fail:
241 printk(KERN_ERR "btrfs: sysfs creation for root failed\n");
242 return error;
243}
244
245void btrfs_sysfs_del_root(struct btrfs_root *root)
246{
247 kobject_put(&root->root_kobj);
248 wait_for_completion(&root->kobj_unregister);
249}
250
251void btrfs_sysfs_del_super(struct btrfs_fs_info *fs)
252{
253 kobject_put(&fs->super_kobj);
254 wait_for_completion(&fs->kobj_unregister);
255}
256
257int btrfs_init_sysfs(void) 192int btrfs_init_sysfs(void)
258{ 193{
259 btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); 194 btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e21130d3f98a..cd0b31a9ba3d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -44,16 +44,6 @@ static int btrfs_relocate_sys_chunks(struct btrfs_root *root);
44static DEFINE_MUTEX(uuid_mutex); 44static DEFINE_MUTEX(uuid_mutex);
45static LIST_HEAD(fs_uuids); 45static LIST_HEAD(fs_uuids);
46 46
47void btrfs_lock_volumes(void)
48{
49 mutex_lock(&uuid_mutex);
50}
51
52void btrfs_unlock_volumes(void)
53{
54 mutex_unlock(&uuid_mutex);
55}
56
57static void lock_chunks(struct btrfs_root *root) 47static void lock_chunks(struct btrfs_root *root)
58{ 48{
59 mutex_lock(&root->fs_info->chunk_mutex); 49 mutex_lock(&root->fs_info->chunk_mutex);
@@ -3688,15 +3678,6 @@ static int read_one_dev(struct btrfs_root *root,
3688 return ret; 3678 return ret;
3689} 3679}
3690 3680
3691int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf)
3692{
3693 struct btrfs_dev_item *dev_item;
3694
3695 dev_item = (struct btrfs_dev_item *)offsetof(struct btrfs_super_block,
3696 dev_item);
3697 return read_one_dev(root, buf, dev_item);
3698}
3699
3700int btrfs_read_sys_array(struct btrfs_root *root) 3681int btrfs_read_sys_array(struct btrfs_root *root)
3701{ 3682{
3702 struct btrfs_super_block *super_copy = &root->fs_info->super_copy; 3683 struct btrfs_super_block *super_copy = &root->fs_info->super_copy;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 036b276b4860..5669ae8ea1c9 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -196,7 +196,6 @@ void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
196void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); 196void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
197int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, 197int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
198 int mirror_num, int async_submit); 198 int mirror_num, int async_submit);
199int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf);
200int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, 199int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
201 fmode_t flags, void *holder); 200 fmode_t flags, void *holder);
202int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, 201int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
@@ -216,8 +215,6 @@ struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid,
216int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); 215int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
217int btrfs_init_new_device(struct btrfs_root *root, char *path); 216int btrfs_init_new_device(struct btrfs_root *root, char *path);
218int btrfs_balance(struct btrfs_root *dev_root); 217int btrfs_balance(struct btrfs_root *dev_root);
219void btrfs_unlock_volumes(void);
220void btrfs_lock_volumes(void);
221int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); 218int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
222int find_free_dev_extent(struct btrfs_trans_handle *trans, 219int find_free_dev_extent(struct btrfs_trans_handle *trans,
223 struct btrfs_device *device, u64 num_bytes, 220 struct btrfs_device *device, u64 num_bytes,