disk-io.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. /*
  2. * Copyright (C) 2007 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #include <linux/fs.h>
  19. #include <linux/blkdev.h>
  20. #include <linux/crc32c.h>
  21. #include <linux/scatterlist.h>
  22. #include <linux/swap.h>
  23. #include <linux/radix-tree.h>
  24. #include <linux/writeback.h>
  25. #include <linux/buffer_head.h> // for block_sync_page
  26. #include "ctree.h"
  27. #include "disk-io.h"
  28. #include "transaction.h"
  29. #include "btrfs_inode.h"
  30. #include "volumes.h"
  31. #include "print-tree.h"
  32. #if 0
  33. static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
  34. {
  35. if (extent_buffer_blocknr(buf) != btrfs_header_blocknr(buf)) {
  36. printk(KERN_CRIT "buf blocknr(buf) is %llu, header is %llu\n",
  37. (unsigned long long)extent_buffer_blocknr(buf),
  38. (unsigned long long)btrfs_header_blocknr(buf));
  39. return 1;
  40. }
  41. return 0;
  42. }
  43. #endif
  44. static struct extent_io_ops btree_extent_io_ops;
  45. struct extent_map *btree_get_extent(struct inode *inode, struct page *page,
  46. size_t page_offset, u64 start, u64 len,
  47. int create)
  48. {
  49. struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
  50. struct extent_map *em;
  51. int ret;
  52. again:
  53. spin_lock(&em_tree->lock);
  54. em = lookup_extent_mapping(em_tree, start, len);
  55. spin_unlock(&em_tree->lock);
  56. if (em) {
  57. goto out;
  58. }
  59. em = alloc_extent_map(GFP_NOFS);
  60. if (!em) {
  61. em = ERR_PTR(-ENOMEM);
  62. goto out;
  63. }
  64. em->start = 0;
  65. em->len = i_size_read(inode);
  66. em->block_start = 0;
  67. em->bdev = inode->i_sb->s_bdev;
  68. spin_lock(&em_tree->lock);
  69. ret = add_extent_mapping(em_tree, em);
  70. spin_unlock(&em_tree->lock);
  71. if (ret == -EEXIST) {
  72. free_extent_map(em);
  73. em = NULL;
  74. goto again;
  75. } else if (ret) {
  76. em = ERR_PTR(ret);
  77. }
  78. out:
  79. return em;
  80. }
  81. u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len)
  82. {
  83. return crc32c(seed, data, len);
  84. }
  85. void btrfs_csum_final(u32 crc, char *result)
  86. {
  87. *(__le32 *)result = ~cpu_to_le32(crc);
  88. }
  89. static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
  90. int verify)
  91. {
  92. char result[BTRFS_CRC32_SIZE];
  93. unsigned long len;
  94. unsigned long cur_len;
  95. unsigned long offset = BTRFS_CSUM_SIZE;
  96. char *map_token = NULL;
  97. char *kaddr;
  98. unsigned long map_start;
  99. unsigned long map_len;
  100. int err;
  101. u32 crc = ~(u32)0;
  102. len = buf->len - offset;
  103. while(len > 0) {
  104. err = map_private_extent_buffer(buf, offset, 32,
  105. &map_token, &kaddr,
  106. &map_start, &map_len, KM_USER0);
  107. if (err) {
  108. printk("failed to map extent buffer! %lu\n",
  109. offset);
  110. return 1;
  111. }
  112. cur_len = min(len, map_len - (offset - map_start));
  113. crc = btrfs_csum_data(root, kaddr + offset - map_start,
  114. crc, cur_len);
  115. len -= cur_len;
  116. offset += cur_len;
  117. unmap_extent_buffer(buf, map_token, KM_USER0);
  118. }
  119. btrfs_csum_final(crc, result);
  120. if (verify) {
  121. int from_this_trans = 0;
  122. if (root->fs_info->running_transaction &&
  123. btrfs_header_generation(buf) ==
  124. root->fs_info->running_transaction->transid)
  125. from_this_trans = 1;
  126. /* FIXME, this is not good */
  127. if (memcmp_extent_buffer(buf, result, 0, BTRFS_CRC32_SIZE)) {
  128. u32 val;
  129. u32 found = 0;
  130. memcpy(&found, result, BTRFS_CRC32_SIZE);
  131. read_extent_buffer(buf, &val, 0, BTRFS_CRC32_SIZE);
  132. WARN_ON(1);
  133. printk("btrfs: %s checksum verify failed on %llu "
  134. "wanted %X found %X from_this_trans %d "
  135. "level %d\n",
  136. root->fs_info->sb->s_id,
  137. buf->start, val, found, from_this_trans,
  138. btrfs_header_level(buf));
  139. return 1;
  140. }
  141. } else {
  142. write_extent_buffer(buf, result, 0, BTRFS_CRC32_SIZE);
  143. }
  144. return 0;
  145. }
  146. int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
  147. {
  148. struct extent_io_tree *tree;
  149. u64 start = (u64)page->index << PAGE_CACHE_SHIFT;
  150. u64 found_start;
  151. int found_level;
  152. unsigned long len;
  153. struct extent_buffer *eb;
  154. tree = &BTRFS_I(page->mapping->host)->io_tree;
  155. if (page->private == EXTENT_PAGE_PRIVATE)
  156. goto out;
  157. if (!page->private)
  158. goto out;
  159. len = page->private >> 2;
  160. if (len == 0) {
  161. WARN_ON(1);
  162. }
  163. eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
  164. read_extent_buffer_pages(tree, eb, start + PAGE_CACHE_SIZE, 1,
  165. btree_get_extent);
  166. btrfs_clear_buffer_defrag(eb);
  167. found_start = btrfs_header_bytenr(eb);
  168. if (found_start != start) {
  169. printk("warning: eb start incorrect %Lu buffer %Lu len %lu\n",
  170. start, found_start, len);
  171. WARN_ON(1);
  172. goto err;
  173. }
  174. if (eb->first_page != page) {
  175. printk("bad first page %lu %lu\n", eb->first_page->index,
  176. page->index);
  177. WARN_ON(1);
  178. goto err;
  179. }
  180. if (!PageUptodate(page)) {
  181. printk("csum not up to date page %lu\n", page->index);
  182. WARN_ON(1);
  183. goto err;
  184. }
  185. found_level = btrfs_header_level(eb);
  186. spin_lock(&root->fs_info->hash_lock);
  187. btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN);
  188. spin_unlock(&root->fs_info->hash_lock);
  189. csum_tree_block(root, eb, 0);
  190. err:
  191. free_extent_buffer(eb);
  192. out:
  193. return 0;
  194. }
  195. static int btree_writepage_io_hook(struct page *page, u64 start, u64 end)
  196. {
  197. struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
  198. csum_dirty_buffer(root, page);
  199. return 0;
  200. }
  201. static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio)
  202. {
  203. struct btrfs_root *root = BTRFS_I(inode)->root;
  204. u64 offset;
  205. offset = bio->bi_sector << 9;
  206. if (offset == BTRFS_SUPER_INFO_OFFSET) {
  207. bio->bi_bdev = root->fs_info->sb->s_bdev;
  208. submit_bio(rw, bio);
  209. return 0;
  210. }
  211. return btrfs_map_bio(BTRFS_I(inode)->root, rw, bio);
  212. }
  213. static int btree_writepage(struct page *page, struct writeback_control *wbc)
  214. {
  215. struct extent_io_tree *tree;
  216. tree = &BTRFS_I(page->mapping->host)->io_tree;
  217. return extent_write_full_page(tree, page, btree_get_extent, wbc);
  218. }
  219. static int btree_writepages(struct address_space *mapping,
  220. struct writeback_control *wbc)
  221. {
  222. struct extent_io_tree *tree;
  223. tree = &BTRFS_I(mapping->host)->io_tree;
  224. if (wbc->sync_mode == WB_SYNC_NONE) {
  225. u64 num_dirty;
  226. u64 start = 0;
  227. unsigned long thresh = 96 * 1024 * 1024;
  228. if (wbc->for_kupdate)
  229. return 0;
  230. if (current_is_pdflush()) {
  231. thresh = 96 * 1024 * 1024;
  232. } else {
  233. thresh = 8 * 1024 * 1024;
  234. }
  235. num_dirty = count_range_bits(tree, &start, (u64)-1,
  236. thresh, EXTENT_DIRTY);
  237. if (num_dirty < thresh) {
  238. return 0;
  239. }
  240. }
  241. return extent_writepages(tree, mapping, btree_get_extent, wbc);
  242. }
  243. int btree_readpage(struct file *file, struct page *page)
  244. {
  245. struct extent_io_tree *tree;
  246. tree = &BTRFS_I(page->mapping->host)->io_tree;
  247. return extent_read_full_page(tree, page, btree_get_extent);
  248. }
  249. static int btree_releasepage(struct page *page, gfp_t gfp_flags)
  250. {
  251. struct extent_io_tree *tree;
  252. struct extent_map_tree *map;
  253. int ret;
  254. tree = &BTRFS_I(page->mapping->host)->io_tree;
  255. map = &BTRFS_I(page->mapping->host)->extent_tree;
  256. ret = try_release_extent_mapping(map, tree, page, gfp_flags);
  257. if (ret == 1) {
  258. ClearPagePrivate(page);
  259. set_page_private(page, 0);
  260. page_cache_release(page);
  261. }
  262. return ret;
  263. }
  264. static void btree_invalidatepage(struct page *page, unsigned long offset)
  265. {
  266. struct extent_io_tree *tree;
  267. tree = &BTRFS_I(page->mapping->host)->io_tree;
  268. extent_invalidatepage(tree, page, offset);
  269. btree_releasepage(page, GFP_NOFS);
  270. }
  271. #if 0
  272. static int btree_writepage(struct page *page, struct writeback_control *wbc)
  273. {
  274. struct buffer_head *bh;
  275. struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
  276. struct buffer_head *head;
  277. if (!page_has_buffers(page)) {
  278. create_empty_buffers(page, root->fs_info->sb->s_blocksize,
  279. (1 << BH_Dirty)|(1 << BH_Uptodate));
  280. }
  281. head = page_buffers(page);
  282. bh = head;
  283. do {
  284. if (buffer_dirty(bh))
  285. csum_tree_block(root, bh, 0);
  286. bh = bh->b_this_page;
  287. } while (bh != head);
  288. return block_write_full_page(page, btree_get_block, wbc);
  289. }
  290. #endif
  291. static struct address_space_operations btree_aops = {
  292. .readpage = btree_readpage,
  293. .writepage = btree_writepage,
  294. .writepages = btree_writepages,
  295. .releasepage = btree_releasepage,
  296. .invalidatepage = btree_invalidatepage,
  297. .sync_page = block_sync_page,
  298. };
  299. int readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize)
  300. {
  301. struct extent_buffer *buf = NULL;
  302. struct inode *btree_inode = root->fs_info->btree_inode;
  303. int ret = 0;
  304. buf = btrfs_find_create_tree_block(root, bytenr, blocksize);
  305. if (!buf)
  306. return 0;
  307. read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree,
  308. buf, 0, 0, btree_get_extent);
  309. free_extent_buffer(buf);
  310. return ret;
  311. }
  312. static int close_all_devices(struct btrfs_fs_info *fs_info)
  313. {
  314. struct list_head *list;
  315. struct list_head *next;
  316. struct btrfs_device *device;
  317. list = &fs_info->fs_devices->devices;
  318. list_for_each(next, list) {
  319. device = list_entry(next, struct btrfs_device, dev_list);
  320. if (device->bdev && device->bdev != fs_info->sb->s_bdev)
  321. close_bdev_excl(device->bdev);
  322. device->bdev = NULL;
  323. }
  324. return 0;
  325. }
  326. int btrfs_verify_block_csum(struct btrfs_root *root,
  327. struct extent_buffer *buf)
  328. {
  329. struct extent_io_tree *io_tree;
  330. u64 end;
  331. int ret;
  332. io_tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree;
  333. if (buf->flags & EXTENT_CSUM)
  334. return 0;
  335. end = min_t(u64, buf->len, PAGE_CACHE_SIZE);
  336. end = buf->start + end - 1;
  337. if (test_range_bit(io_tree, buf->start, end, EXTENT_CSUM, 1)) {
  338. buf->flags |= EXTENT_CSUM;
  339. return 0;
  340. }
  341. lock_extent(io_tree, buf->start, end, GFP_NOFS);
  342. if (test_range_bit(io_tree, buf->start, end, EXTENT_CSUM, 1)) {
  343. buf->flags |= EXTENT_CSUM;
  344. ret = 0;
  345. goto out_unlock;
  346. }
  347. ret = csum_tree_block(root, buf, 1);
  348. set_extent_bits(io_tree, buf->start, end, EXTENT_CSUM, GFP_NOFS);
  349. buf->flags |= EXTENT_CSUM;
  350. out_unlock:
  351. unlock_extent(io_tree, buf->start, end, GFP_NOFS);
  352. return ret;
  353. }
  354. struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
  355. u64 bytenr, u32 blocksize)
  356. {
  357. struct inode *btree_inode = root->fs_info->btree_inode;
  358. struct extent_buffer *eb;
  359. eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
  360. bytenr, blocksize, GFP_NOFS);
  361. return eb;
  362. }
  363. struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
  364. u64 bytenr, u32 blocksize)
  365. {
  366. struct inode *btree_inode = root->fs_info->btree_inode;
  367. struct extent_buffer *eb;
  368. eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
  369. bytenr, blocksize, NULL, GFP_NOFS);
  370. return eb;
  371. }
  372. struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
  373. u32 blocksize)
  374. {
  375. struct extent_buffer *buf = NULL;
  376. struct inode *btree_inode = root->fs_info->btree_inode;
  377. struct extent_io_tree *io_tree;
  378. int ret;
  379. io_tree = &BTRFS_I(btree_inode)->io_tree;
  380. buf = btrfs_find_create_tree_block(root, bytenr, blocksize);
  381. if (!buf)
  382. return NULL;
  383. read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree, buf, 0, 1,
  384. btree_get_extent);
  385. ret = btrfs_verify_block_csum(root, buf);
  386. return buf;
  387. }
  388. int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  389. struct extent_buffer *buf)
  390. {
  391. struct inode *btree_inode = root->fs_info->btree_inode;
  392. if (btrfs_header_generation(buf) ==
  393. root->fs_info->running_transaction->transid)
  394. clear_extent_buffer_dirty(&BTRFS_I(btree_inode)->io_tree,
  395. buf);
  396. return 0;
  397. }
  398. int wait_on_tree_block_writeback(struct btrfs_root *root,
  399. struct extent_buffer *buf)
  400. {
  401. struct inode *btree_inode = root->fs_info->btree_inode;
  402. wait_on_extent_buffer_writeback(&BTRFS_I(btree_inode)->io_tree,
  403. buf);
  404. return 0;
  405. }
  406. static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
  407. u32 stripesize, struct btrfs_root *root,
  408. struct btrfs_fs_info *fs_info,
  409. u64 objectid)
  410. {
  411. root->node = NULL;
  412. root->inode = NULL;
  413. root->commit_root = NULL;
  414. root->sectorsize = sectorsize;
  415. root->nodesize = nodesize;
  416. root->leafsize = leafsize;
  417. root->stripesize = stripesize;
  418. root->ref_cows = 0;
  419. root->track_dirty = 0;
  420. root->fs_info = fs_info;
  421. root->objectid = objectid;
  422. root->last_trans = 0;
  423. root->highest_inode = 0;
  424. root->last_inode_alloc = 0;
  425. root->name = NULL;
  426. root->in_sysfs = 0;
  427. INIT_LIST_HEAD(&root->dirty_list);
  428. memset(&root->root_key, 0, sizeof(root->root_key));
  429. memset(&root->root_item, 0, sizeof(root->root_item));
  430. memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
  431. memset(&root->root_kobj, 0, sizeof(root->root_kobj));
  432. init_completion(&root->kobj_unregister);
  433. root->defrag_running = 0;
  434. root->defrag_level = 0;
  435. root->root_key.objectid = objectid;
  436. return 0;
  437. }
  438. static int find_and_setup_root(struct btrfs_root *tree_root,
  439. struct btrfs_fs_info *fs_info,
  440. u64 objectid,
  441. struct btrfs_root *root)
  442. {
  443. int ret;
  444. u32 blocksize;
  445. __setup_root(tree_root->nodesize, tree_root->leafsize,
  446. tree_root->sectorsize, tree_root->stripesize,
  447. root, fs_info, objectid);
  448. ret = btrfs_find_last_root(tree_root, objectid,
  449. &root->root_item, &root->root_key);
  450. BUG_ON(ret);
  451. blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
  452. root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
  453. blocksize);
  454. BUG_ON(!root->node);
  455. return 0;
  456. }
  457. struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_fs_info *fs_info,
  458. struct btrfs_key *location)
  459. {
  460. struct btrfs_root *root;
  461. struct btrfs_root *tree_root = fs_info->tree_root;
  462. struct btrfs_path *path;
  463. struct extent_buffer *l;
  464. u64 highest_inode;
  465. u32 blocksize;
  466. int ret = 0;
  467. root = kzalloc(sizeof(*root), GFP_NOFS);
  468. if (!root)
  469. return ERR_PTR(-ENOMEM);
  470. if (location->offset == (u64)-1) {
  471. ret = find_and_setup_root(tree_root, fs_info,
  472. location->objectid, root);
  473. if (ret) {
  474. kfree(root);
  475. return ERR_PTR(ret);
  476. }
  477. goto insert;
  478. }
  479. __setup_root(tree_root->nodesize, tree_root->leafsize,
  480. tree_root->sectorsize, tree_root->stripesize,
  481. root, fs_info, location->objectid);
  482. path = btrfs_alloc_path();
  483. BUG_ON(!path);
  484. ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0);
  485. if (ret != 0) {
  486. if (ret > 0)
  487. ret = -ENOENT;
  488. goto out;
  489. }
  490. l = path->nodes[0];
  491. read_extent_buffer(l, &root->root_item,
  492. btrfs_item_ptr_offset(l, path->slots[0]),
  493. sizeof(root->root_item));
  494. memcpy(&root->root_key, location, sizeof(*location));
  495. ret = 0;
  496. out:
  497. btrfs_release_path(root, path);
  498. btrfs_free_path(path);
  499. if (ret) {
  500. kfree(root);
  501. return ERR_PTR(ret);
  502. }
  503. blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
  504. root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
  505. blocksize);
  506. BUG_ON(!root->node);
  507. insert:
  508. root->ref_cows = 1;
  509. ret = btrfs_find_highest_inode(root, &highest_inode);
  510. if (ret == 0) {
  511. root->highest_inode = highest_inode;
  512. root->last_inode_alloc = highest_inode;
  513. }
  514. return root;
  515. }
  516. struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info,
  517. u64 root_objectid)
  518. {
  519. struct btrfs_root *root;
  520. if (root_objectid == BTRFS_ROOT_TREE_OBJECTID)
  521. return fs_info->tree_root;
  522. if (root_objectid == BTRFS_EXTENT_TREE_OBJECTID)
  523. return fs_info->extent_root;
  524. root = radix_tree_lookup(&fs_info->fs_roots_radix,
  525. (unsigned long)root_objectid);
  526. return root;
  527. }
  528. struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info,
  529. struct btrfs_key *location)
  530. {
  531. struct btrfs_root *root;
  532. int ret;
  533. if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
  534. return fs_info->tree_root;
  535. if (location->objectid == BTRFS_EXTENT_TREE_OBJECTID)
  536. return fs_info->extent_root;
  537. root = radix_tree_lookup(&fs_info->fs_roots_radix,
  538. (unsigned long)location->objectid);
  539. if (root)
  540. return root;
  541. root = btrfs_read_fs_root_no_radix(fs_info, location);
  542. if (IS_ERR(root))
  543. return root;
  544. ret = radix_tree_insert(&fs_info->fs_roots_radix,
  545. (unsigned long)root->root_key.objectid,
  546. root);
  547. if (ret) {
  548. free_extent_buffer(root->node);
  549. kfree(root);
  550. return ERR_PTR(ret);
  551. }
  552. ret = btrfs_find_dead_roots(fs_info->tree_root,
  553. root->root_key.objectid, root);
  554. BUG_ON(ret);
  555. return root;
  556. }
  557. struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
  558. struct btrfs_key *location,
  559. const char *name, int namelen)
  560. {
  561. struct btrfs_root *root;
  562. int ret;
  563. root = btrfs_read_fs_root_no_name(fs_info, location);
  564. if (!root)
  565. return NULL;
  566. if (root->in_sysfs)
  567. return root;
  568. ret = btrfs_set_root_name(root, name, namelen);
  569. if (ret) {
  570. free_extent_buffer(root->node);
  571. kfree(root);
  572. return ERR_PTR(ret);
  573. }
  574. ret = btrfs_sysfs_add_root(root);
  575. if (ret) {
  576. free_extent_buffer(root->node);
  577. kfree(root->name);
  578. kfree(root);
  579. return ERR_PTR(ret);
  580. }
  581. root->in_sysfs = 1;
  582. return root;
  583. }
  584. #if 0
  585. static int add_hasher(struct btrfs_fs_info *info, char *type) {
  586. struct btrfs_hasher *hasher;
  587. hasher = kmalloc(sizeof(*hasher), GFP_NOFS);
  588. if (!hasher)
  589. return -ENOMEM;
  590. hasher->hash_tfm = crypto_alloc_hash(type, 0, CRYPTO_ALG_ASYNC);
  591. if (!hasher->hash_tfm) {
  592. kfree(hasher);
  593. return -EINVAL;
  594. }
  595. spin_lock(&info->hash_lock);
  596. list_add(&hasher->list, &info->hashers);
  597. spin_unlock(&info->hash_lock);
  598. return 0;
  599. }
  600. #endif
  601. static int btrfs_congested_fn(void *congested_data, int bdi_bits)
  602. {
  603. struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data;
  604. int ret = 0;
  605. struct list_head *cur;
  606. struct btrfs_device *device;
  607. struct backing_dev_info *bdi;
  608. list_for_each(cur, &info->fs_devices->devices) {
  609. device = list_entry(cur, struct btrfs_device, dev_list);
  610. bdi = blk_get_backing_dev_info(device->bdev);
  611. if (bdi && bdi_congested(bdi, bdi_bits)) {
  612. ret = 1;
  613. break;
  614. }
  615. }
  616. return ret;
  617. }
  618. void btrfs_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
  619. {
  620. struct list_head *cur;
  621. struct btrfs_device *device;
  622. struct btrfs_fs_info *info;
  623. info = (struct btrfs_fs_info *)bdi->unplug_io_data;
  624. list_for_each(cur, &info->fs_devices->devices) {
  625. device = list_entry(cur, struct btrfs_device, dev_list);
  626. bdi = blk_get_backing_dev_info(device->bdev);
  627. if (bdi->unplug_io_fn) {
  628. bdi->unplug_io_fn(bdi, page);
  629. }
  630. }
  631. }
  632. static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
  633. {
  634. bdi_init(bdi);
  635. bdi->ra_pages = default_backing_dev_info.ra_pages * 4;
  636. bdi->state = 0;
  637. bdi->capabilities = default_backing_dev_info.capabilities;
  638. bdi->unplug_io_fn = btrfs_unplug_io_fn;
  639. bdi->unplug_io_data = info;
  640. bdi->congested_fn = btrfs_congested_fn;
  641. bdi->congested_data = info;
  642. return 0;
  643. }
  644. struct btrfs_root *open_ctree(struct super_block *sb,
  645. struct btrfs_fs_devices *fs_devices)
  646. {
  647. u32 sectorsize;
  648. u32 nodesize;
  649. u32 leafsize;
  650. u32 blocksize;
  651. u32 stripesize;
  652. struct btrfs_root *extent_root = kmalloc(sizeof(struct btrfs_root),
  653. GFP_NOFS);
  654. struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root),
  655. GFP_NOFS);
  656. struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info),
  657. GFP_NOFS);
  658. struct btrfs_root *chunk_root = kmalloc(sizeof(struct btrfs_root),
  659. GFP_NOFS);
  660. struct btrfs_root *dev_root = kmalloc(sizeof(struct btrfs_root),
  661. GFP_NOFS);
  662. int ret;
  663. int err = -EINVAL;
  664. struct btrfs_super_block *disk_super;
  665. if (!extent_root || !tree_root || !fs_info) {
  666. err = -ENOMEM;
  667. goto fail;
  668. }
  669. INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_NOFS);
  670. INIT_LIST_HEAD(&fs_info->trans_list);
  671. INIT_LIST_HEAD(&fs_info->dead_roots);
  672. INIT_LIST_HEAD(&fs_info->hashers);
  673. spin_lock_init(&fs_info->hash_lock);
  674. spin_lock_init(&fs_info->delalloc_lock);
  675. spin_lock_init(&fs_info->new_trans_lock);
  676. init_completion(&fs_info->kobj_unregister);
  677. sb_set_blocksize(sb, 4096);
  678. fs_info->tree_root = tree_root;
  679. fs_info->extent_root = extent_root;
  680. fs_info->chunk_root = chunk_root;
  681. fs_info->dev_root = dev_root;
  682. fs_info->fs_devices = fs_devices;
  683. INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
  684. INIT_LIST_HEAD(&fs_info->space_info);
  685. btrfs_mapping_init(&fs_info->mapping_tree);
  686. fs_info->sb = sb;
  687. fs_info->max_extent = (u64)-1;
  688. fs_info->max_inline = 8192 * 1024;
  689. setup_bdi(fs_info, &fs_info->bdi);
  690. fs_info->btree_inode = new_inode(sb);
  691. fs_info->btree_inode->i_ino = 1;
  692. fs_info->btree_inode->i_nlink = 1;
  693. fs_info->btree_inode->i_size = sb->s_bdev->bd_inode->i_size;
  694. fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
  695. fs_info->btree_inode->i_mapping->backing_dev_info = &fs_info->bdi;
  696. extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
  697. fs_info->btree_inode->i_mapping,
  698. GFP_NOFS);
  699. extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree,
  700. GFP_NOFS);
  701. BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
  702. extent_io_tree_init(&fs_info->free_space_cache,
  703. fs_info->btree_inode->i_mapping, GFP_NOFS);
  704. extent_io_tree_init(&fs_info->block_group_cache,
  705. fs_info->btree_inode->i_mapping, GFP_NOFS);
  706. extent_io_tree_init(&fs_info->pinned_extents,
  707. fs_info->btree_inode->i_mapping, GFP_NOFS);
  708. extent_io_tree_init(&fs_info->pending_del,
  709. fs_info->btree_inode->i_mapping, GFP_NOFS);
  710. extent_io_tree_init(&fs_info->extent_ins,
  711. fs_info->btree_inode->i_mapping, GFP_NOFS);
  712. fs_info->do_barriers = 1;
  713. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
  714. INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info);
  715. #else
  716. INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner);
  717. #endif
  718. BTRFS_I(fs_info->btree_inode)->root = tree_root;
  719. memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
  720. sizeof(struct btrfs_key));
  721. insert_inode_hash(fs_info->btree_inode);
  722. mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
  723. mutex_init(&fs_info->trans_mutex);
  724. mutex_init(&fs_info->fs_mutex);
  725. #if 0
  726. ret = add_hasher(fs_info, "crc32c");
  727. if (ret) {
  728. printk("btrfs: failed hash setup, modprobe cryptomgr?\n");
  729. err = -ENOMEM;
  730. goto fail_iput;
  731. }
  732. #endif
  733. __setup_root(4096, 4096, 4096, 4096, tree_root,
  734. fs_info, BTRFS_ROOT_TREE_OBJECTID);
  735. fs_info->sb_buffer = read_tree_block(tree_root,
  736. BTRFS_SUPER_INFO_OFFSET,
  737. 4096);
  738. if (!fs_info->sb_buffer)
  739. goto fail_iput;
  740. read_extent_buffer(fs_info->sb_buffer, &fs_info->super_copy, 0,
  741. sizeof(fs_info->super_copy));
  742. read_extent_buffer(fs_info->sb_buffer, fs_info->fsid,
  743. (unsigned long)btrfs_super_fsid(fs_info->sb_buffer),
  744. BTRFS_FSID_SIZE);
  745. disk_super = &fs_info->super_copy;
  746. if (!btrfs_super_root(disk_super))
  747. goto fail_sb_buffer;
  748. if (btrfs_super_num_devices(disk_super) != fs_devices->num_devices) {
  749. printk("Btrfs: wanted %llu devices, but found %llu\n",
  750. (unsigned long long)btrfs_super_num_devices(disk_super),
  751. (unsigned long long)fs_devices->num_devices);
  752. goto fail_sb_buffer;
  753. }
  754. nodesize = btrfs_super_nodesize(disk_super);
  755. leafsize = btrfs_super_leafsize(disk_super);
  756. sectorsize = btrfs_super_sectorsize(disk_super);
  757. stripesize = btrfs_super_stripesize(disk_super);
  758. tree_root->nodesize = nodesize;
  759. tree_root->leafsize = leafsize;
  760. tree_root->sectorsize = sectorsize;
  761. tree_root->stripesize = stripesize;
  762. sb_set_blocksize(sb, sectorsize);
  763. i_size_write(fs_info->btree_inode,
  764. btrfs_super_total_bytes(disk_super));
  765. if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC,
  766. sizeof(disk_super->magic))) {
  767. printk("btrfs: valid FS not found on %s\n", sb->s_id);
  768. goto fail_sb_buffer;
  769. }
  770. mutex_lock(&fs_info->fs_mutex);
  771. ret = btrfs_read_sys_array(tree_root);
  772. BUG_ON(ret);
  773. blocksize = btrfs_level_size(tree_root,
  774. btrfs_super_chunk_root_level(disk_super));
  775. __setup_root(nodesize, leafsize, sectorsize, stripesize,
  776. chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID);
  777. chunk_root->node = read_tree_block(chunk_root,
  778. btrfs_super_chunk_root(disk_super),
  779. blocksize);
  780. BUG_ON(!chunk_root->node);
  781. ret = btrfs_read_chunk_tree(chunk_root);
  782. BUG_ON(ret);
  783. blocksize = btrfs_level_size(tree_root,
  784. btrfs_super_root_level(disk_super));
  785. tree_root->node = read_tree_block(tree_root,
  786. btrfs_super_root(disk_super),
  787. blocksize);
  788. if (!tree_root->node)
  789. goto fail_sb_buffer;
  790. ret = find_and_setup_root(tree_root, fs_info,
  791. BTRFS_EXTENT_TREE_OBJECTID, extent_root);
  792. if (ret)
  793. goto fail_tree_root;
  794. extent_root->track_dirty = 1;
  795. ret = find_and_setup_root(tree_root, fs_info,
  796. BTRFS_DEV_TREE_OBJECTID, dev_root);
  797. dev_root->track_dirty = 1;
  798. if (ret)
  799. goto fail_extent_root;
  800. btrfs_read_block_groups(extent_root);
  801. fs_info->generation = btrfs_super_generation(disk_super) + 1;
  802. fs_info->data_alloc_profile = (u64)-1;
  803. fs_info->metadata_alloc_profile = (u64)-1;
  804. fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
  805. mutex_unlock(&fs_info->fs_mutex);
  806. return tree_root;
  807. fail_extent_root:
  808. free_extent_buffer(extent_root->node);
  809. fail_tree_root:
  810. mutex_unlock(&fs_info->fs_mutex);
  811. free_extent_buffer(tree_root->node);
  812. fail_sb_buffer:
  813. free_extent_buffer(fs_info->sb_buffer);
  814. extent_io_tree_empty_lru(&BTRFS_I(fs_info->btree_inode)->io_tree);
  815. fail_iput:
  816. iput(fs_info->btree_inode);
  817. fail:
  818. close_all_devices(fs_info);
  819. kfree(extent_root);
  820. kfree(tree_root);
  821. bdi_destroy(&fs_info->bdi);
  822. kfree(fs_info);
  823. return ERR_PTR(err);
  824. }
  825. int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root
  826. *root)
  827. {
  828. int ret;
  829. struct extent_buffer *super = root->fs_info->sb_buffer;
  830. struct inode *btree_inode = root->fs_info->btree_inode;
  831. struct super_block *sb = root->fs_info->sb;
  832. if (!btrfs_test_opt(root, NOBARRIER))
  833. blkdev_issue_flush(sb->s_bdev, NULL);
  834. set_extent_buffer_dirty(&BTRFS_I(btree_inode)->io_tree, super);
  835. ret = sync_page_range_nolock(btree_inode, btree_inode->i_mapping,
  836. super->start, super->len);
  837. if (!btrfs_test_opt(root, NOBARRIER))
  838. blkdev_issue_flush(sb->s_bdev, NULL);
  839. return ret;
  840. }
  841. int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
  842. {
  843. radix_tree_delete(&fs_info->fs_roots_radix,
  844. (unsigned long)root->root_key.objectid);
  845. if (root->in_sysfs)
  846. btrfs_sysfs_del_root(root);
  847. if (root->inode)
  848. iput(root->inode);
  849. if (root->node)
  850. free_extent_buffer(root->node);
  851. if (root->commit_root)
  852. free_extent_buffer(root->commit_root);
  853. if (root->name)
  854. kfree(root->name);
  855. kfree(root);
  856. return 0;
  857. }
  858. static int del_fs_roots(struct btrfs_fs_info *fs_info)
  859. {
  860. int ret;
  861. struct btrfs_root *gang[8];
  862. int i;
  863. while(1) {
  864. ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix,
  865. (void **)gang, 0,
  866. ARRAY_SIZE(gang));
  867. if (!ret)
  868. break;
  869. for (i = 0; i < ret; i++)
  870. btrfs_free_fs_root(fs_info, gang[i]);
  871. }
  872. return 0;
  873. }
  874. int close_ctree(struct btrfs_root *root)
  875. {
  876. int ret;
  877. struct btrfs_trans_handle *trans;
  878. struct btrfs_fs_info *fs_info = root->fs_info;
  879. fs_info->closing = 1;
  880. btrfs_transaction_flush_work(root);
  881. mutex_lock(&fs_info->fs_mutex);
  882. btrfs_defrag_dirty_roots(root->fs_info);
  883. trans = btrfs_start_transaction(root, 1);
  884. ret = btrfs_commit_transaction(trans, root);
  885. /* run commit again to drop the original snapshot */
  886. trans = btrfs_start_transaction(root, 1);
  887. btrfs_commit_transaction(trans, root);
  888. ret = btrfs_write_and_wait_transaction(NULL, root);
  889. BUG_ON(ret);
  890. write_ctree_super(NULL, root);
  891. mutex_unlock(&fs_info->fs_mutex);
  892. if (fs_info->delalloc_bytes) {
  893. printk("btrfs: at unmount delalloc count %Lu\n",
  894. fs_info->delalloc_bytes);
  895. }
  896. if (fs_info->extent_root->node)
  897. free_extent_buffer(fs_info->extent_root->node);
  898. if (fs_info->tree_root->node)
  899. free_extent_buffer(fs_info->tree_root->node);
  900. if (root->fs_info->chunk_root->node);
  901. free_extent_buffer(root->fs_info->chunk_root->node);
  902. if (root->fs_info->dev_root->node);
  903. free_extent_buffer(root->fs_info->dev_root->node);
  904. free_extent_buffer(fs_info->sb_buffer);
  905. btrfs_free_block_groups(root->fs_info);
  906. del_fs_roots(fs_info);
  907. filemap_write_and_wait(fs_info->btree_inode->i_mapping);
  908. extent_io_tree_empty_lru(&fs_info->free_space_cache);
  909. extent_io_tree_empty_lru(&fs_info->block_group_cache);
  910. extent_io_tree_empty_lru(&fs_info->pinned_extents);
  911. extent_io_tree_empty_lru(&fs_info->pending_del);
  912. extent_io_tree_empty_lru(&fs_info->extent_ins);
  913. extent_io_tree_empty_lru(&BTRFS_I(fs_info->btree_inode)->io_tree);
  914. truncate_inode_pages(fs_info->btree_inode->i_mapping, 0);
  915. iput(fs_info->btree_inode);
  916. #if 0
  917. while(!list_empty(&fs_info->hashers)) {
  918. struct btrfs_hasher *hasher;
  919. hasher = list_entry(fs_info->hashers.next, struct btrfs_hasher,
  920. hashers);
  921. list_del(&hasher->hashers);
  922. crypto_free_hash(&fs_info->hash_tfm);
  923. kfree(hasher);
  924. }
  925. #endif
  926. close_all_devices(fs_info);
  927. btrfs_mapping_tree_free(&fs_info->mapping_tree);
  928. bdi_destroy(&fs_info->bdi);
  929. kfree(fs_info->extent_root);
  930. kfree(fs_info->tree_root);
  931. kfree(fs_info->chunk_root);
  932. kfree(fs_info->dev_root);
  933. return 0;
  934. }
  935. int btrfs_buffer_uptodate(struct extent_buffer *buf)
  936. {
  937. struct inode *btree_inode = buf->first_page->mapping->host;
  938. return extent_buffer_uptodate(&BTRFS_I(btree_inode)->io_tree, buf);
  939. }
  940. int btrfs_set_buffer_uptodate(struct extent_buffer *buf)
  941. {
  942. struct inode *btree_inode = buf->first_page->mapping->host;
  943. return set_extent_buffer_uptodate(&BTRFS_I(btree_inode)->io_tree,
  944. buf);
  945. }
  946. void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
  947. {
  948. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  949. u64 transid = btrfs_header_generation(buf);
  950. struct inode *btree_inode = root->fs_info->btree_inode;
  951. if (transid != root->fs_info->generation) {
  952. printk(KERN_CRIT "transid mismatch buffer %llu, found %Lu running %Lu\n",
  953. (unsigned long long)buf->start,
  954. transid, root->fs_info->generation);
  955. WARN_ON(1);
  956. }
  957. set_extent_buffer_dirty(&BTRFS_I(btree_inode)->io_tree, buf);
  958. }
  959. void btrfs_throttle(struct btrfs_root *root)
  960. {
  961. struct backing_dev_info *bdi;
  962. bdi = root->fs_info->sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
  963. if (root->fs_info->throttles && bdi_write_congested(bdi)) {
  964. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
  965. congestion_wait(WRITE, HZ/20);
  966. #else
  967. blk_congestion_wait(WRITE, HZ/20);
  968. #endif
  969. }
  970. }
  971. void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr)
  972. {
  973. balance_dirty_pages_ratelimited_nr(
  974. root->fs_info->btree_inode->i_mapping, 1);
  975. }
  976. void btrfs_set_buffer_defrag(struct extent_buffer *buf)
  977. {
  978. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  979. struct inode *btree_inode = root->fs_info->btree_inode;
  980. set_extent_bits(&BTRFS_I(btree_inode)->io_tree, buf->start,
  981. buf->start + buf->len - 1, EXTENT_DEFRAG, GFP_NOFS);
  982. }
  983. void btrfs_set_buffer_defrag_done(struct extent_buffer *buf)
  984. {
  985. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  986. struct inode *btree_inode = root->fs_info->btree_inode;
  987. set_extent_bits(&BTRFS_I(btree_inode)->io_tree, buf->start,
  988. buf->start + buf->len - 1, EXTENT_DEFRAG_DONE,
  989. GFP_NOFS);
  990. }
  991. int btrfs_buffer_defrag(struct extent_buffer *buf)
  992. {
  993. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  994. struct inode *btree_inode = root->fs_info->btree_inode;
  995. return test_range_bit(&BTRFS_I(btree_inode)->io_tree,
  996. buf->start, buf->start + buf->len - 1, EXTENT_DEFRAG, 0);
  997. }
  998. int btrfs_buffer_defrag_done(struct extent_buffer *buf)
  999. {
  1000. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1001. struct inode *btree_inode = root->fs_info->btree_inode;
  1002. return test_range_bit(&BTRFS_I(btree_inode)->io_tree,
  1003. buf->start, buf->start + buf->len - 1,
  1004. EXTENT_DEFRAG_DONE, 0);
  1005. }
  1006. int btrfs_clear_buffer_defrag_done(struct extent_buffer *buf)
  1007. {
  1008. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1009. struct inode *btree_inode = root->fs_info->btree_inode;
  1010. return clear_extent_bits(&BTRFS_I(btree_inode)->io_tree,
  1011. buf->start, buf->start + buf->len - 1,
  1012. EXTENT_DEFRAG_DONE, GFP_NOFS);
  1013. }
  1014. int btrfs_clear_buffer_defrag(struct extent_buffer *buf)
  1015. {
  1016. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1017. struct inode *btree_inode = root->fs_info->btree_inode;
  1018. return clear_extent_bits(&BTRFS_I(btree_inode)->io_tree,
  1019. buf->start, buf->start + buf->len - 1,
  1020. EXTENT_DEFRAG, GFP_NOFS);
  1021. }
  1022. int btrfs_read_buffer(struct extent_buffer *buf)
  1023. {
  1024. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1025. struct inode *btree_inode = root->fs_info->btree_inode;
  1026. return read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree,
  1027. buf, 0, 1, btree_get_extent);
  1028. }
  1029. static struct extent_io_ops btree_extent_io_ops = {
  1030. .writepage_io_hook = btree_writepage_io_hook,
  1031. .submit_bio_hook = btree_submit_bio_hook,
  1032. /* note we're sharing with inode.c for the merge bio hook */
  1033. .merge_bio_hook = btrfs_merge_bio_hook,
  1034. };