[PATCH] writeback: fix range handling
[linux-2.6-block.git] / fs / locks.c
index efad798824dc19913b7aace09dbee47b8c6ca6a7..69435c68c1ed7a1d95618e8864787174a23f92a0 100644 (file)
@@ -446,15 +446,14 @@ static struct lock_manager_operations lease_manager_ops = {
  */
 static int lease_init(struct file *filp, int type, struct file_lock *fl)
  {
+       if (assign_type(fl, type) != 0)
+               return -EINVAL;
+
        fl->fl_owner = current->files;
        fl->fl_pid = current->tgid;
 
        fl->fl_file = filp;
        fl->fl_flags = FL_LEASE;
-       if (assign_type(fl, type) != 0) {
-               locks_free_lock(fl);
-               return -EINVAL;
-       }
        fl->fl_start = 0;
        fl->fl_end = OFFSET_MAX;
        fl->fl_ops = NULL;
@@ -466,16 +465,19 @@ static int lease_init(struct file *filp, int type, struct file_lock *fl)
 static int lease_alloc(struct file *filp, int type, struct file_lock **flp)
 {
        struct file_lock *fl = locks_alloc_lock();
-       int error;
+       int error = -ENOMEM;
 
        if (fl == NULL)
-               return -ENOMEM;
+               goto out;
 
        error = lease_init(filp, type, fl);
-       if (error)
-               return error;
+       if (error) {
+               locks_free_lock(fl);
+               fl = NULL;
+       }
+out:
        *flp = fl;
-       return 0;
+       return error;
 }
 
 /* Check if two locks overlap each other.
@@ -753,6 +755,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
        if (request->fl_type == F_UNLCK)
                goto out;
 
+       error = -ENOMEM;
        new_fl = locks_alloc_lock();
        if (new_fl == NULL)
                goto out;
@@ -779,6 +782,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
        locks_copy_lock(new_fl, request);
        locks_insert_lock(&inode->i_flock, new_fl);
        new_fl = NULL;
+       error = 0;
 
 out:
        unlock_kernel();
@@ -1372,6 +1376,7 @@ static int __setlease(struct file *filp, long arg, struct file_lock **flp)
                goto out;
 
        if (my_before != NULL) {
+               *flp = *my_before;
                error = lease->fl_lmops->fl_change(my_before, arg);
                goto out;
        }
@@ -2201,63 +2206,6 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len)
 
 EXPORT_SYMBOL(lock_may_write);
 
-static inline void __steal_locks(struct file *file, fl_owner_t from)
-{
-       struct inode *inode = file->f_dentry->d_inode;
-       struct file_lock *fl = inode->i_flock;
-
-       while (fl) {
-               if (fl->fl_file == file && fl->fl_owner == from)
-                       fl->fl_owner = current->files;
-               fl = fl->fl_next;
-       }
-}
-
-/* When getting ready for executing a binary, we make sure that current
- * has a files_struct on its own. Before dropping the old files_struct,
- * we take over ownership of all locks for all file descriptors we own.
- * Note that we may accidentally steal a lock for a file that a sibling
- * has created since the unshare_files() call.
- */
-void steal_locks(fl_owner_t from)
-{
-       struct files_struct *files = current->files;
-       int i, j;
-       struct fdtable *fdt;
-
-       if (from == files)
-               return;
-
-       lock_kernel();
-       j = 0;
-
-       /*
-        * We are not taking a ref to the file structures, so
-        * we need to acquire ->file_lock.
-        */
-       spin_lock(&files->file_lock);
-       fdt = files_fdtable(files);
-       for (;;) {
-               unsigned long set;
-               i = j * __NFDBITS;
-               if (i >= fdt->max_fdset || i >= fdt->max_fds)
-                       break;
-               set = fdt->open_fds->fds_bits[j++];
-               while (set) {
-                       if (set & 1) {
-                               struct file *file = fdt->fd[i];
-                               if (file)
-                                       __steal_locks(file, from);
-                       }
-                       i++;
-                       set >>= 1;
-               }
-       }
-       spin_unlock(&files->file_lock);
-       unlock_kernel();
-}
-EXPORT_SYMBOL(steal_locks);
-
 static int __init filelock_init(void)
 {
        filelock_cache = kmem_cache_create("file_lock_cache",