Commit 48b3fb54 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

[PATCH] sleeping file locks

 - Add FL_SLEEP flag to indicate we intend to sleep and therefore desire
   to be placed on the block list.  Use it for POSIX & flock locks.
 - Remove locks_block_on.
 - Change posix_unblock_lock to eliminate a race that will appear once we
   don't use the BKL any more.
 - Update the comment for locks_same_owner() and rename it to
   posix_same_owner().
 - Change locks_mandatory_area() to allocate its lock on the stack and
   call posix_lock_file() instead of repeating that logic.
 - Rename the "caller" parameter to posix_lock_file() to "request"
   to better show that this is not to be inserted directly.
 - Redo some of the proc code a little.  Stop exposing kernel addresses
   to userspace (whoever thought _that_ was a good idea?!) and show how
   we should be printing the device name.  The last part is ifdeffed
   out to avoid breaking lslk.
 - Remove FL_BROKEN.  And there was much rejoicing.
parent af692bd6
...@@ -237,17 +237,8 @@ nlmsvc_delete_block(struct nlm_block *block, int unlock) ...@@ -237,17 +237,8 @@ nlmsvc_delete_block(struct nlm_block *block, int unlock)
/* Remove block from list */ /* Remove block from list */
nlmsvc_remove_block(block); nlmsvc_remove_block(block);
posix_unblock_lock(&file->f_file, fl);
/* If granted, unlock it, else remove from inode block list */ block->b_granted = 0;
if (unlock && block->b_granted) {
dprintk("lockd: deleting granted lock\n");
fl->fl_type = F_UNLCK;
posix_lock_file(&block->b_file->f_file, fl, 0);
block->b_granted = 0;
} else {
dprintk("lockd: unblocking blocked lock\n");
posix_unblock_lock(fl);
}
/* If the block is in the middle of a GRANT callback, /* If the block is in the middle of a GRANT callback,
* don't kill it yet. */ * don't kill it yet. */
...@@ -324,7 +315,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, ...@@ -324,7 +315,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
again: again:
if (!(conflock = posix_test_lock(&file->f_file, &lock->fl))) { if (!(conflock = posix_test_lock(&file->f_file, &lock->fl))) {
error = posix_lock_file(&file->f_file, &lock->fl, 0); error = posix_lock_file(&file->f_file, &lock->fl);
if (block) if (block)
nlmsvc_delete_block(block, 0); nlmsvc_delete_block(block, 0);
...@@ -428,7 +419,7 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock) ...@@ -428,7 +419,7 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
nlmsvc_cancel_blocked(file, lock); nlmsvc_cancel_blocked(file, lock);
lock->fl.fl_type = F_UNLCK; lock->fl.fl_type = F_UNLCK;
error = posix_lock_file(&file->f_file, &lock->fl, 0); error = posix_lock_file(&file->f_file, &lock->fl);
return (error < 0)? nlm_lck_denied_nolocks : nlm_granted; return (error < 0)? nlm_lck_denied_nolocks : nlm_granted;
} }
...@@ -532,7 +523,7 @@ nlmsvc_grant_blocked(struct nlm_block *block) ...@@ -532,7 +523,7 @@ nlmsvc_grant_blocked(struct nlm_block *block)
* following yields an error, this is most probably due to low * following yields an error, this is most probably due to low
* memory. Retry the lock in a few seconds. * memory. Retry the lock in a few seconds.
*/ */
if ((error = posix_lock_file(&file->f_file, &lock->fl, 0)) < 0) { if ((error = posix_lock_file(&file->f_file, &lock->fl)) < 0) {
printk(KERN_WARNING "lockd: unexpected error %d in %s!\n", printk(KERN_WARNING "lockd: unexpected error %d in %s!\n",
-error, __FUNCTION__); -error, __FUNCTION__);
nlmsvc_insert_block(block, 10 * HZ); nlmsvc_insert_block(block, 10 * HZ);
......
...@@ -176,7 +176,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, int action) ...@@ -176,7 +176,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, int action)
lock.fl_type = F_UNLCK; lock.fl_type = F_UNLCK;
lock.fl_start = 0; lock.fl_start = 0;
lock.fl_end = OFFSET_MAX; lock.fl_end = OFFSET_MAX;
if (posix_lock_file(&file->f_file, &lock, 0) < 0) { if (posix_lock_file(&file->f_file, &lock) < 0) {
printk("lockd: unlock failure in %s:%d\n", printk("lockd: unlock failure in %s:%d\n",
__FILE__, __LINE__); __FILE__, __LINE__);
return 1; return 1;
......
This diff is collapsed.
...@@ -526,10 +526,10 @@ extern int init_private_file(struct file *, struct dentry *, int); ...@@ -526,10 +526,10 @@ extern int init_private_file(struct file *, struct dentry *, int);
#define FL_POSIX 1 #define FL_POSIX 1
#define FL_FLOCK 2 #define FL_FLOCK 2
#define FL_BROKEN 4 /* broken flock() emulation */ #define FL_ACCESS 8 /* not trying to lock, just looking */
#define FL_ACCESS 8 /* for processes suspended by mandatory locking */
#define FL_LOCKD 16 /* lock held by rpc.lockd */ #define FL_LOCKD 16 /* lock held by rpc.lockd */
#define FL_LEASE 32 /* lease held on this file */ #define FL_LEASE 32 /* lease held on this file */
#define FL_SLEEP 128 /* A blocking lock */
/* /*
* The POSIX file lock owner is determined by * The POSIX file lock owner is determined by
...@@ -591,9 +591,9 @@ extern void locks_copy_lock(struct file_lock *, struct file_lock *); ...@@ -591,9 +591,9 @@ extern void locks_copy_lock(struct file_lock *, struct file_lock *);
extern void locks_remove_posix(struct file *, fl_owner_t); extern void locks_remove_posix(struct file *, fl_owner_t);
extern void locks_remove_flock(struct file *); extern void locks_remove_flock(struct file *);
extern struct file_lock *posix_test_lock(struct file *, struct file_lock *); extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
extern int posix_lock_file(struct file *, struct file_lock *, unsigned int); extern int posix_lock_file(struct file *, struct file_lock *);
extern void posix_block_lock(struct file_lock *, struct file_lock *); extern void posix_block_lock(struct file_lock *, struct file_lock *);
extern void posix_unblock_lock(struct file_lock *); extern void posix_unblock_lock(struct file *, struct file_lock *);
extern int posix_locks_deadlock(struct file_lock *, struct file_lock *); extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);
extern int __get_lease(struct inode *inode, unsigned int flags); extern int __get_lease(struct inode *inode, unsigned int flags);
extern time_t lease_get_mtime(struct inode *); extern time_t lease_get_mtime(struct inode *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment