Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'f2fs-for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

Pull f2fs updates from Jaegeuk Kim:
"In this round, we've focused on bug fixes since Pixel devices have
been shipping with f2fs. Some of them were related to hardware
encryption support which are actually not an issue in mainline, but
would be better to merge them in order to avoid potential bugs.

Enhancements:
- do GC sub-sections when the section is large
- add a flag in ioctl(SHUTDOWN) to trigger fsck for QA
- use kvmalloc() in order to give another chance to avoid ENOMEM

Bug fixes:
- fix accessing memory boundaries in a malformed iamge
- GC gives stale unencrypted block
- GC counts in large sections
- detect idle time more precisely
- block allocation of DIO writes
- race conditions between write_begin and write_checkpoint
- allow GCs for node segments via ioctl()

There are various clean-ups and minor bug fixes as well"

* tag 'f2fs-for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (43 commits)
f2fs: sanity check of xattr entry size
f2fs: fix use-after-free issue when accessing sbi->stat_info
f2fs: check PageWriteback flag for ordered case
f2fs: fix validation of the block count in sanity_check_raw_super
f2fs: fix missing unlock(sbi->gc_mutex)
f2fs: fix to dirty inode synchronously
f2fs: clean up structure extent_node
f2fs: fix block address for __check_sit_bitmap
f2fs: fix sbi->extent_list corruption issue
f2fs: clean up checkpoint flow
f2fs: flush stale issued discard candidates
f2fs: correct wrong spelling, issing_*
f2fs: use kvmalloc, if kmalloc is failed
f2fs: remove redundant comment of unused wio_mutex
f2fs: fix to reorder set_page_dirty and wait_on_page_writeback
f2fs: clear PG_writeback if IPU failed
f2fs: add an ioctl() to explicitly trigger fsck later
f2fs: avoid frequent costly fsck triggers
f2fs: fix m_may_create to make OPU DIO write correctly
f2fs: fix to update new block address correctly for OPU
...

+544 -368
+9
Documentation/ABI/testing/sysfs-fs-f2fs
··· 92 92 Description: 93 93 Controls the number of trials to find a victim segment. 94 94 95 + What: /sys/fs/f2fs/<disk>/migration_granularity 96 + Date: October 2018 97 + Contact: "Chao Yu" <yuchao0@huawei.com> 98 + Description: 99 + Controls migration granularity of garbage collection on large 100 + section, it can let GC move partial segment{s} of one section 101 + in one GC cycle, so that dispersing heavy overhead GC to 102 + multiple lightweight one. 103 + 95 104 What: /sys/fs/f2fs/<disk>/dir_level 96 105 Date: March 2014 97 106 Contact: "Jaegeuk Kim" <jaegeuk.kim@samsung.com>
+11 -9
fs/f2fs/acl.c
··· 160 160 return (void *)f2fs_acl; 161 161 162 162 fail: 163 - kfree(f2fs_acl); 163 + kvfree(f2fs_acl); 164 164 return ERR_PTR(-EINVAL); 165 165 } 166 166 ··· 190 190 acl = NULL; 191 191 else 192 192 acl = ERR_PTR(retval); 193 - kfree(value); 193 + kvfree(value); 194 194 195 195 return acl; 196 196 } ··· 240 240 241 241 error = f2fs_setxattr(inode, name_index, "", value, size, ipage, 0); 242 242 243 - kfree(value); 243 + kvfree(value); 244 244 if (!error) 245 245 set_cached_acl(inode, type, acl); 246 246 ··· 352 352 return PTR_ERR(p); 353 353 354 354 clone = f2fs_acl_clone(p, GFP_NOFS); 355 - if (!clone) 356 - goto no_mem; 355 + if (!clone) { 356 + ret = -ENOMEM; 357 + goto release_acl; 358 + } 357 359 358 360 ret = f2fs_acl_create_masq(clone, mode); 359 361 if (ret < 0) 360 - goto no_mem_clone; 362 + goto release_clone; 361 363 362 364 if (ret == 0) 363 365 posix_acl_release(clone); ··· 373 371 374 372 return 0; 375 373 376 - no_mem_clone: 374 + release_clone: 377 375 posix_acl_release(clone); 378 - no_mem: 376 + release_acl: 379 377 posix_acl_release(p); 380 - return -ENOMEM; 378 + return ret; 381 379 } 382 380 383 381 int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage,
+13 -22
fs/f2fs/checkpoint.c
··· 44 44 cond_resched(); 45 45 goto repeat; 46 46 } 47 - f2fs_wait_on_page_writeback(page, META, true); 47 + f2fs_wait_on_page_writeback(page, META, true, true); 48 48 if (!PageUptodate(page)) 49 49 SetPageUptodate(page); 50 50 return page; ··· 370 370 goto continue_unlock; 371 371 } 372 372 373 - f2fs_wait_on_page_writeback(page, META, true); 373 + f2fs_wait_on_page_writeback(page, META, true, true); 374 374 375 - BUG_ON(PageWriteback(page)); 376 375 if (!clear_page_dirty_for_io(page)) 377 376 goto continue_unlock; 378 377 ··· 910 911 f2fs_put_page(cp1, 1); 911 912 f2fs_put_page(cp2, 1); 912 913 fail_no_cp: 913 - kfree(sbi->ckpt); 914 + kvfree(sbi->ckpt); 914 915 return -EINVAL; 915 916 } 916 917 ··· 1289 1290 struct page *page = f2fs_grab_meta_page(sbi, blk_addr); 1290 1291 int err; 1291 1292 1292 - memcpy(page_address(page), src, PAGE_SIZE); 1293 - set_page_dirty(page); 1293 + f2fs_wait_on_page_writeback(page, META, true, true); 1294 1294 1295 - f2fs_wait_on_page_writeback(page, META, true); 1296 - f2fs_bug_on(sbi, PageWriteback(page)); 1295 + memcpy(page_address(page), src, PAGE_SIZE); 1296 + 1297 + set_page_dirty(page); 1297 1298 if (unlikely(!clear_page_dirty_for_io(page))) 1298 1299 f2fs_bug_on(sbi, 1); 1299 1300 ··· 1327 1328 int err; 1328 1329 1329 1330 /* Flush all the NAT/SIT pages */ 1330 - while (get_pages(sbi, F2FS_DIRTY_META)) { 1331 - f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); 1332 - if (unlikely(f2fs_cp_error(sbi))) 1333 - break; 1334 - } 1331 + f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); 1332 + f2fs_bug_on(sbi, get_pages(sbi, F2FS_DIRTY_META) && 1333 + !f2fs_cp_error(sbi)); 1335 1334 1336 1335 /* 1337 1336 * modify checkpoint ··· 1402 1405 for (i = 0; i < nm_i->nat_bits_blocks; i++) 1403 1406 f2fs_update_meta_page(sbi, nm_i->nat_bits + 1404 1407 (i << F2FS_BLKSIZE_BITS), blk + i); 1405 - 1406 - /* Flush all the NAT BITS pages */ 1407 - while (get_pages(sbi, F2FS_DIRTY_META)) { 1408 - f2fs_sync_meta_pages(sbi, META, LONG_MAX, 1409 - FS_CP_META_IO); 1410 - if (unlikely(f2fs_cp_error(sbi))) 1411 - break; 1412 - } 1413 1408 } 1414 1409 1415 1410 /* write out checkpoint buffer at block 0 */ ··· 1437 1448 1438 1449 /* Here, we have one bio having CP pack except cp pack 2 page */ 1439 1450 f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); 1451 + f2fs_bug_on(sbi, get_pages(sbi, F2FS_DIRTY_META) && 1452 + !f2fs_cp_error(sbi)); 1440 1453 1441 1454 /* wait for previous submitted meta pages writeback */ 1442 1455 f2fs_wait_on_all_pages_writeback(sbi); ··· 1456 1465 * invalidate intermediate page cache borrowed from meta inode 1457 1466 * which are used for migration of encrypted inode's blocks. 1458 1467 */ 1459 - if (f2fs_sb_has_encrypt(sbi->sb)) 1468 + if (f2fs_sb_has_encrypt(sbi)) 1460 1469 invalidate_mapping_pages(META_MAPPING(sbi), 1461 1470 MAIN_BLKADDR(sbi), MAX_BLKADDR(sbi) - 1); 1462 1471
+112 -48
fs/f2fs/data.c
··· 372 372 return false; 373 373 } 374 374 375 - static bool has_merged_page(struct f2fs_sb_info *sbi, struct inode *inode, 376 - struct page *page, nid_t ino, 377 - enum page_type type) 378 - { 379 - enum page_type btype = PAGE_TYPE_OF_BIO(type); 380 - enum temp_type temp; 381 - struct f2fs_bio_info *io; 382 - bool ret = false; 383 - 384 - for (temp = HOT; temp < NR_TEMP_TYPE; temp++) { 385 - io = sbi->write_io[btype] + temp; 386 - 387 - down_read(&io->io_rwsem); 388 - ret = __has_merged_page(io, inode, page, ino); 389 - up_read(&io->io_rwsem); 390 - 391 - /* TODO: use HOT temp only for meta pages now. */ 392 - if (ret || btype == META) 393 - break; 394 - } 395 - return ret; 396 - } 397 - 398 375 static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi, 399 376 enum page_type type, enum temp_type temp) 400 377 { ··· 397 420 nid_t ino, enum page_type type, bool force) 398 421 { 399 422 enum temp_type temp; 400 - 401 - if (!force && !has_merged_page(sbi, inode, page, ino, type)) 402 - return; 423 + bool ret = true; 403 424 404 425 for (temp = HOT; temp < NR_TEMP_TYPE; temp++) { 426 + if (!force) { 427 + enum page_type btype = PAGE_TYPE_OF_BIO(type); 428 + struct f2fs_bio_info *io = sbi->write_io[btype] + temp; 405 429 406 - __f2fs_submit_merged_write(sbi, type, temp); 430 + down_read(&io->io_rwsem); 431 + ret = __has_merged_page(io, inode, page, ino); 432 + up_read(&io->io_rwsem); 433 + } 434 + if (ret) 435 + __f2fs_submit_merged_write(sbi, type, temp); 407 436 408 437 /* TODO: use HOT temp only for meta pages now. */ 409 438 if (type >= META) ··· 626 643 */ 627 644 void f2fs_set_data_blkaddr(struct dnode_of_data *dn) 628 645 { 629 - f2fs_wait_on_page_writeback(dn->node_page, NODE, true); 646 + f2fs_wait_on_page_writeback(dn->node_page, NODE, true, true); 630 647 __set_data_blkaddr(dn); 631 648 if (set_page_dirty(dn->node_page)) 632 649 dn->node_changed = true; ··· 656 673 trace_f2fs_reserve_new_blocks(dn->inode, dn->nid, 657 674 dn->ofs_in_node, count); 658 675 659 - f2fs_wait_on_page_writeback(dn->node_page, NODE, true); 676 + f2fs_wait_on_page_writeback(dn->node_page, NODE, true, true); 660 677 661 678 for (; count > 0; dn->ofs_in_node++) { 662 679 block_t blkaddr = datablock_addr(dn->inode, ··· 940 957 return err; 941 958 } 942 959 960 + if (direct_io && allow_outplace_dio(inode, iocb, from)) 961 + return 0; 962 + 943 963 if (is_inode_flag_set(inode, FI_NO_PREALLOC)) 944 964 return 0; 945 965 ··· 956 970 map.m_next_pgofs = NULL; 957 971 map.m_next_extent = NULL; 958 972 map.m_seg_type = NO_CHECK_TYPE; 973 + map.m_may_create = true; 959 974 960 975 if (direct_io) { 961 976 map.m_seg_type = f2fs_rw_hint_to_seg_type(iocb->ki_hint); ··· 1015 1028 unsigned int maxblocks = map->m_len; 1016 1029 struct dnode_of_data dn; 1017 1030 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1018 - int mode = create ? ALLOC_NODE : LOOKUP_NODE; 1031 + int mode = map->m_may_create ? ALLOC_NODE : LOOKUP_NODE; 1019 1032 pgoff_t pgofs, end_offset, end; 1020 1033 int err = 0, ofs = 1; 1021 1034 unsigned int ofs_in_node, last_ofs_in_node; ··· 1035 1048 end = pgofs + maxblocks; 1036 1049 1037 1050 if (!create && f2fs_lookup_extent_cache(inode, pgofs, &ei)) { 1051 + if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO && 1052 + map->m_may_create) 1053 + goto next_dnode; 1054 + 1038 1055 map->m_pblk = ei.blk + pgofs - ei.fofs; 1039 1056 map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs); 1040 1057 map->m_flags = F2FS_MAP_MAPPED; ··· 1053 1062 } 1054 1063 1055 1064 next_dnode: 1056 - if (create) 1065 + if (map->m_may_create) 1057 1066 __do_map_lock(sbi, flag, true); 1058 1067 1059 1068 /* When reading holes, we need its node page */ ··· 1090 1099 1091 1100 if (is_valid_data_blkaddr(sbi, blkaddr)) { 1092 1101 /* use out-place-update for driect IO under LFS mode */ 1093 - if (test_opt(sbi, LFS) && create && 1094 - flag == F2FS_GET_BLOCK_DIO) { 1102 + if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO && 1103 + map->m_may_create) { 1095 1104 err = __allocate_data_block(&dn, map->m_seg_type); 1096 - if (!err) 1105 + if (!err) { 1106 + blkaddr = dn.data_blkaddr; 1097 1107 set_inode_flag(inode, FI_APPEND_WRITE); 1108 + } 1098 1109 } 1099 1110 } else { 1100 1111 if (create) { ··· 1202 1209 1203 1210 f2fs_put_dnode(&dn); 1204 1211 1205 - if (create) { 1212 + if (map->m_may_create) { 1206 1213 __do_map_lock(sbi, flag, false); 1207 1214 f2fs_balance_fs(sbi, dn.node_changed); 1208 1215 } ··· 1228 1235 } 1229 1236 f2fs_put_dnode(&dn); 1230 1237 unlock_out: 1231 - if (create) { 1238 + if (map->m_may_create) { 1232 1239 __do_map_lock(sbi, flag, false); 1233 1240 f2fs_balance_fs(sbi, dn.node_changed); 1234 1241 } ··· 1250 1257 map.m_next_pgofs = NULL; 1251 1258 map.m_next_extent = NULL; 1252 1259 map.m_seg_type = NO_CHECK_TYPE; 1260 + map.m_may_create = false; 1253 1261 last_lblk = F2FS_BLK_ALIGN(pos + len); 1254 1262 1255 1263 while (map.m_lblk < last_lblk) { ··· 1265 1271 1266 1272 static int __get_data_block(struct inode *inode, sector_t iblock, 1267 1273 struct buffer_head *bh, int create, int flag, 1268 - pgoff_t *next_pgofs, int seg_type) 1274 + pgoff_t *next_pgofs, int seg_type, bool may_write) 1269 1275 { 1270 1276 struct f2fs_map_blocks map; 1271 1277 int err; ··· 1275 1281 map.m_next_pgofs = next_pgofs; 1276 1282 map.m_next_extent = NULL; 1277 1283 map.m_seg_type = seg_type; 1284 + map.m_may_create = may_write; 1278 1285 1279 1286 err = f2fs_map_blocks(inode, &map, create, flag); 1280 1287 if (!err) { ··· 1292 1297 { 1293 1298 return __get_data_block(inode, iblock, bh_result, create, 1294 1299 flag, next_pgofs, 1295 - NO_CHECK_TYPE); 1300 + NO_CHECK_TYPE, create); 1301 + } 1302 + 1303 + static int get_data_block_dio_write(struct inode *inode, sector_t iblock, 1304 + struct buffer_head *bh_result, int create) 1305 + { 1306 + return __get_data_block(inode, iblock, bh_result, create, 1307 + F2FS_GET_BLOCK_DIO, NULL, 1308 + f2fs_rw_hint_to_seg_type(inode->i_write_hint), 1309 + true); 1296 1310 } 1297 1311 1298 1312 static int get_data_block_dio(struct inode *inode, sector_t iblock, 1299 1313 struct buffer_head *bh_result, int create) 1300 1314 { 1301 1315 return __get_data_block(inode, iblock, bh_result, create, 1302 - F2FS_GET_BLOCK_DIO, NULL, 1303 - f2fs_rw_hint_to_seg_type( 1304 - inode->i_write_hint)); 1316 + F2FS_GET_BLOCK_DIO, NULL, 1317 + f2fs_rw_hint_to_seg_type(inode->i_write_hint), 1318 + false); 1305 1319 } 1306 1320 1307 1321 static int get_data_block_bmap(struct inode *inode, sector_t iblock, ··· 1322 1318 1323 1319 return __get_data_block(inode, iblock, bh_result, create, 1324 1320 F2FS_GET_BLOCK_BMAP, NULL, 1325 - NO_CHECK_TYPE); 1321 + NO_CHECK_TYPE, create); 1326 1322 } 1327 1323 1328 1324 static inline sector_t logical_to_blk(struct inode *inode, loff_t offset) ··· 1529 1525 map.m_next_pgofs = NULL; 1530 1526 map.m_next_extent = NULL; 1531 1527 map.m_seg_type = NO_CHECK_TYPE; 1528 + map.m_may_create = false; 1532 1529 1533 1530 for (; nr_pages; nr_pages--) { 1534 1531 if (pages) { ··· 1860 1855 if (fio->need_lock == LOCK_REQ) 1861 1856 f2fs_unlock_op(fio->sbi); 1862 1857 err = f2fs_inplace_write_data(fio); 1858 + if (err && PageWriteback(page)) 1859 + end_page_writeback(page); 1863 1860 trace_f2fs_do_write_data_page(fio->page, IPU); 1864 1861 set_inode_flag(inode, FI_UPDATE_WRITE); 1865 1862 return err; ··· 2149 2142 if (PageWriteback(page)) { 2150 2143 if (wbc->sync_mode != WB_SYNC_NONE) 2151 2144 f2fs_wait_on_page_writeback(page, 2152 - DATA, true); 2145 + DATA, true, true); 2153 2146 else 2154 2147 goto continue_unlock; 2155 2148 } 2156 2149 2157 - BUG_ON(PageWriteback(page)); 2158 2150 if (!clear_page_dirty_for_io(page)) 2159 2151 goto continue_unlock; 2160 2152 ··· 2330 2324 bool locked = false; 2331 2325 struct extent_info ei = {0,0,0}; 2332 2326 int err = 0; 2327 + int flag; 2333 2328 2334 2329 /* 2335 2330 * we already allocated all the blocks, so we don't need to get ··· 2340 2333 !is_inode_flag_set(inode, FI_NO_PREALLOC)) 2341 2334 return 0; 2342 2335 2336 + /* f2fs_lock_op avoids race between write CP and convert_inline_page */ 2337 + if (f2fs_has_inline_data(inode) && pos + len > MAX_INLINE_DATA(inode)) 2338 + flag = F2FS_GET_BLOCK_DEFAULT; 2339 + else 2340 + flag = F2FS_GET_BLOCK_PRE_AIO; 2341 + 2343 2342 if (f2fs_has_inline_data(inode) || 2344 2343 (pos & PAGE_MASK) >= i_size_read(inode)) { 2345 - __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); 2344 + __do_map_lock(sbi, flag, true); 2346 2345 locked = true; 2347 2346 } 2348 2347 restart: ··· 2386 2373 f2fs_put_dnode(&dn); 2387 2374 __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, 2388 2375 true); 2376 + WARN_ON(flag != F2FS_GET_BLOCK_PRE_AIO); 2389 2377 locked = true; 2390 2378 goto restart; 2391 2379 } ··· 2400 2386 f2fs_put_dnode(&dn); 2401 2387 unlock_out: 2402 2388 if (locked) 2403 - __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); 2389 + __do_map_lock(sbi, flag, false); 2404 2390 return err; 2405 2391 } 2406 2392 ··· 2471 2457 } 2472 2458 } 2473 2459 2474 - f2fs_wait_on_page_writeback(page, DATA, false); 2460 + f2fs_wait_on_page_writeback(page, DATA, false, true); 2475 2461 2476 2462 if (len == PAGE_SIZE || PageUptodate(page)) 2477 2463 return 0; ··· 2562 2548 return 0; 2563 2549 } 2564 2550 2551 + static void f2fs_dio_end_io(struct bio *bio) 2552 + { 2553 + struct f2fs_private_dio *dio = bio->bi_private; 2554 + 2555 + dec_page_count(F2FS_I_SB(dio->inode), 2556 + dio->write ? F2FS_DIO_WRITE : F2FS_DIO_READ); 2557 + 2558 + bio->bi_private = dio->orig_private; 2559 + bio->bi_end_io = dio->orig_end_io; 2560 + 2561 + kvfree(dio); 2562 + 2563 + bio_endio(bio); 2564 + } 2565 + 2566 + static void f2fs_dio_submit_bio(struct bio *bio, struct inode *inode, 2567 + loff_t file_offset) 2568 + { 2569 + struct f2fs_private_dio *dio; 2570 + bool write = (bio_op(bio) == REQ_OP_WRITE); 2571 + int err; 2572 + 2573 + dio = f2fs_kzalloc(F2FS_I_SB(inode), 2574 + sizeof(struct f2fs_private_dio), GFP_NOFS); 2575 + if (!dio) { 2576 + err = -ENOMEM; 2577 + goto out; 2578 + } 2579 + 2580 + dio->inode = inode; 2581 + dio->orig_end_io = bio->bi_end_io; 2582 + dio->orig_private = bio->bi_private; 2583 + dio->write = write; 2584 + 2585 + bio->bi_end_io = f2fs_dio_end_io; 2586 + bio->bi_private = dio; 2587 + 2588 + inc_page_count(F2FS_I_SB(inode), 2589 + write ? F2FS_DIO_WRITE : F2FS_DIO_READ); 2590 + 2591 + submit_bio(bio); 2592 + return; 2593 + out: 2594 + bio->bi_status = BLK_STS_IOERR; 2595 + bio_endio(bio); 2596 + } 2597 + 2565 2598 static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) 2566 2599 { 2567 2600 struct address_space *mapping = iocb->ki_filp->f_mapping; ··· 2655 2594 down_read(&fi->i_gc_rwsem[READ]); 2656 2595 } 2657 2596 2658 - err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio); 2597 + err = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, 2598 + iter, rw == WRITE ? get_data_block_dio_write : 2599 + get_data_block_dio, NULL, f2fs_dio_submit_bio, 2600 + DIO_LOCKING | DIO_SKIP_HOLES); 2659 2601 2660 2602 if (do_opu) 2661 2603 up_read(&fi->i_gc_rwsem[READ]);
+9 -16
fs/f2fs/debug.c
··· 53 53 si->vw_cnt = atomic_read(&sbi->vw_cnt); 54 54 si->max_aw_cnt = atomic_read(&sbi->max_aw_cnt); 55 55 si->max_vw_cnt = atomic_read(&sbi->max_vw_cnt); 56 + si->nr_dio_read = get_pages(sbi, F2FS_DIO_READ); 57 + si->nr_dio_write = get_pages(sbi, F2FS_DIO_WRITE); 56 58 si->nr_wb_cp_data = get_pages(sbi, F2FS_WB_CP_DATA); 57 59 si->nr_wb_data = get_pages(sbi, F2FS_WB_DATA); 58 60 si->nr_rd_data = get_pages(sbi, F2FS_RD_DATA); ··· 64 62 si->nr_flushed = 65 63 atomic_read(&SM_I(sbi)->fcc_info->issued_flush); 66 64 si->nr_flushing = 67 - atomic_read(&SM_I(sbi)->fcc_info->issing_flush); 65 + atomic_read(&SM_I(sbi)->fcc_info->queued_flush); 68 66 si->flush_list_empty = 69 67 llist_empty(&SM_I(sbi)->fcc_info->issue_list); 70 68 } ··· 72 70 si->nr_discarded = 73 71 atomic_read(&SM_I(sbi)->dcc_info->issued_discard); 74 72 si->nr_discarding = 75 - atomic_read(&SM_I(sbi)->dcc_info->issing_discard); 73 + atomic_read(&SM_I(sbi)->dcc_info->queued_discard); 76 74 si->nr_discard_cmd = 77 75 atomic_read(&SM_I(sbi)->dcc_info->discard_cmd_cnt); 78 76 si->undiscard_blks = SM_I(sbi)->dcc_info->undiscard_blks; ··· 199 197 si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); 200 198 si->base_mem += SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); 201 199 si->base_mem += SIT_VBLOCK_MAP_SIZE; 202 - if (sbi->segs_per_sec > 1) 200 + if (__is_large_section(sbi)) 203 201 si->base_mem += MAIN_SECS(sbi) * sizeof(struct sec_entry); 204 202 si->base_mem += __bitmap_size(sbi, SIT_BITMAP); 205 203 ··· 376 374 seq_printf(s, " - Inner Struct Count: tree: %d(%d), node: %d\n", 377 375 si->ext_tree, si->zombie_tree, si->ext_node); 378 376 seq_puts(s, "\nBalancing F2FS Async:\n"); 377 + seq_printf(s, " - DIO (R: %4d, W: %4d)\n", 378 + si->nr_dio_read, si->nr_dio_write); 379 379 seq_printf(s, " - IO_R (Data: %4d, Node: %4d, Meta: %4d\n", 380 380 si->nr_rd_data, si->nr_rd_node, si->nr_rd_meta); 381 381 seq_printf(s, " - IO_W (CP: %4d, Data: %4d, Flush: (%4d %4d %4d), " ··· 448 444 return 0; 449 445 } 450 446 451 - static int stat_open(struct inode *inode, struct file *file) 452 - { 453 - return single_open(file, stat_show, inode->i_private); 454 - } 455 - 456 - static const struct file_operations stat_fops = { 457 - .owner = THIS_MODULE, 458 - .open = stat_open, 459 - .read = seq_read, 460 - .llseek = seq_lseek, 461 - .release = single_release, 462 - }; 447 + DEFINE_SHOW_ATTRIBUTE(stat); 463 448 464 449 int f2fs_build_stats(struct f2fs_sb_info *sbi) 465 450 { ··· 503 510 list_del(&si->stat_list); 504 511 mutex_unlock(&f2fs_stat_mutex); 505 512 506 - kfree(si); 513 + kvfree(si); 507 514 } 508 515 509 516 int __init f2fs_create_root_stats(void)
+15 -5
fs/f2fs/dir.c
··· 293 293 { 294 294 enum page_type type = f2fs_has_inline_dentry(dir) ? NODE : DATA; 295 295 lock_page(page); 296 - f2fs_wait_on_page_writeback(page, type, true); 296 + f2fs_wait_on_page_writeback(page, type, true, true); 297 297 de->ino = cpu_to_le32(inode->i_ino); 298 298 set_de_type(de, inode->i_mode); 299 299 set_page_dirty(page); ··· 307 307 { 308 308 struct f2fs_inode *ri; 309 309 310 - f2fs_wait_on_page_writeback(ipage, NODE, true); 310 + f2fs_wait_on_page_writeback(ipage, NODE, true, true); 311 311 312 312 /* copy name info. to this inode page */ 313 313 ri = F2FS_INODE(ipage); ··· 550 550 ++level; 551 551 goto start; 552 552 add_dentry: 553 - f2fs_wait_on_page_writeback(dentry_page, DATA, true); 553 + f2fs_wait_on_page_writeback(dentry_page, DATA, true, true); 554 554 555 555 if (inode) { 556 556 down_write(&F2FS_I(inode)->i_sem); ··· 705 705 return f2fs_delete_inline_entry(dentry, page, dir, inode); 706 706 707 707 lock_page(page); 708 - f2fs_wait_on_page_writeback(page, DATA, true); 708 + f2fs_wait_on_page_writeback(page, DATA, true, true); 709 709 710 710 dentry_blk = page_address(page); 711 711 bit_pos = dentry - dentry_blk->dentry; ··· 808 808 de_name.name = d->filename[bit_pos]; 809 809 de_name.len = le16_to_cpu(de->name_len); 810 810 811 + /* check memory boundary before moving forward */ 812 + bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); 813 + if (unlikely(bit_pos > d->max)) { 814 + f2fs_msg(sbi->sb, KERN_WARNING, 815 + "%s: corrupted namelen=%d, run fsck to fix.", 816 + __func__, le16_to_cpu(de->name_len)); 817 + set_sbi_flag(sbi, SBI_NEED_FSCK); 818 + err = -EINVAL; 819 + goto out; 820 + } 821 + 811 822 if (f2fs_encrypted_inode(d->inode)) { 812 823 int save_len = fstr->len; 813 824 ··· 841 830 if (readdir_ra) 842 831 f2fs_ra_node_page(sbi, le32_to_cpu(de->ino)); 843 832 844 - bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); 845 833 ctx->pos = start_pos + bit_pos; 846 834 } 847 835 out:
+65 -33
fs/f2fs/f2fs.h
··· 67 67 unsigned int inject_type; 68 68 }; 69 69 70 - extern char *f2fs_fault_name[FAULT_MAX]; 70 + extern const char *f2fs_fault_name[FAULT_MAX]; 71 71 #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 72 72 #endif 73 73 ··· 152 152 #define F2FS_FEATURE_VERITY 0x0400 /* reserved */ 153 153 #define F2FS_FEATURE_SB_CHKSUM 0x0800 154 154 155 - #define F2FS_HAS_FEATURE(sb, mask) \ 156 - ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 157 - #define F2FS_SET_FEATURE(sb, mask) \ 158 - (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 159 - #define F2FS_CLEAR_FEATURE(sb, mask) \ 160 - (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 155 + #define __F2FS_HAS_FEATURE(raw_super, mask) \ 156 + ((raw_super->feature & cpu_to_le32(mask)) != 0) 157 + #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask) 158 + #define F2FS_SET_FEATURE(sbi, mask) \ 159 + (sbi->raw_super->feature |= cpu_to_le32(mask)) 160 + #define F2FS_CLEAR_FEATURE(sbi, mask) \ 161 + (sbi->raw_super->feature &= ~cpu_to_le32(mask)) 161 162 162 163 /* 163 164 * Default values for user and/or group using reserved blocks ··· 285 284 struct block_device *bdev; /* bdev */ 286 285 unsigned short ref; /* reference count */ 287 286 unsigned char state; /* state */ 288 - unsigned char issuing; /* issuing discard */ 287 + unsigned char queued; /* queued discard */ 289 288 int error; /* bio error */ 290 289 spinlock_t lock; /* for state/bio_ref updating */ 291 290 unsigned short bio_ref; /* bio reference count */ ··· 327 326 unsigned int undiscard_blks; /* # of undiscard blocks */ 328 327 unsigned int next_pos; /* next discard position */ 329 328 atomic_t issued_discard; /* # of issued discard */ 330 - atomic_t issing_discard; /* # of issing discard */ 329 + atomic_t queued_discard; /* # of queued discard */ 331 330 atomic_t discard_cmd_cnt; /* # of cached cmd count */ 332 331 struct rb_root_cached root; /* root of discard rb-tree */ 333 332 bool rbtree_check; /* config for consistence check */ ··· 417 416 #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 418 417 #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 419 418 #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 419 + #define F2FS_GOING_DOWN_NEED_FSCK 0x4 /* going down to trigger fsck */ 420 420 421 421 #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 422 422 /* ··· 559 557 }; 560 558 561 559 struct extent_node { 562 - struct rb_node rb_node; 563 - union { 564 - struct { 565 - unsigned int fofs; 566 - unsigned int len; 567 - u32 blk; 568 - }; 569 - struct extent_info ei; /* extent info */ 570 - 571 - }; 560 + struct rb_node rb_node; /* rb node located in rb-tree */ 561 + struct extent_info ei; /* extent info */ 572 562 struct list_head list; /* node in global extent list of sbi */ 573 563 struct extent_tree *et; /* extent tree pointer */ 574 564 }; ··· 595 601 pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 596 602 pgoff_t *m_next_extent; /* point to next possible extent */ 597 603 int m_seg_type; 604 + bool m_may_create; /* indicate it is from write path */ 598 605 }; 599 606 600 607 /* for flag in get_data_block */ ··· 884 889 struct task_struct *f2fs_issue_flush; /* flush thread */ 885 890 wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 886 891 atomic_t issued_flush; /* # of issued flushes */ 887 - atomic_t issing_flush; /* # of issing flushes */ 892 + atomic_t queued_flush; /* # of queued flushes */ 888 893 struct llist_head issue_list; /* list for command issue */ 889 894 struct llist_node *dispatch_list; /* list for command dispatch */ 890 895 }; ··· 951 956 F2FS_RD_DATA, 952 957 F2FS_RD_NODE, 953 958 F2FS_RD_META, 959 + F2FS_DIO_WRITE, 960 + F2FS_DIO_READ, 954 961 NR_COUNT_TYPE, 955 962 }; 956 963 ··· 1167 1170 1168 1171 /* for bio operations */ 1169 1172 struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1170 - struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 1171 - /* bio ordering for NODE/DATA */ 1172 1173 /* keep migration IO order for LFS mode */ 1173 1174 struct rw_semaphore io_order_lock; 1174 1175 mempool_t *write_io_dummy; /* Dummy pages */ ··· 1258 1263 struct f2fs_gc_kthread *gc_thread; /* GC thread */ 1259 1264 unsigned int cur_victim_sec; /* current victim section num */ 1260 1265 unsigned int gc_mode; /* current GC state */ 1266 + unsigned int next_victim_seg[2]; /* next segment in victim section */ 1261 1267 /* for skip statistic */ 1262 1268 unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ 1263 1269 unsigned long long skipped_gc_rwsem; /* FG_GC only */ ··· 1268 1272 1269 1273 /* maximum # of trials to find a victim segment for SSR and GC */ 1270 1274 unsigned int max_victim_search; 1275 + /* migration granularity of garbage collection, unit: segment */ 1276 + unsigned int migration_granularity; 1271 1277 1272 1278 /* 1273 1279 * for stat information. ··· 1326 1328 1327 1329 /* Precomputed FS UUID checksum for seeding other checksums */ 1328 1330 __u32 s_chksum_seed; 1331 + }; 1332 + 1333 + struct f2fs_private_dio { 1334 + struct inode *inode; 1335 + void *orig_private; 1336 + bio_end_io_t *orig_end_io; 1337 + bool write; 1329 1338 }; 1330 1339 1331 1340 #ifdef CONFIG_F2FS_FAULT_INJECTION ··· 1613 1608 { 1614 1609 unsigned long flags; 1615 1610 1616 - set_sbi_flag(sbi, SBI_NEED_FSCK); 1611 + /* 1612 + * In order to re-enable nat_bits we need to call fsck.f2fs by 1613 + * set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost, 1614 + * so let's rely on regular fsck or unclean shutdown. 1615 + */ 1617 1616 1618 1617 if (lock) 1619 1618 spin_lock_irqsave(&sbi->cp_lock, flags); 1620 1619 __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 1621 - kfree(NM_I(sbi)->nat_bits); 1620 + kvfree(NM_I(sbi)->nat_bits); 1622 1621 NM_I(sbi)->nat_bits = NULL; 1623 1622 if (lock) 1624 1623 spin_unlock_irqrestore(&sbi->cp_lock, flags); ··· 2155 2146 { 2156 2147 if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) || 2157 2148 get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || 2158 - get_pages(sbi, F2FS_WB_CP_DATA)) 2149 + get_pages(sbi, F2FS_WB_CP_DATA) || 2150 + get_pages(sbi, F2FS_DIO_READ) || 2151 + get_pages(sbi, F2FS_DIO_WRITE) || 2152 + atomic_read(&SM_I(sbi)->dcc_info->queued_discard) || 2153 + atomic_read(&SM_I(sbi)->fcc_info->queued_flush)) 2159 2154 return false; 2160 2155 return f2fs_time_over(sbi, type); 2161 2156 } ··· 2383 2370 case FI_NEW_INODE: 2384 2371 if (set) 2385 2372 return; 2373 + /* fall through */ 2386 2374 case FI_DATA_EXIST: 2387 2375 case FI_INLINE_DOTS: 2388 2376 case FI_PIN_FILE: ··· 2686 2672 2687 2673 static inline bool f2fs_may_extent_tree(struct inode *inode) 2688 2674 { 2689 - if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 2675 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2676 + 2677 + if (!test_opt(sbi, EXTENT_CACHE) || 2690 2678 is_inode_flag_set(inode, FI_NO_EXTENT)) 2679 + return false; 2680 + 2681 + /* 2682 + * for recovered files during mount do not create extents 2683 + * if shrinker is not registered. 2684 + */ 2685 + if (list_empty(&sbi->s_list)) 2691 2686 return false; 2692 2687 2693 2688 return S_ISREG(inode->i_mode); ··· 2705 2682 static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 2706 2683 size_t size, gfp_t flags) 2707 2684 { 2685 + void *ret; 2686 + 2708 2687 if (time_to_inject(sbi, FAULT_KMALLOC)) { 2709 2688 f2fs_show_injection_info(FAULT_KMALLOC); 2710 2689 return NULL; 2711 2690 } 2712 2691 2713 - return kmalloc(size, flags); 2692 + ret = kmalloc(size, flags); 2693 + if (ret) 2694 + return ret; 2695 + 2696 + return kvmalloc(size, flags); 2714 2697 } 2715 2698 2716 2699 static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, ··· 2790 2761 sbi->write_iostat[APP_DIRECT_IO]; 2791 2762 spin_unlock(&sbi->iostat_lock); 2792 2763 } 2764 + 2765 + #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 2793 2766 2794 2767 #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META && \ 2795 2768 (!is_read_io(fio->op) || fio->is_meta)) ··· 3038 3007 struct f2fs_summary *sum, int type, 3039 3008 struct f2fs_io_info *fio, bool add_list); 3040 3009 void f2fs_wait_on_page_writeback(struct page *page, 3041 - enum page_type type, bool ordered); 3010 + enum page_type type, bool ordered, bool locked); 3042 3011 void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr); 3043 3012 void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, 3044 3013 block_t len); ··· 3178 3147 int total_count, utilization; 3179 3148 int bg_gc, nr_wb_cp_data, nr_wb_data; 3180 3149 int nr_rd_data, nr_rd_node, nr_rd_meta; 3150 + int nr_dio_read, nr_dio_write; 3181 3151 unsigned int io_skip_bggc, other_skip_bggc; 3182 3152 int nr_flushing, nr_flushed, flush_list_empty; 3183 3153 int nr_discarding, nr_discarded; ··· 3491 3459 } 3492 3460 3493 3461 #define F2FS_FEATURE_FUNCS(name, flagname) \ 3494 - static inline int f2fs_sb_has_##name(struct super_block *sb) \ 3462 + static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \ 3495 3463 { \ 3496 - return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_##flagname); \ 3464 + return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \ 3497 3465 } 3498 3466 3499 3467 F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); ··· 3523 3491 3524 3492 static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) 3525 3493 { 3526 - return f2fs_sb_has_blkzoned(sbi->sb); 3494 + return f2fs_sb_has_blkzoned(sbi); 3527 3495 } 3528 3496 3529 3497 static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) ··· 3598 3566 * for blkzoned device, fallback direct IO to buffered IO, so 3599 3567 * all IOs can be serialized by log-structured write. 3600 3568 */ 3601 - if (f2fs_sb_has_blkzoned(sbi->sb)) 3569 + if (f2fs_sb_has_blkzoned(sbi)) 3602 3570 return true; 3603 3571 if (test_opt(sbi, LFS) && (rw == WRITE) && 3604 3572 block_unaligned_IO(inode, iocb, iter)) ··· 3621 3589 static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) 3622 3590 { 3623 3591 #ifdef CONFIG_QUOTA 3624 - if (f2fs_sb_has_quota_ino(sbi->sb)) 3592 + if (f2fs_sb_has_quota_ino(sbi)) 3625 3593 return true; 3626 3594 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || 3627 3595 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
+27 -15
fs/f2fs/file.c
··· 82 82 } 83 83 84 84 /* fill the page */ 85 - f2fs_wait_on_page_writeback(page, DATA, false); 85 + f2fs_wait_on_page_writeback(page, DATA, false, true); 86 86 87 87 /* wait for GCed page writeback via META_MAPPING */ 88 88 f2fs_wait_on_block_writeback(inode, dn.data_blkaddr); ··· 215 215 return 0; 216 216 217 217 trace_f2fs_sync_file_enter(inode); 218 + 219 + if (S_ISDIR(inode->i_mode)) 220 + goto go_write; 218 221 219 222 /* if fdatasync is triggered, let's do in-place-update */ 220 223 if (datasync || get_dirty_pages(inode) <= SM_I(sbi)->min_fsync_blocks) ··· 578 575 if (IS_ERR(page)) 579 576 return PTR_ERR(page) == -ENOENT ? 0 : PTR_ERR(page); 580 577 truncate_out: 581 - f2fs_wait_on_page_writeback(page, DATA, true); 578 + f2fs_wait_on_page_writeback(page, DATA, true, true); 582 579 zero_user(page, offset, PAGE_SIZE - offset); 583 580 584 581 /* An encrypted inode should have a key and truncate the last page. */ ··· 699 696 unsigned int flags; 700 697 701 698 if (f2fs_has_extra_attr(inode) && 702 - f2fs_sb_has_inode_crtime(inode->i_sb) && 699 + f2fs_sb_has_inode_crtime(F2FS_I_SB(inode)) && 703 700 F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_crtime)) { 704 701 stat->result_mask |= STATX_BTIME; 705 702 stat->btime.tv_sec = fi->i_crtime.tv_sec; ··· 895 892 if (IS_ERR(page)) 896 893 return PTR_ERR(page); 897 894 898 - f2fs_wait_on_page_writeback(page, DATA, true); 895 + f2fs_wait_on_page_writeback(page, DATA, true, true); 899 896 zero_user(page, start, len); 900 897 set_page_dirty(page); 901 898 f2fs_put_page(page, 1); ··· 1499 1496 { 1500 1497 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1501 1498 struct f2fs_map_blocks map = { .m_next_pgofs = NULL, 1502 - .m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE }; 1499 + .m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE, 1500 + .m_may_create = true }; 1503 1501 pgoff_t pg_end; 1504 1502 loff_t new_size = i_size_read(inode); 1505 1503 loff_t off_end; ··· 1685 1681 1686 1682 inode->i_ctime = current_time(inode); 1687 1683 f2fs_set_inode_flags(inode); 1688 - f2fs_mark_inode_dirty_sync(inode, false); 1684 + f2fs_mark_inode_dirty_sync(inode, true); 1689 1685 return 0; 1690 1686 } 1691 1687 ··· 1966 1962 f2fs_stop_checkpoint(sbi, false); 1967 1963 set_sbi_flag(sbi, SBI_IS_SHUTDOWN); 1968 1964 break; 1965 + case F2FS_GOING_DOWN_NEED_FSCK: 1966 + set_sbi_flag(sbi, SBI_NEED_FSCK); 1967 + /* do checkpoint only */ 1968 + ret = f2fs_sync_fs(sb, 1); 1969 + if (ret) 1970 + goto out; 1971 + break; 1969 1972 default: 1970 1973 ret = -EINVAL; 1971 1974 goto out; ··· 2041 2030 { 2042 2031 struct inode *inode = file_inode(filp); 2043 2032 2044 - if (!f2fs_sb_has_encrypt(inode->i_sb)) 2033 + if (!f2fs_sb_has_encrypt(F2FS_I_SB(inode))) 2045 2034 return -EOPNOTSUPP; 2046 2035 2047 2036 f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); ··· 2051 2040 2052 2041 static int f2fs_ioc_get_encryption_policy(struct file *filp, unsigned long arg) 2053 2042 { 2054 - if (!f2fs_sb_has_encrypt(file_inode(filp)->i_sb)) 2043 + if (!f2fs_sb_has_encrypt(F2FS_I_SB(file_inode(filp)))) 2055 2044 return -EOPNOTSUPP; 2056 2045 return fscrypt_ioctl_get_policy(filp, (void __user *)arg); 2057 2046 } ··· 2062 2051 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2063 2052 int err; 2064 2053 2065 - if (!f2fs_sb_has_encrypt(inode->i_sb)) 2054 + if (!f2fs_sb_has_encrypt(sbi)) 2066 2055 return -EOPNOTSUPP; 2067 2056 2068 2057 err = mnt_want_write_file(filp); ··· 2166 2155 } 2167 2156 2168 2157 ret = f2fs_gc(sbi, range.sync, true, GET_SEGNO(sbi, range.start)); 2169 - range.start += sbi->blocks_per_seg; 2158 + range.start += BLKS_PER_SEC(sbi); 2170 2159 if (range.start <= end) 2171 2160 goto do_more; 2172 2161 out: ··· 2208 2197 { 2209 2198 struct inode *inode = file_inode(filp); 2210 2199 struct f2fs_map_blocks map = { .m_next_extent = NULL, 2211 - .m_seg_type = NO_CHECK_TYPE }; 2200 + .m_seg_type = NO_CHECK_TYPE , 2201 + .m_may_create = false }; 2212 2202 struct extent_info ei = {0, 0, 0}; 2213 2203 pgoff_t pg_start, pg_end, next_pgofs; 2214 2204 unsigned int blk_per_seg = sbi->blocks_per_seg; ··· 2572 2560 return -EFAULT; 2573 2561 2574 2562 if (sbi->s_ndevs <= 1 || sbi->s_ndevs - 1 <= range.dev_num || 2575 - sbi->segs_per_sec != 1) { 2563 + __is_large_section(sbi)) { 2576 2564 f2fs_msg(sbi->sb, KERN_WARNING, 2577 2565 "Can't flush %u in %d for segs_per_sec %u != 1\n", 2578 2566 range.dev_num, sbi->s_ndevs, ··· 2647 2635 struct inode *inode = file_inode(filp); 2648 2636 struct f2fs_inode_info *fi = F2FS_I(inode); 2649 2637 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2650 - struct super_block *sb = sbi->sb; 2651 2638 struct page *ipage; 2652 2639 kprojid_t kprojid; 2653 2640 int err; 2654 2641 2655 - if (!f2fs_sb_has_project_quota(sb)) { 2642 + if (!f2fs_sb_has_project_quota(sbi)) { 2656 2643 if (projid != F2FS_DEF_PROJID) 2657 2644 return -EOPNOTSUPP; 2658 2645 else ··· 2768 2757 fa.fsx_xflags = f2fs_iflags_to_xflags(fi->i_flags & 2769 2758 F2FS_FL_USER_VISIBLE); 2770 2759 2771 - if (f2fs_sb_has_project_quota(inode->i_sb)) 2760 + if (f2fs_sb_has_project_quota(F2FS_I_SB(inode))) 2772 2761 fa.fsx_projid = (__u32)from_kprojid(&init_user_ns, 2773 2762 fi->i_projid); 2774 2763 ··· 2943 2932 map.m_next_pgofs = NULL; 2944 2933 map.m_next_extent = &m_next_extent; 2945 2934 map.m_seg_type = NO_CHECK_TYPE; 2935 + map.m_may_create = false; 2946 2936 end = F2FS_I_SB(inode)->max_file_blocks; 2947 2937 2948 2938 while (map.m_lblk < end) {
+60 -21
fs/f2fs/gc.c
··· 142 142 "f2fs_gc-%u:%u", MAJOR(dev), MINOR(dev)); 143 143 if (IS_ERR(gc_th->f2fs_gc_task)) { 144 144 err = PTR_ERR(gc_th->f2fs_gc_task); 145 - kfree(gc_th); 145 + kvfree(gc_th); 146 146 sbi->gc_thread = NULL; 147 147 } 148 148 out: ··· 155 155 if (!gc_th) 156 156 return; 157 157 kthread_stop(gc_th->f2fs_gc_task); 158 - kfree(gc_th); 158 + kvfree(gc_th); 159 159 sbi->gc_thread = NULL; 160 160 } 161 161 ··· 323 323 p.min_cost = get_max_cost(sbi, &p); 324 324 325 325 if (*result != NULL_SEGNO) { 326 - if (IS_DATASEG(get_seg_entry(sbi, *result)->type) && 327 - get_valid_blocks(sbi, *result, false) && 326 + if (get_valid_blocks(sbi, *result, false) && 328 327 !sec_usage_check(sbi, GET_SEC_FROM_SEG(sbi, *result))) 329 328 p.min_segno = *result; 330 329 goto out; ··· 331 332 332 333 if (p.max_search == 0) 333 334 goto out; 335 + 336 + if (__is_large_section(sbi) && p.alloc_mode == LFS) { 337 + if (sbi->next_victim_seg[BG_GC] != NULL_SEGNO) { 338 + p.min_segno = sbi->next_victim_seg[BG_GC]; 339 + *result = p.min_segno; 340 + sbi->next_victim_seg[BG_GC] = NULL_SEGNO; 341 + goto got_result; 342 + } 343 + if (gc_type == FG_GC && 344 + sbi->next_victim_seg[FG_GC] != NULL_SEGNO) { 345 + p.min_segno = sbi->next_victim_seg[FG_GC]; 346 + *result = p.min_segno; 347 + sbi->next_victim_seg[FG_GC] = NULL_SEGNO; 348 + goto got_result; 349 + } 350 + } 334 351 335 352 last_victim = sm->last_victim[p.gc_mode]; 336 353 if (p.alloc_mode == LFS && gc_type == FG_GC) { ··· 410 395 } 411 396 if (p.min_segno != NULL_SEGNO) { 412 397 got_it: 398 + *result = (p.min_segno / p.ofs_unit) * p.ofs_unit; 399 + got_result: 413 400 if (p.alloc_mode == LFS) { 414 401 secno = GET_SEC_FROM_SEG(sbi, p.min_segno); 415 402 if (gc_type == FG_GC) ··· 419 402 else 420 403 set_bit(secno, dirty_i->victim_secmap); 421 404 } 422 - *result = (p.min_segno / p.ofs_unit) * p.ofs_unit; 423 405 406 + } 407 + out: 408 + if (p.min_segno != NULL_SEGNO) 424 409 trace_f2fs_get_victim(sbi->sb, type, gc_type, &p, 425 410 sbi->cur_victim_sec, 426 411 prefree_segments(sbi), free_segments(sbi)); 427 - } 428 - out: 429 412 mutex_unlock(&dirty_i->seglist_lock); 430 413 431 414 return (p.min_segno == NULL_SEGNO) ? 0 : 1; ··· 675 658 fio.page = page; 676 659 fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr; 677 660 661 + /* 662 + * don't cache encrypted data into meta inode until previous dirty 663 + * data were writebacked to avoid racing between GC and flush. 664 + */ 665 + f2fs_wait_on_page_writeback(page, DATA, true, true); 666 + 667 + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr); 668 + 678 669 fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi), 679 670 dn.data_blkaddr, 680 671 FGP_LOCK | FGP_CREAT, GFP_NOFS); ··· 768 743 * don't cache encrypted data into meta inode until previous dirty 769 744 * data were writebacked to avoid racing between GC and flush. 770 745 */ 771 - f2fs_wait_on_page_writeback(page, DATA, true); 746 + f2fs_wait_on_page_writeback(page, DATA, true, true); 747 + 748 + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr); 772 749 773 750 err = f2fs_get_node_info(fio.sbi, dn.nid, &ni); 774 751 if (err) ··· 829 802 } 830 803 831 804 write_page: 805 + f2fs_wait_on_page_writeback(fio.encrypted_page, DATA, true, true); 832 806 set_page_dirty(fio.encrypted_page); 833 - f2fs_wait_on_page_writeback(fio.encrypted_page, DATA, true); 834 807 if (clear_page_dirty_for_io(fio.encrypted_page)) 835 808 dec_page_count(fio.sbi, F2FS_DIRTY_META); 836 809 ··· 838 811 ClearPageError(page); 839 812 840 813 /* allocate block address */ 841 - f2fs_wait_on_page_writeback(dn.node_page, NODE, true); 814 + f2fs_wait_on_page_writeback(dn.node_page, NODE, true, true); 842 815 843 816 fio.op = REQ_OP_WRITE; 844 817 fio.op_flags = REQ_SYNC; ··· 924 897 bool is_dirty = PageDirty(page); 925 898 926 899 retry: 900 + f2fs_wait_on_page_writeback(page, DATA, true, true); 901 + 927 902 set_page_dirty(page); 928 - f2fs_wait_on_page_writeback(page, DATA, true); 929 903 if (clear_page_dirty_for_io(page)) { 930 904 inode_dec_dirty_pages(inode); 931 905 f2fs_remove_dirty_inode(inode); ··· 1121 1093 struct blk_plug plug; 1122 1094 unsigned int segno = start_segno; 1123 1095 unsigned int end_segno = start_segno + sbi->segs_per_sec; 1124 - int seg_freed = 0; 1096 + int seg_freed = 0, migrated = 0; 1125 1097 unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ? 1126 1098 SUM_TYPE_DATA : SUM_TYPE_NODE; 1127 1099 int submitted = 0; 1128 1100 1101 + if (__is_large_section(sbi)) 1102 + end_segno = rounddown(end_segno, sbi->segs_per_sec); 1103 + 1129 1104 /* readahead multi ssa blocks those have contiguous address */ 1130 - if (sbi->segs_per_sec > 1) 1105 + if (__is_large_section(sbi)) 1131 1106 f2fs_ra_meta_pages(sbi, GET_SUM_BLOCK(sbi, segno), 1132 - sbi->segs_per_sec, META_SSA, true); 1107 + end_segno - segno, META_SSA, true); 1133 1108 1134 1109 /* reference all summary page */ 1135 1110 while (segno < end_segno) { ··· 1161 1130 GET_SUM_BLOCK(sbi, segno)); 1162 1131 f2fs_put_page(sum_page, 0); 1163 1132 1164 - if (get_valid_blocks(sbi, segno, false) == 0 || 1165 - !PageUptodate(sum_page) || 1166 - unlikely(f2fs_cp_error(sbi))) 1167 - goto next; 1133 + if (get_valid_blocks(sbi, segno, false) == 0) 1134 + goto freed; 1135 + if (__is_large_section(sbi) && 1136 + migrated >= sbi->migration_granularity) 1137 + goto skip; 1138 + if (!PageUptodate(sum_page) || unlikely(f2fs_cp_error(sbi))) 1139 + goto skip; 1168 1140 1169 1141 sum = page_address(sum_page); 1170 1142 if (type != GET_SUM_TYPE((&sum->footer))) { ··· 1175 1141 "type [%d, %d] in SSA and SIT", 1176 1142 segno, type, GET_SUM_TYPE((&sum->footer))); 1177 1143 set_sbi_flag(sbi, SBI_NEED_FSCK); 1178 - goto next; 1144 + goto skip; 1179 1145 } 1180 1146 1181 1147 /* ··· 1194 1160 1195 1161 stat_inc_seg_count(sbi, type, gc_type); 1196 1162 1163 + freed: 1197 1164 if (gc_type == FG_GC && 1198 1165 get_valid_blocks(sbi, segno, false) == 0) 1199 1166 seg_freed++; 1200 - next: 1167 + migrated++; 1168 + 1169 + if (__is_large_section(sbi) && segno + 1 < end_segno) 1170 + sbi->next_victim_seg[gc_type] = segno + 1; 1171 + skip: 1201 1172 f2fs_put_page(sum_page, 0); 1202 1173 } 1203 1174 ··· 1346 1307 sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES; 1347 1308 1348 1309 /* give warm/cold data area from slower device */ 1349 - if (sbi->s_ndevs && sbi->segs_per_sec == 1) 1310 + if (sbi->s_ndevs && !__is_large_section(sbi)) 1350 1311 SIT_I(sbi)->last_victim[ALLOC_NEXT] = 1351 1312 GET_SEGNO(sbi, FDEV(0).end_blk) + 1; 1352 1313 }
+10 -10
fs/f2fs/inline.c
··· 72 72 73 73 addr = inline_data_addr(inode, ipage); 74 74 75 - f2fs_wait_on_page_writeback(ipage, NODE, true); 75 + f2fs_wait_on_page_writeback(ipage, NODE, true, true); 76 76 memset(addr + from, 0, MAX_INLINE_DATA(inode) - from); 77 77 set_page_dirty(ipage); 78 78 ··· 161 161 fio.old_blkaddr = dn->data_blkaddr; 162 162 set_inode_flag(dn->inode, FI_HOT_DATA); 163 163 f2fs_outplace_write_data(dn, &fio); 164 - f2fs_wait_on_page_writeback(page, DATA, true); 164 + f2fs_wait_on_page_writeback(page, DATA, true, true); 165 165 if (dirty) { 166 166 inode_dec_dirty_pages(dn->inode); 167 167 f2fs_remove_dirty_inode(dn->inode); ··· 236 236 237 237 f2fs_bug_on(F2FS_I_SB(inode), page->index); 238 238 239 - f2fs_wait_on_page_writeback(dn.inode_page, NODE, true); 239 + f2fs_wait_on_page_writeback(dn.inode_page, NODE, true, true); 240 240 src_addr = kmap_atomic(page); 241 241 dst_addr = inline_data_addr(inode, dn.inode_page); 242 242 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); ··· 277 277 ipage = f2fs_get_node_page(sbi, inode->i_ino); 278 278 f2fs_bug_on(sbi, IS_ERR(ipage)); 279 279 280 - f2fs_wait_on_page_writeback(ipage, NODE, true); 280 + f2fs_wait_on_page_writeback(ipage, NODE, true, true); 281 281 282 282 src_addr = inline_data_addr(inode, npage); 283 283 dst_addr = inline_data_addr(inode, ipage); ··· 391 391 goto out; 392 392 } 393 393 394 - f2fs_wait_on_page_writeback(page, DATA, true); 394 + f2fs_wait_on_page_writeback(page, DATA, true, true); 395 395 396 396 dentry_blk = page_address(page); 397 397 ··· 501 501 502 502 stat_dec_inline_dir(dir); 503 503 clear_inode_flag(dir, FI_INLINE_DENTRY); 504 - kfree(backup_dentry); 504 + kvfree(backup_dentry); 505 505 return 0; 506 506 recover: 507 507 lock_page(ipage); 508 - f2fs_wait_on_page_writeback(ipage, NODE, true); 508 + f2fs_wait_on_page_writeback(ipage, NODE, true, true); 509 509 memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir)); 510 510 f2fs_i_depth_write(dir, 0); 511 511 f2fs_i_size_write(dir, MAX_INLINE_DATA(dir)); 512 512 set_page_dirty(ipage); 513 513 f2fs_put_page(ipage, 1); 514 514 515 - kfree(backup_dentry); 515 + kvfree(backup_dentry); 516 516 return err; 517 517 } 518 518 ··· 565 565 } 566 566 } 567 567 568 - f2fs_wait_on_page_writeback(ipage, NODE, true); 568 + f2fs_wait_on_page_writeback(ipage, NODE, true, true); 569 569 570 570 name_hash = f2fs_dentry_hash(new_name, NULL); 571 571 f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos); ··· 597 597 int i; 598 598 599 599 lock_page(page); 600 - f2fs_wait_on_page_writeback(page, NODE, true); 600 + f2fs_wait_on_page_writeback(page, NODE, true, true); 601 601 602 602 inline_dentry = inline_data_addr(dir, page); 603 603 make_dentry_ptr_inline(dir, &d, inline_dentry);
+11 -11
fs/f2fs/inode.c
··· 103 103 104 104 while (start < end) { 105 105 if (*start++) { 106 - f2fs_wait_on_page_writeback(ipage, NODE, true); 106 + f2fs_wait_on_page_writeback(ipage, NODE, true, true); 107 107 108 108 set_inode_flag(inode, FI_DATA_EXIST); 109 109 set_raw_inline(inode, F2FS_INODE(ipage)); ··· 118 118 { 119 119 struct f2fs_inode *ri = &F2FS_NODE(page)->i; 120 120 121 - if (!f2fs_sb_has_inode_chksum(sbi->sb)) 121 + if (!f2fs_sb_has_inode_chksum(sbi)) 122 122 return false; 123 123 124 124 if (!IS_INODE(page) || !(ri->i_inline & F2FS_EXTRA_ATTR)) ··· 218 218 return false; 219 219 } 220 220 221 - if (f2fs_sb_has_flexible_inline_xattr(sbi->sb) 221 + if (f2fs_sb_has_flexible_inline_xattr(sbi) 222 222 && !f2fs_has_extra_attr(inode)) { 223 223 set_sbi_flag(sbi, SBI_NEED_FSCK); 224 224 f2fs_msg(sbi->sb, KERN_WARNING, ··· 228 228 } 229 229 230 230 if (f2fs_has_extra_attr(inode) && 231 - !f2fs_sb_has_extra_attr(sbi->sb)) { 231 + !f2fs_sb_has_extra_attr(sbi)) { 232 232 set_sbi_flag(sbi, SBI_NEED_FSCK); 233 233 f2fs_msg(sbi->sb, KERN_WARNING, 234 234 "%s: inode (ino=%lx) is with extra_attr, " ··· 340 340 fi->i_extra_isize = f2fs_has_extra_attr(inode) ? 341 341 le16_to_cpu(ri->i_extra_isize) : 0; 342 342 343 - if (f2fs_sb_has_flexible_inline_xattr(sbi->sb)) { 343 + if (f2fs_sb_has_flexible_inline_xattr(sbi)) { 344 344 fi->i_inline_xattr_size = le16_to_cpu(ri->i_inline_xattr_size); 345 345 } else if (f2fs_has_inline_xattr(inode) || 346 346 f2fs_has_inline_dentry(inode)) { ··· 390 390 if (fi->i_flags & F2FS_PROJINHERIT_FL) 391 391 set_inode_flag(inode, FI_PROJ_INHERIT); 392 392 393 - if (f2fs_has_extra_attr(inode) && f2fs_sb_has_project_quota(sbi->sb) && 393 + if (f2fs_has_extra_attr(inode) && f2fs_sb_has_project_quota(sbi) && 394 394 F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_projid)) 395 395 i_projid = (projid_t)le32_to_cpu(ri->i_projid); 396 396 else 397 397 i_projid = F2FS_DEF_PROJID; 398 398 fi->i_projid = make_kprojid(&init_user_ns, i_projid); 399 399 400 - if (f2fs_has_extra_attr(inode) && f2fs_sb_has_inode_crtime(sbi->sb) && 400 + if (f2fs_has_extra_attr(inode) && f2fs_sb_has_inode_crtime(sbi) && 401 401 F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_crtime)) { 402 402 fi->i_crtime.tv_sec = le64_to_cpu(ri->i_crtime); 403 403 fi->i_crtime.tv_nsec = le32_to_cpu(ri->i_crtime_nsec); ··· 497 497 struct f2fs_inode *ri; 498 498 struct extent_tree *et = F2FS_I(inode)->extent_tree; 499 499 500 - f2fs_wait_on_page_writeback(node_page, NODE, true); 500 + f2fs_wait_on_page_writeback(node_page, NODE, true, true); 501 501 set_page_dirty(node_page); 502 502 503 503 f2fs_inode_synced(inode); ··· 542 542 if (f2fs_has_extra_attr(inode)) { 543 543 ri->i_extra_isize = cpu_to_le16(F2FS_I(inode)->i_extra_isize); 544 544 545 - if (f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(inode)->sb)) 545 + if (f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(inode))) 546 546 ri->i_inline_xattr_size = 547 547 cpu_to_le16(F2FS_I(inode)->i_inline_xattr_size); 548 548 549 - if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)->sb) && 549 + if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)) && 550 550 F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize, 551 551 i_projid)) { 552 552 projid_t i_projid; ··· 556 556 ri->i_projid = cpu_to_le32(i_projid); 557 557 } 558 558 559 - if (f2fs_sb_has_inode_crtime(F2FS_I_SB(inode)->sb) && 559 + if (f2fs_sb_has_inode_crtime(F2FS_I_SB(inode)) && 560 560 F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize, 561 561 i_crtime)) { 562 562 ri->i_crtime =
+4 -4
fs/f2fs/namei.c
··· 61 61 goto fail; 62 62 } 63 63 64 - if (f2fs_sb_has_project_quota(sbi->sb) && 64 + if (f2fs_sb_has_project_quota(sbi) && 65 65 (F2FS_I(dir)->i_flags & F2FS_PROJINHERIT_FL)) 66 66 F2FS_I(inode)->i_projid = F2FS_I(dir)->i_projid; 67 67 else ··· 79 79 f2fs_may_encrypt(inode)) 80 80 f2fs_set_encrypted_inode(inode); 81 81 82 - if (f2fs_sb_has_extra_attr(sbi->sb)) { 82 + if (f2fs_sb_has_extra_attr(sbi)) { 83 83 set_inode_flag(inode, FI_EXTRA_ATTR); 84 84 F2FS_I(inode)->i_extra_isize = F2FS_TOTAL_EXTRA_ATTR_SIZE; 85 85 } ··· 92 92 if (f2fs_may_inline_dentry(inode)) 93 93 set_inode_flag(inode, FI_INLINE_DENTRY); 94 94 95 - if (f2fs_sb_has_flexible_inline_xattr(sbi->sb)) { 95 + if (f2fs_sb_has_flexible_inline_xattr(sbi)) { 96 96 f2fs_bug_on(sbi, !f2fs_has_extra_attr(inode)); 97 97 if (f2fs_has_inline_xattr(inode)) 98 98 xattr_size = F2FS_OPTION(sbi).inline_xattr_size; ··· 635 635 f2fs_handle_failed_inode(inode); 636 636 out_free_encrypted_link: 637 637 if (disk_link.name != (unsigned char *)symname) 638 - kfree(disk_link.name); 638 + kvfree(disk_link.name); 639 639 return err; 640 640 } 641 641
+21 -21
fs/f2fs/node.c
··· 826 826 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); 827 827 struct node_info ni; 828 828 int err; 829 + pgoff_t index; 829 830 830 831 err = f2fs_get_node_info(sbi, dn->nid, &ni); 831 832 if (err) ··· 846 845 clear_node_page_dirty(dn->node_page); 847 846 set_sbi_flag(sbi, SBI_IS_DIRTY); 848 847 848 + index = dn->node_page->index; 849 849 f2fs_put_page(dn->node_page, 1); 850 850 851 851 invalidate_mapping_pages(NODE_MAPPING(sbi), 852 - dn->node_page->index, dn->node_page->index); 852 + index, index); 853 853 854 854 dn->node_page = NULL; 855 855 trace_f2fs_truncate_node(dn->inode, dn->nid, ni.blk_addr); ··· 1106 1104 ri->i_nid[offset[0] - NODE_DIR1_BLOCK]) { 1107 1105 lock_page(page); 1108 1106 BUG_ON(page->mapping != NODE_MAPPING(sbi)); 1109 - f2fs_wait_on_page_writeback(page, NODE, true); 1107 + f2fs_wait_on_page_writeback(page, NODE, true, true); 1110 1108 ri->i_nid[offset[0] - NODE_DIR1_BLOCK] = 0; 1111 1109 set_page_dirty(page); 1112 1110 unlock_page(page); ··· 1234 1232 new_ni.version = 0; 1235 1233 set_node_addr(sbi, &new_ni, NEW_ADDR, false); 1236 1234 1237 - f2fs_wait_on_page_writeback(page, NODE, true); 1235 + f2fs_wait_on_page_writeback(page, NODE, true, true); 1238 1236 fill_node_footer(page, dn->nid, dn->inode->i_ino, ofs, true); 1239 1237 set_cold_node(page, S_ISDIR(dn->inode->i_mode)); 1240 1238 if (!PageUptodate(page)) ··· 1598 1596 .for_reclaim = 0, 1599 1597 }; 1600 1598 1601 - set_page_dirty(node_page); 1602 - f2fs_wait_on_page_writeback(node_page, NODE, true); 1599 + f2fs_wait_on_page_writeback(node_page, NODE, true, true); 1603 1600 1604 - f2fs_bug_on(F2FS_P_SB(node_page), PageWriteback(node_page)); 1601 + set_page_dirty(node_page); 1602 + 1605 1603 if (!clear_page_dirty_for_io(node_page)) { 1606 1604 err = -EAGAIN; 1607 1605 goto out_page; ··· 1689 1687 goto continue_unlock; 1690 1688 } 1691 1689 1692 - f2fs_wait_on_page_writeback(page, NODE, true); 1693 - BUG_ON(PageWriteback(page)); 1690 + f2fs_wait_on_page_writeback(page, NODE, true, true); 1694 1691 1695 1692 set_fsync_mark(page, 0); 1696 1693 set_dentry_mark(page, 0); ··· 1740 1739 "Retry to write fsync mark: ino=%u, idx=%lx", 1741 1740 ino, last_page->index); 1742 1741 lock_page(last_page); 1743 - f2fs_wait_on_page_writeback(last_page, NODE, true); 1742 + f2fs_wait_on_page_writeback(last_page, NODE, true, true); 1744 1743 set_page_dirty(last_page); 1745 1744 unlock_page(last_page); 1746 1745 goto retry; ··· 1821 1820 goto lock_node; 1822 1821 } 1823 1822 1824 - f2fs_wait_on_page_writeback(page, NODE, true); 1823 + f2fs_wait_on_page_writeback(page, NODE, true, true); 1825 1824 1826 - BUG_ON(PageWriteback(page)); 1827 1825 if (!clear_page_dirty_for_io(page)) 1828 1826 goto continue_unlock; 1829 1827 ··· 1889 1889 get_page(page); 1890 1890 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); 1891 1891 1892 - f2fs_wait_on_page_writeback(page, NODE, true); 1892 + f2fs_wait_on_page_writeback(page, NODE, true, false); 1893 1893 if (TestClearPageError(page)) 1894 1894 ret = -EIO; 1895 1895 ··· 2467 2467 src_addr = inline_xattr_addr(inode, page); 2468 2468 inline_size = inline_xattr_size(inode); 2469 2469 2470 - f2fs_wait_on_page_writeback(ipage, NODE, true); 2470 + f2fs_wait_on_page_writeback(ipage, NODE, true, true); 2471 2471 memcpy(dst_addr, src_addr, inline_size); 2472 2472 update_inode: 2473 2473 f2fs_update_inode(inode, ipage); ··· 2561 2561 if (dst->i_inline & F2FS_EXTRA_ATTR) { 2562 2562 dst->i_extra_isize = src->i_extra_isize; 2563 2563 2564 - if (f2fs_sb_has_flexible_inline_xattr(sbi->sb) && 2564 + if (f2fs_sb_has_flexible_inline_xattr(sbi) && 2565 2565 F2FS_FITS_IN_INODE(src, le16_to_cpu(src->i_extra_isize), 2566 2566 i_inline_xattr_size)) 2567 2567 dst->i_inline_xattr_size = src->i_inline_xattr_size; 2568 2568 2569 - if (f2fs_sb_has_project_quota(sbi->sb) && 2569 + if (f2fs_sb_has_project_quota(sbi) && 2570 2570 F2FS_FITS_IN_INODE(src, le16_to_cpu(src->i_extra_isize), 2571 2571 i_projid)) 2572 2572 dst->i_projid = src->i_projid; 2573 2573 2574 - if (f2fs_sb_has_inode_crtime(sbi->sb) && 2574 + if (f2fs_sb_has_inode_crtime(sbi) && 2575 2575 F2FS_FITS_IN_INODE(src, le16_to_cpu(src->i_extra_isize), 2576 2576 i_crtime_nsec)) { 2577 2577 dst->i_crtime = src->i_crtime; ··· 3113 3113 3114 3114 for (i = 0; i < nm_i->nat_blocks; i++) 3115 3115 kvfree(nm_i->free_nid_bitmap[i]); 3116 - kfree(nm_i->free_nid_bitmap); 3116 + kvfree(nm_i->free_nid_bitmap); 3117 3117 } 3118 3118 kvfree(nm_i->free_nid_count); 3119 3119 3120 - kfree(nm_i->nat_bitmap); 3121 - kfree(nm_i->nat_bits); 3120 + kvfree(nm_i->nat_bitmap); 3121 + kvfree(nm_i->nat_bits); 3122 3122 #ifdef CONFIG_F2FS_CHECK_FS 3123 - kfree(nm_i->nat_bitmap_mir); 3123 + kvfree(nm_i->nat_bitmap_mir); 3124 3124 #endif 3125 3125 sbi->nm_info = NULL; 3126 - kfree(nm_i); 3126 + kvfree(nm_i); 3127 3127 } 3128 3128 3129 3129 int __init f2fs_create_node_manager_caches(void)
+1 -1
fs/f2fs/node.h
··· 361 361 { 362 362 struct f2fs_node *rn = F2FS_NODE(p); 363 363 364 - f2fs_wait_on_page_writeback(p, NODE, true); 364 + f2fs_wait_on_page_writeback(p, NODE, true, true); 365 365 366 366 if (i) 367 367 rn->i.i_nid[off - NODE_DIR1_BLOCK] = cpu_to_le32(nid);
+2 -2
fs/f2fs/recovery.c
··· 250 250 i_gid_write(inode, le32_to_cpu(raw->i_gid)); 251 251 252 252 if (raw->i_inline & F2FS_EXTRA_ATTR) { 253 - if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)->sb) && 253 + if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)) && 254 254 F2FS_FITS_IN_INODE(raw, le16_to_cpu(raw->i_extra_isize), 255 255 i_projid)) { 256 256 projid_t i_projid; ··· 539 539 goto out; 540 540 } 541 541 542 - f2fs_wait_on_page_writeback(dn.node_page, NODE, true); 542 + f2fs_wait_on_page_writeback(dn.node_page, NODE, true, true); 543 543 544 544 err = f2fs_get_node_info(sbi, dn.nid, &ni); 545 545 if (err)
+55 -46
fs/f2fs/segment.c
··· 229 229 230 230 lock_page(page); 231 231 232 - f2fs_wait_on_page_writeback(page, DATA, true); 232 + f2fs_wait_on_page_writeback(page, DATA, true, true); 233 233 234 234 if (recover) { 235 235 struct dnode_of_data dn; ··· 387 387 if (page->mapping == inode->i_mapping) { 388 388 trace_f2fs_commit_inmem_page(page, INMEM); 389 389 390 + f2fs_wait_on_page_writeback(page, DATA, true, true); 391 + 390 392 set_page_dirty(page); 391 - f2fs_wait_on_page_writeback(page, DATA, true); 392 393 if (clear_page_dirty_for_io(page)) { 393 394 inode_dec_dirty_pages(inode); 394 395 f2fs_remove_dirty_inode(inode); ··· 621 620 return 0; 622 621 623 622 if (!test_opt(sbi, FLUSH_MERGE)) { 623 + atomic_inc(&fcc->queued_flush); 624 624 ret = submit_flush_wait(sbi, ino); 625 + atomic_dec(&fcc->queued_flush); 625 626 atomic_inc(&fcc->issued_flush); 626 627 return ret; 627 628 } 628 629 629 - if (atomic_inc_return(&fcc->issing_flush) == 1 || sbi->s_ndevs > 1) { 630 + if (atomic_inc_return(&fcc->queued_flush) == 1 || sbi->s_ndevs > 1) { 630 631 ret = submit_flush_wait(sbi, ino); 631 - atomic_dec(&fcc->issing_flush); 632 + atomic_dec(&fcc->queued_flush); 632 633 633 634 atomic_inc(&fcc->issued_flush); 634 635 return ret; ··· 649 646 650 647 if (fcc->f2fs_issue_flush) { 651 648 wait_for_completion(&cmd.wait); 652 - atomic_dec(&fcc->issing_flush); 649 + atomic_dec(&fcc->queued_flush); 653 650 } else { 654 651 struct llist_node *list; 655 652 656 653 list = llist_del_all(&fcc->issue_list); 657 654 if (!list) { 658 655 wait_for_completion(&cmd.wait); 659 - atomic_dec(&fcc->issing_flush); 656 + atomic_dec(&fcc->queued_flush); 660 657 } else { 661 658 struct flush_cmd *tmp, *next; 662 659 ··· 665 662 llist_for_each_entry_safe(tmp, next, list, llnode) { 666 663 if (tmp == &cmd) { 667 664 cmd.ret = ret; 668 - atomic_dec(&fcc->issing_flush); 665 + atomic_dec(&fcc->queued_flush); 669 666 continue; 670 667 } 671 668 tmp->ret = ret; ··· 694 691 if (!fcc) 695 692 return -ENOMEM; 696 693 atomic_set(&fcc->issued_flush, 0); 697 - atomic_set(&fcc->issing_flush, 0); 694 + atomic_set(&fcc->queued_flush, 0); 698 695 init_waitqueue_head(&fcc->flush_wait_queue); 699 696 init_llist_head(&fcc->issue_list); 700 697 SM_I(sbi)->fcc_info = fcc; ··· 706 703 "f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev)); 707 704 if (IS_ERR(fcc->f2fs_issue_flush)) { 708 705 err = PTR_ERR(fcc->f2fs_issue_flush); 709 - kfree(fcc); 706 + kvfree(fcc); 710 707 SM_I(sbi)->fcc_info = NULL; 711 708 return err; 712 709 } ··· 725 722 kthread_stop(flush_thread); 726 723 } 727 724 if (free) { 728 - kfree(fcc); 725 + kvfree(fcc); 729 726 SM_I(sbi)->fcc_info = NULL; 730 727 } 731 728 } ··· 910 907 dc->len = len; 911 908 dc->ref = 0; 912 909 dc->state = D_PREP; 913 - dc->issuing = 0; 910 + dc->queued = 0; 914 911 dc->error = 0; 915 912 init_completion(&dc->wait); 916 913 list_add_tail(&dc->list, pend_list); ··· 943 940 struct discard_cmd *dc) 944 941 { 945 942 if (dc->state == D_DONE) 946 - atomic_sub(dc->issuing, &dcc->issing_discard); 943 + atomic_sub(dc->queued, &dcc->queued_discard); 947 944 948 945 list_del(&dc->list); 949 946 rb_erase_cached(&dc->rb_node, &dcc->root); ··· 1146 1143 dc->bio_ref++; 1147 1144 spin_unlock_irqrestore(&dc->lock, flags); 1148 1145 1149 - atomic_inc(&dcc->issing_discard); 1150 - dc->issuing++; 1146 + atomic_inc(&dcc->queued_discard); 1147 + dc->queued++; 1151 1148 list_move_tail(&dc->list, wait_list); 1152 1149 1153 1150 /* sanity check on discard range */ 1154 - __check_sit_bitmap(sbi, start, start + len); 1151 + __check_sit_bitmap(sbi, lstart, lstart + len); 1155 1152 1156 1153 bio->bi_private = dc; 1157 1154 bio->bi_end_io = f2fs_submit_discard_endio; ··· 1652 1649 if (dcc->discard_wake) 1653 1650 dcc->discard_wake = 0; 1654 1651 1652 + /* clean up pending candidates before going to sleep */ 1653 + if (atomic_read(&dcc->queued_discard)) 1654 + __wait_all_discard_cmd(sbi, NULL); 1655 + 1655 1656 if (try_to_freeze()) 1656 1657 continue; 1657 1658 if (f2fs_readonly(sbi->sb)) ··· 1741 1734 struct block_device *bdev, block_t blkstart, block_t blklen) 1742 1735 { 1743 1736 #ifdef CONFIG_BLK_DEV_ZONED 1744 - if (f2fs_sb_has_blkzoned(sbi->sb) && 1737 + if (f2fs_sb_has_blkzoned(sbi) && 1745 1738 bdev_zoned_model(bdev) != BLK_ZONED_NONE) 1746 1739 return __f2fs_issue_discard_zone(sbi, bdev, blkstart, blklen); 1747 1740 #endif ··· 1889 1882 unsigned int start = 0, end = -1; 1890 1883 unsigned int secno, start_segno; 1891 1884 bool force = (cpc->reason & CP_DISCARD); 1892 - bool need_align = test_opt(sbi, LFS) && sbi->segs_per_sec > 1; 1885 + bool need_align = test_opt(sbi, LFS) && __is_large_section(sbi); 1893 1886 1894 1887 mutex_lock(&dirty_i->seglist_lock); 1895 1888 ··· 1921 1914 (end - 1) <= cpc->trim_end) 1922 1915 continue; 1923 1916 1924 - if (!test_opt(sbi, LFS) || sbi->segs_per_sec == 1) { 1917 + if (!test_opt(sbi, LFS) || !__is_large_section(sbi)) { 1925 1918 f2fs_issue_discard(sbi, START_BLOCK(sbi, start), 1926 1919 (end - start) << sbi->log_blocks_per_seg); 1927 1920 continue; ··· 1953 1946 sbi->blocks_per_seg, cur_pos); 1954 1947 len = next_pos - cur_pos; 1955 1948 1956 - if (f2fs_sb_has_blkzoned(sbi->sb) || 1949 + if (f2fs_sb_has_blkzoned(sbi) || 1957 1950 (force && len < cpc->trim_minlen)) 1958 1951 goto skip; 1959 1952 ··· 2001 1994 INIT_LIST_HEAD(&dcc->fstrim_list); 2002 1995 mutex_init(&dcc->cmd_lock); 2003 1996 atomic_set(&dcc->issued_discard, 0); 2004 - atomic_set(&dcc->issing_discard, 0); 1997 + atomic_set(&dcc->queued_discard, 0); 2005 1998 atomic_set(&dcc->discard_cmd_cnt, 0); 2006 1999 dcc->nr_discards = 0; 2007 2000 dcc->max_discards = MAIN_SEGS(sbi) << sbi->log_blocks_per_seg; ··· 2017 2010 "f2fs_discard-%u:%u", MAJOR(dev), MINOR(dev)); 2018 2011 if (IS_ERR(dcc->f2fs_issue_discard)) { 2019 2012 err = PTR_ERR(dcc->f2fs_issue_discard); 2020 - kfree(dcc); 2013 + kvfree(dcc); 2021 2014 SM_I(sbi)->dcc_info = NULL; 2022 2015 return err; 2023 2016 } ··· 2034 2027 2035 2028 f2fs_stop_discard_thread(sbi); 2036 2029 2037 - kfree(dcc); 2030 + kvfree(dcc); 2038 2031 SM_I(sbi)->dcc_info = NULL; 2039 2032 } 2040 2033 ··· 2153 2146 /* update total number of valid blocks to be written in ckpt area */ 2154 2147 SIT_I(sbi)->written_valid_blocks += del; 2155 2148 2156 - if (sbi->segs_per_sec > 1) 2149 + if (__is_large_section(sbi)) 2157 2150 get_sec_entry(sbi, segno)->valid_blocks += del; 2158 2151 } 2159 2152 ··· 2419 2412 static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type) 2420 2413 { 2421 2414 /* if segs_per_sec is large than 1, we need to keep original policy. */ 2422 - if (sbi->segs_per_sec != 1) 2415 + if (__is_large_section(sbi)) 2423 2416 return CURSEG_I(sbi, type)->segno; 2424 2417 2425 2418 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) ··· 2729 2722 struct discard_policy dpolicy; 2730 2723 unsigned long long trimmed = 0; 2731 2724 int err = 0; 2732 - bool need_align = test_opt(sbi, LFS) && sbi->segs_per_sec > 1; 2725 + bool need_align = test_opt(sbi, LFS) && __is_large_section(sbi); 2733 2726 2734 2727 if (start >= MAX_BLKADDR(sbi) || range->len < sbi->blocksize) 2735 2728 return -EINVAL; ··· 3279 3272 } 3280 3273 3281 3274 void f2fs_wait_on_page_writeback(struct page *page, 3282 - enum page_type type, bool ordered) 3275 + enum page_type type, bool ordered, bool locked) 3283 3276 { 3284 3277 if (PageWriteback(page)) { 3285 3278 struct f2fs_sb_info *sbi = F2FS_P_SB(page); 3286 3279 3287 3280 f2fs_submit_merged_write_cond(sbi, NULL, page, 0, type); 3288 - if (ordered) 3281 + if (ordered) { 3289 3282 wait_on_page_writeback(page); 3290 - else 3283 + f2fs_bug_on(sbi, locked && PageWriteback(page)); 3284 + } else { 3291 3285 wait_for_stable_page(page); 3286 + } 3292 3287 } 3293 3288 } 3294 3289 ··· 3307 3298 3308 3299 cpage = find_lock_page(META_MAPPING(sbi), blkaddr); 3309 3300 if (cpage) { 3310 - f2fs_wait_on_page_writeback(cpage, DATA, true); 3301 + f2fs_wait_on_page_writeback(cpage, DATA, true, true); 3311 3302 f2fs_put_page(cpage, 1); 3312 3303 } 3313 3304 } ··· 3889 3880 if (!sit_i->tmp_map) 3890 3881 return -ENOMEM; 3891 3882 3892 - if (sbi->segs_per_sec > 1) { 3883 + if (__is_large_section(sbi)) { 3893 3884 sit_i->sec_entries = 3894 3885 f2fs_kvzalloc(sbi, array_size(sizeof(struct sec_entry), 3895 3886 MAIN_SECS(sbi)), ··· 4044 4035 se->valid_blocks; 4045 4036 } 4046 4037 4047 - if (sbi->segs_per_sec > 1) 4038 + if (__is_large_section(sbi)) 4048 4039 get_sec_entry(sbi, start)->valid_blocks += 4049 4040 se->valid_blocks; 4050 4041 } ··· 4088 4079 sbi->discard_blks -= se->valid_blocks; 4089 4080 } 4090 4081 4091 - if (sbi->segs_per_sec > 1) { 4082 + if (__is_large_section(sbi)) { 4092 4083 get_sec_entry(sbi, start)->valid_blocks += 4093 4084 se->valid_blocks; 4094 4085 get_sec_entry(sbi, start)->valid_blocks -= ··· 4323 4314 4324 4315 destroy_victim_secmap(sbi); 4325 4316 SM_I(sbi)->dirty_info = NULL; 4326 - kfree(dirty_i); 4317 + kvfree(dirty_i); 4327 4318 } 4328 4319 4329 4320 static void destroy_curseg(struct f2fs_sb_info *sbi) ··· 4335 4326 return; 4336 4327 SM_I(sbi)->curseg_array = NULL; 4337 4328 for (i = 0; i < NR_CURSEG_TYPE; i++) { 4338 - kfree(array[i].sum_blk); 4339 - kfree(array[i].journal); 4329 + kvfree(array[i].sum_blk); 4330 + kvfree(array[i].journal); 4340 4331 } 4341 - kfree(array); 4332 + kvfree(array); 4342 4333 } 4343 4334 4344 4335 static void destroy_free_segmap(struct f2fs_sb_info *sbi) ··· 4349 4340 SM_I(sbi)->free_info = NULL; 4350 4341 kvfree(free_i->free_segmap); 4351 4342 kvfree(free_i->free_secmap); 4352 - kfree(free_i); 4343 + kvfree(free_i); 4353 4344 } 4354 4345 4355 4346 static void destroy_sit_info(struct f2fs_sb_info *sbi) ··· 4362 4353 4363 4354 if (sit_i->sentries) { 4364 4355 for (start = 0; start < MAIN_SEGS(sbi); start++) { 4365 - kfree(sit_i->sentries[start].cur_valid_map); 4356 + kvfree(sit_i->sentries[start].cur_valid_map); 4366 4357 #ifdef CONFIG_F2FS_CHECK_FS 4367 - kfree(sit_i->sentries[start].cur_valid_map_mir); 4358 + kvfree(sit_i->sentries[start].cur_valid_map_mir); 4368 4359 #endif 4369 - kfree(sit_i->sentries[start].ckpt_valid_map); 4370 - kfree(sit_i->sentries[start].discard_map); 4360 + kvfree(sit_i->sentries[start].ckpt_valid_map); 4361 + kvfree(sit_i->sentries[start].discard_map); 4371 4362 } 4372 4363 } 4373 - kfree(sit_i->tmp_map); 4364 + kvfree(sit_i->tmp_map); 4374 4365 4375 4366 kvfree(sit_i->sentries); 4376 4367 kvfree(sit_i->sec_entries); 4377 4368 kvfree(sit_i->dirty_sentries_bitmap); 4378 4369 4379 4370 SM_I(sbi)->sit_info = NULL; 4380 - kfree(sit_i->sit_bitmap); 4371 + kvfree(sit_i->sit_bitmap); 4381 4372 #ifdef CONFIG_F2FS_CHECK_FS 4382 - kfree(sit_i->sit_bitmap_mir); 4373 + kvfree(sit_i->sit_bitmap_mir); 4383 4374 #endif 4384 - kfree(sit_i); 4375 + kvfree(sit_i); 4385 4376 } 4386 4377 4387 4378 void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi) ··· 4397 4388 destroy_free_segmap(sbi); 4398 4389 destroy_sit_info(sbi); 4399 4390 sbi->sm_info = NULL; 4400 - kfree(sm_info); 4391 + kvfree(sm_info); 4401 4392 } 4402 4393 4403 4394 int __init f2fs_create_segment_manager_caches(void)
+1 -1
fs/f2fs/segment.h
··· 333 333 * In order to get # of valid blocks in a section instantly from many 334 334 * segments, f2fs manages two counting structures separately. 335 335 */ 336 - if (use_section && sbi->segs_per_sec > 1) 336 + if (use_section && __is_large_section(sbi)) 337 337 return get_sec_entry(sbi, segno)->valid_blocks; 338 338 else 339 339 return get_seg_entry(sbi, segno)->valid_blocks;
+1 -1
fs/f2fs/shrinker.c
··· 135 135 f2fs_shrink_extent_tree(sbi, __count_extent_cache(sbi)); 136 136 137 137 spin_lock(&f2fs_list_lock); 138 - list_del(&sbi->s_list); 138 + list_del_init(&sbi->s_list); 139 139 spin_unlock(&f2fs_list_lock); 140 140 }
+85 -85
fs/f2fs/super.c
··· 38 38 39 39 #ifdef CONFIG_F2FS_FAULT_INJECTION 40 40 41 - char *f2fs_fault_name[FAULT_MAX] = { 41 + const char *f2fs_fault_name[FAULT_MAX] = { 42 42 [FAULT_KMALLOC] = "kmalloc", 43 43 [FAULT_KVMALLOC] = "kvmalloc", 44 44 [FAULT_PAGE_ALLOC] = "page alloc", ··· 259 259 "quota options when quota turned on"); 260 260 return -EINVAL; 261 261 } 262 - if (f2fs_sb_has_quota_ino(sb)) { 262 + if (f2fs_sb_has_quota_ino(sbi)) { 263 263 f2fs_msg(sb, KERN_INFO, 264 264 "QUOTA feature is enabled, so ignore qf_name"); 265 265 return 0; ··· 289 289 set_opt(sbi, QUOTA); 290 290 return 0; 291 291 errout: 292 - kfree(qname); 292 + kvfree(qname); 293 293 return ret; 294 294 } 295 295 ··· 302 302 " when quota turned on"); 303 303 return -EINVAL; 304 304 } 305 - kfree(F2FS_OPTION(sbi).s_qf_names[qtype]); 305 + kvfree(F2FS_OPTION(sbi).s_qf_names[qtype]); 306 306 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL; 307 307 return 0; 308 308 } ··· 314 314 * 'grpquota' mount options are allowed even without quota feature 315 315 * to support legacy quotas in quota files. 316 316 */ 317 - if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi->sb)) { 317 + if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) { 318 318 f2fs_msg(sbi->sb, KERN_ERR, "Project quota feature not enabled. " 319 319 "Cannot enable project quota enforcement."); 320 320 return -1; ··· 348 348 } 349 349 } 350 350 351 - if (f2fs_sb_has_quota_ino(sbi->sb) && F2FS_OPTION(sbi).s_jquota_fmt) { 351 + if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) { 352 352 f2fs_msg(sbi->sb, KERN_INFO, 353 353 "QUOTA feature is enabled, so ignore jquota_fmt"); 354 354 F2FS_OPTION(sbi).s_jquota_fmt = 0; ··· 399 399 set_opt(sbi, BG_GC); 400 400 set_opt(sbi, FORCE_FG_GC); 401 401 } else { 402 - kfree(name); 402 + kvfree(name); 403 403 return -EINVAL; 404 404 } 405 - kfree(name); 405 + kvfree(name); 406 406 break; 407 407 case Opt_disable_roll_forward: 408 408 set_opt(sbi, DISABLE_ROLL_FORWARD); ··· 417 417 set_opt(sbi, DISCARD); 418 418 break; 419 419 case Opt_nodiscard: 420 - if (f2fs_sb_has_blkzoned(sb)) { 420 + if (f2fs_sb_has_blkzoned(sbi)) { 421 421 f2fs_msg(sb, KERN_WARNING, 422 422 "discard is required for zoned block devices"); 423 423 return -EINVAL; ··· 566 566 return -ENOMEM; 567 567 if (strlen(name) == 8 && 568 568 !strncmp(name, "adaptive", 8)) { 569 - if (f2fs_sb_has_blkzoned(sb)) { 569 + if (f2fs_sb_has_blkzoned(sbi)) { 570 570 f2fs_msg(sb, KERN_WARNING, 571 571 "adaptive mode is not allowed with " 572 572 "zoned block device feature"); 573 - kfree(name); 573 + kvfree(name); 574 574 return -EINVAL; 575 575 } 576 576 set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE); ··· 578 578 !strncmp(name, "lfs", 3)) { 579 579 set_opt_mode(sbi, F2FS_MOUNT_LFS); 580 580 } else { 581 - kfree(name); 581 + kvfree(name); 582 582 return -EINVAL; 583 583 } 584 - kfree(name); 584 + kvfree(name); 585 585 break; 586 586 case Opt_io_size_bits: 587 587 if (args->from && match_int(args, &arg)) ··· 714 714 !strncmp(name, "fs-based", 8)) { 715 715 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS; 716 716 } else { 717 - kfree(name); 717 + kvfree(name); 718 718 return -EINVAL; 719 719 } 720 - kfree(name); 720 + kvfree(name); 721 721 break; 722 722 case Opt_alloc: 723 723 name = match_strdup(&args[0]); ··· 731 731 !strncmp(name, "reuse", 5)) { 732 732 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; 733 733 } else { 734 - kfree(name); 734 + kvfree(name); 735 735 return -EINVAL; 736 736 } 737 - kfree(name); 737 + kvfree(name); 738 738 break; 739 739 case Opt_fsync: 740 740 name = match_strdup(&args[0]); ··· 751 751 F2FS_OPTION(sbi).fsync_mode = 752 752 FSYNC_MODE_NOBARRIER; 753 753 } else { 754 - kfree(name); 754 + kvfree(name); 755 755 return -EINVAL; 756 756 } 757 - kfree(name); 757 + kvfree(name); 758 758 break; 759 759 case Opt_test_dummy_encryption: 760 760 #ifdef CONFIG_F2FS_FS_ENCRYPTION 761 - if (!f2fs_sb_has_encrypt(sb)) { 761 + if (!f2fs_sb_has_encrypt(sbi)) { 762 762 f2fs_msg(sb, KERN_ERR, "Encrypt feature is off"); 763 763 return -EINVAL; 764 764 } ··· 783 783 !strncmp(name, "disable", 7)) { 784 784 set_opt(sbi, DISABLE_CHECKPOINT); 785 785 } else { 786 - kfree(name); 786 + kvfree(name); 787 787 return -EINVAL; 788 788 } 789 - kfree(name); 789 + kvfree(name); 790 790 break; 791 791 default: 792 792 f2fs_msg(sb, KERN_ERR, ··· 799 799 if (f2fs_check_quota_options(sbi)) 800 800 return -EINVAL; 801 801 #else 802 - if (f2fs_sb_has_quota_ino(sbi->sb) && !f2fs_readonly(sbi->sb)) { 802 + if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { 803 803 f2fs_msg(sbi->sb, KERN_INFO, 804 804 "Filesystem with quota feature cannot be mounted RDWR " 805 805 "without CONFIG_QUOTA"); 806 806 return -EINVAL; 807 807 } 808 - if (f2fs_sb_has_project_quota(sbi->sb) && !f2fs_readonly(sbi->sb)) { 808 + if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) { 809 809 f2fs_msg(sb, KERN_ERR, 810 810 "Filesystem with project quota feature cannot be " 811 811 "mounted RDWR without CONFIG_QUOTA"); ··· 821 821 } 822 822 823 823 if (test_opt(sbi, INLINE_XATTR_SIZE)) { 824 - if (!f2fs_sb_has_extra_attr(sb) || 825 - !f2fs_sb_has_flexible_inline_xattr(sb)) { 824 + if (!f2fs_sb_has_extra_attr(sbi) || 825 + !f2fs_sb_has_flexible_inline_xattr(sbi)) { 826 826 f2fs_msg(sb, KERN_ERR, 827 827 "extra_attr or flexible_inline_xattr " 828 828 "feature is off"); ··· 1017 1017 for (i = 0; i < sbi->s_ndevs; i++) { 1018 1018 blkdev_put(FDEV(i).bdev, FMODE_EXCL); 1019 1019 #ifdef CONFIG_BLK_DEV_ZONED 1020 - kfree(FDEV(i).blkz_type); 1020 + kvfree(FDEV(i).blkz_type); 1021 1021 #endif 1022 1022 } 1023 - kfree(sbi->devs); 1023 + kvfree(sbi->devs); 1024 1024 } 1025 1025 1026 1026 static void f2fs_put_super(struct super_block *sb) ··· 1058 1058 f2fs_write_checkpoint(sbi, &cpc); 1059 1059 } 1060 1060 1061 - /* f2fs_write_checkpoint can update stat informaion */ 1062 - f2fs_destroy_stats(sbi); 1063 - 1064 1061 /* 1065 1062 * normally superblock is clean, so we need to release this. 1066 1063 * In addition, EIO will skip do checkpoint, we need this as well. ··· 1077 1080 iput(sbi->node_inode); 1078 1081 iput(sbi->meta_inode); 1079 1082 1083 + /* 1084 + * iput() can update stat information, if f2fs_write_checkpoint() 1085 + * above failed with error. 1086 + */ 1087 + f2fs_destroy_stats(sbi); 1088 + 1080 1089 /* destroy f2fs internal modules */ 1081 1090 f2fs_destroy_node_manager(sbi); 1082 1091 f2fs_destroy_segment_manager(sbi); 1083 1092 1084 - kfree(sbi->ckpt); 1093 + kvfree(sbi->ckpt); 1085 1094 1086 1095 f2fs_unregister_sysfs(sbi); 1087 1096 1088 1097 sb->s_fs_info = NULL; 1089 1098 if (sbi->s_chksum_driver) 1090 1099 crypto_free_shash(sbi->s_chksum_driver); 1091 - kfree(sbi->raw_super); 1100 + kvfree(sbi->raw_super); 1092 1101 1093 1102 destroy_device_list(sbi); 1094 1103 mempool_destroy(sbi->write_io_dummy); 1095 1104 #ifdef CONFIG_QUOTA 1096 1105 for (i = 0; i < MAXQUOTAS; i++) 1097 - kfree(F2FS_OPTION(sbi).s_qf_names[i]); 1106 + kvfree(F2FS_OPTION(sbi).s_qf_names[i]); 1098 1107 #endif 1099 1108 destroy_percpu_info(sbi); 1100 1109 for (i = 0; i < NR_PAGE_TYPE; i++) 1101 - kfree(sbi->write_io[i]); 1102 - kfree(sbi); 1110 + kvfree(sbi->write_io[i]); 1111 + kvfree(sbi); 1103 1112 } 1104 1113 1105 1114 int f2fs_sync_fs(struct super_block *sb, int sync) ··· 1434 1431 sbi->sb->s_flags |= SB_LAZYTIME; 1435 1432 set_opt(sbi, FLUSH_MERGE); 1436 1433 set_opt(sbi, DISCARD); 1437 - if (f2fs_sb_has_blkzoned(sbi->sb)) 1434 + if (f2fs_sb_has_blkzoned(sbi)) 1438 1435 set_opt_mode(sbi, F2FS_MOUNT_LFS); 1439 1436 else 1440 1437 set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE); ··· 1460 1457 1461 1458 sbi->sb->s_flags |= SB_ACTIVE; 1462 1459 1463 - mutex_lock(&sbi->gc_mutex); 1464 1460 f2fs_update_time(sbi, DISABLE_TIME); 1465 1461 1466 1462 while (!f2fs_time_over(sbi, DISABLE_TIME)) { 1463 + mutex_lock(&sbi->gc_mutex); 1467 1464 err = f2fs_gc(sbi, true, false, NULL_SEGNO); 1468 1465 if (err == -ENODATA) 1469 1466 break; 1470 - if (err && err != -EAGAIN) { 1471 - mutex_unlock(&sbi->gc_mutex); 1467 + if (err && err != -EAGAIN) 1472 1468 return err; 1473 - } 1474 1469 } 1475 - mutex_unlock(&sbi->gc_mutex); 1476 1470 1477 1471 err = sync_filesystem(sbi->sb); 1478 1472 if (err) ··· 1531 1531 GFP_KERNEL); 1532 1532 if (!org_mount_opt.s_qf_names[i]) { 1533 1533 for (j = 0; j < i; j++) 1534 - kfree(org_mount_opt.s_qf_names[j]); 1534 + kvfree(org_mount_opt.s_qf_names[j]); 1535 1535 return -ENOMEM; 1536 1536 } 1537 1537 } else { ··· 1575 1575 sb->s_flags &= ~SB_RDONLY; 1576 1576 if (sb_any_quota_suspended(sb)) { 1577 1577 dquot_resume(sb, -1); 1578 - } else if (f2fs_sb_has_quota_ino(sb)) { 1578 + } else if (f2fs_sb_has_quota_ino(sbi)) { 1579 1579 err = f2fs_enable_quotas(sb); 1580 1580 if (err) 1581 1581 goto restore_opts; ··· 1651 1651 #ifdef CONFIG_QUOTA 1652 1652 /* Release old quota file names */ 1653 1653 for (i = 0; i < MAXQUOTAS; i++) 1654 - kfree(org_mount_opt.s_qf_names[i]); 1654 + kvfree(org_mount_opt.s_qf_names[i]); 1655 1655 #endif 1656 1656 /* Update the POSIXACL Flag */ 1657 1657 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | ··· 1672 1672 #ifdef CONFIG_QUOTA 1673 1673 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt; 1674 1674 for (i = 0; i < MAXQUOTAS; i++) { 1675 - kfree(F2FS_OPTION(sbi).s_qf_names[i]); 1675 + kvfree(F2FS_OPTION(sbi).s_qf_names[i]); 1676 1676 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i]; 1677 1677 } 1678 1678 #endif ··· 1817 1817 int enabled = 0; 1818 1818 int i, err; 1819 1819 1820 - if (f2fs_sb_has_quota_ino(sbi->sb) && rdonly) { 1820 + if (f2fs_sb_has_quota_ino(sbi) && rdonly) { 1821 1821 err = f2fs_enable_quotas(sbi->sb); 1822 1822 if (err) { 1823 1823 f2fs_msg(sbi->sb, KERN_ERR, ··· 1848 1848 unsigned long qf_inum; 1849 1849 int err; 1850 1850 1851 - BUG_ON(!f2fs_sb_has_quota_ino(sb)); 1851 + BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb))); 1852 1852 1853 1853 qf_inum = f2fs_qf_ino(sb, type); 1854 1854 if (!qf_inum) ··· 1993 1993 goto out_put; 1994 1994 1995 1995 err = dquot_quota_off(sb, type); 1996 - if (err || f2fs_sb_has_quota_ino(sb)) 1996 + if (err || f2fs_sb_has_quota_ino(F2FS_SB(sb))) 1997 1997 goto out_put; 1998 1998 1999 1999 inode_lock(inode); ··· 2173 2173 * if LOST_FOUND feature is enabled. 2174 2174 * 2175 2175 */ 2176 - if (f2fs_sb_has_lost_found(sbi->sb) && 2176 + if (f2fs_sb_has_lost_found(sbi) && 2177 2177 inode->i_ino == F2FS_ROOT_INO(sbi)) 2178 2178 return -EPERM; 2179 2179 ··· 2396 2396 __u32 crc = 0; 2397 2397 2398 2398 /* Check checksum_offset and crc in superblock */ 2399 - if (le32_to_cpu(raw_super->feature) & F2FS_FEATURE_SB_CHKSUM) { 2399 + if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) { 2400 2400 crc_offset = le32_to_cpu(raw_super->checksum_offset); 2401 2401 if (crc_offset != 2402 2402 offsetof(struct f2fs_super_block, crc)) { ··· 2496 2496 return 1; 2497 2497 } 2498 2498 2499 - if (segment_count > (le32_to_cpu(raw_super->block_count) >> 9)) { 2499 + if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) { 2500 2500 f2fs_msg(sb, KERN_INFO, 2501 - "Wrong segment_count / block_count (%u > %u)", 2502 - segment_count, le32_to_cpu(raw_super->block_count)); 2501 + "Wrong segment_count / block_count (%u > %llu)", 2502 + segment_count, le64_to_cpu(raw_super->block_count)); 2503 2503 return 1; 2504 2504 } 2505 2505 ··· 2674 2674 static void init_sb_info(struct f2fs_sb_info *sbi) 2675 2675 { 2676 2676 struct f2fs_super_block *raw_super = sbi->raw_super; 2677 - int i, j; 2677 + int i; 2678 2678 2679 2679 sbi->log_sectors_per_block = 2680 2680 le32_to_cpu(raw_super->log_sectors_per_block); ··· 2692 2692 sbi->node_ino_num = le32_to_cpu(raw_super->node_ino); 2693 2693 sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino); 2694 2694 sbi->cur_victim_sec = NULL_SECNO; 2695 + sbi->next_victim_seg[BG_GC] = NULL_SEGNO; 2696 + sbi->next_victim_seg[FG_GC] = NULL_SEGNO; 2695 2697 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; 2698 + sbi->migration_granularity = sbi->segs_per_sec; 2696 2699 2697 2700 sbi->dir_level = DEF_DIR_LEVEL; 2698 2701 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; ··· 2713 2710 2714 2711 INIT_LIST_HEAD(&sbi->s_list); 2715 2712 mutex_init(&sbi->umount_mutex); 2716 - for (i = 0; i < NR_PAGE_TYPE - 1; i++) 2717 - for (j = HOT; j < NR_TEMP_TYPE; j++) 2718 - mutex_init(&sbi->wio_mutex[i][j]); 2719 2713 init_rwsem(&sbi->io_order_lock); 2720 2714 spin_lock_init(&sbi->cp_lock); 2721 2715 ··· 2749 2749 unsigned int n = 0; 2750 2750 int err = -EIO; 2751 2751 2752 - if (!f2fs_sb_has_blkzoned(sbi->sb)) 2752 + if (!f2fs_sb_has_blkzoned(sbi)) 2753 2753 return 0; 2754 2754 2755 2755 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != ··· 2800 2800 } 2801 2801 } 2802 2802 2803 - kfree(zones); 2803 + kvfree(zones); 2804 2804 2805 2805 return err; 2806 2806 } ··· 2860 2860 2861 2861 /* No valid superblock */ 2862 2862 if (!*raw_super) 2863 - kfree(super); 2863 + kvfree(super); 2864 2864 else 2865 2865 err = 0; 2866 2866 ··· 2880 2880 } 2881 2881 2882 2882 /* we should update superblock crc here */ 2883 - if (!recover && f2fs_sb_has_sb_chksum(sbi->sb)) { 2883 + if (!recover && f2fs_sb_has_sb_chksum(sbi)) { 2884 2884 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi), 2885 2885 offsetof(struct f2fs_super_block, crc)); 2886 2886 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc); ··· 2968 2968 2969 2969 #ifdef CONFIG_BLK_DEV_ZONED 2970 2970 if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM && 2971 - !f2fs_sb_has_blkzoned(sbi->sb)) { 2971 + !f2fs_sb_has_blkzoned(sbi)) { 2972 2972 f2fs_msg(sbi->sb, KERN_ERR, 2973 2973 "Zoned block device feature not enabled\n"); 2974 2974 return -EINVAL; ··· 3064 3064 sbi->raw_super = raw_super; 3065 3065 3066 3066 /* precompute checksum seed for metadata */ 3067 - if (f2fs_sb_has_inode_chksum(sb)) 3067 + if (f2fs_sb_has_inode_chksum(sbi)) 3068 3068 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, 3069 3069 sizeof(raw_super->uuid)); 3070 3070 ··· 3074 3074 * devices, but mandatory for host-managed zoned block devices. 3075 3075 */ 3076 3076 #ifndef CONFIG_BLK_DEV_ZONED 3077 - if (f2fs_sb_has_blkzoned(sb)) { 3077 + if (f2fs_sb_has_blkzoned(sbi)) { 3078 3078 f2fs_msg(sb, KERN_ERR, 3079 3079 "Zoned block device support is not enabled\n"); 3080 3080 err = -EOPNOTSUPP; ··· 3101 3101 3102 3102 #ifdef CONFIG_QUOTA 3103 3103 sb->dq_op = &f2fs_quota_operations; 3104 - if (f2fs_sb_has_quota_ino(sb)) 3104 + if (f2fs_sb_has_quota_ino(sbi)) 3105 3105 sb->s_qcop = &dquot_quotactl_sysfile_ops; 3106 3106 else 3107 3107 sb->s_qcop = &f2fs_quotactl_ops; 3108 3108 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; 3109 3109 3110 - if (f2fs_sb_has_quota_ino(sbi->sb)) { 3110 + if (f2fs_sb_has_quota_ino(sbi)) { 3111 3111 for (i = 0; i < MAXQUOTAS; i++) { 3112 3112 if (f2fs_qf_ino(sbi->sb, i)) 3113 3113 sbi->nquota_files++; ··· 3259 3259 3260 3260 f2fs_build_gc_manager(sbi); 3261 3261 3262 + err = f2fs_build_stats(sbi); 3263 + if (err) 3264 + goto free_nm; 3265 + 3262 3266 /* get an inode for node space */ 3263 3267 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); 3264 3268 if (IS_ERR(sbi->node_inode)) { 3265 3269 f2fs_msg(sb, KERN_ERR, "Failed to read node inode"); 3266 3270 err = PTR_ERR(sbi->node_inode); 3267 - goto free_nm; 3271 + goto free_stats; 3268 3272 } 3269 - 3270 - err = f2fs_build_stats(sbi); 3271 - if (err) 3272 - goto free_node_inode; 3273 3273 3274 3274 /* read root inode and dentry */ 3275 3275 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); 3276 3276 if (IS_ERR(root)) { 3277 3277 f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); 3278 3278 err = PTR_ERR(root); 3279 - goto free_stats; 3279 + goto free_node_inode; 3280 3280 } 3281 3281 if (!S_ISDIR(root->i_mode) || !root->i_blocks || 3282 3282 !root->i_size || !root->i_nlink) { 3283 3283 iput(root); 3284 3284 err = -EINVAL; 3285 - goto free_stats; 3285 + goto free_node_inode; 3286 3286 } 3287 3287 3288 3288 sb->s_root = d_make_root(root); /* allocate root dentry */ ··· 3297 3297 3298 3298 #ifdef CONFIG_QUOTA 3299 3299 /* Enable quota usage during mount */ 3300 - if (f2fs_sb_has_quota_ino(sb) && !f2fs_readonly(sb)) { 3300 + if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) { 3301 3301 err = f2fs_enable_quotas(sb); 3302 3302 if (err) 3303 3303 f2fs_msg(sb, KERN_ERR, ··· 3369 3369 if (err) 3370 3370 goto free_meta; 3371 3371 } 3372 - kfree(options); 3372 + kvfree(options); 3373 3373 3374 3374 /* recover broken superblock */ 3375 3375 if (recovery) { ··· 3392 3392 free_meta: 3393 3393 #ifdef CONFIG_QUOTA 3394 3394 f2fs_truncate_quota_inode_pages(sb); 3395 - if (f2fs_sb_has_quota_ino(sb) && !f2fs_readonly(sb)) 3395 + if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) 3396 3396 f2fs_quota_off_umount(sbi->sb); 3397 3397 #endif 3398 3398 /* ··· 3406 3406 free_root_inode: 3407 3407 dput(sb->s_root); 3408 3408 sb->s_root = NULL; 3409 - free_stats: 3410 - f2fs_destroy_stats(sbi); 3411 3409 free_node_inode: 3412 3410 f2fs_release_ino_entry(sbi, true); 3413 3411 truncate_inode_pages_final(NODE_MAPPING(sbi)); 3414 3412 iput(sbi->node_inode); 3413 + free_stats: 3414 + f2fs_destroy_stats(sbi); 3415 3415 free_nm: 3416 3416 f2fs_destroy_node_manager(sbi); 3417 3417 free_sm: 3418 3418 f2fs_destroy_segment_manager(sbi); 3419 3419 free_devices: 3420 3420 destroy_device_list(sbi); 3421 - kfree(sbi->ckpt); 3421 + kvfree(sbi->ckpt); 3422 3422 free_meta_inode: 3423 3423 make_bad_inode(sbi->meta_inode); 3424 3424 iput(sbi->meta_inode); ··· 3428 3428 destroy_percpu_info(sbi); 3429 3429 free_bio_info: 3430 3430 for (i = 0; i < NR_PAGE_TYPE; i++) 3431 - kfree(sbi->write_io[i]); 3431 + kvfree(sbi->write_io[i]); 3432 3432 free_options: 3433 3433 #ifdef CONFIG_QUOTA 3434 3434 for (i = 0; i < MAXQUOTAS; i++) 3435 - kfree(F2FS_OPTION(sbi).s_qf_names[i]); 3435 + kvfree(F2FS_OPTION(sbi).s_qf_names[i]); 3436 3436 #endif 3437 - kfree(options); 3437 + kvfree(options); 3438 3438 free_sb_buf: 3439 - kfree(raw_super); 3439 + kvfree(raw_super); 3440 3440 free_sbi: 3441 3441 if (sbi->s_chksum_driver) 3442 3442 crypto_free_shash(sbi->s_chksum_driver); 3443 - kfree(sbi); 3443 + kvfree(sbi); 3444 3444 3445 3445 /* give only one another chance */ 3446 3446 if (retry) {
+17 -10
fs/f2fs/sysfs.c
··· 90 90 if (!sb->s_bdev->bd_part) 91 91 return snprintf(buf, PAGE_SIZE, "0\n"); 92 92 93 - if (f2fs_sb_has_encrypt(sb)) 93 + if (f2fs_sb_has_encrypt(sbi)) 94 94 len += snprintf(buf, PAGE_SIZE - len, "%s", 95 95 "encryption"); 96 - if (f2fs_sb_has_blkzoned(sb)) 96 + if (f2fs_sb_has_blkzoned(sbi)) 97 97 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 98 98 len ? ", " : "", "blkzoned"); 99 - if (f2fs_sb_has_extra_attr(sb)) 99 + if (f2fs_sb_has_extra_attr(sbi)) 100 100 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 101 101 len ? ", " : "", "extra_attr"); 102 - if (f2fs_sb_has_project_quota(sb)) 102 + if (f2fs_sb_has_project_quota(sbi)) 103 103 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 104 104 len ? ", " : "", "projquota"); 105 - if (f2fs_sb_has_inode_chksum(sb)) 105 + if (f2fs_sb_has_inode_chksum(sbi)) 106 106 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 107 107 len ? ", " : "", "inode_checksum"); 108 - if (f2fs_sb_has_flexible_inline_xattr(sb)) 108 + if (f2fs_sb_has_flexible_inline_xattr(sbi)) 109 109 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 110 110 len ? ", " : "", "flexible_inline_xattr"); 111 - if (f2fs_sb_has_quota_ino(sb)) 111 + if (f2fs_sb_has_quota_ino(sbi)) 112 112 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 113 113 len ? ", " : "", "quota_ino"); 114 - if (f2fs_sb_has_inode_crtime(sb)) 114 + if (f2fs_sb_has_inode_crtime(sbi)) 115 115 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 116 116 len ? ", " : "", "inode_crtime"); 117 - if (f2fs_sb_has_lost_found(sb)) 117 + if (f2fs_sb_has_lost_found(sbi)) 118 118 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 119 119 len ? ", " : "", "lost_found"); 120 - if (f2fs_sb_has_sb_chksum(sb)) 120 + if (f2fs_sb_has_sb_chksum(sbi)) 121 121 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 122 122 len ? ", " : "", "sb_checksum"); 123 123 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); ··· 244 244 return count; 245 245 *ui = t; 246 246 return count; 247 + } 248 + 249 + if (!strcmp(a->attr.name, "migration_granularity")) { 250 + if (t == 0 || t > sbi->segs_per_sec) 251 + return -EINVAL; 247 252 } 248 253 249 254 if (!strcmp(a->attr.name, "trim_sections")) ··· 411 406 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages); 412 407 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio); 413 408 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); 409 + F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity); 414 410 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); 415 411 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); 416 412 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); ··· 466 460 ATTR_LIST(min_hot_blocks), 467 461 ATTR_LIST(min_ssr_sections), 468 462 ATTR_LIST(max_victim_search), 463 + ATTR_LIST(migration_granularity), 469 464 ATTR_LIST(dir_level), 470 465 ATTR_LIST(ram_thresh), 471 466 ATTR_LIST(ra_nid_pages),
+15 -7
fs/f2fs/xattr.c
··· 288 288 static int lookup_all_xattrs(struct inode *inode, struct page *ipage, 289 289 unsigned int index, unsigned int len, 290 290 const char *name, struct f2fs_xattr_entry **xe, 291 - void **base_addr) 291 + void **base_addr, int *base_size) 292 292 { 293 293 void *cur_addr, *txattr_addr, *last_addr = NULL; 294 294 nid_t xnid = F2FS_I(inode)->i_xattr_nid; ··· 299 299 if (!size && !inline_size) 300 300 return -ENODATA; 301 301 302 - txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), 303 - inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS); 302 + *base_size = inline_size + size + XATTR_PADDING_SIZE; 303 + txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), *base_size, GFP_NOFS); 304 304 if (!txattr_addr) 305 305 return -ENOMEM; 306 306 ··· 312 312 313 313 *xe = __find_inline_xattr(inode, txattr_addr, &last_addr, 314 314 index, len, name); 315 - if (*xe) 315 + if (*xe) { 316 + *base_size = inline_size; 316 317 goto check; 318 + } 317 319 } 318 320 319 321 /* read from xattr node block */ ··· 417 415 } 418 416 419 417 f2fs_wait_on_page_writeback(ipage ? ipage : in_page, 420 - NODE, true); 418 + NODE, true, true); 421 419 /* no need to use xattr node block */ 422 420 if (hsize <= inline_size) { 423 421 err = f2fs_truncate_xattr_node(inode); ··· 441 439 goto in_page_out; 442 440 } 443 441 f2fs_bug_on(sbi, new_nid); 444 - f2fs_wait_on_page_writeback(xpage, NODE, true); 442 + f2fs_wait_on_page_writeback(xpage, NODE, true, true); 445 443 } else { 446 444 struct dnode_of_data dn; 447 445 set_new_dnode(&dn, inode, NULL, NULL, new_nid); ··· 476 474 int error = 0; 477 475 unsigned int size, len; 478 476 void *base_addr = NULL; 477 + int base_size; 479 478 480 479 if (name == NULL) 481 480 return -EINVAL; ··· 487 484 488 485 down_read(&F2FS_I(inode)->i_xattr_sem); 489 486 error = lookup_all_xattrs(inode, ipage, index, len, name, 490 - &entry, &base_addr); 487 + &entry, &base_addr, &base_size); 491 488 up_read(&F2FS_I(inode)->i_xattr_sem); 492 489 if (error) 493 490 return error; ··· 501 498 502 499 if (buffer) { 503 500 char *pval = entry->e_name + entry->e_name_len; 501 + 502 + if (base_size - (pval - (char *)base_addr) < size) { 503 + error = -ERANGE; 504 + goto out; 505 + } 504 506 memcpy(buffer, pval, size); 505 507 } 506 508 error = size;