diff options
author | Jeff Layton <jlayton@redhat.com> | 2016-09-17 18:17:38 -0400 |
---|---|---|
committer | Anna Schumaker <Anna.Schumaker@Netapp.com> | 2016-09-22 13:56:04 -0400 |
commit | d2f3a7f9187b0c6a64276d598cd6157437c5a336 (patch) | |
tree | 5d74722f59c3f6bfa46e3b31ee4adce552e67df5 /fs/nfs | |
parent | 1ea67dbd9828278188fb846972c3c368b0ef23a1 (diff) |
nfs: move nfs4 lock retry attempt loop to a separate function
This also consolidates the waiting logic into a single function,
instead of having it spread across two like it is now.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r-- | fs/nfs/nfs4proc.c | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index ffadf6be3668..a74c4167b5b0 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -5530,22 +5530,6 @@ int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4 | |||
5530 | return err; | 5530 | return err; |
5531 | } | 5531 | } |
5532 | 5532 | ||
5533 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) | ||
5534 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) | ||
5535 | |||
5536 | /* | ||
5537 | * sleep, with exponential backoff, and retry the LOCK operation. | ||
5538 | */ | ||
5539 | static unsigned long | ||
5540 | nfs4_set_lock_task_retry(unsigned long timeout) | ||
5541 | { | ||
5542 | freezable_schedule_timeout_interruptible(timeout); | ||
5543 | timeout <<= 1; | ||
5544 | if (timeout > NFS4_LOCK_MAXTIMEOUT) | ||
5545 | return NFS4_LOCK_MAXTIMEOUT; | ||
5546 | return timeout; | ||
5547 | } | ||
5548 | |||
5549 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 5533 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
5550 | { | 5534 | { |
5551 | struct inode *inode = state->inode; | 5535 | struct inode *inode = state->inode; |
@@ -6178,12 +6162,32 @@ static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock * | |||
6178 | return err; | 6162 | return err; |
6179 | } | 6163 | } |
6180 | 6164 | ||
6165 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) | ||
6166 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) | ||
6167 | |||
6168 | static int | ||
6169 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | ||
6170 | { | ||
6171 | int status = -ERESTARTSYS; | ||
6172 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; | ||
6173 | |||
6174 | while(!signalled()) { | ||
6175 | status = nfs4_proc_setlk(state, cmd, request); | ||
6176 | if ((status != -EAGAIN) || IS_SETLK(cmd)) | ||
6177 | break; | ||
6178 | freezable_schedule_timeout_interruptible(timeout); | ||
6179 | timeout *= 2; | ||
6180 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); | ||
6181 | status = -ERESTARTSYS; | ||
6182 | } | ||
6183 | return status; | ||
6184 | } | ||
6185 | |||
6181 | static int | 6186 | static int |
6182 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) | 6187 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
6183 | { | 6188 | { |
6184 | struct nfs_open_context *ctx; | 6189 | struct nfs_open_context *ctx; |
6185 | struct nfs4_state *state; | 6190 | struct nfs4_state *state; |
6186 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; | ||
6187 | int status; | 6191 | int status; |
6188 | 6192 | ||
6189 | /* verify open state */ | 6193 | /* verify open state */ |
@@ -6233,16 +6237,7 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) | |||
6233 | if (status != 0) | 6237 | if (status != 0) |
6234 | return status; | 6238 | return status; |
6235 | 6239 | ||
6236 | do { | 6240 | return nfs4_retry_setlk(state, cmd, request); |
6237 | status = nfs4_proc_setlk(state, cmd, request); | ||
6238 | if ((status != -EAGAIN) || IS_SETLK(cmd)) | ||
6239 | break; | ||
6240 | timeout = nfs4_set_lock_task_retry(timeout); | ||
6241 | status = -ERESTARTSYS; | ||
6242 | if (signalled()) | ||
6243 | break; | ||
6244 | } while(status < 0); | ||
6245 | return status; | ||
6246 | } | 6241 | } |
6247 | 6242 | ||
6248 | int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid) | 6243 | int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid) |