提交 4d01b7f5 编写于 作者: J Jeff Layton

locks: give lm_break a return value

Christoph suggests:

   "Add a return value to lm_break so that the lock manager can tell the
    core code "you can delete this lease right now".  That gets rid of
    the games with the timeout which require all kinds of race avoidance
    code in the users."

Do that here and have the nfsd lease break routine use it when it detects
that there was a race between setting up the lease and it being broken.
Signed-off-by: NJeff Layton <jlayton@primarydata.com>
Reviewed-by: NChristoph Hellwig <hch@lst.de>
上级 03d12ddf
...@@ -427,9 +427,11 @@ static int flock_to_posix_lock(struct file *filp, struct file_lock *fl, ...@@ -427,9 +427,11 @@ static int flock_to_posix_lock(struct file *filp, struct file_lock *fl,
} }
/* default lease lock manager operations */ /* default lease lock manager operations */
static void lease_break_callback(struct file_lock *fl) static bool
lease_break_callback(struct file_lock *fl)
{ {
kill_fasync(&fl->fl_fasync, SIGIO, POLL_MSG); kill_fasync(&fl->fl_fasync, SIGIO, POLL_MSG);
return false;
} }
static void static void
...@@ -1382,7 +1384,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) ...@@ -1382,7 +1384,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
{ {
int error = 0; int error = 0;
struct file_lock *new_fl; struct file_lock *new_fl;
struct file_lock *fl; struct file_lock *fl, **before;
unsigned long break_time; unsigned long break_time;
int want_write = (mode & O_ACCMODE) != O_RDONLY; int want_write = (mode & O_ACCMODE) != O_RDONLY;
LIST_HEAD(dispose); LIST_HEAD(dispose);
...@@ -1406,7 +1408,9 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) ...@@ -1406,7 +1408,9 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
break_time++; /* so that 0 means no break time */ break_time++; /* so that 0 means no break time */
} }
for (fl = inode->i_flock; fl && IS_LEASE(fl); fl = fl->fl_next) { for (before = &inode->i_flock;
((fl = *before) != NULL) && IS_LEASE(fl);
before = &fl->fl_next) {
if (!leases_conflict(fl, new_fl)) if (!leases_conflict(fl, new_fl))
continue; continue;
if (want_write) { if (want_write) {
...@@ -1420,9 +1424,14 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) ...@@ -1420,9 +1424,14 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
fl->fl_flags |= FL_DOWNGRADE_PENDING; fl->fl_flags |= FL_DOWNGRADE_PENDING;
fl->fl_downgrade_time = break_time; fl->fl_downgrade_time = break_time;
} }
fl->fl_lmops->lm_break(fl); if (fl->fl_lmops->lm_break(fl))
locks_delete_lock(before, &dispose);
} }
fl = inode->i_flock;
if (!fl || !IS_LEASE(fl))
goto out;
if (mode & O_NONBLOCK) { if (mode & O_NONBLOCK) {
trace_break_lease_noblock(inode, new_fl); trace_break_lease_noblock(inode, new_fl);
error = -EWOULDBLOCK; error = -EWOULDBLOCK;
......
...@@ -3391,18 +3391,20 @@ static void nfsd_break_one_deleg(struct nfs4_delegation *dp) ...@@ -3391,18 +3391,20 @@ static void nfsd_break_one_deleg(struct nfs4_delegation *dp)
} }
/* Called from break_lease() with i_lock held. */ /* Called from break_lease() with i_lock held. */
static void nfsd_break_deleg_cb(struct file_lock *fl) static bool
nfsd_break_deleg_cb(struct file_lock *fl)
{ {
bool ret = false;
struct nfs4_file *fp = (struct nfs4_file *)fl->fl_owner; struct nfs4_file *fp = (struct nfs4_file *)fl->fl_owner;
struct nfs4_delegation *dp; struct nfs4_delegation *dp;
if (!fp) { if (!fp) {
WARN(1, "(%p)->fl_owner NULL\n", fl); WARN(1, "(%p)->fl_owner NULL\n", fl);
return; return ret;
} }
if (fp->fi_had_conflict) { if (fp->fi_had_conflict) {
WARN(1, "duplicate break on %p\n", fp); WARN(1, "duplicate break on %p\n", fp);
return; return ret;
} }
/* /*
* We don't want the locks code to timeout the lease for us; * We don't want the locks code to timeout the lease for us;
...@@ -3414,17 +3416,16 @@ static void nfsd_break_deleg_cb(struct file_lock *fl) ...@@ -3414,17 +3416,16 @@ static void nfsd_break_deleg_cb(struct file_lock *fl)
spin_lock(&fp->fi_lock); spin_lock(&fp->fi_lock);
fp->fi_had_conflict = true; fp->fi_had_conflict = true;
/* /*
* If there are no delegations on the list, then we can't count on this * If there are no delegations on the list, then return true
* lease ever being cleaned up. Set the fl_break_time to jiffies so that * so that the lease code will go ahead and delete it.
* time_out_leases will do it ASAP. The fact that fi_had_conflict is now
* true should keep any new delegations from being hashed.
*/ */
if (list_empty(&fp->fi_delegations)) if (list_empty(&fp->fi_delegations))
fl->fl_break_time = jiffies; ret = true;
else else
list_for_each_entry(dp, &fp->fi_delegations, dl_perfile) list_for_each_entry(dp, &fp->fi_delegations, dl_perfile)
nfsd_break_one_deleg(dp); nfsd_break_one_deleg(dp);
spin_unlock(&fp->fi_lock); spin_unlock(&fp->fi_lock);
return ret;
} }
static int static int
......
...@@ -872,7 +872,7 @@ struct lock_manager_operations { ...@@ -872,7 +872,7 @@ struct lock_manager_operations {
void (*lm_put_owner)(struct file_lock *); void (*lm_put_owner)(struct file_lock *);
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 *); bool (*lm_break)(struct file_lock *);
int (*lm_change)(struct file_lock **, int, struct list_head *); int (*lm_change)(struct file_lock **, int, struct list_head *);
void (*lm_setup)(struct file_lock *, void **); void (*lm_setup)(struct file_lock *, void **);
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册