aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2013-06-21 08:58:12 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-06-29 04:57:39 -0400
commit1cb360125966cb6cb594e414ea80a0154617b846 (patch)
treea11881df79dfb2b4ba707756e8e91f928b744f9f
parentd4f22d19dffed6d9b50de4123f66b91875464435 (diff)
locks: comment cleanups and clarifications
Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/locks.c21
-rw-r--r--include/linux/fs.h18
2 files changed, 31 insertions, 8 deletions
diff --git a/fs/locks.c b/fs/locks.c
index 804bb9e01a65..ddeab49fe2be 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -518,9 +518,10 @@ static void locks_insert_block(struct file_lock *blocker,
518 list_add(&waiter->fl_link, &blocked_list); 518 list_add(&waiter->fl_link, &blocked_list);
519} 519}
520 520
521/* Wake up processes blocked waiting for blocker. 521/*
522 * If told to wait then schedule the processes until the block list 522 * Wake up processes blocked waiting for blocker.
523 * is empty, otherwise empty the block list ourselves. 523 *
524 * Must be called with the file_lock_lock held!
524 */ 525 */
525static void locks_wake_up_blocks(struct file_lock *blocker) 526static void locks_wake_up_blocks(struct file_lock *blocker)
526{ 527{
@@ -806,6 +807,11 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
806 } 807 }
807 808
808 lock_flocks(); 809 lock_flocks();
810 /*
811 * New lock request. Walk all POSIX locks and look for conflicts. If
812 * there are any, either return error or put the request on the
813 * blocker's list of waiters and the global blocked_list.
814 */
809 if (request->fl_type != F_UNLCK) { 815 if (request->fl_type != F_UNLCK) {
810 for_each_lock(inode, before) { 816 for_each_lock(inode, before) {
811 fl = *before; 817 fl = *before;
@@ -844,7 +850,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
844 before = &fl->fl_next; 850 before = &fl->fl_next;
845 } 851 }
846 852
847 /* Process locks with this owner. */ 853 /* Process locks with this owner. */
848 while ((fl = *before) && posix_same_owner(request, fl)) { 854 while ((fl = *before) && posix_same_owner(request, fl)) {
849 /* Detect adjacent or overlapping regions (if same lock type) 855 /* Detect adjacent or overlapping regions (if same lock type)
850 */ 856 */
@@ -930,10 +936,9 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
930 } 936 }
931 937
932 /* 938 /*
933 * The above code only modifies existing locks in case of 939 * The above code only modifies existing locks in case of merging or
934 * merging or replacing. If new lock(s) need to be inserted 940 * replacing. If new lock(s) need to be inserted all modifications are
935 * all modifications are done bellow this, so it's safe yet to 941 * done below this, so it's safe yet to bail out.
936 * bail out.
937 */ 942 */
938 error = -ENOLCK; /* "no luck" */ 943 error = -ENOLCK; /* "no luck" */
939 if (right && left == right && !new_fl2) 944 if (right && left == right && !new_fl2)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6cfc9a29a783..ed9fdaaf3223 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -926,6 +926,24 @@ int locks_in_grace(struct net *);
926/* that will die - we need it for nfs_lock_info */ 926/* that will die - we need it for nfs_lock_info */
927#include <linux/nfs_fs_i.h> 927#include <linux/nfs_fs_i.h>
928 928
929/*
930 * struct file_lock represents a generic "file lock". It's used to represent
931 * POSIX byte range locks, BSD (flock) locks, and leases. It's important to
932 * note that the same struct is used to represent both a request for a lock and
933 * the lock itself, but the same object is never used for both.
934 *
935 * FIXME: should we create a separate "struct lock_request" to help distinguish
936 * these two uses?
937 *
938 * The i_flock list is ordered by:
939 *
940 * 1) lock type -- FL_LEASEs first, then FL_FLOCK, and finally FL_POSIX
941 * 2) lock owner
942 * 3) lock range start
943 * 4) lock range end
944 *
945 * Obviously, the last two criteria only matter for POSIX locks.
946 */
929struct file_lock { 947struct file_lock {
930 struct file_lock *fl_next; /* singly linked list for this inode */ 948 struct file_lock *fl_next; /* singly linked list for this inode */
931 struct list_head fl_link; /* doubly linked list of all locks */ 949 struct list_head fl_link; /* doubly linked list of all locks */