Commit 3ee17abd14c728d4e0ca7a991c58f2250cb091af

Authored by J. Bruce Fields
1 parent 9d6a8c5c21

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>

Showing 2 changed files with 26 additions and 13 deletions Side-by-side Diff

... ... @@ -1611,6 +1611,24 @@
1611 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 + */
  1623 +int 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 +}
  1630 +EXPORT_SYMBOL_GPL(vfs_test_lock);
  1631 +
1614 1632 static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)
1615 1633 {
1616 1634 flock->l_pid = fl->fl_pid;
... ... @@ -1663,12 +1681,9 @@
1663 1681 if (error)
1664 1682 goto out;
1665 1683  
1666   - if (filp->f_op && filp->f_op->lock) {
1667   - error = filp->f_op->lock(filp, F_GETLK, &file_lock);
1668   - if (error < 0)
1669   - goto out;
1670   - } else
1671   - posix_test_lock(filp, &file_lock);
  1684 + error = vfs_test_lock(filp, &file_lock);
  1685 + if (error)
  1686 + goto out;
1672 1687  
1673 1688 flock.l_type = file_lock.fl_type;
1674 1689 if (file_lock.fl_type != F_UNLCK) {
... ... @@ -1797,13 +1812,10 @@
1797 1812 if (error)
1798 1813 goto out;
1799 1814  
1800   - if (filp->f_op && filp->f_op->lock) {
1801   - error = filp->f_op->lock(filp, F_GETLK, &file_lock);
1802   - if (error < 0)
1803   - goto out;
1804   - } else
1805   - posix_test_lock(filp, &file_lock);
1806   -
  1815 + error = vfs_test_lock(filp, &file_lock);
  1816 + if (error)
  1817 + goto out;
  1818 +
1807 1819 flock.l_type = file_lock.fl_type;
1808 1820 if (file_lock.fl_type != F_UNLCK)
1809 1821 posix_lock_to_flock64(&flock, &file_lock);
... ... @@ -856,6 +856,7 @@
856 856 extern int posix_lock_file(struct file *, struct file_lock *);
857 857 extern int posix_lock_file_wait(struct file *, struct file_lock *);
858 858 extern int posix_unblock_lock(struct file *, struct file_lock *);
  859 +extern int vfs_test_lock(struct file *, struct file_lock *);
859 860 extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
860 861 extern int __break_lease(struct inode *inode, unsigned int flags);
861 862 extern void lease_get_mtime(struct inode *, struct timespec *time);