data.c (736c0a74856d762b09a997d28e3ff6d8bdcf942c) | data.c (d5097be55c21c103d2227591708425aab2e9682d) |
---|---|
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 --- 769 unchanged lines hidden (view full) --- 778 } 779got_it: 780 if (new_i_size && i_size_read(inode) < 781 ((loff_t)(index + 1) << PAGE_SHIFT)) 782 f2fs_i_size_write(inode, ((loff_t)(index + 1) << PAGE_SHIFT)); 783 return page; 784} 785 | 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 --- 769 unchanged lines hidden (view full) --- 778 } 779got_it: 780 if (new_i_size && i_size_read(inode) < 781 ((loff_t)(index + 1) << PAGE_SHIFT)) 782 f2fs_i_size_write(inode, ((loff_t)(index + 1) << PAGE_SHIFT)); 783 return page; 784} 785 |
786static int __allocate_data_block(struct dnode_of_data *dn) | 786static int __allocate_data_block(struct dnode_of_data *dn, int seg_type) |
787{ 788 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); 789 struct f2fs_summary sum; 790 struct node_info ni; 791 pgoff_t fofs; 792 blkcnt_t count = 1; 793 int err; 794 --- 8 unchanged lines hidden (view full) --- 803 if (unlikely((err = inc_valid_block_count(sbi, dn->inode, &count)))) 804 return err; 805 806alloc: 807 get_node_info(sbi, dn->nid, &ni); 808 set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); 809 810 allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr, | 787{ 788 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); 789 struct f2fs_summary sum; 790 struct node_info ni; 791 pgoff_t fofs; 792 blkcnt_t count = 1; 793 int err; 794 --- 8 unchanged lines hidden (view full) --- 803 if (unlikely((err = inc_valid_block_count(sbi, dn->inode, &count)))) 804 return err; 805 806alloc: 807 get_node_info(sbi, dn->nid, &ni); 808 set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); 809 810 allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr, |
811 &sum, CURSEG_WARM_DATA, NULL, false); | 811 &sum, seg_type, NULL, false); |
812 set_data_blkaddr(dn); 813 814 /* update i_size */ 815 fofs = start_bidx_of_node(ofs_of_node(dn->node_page), dn->inode) + 816 dn->ofs_in_node; 817 if (i_size_read(dn->inode) < ((loff_t)(fofs + 1) << PAGE_SHIFT)) 818 f2fs_i_size_write(dn->inode, 819 ((loff_t)(fofs + 1) << PAGE_SHIFT)); --- 26 unchanged lines hidden (view full) --- 846 map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos); 847 map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from)); 848 if (map.m_len > map.m_lblk) 849 map.m_len -= map.m_lblk; 850 else 851 map.m_len = 0; 852 853 map.m_next_pgofs = NULL; | 812 set_data_blkaddr(dn); 813 814 /* update i_size */ 815 fofs = start_bidx_of_node(ofs_of_node(dn->node_page), dn->inode) + 816 dn->ofs_in_node; 817 if (i_size_read(dn->inode) < ((loff_t)(fofs + 1) << PAGE_SHIFT)) 818 f2fs_i_size_write(dn->inode, 819 ((loff_t)(fofs + 1) << PAGE_SHIFT)); --- 26 unchanged lines hidden (view full) --- 846 map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos); 847 map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from)); 848 if (map.m_len > map.m_lblk) 849 map.m_len -= map.m_lblk; 850 else 851 map.m_len = 0; 852 853 map.m_next_pgofs = NULL; |
854 map.m_seg_type = NO_CHECK_TYPE; |
|
854 | 855 |
855 if (iocb->ki_flags & IOCB_DIRECT) | 856 if (iocb->ki_flags & IOCB_DIRECT) { 857 map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint); |
856 return f2fs_map_blocks(inode, &map, 1, 857 __force_buffered_io(inode, WRITE) ? 858 F2FS_GET_BLOCK_PRE_AIO : 859 F2FS_GET_BLOCK_PRE_DIO); | 858 return f2fs_map_blocks(inode, &map, 1, 859 __force_buffered_io(inode, WRITE) ? 860 F2FS_GET_BLOCK_PRE_AIO : 861 F2FS_GET_BLOCK_PRE_DIO); |
862 } |
|
860 if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA(inode)) { 861 err = f2fs_convert_inline_inode(inode); 862 if (err) 863 return err; 864 } 865 if (!f2fs_has_inline_data(inode)) { 866 err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO); 867 if (map.m_len > 0 && err == -ENOSPC) { --- 93 unchanged lines hidden (view full) --- 961 goto sync_out; 962 } 963 if (flag == F2FS_GET_BLOCK_PRE_AIO) { 964 if (blkaddr == NULL_ADDR) { 965 prealloc++; 966 last_ofs_in_node = dn.ofs_in_node; 967 } 968 } else { | 863 if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA(inode)) { 864 err = f2fs_convert_inline_inode(inode); 865 if (err) 866 return err; 867 } 868 if (!f2fs_has_inline_data(inode)) { 869 err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO); 870 if (map.m_len > 0 && err == -ENOSPC) { --- 93 unchanged lines hidden (view full) --- 964 goto sync_out; 965 } 966 if (flag == F2FS_GET_BLOCK_PRE_AIO) { 967 if (blkaddr == NULL_ADDR) { 968 prealloc++; 969 last_ofs_in_node = dn.ofs_in_node; 970 } 971 } else { |
969 err = __allocate_data_block(&dn); | 972 err = __allocate_data_block(&dn, 973 map->m_seg_type); |
970 if (!err) 971 set_inode_flag(inode, FI_APPEND_WRITE); 972 } 973 if (err) 974 goto sync_out; 975 map->m_flags |= F2FS_MAP_NEW; 976 blkaddr = dn.data_blkaddr; 977 } else { --- 76 unchanged lines hidden (view full) --- 1054 } 1055out: 1056 trace_f2fs_map_blocks(inode, map, err); 1057 return err; 1058} 1059 1060static int __get_data_block(struct inode *inode, sector_t iblock, 1061 struct buffer_head *bh, int create, int flag, | 974 if (!err) 975 set_inode_flag(inode, FI_APPEND_WRITE); 976 } 977 if (err) 978 goto sync_out; 979 map->m_flags |= F2FS_MAP_NEW; 980 blkaddr = dn.data_blkaddr; 981 } else { --- 76 unchanged lines hidden (view full) --- 1058 } 1059out: 1060 trace_f2fs_map_blocks(inode, map, err); 1061 return err; 1062} 1063 1064static int __get_data_block(struct inode *inode, sector_t iblock, 1065 struct buffer_head *bh, int create, int flag, |
1062 pgoff_t *next_pgofs) | 1066 pgoff_t *next_pgofs, int seg_type) |
1063{ 1064 struct f2fs_map_blocks map; 1065 int err; 1066 1067 map.m_lblk = iblock; 1068 map.m_len = bh->b_size >> inode->i_blkbits; 1069 map.m_next_pgofs = next_pgofs; | 1067{ 1068 struct f2fs_map_blocks map; 1069 int err; 1070 1071 map.m_lblk = iblock; 1072 map.m_len = bh->b_size >> inode->i_blkbits; 1073 map.m_next_pgofs = next_pgofs; |
1074 map.m_seg_type = seg_type; |
|
1070 1071 err = f2fs_map_blocks(inode, &map, create, flag); 1072 if (!err) { 1073 map_bh(bh, inode->i_sb, map.m_pblk); 1074 bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags; 1075 bh->b_size = (u64)map.m_len << inode->i_blkbits; 1076 } 1077 return err; 1078} 1079 1080static int get_data_block(struct inode *inode, sector_t iblock, 1081 struct buffer_head *bh_result, int create, int flag, 1082 pgoff_t *next_pgofs) 1083{ 1084 return __get_data_block(inode, iblock, bh_result, create, | 1075 1076 err = f2fs_map_blocks(inode, &map, create, flag); 1077 if (!err) { 1078 map_bh(bh, inode->i_sb, map.m_pblk); 1079 bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags; 1080 bh->b_size = (u64)map.m_len << inode->i_blkbits; 1081 } 1082 return err; 1083} 1084 1085static int get_data_block(struct inode *inode, sector_t iblock, 1086 struct buffer_head *bh_result, int create, int flag, 1087 pgoff_t *next_pgofs) 1088{ 1089 return __get_data_block(inode, iblock, bh_result, create, |
1085 flag, next_pgofs); | 1090 flag, next_pgofs, 1091 NO_CHECK_TYPE); |
1086} 1087 1088static int get_data_block_dio(struct inode *inode, sector_t iblock, 1089 struct buffer_head *bh_result, int create) 1090{ 1091 return __get_data_block(inode, iblock, bh_result, create, | 1092} 1093 1094static int get_data_block_dio(struct inode *inode, sector_t iblock, 1095 struct buffer_head *bh_result, int create) 1096{ 1097 return __get_data_block(inode, iblock, bh_result, create, |
1092 F2FS_GET_BLOCK_DEFAULT, NULL); | 1098 F2FS_GET_BLOCK_DEFAULT, NULL, 1099 rw_hint_to_seg_type( 1100 inode->i_write_hint)); |
1093} 1094 1095static int get_data_block_bmap(struct inode *inode, sector_t iblock, 1096 struct buffer_head *bh_result, int create) 1097{ 1098 /* Block number less than F2FS MAX BLOCKS */ 1099 if (unlikely(iblock >= F2FS_I_SB(inode)->max_file_blocks)) 1100 return -EFBIG; 1101 1102 return __get_data_block(inode, iblock, bh_result, create, | 1101} 1102 1103static int get_data_block_bmap(struct inode *inode, sector_t iblock, 1104 struct buffer_head *bh_result, int create) 1105{ 1106 /* Block number less than F2FS MAX BLOCKS */ 1107 if (unlikely(iblock >= F2FS_I_SB(inode)->max_file_blocks)) 1108 return -EFBIG; 1109 1110 return __get_data_block(inode, iblock, bh_result, create, |
1103 F2FS_GET_BLOCK_BMAP, NULL); | 1111 F2FS_GET_BLOCK_BMAP, NULL, 1112 NO_CHECK_TYPE); |
1104} 1105 1106static inline sector_t logical_to_blk(struct inode *inode, loff_t offset) 1107{ 1108 return (offset >> inode->i_blkbits); 1109} 1110 1111static inline loff_t blk_to_logical(struct inode *inode, sector_t blk) --- 102 unchanged lines hidden (view full) --- 1214 sector_t block_nr; 1215 struct f2fs_map_blocks map; 1216 1217 map.m_pblk = 0; 1218 map.m_lblk = 0; 1219 map.m_len = 0; 1220 map.m_flags = 0; 1221 map.m_next_pgofs = NULL; | 1113} 1114 1115static inline sector_t logical_to_blk(struct inode *inode, loff_t offset) 1116{ 1117 return (offset >> inode->i_blkbits); 1118} 1119 1120static inline loff_t blk_to_logical(struct inode *inode, sector_t blk) --- 102 unchanged lines hidden (view full) --- 1223 sector_t block_nr; 1224 struct f2fs_map_blocks map; 1225 1226 map.m_pblk = 0; 1227 map.m_lblk = 0; 1228 map.m_len = 0; 1229 map.m_flags = 0; 1230 map.m_next_pgofs = NULL; |
1231 map.m_seg_type = NO_CHECK_TYPE; |
|
1222 1223 for (; nr_pages; nr_pages--) { 1224 if (pages) { 1225 page = list_last_entry(pages, struct page, lru); 1226 1227 prefetchw(&page->flags); 1228 list_del(&page->lru); 1229 if (add_to_page_cache_lru(page, mapping, --- 1080 unchanged lines hidden --- | 1232 1233 for (; nr_pages; nr_pages--) { 1234 if (pages) { 1235 page = list_last_entry(pages, struct page, lru); 1236 1237 prefetchw(&page->flags); 1238 list_del(&page->lru); 1239 if (add_to_page_cache_lru(page, mapping, --- 1080 unchanged lines hidden --- |