linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Anna Schumaker <Anna.Schumaker@netapp.com>
Cc: Jan Kara <jack@suse.cz>, Jeff Layton <jlayton@redhat.com>,
	Trond Myklebust <trond.myklebust@primarydata.com>,
	Dave Chinner <david@fromorbit.com>,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Mel Gorman <mgorman@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-nfs@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/5] SUNRPC: track when a client connection is routed to the local host.
Date: Thu, 24 Apr 2014 09:14:19 +1000	[thread overview]
Message-ID: <20140424091419.0ba0cfd3@notabene.brown> (raw)
In-Reply-To: <5357C3AC.9090203@netapp.com>

[-- Attachment #1: Type: text/plain, Size: 4638 bytes --]

On Wed, 23 Apr 2014 09:44:12 -0400 Anna Schumaker <Anna.Schumaker@netapp.com>
wrote:

> On 04/22/2014 10:40 PM, NeilBrown wrote:
> > If requests are being sent to the local host, then NFS will
> > need to take care to avoid deadlocks.
> >
> > So keep track when accepting a connection or sending a UDP request
> > and set a flag in the svc_xprt when the peer connected to is local.
> >
> > The interface rpc_is_foreign() is provided to check is a given client
> > is connected to a foreign server.  When it returns zero it is either
> > not connected or connected to a local server and in either case
> > greater care is needed.
> >
> > Signed-off-by: NeilBrown <neilb@suse.de>
> > ---
> >  include/linux/sunrpc/clnt.h |    1 +
> >  include/linux/sunrpc/xprt.h |    1 +
> >  net/sunrpc/clnt.c           |   25 +++++++++++++++++++++++++
> >  net/sunrpc/xprtsock.c       |   17 +++++++++++++++++
> >  4 files changed, 44 insertions(+)
> >
> > diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
> > index 8af2804bab16..5d626cc5ab01 100644
> > --- a/include/linux/sunrpc/clnt.h
> > +++ b/include/linux/sunrpc/clnt.h
> > @@ -173,6 +173,7 @@ void		rpc_force_rebind(struct rpc_clnt *);
> >  size_t		rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
> >  const char	*rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
> >  int		rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
> > +int		rpc_is_foreign(struct rpc_clnt *);
> >  
> >  #endif /* __KERNEL__ */
> >  #endif /* _LINUX_SUNRPC_CLNT_H */
> > diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
> > index 8097b9df6773..318ee37bc358 100644
> > --- a/include/linux/sunrpc/xprt.h
> > +++ b/include/linux/sunrpc/xprt.h
> > @@ -340,6 +340,7 @@ int			xs_swapper(struct rpc_xprt *xprt, int enable);
> >  #define XPRT_CONNECTION_ABORT	(7)
> >  #define XPRT_CONNECTION_CLOSE	(8)
> >  #define XPRT_CONGESTED		(9)
> > +#define XPRT_LOCAL		(10)
> >  
> >  static inline void xprt_set_connected(struct rpc_xprt *xprt)
> >  {
> > diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
> > index 0edada973434..454cea69b373 100644
> > --- a/net/sunrpc/clnt.c
> > +++ b/net/sunrpc/clnt.c
> > @@ -1109,6 +1109,31 @@ const char *rpc_peeraddr2str(struct rpc_clnt *clnt,
> >  }
> >  EXPORT_SYMBOL_GPL(rpc_peeraddr2str);
> >  
> > +/**
> > + * rpc_is_foreign - report is rpc client was recently connected to
> > + *                  remote host
> > + * @clnt: RPC client structure
> > + *
> > + * If the client is not connected, or connected to the local host
> > + * (any IP address), then return 0.  Only return non-zero if the
> > + * most recent state was a connection to a remote host.
> > + * For UDP the client always appears to be connected, and the
> > + * remoteness of the host is of the destination of the last transmission.
> > + */
> > +int rpc_is_foreign(struct rpc_clnt *clnt)
> > +{
> > +	struct rpc_xprt *xprt;
> > +	int conn_foreign;
> > +
> > +	rcu_read_lock();
> > +	xprt = rcu_dereference(clnt->cl_xprt);
> > +	conn_foreign = (xprt && xprt_connected(xprt)
> > +			&& !test_bit(XPRT_LOCAL, &xprt->state));
> > +	rcu_read_unlock();
> > +	return conn_foreign;
> > +}
> > +EXPORT_SYMBOL_GPL(rpc_is_foreign);
> > +
> >  static const struct sockaddr_in rpc_inaddr_loopback = {
> >  	.sin_family		= AF_INET,
> >  	.sin_addr.s_addr	= htonl(INADDR_ANY),
> > diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
> > index 0addefca8e77..74796cf37d5b 100644
> > --- a/net/sunrpc/xprtsock.c
> > +++ b/net/sunrpc/xprtsock.c
> > @@ -642,6 +642,15 @@ static int xs_udp_send_request(struct rpc_task *task)
> >  			xdr->len - req->rq_bytes_sent, status);
> >  
> >  	if (status >= 0) {
> > +		struct dst_entry *dst;
> > +		rcu_read_lock();
> > +		dst = rcu_dereference(transport->sock->sk->sk_dst_cache);
> > +		if (dst && dst->dev && (dst->dev->features & NETIF_F_LOOPBACK))
> > +			set_bit(XPRT_LOCAL, &xprt->state);
> > +		else
> > +			clear_bit(XPRT_LOCAL, &xprt->state);
> > +		rcu_read_unlock();
> > +
> You repeat this block of code a bit later.  Can you please make it an inline helper function?

Thanks for the suggestion.
I've put

static inline int sock_is_loopback(struct sock *sk)
{
	struct dst_entry *dst;
	int loopback = 0;
	rcu_read_lock();
	dst = rcu_dereference(sk->sk_dst_cache);
	if (dst && dst->dev &&
	    (dst->dev->features & NETIF_F_LOOPBACK))
		loopback = 1;
	rcu_read_unlock();
	return loopback;
}


in sunrpc.h, and used it for both the server-side and the client side.

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

  reply	other threads:[~2014-04-23 23:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-23  2:40 [PATCH/RFC 0/5] Support loop-back NFS mounts - take 2 NeilBrown
2014-04-23  2:40 ` [PATCH 2/5] SUNRPC: track whether a request is coming from a loop-back interface NeilBrown
2014-04-23  2:40 ` [PATCH 1/5] MM: avoid throttling reclaim for loop-back nfsd threads NeilBrown
2014-04-23 22:03   ` Andrew Morton
2014-04-23 22:47     ` NeilBrown
2014-04-23  2:40 ` [PATCH 5/5] NFS: avoid deadlocks with loop-back mounted NFS filesystems NeilBrown
2014-04-23  2:40 ` [PATCH 3/5] nfsd: Only set PF_LESS_THROTTLE when really needed NeilBrown
2014-05-06 20:54   ` J. Bruce Fields
2014-05-12  1:05     ` NeilBrown
2014-05-06 21:05   ` Rik van Riel
2014-05-12  1:04     ` NeilBrown
2014-05-12 15:32       ` Jan Kara
2014-04-23  2:40 ` [PATCH 4/5] SUNRPC: track when a client connection is routed to the local host NeilBrown
2014-04-23 13:44   ` Anna Schumaker
2014-04-23 23:14     ` NeilBrown [this message]
2014-04-24 12:46       ` Anna Schumaker
2014-04-24  1:20 ` [PATCH/RFC 0/5] Support loop-back NFS mounts - take 2 Dave Chinner

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=20140424091419.0ba0cfd3@notabene.brown \
    --to=neilb@suse.de \
    --cc=Anna.Schumaker@netapp.com \
    --cc=akpm@linux-foundation.org \
    --cc=bfields@fieldses.org \
    --cc=david@fromorbit.com \
    --cc=jack@suse.cz \
    --cc=jlayton@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=mgorman@suse.com \
    --cc=trond.myklebust@primarydata.com \
    /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).