diff options
Diffstat (limited to 'fs/f2fs/data.c')
-rw-r--r-- | fs/f2fs/data.c | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 76de83e25a89..8e58c4cc2cb9 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c | |||
@@ -85,7 +85,7 @@ static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, | |||
85 | bio = bio_alloc(GFP_NOIO, npages); | 85 | bio = bio_alloc(GFP_NOIO, npages); |
86 | 86 | ||
87 | bio->bi_bdev = sbi->sb->s_bdev; | 87 | bio->bi_bdev = sbi->sb->s_bdev; |
88 | bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(sbi, blk_addr); | 88 | bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blk_addr); |
89 | bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io; | 89 | bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io; |
90 | bio->bi_private = sbi; | 90 | bio->bi_private = sbi; |
91 | 91 | ||
@@ -193,7 +193,7 @@ void f2fs_submit_page_mbio(struct f2fs_sb_info *sbi, struct page *page, | |||
193 | __submit_merged_bio(io); | 193 | __submit_merged_bio(io); |
194 | alloc_new: | 194 | alloc_new: |
195 | if (io->bio == NULL) { | 195 | if (io->bio == NULL) { |
196 | int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi)); | 196 | int bio_blocks = MAX_BIO_BLOCKS(sbi); |
197 | 197 | ||
198 | io->bio = __bio_alloc(sbi, blk_addr, bio_blocks, is_read); | 198 | io->bio = __bio_alloc(sbi, blk_addr, bio_blocks, is_read); |
199 | io->fio = *fio; | 199 | io->fio = *fio; |
@@ -236,7 +236,7 @@ static void __set_data_blkaddr(struct dnode_of_data *dn, block_t new_addr) | |||
236 | 236 | ||
237 | int reserve_new_block(struct dnode_of_data *dn) | 237 | int reserve_new_block(struct dnode_of_data *dn) |
238 | { | 238 | { |
239 | struct f2fs_sb_info *sbi = F2FS_SB(dn->inode->i_sb); | 239 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); |
240 | 240 | ||
241 | if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC))) | 241 | if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC))) |
242 | return -EPERM; | 242 | return -EPERM; |
@@ -258,7 +258,7 @@ int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index) | |||
258 | int err; | 258 | int err; |
259 | 259 | ||
260 | /* if inode_page exists, index should be zero */ | 260 | /* if inode_page exists, index should be zero */ |
261 | f2fs_bug_on(!need_put && index); | 261 | f2fs_bug_on(F2FS_I_SB(dn->inode), !need_put && index); |
262 | 262 | ||
263 | err = get_dnode_of_data(dn, index, ALLOC_NODE); | 263 | err = get_dnode_of_data(dn, index, ALLOC_NODE); |
264 | if (err) | 264 | if (err) |
@@ -321,7 +321,7 @@ void update_extent_cache(block_t blk_addr, struct dnode_of_data *dn) | |||
321 | block_t start_blkaddr, end_blkaddr; | 321 | block_t start_blkaddr, end_blkaddr; |
322 | int need_update = true; | 322 | int need_update = true; |
323 | 323 | ||
324 | f2fs_bug_on(blk_addr == NEW_ADDR); | 324 | f2fs_bug_on(F2FS_I_SB(dn->inode), blk_addr == NEW_ADDR); |
325 | fofs = start_bidx_of_node(ofs_of_node(dn->node_page), fi) + | 325 | fofs = start_bidx_of_node(ofs_of_node(dn->node_page), fi) + |
326 | dn->ofs_in_node; | 326 | dn->ofs_in_node; |
327 | 327 | ||
@@ -396,7 +396,6 @@ end_update: | |||
396 | 396 | ||
397 | struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync) | 397 | struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync) |
398 | { | 398 | { |
399 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | ||
400 | struct address_space *mapping = inode->i_mapping; | 399 | struct address_space *mapping = inode->i_mapping; |
401 | struct dnode_of_data dn; | 400 | struct dnode_of_data dn; |
402 | struct page *page; | 401 | struct page *page; |
@@ -429,7 +428,7 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync) | |||
429 | return page; | 428 | return page; |
430 | } | 429 | } |
431 | 430 | ||
432 | err = f2fs_submit_page_bio(sbi, page, dn.data_blkaddr, | 431 | err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, dn.data_blkaddr, |
433 | sync ? READ_SYNC : READA); | 432 | sync ? READ_SYNC : READA); |
434 | if (err) | 433 | if (err) |
435 | return ERR_PTR(err); | 434 | return ERR_PTR(err); |
@@ -451,7 +450,6 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync) | |||
451 | */ | 450 | */ |
452 | struct page *get_lock_data_page(struct inode *inode, pgoff_t index) | 451 | struct page *get_lock_data_page(struct inode *inode, pgoff_t index) |
453 | { | 452 | { |
454 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | ||
455 | struct address_space *mapping = inode->i_mapping; | 453 | struct address_space *mapping = inode->i_mapping; |
456 | struct dnode_of_data dn; | 454 | struct dnode_of_data dn; |
457 | struct page *page; | 455 | struct page *page; |
@@ -490,7 +488,8 @@ repeat: | |||
490 | return page; | 488 | return page; |
491 | } | 489 | } |
492 | 490 | ||
493 | err = f2fs_submit_page_bio(sbi, page, dn.data_blkaddr, READ_SYNC); | 491 | err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, |
492 | dn.data_blkaddr, READ_SYNC); | ||
494 | if (err) | 493 | if (err) |
495 | return ERR_PTR(err); | 494 | return ERR_PTR(err); |
496 | 495 | ||
@@ -517,7 +516,6 @@ repeat: | |||
517 | struct page *get_new_data_page(struct inode *inode, | 516 | struct page *get_new_data_page(struct inode *inode, |
518 | struct page *ipage, pgoff_t index, bool new_i_size) | 517 | struct page *ipage, pgoff_t index, bool new_i_size) |
519 | { | 518 | { |
520 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | ||
521 | struct address_space *mapping = inode->i_mapping; | 519 | struct address_space *mapping = inode->i_mapping; |
522 | struct page *page; | 520 | struct page *page; |
523 | struct dnode_of_data dn; | 521 | struct dnode_of_data dn; |
@@ -541,8 +539,8 @@ repeat: | |||
541 | zero_user_segment(page, 0, PAGE_CACHE_SIZE); | 539 | zero_user_segment(page, 0, PAGE_CACHE_SIZE); |
542 | SetPageUptodate(page); | 540 | SetPageUptodate(page); |
543 | } else { | 541 | } else { |
544 | err = f2fs_submit_page_bio(sbi, page, dn.data_blkaddr, | 542 | err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, |
545 | READ_SYNC); | 543 | dn.data_blkaddr, READ_SYNC); |
546 | if (err) | 544 | if (err) |
547 | goto put_err; | 545 | goto put_err; |
548 | 546 | ||
@@ -573,10 +571,12 @@ put_err: | |||
573 | 571 | ||
574 | static int __allocate_data_block(struct dnode_of_data *dn) | 572 | static int __allocate_data_block(struct dnode_of_data *dn) |
575 | { | 573 | { |
576 | struct f2fs_sb_info *sbi = F2FS_SB(dn->inode->i_sb); | 574 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); |
575 | struct f2fs_inode_info *fi = F2FS_I(dn->inode); | ||
577 | struct f2fs_summary sum; | 576 | struct f2fs_summary sum; |
578 | block_t new_blkaddr; | 577 | block_t new_blkaddr; |
579 | struct node_info ni; | 578 | struct node_info ni; |
579 | pgoff_t fofs; | ||
580 | int type; | 580 | int type; |
581 | 581 | ||
582 | if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC))) | 582 | if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC))) |
@@ -599,6 +599,12 @@ static int __allocate_data_block(struct dnode_of_data *dn) | |||
599 | update_extent_cache(new_blkaddr, dn); | 599 | update_extent_cache(new_blkaddr, dn); |
600 | clear_inode_flag(F2FS_I(dn->inode), FI_NO_EXTENT); | 600 | clear_inode_flag(F2FS_I(dn->inode), FI_NO_EXTENT); |
601 | 601 | ||
602 | /* update i_size */ | ||
603 | fofs = start_bidx_of_node(ofs_of_node(dn->node_page), fi) + | ||
604 | dn->ofs_in_node; | ||
605 | if (i_size_read(dn->inode) < ((fofs + 1) << PAGE_CACHE_SHIFT)) | ||
606 | i_size_write(dn->inode, ((fofs + 1) << PAGE_CACHE_SHIFT)); | ||
607 | |||
602 | dn->data_blkaddr = new_blkaddr; | 608 | dn->data_blkaddr = new_blkaddr; |
603 | return 0; | 609 | return 0; |
604 | } | 610 | } |
@@ -614,7 +620,6 @@ static int __allocate_data_block(struct dnode_of_data *dn) | |||
614 | static int __get_data_block(struct inode *inode, sector_t iblock, | 620 | static int __get_data_block(struct inode *inode, sector_t iblock, |
615 | struct buffer_head *bh_result, int create, bool fiemap) | 621 | struct buffer_head *bh_result, int create, bool fiemap) |
616 | { | 622 | { |
617 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | ||
618 | unsigned int blkbits = inode->i_sb->s_blocksize_bits; | 623 | unsigned int blkbits = inode->i_sb->s_blocksize_bits; |
619 | unsigned maxblocks = bh_result->b_size >> blkbits; | 624 | unsigned maxblocks = bh_result->b_size >> blkbits; |
620 | struct dnode_of_data dn; | 625 | struct dnode_of_data dn; |
@@ -630,8 +635,8 @@ static int __get_data_block(struct inode *inode, sector_t iblock, | |||
630 | goto out; | 635 | goto out; |
631 | 636 | ||
632 | if (create) { | 637 | if (create) { |
633 | f2fs_balance_fs(sbi); | 638 | f2fs_balance_fs(F2FS_I_SB(inode)); |
634 | f2fs_lock_op(sbi); | 639 | f2fs_lock_op(F2FS_I_SB(inode)); |
635 | } | 640 | } |
636 | 641 | ||
637 | /* When reading holes, we need its node page */ | 642 | /* When reading holes, we need its node page */ |
@@ -707,7 +712,7 @@ put_out: | |||
707 | f2fs_put_dnode(&dn); | 712 | f2fs_put_dnode(&dn); |
708 | unlock_out: | 713 | unlock_out: |
709 | if (create) | 714 | if (create) |
710 | f2fs_unlock_op(sbi); | 715 | f2fs_unlock_op(F2FS_I_SB(inode)); |
711 | out: | 716 | out: |
712 | trace_f2fs_get_data_block(inode, iblock, bh_result, err); | 717 | trace_f2fs_get_data_block(inode, iblock, bh_result, err); |
713 | return err; | 718 | return err; |
@@ -804,7 +809,7 @@ static int f2fs_write_data_page(struct page *page, | |||
804 | struct writeback_control *wbc) | 809 | struct writeback_control *wbc) |
805 | { | 810 | { |
806 | struct inode *inode = page->mapping->host; | 811 | struct inode *inode = page->mapping->host; |
807 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | 812 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
808 | loff_t i_size = i_size_read(inode); | 813 | loff_t i_size = i_size_read(inode); |
809 | const pgoff_t end_index = ((unsigned long long) i_size) | 814 | const pgoff_t end_index = ((unsigned long long) i_size) |
810 | >> PAGE_CACHE_SHIFT; | 815 | >> PAGE_CACHE_SHIFT; |
@@ -846,7 +851,7 @@ write: | |||
846 | if (unlikely(f2fs_cp_error(sbi))) { | 851 | if (unlikely(f2fs_cp_error(sbi))) { |
847 | SetPageError(page); | 852 | SetPageError(page); |
848 | unlock_page(page); | 853 | unlock_page(page); |
849 | return 0; | 854 | goto out; |
850 | } | 855 | } |
851 | 856 | ||
852 | if (!wbc->for_reclaim) | 857 | if (!wbc->for_reclaim) |
@@ -866,7 +871,7 @@ done: | |||
866 | 871 | ||
867 | clear_cold_data(page); | 872 | clear_cold_data(page); |
868 | out: | 873 | out: |
869 | inode_dec_dirty_dents(inode); | 874 | inode_dec_dirty_pages(inode); |
870 | unlock_page(page); | 875 | unlock_page(page); |
871 | if (need_balance_fs) | 876 | if (need_balance_fs) |
872 | f2fs_balance_fs(sbi); | 877 | f2fs_balance_fs(sbi); |
@@ -892,7 +897,7 @@ static int f2fs_write_data_pages(struct address_space *mapping, | |||
892 | struct writeback_control *wbc) | 897 | struct writeback_control *wbc) |
893 | { | 898 | { |
894 | struct inode *inode = mapping->host; | 899 | struct inode *inode = mapping->host; |
895 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | 900 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
896 | bool locked = false; | 901 | bool locked = false; |
897 | int ret; | 902 | int ret; |
898 | long diff; | 903 | long diff; |
@@ -904,7 +909,7 @@ static int f2fs_write_data_pages(struct address_space *mapping, | |||
904 | return 0; | 909 | return 0; |
905 | 910 | ||
906 | if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE && | 911 | if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE && |
907 | get_dirty_dents(inode) < nr_pages_to_skip(sbi, DATA) && | 912 | get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) && |
908 | available_free_memory(sbi, DIRTY_DENTS)) | 913 | available_free_memory(sbi, DIRTY_DENTS)) |
909 | goto skip_write; | 914 | goto skip_write; |
910 | 915 | ||
@@ -926,7 +931,7 @@ static int f2fs_write_data_pages(struct address_space *mapping, | |||
926 | return ret; | 931 | return ret; |
927 | 932 | ||
928 | skip_write: | 933 | skip_write: |
929 | wbc->pages_skipped += get_dirty_dents(inode); | 934 | wbc->pages_skipped += get_dirty_pages(inode); |
930 | return 0; | 935 | return 0; |
931 | } | 936 | } |
932 | 937 | ||
@@ -945,7 +950,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, | |||
945 | struct page **pagep, void **fsdata) | 950 | struct page **pagep, void **fsdata) |
946 | { | 951 | { |
947 | struct inode *inode = mapping->host; | 952 | struct inode *inode = mapping->host; |
948 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | 953 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
949 | struct page *page; | 954 | struct page *page; |
950 | pgoff_t index = ((unsigned long long) pos) >> PAGE_CACHE_SHIFT; | 955 | pgoff_t index = ((unsigned long long) pos) >> PAGE_CACHE_SHIFT; |
951 | struct dnode_of_data dn; | 956 | struct dnode_of_data dn; |
@@ -1047,7 +1052,10 @@ static int f2fs_write_end(struct file *file, | |||
1047 | 1052 | ||
1048 | trace_f2fs_write_end(inode, pos, len, copied); | 1053 | trace_f2fs_write_end(inode, pos, len, copied); |
1049 | 1054 | ||
1050 | set_page_dirty(page); | 1055 | if (f2fs_is_atomic_file(inode) || f2fs_is_volatile_file(inode)) |
1056 | register_inmem_page(inode, page); | ||
1057 | else | ||
1058 | set_page_dirty(page); | ||
1051 | 1059 | ||
1052 | if (pos + copied > i_size_read(inode)) { | 1060 | if (pos + copied > i_size_read(inode)) { |
1053 | i_size_write(inode, pos + copied); | 1061 | i_size_write(inode, pos + copied); |
@@ -1092,9 +1100,6 @@ static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb, | |||
1092 | if (check_direct_IO(inode, rw, iter, offset)) | 1100 | if (check_direct_IO(inode, rw, iter, offset)) |
1093 | return 0; | 1101 | return 0; |
1094 | 1102 | ||
1095 | /* clear fsync mark to recover these blocks */ | ||
1096 | fsync_mark_clear(F2FS_SB(inode->i_sb), inode->i_ino); | ||
1097 | |||
1098 | trace_f2fs_direct_IO_enter(inode, offset, count, rw); | 1103 | trace_f2fs_direct_IO_enter(inode, offset, count, rw); |
1099 | 1104 | ||
1100 | err = blockdev_direct_IO(rw, iocb, inode, iter, offset, get_data_block); | 1105 | err = blockdev_direct_IO(rw, iocb, inode, iter, offset, get_data_block); |
@@ -1110,8 +1115,12 @@ static void f2fs_invalidate_data_page(struct page *page, unsigned int offset, | |||
1110 | unsigned int length) | 1115 | unsigned int length) |
1111 | { | 1116 | { |
1112 | struct inode *inode = page->mapping->host; | 1117 | struct inode *inode = page->mapping->host; |
1118 | |||
1119 | if (offset % PAGE_CACHE_SIZE || length != PAGE_CACHE_SIZE) | ||
1120 | return; | ||
1121 | |||
1113 | if (PageDirty(page)) | 1122 | if (PageDirty(page)) |
1114 | inode_dec_dirty_dents(inode); | 1123 | inode_dec_dirty_pages(inode); |
1115 | ClearPagePrivate(page); | 1124 | ClearPagePrivate(page); |
1116 | } | 1125 | } |
1117 | 1126 | ||
@@ -1133,7 +1142,7 @@ static int f2fs_set_data_page_dirty(struct page *page) | |||
1133 | 1142 | ||
1134 | if (!PageDirty(page)) { | 1143 | if (!PageDirty(page)) { |
1135 | __set_page_dirty_nobuffers(page); | 1144 | __set_page_dirty_nobuffers(page); |
1136 | set_dirty_dir_page(inode, page); | 1145 | update_dirty_page(inode, page); |
1137 | return 1; | 1146 | return 1; |
1138 | } | 1147 | } |
1139 | return 0; | 1148 | return 0; |