From: Jeff Layton <jlayton@kernel.org>
To: NeilBrown <neilb@suse.de>, Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH 04/14] SUNRPC: change svc_recv() to return void.
Date: Thu, 20 Jul 2023 16:02:47 -0400 [thread overview]
Message-ID: <32d10c61803c83d4e4812c84a3080728acb91061.camel@kernel.org> (raw)
In-Reply-To: <168966228862.11075.10086063375287695723.stgit@noble.brown>
On Tue, 2023-07-18 at 16:38 +1000, NeilBrown wrote:
> svc_recv() currently returns a 0 on success or one of two errors:
> - -EAGAIN means no message was successfully received
> - -EINTR means the thread has been told to stop
>
> Previously nfsd would stop as the result of a signal as well as
> following kthread_stop(). In that case the difference was useful: EINTR
> means stop unconditionally. EAGAIN means stop if kthread_should_stop(),
> continue otherwise.
>
> Now threads only exit when kthread_should_stop() so we don't need the
> distinction.
>
> So have all threads test kthread_should_stop() (most do), and return
> simple success/failure from svc_recv().
The patch makes sense, but the above sentence doesn't. You're making
svc_recv void return, but you're returning simple success/failure?
> Also change some helpers that svc_recv() uses to not bother with an
> error code, returning a bool in once case, and NULL for failure in
> another.
>
> Signed-off-by: NeilBrown <neilb@suse.de>
> ---
> fs/lockd/svc.c | 9 +++------
> fs/nfs/callback.c | 5 +----
> fs/nfsd/nfssvc.c | 8 ++------
> include/linux/sunrpc/svcsock.h | 2 +-
> net/sunrpc/svc_xprt.c | 27 +++++++++++----------------
> 5 files changed, 18 insertions(+), 33 deletions(-)
>
> diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
> index 91ef139a7757..a43b63e46127 100644
> --- a/fs/lockd/svc.c
> +++ b/fs/lockd/svc.c
> @@ -116,7 +116,6 @@ static void set_grace_period(struct net *net)
> static int
> lockd(void *vrqstp)
> {
> - int err = 0;
> struct svc_rqst *rqstp = vrqstp;
> struct net *net = &init_net;
> struct lockd_net *ln = net_generic(net, lockd_net_id);
> @@ -139,12 +138,10 @@ lockd(void *vrqstp)
> timeout = nlmsvc_retry_blocked();
>
> /*
> - * Find a socket with data available and call its
> - * recvfrom routine.
> + * Find any work to do, such as a socket with data available,
> + * and do the work.
> */
> - err = svc_recv(rqstp, timeout);
> - if (err == -EAGAIN || err == -EINTR)
> - continue;
> + svc_recv(rqstp, timeout);
> }
> if (nlmsvc_ops)
> nlmsvc_invalidate_all();
> diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
> index 2d94384bd6a9..914d2402ca98 100644
> --- a/fs/nfs/callback.c
> +++ b/fs/nfs/callback.c
> @@ -74,7 +74,6 @@ static int nfs4_callback_up_net(struct svc_serv *serv, struct net *net)
> static int
> nfs4_callback_svc(void *vrqstp)
> {
> - int err;
> struct svc_rqst *rqstp = vrqstp;
>
> set_freezable();
> @@ -83,9 +82,7 @@ nfs4_callback_svc(void *vrqstp)
> /*
> * Listen for a request on the socket
> */
> - err = svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT);
> - if (err == -EAGAIN || err == -EINTR)
> - continue;
> + svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT);
> }
>
> svc_exit_thread(rqstp);
> diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
> index 3e08cc746870..5bf48c33986e 100644
> --- a/fs/nfsd/nfssvc.c
> +++ b/fs/nfsd/nfssvc.c
> @@ -953,7 +953,6 @@ nfsd(void *vrqstp)
> struct svc_xprt *perm_sock = list_entry(rqstp->rq_server->sv_permsocks.next, typeof(struct svc_xprt), xpt_list);
> struct net *net = perm_sock->xpt_net;
> struct nfsd_net *nn = net_generic(net, nfsd_net_id);
> - int err;
>
> /* At this point, the thread shares current->fs
> * with the init process. We need to create files with the
> @@ -972,7 +971,7 @@ nfsd(void *vrqstp)
> /*
> * The main request loop
> */
> - for (;;) {
> + while (!kthread_should_stop()) {
> /* Update sv_maxconn if it has changed */
> rqstp->rq_server->sv_maxconn = nn->max_connections;
>
> @@ -980,10 +979,7 @@ nfsd(void *vrqstp)
> * Find a socket with data available and call its
> * recvfrom routine.
> */
> - while ((err = svc_recv(rqstp, 60*60*HZ)) == -EAGAIN)
> - ;
> - if (err == -EINTR)
> - break;
> + svc_recv(rqstp, 60*60*HZ);
> validate_process_creds();
> }
>
> diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h
> index 55446136499f..fb5c98069356 100644
> --- a/include/linux/sunrpc/svcsock.h
> +++ b/include/linux/sunrpc/svcsock.h
> @@ -64,7 +64,7 @@ static inline u32 svc_sock_final_rec(struct svc_sock *svsk)
> * Function prototypes.
> */
> void svc_close_net(struct svc_serv *, struct net *);
> -int svc_recv(struct svc_rqst *, long);
> +void svc_recv(struct svc_rqst *, long);
> void svc_send(struct svc_rqst *rqstp);
> void svc_drop(struct svc_rqst *);
> void svc_sock_update_bufs(struct svc_serv *serv);
> diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
> index c808f6d60c99..67825eef8646 100644
> --- a/net/sunrpc/svc_xprt.c
> +++ b/net/sunrpc/svc_xprt.c
> @@ -664,7 +664,7 @@ static void svc_check_conn_limits(struct svc_serv *serv)
> }
> }
>
> -static int svc_alloc_arg(struct svc_rqst *rqstp)
> +static bool svc_alloc_arg(struct svc_rqst *rqstp)
> {
> struct svc_serv *serv = rqstp->rq_server;
> struct xdr_buf *arg = &rqstp->rq_arg;
> @@ -689,7 +689,7 @@ static int svc_alloc_arg(struct svc_rqst *rqstp)
> set_current_state(TASK_IDLE);
> if (kthread_should_stop()) {
> set_current_state(TASK_RUNNING);
> - return -EINTR;
> + return false;
> }
> trace_svc_alloc_arg_err(pages, ret);
> memalloc_retry_wait(GFP_KERNEL);
> @@ -708,7 +708,7 @@ static int svc_alloc_arg(struct svc_rqst *rqstp)
> arg->tail[0].iov_len = 0;
>
> rqstp->rq_xid = xdr_zero;
> - return 0;
> + return true;
> }
>
> static bool
> @@ -773,9 +773,9 @@ static struct svc_xprt *svc_get_next_xprt(struct svc_rqst *rqstp, long timeout)
> if (!time_left)
> percpu_counter_inc(&pool->sp_threads_timedout);
> if (kthread_should_stop())
> - return ERR_PTR(-EINTR);
> + return NULL;
> percpu_counter_inc(&pool->sp_threads_no_work);
> - return ERR_PTR(-EAGAIN);
> + return NULL;
> out_found:
> /* Normally we will wait up to 5 seconds for any required
> * cache information to be provided.
> @@ -856,32 +856,27 @@ static int svc_handle_xprt(struct svc_rqst *rqstp, struct svc_xprt *xprt)
> * organised not to touch any cachelines in the shared svc_serv
> * structure, only cachelines in the local svc_pool.
> */
> -int svc_recv(struct svc_rqst *rqstp, long timeout)
> +void svc_recv(struct svc_rqst *rqstp, long timeout)
> {
> struct svc_xprt *xprt = NULL;
> struct svc_serv *serv = rqstp->rq_server;
> - int len, err;
> + int len;
>
> - err = svc_alloc_arg(rqstp);
> - if (err)
> + if (!svc_alloc_arg(rqstp))
> goto out;
>
> try_to_freeze();
> cond_resched();
> - err = -EINTR;
> if (kthread_should_stop())
> goto out;
>
> xprt = svc_get_next_xprt(rqstp, timeout);
> - if (IS_ERR(xprt)) {
> - err = PTR_ERR(xprt);
> + if (!xprt)
> goto out;
> - }
>
> len = svc_handle_xprt(rqstp, xprt);
>
> /* No data, incomplete (TCP) read, or accept() */
> - err = -EAGAIN;
> if (len <= 0)
> goto out_release;
>
> @@ -896,12 +891,12 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
> percpu_counter_inc(&rqstp->rq_pool->sp_messages_arrived);
> rqstp->rq_stime = ktime_get();
> svc_process(rqstp);
> - return 0;
> + return;
> out_release:
> rqstp->rq_res.len = 0;
> svc_xprt_release(rqstp);
> out:
> - return err;
> + return;
> }
> EXPORT_SYMBOL_GPL(svc_recv);
>
>
>
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2023-07-20 20:02 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-18 6:38 [PATCH 00/14] Refactor SUNRPC svc thread code, and use llist NeilBrown
2023-07-18 6:38 ` [PATCH 10/14] SUNRPC: change svc_pool_wake_idle_thread() to return nothing NeilBrown
2023-07-18 13:58 ` Chuck Lever
2023-07-19 1:16 ` NeilBrown
2023-07-19 13:12 ` Chuck Lever III
2023-07-19 23:20 ` NeilBrown
2023-07-19 23:44 ` Chuck Lever III
2023-07-20 14:29 ` Chuck Lever III
2023-07-24 0:03 ` NeilBrown
2023-07-24 4:44 ` NeilBrown
2023-07-25 13:49 ` Chuck Lever III
2023-07-18 6:38 ` [PATCH 02/14] nfsd: don't allow nfsd threads to be signalled NeilBrown
2023-07-20 20:05 ` Jeff Layton
2023-07-18 6:38 ` [PATCH 09/14] SUNRPC: change how svc threads are asked to exit NeilBrown
2023-07-20 20:30 ` Jeff Layton
2023-07-20 21:32 ` NeilBrown
2023-07-18 6:38 ` [PATCH 03/14] SUNRPC: call svc_process() from svc_recv() NeilBrown
2023-07-20 20:07 ` Jeff Layton
2023-07-18 6:38 ` [PATCH 04/14] SUNRPC: change svc_recv() to return void NeilBrown
2023-07-18 13:26 ` Chuck Lever
2023-07-20 20:02 ` Jeff Layton [this message]
2023-07-18 6:38 ` [PATCH 08/14] SUNRPC: integrate back-channel processing with svc_recv() and svc_process() NeilBrown
2023-07-20 20:16 ` Jeff Layton
2023-07-18 6:38 ` [PATCH 14/14] SUNRPC: only have one thread waking up at a time NeilBrown
2023-07-18 6:38 ` [PATCH 01/14] lockd: remove SIGKILL handling NeilBrown
2023-07-20 20:05 ` Jeff Layton
2023-07-18 6:38 ` [PATCH 12/14] SUNRPC: discard SP_CONGESTED NeilBrown
2023-07-18 6:38 ` [PATCH 11/14] SUNRPC: add list of idle threads NeilBrown
2023-07-18 6:38 ` [PATCH 07/14] SUNRPC: refactor svc_recv() NeilBrown
2023-07-18 13:49 ` Chuck Lever
2023-07-18 6:38 ` [PATCH 13/14] SUNRPC: change service idle list to be an llist NeilBrown
2023-07-18 6:38 ` [PATCH 06/14] SUNRPC: change various server-side #defines to enum NeilBrown
2023-07-18 13:37 ` Chuck Lever
2023-07-30 15:57 ` Chuck Lever
2023-07-30 22:11 ` NeilBrown
2023-07-30 22:14 ` NeilBrown
2023-07-30 22:16 ` Chuck Lever III
2023-07-30 22:56 ` NeilBrown
2023-07-30 22:57 ` Chuck Lever III
2023-07-30 23:19 ` Chuck Lever III
2023-07-18 6:38 ` [PATCH 05/14] SUNRPC: remove timeout arg from svc_recv() NeilBrown
2023-07-20 20:12 ` Jeff Layton
2023-07-18 18:12 ` [PATCH 00/14] Refactor SUNRPC svc thread code, and use llist Chuck Lever III
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32d10c61803c83d4e4812c84a3080728acb91061.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).