compression.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  2. * Copyright (C) 2008 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/kernel.h>
  19. #include <linux/bio.h>
  20. #include <linux/buffer_head.h>
  21. #include <linux/file.h>
  22. #include <linux/fs.h>
  23. #include <linux/pagemap.h>
  24. #include <linux/highmem.h>
  25. #include <linux/time.h>
  26. #include <linux/init.h>
  27. #include <linux/string.h>
  28. #include <linux/backing-dev.h>
  29. #include <linux/mpage.h>
  30. #include <linux/swap.h>
  31. #include <linux/writeback.h>
  32. #include <linux/bit_spinlock.h>
  33. #include "compat.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 "ordered-data.h"
  40. #include "compression.h"
  41. #include "extent_io.h"
  42. #include "extent_map.h"
  43. struct compressed_bio {
  44. /* number of bios pending for this compressed extent */
  45. atomic_t pending_bios;
  46. /* the pages with the compressed data on them */
  47. struct page **compressed_pages;
  48. /* inode that owns this data */
  49. struct inode *inode;
  50. /* starting offset in the inode for our pages */
  51. u64 start;
  52. /* number of bytes in the inode we're working on */
  53. unsigned long len;
  54. /* number of bytes on disk */
  55. unsigned long compressed_len;
  56. /* number of compressed pages in the array */
  57. unsigned long nr_pages;
  58. /* IO errors */
  59. int errors;
  60. int mirror_num;
  61. /* for reads, this is the bio we are copying the data into */
  62. struct bio *orig_bio;
  63. /*
  64. * the start of a variable length array of checksums only
  65. * used by reads
  66. */
  67. u32 sums;
  68. };
  69. static inline int compressed_bio_size(struct btrfs_root *root,
  70. unsigned long disk_size)
  71. {
  72. u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy);
  73. return sizeof(struct compressed_bio) +
  74. ((disk_size + root->sectorsize - 1) / root->sectorsize) *
  75. csum_size;
  76. }
  77. static struct bio *compressed_bio_alloc(struct block_device *bdev,
  78. u64 first_byte, gfp_t gfp_flags)
  79. {
  80. struct bio *bio;
  81. int nr_vecs;
  82. nr_vecs = bio_get_nr_vecs(bdev);
  83. bio = bio_alloc(gfp_flags, nr_vecs);
  84. if (bio == NULL && (current->flags & PF_MEMALLOC)) {
  85. while (!bio && (nr_vecs /= 2))
  86. bio = bio_alloc(gfp_flags, nr_vecs);
  87. }
  88. if (bio) {
  89. bio->bi_size = 0;
  90. bio->bi_bdev = bdev;
  91. bio->bi_sector = first_byte >> 9;
  92. }
  93. return bio;
  94. }
  95. static int check_compressed_csum(struct inode *inode,
  96. struct compressed_bio *cb,
  97. u64 disk_start)
  98. {
  99. int ret;
  100. struct btrfs_root *root = BTRFS_I(inode)->root;
  101. struct page *page;
  102. unsigned long i;
  103. char *kaddr;
  104. u32 csum;
  105. u32 *cb_sum = &cb->sums;
  106. if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
  107. return 0;
  108. for (i = 0; i < cb->nr_pages; i++) {
  109. page = cb->compressed_pages[i];
  110. csum = ~(u32)0;
  111. kaddr = kmap_atomic(page, KM_USER0);
  112. csum = btrfs_csum_data(root, kaddr, csum, PAGE_CACHE_SIZE);
  113. btrfs_csum_final(csum, (char *)&csum);
  114. kunmap_atomic(kaddr, KM_USER0);
  115. if (csum != *cb_sum) {
  116. printk(KERN_INFO "btrfs csum failed ino %lu "
  117. "extent %llu csum %u "
  118. "wanted %u mirror %d\n", inode->i_ino,
  119. (unsigned long long)disk_start,
  120. csum, *cb_sum, cb->mirror_num);
  121. ret = -EIO;
  122. goto fail;
  123. }
  124. cb_sum++;
  125. }
  126. ret = 0;
  127. fail:
  128. return ret;
  129. }
  130. /* when we finish reading compressed pages from the disk, we
  131. * decompress them and then run the bio end_io routines on the
  132. * decompressed pages (in the inode address space).
  133. *
  134. * This allows the checksumming and other IO error handling routines
  135. * to work normally
  136. *
  137. * The compressed pages are freed here, and it must be run
  138. * in process context
  139. */
  140. static void end_compressed_bio_read(struct bio *bio, int err)
  141. {
  142. struct extent_io_tree *tree;
  143. struct compressed_bio *cb = bio->bi_private;
  144. struct inode *inode;
  145. struct page *page;
  146. unsigned long index;
  147. int ret;
  148. if (err)
  149. cb->errors = 1;
  150. /* if there are more bios still pending for this compressed
  151. * extent, just exit
  152. */
  153. if (!atomic_dec_and_test(&cb->pending_bios))
  154. goto out;
  155. inode = cb->inode;
  156. ret = check_compressed_csum(inode, cb, (u64)bio->bi_sector << 9);
  157. if (ret)
  158. goto csum_failed;
  159. /* ok, we're the last bio for this extent, lets start
  160. * the decompression.
  161. */
  162. tree = &BTRFS_I(inode)->io_tree;
  163. ret = btrfs_zlib_decompress_biovec(cb->compressed_pages,
  164. cb->start,
  165. cb->orig_bio->bi_io_vec,
  166. cb->orig_bio->bi_vcnt,
  167. cb->compressed_len);
  168. csum_failed:
  169. if (ret)
  170. cb->errors = 1;
  171. /* release the compressed pages */
  172. index = 0;
  173. for (index = 0; index < cb->nr_pages; index++) {
  174. page = cb->compressed_pages[index];
  175. page->mapping = NULL;
  176. page_cache_release(page);
  177. }
  178. /* do io completion on the original bio */
  179. if (cb->errors) {
  180. bio_io_error(cb->orig_bio);
  181. } else {
  182. int bio_index = 0;
  183. struct bio_vec *bvec = cb->orig_bio->bi_io_vec;
  184. /*
  185. * we have verified the checksum already, set page
  186. * checked so the end_io handlers know about it
  187. */
  188. while (bio_index < cb->orig_bio->bi_vcnt) {
  189. SetPageChecked(bvec->bv_page);
  190. bvec++;
  191. bio_index++;
  192. }
  193. bio_endio(cb->orig_bio, 0);
  194. }
  195. /* finally free the cb struct */
  196. kfree(cb->compressed_pages);
  197. kfree(cb);
  198. out:
  199. bio_put(bio);
  200. }
  201. /*
  202. * Clear the writeback bits on all of the file
  203. * pages for a compressed write
  204. */
  205. static noinline int end_compressed_writeback(struct inode *inode, u64 start,
  206. unsigned long ram_size)
  207. {
  208. unsigned long index = start >> PAGE_CACHE_SHIFT;
  209. unsigned long end_index = (start + ram_size - 1) >> PAGE_CACHE_SHIFT;
  210. struct page *pages[16];
  211. unsigned long nr_pages = end_index - index + 1;
  212. int i;
  213. int ret;
  214. while (nr_pages > 0) {
  215. ret = find_get_pages_contig(inode->i_mapping, index,
  216. min_t(unsigned long,
  217. nr_pages, ARRAY_SIZE(pages)), pages);
  218. if (ret == 0) {
  219. nr_pages -= 1;
  220. index += 1;
  221. continue;
  222. }
  223. for (i = 0; i < ret; i++) {
  224. end_page_writeback(pages[i]);
  225. page_cache_release(pages[i]);
  226. }
  227. nr_pages -= ret;
  228. index += ret;
  229. }
  230. /* the inode may be gone now */
  231. return 0;
  232. }
  233. /*
  234. * do the cleanup once all the compressed pages hit the disk.
  235. * This will clear writeback on the file pages and free the compressed
  236. * pages.
  237. *
  238. * This also calls the writeback end hooks for the file pages so that
  239. * metadata and checksums can be updated in the file.
  240. */
  241. static void end_compressed_bio_write(struct bio *bio, int err)
  242. {
  243. struct extent_io_tree *tree;
  244. struct compressed_bio *cb = bio->bi_private;
  245. struct inode *inode;
  246. struct page *page;
  247. unsigned long index;
  248. if (err)
  249. cb->errors = 1;
  250. /* if there are more bios still pending for this compressed
  251. * extent, just exit
  252. */
  253. if (!atomic_dec_and_test(&cb->pending_bios))
  254. goto out;
  255. /* ok, we're the last bio for this extent, step one is to
  256. * call back into the FS and do all the end_io operations
  257. */
  258. inode = cb->inode;
  259. tree = &BTRFS_I(inode)->io_tree;
  260. cb->compressed_pages[0]->mapping = cb->inode->i_mapping;
  261. tree->ops->writepage_end_io_hook(cb->compressed_pages[0],
  262. cb->start,
  263. cb->start + cb->len - 1,
  264. NULL, 1);
  265. cb->compressed_pages[0]->mapping = NULL;
  266. end_compressed_writeback(inode, cb->start, cb->len);
  267. /* note, our inode could be gone now */
  268. /*
  269. * release the compressed pages, these came from alloc_page and
  270. * are not attached to the inode at all
  271. */
  272. index = 0;
  273. for (index = 0; index < cb->nr_pages; index++) {
  274. page = cb->compressed_pages[index];
  275. page->mapping = NULL;
  276. page_cache_release(page);
  277. }
  278. /* finally free the cb struct */
  279. kfree(cb->compressed_pages);
  280. kfree(cb);
  281. out:
  282. bio_put(bio);
  283. }
  284. /*
  285. * worker function to build and submit bios for previously compressed pages.
  286. * The corresponding pages in the inode should be marked for writeback
  287. * and the compressed pages should have a reference on them for dropping
  288. * when the IO is complete.
  289. *
  290. * This also checksums the file bytes and gets things ready for
  291. * the end io hooks.
  292. */
  293. int btrfs_submit_compressed_write(struct inode *inode, u64 start,
  294. unsigned long len, u64 disk_start,
  295. unsigned long compressed_len,
  296. struct page **compressed_pages,
  297. unsigned long nr_pages)
  298. {
  299. struct bio *bio = NULL;
  300. struct btrfs_root *root = BTRFS_I(inode)->root;
  301. struct compressed_bio *cb;
  302. unsigned long bytes_left;
  303. struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
  304. int page_index = 0;
  305. struct page *page;
  306. u64 first_byte = disk_start;
  307. struct block_device *bdev;
  308. int ret;
  309. WARN_ON(start & ((u64)PAGE_CACHE_SIZE - 1));
  310. cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS);
  311. atomic_set(&cb->pending_bios, 0);
  312. cb->errors = 0;
  313. cb->inode = inode;
  314. cb->start = start;
  315. cb->len = len;
  316. cb->mirror_num = 0;
  317. cb->compressed_pages = compressed_pages;
  318. cb->compressed_len = compressed_len;
  319. cb->orig_bio = NULL;
  320. cb->nr_pages = nr_pages;
  321. bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
  322. bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS);
  323. bio->bi_private = cb;
  324. bio->bi_end_io = end_compressed_bio_write;
  325. atomic_inc(&cb->pending_bios);
  326. /* create and submit bios for the compressed pages */
  327. bytes_left = compressed_len;
  328. for (page_index = 0; page_index < cb->nr_pages; page_index++) {
  329. page = compressed_pages[page_index];
  330. page->mapping = inode->i_mapping;
  331. if (bio->bi_size)
  332. ret = io_tree->ops->merge_bio_hook(page, 0,
  333. PAGE_CACHE_SIZE,
  334. bio, 0);
  335. else
  336. ret = 0;
  337. page->mapping = NULL;
  338. if (ret || bio_add_page(bio, page, PAGE_CACHE_SIZE, 0) <
  339. PAGE_CACHE_SIZE) {
  340. bio_get(bio);
  341. /*
  342. * inc the count before we submit the bio so
  343. * we know the end IO handler won't happen before
  344. * we inc the count. Otherwise, the cb might get
  345. * freed before we're done setting it up
  346. */
  347. atomic_inc(&cb->pending_bios);
  348. ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0);
  349. BUG_ON(ret);
  350. ret = btrfs_csum_one_bio(root, inode, bio, start, 1);
  351. BUG_ON(ret);
  352. ret = btrfs_map_bio(root, WRITE, bio, 0, 1);
  353. BUG_ON(ret);
  354. bio_put(bio);
  355. bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS);
  356. bio->bi_private = cb;
  357. bio->bi_end_io = end_compressed_bio_write;
  358. bio_add_page(bio, page, PAGE_CACHE_SIZE, 0);
  359. }
  360. if (bytes_left < PAGE_CACHE_SIZE) {
  361. printk("bytes left %lu compress len %lu nr %lu\n",
  362. bytes_left, cb->compressed_len, cb->nr_pages);
  363. }
  364. bytes_left -= PAGE_CACHE_SIZE;
  365. first_byte += PAGE_CACHE_SIZE;
  366. cond_resched();
  367. }
  368. bio_get(bio);
  369. ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0);
  370. BUG_ON(ret);
  371. ret = btrfs_csum_one_bio(root, inode, bio, start, 1);
  372. BUG_ON(ret);
  373. ret = btrfs_map_bio(root, WRITE, bio, 0, 1);
  374. BUG_ON(ret);
  375. bio_put(bio);
  376. return 0;
  377. }
  378. static noinline int add_ra_bio_pages(struct inode *inode,
  379. u64 compressed_end,
  380. struct compressed_bio *cb)
  381. {
  382. unsigned long end_index;
  383. unsigned long page_index;
  384. u64 last_offset;
  385. u64 isize = i_size_read(inode);
  386. int ret;
  387. struct page *page;
  388. unsigned long nr_pages = 0;
  389. struct extent_map *em;
  390. struct address_space *mapping = inode->i_mapping;
  391. struct extent_map_tree *em_tree;
  392. struct extent_io_tree *tree;
  393. u64 end;
  394. int misses = 0;
  395. page = cb->orig_bio->bi_io_vec[cb->orig_bio->bi_vcnt - 1].bv_page;
  396. last_offset = (page_offset(page) + PAGE_CACHE_SIZE);
  397. em_tree = &BTRFS_I(inode)->extent_tree;
  398. tree = &BTRFS_I(inode)->io_tree;
  399. if (isize == 0)
  400. return 0;
  401. end_index = (i_size_read(inode) - 1) >> PAGE_CACHE_SHIFT;
  402. while (last_offset < compressed_end) {
  403. page_index = last_offset >> PAGE_CACHE_SHIFT;
  404. if (page_index > end_index)
  405. break;
  406. rcu_read_lock();
  407. page = radix_tree_lookup(&mapping->page_tree, page_index);
  408. rcu_read_unlock();
  409. if (page) {
  410. misses++;
  411. if (misses > 4)
  412. break;
  413. goto next;
  414. }
  415. page = __page_cache_alloc(mapping_gfp_mask(mapping) &
  416. ~__GFP_FS);
  417. if (!page)
  418. break;
  419. if (add_to_page_cache_lru(page, mapping, page_index,
  420. GFP_NOFS)) {
  421. page_cache_release(page);
  422. goto next;
  423. }
  424. end = last_offset + PAGE_CACHE_SIZE - 1;
  425. /*
  426. * at this point, we have a locked page in the page cache
  427. * for these bytes in the file. But, we have to make
  428. * sure they map to this compressed extent on disk.
  429. */
  430. set_page_extent_mapped(page);
  431. lock_extent(tree, last_offset, end, GFP_NOFS);
  432. read_lock(&em_tree->lock);
  433. em = lookup_extent_mapping(em_tree, last_offset,
  434. PAGE_CACHE_SIZE);
  435. read_unlock(&em_tree->lock);
  436. if (!em || last_offset < em->start ||
  437. (last_offset + PAGE_CACHE_SIZE > extent_map_end(em)) ||
  438. (em->block_start >> 9) != cb->orig_bio->bi_sector) {
  439. free_extent_map(em);
  440. unlock_extent(tree, last_offset, end, GFP_NOFS);
  441. unlock_page(page);
  442. page_cache_release(page);
  443. break;
  444. }
  445. free_extent_map(em);
  446. if (page->index == end_index) {
  447. char *userpage;
  448. size_t zero_offset = isize & (PAGE_CACHE_SIZE - 1);
  449. if (zero_offset) {
  450. int zeros;
  451. zeros = PAGE_CACHE_SIZE - zero_offset;
  452. userpage = kmap_atomic(page, KM_USER0);
  453. memset(userpage + zero_offset, 0, zeros);
  454. flush_dcache_page(page);
  455. kunmap_atomic(userpage, KM_USER0);
  456. }
  457. }
  458. ret = bio_add_page(cb->orig_bio, page,
  459. PAGE_CACHE_SIZE, 0);
  460. if (ret == PAGE_CACHE_SIZE) {
  461. nr_pages++;
  462. page_cache_release(page);
  463. } else {
  464. unlock_extent(tree, last_offset, end, GFP_NOFS);
  465. unlock_page(page);
  466. page_cache_release(page);
  467. break;
  468. }
  469. next:
  470. last_offset += PAGE_CACHE_SIZE;
  471. }
  472. return 0;
  473. }
  474. /*
  475. * for a compressed read, the bio we get passed has all the inode pages
  476. * in it. We don't actually do IO on those pages but allocate new ones
  477. * to hold the compressed pages on disk.
  478. *
  479. * bio->bi_sector points to the compressed extent on disk
  480. * bio->bi_io_vec points to all of the inode pages
  481. * bio->bi_vcnt is a count of pages
  482. *
  483. * After the compressed pages are read, we copy the bytes into the
  484. * bio we were passed and then call the bio end_io calls
  485. */
  486. int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
  487. int mirror_num, unsigned long bio_flags)
  488. {
  489. struct extent_io_tree *tree;
  490. struct extent_map_tree *em_tree;
  491. struct compressed_bio *cb;
  492. struct btrfs_root *root = BTRFS_I(inode)->root;
  493. unsigned long uncompressed_len = bio->bi_vcnt * PAGE_CACHE_SIZE;
  494. unsigned long compressed_len;
  495. unsigned long nr_pages;
  496. unsigned long page_index;
  497. struct page *page;
  498. struct block_device *bdev;
  499. struct bio *comp_bio;
  500. u64 cur_disk_byte = (u64)bio->bi_sector << 9;
  501. u64 em_len;
  502. u64 em_start;
  503. struct extent_map *em;
  504. int ret;
  505. u32 *sums;
  506. tree = &BTRFS_I(inode)->io_tree;
  507. em_tree = &BTRFS_I(inode)->extent_tree;
  508. /* we need the actual starting offset of this extent in the file */
  509. read_lock(&em_tree->lock);
  510. em = lookup_extent_mapping(em_tree,
  511. page_offset(bio->bi_io_vec->bv_page),
  512. PAGE_CACHE_SIZE);
  513. read_unlock(&em_tree->lock);
  514. compressed_len = em->block_len;
  515. cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS);
  516. atomic_set(&cb->pending_bios, 0);
  517. cb->errors = 0;
  518. cb->inode = inode;
  519. cb->mirror_num = mirror_num;
  520. sums = &cb->sums;
  521. cb->start = em->orig_start;
  522. em_len = em->len;
  523. em_start = em->start;
  524. free_extent_map(em);
  525. em = NULL;
  526. cb->len = uncompressed_len;
  527. cb->compressed_len = compressed_len;
  528. cb->orig_bio = bio;
  529. nr_pages = (compressed_len + PAGE_CACHE_SIZE - 1) /
  530. PAGE_CACHE_SIZE;
  531. cb->compressed_pages = kmalloc(sizeof(struct page *) * nr_pages,
  532. GFP_NOFS);
  533. bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
  534. for (page_index = 0; page_index < nr_pages; page_index++) {
  535. cb->compressed_pages[page_index] = alloc_page(GFP_NOFS |
  536. __GFP_HIGHMEM);
  537. }
  538. cb->nr_pages = nr_pages;
  539. add_ra_bio_pages(inode, em_start + em_len, cb);
  540. /* include any pages we added in add_ra-bio_pages */
  541. uncompressed_len = bio->bi_vcnt * PAGE_CACHE_SIZE;
  542. cb->len = uncompressed_len;
  543. comp_bio = compressed_bio_alloc(bdev, cur_disk_byte, GFP_NOFS);
  544. comp_bio->bi_private = cb;
  545. comp_bio->bi_end_io = end_compressed_bio_read;
  546. atomic_inc(&cb->pending_bios);
  547. for (page_index = 0; page_index < nr_pages; page_index++) {
  548. page = cb->compressed_pages[page_index];
  549. page->mapping = inode->i_mapping;
  550. page->index = em_start >> PAGE_CACHE_SHIFT;
  551. if (comp_bio->bi_size)
  552. ret = tree->ops->merge_bio_hook(page, 0,
  553. PAGE_CACHE_SIZE,
  554. comp_bio, 0);
  555. else
  556. ret = 0;
  557. page->mapping = NULL;
  558. if (ret || bio_add_page(comp_bio, page, PAGE_CACHE_SIZE, 0) <
  559. PAGE_CACHE_SIZE) {
  560. bio_get(comp_bio);
  561. ret = btrfs_bio_wq_end_io(root->fs_info, comp_bio, 0);
  562. BUG_ON(ret);
  563. /*
  564. * inc the count before we submit the bio so
  565. * we know the end IO handler won't happen before
  566. * we inc the count. Otherwise, the cb might get
  567. * freed before we're done setting it up
  568. */
  569. atomic_inc(&cb->pending_bios);
  570. if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
  571. btrfs_lookup_bio_sums(root, inode, comp_bio,
  572. sums);
  573. }
  574. sums += (comp_bio->bi_size + root->sectorsize - 1) /
  575. root->sectorsize;
  576. ret = btrfs_map_bio(root, READ, comp_bio,
  577. mirror_num, 0);
  578. BUG_ON(ret);
  579. bio_put(comp_bio);
  580. comp_bio = compressed_bio_alloc(bdev, cur_disk_byte,
  581. GFP_NOFS);
  582. comp_bio->bi_private = cb;
  583. comp_bio->bi_end_io = end_compressed_bio_read;
  584. bio_add_page(comp_bio, page, PAGE_CACHE_SIZE, 0);
  585. }
  586. cur_disk_byte += PAGE_CACHE_SIZE;
  587. }
  588. bio_get(comp_bio);
  589. ret = btrfs_bio_wq_end_io(root->fs_info, comp_bio, 0);
  590. BUG_ON(ret);
  591. if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM))
  592. btrfs_lookup_bio_sums(root, inode, comp_bio, sums);
  593. ret = btrfs_map_bio(root, READ, comp_bio, mirror_num, 0);
  594. BUG_ON(ret);
  595. bio_put(comp_bio);
  596. return 0;
  597. }