Fix up soft mounts for NFSv4.x
Subsystems (4)
cover Fix up soft mounts for NFSv4.x
This patchset aims to make soft mounts a viable option for NFSv4 clients by minimising the risk of false positive timeouts, while allowing for faster failover of reads and writes once a timeout is actually observed.
The patches rely on the NFS server correctly implementing the contract specified in RFC7530 section 3.1.1 with respect to not dropping requests while the transport connection is up. When this is the case, the client can safely assume that if the request has not received a reply after transmitting a RPC request, it is not because the request was dropped, but rather is due to congestion, or slow processing on the server.
IOW: as long as the connection remains up, there is no need for requests to time out.
The patches break down roughly as follows:
- A set of patches to clean up the RPC engine timeouts, and ensure they are accurate.
- A set of patches to change the 'soft' mount semantics for NFSv4.x.
- A set of patches to add a new 'softerr' mount option that works like soft, but explicitly signals timeouts using the ETIMEDOUT error code rather than using EIO. This allows applications to tune their behaviour (e.g. by failing over to a different server) if a timeout occurs.
- A set of patches to change the NFS error reporting so that it matches that of local filesystems w.r.t. guarantees that filesystem errors are seen once and once only.
- A patch to ensure the safe interruption of NFS4ERR_DELAYed operations
- A patch to ensure that pNFS operations can be forced to break out of layout error cycles after a certain number of retries.
- A few cleanups...
Trond Myklebust (25):
SUNRPC: Fix up task signalling
SUNRPC: Refactor rpc_restart_call/rpc_restart_call_prepare
SUNRPC: Refactor xprt_request_wait_receive()
SUNRPC: Refactor rpc_sleep_on()
SUNRPC: Remove unused argument 'action' from rpc_sleep_on_priority()
SUNRPC: Add function rpc_sleep_on_timeout()
SUNRPC: Fix up tracking of timeouts
SUNRPC: Ensure that the transport layer respect major timeouts
SUNRPC: Add tracking of RPC level errors
SUNRPC: Make "no retrans timeout" soft tasks behave like softconn for
timeouts
SUNRPC: Start the first major timeout calculation at task creation
SUNRPC: Add the 'softerr' rpc_client flag
NFS: Consider ETIMEDOUT to be a fatal error
NFS: Move internal constants out of uapi/linux/nfs_mount.h
NFS: Add a mount option "softerr" to allow clients to see ETIMEDOUT
errors
NFS: Don't interrupt file writeout due to fatal errors
NFS: Don't call generic_error_remove_page() while holding locks
NFS: Don't inadvertently clear writeback errors
NFS: Replace custom error reporting mechanism with generic one
NFS: Fix up NFS I/O subrequest creation
NFS: Remove unused argument from nfs_create_request()
pNFS: Add tracking to limit the number of pNFS retries
NFS: Allow signal interruption of NFS4ERR_DELAYed operations
NFS: Add a helper to return a pointer to the open context of a struct
nfs_page
NFS: Remove redundant open context from nfs_page
fs/lockd/clntproc.c | 4 +- fs/nfs/client.c | 2 + fs/nfs/direct.c | 11 +- fs/nfs/file.c | 31 +--- fs/nfs/filelayout/filelayout.c | 4 +- fs/nfs/flexfilelayout/flexfilelayout.c | 14 +- fs/nfs/internal.h | 7 +- fs/nfs/nfs4_fs.h | 1 + fs/nfs/nfs4file.c | 2 +- fs/nfs/nfs4proc.c | 159 +++++++++++++++------ fs/nfs/pagelist.c | 122 +++++++++------- fs/nfs/pnfs.c | 4 +- fs/nfs/pnfs.h | 4 +- fs/nfs/read.c | 6 +- fs/nfs/super.c | 15 +- fs/nfs/write.c | 67 +++++---- fs/nfsd/nfs4callback.c | 4 +- include/linux/nfs_fs.h | 1 - include/linux/nfs_fs_sb.h | 10 ++ include/linux/nfs_page.h | 12 +- include/linux/sunrpc/clnt.h | 2 + include/linux/sunrpc/sched.h | 19 ++- include/linux/sunrpc/xprt.h | 6 +- include/trace/events/sunrpc.h | 8 +- include/uapi/linux/nfs_mount.h | 9 -- net/sunrpc/auth_gss/auth_gss.c | 5 +- net/sunrpc/clnt.c | 105 ++++++++------ net/sunrpc/debugfs.c | 2 +- net/sunrpc/rpcb_clnt.c | 3 +- net/sunrpc/sched.c | 152 +++++++++++++++----- net/sunrpc/xprt.c | 146 ++++++++++++------- net/sunrpc/xprtrdma/svc_rdma_backchannel.c | 2 +- net/sunrpc/xprtrdma/transport.c | 2 +- net/sunrpc/xprtsock.c | 9 +- 34 files changed, 619 insertions(+), 331 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/25 SUNRPC: Fix up task signalling
The RPC_TASK_KILLED flag should really not be set from another context because it can clobber data in the struct task when task->tk_flags is changed non-atomically.
Let's therefore swap out RPC_TASK_KILLED with an atomic flag, and add a function to set that flag and safely wake up the task.
--- fs/lockd/clntproc.c | 4 ++-- fs/nfsd/nfs4callback.c | 4 ++-- include/linux/sunrpc/sched.h | 6 ++++-- include/trace/events/sunrpc.h | 6 +++--- net/sunrpc/clnt.c | 14 ++------------ net/sunrpc/sched.c | 28 +++++++++++++++++++++++----- net/sunrpc/xprt.c | 4 ++++ 7 files changed, 40 insertions(+), 26 deletions(-)
fs/lockd/clntproc.c +2 -2
@@ -715,7 +715,7 @@ static void nlmclnt_unlock_callback(struct rpc_task *task, void *data)struct nlm_rqst *req = data;u32 status =ntohl (req->a_res.status); -if (RPC_ASSASSINATED (task)) +if (RPC_SIGNALLED (task)) goto die;if (task->tk_status <0 ) {
@@ -783,7 +783,7 @@ static void nlmclnt_cancel_callback(struct rpc_task *task, void *data)struct nlm_rqst *req = data;u32 status =ntohl (req->a_res.status); -if (RPC_ASSASSINATED (task)) +if (RPC_SIGNALLED (task)) goto die;if (task->tk_status <0 ) {
fs/nfsd/nfs4callback.c +2 -2
@@ -1032,7 +1032,7 @@ static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback* the submission code will error out, so we don't need to * handle that case here. */ -if (task->tk_flags &RPC_TASK_KILLED ) +if (RPC_SIGNALLED (task)) goto need_restart;return true;
@@ -1081,7 +1081,7 @@ static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callbackdprintk ("%s: freed slot, new seqid=%d\n" , __func__, clp->cl_cb_session->se_cb_seq_nr); -if (task->tk_flags &RPC_TASK_KILLED ) +if (RPC_SIGNALLED (task)) goto need_restart; out:return ret;
include/linux/sunrpc/sched.h +4 -2
@@ -125,7 +125,6 @@ struct rpc_task_setup {#define RPC_CALL_MAJORSEEN 0x0020/* major timeout seen */ #define RPC_TASK_ROOTCREDS 0x0040/* force root creds */ #define RPC_TASK_DYNAMIC 0x0080/* task was kmalloc'ed */ -#define RPC_TASK_KILLED 0x0100/* task was killed */ #define RPC_TASK_SOFT 0x0200/* Use soft timeouts */ #define RPC_TASK_SOFTCONN 0x0400/* Fail if can't connect */ #define RPC_TASK_SENT 0x0800/* message was sent */
@@ -135,7 +134,6 @@ struct rpc_task_setup {#define RPC_IS_ASYNC (t) ((t)->tk_flags & RPC_TASK_ASYNC)#define RPC_IS_SWAPPER (t) ((t)->tk_flags & RPC_TASK_SWAPPER) -#define RPC_ASSASSINATED (t) ((t)->tk_flags & RPC_TASK_KILLED)#define RPC_IS_SOFT (t) ((t)->tk_flags & (RPC_TASK_SOFT|RPC_TASK_TIMEOUT))#define RPC_IS_SOFTCONN (t) ((t)->tk_flags & RPC_TASK_SOFTCONN)#define RPC_WAS_SENT (t) ((t)->tk_flags & RPC_TASK_SENT)
@@ -146,6 +144,7 @@ struct rpc_task_setup {#define RPC_TASK_NEED_XMIT 3#define RPC_TASK_NEED_RECV 4#define RPC_TASK_MSG_PIN_WAIT 5 +#define RPC_TASK_SIGNALLED 6#define RPC_IS_RUNNING (t) test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)#define rpc_set_running (t) set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
@@ -169,6 +168,8 @@ struct rpc_task_setup {#define RPC_IS_ACTIVATED (t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate) +#define RPC_SIGNALLED (t) test_bit(RPC_TASK_SIGNALLED, &(t)->tk_runstate) +/* * Task priorities. * Note: if you change these, you must also change
@@ -217,6 +218,7 @@ struct rpc_task *rpc_run_task(const struct rpc_task_setup *);struct rpc_task *rpc_run_bc_task (struct rpc_rqst *req);void rpc_put_task (struct rpc_task *);void rpc_put_task_async (struct rpc_task *); +void rpc_signal_task (struct rpc_task *);void rpc_exit_task (struct rpc_task *);void rpc_exit (struct rpc_task *,int );void rpc_release_calldata (const struct rpc_call_ops *,void *);
include/trace/events/sunrpc.h +3 -3
@@ -82,7 +82,6 @@ TRACE_DEFINE_ENUM(RPC_TASK_SWAPPER);TRACE_DEFINE_ENUM (RPC_CALL_MAJORSEEN );TRACE_DEFINE_ENUM (RPC_TASK_ROOTCREDS );TRACE_DEFINE_ENUM (RPC_TASK_DYNAMIC ); -TRACE_DEFINE_ENUM (RPC_TASK_KILLED );TRACE_DEFINE_ENUM (RPC_TASK_SOFT );TRACE_DEFINE_ENUM (RPC_TASK_SOFTCONN );TRACE_DEFINE_ENUM (RPC_TASK_SENT );
@@ -97,7 +96,6 @@ TRACE_DEFINE_ENUM(RPC_TASK_NO_RETRANS_TIMEOUT); { RPC_CALL_MAJORSEEN, "MAJORSEEN" }, \ { RPC_TASK_ROOTCREDS, "ROOTCREDS" }, \ { RPC_TASK_DYNAMIC, "DYNAMIC" }, \ - { RPC_TASK_KILLED, "KILLED" }, \ { RPC_TASK_SOFT, "SOFT" }, \ { RPC_TASK_SOFTCONN, "SOFTCONN" }, \ { RPC_TASK_SENT, "SENT" }, \
@@ -111,6 +109,7 @@ TRACE_DEFINE_ENUM(RPC_TASK_ACTIVE);TRACE_DEFINE_ENUM (RPC_TASK_NEED_XMIT );TRACE_DEFINE_ENUM (RPC_TASK_NEED_RECV );TRACE_DEFINE_ENUM (RPC_TASK_MSG_PIN_WAIT ); +TRACE_DEFINE_ENUM (RPC_TASK_SIGNALLED );#define rpc_show_runstate (flags) \ __print_flags(flags, "|", \
@@ -119,7 +118,8 @@ TRACE_DEFINE_ENUM(RPC_TASK_MSG_PIN_WAIT); { (1UL << RPC_TASK_ACTIVE), "ACTIVE" }, \ { (1UL << RPC_TASK_NEED_XMIT), "NEED_XMIT" }, \ { (1UL << RPC_TASK_NEED_RECV), "NEED_RECV" }, \ - { (1UL << RPC_TASK_MSG_PIN_WAIT), "MSG_PIN_WAIT" }) + { (1UL << RPC_TASK_MSG_PIN_WAIT), "MSG_PIN_WAIT" }, \ + { (1UL << RPC_TASK_SIGNALLED), "SIGNALLED" }) DECLARE_EVENT_CLASS(rpc_task_running,
net/sunrpc/clnt.c +2 -12
@@ -827,14 +827,8 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)* Spin lock all_tasks to prevent changes... */ spin_lock (&clnt->cl_lock); -list_for_each_entry (rovr, &clnt->cl_tasks, tk_task) { -if (!RPC_IS_ACTIVATED (rovr)) -continue ; -if (!(rovr->tk_flags &RPC_TASK_KILLED )) { - rovr->tk_flags |=RPC_TASK_KILLED ; -rpc_exit (rovr, -EIO ); - } - } +list_for_each_entry (rovr, &clnt->cl_tasks, tk_task) +rpc_signal_task (rovr);spin_unlock (&clnt->cl_lock); }EXPORT_SYMBOL_GPL (rpc_killall_tasks);
@@ -1477,8 +1471,6 @@ EXPORT_SYMBOL_GPL(rpc_force_rebind);int rpc_restart_call_prepare (struct rpc_task *task) { -if (RPC_ASSASSINATED (task)) -return 0 ; task->tk_action = call_start; task->tk_status =0 ;if (task->tk_ops->rpc_call_prepare !=NULL )
@@ -1494,8 +1486,6 @@ EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);int rpc_restart_call (struct rpc_task *task) { -if (RPC_ASSASSINATED (task)) -return 0 ; task->tk_action = call_start; task->tk_status =0 ;return 1 ;
net/sunrpc/sched.c +23 -5
@@ -759,8 +759,7 @@ static void rpc_reset_task_statistics(struct rpc_task *task) { task->tk_timeouts =0 ; - task->tk_flags &= ~(RPC_CALL_MAJORSEEN |RPC_TASK_KILLED |RPC_TASK_SENT ); - + task->tk_flags &= ~(RPC_CALL_MAJORSEEN |RPC_TASK_SENT );rpc_init_task_statistics (task); }
@@ -773,7 +772,6 @@ void rpc_exit_task(struct rpc_task *task)if (task->tk_ops->rpc_call_done !=NULL ) { task->tk_ops->rpc_call_done (task, task->tk_calldata);if (task->tk_action !=NULL ) { -WARN_ON (RPC_ASSASSINATED (task));/* Always release the RPC slot and buffer memory */ xprt_release (task);rpc_reset_task_statistics (task);
@@ -781,6 +779,19 @@ void rpc_exit_task(struct rpc_task *task) } } +void rpc_signal_task (struct rpc_task *task) +{ +struct rpc_wait_queue *queue; + +if (!RPC_IS_ACTIVATED (task)) +return ; +set_bit (RPC_TASK_SIGNALLED , &task->tk_runstate); +smp_mb__after_atomic (); + queue =READ_ONCE (task->tk_waitqueue); +if (queue) +rpc_wake_up_queued_task_set_status (queue, task, -ERESTARTSYS ); +} +void rpc_exit (struct rpc_task *task,int status) { task->tk_status = status;
@@ -836,6 +847,13 @@ static void __rpc_execute(struct rpc_task *task)*/ if (!RPC_IS_QUEUED (task))continue ; + +/* +* Signalled tasks should exit rather than sleep. +*/ +if (RPC_SIGNALLED (task)) +rpc_exit (task, -ERESTARTSYS ); +/* * The queue->lock protects against races with * rpc_make_runnable().
@@ -861,7 +879,7 @@ static void __rpc_execute(struct rpc_task *task) status =out_of_line_wait_on_bit (&task->tk_runstate,RPC_TASK_QUEUED , rpc_wait_bit_killable,TASK_KILLABLE ); -if (status == -ERESTARTSYS ) { +if (status <0 ) {/* * When a sync task receives a signal, it exits with * -ERESTARTSYS. In order to catch any callbacks that
@@ -869,7 +887,7 @@ static void __rpc_execute(struct rpc_task *task)* break the loop here, but go around once more. */ dprintk ("RPC: %5u got signal\n" , task->tk_pid); - task->tk_flags |=RPC_TASK_KILLED ; +set_bit (RPC_TASK_SIGNALLED , &task->tk_runstate);rpc_exit (task, -ERESTARTSYS ); }dprintk ("RPC: %5u sync task resuming\n" , task->tk_pid);
net/sunrpc/xprt.c +4 -0
@@ -1337,6 +1337,10 @@ xprt_request_transmit(struct rpc_rqst *req, struct rpc_task *snd_task)if (status <0 ) goto out_dequeue; } +if (RPC_SIGNALLED (task)) { + status = -ERESTARTSYS ; + goto out_dequeue; + } }/*
Signature · 1 line
2.20.1
PATCH 2/25 SUNRPC: Refactor rpc_restart_call/rpc_restart_call_prepare
Clean up.
--- net/sunrpc/clnt.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
net/sunrpc/clnt.c +17 -13
@@ -1464,20 +1464,13 @@ void rpc_force_rebind(struct rpc_clnt *clnt) }EXPORT_SYMBOL_GPL (rpc_force_rebind); -/* -* Restart an (async) RPC call from the call_prepare state. -* Usually called from within the exit handler. -*/ -int -rpc_restart_call_prepare (struct rpc_task *task) +static int +__rpc_restart_call (struct rpc_task *task,void (*action)(struct rpc_task *)) { - task->tk_action = call_start; task->tk_status =0 ; -if (task->tk_ops->rpc_call_prepare !=NULL ) - task->tk_action = rpc_prepare_task; + task->tk_action = action;return 1 ; } -EXPORT_SYMBOL_GPL (rpc_restart_call_prepare);/* * Restart an (async) RPC call. Usually called from within the
@@ -1486,12 +1479,23 @@ EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);int rpc_restart_call (struct rpc_task *task) { - task->tk_action = call_start; - task->tk_status =0 ; -return 1 ; +return __rpc_restart_call (task, call_start); }EXPORT_SYMBOL_GPL (rpc_restart_call); +/* +* Restart an (async) RPC call from the call_prepare state. +* Usually called from within the exit handler. +*/ +int +rpc_restart_call_prepare (struct rpc_task *task) +{ +if (task->tk_ops->rpc_call_prepare !=NULL ) +return __rpc_restart_call (task, rpc_prepare_task); +return rpc_restart_call (task); +} +EXPORT_SYMBOL_GPL (rpc_restart_call_prepare); +const char *rpc_proc_name (const struct rpc_task *task) {
Signature · 1 line
2.20.1
PATCH 3/25 SUNRPC: Refactor xprt_request_wait_receive()
Convert the transport callback to actually put the request to sleep instead of just setting a timeout. This is in preparation for rpc_sleep_on_timeout().
--- include/linux/sunrpc/xprt.h | 6 +- net/sunrpc/xprt.c | 79 ++++++++++++---------- net/sunrpc/xprtrdma/svc_rdma_backchannel.c | 2 +- net/sunrpc/xprtrdma/transport.c | 2 +- net/sunrpc/xprtsock.c | 8 +-- 5 files changed, 51 insertions(+), 46 deletions(-)
include/linux/sunrpc/xprt.h +3 -3
@@ -143,7 +143,7 @@ struct rpc_xprt_ops {void (*buf_free)(struct rpc_task *task);void (*prepare_request)(struct rpc_rqst *req);int (*send_request)(struct rpc_rqst *req); -void (*set_retrans_timeout)(struct rpc_task *task); +void (*wait_for_reply_request)(struct rpc_task *task);void (*timer)(struct rpc_xprt *xprt,struct rpc_task *task);void (*release_request)(struct rpc_task *task);void (*close)(struct rpc_xprt *xprt);
@@ -378,8 +378,8 @@ xprt_disable_swap(struct rpc_xprt *xprt)int xprt_register_transport (struct xprt_class *type);int xprt_unregister_transport (struct xprt_class *type);int xprt_load_transport (const char *); -void xprt_set_retrans_timeout_def (struct rpc_task *task); -void xprt_set_retrans_timeout_rtt (struct rpc_task *task); +void xprt_wait_for_reply_request_def (struct rpc_task *task); +void xprt_wait_for_reply_request_rtt (struct rpc_task *task);void xprt_wake_pending_tasks (struct rpc_xprt *xprt,int status);void xprt_wait_for_buffer_space (struct rpc_xprt *xprt);bool xprt_write_space (struct rpc_xprt *xprt);
net/sunrpc/xprt.c +42 -37
97 lines not on this page · raw message
net/sunrpc/xprtrdma/svc_rdma_backchannel.c +1 -1
@@ -261,7 +261,7 @@ static const struct rpc_xprt_ops xprt_rdma_bc_procs = { .buf_alloc = xprt_rdma_bc_allocate, .buf_free = xprt_rdma_bc_free, .send_request = xprt_rdma_bc_send_request, - .set_retrans_timeout = xprt_set_retrans_timeout_def, + .wait_for_reply_request = xprt_wait_for_reply_request_def, .close = xprt_rdma_bc_close, .destroy = xprt_rdma_bc_put, .print_stats = xprt_rdma_print_stats
net/sunrpc/xprtrdma/transport.c +1 -1
@@ -815,7 +815,7 @@ static const struct rpc_xprt_ops xprt_rdma_procs = { .alloc_slot = xprt_rdma_alloc_slot, .free_slot = xprt_rdma_free_slot, .release_request = xprt_release_rqst_cong, /* ditto */ - .set_retrans_timeout = xprt_set_retrans_timeout_def, /* ditto */ + .wait_for_reply_request = xprt_wait_for_reply_request_def, /* ditto */ .timer = xprt_rdma_timer, .rpcbind = rpcb_getport_async, /* sunrpc/rpcb_clnt.c */ .set_port = xprt_rdma_set_port,
net/sunrpc/xprtsock.c +4 -4
@@ -2690,7 +2690,7 @@ static const struct rpc_xprt_ops xs_local_ops = { .buf_free = rpc_free, .prepare_request = xs_stream_prepare_request, .send_request = xs_local_send_request, - .set_retrans_timeout = xprt_set_retrans_timeout_def, + .wait_for_reply_request = xprt_wait_for_reply_request_def, .close = xs_close, .destroy = xs_destroy, .print_stats = xs_local_print_stats,
@@ -2710,7 +2710,7 @@ static const struct rpc_xprt_ops xs_udp_ops = { .buf_alloc = rpc_malloc, .buf_free = rpc_free, .send_request = xs_udp_send_request, - .set_retrans_timeout = xprt_set_retrans_timeout_rtt, + .wait_for_reply_request = xprt_wait_for_reply_request_rtt, .timer = xs_udp_timer, .release_request = xprt_release_rqst_cong, .close = xs_close,
@@ -2733,7 +2733,7 @@ static const struct rpc_xprt_ops xs_tcp_ops = { .buf_free = rpc_free, .prepare_request = xs_stream_prepare_request, .send_request = xs_tcp_send_request, - .set_retrans_timeout = xprt_set_retrans_timeout_def, + .wait_for_reply_request = xprt_wait_for_reply_request_def, .close = xs_tcp_shutdown, .destroy = xs_destroy, .set_connect_timeout = xs_tcp_set_connect_timeout,
@@ -2761,7 +2761,7 @@ static const struct rpc_xprt_ops bc_tcp_ops = { .buf_alloc = bc_malloc, .buf_free = bc_free, .send_request = bc_send_request, - .set_retrans_timeout = xprt_set_retrans_timeout_def, + .wait_for_reply_request = xprt_wait_for_reply_request_def, .close = bc_close, .destroy = bc_destroy, .print_stats = xs_tcp_print_stats,
Signature · 1 line
2.20.1
PATCH 4/25 SUNRPC: Refactor rpc_sleep_on()
rpc_sleep_on() does not need to set the task->tk_callback under the queue lock, so move that out.
Also refactor the check for whether the task is active.
--- net/sunrpc/sched.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-)
net/sunrpc/sched.c +24 -16
@@ -362,7 +362,6 @@ static void rpc_make_runnable(struct workqueue_struct *wq,*/ static void __rpc_sleep_on_priority (struct rpc_wait_queue *q,struct rpc_task *task, -rpc_action action,unsigned char queue_priority) { dprintk("RPC: %5u sleep_on(queue \"%s\" time %lu)\n",
@@ -372,27 +371,39 @@ static void __rpc_sleep_on_priority(struct rpc_wait_queue *q,__rpc_add_wait_queue (q, task, queue_priority); -WARN_ON_ONCE (task->tk_callback !=NULL ); - task->tk_callback = action;__rpc_add_timer (q, task); } -void rpc_sleep_on (struct rpc_wait_queue *q,struct rpc_task *task, -rpc_action action) +static void rpc_set_tk_callback (struct rpc_task *task,rpc_action action) +{ +if (action && !WARN_ON_ONCE (task->tk_callback !=NULL )) + task->tk_callback = action; +} + +static bool rpc_sleep_check_activated (struct rpc_task *task) {/* We shouldn't ever put an inactive task to sleep */ -WARN_ON_ONCE (!RPC_IS_ACTIVATED (task)); -if (!RPC_IS_ACTIVATED (task)) { +if (WARN_ON_ONCE (!RPC_IS_ACTIVATED (task))) { task->tk_status = -EIO ;rpc_put_task_async (task); -return ; +return false; } +return true; +} + +void rpc_sleep_on (struct rpc_wait_queue *q,struct rpc_task *task, +rpc_action action) +{ +if (!rpc_sleep_check_activated (task)) +return ; + +rpc_set_tk_callback (task, action);/* * Protect the queue operations. */ spin_lock_bh (&q->lock); -__rpc_sleep_on_priority (q, task, action, task->tk_priority); +__rpc_sleep_on_priority (q, task, task->tk_priority);spin_unlock_bh (&q->lock); }EXPORT_SYMBOL_GPL (rpc_sleep_on);
@@ -400,19 +411,16 @@ EXPORT_SYMBOL_GPL(rpc_sleep_on);void rpc_sleep_on_priority (struct rpc_wait_queue *q,struct rpc_task *task,rpc_action action,int priority) { -/* We shouldn't ever put an inactive task to sleep */ -WARN_ON_ONCE (!RPC_IS_ACTIVATED (task)); -if (!RPC_IS_ACTIVATED (task)) { - task->tk_status = -EIO ; -rpc_put_task_async (task); +if (!rpc_sleep_check_activated (task))return ; - } + +rpc_set_tk_callback (task, action);/* * Protect the queue operations. */ spin_lock_bh (&q->lock); -__rpc_sleep_on_priority (q, task, action, priority -RPC_PRIORITY_LOW ); +__rpc_sleep_on_priority (q, task, priority -RPC_PRIORITY_LOW );spin_unlock_bh (&q->lock); }EXPORT_SYMBOL_GPL (rpc_sleep_on_priority);
Signature · 1 line
2.20.1
PATCH 5/25 SUNRPC: Remove unused argument 'action' from rpc_sleep_on_priority()
None of the callers set the 'action' argument, so let's just remove it.
--- fs/nfs/nfs4proc.c | 2 +- include/linux/sunrpc/sched.h | 1 - net/sunrpc/sched.c | 7 +++---- 3 files changed, 4 insertions(+), 6 deletions(-)
fs/nfs/nfs4proc.c +1 -1
@@ -1008,7 +1008,7 @@ int nfs4_setup_sequence(struct nfs_client *client, out_sleep:if (args->sa_privileged)rpc_sleep_on_priority (&tbl->slot_tbl_waitq, task, -NULL ,RPC_PRIORITY_PRIVILEGED ); +RPC_PRIORITY_PRIVILEGED );else rpc_sleep_on (&tbl->slot_tbl_waitq, task,NULL );spin_unlock (&tbl->slot_tbl_lock);
include/linux/sunrpc/sched.h +0 -1
@@ -231,7 +231,6 @@ void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *, rpc_action action);void rpc_sleep_on_priority (struct rpc_wait_queue *,struct rpc_task *, -rpc_action action,int priority); void rpc_wake_up_queued_task_on_wq(struct workqueue_struct *wq, struct rpc_wait_queue *queue,
net/sunrpc/sched.c +3 -4
@@ -409,18 +409,17 @@ void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,EXPORT_SYMBOL_GPL (rpc_sleep_on);void rpc_sleep_on_priority (struct rpc_wait_queue *q,struct rpc_task *task, -rpc_action action,int priority) +int priority) {if (!rpc_sleep_check_activated (task))return ; -rpc_set_tk_callback (task, action); - + priority -=RPC_PRIORITY_LOW ;/* * Protect the queue operations. */ spin_lock_bh (&q->lock); -__rpc_sleep_on_priority (q, task, priority -RPC_PRIORITY_LOW ); +__rpc_sleep_on_priority (q, task, priority);spin_unlock_bh (&q->lock); }EXPORT_SYMBOL_GPL (rpc_sleep_on_priority);
Signature · 1 line
2.20.1
PATCH 6/25 SUNRPC: Add function rpc_sleep_on_timeout()
Clean up the RPC task sleep interfaces by replacing the task->tk_timeout 'hidden parameter' to rpc_sleep_on() with a new function that takes an absolute timeout.
--- fs/nfs/nfs4proc.c | 18 ++++++--- include/linux/sunrpc/sched.h | 9 ++++- net/sunrpc/auth_gss/auth_gss.c | 5 +-- net/sunrpc/clnt.c | 1 - net/sunrpc/rpcb_clnt.c | 3 +- net/sunrpc/sched.c | 69 +++++++++++++++++++++++++++------- net/sunrpc/xprt.c | 36 ++++++++++-------- 7 files changed, 101 insertions(+), 40 deletions(-)
fs/nfs/nfs4proc.c +12 -6
@@ -978,10 +978,8 @@ int nfs4_setup_sequence(struct nfs_client *client,if (res->sr_slot !=NULL ) goto out_start; -if (session) { +if (session) tbl = &session->fc_slot_table; - task->tk_timeout =0 ; - }spin_lock (&tbl->slot_tbl_lock);/* The state manager will wait until the slot table is empty */
@@ -990,9 +988,8 @@ int nfs4_setup_sequence(struct nfs_client *client, slot =nfs4_alloc_slot (tbl);if (IS_ERR (slot)) { -/* Try again in 1/4 second */ if (slot ==ERR_PTR (-ENOMEM )) - task->tk_timeout =HZ >>2 ; + goto out_sleep_timeout; goto out_sleep; }spin_unlock (&tbl->slot_tbl_lock);
@@ -1004,7 +1001,16 @@ int nfs4_setup_sequence(struct nfs_client *client,nfs41_sequence_res_init (res);rpc_call_start (task);return 0 ; - +out_sleep_timeout: +/* Try again in 1/4 second */ +if (args->sa_privileged) +rpc_sleep_on_priority_timeout (&tbl->slot_tbl_waitq, task, + jiffies + (HZ >>2 ),RPC_PRIORITY_PRIVILEGED ); +else +rpc_sleep_on_timeout (&tbl->slot_tbl_waitq, task, +NULL , jiffies + (HZ >>2 )); +spin_unlock (&tbl->slot_tbl_lock); +return -EAGAIN ; out_sleep:if (args->sa_privileged) rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task,
include/linux/sunrpc/sched.h +8 -1
@@ -35,7 +35,6 @@ struct rpc_wait {struct list_head list;/* wait queue links */ struct list_head links;/* Links to related tasks */ struct list_head timer_list;/* Timer list */ -unsigned long expires; };/*
@@ -227,8 +226,16 @@ void rpc_execute(struct rpc_task *);void rpc_init_priority_wait_queue (struct rpc_wait_queue *,const char *);void rpc_init_wait_queue (struct rpc_wait_queue *,const char *);void rpc_destroy_wait_queue (struct rpc_wait_queue *); +void rpc_sleep_on_timeout (struct rpc_wait_queue *queue, +struct rpc_task *task, +rpc_action action, +unsigned long timeout);void rpc_sleep_on (struct rpc_wait_queue *,struct rpc_task *,rpc_action action); +void rpc_sleep_on_priority_timeout (struct rpc_wait_queue *queue, +struct rpc_task *task, +unsigned long timeout, +int priority);void rpc_sleep_on_priority (struct rpc_wait_queue *,struct rpc_task *,int priority);
net/sunrpc/auth_gss/auth_gss.c +2 -3
@@ -581,8 +581,8 @@ gss_refresh_upcall(struct rpc_task *task)/* XXX: warning on the first, under the assumption we * shouldn't normally hit this case on a refresh. */ warn_gssd (); - task->tk_timeout =15 *HZ ; -rpc_sleep_on (&pipe_version_rpc_waitqueue, task,NULL ); +rpc_sleep_on_timeout (&pipe_version_rpc_waitqueue, + task,NULL , jiffies + (15 *HZ )); err = -EAGAIN ; goto out; }
@@ -595,7 +595,6 @@ gss_refresh_upcall(struct rpc_task *task)if (gss_cred->gc_upcall !=NULL )rpc_sleep_on (&gss_cred->gc_upcall->rpc_waitqueue, task,NULL );else if (gss_msg->ctx ==NULL && gss_msg->msg.errno >=0 ) { - task->tk_timeout =0 ; gss_cred->gc_upcall = gss_msg;/* gss_upcall_callback will release the reference to gss_upcall_msg */ refcount_inc (&gss_msg->count);
net/sunrpc/clnt.c +0 -1
@@ -1869,7 +1869,6 @@ call_bind(struct rpc_task *task)if (!xprt_prepare_transmit (task))return ; - task->tk_timeout = xprt->bind_timeout; xprt->ops->rpcbind (task); }
net/sunrpc/rpcb_clnt.c +2 -1
@@ -694,7 +694,8 @@ void rpcb_getport_async(struct rpc_task *task)/* Put self on the wait queue to ensure we get notified if * some other task is already attempting to bind the port */ -rpc_sleep_on (&xprt->binding, task,NULL ); +rpc_sleep_on_timeout (&xprt->binding, task, +NULL , jiffies + xprt->bind_timeout);if (xprt_test_and_set_binding (xprt)) { dprintk("RPC: %5u %s: waiting for another binder\n",
net/sunrpc/sched.c +56 -13
132 lines not on this page · raw message
net/sunrpc/xprt.c +21 -15
@@ -209,9 +209,12 @@ int xprt_reserve_xprt(struct rpc_xprt *xprt, struct rpc_task *task) out_sleep:dprintk ("RPC: %5u failed to lock transport %p\n" , task->tk_pid, xprt); - task->tk_timeout =RPC_IS_SOFT (task) ? req->rq_timeout :0 ; task->tk_status = -EAGAIN ; -rpc_sleep_on (&xprt->sending, task,NULL ); +if (RPC_IS_SOFT (task)) +rpc_sleep_on_timeout (&xprt->sending, task,NULL , + jiffies + req->rq_timeout); +else +rpc_sleep_on (&xprt->sending, task,NULL );return 0 ; }EXPORT_SYMBOL_GPL (xprt_reserve_xprt);
@@ -273,9 +276,12 @@ int xprt_reserve_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task)xprt_clear_locked (xprt); out_sleep:dprintk ("RPC: %5u failed to lock transport %p\n" , task->tk_pid, xprt); - task->tk_timeout =RPC_IS_SOFT (task) ? req->rq_timeout :0 ; task->tk_status = -EAGAIN ; -rpc_sleep_on (&xprt->sending, task,NULL ); +if (RPC_IS_SOFT (task)) +rpc_sleep_on_timeout (&xprt->sending, task,NULL , + jiffies + req->rq_timeout); +else +rpc_sleep_on (&xprt->sending, task,NULL );return 0 ; }EXPORT_SYMBOL_GPL (xprt_reserve_xprt_cong);
@@ -787,9 +793,9 @@ void xprt_connect(struct rpc_task *task) xprt->ops->close (xprt);if (!xprt_connected (xprt)) { - task->tk_timeout = task->tk_rqstp->rq_timeout; task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie; -rpc_sleep_on (&xprt->pending, task,NULL ); +rpc_sleep_on_timeout (&xprt->pending, task,NULL , + jiffies + task->tk_rqstp->rq_timeout);if (test_bit (XPRT_CLOSING , &xprt->state))return ;
@@ -1080,8 +1086,8 @@ void xprt_wait_for_reply_request_def(struct rpc_task *task) {struct rpc_rqst *req = task->tk_rqstp; - task->tk_timeout = req->rq_timeout; -rpc_sleep_on (&req->rq_xprt->pending, task, xprt_timer); +rpc_sleep_on_timeout (&req->rq_xprt->pending, task, xprt_timer, + jiffies + req->rq_timeout); }EXPORT_SYMBOL_GPL (xprt_wait_for_reply_request_def);
@@ -1099,12 +1105,14 @@ void xprt_wait_for_reply_request_rtt(struct rpc_task *task)struct rpc_rtt *rtt = clnt->cl_rtt;struct rpc_rqst *req = task->tk_rqstp;unsigned long max_timeout = clnt->cl_timeout->to_maxval; +unsigned long timeout; - task->tk_timeout =rpc_calc_rto (rtt, timer); - task->tk_timeout <<=rpc_ntimeo (rtt, timer) + req->rq_retries; -if (task->tk_timeout > max_timeout || task->tk_timeout ==0 ) - task->tk_timeout = max_timeout; -rpc_sleep_on (&req->rq_xprt->pending, task, xprt_timer); + timeout =rpc_calc_rto (rtt, timer); + timeout <<=rpc_ntimeo (rtt, timer) + req->rq_retries; +if (timeout > max_timeout || timeout ==0 ) + timeout = max_timeout; +rpc_sleep_on_timeout (&req->rq_xprt->pending, task, xprt_timer, + jiffies + timeout); }EXPORT_SYMBOL_GPL (xprt_wait_for_reply_request_rtt);
@@ -1656,7 +1664,6 @@ void xprt_reserve(struct rpc_task *task)if (task->tk_rqstp !=NULL )return ; - task->tk_timeout =0 ; task->tk_status = -EAGAIN ;if (!xprt_throttle_congested (xprt, task))xprt_do_reserve (xprt, task);
@@ -1679,7 +1686,6 @@ void xprt_retry_reserve(struct rpc_task *task)if (task->tk_rqstp !=NULL )return ; - task->tk_timeout =0 ; task->tk_status = -EAGAIN ;xprt_do_reserve (xprt, task); }
Signature · 1 line
2.20.1
PATCH 7/25 SUNRPC: Fix up tracking of timeouts
Add a helper to ensure that debugfs and friends print out the correct current task timeout value.
--- include/linux/sunrpc/sched.h | 1 + include/trace/events/sunrpc.h | 2 +- net/sunrpc/clnt.c | 2 +- net/sunrpc/debugfs.c | 2 +- net/sunrpc/sched.c | 14 ++++++++++++++ 5 files changed, 18 insertions(+), 3 deletions(-)
include/linux/sunrpc/sched.h +1 -0
@@ -226,6 +226,7 @@ void rpc_execute(struct rpc_task *);void rpc_init_priority_wait_queue (struct rpc_wait_queue *,const char *);void rpc_init_wait_queue (struct rpc_wait_queue *,const char *);void rpc_destroy_wait_queue (struct rpc_wait_queue *); +unsigned long rpc_task_timeout (const struct rpc_task *task); void rpc_sleep_on_timeout(struct rpc_wait_queue *queue, struct rpc_task *task, rpc_action action,
include/trace/events/sunrpc.h +1 -1
@@ -186,7 +186,7 @@ DECLARE_EVENT_CLASS(rpc_task_queued, __entry->client_id = task->tk_client ? task->tk_client->cl_clid :-1 ; __entry->task_id = task->tk_pid; - __entry->timeout = task->tk_timeout; + __entry->timeout =rpc_task_timeout (task); __entry->runstate = task->tk_runstate; __entry->status = task->tk_status; __entry->flags = task->tk_flags;
net/sunrpc/clnt.c +1 -1
@@ -2900,7 +2900,7 @@ static void rpc_show_task(const struct rpc_clnt *clnt,printk (KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n" , task->tk_pid, task->tk_flags, task->tk_status, - clnt, task->tk_rqstp, task->tk_timeout, task->tk_ops, + clnt, task->tk_rqstp,rpc_task_timeout (task), task->tk_ops, clnt->cl_program->name, clnt->cl_vers,rpc_proc_name (task), task->tk_action, rpc_waitq); }
net/sunrpc/debugfs.c +1 -1
@@ -33,7 +33,7 @@ tasks_show(struct seq_file *f, void *v)seq_printf (f,"%5u %04x %6d 0x%x 0x%x %8ld %ps %sv%u %s a:%ps q:%s\n" , task->tk_pid, task->tk_flags, task->tk_status, - clnt->cl_clid, xid, task->tk_timeout, task->tk_ops, + clnt->cl_clid, xid,rpc_task_timeout (task), task->tk_ops, clnt->cl_program->name, clnt->cl_vers,rpc_proc_name (task), task->tk_action, rpc_waitq);return 0 ;
net/sunrpc/sched.c +14 -0
@@ -58,6 +58,20 @@ static struct rpc_wait_queue delay_queue;struct workqueue_struct *rpciod_workqueue__read_mostly ;struct workqueue_struct *xprtiod_workqueue__read_mostly ; +unsigned long +rpc_task_timeout (const struct rpc_task *task) +{ +unsigned long timeout =READ_ONCE (task->tk_timeout); + +if (timeout !=0 ) { +unsigned long now = jiffies; +if (time_before (now, timeout)) +return timeout - now; + } +return 0 ; +} +EXPORT_SYMBOL_GPL (rpc_task_timeout); +/* * Disable the timer for a given RPC task. Should be called with * queue->lock and bh_disabled in order to avoid races within
Signature · 1 line
2.20.1
PATCH 8/25 SUNRPC: Ensure that the transport layer respect major timeouts
Ensure that when in the transport layer, we don't sleep past a major timeout.
--- net/sunrpc/xprt.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
net/sunrpc/xprt.c +13 -4
@@ -73,6 +73,15 @@ static void xprt_destroy(struct rpc_xprt *xprt);static DEFINE_SPINLOCK (xprt_list_lock);static LIST_HEAD (xprt_list); +static unsigned long xprt_request_timeout (const struct rpc_rqst *req) +{ +unsigned long timeout = jiffies + req->rq_timeout; + +if (time_before (timeout, req->rq_majortimeo)) +return timeout; +return req->rq_majortimeo; +} +/** * xprt_register_transport - register a transport implementation * @transport: transport to register
@@ -212,7 +221,7 @@ int xprt_reserve_xprt(struct rpc_xprt *xprt, struct rpc_task *task) task->tk_status = -EAGAIN ;if (RPC_IS_SOFT (task))rpc_sleep_on_timeout (&xprt->sending, task,NULL , - jiffies + req->rq_timeout); +xprt_request_timeout (req));else rpc_sleep_on (&xprt->sending, task,NULL );return 0 ;
@@ -279,7 +288,7 @@ int xprt_reserve_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task) task->tk_status = -EAGAIN ;if (RPC_IS_SOFT (task))rpc_sleep_on_timeout (&xprt->sending, task,NULL , - jiffies + req->rq_timeout); +xprt_request_timeout (req));else rpc_sleep_on (&xprt->sending, task,NULL );return 0 ;
@@ -795,7 +804,7 @@ void xprt_connect(struct rpc_task *task)if (!xprt_connected (xprt)) { task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie;rpc_sleep_on_timeout (&xprt->pending, task,NULL , - jiffies + task->tk_rqstp->rq_timeout); +xprt_request_timeout (task->tk_rqstp));if (test_bit (XPRT_CLOSING , &xprt->state))return ;
@@ -1087,7 +1096,7 @@ void xprt_wait_for_reply_request_def(struct rpc_task *task)struct rpc_rqst *req = task->tk_rqstp;rpc_sleep_on_timeout (&req->rq_xprt->pending, task, xprt_timer, - jiffies + req->rq_timeout); +xprt_request_timeout (req)); }EXPORT_SYMBOL_GPL (xprt_wait_for_reply_request_def);
Signature · 1 line
2.20.1
PATCH 9/25 SUNRPC: Add tracking of RPC level errors
Add variables to track RPC level errors so that we can distinguish between issue that arose in the RPC transport layer as opposed to those arising from the reply message.
--- include/linux/sunrpc/sched.h | 2 ++ net/sunrpc/clnt.c | 40 ++++++++++++++++++++++++------------ net/sunrpc/xprtsock.c | 1 + 3 files changed, 30 insertions(+), 13 deletions(-)
include/linux/sunrpc/sched.h +2 -0
@@ -61,6 +61,8 @@ struct rpc_task {struct rpc_wait tk_wait;/* RPC wait */ } u; +int tk_rpc_status;/* Result of last RPC operation */ +/* * RPC call state */
net/sunrpc/clnt.c +27 -13
@@ -1468,6 +1468,7 @@ static int __rpc_restart_call(struct rpc_task *task, void (*action)(struct rpc_task *)) { task->tk_status = 0; + task->tk_rpc_status =0 ; task->tk_action = action;return 1 ; }
@@ -1510,6 +1511,19 @@ const charreturn "no proc" ; } +static void +__rpc_call_rpcerror (struct rpc_task *task,int tk_status,int rpc_status) +{ + task->tk_rpc_status = rpc_status; +rpc_exit (task, tk_status); +} + +static void +rpc_call_rpcerror (struct rpc_task *task,int status) +{ +__rpc_call_rpcerror (task, status, status); +} +/* * 0. Initial state *
@@ -1579,7 +1593,7 @@ call_reserveresult(struct rpc_task *task)printk (KERN_ERR "%s: status=%d, but no request slot, exiting\n" , __func__, status); -rpc_exit (task, -EIO ); +rpc_call_rpcerror (task, -EIO );return ; }
@@ -1608,7 +1622,7 @@ call_reserveresult(struct rpc_task *task) __func__, status);break ; } -rpc_exit (task, status); +rpc_call_rpcerror (task, status); }/*
@@ -1684,7 +1698,7 @@ call_refreshresult(struct rpc_task *task) }dprintk ("RPC: %5u %s: refresh creds failed with error %d\n" , task->tk_pid, __func__, status); -rpc_exit (task, status); +rpc_call_rpcerror (task, status); }/*
@@ -1741,7 +1755,7 @@ call_allocate(struct rpc_task *task)return ; }if (status != -ENOMEM ) { -rpc_exit (task, status); +rpc_call_rpcerror (task, status);return ; }
@@ -1810,7 +1824,7 @@ call_encode(struct rpc_task *task) task->tk_action = call_refresh;break ;default : -rpc_exit (task, task->tk_status); +rpc_call_rpcerror (task, task->tk_status); }return ; }else {
@@ -1950,7 +1964,7 @@ call_bind_status(struct rpc_task *task) task->tk_pid, -task->tk_status); } -rpc_exit (task, status); +rpc_call_rpcerror (task, status);return ; retry_timeout:
@@ -1986,7 +2000,7 @@ call_connect(struct rpc_task *task)if (task->tk_status <0 )return ;if (task->tk_flags &RPC_TASK_NOCONNECT ) { -rpc_exit (task, -ENOTCONN ); +rpc_call_rpcerror (task, -ENOTCONN );return ; }if (!xprt_prepare_transmit (task))
@@ -2047,7 +2061,7 @@ call_connect_status(struct rpc_task *task)call_transmit (task);return ; } -rpc_exit (task, status); +rpc_call_rpcerror (task, status);return ; out_retry:/* Check for timeouts before looping back to call_bind */
@@ -2138,7 +2152,7 @@ call_transmit_status(struct rpc_task *task)if (!task->tk_msg.rpc_proc->p_proc)trace_xprt_ping (task->tk_xprt, task->tk_status); -rpc_exit (task, task->tk_status); +rpc_call_rpcerror (task, task->tk_status);return ; }/* fall through */
@@ -2301,7 +2315,7 @@ call_status(struct rpc_task *task)rpc_check_timeout (task);return ; out_exit: -rpc_exit (task, status); +rpc_call_rpcerror (task, status); } static bool
@@ -2325,7 +2339,7 @@ rpc_check_timeout(struct rpc_task *task) task->tk_timeouts++;if (RPC_IS_SOFTCONN (task) && !rpc_check_connected (task->tk_rqstp)) { -rpc_exit (task, -ETIMEDOUT ); +rpc_call_rpcerror (task, -ETIMEDOUT );return ; }
@@ -2336,9 +2350,9 @@ rpc_check_timeout(struct rpc_task *task) task->tk_xprt->servername); }if (task->tk_flags &RPC_TASK_TIMEOUT ) -rpc_exit (task, -ETIMEDOUT ); +rpc_call_rpcerror (task, -ETIMEDOUT );else -rpc_exit (task, -EIO ); +__rpc_call_rpcerror (task, -EIO , -ETIMEDOUT );return ; }
net/sunrpc/xprtsock.c +1 -0
@@ -2017,6 +2017,7 @@ static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task)* we'll need to figure out how to pass a namespace to * connect. */ + task->tk_rpc_status = -ENOTCONN ;rpc_exit (task, -ENOTCONN );return ; }
Signature · 1 line
2.20.1
PATCH 10/25 SUNRPC: Make "no retrans timeout" soft tasks behave like softconn for timeouts
If a soft NFSv4 request is sent, then we don't need it to time out unless the connection breaks. The reason is that as long as the connection is unbroken, the protocol states that the server is not allowed to drop the request. IOW: as long as the connection remains unbroken, the client may assume that all transmitted RPC requests are being processed by the server, and that retransmissions and timeouts of those requests are unwarranted.
--- net/sunrpc/clnt.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/sunrpc/clnt.c +10 -0
@@ -2344,6 +2344,16 @@ rpc_check_timeout(struct rpc_task *task) }if (RPC_IS_SOFT (task)) { +/* +* Once a "no retrans timeout" soft tasks (a.k.a NFSv4) has +* been sent, it should time out only if the transport +* connection gets terminally broken. +*/ +if ((task->tk_flags &RPC_TASK_NO_RETRANS_TIMEOUT ) && + (task->tk_flags &RPC_TASK_SENT ) && +rpc_check_connected (task->tk_rqstp)) +return ; +if (clnt->cl_chatty) { printk(KERN_NOTICE "%s: server %s not responding, timed out\n", clnt->cl_program->name,
Signature · 1 line
2.20.1
PATCH 11/25 SUNRPC: Start the first major timeout calculation at task creation
When calculating the major timeout for a new task, when we know that the connection has been broken, use the task->tk_start to ensure that we also take into account the time spent waiting for a slot or session slot. This ensures that we fail over soft requests relatively quickly once the connection has actually been broken, and the first requests have started to fail.
--- net/sunrpc/xprt.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-)
net/sunrpc/xprt.c +34 -10
@@ -569,18 +569,44 @@ bool xprt_write_space(struct rpc_xprt *xprt) }EXPORT_SYMBOL_GPL (xprt_write_space); -static void xprt_reset_majortimeo (struct rpc_rqst *req) +static unsigned long xprt_abs_ktime_to_jiffies (ktime_t abstime) +{ +s64 delta =ktime_to_ns (ktime_get () - abstime); +return likely (delta >=0 ) ? + jiffies -nsecs_to_jiffies (delta) : + jiffies +nsecs_to_jiffies (-delta); +} + +static unsigned long xprt_calc_majortimeo (struct rpc_rqst *req) {const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout; +unsigned long majortimeo = req->rq_timeout; - req->rq_majortimeo = req->rq_timeout;if (to->to_exponential) - req->rq_majortimeo <<= to->to_retries; + majortimeo <<= to->to_retries; +else + majortimeo += to->to_increment * to->to_retries; +if (majortimeo > to->to_maxval || majortimeo ==0 ) + majortimeo = to->to_maxval; +return majortimeo; +} + +static void xprt_reset_majortimeo (struct rpc_rqst *req) +{ + req->rq_majortimeo +=xprt_calc_majortimeo (req); +} + +static void xprt_init_majortimeo (struct rpc_task *task,struct rpc_rqst *req) +{ +unsigned long time_init; +struct rpc_xprt *xprt = req->rq_xprt; + +if (likely (xprt &&xprt_connected (xprt))) + time_init = jiffies;else - req->rq_majortimeo += to->to_increment * to->to_retries; -if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo ==0 ) - req->rq_majortimeo = to->to_maxval; - req->rq_majortimeo += jiffies; + time_init =xprt_abs_ktime_to_jiffies (task->tk_start); + req->rq_timeout = task->tk_client->cl_timeout->to_initval; + req->rq_majortimeo = time_init +xprt_calc_majortimeo (req); }/**
@@ -997,7 +1023,6 @@ xprt_request_enqueue_receive(struct rpc_task *task)set_bit (RPC_TASK_NEED_RECV , &task->tk_runstate);spin_unlock (&xprt->queue_lock); -xprt_reset_majortimeo (req);/* Turn off autodisconnect */ del_singleshot_timer_sync (&xprt->timer); }
@@ -1631,7 +1656,6 @@ xprt_request_init(struct rpc_task *task)struct rpc_xprt *xprt = task->tk_xprt;struct rpc_rqst *req = task->tk_rqstp; - req->rq_timeout = task->tk_client->cl_timeout->to_initval; req->rq_task = task; req->rq_xprt = xprt; req->rq_buffer =NULL ;
@@ -1644,7 +1668,7 @@ xprt_request_init(struct rpc_task *task) req->rq_snd_buf.bvec =NULL ; req->rq_rcv_buf.bvec =NULL ; req->rq_release_snd_buf =NULL ; -xprt_reset_majortimeo (req); +xprt_init_majortimeo (task, req);dprintk ("RPC: %5u reserved req %p xid %08x\n" , task->tk_pid, req,ntohl (req->rq_xid)); }
Signature · 1 line
2.20.1
PATCH 12/25 SUNRPC: Add the 'softerr' rpc_client flag
Add the 'softerr' rpc client flag that sets the RPC_TASK_TIMEOUT flag on all new rpc tasks that are attached to that rpc client.
--- include/linux/sunrpc/clnt.h | 2 ++ net/sunrpc/clnt.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
include/linux/sunrpc/clnt.h +2 -0
@@ -50,6 +50,7 @@ struct rpc_clnt {struct rpc_iostats * cl_metrics;/* per-client statistics */ unsigned int cl_softrtry : 1,/* soft timeouts */ + cl_softerr : 1,/* Timeouts return errors */ cl_discrtry : 1,/* disconnect before retry */ cl_noretranstimeo: 1,/* No retransmit timeouts */ cl_autobind : 1,/* use getport() */
@@ -144,6 +145,7 @@ struct rpc_add_xprt_test {#define RPC_CLNT_CREATE_INFINITE_SLOTS (1UL << 7)#define RPC_CLNT_CREATE_NO_IDLE_TIMEOUT (1UL << 8)#define RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT (1UL << 9) +#define RPC_CLNT_CREATE_SOFTERR (1UL << 10)struct rpc_clnt *rpc_create (struct rpc_create_args *args); struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
net/sunrpc/clnt.c +7 -1
@@ -484,8 +484,11 @@ static struct rpc_clnt *rpc_create_xprt(struct rpc_create_args *args, } clnt->cl_softrtry =1 ; -if (args->flags &RPC_CLNT_CREATE_HARDRTRY ) +if (args->flags & (RPC_CLNT_CREATE_HARDRTRY |RPC_CLNT_CREATE_SOFTERR )) { clnt->cl_softrtry =0 ; +if (args->flags &RPC_CLNT_CREATE_SOFTERR ) + clnt->cl_softerr =1 ; + }if (args->flags &RPC_CLNT_CREATE_AUTOBIND ) clnt->cl_autobind =1 ;
@@ -623,6 +626,7 @@ static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args,/* Turn off autobind on clones */ new->cl_autobind =0 ; new->cl_softrtry = clnt->cl_softrtry; + new->cl_softerr = clnt->cl_softerr; new->cl_noretranstimeo = clnt->cl_noretranstimeo; new->cl_discrtry = clnt->cl_discrtry; new->cl_chatty = clnt->cl_chatty;
@@ -1001,6 +1005,8 @@ void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt)atomic_inc (&clnt->cl_count);if (clnt->cl_softrtry) task->tk_flags |=RPC_TASK_SOFT ; +if (clnt->cl_softerr) + task->tk_flags |=RPC_TASK_TIMEOUT ;if (clnt->cl_noretranstimeo) task->tk_flags |=RPC_TASK_NO_RETRANS_TIMEOUT ;if (atomic_read (&clnt->cl_swapper))
Signature · 1 line
2.20.1
PATCH 13/25 NFS: Consider ETIMEDOUT to be a fatal error
When we introduce the 'softerr' mount option, we will see the RPC layer returning ETIMEDOUT errors if the server is unresponsive. We want to consider those errors to be fatal on par with the EIO errors that are returned by ordinary 'soft' timeouts..
--- fs/nfs/internal.h | 1 + 1 file changed, 1 insertion(+)
fs/nfs/internal.h +1 -0
@@ -766,6 +766,7 @@ static inline bool nfs_error_is_fatal(int err)case -ESTALE :case -E2BIG :case -ENOMEM : +case -ETIMEDOUT :return true;default :return false;
Signature · 1 line
2.20.1
PATCH 14/25 NFS: Move internal constants out of uapi/linux/nfs_mount.h
When the label says "for internal use only", then it doesn't belong in the 'uapi' subtree.
--- include/linux/nfs_fs_sb.h | 9 +++++++++ include/uapi/linux/nfs_mount.h | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-)
include/linux/nfs_fs_sb.h +9 -0
@@ -139,6 +139,15 @@ struct nfs_server {struct nfs_iostats __percpu *io_stats;/* I/O statistics */ atomic_long_t writeback;/* number of writeback pages */ int flags;/* various flags */ + +/* The following are for internal use only. Also see uapi/linux/nfs_mount.h */ +#define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000 +#define NFS_MOUNT_LOOKUP_CACHE_NONE 0x20000 +#define NFS_MOUNT_NORESVPORT 0x40000 +#define NFS_MOUNT_LEGACY_INTERFACE 0x80000 +#define NFS_MOUNT_LOCAL_FLOCK 0x100000 +#define NFS_MOUNT_LOCAL_FCNTL 0x200000 +unsigned int caps;/* server capabilities */ unsigned int rsize;/* read size */ unsigned int rpages;/* read size (in pages) */
include/uapi/linux/nfs_mount.h +0 -9
@@ -66,13 +66,4 @@ struct nfs_mount_data {#define NFS_MOUNT_UNSHARED 0x8000/* 5 */ #define NFS_MOUNT_FLAGMASK 0xFFFF -/* The following are for internal use only */ -#define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000 -#define NFS_MOUNT_LOOKUP_CACHE_NONE 0x20000 -#define NFS_MOUNT_NORESVPORT 0x40000 -#define NFS_MOUNT_LEGACY_INTERFACE 0x80000 - -#define NFS_MOUNT_LOCAL_FLOCK 0x100000 -#define NFS_MOUNT_LOCAL_FCNTL 0x200000 -#endif
Signature · 1 line
2.20.1
PATCH 15/25 NFS: Add a mount option "softerr" to allow clients to see ETIMEDOUT errors
Add a mount option that exposes the ETIMEDOUT errors that occur during soft timeouts to the application. This allows aware applications to distinguish between server disk IO errors and client timeout errors.
--- fs/nfs/client.c | 2 ++ fs/nfs/super.c | 15 ++++++++++++--- include/linux/nfs_fs_sb.h | 1 + 3 files changed, 15 insertions(+), 3 deletions(-)
fs/nfs/client.c +2 -0
@@ -598,6 +598,8 @@ int nfs_init_server_rpcclient(struct nfs_server *server, sizeof(server->client->cl_timeout_default)); server->client->cl_timeout = &server->client->cl_timeout_default; server->client->cl_softrtry =0 ; +if (server->flags &NFS_MOUNT_SOFTERR ) + server->client->cl_softerr =1 ;if (server->flags &NFS_MOUNT_SOFT ) server->client->cl_softrtry =1 ;
fs/nfs/super.c +12 -3
@@ -78,7 +78,7 @@enum {/* Mount options that take no arguments */ - Opt_soft, Opt_hard, + Opt_soft, Opt_softerr, Opt_hard, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, Opt_noac,
@@ -125,6 +125,7 @@ static const match_table_t nfs_mount_option_tokens = { { Opt_sloppy, "sloppy" }, { Opt_soft, "soft" }, + { Opt_softerr, "softerr" }, { Opt_hard, "hard" }, { Opt_deprecated, "intr" }, { Opt_deprecated, "nointr" },
@@ -628,7 +629,8 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,const char *str;const char *nostr; } nfs_info[] = { - { NFS_MOUNT_SOFT, ",soft", ",hard" }, + { NFS_MOUNT_SOFT, ",soft", "" }, + { NFS_MOUNT_SOFTERR, ",softerr", "" }, { NFS_MOUNT_POSIX, ",posix", "" }, { NFS_MOUNT_NOCTO, ",nocto", "" }, { NFS_MOUNT_NOAC, ",noac", "" },
@@ -658,6 +660,8 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,seq_printf (m,",acdirmin=%u" , nfss->acdirmin/HZ );if (nfss->acdirmax !=NFS_DEF_ACDIRMAX *HZ || showdefaults)seq_printf (m,",acdirmax=%u" , nfss->acdirmax/HZ ); +if (!(nfss->flags & (NFS_MOUNT_SOFT |NFS_MOUNT_SOFTERR ))) +seq_puts (m,",hard" );for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {if (nfss->flags & nfs_infop->flag)seq_puts (m, nfs_infop->str);
@@ -1239,10 +1243,15 @@ static int nfs_parse_mount_options(char *raw,*/ case Opt_soft: mnt->flags |=NFS_MOUNT_SOFT ; + mnt->flags &= ~NFS_MOUNT_SOFTERR ;break ; -case Opt_hard: +case Opt_softerr: + mnt->flags |=NFS_MOUNT_SOFTERR ; mnt->flags &= ~NFS_MOUNT_SOFT ;break ; +case Opt_hard: + mnt->flags &= ~(NFS_MOUNT_SOFT |NFS_MOUNT_SOFTERR ); +break ;case Opt_posix: mnt->flags |=NFS_MOUNT_POSIX ;break ;
include/linux/nfs_fs_sb.h +1 -0
@@ -147,6 +147,7 @@ struct nfs_server {#define NFS_MOUNT_LEGACY_INTERFACE 0x80000#define NFS_MOUNT_LOCAL_FLOCK 0x100000#define NFS_MOUNT_LOCAL_FCNTL 0x200000 +#define NFS_MOUNT_SOFTERR 0x400000unsigned int caps;/* server capabilities */ unsigned int rsize;/* read size */
Signature · 1 line
2.20.1
PATCH 16/25 NFS: Don't interrupt file writeout due to fatal errors
When flushing out dirty pages, the fact that we may hit fatal errors is not a reason to stop writeback. Those errors are reported through fsync(), not through the flush mechanism.
--- fs/nfs/write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/write.c +1 -1
@@ -647,7 +647,7 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,return ret; out_launder:nfs_write_error_remove_page (req); -return ret; +return 0 ; } static int nfs_do_writepage(struct page *page, struct writeback_control *wbc,
Signature · 1 line
2.20.1
PATCH 17/25 NFS: Don't call generic_error_remove_page() while holding locks
The NFS read code can trigger writeback while holding the page lock. If an error then triggers a call to nfs_write_error_remove_page(), we can deadlock.
--- fs/nfs/write.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nfs/write.c +1 -2
@@ -584,9 +584,8 @@ nfs_lock_and_join_requests(struct page *page)static void nfs_write_error_remove_page (struct nfs_page *req) { +SetPageError (req->wb_page);nfs_end_page_writeback (req); -generic_error_remove_page (page_file_mapping (req->wb_page), - req->wb_page);nfs_release_request (req); }
Signature · 1 line
2.20.1
PATCH 18/25 NFS: Don't inadvertently clear writeback errors
vfs_fsync() has the side effect of clearing unreported writeback errors, so we need to make sure that we do not abuse it in situations where applications might not normally expect us to report those errors.
The solution is to replace calls to vfs_fsync() with calls to nfs_wb_all().
--- fs/nfs/file.c | 6 +++--- fs/nfs/nfs4file.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
fs/nfs/file.c +3 -3
@@ -147,7 +147,7 @@ nfs_file_flush(struct file *file, fl_owner_t id)return 0 ;/* Flush writes to the server and return any errors */ -return vfs_fsync (file,0 ); +return nfs_wb_all (inode); }ssize_t
@@ -655,7 +655,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)/* Return error values */ if (nfs_need_check_write (file, inode)) { -int err =vfs_fsync (file,0 ); +int err =nfs_wb_all (inode);if (err <0 ) result = err; }
@@ -709,7 +709,7 @@ do_unlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)* Flush all pending writes before doing anything * with locks.. */ -vfs_fsync (filp,0 ); +nfs_wb_all (inode); l_ctx =nfs_get_lock_context (nfs_file_open_context (filp));if (!IS_ERR (l_ctx)) {
fs/nfs/nfs4file.c +1 -1
@@ -125,7 +125,7 @@ nfs4_file_flush(struct file *file, fl_owner_t id)return filemap_fdatawrite (file->f_mapping);/* Flush writes to the server and return any errors */ -return vfs_fsync (file,0 ); +return nfs_wb_all (inode); }#ifdef CONFIG_NFS_V4_2
Signature · 1 line
2.20.1
PATCH 19/25 NFS: Replace custom error reporting mechanism with generic one
Replace the NFS custom error reporting mechanism with the generic mapping_set_error().
--- fs/nfs/file.c | 25 ++++--------------------- fs/nfs/internal.h | 6 ------ fs/nfs/write.c | 37 ++++++++++++++++++++----------------- include/linux/nfs_fs.h | 1 - 4 files changed, 24 insertions(+), 45 deletions(-)
fs/nfs/file.c +4 -21
@@ -199,13 +199,6 @@ EXPORT_SYMBOL_GPL(nfs_file_mmap);* Flush any dirty pages for this process, and check for write errors. * The return status from this call provides a reliable indication of * whether any write errors occurred for this process. -* -* Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to -* disk, but it retrieves and clears ctx->error after synching, despite -* the two being set at the same time in nfs_context_set_write_error(). -* This is because the former is used to notify the _next_ call to -* nfs_file_write() that a write error occurred, and hence cause it to -* fall back to doing a synchronous write. */ static int nfs_file_fsync_commit (struct file *file,int datasync)
@@ -220,11 +213,8 @@ nfs_file_fsync_commit(struct file *file, int datasync)nfs_inc_stats (inode,NFSIOS_VFSFSYNC ); do_resend =test_and_clear_bit (NFS_CONTEXT_RESEND_WRITES , &ctx->flags); status =nfs_commit_inode (inode,FLUSH_SYNC ); -if (test_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags)) { - ret =xchg (&ctx->error,0 ); -if (ret) - goto out; - } +if (status ==0 ) + status =file_check_and_advance_wb_err (file);if (status <0 ) { ret = status; goto out;
@@ -245,13 +235,7 @@ nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)trace_nfs_fsync_enter (inode); do { - struct nfs_open_context *ctx = nfs_file_open_context(file); - ret = filemap_write_and_wait_range(inode->i_mapping, start, end); - if (test_and_clear_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags)) { - int ret2 = xchg(&ctx->error, 0); - if (ret2) - ret = ret2; - } + ret = file_write_and_wait_range(file, start, end); if (ret != 0) break; ret = nfs_file_fsync_commit(file, datasync);
@@ -600,8 +584,7 @@ static int nfs_need_check_write(struct file *filp, struct inode *inode)struct nfs_open_context *ctx; ctx =nfs_file_open_context (filp); -if (test_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags) || -nfs_ctx_key_to_expire (ctx, inode)) +if (nfs_ctx_key_to_expire (ctx, inode))return 1 ;return 0 ; }
fs/nfs/internal.h +0 -6
@@ -773,9 +773,3 @@ static inline bool nfs_error_is_fatal(int err) } } -static inline void nfs_context_set_write_error (struct nfs_open_context *ctx,int error) -{ - ctx->error = error; -smp_wmb (); -set_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags); -}
fs/nfs/write.c +20 -17
@@ -244,6 +244,12 @@ static void nfs_set_pageerror(struct address_space *mapping)nfs_zap_mapping (mapping->host, mapping); } +static void nfs_mapping_set_error (struct page *page,int error) +{ +SetPageError (page); +mapping_set_error (page_file_mapping (page), error); +} +/* * nfs_page_group_search_locked * @head - head request of page group
@@ -582,9 +588,9 @@ nfs_lock_and_join_requests(struct page *page)return ERR_PTR (ret); } -static void nfs_write_error_remove_page (struct nfs_page *req) +static void nfs_write_error (struct nfs_page *req,int error) { -SetPageError (req->wb_page); +nfs_mapping_set_error (req->wb_page, error);nfs_end_page_writeback (req);nfs_release_request (req); }
@@ -608,6 +614,7 @@ nfs_error_is_fatal_on_server(int err)static int nfs_page_async_flush (struct nfs_pageio_descriptor *pgio,struct page *page) { +struct address_space *mapping;struct nfs_page *req;int ret =0 ;
@@ -621,19 +628,19 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,nfs_set_page_writeback (page);WARN_ON_ONCE (test_bit (PG_CLEAN , &req->wb_flags)); - ret = req->wb_context->error;/* If there is a fatal error that covers this write, just exit */ -if (nfs_error_is_fatal_on_server (ret)) + ret =0 ; + mapping =page_file_mapping (page); +if (test_bit (AS_ENOSPC , &mapping->flags) || +test_bit (AS_EIO , &mapping->flags)) goto out_launder; - ret =0 ;if (!nfs_pageio_add_request (pgio, req)) { ret = pgio->pg_error;/* * Remove the problematic req upon fatal errors on the server */ if (nfs_error_is_fatal (ret)) { -nfs_context_set_write_error (req->wb_context, ret);if (nfs_error_is_fatal_on_server (ret)) goto out_launder; }else
@@ -645,7 +652,7 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio, out:return ret; out_launder: -nfs_write_error_remove_page (req); +nfs_write_error (req, ret);return 0 ; }
@@ -998,7 +1005,7 @@ static void nfs_write_completion(struct nfs_pgio_header *hdr)if (test_bit (NFS_IOHDR_ERROR , &hdr->flags) && (hdr->good_bytes < bytes)) {nfs_set_pageerror (page_file_mapping (req->wb_page)); -nfs_context_set_write_error (req->wb_context, hdr->error); +nfs_mapping_set_error (req->wb_page, hdr->error); goto remove_req; }if (nfs_write_need_commit (hdr)) {
@@ -1422,14 +1429,10 @@ static void nfs_async_write_error(struct list_head *head, int error)while (!list_empty (head)) { req =nfs_list_entry (head->next);nfs_list_remove_request (req); -if (nfs_error_is_fatal (error)) { -nfs_context_set_write_error (req->wb_context, error); -if (nfs_error_is_fatal_on_server (error)) { -nfs_write_error_remove_page (req); -continue ; - } - } -nfs_redirty_request (req); +if (nfs_error_is_fatal (error)) +nfs_write_error (req, error); +else +nfs_redirty_request (req); } }
@@ -1843,7 +1846,7 @@ static void nfs_commit_release_pages(struct nfs_commit_data *data) req->wb_bytes, (long long)req_offset(req));if (status <0 ) { -nfs_context_set_write_error (req->wb_context, status); +nfs_mapping_set_error (req->wb_page, status);if (req->wb_page)nfs_inode_remove_request (req);dprintk_cont (", error = %d\n" , status);
include/linux/nfs_fs.h +0 -1
@@ -76,7 +76,6 @@ struct nfs_open_context {fmode_t mode;unsigned long flags; -#define NFS_CONTEXT_ERROR_WRITE (0)#define NFS_CONTEXT_RESEND_WRITES (1)#define NFS_CONTEXT_BAD (2)#define NFS_CONTEXT_UNLOCK (3)
Signature · 1 line
2.20.1
PATCH 20/25 NFS: Fix up NFS I/O subrequest creation
We require all NFS I/O subrequests to duplicate the lock context as well as the open context.
--- fs/nfs/pagelist.c | 93 ++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 38 deletions(-)
fs/nfs/pagelist.c +55 -38
@@ -295,25 +295,13 @@ nfs_page_group_destroy(struct kref *kref)nfs_release_request (head); } -/** -* nfs_create_request - Create an NFS read/write request. -* @ctx: open context to use -* @page: page to write -* @last: last nfs request created for this page group or NULL if head -* @offset: starting offset within the page for the write -* @count: number of bytes to read/write -* -* The page must be locked by the caller. This makes sure we never -* create two different requests for the same page. -* User should ensure it is safe to sleep in this function. -*/ -struct nfs_page * -nfs_create_request (struct nfs_open_context *ctx,struct page *page, -struct nfs_page *last,unsigned int offset, -unsigned int count) +static struct nfs_page * +__nfs_create_request (struct nfs_lock_context *l_ctx,struct page *page, +struct nfs_page *last,unsigned int pgbase, +unsigned int offset,unsigned int count) {struct nfs_page *req; -struct nfs_lock_context *l_ctx; +struct nfs_open_context *ctx = l_ctx->open_context;if (test_bit (NFS_CONTEXT_BAD , &ctx->flags))return ERR_PTR (-EBADF );
@@ -322,13 +310,8 @@ nfs_create_request(struct nfs_open_context *ctx, struct page *page,if (req ==NULL )return ERR_PTR (-ENOMEM ); -/* get lock context early so we can deal with alloc failures */ - l_ctx =nfs_get_lock_context (ctx); -if (IS_ERR (l_ctx)) { -nfs_page_free (req); -return ERR_CAST (l_ctx); - } req->wb_lock_context = l_ctx; +refcount_inc (&l_ctx->count);atomic_inc (&l_ctx->io_count);/* Initialize the request struct. Initially, we assume a
@@ -340,7 +323,7 @@ nfs_create_request(struct nfs_open_context *ctx, struct page *page,get_page (page); } req->wb_offset = offset; - req->wb_pgbase = offset; + req->wb_pgbase = pgbase; req->wb_bytes = count; req->wb_context =get_nfs_open_context (ctx);kref_init (&req->wb_kref);
@@ -348,6 +331,49 @@ nfs_create_request(struct nfs_open_context *ctx, struct page *page,return req; } +/** +* nfs_create_request - Create an NFS read/write request. +* @ctx: open context to use +* @page: page to write +* @last: last nfs request created for this page group or NULL if head +* @offset: starting offset within the page for the write +* @count: number of bytes to read/write +* +* The page must be locked by the caller. This makes sure we never +* create two different requests for the same page. +* User should ensure it is safe to sleep in this function. +*/ +struct nfs_page * +nfs_create_request (struct nfs_open_context *ctx,struct page *page, +struct nfs_page *last,unsigned int offset, +unsigned int count) +{ +struct nfs_lock_context *l_ctx =nfs_get_lock_context (ctx); +struct nfs_page *ret; + +if (IS_ERR (l_ctx)) +return ERR_CAST (l_ctx); + ret =__nfs_create_request (l_ctx, page, last, offset, offset, count); +nfs_put_lock_context (l_ctx); +return ret; +} + +static struct nfs_page * +nfs_create_subreq (struct nfs_page *req,struct nfs_page *last, +unsigned int pgbase,unsigned int offset, +unsigned int count) +{ +struct nfs_page *ret; + + ret =__nfs_create_request (req->wb_lock_context, req->wb_page, last, + pgbase, offset, count); +if (!IS_ERR (ret)) { +nfs_lock_request (ret); + ret->wb_index = req->wb_index; + } +return ret; +} +/** * nfs_unlock_request - Unlock request and wake up sleepers. * @req: pointer to request
@@ -1049,14 +1075,10 @@ static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, pgbase += subreq->wb_bytes;if (bytes_left) { - subreq =nfs_create_request (req->wb_context, - req->wb_page, - subreq, pgbase, bytes_left); + subreq =nfs_create_subreq (req, subreq, pgbase, + offset, bytes_left);if (IS_ERR (subreq)) goto err_ptr; -nfs_lock_request (subreq); - subreq->wb_offset = offset; - subreq->wb_index = req->wb_index; } }while (bytes_left >0 );
@@ -1158,19 +1180,14 @@ int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, lastreq = lastreq->wb_this_page) ; - dupreq =nfs_create_request (req->wb_context, - req->wb_page, lastreq, pgbase, bytes); + dupreq =nfs_create_subreq (req, lastreq, + pgbase, offset, bytes); +nfs_page_group_unlock (req);if (IS_ERR (dupreq)) { -nfs_page_group_unlock (req); desc->pg_error =PTR_ERR (dupreq); goto out_failed; } - -nfs_lock_request (dupreq); -nfs_page_group_unlock (req); - dupreq->wb_offset = offset; - dupreq->wb_index = req->wb_index; }else dupreq = req;
Signature · 1 line
2.20.1
PATCH 21/25 NFS: Remove unused argument from nfs_create_request()
All the callers of nfs_create_request() are now creating page group heads, so we can remove the redundant 'last' page argument.
--- fs/nfs/direct.c | 4 ++-- fs/nfs/pagelist.c | 16 ++++++++-------- fs/nfs/read.c | 4 ++-- fs/nfs/write.c | 2 +- include/linux/nfs_page.h | 1 - 5 files changed, 13 insertions(+), 14 deletions(-)
fs/nfs/direct.c +2 -2
@@ -492,7 +492,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,struct nfs_page *req;unsigned int req_len =min_t (size_t, bytes,PAGE_SIZE - pgbase);/* XXX do we need to do the eof zeroing found in async_filler? */ - req =nfs_create_request (dreq->ctx, pagevec[i],NULL , + req =nfs_create_request (dreq->ctx, pagevec[i], pgbase, req_len);if (IS_ERR (req)) { result =PTR_ERR (req);
@@ -899,7 +899,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq,struct nfs_page *req;unsigned int req_len =min_t (size_t, bytes,PAGE_SIZE - pgbase); - req =nfs_create_request (dreq->ctx, pagevec[i],NULL , + req =nfs_create_request (dreq->ctx, pagevec[i], pgbase, req_len);if (IS_ERR (req)) { result =PTR_ERR (req);
fs/nfs/pagelist.c +8 -8
@@ -297,8 +297,8 @@ nfs_page_group_destroy(struct kref *kref)static struct nfs_page *__nfs_create_request (struct nfs_lock_context *l_ctx,struct page *page, -struct nfs_page *last,unsigned int pgbase, -unsigned int offset,unsigned int count) +unsigned int pgbase,unsigned int offset, +unsigned int count) {struct nfs_page *req;struct nfs_open_context *ctx = l_ctx->open_context;
@@ -327,7 +327,6 @@ __nfs_create_request(struct nfs_lock_context *l_ctx, struct page *page, req->wb_bytes = count; req->wb_context =get_nfs_open_context (ctx);kref_init (&req->wb_kref); -nfs_page_group_init (req, last);return req; }
@@ -335,7 +334,6 @@ __nfs_create_request(struct nfs_lock_context *l_ctx, struct page *page,* nfs_create_request - Create an NFS read/write request. * @ctx: open context to use * @page: page to write -* @last: last nfs request created for this page group or NULL if head * @offset: starting offset within the page for the write * @count: number of bytes to read/write *
@@ -345,15 +343,16 @@ __nfs_create_request(struct nfs_lock_context *l_ctx, struct page *page,*/ struct nfs_page *nfs_create_request (struct nfs_open_context *ctx,struct page *page, -struct nfs_page *last,unsigned int offset, -unsigned int count) +unsigned int offset,unsigned int count) {struct nfs_lock_context *l_ctx =nfs_get_lock_context (ctx);struct nfs_page *ret;if (IS_ERR (l_ctx))return ERR_CAST (l_ctx); - ret =__nfs_create_request (l_ctx, page, last, offset, offset, count); + ret =__nfs_create_request (l_ctx, page, offset, offset, count); +if (!IS_ERR (ret)) +nfs_page_group_init (ret,NULL );nfs_put_lock_context (l_ctx);return ret; }
@@ -365,11 +364,12 @@ nfs_create_subreq(struct nfs_page *req, struct nfs_page *last, {struct nfs_page *ret; - ret =__nfs_create_request (req->wb_lock_context, req->wb_page, last, + ret =__nfs_create_request (req->wb_lock_context, req->wb_page, pgbase, offset, count);if (!IS_ERR (ret)) {nfs_lock_request (ret); ret->wb_index = req->wb_index; +nfs_page_group_init (ret, last); }return ret; }
fs/nfs/read.c +2 -2
@@ -118,7 +118,7 @@ int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode, len =nfs_page_length (page);if (len ==0 )return nfs_return_empty_page (page); - new =nfs_create_request (ctx, page,NULL ,0 , len); + new =nfs_create_request (ctx, page,0 , len);if (IS_ERR (new)) {unlock_page (page);return PTR_ERR (new);
@@ -363,7 +363,7 @@ readpage_async_filler(void *data, struct page *page)if (len ==0 )return nfs_return_empty_page (page); - new =nfs_create_request (desc->ctx, page,NULL ,0 , len); + new =nfs_create_request (desc->ctx, page,0 , len);if (IS_ERR (new)) goto out_error;
fs/nfs/write.c +1 -1
@@ -1171,7 +1171,7 @@ static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx, req =nfs_try_to_update_request (inode, page, offset, bytes);if (req !=NULL ) goto out; - req =nfs_create_request (ctx, page,NULL , offset, bytes); + req =nfs_create_request (ctx, page, offset, bytes);if (IS_ERR (req)) goto out;nfs_inode_add_request (inode, req);
include/linux/nfs_page.h +0 -1
@@ -114,7 +114,6 @@ struct nfs_pageio_descriptor {extern struct nfs_page *nfs_create_request (struct nfs_open_context *ctx,struct page *page, -struct nfs_page *last,unsigned int offset,unsigned int count);extern void nfs_release_request (struct nfs_page *);
Signature · 1 line
2.20.1
PATCH 22/25 pNFS: Add tracking to limit the number of pNFS retries
When the client is reading or writing using pNFS, and hits an error on the DS, then it typically sends a LAYOUTERROR and/or LAYOUTRETURN to the MDS, before redirtying the failed pages, and going for a new round of reads/writebacks. The problem is that if the server has no way to fix the DS, then we may need a way to interrupt this loop after a set number of attempts have been made.
This patch adds an optional module parameter that allows the admin to specify how many times to retry the read/writeback process before failing with a fatal error.
The default behaviour is to retry forever.
--- fs/nfs/direct.c | 7 +++++++ fs/nfs/flexfilelayout/flexfilelayout.c | 8 ++++++++ fs/nfs/pagelist.c | 14 +++++++++++++- fs/nfs/write.c | 5 +++++ include/linux/nfs_page.h | 4 +++- 5 files changed, 36 insertions(+), 2 deletions(-)
fs/nfs/direct.c +7 -0
@@ -663,6 +663,8 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) }list_for_each_entry_safe (req, tmp, &reqs, wb_list) { +/* Bump the transmission count */ + req->wb_nio++;if (!nfs_pageio_add_request (&desc, req)) {nfs_list_move_request (req, &failed);spin_lock (&cinfo.inode->i_lock);
@@ -703,6 +705,11 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data) req =nfs_list_entry (data->pages.next);nfs_list_remove_request (req);if (dreq->flags ==NFS_ODIRECT_RESCHED_WRITES ) { +/* +* Despite the reboot, the write was successful, +* so reset wb_nio. +*/ + req->wb_nio =0 ;/* Note the rewrite will go through mds */ nfs_mark_request_commit (req,NULL , &cinfo,0 ); }else
fs/nfs/flexfilelayout/flexfilelayout.c +8 -0
@@ -28,6 +28,8 @@#define FF_LAYOUT_POLL_RETRY_MAX (15*HZ)#define FF_LAYOUTRETURN_MAXERR 20 +static unsigned short io_maxretrans; +static void ff_layout_read_record_layoutstats_done (struct rpc_task *task,struct nfs_pgio_header *hdr); static int ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo,
@@ -925,6 +927,7 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, pgm = &pgio->pg_mirrors[0 ]; pgm->pg_bsize = mirror->mirror_ds->ds_versions[0 ].rsize; + pgio->pg_maxretrans = io_maxretrans;return ; out_nolseg:if (pgio->pg_error <0 )
@@ -992,6 +995,7 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, pgm->pg_bsize = mirror->mirror_ds->ds_versions[0 ].wsize; } + pgio->pg_maxretrans = io_maxretrans;return ; out_mds:
@@ -2515,3 +2519,7 @@ MODULE_DESCRIPTION("The NFSv4 flexfile layout driver");module_init (nfs4flexfilelayout_init);module_exit (nfs4flexfilelayout_exit); + +module_param (io_maxretrans, ushort,0644 ); +MODULE_PARM_DESC (io_maxretrans,"The number of times the NFSv4.1 client " +"retries an I/O request before returning an error. " );
fs/nfs/pagelist.c +13 -1
@@ -16,8 +16,8 @@#include <linux/nfs.h> #include <linux/nfs3.h> #include <linux/nfs4.h> -#include <linux/nfs_page.h> #include <linux/nfs_fs.h> +#include <linux/nfs_page.h> #include <linux/nfs_mount.h> #include <linux/export.h>
@@ -327,6 +327,7 @@ __nfs_create_request(struct nfs_lock_context *l_ctx, struct page *page, req->wb_bytes = count; req->wb_context =get_nfs_open_context (ctx);kref_init (&req->wb_kref); + req->wb_nio =0 ;return req; }
@@ -370,6 +371,7 @@ nfs_create_subreq(struct nfs_page *req, struct nfs_page *last,nfs_lock_request (ret); ret->wb_index = req->wb_index;nfs_page_group_init (ret, last); + ret->wb_nio = req->wb_nio; }return ret; }
@@ -724,6 +726,7 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc, desc->pg_mirrors_dynamic =NULL ; desc->pg_mirrors = desc->pg_mirrors_static;nfs_pageio_mirror_init (&desc->pg_mirrors[0 ], bsize); + desc->pg_maxretrans =0 ; }/**
@@ -983,6 +986,15 @@ static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc,return 0 ; mirror->pg_base = req->wb_pgbase; } + +if (desc->pg_maxretrans && req->wb_nio > desc->pg_maxretrans) { +if (NFS_SERVER (desc->pg_inode)->flags &NFS_MOUNT_SOFTERR ) + desc->pg_error = -ETIMEDOUT ; +else + desc->pg_error = -EIO ; +return 0 ; + } +if (!nfs_can_coalesce_requests (prev, req, desc))return 0 ;nfs_list_move_request (req, &mirror->pg_list);
fs/nfs/write.c +5 -0
@@ -1009,6 +1009,8 @@ static void nfs_write_completion(struct nfs_pgio_header *hdr) goto remove_req; }if (nfs_write_need_commit (hdr)) { +/* Reset wb_nio, since the write was successful. */ + req->wb_nio =0 ;memcpy (&req->wb_verf, &hdr->verf.verifier,sizeof (req->wb_verf));nfs_mark_request_commit (req, hdr->lseg, &cinfo, hdr->pgio_mirror_idx);
@@ -1142,6 +1144,7 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode, req->wb_bytes = end - req->wb_offset; else req->wb_bytes = rqend - req->wb_offset; + req->wb_nio =0 ;return req; out_flushme:/*
@@ -1416,6 +1419,8 @@ static void nfs_initiate_write(struct nfs_pgio_header *hdr,*/ static void nfs_redirty_request (struct nfs_page *req) { +/* Bump the transmission count */ + req->wb_nio++;nfs_mark_request_dirty (req);set_bit (NFS_CONTEXT_RESEND_WRITES , &req->wb_context->flags);nfs_end_page_writeback (req);
include/linux/nfs_page.h +3 -1
@@ -53,6 +53,7 @@ struct nfs_page {struct nfs_write_verifier wb_verf;/* Commit cookie */ struct nfs_page *wb_this_page;/* list of reqs for this page */ struct nfs_page *wb_head;/* head pointer for req list */ +unsigned short wb_nio;/* Number of I/O attempts */ };struct nfs_pageio_descriptor ;
@@ -87,7 +88,6 @@ struct nfs_pgio_mirror { };struct nfs_pageio_descriptor { -unsigned char pg_moreio :1 ;struct inode *pg_inode;const struct nfs_pageio_ops *pg_ops;const struct nfs_rw_ops *pg_rw_ops;
@@ -105,6 +105,8 @@ struct nfs_pageio_descriptor {struct nfs_pgio_mirror pg_mirrors_static[1 ];struct nfs_pgio_mirror *pg_mirrors_dynamic;u32 pg_mirror_idx;/* current mirror */ +unsigned short pg_maxretrans; + unsigned char pg_moreio : 1; };/* arbitrarily selected limit to number of mirrors */
Signature · 1 line
2.20.1
PATCH 23/25 NFS: Allow signal interruption of NFS4ERR_DELAYed operations
If the server is unable to immediately execute an RPC call, and returns an NFS4ERR_DELAY then we can assume it is safe to interrupt the operation in order to handle ordinary signals. This allows the application to service timer interrupts that would otherwise have to wait until the server is again able to respond.
--- fs/nfs/nfs4_fs.h | 1 + fs/nfs/nfs4proc.c | 139 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 106 insertions(+), 34 deletions(-)
fs/nfs/nfs4_fs.h +1 -0
@@ -206,6 +206,7 @@ struct nfs4_exception { unsigned char delay : 1, recovering : 1, retry : 1; +bool interruptible; };struct nfs4_state_recovery_ops {
fs/nfs/nfs4proc.c +105 -34
324 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 24/25 NFS: Add a helper to return a pointer to the open context of a struct nfs_page
Add a helper for when we remove the explicit pointer to the open context.
--- fs/nfs/filelayout/filelayout.c | 4 ++-- fs/nfs/flexfilelayout/flexfilelayout.c | 6 +++--- fs/nfs/pagelist.c | 8 ++++---- fs/nfs/pnfs.c | 4 ++-- fs/nfs/pnfs.h | 4 ++-- fs/nfs/read.c | 2 +- fs/nfs/write.c | 20 +++++++++++--------- include/linux/nfs_page.h | 6 ++++++ 8 files changed, 31 insertions(+), 23 deletions(-)
fs/nfs/filelayout/filelayout.c +2 -2
@@ -917,7 +917,7 @@ filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,pnfs_generic_pg_check_layout (pgio);if (!pgio->pg_lseg) { pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode, - req->wb_context, + nfs_req_openctx(req), 0, NFS4_MAX_UINT64, IOMODE_READ,
@@ -944,7 +944,7 @@ filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,pnfs_generic_pg_check_layout (pgio);if (!pgio->pg_lseg) { pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode, - req->wb_context, + nfs_req_openctx(req), 0, NFS4_MAX_UINT64, IOMODE_RW,
fs/nfs/flexfilelayout/flexfilelayout.c +3 -3
@@ -873,7 +873,7 @@ ff_layout_pg_get_read(struct nfs_pageio_descriptor *pgio, {pnfs_put_lseg (pgio->pg_lseg); pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, - req->wb_context, + nfs_req_openctx(req), 0, NFS4_MAX_UINT64, IOMODE_READ,
@@ -953,7 +953,7 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,pnfs_generic_pg_check_layout (pgio);if (!pgio->pg_lseg) { pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, - req->wb_context, + nfs_req_openctx(req), 0, NFS4_MAX_UINT64, IOMODE_RW,
@@ -1010,7 +1010,7 @@ ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio, {if (!pgio->pg_lseg) { pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, - req->wb_context, + nfs_req_openctx(req), 0, NFS4_MAX_UINT64, IOMODE_RW,
fs/nfs/pagelist.c +4 -4
@@ -47,7 +47,7 @@ void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, hdr->req =nfs_list_entry (mirror->pg_list.next); hdr->inode = desc->pg_inode; - hdr->cred = hdr->req->wb_context->cred; + hdr->cred =nfs_req_openctx (hdr->req)->cred; hdr->io_start =req_offset (hdr->req); hdr->good_bytes = mirror->pg_count; hdr->io_completion = desc->pg_io_completion;
@@ -578,7 +578,7 @@ static void nfs_pgio_rpcsetup(struct nfs_pgio_header *hdr, hdr->args.pgbase = req->wb_pgbase; hdr->args.pages = hdr->page_array.pagevec; hdr->args.count = count; - hdr->args.context =get_nfs_open_context (req->wb_context); + hdr->args.context =get_nfs_open_context (nfs_req_openctx (req)); hdr->args.lock_context = req->wb_lock_context; hdr->args.stable =NFS_UNSTABLE ;switch (how & (FLUSH_STABLE |FLUSH_COND_STABLE )) {
@@ -935,9 +935,9 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev,struct file_lock_context *flctx;if (prev) { -if (!nfs_match_open_context (req->wb_context, prev->wb_context)) +if (!nfs_match_open_context (nfs_req_openctx (req),nfs_req_openctx (prev)))return false; - flctx =d_inode (req->wb_context->dentry)->i_flctx; + flctx =d_inode (nfs_req_openctx (req)->dentry)->i_flctx; if (flctx != NULL && !(list_empty_careful(&flctx->flc_posix) && list_empty_careful(&flctx->flc_flock)) &&
fs/nfs/pnfs.c +2 -2
@@ -2436,7 +2436,7 @@ pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *r rd_size =nfs_dreq_bytes_left (pgio->pg_dreq); pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, - req->wb_context, + nfs_req_openctx(req), req_offset(req), rd_size, IOMODE_READ,
@@ -2463,7 +2463,7 @@ pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio,pnfs_generic_pg_check_range (pgio, req);if (pgio->pg_lseg ==NULL ) { pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, - req->wb_context, + nfs_req_openctx(req), req_offset(req), wb_size, IOMODE_RW,
fs/nfs/pnfs.h +2 -2
@@ -459,7 +459,7 @@ static inline bool pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, struct nfs_commit_info *cinfo, u32 ds_commit_idx) { - struct inode *inode = d_inode(req->wb_context->dentry); + struct inode *inode = d_inode(nfs_req_openctx(req)->dentry);struct pnfs_layoutdriver_type *ld =NFS_SERVER (inode)->pnfs_curr_ld;if (lseg ==NULL || ld->mark_request_commit ==NULL )
@@ -471,7 +471,7 @@ pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,static inline bool pnfs_clear_request_commit (struct nfs_page *req,struct nfs_commit_info *cinfo) { -struct inode *inode =d_inode (req->wb_context->dentry); +struct inode *inode =d_inode (nfs_req_openctx (req)->dentry);struct pnfs_layoutdriver_type *ld =NFS_SERVER (inode)->pnfs_curr_ld;if (ld ==NULL || ld->clear_request_commit ==NULL )
fs/nfs/read.c +1 -1
@@ -92,7 +92,7 @@ EXPORT_SYMBOL_GPL(nfs_pageio_reset_read_mds);static void nfs_readpage_release (struct nfs_page *req) { -struct inode *inode =d_inode (req->wb_context->dentry); +struct inode *inode =d_inode (nfs_req_openctx (req)->dentry); dprintk("NFS: read done (%s/%llu %d@%lld)\n", inode->i_sb->s_id, (unsigned long long)NFS_FILEID(inode), req->wb_bytes,
fs/nfs/write.c +11 -9
@@ -964,7 +964,8 @@ static void nfs_clear_request_commit(struct nfs_page *req) {if (test_bit (PG_CLEAN , &req->wb_flags)) { -struct inode *inode =d_inode (req->wb_context->dentry); +struct nfs_open_context *ctx =nfs_req_openctx (req); +struct inode *inode =d_inode (ctx->dentry);struct nfs_commit_info cinfo;nfs_init_cinfo_from_inode (&cinfo, inode);
@@ -1219,7 +1220,7 @@ int nfs_flush_incompatible(struct file *file, struct page *page)return 0 ; l_ctx = req->wb_lock_context; do_flush = req->wb_page != page || - !nfs_match_open_context (req->wb_context, ctx); + !nfs_match_open_context (nfs_req_openctx (req), ctx);if (l_ctx && flctx && !(list_empty_careful (&flctx->flc_posix) &&list_empty_careful (&flctx->flc_flock))) {
@@ -1422,7 +1423,7 @@ static void nfs_redirty_request(struct nfs_page *req)/* Bump the transmission count */ req->wb_nio++;nfs_mark_request_dirty (req); -set_bit (NFS_CONTEXT_RESEND_WRITES , &req->wb_context->flags); +set_bit (NFS_CONTEXT_RESEND_WRITES , &nfs_req_openctx (req)->flags);nfs_end_page_writeback (req);nfs_release_request (req); }
@@ -1742,7 +1743,8 @@ void nfs_init_commit(struct nfs_commit_data *data, struct nfs_commit_info *cinfo) {struct nfs_page *first =nfs_list_entry (head->next); -struct inode *inode =d_inode (first->wb_context->dentry); +struct nfs_open_context *ctx =nfs_req_openctx (first); +struct inode *inode =d_inode (ctx->dentry);/* Set up the RPC argument and reply structs * NB: take care not to mess about with data->commit et al. */
@@ -1750,7 +1752,7 @@ void nfs_init_commit(struct nfs_commit_data *data,list_splice_init (head, &data->pages); data->inode = inode; - data->cred = first->wb_context->cred; + data->cred = ctx->cred; data->lseg = lseg;/* reference transferred */ /* only set lwb for pnfs commit */ if (lseg)
@@ -1763,7 +1765,7 @@ void nfs_init_commit(struct nfs_commit_data *data,/* Note: we always request a commit of the entire inode */ data->args.offset =0 ; data->args.count =0 ; - data->context =get_nfs_open_context (first->wb_context); + data->context =get_nfs_open_context (ctx); data->res.fattr = &data->fattr; data->res.verf = &data->verf;nfs_fattr_init (&data->fattr);
@@ -1846,8 +1848,8 @@ static void nfs_commit_release_pages(struct nfs_commit_data *data)nfs_clear_page_commit (req->wb_page);dprintk ("NFS: commit (%s/%llu %d@%lld)" , - req->wb_context->dentry->d_sb->s_id, - (unsigned long long )NFS_FILEID (d_inode (req->wb_context->dentry)), +nfs_req_openctx (req)->dentry->d_sb->s_id, + (unsigned long long )NFS_FILEID (d_inode (nfs_req_openctx (req)->dentry)), req->wb_bytes, (long long )req_offset (req));if (status <0 ) {
@@ -1870,7 +1872,7 @@ static void nfs_commit_release_pages(struct nfs_commit_data *data)/* We have a mismatch. Write the page again */ dprintk_cont (" mismatch\n" );nfs_mark_request_dirty (req); -set_bit (NFS_CONTEXT_RESEND_WRITES , &req->wb_context->flags); +set_bit (NFS_CONTEXT_RESEND_WRITES , &nfs_req_openctx (req)->flags); next:nfs_unlock_and_release_request (req);/* Latency breaker */
include/linux/nfs_page.h +6 -0
@@ -200,4 +200,10 @@ loff_t req_offset(struct nfs_page *req) return (((loff_t)req->wb_index) << PAGE_SHIFT) + req->wb_offset; } +static inline struct nfs_open_context * +nfs_req_openctx (struct nfs_page *req) +{ +return req->wb_context; +} +#endif /* _LINUX_NFS_PAGE_H */
Signature · 1 line
2.20.1
PATCH 25/25 NFS: Remove redundant open context from nfs_page
The lock context already references and tracks the open context, so take the opportunity to save some space in struct nfs_page.
--- fs/nfs/pagelist.c | 7 +------ include/linux/nfs_page.h | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-)
fs/nfs/pagelist.c +1 -6
@@ -325,7 +325,6 @@ __nfs_create_request(struct nfs_lock_context *l_ctx, struct page *page, req->wb_offset = offset; req->wb_pgbase = pgbase; req->wb_bytes = count; - req->wb_context =get_nfs_open_context (ctx);kref_init (&req->wb_kref); req->wb_nio =0 ;return req;
@@ -414,8 +413,8 @@ void nfs_unlock_and_release_request(struct nfs_page *req)static void nfs_clear_request (struct nfs_page *req) {struct page *page = req->wb_page; -struct nfs_open_context *ctx = req->wb_context;struct nfs_lock_context *l_ctx = req->wb_lock_context; +struct nfs_open_context *ctx = l_ctx->open_context;if (page !=NULL ) {put_page (page);
@@ -430,10 +429,6 @@ static void nfs_clear_request(struct nfs_page *req)nfs_put_lock_context (l_ctx); req->wb_lock_context =NULL ; } -if (ctx !=NULL ) { -put_nfs_open_context (ctx); - req->wb_context =NULL ; - } }/**
include/linux/nfs_page.h +1 -2
@@ -42,7 +42,6 @@ struct nfs_inode;struct nfs_page {struct list_head wb_list;/* Defines state of page: */ struct page *wb_page;/* page to read in/write out */ -struct nfs_open_context *wb_context;/* File state context info */ struct nfs_lock_context *wb_lock_context;/* lock context info */ pgoff_t wb_index;/* Offset >> PAGE_SHIFT */ unsigned int wb_offset, /* Offset & ~PAGE_MASK */
@@ -203,7 +202,7 @@ loff_t req_offset(struct nfs_page *req)static inline struct nfs_open_context *nfs_req_openctx (struct nfs_page *req) { -return req->wb_context; +return req->wb_lock_context->open_context; }#endif /* _LINUX_NFS_PAGE_H */
Signature · 1 line
2.20.1
Re: [PATCH 25/25] NFS: Remove redundant open context from nfs_page
Hi Trond,
url: https://github.com/0day-ci/linux/commits/Trond-Myklebust/Fix-up-soft-mounts-for-NFSv4-x/20190331-130454 base: git://git.linux-nfs.org/projects/trondmy/linux-nfs.git linux-next
New smatch warnings:fs/nfs/pagelist.c:423 nfs_clear_request() warn: variable dereferenced before check 'l_ctx' (see line 417)
# https://github.com/0day-ci/linux/commit/1f204cd821631257d43efaaf86b8d1541f818585
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 1f204cd821631257d43efaaf86b8d1541f818585
vim +/l_ctx +423 fs/nfs/pagelist.c
^1da177e Linus Torvalds 2005-04-16 405
4d65c520 Trond Myklebust 2011-03-25 406 /*
^1da177e Linus Torvalds 2005-04-16 407 * nfs_clear_request - Free up all resources allocated to the request
^1da177e Linus Torvalds 2005-04-16 408 * @req:
^1da177e Linus Torvalds 2005-04-16 409 *
bb6fbc45 Trond Myklebust 2010-03-11 410 * Release page and open context resources associated with a read/write
bb6fbc45 Trond Myklebust 2010-03-11 411 * request after it has completed.
^1da177e Linus Torvalds 2005-04-16 412 */
4d65c520 Trond Myklebust 2011-03-25 413 static void nfs_clear_request(struct nfs_page *req)
^1da177e Linus Torvalds 2005-04-16 414 {
cd52ed35 Trond Myklebust 2006-03-20 415 struct page *page = req->wb_page;
f11ac8db Trond Myklebust 2010-06-25 416 struct nfs_lock_context *l_ctx = req->wb_lock_context;
1f204cd8 Trond Myklebust 2019-03-28 @417 struct nfs_open_context *ctx = l_ctx->open_context;
^^^^^^^^^^^^^^^^^^^Dereferenced
bb6fbc45 Trond Myklebust 2010-03-11 418
cd52ed35 Trond Myklebust 2006-03-20 419 if (page != NULL) {
09cbfeaf Kirill A. Shutemov 2016-04-01 420 put_page(page);
^1da177e Linus Torvalds 2005-04-16 421 req->wb_page = NULL;
^1da177e Linus Torvalds 2005-04-16 422 }
f11ac8db Trond Myklebust 2010-06-25 @423 if (l_ctx != NULL) {
^^^^^^^^^^^^^Check
7d6ddf88 Benjamin Coddington 2017-04-11 424 if (atomic_dec_and_test(&l_ctx->io_count)) {
723c921e Peter Zijlstra 2018-03-15 425 wake_up_var(&l_ctx->io_count);
7d6ddf88 Benjamin Coddington 2017-04-11 426 if (test_bit(NFS_CONTEXT_UNLOCK, &ctx->flags))
7d6ddf88 Benjamin Coddington 2017-04-11 427 rpc_wake_up(&NFS_SERVER(d_inode(ctx->dentry))->uoc_rpcwaitq);
7d6ddf88 Benjamin Coddington 2017-04-11 428 }
f11ac8db Trond Myklebust 2010-06-25 429 nfs_put_lock_context(l_ctx);
f11ac8db Trond Myklebust 2010-06-25 430 req->wb_lock_context = NULL;
f11ac8db Trond Myklebust 2010-06-25 431 }
^1da177e Linus Torvalds 2005-04-16 432 }
^1da177e Linus Torvalds 2005-04-16 433 ---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH 19/25] NFS: Replace custom error reporting mechanism with generic one
In reply to Trond MyklebustHi Trond,
url: https://github.com/0day-ci/linux/commits/Trond-Myklebust/Fix-up-soft-mounts-for-NFSv4-x/20190331-130454 base: git://git.linux-nfs.org/projects/trondmy/linux-nfs.git linux-next
New smatch warnings:fs/nfs/write.c:1849 nfs_commit_release_pages() error: we previously assumed 'req->wb_page' could be null (see line 1840) fs/nfs/write.c:1850 nfs_commit_release_pages() warn: variable dereferenced before check 'req->wb_page' (see line 1849)
# https://github.com/0day-ci/linux/commit/2f2cfd52810bf732da40334bf590dbadda75d6cf
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 2f2cfd52810bf732da40334bf590dbadda75d6cf
vim +1849 fs/nfs/write.c
c9d8f89d9 Trond Myklebust 2008-04-15 1829
f453a54a0 Fred Isaman 2012-04-20 1830 static void nfs_commit_release_pages(struct nfs_commit_data *data)
c9d8f89d9 Trond Myklebust 2008-04-15 1831 {
c9d8f89d9 Trond Myklebust 2008-04-15 1832 struct nfs_page *req;
c9d8f89d9 Trond Myklebust 2008-04-15 1833 int status = data->task.tk_status;
f453a54a0 Fred Isaman 2012-04-20 1834 struct nfs_commit_info cinfo;
353db7966 NeilBrown 2014-09-24 1835 struct nfs_server *nfss;
788e7a89a Trond Myklebust 2006-03-20 1836
^1da177e4 Linus Torvalds 2005-04-16 1837 while (!list_empty(&data->pages)) {
^1da177e4 Linus Torvalds 2005-04-16 1838 req = nfs_list_entry(data->pages.next);
^1da177e4 Linus Torvalds 2005-04-16 1839 nfs_list_remove_request(req);
67911c8f1 Anna Schumaker 2016-01-19 @1840 if (req->wb_page)
^^^^^^^^^^^^d6d6dc7cd Fred Isaman 2012-03-08 1841 nfs_clear_page_commit(req->wb_page);
^1da177e4 Linus Torvalds 2005-04-16 1842
1e8968c5b Niels de Vos 2013-12-17 1843 dprintk("NFS: commit (%s/%llu %d@%lld)",
3d4ff43d8 Al Viro 2011-06-22 1844 req->wb_context->dentry->d_sb->s_id,
2b0143b5c David Howells 2015-03-17 1845 (unsigned long long)NFS_FILEID(d_inode(req->wb_context->dentry)),
^1da177e4 Linus Torvalds 2005-04-16 1846 req->wb_bytes,
^1da177e4 Linus Torvalds 2005-04-16 1847 (long long)req_offset(req));
c9d8f89d9 Trond Myklebust 2008-04-15 1848 if (status < 0) {
2f2cfd528 Trond Myklebust 2019-03-28 @1849 nfs_mapping_set_error(req->wb_page, status);
^^^^^^^^^^^^Dereferenced inside function probably?
38a33101d Kinglong Mee 2017-03-09 @1850 if (req->wb_page)
^^^^^^^^^^^^
Too late.
^1da177e4 Linus Torvalds 2005-04-16 1851 nfs_inode_remove_request(req);
ddeaa6379 Joe Perches 2016-10-15 1852 dprintk_cont(", error = %d\n", status);
^1da177e4 Linus Torvalds 2005-04-16 1853 goto next;
^1da177e4 Linus Torvalds 2005-04-16 1854 }
^1da177e4 Linus Torvalds 2005-04-16 1855 ---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation