@@ -2468,27 +2468,28 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg)
2468
2468
return ret ;
2469
2469
}
2470
2470
2471
- static void f2fs_keep_noreuse_range (struct inode * inode ,
2471
+ static int f2fs_keep_noreuse_range (struct inode * inode ,
2472
2472
loff_t offset , loff_t len )
2473
2473
{
2474
2474
struct f2fs_sb_info * sbi = F2FS_I_SB (inode );
2475
2475
u64 max_bytes = F2FS_BLK_TO_BYTES (max_file_blocks (inode ));
2476
2476
u64 start , end ;
2477
+ int ret = 0 ;
2477
2478
2478
2479
if (!S_ISREG (inode -> i_mode ))
2479
- return ;
2480
+ return 0 ;
2480
2481
2481
2482
if (offset >= max_bytes || len > max_bytes ||
2482
2483
(offset + len ) > max_bytes )
2483
- return ;
2484
+ return 0 ;
2484
2485
2485
2486
start = offset >> PAGE_SHIFT ;
2486
2487
end = DIV_ROUND_UP (offset + len , PAGE_SIZE );
2487
2488
2488
2489
inode_lock (inode );
2489
2490
if (f2fs_is_atomic_file (inode )) {
2490
2491
inode_unlock (inode );
2491
- return ;
2492
+ return 0 ;
2492
2493
}
2493
2494
2494
2495
spin_lock (& sbi -> inode_lock [DONATE_INODE ]);
@@ -2497,7 +2498,12 @@ static void f2fs_keep_noreuse_range(struct inode *inode,
2497
2498
if (!list_empty (& F2FS_I (inode )-> gdonate_list )) {
2498
2499
list_del_init (& F2FS_I (inode )-> gdonate_list );
2499
2500
sbi -> donate_files -- ;
2500
- }
2501
+ if (is_inode_flag_set (inode , FI_DONATE_FINISHED ))
2502
+ ret = - EALREADY ;
2503
+ else
2504
+ set_inode_flag (inode , FI_DONATE_FINISHED );
2505
+ } else
2506
+ ret = - ENOENT ;
2501
2507
} else {
2502
2508
if (list_empty (& F2FS_I (inode )-> gdonate_list )) {
2503
2509
list_add_tail (& F2FS_I (inode )-> gdonate_list ,
@@ -2509,9 +2515,12 @@ static void f2fs_keep_noreuse_range(struct inode *inode,
2509
2515
}
2510
2516
F2FS_I (inode )-> donate_start = start ;
2511
2517
F2FS_I (inode )-> donate_end = end - 1 ;
2518
+ clear_inode_flag (inode , FI_DONATE_FINISHED );
2512
2519
}
2513
2520
spin_unlock (& sbi -> inode_lock [DONATE_INODE ]);
2514
2521
inode_unlock (inode );
2522
+
2523
+ return ret ;
2515
2524
}
2516
2525
2517
2526
static int f2fs_ioc_fitrim (struct file * filp , unsigned long arg )
@@ -5242,8 +5251,8 @@ static int f2fs_file_fadvise(struct file *filp, loff_t offset, loff_t len,
5242
5251
f2fs_compressed_file (inode )))
5243
5252
f2fs_invalidate_compress_pages (F2FS_I_SB (inode ), inode -> i_ino );
5244
5253
else if (advice == POSIX_FADV_NOREUSE )
5245
- f2fs_keep_noreuse_range (inode , offset , len );
5246
- return 0 ;
5254
+ err = f2fs_keep_noreuse_range (inode , offset , len );
5255
+ return err ;
5247
5256
}
5248
5257
5249
5258
#ifdef CONFIG_COMPAT
0 commit comments