nfs: add CB_NOTIFY_LOCK support to nfs client
Subsystems (2)
v4 cover nfs: add CB_NOTIFY_LOCK support to nfs client
v4:
- reinstate patch to fix read_buf args
- drop patch to check NFS_STATE_POSIX_LOCKS on FL_FLOCK locks
- clean up retry loops. Use while loops instead of do..while and use !signalled() as the condition.
- add a cbnl_valid flag to cb_notify_lock_args to indicate whether decoding worked. s_dev and id could legitimately both be zero.
v3:
- add NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK in a separate patch
- a little cleanup and patch squashing
- changelog cleanups
v2:
- don't use *_unsafe sleep in setlk retry code
- better encapsulate retry logic into helper functions
- don't bother with waitqueue handling if we aren't expecting callback
- fix build when CONFIG_NFS_V4_1 is not set
- address several other style comments
This is the third posting of this patchset. The only real change is a separate patch to add the NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK constant.
This patchset adds support for CB_NOTIFY_LOCK callbacks to the NFS client. The basic idea is to add a waitqueue to the nfs_client and then have blocking lock waiters wait on that queue for callbacks.
When a callback comes in, we use a keyed wakeup to wake any waiters. The waitqueue handling is necessarily more "manual" than I would like, but I don't see a real alternative there given that we need to insert the waiters onto the waitqueue prior to sending the lock request, and sending a lock request can involve blocking operations.
Tested in conjunction with the corresponding knfsd server-side patchset.
Jeff Layton (9):
nfs: the length argument to read_buf should be unsigned
nfs: eliminate pointless and confusing do_vfs_lock wrappers
nfs: use safe, interruptible sleeps when waiting to retry LOCK
nfs: add a new NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK constant
nfs: track whether server sets MAY_NOTIFY_LOCK flag
nfs: add handling for CB_NOTIFY_LOCK in client
nfs: move nfs4_set_lock_state call into caller
nfs: move nfs4 lock retry attempt loop to a separate function
nfs: allow blocking locks to be awoken by lock callbacks
fs/nfs/callback.h | 9 +++ fs/nfs/callback_proc.c | 16 +++++ fs/nfs/callback_xdr.c | 53 +++++++++++++- fs/nfs/file.c | 9 +-- fs/nfs/nfs4_fs.h | 1 + fs/nfs/nfs4client.c | 3 + fs/nfs/nfs4proc.c | 176 ++++++++++++++++++++++++++++++++++------------ include/linux/nfs_fs_sb.h | 3 + include/uapi/linux/nfs4.h | 5 +- 9 files changed, 219 insertions(+), 56 deletions(-)
Signature · 1 line
2.7.4
PATCH v4 1/9 nfs: the length argument to read_buf should be unsigned
Since it gets passed through to xdr_inline_decode, we might as well have read_buf expect what it expects -- a size_t.
--- fs/nfs/callback_xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/callback_xdr.c +1 -1
@@ -72,7 +72,7 @@ static int nfs4_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)return xdr_ressize_check (rqstp, p); } -static __be32 *read_buf (struct xdr_stream *xdr,int nbytes) +static __be32 *read_buf (struct xdr_stream *xdr,size_t nbytes) {__be32 *p;
Signature · 1 line
2.7.4
PATCH v4 2/9 nfs: eliminate pointless and confusing do_vfs_lock wrappers
In reply to Jeff Layton--- fs/nfs/file.c | 9 ++------- fs/nfs/nfs4proc.c | 15 +++++---------- 2 files changed, 7 insertions(+), 17 deletions(-)
fs/nfs/file.c +2 -7
@@ -708,11 +708,6 @@ out_noconflict: goto out; } -static int do_vfs_lock (struct file *file,struct file_lock *fl) -{ -return locks_lock_file_wait (file, fl); -} -static int do_unlk (struct file *filp,int cmd,struct file_lock *fl,int is_local) {
@@ -745,7 +740,7 @@ do_unlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)if (!is_local) status =NFS_PROTO (inode)->lock (filp, cmd, fl);else - status =do_vfs_lock (filp, fl); + status =locks_lock_file_wait (filp, fl);return status; }
@@ -770,7 +765,7 @@ do_setlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)if (!is_local) status =NFS_PROTO (inode)->lock (filp, cmd, fl);else - status =do_vfs_lock (filp, fl); + status =locks_lock_file_wait (filp, fl);if (status <0 ) goto out;
fs/nfs/nfs4proc.c +5 -10
@@ -5600,11 +5600,6 @@ static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *return err; } -static int do_vfs_lock (struct inode *inode,struct file_lock *fl) -{ -return locks_lock_inode_wait (inode, fl); -} -struct nfs4_unlockdata {struct nfs_locku_args arg;struct nfs_locku_res res;
@@ -5657,7 +5652,7 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)switch (task->tk_status) {case 0 :renew_lease (calldata->server, calldata->timestamp); -do_vfs_lock (calldata->lsp->ls_state->inode, &calldata->fl); +locks_lock_inode_wait (calldata->lsp->ls_state->inode, &calldata->fl);if (nfs4_update_lock_stateid (calldata->lsp, &calldata->res.stateid))break ;
@@ -5765,7 +5760,7 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *mutex_lock (&sp->so_delegreturn_mutex);/* Exclude nfs4_reclaim_open_stateid() - note nesting! */ down_read (&nfsi->rwsem); -if (do_vfs_lock (inode, request) == -ENOENT ) { +if (locks_lock_inode_wait (inode, request) == -ENOENT ) {up_read (&nfsi->rwsem);mutex_unlock (&sp->so_delegreturn_mutex); goto out;
@@ -5906,7 +5901,7 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata) data->timestamp);if (data->arg.new_lock) { data->fl.fl_flags &= ~(FL_SLEEP |FL_ACCESS ); -if (do_vfs_lock (lsp->ls_state->inode, &data->fl) <0 ) { +if (locks_lock_inode_wait (lsp->ls_state->inode, &data->fl) <0 ) {rpc_restart_call_prepare (task);break ; }
@@ -6148,7 +6143,7 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lockif (status !=0 ) goto out; request->fl_flags |=FL_ACCESS ; - status =do_vfs_lock (state->inode, request); + status =locks_lock_inode_wait (state->inode, request);if (status <0 ) goto out;mutex_lock (&sp->so_delegreturn_mutex);
@@ -6157,7 +6152,7 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock/* Yes: cache locks! */ /* ...but avoid races with delegation recall... */ request->fl_flags = fl_flags & ~FL_SLEEP ; - status =do_vfs_lock (state->inode, request); + status =locks_lock_inode_wait (state->inode, request);up_read (&nfsi->rwsem);mutex_unlock (&sp->so_delegreturn_mutex); goto out;
Signature · 1 line
2.7.4
PATCH v4 3/9 nfs: use safe, interruptible sleeps when waiting to retry LOCK
In reply to Jeff LaytonWe actually want to use TASK_INTERRUPTIBLE sleeps when we're in the process of polling for a NFSv4 lock. If there is a signal pending when the task wakes up, then we'll be returning an error anyway. So, we might as well wake up immediately for non-fatal signals as well. That allows us to return to userland more quickly in that case, but won't change the error that userland sees.
Also, there is no need to use the *_unsafe sleep variants here, as no vfs-layer locks should be held at this point.
--- fs/nfs/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4proc.c +1 -1
@@ -5537,7 +5537,7 @@ int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4static unsigned long nfs4_set_lock_task_retry (unsigned long timeout) { -freezable_schedule_timeout_killable_unsafe (timeout); +freezable_schedule_timeout_interruptible (timeout); timeout <<=1 ;if (timeout >NFS4_LOCK_MAXTIMEOUT )return NFS4_LOCK_MAXTIMEOUT ;
Signature · 1 line
2.7.4
PATCH v4 4/9 nfs: add a new NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK constant
In reply to Jeff LaytonAs defined in RFC 5661, section 18.16.
--- include/uapi/linux/nfs4.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
include/uapi/linux/nfs4.h +3 -2
@@ -39,8 +39,9 @@#define NFS4_FH_VOL_MIGRATION 0x0004#define NFS4_FH_VOL_RENAME 0x0008 -#define NFS4_OPEN_RESULT_CONFIRM 0x0002 -#define NFS4_OPEN_RESULT_LOCKTYPE_POSIX 0x0004 +#define NFS4_OPEN_RESULT_CONFIRM 0x0002 +#define NFS4_OPEN_RESULT_LOCKTYPE_POSIX 0x0004 +#define NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK 0x0020#define NFS4_SHARE_ACCESS_MASK 0x000F#define NFS4_SHARE_ACCESS_READ 0x0001
Signature · 1 line
2.7.4
PATCH v4 5/9 nfs: track whether server sets MAY_NOTIFY_LOCK flag
In reply to Jeff LaytonWe want to handle the two cases differently, such that we poll more aggressively when we don't expect a callback.
--- fs/nfs/nfs4_fs.h | 1 + fs/nfs/nfs4proc.c | 2 ++ 2 files changed, 3 insertions(+)
fs/nfs/nfs4_fs.h +1 -0
@@ -156,6 +156,7 @@ enum {NFS_STATE_RECLAIM_NOGRACE ,/* OPEN stateid needs to recover state */ NFS_STATE_POSIX_LOCKS ,/* Posix locks are supported */ NFS_STATE_RECOVERY_FAILED ,/* OPEN stateid state recovery failed */ + NFS_STATE_MAY_NOTIFY_LOCK, /* server may CB_NOTIFY_LOCK */ }; struct nfs4_state {
fs/nfs/nfs4proc.c +2 -0
@@ -2537,6 +2537,8 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, goto out;if (server->caps &NFS_CAP_POSIX_LOCK )set_bit (NFS_STATE_POSIX_LOCKS , &state->flags); +if (opendata->o_res.rflags &NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK ) +set_bit (NFS_STATE_MAY_NOTIFY_LOCK , &state->flags); dentry = opendata->dentry;if (d_really_is_negative (dentry)) {
Signature · 1 line
2.7.4
PATCH v4 6/9 nfs: add handling for CB_NOTIFY_LOCK in client
In reply to Jeff LaytonFor now, the callback doesn't do anything. Support for that will be added in later patches.
--- fs/nfs/callback.h | 9 +++++++++ fs/nfs/callback_proc.c | 12 ++++++++++++ fs/nfs/callback_xdr.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 1 deletion(-)
fs/nfs/callback.h +9 -0
@@ -179,6 +179,15 @@ extern __be32 nfs4_callback_devicenotify(struct cb_devicenotifyargs *args, void *dummy, struct cb_process_state *cps); +struct cb_notify_lock_args { +struct nfs_fh cbnl_fh; +struct nfs_lowner cbnl_owner; +bool cbnl_valid; +}; + +extern __be32 nfs4_callback_notify_lock (struct cb_notify_lock_args *args, +void *dummy, +struct cb_process_state *cps);#endif /* CONFIG_NFS_V4_1 */ extern int check_gss_callback_principal (struct nfs_client *,struct svc_rqst *); extern __be32 nfs4_callback_getattr(struct cb_getattrargs *args,
fs/nfs/callback_proc.c +12 -0
@@ -628,4 +628,16 @@ out:dprintk ("%s: exit with status = %d\n" , __func__,ntohl (status)); return status; } + +__be32 nfs4_callback_notify_lock (struct cb_notify_lock_args *args,void *dummy, +struct cb_process_state *cps) +{ +if (!cps->clp)/* set in cb_sequence */ +return htonl (NFS4ERR_OP_NOT_IN_SESSION ); + +dprintk_rcu ("NFS: CB_NOTIFY_LOCK request from %s\n" , +rpc_peeraddr2str (cps->clp->cl_rpcclient,RPC_DISPLAY_ADDR )); + +return htonl (NFS4_OK ); +}#endif /* CONFIG_NFS_V4_1 */
fs/nfs/callback_xdr.c +50 -1
81 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 7/9 nfs: move nfs4_set_lock_state call into caller
In reply to Jeff LaytonWe need to have this info set up before adding the waiter to the waitqueue, so move this out of the _nfs4_proc_setlk and into the caller. That's more efficient anyway since we don't need to do this more than once if we end up waiting on the lock.
--- fs/nfs/nfs4proc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
fs/nfs/nfs4proc.c +10 -8
@@ -6135,15 +6135,8 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lockstruct nfs_inode *nfsi =NFS_I (state->inode);struct nfs4_state_owner *sp = state->owner;unsigned char fl_flags = request->fl_flags; -int status = -ENOLCK ; +int status; -if ((fl_flags &FL_POSIX ) && - !test_bit (NFS_STATE_POSIX_LOCKS , &state->flags)) - goto out; -/* Is this a delegated open? */ - status =nfs4_set_lock_state (state, request); -if (status !=0 ) - goto out; request->fl_flags |=FL_ACCESS ; status =locks_lock_inode_wait (state->inode, request);if (status <0 )
@@ -6217,6 +6210,11 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)if (state ==NULL )return -ENOLCK ; + +if ((request->fl_flags &FL_POSIX ) && + !test_bit (NFS_STATE_POSIX_LOCKS , &state->flags)) +return -ENOLCK ; +/* * Don't rely on the VFS having checked the file open mode, * since it won't do this for flock() locks.
@@ -6231,6 +6229,10 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)return -EBADF ; } + status =nfs4_set_lock_state (state, request); +if (status !=0 ) +return status; + do { status = nfs4_proc_setlk(state, cmd, request); if ((status != -EAGAIN) || IS_SETLK(cmd))
Signature · 1 line
2.7.4
PATCH v4 8/9 nfs: move nfs4 lock retry attempt loop to a separate function
In reply to Jeff LaytonThis also consolidates the waiting logic into a single function, instead of having it spread across two like it is now.
--- fs/nfs/nfs4proc.c | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-)
fs/nfs/nfs4proc.c +22 -27
@@ -5530,22 +5530,6 @@ int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4return err; } -#define NFS4_LOCK_MINTIMEOUT (1 * HZ) -#define NFS4_LOCK_MAXTIMEOUT (30 * HZ) - -/* -* sleep, with exponential backoff, and retry the LOCK operation. -*/ -static unsigned long -nfs4_set_lock_task_retry (unsigned long timeout) -{ -freezable_schedule_timeout_interruptible (timeout); - timeout <<=1 ; -if (timeout >NFS4_LOCK_MAXTIMEOUT ) -return NFS4_LOCK_MAXTIMEOUT ; -return timeout; -} -static int _nfs4_proc_getlk (struct nfs4_state *state,int cmd,struct file_lock *request) {struct inode *inode = state->inode;
@@ -6178,12 +6162,32 @@ static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *return err; } +#define NFS4_LOCK_MINTIMEOUT (1 * HZ) +#define NFS4_LOCK_MAXTIMEOUT (30 * HZ) + +static int +nfs4_retry_setlk (struct nfs4_state *state,int cmd,struct file_lock *request) +{ +int status = -ERESTARTSYS ; +unsigned long timeout =NFS4_LOCK_MINTIMEOUT ; + +while (!signalled ()) { + status =nfs4_proc_setlk (state, cmd, request); +if ((status != -EAGAIN ) ||IS_SETLK (cmd)) +break ; +freezable_schedule_timeout_interruptible (timeout); + timeout *=2 ; + timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); + status = -ERESTARTSYS ; + } +return status; +} +static int nfs4_proc_lock (struct file *filp,int cmd,struct file_lock *request) {struct nfs_open_context *ctx;struct nfs4_state *state; -unsigned long timeout =NFS4_LOCK_MINTIMEOUT ;int status;/* verify open state */
@@ -6233,16 +6237,7 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)if (status !=0 )return status; -do { - status =nfs4_proc_setlk (state, cmd, request); -if ((status != -EAGAIN ) ||IS_SETLK (cmd)) -break ; - timeout =nfs4_set_lock_task_retry (timeout); - status = -ERESTARTSYS ; -if (signalled ()) -break ; - }while (status <0 ); -return status; +return nfs4_retry_setlk (state, cmd, request); }int nfs4_lock_delegation_recall (struct file_lock *fl,struct nfs4_state *state,const nfs4_stateid *stateid)
Signature · 1 line
2.7.4
PATCH v4 9/9 nfs: allow blocking locks to be awoken by lock callbacks
In reply to Jeff LaytonAdd a waitqueue head to the client structure. Have clients set a wait on that queue prior to requesting a lock from the server. If the lock is blocked, then we can use that to wait for wakeups.
Note that we do need to do this "manually" since we need to set the wait on the waitqueue prior to requesting the lock, but requesting a lock can involve activities that can block.
However, only do that for NFSv4.1 locks, either by compiling out all of the waitqueue handling when CONFIG_NFS_V4_1 is disabled, or skipping all of it at runtime if we're dealing with v4.0, or v4.1 servers that don't send lock callbacks.
Note too that even when we expect to get a lock callback, RFC5661 section 20.11.4 is pretty clear that we still need to poll for them, so we do still sleep on a timeout. We do however always poll at the longest interval in that case.
--- fs/nfs/callback_proc.c | 4 ++ fs/nfs/nfs4client.c | 3 ++ fs/nfs/nfs4proc.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++- include/linux/nfs_fs_sb.h | 3 ++ 4 files changed, 103 insertions(+), 1 deletion(-)
fs/nfs/callback_proc.c +4 -0
@@ -638,6 +638,10 @@ __be32 nfs4_callback_notify_lock(struct cb_notify_lock_args *args, void *dummy,dprintk_rcu ("NFS: CB_NOTIFY_LOCK request from %s\n" ,rpc_peeraddr2str (cps->clp->cl_rpcclient,RPC_DISPLAY_ADDR )); +/* Don't wake anybody if the string looked bogus */ +if (args->cbnl_valid) +__wake_up (&cps->clp->cl_lock_waitq,TASK_NORMAL ,0 , args); + return htonl(NFS4_OK); }#endif /* CONFIG_NFS_V4_1 */
fs/nfs/nfs4client.c +3 -0
@@ -199,6 +199,9 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) clp->cl_minorversion = cl_init->minorversion; clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion]; clp->cl_mig_gen =1 ; +#if IS_ENABLED (CONFIG_NFS_V4_1 ) +init_waitqueue_head (&clp->cl_lock_waitq); +#endif return clp; error:
fs/nfs/nfs4proc.c +93 -1
106 lines not on this page · raw message
include/linux/nfs_fs_sb.h +3 -0
@@ -103,6 +103,9 @@ struct nfs_client {#define NFS_SP4_MACH_CRED_WRITE 5/* WRITE */ #define NFS_SP4_MACH_CRED_COMMIT 6/* COMMIT */ #define NFS_SP4_MACH_CRED_PNFS_CLEANUP 7/* LAYOUTRETURN */ +#if IS_ENABLED (CONFIG_NFS_V4_1 ) +wait_queue_head_t cl_lock_waitq; +#endif /* CONFIG_NFS_V4_1 */ #endif /* CONFIG_NFS_V4 */ /* Our own IP address, as a null-terminated string.
Signature · 1 line
2.7.4
Re: [PATCH v4 9/9] nfs: allow blocking locks to be awoken by lock callbacks
Quoted 107 lines · Jeff Layton
Add a waitqueue head to the client structure. Have clients set a wait on that queue prior to requesting a lock from the server. If the lock is blocked, then we can use that to wait for wakeups.
Note that we do need to do this "manually" since we need to set the wait on the waitqueue prior to requesting the lock, but requesting a lock can involve activities that can block.
However, only do that for NFSv4.1 locks, either by compiling out all of the waitqueue handling when
CONFIG_NFS_V4_1is disabled, or skipping all of it at runtime if we're dealing with v4.0, or v4.1 servers that don't send lock callbacks.Note too that even when we expect to get a lock callback, RFC5661 section 20.11.4 is pretty clear that we still need to poll for them, so we do still sleep on a timeout. We do however always poll at the longest interval in that case.
Quoted 1 line
Signed-off-by Jeff Layton <[email protected]>---
fs/nfs/callback_proc.c | 4 ++
fs/nfs/nfs4client.c | 3 ++
fs/nfs/nfs4proc.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++-include/linux/nfs_fs_sb.h| 3 ++4 files changed, 103 insertions(+), 1 deletion(-)fs/nfs/callback_proc.c +0
-0@@ -638,6 +638,10 @@ __be32 nfs4_callback_notify_lock(struct cb_notify_lock_args *args, void *dummy, > dprintk_rcu("NFS: CB_NOTIFY_LOCK request from %s\n", > rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));fs/nfs/callback_proc.c __be32 nfs4_callback_notify_lock(struct cb_notify_lock_args *args, void *dummy, · line 643
Quoted 3 lines
fs/nfs/callback_proc.c +3
-0+/* Don't wake anybody if the string looked bogus */ +if (args->cbnl_valid) +__wake_up (&cps->clp->cl_lock_waitq,TASK_NORMAL ,0 , args);+
Quoted 1 line
return
htonl(NFS4_OK);}
#endif /*CONFIG_NFS_V4_1*/fs/nfs/nfs4client.c +2
-0@@ -199,6 +199,9 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) > clp->cl_minorversion = cl_init->minorversion; > clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion]; > clp->cl_mig_gen = 1; +#if IS_ENABLED (CONFIG_NFS_V4_1 ) > + init_waitqueue_head(&clp->cl_lock_waitq); +#endif > return clp;
error:fs/nfs/nfs4proc.c +0
-0@@ -6166,7 +6166,8 @@ static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock * #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
static intfs/nfs/nfs4proc.c +1
-1-nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) +nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd,fs/nfs/nfs4proc.c static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock * · line 6170
Quoted 1 line
fs/nfs/nfs4proc.c +1
-0+ struct file_lock *request){
Quoted 2 lines
Quoted 2 lines
int status =
-ERESTARTSYS;
unsigned long timeout =NFS4_LOCK_MINTIMEOUT;fs/nfs/nfs4proc.c +0
-0@@ -6183,6 +6184,97 @@ nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) > return status; }fs/nfs/nfs4proc.c +2
-0+#ifdef CONFIG_NFS_V4_1 +struct nfs4_lock_waiter {Quoted 4 lines
Quoted 4 lines
fs/nfs/nfs4proc.c +4
-0+struct task_struct *task; +struct inode *inode; +struct nfs_lowner *owner; +bool notified;fs/nfs/nfs4proc.c +5
-0+}; + +static int +nfs4_wake_lock_waiter (wait_queue_t *wait,unsigned int mode,int flags,void *key) +{fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6202
Quoted 5 lines
fs/nfs/nfs4proc.c +2
-0+int ret; +struct cb_notify_lock_args *cbnl = key;Quoted 2 lines
Quoted 1 line
fs/nfs/nfs4proc.c +1
-0+struct nfs4_lock_waiter *waiter = wait->private;fs/nfs/nfs4proc.c +1
-0+ struct nfs_lowner *lowner = &cbnl->cbnl_owner,fs/nfs/nfs4proc.c +1
-0+ *wowner = waiter->owner;+
Review
Quoted 5 lines
fs/nfs/nfs4proc.c +2
-0+/* Only wake if the callback was for the same owner */ + if (lowner->clientid != wowner->clientid ||Quoted 1 line
fs/nfs/nfs4proc.c +1
-0+ lowner->id != wowner->id ||(quoted diff) +2
-0+ lowner->s_dev != wowner->s_dev) + return 0;+
fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6212
Quoted 3 lines
fs/nfs/nfs4proc.c +3
-0+/* Make sure it's for the right inode */ +if (nfs_compare_fh (NFS_FH (waiter->inode), &cbnl->cbnl_fh)) +return 0 ;+
fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6214
Quoted 1 line
fs/nfs/nfs4proc.c +1
-0+ waiter->notified = true;+
Quoted 5 lines
fs/nfs/nfs4proc.c +5
-0+/* override "private" so we can use default_wake_function */ + wait->private = waiter->task; + ret =autoremove_wake_function (wait, mode, flags, key); + wait->private = waiter; +return ret;
fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6226
Quoted 6 lines
fs/nfs/nfs4proc.c +6
-0+} + +static int +nfs4_retry_setlk (struct nfs4_state *state,int cmd,struct file_lock *request) +{ +int status;
Whoops! We can end up returning an uninitialized value if signalled() is true when we hit the while loop below. Need to initialize that to -ERESTARTSYS here.
Now why didn't the compiler catch that? Hmmm...
Quoted 68 lines
fs/nfs/nfs4proc.c +1
-0+unsigned long flags;fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6239
Quoted 12 lines
fs/nfs/nfs4proc.c +12
-0+struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; +struct nfs_server *server =NFS_SERVER (state->inode); +struct nfs_client *clp = server->nfs_client; +wait_queue_head_t *q = &clp->cl_lock_waitq; +struct nfs_lowner owner = { .clientid = clp->cl_clientid, + .id = lsp->ls_seqid.owner_id, + .s_dev = server->s_dev }; + struct nfs4_lock_waiter waiter = { .task = current, + .inode = state->inode, + .owner = &owner, + .notified = false }; +wait_queue_t wait;+
fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6243
Quoted 3 lines
fs/nfs/nfs4proc.c +3
-0+/* Don't bother with waitqueue if we don't expect a callback */ +if (!test_bit (NFS_STATE_MAY_NOTIFY_LOCK , &state->flags)) +return nfs4_retry_setlk_simple (state, cmd, request);+
fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6248
Quoted 4 lines
fs/nfs/nfs4proc.c +4
-0+init_wait (&wait); + wait.private = &waiter; + wait.func = nfs4_wake_lock_waiter; +add_wait_queue (q, &wait);+
fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6253
Quoted 4 lines
fs/nfs/nfs4proc.c +4
-0+while (!signalled ()) { + status =nfs4_proc_setlk (state, cmd, request); +if ((status != -EAGAIN ) ||IS_SETLK (cmd)) +break ;+
fs/nfs/nfs4proc.c nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) · line 6262
Quoted 8 lines
fs/nfs/nfs4proc.c +8
-0+ status = -ERESTARTSYS ; +spin_lock_irqsave (&q->lock, flags); +if (waiter.notified) { +spin_unlock_irqrestore (&q->lock, flags); +continue ; + } +set_current_state (TASK_INTERRUPTIBLE ); +spin_unlock_irqrestore (&q->lock, flags);+
Review
Quoted 2 lines
(quoted diff) +2
-0+ freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); + }+
Quoted 2 lines
fs/nfs/nfs4proc.c +2
-0+finish_wait (q, &wait); +return status;fs/nfs/nfs4proc.c +5
-0+} +#else /* !CONFIG_NFS_V4_1 */ +static inline int +nfs4_retry_setlk (struct nfs4_state *state,int cmd,struct file_lock *request) +{Quoted 1 line
(quoted diff) +1
-0+ return nfs4_retry_setlk_simple(state, cmd, request);fs/nfs/nfs4proc.c +3
-0+} +#endif +static int
nfs4_proc_lock(struct file *filp, int cmd, structfile_lock*request) {include/linux/nfs_fs_sb.h +0
-0@@ -103,6 +103,9 @@ struct nfs_client {Quoted 2 lines
#define NFS_SP4_MACH_CRED_WRITE 5 /* WRITE */
#define NFS_SP4_MACH_CRED_COMMIT 6 /* COMMIT */#define NFS_SP4_MACH_CRED_PNFS_CLEANUP 7 /* LAYOUTRETURN */ +#if
IS_ENABLED(CONFIG_NFS_V4_1)Quoted 1 line
include/linux/nfs_fs_sb.h struct nfs_client { · line 107
Quoted 1 line
include/linux/nfs_fs_sb.h +1
-0+wait_queue_head_t cl_lock_waitq;+#endif /*
CONFIG_NFS_V4_1*/
#endif /*CONFIG_NFS_V4*/Quoted 1 line
/* Our own IP address, as a null-terminated string.
Signature · 1 line
Jeff Layton <[email protected]>