data.c (1ad71a27124caf0b68ddd3c92be01aa2b2a72b2a) data.c (c4020b2da4c9e84d63e30ce5a85dc287507f0e60)
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

--- 851 unchanged lines hidden (view full) ---

860 map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos);
861 map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from));
862 if (map.m_len > map.m_lblk)
863 map.m_len -= map.m_lblk;
864 else
865 map.m_len = 0;
866
867 map.m_next_pgofs = NULL;
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

--- 851 unchanged lines hidden (view full) ---

860 map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos);
861 map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from));
862 if (map.m_len > map.m_lblk)
863 map.m_len -= map.m_lblk;
864 else
865 map.m_len = 0;
866
867 map.m_next_pgofs = NULL;
868 map.m_next_extent = NULL;
868 map.m_seg_type = NO_CHECK_TYPE;
869
870 if (direct_io) {
871 map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint);
872 flag = __force_buffered_io(inode, WRITE) ?
873 F2FS_GET_BLOCK_PRE_AIO :
874 F2FS_GET_BLOCK_PRE_DIO;
875 goto map_blocks;

--- 50 unchanged lines hidden (view full) ---

926 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
927 int mode = create ? ALLOC_NODE : LOOKUP_NODE;
928 pgoff_t pgofs, end_offset, end;
929 int err = 0, ofs = 1;
930 unsigned int ofs_in_node, last_ofs_in_node;
931 blkcnt_t prealloc;
932 struct extent_info ei = {0,0,0};
933 block_t blkaddr;
869 map.m_seg_type = NO_CHECK_TYPE;
870
871 if (direct_io) {
872 map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint);
873 flag = __force_buffered_io(inode, WRITE) ?
874 F2FS_GET_BLOCK_PRE_AIO :
875 F2FS_GET_BLOCK_PRE_DIO;
876 goto map_blocks;

--- 50 unchanged lines hidden (view full) ---

927 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
928 int mode = create ? ALLOC_NODE : LOOKUP_NODE;
929 pgoff_t pgofs, end_offset, end;
930 int err = 0, ofs = 1;
931 unsigned int ofs_in_node, last_ofs_in_node;
932 blkcnt_t prealloc;
933 struct extent_info ei = {0,0,0};
934 block_t blkaddr;
935 unsigned int start_pgofs;
934
935 if (!maxblocks)
936 return 0;
937
938 map->m_len = 0;
939 map->m_flags = 0;
940
941 /* it only supports block size == page size */
942 pgofs = (pgoff_t)map->m_lblk;
943 end = pgofs + maxblocks;
944
945 if (!create && f2fs_lookup_extent_cache(inode, pgofs, &ei)) {
946 map->m_pblk = ei.blk + pgofs - ei.fofs;
947 map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs);
948 map->m_flags = F2FS_MAP_MAPPED;
936
937 if (!maxblocks)
938 return 0;
939
940 map->m_len = 0;
941 map->m_flags = 0;
942
943 /* it only supports block size == page size */
944 pgofs = (pgoff_t)map->m_lblk;
945 end = pgofs + maxblocks;
946
947 if (!create && f2fs_lookup_extent_cache(inode, pgofs, &ei)) {
948 map->m_pblk = ei.blk + pgofs - ei.fofs;
949 map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs);
950 map->m_flags = F2FS_MAP_MAPPED;
951 if (map->m_next_extent)
952 *map->m_next_extent = pgofs + map->m_len;
949 goto out;
950 }
951
952next_dnode:
953 if (create)
954 __do_map_lock(sbi, flag, true);
955
956 /* When reading holes, we need its node page */
957 set_new_dnode(&dn, inode, NULL, NULL, 0);
958 err = get_dnode_of_data(&dn, pgofs, mode);
959 if (err) {
960 if (flag == F2FS_GET_BLOCK_BMAP)
961 map->m_pblk = 0;
962 if (err == -ENOENT) {
963 err = 0;
964 if (map->m_next_pgofs)
965 *map->m_next_pgofs =
966 get_next_page_offset(&dn, pgofs);
953 goto out;
954 }
955
956next_dnode:
957 if (create)
958 __do_map_lock(sbi, flag, true);
959
960 /* When reading holes, we need its node page */
961 set_new_dnode(&dn, inode, NULL, NULL, 0);
962 err = get_dnode_of_data(&dn, pgofs, mode);
963 if (err) {
964 if (flag == F2FS_GET_BLOCK_BMAP)
965 map->m_pblk = 0;
966 if (err == -ENOENT) {
967 err = 0;
968 if (map->m_next_pgofs)
969 *map->m_next_pgofs =
970 get_next_page_offset(&dn, pgofs);
971 if (map->m_next_extent)
972 *map->m_next_extent =
973 get_next_page_offset(&dn, pgofs);
967 }
968 goto unlock_out;
969 }
970
974 }
975 goto unlock_out;
976 }
977
978 start_pgofs = pgofs;
971 prealloc = 0;
972 last_ofs_in_node = ofs_in_node = dn.ofs_in_node;
973 end_offset = ADDRS_PER_PAGE(dn.node_page, inode);
974
975next_block:
976 blkaddr = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node);
977
978 if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) {

--- 17 unchanged lines hidden (view full) ---

996 goto sync_out;
997 map->m_flags |= F2FS_MAP_NEW;
998 blkaddr = dn.data_blkaddr;
999 } else {
1000 if (flag == F2FS_GET_BLOCK_BMAP) {
1001 map->m_pblk = 0;
1002 goto sync_out;
1003 }
979 prealloc = 0;
980 last_ofs_in_node = ofs_in_node = dn.ofs_in_node;
981 end_offset = ADDRS_PER_PAGE(dn.node_page, inode);
982
983next_block:
984 blkaddr = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node);
985
986 if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) {

--- 17 unchanged lines hidden (view full) ---

1004 goto sync_out;
1005 map->m_flags |= F2FS_MAP_NEW;
1006 blkaddr = dn.data_blkaddr;
1007 } else {
1008 if (flag == F2FS_GET_BLOCK_BMAP) {
1009 map->m_pblk = 0;
1010 goto sync_out;
1011 }
1012 if (flag == F2FS_GET_BLOCK_PRECACHE)
1013 goto sync_out;
1004 if (flag == F2FS_GET_BLOCK_FIEMAP &&
1005 blkaddr == NULL_ADDR) {
1006 if (map->m_next_pgofs)
1007 *map->m_next_pgofs = pgofs + 1;
1008 goto sync_out;
1009 }
1010 if (flag != F2FS_GET_BLOCK_FIEMAP)
1011 goto sync_out;

--- 42 unchanged lines hidden (view full) ---

1054 dn.ofs_in_node = end_offset;
1055 }
1056
1057 if (pgofs >= end)
1058 goto sync_out;
1059 else if (dn.ofs_in_node < end_offset)
1060 goto next_block;
1061
1014 if (flag == F2FS_GET_BLOCK_FIEMAP &&
1015 blkaddr == NULL_ADDR) {
1016 if (map->m_next_pgofs)
1017 *map->m_next_pgofs = pgofs + 1;
1018 goto sync_out;
1019 }
1020 if (flag != F2FS_GET_BLOCK_FIEMAP)
1021 goto sync_out;

--- 42 unchanged lines hidden (view full) ---

1064 dn.ofs_in_node = end_offset;
1065 }
1066
1067 if (pgofs >= end)
1068 goto sync_out;
1069 else if (dn.ofs_in_node < end_offset)
1070 goto next_block;
1071
1072 if (flag == F2FS_GET_BLOCK_PRECACHE) {
1073 if (map->m_flags & F2FS_MAP_MAPPED) {
1074 unsigned int ofs = start_pgofs - map->m_lblk;
1075
1076 f2fs_update_extent_cache_range(&dn,
1077 start_pgofs, map->m_pblk + ofs,
1078 map->m_len - ofs);
1079 }
1080 }
1081
1062 f2fs_put_dnode(&dn);
1063
1064 if (create) {
1065 __do_map_lock(sbi, flag, false);
1066 f2fs_balance_fs(sbi, dn.node_changed);
1067 }
1068 goto next_dnode;
1069
1070sync_out:
1082 f2fs_put_dnode(&dn);
1083
1084 if (create) {
1085 __do_map_lock(sbi, flag, false);
1086 f2fs_balance_fs(sbi, dn.node_changed);
1087 }
1088 goto next_dnode;
1089
1090sync_out:
1091 if (flag == F2FS_GET_BLOCK_PRECACHE) {
1092 if (map->m_flags & F2FS_MAP_MAPPED) {
1093 unsigned int ofs = start_pgofs - map->m_lblk;
1094
1095 f2fs_update_extent_cache_range(&dn,
1096 start_pgofs, map->m_pblk + ofs,
1097 map->m_len - ofs);
1098 }
1099 if (map->m_next_extent)
1100 *map->m_next_extent = pgofs + 1;
1101 }
1071 f2fs_put_dnode(&dn);
1072unlock_out:
1073 if (create) {
1074 __do_map_lock(sbi, flag, false);
1075 f2fs_balance_fs(sbi, dn.node_changed);
1076 }
1077out:
1078 trace_f2fs_map_blocks(inode, map, err);

--- 5 unchanged lines hidden (view full) ---

1084 pgoff_t *next_pgofs, int seg_type)
1085{
1086 struct f2fs_map_blocks map;
1087 int err;
1088
1089 map.m_lblk = iblock;
1090 map.m_len = bh->b_size >> inode->i_blkbits;
1091 map.m_next_pgofs = next_pgofs;
1102 f2fs_put_dnode(&dn);
1103unlock_out:
1104 if (create) {
1105 __do_map_lock(sbi, flag, false);
1106 f2fs_balance_fs(sbi, dn.node_changed);
1107 }
1108out:
1109 trace_f2fs_map_blocks(inode, map, err);

--- 5 unchanged lines hidden (view full) ---

1115 pgoff_t *next_pgofs, int seg_type)
1116{
1117 struct f2fs_map_blocks map;
1118 int err;
1119
1120 map.m_lblk = iblock;
1121 map.m_len = bh->b_size >> inode->i_blkbits;
1122 map.m_next_pgofs = next_pgofs;
1123 map.m_next_extent = NULL;
1092 map.m_seg_type = seg_type;
1093
1094 err = f2fs_map_blocks(inode, &map, create, flag);
1095 if (!err) {
1096 map_bh(bh, inode->i_sb, map.m_pblk);
1097 bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
1098 bh->b_size = (u64)map.m_len << inode->i_blkbits;
1099 }

--- 107 unchanged lines hidden (view full) ---

1207{
1208 struct buffer_head map_bh;
1209 sector_t start_blk, last_blk;
1210 pgoff_t next_pgofs;
1211 u64 logical = 0, phys = 0, size = 0;
1212 u32 flags = 0;
1213 int ret = 0;
1214
1124 map.m_seg_type = seg_type;
1125
1126 err = f2fs_map_blocks(inode, &map, create, flag);
1127 if (!err) {
1128 map_bh(bh, inode->i_sb, map.m_pblk);
1129 bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
1130 bh->b_size = (u64)map.m_len << inode->i_blkbits;
1131 }

--- 107 unchanged lines hidden (view full) ---

1239{
1240 struct buffer_head map_bh;
1241 sector_t start_blk, last_blk;
1242 pgoff_t next_pgofs;
1243 u64 logical = 0, phys = 0, size = 0;
1244 u32 flags = 0;
1245 int ret = 0;
1246
1247 if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
1248 ret = f2fs_precache_extents(inode);
1249 if (ret)
1250 return ret;
1251 }
1252
1215 ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR);
1216 if (ret)
1217 return ret;
1218
1219 inode_lock(inode);
1220
1221 if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
1222 ret = f2fs_xattr_fiemap(inode, fieinfo);

--- 85 unchanged lines hidden (view full) ---

1308 sector_t block_nr;
1309 struct f2fs_map_blocks map;
1310
1311 map.m_pblk = 0;
1312 map.m_lblk = 0;
1313 map.m_len = 0;
1314 map.m_flags = 0;
1315 map.m_next_pgofs = NULL;
1253 ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR);
1254 if (ret)
1255 return ret;
1256
1257 inode_lock(inode);
1258
1259 if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
1260 ret = f2fs_xattr_fiemap(inode, fieinfo);

--- 85 unchanged lines hidden (view full) ---

1346 sector_t block_nr;
1347 struct f2fs_map_blocks map;
1348
1349 map.m_pblk = 0;
1350 map.m_lblk = 0;
1351 map.m_len = 0;
1352 map.m_flags = 0;
1353 map.m_next_pgofs = NULL;
1354 map.m_next_extent = NULL;
1316 map.m_seg_type = NO_CHECK_TYPE;
1317
1318 for (; nr_pages; nr_pages--) {
1319 if (pages) {
1320 page = list_last_entry(pages, struct page, lru);
1321
1322 prefetchw(&page->flags);
1323 list_del(&page->lru);

--- 1084 unchanged lines hidden ---
1355 map.m_seg_type = NO_CHECK_TYPE;
1356
1357 for (; nr_pages; nr_pages--) {
1358 if (pages) {
1359 page = list_last_entry(pages, struct page, lru);
1360
1361 prefetchw(&page->flags);
1362 list_del(&page->lru);

--- 1084 unchanged lines hidden ---