Commit c45198ed authored by Jeff Layton's avatar Jeff Layton

locks: move freeing of leases outside of i_lock

There was only one place where we still could free a file_lock while
holding the i_lock -- lease_modify. Add a new list_head argument to the
lm_change operation, pass in a private list when calling it, and fix
those callers to dispose of the list once the lock has been dropped.
Signed-off-by: default avatarJeff Layton <jlayton@primarydata.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent f82b4b67
...@@ -469,8 +469,7 @@ prototypes: ...@@ -469,8 +469,7 @@ prototypes:
}; };
locking rules: locking rules:
All may block except for ->setlease. All may block.
No VFS locks held on entry except for ->setlease.
->llseek() locking has moved from llseek to the individual llseek ->llseek() locking has moved from llseek to the individual llseek
implementations. If your fs is not using generic_file_llseek, you implementations. If your fs is not using generic_file_llseek, you
......
...@@ -1292,7 +1292,7 @@ static void lease_clear_pending(struct file_lock *fl, int arg) ...@@ -1292,7 +1292,7 @@ static void lease_clear_pending(struct file_lock *fl, int arg)
} }
/* We already had a lease on this file; just change its type */ /* We already had a lease on this file; just change its type */
int lease_modify(struct file_lock **before, int arg) int lease_modify(struct file_lock **before, int arg, struct list_head *dispose)
{ {
struct file_lock *fl = *before; struct file_lock *fl = *before;
int error = assign_type(fl, arg); int error = assign_type(fl, arg);
...@@ -1311,7 +1311,7 @@ int lease_modify(struct file_lock **before, int arg) ...@@ -1311,7 +1311,7 @@ int lease_modify(struct file_lock **before, int arg)
printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync); printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync);
fl->fl_fasync = NULL; fl->fl_fasync = NULL;
} }
locks_delete_lock(before, NULL); locks_delete_lock(before, dispose);
} }
return 0; return 0;
} }
...@@ -1325,7 +1325,7 @@ static bool past_time(unsigned long then) ...@@ -1325,7 +1325,7 @@ static bool past_time(unsigned long then)
return time_after(jiffies, then); return time_after(jiffies, then);
} }
static void time_out_leases(struct inode *inode) static void time_out_leases(struct inode *inode, struct list_head *dispose)
{ {
struct file_lock **before; struct file_lock **before;
struct file_lock *fl; struct file_lock *fl;
...@@ -1336,9 +1336,9 @@ static void time_out_leases(struct inode *inode) ...@@ -1336,9 +1336,9 @@ static void time_out_leases(struct inode *inode)
while ((fl = *before) && IS_LEASE(fl) && lease_breaking(fl)) { while ((fl = *before) && IS_LEASE(fl) && lease_breaking(fl)) {
trace_time_out_leases(inode, fl); trace_time_out_leases(inode, fl);
if (past_time(fl->fl_downgrade_time)) if (past_time(fl->fl_downgrade_time))
lease_modify(before, F_RDLCK); lease_modify(before, F_RDLCK, dispose);
if (past_time(fl->fl_break_time)) if (past_time(fl->fl_break_time))
lease_modify(before, F_UNLCK); lease_modify(before, F_UNLCK, dispose);
if (fl == *before) /* lease_modify may have freed fl */ if (fl == *before) /* lease_modify may have freed fl */
before = &fl->fl_next; before = &fl->fl_next;
} }
...@@ -1373,6 +1373,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) ...@@ -1373,6 +1373,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
int i_have_this_lease = 0; int i_have_this_lease = 0;
bool lease_conflict = false; bool lease_conflict = false;
int want_write = (mode & O_ACCMODE) != O_RDONLY; int want_write = (mode & O_ACCMODE) != O_RDONLY;
LIST_HEAD(dispose);
new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK); new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK);
if (IS_ERR(new_fl)) if (IS_ERR(new_fl))
...@@ -1381,7 +1382,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) ...@@ -1381,7 +1382,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
time_out_leases(inode); time_out_leases(inode, &dispose);
flock = inode->i_flock; flock = inode->i_flock;
if ((flock == NULL) || !IS_LEASE(flock)) if ((flock == NULL) || !IS_LEASE(flock))
...@@ -1436,6 +1437,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) ...@@ -1436,6 +1437,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
locks_insert_block(flock, new_fl); locks_insert_block(flock, new_fl);
trace_break_lease_block(inode, new_fl); trace_break_lease_block(inode, new_fl);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
locks_dispose_list(&dispose);
error = wait_event_interruptible_timeout(new_fl->fl_wait, error = wait_event_interruptible_timeout(new_fl->fl_wait,
!new_fl->fl_next, break_time); !new_fl->fl_next, break_time);
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
...@@ -1443,7 +1445,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) ...@@ -1443,7 +1445,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
locks_delete_block(new_fl); locks_delete_block(new_fl);
if (error >= 0) { if (error >= 0) {
if (error == 0) if (error == 0)
time_out_leases(inode); time_out_leases(inode, &dispose);
/* /*
* Wait for the next conflicting lease that has not been * Wait for the next conflicting lease that has not been
* broken yet * broken yet
...@@ -1458,6 +1460,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) ...@@ -1458,6 +1460,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
out: out:
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
locks_dispose_list(&dispose);
locks_free_lock(new_fl); locks_free_lock(new_fl);
return error; return error;
} }
...@@ -1522,9 +1525,10 @@ int fcntl_getlease(struct file *filp) ...@@ -1522,9 +1525,10 @@ int fcntl_getlease(struct file *filp)
struct file_lock *fl; struct file_lock *fl;
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
int type = F_UNLCK; int type = F_UNLCK;
LIST_HEAD(dispose);
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
time_out_leases(file_inode(filp)); time_out_leases(file_inode(filp), &dispose);
for (fl = file_inode(filp)->i_flock; fl && IS_LEASE(fl); for (fl = file_inode(filp)->i_flock; fl && IS_LEASE(fl);
fl = fl->fl_next) { fl = fl->fl_next) {
if (fl->fl_file == filp) { if (fl->fl_file == filp) {
...@@ -1533,6 +1537,7 @@ int fcntl_getlease(struct file *filp) ...@@ -1533,6 +1537,7 @@ int fcntl_getlease(struct file *filp)
} }
} }
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
locks_dispose_list(&dispose);
return type; return type;
} }
...@@ -1570,6 +1575,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr ...@@ -1570,6 +1575,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
bool is_deleg = (*flp)->fl_flags & FL_DELEG; bool is_deleg = (*flp)->fl_flags & FL_DELEG;
int error; int error;
LIST_HEAD(dispose);
lease = *flp; lease = *flp;
trace_generic_add_lease(inode, lease); trace_generic_add_lease(inode, lease);
...@@ -1593,7 +1599,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr ...@@ -1593,7 +1599,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
} }
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
time_out_leases(inode); time_out_leases(inode, &dispose);
error = check_conflicting_open(dentry, arg); error = check_conflicting_open(dentry, arg);
if (error) if (error)
goto out; goto out;
...@@ -1630,7 +1636,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr ...@@ -1630,7 +1636,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
if (my_before != NULL) { if (my_before != NULL) {
lease = *my_before; lease = *my_before;
error = lease->fl_lmops->lm_change(my_before, arg); error = lease->fl_lmops->lm_change(my_before, arg, &dispose);
if (error) if (error)
goto out; goto out;
goto out_setup; goto out_setup;
...@@ -1660,6 +1666,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr ...@@ -1660,6 +1666,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
lease->fl_lmops->lm_setup(lease, priv); lease->fl_lmops->lm_setup(lease, priv);
out: out:
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
locks_dispose_list(&dispose);
if (is_deleg) if (is_deleg)
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
if (!error && !my_before) if (!error && !my_before)
...@@ -1676,8 +1683,10 @@ static int generic_delete_lease(struct file *filp) ...@@ -1676,8 +1683,10 @@ static int generic_delete_lease(struct file *filp)
struct file_lock *fl, **before; struct file_lock *fl, **before;
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;
LIST_HEAD(dispose);
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
time_out_leases(inode, &dispose);
for (before = &inode->i_flock; for (before = &inode->i_flock;
((fl = *before) != NULL) && IS_LEASE(fl); ((fl = *before) != NULL) && IS_LEASE(fl);
before = &fl->fl_next) { before = &fl->fl_next) {
...@@ -1686,8 +1695,9 @@ static int generic_delete_lease(struct file *filp) ...@@ -1686,8 +1695,9 @@ static int generic_delete_lease(struct file *filp)
} }
trace_generic_delete_lease(inode, fl); trace_generic_delete_lease(inode, fl);
if (fl) if (fl)
error = fl->fl_lmops->lm_change(before, F_UNLCK); error = fl->fl_lmops->lm_change(before, F_UNLCK, &dispose);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
locks_dispose_list(&dispose);
return error; return error;
} }
...@@ -2372,7 +2382,7 @@ void locks_remove_file(struct file *filp) ...@@ -2372,7 +2382,7 @@ void locks_remove_file(struct file *filp)
while ((fl = *before) != NULL) { while ((fl = *before) != NULL) {
if (fl->fl_file == filp) { if (fl->fl_file == filp) {
if (IS_LEASE(fl)) { if (IS_LEASE(fl)) {
lease_modify(before, F_UNLCK); lease_modify(before, F_UNLCK, &dispose);
continue; continue;
} }
......
...@@ -3427,11 +3427,11 @@ static void nfsd_break_deleg_cb(struct file_lock *fl) ...@@ -3427,11 +3427,11 @@ static void nfsd_break_deleg_cb(struct file_lock *fl)
spin_unlock(&fp->fi_lock); spin_unlock(&fp->fi_lock);
} }
static static int
int nfsd_change_deleg_cb(struct file_lock **onlist, int arg) nfsd_change_deleg_cb(struct file_lock **onlist, int arg, struct list_head *dispose)
{ {
if (arg & F_UNLCK) if (arg & F_UNLCK)
return lease_modify(onlist, arg); return lease_modify(onlist, arg, dispose);
else else
return -EAGAIN; return -EAGAIN;
} }
......
...@@ -873,7 +873,7 @@ struct lock_manager_operations { ...@@ -873,7 +873,7 @@ struct lock_manager_operations {
void (*lm_notify)(struct file_lock *); /* unblock callback */ void (*lm_notify)(struct file_lock *); /* unblock callback */
int (*lm_grant)(struct file_lock *, int); int (*lm_grant)(struct file_lock *, int);
void (*lm_break)(struct file_lock *); void (*lm_break)(struct file_lock *);
int (*lm_change)(struct file_lock **, int); int (*lm_change)(struct file_lock **, int, struct list_head *);
void (*lm_setup)(struct file_lock *, void **); void (*lm_setup)(struct file_lock *, void **);
}; };
...@@ -985,7 +985,7 @@ extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int t ...@@ -985,7 +985,7 @@ extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int t
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 **, void **priv); extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
extern int vfs_setlease(struct file *, long, struct file_lock **, void **); 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, struct list_head *);
#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,
struct flock __user *user) struct flock __user *user)
...@@ -1112,7 +1112,8 @@ static inline int vfs_setlease(struct file *filp, long arg, ...@@ -1112,7 +1112,8 @@ static inline int vfs_setlease(struct file *filp, long arg,
return -EINVAL; return -EINVAL;
} }
static inline int lease_modify(struct file_lock **before, int arg) static inline int lease_modify(struct file_lock **before, int arg,
struct list_head *dispose)
{ {
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment