From: Trond Myklebust VFS: Allow caller to determine if BSD or posix locks were actually freed Change posix_lock_file_conf(), and flock_lock_file() so that if called with an F_UNLCK argument, they will indicate whether or not any locks were actually freed by either setting or clearing request->fl_type. Signed-off-by: Trond Myklebust --- fs/locks.c | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index dda83d6..0f07353 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -725,6 +725,10 @@ EXPORT_SYMBOL(posix_locks_deadlock); /* Try to create a FLOCK lock on filp. We always insert new FLOCK locks * at the head of the list, but that's secret knowledge known only to * flock_lock_file and posix_lock_file. + * + * Note that if called with an F_UNLCK argument, the caller may determine + * whether or not a lock was successfully freed by testing the return + * value of request->fl_type */ static int flock_lock_file(struct file *filp, struct file_lock *request) { @@ -750,8 +754,11 @@ static int flock_lock_file(struct file * break; } - if (request->fl_type == F_UNLCK) + if (request->fl_type == F_UNLCK) { + if (!found) + request->fl_type = 0; goto out; + } new_fl = locks_alloc_lock(); if (new_fl == NULL) @@ -936,8 +943,10 @@ static int __posix_lock_file_conf(struct error = 0; if (!added) { - if (request->fl_type == F_UNLCK) + if (request->fl_type == F_UNLCK) { + request->fl_type = 0; goto out; + } locks_copy_lock(new_fl, request); locks_insert_lock(before, new_fl); new_fl = NULL; @@ -979,6 +988,10 @@ static int __posix_lock_file_conf(struct * Add a POSIX style lock to a file. * We merge adjacent & overlapping locks whenever possible. * POSIX locks are sorted by owner task, then by starting address + * + * Note that if called with an F_UNLCK argument, the caller may determine + * whether or not a lock was successfully freed by testing the return + * value of fl->fl_type */ int posix_lock_file(struct file *filp, struct file_lock *fl) {