diff options
| author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2006-07-05 13:19:25 -0400 | 
|---|---|---|
| committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2006-07-05 13:19:25 -0400 | 
| commit | 72dbac37e3a0acf8e8f07fc65e34e83de83e0b28 (patch) | |
| tree | 4f70bea9d6e8098c13a8cc89806a1e569737ad13 /fs/locks.c | |
| parent | 4e0641a7ad98fca5646a6be17605bc80f6c4ebde (diff) | |
| parent | 01c3b861cd77b28565a2d18c7caa3ce7f938e35c (diff) | |
Merge branch 'locks'
Diffstat (limited to 'fs/locks.c')
| -rw-r--r-- | fs/locks.c | 23 | 
1 files changed, 21 insertions, 2 deletions
diff --git a/fs/locks.c b/fs/locks.c index 1ad29c9b6252..b0b41a64e10b 100644 --- a/fs/locks.c +++ b/fs/locks.c  | |||
| @@ -725,6 +725,10 @@ next_task: | |||
| 725 | /* Try to create a FLOCK lock on filp. We always insert new FLOCK locks | 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 | 726 | * at the head of the list, but that's secret knowledge known only to | 
| 727 | * flock_lock_file and posix_lock_file. | 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 | static int flock_lock_file(struct file *filp, struct file_lock *request) | 733 | static int flock_lock_file(struct file *filp, struct file_lock *request) | 
| 730 | { | 734 | { | 
| @@ -735,6 +739,8 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) | |||
| 735 | int found = 0; | 739 | int found = 0; | 
| 736 | 740 | ||
| 737 | lock_kernel(); | 741 | lock_kernel(); | 
| 742 | if (request->fl_flags & FL_ACCESS) | ||
| 743 | goto find_conflict; | ||
| 738 | for_each_lock(inode, before) { | 744 | for_each_lock(inode, before) { | 
| 739 | struct file_lock *fl = *before; | 745 | struct file_lock *fl = *before; | 
| 740 | if (IS_POSIX(fl)) | 746 | if (IS_POSIX(fl)) | 
| @@ -750,8 +756,11 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) | |||
| 750 | break; | 756 | break; | 
| 751 | } | 757 | } | 
| 752 | 758 | ||
| 753 | if (request->fl_type == F_UNLCK) | 759 | if (request->fl_type == F_UNLCK) { | 
| 760 | if ((request->fl_flags & FL_EXISTS) && !found) | ||
| 761 | error = -ENOENT; | ||
| 754 | goto out; | 762 | goto out; | 
| 763 | } | ||
| 755 | 764 | ||
| 756 | error = -ENOMEM; | 765 | error = -ENOMEM; | 
| 757 | new_fl = locks_alloc_lock(); | 766 | new_fl = locks_alloc_lock(); | 
| @@ -764,6 +773,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) | |||
| 764 | if (found) | 773 | if (found) | 
| 765 | cond_resched(); | 774 | cond_resched(); | 
| 766 | 775 | ||
| 776 | find_conflict: | ||
| 767 | for_each_lock(inode, before) { | 777 | for_each_lock(inode, before) { | 
| 768 | struct file_lock *fl = *before; | 778 | struct file_lock *fl = *before; | 
| 769 | if (IS_POSIX(fl)) | 779 | if (IS_POSIX(fl)) | 
| @@ -777,6 +787,8 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) | |||
| 777 | locks_insert_block(fl, request); | 787 | locks_insert_block(fl, request); | 
| 778 | goto out; | 788 | goto out; | 
| 779 | } | 789 | } | 
| 790 | if (request->fl_flags & FL_ACCESS) | ||
| 791 | goto out; | ||
| 780 | locks_copy_lock(new_fl, request); | 792 | locks_copy_lock(new_fl, request); | 
| 781 | locks_insert_lock(&inode->i_flock, new_fl); | 793 | locks_insert_lock(&inode->i_flock, new_fl); | 
| 782 | new_fl = NULL; | 794 | new_fl = NULL; | 
| @@ -948,8 +960,11 @@ static int __posix_lock_file_conf(struct inode *inode, struct file_lock *request | |||
| 948 | 960 | ||
| 949 | error = 0; | 961 | error = 0; | 
| 950 | if (!added) { | 962 | if (!added) { | 
| 951 | if (request->fl_type == F_UNLCK) | 963 | if (request->fl_type == F_UNLCK) { | 
| 964 | if (request->fl_flags & FL_EXISTS) | ||
| 965 | error = -ENOENT; | ||
| 952 | goto out; | 966 | goto out; | 
| 967 | } | ||
| 953 | 968 | ||
| 954 | if (!new_fl) { | 969 | if (!new_fl) { | 
| 955 | error = -ENOLCK; | 970 | error = -ENOLCK; | 
| @@ -996,6 +1011,10 @@ static int __posix_lock_file_conf(struct inode *inode, struct file_lock *request | |||
| 996 | * Add a POSIX style lock to a file. | 1011 | * Add a POSIX style lock to a file. | 
| 997 | * We merge adjacent & overlapping locks whenever possible. | 1012 | * We merge adjacent & overlapping locks whenever possible. | 
| 998 | * POSIX locks are sorted by owner task, then by starting address | 1013 | * POSIX locks are sorted by owner task, then by starting address | 
| 1014 | * | ||
| 1015 | * Note that if called with an FL_EXISTS argument, the caller may determine | ||
| 1016 | * whether or not a lock was successfully freed by testing the return | ||
| 1017 | * value for -ENOENT. | ||
| 999 | */ | 1018 | */ | 
| 1000 | int posix_lock_file(struct file *filp, struct file_lock *fl) | 1019 | int posix_lock_file(struct file *filp, struct file_lock *fl) | 
| 1001 | { | 1020 | { | 
