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