Skip to content

Commit d2f3a7f

Browse files
jtlaytonamschuma-ntap
authored andcommitted
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 <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 1ea67db commit d2f3a7f

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

fs/nfs/nfs4proc.c

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5530,22 +5530,6 @@ int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4
55305530
return err;
55315531
}
55325532

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-
55495533
static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
55505534
{
55515535
struct inode *inode = state->inode;
@@ -6178,12 +6162,32 @@ static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *
61786162
return err;
61796163
}
61806164

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+
61816186
static int
61826187
nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
61836188
{
61846189
struct nfs_open_context *ctx;
61856190
struct nfs4_state *state;
6186-
unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
61876191
int status;
61886192

61896193
/* verify open state */
@@ -6233,16 +6237,7 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
62336237
if (status != 0)
62346238
return status;
62356239

6236-
do {
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;
6240+
return nfs4_retry_setlk(state, cmd, request);
62466241
}
62476242

62486243
int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid)

0 commit comments

Comments
 (0)