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, and the FL_EXISTS flag they will indicate
whether or not any locks were actually freed by returning 0 or -ENOENT.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

+17 -2
+16 -2
fs/locks.c
··· 725 725 /* Try to create a FLOCK lock on filp. We always insert new FLOCK locks 726 726 * at the head of the list, but that's secret knowledge known only to 727 727 * flock_lock_file and posix_lock_file. 728 + * 729 + * Note that if called with an FL_EXISTS argument, the caller may determine 730 + * whether or not a lock was successfully freed by testing the return 731 + * value for -ENOENT. 728 732 */ 729 733 static int flock_lock_file(struct file *filp, struct file_lock *request) 730 734 { ··· 754 750 break; 755 751 } 756 752 757 - if (request->fl_type == F_UNLCK) 753 + if (request->fl_type == F_UNLCK) { 754 + if ((request->fl_flags & FL_EXISTS) && !found) 755 + error = -ENOENT; 758 756 goto out; 757 + } 759 758 760 759 error = -ENOMEM; 761 760 new_fl = locks_alloc_lock(); ··· 955 948 956 949 error = 0; 957 950 if (!added) { 958 - if (request->fl_type == F_UNLCK) 951 + if (request->fl_type == F_UNLCK) { 952 + if (request->fl_flags & FL_EXISTS) 953 + error = -ENOENT; 959 954 goto out; 955 + } 960 956 961 957 if (!new_fl) { 962 958 error = -ENOLCK; ··· 1006 996 * Add a POSIX style lock to a file. 1007 997 * We merge adjacent & overlapping locks whenever possible. 1008 998 * POSIX locks are sorted by owner task, then by starting address 999 + * 1000 + * Note that if called with an FL_EXISTS argument, the caller may determine 1001 + * whether or not a lock was successfully freed by testing the return 1002 + * value for -ENOENT. 1009 1003 */ 1010 1004 int posix_lock_file(struct file *filp, struct file_lock *fl) 1011 1005 {
+1
include/linux/fs.h
··· 716 716 #define FL_POSIX 1 717 717 #define FL_FLOCK 2 718 718 #define FL_ACCESS 8 /* not trying to lock, just looking */ 719 + #define FL_EXISTS 16 /* when unlocking, test for existence */ 719 720 #define FL_LEASE 32 /* lease held on this file */ 720 721 #define FL_CLOSE 64 /* unlock on close */ 721 722 #define FL_SLEEP 128 /* A blocking lock */