inode.c (6a6788576dac56135bf98ad974a038b0afb1a499) | inode.c (13ec7297e5331f2754d7629a068c619c41f20e56) |
---|---|
1/* 2 * fs/f2fs/inode.c 3 * 4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 5 * http://www.samsung.com/ 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 303 unchanged lines hidden (view full) --- 312/* 313 * Called at the last iput() if i_nlink is zero 314 */ 315void f2fs_evict_inode(struct inode *inode) 316{ 317 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 318 struct f2fs_inode_info *fi = F2FS_I(inode); 319 nid_t xnid = fi->i_xattr_nid; | 1/* 2 * fs/f2fs/inode.c 3 * 4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 5 * http://www.samsung.com/ 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 303 unchanged lines hidden (view full) --- 312/* 313 * Called at the last iput() if i_nlink is zero 314 */ 315void f2fs_evict_inode(struct inode *inode) 316{ 317 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 318 struct f2fs_inode_info *fi = F2FS_I(inode); 319 nid_t xnid = fi->i_xattr_nid; |
320 int err = 0; |
|
320 321 /* some remained atomic pages should discarded */ 322 if (f2fs_is_atomic_file(inode)) 323 commit_inmem_pages(inode, true); 324 325 trace_f2fs_evict_inode(inode); 326 truncate_inode_pages_final(&inode->i_data); 327 --- 9 unchanged lines hidden (view full) --- 337 if (inode->i_nlink || is_bad_inode(inode)) 338 goto no_delete; 339 340 sb_start_intwrite(inode->i_sb); 341 set_inode_flag(fi, FI_NO_ALLOC); 342 i_size_write(inode, 0); 343 344 if (F2FS_HAS_BLOCKS(inode)) | 321 322 /* some remained atomic pages should discarded */ 323 if (f2fs_is_atomic_file(inode)) 324 commit_inmem_pages(inode, true); 325 326 trace_f2fs_evict_inode(inode); 327 truncate_inode_pages_final(&inode->i_data); 328 --- 9 unchanged lines hidden (view full) --- 338 if (inode->i_nlink || is_bad_inode(inode)) 339 goto no_delete; 340 341 sb_start_intwrite(inode->i_sb); 342 set_inode_flag(fi, FI_NO_ALLOC); 343 i_size_write(inode, 0); 344 345 if (F2FS_HAS_BLOCKS(inode)) |
345 f2fs_truncate(inode, true); | 346 err = f2fs_truncate(inode, true); |
346 | 347 |
347 f2fs_lock_op(sbi); 348 remove_inode_page(inode); 349 f2fs_unlock_op(sbi); | 348 if (!err) { 349 f2fs_lock_op(sbi); 350 err = remove_inode_page(inode); 351 f2fs_unlock_op(sbi); 352 } |
350 351 sb_end_intwrite(inode->i_sb); 352no_delete: 353 stat_dec_inline_xattr(inode); 354 stat_dec_inline_dir(inode); 355 stat_dec_inline_inode(inode); 356 357 invalidate_mapping_pages(NODE_MAPPING(sbi), inode->i_ino, inode->i_ino); 358 if (xnid) 359 invalidate_mapping_pages(NODE_MAPPING(sbi), xnid, xnid); 360 if (is_inode_flag_set(fi, FI_APPEND_WRITE)) 361 add_dirty_inode(sbi, inode->i_ino, APPEND_INO); 362 if (is_inode_flag_set(fi, FI_UPDATE_WRITE)) 363 add_dirty_inode(sbi, inode->i_ino, UPDATE_INO); 364 if (is_inode_flag_set(fi, FI_FREE_NID)) { | 353 354 sb_end_intwrite(inode->i_sb); 355no_delete: 356 stat_dec_inline_xattr(inode); 357 stat_dec_inline_dir(inode); 358 stat_dec_inline_inode(inode); 359 360 invalidate_mapping_pages(NODE_MAPPING(sbi), inode->i_ino, inode->i_ino); 361 if (xnid) 362 invalidate_mapping_pages(NODE_MAPPING(sbi), xnid, xnid); 363 if (is_inode_flag_set(fi, FI_APPEND_WRITE)) 364 add_dirty_inode(sbi, inode->i_ino, APPEND_INO); 365 if (is_inode_flag_set(fi, FI_UPDATE_WRITE)) 366 add_dirty_inode(sbi, inode->i_ino, UPDATE_INO); 367 if (is_inode_flag_set(fi, FI_FREE_NID)) { |
365 alloc_nid_failed(sbi, inode->i_ino); | 368 if (err && err != -ENOENT) 369 alloc_nid_done(sbi, inode->i_ino); 370 else 371 alloc_nid_failed(sbi, inode->i_ino); |
366 clear_inode_flag(fi, FI_FREE_NID); 367 } | 372 clear_inode_flag(fi, FI_FREE_NID); 373 } |
374 375 if (err && err != -ENOENT) { 376 if (!exist_written_data(sbi, inode->i_ino, ORPHAN_INO)) { 377 /* 378 * get here because we failed to release resource 379 * of inode previously, reminder our user to run fsck 380 * for fixing. 381 */ 382 set_sbi_flag(sbi, SBI_NEED_FSCK); 383 f2fs_msg(sbi->sb, KERN_WARNING, 384 "inode (ino:%lu) resource leak, run fsck " 385 "to fix this issue!", inode->i_ino); 386 } 387 } |
|
368out_clear: 369#ifdef CONFIG_F2FS_FS_ENCRYPTION 370 if (fi->i_crypt_info) 371 f2fs_free_encryption_info(inode, fi->i_crypt_info); 372#endif 373 clear_inode(inode); 374} 375 376/* caller should call f2fs_lock_op() */ 377void handle_failed_inode(struct inode *inode) 378{ 379 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | 388out_clear: 389#ifdef CONFIG_F2FS_FS_ENCRYPTION 390 if (fi->i_crypt_info) 391 f2fs_free_encryption_info(inode, fi->i_crypt_info); 392#endif 393 clear_inode(inode); 394} 395 396/* caller should call f2fs_lock_op() */ 397void handle_failed_inode(struct inode *inode) 398{ 399 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
400 int err = 0; |
|
380 381 clear_nlink(inode); 382 make_bad_inode(inode); 383 unlock_new_inode(inode); 384 385 i_size_write(inode, 0); 386 if (F2FS_HAS_BLOCKS(inode)) | 401 402 clear_nlink(inode); 403 make_bad_inode(inode); 404 unlock_new_inode(inode); 405 406 i_size_write(inode, 0); 407 if (F2FS_HAS_BLOCKS(inode)) |
387 f2fs_truncate(inode, false); | 408 err = f2fs_truncate(inode, false); |
388 | 409 |
389 remove_inode_page(inode); | 410 if (!err) 411 err = remove_inode_page(inode); |
390 | 412 |
413 /* 414 * if we skip truncate_node in remove_inode_page bacause we failed 415 * before, it's better to find another way to release resource of 416 * this inode (e.g. valid block count, node block or nid). Here we 417 * choose to add this inode to orphan list, so that we can call iput 418 * for releasing in orphan recovery flow. 419 * 420 * Note: we should add inode to orphan list before f2fs_unlock_op() 421 * so we can prevent losing this orphan when encoutering checkpoint 422 * and following suddenly power-off. 423 */ 424 if (err && err != -ENOENT) { 425 err = acquire_orphan_inode(sbi); 426 if (!err) 427 add_orphan_inode(sbi, inode->i_ino); 428 } 429 |
|
391 set_inode_flag(F2FS_I(inode), FI_FREE_NID); 392 f2fs_unlock_op(sbi); 393 394 /* iput will drop the inode object */ 395 iput(inode); 396} | 430 set_inode_flag(F2FS_I(inode), FI_FREE_NID); 431 f2fs_unlock_op(sbi); 432 433 /* iput will drop the inode object */ 434 iput(inode); 435} |