compression.c 18 KB

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