From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Adamson Subject: [PATCH 8 of 10] RESEND lease interfaces for version 4 NFSD Date: Tue, 21 Sep 2004 18:36:16 -0400 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <1095804047.21441d5b.8@citi.umich.edu> Cc: nfsv4@linux-nfs.org, willy@debian.org Return-path: Received: from thnk.citi.umich.edu ([141.211.133.95]:20613 "EHLO thnk.citi.umich.edu") by vger.kernel.org with ESMTP id S266910AbUIUWgs (ORCPT ); Tue, 21 Sep 2004 18:36:48 -0400 To: linux-fsdevel@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org VFS: export setlease(), a direct interface to __setlease() used by nfsd Signed-off-by: Andy Adamson --- linux-2.6.9-rc2-andros/fs/locks.c | 33 ++++++++++++++++++++++++++++++ linux-2.6.9-rc2-andros/include/linux/fs.h | 1 2 files changed, 34 insertions(+) diff -puN fs/locks.c~setlease fs/locks.c --- linux-2.6.9-rc2/fs/locks.c~setlease 2004-09-21 18:00:32.094088136 -0400 +++ linux-2.6.9-rc2-andros/fs/locks.c 2004-09-21 18:00:32.100087224 -0400 @@ -1339,6 +1339,39 @@ out: return error; } + /** + * setlease - sets a lease on an open file + * @filp: file pointer + * @arg: type of lease to obtain + * @lease: file_lock to use + * + * Call this to establish a lease on the file. + * The fl_lmops fl_break function is required by break_lease + */ + +int setlease(struct file *filp, long arg, struct file_lock **lease) +{ + 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; + + lock_kernel(); + error = __setlease(filp, arg, lease); + unlock_kernel(); + + return error; +} + +EXPORT_SYMBOL(setlease); + /** * fcntl_setlease - sets a lease on an open file * @fd: open file descriptor diff -puN include/linux/fs.h~setlease include/linux/fs.h --- linux-2.6.9-rc2/include/linux/fs.h~setlease 2004-09-21 18:00:32.096087832 -0400 +++ linux-2.6.9-rc2-andros/include/linux/fs.h 2004-09-21 18:00:32.102086920 -0400 @@ -701,6 +701,7 @@ extern int posix_locks_deadlock(struct f extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); extern int __break_lease(struct inode *inode, unsigned int flags); extern void lease_get_mtime(struct inode *, struct timespec *time); +extern int setlease(struct file *, long, struct file_lock **); extern int lock_may_read(struct inode *, loff_t start, unsigned long count); extern int lock_may_write(struct inode *, loff_t start, unsigned long count); extern void steal_locks(fl_owner_t from); _