@@ -252,7 +252,9 @@ static int ovl_copy_up_file(struct ovl_fs *ofs, struct dentry *dentry,
252
252
return PTR_ERR (old_file );
253
253
254
254
/* Try to use clone_file_range to clone up within the same fs */
255
+ ovl_start_write (dentry );
255
256
cloned = do_clone_file_range (old_file , 0 , new_file , 0 , len , 0 );
257
+ ovl_end_write (dentry );
256
258
if (cloned == len )
257
259
goto out_fput ;
258
260
/* Couldn't clone, so now we try to copy the data */
@@ -287,8 +289,12 @@ static int ovl_copy_up_file(struct ovl_fs *ofs, struct dentry *dentry,
287
289
* it may not recognize all kind of holes and sometimes
288
290
* only skips partial of hole area. However, it will be
289
291
* enough for most of the use cases.
292
+ *
293
+ * We do not hold upper sb_writers throughout the loop to avert
294
+ * lockdep warning with llseek of lower file in nested overlay:
295
+ * - upper sb_writers
296
+ * -- lower ovl_inode_lock (ovl_llseek)
290
297
*/
291
-
292
298
if (skip_hole && data_pos < old_pos ) {
293
299
data_pos = vfs_llseek (old_file , old_pos , SEEK_DATA );
294
300
if (data_pos > old_pos ) {
@@ -303,9 +309,11 @@ static int ovl_copy_up_file(struct ovl_fs *ofs, struct dentry *dentry,
303
309
}
304
310
}
305
311
312
+ ovl_start_write (dentry );
306
313
bytes = do_splice_direct (old_file , & old_pos ,
307
314
new_file , & new_pos ,
308
315
this_len , SPLICE_F_MOVE );
316
+ ovl_end_write (dentry );
309
317
if (bytes <= 0 ) {
310
318
error = bytes ;
311
319
break ;
@@ -555,14 +563,16 @@ static int ovl_link_up(struct ovl_copy_up_ctx *c)
555
563
struct ovl_fs * ofs = OVL_FS (c -> dentry -> d_sb );
556
564
struct inode * udir = d_inode (upperdir );
557
565
566
+ ovl_start_write (c -> dentry );
567
+
558
568
/* Mark parent "impure" because it may now contain non-pure upper */
559
569
err = ovl_set_impure (c -> parent , upperdir );
560
570
if (err )
561
- return err ;
571
+ goto out ;
562
572
563
573
err = ovl_set_nlink_lower (c -> dentry );
564
574
if (err )
565
- return err ;
575
+ goto out ;
566
576
567
577
inode_lock_nested (udir , I_MUTEX_PARENT );
568
578
upper = ovl_lookup_upper (ofs , c -> dentry -> d_name .name , upperdir ,
@@ -581,10 +591,12 @@ static int ovl_link_up(struct ovl_copy_up_ctx *c)
581
591
}
582
592
inode_unlock (udir );
583
593
if (err )
584
- return err ;
594
+ goto out ;
585
595
586
596
err = ovl_set_nlink_upper (c -> dentry );
587
597
598
+ out :
599
+ ovl_end_write (c -> dentry );
588
600
return err ;
589
601
}
590
602
@@ -719,30 +731,41 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
719
731
.link = c -> link
720
732
};
721
733
722
- /* workdir and destdir could be the same when copying up to indexdir */
723
- err = - EIO ;
724
- if (lock_rename (c -> workdir , c -> destdir ) != NULL )
725
- goto unlock ;
726
-
727
734
err = ovl_prep_cu_creds (c -> dentry , & cc );
728
735
if (err )
729
- goto unlock ;
736
+ return err ;
730
737
738
+ ovl_start_write (c -> dentry );
739
+ inode_lock (wdir );
731
740
temp = ovl_create_temp (ofs , c -> workdir , & cattr );
741
+ inode_unlock (wdir );
742
+ ovl_end_write (c -> dentry );
732
743
ovl_revert_cu_creds (& cc );
733
744
734
- err = PTR_ERR (temp );
735
745
if (IS_ERR (temp ))
736
- goto unlock ;
746
+ return PTR_ERR ( temp ) ;
737
747
738
748
/*
739
749
* Copy up data first and then xattrs. Writing data after
740
750
* xattrs will remove security.capability xattr automatically.
741
751
*/
742
752
path .dentry = temp ;
743
753
err = ovl_copy_up_data (c , & path );
744
- if (err )
754
+ /*
755
+ * We cannot hold lock_rename() throughout this helper, because or
756
+ * lock ordering with sb_writers, which shouldn't be held when calling
757
+ * ovl_copy_up_data(), so lock workdir and destdir and make sure that
758
+ * temp wasn't moved before copy up completion or cleanup.
759
+ * If temp was moved, abort without the cleanup.
760
+ */
761
+ ovl_start_write (c -> dentry );
762
+ if (lock_rename (c -> workdir , c -> destdir ) != NULL ||
763
+ temp -> d_parent != c -> workdir ) {
764
+ err = - EIO ;
765
+ goto unlock ;
766
+ } else if (err ) {
745
767
goto cleanup ;
768
+ }
746
769
747
770
err = ovl_copy_up_metadata (c , temp );
748
771
if (err )
@@ -779,6 +802,7 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
779
802
ovl_set_flag (OVL_WHITEOUTS , inode );
780
803
unlock :
781
804
unlock_rename (c -> workdir , c -> destdir );
805
+ ovl_end_write (c -> dentry );
782
806
783
807
return err ;
784
808
@@ -802,9 +826,10 @@ static int ovl_copy_up_tmpfile(struct ovl_copy_up_ctx *c)
802
826
if (err )
803
827
return err ;
804
828
829
+ ovl_start_write (c -> dentry );
805
830
tmpfile = ovl_do_tmpfile (ofs , c -> workdir , c -> stat .mode );
831
+ ovl_end_write (c -> dentry );
806
832
ovl_revert_cu_creds (& cc );
807
-
808
833
if (IS_ERR (tmpfile ))
809
834
return PTR_ERR (tmpfile );
810
835
@@ -815,9 +840,11 @@ static int ovl_copy_up_tmpfile(struct ovl_copy_up_ctx *c)
815
840
goto out_fput ;
816
841
}
817
842
843
+ ovl_start_write (c -> dentry );
844
+
818
845
err = ovl_copy_up_metadata (c , temp );
819
846
if (err )
820
- goto out_fput ;
847
+ goto out ;
821
848
822
849
inode_lock_nested (udir , I_MUTEX_PARENT );
823
850
@@ -831,7 +858,7 @@ static int ovl_copy_up_tmpfile(struct ovl_copy_up_ctx *c)
831
858
inode_unlock (udir );
832
859
833
860
if (err )
834
- goto out_fput ;
861
+ goto out ;
835
862
836
863
if (c -> metacopy_digest )
837
864
ovl_set_flag (OVL_HAS_DIGEST , d_inode (c -> dentry ));
@@ -843,6 +870,8 @@ static int ovl_copy_up_tmpfile(struct ovl_copy_up_ctx *c)
843
870
ovl_set_upperdata (d_inode (c -> dentry ));
844
871
ovl_inode_update (d_inode (c -> dentry ), dget (temp ));
845
872
873
+ out :
874
+ ovl_end_write (c -> dentry );
846
875
out_fput :
847
876
fput (tmpfile );
848
877
return err ;
@@ -893,7 +922,9 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
893
922
* Mark parent "impure" because it may now contain non-pure
894
923
* upper
895
924
*/
925
+ ovl_start_write (c -> dentry );
896
926
err = ovl_set_impure (c -> parent , c -> destdir );
927
+ ovl_end_write (c -> dentry );
897
928
if (err )
898
929
return err ;
899
930
}
@@ -909,6 +940,7 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
909
940
if (c -> indexed )
910
941
ovl_set_flag (OVL_INDEX , d_inode (c -> dentry ));
911
942
943
+ ovl_start_write (c -> dentry );
912
944
if (to_index ) {
913
945
/* Initialize nlink for copy up of disconnected dentry */
914
946
err = ovl_set_nlink_upper (c -> dentry );
@@ -923,6 +955,7 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
923
955
ovl_dentry_set_upper_alias (c -> dentry );
924
956
ovl_dentry_update_reval (c -> dentry , ovl_dentry_upper (c -> dentry ));
925
957
}
958
+ ovl_end_write (c -> dentry );
926
959
927
960
out :
928
961
if (to_index )
@@ -1011,15 +1044,16 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)
1011
1044
* Writing to upper file will clear security.capability xattr. We
1012
1045
* don't want that to happen for normal copy-up operation.
1013
1046
*/
1047
+ ovl_start_write (c -> dentry );
1014
1048
if (capability ) {
1015
1049
err = ovl_do_setxattr (ofs , upperpath .dentry , XATTR_NAME_CAPS ,
1016
1050
capability , cap_size , 0 );
1017
- if (err )
1018
- goto out_free ;
1019
1051
}
1020
-
1021
-
1022
- err = ovl_removexattr (ofs , upperpath .dentry , OVL_XATTR_METACOPY );
1052
+ if (!err ) {
1053
+ err = ovl_removexattr (ofs , upperpath .dentry ,
1054
+ OVL_XATTR_METACOPY );
1055
+ }
1056
+ ovl_end_write (c -> dentry );
1023
1057
if (err )
1024
1058
goto out_free ;
1025
1059
0 commit comments