@@ -1066,20 +1066,22 @@ static ssize_t fuse_send_write(struct fuse_io_args *ia, loff_t pos,
1066
1066
return err ?: ia -> write .out .size ;
1067
1067
}
1068
1068
1069
- bool fuse_write_update_attr (struct inode * inode , loff_t pos )
1069
+ bool fuse_write_update_attr (struct inode * inode , loff_t pos , ssize_t written )
1070
1070
{
1071
1071
struct fuse_conn * fc = get_fuse_conn (inode );
1072
1072
struct fuse_inode * fi = get_fuse_inode (inode );
1073
1073
bool ret = false;
1074
1074
1075
1075
spin_lock (& fi -> lock );
1076
1076
fi -> attr_version = atomic64_inc_return (& fc -> attr_version );
1077
- if (pos > inode -> i_size ) {
1077
+ if (written > 0 && pos > inode -> i_size ) {
1078
1078
i_size_write (inode , pos );
1079
1079
ret = true;
1080
1080
}
1081
1081
spin_unlock (& fi -> lock );
1082
1082
1083
+ fuse_invalidate_attr_mask (inode , FUSE_STATX_MODSIZE );
1084
+
1083
1085
return ret ;
1084
1086
}
1085
1087
@@ -1262,11 +1264,8 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
1262
1264
kfree (ap -> pages );
1263
1265
} while (!err && iov_iter_count (ii ));
1264
1266
1265
- if (res > 0 )
1266
- fuse_write_update_attr (inode , pos );
1267
-
1267
+ fuse_write_update_attr (inode , pos , res );
1268
1268
clear_bit (FUSE_I_SIZE_UNSTABLE , & fi -> state );
1269
- fuse_invalidate_attr_mask (inode , FUSE_STATX_MODSIZE );
1270
1269
1271
1270
return res > 0 ? res : err ;
1272
1271
}
@@ -1554,11 +1553,9 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)
1554
1553
} else {
1555
1554
res = fuse_direct_io (& io , from , & iocb -> ki_pos ,
1556
1555
FUSE_DIO_WRITE );
1556
+ fuse_write_update_attr (inode , iocb -> ki_pos , res );
1557
1557
}
1558
1558
}
1559
- fuse_invalidate_attr_mask (inode , FUSE_STATX_MODSIZE );
1560
- if (res > 0 )
1561
- fuse_write_update_attr (inode , iocb -> ki_pos );
1562
1559
inode_unlock (inode );
1563
1560
1564
1561
return res ;
@@ -2900,9 +2897,8 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
2900
2897
kref_put (& io -> refcnt , fuse_io_release );
2901
2898
2902
2899
if (iov_iter_rw (iter ) == WRITE ) {
2903
- if (ret > 0 )
2904
- fuse_write_update_attr (inode , pos );
2905
- else if (ret < 0 && offset + count > i_size )
2900
+ fuse_write_update_attr (inode , pos , ret );
2901
+ if (ret < 0 && offset + count > i_size )
2906
2902
fuse_do_truncate (file );
2907
2903
}
2908
2904
@@ -2990,7 +2986,8 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2990
2986
2991
2987
/* we could have extended the file */
2992
2988
if (!(mode & FALLOC_FL_KEEP_SIZE )) {
2993
- bool changed = fuse_write_update_attr (inode , offset + length );
2989
+ bool changed = fuse_write_update_attr (inode , offset + length ,
2990
+ length );
2994
2991
2995
2992
if (changed && fm -> fc -> writeback_cache )
2996
2993
file_update_time (file );
@@ -3108,7 +3105,8 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
3108
3105
ALIGN (pos_out + outarg .size , PAGE_SIZE ) - 1 );
3109
3106
3110
3107
if (fc -> writeback_cache ) {
3111
- fuse_write_update_attr (inode_out , pos_out + outarg .size );
3108
+ fuse_write_update_attr (inode_out , pos_out + outarg .size ,
3109
+ outarg .size );
3112
3110
file_update_time (file_out );
3113
3111
}
3114
3112
0 commit comments