From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sukadev Bhattiprolu Subject: [PATCH 8/9][cr][v2]: Define flock64_set() Date: Tue, 18 May 2010 20:07:31 -0700 Message-ID: <1274238452-15382-9-git-send-email-sukadev@linux.vnet.ibm.com> References: <1274238452-15382-1-git-send-email-sukadev@linux.vnet.ibm.com> Cc: serue@us.ibm.com, Matt Helsley , matthew@wil.cx, , Containers To: Oren Laadan Return-path: Received: from e9.ny.us.ibm.com ([32.97.182.139]:44539 "EHLO e9.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755701Ab0ESDB3 (ORCPT ); Tue, 18 May 2010 23:01:29 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e9.ny.us.ibm.com (8.14.3/8.13.1) with ESMTP id o4J2lwYW017802 for ; Tue, 18 May 2010 22:47:58 -0400 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o4J31TR8136844 for ; Tue, 18 May 2010 23:01:29 -0400 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o4J31S2l011817 for ; Tue, 18 May 2010 23:01:29 -0400 In-Reply-To: <1274238452-15382-1-git-send-email-sukadev@linux.vnet.ibm.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Extract core functionality of fcntl_setlk64() into a separate function, flock64_set(). flock64_set() can be also used when restarting a checkpointed application and restoring its file-locks. Signed-off-by: Sukadev Bhattiprolu --- fs/locks.c | 38 ++++++++++++++++++++++++-------------- include/linux/fs.h | 2 ++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index cb83741..c62ab7f 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1890,11 +1890,10 @@ out: /* 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_setlk64(unsigned int fd, struct file *filp, unsigned int cmd, - struct flock64 __user *l) +int flock64_set(unsigned int fd, struct file *filp, unsigned int cmd, + struct flock64 *flock) { struct file_lock *file_lock = locks_alloc_lock(); - struct flock64 flock; struct inode *inode; struct file *f; int error; @@ -1902,13 +1901,6 @@ int fcntl_setlk64(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 @@ -1920,7 +1912,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd, } again: - error = flock64_to_posix_lock(filp, file_lock, &flock); + error = flock64_to_posix_lock(filp, file_lock, flock); if (error) goto out; if (cmd == F_SETLKW64) { @@ -1928,7 +1920,7 @@ again: } error = -EBADF; - switch (flock.l_type) { + switch (flock->l_type) { case F_RDLCK: if (!(filp->f_mode & FMODE_READ)) goto out; @@ -1953,8 +1945,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; } @@ -1962,6 +1954,24 @@ out: locks_free_lock(file_lock); 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_setlk64(unsigned int fd, struct file *filp, unsigned int cmd, + struct flock64 __user *l) +{ + struct flock64 flock; + + /* + * This might block, so we do it before checking the inode in + * flock64_set(). + */ + if (copy_from_user(&flock, l, sizeof(flock))) + return -EFAULT; + + return flock64_set(fd, filp, cmd, &flock); +} #endif /* BITS_PER_LONG == 32 */ /* diff --git a/include/linux/fs.h b/include/linux/fs.h index fd66f37..49d4eeb 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1118,6 +1118,8 @@ extern int flock_set(unsigned int, struct file *, unsigned int, struct flock *); extern int fcntl_getlk64(struct file *, struct flock64 __user *); extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, struct flock64 __user *); +extern int flock64_set(unsigned int, struct file *, unsigned int, + struct flock64 *); #endif extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); -- 1.6.0.4