]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - fs/locks.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/lethal/sh-2.6
[mv-sheeva.git] / fs / locks.c
index 242328e17f32e9961310f5403d3aeba34189ed16..431a8b871fcef03ea098f8d8ac8f8602a2d33f66 100644 (file)
@@ -203,10 +203,6 @@ static void init_once(void *foo, struct kmem_cache *cache, unsigned long flags)
 {
        struct file_lock *lock = (struct file_lock *) foo;
 
-       if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) !=
-                                       SLAB_CTOR_CONSTRUCTOR)
-               return;
-
        locks_init_lock(lock);
 }
 
@@ -670,7 +666,6 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
 {
        struct file_lock *cfl;
 
-       fl->fl_type = F_UNLCK;
        lock_kernel();
        for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) {
                if (!IS_POSIX(cfl))
@@ -682,7 +677,8 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
                __locks_copy_lock(fl, cfl);
                unlock_kernel();
                return 1;
-       }
+       } else
+               fl->fl_type = F_UNLCK;
        unlock_kernel();
        return 0;
 }
@@ -1633,6 +1629,7 @@ static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)
        flock->l_len = fl->fl_end == OFFSET_MAX ? 0 :
                fl->fl_end - fl->fl_start + 1;
        flock->l_whence = 0;
+       flock->l_type = fl->fl_type;
        return 0;
 }
 
@@ -1698,6 +1695,25 @@ out:
  * If the filesystem defines a private ->lock() method, then @conf will
  * be left unchanged; so a caller that cares should initialize it to
  * some acceptable default.
+ *
+ * To avoid blocking kernel daemons, such as lockd, that need to acquire POSIX
+ * locks, the ->lock() interface may return asynchronously, before the lock has
+ * been granted or denied by the underlying filesystem, if (and only if)
+ * fl_grant is set. Callers expecting ->lock() to return asynchronously
+ * will only use F_SETLK, not F_SETLKW; they will set FL_SLEEP if (and only if)
+ * the request is for a blocking lock. When ->lock() does return asynchronously,
+ * it must return -EINPROGRESS, and call ->fl_grant() when the lock
+ * request completes.
+ * If the request is for non-blocking lock the file system should return
+ * -EINPROGRESS then try to get the lock and call the callback routine with
+ * the result. If the request timed out the callback routine will return a
+ * nonzero return code and the file system should release the lock. The file
+ * system is also responsible to keep a corresponding posix lock when it
+ * grants a lock so the VFS can find out which locks are locally held and do
+ * the correct lock cleanup when required.
+ * The underlying filesystem must not drop the kernel lock or call
+ * ->fl_grant() before returning to the caller with a -EINPROGRESS
+ * return code.
  */
 int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf)
 {