* PATCH [6/10] lease interfaces for version 4 NFSD
@ 2004-09-20 20:23 William A.(Andy) Adamson
2004-09-20 20:33 ` Matthew Wilcox
0 siblings, 1 reply; 3+ messages in thread
From: William A.(Andy) Adamson @ 2004-09-20 20:23 UTC (permalink / raw)
To: linux-fsdevel; +Cc: andros
[-- Attachment #1: Type: text/plain, Size: 237 bytes --]
VFS: nfsd will not have a file descriptor, nor an owner on the filp. nfsd also
will not use signals. Seperate the lease processing code from fcntl_setlease()
into a __setlease() call.
Signed-off-by: Andy Adamson <andros@umich.edu>
[-- Attachment #2: linux-2.6.9-rc2-06-fcntl_setlease.dif --]
[-- Type: text/plain , Size: 4065 bytes --]
diff --recursive -puN old/fs/locks.c new/fs/locks.c
--- old/fs/locks.c 2004-09-20 13:36:41.571386000 -0400
+++ new/fs/locks.c 2004-09-20 13:56:25.385316000 -0400
@@ -1252,37 +1252,29 @@ int fcntl_getlease(struct file *filp)
}
/**
- * fcntl_setlease - sets a lease on an open file
- * @fd: open file descriptor
+ * __setlease - sets a lease on an open file
* @filp: file pointer
* @arg: type of lease to obtain
+ * @flp: input - file_lock to use, output - file_lock inserted
*
- * Call this fcntl to establish a lease on the file.
- * Note that you also need to call %F_SETSIG to
- * receive a signal when the lease is broken.
+ * The (input) flp->fl_lmops->fl_break function is required
+ * by break_lease
+ *
+ * Called with kernel lock held.
*/
-int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
+int __setlease(struct file *filp, long arg, struct file_lock **flp)
{
struct file_lock *fl, **before, **my_before = NULL;
- struct dentry *dentry;
- struct inode *inode;
+ struct dentry *dentry = filp->f_dentry;
+ struct inode *inode = dentry->d_inode;
int error, rdlease_count = 0, wrlease_count = 0;
- dentry = filp->f_dentry;
- inode = dentry->d_inode;
-
- if ((current->fsuid != inode->i_uid) && !capable(CAP_LEASE))
- return -EACCES;
- if (!S_ISREG(inode->i_mode))
- return -EINVAL;
- error = security_file_lock(filp, arg);
- if (error)
- return error;
-
- lock_kernel();
-
time_out_leases(inode);
+ error = -EINVAL;
+ if (!flp || !(*flp) || !(*flp)->fl_lmops || !(*flp)->fl_lmops->fl_break)
+ goto out;
+
/*
* FIXME: What about F_RDLCK and files open for writing?
*/
@@ -1290,7 +1282,7 @@ int fcntl_setlease(unsigned int fd, stru
if ((arg == F_WRLCK)
&& ((atomic_read(&dentry->d_count) > 1)
|| (atomic_read(&inode->i_count) > 1)))
- goto out_unlock;
+ goto out;
/*
* At this point, we know that if there is an exclusive
@@ -1318,39 +1310,83 @@ int fcntl_setlease(unsigned int fd, stru
if ((arg == F_RDLCK && (wrlease_count > 0)) ||
(arg == F_WRLCK && ((rdlease_count + wrlease_count) > 0)))
- goto out_unlock;
+ goto out;
if (my_before != NULL) {
error = lease_modify(my_before, arg);
- goto out_unlock;
+ goto out;
}
error = 0;
if (arg == F_UNLCK)
- goto out_unlock;
+ goto out;
error = -EINVAL;
if (!leases_enable)
- goto out_unlock;
+ goto out;
error = lease_alloc(filp, arg, &fl);
if (error)
- goto out_unlock;
+ goto out;
- error = fasync_helper(fd, filp, 1, &fl->fl_fasync);
- if (error < 0) {
- locks_free_lock(fl);
- goto out_unlock;
- }
+ locks_copy_lock(fl, lease);
locks_insert_lock(before, fl);
+out:
+ return error;
+}
+
+/**
+ * fcntl_setlease - sets a lease on an open file
+ * @fd: open file descriptor
+ * @filp: file pointer
+ * @arg: type of lease to obtain
+ *
+ * Call this fcntl to establish a lease on the file.
+ * Uses default fl_break function.
+ * Note that you also need to call %F_SETSIG to
+ * receive a signal when the lease is broken.
+ */
+int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
+{
+ struct file_lock fl, *flp = &fl;
+ struct dentry *dentry = filp->f_dentry;
+ struct inode *inode = dentry->d_inode;
+ int error;
+
+ if ((current->fsuid != inode->i_uid) && !capable(CAP_LEASE))
+ return -EACCES;
+ if (!S_ISREG(inode->i_mode))
+ return -EINVAL;
+ error = security_file_lock(filp, arg);
+ if (error)
+ return error;
+
+ locks_init_lock(&fl);
+ if ((error = lease_init(filp, arg, &fl)))
+ return error;
+
+ lock_kernel();
+ if((error = __setlease(filp, arg, &flp)))
+ goto out;
+
+ error = fasync_helper(fd, filp, 1, &flp->fl_fasync);
+ if (error < 0) {
+ /* remove lease just inserted by __setlease */
+ flp->fl_type = F_UNLCK | F_INPROGRESS;
+ flp->fl_break_time = jiffies - 10;
+ time_out_leases(inode);
+ goto out;
+ }
+
error = f_setown(filp, current->pid, 0);
-out_unlock:
+out:
unlock_kernel();
return error;
}
+
/**
* flock_lock_file_wait - Apply a FLOCK-style lock to a file
* @filp: The file to apply the lock to
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: PATCH [6/10] lease interfaces for version 4 NFSD
2004-09-20 20:23 PATCH [6/10] lease interfaces for version 4 NFSD William A.(Andy) Adamson
@ 2004-09-20 20:33 ` Matthew Wilcox
2004-09-20 20:38 ` William A.(Andy) Adamson
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2004-09-20 20:33 UTC (permalink / raw)
To: William A.(Andy) Adamson; +Cc: linux-fsdevel
On Mon, Sep 20, 2004 at 04:23:00PM -0400, William A.(Andy) Adamson wrote:
> + locks_init_lock(&fl);
> + if ((error = lease_init(filp, arg, &fl)))
> + return error;
> + lock_kernel();
> + if((error = __setlease(filp, arg, &flp)))
> + goto out;
> +
Please follow kernel coding style. That means:
- Tabs, not spaces for indentation.
- No assignment within if ()
- Space between if and (
ie write this bit as:
locks_init_lock(&fl);
error = lease_init(filp, arg, &fl);
if (error)
return error;
lock_kernel();
error = __setlease(filp, arg, &flp);
if (error)
goto out;
> return error;
> }
>
> +
> /**
> * flock_lock_file_wait - Apply a FLOCK-style lock to a file
> * @filp: The file to apply the lock to
Don't put this additional line in. I don't like it.
--
"Next the statesmen will invent cheap lies, putting the blame upon
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince
himself that the war is just, and will thank God for the better sleep
he enjoys after this process of grotesque self-deception." -- Mark Twain
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH [6/10] lease interfaces for version 4 NFSD
2004-09-20 20:33 ` Matthew Wilcox
@ 2004-09-20 20:38 ` William A.(Andy) Adamson
0 siblings, 0 replies; 3+ messages in thread
From: William A.(Andy) Adamson @ 2004-09-20 20:38 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: William A.(Andy) Adamson, linux-fsdevel
> On Mon, Sep 20, 2004 at 04:23:00PM -0400, William A.(Andy) Adamson wrote:
> > + locks_init_lock(&fl);
> > + if ((error = lease_init(filp, arg, &fl)))
> > + return error;
> > + lock_kernel();
> > + if((error = __setlease(filp, arg, &flp)))
> > + goto out;
> > +
>
> Please follow kernel coding style. That means:
ok.
BTW: i just noted that there are two emails with PATCH [9/10] in the title.
they are different patches...
-->Andy
> - Tabs, not spaces for indentation.
> - No assignment within if ()
> - Space between if and (
> ie write this bit as:
>
> locks_init_lock(&fl);
> error = lease_init(filp, arg, &fl);
> if (error)
> return error;
> lock_kernel();
> error = __setlease(filp, arg, &flp);
> if (error)
> goto out;
>
> > return error;
> > }
> >
> > +
> > /**
> > * flock_lock_file_wait - Apply a FLOCK-style lock to a file
> > * @filp: The file to apply the lock to
>
> Don't put this additional line in. I don't like it.
>
> --
> "Next the statesmen will invent cheap lies, putting the blame upon
> the nation that is attacked, and every man will be glad of those
> conscience-soothing falsities, and will diligently study them, and refuse
> to examine any refutations of them; and thus he will by and by convince
> himself that the war is just, and will thank God for the better sleep
> he enjoys after this process of grotesque self-deception." -- Mark Twain
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-09-20 20:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-20 20:23 PATCH [6/10] lease interfaces for version 4 NFSD William A.(Andy) Adamson
2004-09-20 20:33 ` Matthew Wilcox
2004-09-20 20:38 ` William A.(Andy) Adamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).