Skip to content

Commit e6f5c78

Browse files
author
Jeff Layton
committed
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 0c637be commit e6f5c78

File tree

7 files changed

+37
-26
lines changed

7 files changed

+37
-26
lines changed

Documentation/filesystems/Locking

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ prototypes:
464464
size_t, unsigned int);
465465
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *,
466466
size_t, unsigned int);
467-
int (*setlease)(struct file *, long, struct file_lock **);
467+
int (*setlease)(struct file *, long, struct file_lock **, void **);
468468
long (*fallocate)(struct file *, int, loff_t, loff_t);
469469
};
470470

Documentation/filesystems/vfs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ struct file_operations {
826826
int (*flock) (struct file *, int, struct file_lock *);
827827
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, size_t, unsigned int);
828828
ssize_t (*splice_read)(struct file *, struct pipe_inode_info *, size_t, unsigned int);
829-
int (*setlease)(struct file *, long arg, struct file_lock **);
829+
int (*setlease)(struct file *, long arg, struct file_lock **, void **);
830830
long (*fallocate)(struct file *, int mode, loff_t offset, loff_t len);
831831
int (*show_fdinfo)(struct seq_file *m, struct file *f);
832832
};

fs/cifs/cifsfs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int whence)
800800
return generic_file_llseek(file, offset, whence);
801801
}
802802

803-
static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
803+
static int
804+
cifs_setlease(struct file *file, long arg, struct file_lock **lease, void **priv)
804805
{
805806
/*
806807
* 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)
815816
/* check if file is oplocked */
816817
if (((arg == F_RDLCK) && CIFS_CACHE_READ(CIFS_I(inode))) ||
817818
((arg == F_WRLCK) && CIFS_CACHE_WRITE(CIFS_I(inode))))
818-
return generic_setlease(file, arg, lease);
819+
return generic_setlease(file, arg, lease, priv);
819820
else if (tlink_tcon(cfile->tlink)->local_lease &&
820821
!CIFS_CACHE_READ(CIFS_I(inode)))
821822
/*
@@ -826,7 +827,7 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
826827
* knows that the file won't be changed on the server by anyone
827828
* else.
828829
*/
829-
return generic_setlease(file, arg, lease);
830+
return generic_setlease(file, arg, lease, priv);
830831
else
831832
return -EAGAIN;
832833
}

fs/libfs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,12 +1081,14 @@ EXPORT_SYMBOL(alloc_anon_inode);
10811081
* @filp: file pointer
10821082
* @arg: type of lease to obtain
10831083
* @flp: new lease supplied for insertion
1084+
* @priv: private data for lm_setup operation
10841085
*
10851086
* Generic helper for filesystems that do not wish to allow leases to be set.
10861087
* All arguments are ignored and it just returns -EINVAL.
10871088
*/
10881089
int
1089-
simple_nosetlease(struct file *filp, long arg, struct file_lock **flp)
1090+
simple_nosetlease(struct file *filp, long arg, struct file_lock **flp,
1091+
void **priv)
10901092
{
10911093
return -EINVAL;
10921094
}

fs/locks.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ int lease_modify(struct file_lock **before, int arg)
12971297
}
12981298
return 0;
12991299
}
1300-
13011300
EXPORT_SYMBOL(lease_modify);
13021301

13031302
static bool past_time(unsigned long then)
@@ -1543,7 +1542,8 @@ check_conflicting_open(const struct dentry *dentry, const long arg)
15431542
return ret;
15441543
}
15451544

1546-
static int generic_add_lease(struct file *filp, long arg, struct file_lock **flp)
1545+
static int
1546+
generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **priv)
15471547
{
15481548
struct file_lock *fl, **before, **my_before = NULL, *lease;
15491549
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
16301630
smp_mb();
16311631
error = check_conflicting_open(dentry, arg);
16321632
if (error)
1633-
locks_unlink_lock(before);
1633+
goto out_unlink;
16341634
out:
16351635
if (is_deleg)
16361636
mutex_unlock(&inode->i_mutex);
16371637
return error;
1638+
out_unlink:
1639+
locks_unlink_lock(before);
1640+
goto out;
16381641
}
16391642

16401643
static int generic_delete_lease(struct file *filp)
@@ -1661,13 +1664,15 @@ static int generic_delete_lease(struct file *filp)
16611664
* @filp: file pointer
16621665
* @arg: type of lease to obtain
16631666
* @flp: input - file_lock to use, output - file_lock inserted
1667+
* @priv: private data for lm_setup
16641668
*
16651669
* The (input) flp->fl_lmops->lm_break function is required
16661670
* by break_lease().
16671671
*
16681672
* Called with inode->i_lock held.
16691673
*/
1670-
int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1674+
int generic_setlease(struct file *filp, long arg, struct file_lock **flp,
1675+
void **priv)
16711676
{
16721677
struct dentry *dentry = filp->f_path.dentry;
16731678
struct inode *inode = dentry->d_inode;
@@ -1692,26 +1697,28 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
16921697
WARN_ON_ONCE(1);
16931698
return -ENOLCK;
16941699
}
1695-
return generic_add_lease(filp, arg, flp);
1700+
return generic_add_lease(filp, arg, flp, priv);
16961701
default:
16971702
return -EINVAL;
16981703
}
16991704
}
17001705
EXPORT_SYMBOL(generic_setlease);
17011706

1702-
static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
1707+
static int
1708+
__vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv)
17031709
{
17041710
if (filp->f_op->setlease)
1705-
return filp->f_op->setlease(filp, arg, lease);
1711+
return filp->f_op->setlease(filp, arg, lease, priv);
17061712
else
1707-
return generic_setlease(filp, arg, lease);
1713+
return generic_setlease(filp, arg, lease, priv);
17081714
}
17091715

17101716
/**
17111717
* vfs_setlease - sets a lease on an open file
17121718
* @filp: file pointer
17131719
* @arg: type of lease to obtain
17141720
* @lease: file_lock to use when adding a lease
1721+
* @priv: private info for lm_setup when adding a lease
17151722
*
17161723
* Call this to establish a lease on the file. The "lease" argument is not
17171724
* 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)
17201727
* stack trace).
17211728
*/
17221729

1723-
int vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
1730+
int
1731+
vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv)
17241732
{
17251733
struct inode *inode = file_inode(filp);
17261734
int error;
17271735

17281736
spin_lock(&inode->i_lock);
1729-
error = __vfs_setlease(filp, arg, lease);
1737+
error = __vfs_setlease(filp, arg, lease, priv);
17301738
spin_unlock(&inode->i_lock);
17311739

17321740
return error;
@@ -1751,7 +1759,7 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
17511759
}
17521760
ret = fl;
17531761
spin_lock(&inode->i_lock);
1754-
error = __vfs_setlease(filp, arg, &ret);
1762+
error = __vfs_setlease(filp, arg, &ret, NULL);
17551763
if (error)
17561764
goto out_unlock;
17571765
if (ret == fl)
@@ -1789,7 +1797,7 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
17891797
int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
17901798
{
17911799
if (arg == F_UNLCK)
1792-
return vfs_setlease(filp, F_UNLCK, NULL);
1800+
return vfs_setlease(filp, F_UNLCK, NULL, NULL);
17931801
return do_fcntl_add_lease(fd, filp, arg);
17941802
}
17951803

fs/nfsd/nfs4state.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ static void nfs4_put_deleg_lease(struct nfs4_file *fp)
686686
spin_unlock(&fp->fi_lock);
687687

688688
if (filp) {
689-
vfs_setlease(filp, F_UNLCK, NULL);
689+
vfs_setlease(filp, F_UNLCK, NULL, NULL);
690690
fput(filp);
691691
}
692692
}
@@ -3792,7 +3792,7 @@ static int nfs4_setlease(struct nfs4_delegation *dp)
37923792
}
37933793
fl->fl_file = filp;
37943794
ret = fl;
3795-
status = vfs_setlease(filp, fl->fl_type, &ret);
3795+
status = vfs_setlease(filp, fl->fl_type, &fl, NULL);
37963796
if (status) {
37973797
locks_free_lock(fl);
37983798
goto out_fput;

include/linux/fs.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,8 @@ extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
982982
extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
983983
extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
984984
extern void lease_get_mtime(struct inode *, struct timespec *time);
985-
extern int generic_setlease(struct file *, long, struct file_lock **);
986-
extern int vfs_setlease(struct file *, long, struct file_lock **);
985+
extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
986+
extern int vfs_setlease(struct file *, long, struct file_lock **, void **);
987987
extern int lease_modify(struct file_lock **, int);
988988
#else /* !CONFIG_FILE_LOCKING */
989989
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)
11001100
}
11011101

11021102
static inline int generic_setlease(struct file *filp, long arg,
1103-
struct file_lock **flp)
1103+
struct file_lock **flp, void **priv)
11041104
{
11051105
return -EINVAL;
11061106
}
11071107

11081108
static inline int vfs_setlease(struct file *filp, long arg,
1109-
struct file_lock **lease)
1109+
struct file_lock **lease, void **priv)
11101110
{
11111111
return -EINVAL;
11121112
}
@@ -1494,7 +1494,7 @@ struct file_operations {
14941494
int (*flock) (struct file *, int, struct file_lock *);
14951495
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
14961496
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
1497-
int (*setlease)(struct file *, long, struct file_lock **);
1497+
int (*setlease)(struct file *, long, struct file_lock **, void **);
14981498
long (*fallocate)(struct file *file, int mode, loff_t offset,
14991499
loff_t len);
15001500
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,
25992599
struct page *page, void *fsdata);
26002600
extern int always_delete_dentry(const struct dentry *);
26012601
extern struct inode *alloc_anon_inode(struct super_block *);
2602-
extern int simple_nosetlease(struct file *, long, struct file_lock **);
2602+
extern int simple_nosetlease(struct file *, long, struct file_lock **, void **);
26032603
extern const struct dentry_operations simple_dentry_operations;
26042604

26052605
extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags);

0 commit comments

Comments
 (0)