Lines Matching defs:bio

16 #include <linux/bio.h>
53 static inline struct bio *__f2fs_bio_alloc(gfp_t gfp_mask,
59 struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, int npages, bool noio)
62 /* No failure on bio allocation */
125 struct bio *bio;
131 static void __read_end_io(struct bio *bio, bool compr, bool verity)
137 bio_for_each_segment_all(bv, bio, iter_all) {
142 f2fs_decompress_pages(bio, page, verity);
150 if (bio->bi_status || PageError(page)) {
162 static void f2fs_release_read_bio(struct bio *bio);
163 static void __f2fs_read_end_io(struct bio *bio, bool compr, bool verity)
166 __read_end_io(bio, false, verity);
167 f2fs_release_read_bio(bio);
170 static void f2fs_decompress_bio(struct bio *bio, bool verity)
172 __read_end_io(bio, true, verity);
179 fscrypt_decrypt_bio(ctx->bio);
184 f2fs_decompress_bio(ctx->bio, ctx->enabled_steps & (1 << STEP_VERITY));
193 static void f2fs_verify_bio(struct bio *bio)
198 bio_for_each_segment_all(bv, bio, iter_all) {
213 if (bio->bi_status || PageError(page))
234 struct bio *bio = ctx->bio;
247 bio->bi_private = NULL;
252 f2fs_verify_bio(bio);
253 f2fs_release_read_bio(bio);
258 fsverity_verify_bio(bio);
259 __f2fs_read_end_io(bio, false, false);
279 __f2fs_read_end_io(ctx->bio,
310 __f2fs_read_end_io(ctx->bio, false, false);
313 static bool f2fs_bio_post_read_required(struct bio *bio)
315 return bio->bi_private;
318 static void f2fs_read_end_io(struct bio *bio)
320 struct f2fs_sb_info *sbi = F2FS_P_SB(bio_first_page_all(bio));
324 bio->bi_status = BLK_STS_IOERR;
327 if (f2fs_bio_post_read_required(bio)) {
328 struct bio_post_read_ctx *ctx = bio->bi_private;
334 __f2fs_read_end_io(bio, false, false);
337 static void f2fs_write_end_io(struct bio *bio)
339 struct f2fs_sb_info *sbi = bio->bi_private;
345 bio->bi_status = BLK_STS_IOERR;
348 bio_for_each_segment_all(bvec, bio, iter_all) {
358 if (unlikely(bio->bi_status))
367 f2fs_compress_write_end_io(bio, page);
372 if (unlikely(bio->bi_status)) {
391 bio_put(bio);
395 block_t blk_addr, struct bio *bio)
410 if (bio) {
411 bio_set_dev(bio, bdev);
412 bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blk_addr);
434 block_t blk_addr, struct bio *bio)
437 return bio->bi_disk == b->bd_disk && bio->bi_partno == b->bd_partno;
440 static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)
443 struct bio *bio;
445 bio = f2fs_bio_alloc(sbi, npages, true);
447 f2fs_target_device(sbi, fio->new_blkaddr, bio);
449 bio->bi_end_io = f2fs_read_end_io;
450 bio->bi_private = NULL;
452 bio->bi_end_io = f2fs_write_end_io;
453 bio->bi_private = sbi;
454 bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi,
458 wbc_init_bio(fio->io_wbc, bio);
460 return bio;
463 static void f2fs_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,
473 fscrypt_set_bio_crypt_ctx(bio, inode, first_idx, gfp_mask);
476 static bool f2fs_crypt_mergeable_bio(struct bio *bio, const struct inode *inode,
485 return !bio_has_crypt_ctx(bio);
487 return fscrypt_mergeable_bio(bio, inode, next_idx);
491 struct bio *bio, enum page_type type)
493 if (!is_read_io(bio_op(bio))) {
505 start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS;
522 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE)
533 if (is_read_io(bio_op(bio)))
534 trace_f2fs_submit_read_bio(sbi->sb, type, bio);
536 trace_f2fs_submit_write_bio(sbi->sb, type, bio);
537 submit_bio(bio);
541 struct bio *bio, enum page_type type)
543 __submit_bio(sbi, bio, type);
578 if (!io->bio)
582 bio_set_op_attrs(io->bio, fio->op, fio->op_flags);
585 trace_f2fs_prepare_read_bio(io->sbi->sb, fio->type, io->bio);
587 trace_f2fs_prepare_write_bio(io->sbi->sb, fio->type, io->bio);
589 __submit_bio(io->sbi, io->bio, fio->type);
590 io->bio = NULL;
593 static bool __has_merged_page(struct bio *bio, struct inode *inode,
599 if (!bio)
605 bio_for_each_segment_all(bvec, bio, iter_all) {
663 ret = __has_merged_page(io->bio, inode, page, ino);
700 struct bio *bio;
712 /* Allocate a new bio */
713 bio = __bio_alloc(fio, 1);
715 f2fs_set_bio_crypt_ctx(bio, fio->page->mapping->host,
718 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
719 bio_put(bio);
727 bio_set_op_attrs(bio, fio->op, fio->op_flags);
732 __submit_bio(fio->sbi, bio, fio->type);
736 static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
741 return __same_bdev(sbi, cur_blkaddr, bio);
752 static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
760 F2FS_BYTES_TO_BLK(bio->bi_iter.bi_size);
762 unsigned int left_vecs = bio->bi_max_vecs - bio->bi_vcnt;
764 /* IOs in bio is aligned and left space of vectors is not enough */
768 if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr))
773 static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
780 be->bio = bio;
781 bio_get(bio);
783 if (bio_add_page(bio, page, PAGE_SIZE, 0) != PAGE_SIZE)
797 static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
812 if (be->bio != *bio)
817 f2fs_bug_on(sbi, !page_is_mergeable(sbi, *bio,
820 if (f2fs_crypt_mergeable_bio(*bio,
823 bio_add_page(*bio, page, PAGE_SIZE, 0) ==
829 /* page can't be merged into bio; submit the bio */
831 __submit_bio(sbi, *bio, DATA);
838 bio_put(*bio);
839 *bio = NULL;
846 struct bio **bio, struct page *page)
850 struct bio *target = bio ? *bio : NULL;
865 found = (target == be->bio);
867 found = __has_merged_page(be->bio, NULL,
882 found = (target == be->bio);
884 found = __has_merged_page(be->bio, NULL,
887 target = be->bio;
897 if (bio && *bio) {
898 bio_put(*bio);
899 *bio = NULL;
905 struct bio *bio = *fio->bio;
916 if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block,
918 f2fs_submit_merged_ipu_write(fio->sbi, &bio, NULL);
920 if (!bio) {
921 bio = __bio_alloc(fio, BIO_MAX_PAGES);
923 f2fs_set_bio_crypt_ctx(bio, fio->page->mapping->host,
925 bio_set_op_attrs(bio, fio->op, fio->op_flags);
927 add_bio_entry(fio->sbi, bio, page, fio->temp);
929 if (add_ipu_page(fio, &bio, page))
939 *fio->bio = bio;
981 if (io->bio &&
982 (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio,
984 !f2fs_crypt_mergeable_bio(io->bio, fio->page->mapping->host,
988 if (io->bio == NULL) {
996 io->bio = __bio_alloc(fio, BIO_MAX_PAGES);
997 f2fs_set_bio_crypt_ctx(io->bio, fio->page->mapping->host,
1002 if (bio_add_page(io->bio, bio_page, PAGE_SIZE, 0) < PAGE_SIZE) {
1030 static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,
1036 struct bio *bio;
1040 bio = f2fs_bio_alloc(sbi, min_t(int, nr_pages, BIO_MAX_PAGES),
1042 if (!bio)
1045 f2fs_set_bio_crypt_ctx(bio, inode, first_idx, NULL, GFP_NOFS);
1047 f2fs_target_device(sbi, blkaddr, bio);
1048 bio->bi_end_io = f2fs_read_end_io;
1049 bio_set_op_attrs(bio, REQ_OP_READ, op_flag);
1061 ctx->bio = bio;
1064 bio->bi_private = ctx;
1067 return bio;
1070 static void f2fs_release_read_bio(struct bio *bio)
1072 if (bio->bi_private)
1073 mempool_free(bio->bi_private, bio_post_read_ctx_pool);
1074 bio_put(bio);
1082 struct bio *bio;
1084 bio = f2fs_grab_read_bio(inode, blkaddr, 1, op_flags,
1086 if (IS_ERR(bio))
1087 return PTR_ERR(bio);
1092 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
1093 bio_put(bio);
1099 __submit_bio(sbi, bio, DATA);
2072 struct bio **bio_ret,
2076 struct bio *bio = *bio_ret;
2147 if (bio && (!page_is_mergeable(F2FS_I_SB(inode), bio,
2149 !f2fs_crypt_mergeable_bio(bio, inode, page->index, NULL))) {
2151 __submit_bio(F2FS_I_SB(inode), bio, DATA);
2152 bio = NULL;
2154 if (bio == NULL) {
2155 bio = f2fs_grab_read_bio(inode, block_nr, nr_pages,
2158 if (IS_ERR(bio)) {
2159 ret = PTR_ERR(bio);
2160 bio = NULL;
2171 if (bio_add_page(bio, page, blocksize, 0) < blocksize)
2180 if (bio) {
2181 __submit_bio(F2FS_I_SB(inode), bio, DATA);
2182 bio = NULL;
2186 *bio_ret = bio;
2191 int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
2198 struct bio *bio = *bio_ret;
2277 * per cluster. In order to do that, we need to submit bio, if previous
2278 * bio sets a different post-process policy.
2284 if (bio) {
2285 ctx = bio->bi_private;
2287 __submit_bio(sbi, bio, DATA);
2288 bio = NULL;
2300 if (bio && (!page_is_mergeable(sbi, bio,
2302 !f2fs_crypt_mergeable_bio(bio, inode, page->index, NULL))) {
2304 __submit_bio(sbi, bio, DATA);
2305 bio = NULL;
2308 if (!bio) {
2309 bio = f2fs_grab_read_bio(inode, blkaddr, nr_pages,
2312 if (IS_ERR(bio)) {
2316 ret = PTR_ERR(bio);
2344 if (bio_add_page(bio, page, blocksize, 0) < blocksize)
2348 ctx = bio->bi_private;
2361 *bio_ret = bio;
2368 *bio_ret = bio;
2385 struct bio *bio = NULL;
2440 ret = f2fs_read_multi_pages(&cc, &bio,
2466 &bio, &last_block_in_bio, rac);
2485 ret = f2fs_read_multi_pages(&cc, &bio,
2494 if (bio)
2495 __submit_bio(F2FS_I_SB(inode), bio, DATA);
2778 struct bio **bio,
2808 .bio = bio,
2927 if (bio && *bio)
2928 f2fs_submit_merged_ipu_write(sbi, bio, NULL);
2986 struct bio *bio = NULL;
3138 &bio, &last_block, wbc, io_type,
3210 /* submit cached bio of IPU write */
3211 if (bio)
3212 f2fs_submit_merged_ipu_write(sbi, &bio, NULL);
3634 static void f2fs_dio_end_io(struct bio *bio)
3636 struct f2fs_private_dio *dio = bio->bi_private;
3641 bio->bi_private = dio->orig_private;
3642 bio->bi_end_io = dio->orig_end_io;
3646 bio_endio(bio);
3649 static void f2fs_dio_submit_bio(struct bio *bio, struct inode *inode,
3653 bool write = (bio_op(bio) == REQ_OP_WRITE);
3661 dio->orig_end_io = bio->bi_end_io;
3662 dio->orig_private = bio->bi_private;
3665 bio->bi_end_io = f2fs_dio_end_io;
3666 bio->bi_private = dio;
3671 submit_bio(bio);
3674 bio->bi_status = BLK_STS_IOERR;
3675 bio_endio(bio);