aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@citi.umich.edu>2007-02-21 00:58:50 -0500
committerJ. Bruce Fields <bfields@citi.umich.edu>2007-05-06 18:06:44 -0400
commit3ee17abd14c728d4e0ca7a991c58f2250cb091af (patch)
tree6f49a9893dc656fac4d5a334946ccbf4e911891f /fs
parent9d6a8c5c213e34c475e72b245a8eb709258e968c (diff)
locks: factor out generic/filesystem switch from test_lock
Factor out the code that switches between generic and filesystem-specific lock methods; eventually we want to call this from lock managers (lockd and nfsd) too; currently they only call the generic methods. This patch does that for test_lock. Note that this hasn't been necessary until recently, because the few filesystems that define ->lock() (nfs, cifs...) aren't exportable via NFS. However GFS (and, in the future, other cluster filesystems) need to implement their own locking to get cluster-coherent locking, and also want to be able to export locking to NFS (lockd and NFSv4). So we accomplish this by factoring out code such as this and exporting it for the use of lockd and nfsd. Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
Diffstat (limited to 'fs')
-rw-r--r--fs/locks.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/fs/locks.c b/fs/locks.c
index 749a0dc7cd4b..a31648e3ec1b 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1611,6 +1611,24 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd)
1611 return error; 1611 return error;
1612} 1612}
1613 1613
1614/**
1615 * vfs_test_lock - test file byte range lock
1616 * @filp: The file to test lock for
1617 * @fl: The lock to test
1618 * @conf: Place to return a copy of the conflicting lock, if found
1619 *
1620 * Returns -ERRNO on failure. Indicates presence of conflicting lock by
1621 * setting conf->fl_type to something other than F_UNLCK.
1622 */
1623int vfs_test_lock(struct file *filp, struct file_lock *fl)
1624{
1625 if (filp->f_op && filp->f_op->lock)
1626 return filp->f_op->lock(filp, F_GETLK, fl);
1627 posix_test_lock(filp, fl);
1628 return 0;
1629}
1630EXPORT_SYMBOL_GPL(vfs_test_lock);
1631
1614static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl) 1632static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)
1615{ 1633{
1616 flock->l_pid = fl->fl_pid; 1634 flock->l_pid = fl->fl_pid;
@@ -1663,12 +1681,9 @@ int fcntl_getlk(struct file *filp, struct flock __user *l)
1663 if (error) 1681 if (error)
1664 goto out; 1682 goto out;
1665 1683
1666 if (filp->f_op && filp->f_op->lock) { 1684 error = vfs_test_lock(filp, &file_lock);
1667 error = filp->f_op->lock(filp, F_GETLK, &file_lock); 1685 if (error)
1668 if (error < 0) 1686 goto out;
1669 goto out;
1670 } else
1671 posix_test_lock(filp, &file_lock);
1672 1687
1673 flock.l_type = file_lock.fl_type; 1688 flock.l_type = file_lock.fl_type;
1674 if (file_lock.fl_type != F_UNLCK) { 1689 if (file_lock.fl_type != F_UNLCK) {
@@ -1797,13 +1812,10 @@ int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
1797 if (error) 1812 if (error)
1798 goto out; 1813 goto out;
1799 1814
1800 if (filp->f_op && filp->f_op->lock) { 1815 error = vfs_test_lock(filp, &file_lock);
1801 error = filp->f_op->lock(filp, F_GETLK, &file_lock); 1816 if (error)
1802 if (error < 0) 1817 goto out;
1803 goto out; 1818
1804 } else
1805 posix_test_lock(filp, &file_lock);
1806
1807 flock.l_type = file_lock.fl_type; 1819 flock.l_type = file_lock.fl_type;
1808 if (file_lock.fl_type != F_UNLCK) 1820 if (file_lock.fl_type != F_UNLCK)
1809 posix_lock_to_flock64(&flock, &file_lock); 1821 posix_lock_to_flock64(&flock, &file_lock);