disk-io.c 47 KB

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