@@ -725,6 +725,11 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
725725
726726 trace_f2fs_truncate_blocks_enter (inode , from );
727727
728+ if (IS_DEVICE_ALIASING (inode ) && from ) {
729+ err = - EINVAL ;
730+ goto out_err ;
731+ }
732+
728733 free_from = (pgoff_t )F2FS_BLK_ALIGN (from );
729734
730735 if (free_from >= max_file_blocks (inode ))
@@ -739,6 +744,21 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
739744 goto out ;
740745 }
741746
747+ if (IS_DEVICE_ALIASING (inode )) {
748+ struct extent_tree * et = F2FS_I (inode )-> extent_tree [EX_READ ];
749+ struct extent_info ei = et -> largest ;
750+ unsigned int i ;
751+
752+ for (i = 0 ; i < ei .len ; i ++ )
753+ f2fs_invalidate_blocks (sbi , ei .blk + i );
754+
755+ dec_valid_block_count (sbi , inode , ei .len );
756+ f2fs_update_time (sbi , REQ_TIME );
757+
758+ f2fs_put_page (ipage , 1 );
759+ goto out ;
760+ }
761+
742762 if (f2fs_has_inline_data (inode )) {
743763 f2fs_truncate_inline_inode (inode , ipage , from );
744764 f2fs_put_page (ipage , 1 );
@@ -774,7 +794,7 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
774794 /* lastly zero out the first data page */
775795 if (!err )
776796 err = truncate_partial_data_page (inode , from , truncate_page );
777-
797+ out_err :
778798 trace_f2fs_truncate_blocks_exit (inode , err );
779799 return err ;
780800}
@@ -992,7 +1012,8 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
9921012 return - EPERM ;
9931013
9941014 if ((attr -> ia_valid & ATTR_SIZE )) {
995- if (!f2fs_is_compress_backend_ready (inode ))
1015+ if (!f2fs_is_compress_backend_ready (inode ) ||
1016+ IS_DEVICE_ALIASING (inode ))
9961017 return - EOPNOTSUPP ;
9971018 if (is_inode_flag_set (inode , FI_COMPRESS_RELEASED ) &&
9981019 !IS_ALIGNED (attr -> ia_size ,
@@ -1861,7 +1882,7 @@ static long f2fs_fallocate(struct file *file, int mode,
18611882 return - EIO ;
18621883 if (!f2fs_is_checkpoint_ready (F2FS_I_SB (inode )))
18631884 return - ENOSPC ;
1864- if (!f2fs_is_compress_backend_ready (inode ))
1885+ if (!f2fs_is_compress_backend_ready (inode ) || IS_DEVICE_ALIASING ( inode ) )
18651886 return - EOPNOTSUPP ;
18661887
18671888 /* f2fs only support ->fallocate for regular file */
@@ -3297,6 +3318,9 @@ int f2fs_pin_file_control(struct inode *inode, bool inc)
32973318 struct f2fs_inode_info * fi = F2FS_I (inode );
32983319 struct f2fs_sb_info * sbi = F2FS_I_SB (inode );
32993320
3321+ if (IS_DEVICE_ALIASING (inode ))
3322+ return - EINVAL ;
3323+
33003324 if (fi -> i_gc_failures >= sbi -> gc_pin_file_threshold ) {
33013325 f2fs_warn (sbi , "%s: Enable GC = ino %lx after %x GC trials" ,
33023326 __func__ , inode -> i_ino , fi -> i_gc_failures );
@@ -3327,6 +3351,9 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg)
33273351 if (f2fs_readonly (sbi -> sb ))
33283352 return - EROFS ;
33293353
3354+ if (!pin && IS_DEVICE_ALIASING (inode ))
3355+ return - EOPNOTSUPP ;
3356+
33303357 ret = mnt_want_write_file (filp );
33313358 if (ret )
33323359 return ret ;
@@ -3392,6 +3419,12 @@ static int f2fs_ioc_get_pin_file(struct file *filp, unsigned long arg)
33923419 return put_user (pin , (u32 __user * )arg );
33933420}
33943421
3422+ static int f2fs_ioc_get_dev_alias_file (struct file * filp , unsigned long arg )
3423+ {
3424+ return put_user (IS_DEVICE_ALIASING (file_inode (filp )) ? 1 : 0 ,
3425+ (u32 __user * )arg );
3426+ }
3427+
33953428int f2fs_precache_extents (struct inode * inode )
33963429{
33973430 struct f2fs_inode_info * fi = F2FS_I (inode );
@@ -4491,6 +4524,8 @@ static long __f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
44914524 return f2fs_ioc_decompress_file (filp );
44924525 case F2FS_IOC_COMPRESS_FILE :
44934526 return f2fs_ioc_compress_file (filp );
4527+ case F2FS_IOC_GET_DEV_ALIAS_FILE :
4528+ return f2fs_ioc_get_dev_alias_file (filp , arg );
44944529 default :
44954530 return - ENOTTY ;
44964531 }
@@ -4766,7 +4801,8 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,
47664801 else
47674802 return 0 ;
47684803
4769- map .m_may_create = true;
4804+ if (!IS_DEVICE_ALIASING (inode ))
4805+ map .m_may_create = true;
47704806 if (dio ) {
47714807 map .m_seg_type = f2fs_rw_hint_to_seg_type (sbi ,
47724808 inode -> i_write_hint );
@@ -5203,6 +5239,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
52035239 case F2FS_IOC_SET_COMPRESS_OPTION :
52045240 case F2FS_IOC_DECOMPRESS_FILE :
52055241 case F2FS_IOC_COMPRESS_FILE :
5242+ case F2FS_IOC_GET_DEV_ALIAS_FILE :
52065243 break ;
52075244 default :
52085245 return - ENOIOCTLCMD ;
0 commit comments