data.c (e57e9ae5b179a6b243c42bf6d9549d1595c27089) | data.c (3c62be17d4f562f43fe1d03b48194399caa35aa5) |
---|---|
1/* 2 * fs/f2fs/data.c 3 * 4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 5 * http://www.samsung.com/ 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 74 unchanged lines hidden (view full) --- 83 if (atomic_dec_and_test(&sbi->nr_wb_bios) && 84 wq_has_sleeper(&sbi->cp_wait)) 85 wake_up(&sbi->cp_wait); 86 87 bio_put(bio); 88} 89 90/* | 1/* 2 * fs/f2fs/data.c 3 * 4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 5 * http://www.samsung.com/ 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 74 unchanged lines hidden (view full) --- 83 if (atomic_dec_and_test(&sbi->nr_wb_bios) && 84 wq_has_sleeper(&sbi->cp_wait)) 85 wake_up(&sbi->cp_wait); 86 87 bio_put(bio); 88} 89 90/* |
91 * Return true, if pre_bio's bdev is same as its target device. 92 */ 93struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 94 block_t blk_addr, struct bio *bio) 95{ 96 struct block_device *bdev = sbi->sb->s_bdev; 97 int i; 98 99 for (i = 0; i < sbi->s_ndevs; i++) { 100 if (FDEV(i).start_blk <= blk_addr && 101 FDEV(i).end_blk >= blk_addr) { 102 blk_addr -= FDEV(i).start_blk; 103 bdev = FDEV(i).bdev; 104 break; 105 } 106 } 107 if (bio) { 108 bio->bi_bdev = bdev; 109 bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blk_addr); 110 } 111 return bdev; 112} 113 114int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr) 115{ 116 int i; 117 118 for (i = 0; i < sbi->s_ndevs; i++) 119 if (FDEV(i).start_blk <= blkaddr && FDEV(i).end_blk >= blkaddr) 120 return i; 121 return 0; 122} 123 124static bool __same_bdev(struct f2fs_sb_info *sbi, 125 block_t blk_addr, struct bio *bio) 126{ 127 return f2fs_target_device(sbi, blk_addr, NULL) == bio->bi_bdev; 128} 129 130/* |
|
91 * Low-level block read/write IO operations. 92 */ 93static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, 94 int npages, bool is_read) 95{ 96 struct bio *bio; 97 98 bio = f2fs_bio_alloc(npages); 99 | 131 * Low-level block read/write IO operations. 132 */ 133static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, 134 int npages, bool is_read) 135{ 136 struct bio *bio; 137 138 bio = f2fs_bio_alloc(npages); 139 |
100 bio->bi_bdev = sbi->sb->s_bdev; 101 bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blk_addr); | 140 f2fs_target_device(sbi, blk_addr, bio); |
102 bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io; 103 bio->bi_private = is_read ? NULL : sbi; 104 105 return bio; 106} 107 108static inline void __submit_bio(struct f2fs_sb_info *sbi, 109 struct bio *bio, enum page_type type) --- 158 unchanged lines hidden (view full) --- 268 269 if (fio->old_blkaddr != NEW_ADDR) 270 verify_block_addr(sbi, fio->old_blkaddr); 271 verify_block_addr(sbi, fio->new_blkaddr); 272 273 down_write(&io->io_rwsem); 274 275 if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 || | 141 bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io; 142 bio->bi_private = is_read ? NULL : sbi; 143 144 return bio; 145} 146 147static inline void __submit_bio(struct f2fs_sb_info *sbi, 148 struct bio *bio, enum page_type type) --- 158 unchanged lines hidden (view full) --- 307 308 if (fio->old_blkaddr != NEW_ADDR) 309 verify_block_addr(sbi, fio->old_blkaddr); 310 verify_block_addr(sbi, fio->new_blkaddr); 311 312 down_write(&io->io_rwsem); 313 314 if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 || |
276 (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags))) | 315 (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) || 316 !__same_bdev(sbi, fio->new_blkaddr, io->bio))) |
277 __submit_merged_bio(io); 278alloc_new: 279 if (io->bio == NULL) { 280 io->bio = __bio_alloc(sbi, fio->new_blkaddr, 281 BIO_MAX_PAGES, is_read); 282 io->fio = *fio; 283 } 284 --- 671 unchanged lines hidden (view full) --- 956 return ret; 957} 958 959static struct bio *f2fs_grab_bio(struct inode *inode, block_t blkaddr, 960 unsigned nr_pages) 961{ 962 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 963 struct fscrypt_ctx *ctx = NULL; | 317 __submit_merged_bio(io); 318alloc_new: 319 if (io->bio == NULL) { 320 io->bio = __bio_alloc(sbi, fio->new_blkaddr, 321 BIO_MAX_PAGES, is_read); 322 io->fio = *fio; 323 } 324 --- 671 unchanged lines hidden (view full) --- 996 return ret; 997} 998 999static struct bio *f2fs_grab_bio(struct inode *inode, block_t blkaddr, 1000 unsigned nr_pages) 1001{ 1002 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1003 struct fscrypt_ctx *ctx = NULL; |
964 struct block_device *bdev = sbi->sb->s_bdev; | |
965 struct bio *bio; 966 967 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) { 968 ctx = fscrypt_get_ctx(inode, GFP_NOFS); 969 if (IS_ERR(ctx)) 970 return ERR_CAST(ctx); 971 972 /* wait the page to be moved by cleaning */ 973 f2fs_wait_on_encrypted_page_writeback(sbi, blkaddr); 974 } 975 976 bio = bio_alloc(GFP_KERNEL, min_t(int, nr_pages, BIO_MAX_PAGES)); 977 if (!bio) { 978 if (ctx) 979 fscrypt_release_ctx(ctx); 980 return ERR_PTR(-ENOMEM); 981 } | 1004 struct bio *bio; 1005 1006 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) { 1007 ctx = fscrypt_get_ctx(inode, GFP_NOFS); 1008 if (IS_ERR(ctx)) 1009 return ERR_CAST(ctx); 1010 1011 /* wait the page to be moved by cleaning */ 1012 f2fs_wait_on_encrypted_page_writeback(sbi, blkaddr); 1013 } 1014 1015 bio = bio_alloc(GFP_KERNEL, min_t(int, nr_pages, BIO_MAX_PAGES)); 1016 if (!bio) { 1017 if (ctx) 1018 fscrypt_release_ctx(ctx); 1019 return ERR_PTR(-ENOMEM); 1020 } |
982 bio->bi_bdev = bdev; 983 bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blkaddr); | 1021 f2fs_target_device(sbi, blkaddr, bio); |
984 bio->bi_end_io = f2fs_read_end_io; 985 bio->bi_private = ctx; 986 987 return bio; 988} 989 990/* 991 * This function was originally taken from fs/mpage.c, and customized for f2fs. --- 78 unchanged lines hidden (view full) --- 1070 unlock_page(page); 1071 goto next_page; 1072 } 1073 1074 /* 1075 * This page will go to BIO. Do we need to send this 1076 * BIO off first? 1077 */ | 1022 bio->bi_end_io = f2fs_read_end_io; 1023 bio->bi_private = ctx; 1024 1025 return bio; 1026} 1027 1028/* 1029 * This function was originally taken from fs/mpage.c, and customized for f2fs. --- 78 unchanged lines hidden (view full) --- 1108 unlock_page(page); 1109 goto next_page; 1110 } 1111 1112 /* 1113 * This page will go to BIO. Do we need to send this 1114 * BIO off first? 1115 */ |
1078 if (bio && (last_block_in_bio != block_nr - 1)) { | 1116 if (bio && (last_block_in_bio != block_nr - 1 || 1117 !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) { |
1079submit_and_realloc: 1080 __submit_bio(F2FS_I_SB(inode), bio, DATA); 1081 bio = NULL; 1082 } 1083 if (bio == NULL) { 1084 bio = f2fs_grab_bio(inode, block_nr, nr_pages); 1085 if (IS_ERR(bio)) { 1086 bio = NULL; --- 642 unchanged lines hidden (view full) --- 1729 err = check_direct_IO(inode, iter, offset); 1730 if (err) 1731 return err; 1732 1733 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) 1734 return 0; 1735 if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) 1736 return 0; | 1118submit_and_realloc: 1119 __submit_bio(F2FS_I_SB(inode), bio, DATA); 1120 bio = NULL; 1121 } 1122 if (bio == NULL) { 1123 bio = f2fs_grab_bio(inode, block_nr, nr_pages); 1124 if (IS_ERR(bio)) { 1125 bio = NULL; --- 642 unchanged lines hidden (view full) --- 1768 err = check_direct_IO(inode, iter, offset); 1769 if (err) 1770 return err; 1771 1772 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) 1773 return 0; 1774 if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) 1775 return 0; |
1776 if (F2FS_I_SB(inode)->s_ndevs) 1777 return 0; |
|
1737 1738 trace_f2fs_direct_IO_enter(inode, offset, count, rw); 1739 1740 down_read(&F2FS_I(inode)->dio_rwsem[rw]); 1741 err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio); 1742 up_read(&F2FS_I(inode)->dio_rwsem[rw]); 1743 1744 if (rw == WRITE) { --- 196 unchanged lines hidden --- | 1778 1779 trace_f2fs_direct_IO_enter(inode, offset, count, rw); 1780 1781 down_read(&F2FS_I(inode)->dio_rwsem[rw]); 1782 err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio); 1783 up_read(&F2FS_I(inode)->dio_rwsem[rw]); 1784 1785 if (rw == WRITE) { --- 196 unchanged lines hidden --- |