@@ -87,8 +87,9 @@ __zpl_clone_file_range(struct file *src_file, loff_t src_off,
87
87
*/
88
88
static ssize_t
89
89
__zpl_clone_file_range_locked (struct file * src_file , loff_t src_off ,
90
- struct file * dst_file , loff_t dst_off , size_t len ,
91
- zfs_locked_range_t * src_zlr , zfs_locked_range_t * dst_zlr ) {
90
+ struct file * dst_file , loff_t dst_off , size_t len ,
91
+ zfs_locked_range_t * src_zlr , zfs_locked_range_t * dst_zlr )
92
+ {
92
93
struct inode * src_i = file_inode (src_file );
93
94
struct inode * dst_i = file_inode (dst_file );
94
95
uint64_t src_off_o = (uint64_t )src_off ;
@@ -98,8 +99,8 @@ __zpl_clone_file_range_locked(struct file *src_file, loff_t src_off,
98
99
fstrans_cookie_t cookie ;
99
100
int err ;
100
101
101
- if (!spa_feature_is_enabled (dmu_objset_spa ( ITOZSB ( dst_i ) -> z_os ),
102
- SPA_FEATURE_BLOCK_CLONING ))
102
+ if (!spa_feature_is_enabled (
103
+ dmu_objset_spa ( ITOZSB ( dst_i ) -> z_os ), SPA_FEATURE_BLOCK_CLONING ))
103
104
return (- EOPNOTSUPP );
104
105
105
106
if (src_i != dst_i )
@@ -108,9 +109,8 @@ __zpl_clone_file_range_locked(struct file *src_file, loff_t src_off,
108
109
109
110
crhold (cr );
110
111
cookie = spl_fstrans_mark ();
111
-
112
- err = - zfs_clone_range_locked (ITOZ (src_i ), & src_off_o , ITOZ (dst_i ), & dst_off_o ,
113
- & len_o , cr , src_zlr , dst_zlr );
112
+ err = - zfs_clone_range_locked (ITOZ (src_i ), & src_off_o , ITOZ (dst_i ),
113
+ & dst_off_o , & len_o , cr , src_zlr , dst_zlr );
114
114
115
115
spl_fstrans_unmark (cookie );
116
116
crfree (cr );
@@ -125,7 +125,6 @@ __zpl_clone_file_range_locked(struct file *src_file, loff_t src_off,
125
125
return ((ssize_t )len_o );
126
126
}
127
127
128
-
129
128
#if defined(HAVE_VFS_COPY_FILE_RANGE ) || \
130
129
defined(HAVE_VFS_FILE_OPERATIONS_EXTEND )
131
130
/*
@@ -196,11 +195,6 @@ zpl_remap_file_range(struct file *src_file, loff_t src_off,
196
195
* doesn't do that, so we just turn the flag off.
197
196
*/
198
197
flags &= ~REMAP_FILE_CAN_SHORTEN ;
199
- /* Zero length means to clone everything to the end of the file
200
- */
201
- if (len == 0 )
202
- len = i_size_read (file_inode (src_file )) - src_off ;
203
-
204
198
if (flags & REMAP_FILE_DEDUP ) {
205
199
/* Both nodes must be range locked */
206
200
zfs_locked_range_t * src_zlr ;
@@ -229,9 +223,8 @@ zpl_remap_file_range(struct file *src_file, loff_t src_off,
229
223
}
230
224
231
225
bool same = false;
232
- int ret = zpl_dedupe_file_compare_locked (
233
- src_file , src_off , dst_file , dst_off , len , & same , src_zlr ,
234
- dst_zlr );
226
+ int ret = zpl_dedupe_file_compare_locked (src_file , src_off ,
227
+ dst_file , dst_off , len , & same , src_zlr , dst_zlr );
235
228
if (ret ) {
236
229
goto cleanup ;
237
230
}
@@ -240,11 +233,11 @@ zpl_remap_file_range(struct file *src_file, loff_t src_off,
240
233
goto cleanup ;
241
234
}
242
235
ret = __zpl_clone_file_range_locked (src_file , src_off , dst_file ,
243
- dst_off , len , src_zlr , dst_zlr );
236
+ dst_off , len , src_zlr , dst_zlr );
244
237
cleanup :
245
238
zfs_rangelock_exit (src_zlr );
246
239
zfs_rangelock_exit (dst_zlr );
247
- return ret ;
240
+ return ( ret ) ;
248
241
}
249
242
if (len == 0 )
250
243
len = i_size_read (file_inode (src_file )) - src_off ;
@@ -261,7 +254,8 @@ zpl_remap_file_range(struct file *src_file, loff_t src_off,
261
254
*/
262
255
int
263
256
zpl_clone_file_range (struct file * src_file , loff_t src_off ,
264
- struct file * dst_file , loff_t dst_off , uint64_t len ) {
257
+ struct file * dst_file , loff_t dst_off , uint64_t len )
258
+ {
265
259
/* Zero length means to clone everything to the end of the file */
266
260
if (len == 0 )
267
261
len = i_size_read (file_inode (src_file )) - src_off ;
@@ -358,36 +352,36 @@ zpl_ioctl_ficlonerange(struct file *dst_file, void __user *arg)
358
352
359
353
/* Entry point for FIDEDUPERANGE, before Linux 4.5. */
360
354
long
361
- zpl_ioctl_fideduperange (struct file * src_file , void * arg ) {
355
+ zpl_ioctl_fideduperange (struct file * src_file , void * arg )
356
+ {
362
357
zfs_ioc_compat_dedupe_range_t dup ;
363
358
int i ;
364
-
365
- if (copy_from_user (& dup , arg , sizeof (dup )))
359
+ if (copy_from_user (& dup , arg , sizeof (dup )))
366
360
return (- EFAULT );
367
361
368
362
u16 count = dup .fdr_dest_count ;
369
363
struct inode * src_inode = file_inode (src_file );
370
364
371
365
/* Nothing to duplicate to */
372
366
if (count == 0 )
373
- return - EINVAL ;
367
+ return ( - EINVAL ) ;
374
368
375
369
/* Check the src file */
376
370
if (!(src_file -> f_mode & FMODE_READ ))
377
- return - EINVAL ;
371
+ return ( - EINVAL ) ;
378
372
379
373
if (S_ISDIR (src_inode -> i_mode ))
380
- return - EISDIR ;
374
+ return ( - EISDIR ) ;
381
375
382
376
if (!S_ISREG (src_inode -> i_mode ))
383
- return - EINVAL ;
377
+ return ( - EINVAL ) ;
384
378
385
379
if (dup .fdr_src_offset + dup .fdr_src_length > i_size_read (src_inode ))
386
- return - EINVAL ;
380
+ return ( - EINVAL ) ;
387
381
388
382
/* Check the dup structure */
389
383
if (dup .fdr_reserved1 || dup .fdr_reserved2 )
390
- return - EINVAL ;
384
+ return ( - EINVAL ) ;
391
385
392
386
/* Set output values to safe results */
393
387
for (i = 0 ; i < count ; i ++ ) {
@@ -409,8 +403,8 @@ zpl_ioctl_fideduperange(struct file *src_file, void *arg) {
409
403
}
410
404
loff_t deduped =
411
405
zpl_remap_file_range (src_file , dup .fdr_src_offset , dst_file ,
412
- dup .fdr_info [i ].fdri_dest_offset ,
413
- dup . fdr_src_length , REMAP_FILE_DEDUP );
406
+ dup .fdr_info [i ].fdri_dest_offset , dup . fdr_src_length ,
407
+ REMAP_FILE_DEDUP );
414
408
if (deduped == - EBADE ) {
415
409
dup .fdr_info [i ].fdri_status = FILE_DEDUPE_RANGE_DIFFERS ;
416
410
} else if (deduped < 0 ) {
@@ -421,15 +415,14 @@ zpl_ioctl_fideduperange(struct file *src_file, void *arg) {
421
415
do_fdput :
422
416
fdput (dst_fd );
423
417
}
424
- return 0 ;
418
+ return ( 0 ) ;
425
419
}
426
420
427
421
int
428
422
zpl_dedupe_file_compare_locked (struct file * src_file , loff_t src_off ,
429
- struct file * dst_file , loff_t dst_off ,
430
- uint64_t len , bool * is_same ,
431
- zfs_locked_range_t * src_zlr ,
432
- zfs_locked_range_t * dst_zlr ) {
423
+ struct file * dst_file , loff_t dst_off , uint64_t len , bool * is_same ,
424
+ zfs_locked_range_t * src_zlr , zfs_locked_range_t * dst_zlr )
425
+ {
433
426
bool same = true;
434
427
int err = 0 ;
435
428
znode_t * src_znode = ITOZ (file_inode (src_file ));
@@ -443,7 +436,7 @@ zpl_dedupe_file_compare_locked(struct file *src_file, loff_t src_off,
443
436
zfs_uio_t uio ;
444
437
445
438
uint64_t cmp_len = min (PAGE_SIZE - offset_in_page (src_off ),
446
- PAGE_SIZE - offset_in_page (dst_off ));
439
+ PAGE_SIZE - offset_in_page (dst_off ));
447
440
448
441
cmp_len = min (cmp_len , len );
449
442
@@ -456,25 +449,29 @@ zpl_dedupe_file_compare_locked(struct file *src_file, loff_t src_off,
456
449
zfs_uio_iovec_init (& uio , & iov , 1 , 0 , UIO_SYSSPACE , cmp_len , 0 );
457
450
crhold (cr );
458
451
cookie = spl_fstrans_mark ();
459
- err = - zfs_read_locked (src_znode , & uio , src_file -> f_flags , cr ,
460
- src_zlr );
452
+ err = - zfs_read_locked (
453
+ src_znode , & uio , src_file -> f_flags , cr , src_zlr );
461
454
spl_fstrans_unmark (cookie );
462
455
crfree (cr );
463
-
456
+ if (zfs_uio_resid (& uio ) != 0 )
457
+ err = - EIO ;
464
458
if (err )
465
459
goto done ;
466
460
iov .iov_base = dst_buf ;
467
461
iov .iov_len = cmp_len ;
462
+
463
+ zfs_uio_iovec_init (& uio , & iov , 1 , 0 , UIO_SYSSPACE , cmp_len , 0 );
468
464
crhold (cr );
469
465
cookie = spl_fstrans_mark ();
470
- err = - zfs_read_locked (dst_znode , & uio , dst_file -> f_flags , cr ,
471
- dst_zlr );
466
+ err = - zfs_read_locked (
467
+ dst_znode , & uio , dst_file -> f_flags , cr , dst_zlr );
472
468
spl_fstrans_unmark (cookie );
473
469
crfree (cr );
470
+ if (zfs_uio_resid (& uio ) != 0 )
471
+ err = - EIO ;
474
472
475
473
if (err )
476
474
goto done ;
477
-
478
475
if (memcmp (src_buf , dst_buf , cmp_len ))
479
476
same = false;
480
477
@@ -487,9 +484,8 @@ zpl_dedupe_file_compare_locked(struct file *src_file, loff_t src_off,
487
484
}
488
485
489
486
* is_same = same ;
490
-
491
487
done :
492
488
kmem_free (src_buf , PAGE_SIZE );
493
489
kmem_free (dst_buf , PAGE_SIZE );
494
- return err ;
490
+ return ( err ) ;
495
491
}
0 commit comments