compression.c 17 KB

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