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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull f2fs updates from Jaegeuk Kim:
"In this round, we've added new features such as disk quota and statx,
and modified internal bio management flow to merge more IOs depending
on block types. We've also made internal threads freezeable for
Android battery life. In addition to them, there are some patches to
avoid lock contention as well as a couple of deadlock conditions.

Enhancements:
- support usrquota, grpquota, and statx
- manage DATA/NODE typed bios separately to serialize more IOs
- modify f2fs_lock_op/wio_mutex to avoid lock contention
- prevent lock contention in migratepage

Bug fixes:
- fix missing load of written inode flag
- fix worst case victim selection in GC
- freezeable GC and discard threads for Android battery life
- sanitize f2fs metadata to deal with security hole
- clean up sysfs-related code and docs"

* tag 'for-f2fs-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (59 commits)
f2fs: support plain user/group quota
f2fs: avoid deadlock caused by lock order of page and lock_op
f2fs: use spin_{,un}lock_irq{save,restore}
f2fs: relax migratepage for atomic written page
f2fs: don't count inode block in in-memory inode.i_blocks
Revert "f2fs: fix to clean previous mount option when remount_fs"
f2fs: do not set LOST_PINO for renamed dir
f2fs: do not set LOST_PINO for newly created dir
f2fs: skip ->writepages for {mete,node}_inode during recovery
f2fs: introduce __check_sit_bitmap
f2fs: stop gc/discard thread in prior during umount
f2fs: introduce reserved_blocks in sysfs
f2fs: avoid redundant f2fs_flush after remount
f2fs: report # of free inodes more precisely
f2fs: add ioctl to do gc with target block address
f2fs: don't need to check encrypted inode for partial truncation
f2fs: measure inode.i_blocks as generic filesystem
f2fs: set CP_TRIMMED_FLAG correctly
f2fs: require key for truncate(2) of encrypted file
f2fs: move sysfs code from super.c to fs/f2fs/sysfs.c
...

+1562 -667
+19 -1
Documentation/ABI/testing/sysfs-fs-f2fs
··· 75 75 Description: 76 76 Controls the memory footprint used by f2fs. 77 77 78 - What: /sys/fs/f2fs/<disk>/trim_sections 78 + What: /sys/fs/f2fs/<disk>/batched_trim_sections 79 79 Date: February 2015 80 80 Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> 81 81 Description: ··· 112 112 Contact: "Shuoran Liu" <liushuoran@huawei.com> 113 113 Description: 114 114 Shows total written kbytes issued to disk. 115 + 116 + What: /sys/fs/f2fs/<disk>/inject_rate 117 + Date: May 2016 118 + Contact: "Sheng Yong" <shengyong1@huawei.com> 119 + Description: 120 + Controls the injection rate. 121 + 122 + What: /sys/fs/f2fs/<disk>/inject_type 123 + Date: May 2016 124 + Contact: "Sheng Yong" <shengyong1@huawei.com> 125 + Description: 126 + Controls the injection type. 127 + 128 + What: /sys/fs/f2fs/<disk>/reserved_blocks 129 + Date: June 2017 130 + Contact: "Chao Yu" <yuchao0@huawei.com> 131 + Description: 132 + Controls current reserved blocks in system.
+4
Documentation/filesystems/f2fs.txt
··· 155 155 enabled by default. 156 156 data_flush Enable data flushing before checkpoint in order to 157 157 persist data of regular and symlink. 158 + fault_injection=%d Enable fault injection in all supported types with 159 + specified injection rate. 158 160 mode=%s Control block allocation mode which supports "adaptive" 159 161 and "lfs". In "lfs" mode, there should be no random 160 162 writes towards main area. 161 163 io_bits=%u Set the bit size of write IO requests. It should be set 162 164 with "mode=lfs". 165 + usrquota Enable plain user disk quota accounting. 166 + grpquota Enable plain group disk quota accounting. 163 167 164 168 ================================================================================ 165 169 DEBUGFS ENTRIES
+1 -1
fs/f2fs/Makefile
··· 2 2 3 3 f2fs-y := dir.o file.o inode.o namei.o hash.o super.o inline.o 4 4 f2fs-y += checkpoint.o gc.o data.o node.o segment.o recovery.o 5 - f2fs-y += shrinker.o extent_cache.o 5 + f2fs-y += shrinker.o extent_cache.o sysfs.o 6 6 f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o 7 7 f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o 8 8 f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
+1 -1
fs/f2fs/acl.c
··· 233 233 value = f2fs_acl_to_disk(F2FS_I_SB(inode), acl, &size); 234 234 if (IS_ERR(value)) { 235 235 clear_inode_flag(inode, FI_ACL_MODE); 236 - return (int)PTR_ERR(value); 236 + return PTR_ERR(value); 237 237 } 238 238 } 239 239
+18 -15
fs/f2fs/checkpoint.c
··· 31 31 set_ckpt_flags(sbi, CP_ERROR_FLAG); 32 32 sbi->sb->s_flags |= MS_RDONLY; 33 33 if (!end_io) 34 - f2fs_flush_merged_bios(sbi); 34 + f2fs_flush_merged_writes(sbi); 35 35 } 36 36 37 37 /* ··· 162 162 .op = REQ_OP_READ, 163 163 .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD, 164 164 .encrypted_page = NULL, 165 + .in_list = false, 165 166 }; 166 167 struct blk_plug plug; 167 168 ··· 208 207 } 209 208 210 209 fio.page = page; 211 - fio.old_blkaddr = fio.new_blkaddr; 212 - f2fs_submit_page_mbio(&fio); 210 + f2fs_submit_page_bio(&fio); 213 211 f2fs_put_page(page, 0); 214 212 } 215 213 out: 216 - f2fs_submit_merged_bio(sbi, META, READ); 217 214 blk_finish_plug(&plug); 218 215 return blkno - start; 219 216 } ··· 248 249 dec_page_count(sbi, F2FS_DIRTY_META); 249 250 250 251 if (wbc->for_reclaim) 251 - f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 252 - 0, page->index, META, WRITE); 252 + f2fs_submit_merged_write_cond(sbi, page->mapping->host, 253 + 0, page->index, META); 253 254 254 255 unlock_page(page); 255 256 256 257 if (unlikely(f2fs_cp_error(sbi))) 257 - f2fs_submit_merged_bio(sbi, META, WRITE); 258 + f2fs_submit_merged_write(sbi, META); 258 259 259 260 return 0; 260 261 ··· 268 269 { 269 270 struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); 270 271 long diff, written; 272 + 273 + if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 274 + goto skip_write; 271 275 272 276 /* collect a number of dirty meta pages and write together */ 273 277 if (wbc->for_kupdate || ··· 360 358 } 361 359 stop: 362 360 if (nwritten) 363 - f2fs_submit_merged_bio(sbi, type, WRITE); 361 + f2fs_submit_merged_write(sbi, type); 364 362 365 363 blk_finish_plug(&plug); 366 364 ··· 908 906 * We should submit bio, since it exists several 909 907 * wribacking dentry pages in the freeing inode. 910 908 */ 911 - f2fs_submit_merged_bio(sbi, DATA, WRITE); 909 + f2fs_submit_merged_write(sbi, DATA); 912 910 cond_resched(); 913 911 } 914 912 goto retry; ··· 1053 1051 { 1054 1052 unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num; 1055 1053 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1054 + unsigned long flags; 1056 1055 1057 - spin_lock(&sbi->cp_lock); 1056 + spin_lock_irqsave(&sbi->cp_lock, flags); 1058 1057 1059 1058 if ((cpc->reason & CP_UMOUNT) && 1060 1059 le32_to_cpu(ckpt->cp_pack_total_block_count) > ··· 1086 1083 /* set this flag to activate crc|cp_ver for recovery */ 1087 1084 __set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG); 1088 1085 1089 - spin_unlock(&sbi->cp_lock); 1086 + spin_unlock_irqrestore(&sbi->cp_lock, flags); 1090 1087 } 1091 1088 1092 1089 static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1093 1090 { 1094 1091 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1095 1092 struct f2fs_nm_info *nm_i = NM_I(sbi); 1096 - unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num; 1093 + unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num, flags; 1097 1094 block_t start_blk; 1098 1095 unsigned int data_sum_blocks, orphan_blocks; 1099 1096 __u32 crc32 = 0; ··· 1135 1132 1136 1133 /* 2 cp + n data seg summary + orphan inode blocks */ 1137 1134 data_sum_blocks = npages_for_summary_flush(sbi, false); 1138 - spin_lock(&sbi->cp_lock); 1135 + spin_lock_irqsave(&sbi->cp_lock, flags); 1139 1136 if (data_sum_blocks < NR_CURSEG_DATA_TYPE) 1140 1137 __set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); 1141 1138 else 1142 1139 __clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); 1143 - spin_unlock(&sbi->cp_lock); 1140 + spin_unlock_irqrestore(&sbi->cp_lock, flags); 1144 1141 1145 1142 orphan_blocks = GET_ORPHAN_BLOCKS(orphan_num); 1146 1143 ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks + ··· 1298 1295 1299 1296 trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish block_ops"); 1300 1297 1301 - f2fs_flush_merged_bios(sbi); 1298 + f2fs_flush_merged_writes(sbi); 1302 1299 1303 1300 /* this is the case of multiple fstrims without any changes */ 1304 1301 if (cpc->reason & CP_DISCARD) {
+144 -77
fs/f2fs/data.c
··· 282 282 nid_t ino, pgoff_t idx, enum page_type type) 283 283 { 284 284 enum page_type btype = PAGE_TYPE_OF_BIO(type); 285 - struct f2fs_bio_info *io = &sbi->write_io[btype]; 286 - bool ret; 285 + enum temp_type temp; 286 + struct f2fs_bio_info *io; 287 + bool ret = false; 287 288 288 - down_read(&io->io_rwsem); 289 - ret = __has_merged_page(io, inode, ino, idx); 290 - up_read(&io->io_rwsem); 289 + for (temp = HOT; temp < NR_TEMP_TYPE; temp++) { 290 + io = sbi->write_io[btype] + temp; 291 + 292 + down_read(&io->io_rwsem); 293 + ret = __has_merged_page(io, inode, ino, idx); 294 + up_read(&io->io_rwsem); 295 + 296 + /* TODO: use HOT temp only for meta pages now. */ 297 + if (ret || btype == META) 298 + break; 299 + } 291 300 return ret; 292 301 } 293 302 294 - static void __f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, 295 - struct inode *inode, nid_t ino, pgoff_t idx, 296 - enum page_type type, int rw) 303 + static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi, 304 + enum page_type type, enum temp_type temp) 297 305 { 298 306 enum page_type btype = PAGE_TYPE_OF_BIO(type); 299 - struct f2fs_bio_info *io; 300 - 301 - io = is_read_io(rw) ? &sbi->read_io : &sbi->write_io[btype]; 307 + struct f2fs_bio_info *io = sbi->write_io[btype] + temp; 302 308 303 309 down_write(&io->io_rwsem); 304 - 305 - if (!__has_merged_page(io, inode, ino, idx)) 306 - goto out; 307 310 308 311 /* change META to META_FLUSH in the checkpoint procedure */ 309 312 if (type >= META_FLUSH) { ··· 317 314 io->fio.op_flags |= REQ_PREFLUSH | REQ_FUA; 318 315 } 319 316 __submit_merged_bio(io); 320 - out: 321 317 up_write(&io->io_rwsem); 322 318 } 323 319 324 - void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 325 - int rw) 326 - { 327 - __f2fs_submit_merged_bio(sbi, NULL, 0, 0, type, rw); 328 - } 329 - 330 - void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 320 + static void __submit_merged_write_cond(struct f2fs_sb_info *sbi, 331 321 struct inode *inode, nid_t ino, pgoff_t idx, 332 - enum page_type type, int rw) 322 + enum page_type type, bool force) 333 323 { 334 - if (has_merged_page(sbi, inode, ino, idx, type)) 335 - __f2fs_submit_merged_bio(sbi, inode, ino, idx, type, rw); 324 + enum temp_type temp; 325 + 326 + if (!force && !has_merged_page(sbi, inode, ino, idx, type)) 327 + return; 328 + 329 + for (temp = HOT; temp < NR_TEMP_TYPE; temp++) { 330 + 331 + __f2fs_submit_merged_write(sbi, type, temp); 332 + 333 + /* TODO: use HOT temp only for meta pages now. */ 334 + if (type >= META) 335 + break; 336 + } 336 337 } 337 338 338 - void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi) 339 + void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type) 339 340 { 340 - f2fs_submit_merged_bio(sbi, DATA, WRITE); 341 - f2fs_submit_merged_bio(sbi, NODE, WRITE); 342 - f2fs_submit_merged_bio(sbi, META, WRITE); 341 + __submit_merged_write_cond(sbi, NULL, 0, 0, type, true); 342 + } 343 + 344 + void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 345 + struct inode *inode, nid_t ino, pgoff_t idx, 346 + enum page_type type) 347 + { 348 + __submit_merged_write_cond(sbi, inode, ino, idx, type, false); 349 + } 350 + 351 + void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi) 352 + { 353 + f2fs_submit_merged_write(sbi, DATA); 354 + f2fs_submit_merged_write(sbi, NODE); 355 + f2fs_submit_merged_write(sbi, META); 343 356 } 344 357 345 358 /* ··· 387 368 return 0; 388 369 } 389 370 390 - int f2fs_submit_page_mbio(struct f2fs_io_info *fio) 371 + int f2fs_submit_page_write(struct f2fs_io_info *fio) 391 372 { 392 373 struct f2fs_sb_info *sbi = fio->sbi; 393 374 enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); 394 - struct f2fs_bio_info *io; 395 - bool is_read = is_read_io(fio->op); 375 + struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp; 396 376 struct page *bio_page; 397 377 int err = 0; 398 378 399 - io = is_read ? &sbi->read_io : &sbi->write_io[btype]; 379 + f2fs_bug_on(sbi, is_read_io(fio->op)); 380 + 381 + down_write(&io->io_rwsem); 382 + next: 383 + if (fio->in_list) { 384 + spin_lock(&io->io_lock); 385 + if (list_empty(&io->io_list)) { 386 + spin_unlock(&io->io_lock); 387 + goto out_fail; 388 + } 389 + fio = list_first_entry(&io->io_list, 390 + struct f2fs_io_info, list); 391 + list_del(&fio->list); 392 + spin_unlock(&io->io_lock); 393 + } 400 394 401 395 if (fio->old_blkaddr != NEW_ADDR) 402 396 verify_block_addr(sbi, fio->old_blkaddr); ··· 420 388 /* set submitted = 1 as a return value */ 421 389 fio->submitted = 1; 422 390 423 - if (!is_read) 424 - inc_page_count(sbi, WB_DATA_TYPE(bio_page)); 425 - 426 - down_write(&io->io_rwsem); 391 + inc_page_count(sbi, WB_DATA_TYPE(bio_page)); 427 392 428 393 if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 || 429 394 (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) || ··· 431 402 if ((fio->type == DATA || fio->type == NODE) && 432 403 fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { 433 404 err = -EAGAIN; 434 - if (!is_read) 435 - dec_page_count(sbi, WB_DATA_TYPE(bio_page)); 405 + dec_page_count(sbi, WB_DATA_TYPE(bio_page)); 436 406 goto out_fail; 437 407 } 438 408 io->bio = __bio_alloc(sbi, fio->new_blkaddr, 439 - BIO_MAX_PAGES, is_read); 409 + BIO_MAX_PAGES, false); 440 410 io->fio = *fio; 441 411 } 442 412 443 - if (bio_add_page(io->bio, bio_page, PAGE_SIZE, 0) < 444 - PAGE_SIZE) { 413 + if (bio_add_page(io->bio, bio_page, PAGE_SIZE, 0) < PAGE_SIZE) { 445 414 __submit_merged_bio(io); 446 415 goto alloc_new; 447 416 } 448 417 449 418 io->last_block_in_bio = fio->new_blkaddr; 450 419 f2fs_trace_ios(fio, 0); 420 + 421 + trace_f2fs_submit_page_write(fio->page, fio); 422 + 423 + if (fio->in_list) 424 + goto next; 451 425 out_fail: 452 426 up_write(&io->io_rwsem); 453 - trace_f2fs_submit_page_mbio(fio->page, fio); 454 427 return err; 455 428 } 456 429 ··· 491 460 int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count) 492 461 { 493 462 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); 463 + int err; 494 464 495 465 if (!count) 496 466 return 0; 497 467 498 468 if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) 499 469 return -EPERM; 500 - if (unlikely(!inc_valid_block_count(sbi, dn->inode, &count))) 501 - return -ENOSPC; 470 + if (unlikely((err = inc_valid_block_count(sbi, dn->inode, &count)))) 471 + return err; 502 472 503 473 trace_f2fs_reserve_new_blocks(dn->inode, dn->nid, 504 474 dn->ofs_in_node, count); ··· 750 718 struct node_info ni; 751 719 pgoff_t fofs; 752 720 blkcnt_t count = 1; 721 + int err; 753 722 754 723 if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) 755 724 return -EPERM; ··· 759 726 if (dn->data_blkaddr == NEW_ADDR) 760 727 goto alloc; 761 728 762 - if (unlikely(!inc_valid_block_count(sbi, dn->inode, &count))) 763 - return -ENOSPC; 729 + if (unlikely((err = inc_valid_block_count(sbi, dn->inode, &count)))) 730 + return err; 764 731 765 732 alloc: 766 733 get_node_info(sbi, dn->nid, &ni); 767 734 set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); 768 735 769 736 allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr, 770 - &sum, CURSEG_WARM_DATA); 737 + &sum, CURSEG_WARM_DATA, NULL, false); 771 738 set_data_blkaddr(dn); 772 739 773 740 /* update i_size */ ··· 1354 1321 1355 1322 /* flush pending IOs and wait for a while in the ENOMEM case */ 1356 1323 if (PTR_ERR(fio->encrypted_page) == -ENOMEM) { 1357 - f2fs_flush_merged_bios(fio->sbi); 1324 + f2fs_flush_merged_writes(fio->sbi); 1358 1325 congestion_wait(BLK_RW_ASYNC, HZ/50); 1359 1326 gfp_flags |= __GFP_NOFAIL; 1360 1327 goto retry_encrypt; ··· 1401 1368 1402 1369 if (valid_ipu_blkaddr(fio)) { 1403 1370 ipu_force = true; 1404 - fio->need_lock = false; 1371 + fio->need_lock = LOCK_DONE; 1405 1372 goto got_it; 1406 1373 } 1407 1374 } 1408 1375 1409 - if (fio->need_lock) 1410 - f2fs_lock_op(fio->sbi); 1376 + /* Deadlock due to between page->lock and f2fs_lock_op */ 1377 + if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi)) 1378 + return -EAGAIN; 1411 1379 1412 1380 err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE); 1413 1381 if (err) ··· 1422 1388 goto out_writepage; 1423 1389 } 1424 1390 got_it: 1425 - err = encrypt_one_page(fio); 1426 - if (err) 1427 - goto out_writepage; 1428 - 1429 - set_page_writeback(page); 1430 - 1431 1391 /* 1432 1392 * If current allocation needs SSR, 1433 1393 * it had better in-place writes for updated data. 1434 1394 */ 1435 1395 if (ipu_force || (valid_ipu_blkaddr(fio) && need_inplace_update(fio))) { 1396 + err = encrypt_one_page(fio); 1397 + if (err) 1398 + goto out_writepage; 1399 + 1400 + set_page_writeback(page); 1436 1401 f2fs_put_dnode(&dn); 1437 - if (fio->need_lock) 1402 + if (fio->need_lock == LOCK_REQ) 1438 1403 f2fs_unlock_op(fio->sbi); 1439 1404 err = rewrite_data_page(fio); 1440 1405 trace_f2fs_do_write_data_page(fio->page, IPU); 1441 1406 set_inode_flag(inode, FI_UPDATE_WRITE); 1442 1407 return err; 1443 1408 } 1409 + 1410 + if (fio->need_lock == LOCK_RETRY) { 1411 + if (!f2fs_trylock_op(fio->sbi)) { 1412 + err = -EAGAIN; 1413 + goto out_writepage; 1414 + } 1415 + fio->need_lock = LOCK_REQ; 1416 + } 1417 + 1418 + err = encrypt_one_page(fio); 1419 + if (err) 1420 + goto out_writepage; 1421 + 1422 + set_page_writeback(page); 1444 1423 1445 1424 /* LFS mode write path */ 1446 1425 write_data_page(&dn, fio); ··· 1464 1417 out_writepage: 1465 1418 f2fs_put_dnode(&dn); 1466 1419 out: 1467 - if (fio->need_lock) 1420 + if (fio->need_lock == LOCK_REQ) 1468 1421 f2fs_unlock_op(fio->sbi); 1469 1422 return err; 1470 1423 } ··· 1490 1443 .page = page, 1491 1444 .encrypted_page = NULL, 1492 1445 .submitted = false, 1493 - .need_lock = true, 1446 + .need_lock = LOCK_RETRY, 1494 1447 }; 1495 1448 1496 1449 trace_f2fs_writepage(page, DATA); 1450 + 1451 + if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 1452 + goto redirty_out; 1497 1453 1498 1454 if (page->index < end_index) 1499 1455 goto write; ··· 1511 1461 1512 1462 zero_user_segment(page, offset, PAGE_SIZE); 1513 1463 write: 1514 - if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 1515 - goto redirty_out; 1516 1464 if (f2fs_is_drop_cache(inode)) 1517 1465 goto out; 1518 1466 /* we should not write 0'th page having journal header */ ··· 1527 1479 1528 1480 /* Dentry blocks are controlled by checkpoint */ 1529 1481 if (S_ISDIR(inode->i_mode)) { 1530 - fio.need_lock = false; 1482 + fio.need_lock = LOCK_DONE; 1531 1483 err = do_write_data_page(&fio); 1532 1484 goto done; 1533 1485 } ··· 1546 1498 goto out; 1547 1499 } 1548 1500 1549 - if (err == -EAGAIN) 1501 + if (err == -EAGAIN) { 1550 1502 err = do_write_data_page(&fio); 1503 + if (err == -EAGAIN) { 1504 + fio.need_lock = LOCK_REQ; 1505 + err = do_write_data_page(&fio); 1506 + } 1507 + } 1551 1508 if (F2FS_I(inode)->last_disk_size < psize) 1552 1509 F2FS_I(inode)->last_disk_size = psize; 1553 1510 ··· 1566 1513 ClearPageUptodate(page); 1567 1514 1568 1515 if (wbc->for_reclaim) { 1569 - f2fs_submit_merged_bio_cond(sbi, inode, 0, page->index, 1570 - DATA, WRITE); 1516 + f2fs_submit_merged_write_cond(sbi, inode, 0, page->index, DATA); 1571 1517 clear_inode_flag(inode, FI_HOT_DATA); 1572 1518 remove_dirty_inode(inode); 1573 1519 submitted = NULL; ··· 1577 1525 f2fs_balance_fs(sbi, need_balance_fs); 1578 1526 1579 1527 if (unlikely(f2fs_cp_error(sbi))) { 1580 - f2fs_submit_merged_bio(sbi, DATA, WRITE); 1528 + f2fs_submit_merged_write(sbi, DATA); 1581 1529 submitted = NULL; 1582 1530 } 1583 1531 ··· 1670 1618 } 1671 1619 1672 1620 done_index = page->index; 1673 - 1621 + retry_write: 1674 1622 lock_page(page); 1675 1623 1676 1624 if (unlikely(page->mapping != mapping)) { ··· 1706 1654 unlock_page(page); 1707 1655 ret = 0; 1708 1656 continue; 1657 + } else if (ret == -EAGAIN) { 1658 + ret = 0; 1659 + if (wbc->sync_mode == WB_SYNC_ALL) { 1660 + cond_resched(); 1661 + congestion_wait(BLK_RW_ASYNC, 1662 + HZ/50); 1663 + goto retry_write; 1664 + } 1665 + continue; 1709 1666 } 1710 1667 done_index = page->index + 1; 1711 1668 done = 1; ··· 1745 1684 mapping->writeback_index = done_index; 1746 1685 1747 1686 if (last_idx != ULONG_MAX) 1748 - f2fs_submit_merged_bio_cond(F2FS_M_SB(mapping), mapping->host, 1749 - 0, last_idx, DATA, WRITE); 1687 + f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host, 1688 + 0, last_idx, DATA); 1750 1689 1751 1690 return ret; 1752 1691 } ··· 1767 1706 if (!get_dirty_pages(inode) && wbc->sync_mode == WB_SYNC_NONE) 1768 1707 return 0; 1769 1708 1709 + /* during POR, we don't need to trigger writepage at all. */ 1710 + if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 1711 + goto skip_write; 1712 + 1770 1713 if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE && 1771 1714 get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) && 1772 1715 available_free_memory(sbi, DIRTY_DENTS)) ··· 1778 1713 1779 1714 /* skip writing during file defragment */ 1780 1715 if (is_inode_flag_set(inode, FI_DO_DEFRAG)) 1781 - goto skip_write; 1782 - 1783 - /* during POR, we don't need to trigger writepage at all. */ 1784 - if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 1785 1716 goto skip_write; 1786 1717 1787 1718 trace_f2fs_writepages(mapping->host, wbc, DATA); ··· 1814 1753 loff_t i_size = i_size_read(inode); 1815 1754 1816 1755 if (to > i_size) { 1756 + down_write(&F2FS_I(inode)->i_mmap_sem); 1817 1757 truncate_pagecache(inode, i_size); 1818 1758 truncate_blocks(inode, i_size, true); 1759 + up_write(&F2FS_I(inode)->i_mmap_sem); 1819 1760 } 1820 1761 } 1821 1762 ··· 2215 2152 BUG_ON(PageWriteback(page)); 2216 2153 2217 2154 /* migrating an atomic written page is safe with the inmem_lock hold */ 2218 - if (atomic_written && !mutex_trylock(&fi->inmem_lock)) 2219 - return -EAGAIN; 2155 + if (atomic_written) { 2156 + if (mode != MIGRATE_SYNC) 2157 + return -EBUSY; 2158 + if (!mutex_trylock(&fi->inmem_lock)) 2159 + return -EAGAIN; 2160 + } 2220 2161 2221 2162 /* 2222 2163 * A reference is expected if PagePrivate set when move mapping,
+2 -1
fs/f2fs/dir.c
··· 415 415 * We lost i_pino from now on. 416 416 */ 417 417 if (is_inode_flag_set(inode, FI_INC_LINK)) { 418 - file_lost_pino(inode); 418 + if (!S_ISDIR(inode->i_mode)) 419 + file_lost_pino(inode); 419 420 /* 420 421 * If link the tmpfile to alias through linkat path, 421 422 * we should remove this inode from orphan list.
+11 -1
fs/f2fs/extent_cache.c
··· 320 320 } 321 321 322 322 /* return true, if inode page is changed */ 323 - bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) 323 + static bool __f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) 324 324 { 325 325 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 326 326 struct extent_tree *et; ··· 356 356 out: 357 357 write_unlock(&et->lock); 358 358 return false; 359 + } 360 + 361 + bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) 362 + { 363 + bool ret = __f2fs_init_extent_tree(inode, i_ext); 364 + 365 + if (!F2FS_I(inode)->extent_tree) 366 + set_inode_flag(inode, FI_NO_EXTENT); 367 + 368 + return ret; 359 369 } 360 370 361 371 static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
+150 -51
fs/f2fs/f2fs.h
··· 22 22 #include <linux/vmalloc.h> 23 23 #include <linux/bio.h> 24 24 #include <linux/blkdev.h> 25 + #include <linux/quotaops.h> 25 26 #ifdef CONFIG_F2FS_FS_ENCRYPTION 26 27 #include <linux/fscrypt_supp.h> 27 28 #else ··· 89 88 #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 90 89 #define F2FS_MOUNT_ADAPTIVE 0x00020000 91 90 #define F2FS_MOUNT_LFS 0x00040000 91 + #define F2FS_MOUNT_USRQUOTA 0x00080000 92 + #define F2FS_MOUNT_GRPQUOTA 0x00100000 92 93 93 94 #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 94 95 #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) ··· 306 303 struct f2fs_move_range) 307 304 #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 308 305 struct f2fs_flush_device) 306 + #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 307 + struct f2fs_gc_range) 309 308 310 309 #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 311 310 #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY ··· 331 326 #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 332 327 #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 333 328 #endif 329 + 330 + struct f2fs_gc_range { 331 + u32 sync; 332 + u64 start; 333 + u64 len; 334 + }; 334 335 335 336 struct f2fs_defragment { 336 337 u64 start; ··· 524 513 nid_t i_xattr_nid; /* node id that contains xattrs */ 525 514 loff_t last_disk_size; /* lastly written file size */ 526 515 516 + #ifdef CONFIG_QUOTA 517 + struct dquot *i_dquot[MAXQUOTAS]; 518 + 519 + /* quota space reservation, managed internally by quota code */ 520 + qsize_t i_reserved_quota; 521 + #endif 527 522 struct list_head dirty_list; /* dirty list for dirs and files */ 528 523 struct list_head gdirty_list; /* linked in global dirty list */ 529 524 struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 530 525 struct mutex inmem_lock; /* lock for inmemory pages */ 531 526 struct extent_tree *extent_tree; /* cached extent_tree entry */ 532 527 struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 528 + struct rw_semaphore i_mmap_sem; 533 529 }; 534 530 535 531 static inline void get_extent_info(struct extent_info *ext, ··· 810 792 OPU, 811 793 }; 812 794 795 + enum temp_type { 796 + HOT = 0, /* must be zero for meta bio */ 797 + WARM, 798 + COLD, 799 + NR_TEMP_TYPE, 800 + }; 801 + 802 + enum need_lock_type { 803 + LOCK_REQ = 0, 804 + LOCK_DONE, 805 + LOCK_RETRY, 806 + }; 807 + 813 808 struct f2fs_io_info { 814 809 struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 815 810 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 811 + enum temp_type temp; /* contains HOT/WARM/COLD */ 816 812 int op; /* contains REQ_OP_ */ 817 813 int op_flags; /* req_flag_bits */ 818 814 block_t new_blkaddr; /* new block address to be written */ 819 815 block_t old_blkaddr; /* old block address before Cow */ 820 816 struct page *page; /* page to be written */ 821 817 struct page *encrypted_page; /* encrypted page */ 818 + struct list_head list; /* serialize IOs */ 822 819 bool submitted; /* indicate IO submission */ 823 - bool need_lock; /* indicate we need to lock cp_rwsem */ 820 + int need_lock; /* indicate we need to lock cp_rwsem */ 821 + bool in_list; /* indicate fio is in io_list */ 824 822 }; 825 823 826 824 #define is_read_io(rw) ((rw) == READ) ··· 846 812 sector_t last_block_in_bio; /* last block number */ 847 813 struct f2fs_io_info fio; /* store buffered io info. */ 848 814 struct rw_semaphore io_rwsem; /* blocking op for bio */ 815 + spinlock_t io_lock; /* serialize DATA/NODE IOs */ 816 + struct list_head io_list; /* track fios */ 849 817 }; 850 818 851 819 #define FDEV(i) (sbi->devs[i]) ··· 915 879 struct f2fs_sm_info *sm_info; /* segment manager */ 916 880 917 881 /* for bio operations */ 918 - struct f2fs_bio_info read_io; /* for read bios */ 919 - struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 920 - struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 882 + struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 883 + struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 884 + /* bio ordering for NODE/DATA */ 921 885 int write_io_size_bits; /* Write IO size bits */ 922 886 mempool_t *write_io_dummy; /* Dummy pages */ 923 887 ··· 975 939 block_t total_valid_block_count; /* # of valid blocks */ 976 940 block_t discard_blks; /* discard command candidats */ 977 941 block_t last_valid_block_count; /* for recovery */ 942 + block_t reserved_blocks; /* configurable reserved blocks */ 943 + 978 944 u32 s_next_generation; /* for NFS support */ 979 945 980 946 /* # of pages, see count_type */ ··· 1266 1228 1267 1229 static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1268 1230 { 1269 - spin_lock(&sbi->cp_lock); 1231 + unsigned long flags; 1232 + 1233 + spin_lock_irqsave(&sbi->cp_lock, flags); 1270 1234 __set_ckpt_flags(F2FS_CKPT(sbi), f); 1271 - spin_unlock(&sbi->cp_lock); 1235 + spin_unlock_irqrestore(&sbi->cp_lock, flags); 1272 1236 } 1273 1237 1274 1238 static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) ··· 1284 1244 1285 1245 static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1286 1246 { 1287 - spin_lock(&sbi->cp_lock); 1247 + unsigned long flags; 1248 + 1249 + spin_lock_irqsave(&sbi->cp_lock, flags); 1288 1250 __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1289 - spin_unlock(&sbi->cp_lock); 1251 + spin_unlock_irqrestore(&sbi->cp_lock, flags); 1290 1252 } 1291 1253 1292 1254 static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 1293 1255 { 1256 + unsigned long flags; 1257 + 1294 1258 set_sbi_flag(sbi, SBI_NEED_FSCK); 1295 1259 1296 1260 if (lock) 1297 - spin_lock(&sbi->cp_lock); 1261 + spin_lock_irqsave(&sbi->cp_lock, flags); 1298 1262 __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 1299 1263 kfree(NM_I(sbi)->nat_bits); 1300 1264 NM_I(sbi)->nat_bits = NULL; 1301 1265 if (lock) 1302 - spin_unlock(&sbi->cp_lock); 1266 + spin_unlock_irqrestore(&sbi->cp_lock, flags); 1303 1267 } 1304 1268 1305 1269 static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, ··· 1317 1273 static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 1318 1274 { 1319 1275 down_read(&sbi->cp_rwsem); 1276 + } 1277 + 1278 + static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1279 + { 1280 + return down_read_trylock(&sbi->cp_rwsem); 1320 1281 } 1321 1282 1322 1283 static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) ··· 1373 1324 return 0; 1374 1325 } 1375 1326 1376 - #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 1377 - 1378 1327 /* 1379 1328 * Check whether the inode has blocks or not 1380 1329 */ 1381 1330 static inline int F2FS_HAS_BLOCKS(struct inode *inode) 1382 1331 { 1383 - if (F2FS_I(inode)->i_xattr_nid) 1384 - return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 1385 - else 1386 - return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 1332 + block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 1333 + 1334 + return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 1387 1335 } 1388 1336 1389 1337 static inline bool f2fs_has_xattr_block(unsigned int ofs) ··· 1388 1342 return ofs == XATTR_NODE_OFFSET; 1389 1343 } 1390 1344 1391 - static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 1392 - static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 1345 + static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 1346 + static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 1393 1347 struct inode *inode, blkcnt_t *count) 1394 1348 { 1395 - blkcnt_t diff; 1349 + blkcnt_t diff = 0, release = 0; 1350 + block_t avail_user_block_count; 1351 + int ret; 1352 + 1353 + ret = dquot_reserve_block(inode, *count); 1354 + if (ret) 1355 + return ret; 1396 1356 1397 1357 #ifdef CONFIG_F2FS_FAULT_INJECTION 1398 1358 if (time_to_inject(sbi, FAULT_BLOCK)) { 1399 1359 f2fs_show_injection_info(FAULT_BLOCK); 1400 - return false; 1360 + release = *count; 1361 + goto enospc; 1401 1362 } 1402 1363 #endif 1403 1364 /* ··· 1415 1362 1416 1363 spin_lock(&sbi->stat_lock); 1417 1364 sbi->total_valid_block_count += (block_t)(*count); 1418 - if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1419 - diff = sbi->total_valid_block_count - sbi->user_block_count; 1365 + avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks; 1366 + if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1367 + diff = sbi->total_valid_block_count - avail_user_block_count; 1420 1368 *count -= diff; 1421 - sbi->total_valid_block_count = sbi->user_block_count; 1369 + release = diff; 1370 + sbi->total_valid_block_count = avail_user_block_count; 1422 1371 if (!*count) { 1423 1372 spin_unlock(&sbi->stat_lock); 1424 1373 percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 1425 - return false; 1374 + goto enospc; 1426 1375 } 1427 1376 } 1428 1377 spin_unlock(&sbi->stat_lock); 1429 1378 1430 - f2fs_i_blocks_write(inode, *count, true); 1431 - return true; 1379 + if (release) 1380 + dquot_release_reservation_block(inode, release); 1381 + f2fs_i_blocks_write(inode, *count, true, true); 1382 + return 0; 1383 + 1384 + enospc: 1385 + dquot_release_reservation_block(inode, release); 1386 + return -ENOSPC; 1432 1387 } 1433 1388 1434 1389 static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 1435 1390 struct inode *inode, 1436 - blkcnt_t count) 1391 + block_t count) 1437 1392 { 1393 + blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 1394 + 1438 1395 spin_lock(&sbi->stat_lock); 1439 1396 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 1440 - f2fs_bug_on(sbi, inode->i_blocks < count); 1397 + f2fs_bug_on(sbi, inode->i_blocks < sectors); 1441 1398 sbi->total_valid_block_count -= (block_t)count; 1442 1399 spin_unlock(&sbi->stat_lock); 1443 - f2fs_i_blocks_write(inode, count, false); 1400 + f2fs_i_blocks_write(inode, count, false, true); 1444 1401 } 1445 1402 1446 1403 static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) ··· 1579 1516 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 1580 1517 } 1581 1518 1582 - static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1583 - struct inode *inode) 1519 + static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 1520 + struct inode *inode, bool is_inode) 1584 1521 { 1585 1522 block_t valid_block_count; 1586 1523 unsigned int valid_node_count; 1524 + bool quota = inode && !is_inode; 1525 + 1526 + if (quota) { 1527 + int ret = dquot_reserve_block(inode, 1); 1528 + if (ret) 1529 + return ret; 1530 + } 1587 1531 1588 1532 spin_lock(&sbi->stat_lock); 1589 1533 1590 1534 valid_block_count = sbi->total_valid_block_count + 1; 1591 - if (unlikely(valid_block_count > sbi->user_block_count)) { 1535 + if (unlikely(valid_block_count + sbi->reserved_blocks > 1536 + sbi->user_block_count)) { 1592 1537 spin_unlock(&sbi->stat_lock); 1593 - return false; 1538 + goto enospc; 1594 1539 } 1595 1540 1596 1541 valid_node_count = sbi->total_valid_node_count + 1; 1597 1542 if (unlikely(valid_node_count > sbi->total_node_count)) { 1598 1543 spin_unlock(&sbi->stat_lock); 1599 - return false; 1544 + goto enospc; 1600 1545 } 1601 - 1602 - if (inode) 1603 - f2fs_i_blocks_write(inode, 1, true); 1604 1546 1605 1547 sbi->total_valid_node_count++; 1606 1548 sbi->total_valid_block_count++; 1607 1549 spin_unlock(&sbi->stat_lock); 1608 1550 1551 + if (inode) { 1552 + if (is_inode) 1553 + f2fs_mark_inode_dirty_sync(inode, true); 1554 + else 1555 + f2fs_i_blocks_write(inode, 1, true, true); 1556 + } 1557 + 1609 1558 percpu_counter_inc(&sbi->alloc_valid_block_count); 1610 - return true; 1559 + return 0; 1560 + 1561 + enospc: 1562 + if (quota) 1563 + dquot_release_reservation_block(inode, 1); 1564 + return -ENOSPC; 1611 1565 } 1612 1566 1613 1567 static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1614 - struct inode *inode) 1568 + struct inode *inode, bool is_inode) 1615 1569 { 1616 1570 spin_lock(&sbi->stat_lock); 1617 1571 1618 1572 f2fs_bug_on(sbi, !sbi->total_valid_block_count); 1619 1573 f2fs_bug_on(sbi, !sbi->total_valid_node_count); 1620 - f2fs_bug_on(sbi, !inode->i_blocks); 1574 + f2fs_bug_on(sbi, !is_inode && !inode->i_blocks); 1621 1575 1622 - f2fs_i_blocks_write(inode, 1, false); 1623 1576 sbi->total_valid_node_count--; 1624 1577 sbi->total_valid_block_count--; 1625 1578 1626 1579 spin_unlock(&sbi->stat_lock); 1580 + 1581 + if (!is_inode) 1582 + f2fs_i_blocks_write(inode, 1, false, true); 1627 1583 } 1628 1584 1629 1585 static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) ··· 1917 1835 } 1918 1836 1919 1837 static inline void f2fs_i_blocks_write(struct inode *inode, 1920 - blkcnt_t diff, bool add) 1838 + block_t diff, bool add, bool claim) 1921 1839 { 1922 1840 bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 1923 1841 bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 1924 1842 1925 - inode->i_blocks = add ? inode->i_blocks + diff : 1926 - inode->i_blocks - diff; 1843 + /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 1844 + if (add) { 1845 + if (claim) 1846 + dquot_claim_block(inode, diff); 1847 + else 1848 + dquot_alloc_block_nofail(inode, diff); 1849 + } else { 1850 + dquot_free_block(inode, diff); 1851 + } 1852 + 1927 1853 f2fs_mark_inode_dirty_sync(inode, true); 1928 1854 if (clean || recover) 1929 1855 set_inode_flag(inode, FI_AUTO_RECOVER); ··· 2326 2236 void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2327 2237 bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2328 2238 void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2239 + void stop_discard_thread(struct f2fs_sb_info *sbi); 2329 2240 void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2330 2241 void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2331 2242 void release_discard_addrs(struct f2fs_sb_info *sbi); ··· 2349 2258 bool recover_newaddr); 2350 2259 void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2351 2260 block_t old_blkaddr, block_t *new_blkaddr, 2352 - struct f2fs_summary *sum, int type); 2261 + struct f2fs_summary *sum, int type, 2262 + struct f2fs_io_info *fio, bool add_list); 2353 2263 void f2fs_wait_on_page_writeback(struct page *page, 2354 2264 enum page_type type, bool ordered); 2355 2265 void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, ··· 2400 2308 /* 2401 2309 * data.c 2402 2310 */ 2403 - void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 2404 - int rw); 2405 - void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 2311 + void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2312 + void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2406 2313 struct inode *inode, nid_t ino, pgoff_t idx, 2407 - enum page_type type, int rw); 2408 - void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); 2314 + enum page_type type); 2315 + void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2409 2316 int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2410 - int f2fs_submit_page_mbio(struct f2fs_io_info *fio); 2317 + int f2fs_submit_page_write(struct f2fs_io_info *fio); 2411 2318 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2412 2319 block_t blk_addr, struct bio *bio); 2413 2320 int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); ··· 2722 2631 void init_extent_cache_info(struct f2fs_sb_info *sbi); 2723 2632 int __init create_extent_cache(void); 2724 2633 void destroy_extent_cache(void); 2634 + 2635 + /* 2636 + * sysfs.c 2637 + */ 2638 + int __init f2fs_register_sysfs(void); 2639 + void f2fs_unregister_sysfs(void); 2640 + int f2fs_init_sysfs(struct f2fs_sb_info *sbi); 2641 + void f2fs_exit_sysfs(struct f2fs_sb_info *sbi); 2725 2642 2726 2643 /* 2727 2644 * crypto support
+147 -36
fs/f2fs/file.c
··· 33 33 #include "trace.h" 34 34 #include <trace/events/f2fs.h> 35 35 36 + static int f2fs_filemap_fault(struct vm_fault *vmf) 37 + { 38 + struct inode *inode = file_inode(vmf->vma->vm_file); 39 + int err; 40 + 41 + down_read(&F2FS_I(inode)->i_mmap_sem); 42 + err = filemap_fault(vmf); 43 + up_read(&F2FS_I(inode)->i_mmap_sem); 44 + 45 + return err; 46 + } 47 + 36 48 static int f2fs_vm_page_mkwrite(struct vm_fault *vmf) 37 49 { 38 50 struct page *page = vmf->page; ··· 71 59 f2fs_balance_fs(sbi, dn.node_changed); 72 60 73 61 file_update_time(vmf->vma->vm_file); 62 + down_read(&F2FS_I(inode)->i_mmap_sem); 74 63 lock_page(page); 75 64 if (unlikely(page->mapping != inode->i_mapping || 76 65 page_offset(page) > i_size_read(inode) || 77 66 !PageUptodate(page))) { 78 67 unlock_page(page); 79 68 err = -EFAULT; 80 - goto out; 69 + goto out_sem; 81 70 } 82 71 83 72 /* ··· 107 94 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) 108 95 f2fs_wait_on_encrypted_page_writeback(sbi, dn.data_blkaddr); 109 96 97 + out_sem: 98 + up_read(&F2FS_I(inode)->i_mmap_sem); 110 99 out: 111 100 sb_end_pagefault(inode->i_sb); 112 101 f2fs_update_time(sbi, REQ_TIME); ··· 116 101 } 117 102 118 103 static const struct vm_operations_struct f2fs_file_vm_ops = { 119 - .fault = filemap_fault, 104 + .fault = f2fs_filemap_fault, 120 105 .map_pages = filemap_map_pages, 121 106 .page_mkwrite = f2fs_vm_page_mkwrite, 122 107 }; ··· 430 415 struct inode *inode = file_inode(file); 431 416 int err; 432 417 433 - if (f2fs_encrypted_inode(inode)) { 434 - err = fscrypt_get_encryption_info(inode); 435 - if (err) 436 - return 0; 437 - if (!f2fs_encrypted_inode(inode)) 438 - return -ENOKEY; 439 - } 440 - 441 418 /* we don't need to use inline_data strictly */ 442 419 err = f2fs_convert_inline_inode(inode); 443 420 if (err) ··· 442 435 443 436 static int f2fs_file_open(struct inode *inode, struct file *filp) 444 437 { 445 - int ret = generic_file_open(inode, filp); 446 438 struct dentry *dir; 447 439 448 - if (!ret && f2fs_encrypted_inode(inode)) { 449 - ret = fscrypt_get_encryption_info(inode); 440 + if (f2fs_encrypted_inode(inode)) { 441 + int ret = fscrypt_get_encryption_info(inode); 450 442 if (ret) 451 443 return -EACCES; 452 444 if (!fscrypt_has_encryption_key(inode)) ··· 458 452 return -EPERM; 459 453 } 460 454 dput(dir); 461 - return ret; 455 + return dquot_file_open(inode, filp); 462 456 } 463 457 464 458 int truncate_data_blocks_range(struct dnode_of_data *dn, int count) ··· 533 527 truncate_out: 534 528 f2fs_wait_on_page_writeback(page, DATA, true); 535 529 zero_user(page, offset, PAGE_SIZE - offset); 536 - if (!cache_only || !f2fs_encrypted_inode(inode) || 537 - !S_ISREG(inode->i_mode)) 530 + 531 + /* An encrypted inode should have a key and truncate the last page. */ 532 + f2fs_bug_on(F2FS_I_SB(inode), cache_only && f2fs_encrypted_inode(inode)); 533 + if (!cache_only) 538 534 set_page_dirty(page); 539 535 f2fs_put_page(page, 1); 540 536 return 0; ··· 641 633 } 642 634 643 635 int f2fs_getattr(const struct path *path, struct kstat *stat, 644 - u32 request_mask, unsigned int flags) 636 + u32 request_mask, unsigned int query_flags) 645 637 { 646 638 struct inode *inode = d_inode(path->dentry); 639 + struct f2fs_inode_info *fi = F2FS_I(inode); 640 + unsigned int flags; 641 + 642 + flags = fi->i_flags & FS_FL_USER_VISIBLE; 643 + if (flags & FS_APPEND_FL) 644 + stat->attributes |= STATX_ATTR_APPEND; 645 + if (flags & FS_COMPR_FL) 646 + stat->attributes |= STATX_ATTR_COMPRESSED; 647 + if (f2fs_encrypted_inode(inode)) 648 + stat->attributes |= STATX_ATTR_ENCRYPTED; 649 + if (flags & FS_IMMUTABLE_FL) 650 + stat->attributes |= STATX_ATTR_IMMUTABLE; 651 + if (flags & FS_NODUMP_FL) 652 + stat->attributes |= STATX_ATTR_NODUMP; 653 + 654 + stat->attributes_mask |= (STATX_ATTR_APPEND | 655 + STATX_ATTR_COMPRESSED | 656 + STATX_ATTR_ENCRYPTED | 657 + STATX_ATTR_IMMUTABLE | 658 + STATX_ATTR_NODUMP); 659 + 647 660 generic_fillattr(inode, stat); 648 - stat->blocks <<= 3; 649 661 return 0; 650 662 } 651 663 ··· 709 681 if (err) 710 682 return err; 711 683 684 + if (is_quota_modification(inode, attr)) { 685 + err = dquot_initialize(inode); 686 + if (err) 687 + return err; 688 + } 689 + if ((attr->ia_valid & ATTR_UID && 690 + !uid_eq(attr->ia_uid, inode->i_uid)) || 691 + (attr->ia_valid & ATTR_GID && 692 + !gid_eq(attr->ia_gid, inode->i_gid))) { 693 + err = dquot_transfer(inode, attr); 694 + if (err) 695 + return err; 696 + } 697 + 712 698 if (attr->ia_valid & ATTR_SIZE) { 713 - if (f2fs_encrypted_inode(inode) && 714 - fscrypt_get_encryption_info(inode)) 715 - return -EACCES; 699 + if (f2fs_encrypted_inode(inode)) { 700 + err = fscrypt_get_encryption_info(inode); 701 + if (err) 702 + return err; 703 + if (!fscrypt_has_encryption_key(inode)) 704 + return -ENOKEY; 705 + } 716 706 717 707 if (attr->ia_size <= i_size_read(inode)) { 708 + down_write(&F2FS_I(inode)->i_mmap_sem); 718 709 truncate_setsize(inode, attr->ia_size); 719 710 err = f2fs_truncate(inode); 711 + up_write(&F2FS_I(inode)->i_mmap_sem); 720 712 if (err) 721 713 return err; 722 714 } else { ··· 744 696 * do not trim all blocks after i_size if target size is 745 697 * larger than i_size. 746 698 */ 699 + down_write(&F2FS_I(inode)->i_mmap_sem); 747 700 truncate_setsize(inode, attr->ia_size); 701 + up_write(&F2FS_I(inode)->i_mmap_sem); 748 702 749 703 /* should convert inline inode here */ 750 704 if (!f2fs_may_inline_data(inode)) { ··· 889 839 890 840 blk_start = (loff_t)pg_start << PAGE_SHIFT; 891 841 blk_end = (loff_t)pg_end << PAGE_SHIFT; 842 + down_write(&F2FS_I(inode)->i_mmap_sem); 892 843 truncate_inode_pages_range(mapping, blk_start, 893 844 blk_end - 1); 894 845 895 846 f2fs_lock_op(sbi); 896 847 ret = truncate_hole(inode, pg_start, pg_end); 897 848 f2fs_unlock_op(sbi); 849 + up_write(&F2FS_I(inode)->i_mmap_sem); 898 850 } 899 851 } 900 852 ··· 1009 957 1010 958 if (do_replace[i]) { 1011 959 f2fs_i_blocks_write(src_inode, 1012 - 1, false); 960 + 1, false, false); 1013 961 f2fs_i_blocks_write(dst_inode, 1014 - 1, true); 962 + 1, true, false); 1015 963 f2fs_replace_block(sbi, &dn, dn.data_blkaddr, 1016 964 blkaddr[i], ni.version, true, false); 1017 965 ··· 1135 1083 pg_start = offset >> PAGE_SHIFT; 1136 1084 pg_end = (offset + len) >> PAGE_SHIFT; 1137 1085 1086 + down_write(&F2FS_I(inode)->i_mmap_sem); 1138 1087 /* write out all dirty pages from offset */ 1139 1088 ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); 1140 1089 if (ret) 1141 - return ret; 1090 + goto out; 1142 1091 1143 1092 truncate_pagecache(inode, offset); 1144 1093 1145 1094 ret = f2fs_do_collapse(inode, pg_start, pg_end); 1146 1095 if (ret) 1147 - return ret; 1096 + goto out; 1148 1097 1149 1098 /* write out all moved pages, if possible */ 1150 1099 filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); ··· 1158 1105 if (!ret) 1159 1106 f2fs_i_size_write(inode, new_size); 1160 1107 1108 + out: 1109 + up_write(&F2FS_I(inode)->i_mmap_sem); 1161 1110 return ret; 1162 1111 } 1163 1112 ··· 1224 1169 if (ret) 1225 1170 return ret; 1226 1171 1172 + down_write(&F2FS_I(inode)->i_mmap_sem); 1227 1173 ret = filemap_write_and_wait_range(mapping, offset, offset + len - 1); 1228 1174 if (ret) 1229 - return ret; 1175 + goto out_sem; 1230 1176 1231 1177 truncate_pagecache_range(inode, offset, offset + len - 1); 1232 1178 ··· 1241 1185 ret = fill_zero(inode, pg_start, off_start, 1242 1186 off_end - off_start); 1243 1187 if (ret) 1244 - return ret; 1188 + goto out_sem; 1245 1189 1246 1190 new_size = max_t(loff_t, new_size, offset + len); 1247 1191 } else { ··· 1249 1193 ret = fill_zero(inode, pg_start++, off_start, 1250 1194 PAGE_SIZE - off_start); 1251 1195 if (ret) 1252 - return ret; 1196 + goto out_sem; 1253 1197 1254 1198 new_size = max_t(loff_t, new_size, 1255 1199 (loff_t)pg_start << PAGE_SHIFT); ··· 1298 1242 out: 1299 1243 if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size) 1300 1244 f2fs_i_size_write(inode, new_size); 1245 + out_sem: 1246 + up_write(&F2FS_I(inode)->i_mmap_sem); 1301 1247 1302 1248 return ret; 1303 1249 } ··· 1329 1271 1330 1272 f2fs_balance_fs(sbi, true); 1331 1273 1274 + down_write(&F2FS_I(inode)->i_mmap_sem); 1332 1275 ret = truncate_blocks(inode, i_size_read(inode), true); 1333 1276 if (ret) 1334 - return ret; 1277 + goto out; 1335 1278 1336 1279 /* write out all dirty pages from offset */ 1337 1280 ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); 1338 1281 if (ret) 1339 - return ret; 1282 + goto out; 1340 1283 1341 1284 truncate_pagecache(inode, offset); 1342 1285 ··· 1366 1307 1367 1308 if (!ret) 1368 1309 f2fs_i_size_write(inode, new_size); 1310 + out: 1311 + up_write(&F2FS_I(inode)->i_mmap_sem); 1369 1312 return ret; 1370 1313 } 1371 1314 ··· 1536 1475 1537 1476 inode_lock(inode); 1538 1477 1478 + /* Is it quota file? Do not allow user to mess with it */ 1479 + if (IS_NOQUOTA(inode)) { 1480 + inode_unlock(inode); 1481 + ret = -EPERM; 1482 + goto unlock_out; 1483 + } 1484 + 1539 1485 flags = f2fs_mask_flags(inode->i_mode, flags); 1540 1486 1541 1487 oldflags = fi->i_flags; ··· 1561 1493 1562 1494 inode->i_ctime = current_time(inode); 1563 1495 f2fs_set_inode_flags(inode); 1564 - 1496 + f2fs_mark_inode_dirty_sync(inode, false); 1497 + unlock_out: 1565 1498 inode_unlock(inode); 1566 1499 out: 1567 1500 mnt_drop_write_file(filp); ··· 1926 1857 } 1927 1858 1928 1859 ret = f2fs_gc(sbi, sync, true, NULL_SEGNO); 1860 + out: 1861 + mnt_drop_write_file(filp); 1862 + return ret; 1863 + } 1864 + 1865 + static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg) 1866 + { 1867 + struct inode *inode = file_inode(filp); 1868 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1869 + struct f2fs_gc_range range; 1870 + u64 end; 1871 + int ret; 1872 + 1873 + if (!capable(CAP_SYS_ADMIN)) 1874 + return -EPERM; 1875 + 1876 + if (copy_from_user(&range, (struct f2fs_gc_range __user *)arg, 1877 + sizeof(range))) 1878 + return -EFAULT; 1879 + 1880 + if (f2fs_readonly(sbi->sb)) 1881 + return -EROFS; 1882 + 1883 + ret = mnt_want_write_file(filp); 1884 + if (ret) 1885 + return ret; 1886 + 1887 + end = range.start + range.len; 1888 + if (range.start < MAIN_BLKADDR(sbi) || end >= MAX_BLKADDR(sbi)) 1889 + return -EINVAL; 1890 + do_more: 1891 + if (!range.sync) { 1892 + if (!mutex_trylock(&sbi->gc_mutex)) { 1893 + ret = -EBUSY; 1894 + goto out; 1895 + } 1896 + } else { 1897 + mutex_lock(&sbi->gc_mutex); 1898 + } 1899 + 1900 + ret = f2fs_gc(sbi, range.sync, true, GET_SEGNO(sbi, range.start)); 1901 + range.start += sbi->blocks_per_seg; 1902 + if (range.start <= end) 1903 + goto do_more; 1929 1904 out: 1930 1905 mnt_drop_write_file(filp); 1931 1906 return ret; ··· 2419 2306 return f2fs_ioc_get_encryption_pwsalt(filp, arg); 2420 2307 case F2FS_IOC_GARBAGE_COLLECT: 2421 2308 return f2fs_ioc_gc(filp, arg); 2309 + case F2FS_IOC_GARBAGE_COLLECT_RANGE: 2310 + return f2fs_ioc_gc_range(filp, arg); 2422 2311 case F2FS_IOC_WRITE_CHECKPOINT: 2423 2312 return f2fs_ioc_write_checkpoint(filp, arg); 2424 2313 case F2FS_IOC_DEFRAGMENT: ··· 2440 2325 struct inode *inode = file_inode(file); 2441 2326 struct blk_plug plug; 2442 2327 ssize_t ret; 2443 - 2444 - if (f2fs_encrypted_inode(inode) && 2445 - !fscrypt_has_encryption_key(inode) && 2446 - fscrypt_get_encryption_info(inode)) 2447 - return -EACCES; 2448 2328 2449 2329 inode_lock(inode); 2450 2330 ret = generic_write_checks(iocb, from); ··· 2489 2379 case F2FS_IOC_GET_ENCRYPTION_PWSALT: 2490 2380 case F2FS_IOC_GET_ENCRYPTION_POLICY: 2491 2381 case F2FS_IOC_GARBAGE_COLLECT: 2382 + case F2FS_IOC_GARBAGE_COLLECT_RANGE: 2492 2383 case F2FS_IOC_WRITE_CHECKPOINT: 2493 2384 case F2FS_IOC_DEFRAGMENT: 2494 2385 case F2FS_IOC_MOVE_RANGE:
+28 -12
fs/f2fs/gc.c
··· 32 32 33 33 wait_ms = gc_th->min_sleep_time; 34 34 35 + set_freezable(); 35 36 do { 37 + wait_event_interruptible_timeout(*wq, 38 + kthread_should_stop() || freezing(current), 39 + msecs_to_jiffies(wait_ms)); 40 + 36 41 if (try_to_freeze()) 37 42 continue; 38 - else 39 - wait_event_interruptible_timeout(*wq, 40 - kthread_should_stop(), 41 - msecs_to_jiffies(wait_ms)); 42 43 if (kthread_should_stop()) 43 44 break; 44 45 ··· 259 258 valid_blocks * 2 : valid_blocks; 260 259 } 261 260 261 + static unsigned int get_ssr_cost(struct f2fs_sb_info *sbi, 262 + unsigned int segno) 263 + { 264 + struct seg_entry *se = get_seg_entry(sbi, segno); 265 + 266 + return se->ckpt_valid_blocks > se->valid_blocks ? 267 + se->ckpt_valid_blocks : se->valid_blocks; 268 + } 269 + 262 270 static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi, 263 271 unsigned int segno, struct victim_sel_policy *p) 264 272 { 265 273 if (p->alloc_mode == SSR) 266 - return get_seg_entry(sbi, segno)->ckpt_valid_blocks; 274 + return get_ssr_cost(sbi, segno); 267 275 268 276 /* alloc_mode == LFS */ 269 277 if (p->gc_mode == GC_GREEDY) ··· 596 586 struct f2fs_io_info fio = { 597 587 .sbi = F2FS_I_SB(inode), 598 588 .type = DATA, 589 + .temp = COLD, 599 590 .op = REQ_OP_READ, 600 591 .op_flags = 0, 601 592 .encrypted_page = NULL, 593 + .in_list = false, 602 594 }; 603 595 struct dnode_of_data dn; 604 596 struct f2fs_summary sum; ··· 644 632 fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr; 645 633 646 634 allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, 647 - &sum, CURSEG_COLD_DATA); 635 + &sum, CURSEG_COLD_DATA, NULL, false); 648 636 649 637 fio.encrypted_page = pagecache_get_page(META_MAPPING(fio.sbi), newaddr, 650 638 FGP_LOCK | FGP_CREAT, GFP_NOFS); ··· 682 670 fio.op = REQ_OP_WRITE; 683 671 fio.op_flags = REQ_SYNC; 684 672 fio.new_blkaddr = newaddr; 685 - f2fs_submit_page_mbio(&fio); 673 + f2fs_submit_page_write(&fio); 686 674 687 675 f2fs_update_data_blkaddr(&dn, newaddr); 688 676 set_inode_flag(inode, FI_APPEND_WRITE); ··· 724 712 struct f2fs_io_info fio = { 725 713 .sbi = F2FS_I_SB(inode), 726 714 .type = DATA, 715 + .temp = COLD, 727 716 .op = REQ_OP_WRITE, 728 717 .op_flags = REQ_SYNC, 729 718 .old_blkaddr = NULL_ADDR, 730 719 .page = page, 731 720 .encrypted_page = NULL, 732 - .need_lock = true, 721 + .need_lock = LOCK_REQ, 733 722 }; 734 723 bool is_dirty = PageDirty(page); 735 724 int err; ··· 949 936 } 950 937 951 938 if (gc_type == FG_GC) 952 - f2fs_submit_merged_bio(sbi, 953 - (type == SUM_TYPE_NODE) ? NODE : DATA, WRITE); 939 + f2fs_submit_merged_write(sbi, 940 + (type == SUM_TYPE_NODE) ? NODE : DATA); 954 941 955 942 blk_finish_plug(&plug); 956 943 ··· 968 955 { 969 956 int gc_type = sync ? FG_GC : BG_GC; 970 957 int sec_freed = 0; 971 - int ret = -EINVAL; 958 + int ret; 972 959 struct cp_control cpc; 973 960 unsigned int init_segno = segno; 974 961 struct gc_inode_list gc_list = { ··· 978 965 979 966 cpc.reason = __get_cp_reason(sbi); 980 967 gc_more: 981 - if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) 968 + if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) { 969 + ret = -EINVAL; 982 970 goto stop; 971 + } 983 972 if (unlikely(f2fs_cp_error(sbi))) { 984 973 ret = -EIO; 985 974 goto stop; ··· 1002 987 gc_type = FG_GC; 1003 988 } 1004 989 990 + ret = -EINVAL; 1005 991 /* f2fs_balance_fs doesn't need to do BG_GC in critical path. */ 1006 992 if (gc_type == BG_GC && !background) 1007 993 goto stop;
+11 -11
fs/f2fs/inline.c
··· 316 316 int make_empty_inline_dir(struct inode *inode, struct inode *parent, 317 317 struct page *ipage) 318 318 { 319 - struct f2fs_inline_dentry *dentry_blk; 319 + struct f2fs_inline_dentry *inline_dentry; 320 320 struct f2fs_dentry_ptr d; 321 321 322 - dentry_blk = inline_data_addr(ipage); 322 + inline_dentry = inline_data_addr(ipage); 323 323 324 - make_dentry_ptr_inline(NULL, &d, dentry_blk); 324 + make_dentry_ptr_inline(NULL, &d, inline_dentry); 325 325 do_make_empty_dir(inode, parent, &d); 326 326 327 327 set_page_dirty(ipage); ··· 500 500 struct page *ipage; 501 501 unsigned int bit_pos; 502 502 f2fs_hash_t name_hash; 503 - struct f2fs_inline_dentry *dentry_blk = NULL; 503 + struct f2fs_inline_dentry *inline_dentry = NULL; 504 504 struct f2fs_dentry_ptr d; 505 505 int slots = GET_DENTRY_SLOTS(new_name->len); 506 506 struct page *page = NULL; ··· 510 510 if (IS_ERR(ipage)) 511 511 return PTR_ERR(ipage); 512 512 513 - dentry_blk = inline_data_addr(ipage); 514 - bit_pos = room_for_filename(&dentry_blk->dentry_bitmap, 513 + inline_dentry = inline_data_addr(ipage); 514 + bit_pos = room_for_filename(&inline_dentry->dentry_bitmap, 515 515 slots, NR_INLINE_DENTRY); 516 516 if (bit_pos >= NR_INLINE_DENTRY) { 517 - err = f2fs_convert_inline_dir(dir, ipage, dentry_blk); 517 + err = f2fs_convert_inline_dir(dir, ipage, inline_dentry); 518 518 if (err) 519 519 return err; 520 520 err = -EAGAIN; ··· 534 534 f2fs_wait_on_page_writeback(ipage, NODE, true); 535 535 536 536 name_hash = f2fs_dentry_hash(new_name, NULL); 537 - make_dentry_ptr_inline(NULL, &d, dentry_blk); 537 + make_dentry_ptr_inline(NULL, &d, inline_dentry); 538 538 f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos); 539 539 540 540 set_page_dirty(ipage); ··· 586 586 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 587 587 struct page *ipage; 588 588 unsigned int bit_pos = 2; 589 - struct f2fs_inline_dentry *dentry_blk; 589 + struct f2fs_inline_dentry *inline_dentry; 590 590 591 591 ipage = get_node_page(sbi, dir->i_ino); 592 592 if (IS_ERR(ipage)) 593 593 return false; 594 594 595 - dentry_blk = inline_data_addr(ipage); 596 - bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, 595 + inline_dentry = inline_data_addr(ipage); 596 + bit_pos = find_next_bit_le(&inline_dentry->dentry_bitmap, 597 597 NR_INLINE_DENTRY, 598 598 bit_pos); 599 599
+12 -5
fs/f2fs/inode.c
··· 16 16 17 17 #include "f2fs.h" 18 18 #include "node.h" 19 + #include "segment.h" 19 20 20 21 #include <trace/events/f2fs.h> 21 22 ··· 45 44 new_fl |= S_DIRSYNC; 46 45 inode_set_flags(inode, new_fl, 47 46 S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); 48 - f2fs_mark_inode_dirty_sync(inode, false); 49 47 } 50 48 51 49 static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri) ··· 130 130 i_gid_write(inode, le32_to_cpu(ri->i_gid)); 131 131 set_nlink(inode, le32_to_cpu(ri->i_links)); 132 132 inode->i_size = le64_to_cpu(ri->i_size); 133 - inode->i_blocks = le64_to_cpu(ri->i_blocks); 133 + inode->i_blocks = SECTOR_FROM_BLOCK(le64_to_cpu(ri->i_blocks) - 1); 134 134 135 135 inode->i_atime.tv_sec = le64_to_cpu(ri->i_atime); 136 136 inode->i_ctime.tv_sec = le64_to_cpu(ri->i_ctime); ··· 226 226 ret = -EIO; 227 227 goto bad_inode; 228 228 } 229 + f2fs_set_inode_flags(inode); 229 230 unlock_new_inode(inode); 230 231 trace_f2fs_iget(inode); 231 232 return inode; ··· 268 267 ri->i_gid = cpu_to_le32(i_gid_read(inode)); 269 268 ri->i_links = cpu_to_le32(inode->i_nlink); 270 269 ri->i_size = cpu_to_le64(i_size_read(inode)); 271 - ri->i_blocks = cpu_to_le64(inode->i_blocks); 270 + ri->i_blocks = cpu_to_le64(SECTOR_TO_BLOCK(inode->i_blocks) + 1); 272 271 273 272 if (et) { 274 273 read_lock(&et->lock); ··· 373 372 if (inode->i_nlink || is_bad_inode(inode)) 374 373 goto no_delete; 375 374 375 + dquot_initialize(inode); 376 + 376 377 remove_ino_entry(sbi, inode->i_ino, APPEND_INO); 377 378 remove_ino_entry(sbi, inode->i_ino, UPDATE_INO); 378 379 ··· 407 404 408 405 if (err) 409 406 update_inode_page(inode); 407 + dquot_free_inode(inode); 410 408 sb_end_intwrite(inode->i_sb); 411 409 no_delete: 410 + dquot_drop(inode); 411 + 412 412 stat_dec_inline_xattr(inode); 413 413 stat_dec_inline_dir(inode); 414 414 stat_dec_inline_inode(inode); ··· 431 425 if (is_inode_flag_set(inode, FI_FREE_NID)) { 432 426 alloc_nid_failed(sbi, inode->i_ino); 433 427 clear_inode_flag(inode, FI_FREE_NID); 428 + } else { 429 + f2fs_bug_on(sbi, err && 430 + !exist_written_data(sbi, inode->i_ino, ORPHAN_INO)); 434 431 } 435 - f2fs_bug_on(sbi, err && 436 - !exist_written_data(sbi, inode->i_ino, ORPHAN_INO)); 437 432 out_clear: 438 433 fscrypt_put_encryption_info(inode, NULL); 439 434 clear_inode(inode);
+69 -2
fs/f2fs/namei.c
··· 15 15 #include <linux/ctype.h> 16 16 #include <linux/dcache.h> 17 17 #include <linux/namei.h> 18 + #include <linux/quotaops.h> 18 19 19 20 #include "f2fs.h" 20 21 #include "node.h" ··· 43 42 } 44 43 f2fs_unlock_op(sbi); 45 44 45 + nid_free = true; 46 + 46 47 inode_init_owner(inode, dir, mode); 47 48 48 49 inode->i_ino = ino; ··· 55 52 err = insert_inode_locked(inode); 56 53 if (err) { 57 54 err = -EINVAL; 58 - nid_free = true; 59 55 goto fail; 60 56 } 57 + 58 + err = dquot_initialize(inode); 59 + if (err) 60 + goto fail_drop; 61 + 62 + err = dquot_alloc_inode(inode); 63 + if (err) 64 + goto fail_drop; 61 65 62 66 /* If the directory encrypted, then we should encrypt the inode. */ 63 67 if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) ··· 93 83 make_bad_inode(inode); 94 84 if (nid_free) 95 85 set_inode_flag(inode, FI_FREE_NID); 86 + iput(inode); 87 + return ERR_PTR(err); 88 + fail_drop: 89 + trace_f2fs_new_inode(inode, err); 90 + dquot_drop(inode); 91 + inode->i_flags |= S_NOQUOTA; 92 + if (nid_free) 93 + set_inode_flag(inode, FI_FREE_NID); 94 + clear_nlink(inode); 95 + unlock_new_inode(inode); 96 96 iput(inode); 97 97 return ERR_PTR(err); 98 98 } ··· 156 136 nid_t ino = 0; 157 137 int err; 158 138 139 + err = dquot_initialize(dir); 140 + if (err) 141 + return err; 142 + 159 143 inode = f2fs_new_inode(dir, mode); 160 144 if (IS_ERR(inode)) 161 145 return PTR_ERR(inode); ··· 203 179 if (f2fs_encrypted_inode(dir) && 204 180 !fscrypt_has_permitted_context(dir, inode)) 205 181 return -EPERM; 182 + 183 + err = dquot_initialize(dir); 184 + if (err) 185 + return err; 206 186 207 187 f2fs_balance_fs(sbi, true); 208 188 ··· 375 347 376 348 trace_f2fs_unlink_enter(dir, dentry); 377 349 350 + err = dquot_initialize(dir); 351 + if (err) 352 + return err; 353 + 378 354 de = f2fs_find_entry(dir, &dentry->d_name, &page); 379 355 if (!de) { 380 356 if (IS_ERR(page)) ··· 444 412 445 413 if (disk_link.len > dir->i_sb->s_blocksize) 446 414 return -ENAMETOOLONG; 415 + 416 + err = dquot_initialize(dir); 417 + if (err) 418 + return err; 447 419 448 420 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO); 449 421 if (IS_ERR(inode)) ··· 536 500 struct inode *inode; 537 501 int err; 538 502 503 + err = dquot_initialize(dir); 504 + if (err) 505 + return err; 506 + 539 507 inode = f2fs_new_inode(dir, S_IFDIR | mode); 540 508 if (IS_ERR(inode)) 541 509 return PTR_ERR(inode); ··· 588 548 struct inode *inode; 589 549 int err = 0; 590 550 551 + err = dquot_initialize(dir); 552 + if (err) 553 + return err; 554 + 591 555 inode = f2fs_new_inode(dir, mode); 592 556 if (IS_ERR(inode)) 593 557 return PTR_ERR(inode); ··· 626 582 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 627 583 struct inode *inode; 628 584 int err; 585 + 586 + err = dquot_initialize(dir); 587 + if (err) 588 + return err; 629 589 630 590 inode = f2fs_new_inode(dir, mode); 631 591 if (IS_ERR(inode)) ··· 723 675 err = -EPERM; 724 676 goto out; 725 677 } 678 + 679 + err = dquot_initialize(old_dir); 680 + if (err) 681 + goto out; 682 + 683 + err = dquot_initialize(new_dir); 684 + if (err) 685 + goto out; 726 686 727 687 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); 728 688 if (!old_entry) { ··· 828 772 } 829 773 830 774 down_write(&F2FS_I(old_inode)->i_sem); 831 - file_lost_pino(old_inode); 775 + if (!old_dir_entry || whiteout) 776 + file_lost_pino(old_inode); 777 + else 778 + F2FS_I(old_inode)->i_pino = new_dir->i_ino; 832 779 up_write(&F2FS_I(old_inode)->i_sem); 833 780 834 781 old_inode->i_ctime = current_time(old_inode); ··· 911 852 (!fscrypt_has_permitted_context(new_dir, old_inode) || 912 853 !fscrypt_has_permitted_context(old_dir, new_inode))) 913 854 return -EPERM; 855 + 856 + err = dquot_initialize(old_dir); 857 + if (err) 858 + goto out; 859 + 860 + err = dquot_initialize(new_dir); 861 + if (err) 862 + goto out; 914 863 915 864 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); 916 865 if (!old_entry) {
+38 -29
fs/f2fs/node.c
··· 158 158 nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid); 159 159 struct nat_entry_set *head; 160 160 161 - if (get_nat_flag(ne, IS_DIRTY)) 162 - return; 163 - 164 161 head = radix_tree_lookup(&nm_i->nat_set_root, set); 165 162 if (!head) { 166 163 head = f2fs_kmem_cache_alloc(nat_entry_set_slab, GFP_NOFS); ··· 168 171 head->entry_cnt = 0; 169 172 f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head); 170 173 } 171 - list_move_tail(&ne->list, &head->entry_list); 174 + 175 + if (get_nat_flag(ne, IS_DIRTY)) 176 + goto refresh_list; 177 + 172 178 nm_i->dirty_nat_cnt++; 173 179 head->entry_cnt++; 174 180 set_nat_flag(ne, IS_DIRTY, true); 181 + refresh_list: 182 + if (nat_get_blkaddr(ne) == NEW_ADDR) 183 + list_del_init(&ne->list); 184 + else 185 + list_move_tail(&ne->list, &head->entry_list); 175 186 } 176 187 177 188 static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i, ··· 678 673 struct node_info ni; 679 674 680 675 get_node_info(sbi, dn->nid, &ni); 681 - if (dn->inode->i_blocks == 0) { 682 - f2fs_bug_on(sbi, ni.blk_addr != NULL_ADDR); 683 - goto invalidate; 684 - } 685 676 f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR); 686 677 687 678 /* Deallocate node address */ 688 679 invalidate_blocks(sbi, ni.blk_addr); 689 - dec_valid_node_count(sbi, dn->inode); 680 + dec_valid_node_count(sbi, dn->inode, dn->nid == dn->inode->i_ino); 690 681 set_node_addr(sbi, &ni, NULL_ADDR, false); 691 682 692 683 if (dn->nid == dn->inode->i_ino) { ··· 690 689 dec_valid_inode_count(sbi); 691 690 f2fs_inode_synced(dn->inode); 692 691 } 693 - invalidate: 692 + 694 693 clear_node_page_dirty(dn->node_page); 695 694 set_sbi_flag(sbi, SBI_IS_DIRTY); 696 695 ··· 1007 1006 1008 1007 /* 0 is possible, after f2fs_new_inode() has failed */ 1009 1008 f2fs_bug_on(F2FS_I_SB(inode), 1010 - inode->i_blocks != 0 && inode->i_blocks != 1); 1009 + inode->i_blocks != 0 && inode->i_blocks != 8); 1011 1010 1012 1011 /* will put inode & node pages */ 1013 1012 truncate_node(&dn); ··· 1040 1039 if (!page) 1041 1040 return ERR_PTR(-ENOMEM); 1042 1041 1043 - if (unlikely(!inc_valid_node_count(sbi, dn->inode))) { 1044 - err = -ENOSPC; 1042 + if (unlikely((err = inc_valid_node_count(sbi, dn->inode, !ofs)))) 1045 1043 goto fail; 1046 - } 1044 + 1047 1045 #ifdef CONFIG_F2FS_CHECK_FS 1048 1046 get_node_info(sbi, dn->nid, &new_ni); 1049 1047 f2fs_bug_on(sbi, new_ni.blk_addr != NULL_ADDR); ··· 1152 1152 f2fs_put_page(page, 1); 1153 1153 return ERR_PTR(err); 1154 1154 } else if (err == LOCKED_PAGE) { 1155 + err = 0; 1155 1156 goto page_hit; 1156 1157 } 1157 1158 ··· 1166 1165 goto repeat; 1167 1166 } 1168 1167 1169 - if (unlikely(!PageUptodate(page))) 1168 + if (unlikely(!PageUptodate(page))) { 1169 + err = -EIO; 1170 1170 goto out_err; 1171 + } 1171 1172 page_hit: 1172 1173 if(unlikely(nid != nid_of_node(page))) { 1173 - f2fs_bug_on(sbi, 1); 1174 + f2fs_msg(sbi->sb, KERN_WARNING, "inconsistent node block, " 1175 + "nid:%lu, node_footer[nid:%u,ino:%u,ofs:%u,cpver:%llu,blkaddr:%u]", 1176 + nid, nid_of_node(page), ino_of_node(page), 1177 + ofs_of_node(page), cpver_of_node(page), 1178 + next_blkaddr_of_node(page)); 1174 1179 ClearPageUptodate(page); 1180 + err = -EINVAL; 1175 1181 out_err: 1176 1182 f2fs_put_page(page, 1); 1177 - return ERR_PTR(-EIO); 1183 + return ERR_PTR(err); 1178 1184 } 1179 1185 return page; 1180 1186 } ··· 1381 1373 up_read(&sbi->node_write); 1382 1374 1383 1375 if (wbc->for_reclaim) { 1384 - f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 0, 1385 - page->index, NODE, WRITE); 1376 + f2fs_submit_merged_write_cond(sbi, page->mapping->host, 0, 1377 + page->index, NODE); 1386 1378 submitted = NULL; 1387 1379 } 1388 1380 1389 1381 unlock_page(page); 1390 1382 1391 1383 if (unlikely(f2fs_cp_error(sbi))) { 1392 - f2fs_submit_merged_bio(sbi, NODE, WRITE); 1384 + f2fs_submit_merged_write(sbi, NODE); 1393 1385 submitted = NULL; 1394 1386 } 1395 1387 if (submitted) ··· 1526 1518 } 1527 1519 out: 1528 1520 if (last_idx != ULONG_MAX) 1529 - f2fs_submit_merged_bio_cond(sbi, NULL, ino, last_idx, 1530 - NODE, WRITE); 1521 + f2fs_submit_merged_write_cond(sbi, NULL, ino, last_idx, NODE); 1531 1522 return ret ? -EIO: 0; 1532 1523 } 1533 1524 ··· 1632 1625 } 1633 1626 out: 1634 1627 if (nwritten) 1635 - f2fs_submit_merged_bio(sbi, NODE, WRITE); 1628 + f2fs_submit_merged_write(sbi, NODE); 1636 1629 return ret; 1637 1630 } 1638 1631 ··· 1681 1674 struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); 1682 1675 struct blk_plug plug; 1683 1676 long diff; 1677 + 1678 + if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 1679 + goto skip_write; 1684 1680 1685 1681 /* balancing f2fs's metadata in background */ 1686 1682 f2fs_balance_fs_bg(sbi); ··· 2202 2192 get_node_info(sbi, prev_xnid, &ni); 2203 2193 f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR); 2204 2194 invalidate_blocks(sbi, ni.blk_addr); 2205 - dec_valid_node_count(sbi, inode); 2195 + dec_valid_node_count(sbi, inode, false); 2206 2196 set_node_addr(sbi, &ni, NULL_ADDR, false); 2207 2197 2208 2198 recover_xnid: 2209 2199 /* 2: update xattr nid in inode */ 2210 2200 remove_free_nid(sbi, new_xnid); 2211 2201 f2fs_i_xnid_write(inode, new_xnid); 2212 - if (unlikely(!inc_valid_node_count(sbi, inode))) 2202 + if (unlikely(inc_valid_node_count(sbi, inode, false))) 2213 2203 f2fs_bug_on(sbi, 1); 2214 2204 update_inode_page(inode); 2215 2205 ··· 2267 2257 new_ni = old_ni; 2268 2258 new_ni.ino = ino; 2269 2259 2270 - if (unlikely(!inc_valid_node_count(sbi, NULL))) 2260 + if (unlikely(inc_valid_node_count(sbi, NULL, true))) 2271 2261 WARN_ON(1); 2272 2262 set_node_addr(sbi, &new_ni, NEW_ADDR, false); 2273 2263 inc_valid_inode_count(sbi); ··· 2434 2424 nid_t nid = nat_get_nid(ne); 2435 2425 int offset; 2436 2426 2437 - if (nat_get_blkaddr(ne) == NEW_ADDR) 2438 - continue; 2427 + f2fs_bug_on(sbi, nat_get_blkaddr(ne) == NEW_ADDR); 2439 2428 2440 2429 if (to_journal) { 2441 2430 offset = lookup_journal_in_cursum(journal, ··· 2562 2553 return 0; 2563 2554 } 2564 2555 2565 - inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi) 2556 + static inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi) 2566 2557 { 2567 2558 struct f2fs_nm_info *nm_i = NM_I(sbi); 2568 2559 unsigned int i = 0;
+1 -5
fs/f2fs/node.h
··· 224 224 struct f2fs_nm_info *nm_i = NM_I(sbi); 225 225 226 226 block_addr -= nm_i->nat_blkaddr; 227 - if ((block_addr >> sbi->log_blocks_per_seg) % 2) 228 - block_addr -= sbi->blocks_per_seg; 229 - else 230 - block_addr += sbi->blocks_per_seg; 231 - 227 + block_addr ^= 1 << sbi->log_blocks_per_seg; 232 228 return block_addr + nm_i->nat_blkaddr; 233 229 } 234 230
+160 -76
fs/f2fs/segment.c
··· 16 16 #include <linux/kthread.h> 17 17 #include <linux/swap.h> 18 18 #include <linux/timer.h> 19 + #include <linux/freezer.h> 19 20 20 21 #include "f2fs.h" 21 22 #include "segment.h" ··· 313 312 fio.page = page; 314 313 fio.old_blkaddr = NULL_ADDR; 315 314 fio.encrypted_page = NULL; 316 - fio.need_lock = false, 315 + fio.need_lock = LOCK_DONE; 317 316 err = do_write_data_page(&fio); 318 317 if (err) { 319 318 unlock_page(page); ··· 329 328 } 330 329 331 330 if (last_idx != ULONG_MAX) 332 - f2fs_submit_merged_bio_cond(sbi, inode, 0, last_idx, 333 - DATA, WRITE); 331 + f2fs_submit_merged_write_cond(sbi, inode, 0, last_idx, DATA); 334 332 335 333 if (!err) 336 334 __revoke_inmem_pages(inode, revoke_list, false, false); ··· 555 555 556 556 if (SM_I(sbi)->fcc_info) { 557 557 fcc = SM_I(sbi)->fcc_info; 558 + if (fcc->f2fs_issue_flush) 559 + return err; 558 560 goto init_thread; 559 561 } 560 562 ··· 568 566 init_waitqueue_head(&fcc->flush_wait_queue); 569 567 init_llist_head(&fcc->issue_list); 570 568 SM_I(sbi)->fcc_info = fcc; 569 + if (!test_opt(sbi, FLUSH_MERGE)) 570 + return err; 571 + 571 572 init_thread: 572 573 fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi, 573 574 "f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev)); ··· 741 736 { 742 737 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 743 738 739 + f2fs_bug_on(sbi, dc->ref); 740 + 744 741 if (dc->error == -EOPNOTSUPP) 745 742 dc->error = 0; 746 743 747 744 if (dc->error) 748 745 f2fs_msg(sbi->sb, KERN_INFO, 749 - "Issue discard failed, ret: %d", dc->error); 746 + "Issue discard(%u, %u, %u) failed, ret: %d", 747 + dc->lstart, dc->start, dc->len, dc->error); 750 748 __detach_discard_cmd(dcc, dc); 751 749 } 752 750 ··· 759 751 760 752 dc->error = blk_status_to_errno(bio->bi_status); 761 753 dc->state = D_DONE; 762 - complete(&dc->wait); 754 + complete_all(&dc->wait); 763 755 bio_put(bio); 756 + } 757 + 758 + void __check_sit_bitmap(struct f2fs_sb_info *sbi, 759 + block_t start, block_t end) 760 + { 761 + #ifdef CONFIG_F2FS_CHECK_FS 762 + struct seg_entry *sentry; 763 + unsigned int segno; 764 + block_t blk = start; 765 + unsigned long offset, size, max_blocks = sbi->blocks_per_seg; 766 + unsigned long *map; 767 + 768 + while (blk < end) { 769 + segno = GET_SEGNO(sbi, blk); 770 + sentry = get_seg_entry(sbi, segno); 771 + offset = GET_BLKOFF_FROM_SEG0(sbi, blk); 772 + 773 + size = min((unsigned long)(end - blk), max_blocks); 774 + map = (unsigned long *)(sentry->cur_valid_map); 775 + offset = __find_rev_next_bit(map, size, offset); 776 + f2fs_bug_on(sbi, offset != size); 777 + blk += size; 778 + } 779 + #endif 764 780 } 765 781 766 782 /* this function is copied from blkdev_issue_discard from block/blk-lib.c */ ··· 814 782 bio->bi_opf |= REQ_SYNC; 815 783 submit_bio(bio); 816 784 list_move_tail(&dc->list, &dcc->wait_list); 785 + __check_sit_bitmap(sbi, dc->start, dc->start + dc->len); 817 786 } 818 787 } else { 819 788 __remove_discard_cmd(sbi, dc); ··· 871 838 dc->len = blkaddr - dc->lstart; 872 839 dcc->undiscard_blks += dc->len; 873 840 __relocate_discard_cmd(dcc, dc); 874 - f2fs_bug_on(sbi, !__check_rb_tree_consistence(sbi, &dcc->root)); 875 841 modified = true; 876 842 } 877 843 ··· 880 848 di.start + blkaddr + 1 - di.lstart, 881 849 di.lstart + di.len - 1 - blkaddr, 882 850 NULL, NULL); 883 - f2fs_bug_on(sbi, 884 - !__check_rb_tree_consistence(sbi, &dcc->root)); 885 851 } else { 886 852 dc->lstart++; 887 853 dc->len--; 888 854 dc->start++; 889 855 dcc->undiscard_blks += dc->len; 890 856 __relocate_discard_cmd(dcc, dc); 891 - f2fs_bug_on(sbi, 892 - !__check_rb_tree_consistence(sbi, &dcc->root)); 893 857 } 894 858 } 895 859 } ··· 946 918 prev_dc->di.len += di.len; 947 919 dcc->undiscard_blks += di.len; 948 920 __relocate_discard_cmd(dcc, prev_dc); 949 - f2fs_bug_on(sbi, 950 - !__check_rb_tree_consistence(sbi, &dcc->root)); 951 921 di = prev_dc->di; 952 922 tdc = prev_dc; 953 923 merged = true; ··· 961 935 __relocate_discard_cmd(dcc, next_dc); 962 936 if (tdc) 963 937 __remove_discard_cmd(sbi, tdc); 964 - f2fs_bug_on(sbi, 965 - !__check_rb_tree_consistence(sbi, &dcc->root)); 966 938 merged = true; 967 939 } 968 940 969 941 if (!merged) { 970 942 __insert_discard_tree(sbi, bdev, di.lstart, di.start, 971 943 di.len, NULL, NULL); 972 - f2fs_bug_on(sbi, 973 - !__check_rb_tree_consistence(sbi, &dcc->root)); 974 944 } 975 945 next: 976 946 prev_dc = next_dc; ··· 1005 983 int i, iter = 0; 1006 984 1007 985 mutex_lock(&dcc->cmd_lock); 986 + f2fs_bug_on(sbi, 987 + !__check_rb_tree_consistence(sbi, &dcc->root)); 1008 988 blk_start_plug(&plug); 1009 989 for (i = MAX_PLIST_NUM - 1; i >= 0; i--) { 1010 990 pend_list = &dcc->pend_list[i]; ··· 1024 1000 mutex_unlock(&dcc->cmd_lock); 1025 1001 } 1026 1002 1003 + static void __wait_one_discard_bio(struct f2fs_sb_info *sbi, 1004 + struct discard_cmd *dc) 1005 + { 1006 + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1007 + 1008 + wait_for_completion_io(&dc->wait); 1009 + mutex_lock(&dcc->cmd_lock); 1010 + f2fs_bug_on(sbi, dc->state != D_DONE); 1011 + dc->ref--; 1012 + if (!dc->ref) 1013 + __remove_discard_cmd(sbi, dc); 1014 + mutex_unlock(&dcc->cmd_lock); 1015 + } 1016 + 1027 1017 static void __wait_discard_cmd(struct f2fs_sb_info *sbi, bool wait_cond) 1028 1018 { 1029 1019 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1030 1020 struct list_head *wait_list = &(dcc->wait_list); 1031 1021 struct discard_cmd *dc, *tmp; 1022 + bool need_wait; 1023 + 1024 + next: 1025 + need_wait = false; 1032 1026 1033 1027 mutex_lock(&dcc->cmd_lock); 1034 1028 list_for_each_entry_safe(dc, tmp, wait_list, list) { 1035 - if (!wait_cond || dc->state == D_DONE) { 1036 - if (dc->ref) 1037 - continue; 1029 + if (!wait_cond || (dc->state == D_DONE && !dc->ref)) { 1038 1030 wait_for_completion_io(&dc->wait); 1039 1031 __remove_discard_cmd(sbi, dc); 1032 + } else { 1033 + dc->ref++; 1034 + need_wait = true; 1035 + break; 1040 1036 } 1041 1037 } 1042 1038 mutex_unlock(&dcc->cmd_lock); 1039 + 1040 + if (need_wait) { 1041 + __wait_one_discard_bio(sbi, dc); 1042 + goto next; 1043 + } 1043 1044 } 1044 1045 1045 1046 /* This should be covered by global mutex, &sit_i->sentry_lock */ ··· 1086 1037 } 1087 1038 mutex_unlock(&dcc->cmd_lock); 1088 1039 1089 - if (need_wait) { 1090 - wait_for_completion_io(&dc->wait); 1091 - mutex_lock(&dcc->cmd_lock); 1092 - f2fs_bug_on(sbi, dc->state != D_DONE); 1093 - dc->ref--; 1094 - if (!dc->ref) 1095 - __remove_discard_cmd(sbi, dc); 1096 - mutex_unlock(&dcc->cmd_lock); 1040 + if (need_wait) 1041 + __wait_one_discard_bio(sbi, dc); 1042 + } 1043 + 1044 + void stop_discard_thread(struct f2fs_sb_info *sbi) 1045 + { 1046 + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1047 + 1048 + if (dcc && dcc->f2fs_issue_discard) { 1049 + struct task_struct *discard_thread = dcc->f2fs_issue_discard; 1050 + 1051 + dcc->f2fs_issue_discard = NULL; 1052 + kthread_stop(discard_thread); 1097 1053 } 1098 1054 } 1099 1055 ··· 1114 1060 struct f2fs_sb_info *sbi = data; 1115 1061 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1116 1062 wait_queue_head_t *q = &dcc->discard_wait_queue; 1117 - repeat: 1118 - if (kthread_should_stop()) 1119 - return 0; 1120 1063 1121 - __issue_discard_cmd(sbi, true); 1122 - __wait_discard_cmd(sbi, true); 1064 + set_freezable(); 1123 1065 1124 - congestion_wait(BLK_RW_SYNC, HZ/50); 1066 + do { 1067 + wait_event_interruptible(*q, kthread_should_stop() || 1068 + freezing(current) || 1069 + atomic_read(&dcc->discard_cmd_cnt)); 1070 + if (try_to_freeze()) 1071 + continue; 1072 + if (kthread_should_stop()) 1073 + return 0; 1125 1074 1126 - wait_event_interruptible(*q, kthread_should_stop() || 1127 - atomic_read(&dcc->discard_cmd_cnt)); 1128 - goto repeat; 1075 + __issue_discard_cmd(sbi, true); 1076 + __wait_discard_cmd(sbi, true); 1077 + 1078 + congestion_wait(BLK_RW_SYNC, HZ/50); 1079 + } while (!kthread_should_stop()); 1080 + return 0; 1129 1081 } 1130 1082 1131 1083 #ifdef CONFIG_BLK_DEV_ZONED ··· 1382 1322 sbi->blocks_per_seg, cur_pos); 1383 1323 len = next_pos - cur_pos; 1384 1324 1385 - if (force && len < cpc->trim_minlen) 1325 + if (f2fs_sb_mounted_blkzoned(sbi->sb) || 1326 + (force && len < cpc->trim_minlen)) 1386 1327 goto skip; 1387 1328 1388 1329 f2fs_issue_discard(sbi, entry->start_blkaddr + cur_pos, ··· 1459 1398 if (!dcc) 1460 1399 return; 1461 1400 1462 - if (dcc->f2fs_issue_discard) { 1463 - struct task_struct *discard_thread = dcc->f2fs_issue_discard; 1464 - 1465 - dcc->f2fs_issue_discard = NULL; 1466 - kthread_stop(discard_thread); 1467 - } 1401 + stop_discard_thread(sbi); 1468 1402 1469 1403 kfree(dcc); 1470 1404 SM_I(sbi)->dcc_info = NULL; ··· 2096 2040 return false; 2097 2041 } 2098 2042 2099 - static int __get_segment_type_2(struct page *page, enum page_type p_type) 2043 + static int __get_segment_type_2(struct f2fs_io_info *fio) 2100 2044 { 2101 - if (p_type == DATA) 2045 + if (fio->type == DATA) 2102 2046 return CURSEG_HOT_DATA; 2103 2047 else 2104 2048 return CURSEG_HOT_NODE; 2105 2049 } 2106 2050 2107 - static int __get_segment_type_4(struct page *page, enum page_type p_type) 2051 + static int __get_segment_type_4(struct f2fs_io_info *fio) 2108 2052 { 2109 - if (p_type == DATA) { 2110 - struct inode *inode = page->mapping->host; 2053 + if (fio->type == DATA) { 2054 + struct inode *inode = fio->page->mapping->host; 2111 2055 2112 2056 if (S_ISDIR(inode->i_mode)) 2113 2057 return CURSEG_HOT_DATA; 2114 2058 else 2115 2059 return CURSEG_COLD_DATA; 2116 2060 } else { 2117 - if (IS_DNODE(page) && is_cold_node(page)) 2061 + if (IS_DNODE(fio->page) && is_cold_node(fio->page)) 2118 2062 return CURSEG_WARM_NODE; 2119 2063 else 2120 2064 return CURSEG_COLD_NODE; 2121 2065 } 2122 2066 } 2123 2067 2124 - static int __get_segment_type_6(struct page *page, enum page_type p_type) 2068 + static int __get_segment_type_6(struct f2fs_io_info *fio) 2125 2069 { 2126 - if (p_type == DATA) { 2127 - struct inode *inode = page->mapping->host; 2070 + if (fio->type == DATA) { 2071 + struct inode *inode = fio->page->mapping->host; 2128 2072 2129 - if (is_cold_data(page) || file_is_cold(inode)) 2073 + if (is_cold_data(fio->page) || file_is_cold(inode)) 2130 2074 return CURSEG_COLD_DATA; 2131 2075 if (is_inode_flag_set(inode, FI_HOT_DATA)) 2132 2076 return CURSEG_HOT_DATA; 2133 2077 return CURSEG_WARM_DATA; 2134 2078 } else { 2135 - if (IS_DNODE(page)) 2136 - return is_cold_node(page) ? CURSEG_WARM_NODE : 2079 + if (IS_DNODE(fio->page)) 2080 + return is_cold_node(fio->page) ? CURSEG_WARM_NODE : 2137 2081 CURSEG_HOT_NODE; 2138 2082 return CURSEG_COLD_NODE; 2139 2083 } 2140 2084 } 2141 2085 2142 - static int __get_segment_type(struct page *page, enum page_type p_type) 2086 + static int __get_segment_type(struct f2fs_io_info *fio) 2143 2087 { 2144 - switch (F2FS_P_SB(page)->active_logs) { 2088 + int type = 0; 2089 + 2090 + switch (fio->sbi->active_logs) { 2145 2091 case 2: 2146 - return __get_segment_type_2(page, p_type); 2092 + type = __get_segment_type_2(fio); 2093 + break; 2147 2094 case 4: 2148 - return __get_segment_type_4(page, p_type); 2095 + type = __get_segment_type_4(fio); 2096 + break; 2097 + case 6: 2098 + type = __get_segment_type_6(fio); 2099 + break; 2100 + default: 2101 + f2fs_bug_on(fio->sbi, true); 2149 2102 } 2150 - /* NR_CURSEG_TYPE(6) logs by default */ 2151 - f2fs_bug_on(F2FS_P_SB(page), 2152 - F2FS_P_SB(page)->active_logs != NR_CURSEG_TYPE); 2153 - return __get_segment_type_6(page, p_type); 2103 + 2104 + if (IS_HOT(type)) 2105 + fio->temp = HOT; 2106 + else if (IS_WARM(type)) 2107 + fio->temp = WARM; 2108 + else 2109 + fio->temp = COLD; 2110 + return type; 2154 2111 } 2155 2112 2156 2113 void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2157 2114 block_t old_blkaddr, block_t *new_blkaddr, 2158 - struct f2fs_summary *sum, int type) 2115 + struct f2fs_summary *sum, int type, 2116 + struct f2fs_io_info *fio, bool add_list) 2159 2117 { 2160 2118 struct sit_info *sit_i = SIT_I(sbi); 2161 2119 struct curseg_info *curseg = CURSEG_I(sbi, type); ··· 2205 2135 if (page && IS_NODESEG(type)) 2206 2136 fill_node_footer_blkaddr(page, NEXT_FREE_BLKADDR(sbi, curseg)); 2207 2137 2138 + if (add_list) { 2139 + struct f2fs_bio_info *io; 2140 + 2141 + INIT_LIST_HEAD(&fio->list); 2142 + fio->in_list = true; 2143 + io = sbi->write_io[fio->type] + fio->temp; 2144 + spin_lock(&io->io_lock); 2145 + list_add_tail(&fio->list, &io->io_list); 2146 + spin_unlock(&io->io_lock); 2147 + } 2148 + 2208 2149 mutex_unlock(&curseg->curseg_mutex); 2209 2150 } 2210 2151 2211 2152 static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio) 2212 2153 { 2213 - int type = __get_segment_type(fio->page, fio->type); 2154 + int type = __get_segment_type(fio); 2214 2155 int err; 2215 2156 2216 - if (fio->type == NODE || fio->type == DATA) 2217 - mutex_lock(&fio->sbi->wio_mutex[fio->type]); 2218 2157 reallocate: 2219 2158 allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr, 2220 - &fio->new_blkaddr, sum, type); 2159 + &fio->new_blkaddr, sum, type, fio, true); 2221 2160 2222 2161 /* writeout dirty page into bdev */ 2223 - err = f2fs_submit_page_mbio(fio); 2162 + err = f2fs_submit_page_write(fio); 2224 2163 if (err == -EAGAIN) { 2225 2164 fio->old_blkaddr = fio->new_blkaddr; 2226 2165 goto reallocate; 2227 2166 } 2228 - 2229 - if (fio->type == NODE || fio->type == DATA) 2230 - mutex_unlock(&fio->sbi->wio_mutex[fio->type]); 2231 2167 } 2232 2168 2233 2169 void write_meta_page(struct f2fs_sb_info *sbi, struct page *page) ··· 2247 2171 .new_blkaddr = page->index, 2248 2172 .page = page, 2249 2173 .encrypted_page = NULL, 2174 + .in_list = false, 2250 2175 }; 2251 2176 2252 2177 if (unlikely(page->index >= MAIN_BLKADDR(sbi))) 2253 2178 fio.op_flags &= ~REQ_META; 2254 2179 2255 2180 set_page_writeback(page); 2256 - f2fs_submit_page_mbio(&fio); 2181 + f2fs_submit_page_write(&fio); 2257 2182 } 2258 2183 2259 2184 void write_node_page(unsigned int nid, struct f2fs_io_info *fio) ··· 2373 2296 if (PageWriteback(page)) { 2374 2297 struct f2fs_sb_info *sbi = F2FS_P_SB(page); 2375 2298 2376 - f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 2377 - 0, page->index, type, WRITE); 2299 + f2fs_submit_merged_write_cond(sbi, page->mapping->host, 2300 + 0, page->index, type); 2378 2301 if (ordered) 2379 2302 wait_on_page_writeback(page); 2380 2303 else ··· 2532 2455 2533 2456 static int restore_curseg_summaries(struct f2fs_sb_info *sbi) 2534 2457 { 2458 + struct f2fs_journal *sit_j = CURSEG_I(sbi, CURSEG_COLD_DATA)->journal; 2459 + struct f2fs_journal *nat_j = CURSEG_I(sbi, CURSEG_HOT_DATA)->journal; 2535 2460 int type = CURSEG_HOT_DATA; 2536 2461 int err; 2537 2462 ··· 2559 2480 if (err) 2560 2481 return err; 2561 2482 } 2483 + 2484 + /* sanity check for summary blocks */ 2485 + if (nats_in_cursum(nat_j) > NAT_JOURNAL_ENTRIES || 2486 + sits_in_cursum(sit_j) > SIT_JOURNAL_ENTRIES) 2487 + return -EINVAL; 2562 2488 2563 2489 return 0; 2564 2490 } ··· 3287 3203 3288 3204 INIT_LIST_HEAD(&sm_info->sit_entry_set); 3289 3205 3290 - if (test_opt(sbi, FLUSH_MERGE) && !f2fs_readonly(sbi->sb)) { 3206 + if (!f2fs_readonly(sbi->sb)) { 3291 3207 err = create_flush_cmd_control(sbi); 3292 3208 if (err) 3293 3209 return err;
+4
fs/f2fs/segment.h
··· 27 27 #define IS_DATASEG(t) ((t) <= CURSEG_COLD_DATA) 28 28 #define IS_NODESEG(t) ((t) >= CURSEG_HOT_NODE) 29 29 30 + #define IS_HOT(t) ((t) == CURSEG_HOT_NODE || (t) == CURSEG_HOT_DATA) 31 + #define IS_WARM(t) ((t) == CURSEG_WARM_NODE || (t) == CURSEG_WARM_DATA) 32 + #define IS_COLD(t) ((t) == CURSEG_COLD_NODE || (t) == CURSEG_COLD_DATA) 33 + 30 34 #define IS_CURSEG(sbi, seg) \ 31 35 (((seg) == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \ 32 36 ((seg) == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \
+364 -341
fs/f2fs/super.c
··· 22 22 #include <linux/random.h> 23 23 #include <linux/exportfs.h> 24 24 #include <linux/blkdev.h> 25 + #include <linux/quotaops.h> 25 26 #include <linux/f2fs_fs.h> 26 27 #include <linux/sysfs.h> 27 28 ··· 36 35 #define CREATE_TRACE_POINTS 37 36 #include <trace/events/f2fs.h> 38 37 39 - static struct proc_dir_entry *f2fs_proc_root; 40 38 static struct kmem_cache *f2fs_inode_cachep; 41 - static struct kset *f2fs_kset; 42 39 43 40 #ifdef CONFIG_F2FS_FAULT_INJECTION 44 41 ··· 107 108 Opt_fault_injection, 108 109 Opt_lazytime, 109 110 Opt_nolazytime, 111 + Opt_usrquota, 112 + Opt_grpquota, 110 113 Opt_err, 111 114 }; 112 115 ··· 144 143 {Opt_fault_injection, "fault_injection=%u"}, 145 144 {Opt_lazytime, "lazytime"}, 146 145 {Opt_nolazytime, "nolazytime"}, 146 + {Opt_usrquota, "usrquota"}, 147 + {Opt_grpquota, "grpquota"}, 147 148 {Opt_err, NULL}, 148 - }; 149 - 150 - /* Sysfs support for f2fs */ 151 - enum { 152 - GC_THREAD, /* struct f2fs_gc_thread */ 153 - SM_INFO, /* struct f2fs_sm_info */ 154 - DCC_INFO, /* struct discard_cmd_control */ 155 - NM_INFO, /* struct f2fs_nm_info */ 156 - F2FS_SBI, /* struct f2fs_sb_info */ 157 - #ifdef CONFIG_F2FS_FAULT_INJECTION 158 - FAULT_INFO_RATE, /* struct f2fs_fault_info */ 159 - FAULT_INFO_TYPE, /* struct f2fs_fault_info */ 160 - #endif 161 - }; 162 - 163 - struct f2fs_attr { 164 - struct attribute attr; 165 - ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *); 166 - ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *, 167 - const char *, size_t); 168 - int struct_type; 169 - int offset; 170 - }; 171 - 172 - static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) 173 - { 174 - if (struct_type == GC_THREAD) 175 - return (unsigned char *)sbi->gc_thread; 176 - else if (struct_type == SM_INFO) 177 - return (unsigned char *)SM_I(sbi); 178 - else if (struct_type == DCC_INFO) 179 - return (unsigned char *)SM_I(sbi)->dcc_info; 180 - else if (struct_type == NM_INFO) 181 - return (unsigned char *)NM_I(sbi); 182 - else if (struct_type == F2FS_SBI) 183 - return (unsigned char *)sbi; 184 - #ifdef CONFIG_F2FS_FAULT_INJECTION 185 - else if (struct_type == FAULT_INFO_RATE || 186 - struct_type == FAULT_INFO_TYPE) 187 - return (unsigned char *)&sbi->fault_info; 188 - #endif 189 - return NULL; 190 - } 191 - 192 - static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, 193 - struct f2fs_sb_info *sbi, char *buf) 194 - { 195 - struct super_block *sb = sbi->sb; 196 - 197 - if (!sb->s_bdev->bd_part) 198 - return snprintf(buf, PAGE_SIZE, "0\n"); 199 - 200 - return snprintf(buf, PAGE_SIZE, "%llu\n", 201 - (unsigned long long)(sbi->kbytes_written + 202 - BD_PART_WRITTEN(sbi))); 203 - } 204 - 205 - static ssize_t f2fs_sbi_show(struct f2fs_attr *a, 206 - struct f2fs_sb_info *sbi, char *buf) 207 - { 208 - unsigned char *ptr = NULL; 209 - unsigned int *ui; 210 - 211 - ptr = __struct_ptr(sbi, a->struct_type); 212 - if (!ptr) 213 - return -EINVAL; 214 - 215 - ui = (unsigned int *)(ptr + a->offset); 216 - 217 - return snprintf(buf, PAGE_SIZE, "%u\n", *ui); 218 - } 219 - 220 - static ssize_t f2fs_sbi_store(struct f2fs_attr *a, 221 - struct f2fs_sb_info *sbi, 222 - const char *buf, size_t count) 223 - { 224 - unsigned char *ptr; 225 - unsigned long t; 226 - unsigned int *ui; 227 - ssize_t ret; 228 - 229 - ptr = __struct_ptr(sbi, a->struct_type); 230 - if (!ptr) 231 - return -EINVAL; 232 - 233 - ui = (unsigned int *)(ptr + a->offset); 234 - 235 - ret = kstrtoul(skip_spaces(buf), 0, &t); 236 - if (ret < 0) 237 - return ret; 238 - #ifdef CONFIG_F2FS_FAULT_INJECTION 239 - if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX)) 240 - return -EINVAL; 241 - #endif 242 - *ui = t; 243 - return count; 244 - } 245 - 246 - static ssize_t f2fs_attr_show(struct kobject *kobj, 247 - struct attribute *attr, char *buf) 248 - { 249 - struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 250 - s_kobj); 251 - struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 252 - 253 - return a->show ? a->show(a, sbi, buf) : 0; 254 - } 255 - 256 - static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr, 257 - const char *buf, size_t len) 258 - { 259 - struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 260 - s_kobj); 261 - struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 262 - 263 - return a->store ? a->store(a, sbi, buf, len) : 0; 264 - } 265 - 266 - static void f2fs_sb_release(struct kobject *kobj) 267 - { 268 - struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 269 - s_kobj); 270 - complete(&sbi->s_kobj_unregister); 271 - } 272 - 273 - #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \ 274 - static struct f2fs_attr f2fs_attr_##_name = { \ 275 - .attr = {.name = __stringify(_name), .mode = _mode }, \ 276 - .show = _show, \ 277 - .store = _store, \ 278 - .struct_type = _struct_type, \ 279 - .offset = _offset \ 280 - } 281 - 282 - #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \ 283 - F2FS_ATTR_OFFSET(struct_type, name, 0644, \ 284 - f2fs_sbi_show, f2fs_sbi_store, \ 285 - offsetof(struct struct_name, elname)) 286 - 287 - #define F2FS_GENERAL_RO_ATTR(name) \ 288 - static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) 289 - 290 - F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); 291 - F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); 292 - F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); 293 - F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle); 294 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); 295 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards); 296 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections); 297 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); 298 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); 299 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks); 300 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks); 301 - F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh); 302 - F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages); 303 - F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio); 304 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); 305 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); 306 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); 307 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); 308 - #ifdef CONFIG_F2FS_FAULT_INJECTION 309 - F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); 310 - F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); 311 - #endif 312 - F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); 313 - 314 - #define ATTR_LIST(name) (&f2fs_attr_##name.attr) 315 - static struct attribute *f2fs_attrs[] = { 316 - ATTR_LIST(gc_min_sleep_time), 317 - ATTR_LIST(gc_max_sleep_time), 318 - ATTR_LIST(gc_no_gc_sleep_time), 319 - ATTR_LIST(gc_idle), 320 - ATTR_LIST(reclaim_segments), 321 - ATTR_LIST(max_small_discards), 322 - ATTR_LIST(batched_trim_sections), 323 - ATTR_LIST(ipu_policy), 324 - ATTR_LIST(min_ipu_util), 325 - ATTR_LIST(min_fsync_blocks), 326 - ATTR_LIST(min_hot_blocks), 327 - ATTR_LIST(max_victim_search), 328 - ATTR_LIST(dir_level), 329 - ATTR_LIST(ram_thresh), 330 - ATTR_LIST(ra_nid_pages), 331 - ATTR_LIST(dirty_nats_ratio), 332 - ATTR_LIST(cp_interval), 333 - ATTR_LIST(idle_interval), 334 - #ifdef CONFIG_F2FS_FAULT_INJECTION 335 - ATTR_LIST(inject_rate), 336 - ATTR_LIST(inject_type), 337 - #endif 338 - ATTR_LIST(lifetime_write_kbytes), 339 - NULL, 340 - }; 341 - 342 - static const struct sysfs_ops f2fs_attr_ops = { 343 - .show = f2fs_attr_show, 344 - .store = f2fs_attr_store, 345 - }; 346 - 347 - static struct kobj_type f2fs_ktype = { 348 - .default_attrs = f2fs_attrs, 349 - .sysfs_ops = &f2fs_attr_ops, 350 - .release = f2fs_sb_release, 351 149 }; 352 150 353 151 void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...) ··· 385 585 case Opt_nolazytime: 386 586 sb->s_flags &= ~MS_LAZYTIME; 387 587 break; 588 + #ifdef CONFIG_QUOTA 589 + case Opt_usrquota: 590 + set_opt(sbi, USRQUOTA); 591 + break; 592 + case Opt_grpquota: 593 + set_opt(sbi, GRPQUOTA); 594 + break; 595 + #else 596 + case Opt_usrquota: 597 + case Opt_grpquota: 598 + f2fs_msg(sb, KERN_INFO, 599 + "quota operations not supported"); 600 + break; 601 + #endif 388 602 default: 389 603 f2fs_msg(sb, KERN_ERR, 390 604 "Unrecognized mount option \"%s\" or missing value", ··· 438 624 mutex_init(&fi->inmem_lock); 439 625 init_rwsem(&fi->dio_rwsem[READ]); 440 626 init_rwsem(&fi->dio_rwsem[WRITE]); 627 + init_rwsem(&fi->i_mmap_sem); 441 628 629 + #ifdef CONFIG_QUOTA 630 + memset(&fi->i_dquot, 0, sizeof(fi->i_dquot)); 631 + fi->i_reserved_quota = 0; 632 + #endif 442 633 /* Will be used by directory only */ 443 634 fi->i_dir_level = F2FS_SB(sb)->dir_level; 444 635 return &fi->vfs_inode; ··· 584 765 kfree(sbi->devs); 585 766 } 586 767 768 + static void f2fs_quota_off_umount(struct super_block *sb); 587 769 static void f2fs_put_super(struct super_block *sb) 588 770 { 589 771 struct f2fs_sb_info *sbi = F2FS_SB(sb); 772 + int i; 590 773 591 - if (sbi->s_proc) { 592 - remove_proc_entry("segment_info", sbi->s_proc); 593 - remove_proc_entry("segment_bits", sbi->s_proc); 594 - remove_proc_entry(sb->s_id, f2fs_proc_root); 595 - } 596 - kobject_del(&sbi->s_kobj); 597 - 598 - stop_gc_thread(sbi); 774 + f2fs_quota_off_umount(sb); 599 775 600 776 /* prevent remaining shrinker jobs */ 601 777 mutex_lock(&sbi->umount_mutex); ··· 611 797 /* be sure to wait for any on-going discard commands */ 612 798 f2fs_wait_discard_bios(sbi); 613 799 614 - if (!sbi->discard_blks) { 800 + if (f2fs_discard_en(sbi) && !sbi->discard_blks) { 615 801 struct cp_control cpc = { 616 802 .reason = CP_UMOUNT | CP_TRIMMED, 617 803 }; ··· 631 817 mutex_unlock(&sbi->umount_mutex); 632 818 633 819 /* our cp_error case, we can wait for any writeback page */ 634 - f2fs_flush_merged_bios(sbi); 820 + f2fs_flush_merged_writes(sbi); 635 821 636 822 iput(sbi->node_inode); 637 823 iput(sbi->meta_inode); ··· 641 827 destroy_segment_manager(sbi); 642 828 643 829 kfree(sbi->ckpt); 644 - kobject_put(&sbi->s_kobj); 645 - wait_for_completion(&sbi->s_kobj_unregister); 830 + 831 + f2fs_exit_sysfs(sbi); 646 832 647 833 sb->s_fs_info = NULL; 648 834 if (sbi->s_chksum_driver) ··· 652 838 destroy_device_list(sbi); 653 839 mempool_destroy(sbi->write_io_dummy); 654 840 destroy_percpu_info(sbi); 841 + for (i = 0; i < NR_PAGE_TYPE; i++) 842 + kfree(sbi->write_io[i]); 655 843 kfree(sbi); 656 844 } 657 845 ··· 704 888 struct f2fs_sb_info *sbi = F2FS_SB(sb); 705 889 u64 id = huge_encode_dev(sb->s_bdev->bd_dev); 706 890 block_t total_count, user_block_count, start_count, ovp_count; 891 + u64 avail_node_count; 707 892 708 893 total_count = le64_to_cpu(sbi->raw_super->block_count); 709 894 user_block_count = sbi->user_block_count; ··· 715 898 716 899 buf->f_blocks = total_count - start_count; 717 900 buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count; 718 - buf->f_bavail = user_block_count - valid_user_blocks(sbi); 901 + buf->f_bavail = user_block_count - valid_user_blocks(sbi) - 902 + sbi->reserved_blocks; 719 903 720 - buf->f_files = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; 721 - buf->f_ffree = min(buf->f_files - valid_node_count(sbi), 722 - buf->f_bavail); 904 + avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; 905 + 906 + if (avail_node_count > user_block_count) { 907 + buf->f_files = user_block_count; 908 + buf->f_ffree = buf->f_bavail; 909 + } else { 910 + buf->f_files = avail_node_count; 911 + buf->f_ffree = min(avail_node_count - valid_node_count(sbi), 912 + buf->f_bavail); 913 + } 723 914 724 915 buf->f_namelen = F2FS_NAME_LEN; 725 916 buf->f_fsid.val[0] = (u32)id; ··· 805 980 seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi)); 806 981 #ifdef CONFIG_F2FS_FAULT_INJECTION 807 982 if (test_opt(sbi, FAULT_INJECTION)) 808 - seq_puts(seq, ",fault_injection"); 983 + seq_printf(seq, ",fault_injection=%u", 984 + sbi->fault_info.inject_rate); 985 + #endif 986 + #ifdef CONFIG_QUOTA 987 + if (test_opt(sbi, USRQUOTA)) 988 + seq_puts(seq, ",usrquota"); 989 + if (test_opt(sbi, GRPQUOTA)) 990 + seq_puts(seq, ",grpquota"); 809 991 #endif 810 992 811 993 return 0; 812 994 } 813 - 814 - static int segment_info_seq_show(struct seq_file *seq, void *offset) 815 - { 816 - struct super_block *sb = seq->private; 817 - struct f2fs_sb_info *sbi = F2FS_SB(sb); 818 - unsigned int total_segs = 819 - le32_to_cpu(sbi->raw_super->segment_count_main); 820 - int i; 821 - 822 - seq_puts(seq, "format: segment_type|valid_blocks\n" 823 - "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); 824 - 825 - for (i = 0; i < total_segs; i++) { 826 - struct seg_entry *se = get_seg_entry(sbi, i); 827 - 828 - if ((i % 10) == 0) 829 - seq_printf(seq, "%-10d", i); 830 - seq_printf(seq, "%d|%-3u", se->type, 831 - get_valid_blocks(sbi, i, false)); 832 - if ((i % 10) == 9 || i == (total_segs - 1)) 833 - seq_putc(seq, '\n'); 834 - else 835 - seq_putc(seq, ' '); 836 - } 837 - 838 - return 0; 839 - } 840 - 841 - static int segment_bits_seq_show(struct seq_file *seq, void *offset) 842 - { 843 - struct super_block *sb = seq->private; 844 - struct f2fs_sb_info *sbi = F2FS_SB(sb); 845 - unsigned int total_segs = 846 - le32_to_cpu(sbi->raw_super->segment_count_main); 847 - int i, j; 848 - 849 - seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n" 850 - "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); 851 - 852 - for (i = 0; i < total_segs; i++) { 853 - struct seg_entry *se = get_seg_entry(sbi, i); 854 - 855 - seq_printf(seq, "%-10d", i); 856 - seq_printf(seq, "%d|%-3u|", se->type, 857 - get_valid_blocks(sbi, i, false)); 858 - for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++) 859 - seq_printf(seq, " %.2x", se->cur_valid_map[j]); 860 - seq_putc(seq, '\n'); 861 - } 862 - return 0; 863 - } 864 - 865 - #define F2FS_PROC_FILE_DEF(_name) \ 866 - static int _name##_open_fs(struct inode *inode, struct file *file) \ 867 - { \ 868 - return single_open(file, _name##_seq_show, PDE_DATA(inode)); \ 869 - } \ 870 - \ 871 - static const struct file_operations f2fs_seq_##_name##_fops = { \ 872 - .open = _name##_open_fs, \ 873 - .read = seq_read, \ 874 - .llseek = seq_lseek, \ 875 - .release = single_release, \ 876 - }; 877 - 878 - F2FS_PROC_FILE_DEF(segment_info); 879 - F2FS_PROC_FILE_DEF(segment_bits); 880 995 881 996 static void default_options(struct f2fs_sb_info *sbi) 882 997 { ··· 854 1089 { 855 1090 struct f2fs_sb_info *sbi = F2FS_SB(sb); 856 1091 struct f2fs_mount_info org_mount_opt; 1092 + unsigned long old_sb_flags; 857 1093 int err, active_logs; 858 1094 bool need_restart_gc = false; 859 1095 bool need_stop_gc = false; ··· 868 1102 * need to restore them. 869 1103 */ 870 1104 org_mount_opt = sbi->mount_opt; 1105 + old_sb_flags = sb->s_flags; 871 1106 active_logs = sbi->active_logs; 872 1107 873 1108 /* recover superblocks we couldn't write due to previous RO mount */ ··· 880 1113 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); 881 1114 } 882 1115 883 - sbi->mount_opt.opt = 0; 884 1116 default_options(sbi); 885 1117 886 1118 /* parse mount options */ ··· 893 1127 */ 894 1128 if (f2fs_readonly(sb) && (*flags & MS_RDONLY)) 895 1129 goto skip; 1130 + 1131 + if (!f2fs_readonly(sb) && (*flags & MS_RDONLY)) { 1132 + err = dquot_suspend(sb, -1); 1133 + if (err < 0) 1134 + goto restore_opts; 1135 + } else { 1136 + /* dquot_resume needs RW */ 1137 + sb->s_flags &= ~MS_RDONLY; 1138 + dquot_resume(sb, -1); 1139 + } 896 1140 897 1141 /* disallow enable/disable extent_cache dynamically */ 898 1142 if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) { ··· 968 1192 restore_opts: 969 1193 sbi->mount_opt = org_mount_opt; 970 1194 sbi->active_logs = active_logs; 1195 + sb->s_flags = old_sb_flags; 971 1196 #ifdef CONFIG_F2FS_FAULT_INJECTION 972 1197 sbi->fault_info = ffi; 973 1198 #endif 974 1199 return err; 975 1200 } 1201 + 1202 + #ifdef CONFIG_QUOTA 1203 + /* Read data from quotafile */ 1204 + static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data, 1205 + size_t len, loff_t off) 1206 + { 1207 + struct inode *inode = sb_dqopt(sb)->files[type]; 1208 + struct address_space *mapping = inode->i_mapping; 1209 + block_t blkidx = F2FS_BYTES_TO_BLK(off); 1210 + int offset = off & (sb->s_blocksize - 1); 1211 + int tocopy; 1212 + size_t toread; 1213 + loff_t i_size = i_size_read(inode); 1214 + struct page *page; 1215 + char *kaddr; 1216 + 1217 + if (off > i_size) 1218 + return 0; 1219 + 1220 + if (off + len > i_size) 1221 + len = i_size - off; 1222 + toread = len; 1223 + while (toread > 0) { 1224 + tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread); 1225 + repeat: 1226 + page = read_mapping_page(mapping, blkidx, NULL); 1227 + if (IS_ERR(page)) 1228 + return PTR_ERR(page); 1229 + 1230 + lock_page(page); 1231 + 1232 + if (unlikely(page->mapping != mapping)) { 1233 + f2fs_put_page(page, 1); 1234 + goto repeat; 1235 + } 1236 + if (unlikely(!PageUptodate(page))) { 1237 + f2fs_put_page(page, 1); 1238 + return -EIO; 1239 + } 1240 + 1241 + kaddr = kmap_atomic(page); 1242 + memcpy(data, kaddr + offset, tocopy); 1243 + kunmap_atomic(kaddr); 1244 + f2fs_put_page(page, 1); 1245 + 1246 + offset = 0; 1247 + toread -= tocopy; 1248 + data += tocopy; 1249 + blkidx++; 1250 + } 1251 + return len; 1252 + } 1253 + 1254 + /* Write to quotafile */ 1255 + static ssize_t f2fs_quota_write(struct super_block *sb, int type, 1256 + const char *data, size_t len, loff_t off) 1257 + { 1258 + struct inode *inode = sb_dqopt(sb)->files[type]; 1259 + struct address_space *mapping = inode->i_mapping; 1260 + const struct address_space_operations *a_ops = mapping->a_ops; 1261 + int offset = off & (sb->s_blocksize - 1); 1262 + size_t towrite = len; 1263 + struct page *page; 1264 + char *kaddr; 1265 + int err = 0; 1266 + int tocopy; 1267 + 1268 + while (towrite > 0) { 1269 + tocopy = min_t(unsigned long, sb->s_blocksize - offset, 1270 + towrite); 1271 + 1272 + err = a_ops->write_begin(NULL, mapping, off, tocopy, 0, 1273 + &page, NULL); 1274 + if (unlikely(err)) 1275 + break; 1276 + 1277 + kaddr = kmap_atomic(page); 1278 + memcpy(kaddr + offset, data, tocopy); 1279 + kunmap_atomic(kaddr); 1280 + flush_dcache_page(page); 1281 + 1282 + a_ops->write_end(NULL, mapping, off, tocopy, tocopy, 1283 + page, NULL); 1284 + offset = 0; 1285 + towrite -= tocopy; 1286 + off += tocopy; 1287 + data += tocopy; 1288 + cond_resched(); 1289 + } 1290 + 1291 + if (len == towrite) 1292 + return err; 1293 + inode->i_version++; 1294 + inode->i_mtime = inode->i_ctime = current_time(inode); 1295 + f2fs_mark_inode_dirty_sync(inode, false); 1296 + return len - towrite; 1297 + } 1298 + 1299 + static struct dquot **f2fs_get_dquots(struct inode *inode) 1300 + { 1301 + return F2FS_I(inode)->i_dquot; 1302 + } 1303 + 1304 + static qsize_t *f2fs_get_reserved_space(struct inode *inode) 1305 + { 1306 + return &F2FS_I(inode)->i_reserved_quota; 1307 + } 1308 + 1309 + static int f2fs_quota_sync(struct super_block *sb, int type) 1310 + { 1311 + struct quota_info *dqopt = sb_dqopt(sb); 1312 + int cnt; 1313 + int ret; 1314 + 1315 + ret = dquot_writeback_dquots(sb, type); 1316 + if (ret) 1317 + return ret; 1318 + 1319 + /* 1320 + * Now when everything is written we can discard the pagecache so 1321 + * that userspace sees the changes. 1322 + */ 1323 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1324 + if (type != -1 && cnt != type) 1325 + continue; 1326 + if (!sb_has_quota_active(sb, cnt)) 1327 + continue; 1328 + 1329 + ret = filemap_write_and_wait(dqopt->files[cnt]->i_mapping); 1330 + if (ret) 1331 + return ret; 1332 + 1333 + inode_lock(dqopt->files[cnt]); 1334 + truncate_inode_pages(&dqopt->files[cnt]->i_data, 0); 1335 + inode_unlock(dqopt->files[cnt]); 1336 + } 1337 + return 0; 1338 + } 1339 + 1340 + static int f2fs_quota_on(struct super_block *sb, int type, int format_id, 1341 + const struct path *path) 1342 + { 1343 + struct inode *inode; 1344 + int err; 1345 + 1346 + err = f2fs_quota_sync(sb, -1); 1347 + if (err) 1348 + return err; 1349 + 1350 + err = dquot_quota_on(sb, type, format_id, path); 1351 + if (err) 1352 + return err; 1353 + 1354 + inode = d_inode(path->dentry); 1355 + 1356 + inode_lock(inode); 1357 + F2FS_I(inode)->i_flags |= FS_NOATIME_FL | FS_IMMUTABLE_FL; 1358 + inode_set_flags(inode, S_NOATIME | S_IMMUTABLE, 1359 + S_NOATIME | S_IMMUTABLE); 1360 + inode_unlock(inode); 1361 + f2fs_mark_inode_dirty_sync(inode, false); 1362 + 1363 + return 0; 1364 + } 1365 + 1366 + static int f2fs_quota_off(struct super_block *sb, int type) 1367 + { 1368 + struct inode *inode = sb_dqopt(sb)->files[type]; 1369 + int err; 1370 + 1371 + if (!inode || !igrab(inode)) 1372 + return dquot_quota_off(sb, type); 1373 + 1374 + f2fs_quota_sync(sb, -1); 1375 + 1376 + err = dquot_quota_off(sb, type); 1377 + if (err) 1378 + goto out_put; 1379 + 1380 + inode_lock(inode); 1381 + F2FS_I(inode)->i_flags &= ~(FS_NOATIME_FL | FS_IMMUTABLE_FL); 1382 + inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE); 1383 + inode_unlock(inode); 1384 + f2fs_mark_inode_dirty_sync(inode, false); 1385 + out_put: 1386 + iput(inode); 1387 + return err; 1388 + } 1389 + 1390 + static void f2fs_quota_off_umount(struct super_block *sb) 1391 + { 1392 + int type; 1393 + 1394 + for (type = 0; type < MAXQUOTAS; type++) 1395 + f2fs_quota_off(sb, type); 1396 + } 1397 + 1398 + static const struct dquot_operations f2fs_quota_operations = { 1399 + .get_reserved_space = f2fs_get_reserved_space, 1400 + .write_dquot = dquot_commit, 1401 + .acquire_dquot = dquot_acquire, 1402 + .release_dquot = dquot_release, 1403 + .mark_dirty = dquot_mark_dquot_dirty, 1404 + .write_info = dquot_commit_info, 1405 + .alloc_dquot = dquot_alloc, 1406 + .destroy_dquot = dquot_destroy, 1407 + .get_next_id = dquot_get_next_id, 1408 + }; 1409 + 1410 + static const struct quotactl_ops f2fs_quotactl_ops = { 1411 + .quota_on = f2fs_quota_on, 1412 + .quota_off = f2fs_quota_off, 1413 + .quota_sync = f2fs_quota_sync, 1414 + .get_state = dquot_get_state, 1415 + .set_info = dquot_set_dqinfo, 1416 + .get_dqblk = dquot_get_dqblk, 1417 + .set_dqblk = dquot_set_dqblk, 1418 + .get_nextdqblk = dquot_get_next_dqblk, 1419 + }; 1420 + #else 1421 + static inline void f2fs_quota_off_umount(struct super_block *sb) 1422 + { 1423 + } 1424 + #endif 976 1425 977 1426 static struct super_operations f2fs_sops = { 978 1427 .alloc_inode = f2fs_alloc_inode, ··· 1206 1205 .write_inode = f2fs_write_inode, 1207 1206 .dirty_inode = f2fs_dirty_inode, 1208 1207 .show_options = f2fs_show_options, 1208 + #ifdef CONFIG_QUOTA 1209 + .quota_read = f2fs_quota_read, 1210 + .quota_write = f2fs_quota_write, 1211 + .get_dquots = f2fs_get_dquots, 1212 + #endif 1209 1213 .evict_inode = f2fs_evict_inode, 1210 1214 .put_super = f2fs_put_super, 1211 1215 .sync_fs = f2fs_sync_fs, ··· 1527 1521 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); 1528 1522 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1529 1523 unsigned int ovp_segments, reserved_segments; 1524 + unsigned int main_segs, blocks_per_seg; 1525 + int i; 1530 1526 1531 1527 total = le32_to_cpu(raw_super->segment_count); 1532 1528 fsmeta = le32_to_cpu(raw_super->segment_count_ckpt); ··· 1550 1542 return 1; 1551 1543 } 1552 1544 1545 + main_segs = le32_to_cpu(raw_super->segment_count_main); 1546 + blocks_per_seg = sbi->blocks_per_seg; 1547 + 1548 + for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { 1549 + if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs || 1550 + le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg) 1551 + return 1; 1552 + } 1553 + for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { 1554 + if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || 1555 + le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) 1556 + return 1; 1557 + } 1558 + 1553 1559 if (unlikely(f2fs_cp_error(sbi))) { 1554 1560 f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck"); 1555 1561 return 1; ··· 1574 1552 static void init_sb_info(struct f2fs_sb_info *sbi) 1575 1553 { 1576 1554 struct f2fs_super_block *raw_super = sbi->raw_super; 1577 - int i; 1555 + int i, j; 1578 1556 1579 1557 sbi->log_sectors_per_block = 1580 1558 le32_to_cpu(raw_super->log_sectors_per_block); ··· 1606 1584 1607 1585 INIT_LIST_HEAD(&sbi->s_list); 1608 1586 mutex_init(&sbi->umount_mutex); 1609 - mutex_init(&sbi->wio_mutex[NODE]); 1610 - mutex_init(&sbi->wio_mutex[DATA]); 1587 + for (i = 0; i < NR_PAGE_TYPE - 1; i++) 1588 + for (j = HOT; j < NR_TEMP_TYPE; j++) 1589 + mutex_init(&sbi->wio_mutex[i][j]); 1611 1590 spin_lock_init(&sbi->cp_lock); 1612 1591 } 1613 1592 ··· 1931 1908 if (f2fs_sb_mounted_blkzoned(sb)) { 1932 1909 f2fs_msg(sb, KERN_ERR, 1933 1910 "Zoned block device support is not enabled\n"); 1911 + err = -EOPNOTSUPP; 1934 1912 goto free_sb_buf; 1935 1913 } 1936 1914 #endif ··· 1952 1928 le32_to_cpu(raw_super->log_blocksize); 1953 1929 sb->s_max_links = F2FS_LINK_MAX; 1954 1930 get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 1931 + 1932 + #ifdef CONFIG_QUOTA 1933 + sb->dq_op = &f2fs_quota_operations; 1934 + sb->s_qcop = &f2fs_quotactl_ops; 1935 + sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP; 1936 + #endif 1955 1937 1956 1938 sb->s_op = &f2fs_sops; 1957 1939 sb->s_cop = &f2fs_cryptops; ··· 1980 1950 set_sbi_flag(sbi, SBI_POR_DOING); 1981 1951 spin_lock_init(&sbi->stat_lock); 1982 1952 1983 - init_rwsem(&sbi->read_io.io_rwsem); 1984 - sbi->read_io.sbi = sbi; 1985 - sbi->read_io.bio = NULL; 1986 1953 for (i = 0; i < NR_PAGE_TYPE; i++) { 1987 - init_rwsem(&sbi->write_io[i].io_rwsem); 1988 - sbi->write_io[i].sbi = sbi; 1989 - sbi->write_io[i].bio = NULL; 1954 + int n = (i == META) ? 1: NR_TEMP_TYPE; 1955 + int j; 1956 + 1957 + sbi->write_io[i] = kmalloc(n * sizeof(struct f2fs_bio_info), 1958 + GFP_KERNEL); 1959 + if (!sbi->write_io[i]) { 1960 + err = -ENOMEM; 1961 + goto free_options; 1962 + } 1963 + 1964 + for (j = HOT; j < n; j++) { 1965 + init_rwsem(&sbi->write_io[i][j].io_rwsem); 1966 + sbi->write_io[i][j].sbi = sbi; 1967 + sbi->write_io[i][j].bio = NULL; 1968 + spin_lock_init(&sbi->write_io[i][j].io_lock); 1969 + INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); 1970 + } 1990 1971 } 1991 1972 1992 1973 init_rwsem(&sbi->cp_rwsem); ··· 2011 1970 if (F2FS_IO_SIZE(sbi) > 1) { 2012 1971 sbi->write_io_dummy = 2013 1972 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); 2014 - if (!sbi->write_io_dummy) 1973 + if (!sbi->write_io_dummy) { 1974 + err = -ENOMEM; 2015 1975 goto free_options; 1976 + } 2016 1977 } 2017 1978 2018 1979 /* get an inode for meta space */ ··· 2046 2003 sbi->total_valid_block_count = 2047 2004 le64_to_cpu(sbi->ckpt->valid_block_count); 2048 2005 sbi->last_valid_block_count = sbi->total_valid_block_count; 2006 + sbi->reserved_blocks = 0; 2049 2007 2050 2008 for (i = 0; i < NR_INODE_TYPE; i++) { 2051 2009 INIT_LIST_HEAD(&sbi->inode_list[i]); ··· 2122 2078 goto free_root_inode; 2123 2079 } 2124 2080 2125 - if (f2fs_proc_root) 2126 - sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); 2127 - 2128 - if (sbi->s_proc) { 2129 - proc_create_data("segment_info", S_IRUGO, sbi->s_proc, 2130 - &f2fs_seq_segment_info_fops, sb); 2131 - proc_create_data("segment_bits", S_IRUGO, sbi->s_proc, 2132 - &f2fs_seq_segment_bits_fops, sb); 2133 - } 2134 - 2135 - sbi->s_kobj.kset = f2fs_kset; 2136 - init_completion(&sbi->s_kobj_unregister); 2137 - err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL, 2138 - "%s", sb->s_id); 2081 + err = f2fs_init_sysfs(sbi); 2139 2082 if (err) 2140 - goto free_proc; 2083 + goto free_root_inode; 2141 2084 2142 2085 /* recover fsynced data */ 2143 2086 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { ··· 2135 2104 if (bdev_read_only(sb->s_bdev) && 2136 2105 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { 2137 2106 err = -EROFS; 2138 - goto free_kobj; 2107 + goto free_sysfs; 2139 2108 } 2140 2109 2141 2110 if (need_fsck) ··· 2149 2118 need_fsck = true; 2150 2119 f2fs_msg(sb, KERN_ERR, 2151 2120 "Cannot recover all fsync data errno=%d", err); 2152 - goto free_kobj; 2121 + goto free_sysfs; 2153 2122 } 2154 2123 } else { 2155 2124 err = recover_fsync_data(sbi, true); ··· 2158 2127 err = -EINVAL; 2159 2128 f2fs_msg(sb, KERN_ERR, 2160 2129 "Need to recover fsync data"); 2161 - goto free_kobj; 2130 + goto free_sysfs; 2162 2131 } 2163 2132 } 2164 2133 skip_recovery: ··· 2173 2142 /* After POR, we can run background GC thread.*/ 2174 2143 err = start_gc_thread(sbi); 2175 2144 if (err) 2176 - goto free_kobj; 2145 + goto free_sysfs; 2177 2146 } 2178 2147 kfree(options); 2179 2148 ··· 2191 2160 f2fs_update_time(sbi, REQ_TIME); 2192 2161 return 0; 2193 2162 2194 - free_kobj: 2163 + free_sysfs: 2195 2164 f2fs_sync_inode_meta(sbi); 2196 - kobject_del(&sbi->s_kobj); 2197 - kobject_put(&sbi->s_kobj); 2198 - wait_for_completion(&sbi->s_kobj_unregister); 2199 - free_proc: 2200 - if (sbi->s_proc) { 2201 - remove_proc_entry("segment_info", sbi->s_proc); 2202 - remove_proc_entry("segment_bits", sbi->s_proc); 2203 - remove_proc_entry(sb->s_id, f2fs_proc_root); 2204 - } 2165 + f2fs_exit_sysfs(sbi); 2205 2166 free_root_inode: 2206 2167 dput(sb->s_root); 2207 2168 sb->s_root = NULL; ··· 2225 2202 free_io_dummy: 2226 2203 mempool_destroy(sbi->write_io_dummy); 2227 2204 free_options: 2205 + for (i = 0; i < NR_PAGE_TYPE; i++) 2206 + kfree(sbi->write_io[i]); 2228 2207 destroy_percpu_info(sbi); 2229 2208 kfree(options); 2230 2209 free_sb_buf: ··· 2253 2228 2254 2229 static void kill_f2fs_super(struct super_block *sb) 2255 2230 { 2256 - if (sb->s_root) 2231 + if (sb->s_root) { 2257 2232 set_sbi_flag(F2FS_SB(sb), SBI_IS_CLOSE); 2233 + stop_gc_thread(F2FS_SB(sb)); 2234 + stop_discard_thread(F2FS_SB(sb)); 2235 + } 2258 2236 kill_block_super(sb); 2259 2237 } 2260 2238 ··· 2311 2283 err = create_extent_cache(); 2312 2284 if (err) 2313 2285 goto free_checkpoint_caches; 2314 - f2fs_kset = kset_create_and_add("f2fs", NULL, fs_kobj); 2315 - if (!f2fs_kset) { 2316 - err = -ENOMEM; 2286 + err = f2fs_register_sysfs(); 2287 + if (err) 2317 2288 goto free_extent_cache; 2318 - } 2319 2289 err = register_shrinker(&f2fs_shrinker_info); 2320 2290 if (err) 2321 - goto free_kset; 2322 - 2291 + goto free_sysfs; 2323 2292 err = register_filesystem(&f2fs_fs_type); 2324 2293 if (err) 2325 2294 goto free_shrinker; 2326 2295 err = f2fs_create_root_stats(); 2327 2296 if (err) 2328 2297 goto free_filesystem; 2329 - f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); 2330 2298 return 0; 2331 2299 2332 2300 free_filesystem: 2333 2301 unregister_filesystem(&f2fs_fs_type); 2334 2302 free_shrinker: 2335 2303 unregister_shrinker(&f2fs_shrinker_info); 2336 - free_kset: 2337 - kset_unregister(f2fs_kset); 2304 + free_sysfs: 2305 + f2fs_unregister_sysfs(); 2338 2306 free_extent_cache: 2339 2307 destroy_extent_cache(); 2340 2308 free_checkpoint_caches: ··· 2347 2323 2348 2324 static void __exit exit_f2fs_fs(void) 2349 2325 { 2350 - remove_proc_entry("fs/f2fs", NULL); 2351 2326 f2fs_destroy_root_stats(); 2352 2327 unregister_filesystem(&f2fs_fs_type); 2353 2328 unregister_shrinker(&f2fs_shrinker_info); 2354 - kset_unregister(f2fs_kset); 2329 + f2fs_unregister_sysfs(); 2355 2330 destroy_extent_cache(); 2356 2331 destroy_checkpoint_caches(); 2357 2332 destroy_segment_manager_caches();
+364
fs/f2fs/sysfs.c
··· 1 + /* 2 + * f2fs sysfs interface 3 + * 4 + * Copyright (c) 2012 Samsung Electronics Co., Ltd. 5 + * http://www.samsung.com/ 6 + * Copyright (c) 2017 Chao Yu <chao@kernel.org> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + */ 12 + #include <linux/proc_fs.h> 13 + #include <linux/f2fs_fs.h> 14 + 15 + #include "f2fs.h" 16 + #include "segment.h" 17 + #include "gc.h" 18 + 19 + static struct proc_dir_entry *f2fs_proc_root; 20 + static struct kset *f2fs_kset; 21 + 22 + /* Sysfs support for f2fs */ 23 + enum { 24 + GC_THREAD, /* struct f2fs_gc_thread */ 25 + SM_INFO, /* struct f2fs_sm_info */ 26 + DCC_INFO, /* struct discard_cmd_control */ 27 + NM_INFO, /* struct f2fs_nm_info */ 28 + F2FS_SBI, /* struct f2fs_sb_info */ 29 + #ifdef CONFIG_F2FS_FAULT_INJECTION 30 + FAULT_INFO_RATE, /* struct f2fs_fault_info */ 31 + FAULT_INFO_TYPE, /* struct f2fs_fault_info */ 32 + #endif 33 + RESERVED_BLOCKS, 34 + }; 35 + 36 + struct f2fs_attr { 37 + struct attribute attr; 38 + ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *); 39 + ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *, 40 + const char *, size_t); 41 + int struct_type; 42 + int offset; 43 + }; 44 + 45 + static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) 46 + { 47 + if (struct_type == GC_THREAD) 48 + return (unsigned char *)sbi->gc_thread; 49 + else if (struct_type == SM_INFO) 50 + return (unsigned char *)SM_I(sbi); 51 + else if (struct_type == DCC_INFO) 52 + return (unsigned char *)SM_I(sbi)->dcc_info; 53 + else if (struct_type == NM_INFO) 54 + return (unsigned char *)NM_I(sbi); 55 + else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS) 56 + return (unsigned char *)sbi; 57 + #ifdef CONFIG_F2FS_FAULT_INJECTION 58 + else if (struct_type == FAULT_INFO_RATE || 59 + struct_type == FAULT_INFO_TYPE) 60 + return (unsigned char *)&sbi->fault_info; 61 + #endif 62 + return NULL; 63 + } 64 + 65 + static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, 66 + struct f2fs_sb_info *sbi, char *buf) 67 + { 68 + struct super_block *sb = sbi->sb; 69 + 70 + if (!sb->s_bdev->bd_part) 71 + return snprintf(buf, PAGE_SIZE, "0\n"); 72 + 73 + return snprintf(buf, PAGE_SIZE, "%llu\n", 74 + (unsigned long long)(sbi->kbytes_written + 75 + BD_PART_WRITTEN(sbi))); 76 + } 77 + 78 + static ssize_t f2fs_sbi_show(struct f2fs_attr *a, 79 + struct f2fs_sb_info *sbi, char *buf) 80 + { 81 + unsigned char *ptr = NULL; 82 + unsigned int *ui; 83 + 84 + ptr = __struct_ptr(sbi, a->struct_type); 85 + if (!ptr) 86 + return -EINVAL; 87 + 88 + ui = (unsigned int *)(ptr + a->offset); 89 + 90 + return snprintf(buf, PAGE_SIZE, "%u\n", *ui); 91 + } 92 + 93 + static ssize_t f2fs_sbi_store(struct f2fs_attr *a, 94 + struct f2fs_sb_info *sbi, 95 + const char *buf, size_t count) 96 + { 97 + unsigned char *ptr; 98 + unsigned long t; 99 + unsigned int *ui; 100 + ssize_t ret; 101 + 102 + ptr = __struct_ptr(sbi, a->struct_type); 103 + if (!ptr) 104 + return -EINVAL; 105 + 106 + ui = (unsigned int *)(ptr + a->offset); 107 + 108 + ret = kstrtoul(skip_spaces(buf), 0, &t); 109 + if (ret < 0) 110 + return ret; 111 + #ifdef CONFIG_F2FS_FAULT_INJECTION 112 + if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX)) 113 + return -EINVAL; 114 + #endif 115 + if (a->struct_type == RESERVED_BLOCKS) { 116 + spin_lock(&sbi->stat_lock); 117 + if ((unsigned long)sbi->total_valid_block_count + t > 118 + (unsigned long)sbi->user_block_count) { 119 + spin_unlock(&sbi->stat_lock); 120 + return -EINVAL; 121 + } 122 + *ui = t; 123 + spin_unlock(&sbi->stat_lock); 124 + return count; 125 + } 126 + *ui = t; 127 + return count; 128 + } 129 + 130 + static ssize_t f2fs_attr_show(struct kobject *kobj, 131 + struct attribute *attr, char *buf) 132 + { 133 + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 134 + s_kobj); 135 + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 136 + 137 + return a->show ? a->show(a, sbi, buf) : 0; 138 + } 139 + 140 + static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr, 141 + const char *buf, size_t len) 142 + { 143 + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 144 + s_kobj); 145 + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 146 + 147 + return a->store ? a->store(a, sbi, buf, len) : 0; 148 + } 149 + 150 + static void f2fs_sb_release(struct kobject *kobj) 151 + { 152 + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 153 + s_kobj); 154 + complete(&sbi->s_kobj_unregister); 155 + } 156 + 157 + #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \ 158 + static struct f2fs_attr f2fs_attr_##_name = { \ 159 + .attr = {.name = __stringify(_name), .mode = _mode }, \ 160 + .show = _show, \ 161 + .store = _store, \ 162 + .struct_type = _struct_type, \ 163 + .offset = _offset \ 164 + } 165 + 166 + #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \ 167 + F2FS_ATTR_OFFSET(struct_type, name, 0644, \ 168 + f2fs_sbi_show, f2fs_sbi_store, \ 169 + offsetof(struct struct_name, elname)) 170 + 171 + #define F2FS_GENERAL_RO_ATTR(name) \ 172 + static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) 173 + 174 + F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); 175 + F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); 176 + F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); 177 + F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle); 178 + F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); 179 + F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards); 180 + F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks); 181 + F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections); 182 + F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); 183 + F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); 184 + F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks); 185 + F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks); 186 + F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh); 187 + F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages); 188 + F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio); 189 + F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); 190 + F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); 191 + F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); 192 + F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); 193 + #ifdef CONFIG_F2FS_FAULT_INJECTION 194 + F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); 195 + F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); 196 + #endif 197 + F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); 198 + 199 + #define ATTR_LIST(name) (&f2fs_attr_##name.attr) 200 + static struct attribute *f2fs_attrs[] = { 201 + ATTR_LIST(gc_min_sleep_time), 202 + ATTR_LIST(gc_max_sleep_time), 203 + ATTR_LIST(gc_no_gc_sleep_time), 204 + ATTR_LIST(gc_idle), 205 + ATTR_LIST(reclaim_segments), 206 + ATTR_LIST(max_small_discards), 207 + ATTR_LIST(batched_trim_sections), 208 + ATTR_LIST(ipu_policy), 209 + ATTR_LIST(min_ipu_util), 210 + ATTR_LIST(min_fsync_blocks), 211 + ATTR_LIST(min_hot_blocks), 212 + ATTR_LIST(max_victim_search), 213 + ATTR_LIST(dir_level), 214 + ATTR_LIST(ram_thresh), 215 + ATTR_LIST(ra_nid_pages), 216 + ATTR_LIST(dirty_nats_ratio), 217 + ATTR_LIST(cp_interval), 218 + ATTR_LIST(idle_interval), 219 + #ifdef CONFIG_F2FS_FAULT_INJECTION 220 + ATTR_LIST(inject_rate), 221 + ATTR_LIST(inject_type), 222 + #endif 223 + ATTR_LIST(lifetime_write_kbytes), 224 + ATTR_LIST(reserved_blocks), 225 + NULL, 226 + }; 227 + 228 + static const struct sysfs_ops f2fs_attr_ops = { 229 + .show = f2fs_attr_show, 230 + .store = f2fs_attr_store, 231 + }; 232 + 233 + static struct kobj_type f2fs_ktype = { 234 + .default_attrs = f2fs_attrs, 235 + .sysfs_ops = &f2fs_attr_ops, 236 + .release = f2fs_sb_release, 237 + }; 238 + 239 + static int segment_info_seq_show(struct seq_file *seq, void *offset) 240 + { 241 + struct super_block *sb = seq->private; 242 + struct f2fs_sb_info *sbi = F2FS_SB(sb); 243 + unsigned int total_segs = 244 + le32_to_cpu(sbi->raw_super->segment_count_main); 245 + int i; 246 + 247 + seq_puts(seq, "format: segment_type|valid_blocks\n" 248 + "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); 249 + 250 + for (i = 0; i < total_segs; i++) { 251 + struct seg_entry *se = get_seg_entry(sbi, i); 252 + 253 + if ((i % 10) == 0) 254 + seq_printf(seq, "%-10d", i); 255 + seq_printf(seq, "%d|%-3u", se->type, 256 + get_valid_blocks(sbi, i, false)); 257 + if ((i % 10) == 9 || i == (total_segs - 1)) 258 + seq_putc(seq, '\n'); 259 + else 260 + seq_putc(seq, ' '); 261 + } 262 + 263 + return 0; 264 + } 265 + 266 + static int segment_bits_seq_show(struct seq_file *seq, void *offset) 267 + { 268 + struct super_block *sb = seq->private; 269 + struct f2fs_sb_info *sbi = F2FS_SB(sb); 270 + unsigned int total_segs = 271 + le32_to_cpu(sbi->raw_super->segment_count_main); 272 + int i, j; 273 + 274 + seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n" 275 + "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); 276 + 277 + for (i = 0; i < total_segs; i++) { 278 + struct seg_entry *se = get_seg_entry(sbi, i); 279 + 280 + seq_printf(seq, "%-10d", i); 281 + seq_printf(seq, "%d|%-3u|", se->type, 282 + get_valid_blocks(sbi, i, false)); 283 + for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++) 284 + seq_printf(seq, " %.2x", se->cur_valid_map[j]); 285 + seq_putc(seq, '\n'); 286 + } 287 + return 0; 288 + } 289 + 290 + #define F2FS_PROC_FILE_DEF(_name) \ 291 + static int _name##_open_fs(struct inode *inode, struct file *file) \ 292 + { \ 293 + return single_open(file, _name##_seq_show, PDE_DATA(inode)); \ 294 + } \ 295 + \ 296 + static const struct file_operations f2fs_seq_##_name##_fops = { \ 297 + .open = _name##_open_fs, \ 298 + .read = seq_read, \ 299 + .llseek = seq_lseek, \ 300 + .release = single_release, \ 301 + }; 302 + 303 + F2FS_PROC_FILE_DEF(segment_info); 304 + F2FS_PROC_FILE_DEF(segment_bits); 305 + 306 + int __init f2fs_register_sysfs(void) 307 + { 308 + f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); 309 + 310 + f2fs_kset = kset_create_and_add("f2fs", NULL, fs_kobj); 311 + if (!f2fs_kset) 312 + return -ENOMEM; 313 + return 0; 314 + } 315 + 316 + void f2fs_unregister_sysfs(void) 317 + { 318 + kset_unregister(f2fs_kset); 319 + remove_proc_entry("fs/f2fs", NULL); 320 + } 321 + 322 + int f2fs_init_sysfs(struct f2fs_sb_info *sbi) 323 + { 324 + struct super_block *sb = sbi->sb; 325 + int err; 326 + 327 + if (f2fs_proc_root) 328 + sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); 329 + 330 + if (sbi->s_proc) { 331 + proc_create_data("segment_info", S_IRUGO, sbi->s_proc, 332 + &f2fs_seq_segment_info_fops, sb); 333 + proc_create_data("segment_bits", S_IRUGO, sbi->s_proc, 334 + &f2fs_seq_segment_bits_fops, sb); 335 + } 336 + 337 + sbi->s_kobj.kset = f2fs_kset; 338 + init_completion(&sbi->s_kobj_unregister); 339 + err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL, 340 + "%s", sb->s_id); 341 + if (err) 342 + goto err_out; 343 + return 0; 344 + err_out: 345 + if (sbi->s_proc) { 346 + remove_proc_entry("segment_info", sbi->s_proc); 347 + remove_proc_entry("segment_bits", sbi->s_proc); 348 + remove_proc_entry(sb->s_id, f2fs_proc_root); 349 + } 350 + return err; 351 + } 352 + 353 + void f2fs_exit_sysfs(struct f2fs_sb_info *sbi) 354 + { 355 + kobject_del(&sbi->s_kobj); 356 + kobject_put(&sbi->s_kobj); 357 + wait_for_completion(&sbi->s_kobj_unregister); 358 + 359 + if (sbi->s_proc) { 360 + remove_proc_entry("segment_info", sbi->s_proc); 361 + remove_proc_entry("segment_bits", sbi->s_proc); 362 + remove_proc_entry(sbi->sb->s_id, f2fs_proc_root); 363 + } 364 + }
+14 -2
include/trace/events/f2fs.h
··· 19 19 TRACE_DEFINE_ENUM(INMEM_REVOKE); 20 20 TRACE_DEFINE_ENUM(IPU); 21 21 TRACE_DEFINE_ENUM(OPU); 22 + TRACE_DEFINE_ENUM(HOT); 23 + TRACE_DEFINE_ENUM(WARM); 24 + TRACE_DEFINE_ENUM(COLD); 22 25 TRACE_DEFINE_ENUM(CURSEG_HOT_DATA); 23 26 TRACE_DEFINE_ENUM(CURSEG_WARM_DATA); 24 27 TRACE_DEFINE_ENUM(CURSEG_COLD_DATA); ··· 61 58 { INMEM_REVOKE, "INMEM_REVOKE" }, \ 62 59 { IPU, "IN-PLACE" }, \ 63 60 { OPU, "OUT-OF-PLACE" }) 61 + 62 + #define show_block_temp(temp) \ 63 + __print_symbolic(temp, \ 64 + { HOT, "HOT" }, \ 65 + { WARM, "WARM" }, \ 66 + { COLD, "COLD" }) 64 67 65 68 #define F2FS_OP_FLAGS (REQ_RAHEAD | REQ_SYNC | REQ_META | REQ_PRIO | \ 66 69 REQ_PREFLUSH | REQ_FUA) ··· 766 757 __field(block_t, new_blkaddr) 767 758 __field(int, op) 768 759 __field(int, op_flags) 760 + __field(int, temp) 769 761 __field(int, type) 770 762 ), 771 763 ··· 778 768 __entry->new_blkaddr = fio->new_blkaddr; 779 769 __entry->op = fio->op; 780 770 __entry->op_flags = fio->op_flags; 771 + __entry->temp = fio->temp; 781 772 __entry->type = fio->type; 782 773 ), 783 774 784 775 TP_printk("dev = (%d,%d), ino = %lu, page_index = 0x%lx, " 785 - "oldaddr = 0x%llx, newaddr = 0x%llx, rw = %s(%s), type = %s", 776 + "oldaddr = 0x%llx, newaddr = 0x%llx, rw = %s(%s), type = %s_%s", 786 777 show_dev_ino(__entry), 787 778 (unsigned long)__entry->index, 788 779 (unsigned long long)__entry->old_blkaddr, 789 780 (unsigned long long)__entry->new_blkaddr, 790 781 show_bio_type(__entry->op, __entry->op_flags), 782 + show_block_temp(__entry->temp), 791 783 show_block_type(__entry->type)) 792 784 ); 793 785 ··· 802 790 TP_CONDITION(page->mapping) 803 791 ); 804 792 805 - DEFINE_EVENT_CONDITION(f2fs__submit_page_bio, f2fs_submit_page_mbio, 793 + DEFINE_EVENT_CONDITION(f2fs__submit_page_bio, f2fs_submit_page_write, 806 794 807 795 TP_PROTO(struct page *page, struct f2fs_io_info *fio), 808 796