locks: plumb a "priv" pointer into the setlease routines

In later patches, we're going to add a new lock_manager_operation to
finish setting up the lease while still holding the i_lock.  To do
this, we'll need to pass a little bit of info in the fcntl setlease
case (primarily an fasync structure). Plumb the extra pointer into
there in advance of that.

We declare this pointer as a void ** to make it clear that this is
private info, and that the caller isn't required to set this unless
the lm_setup specifically requires it.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Jeff Layton 2014-08-22 10:40:25 -04:00
Родитель 0c637be884
Коммит e6f5c78930
7 изменённых файлов: 37 добавлений и 26 удалений

Просмотреть файл

@ -464,7 +464,7 @@ prototypes:
size_t, unsigned int); size_t, unsigned int);
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *,
size_t, unsigned int); size_t, unsigned int);
int (*setlease)(struct file *, long, struct file_lock **); int (*setlease)(struct file *, long, struct file_lock **, void **);
long (*fallocate)(struct file *, int, loff_t, loff_t); long (*fallocate)(struct file *, int, loff_t, loff_t);
}; };

Просмотреть файл

@ -826,7 +826,7 @@ struct file_operations {
int (*flock) (struct file *, int, struct file_lock *); int (*flock) (struct file *, int, struct file_lock *);
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, size_t, unsigned int); ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, size_t, unsigned int);
ssize_t (*splice_read)(struct file *, struct pipe_inode_info *, size_t, unsigned int); ssize_t (*splice_read)(struct file *, struct pipe_inode_info *, size_t, unsigned int);
int (*setlease)(struct file *, long arg, struct file_lock **); int (*setlease)(struct file *, long arg, struct file_lock **, void **);
long (*fallocate)(struct file *, int mode, loff_t offset, loff_t len); long (*fallocate)(struct file *, int mode, loff_t offset, loff_t len);
int (*show_fdinfo)(struct seq_file *m, struct file *f); int (*show_fdinfo)(struct seq_file *m, struct file *f);
}; };

Просмотреть файл

@ -800,7 +800,8 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int whence)
return generic_file_llseek(file, offset, whence); return generic_file_llseek(file, offset, whence);
} }
static int cifs_setlease(struct file *file, long arg, struct file_lock **lease) static int
cifs_setlease(struct file *file, long arg, struct file_lock **lease, void **priv)
{ {
/* /*
* Note that this is called by vfs setlease with i_lock held to * Note that this is called by vfs setlease with i_lock held to
@ -815,7 +816,7 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
/* check if file is oplocked */ /* check if file is oplocked */
if (((arg == F_RDLCK) && CIFS_CACHE_READ(CIFS_I(inode))) || if (((arg == F_RDLCK) && CIFS_CACHE_READ(CIFS_I(inode))) ||
((arg == F_WRLCK) && CIFS_CACHE_WRITE(CIFS_I(inode)))) ((arg == F_WRLCK) && CIFS_CACHE_WRITE(CIFS_I(inode))))
return generic_setlease(file, arg, lease); return generic_setlease(file, arg, lease, priv);
else if (tlink_tcon(cfile->tlink)->local_lease && else if (tlink_tcon(cfile->tlink)->local_lease &&
!CIFS_CACHE_READ(CIFS_I(inode))) !CIFS_CACHE_READ(CIFS_I(inode)))
/* /*
@ -826,7 +827,7 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
* knows that the file won't be changed on the server by anyone * knows that the file won't be changed on the server by anyone
* else. * else.
*/ */
return generic_setlease(file, arg, lease); return generic_setlease(file, arg, lease, priv);
else else
return -EAGAIN; return -EAGAIN;
} }

Просмотреть файл

@ -1081,12 +1081,14 @@ EXPORT_SYMBOL(alloc_anon_inode);
* @filp: file pointer * @filp: file pointer
* @arg: type of lease to obtain * @arg: type of lease to obtain
* @flp: new lease supplied for insertion * @flp: new lease supplied for insertion
* @priv: private data for lm_setup operation
* *
* Generic helper for filesystems that do not wish to allow leases to be set. * Generic helper for filesystems that do not wish to allow leases to be set.
* All arguments are ignored and it just returns -EINVAL. * All arguments are ignored and it just returns -EINVAL.
*/ */
int int
simple_nosetlease(struct file *filp, long arg, struct file_lock **flp) simple_nosetlease(struct file *filp, long arg, struct file_lock **flp,
void **priv)
{ {
return -EINVAL; return -EINVAL;
} }

Просмотреть файл

@ -1297,7 +1297,6 @@ int lease_modify(struct file_lock **before, int arg)
} }
return 0; return 0;
} }
EXPORT_SYMBOL(lease_modify); EXPORT_SYMBOL(lease_modify);
static bool past_time(unsigned long then) static bool past_time(unsigned long then)
@ -1543,7 +1542,8 @@ check_conflicting_open(const struct dentry *dentry, const long arg)
return ret; return ret;
} }
static int generic_add_lease(struct file *filp, long arg, struct file_lock **flp) static int
generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **priv)
{ {
struct file_lock *fl, **before, **my_before = NULL, *lease; struct file_lock *fl, **before, **my_before = NULL, *lease;
struct dentry *dentry = filp->f_path.dentry; struct dentry *dentry = filp->f_path.dentry;
@ -1630,11 +1630,14 @@ static int generic_add_lease(struct file *filp, long arg, struct file_lock **flp
smp_mb(); smp_mb();
error = check_conflicting_open(dentry, arg); error = check_conflicting_open(dentry, arg);
if (error) if (error)
locks_unlink_lock(before); goto out_unlink;
out: out:
if (is_deleg) if (is_deleg)
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return error; return error;
out_unlink:
locks_unlink_lock(before);
goto out;
} }
static int generic_delete_lease(struct file *filp) static int generic_delete_lease(struct file *filp)
@ -1661,13 +1664,15 @@ static int generic_delete_lease(struct file *filp)
* @filp: file pointer * @filp: file pointer
* @arg: type of lease to obtain * @arg: type of lease to obtain
* @flp: input - file_lock to use, output - file_lock inserted * @flp: input - file_lock to use, output - file_lock inserted
* @priv: private data for lm_setup
* *
* The (input) flp->fl_lmops->lm_break function is required * The (input) flp->fl_lmops->lm_break function is required
* by break_lease(). * by break_lease().
* *
* Called with inode->i_lock held. * Called with inode->i_lock held.
*/ */
int generic_setlease(struct file *filp, long arg, struct file_lock **flp) int generic_setlease(struct file *filp, long arg, struct file_lock **flp,
void **priv)
{ {
struct dentry *dentry = filp->f_path.dentry; struct dentry *dentry = filp->f_path.dentry;
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
@ -1692,19 +1697,20 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
return -ENOLCK; return -ENOLCK;
} }
return generic_add_lease(filp, arg, flp); return generic_add_lease(filp, arg, flp, priv);
default: default:
return -EINVAL; return -EINVAL;
} }
} }
EXPORT_SYMBOL(generic_setlease); EXPORT_SYMBOL(generic_setlease);
static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease) static int
__vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv)
{ {
if (filp->f_op->setlease) if (filp->f_op->setlease)
return filp->f_op->setlease(filp, arg, lease); return filp->f_op->setlease(filp, arg, lease, priv);
else else
return generic_setlease(filp, arg, lease); return generic_setlease(filp, arg, lease, priv);
} }
/** /**
@ -1712,6 +1718,7 @@ static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
* @filp: file pointer * @filp: file pointer
* @arg: type of lease to obtain * @arg: type of lease to obtain
* @lease: file_lock to use when adding a lease * @lease: file_lock to use when adding a lease
* @priv: private info for lm_setup when adding a lease
* *
* Call this to establish a lease on the file. The "lease" argument is not * Call this to establish a lease on the file. The "lease" argument is not
* used for F_UNLCK requests and may be NULL. For commands that set or alter * used for F_UNLCK requests and may be NULL. For commands that set or alter
@ -1720,13 +1727,14 @@ static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
* stack trace). * stack trace).
*/ */
int vfs_setlease(struct file *filp, long arg, struct file_lock **lease) int
vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
int error; int error;
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
error = __vfs_setlease(filp, arg, lease); error = __vfs_setlease(filp, arg, lease, priv);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
return error; return error;
@ -1751,7 +1759,7 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
} }
ret = fl; ret = fl;
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
error = __vfs_setlease(filp, arg, &ret); error = __vfs_setlease(filp, arg, &ret, NULL);
if (error) if (error)
goto out_unlock; goto out_unlock;
if (ret == fl) if (ret == fl)
@ -1789,7 +1797,7 @@ out_unlock:
int fcntl_setlease(unsigned int fd, struct file *filp, long arg) int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
{ {
if (arg == F_UNLCK) if (arg == F_UNLCK)
return vfs_setlease(filp, F_UNLCK, NULL); return vfs_setlease(filp, F_UNLCK, NULL, NULL);
return do_fcntl_add_lease(fd, filp, arg); return do_fcntl_add_lease(fd, filp, arg);
} }

Просмотреть файл

@ -686,7 +686,7 @@ static void nfs4_put_deleg_lease(struct nfs4_file *fp)
spin_unlock(&fp->fi_lock); spin_unlock(&fp->fi_lock);
if (filp) { if (filp) {
vfs_setlease(filp, F_UNLCK, NULL); vfs_setlease(filp, F_UNLCK, NULL, NULL);
fput(filp); fput(filp);
} }
} }
@ -3792,7 +3792,7 @@ static int nfs4_setlease(struct nfs4_delegation *dp)
} }
fl->fl_file = filp; fl->fl_file = filp;
ret = fl; ret = fl;
status = vfs_setlease(filp, fl->fl_type, &ret); status = vfs_setlease(filp, fl->fl_type, &fl, NULL);
if (status) { if (status) {
locks_free_lock(fl); locks_free_lock(fl);
goto out_fput; goto out_fput;

Просмотреть файл

@ -982,8 +982,8 @@ extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type); extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
extern void lease_get_mtime(struct inode *, struct timespec *time); extern void lease_get_mtime(struct inode *, struct timespec *time);
extern int generic_setlease(struct file *, long, struct file_lock **); extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
extern int vfs_setlease(struct file *, long, struct file_lock **); extern int vfs_setlease(struct file *, long, struct file_lock **, void **);
extern int lease_modify(struct file_lock **, int); extern int lease_modify(struct file_lock **, int);
#else /* !CONFIG_FILE_LOCKING */ #else /* !CONFIG_FILE_LOCKING */
static inline int fcntl_getlk(struct file *file, unsigned int cmd, static inline int fcntl_getlk(struct file *file, unsigned int cmd,
@ -1100,13 +1100,13 @@ static inline void lease_get_mtime(struct inode *inode, struct timespec *time)
} }
static inline int generic_setlease(struct file *filp, long arg, static inline int generic_setlease(struct file *filp, long arg,
struct file_lock **flp) struct file_lock **flp, void **priv)
{ {
return -EINVAL; return -EINVAL;
} }
static inline int vfs_setlease(struct file *filp, long arg, static inline int vfs_setlease(struct file *filp, long arg,
struct file_lock **lease) struct file_lock **lease, void **priv)
{ {
return -EINVAL; return -EINVAL;
} }
@ -1494,7 +1494,7 @@ struct file_operations {
int (*flock) (struct file *, int, struct file_lock *); int (*flock) (struct file *, int, struct file_lock *);
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
int (*setlease)(struct file *, long, struct file_lock **); int (*setlease)(struct file *, long, struct file_lock **, void **);
long (*fallocate)(struct file *file, int mode, loff_t offset, long (*fallocate)(struct file *file, int mode, loff_t offset,
loff_t len); loff_t len);
int (*show_fdinfo)(struct seq_file *m, struct file *f); int (*show_fdinfo)(struct seq_file *m, struct file *f);
@ -2599,7 +2599,7 @@ extern int simple_write_end(struct file *file, struct address_space *mapping,
struct page *page, void *fsdata); struct page *page, void *fsdata);
extern int always_delete_dentry(const struct dentry *); extern int always_delete_dentry(const struct dentry *);
extern struct inode *alloc_anon_inode(struct super_block *); extern struct inode *alloc_anon_inode(struct super_block *);
extern int simple_nosetlease(struct file *, long, struct file_lock **); extern int simple_nosetlease(struct file *, long, struct file_lock **, void **);
extern const struct dentry_operations simple_dentry_operations; extern const struct dentry_operations simple_dentry_operations;
extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags); extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags);