Skip to content

Commit b84d49f

Browse files
author
Jeff Layton
committed
locks: don't reuse file_lock in __posix_lock_file
Currently in the case where a new file lock completely replaces the old one, we end up overwriting the existing lock with the new info. This means that we have to call fl_release_private inside i_lock. Change the code to instead copy the info to new_fl, insert that lock into the correct spot and then delete the old lock. In a later patch, we'll defer the freeing of the old lock until after the i_lock has been dropped. Acked-by: J. Bruce Fields <[email protected]> Signed-off-by: Jeff Layton <[email protected]>
1 parent 566709b commit b84d49f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

fs/locks.c

+14-11
Original file line numberDiff line numberDiff line change
@@ -1022,18 +1022,21 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
10221022
locks_delete_lock(before);
10231023
continue;
10241024
}
1025-
/* Replace the old lock with the new one.
1026-
* Wake up anybody waiting for the old one,
1027-
* as the change in lock type might satisfy
1028-
* their needs.
1025+
/*
1026+
* Replace the old lock with new_fl, and
1027+
* remove the old one. It's safe to do the
1028+
* insert here since we know that we won't be
1029+
* using new_fl later, and that the lock is
1030+
* just replacing an existing lock.
10291031
*/
1030-
locks_wake_up_blocks(fl);
1031-
fl->fl_start = request->fl_start;
1032-
fl->fl_end = request->fl_end;
1033-
fl->fl_type = request->fl_type;
1034-
locks_release_private(fl);
1035-
locks_copy_private(fl, request);
1036-
request = fl;
1032+
error = -ENOLCK;
1033+
if (!new_fl)
1034+
goto out;
1035+
locks_copy_lock(new_fl, request);
1036+
request = new_fl;
1037+
new_fl = NULL;
1038+
locks_delete_lock(before);
1039+
locks_insert_lock(before, request);
10371040
added = true;
10381041
}
10391042
}

0 commit comments

Comments
 (0)