From: Andrew Pam <andrew@sericyb.com.au>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: Andrew Pam <andrew@sericyb.com.au>, Chuck Lever <cel@kernel.org>,
Jeff Layton <jlayton@kernel.org>, NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Mike Snitzer <snitzer@kernel.org>,
linux-nfs@vger.kernel.org, linux-pm@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 3/3] SUNRPC: reconnect client transports after resuming from hibernation
Date: Thu, 19 Nov 2026 13:47:18 +1100 [thread overview]
Message-ID: <20261119024719.311474-4-andrew@sericyb.com.au> (raw)
In-Reply-To: <20261119024719.311474-1-andrew@sericyb.com.au>
With rpciod and xprtiod frozen across hibernation, no RPC is sent after
the snapshot. TCP can still acknowledge data the server sends then,
though: typically a reply that was in flight when the snapshot was
taken. The restored image has not seen that data, and the server, which
saw it acknowledged, will not send it again. The client then waits
indefinitely for replies that never arrive.
After resuming, disconnect every client transport. Requests in flight
are retransmitted on the new connection, and the server answers any it
has already executed from its reply cache. Because nothing was sent
after the snapshot, NFSv4.1 session slot sequence ids still agree on
both sides.
The disconnect is done from a PM notifier at PM_POST_HIBERNATION, which
runs in the restored kernel once everything has thawed. It is also sent
when hibernation fails, where the reconnect is unnecessary but harmless.
The notifier walks each client's transport switch under its xps_lock.
Every transport on the switch's list holds a reference that is dropped
only after it has been removed under that lock, so the transports stay
valid while it is held. xprt_force_disconnect() does not sleep, so no
references need to be taken and nothing is allocated.
Drafted with an AI coding assistant (Claude).
Signed-off-by: Andrew Pam <andrew@sericyb.com.au>
---
net/sunrpc/clnt.c | 61 ++++++++++++++++++++++++++++++++++++++++
net/sunrpc/sunrpc.h | 2 ++
net/sunrpc/sunrpc_syms.c | 7 +++++
3 files changed, 70 insertions(+)
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 2f076b4bfd54..89afd2d0a47e 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -32,6 +32,8 @@
#include <linux/in.h>
#include <linux/in6.h>
#include <linux/un.h>
+#include <linux/suspend.h>
+#include <net/net_namespace.h>
#include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/addr.h>
@@ -881,6 +883,65 @@ int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
}
EXPORT_SYMBOL_GPL(rpc_clnt_iterate_for_each_xprt);
+/*
+ * TCP may have acknowledged data from the server after the hibernation
+ * snapshot was taken, which the restored kernel has never seen. Disconnect
+ * every client transport after resume, so that outstanding requests are
+ * retransmitted on a new connection.
+ *
+ * Each transport on a switch's list holds a reference that is dropped only
+ * after it is removed under xps_lock, and xprt_force_disconnect() does not
+ * sleep.
+ */
+static int rpc_pm_notify(struct notifier_block *nb, unsigned long action,
+ void *data)
+{
+ struct net *net;
+
+ if (action != PM_POST_HIBERNATION)
+ return NOTIFY_DONE;
+
+ down_read(&net_rwsem);
+ for_each_net(net) {
+ struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
+ struct rpc_clnt *clnt;
+
+ spin_lock(&sn->rpc_client_lock);
+ rcu_read_lock();
+ list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
+ struct rpc_xprt_switch *xps;
+ struct rpc_xprt *xprt;
+
+ xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
+ if (!xps)
+ continue;
+ spin_lock(&xps->xps_lock);
+ list_for_each_entry(xprt, &xps->xps_xprt_list,
+ xprt_switch)
+ xprt_force_disconnect(xprt);
+ spin_unlock(&xps->xps_lock);
+ }
+ rcu_read_unlock();
+ spin_unlock(&sn->rpc_client_lock);
+ }
+ up_read(&net_rwsem);
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block rpc_pm_nb = {
+ .notifier_call = rpc_pm_notify,
+};
+
+int rpc_pm_notifier_register(void)
+{
+ return register_pm_notifier(&rpc_pm_nb);
+}
+
+void rpc_pm_notifier_unregister(void)
+{
+ unregister_pm_notifier(&rpc_pm_nb);
+}
+
/*
* Kill all tasks for the given client.
* XXX: kill their descendants as well?
diff --git a/net/sunrpc/sunrpc.h b/net/sunrpc/sunrpc.h
index 11b9e5cead8e..1833b167616c 100644
--- a/net/sunrpc/sunrpc.h
+++ b/net/sunrpc/sunrpc.h
@@ -43,6 +43,8 @@ struct rpc_task;
struct rpc_xprt;
int rpc_clients_notifier_register(void);
void rpc_clients_notifier_unregister(void);
+int rpc_pm_notifier_register(void);
+void rpc_pm_notifier_unregister(void);
void auth_domain_cleanup(void);
void svc_sock_update_bufs(struct svc_serv *serv);
enum svc_auth_status svc_authenticate(struct svc_rqst *rqstp);
diff --git a/net/sunrpc/sunrpc_syms.c b/net/sunrpc/sunrpc_syms.c
index 1a3884a0376a..d32786f51ae5 100644
--- a/net/sunrpc/sunrpc_syms.c
+++ b/net/sunrpc/sunrpc_syms.c
@@ -116,6 +116,10 @@ init_sunrpc(void)
if (err)
goto out6;
+ err = rpc_pm_notifier_register();
+ if (err)
+ goto out7;
+
sunrpc_debugfs_init();
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
rpc_register_sysctl();
@@ -124,6 +128,8 @@ init_sunrpc(void)
init_socket_xprt(); /* clnt sock transport */
return 0;
+out7:
+ genl_unregister_family(&sunrpc_nl_family);
out6:
rpc_sysfs_exit();
out5:
@@ -141,6 +147,7 @@ init_sunrpc(void)
static void __exit
cleanup_sunrpc(void)
{
+ rpc_pm_notifier_unregister();
genl_unregister_family(&sunrpc_nl_family);
rpc_sysfs_exit();
rpc_cleanup_clids();
--
2.53.0
prev parent reply other threads:[~2026-11-19 2:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 2:47 [PATCH v3 0/3] SUNRPC: keep NFS client connections consistent across hibernation Andrew Pam
2026-11-19 2:47 ` [PATCH v3 1/3] SUNRPC: freeze rpciod and xprtiod across system sleep Andrew Pam
2026-11-19 2:47 ` [PATCH v3 2/3] NFSv4: run lease renewal on a freezable workqueue Andrew Pam
2026-11-19 2:47 ` Andrew Pam [this message]
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=20261119024719.311474-4-andrew@sericyb.com.au \
--to=andrew@sericyb.com.au \
--cc=Dai.Ngo@oracle.com \
--cc=anna@kernel.org \
--cc=cel@kernel.org \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=neil@brown.name \
--cc=netdev@vger.kernel.org \
--cc=okorniev@redhat.com \
--cc=rafael@kernel.org \
--cc=snitzer@kernel.org \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
/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
all inboxes | Powered by JetHome®