From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sukadev Bhattiprolu Subject: [PATCH 07/17][cr][v4]: Define flock_set() Date: Mon, 16 Aug 2010 12:43:11 -0700 Message-ID: <1281987801-1293-8-git-send-email-sukadev@linux.vnet.ibm.com> References: <1281987801-1293-1-git-send-email-sukadev@linux.vnet.ibm.com> Cc: Serge Hallyn , Matt Helsley , Dan Smith , John Stultz , Matthew Wilcox , Jamie Lokier , Steven Whitehouse , , Containers To: Oren Laadan Return-path: Received: from e31.co.us.ibm.com ([32.97.110.149]:48342 "EHLO e31.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756057Ab0HPThu (ORCPT ); Mon, 16 Aug 2010 15:37:50 -0400 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e31.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id o7GJQ7bp009588 for ; Mon, 16 Aug 2010 13:26:07 -0600 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id o7GJbjqX150028 for ; Mon, 16 Aug 2010 13:37:47 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o7GJbdL1015299 for ; Mon, 16 Aug 2010 13:37:40 -0600 In-Reply-To: <1281987801-1293-1-git-send-email-sukadev@linux.vnet.ibm.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Extract core functionality of fcntl_setlk() into a separate function, flock_set(). flock_set() can be also used when restarting a checkpointed application and restoring its file-locks. Signed-off-by: Sukadev Bhattiprolu --- fs/locks.c | 44 +++++++++++++++++++++++++++----------------- include/linux/fs.h | 1 + 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 741b8b7..cb83741 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1759,14 +1759,10 @@ static int do_lock_file_wait(struct file *filp, unsigned int cmd, return error; } -/* Apply the lock described by l to an open file descriptor. - * This implements both the F_SETLK and F_SETLKW commands of fcntl(). - */ -int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, - struct flock __user *l) +int flock_set(unsigned int fd, struct file *filp, unsigned int cmd, + struct flock *flock) { struct file_lock *file_lock = locks_alloc_lock(); - struct flock flock; struct inode *inode; struct file *f; int error; @@ -1774,13 +1770,6 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, if (file_lock == NULL) return -ENOLCK; - /* - * This might block, so we do it before checking the inode. - */ - error = -EFAULT; - if (copy_from_user(&flock, l, sizeof(flock))) - goto out; - inode = filp->f_path.dentry->d_inode; /* Don't allow mandatory locks on files that may be memory mapped @@ -1792,7 +1781,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, } again: - error = flock_to_posix_lock(filp, file_lock, &flock); + error = flock_to_posix_lock(filp, file_lock, flock); if (error) goto out; if (cmd == F_SETLKW) { @@ -1800,7 +1789,7 @@ again: } error = -EBADF; - switch (flock.l_type) { + switch (flock->l_type) { case F_RDLCK: if (!(filp->f_mode & FMODE_READ)) goto out; @@ -1830,8 +1819,8 @@ again: spin_lock(¤t->files->file_lock); f = fcheck(fd); spin_unlock(¤t->files->file_lock); - if (!error && f != filp && flock.l_type != F_UNLCK) { - flock.l_type = F_UNLCK; + if (!error && f != filp && flock->l_type != F_UNLCK) { + flock->l_type = F_UNLCK; goto again; } @@ -1840,6 +1829,27 @@ out: return error; } +/* Apply the lock described by l to an open file descriptor. + * This implements both the F_SETLK and F_SETLKW commands of fcntl(). + */ +int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, + struct flock __user *l) +{ + int error; + struct flock flock; + + /* + * This might block, so we do it before checking the inode + * in flock_set(). + */ + error = -EFAULT; + if (copy_from_user(&flock, l, sizeof(flock))) + return error; + + return flock_set(fd, filp, cmd, &flock); +} + + #if BITS_PER_LONG == 32 /* Report the first existing lock that would conflict with l. * This implements the F_GETLK command of fcntl(). diff --git a/include/linux/fs.h b/include/linux/fs.h index abd2267..fd66f37 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1112,6 +1112,7 @@ extern void send_sigio(struct fown_struct *fown, int fd, int band); extern int fcntl_getlk(struct file *, struct flock __user *); extern int fcntl_setlk(unsigned int, struct file *, unsigned int, struct flock __user *); +extern int flock_set(unsigned int, struct file *, unsigned int, struct flock *); #if BITS_PER_LONG == 32 extern int fcntl_getlk64(struct file *, struct flock64 __user *); -- 1.6.0.4