disk-io.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  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/scatterlist.h>
  21. #include <linux/swap.h>
  22. #include <linux/radix-tree.h>
  23. #include <linux/writeback.h>
  24. #include <linux/buffer_head.h> // for block_sync_page
  25. #include <linux/workqueue.h>
  26. #include "crc32c.h"
  27. #include "ctree.h"
  28. #include "disk-io.h"
  29. #include "transaction.h"
  30. #include "btrfs_inode.h"
  31. #include "volumes.h"
  32. #include "print-tree.h"
  33. #include "async-thread.h"
  34. #include "locking.h"
  35. #if 0
  36. static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
  37. {
  38. if (extent_buffer_blocknr(buf) != btrfs_header_blocknr(buf)) {
  39. printk(KERN_CRIT "buf blocknr(buf) is %llu, header is %llu\n",
  40. (unsigned long long)extent_buffer_blocknr(buf),
  41. (unsigned long long)btrfs_header_blocknr(buf));
  42. return 1;
  43. }
  44. return 0;
  45. }
  46. #endif
  47. static struct extent_io_ops btree_extent_io_ops;
  48. static void end_workqueue_fn(struct btrfs_work *work);
  49. struct end_io_wq {
  50. struct bio *bio;
  51. bio_end_io_t *end_io;
  52. void *private;
  53. struct btrfs_fs_info *info;
  54. int error;
  55. int metadata;
  56. struct list_head list;
  57. struct btrfs_work work;
  58. };
  59. struct async_submit_bio {
  60. struct inode *inode;
  61. struct bio *bio;
  62. struct list_head list;
  63. extent_submit_bio_hook_t *submit_bio_hook;
  64. int rw;
  65. int mirror_num;
  66. struct btrfs_work work;
  67. };
  68. struct extent_map *btree_get_extent(struct inode *inode, struct page *page,
  69. size_t page_offset, u64 start, u64 len,
  70. int create)
  71. {
  72. struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
  73. struct extent_map *em;
  74. int ret;
  75. spin_lock(&em_tree->lock);
  76. em = lookup_extent_mapping(em_tree, start, len);
  77. if (em) {
  78. em->bdev =
  79. BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
  80. spin_unlock(&em_tree->lock);
  81. goto out;
  82. }
  83. spin_unlock(&em_tree->lock);
  84. em = alloc_extent_map(GFP_NOFS);
  85. if (!em) {
  86. em = ERR_PTR(-ENOMEM);
  87. goto out;
  88. }
  89. em->start = 0;
  90. em->len = (u64)-1;
  91. em->block_start = 0;
  92. em->bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
  93. spin_lock(&em_tree->lock);
  94. ret = add_extent_mapping(em_tree, em);
  95. if (ret == -EEXIST) {
  96. u64 failed_start = em->start;
  97. u64 failed_len = em->len;
  98. printk("failed to insert %Lu %Lu -> %Lu into tree\n",
  99. em->start, em->len, em->block_start);
  100. free_extent_map(em);
  101. em = lookup_extent_mapping(em_tree, start, len);
  102. if (em) {
  103. printk("after failing, found %Lu %Lu %Lu\n",
  104. em->start, em->len, em->block_start);
  105. ret = 0;
  106. } else {
  107. em = lookup_extent_mapping(em_tree, failed_start,
  108. failed_len);
  109. if (em) {
  110. printk("double failure lookup gives us "
  111. "%Lu %Lu -> %Lu\n", em->start,
  112. em->len, em->block_start);
  113. free_extent_map(em);
  114. }
  115. ret = -EIO;
  116. }
  117. } else if (ret) {
  118. free_extent_map(em);
  119. em = NULL;
  120. }
  121. spin_unlock(&em_tree->lock);
  122. if (ret)
  123. em = ERR_PTR(ret);
  124. out:
  125. return em;
  126. }
  127. u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len)
  128. {
  129. return btrfs_crc32c(seed, data, len);
  130. }
  131. void btrfs_csum_final(u32 crc, char *result)
  132. {
  133. *(__le32 *)result = ~cpu_to_le32(crc);
  134. }
  135. static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
  136. int verify)
  137. {
  138. char result[BTRFS_CRC32_SIZE];
  139. unsigned long len;
  140. unsigned long cur_len;
  141. unsigned long offset = BTRFS_CSUM_SIZE;
  142. char *map_token = NULL;
  143. char *kaddr;
  144. unsigned long map_start;
  145. unsigned long map_len;
  146. int err;
  147. u32 crc = ~(u32)0;
  148. len = buf->len - offset;
  149. while(len > 0) {
  150. err = map_private_extent_buffer(buf, offset, 32,
  151. &map_token, &kaddr,
  152. &map_start, &map_len, KM_USER0);
  153. if (err) {
  154. printk("failed to map extent buffer! %lu\n",
  155. offset);
  156. return 1;
  157. }
  158. cur_len = min(len, map_len - (offset - map_start));
  159. crc = btrfs_csum_data(root, kaddr + offset - map_start,
  160. crc, cur_len);
  161. len -= cur_len;
  162. offset += cur_len;
  163. unmap_extent_buffer(buf, map_token, KM_USER0);
  164. }
  165. btrfs_csum_final(crc, result);
  166. if (verify) {
  167. int from_this_trans = 0;
  168. if (root->fs_info->running_transaction &&
  169. btrfs_header_generation(buf) ==
  170. root->fs_info->running_transaction->transid)
  171. from_this_trans = 1;
  172. /* FIXME, this is not good */
  173. if (memcmp_extent_buffer(buf, result, 0, BTRFS_CRC32_SIZE)) {
  174. u32 val;
  175. u32 found = 0;
  176. memcpy(&found, result, BTRFS_CRC32_SIZE);
  177. read_extent_buffer(buf, &val, 0, BTRFS_CRC32_SIZE);
  178. printk("btrfs: %s checksum verify failed on %llu "
  179. "wanted %X found %X from_this_trans %d "
  180. "level %d\n",
  181. root->fs_info->sb->s_id,
  182. buf->start, val, found, from_this_trans,
  183. btrfs_header_level(buf));
  184. return 1;
  185. }
  186. } else {
  187. write_extent_buffer(buf, result, 0, BTRFS_CRC32_SIZE);
  188. }
  189. return 0;
  190. }
  191. static int verify_parent_transid(struct extent_io_tree *io_tree,
  192. struct extent_buffer *eb, u64 parent_transid)
  193. {
  194. int ret;
  195. if (!parent_transid || btrfs_header_generation(eb) == parent_transid)
  196. return 0;
  197. lock_extent(io_tree, eb->start, eb->start + eb->len - 1, GFP_NOFS);
  198. if (extent_buffer_uptodate(io_tree, eb) &&
  199. btrfs_header_generation(eb) == parent_transid) {
  200. ret = 0;
  201. goto out;
  202. }
  203. printk("parent transid verify failed on %llu wanted %llu found %llu\n",
  204. (unsigned long long)eb->start,
  205. (unsigned long long)parent_transid,
  206. (unsigned long long)btrfs_header_generation(eb));
  207. ret = 1;
  208. out:
  209. clear_extent_buffer_uptodate(io_tree, eb);
  210. unlock_extent(io_tree, eb->start, eb->start + eb->len - 1,
  211. GFP_NOFS);
  212. return ret;
  213. }
  214. static int btree_read_extent_buffer_pages(struct btrfs_root *root,
  215. struct extent_buffer *eb,
  216. u64 start, u64 parent_transid)
  217. {
  218. struct extent_io_tree *io_tree;
  219. int ret;
  220. int num_copies = 0;
  221. int mirror_num = 0;
  222. io_tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree;
  223. while (1) {
  224. ret = read_extent_buffer_pages(io_tree, eb, start, 1,
  225. btree_get_extent, mirror_num);
  226. if (!ret &&
  227. !verify_parent_transid(io_tree, eb, parent_transid))
  228. return ret;
  229. num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
  230. eb->start, eb->len);
  231. if (num_copies == 1)
  232. return ret;
  233. mirror_num++;
  234. if (mirror_num > num_copies)
  235. return ret;
  236. }
  237. return -EIO;
  238. }
  239. int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
  240. {
  241. struct extent_io_tree *tree;
  242. u64 start = (u64)page->index << PAGE_CACHE_SHIFT;
  243. u64 found_start;
  244. int found_level;
  245. unsigned long len;
  246. struct extent_buffer *eb;
  247. int ret;
  248. tree = &BTRFS_I(page->mapping->host)->io_tree;
  249. if (page->private == EXTENT_PAGE_PRIVATE)
  250. goto out;
  251. if (!page->private)
  252. goto out;
  253. len = page->private >> 2;
  254. if (len == 0) {
  255. WARN_ON(1);
  256. }
  257. eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
  258. ret = btree_read_extent_buffer_pages(root, eb, start + PAGE_CACHE_SIZE,
  259. btrfs_header_generation(eb));
  260. BUG_ON(ret);
  261. btrfs_clear_buffer_defrag(eb);
  262. found_start = btrfs_header_bytenr(eb);
  263. if (found_start != start) {
  264. printk("warning: eb start incorrect %Lu buffer %Lu len %lu\n",
  265. start, found_start, len);
  266. WARN_ON(1);
  267. goto err;
  268. }
  269. if (eb->first_page != page) {
  270. printk("bad first page %lu %lu\n", eb->first_page->index,
  271. page->index);
  272. WARN_ON(1);
  273. goto err;
  274. }
  275. if (!PageUptodate(page)) {
  276. printk("csum not up to date page %lu\n", page->index);
  277. WARN_ON(1);
  278. goto err;
  279. }
  280. found_level = btrfs_header_level(eb);
  281. spin_lock(&root->fs_info->hash_lock);
  282. btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN);
  283. spin_unlock(&root->fs_info->hash_lock);
  284. csum_tree_block(root, eb, 0);
  285. err:
  286. free_extent_buffer(eb);
  287. out:
  288. return 0;
  289. }
  290. static int btree_writepage_io_hook(struct page *page, u64 start, u64 end)
  291. {
  292. struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
  293. csum_dirty_buffer(root, page);
  294. return 0;
  295. }
  296. int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end,
  297. struct extent_state *state)
  298. {
  299. struct extent_io_tree *tree;
  300. u64 found_start;
  301. int found_level;
  302. unsigned long len;
  303. struct extent_buffer *eb;
  304. struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
  305. int ret = 0;
  306. tree = &BTRFS_I(page->mapping->host)->io_tree;
  307. if (page->private == EXTENT_PAGE_PRIVATE)
  308. goto out;
  309. if (!page->private)
  310. goto out;
  311. len = page->private >> 2;
  312. if (len == 0) {
  313. WARN_ON(1);
  314. }
  315. eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
  316. btrfs_clear_buffer_defrag(eb);
  317. found_start = btrfs_header_bytenr(eb);
  318. if (found_start != start) {
  319. ret = -EIO;
  320. goto err;
  321. }
  322. if (eb->first_page != page) {
  323. printk("bad first page %lu %lu\n", eb->first_page->index,
  324. page->index);
  325. WARN_ON(1);
  326. ret = -EIO;
  327. goto err;
  328. }
  329. if (memcmp_extent_buffer(eb, root->fs_info->fsid,
  330. (unsigned long)btrfs_header_fsid(eb),
  331. BTRFS_FSID_SIZE)) {
  332. printk("bad fsid on block %Lu\n", eb->start);
  333. ret = -EIO;
  334. goto err;
  335. }
  336. found_level = btrfs_header_level(eb);
  337. ret = csum_tree_block(root, eb, 1);
  338. if (ret)
  339. ret = -EIO;
  340. end = min_t(u64, eb->len, PAGE_CACHE_SIZE);
  341. end = eb->start + end - 1;
  342. release_extent_buffer_tail_pages(eb);
  343. err:
  344. free_extent_buffer(eb);
  345. out:
  346. return ret;
  347. }
  348. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)
  349. static void end_workqueue_bio(struct bio *bio, int err)
  350. #else
  351. static int end_workqueue_bio(struct bio *bio,
  352. unsigned int bytes_done, int err)
  353. #endif
  354. {
  355. struct end_io_wq *end_io_wq = bio->bi_private;
  356. struct btrfs_fs_info *fs_info;
  357. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
  358. if (bio->bi_size)
  359. return 1;
  360. #endif
  361. fs_info = end_io_wq->info;
  362. end_io_wq->error = err;
  363. end_io_wq->work.func = end_workqueue_fn;
  364. end_io_wq->work.flags = 0;
  365. btrfs_queue_worker(&fs_info->endio_workers, &end_io_wq->work);
  366. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
  367. return 0;
  368. #endif
  369. }
  370. int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
  371. int metadata)
  372. {
  373. struct end_io_wq *end_io_wq;
  374. end_io_wq = kmalloc(sizeof(*end_io_wq), GFP_NOFS);
  375. if (!end_io_wq)
  376. return -ENOMEM;
  377. end_io_wq->private = bio->bi_private;
  378. end_io_wq->end_io = bio->bi_end_io;
  379. end_io_wq->info = info;
  380. end_io_wq->error = 0;
  381. end_io_wq->bio = bio;
  382. end_io_wq->metadata = metadata;
  383. bio->bi_private = end_io_wq;
  384. bio->bi_end_io = end_workqueue_bio;
  385. return 0;
  386. }
  387. static void run_one_async_submit(struct btrfs_work *work)
  388. {
  389. struct btrfs_fs_info *fs_info;
  390. struct async_submit_bio *async;
  391. async = container_of(work, struct async_submit_bio, work);
  392. fs_info = BTRFS_I(async->inode)->root->fs_info;
  393. atomic_dec(&fs_info->nr_async_submits);
  394. async->submit_bio_hook(async->inode, async->rw, async->bio,
  395. async->mirror_num);
  396. kfree(async);
  397. }
  398. int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
  399. int rw, struct bio *bio, int mirror_num,
  400. extent_submit_bio_hook_t *submit_bio_hook)
  401. {
  402. struct async_submit_bio *async;
  403. async = kmalloc(sizeof(*async), GFP_NOFS);
  404. if (!async)
  405. return -ENOMEM;
  406. async->inode = inode;
  407. async->rw = rw;
  408. async->bio = bio;
  409. async->mirror_num = mirror_num;
  410. async->submit_bio_hook = submit_bio_hook;
  411. async->work.func = run_one_async_submit;
  412. async->work.flags = 0;
  413. atomic_inc(&fs_info->nr_async_submits);
  414. btrfs_queue_worker(&fs_info->workers, &async->work);
  415. return 0;
  416. }
  417. static int __btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
  418. int mirror_num)
  419. {
  420. struct btrfs_root *root = BTRFS_I(inode)->root;
  421. u64 offset;
  422. int ret;
  423. offset = bio->bi_sector << 9;
  424. /*
  425. * when we're called for a write, we're already in the async
  426. * submission context. Just jump ingo btrfs_map_bio
  427. */
  428. if (rw & (1 << BIO_RW)) {
  429. return btrfs_map_bio(BTRFS_I(inode)->root, rw, bio,
  430. mirror_num, 0);
  431. }
  432. /*
  433. * called for a read, do the setup so that checksum validation
  434. * can happen in the async kernel threads
  435. */
  436. ret = btrfs_bio_wq_end_io(root->fs_info, bio, 1);
  437. BUG_ON(ret);
  438. return btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, mirror_num, 1);
  439. }
  440. static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
  441. int mirror_num)
  442. {
  443. /*
  444. * kthread helpers are used to submit writes so that checksumming
  445. * can happen in parallel across all CPUs
  446. */
  447. if (!(rw & (1 << BIO_RW))) {
  448. return __btree_submit_bio_hook(inode, rw, bio, mirror_num);
  449. }
  450. return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info,
  451. inode, rw, bio, mirror_num,
  452. __btree_submit_bio_hook);
  453. }
  454. static int btree_writepage(struct page *page, struct writeback_control *wbc)
  455. {
  456. struct extent_io_tree *tree;
  457. tree = &BTRFS_I(page->mapping->host)->io_tree;
  458. return extent_write_full_page(tree, page, btree_get_extent, wbc);
  459. }
  460. static int btree_writepages(struct address_space *mapping,
  461. struct writeback_control *wbc)
  462. {
  463. struct extent_io_tree *tree;
  464. tree = &BTRFS_I(mapping->host)->io_tree;
  465. if (wbc->sync_mode == WB_SYNC_NONE) {
  466. u64 num_dirty;
  467. u64 start = 0;
  468. unsigned long thresh = 96 * 1024 * 1024;
  469. if (wbc->for_kupdate)
  470. return 0;
  471. if (current_is_pdflush()) {
  472. thresh = 96 * 1024 * 1024;
  473. } else {
  474. thresh = 8 * 1024 * 1024;
  475. }
  476. num_dirty = count_range_bits(tree, &start, (u64)-1,
  477. thresh, EXTENT_DIRTY);
  478. if (num_dirty < thresh) {
  479. return 0;
  480. }
  481. }
  482. return extent_writepages(tree, mapping, btree_get_extent, wbc);
  483. }
  484. int btree_readpage(struct file *file, struct page *page)
  485. {
  486. struct extent_io_tree *tree;
  487. tree = &BTRFS_I(page->mapping->host)->io_tree;
  488. return extent_read_full_page(tree, page, btree_get_extent);
  489. }
  490. static int btree_releasepage(struct page *page, gfp_t gfp_flags)
  491. {
  492. struct extent_io_tree *tree;
  493. struct extent_map_tree *map;
  494. int ret;
  495. if (page_count(page) > 3) {
  496. /* once for page->private, once for the caller, once
  497. * once for the page cache
  498. */
  499. return 0;
  500. }
  501. tree = &BTRFS_I(page->mapping->host)->io_tree;
  502. map = &BTRFS_I(page->mapping->host)->extent_tree;
  503. ret = try_release_extent_state(map, tree, page, gfp_flags);
  504. if (ret == 1) {
  505. invalidate_extent_lru(tree, page_offset(page), PAGE_CACHE_SIZE);
  506. ClearPagePrivate(page);
  507. set_page_private(page, 0);
  508. page_cache_release(page);
  509. }
  510. return ret;
  511. }
  512. static void btree_invalidatepage(struct page *page, unsigned long offset)
  513. {
  514. struct extent_io_tree *tree;
  515. tree = &BTRFS_I(page->mapping->host)->io_tree;
  516. extent_invalidatepage(tree, page, offset);
  517. btree_releasepage(page, GFP_NOFS);
  518. if (PagePrivate(page)) {
  519. invalidate_extent_lru(tree, page_offset(page), PAGE_CACHE_SIZE);
  520. ClearPagePrivate(page);
  521. set_page_private(page, 0);
  522. page_cache_release(page);
  523. }
  524. }
  525. #if 0
  526. static int btree_writepage(struct page *page, struct writeback_control *wbc)
  527. {
  528. struct buffer_head *bh;
  529. struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
  530. struct buffer_head *head;
  531. if (!page_has_buffers(page)) {
  532. create_empty_buffers(page, root->fs_info->sb->s_blocksize,
  533. (1 << BH_Dirty)|(1 << BH_Uptodate));
  534. }
  535. head = page_buffers(page);
  536. bh = head;
  537. do {
  538. if (buffer_dirty(bh))
  539. csum_tree_block(root, bh, 0);
  540. bh = bh->b_this_page;
  541. } while (bh != head);
  542. return block_write_full_page(page, btree_get_block, wbc);
  543. }
  544. #endif
  545. static struct address_space_operations btree_aops = {
  546. .readpage = btree_readpage,
  547. .writepage = btree_writepage,
  548. .writepages = btree_writepages,
  549. .releasepage = btree_releasepage,
  550. .invalidatepage = btree_invalidatepage,
  551. .sync_page = block_sync_page,
  552. };
  553. int readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize,
  554. u64 parent_transid)
  555. {
  556. struct extent_buffer *buf = NULL;
  557. struct inode *btree_inode = root->fs_info->btree_inode;
  558. int ret = 0;
  559. buf = btrfs_find_create_tree_block(root, bytenr, blocksize);
  560. if (!buf)
  561. return 0;
  562. read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree,
  563. buf, 0, 0, btree_get_extent, 0);
  564. free_extent_buffer(buf);
  565. return ret;
  566. }
  567. struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
  568. u64 bytenr, u32 blocksize)
  569. {
  570. struct inode *btree_inode = root->fs_info->btree_inode;
  571. struct extent_buffer *eb;
  572. eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
  573. bytenr, blocksize, GFP_NOFS);
  574. return eb;
  575. }
  576. struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
  577. u64 bytenr, u32 blocksize)
  578. {
  579. struct inode *btree_inode = root->fs_info->btree_inode;
  580. struct extent_buffer *eb;
  581. eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
  582. bytenr, blocksize, NULL, GFP_NOFS);
  583. return eb;
  584. }
  585. struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
  586. u32 blocksize, u64 parent_transid)
  587. {
  588. struct extent_buffer *buf = NULL;
  589. struct inode *btree_inode = root->fs_info->btree_inode;
  590. struct extent_io_tree *io_tree;
  591. int ret;
  592. io_tree = &BTRFS_I(btree_inode)->io_tree;
  593. buf = btrfs_find_create_tree_block(root, bytenr, blocksize);
  594. if (!buf)
  595. return NULL;
  596. ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid);
  597. if (ret == 0) {
  598. buf->flags |= EXTENT_UPTODATE;
  599. }
  600. return buf;
  601. }
  602. int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  603. struct extent_buffer *buf)
  604. {
  605. struct inode *btree_inode = root->fs_info->btree_inode;
  606. if (btrfs_header_generation(buf) ==
  607. root->fs_info->running_transaction->transid) {
  608. WARN_ON(!btrfs_tree_locked(buf));
  609. clear_extent_buffer_dirty(&BTRFS_I(btree_inode)->io_tree,
  610. buf);
  611. }
  612. return 0;
  613. }
  614. int wait_on_tree_block_writeback(struct btrfs_root *root,
  615. struct extent_buffer *buf)
  616. {
  617. struct inode *btree_inode = root->fs_info->btree_inode;
  618. wait_on_extent_buffer_writeback(&BTRFS_I(btree_inode)->io_tree,
  619. buf);
  620. return 0;
  621. }
  622. static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
  623. u32 stripesize, struct btrfs_root *root,
  624. struct btrfs_fs_info *fs_info,
  625. u64 objectid)
  626. {
  627. root->node = NULL;
  628. root->inode = NULL;
  629. root->commit_root = NULL;
  630. root->sectorsize = sectorsize;
  631. root->nodesize = nodesize;
  632. root->leafsize = leafsize;
  633. root->stripesize = stripesize;
  634. root->ref_cows = 0;
  635. root->track_dirty = 0;
  636. root->fs_info = fs_info;
  637. root->objectid = objectid;
  638. root->last_trans = 0;
  639. root->highest_inode = 0;
  640. root->last_inode_alloc = 0;
  641. root->name = NULL;
  642. root->in_sysfs = 0;
  643. INIT_LIST_HEAD(&root->dirty_list);
  644. spin_lock_init(&root->node_lock);
  645. mutex_init(&root->objectid_mutex);
  646. memset(&root->root_key, 0, sizeof(root->root_key));
  647. memset(&root->root_item, 0, sizeof(root->root_item));
  648. memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
  649. memset(&root->root_kobj, 0, sizeof(root->root_kobj));
  650. init_completion(&root->kobj_unregister);
  651. root->defrag_running = 0;
  652. root->defrag_level = 0;
  653. root->root_key.objectid = objectid;
  654. return 0;
  655. }
  656. static int find_and_setup_root(struct btrfs_root *tree_root,
  657. struct btrfs_fs_info *fs_info,
  658. u64 objectid,
  659. struct btrfs_root *root)
  660. {
  661. int ret;
  662. u32 blocksize;
  663. __setup_root(tree_root->nodesize, tree_root->leafsize,
  664. tree_root->sectorsize, tree_root->stripesize,
  665. root, fs_info, objectid);
  666. ret = btrfs_find_last_root(tree_root, objectid,
  667. &root->root_item, &root->root_key);
  668. BUG_ON(ret);
  669. blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
  670. root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
  671. blocksize, 0);
  672. BUG_ON(!root->node);
  673. return 0;
  674. }
  675. struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_fs_info *fs_info,
  676. struct btrfs_key *location)
  677. {
  678. struct btrfs_root *root;
  679. struct btrfs_root *tree_root = fs_info->tree_root;
  680. struct btrfs_path *path;
  681. struct extent_buffer *l;
  682. u64 highest_inode;
  683. u32 blocksize;
  684. int ret = 0;
  685. root = kzalloc(sizeof(*root), GFP_NOFS);
  686. if (!root)
  687. return ERR_PTR(-ENOMEM);
  688. if (location->offset == (u64)-1) {
  689. ret = find_and_setup_root(tree_root, fs_info,
  690. location->objectid, root);
  691. if (ret) {
  692. kfree(root);
  693. return ERR_PTR(ret);
  694. }
  695. goto insert;
  696. }
  697. __setup_root(tree_root->nodesize, tree_root->leafsize,
  698. tree_root->sectorsize, tree_root->stripesize,
  699. root, fs_info, location->objectid);
  700. path = btrfs_alloc_path();
  701. BUG_ON(!path);
  702. ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0);
  703. if (ret != 0) {
  704. if (ret > 0)
  705. ret = -ENOENT;
  706. goto out;
  707. }
  708. l = path->nodes[0];
  709. read_extent_buffer(l, &root->root_item,
  710. btrfs_item_ptr_offset(l, path->slots[0]),
  711. sizeof(root->root_item));
  712. memcpy(&root->root_key, location, sizeof(*location));
  713. ret = 0;
  714. out:
  715. btrfs_release_path(root, path);
  716. btrfs_free_path(path);
  717. if (ret) {
  718. kfree(root);
  719. return ERR_PTR(ret);
  720. }
  721. blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
  722. root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
  723. blocksize, 0);
  724. BUG_ON(!root->node);
  725. insert:
  726. root->ref_cows = 1;
  727. ret = btrfs_find_highest_inode(root, &highest_inode);
  728. if (ret == 0) {
  729. root->highest_inode = highest_inode;
  730. root->last_inode_alloc = highest_inode;
  731. }
  732. return root;
  733. }
  734. struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info,
  735. u64 root_objectid)
  736. {
  737. struct btrfs_root *root;
  738. if (root_objectid == BTRFS_ROOT_TREE_OBJECTID)
  739. return fs_info->tree_root;
  740. if (root_objectid == BTRFS_EXTENT_TREE_OBJECTID)
  741. return fs_info->extent_root;
  742. root = radix_tree_lookup(&fs_info->fs_roots_radix,
  743. (unsigned long)root_objectid);
  744. return root;
  745. }
  746. struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info,
  747. struct btrfs_key *location)
  748. {
  749. struct btrfs_root *root;
  750. int ret;
  751. if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
  752. return fs_info->tree_root;
  753. if (location->objectid == BTRFS_EXTENT_TREE_OBJECTID)
  754. return fs_info->extent_root;
  755. if (location->objectid == BTRFS_CHUNK_TREE_OBJECTID)
  756. return fs_info->chunk_root;
  757. if (location->objectid == BTRFS_DEV_TREE_OBJECTID)
  758. return fs_info->dev_root;
  759. root = radix_tree_lookup(&fs_info->fs_roots_radix,
  760. (unsigned long)location->objectid);
  761. if (root)
  762. return root;
  763. root = btrfs_read_fs_root_no_radix(fs_info, location);
  764. if (IS_ERR(root))
  765. return root;
  766. ret = radix_tree_insert(&fs_info->fs_roots_radix,
  767. (unsigned long)root->root_key.objectid,
  768. root);
  769. if (ret) {
  770. free_extent_buffer(root->node);
  771. kfree(root);
  772. return ERR_PTR(ret);
  773. }
  774. ret = btrfs_find_dead_roots(fs_info->tree_root,
  775. root->root_key.objectid, root);
  776. BUG_ON(ret);
  777. return root;
  778. }
  779. struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
  780. struct btrfs_key *location,
  781. const char *name, int namelen)
  782. {
  783. struct btrfs_root *root;
  784. int ret;
  785. root = btrfs_read_fs_root_no_name(fs_info, location);
  786. if (!root)
  787. return NULL;
  788. if (root->in_sysfs)
  789. return root;
  790. ret = btrfs_set_root_name(root, name, namelen);
  791. if (ret) {
  792. free_extent_buffer(root->node);
  793. kfree(root);
  794. return ERR_PTR(ret);
  795. }
  796. ret = btrfs_sysfs_add_root(root);
  797. if (ret) {
  798. free_extent_buffer(root->node);
  799. kfree(root->name);
  800. kfree(root);
  801. return ERR_PTR(ret);
  802. }
  803. root->in_sysfs = 1;
  804. return root;
  805. }
  806. #if 0
  807. static int add_hasher(struct btrfs_fs_info *info, char *type) {
  808. struct btrfs_hasher *hasher;
  809. hasher = kmalloc(sizeof(*hasher), GFP_NOFS);
  810. if (!hasher)
  811. return -ENOMEM;
  812. hasher->hash_tfm = crypto_alloc_hash(type, 0, CRYPTO_ALG_ASYNC);
  813. if (!hasher->hash_tfm) {
  814. kfree(hasher);
  815. return -EINVAL;
  816. }
  817. spin_lock(&info->hash_lock);
  818. list_add(&hasher->list, &info->hashers);
  819. spin_unlock(&info->hash_lock);
  820. return 0;
  821. }
  822. #endif
  823. static int btrfs_congested_fn(void *congested_data, int bdi_bits)
  824. {
  825. struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data;
  826. int ret = 0;
  827. int limit = 256 * info->fs_devices->open_devices;
  828. struct list_head *cur;
  829. struct btrfs_device *device;
  830. struct backing_dev_info *bdi;
  831. if ((bdi_bits & (1 << BDI_write_congested)) &&
  832. atomic_read(&info->nr_async_submits) > limit) {
  833. return 1;
  834. }
  835. list_for_each(cur, &info->fs_devices->devices) {
  836. device = list_entry(cur, struct btrfs_device, dev_list);
  837. if (!device->bdev)
  838. continue;
  839. bdi = blk_get_backing_dev_info(device->bdev);
  840. if (bdi && bdi_congested(bdi, bdi_bits)) {
  841. ret = 1;
  842. break;
  843. }
  844. }
  845. return ret;
  846. }
  847. /*
  848. * this unplugs every device on the box, and it is only used when page
  849. * is null
  850. */
  851. static void __unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
  852. {
  853. struct list_head *cur;
  854. struct btrfs_device *device;
  855. struct btrfs_fs_info *info;
  856. info = (struct btrfs_fs_info *)bdi->unplug_io_data;
  857. list_for_each(cur, &info->fs_devices->devices) {
  858. device = list_entry(cur, struct btrfs_device, dev_list);
  859. bdi = blk_get_backing_dev_info(device->bdev);
  860. if (bdi->unplug_io_fn) {
  861. bdi->unplug_io_fn(bdi, page);
  862. }
  863. }
  864. }
  865. void btrfs_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
  866. {
  867. struct inode *inode;
  868. struct extent_map_tree *em_tree;
  869. struct extent_map *em;
  870. struct address_space *mapping;
  871. u64 offset;
  872. /* the generic O_DIRECT read code does this */
  873. if (!page) {
  874. __unplug_io_fn(bdi, page);
  875. return;
  876. }
  877. /*
  878. * page->mapping may change at any time. Get a consistent copy
  879. * and use that for everything below
  880. */
  881. smp_mb();
  882. mapping = page->mapping;
  883. if (!mapping)
  884. return;
  885. inode = mapping->host;
  886. offset = page_offset(page);
  887. em_tree = &BTRFS_I(inode)->extent_tree;
  888. spin_lock(&em_tree->lock);
  889. em = lookup_extent_mapping(em_tree, offset, PAGE_CACHE_SIZE);
  890. spin_unlock(&em_tree->lock);
  891. if (!em)
  892. return;
  893. offset = offset - em->start;
  894. btrfs_unplug_page(&BTRFS_I(inode)->root->fs_info->mapping_tree,
  895. em->block_start + offset, page);
  896. free_extent_map(em);
  897. }
  898. static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
  899. {
  900. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)
  901. bdi_init(bdi);
  902. #endif
  903. bdi->ra_pages = default_backing_dev_info.ra_pages;
  904. bdi->state = 0;
  905. bdi->capabilities = default_backing_dev_info.capabilities;
  906. bdi->unplug_io_fn = btrfs_unplug_io_fn;
  907. bdi->unplug_io_data = info;
  908. bdi->congested_fn = btrfs_congested_fn;
  909. bdi->congested_data = info;
  910. return 0;
  911. }
  912. static int bio_ready_for_csum(struct bio *bio)
  913. {
  914. u64 length = 0;
  915. u64 buf_len = 0;
  916. u64 start = 0;
  917. struct page *page;
  918. struct extent_io_tree *io_tree = NULL;
  919. struct btrfs_fs_info *info = NULL;
  920. struct bio_vec *bvec;
  921. int i;
  922. int ret;
  923. bio_for_each_segment(bvec, bio, i) {
  924. page = bvec->bv_page;
  925. if (page->private == EXTENT_PAGE_PRIVATE) {
  926. length += bvec->bv_len;
  927. continue;
  928. }
  929. if (!page->private) {
  930. length += bvec->bv_len;
  931. continue;
  932. }
  933. length = bvec->bv_len;
  934. buf_len = page->private >> 2;
  935. start = page_offset(page) + bvec->bv_offset;
  936. io_tree = &BTRFS_I(page->mapping->host)->io_tree;
  937. info = BTRFS_I(page->mapping->host)->root->fs_info;
  938. }
  939. /* are we fully contained in this bio? */
  940. if (buf_len <= length)
  941. return 1;
  942. ret = extent_range_uptodate(io_tree, start + length,
  943. start + buf_len - 1);
  944. if (ret == 1)
  945. return ret;
  946. return ret;
  947. }
  948. /*
  949. * called by the kthread helper functions to finally call the bio end_io
  950. * functions. This is where read checksum verification actually happens
  951. */
  952. static void end_workqueue_fn(struct btrfs_work *work)
  953. {
  954. struct bio *bio;
  955. struct end_io_wq *end_io_wq;
  956. struct btrfs_fs_info *fs_info;
  957. int error;
  958. end_io_wq = container_of(work, struct end_io_wq, work);
  959. bio = end_io_wq->bio;
  960. fs_info = end_io_wq->info;
  961. /* metadata bios are special because the whole tree block must
  962. * be checksummed at once. This makes sure the entire block is in
  963. * ram and up to date before trying to verify things. For
  964. * blocksize <= pagesize, it is basically a noop
  965. */
  966. if (end_io_wq->metadata && !bio_ready_for_csum(bio)) {
  967. btrfs_queue_worker(&fs_info->endio_workers,
  968. &end_io_wq->work);
  969. return;
  970. }
  971. error = end_io_wq->error;
  972. bio->bi_private = end_io_wq->private;
  973. bio->bi_end_io = end_io_wq->end_io;
  974. kfree(end_io_wq);
  975. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
  976. bio_endio(bio, bio->bi_size, error);
  977. #else
  978. bio_endio(bio, error);
  979. #endif
  980. }
  981. struct btrfs_root *open_ctree(struct super_block *sb,
  982. struct btrfs_fs_devices *fs_devices,
  983. char *options)
  984. {
  985. u32 sectorsize;
  986. u32 nodesize;
  987. u32 leafsize;
  988. u32 blocksize;
  989. u32 stripesize;
  990. struct buffer_head *bh;
  991. struct btrfs_root *extent_root = kmalloc(sizeof(struct btrfs_root),
  992. GFP_NOFS);
  993. struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root),
  994. GFP_NOFS);
  995. struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info),
  996. GFP_NOFS);
  997. struct btrfs_root *chunk_root = kmalloc(sizeof(struct btrfs_root),
  998. GFP_NOFS);
  999. struct btrfs_root *dev_root = kmalloc(sizeof(struct btrfs_root),
  1000. GFP_NOFS);
  1001. int ret;
  1002. int err = -EINVAL;
  1003. struct btrfs_super_block *disk_super;
  1004. if (!extent_root || !tree_root || !fs_info) {
  1005. err = -ENOMEM;
  1006. goto fail;
  1007. }
  1008. INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_NOFS);
  1009. INIT_LIST_HEAD(&fs_info->trans_list);
  1010. INIT_LIST_HEAD(&fs_info->dead_roots);
  1011. INIT_LIST_HEAD(&fs_info->hashers);
  1012. spin_lock_init(&fs_info->hash_lock);
  1013. spin_lock_init(&fs_info->delalloc_lock);
  1014. spin_lock_init(&fs_info->new_trans_lock);
  1015. init_completion(&fs_info->kobj_unregister);
  1016. fs_info->tree_root = tree_root;
  1017. fs_info->extent_root = extent_root;
  1018. fs_info->chunk_root = chunk_root;
  1019. fs_info->dev_root = dev_root;
  1020. fs_info->fs_devices = fs_devices;
  1021. INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
  1022. INIT_LIST_HEAD(&fs_info->space_info);
  1023. btrfs_mapping_init(&fs_info->mapping_tree);
  1024. atomic_set(&fs_info->nr_async_submits, 0);
  1025. atomic_set(&fs_info->throttles, 0);
  1026. fs_info->sb = sb;
  1027. fs_info->max_extent = (u64)-1;
  1028. fs_info->max_inline = 8192 * 1024;
  1029. setup_bdi(fs_info, &fs_info->bdi);
  1030. fs_info->btree_inode = new_inode(sb);
  1031. fs_info->btree_inode->i_ino = 1;
  1032. fs_info->btree_inode->i_nlink = 1;
  1033. fs_info->thread_pool_size = min(num_online_cpus() + 2, 8);
  1034. sb->s_blocksize = 4096;
  1035. sb->s_blocksize_bits = blksize_bits(4096);
  1036. /*
  1037. * we set the i_size on the btree inode to the max possible int.
  1038. * the real end of the address space is determined by all of
  1039. * the devices in the system
  1040. */
  1041. fs_info->btree_inode->i_size = OFFSET_MAX;
  1042. fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
  1043. fs_info->btree_inode->i_mapping->backing_dev_info = &fs_info->bdi;
  1044. extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
  1045. fs_info->btree_inode->i_mapping,
  1046. GFP_NOFS);
  1047. extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree,
  1048. GFP_NOFS);
  1049. BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
  1050. extent_io_tree_init(&fs_info->free_space_cache,
  1051. fs_info->btree_inode->i_mapping, GFP_NOFS);
  1052. extent_io_tree_init(&fs_info->block_group_cache,
  1053. fs_info->btree_inode->i_mapping, GFP_NOFS);
  1054. extent_io_tree_init(&fs_info->pinned_extents,
  1055. fs_info->btree_inode->i_mapping, GFP_NOFS);
  1056. extent_io_tree_init(&fs_info->pending_del,
  1057. fs_info->btree_inode->i_mapping, GFP_NOFS);
  1058. extent_io_tree_init(&fs_info->extent_ins,
  1059. fs_info->btree_inode->i_mapping, GFP_NOFS);
  1060. fs_info->do_barriers = 1;
  1061. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
  1062. INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info);
  1063. #else
  1064. INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner);
  1065. #endif
  1066. BTRFS_I(fs_info->btree_inode)->root = tree_root;
  1067. memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
  1068. sizeof(struct btrfs_key));
  1069. insert_inode_hash(fs_info->btree_inode);
  1070. mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
  1071. mutex_init(&fs_info->trans_mutex);
  1072. mutex_init(&fs_info->drop_mutex);
  1073. mutex_init(&fs_info->alloc_mutex);
  1074. mutex_init(&fs_info->chunk_mutex);
  1075. #if 0
  1076. ret = add_hasher(fs_info, "crc32c");
  1077. if (ret) {
  1078. printk("btrfs: failed hash setup, modprobe cryptomgr?\n");
  1079. err = -ENOMEM;
  1080. goto fail_iput;
  1081. }
  1082. #endif
  1083. __setup_root(4096, 4096, 4096, 4096, tree_root,
  1084. fs_info, BTRFS_ROOT_TREE_OBJECTID);
  1085. bh = __bread(fs_devices->latest_bdev,
  1086. BTRFS_SUPER_INFO_OFFSET / 4096, 4096);
  1087. if (!bh)
  1088. goto fail_iput;
  1089. memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy));
  1090. brelse(bh);
  1091. memcpy(fs_info->fsid, fs_info->super_copy.fsid, BTRFS_FSID_SIZE);
  1092. disk_super = &fs_info->super_copy;
  1093. if (!btrfs_super_root(disk_super))
  1094. goto fail_sb_buffer;
  1095. err = btrfs_parse_options(tree_root, options);
  1096. if (err)
  1097. goto fail_sb_buffer;
  1098. /*
  1099. * we need to start all the end_io workers up front because the
  1100. * queue work function gets called at interrupt time, and so it
  1101. * cannot dynamically grow.
  1102. */
  1103. btrfs_init_workers(&fs_info->workers, fs_info->thread_pool_size);
  1104. btrfs_init_workers(&fs_info->submit_workers, fs_info->thread_pool_size);
  1105. btrfs_init_workers(&fs_info->endio_workers, fs_info->thread_pool_size);
  1106. btrfs_start_workers(&fs_info->workers, 1);
  1107. btrfs_start_workers(&fs_info->submit_workers, 1);
  1108. btrfs_start_workers(&fs_info->endio_workers, fs_info->thread_pool_size);
  1109. err = -EINVAL;
  1110. if (btrfs_super_num_devices(disk_super) > fs_devices->open_devices) {
  1111. printk("Btrfs: wanted %llu devices, but found %llu\n",
  1112. (unsigned long long)btrfs_super_num_devices(disk_super),
  1113. (unsigned long long)fs_devices->open_devices);
  1114. if (btrfs_test_opt(tree_root, DEGRADED))
  1115. printk("continuing in degraded mode\n");
  1116. else {
  1117. goto fail_sb_buffer;
  1118. }
  1119. }
  1120. fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super);
  1121. nodesize = btrfs_super_nodesize(disk_super);
  1122. leafsize = btrfs_super_leafsize(disk_super);
  1123. sectorsize = btrfs_super_sectorsize(disk_super);
  1124. stripesize = btrfs_super_stripesize(disk_super);
  1125. tree_root->nodesize = nodesize;
  1126. tree_root->leafsize = leafsize;
  1127. tree_root->sectorsize = sectorsize;
  1128. tree_root->stripesize = stripesize;
  1129. sb->s_blocksize = sectorsize;
  1130. sb->s_blocksize_bits = blksize_bits(sectorsize);
  1131. if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC,
  1132. sizeof(disk_super->magic))) {
  1133. printk("btrfs: valid FS not found on %s\n", sb->s_id);
  1134. goto fail_sb_buffer;
  1135. }
  1136. mutex_lock(&fs_info->chunk_mutex);
  1137. ret = btrfs_read_sys_array(tree_root);
  1138. mutex_unlock(&fs_info->chunk_mutex);
  1139. if (ret) {
  1140. printk("btrfs: failed to read the system array on %s\n",
  1141. sb->s_id);
  1142. goto fail_sys_array;
  1143. }
  1144. blocksize = btrfs_level_size(tree_root,
  1145. btrfs_super_chunk_root_level(disk_super));
  1146. __setup_root(nodesize, leafsize, sectorsize, stripesize,
  1147. chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID);
  1148. chunk_root->node = read_tree_block(chunk_root,
  1149. btrfs_super_chunk_root(disk_super),
  1150. blocksize, 0);
  1151. BUG_ON(!chunk_root->node);
  1152. read_extent_buffer(chunk_root->node, fs_info->chunk_tree_uuid,
  1153. (unsigned long)btrfs_header_chunk_tree_uuid(chunk_root->node),
  1154. BTRFS_UUID_SIZE);
  1155. mutex_lock(&fs_info->chunk_mutex);
  1156. ret = btrfs_read_chunk_tree(chunk_root);
  1157. mutex_unlock(&fs_info->chunk_mutex);
  1158. BUG_ON(ret);
  1159. btrfs_close_extra_devices(fs_devices);
  1160. blocksize = btrfs_level_size(tree_root,
  1161. btrfs_super_root_level(disk_super));
  1162. tree_root->node = read_tree_block(tree_root,
  1163. btrfs_super_root(disk_super),
  1164. blocksize, 0);
  1165. if (!tree_root->node)
  1166. goto fail_sb_buffer;
  1167. ret = find_and_setup_root(tree_root, fs_info,
  1168. BTRFS_EXTENT_TREE_OBJECTID, extent_root);
  1169. if (ret)
  1170. goto fail_tree_root;
  1171. extent_root->track_dirty = 1;
  1172. ret = find_and_setup_root(tree_root, fs_info,
  1173. BTRFS_DEV_TREE_OBJECTID, dev_root);
  1174. dev_root->track_dirty = 1;
  1175. if (ret)
  1176. goto fail_extent_root;
  1177. btrfs_read_block_groups(extent_root);
  1178. fs_info->generation = btrfs_super_generation(disk_super) + 1;
  1179. fs_info->data_alloc_profile = (u64)-1;
  1180. fs_info->metadata_alloc_profile = (u64)-1;
  1181. fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
  1182. return tree_root;
  1183. fail_extent_root:
  1184. free_extent_buffer(extent_root->node);
  1185. fail_tree_root:
  1186. free_extent_buffer(tree_root->node);
  1187. fail_sys_array:
  1188. fail_sb_buffer:
  1189. extent_io_tree_empty_lru(&BTRFS_I(fs_info->btree_inode)->io_tree);
  1190. btrfs_stop_workers(&fs_info->workers);
  1191. btrfs_stop_workers(&fs_info->endio_workers);
  1192. btrfs_stop_workers(&fs_info->submit_workers);
  1193. fail_iput:
  1194. iput(fs_info->btree_inode);
  1195. fail:
  1196. btrfs_close_devices(fs_info->fs_devices);
  1197. btrfs_mapping_tree_free(&fs_info->mapping_tree);
  1198. kfree(extent_root);
  1199. kfree(tree_root);
  1200. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)
  1201. bdi_destroy(&fs_info->bdi);
  1202. #endif
  1203. kfree(fs_info);
  1204. return ERR_PTR(err);
  1205. }
  1206. static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
  1207. {
  1208. char b[BDEVNAME_SIZE];
  1209. if (uptodate) {
  1210. set_buffer_uptodate(bh);
  1211. } else {
  1212. if (!buffer_eopnotsupp(bh) && printk_ratelimit()) {
  1213. printk(KERN_WARNING "lost page write due to "
  1214. "I/O error on %s\n",
  1215. bdevname(bh->b_bdev, b));
  1216. }
  1217. /* note, we dont' set_buffer_write_io_error because we have
  1218. * our own ways of dealing with the IO errors
  1219. */
  1220. clear_buffer_uptodate(bh);
  1221. }
  1222. unlock_buffer(bh);
  1223. put_bh(bh);
  1224. }
  1225. int write_all_supers(struct btrfs_root *root)
  1226. {
  1227. struct list_head *cur;
  1228. struct list_head *head = &root->fs_info->fs_devices->devices;
  1229. struct btrfs_device *dev;
  1230. struct btrfs_super_block *sb;
  1231. struct btrfs_dev_item *dev_item;
  1232. struct buffer_head *bh;
  1233. int ret;
  1234. int do_barriers;
  1235. int max_errors;
  1236. int total_errors = 0;
  1237. u32 crc;
  1238. u64 flags;
  1239. max_errors = btrfs_super_num_devices(&root->fs_info->super_copy) - 1;
  1240. do_barriers = !btrfs_test_opt(root, NOBARRIER);
  1241. sb = &root->fs_info->super_for_commit;
  1242. dev_item = &sb->dev_item;
  1243. list_for_each(cur, head) {
  1244. dev = list_entry(cur, struct btrfs_device, dev_list);
  1245. if (!dev->bdev) {
  1246. total_errors++;
  1247. continue;
  1248. }
  1249. if (!dev->in_fs_metadata)
  1250. continue;
  1251. btrfs_set_stack_device_type(dev_item, dev->type);
  1252. btrfs_set_stack_device_id(dev_item, dev->devid);
  1253. btrfs_set_stack_device_total_bytes(dev_item, dev->total_bytes);
  1254. btrfs_set_stack_device_bytes_used(dev_item, dev->bytes_used);
  1255. btrfs_set_stack_device_io_align(dev_item, dev->io_align);
  1256. btrfs_set_stack_device_io_width(dev_item, dev->io_width);
  1257. btrfs_set_stack_device_sector_size(dev_item, dev->sector_size);
  1258. memcpy(dev_item->uuid, dev->uuid, BTRFS_UUID_SIZE);
  1259. flags = btrfs_super_flags(sb);
  1260. btrfs_set_super_flags(sb, flags | BTRFS_HEADER_FLAG_WRITTEN);
  1261. crc = ~(u32)0;
  1262. crc = btrfs_csum_data(root, (char *)sb + BTRFS_CSUM_SIZE, crc,
  1263. BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
  1264. btrfs_csum_final(crc, sb->csum);
  1265. bh = __getblk(dev->bdev, BTRFS_SUPER_INFO_OFFSET / 4096,
  1266. BTRFS_SUPER_INFO_SIZE);
  1267. memcpy(bh->b_data, sb, BTRFS_SUPER_INFO_SIZE);
  1268. dev->pending_io = bh;
  1269. get_bh(bh);
  1270. set_buffer_uptodate(bh);
  1271. lock_buffer(bh);
  1272. bh->b_end_io = btrfs_end_buffer_write_sync;
  1273. if (do_barriers && dev->barriers) {
  1274. ret = submit_bh(WRITE_BARRIER, bh);
  1275. if (ret == -EOPNOTSUPP) {
  1276. printk("btrfs: disabling barriers on dev %s\n",
  1277. dev->name);
  1278. set_buffer_uptodate(bh);
  1279. dev->barriers = 0;
  1280. get_bh(bh);
  1281. lock_buffer(bh);
  1282. ret = submit_bh(WRITE, bh);
  1283. }
  1284. } else {
  1285. ret = submit_bh(WRITE, bh);
  1286. }
  1287. if (ret)
  1288. total_errors++;
  1289. }
  1290. if (total_errors > max_errors) {
  1291. printk("btrfs: %d errors while writing supers\n", total_errors);
  1292. BUG();
  1293. }
  1294. total_errors = 0;
  1295. list_for_each(cur, head) {
  1296. dev = list_entry(cur, struct btrfs_device, dev_list);
  1297. if (!dev->bdev)
  1298. continue;
  1299. if (!dev->in_fs_metadata)
  1300. continue;
  1301. BUG_ON(!dev->pending_io);
  1302. bh = dev->pending_io;
  1303. wait_on_buffer(bh);
  1304. if (!buffer_uptodate(dev->pending_io)) {
  1305. if (do_barriers && dev->barriers) {
  1306. printk("btrfs: disabling barriers on dev %s\n",
  1307. dev->name);
  1308. set_buffer_uptodate(bh);
  1309. get_bh(bh);
  1310. lock_buffer(bh);
  1311. dev->barriers = 0;
  1312. ret = submit_bh(WRITE, bh);
  1313. BUG_ON(ret);
  1314. wait_on_buffer(bh);
  1315. if (!buffer_uptodate(bh))
  1316. total_errors++;
  1317. } else {
  1318. total_errors++;
  1319. }
  1320. }
  1321. dev->pending_io = NULL;
  1322. brelse(bh);
  1323. }
  1324. if (total_errors > max_errors) {
  1325. printk("btrfs: %d errors while writing supers\n", total_errors);
  1326. BUG();
  1327. }
  1328. return 0;
  1329. }
  1330. int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root
  1331. *root)
  1332. {
  1333. int ret;
  1334. ret = write_all_supers(root);
  1335. return ret;
  1336. }
  1337. int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
  1338. {
  1339. radix_tree_delete(&fs_info->fs_roots_radix,
  1340. (unsigned long)root->root_key.objectid);
  1341. if (root->in_sysfs)
  1342. btrfs_sysfs_del_root(root);
  1343. if (root->inode)
  1344. iput(root->inode);
  1345. if (root->node)
  1346. free_extent_buffer(root->node);
  1347. if (root->commit_root)
  1348. free_extent_buffer(root->commit_root);
  1349. if (root->name)
  1350. kfree(root->name);
  1351. kfree(root);
  1352. return 0;
  1353. }
  1354. static int del_fs_roots(struct btrfs_fs_info *fs_info)
  1355. {
  1356. int ret;
  1357. struct btrfs_root *gang[8];
  1358. int i;
  1359. while(1) {
  1360. ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix,
  1361. (void **)gang, 0,
  1362. ARRAY_SIZE(gang));
  1363. if (!ret)
  1364. break;
  1365. for (i = 0; i < ret; i++)
  1366. btrfs_free_fs_root(fs_info, gang[i]);
  1367. }
  1368. return 0;
  1369. }
  1370. int close_ctree(struct btrfs_root *root)
  1371. {
  1372. int ret;
  1373. struct btrfs_trans_handle *trans;
  1374. struct btrfs_fs_info *fs_info = root->fs_info;
  1375. fs_info->closing = 1;
  1376. smp_mb();
  1377. btrfs_transaction_flush_work(root);
  1378. btrfs_defrag_dirty_roots(root->fs_info);
  1379. trans = btrfs_start_transaction(root, 1);
  1380. ret = btrfs_commit_transaction(trans, root);
  1381. /* run commit again to drop the original snapshot */
  1382. trans = btrfs_start_transaction(root, 1);
  1383. btrfs_commit_transaction(trans, root);
  1384. ret = btrfs_write_and_wait_transaction(NULL, root);
  1385. BUG_ON(ret);
  1386. write_ctree_super(NULL, root);
  1387. btrfs_transaction_flush_work(root);
  1388. if (fs_info->delalloc_bytes) {
  1389. printk("btrfs: at unmount delalloc count %Lu\n",
  1390. fs_info->delalloc_bytes);
  1391. }
  1392. if (fs_info->extent_root->node)
  1393. free_extent_buffer(fs_info->extent_root->node);
  1394. if (fs_info->tree_root->node)
  1395. free_extent_buffer(fs_info->tree_root->node);
  1396. if (root->fs_info->chunk_root->node);
  1397. free_extent_buffer(root->fs_info->chunk_root->node);
  1398. if (root->fs_info->dev_root->node);
  1399. free_extent_buffer(root->fs_info->dev_root->node);
  1400. btrfs_free_block_groups(root->fs_info);
  1401. del_fs_roots(fs_info);
  1402. filemap_write_and_wait(fs_info->btree_inode->i_mapping);
  1403. extent_io_tree_empty_lru(&fs_info->free_space_cache);
  1404. extent_io_tree_empty_lru(&fs_info->block_group_cache);
  1405. extent_io_tree_empty_lru(&fs_info->pinned_extents);
  1406. extent_io_tree_empty_lru(&fs_info->pending_del);
  1407. extent_io_tree_empty_lru(&fs_info->extent_ins);
  1408. extent_io_tree_empty_lru(&BTRFS_I(fs_info->btree_inode)->io_tree);
  1409. truncate_inode_pages(fs_info->btree_inode->i_mapping, 0);
  1410. btrfs_stop_workers(&fs_info->workers);
  1411. btrfs_stop_workers(&fs_info->endio_workers);
  1412. btrfs_stop_workers(&fs_info->submit_workers);
  1413. iput(fs_info->btree_inode);
  1414. #if 0
  1415. while(!list_empty(&fs_info->hashers)) {
  1416. struct btrfs_hasher *hasher;
  1417. hasher = list_entry(fs_info->hashers.next, struct btrfs_hasher,
  1418. hashers);
  1419. list_del(&hasher->hashers);
  1420. crypto_free_hash(&fs_info->hash_tfm);
  1421. kfree(hasher);
  1422. }
  1423. #endif
  1424. btrfs_close_devices(fs_info->fs_devices);
  1425. btrfs_mapping_tree_free(&fs_info->mapping_tree);
  1426. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)
  1427. bdi_destroy(&fs_info->bdi);
  1428. #endif
  1429. kfree(fs_info->extent_root);
  1430. kfree(fs_info->tree_root);
  1431. kfree(fs_info->chunk_root);
  1432. kfree(fs_info->dev_root);
  1433. return 0;
  1434. }
  1435. int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid)
  1436. {
  1437. int ret;
  1438. struct inode *btree_inode = buf->first_page->mapping->host;
  1439. ret = extent_buffer_uptodate(&BTRFS_I(btree_inode)->io_tree, buf);
  1440. if (!ret)
  1441. return ret;
  1442. ret = verify_parent_transid(&BTRFS_I(btree_inode)->io_tree, buf,
  1443. parent_transid);
  1444. return !ret;
  1445. }
  1446. int btrfs_set_buffer_uptodate(struct extent_buffer *buf)
  1447. {
  1448. struct inode *btree_inode = buf->first_page->mapping->host;
  1449. return set_extent_buffer_uptodate(&BTRFS_I(btree_inode)->io_tree,
  1450. buf);
  1451. }
  1452. void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
  1453. {
  1454. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1455. u64 transid = btrfs_header_generation(buf);
  1456. struct inode *btree_inode = root->fs_info->btree_inode;
  1457. WARN_ON(!btrfs_tree_locked(buf));
  1458. if (transid != root->fs_info->generation) {
  1459. printk(KERN_CRIT "transid mismatch buffer %llu, found %Lu running %Lu\n",
  1460. (unsigned long long)buf->start,
  1461. transid, root->fs_info->generation);
  1462. WARN_ON(1);
  1463. }
  1464. set_extent_buffer_dirty(&BTRFS_I(btree_inode)->io_tree, buf);
  1465. }
  1466. void btrfs_throttle(struct btrfs_root *root)
  1467. {
  1468. #if 0
  1469. struct backing_dev_info *bdi;
  1470. bdi = &root->fs_info->bdi;
  1471. if (atomic_read(&root->fs_info->throttles) &&
  1472. bdi_write_congested(bdi)) {
  1473. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
  1474. congestion_wait(WRITE, HZ/20);
  1475. #else
  1476. blk_congestion_wait(WRITE, HZ/20);
  1477. #endif
  1478. }
  1479. #endif
  1480. }
  1481. void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr)
  1482. {
  1483. /*
  1484. * looks as though older kernels can get into trouble with
  1485. * this code, they end up stuck in balance_dirty_pages forever
  1486. */
  1487. struct extent_io_tree *tree;
  1488. u64 num_dirty;
  1489. u64 start = 0;
  1490. unsigned long thresh = 16 * 1024 * 1024;
  1491. tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree;
  1492. if (current_is_pdflush())
  1493. return;
  1494. num_dirty = count_range_bits(tree, &start, (u64)-1,
  1495. thresh, EXTENT_DIRTY);
  1496. if (num_dirty > thresh) {
  1497. balance_dirty_pages_ratelimited_nr(
  1498. root->fs_info->btree_inode->i_mapping, 1);
  1499. }
  1500. return;
  1501. }
  1502. void btrfs_set_buffer_defrag(struct extent_buffer *buf)
  1503. {
  1504. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1505. struct inode *btree_inode = root->fs_info->btree_inode;
  1506. set_extent_bits(&BTRFS_I(btree_inode)->io_tree, buf->start,
  1507. buf->start + buf->len - 1, EXTENT_DEFRAG, GFP_NOFS);
  1508. }
  1509. void btrfs_set_buffer_defrag_done(struct extent_buffer *buf)
  1510. {
  1511. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1512. struct inode *btree_inode = root->fs_info->btree_inode;
  1513. set_extent_bits(&BTRFS_I(btree_inode)->io_tree, buf->start,
  1514. buf->start + buf->len - 1, EXTENT_DEFRAG_DONE,
  1515. GFP_NOFS);
  1516. }
  1517. int btrfs_buffer_defrag(struct extent_buffer *buf)
  1518. {
  1519. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1520. struct inode *btree_inode = root->fs_info->btree_inode;
  1521. return test_range_bit(&BTRFS_I(btree_inode)->io_tree,
  1522. buf->start, buf->start + buf->len - 1, EXTENT_DEFRAG, 0);
  1523. }
  1524. int btrfs_buffer_defrag_done(struct extent_buffer *buf)
  1525. {
  1526. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1527. struct inode *btree_inode = root->fs_info->btree_inode;
  1528. return test_range_bit(&BTRFS_I(btree_inode)->io_tree,
  1529. buf->start, buf->start + buf->len - 1,
  1530. EXTENT_DEFRAG_DONE, 0);
  1531. }
  1532. int btrfs_clear_buffer_defrag_done(struct extent_buffer *buf)
  1533. {
  1534. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1535. struct inode *btree_inode = root->fs_info->btree_inode;
  1536. return clear_extent_bits(&BTRFS_I(btree_inode)->io_tree,
  1537. buf->start, buf->start + buf->len - 1,
  1538. EXTENT_DEFRAG_DONE, GFP_NOFS);
  1539. }
  1540. int btrfs_clear_buffer_defrag(struct extent_buffer *buf)
  1541. {
  1542. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1543. struct inode *btree_inode = root->fs_info->btree_inode;
  1544. return clear_extent_bits(&BTRFS_I(btree_inode)->io_tree,
  1545. buf->start, buf->start + buf->len - 1,
  1546. EXTENT_DEFRAG, GFP_NOFS);
  1547. }
  1548. int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid)
  1549. {
  1550. struct btrfs_root *root = BTRFS_I(buf->first_page->mapping->host)->root;
  1551. int ret;
  1552. ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid);
  1553. if (ret == 0) {
  1554. buf->flags |= EXTENT_UPTODATE;
  1555. }
  1556. return ret;
  1557. }
  1558. static struct extent_io_ops btree_extent_io_ops = {
  1559. .writepage_io_hook = btree_writepage_io_hook,
  1560. .readpage_end_io_hook = btree_readpage_end_io_hook,
  1561. .submit_bio_hook = btree_submit_bio_hook,
  1562. /* note we're sharing with inode.c for the merge bio hook */
  1563. .merge_bio_hook = btrfs_merge_bio_hook,
  1564. };