@@ -195,16 +195,6 @@ static struct file *ovl_real_file(const struct file *file)
195
195
return ovl_real_file_path (file , & realpath );
196
196
}
197
197
198
- static int ovl_real_fdget (const struct file * file , struct fd * real )
199
- {
200
- struct file * f = ovl_real_file (file );
201
-
202
- if (IS_ERR (f ))
203
- return PTR_ERR (f );
204
- real -> word = (unsigned long )f ;
205
- return 0 ;
206
- }
207
-
208
198
static int ovl_open (struct inode * inode , struct file * file )
209
199
{
210
200
struct dentry * dentry = file_dentry (file );
@@ -253,7 +243,7 @@ static int ovl_release(struct inode *inode, struct file *file)
253
243
static loff_t ovl_llseek (struct file * file , loff_t offset , int whence )
254
244
{
255
245
struct inode * inode = file_inode (file );
256
- struct fd real ;
246
+ struct file * realfile ;
257
247
const struct cred * old_cred ;
258
248
loff_t ret ;
259
249
@@ -269,9 +259,9 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence)
269
259
return vfs_setpos (file , 0 , 0 );
270
260
}
271
261
272
- ret = ovl_real_fdget (file , & real );
273
- if (ret )
274
- return ret ;
262
+ realfile = ovl_real_file (file );
263
+ if (IS_ERR ( realfile ) )
264
+ return PTR_ERR ( realfile ) ;
275
265
276
266
/*
277
267
* Overlay file f_pos is the master copy that is preserved
@@ -281,17 +271,15 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence)
281
271
* files, so we use the real file to perform seeks.
282
272
*/
283
273
ovl_inode_lock (inode );
284
- fd_file ( real ) -> f_pos = file -> f_pos ;
274
+ realfile -> f_pos = file -> f_pos ;
285
275
286
276
old_cred = ovl_override_creds (inode -> i_sb );
287
- ret = vfs_llseek (fd_file ( real ) , offset , whence );
277
+ ret = vfs_llseek (realfile , offset , whence );
288
278
ovl_revert_creds (old_cred );
289
279
290
- file -> f_pos = fd_file ( real ) -> f_pos ;
280
+ file -> f_pos = realfile -> f_pos ;
291
281
ovl_inode_unlock (inode );
292
282
293
- fdput (real );
294
-
295
283
return ret ;
296
284
}
297
285
@@ -337,8 +325,7 @@ static void ovl_file_accessed(struct file *file)
337
325
static ssize_t ovl_read_iter (struct kiocb * iocb , struct iov_iter * iter )
338
326
{
339
327
struct file * file = iocb -> ki_filp ;
340
- struct fd real ;
341
- ssize_t ret ;
328
+ struct file * realfile ;
342
329
struct backing_file_ctx ctx = {
343
330
.cred = ovl_creds (file_inode (file )-> i_sb ),
344
331
.accessed = ovl_file_accessed ,
@@ -347,22 +334,19 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
347
334
if (!iov_iter_count (iter ))
348
335
return 0 ;
349
336
350
- ret = ovl_real_fdget (file , & real );
351
- if (ret )
352
- return ret ;
353
-
354
- ret = backing_file_read_iter (fd_file (real ), iter , iocb , iocb -> ki_flags ,
355
- & ctx );
356
- fdput (real );
337
+ realfile = ovl_real_file (file );
338
+ if (IS_ERR (realfile ))
339
+ return PTR_ERR (realfile );
357
340
358
- return ret ;
341
+ return backing_file_read_iter (realfile , iter , iocb , iocb -> ki_flags ,
342
+ & ctx );
359
343
}
360
344
361
345
static ssize_t ovl_write_iter (struct kiocb * iocb , struct iov_iter * iter )
362
346
{
363
347
struct file * file = iocb -> ki_filp ;
364
348
struct inode * inode = file_inode (file );
365
- struct fd real ;
349
+ struct file * realfile ;
366
350
ssize_t ret ;
367
351
int ifl = iocb -> ki_flags ;
368
352
struct backing_file_ctx ctx = {
@@ -377,8 +361,9 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
377
361
/* Update mode */
378
362
ovl_copyattr (inode );
379
363
380
- ret = ovl_real_fdget (file , & real );
381
- if (ret )
364
+ realfile = ovl_real_file (file );
365
+ ret = PTR_ERR (realfile );
366
+ if (IS_ERR (realfile ))
382
367
goto out_unlock ;
383
368
384
369
if (!ovl_should_sync (OVL_FS (inode -> i_sb )))
@@ -389,8 +374,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
389
374
* this property in case it is set by the issuer.
390
375
*/
391
376
ifl &= ~IOCB_DIO_CALLER_COMP ;
392
- ret = backing_file_write_iter (fd_file (real ), iter , iocb , ifl , & ctx );
393
- fdput (real );
377
+ ret = backing_file_write_iter (realfile , iter , iocb , ifl , & ctx );
394
378
395
379
out_unlock :
396
380
inode_unlock (inode );
@@ -402,39 +386,38 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos,
402
386
struct pipe_inode_info * pipe , size_t len ,
403
387
unsigned int flags )
404
388
{
405
- struct fd real ;
389
+ struct file * realfile ;
406
390
ssize_t ret ;
407
391
struct backing_file_ctx ctx = {
408
392
.cred = ovl_creds (file_inode (in )-> i_sb ),
409
393
.accessed = ovl_file_accessed ,
410
394
};
411
395
struct kiocb iocb ;
412
396
413
- ret = ovl_real_fdget (in , & real );
414
- if (ret )
415
- return ret ;
397
+ realfile = ovl_real_file (in );
398
+ if (IS_ERR ( realfile ) )
399
+ return PTR_ERR ( realfile ) ;
416
400
417
401
init_sync_kiocb (& iocb , in );
418
402
iocb .ki_pos = * ppos ;
419
- ret = backing_file_splice_read (fd_file ( real ) , & iocb , pipe , len , flags , & ctx );
403
+ ret = backing_file_splice_read (realfile , & iocb , pipe , len , flags , & ctx );
420
404
* ppos = iocb .ki_pos ;
421
- fdput (real );
422
405
423
406
return ret ;
424
407
}
425
408
426
409
/*
427
410
* Calling iter_file_splice_write() directly from overlay's f_op may deadlock
428
411
* due to lock order inversion between pipe->mutex in iter_file_splice_write()
429
- * and file_start_write(fd_file(real) ) in ovl_write_iter().
412
+ * and file_start_write(realfile ) in ovl_write_iter().
430
413
*
431
414
* So do everything ovl_write_iter() does and call iter_file_splice_write() on
432
415
* the real file.
433
416
*/
434
417
static ssize_t ovl_splice_write (struct pipe_inode_info * pipe , struct file * out ,
435
418
loff_t * ppos , size_t len , unsigned int flags )
436
419
{
437
- struct fd real ;
420
+ struct file * realfile ;
438
421
struct inode * inode = file_inode (out );
439
422
ssize_t ret ;
440
423
struct backing_file_ctx ctx = {
@@ -447,16 +430,15 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out,
447
430
/* Update mode */
448
431
ovl_copyattr (inode );
449
432
450
- ret = ovl_real_fdget (out , & real );
451
- if (ret )
433
+ realfile = ovl_real_file (out );
434
+ ret = PTR_ERR (realfile );
435
+ if (IS_ERR (realfile ))
452
436
goto out_unlock ;
453
437
454
438
init_sync_kiocb (& iocb , out );
455
439
iocb .ki_pos = * ppos ;
456
- ret = backing_file_splice_write (pipe , fd_file ( real ) , & iocb , len , flags , & ctx );
440
+ ret = backing_file_splice_write (pipe , realfile , & iocb , len , flags , & ctx );
457
441
* ppos = iocb .ki_pos ;
458
- fdput (real );
459
-
460
442
461
443
out_unlock :
462
444
inode_unlock (inode );
@@ -508,7 +490,7 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
508
490
static long ovl_fallocate (struct file * file , int mode , loff_t offset , loff_t len )
509
491
{
510
492
struct inode * inode = file_inode (file );
511
- struct fd real ;
493
+ struct file * realfile ;
512
494
const struct cred * old_cred ;
513
495
int ret ;
514
496
@@ -519,19 +501,18 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
519
501
if (ret )
520
502
goto out_unlock ;
521
503
522
- ret = ovl_real_fdget (file , & real );
523
- if (ret )
504
+ realfile = ovl_real_file (file );
505
+ ret = PTR_ERR (realfile );
506
+ if (IS_ERR (realfile ))
524
507
goto out_unlock ;
525
508
526
509
old_cred = ovl_override_creds (file_inode (file )-> i_sb );
527
- ret = vfs_fallocate (fd_file ( real ) , mode , offset , len );
510
+ ret = vfs_fallocate (realfile , mode , offset , len );
528
511
ovl_revert_creds (old_cred );
529
512
530
513
/* Update size */
531
514
ovl_file_modified (file );
532
515
533
- fdput (real );
534
-
535
516
out_unlock :
536
517
inode_unlock (inode );
537
518
@@ -540,20 +521,18 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
540
521
541
522
static int ovl_fadvise (struct file * file , loff_t offset , loff_t len , int advice )
542
523
{
543
- struct fd real ;
524
+ struct file * realfile ;
544
525
const struct cred * old_cred ;
545
526
int ret ;
546
527
547
- ret = ovl_real_fdget (file , & real );
548
- if (ret )
549
- return ret ;
528
+ realfile = ovl_real_file (file );
529
+ if (IS_ERR ( realfile ) )
530
+ return PTR_ERR ( realfile ) ;
550
531
551
532
old_cred = ovl_override_creds (file_inode (file )-> i_sb );
552
- ret = vfs_fadvise (fd_file ( real ) , offset , len , advice );
533
+ ret = vfs_fadvise (realfile , offset , len , advice );
553
534
ovl_revert_creds (old_cred );
554
535
555
- fdput (real );
556
-
557
536
return ret ;
558
537
}
559
538
@@ -568,7 +547,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
568
547
loff_t len , unsigned int flags , enum ovl_copyop op )
569
548
{
570
549
struct inode * inode_out = file_inode (file_out );
571
- struct fd real_in , real_out ;
550
+ struct file * realfile_in , * realfile_out ;
572
551
const struct cred * old_cred ;
573
552
loff_t ret ;
574
553
@@ -581,31 +560,31 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
581
560
goto out_unlock ;
582
561
}
583
562
584
- ret = ovl_real_fdget (file_out , & real_out );
585
- if (ret )
563
+ realfile_out = ovl_real_file (file_out );
564
+ ret = PTR_ERR (realfile_out );
565
+ if (IS_ERR (realfile_out ))
586
566
goto out_unlock ;
587
567
588
- ret = ovl_real_fdget (file_in , & real_in );
589
- if ( ret ) {
590
- fdput ( real_out );
568
+ realfile_in = ovl_real_file (file_in );
569
+ ret = PTR_ERR ( realfile_in );
570
+ if ( IS_ERR ( realfile_in ))
591
571
goto out_unlock ;
592
- }
593
572
594
573
old_cred = ovl_override_creds (file_inode (file_out )-> i_sb );
595
574
switch (op ) {
596
575
case OVL_COPY :
597
- ret = vfs_copy_file_range (fd_file ( real_in ) , pos_in ,
598
- fd_file ( real_out ) , pos_out , len , flags );
576
+ ret = vfs_copy_file_range (realfile_in , pos_in ,
577
+ realfile_out , pos_out , len , flags );
599
578
break ;
600
579
601
580
case OVL_CLONE :
602
- ret = vfs_clone_file_range (fd_file ( real_in ) , pos_in ,
603
- fd_file ( real_out ) , pos_out , len , flags );
581
+ ret = vfs_clone_file_range (realfile_in , pos_in ,
582
+ realfile_out , pos_out , len , flags );
604
583
break ;
605
584
606
585
case OVL_DEDUPE :
607
- ret = vfs_dedupe_file_range_one (fd_file ( real_in ) , pos_in ,
608
- fd_file ( real_out ) , pos_out , len ,
586
+ ret = vfs_dedupe_file_range_one (realfile_in , pos_in ,
587
+ realfile_out , pos_out , len ,
609
588
flags );
610
589
break ;
611
590
}
@@ -614,9 +593,6 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
614
593
/* Update size */
615
594
ovl_file_modified (file_out );
616
595
617
- fdput (real_in );
618
- fdput (real_out );
619
-
620
596
out_unlock :
621
597
inode_unlock (inode_out );
622
598
@@ -660,20 +636,19 @@ static loff_t ovl_remap_file_range(struct file *file_in, loff_t pos_in,
660
636
661
637
static int ovl_flush (struct file * file , fl_owner_t id )
662
638
{
663
- struct fd real ;
639
+ struct file * realfile ;
664
640
const struct cred * old_cred ;
665
- int err ;
641
+ int err = 0 ;
666
642
667
- err = ovl_real_fdget (file , & real );
668
- if (err )
669
- return err ;
643
+ realfile = ovl_real_file (file );
644
+ if (IS_ERR ( realfile ) )
645
+ return PTR_ERR ( realfile ) ;
670
646
671
- if (fd_file ( real ) -> f_op -> flush ) {
647
+ if (realfile -> f_op -> flush ) {
672
648
old_cred = ovl_override_creds (file_inode (file )-> i_sb );
673
- err = fd_file ( real ) -> f_op -> flush (fd_file ( real ) , id );
649
+ err = realfile -> f_op -> flush (realfile , id );
674
650
ovl_revert_creds (old_cred );
675
651
}
676
- fdput (real );
677
652
678
653
return err ;
679
654
}
0 commit comments