@@ -681,21 +681,18 @@ static void locks_wake_up_blocks(struct file_lock *blocker)
681681}
682682
683683static void
684- locks_insert_lock_ctx (struct file_lock * fl , int * counter ,
685- struct list_head * before )
684+ locks_insert_lock_ctx (struct file_lock * fl , struct list_head * before )
686685{
687686 fl -> fl_nspid = get_pid (task_tgid (current ));
688687 list_add_tail (& fl -> fl_list , before );
689- ++ * counter ;
690688 locks_insert_global_locks (fl );
691689}
692690
693691static void
694- locks_unlink_lock_ctx (struct file_lock * fl , int * counter )
692+ locks_unlink_lock_ctx (struct file_lock * fl )
695693{
696694 locks_delete_global_locks (fl );
697695 list_del_init (& fl -> fl_list );
698- -- * counter ;
699696 if (fl -> fl_nspid ) {
700697 put_pid (fl -> fl_nspid );
701698 fl -> fl_nspid = NULL ;
@@ -704,10 +701,9 @@ locks_unlink_lock_ctx(struct file_lock *fl, int *counter)
704701}
705702
706703static void
707- locks_delete_lock_ctx (struct file_lock * fl , int * counter ,
708- struct list_head * dispose )
704+ locks_delete_lock_ctx (struct file_lock * fl , struct list_head * dispose )
709705{
710- locks_unlink_lock_ctx (fl , counter );
706+ locks_unlink_lock_ctx (fl );
711707 if (dispose )
712708 list_add (& fl -> fl_list , dispose );
713709 else
@@ -895,7 +891,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
895891 if (request -> fl_type == fl -> fl_type )
896892 goto out ;
897893 found = true;
898- locks_delete_lock_ctx (fl , & ctx -> flc_flock_cnt , & dispose );
894+ locks_delete_lock_ctx (fl , & dispose );
899895 break ;
900896 }
901897
@@ -905,16 +901,6 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
905901 goto out ;
906902 }
907903
908- /*
909- * If a higher-priority process was blocked on the old file lock,
910- * give it the opportunity to lock the file.
911- */
912- if (found ) {
913- spin_unlock (& ctx -> flc_lock );
914- cond_resched ();
915- spin_lock (& ctx -> flc_lock );
916- }
917-
918904find_conflict :
919905 list_for_each_entry (fl , & ctx -> flc_flock , fl_list ) {
920906 if (!flock_locks_conflict (request , fl ))
@@ -929,7 +915,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
929915 if (request -> fl_flags & FL_ACCESS )
930916 goto out ;
931917 locks_copy_lock (new_fl , request );
932- locks_insert_lock_ctx (new_fl , & ctx -> flc_flock_cnt , & ctx -> flc_flock );
918+ locks_insert_lock_ctx (new_fl , & ctx -> flc_flock );
933919 new_fl = NULL ;
934920 error = 0 ;
935921
@@ -1046,8 +1032,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
10461032 else
10471033 request -> fl_end = fl -> fl_end ;
10481034 if (added ) {
1049- locks_delete_lock_ctx (fl , & ctx -> flc_posix_cnt ,
1050- & dispose );
1035+ locks_delete_lock_ctx (fl , & dispose );
10511036 continue ;
10521037 }
10531038 request = fl ;
@@ -1076,8 +1061,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
10761061 * one (This may happen several times).
10771062 */
10781063 if (added ) {
1079- locks_delete_lock_ctx (fl ,
1080- & ctx -> flc_posix_cnt , & dispose );
1064+ locks_delete_lock_ctx (fl , & dispose );
10811065 continue ;
10821066 }
10831067 /*
@@ -1093,10 +1077,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
10931077 locks_copy_lock (new_fl , request );
10941078 request = new_fl ;
10951079 new_fl = NULL ;
1096- locks_insert_lock_ctx (request ,
1097- & ctx -> flc_posix_cnt , & fl -> fl_list );
1098- locks_delete_lock_ctx (fl ,
1099- & ctx -> flc_posix_cnt , & dispose );
1080+ locks_insert_lock_ctx (request , & fl -> fl_list );
1081+ locks_delete_lock_ctx (fl , & dispose );
11001082 added = true;
11011083 }
11021084 }
@@ -1124,8 +1106,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
11241106 goto out ;
11251107 }
11261108 locks_copy_lock (new_fl , request );
1127- locks_insert_lock_ctx (new_fl , & ctx -> flc_posix_cnt ,
1128- & fl -> fl_list ) ;
1109+ locks_insert_lock_ctx (new_fl , & fl -> fl_list );
1110+ fl = new_fl ;
11291111 new_fl = NULL ;
11301112 }
11311113 if (right ) {
@@ -1136,8 +1118,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
11361118 left = new_fl2 ;
11371119 new_fl2 = NULL ;
11381120 locks_copy_lock (left , right );
1139- locks_insert_lock_ctx (left , & ctx -> flc_posix_cnt ,
1140- & fl -> fl_list );
1121+ locks_insert_lock_ctx (left , & fl -> fl_list );
11411122 }
11421123 right -> fl_start = request -> fl_end + 1 ;
11431124 locks_wake_up_blocks (right );
@@ -1321,7 +1302,6 @@ static void lease_clear_pending(struct file_lock *fl, int arg)
13211302/* We already had a lease on this file; just change its type */
13221303int lease_modify (struct file_lock * fl , int arg , struct list_head * dispose )
13231304{
1324- struct file_lock_context * flctx ;
13251305 int error = assign_type (fl , arg );
13261306
13271307 if (error )
@@ -1331,15 +1311,14 @@ int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose)
13311311 if (arg == F_UNLCK ) {
13321312 struct file * filp = fl -> fl_file ;
13331313
1334- flctx = file_inode (filp )-> i_flctx ;
13351314 f_delown (filp );
13361315 filp -> f_owner .signum = 0 ;
13371316 fasync_helper (0 , fl -> fl_file , 0 , & fl -> fl_fasync );
13381317 if (fl -> fl_fasync != NULL ) {
13391318 printk (KERN_ERR "locks_delete_lock: fasync == %p\n" , fl -> fl_fasync );
13401319 fl -> fl_fasync = NULL ;
13411320 }
1342- locks_delete_lock_ctx (fl , & flctx -> flc_lease_cnt , dispose );
1321+ locks_delete_lock_ctx (fl , dispose );
13431322 }
13441323 return 0 ;
13451324}
@@ -1456,8 +1435,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
14561435 fl -> fl_downgrade_time = break_time ;
14571436 }
14581437 if (fl -> fl_lmops -> lm_break (fl ))
1459- locks_delete_lock_ctx (fl , & ctx -> flc_lease_cnt ,
1460- & dispose );
1438+ locks_delete_lock_ctx (fl , & dispose );
14611439 }
14621440
14631441 if (list_empty (& ctx -> flc_lease ))
@@ -1697,7 +1675,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
16971675 if (!leases_enable )
16981676 goto out ;
16991677
1700- locks_insert_lock_ctx (lease , & ctx -> flc_lease_cnt , & ctx -> flc_lease );
1678+ locks_insert_lock_ctx (lease , & ctx -> flc_lease );
17011679 /*
17021680 * The check in break_lease() is lockless. It's possible for another
17031681 * open to race in after we did the earlier check for a conflicting
@@ -1710,7 +1688,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
17101688 smp_mb ();
17111689 error = check_conflicting_open (dentry , arg , lease -> fl_flags );
17121690 if (error ) {
1713- locks_unlink_lock_ctx (lease , & ctx -> flc_lease_cnt );
1691+ locks_unlink_lock_ctx (lease );
17141692 goto out ;
17151693 }
17161694
@@ -2448,7 +2426,8 @@ locks_remove_lease(struct file *filp)
24482426
24492427 spin_lock (& ctx -> flc_lock );
24502428 list_for_each_entry_safe (fl , tmp , & ctx -> flc_lease , fl_list )
2451- lease_modify (fl , F_UNLCK , & dispose );
2429+ if (filp == fl -> fl_file )
2430+ lease_modify (fl , F_UNLCK , & dispose );
24522431 spin_unlock (& ctx -> flc_lock );
24532432 locks_dispose_list (& dispose );
24542433}
0 commit comments