vserver 2.0 rc7
[linux-2.6.git] / fs / locks.c
index 3098b3f..5cfa965 100644 (file)
@@ -280,7 +280,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock,
        fl->fl_type = type;
        fl->fl_end = OFFSET_MAX;
 
-       /* check agains file xid maybe ? */
+       /* check against file xid maybe ? */
        fl->fl_xid = vx_current_xid();
        vx_locks_inc(fl);
        
@@ -418,9 +418,16 @@ static void lease_release_private_callback(struct file_lock *fl)
        fl->fl_file->f_owner.signum = 0;
 }
 
-struct lock_manager_operations lease_manager_ops = {
+static int lease_mylease_callback(struct file_lock *fl, struct file_lock *try)
+{
+       return fl->fl_file == try->fl_file;
+}
+
+static struct lock_manager_operations lease_manager_ops = {
        .fl_break = lease_break_callback,
        .fl_release_private = lease_release_private_callback,
+       .fl_mylease = lease_mylease_callback,
+       .fl_change = lease_modify,
 };
 
 /*
@@ -1076,7 +1083,7 @@ int locks_mandatory_area(int read_write, struct inode *inode,
 EXPORT_SYMBOL(locks_mandatory_area);
 
 /* We already had a lease on this file; just change its type */
-static int lease_modify(struct file_lock **before, int arg)
+int lease_modify(struct file_lock **before, int arg)
 {
        struct file_lock *fl = *before;
        int error = assign_type(fl, arg);
@@ -1089,6 +1096,8 @@ static int lease_modify(struct file_lock **before, int arg)
        return 0;
 }
 
+EXPORT_SYMBOL(lease_modify);
+
 static void time_out_leases(struct inode *inode)
 {
        struct file_lock **before;
@@ -1108,24 +1117,6 @@ static void time_out_leases(struct inode *inode)
        }
 }
 
- /**
-*      remove_lease - let time_out_leases remove the lease.
-*      @@file_lock: the lease to remove
-*/
-void remove_lease(struct file_lock *fl)
-{
-       lock_kernel();
-       if (!fl || !IS_LEASE(fl))
-               goto out;
-       fl->fl_type = F_UNLCK | F_INPROGRESS;
-       fl->fl_break_time = jiffies - 10;
-       time_out_leases(fl->fl_file->f_dentry->d_inode);
-out:
-       unlock_kernel();
-}
-
-EXPORT_SYMBOL(remove_lease);
-
 /**
  *     __break_lease   -       revoke all outstanding leases on file
  *     @inode: the inode of the file to return
@@ -1190,10 +1181,8 @@ int __break_lease(struct inode *inode, unsigned int mode)
                if (fl->fl_type != future) {
                        fl->fl_type = future;
                        fl->fl_break_time = break_time;
-                       if (fl->fl_lmops && fl->fl_lmops->fl_break)
-                               fl->fl_lmops->fl_break(fl);
-                       else    /* lease must have lmops break callback */
-                               BUG();
+                       /* lease must have lmops break callback */
+                       fl->fl_lmops->fl_break(fl);
                }
        }
 
@@ -1303,7 +1292,7 @@ int fcntl_getlease(struct file *filp)
  *
  *     Called with kernel lock held.
  */
-int __setlease(struct file *filp, long arg, struct file_lock **flp)
+static int __setlease(struct file *filp, long arg, struct file_lock **flp)
 {
        struct file_lock *fl, **before, **my_before = NULL, *lease = *flp;
        struct dentry *dentry = filp->f_dentry;
@@ -1335,7 +1324,7 @@ int __setlease(struct file *filp, long arg, struct file_lock **flp)
        for (before = &inode->i_flock;
                        ((fl = *before) != NULL) && IS_LEASE(fl);
                        before = &fl->fl_next) {
-               if (fl->fl_file == filp)
+               if (lease->fl_lmops->fl_mylease(fl, lease))
                        my_before = before;
                else if (fl->fl_type == (F_INPROGRESS | F_UNLCK))
                        /*
@@ -1353,7 +1342,7 @@ int __setlease(struct file *filp, long arg, struct file_lock **flp)
                goto out;
 
        if (my_before != NULL) {
-               error = lease_modify(my_before, arg);
+               error = lease->fl_lmops->fl_change(my_before, arg);
                goto out;
        }
 
@@ -1900,8 +1889,13 @@ void locks_remove_flock(struct file *filp)
                return;
 
        if (filp->f_op && filp->f_op->flock) {
-               struct file_lock fl = { .fl_flags = FL_FLOCK,
-                                       .fl_type = F_UNLCK };
+               struct file_lock fl = {
+                       .fl_pid = current->tgid,
+                       .fl_file = filp,
+                       .fl_flags = FL_FLOCK,
+                       .fl_type = F_UNLCK,
+                       .fl_end = OFFSET_MAX,
+               };
                filp->f_op->flock(filp, F_SETLKW, &fl);
        }