Article View: linux.kernel.netdev
Article #11473Re: [PATCH v2 1/2] SUNRPC: add request-scoped disconnects when cancelling tasks
From: Trond Myklebust
Date: Thu, 05 Nov 2026 03:20
Date: Thu, 05 Nov 2026 03:20
153 lines
13477 bytes
13477 bytes
On Wed, 2026-11-04 at 22:14 -0500, Trond Myklebust wrote:
> On Thu, 2026-11-05 at 02:02 +0000, tmenninger@purestorage.com wrote:
> > From: Tim Menninger <tmenninger@everpuredata.com>
> >
> > rpc_cancel_tasks() allows callers to cancel a selected set of RPC
> > tasks,
> > but callers that also need to tear down the connection currently
> > have
> > to
> > disconnect at the rpc_clnt level.
> >
> > That is broader than necessary for clients with multiple
> > transports.
> > A
> > cancelled request is associated with a specific rpc_xprt and
> > records
> > the
> > connection generation on which it was transmitted in
> > rq_connect_cookie.
> >
> > Add rpc_cancel_tasks_and_disconnect() to cancel matching tasks and
> > mark
> > matching requests that remain on the transport transmit or receive
> > queues
> > for conditional transport disconnect when the request is released.
> >
> > Store the disconnect indication in struct rpc_rqst rather than
> > struct
> > rpc_task. An RPC task can release one request and later acquire
> > another,
> > so task-scoped state could otherwise be consumed by a successor
> > request
> > and disconnect the wrong transport generation.
> >
> > After cancelling matching tasks, walk the client's transports and
> > mark
> > matching requests belonging to that client that remain on the
> > transmit
> > or receive queues. An rpc_xprt may be shared by multiple rpc_clnt
> > instances, so requests belonging to other clients are left
> > untouched.
> >
> > When a marked request is released, use
> > xprt_conditional_disconnect()
> > with
> > its saved rq_connect_cookie. This disconnects the transport only if
> > it is
> > still using the same connection generation on which the request was
> > sent,
> > and leaves a replacement connection untouched.
> >
> > Requests that were never transmitted do not require a disconnect.
> >
>
> I'm all for optimising where it makes sense, however this is adding
> another spinlock protected section in xprt_release() for something
> that
> is clearly a rare corner case.
>
> So how about something like the following change instead?
>
Sorry, I oversimplified. Something like this:
8<------------------------------------------------------
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 7fe8b91fa47c..42b0b04de659 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -2459,6 +2459,12 @@ static bool ff_layout_match_io(const struct rpc_task *task, const void *data)
return false;
}
+static bool ff_layout_match_untransmitted_io(const struct rpc_task *task,
+ const void *data)
+{
+ return !RPC_WAS_SENT(task) && ff_layout_match_io(task, data);
+}
+
static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg)
{
struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
@@ -2484,6 +2490,9 @@ static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg)
clnt = ds_clp->cl_rpcclient;
if (!clnt)
continue;
+ rpc_cancel_tasks(clnt, -ECANCELED,
+ ff_layout_match_untransmitted_io,
+ lseg);
if (!rpc_cancel_tasks(clnt, -ECANCELED,
ff_layout_match_io, lseg))
continue;
diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
index 0dbdf3722537..28f5bacb59f9 100644
--- a/include/linux/sunrpc/sched.h
+++ b/include/linux/sunrpc/sched.h
@@ -219,8 +219,8 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
struct rpc_timeout *timeout);
void rpc_put_task(struct rpc_task *);
void rpc_put_task_async(struct rpc_task *);
-bool rpc_task_set_rpc_status(struct rpc_task *task, int rpc_status);
-void rpc_task_try_cancel(struct rpc_task *task, int error);
+bool rpc_task_set_rpc_status(struct rpc_task *task, int rpc_status);
+bool rpc_task_try_cancel(struct rpc_task *task, int error);
void rpc_signal_task(struct rpc_task *);
void rpc_exit_task(struct rpc_task *);
void rpc_exit(struct rpc_task *, int);
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 6cedc824cf82..503e95647270 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -930,7 +930,8 @@ unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error,
continue;
if (!fnmatch(task, data))
continue;
- rpc_task_try_cancel(task, error);
+ if (!rpc_task_try_cancel(task, error))
+ continue;
count++;
}
spin_unlock(&clnt->cl_lock);
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index 016f16ca5779..97727732400b 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -869,15 +869,16 @@ void rpc_signal_task(struct rpc_task *task)
rpc_wake_up_queued_task(queue, task);
}
-void rpc_task_try_cancel(struct rpc_task *task, int error)
+bool rpc_task_try_cancel(struct rpc_task *task, int error)
{
struct rpc_wait_queue *queue;
if (!rpc_task_set_rpc_status(task, error))
- return;
+ return false;
queue = READ_ONCE(task->tk_waitqueue);
if (queue)
rpc_wake_up_queued_task(queue, task);
+ return true;
}
void rpc_exit(struct rpc_task *task, int status)
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com
Technical Details
Message-ID:
<b9ed2a8b5f687d7f581d4867a7867c5c012bb2cc.camel@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357049-linux-kernel-netdev=dewy.ruReferences:
<20261105020249.2607367-1-tmenninger@purestorage.com> <20261105020249.2607367-2-tmenninger@purestorage.com> <681354cdb85b67410793908d9aa4ee37a06408d2.camel@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357049-linux-kernel-netdev=dewy.ru From: trondmy@kernel.org (Trond Myklebust) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH v2 1/2] SUNRPC: add request-scoped disconnects when cancelling tasks Date: Wed, 04 Nov 2026 22:20:24 -0500 Organization: Usenet Network Message-ID: <b9ed2a8b5f687d7f581d4867a7867c5c012bb2cc.camel@kernel.org> References: <20261105020249.2607367-1-tmenninger@purestorage.com> <20261105020249.2607367-2-tmenninger@purestorage.com> <681354cdb85b67410793908d9aa4ee37a06408d2.camel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="3550426"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:F8kHEAmvy7q4QQaDPyVrOhLvLZo= sha256:uuFpb1UlqM0uKiU9UH/Kq7LCG5IakYsCRHLXRY8g7Zw= sha1:Gtc0qa4cDQ9TT17snlS+mG3hw/w= sha256:7sGqklQFFTWYw7xuqa0piYV6sb9vTw8cKvNNGwuUiCE= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 992F8112E79; Thu, 5 Nov 2026 06:20:47 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dNxa5stwNXA9; Thu, 5 Nov 2026 06:20:44 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-357049-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 8EF42112E3F; Thu, 5 Nov 2026 06:20:35 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id DE9DE60135D; Thu, 5 Nov 2026 03:20:34 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793848833; b=gWyZj1/Kj2zCQ2SyWH4xMhJoKGXVbQ+qyBdDtCbQjgsXtSrv9w5AhIC1IQ73Uda+Qgt6 PbtCqTwq9VU/D2pmQj6aGVaD9MJ+6pOVmZ+PHlqhXd8MeZE1pDy16oahHnGLviA5ljTb+ lLzhtndnGnajY3cXRt2+c0gSvAUmOxaivG9o45yeyWzqaE/aR2wwxO/T/M8mcMlwPFn3a RhpSerK7iZD+7yBCxtyXKVOq1HNTjEGeVA7E1YbZ00dbeD7/fNkqoD992FFThJ14HcyVe HShBMNCaMQk1YMTMnbEHIJGHFIbWc38fzWDbxGmzsXPxMe0EkAyGTPtNoG0VzT3ELoQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793848833; h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Subject: From:To:Cc:Date:In-Reply-To:References:Content-Type: Content-Transfer-Encoding:User-Agent:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version; bh=f1k09c1wR/2ZTf34h9QyJ4bsorM7gCNcAVQZ4O8hKBU=; b=xrZJbrbO3s3YNxOqNuCWmEcIUFAYObRHuuP1ndpb8jEo/KUwU67l2iJuFZvULvSZkLjH +HTs5h5Mhi2KQ+Jy1bwFSz/IoQ0yFg7F4vJfEFcQudrovZZp5TLvCwjQhIeLTEt6SC5xh ElC9pTKphlNCugyT+YpghNsYXG5v7NgrvP3EFponkFjjArYeXdxZNYbIoPheApqnaT4V2 zIn7F4gK6+pnPJgeGCWIopQws799h1MKC4xOFT5t84OVU+Jw1dn5TQ+58nXyx1N9usaH5 u200c9blDRdVpLxTdmB6d/gk0wGEcdBF3Q1Z9g7JbRxb4a6HU7cXsbSdTVqowXo0nMg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LVufgj4a; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E0DB606A32F; Thu, 5 Nov 2026 03:20:33 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LVufgj4a X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793848827; b=ftBzx9yy++2MlHtLTy1SJbcCVkirXsS3Gkd3S5wU5T7/E0yfcz0S4D674lJk+C9UU0s9 DXN/iijVttQr6KspjGdyJiWoEOSkwUPNaO+pp56Qm/bIsza7koudAt/UUGaz2JjQoMbnV iuKPiLhX+LsKuZq+AhXBw6IwEGBLt2jZDFa5E92GhqsaxXKTpRxCpenHYHRbsF/1DEGVb rHzkOiAQHJ2kB8nayF5uyBSiyTzaHvENoxX72HQ8fLExl8zkrV/lxUYtOYp3CpyJCfdf3 HgoS4ceaJy0F1gw+UcIZHEPIeFq0n0EAMItYdId+16P0haG+h4+wkHp8o0BPvUEkz9A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793848827; h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date: In-Reply-To:References:Content-Type:Content-Transfer-Encoding: User-Agent:MIME-Version; bh=f1k09c1wR/2ZTf34h9QyJ4bsorM7gCNcAVQZ4O8hKBU=; b=NTcbkow6K8phrnWcFQ8C5aOlRx6cyEZ2i74+ZqLFjlEcUcTMp9tfgZ74LwvRGE+MgTZx cM7O2loUj40In0cpTMU4as48iO9UT6bcce/EfIeJ85BjeKZANh224Gs/fWqWNEDuv0Lct CZ/cv+mURV/LVH6KEJlsoesadLrjDLzw1ro6PQv/7nZXzWSHOwHphF/mGVAQrcD25bz/v G9AejFS57/0Ea/bjSGqs30M2CnOifVCHFXOvqcqBsEumFQc8J1CIJBRWafUaei7DzvQr/ FK25JIJI3Ia8RBrCfLjAxsWZE6jVhYG2IM7jAb70znKO7+G6cLxadDL6Qra4yzSAOwQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LVufgj4a; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37602606A31B; Thu, 5 Nov 2026 03:20:26 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D555C1F000C1; Thu, 5 Nov 2026 03:20:25 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793848826; bh=f1k09c1wR/2ZTf34h9QyJ4bsorM7gCNcAVQZ4O8hKBU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=LVufgj4aKr3Qdju5kzCcj9anfQIgtXx4CcZmT9o4Jh6mt4FDHsKgOvFYwCrnmjO5I pJUBVrQknvnIS4q5g8aH6flzN/GQeIlOMOfJyz2N9JSvOrMPIdHVOjjjEw/wzaO2Zs MN+HLUzlCwssmHgeYLQ/glWpTIogak1Muym77DbfcYNNmsDeMQpZap5JCuAxKYDQI0 6wAlCnHiWfpflzpi6WGHJ4fjHBTxUqJ64dr89Zc5oQJFhjemQM/6zUMhXTB/XMlBdV LMGQggTsxG/gn98zNiJrIRkidLWfj1UI5ddCp6PzVcc1IdRd9Dq1QKgWge0DLhKDId PjycxIt62Y5qQ== X-Cc: cel@kernel.org, ebadger@everpuredata.com, jcurley@everpuredata.com, jlayton@kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, slingappa@everpuredata.com, Tim Menninger <tmenninger@everpuredata.com> X-In-Reply-To: <681354cdb85b67410793908d9aa4ee37a06408d2.camel@kernel.org> X-User-Agent: Evolution 3.62.1 (3.62.1-1.fc45) X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list