12
12
#include <linux/uuid.h>
13
13
#include <linux/sort.h>
14
14
#include <crypto/aead.h>
15
+ #include "cifsfs.h"
15
16
#include "cifsglob.h"
16
17
#include "smb2pdu.h"
17
18
#include "smb2proto.h"
@@ -3171,29 +3172,33 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3171
3172
return rc ;
3172
3173
}
3173
3174
3175
+ /*
3176
+ * Extending the file
3177
+ */
3178
+ if ((keep_size == false) && i_size_read (inode ) < off + len ) {
3179
+ if ((cifsi -> cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE ) == 0 )
3180
+ smb2_set_sparse (xid , tcon , cfile , inode , false);
3181
+
3182
+ eof = cpu_to_le64 (off + len );
3183
+ rc = SMB2_set_eof (xid , tcon , cfile -> fid .persistent_fid ,
3184
+ cfile -> fid .volatile_fid , cfile -> pid , & eof );
3185
+ if (rc == 0 ) {
3186
+ cifsi -> server_eof = off + len ;
3187
+ cifs_setsize (inode , off + len );
3188
+ cifs_truncate_page (inode -> i_mapping , inode -> i_size );
3189
+ truncate_setsize (inode , off + len );
3190
+ }
3191
+ goto out ;
3192
+ }
3193
+
3174
3194
/*
3175
3195
* Files are non-sparse by default so falloc may be a no-op
3176
- * Must check if file sparse. If not sparse, and not extending
3177
- * then no need to do anything since file already allocated
3196
+ * Must check if file sparse. If not sparse, and since we are not
3197
+ * extending then no need to do anything since file already allocated
3178
3198
*/
3179
3199
if ((cifsi -> cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE ) == 0 ) {
3180
- if (keep_size == true)
3181
- rc = 0 ;
3182
- /* check if extending file */
3183
- else if (i_size_read (inode ) >= off + len )
3184
- /* not extending file and already not sparse */
3185
- rc = 0 ;
3186
- /* BB: in future add else clause to extend file */
3187
- else
3188
- rc = - EOPNOTSUPP ;
3189
- if (rc )
3190
- trace_smb3_falloc_err (xid , cfile -> fid .persistent_fid ,
3191
- tcon -> tid , tcon -> ses -> Suid , off , len , rc );
3192
- else
3193
- trace_smb3_falloc_done (xid , cfile -> fid .persistent_fid ,
3194
- tcon -> tid , tcon -> ses -> Suid , off , len );
3195
- free_xid (xid );
3196
- return rc ;
3200
+ rc = 0 ;
3201
+ goto out ;
3197
3202
}
3198
3203
3199
3204
if ((keep_size == true) || (i_size_read (inode ) >= off + len )) {
@@ -3207,25 +3212,14 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3207
3212
*/
3208
3213
if ((off > 8192 ) || (off + len + 8192 < i_size_read (inode ))) {
3209
3214
rc = - EOPNOTSUPP ;
3210
- trace_smb3_falloc_err (xid , cfile -> fid .persistent_fid ,
3211
- tcon -> tid , tcon -> ses -> Suid , off , len , rc );
3212
- free_xid (xid );
3213
- return rc ;
3214
- }
3215
-
3216
- smb2_set_sparse (xid , tcon , cfile , inode , false);
3217
- rc = 0 ;
3218
- } else {
3219
- smb2_set_sparse (xid , tcon , cfile , inode , false);
3220
- rc = 0 ;
3221
- if (i_size_read (inode ) < off + len ) {
3222
- eof = cpu_to_le64 (off + len );
3223
- rc = SMB2_set_eof (xid , tcon , cfile -> fid .persistent_fid ,
3224
- cfile -> fid .volatile_fid , cfile -> pid ,
3225
- & eof );
3215
+ goto out ;
3226
3216
}
3227
3217
}
3228
3218
3219
+ smb2_set_sparse (xid , tcon , cfile , inode , false);
3220
+ rc = 0 ;
3221
+
3222
+ out :
3229
3223
if (rc )
3230
3224
trace_smb3_falloc_err (xid , cfile -> fid .persistent_fid , tcon -> tid ,
3231
3225
tcon -> ses -> Suid , off , len , rc );
0 commit comments