@@ -195,16 +195,6 @@ static struct file *ovl_real_file(const struct file *file)
195195 return ovl_real_file_path (file , & realpath );
196196}
197197
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-
208198static int ovl_open (struct inode * inode , struct file * file )
209199{
210200 struct dentry * dentry = file_dentry (file );
@@ -253,7 +243,7 @@ static int ovl_release(struct inode *inode, struct file *file)
253243static loff_t ovl_llseek (struct file * file , loff_t offset , int whence )
254244{
255245 struct inode * inode = file_inode (file );
256- struct fd real ;
246+ struct file * realfile ;
257247 const struct cred * old_cred ;
258248 loff_t ret ;
259249
@@ -269,9 +259,9 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence)
269259 return vfs_setpos (file , 0 , 0 );
270260 }
271261
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 ) ;
275265
276266 /*
277267 * 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)
281271 * files, so we use the real file to perform seeks.
282272 */
283273 ovl_inode_lock (inode );
284- fd_file ( real ) -> f_pos = file -> f_pos ;
274+ realfile -> f_pos = file -> f_pos ;
285275
286276 old_cred = ovl_override_creds (inode -> i_sb );
287- ret = vfs_llseek (fd_file ( real ) , offset , whence );
277+ ret = vfs_llseek (realfile , offset , whence );
288278 ovl_revert_creds (old_cred );
289279
290- file -> f_pos = fd_file ( real ) -> f_pos ;
280+ file -> f_pos = realfile -> f_pos ;
291281 ovl_inode_unlock (inode );
292282
293- fdput (real );
294-
295283 return ret ;
296284}
297285
@@ -337,8 +325,7 @@ static void ovl_file_accessed(struct file *file)
337325static ssize_t ovl_read_iter (struct kiocb * iocb , struct iov_iter * iter )
338326{
339327 struct file * file = iocb -> ki_filp ;
340- struct fd real ;
341- ssize_t ret ;
328+ struct file * realfile ;
342329 struct backing_file_ctx ctx = {
343330 .cred = ovl_creds (file_inode (file )-> i_sb ),
344331 .accessed = ovl_file_accessed ,
@@ -347,22 +334,19 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
347334 if (!iov_iter_count (iter ))
348335 return 0 ;
349336
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 );
357340
358- return ret ;
341+ return backing_file_read_iter (realfile , iter , iocb , iocb -> ki_flags ,
342+ & ctx );
359343}
360344
361345static ssize_t ovl_write_iter (struct kiocb * iocb , struct iov_iter * iter )
362346{
363347 struct file * file = iocb -> ki_filp ;
364348 struct inode * inode = file_inode (file );
365- struct fd real ;
349+ struct file * realfile ;
366350 ssize_t ret ;
367351 int ifl = iocb -> ki_flags ;
368352 struct backing_file_ctx ctx = {
@@ -377,8 +361,9 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
377361 /* Update mode */
378362 ovl_copyattr (inode );
379363
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 ))
382367 goto out_unlock ;
383368
384369 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)
389374 * this property in case it is set by the issuer.
390375 */
391376 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 );
394378
395379out_unlock :
396380 inode_unlock (inode );
@@ -402,39 +386,38 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos,
402386 struct pipe_inode_info * pipe , size_t len ,
403387 unsigned int flags )
404388{
405- struct fd real ;
389+ struct file * realfile ;
406390 ssize_t ret ;
407391 struct backing_file_ctx ctx = {
408392 .cred = ovl_creds (file_inode (in )-> i_sb ),
409393 .accessed = ovl_file_accessed ,
410394 };
411395 struct kiocb iocb ;
412396
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 ) ;
416400
417401 init_sync_kiocb (& iocb , in );
418402 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 );
420404 * ppos = iocb .ki_pos ;
421- fdput (real );
422405
423406 return ret ;
424407}
425408
426409/*
427410 * Calling iter_file_splice_write() directly from overlay's f_op may deadlock
428411 * 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().
430413 *
431414 * So do everything ovl_write_iter() does and call iter_file_splice_write() on
432415 * the real file.
433416 */
434417static ssize_t ovl_splice_write (struct pipe_inode_info * pipe , struct file * out ,
435418 loff_t * ppos , size_t len , unsigned int flags )
436419{
437- struct fd real ;
420+ struct file * realfile ;
438421 struct inode * inode = file_inode (out );
439422 ssize_t ret ;
440423 struct backing_file_ctx ctx = {
@@ -447,16 +430,15 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out,
447430 /* Update mode */
448431 ovl_copyattr (inode );
449432
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 ))
452436 goto out_unlock ;
453437
454438 init_sync_kiocb (& iocb , out );
455439 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 );
457441 * ppos = iocb .ki_pos ;
458- fdput (real );
459-
460442
461443out_unlock :
462444 inode_unlock (inode );
@@ -508,7 +490,7 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
508490static long ovl_fallocate (struct file * file , int mode , loff_t offset , loff_t len )
509491{
510492 struct inode * inode = file_inode (file );
511- struct fd real ;
493+ struct file * realfile ;
512494 const struct cred * old_cred ;
513495 int ret ;
514496
@@ -519,19 +501,18 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
519501 if (ret )
520502 goto out_unlock ;
521503
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 ))
524507 goto out_unlock ;
525508
526509 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 );
528511 ovl_revert_creds (old_cred );
529512
530513 /* Update size */
531514 ovl_file_modified (file );
532515
533- fdput (real );
534-
535516out_unlock :
536517 inode_unlock (inode );
537518
@@ -540,20 +521,18 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
540521
541522static int ovl_fadvise (struct file * file , loff_t offset , loff_t len , int advice )
542523{
543- struct fd real ;
524+ struct file * realfile ;
544525 const struct cred * old_cred ;
545526 int ret ;
546527
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 ) ;
550531
551532 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 );
553534 ovl_revert_creds (old_cred );
554535
555- fdput (real );
556-
557536 return ret ;
558537}
559538
@@ -568,7 +547,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
568547 loff_t len , unsigned int flags , enum ovl_copyop op )
569548{
570549 struct inode * inode_out = file_inode (file_out );
571- struct fd real_in , real_out ;
550+ struct file * realfile_in , * realfile_out ;
572551 const struct cred * old_cred ;
573552 loff_t ret ;
574553
@@ -581,31 +560,31 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
581560 goto out_unlock ;
582561 }
583562
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 ))
586566 goto out_unlock ;
587567
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 ))
591571 goto out_unlock ;
592- }
593572
594573 old_cred = ovl_override_creds (file_inode (file_out )-> i_sb );
595574 switch (op ) {
596575 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 );
599578 break ;
600579
601580 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 );
604583 break ;
605584
606585 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 ,
609588 flags );
610589 break ;
611590 }
@@ -614,9 +593,6 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
614593 /* Update size */
615594 ovl_file_modified (file_out );
616595
617- fdput (real_in );
618- fdput (real_out );
619-
620596out_unlock :
621597 inode_unlock (inode_out );
622598
@@ -660,20 +636,19 @@ static loff_t ovl_remap_file_range(struct file *file_in, loff_t pos_in,
660636
661637static int ovl_flush (struct file * file , fl_owner_t id )
662638{
663- struct fd real ;
639+ struct file * realfile ;
664640 const struct cred * old_cred ;
665- int err ;
641+ int err = 0 ;
666642
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 ) ;
670646
671- if (fd_file ( real ) -> f_op -> flush ) {
647+ if (realfile -> f_op -> flush ) {
672648 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 );
674650 ovl_revert_creds (old_cred );
675651 }
676- fdput (real );
677652
678653 return err ;
679654}
0 commit comments