Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2964346rdb; Mon, 4 Dec 2023 12:25:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNPK3SR0vt20gf2rrB5BtZA/LLpmcKLfAZ+2cq8DUMRkhXD0HbQ92xSK8LHm1rpWbo/nBY X-Received: by 2002:a17:906:b818:b0:a01:c1f9:2f54 with SMTP id dv24-20020a170906b81800b00a01c1f92f54mr3656688ejb.21.1701721523988; Mon, 04 Dec 2023 12:25:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701721523; cv=none; d=google.com; s=arc-20160816; b=h0n7DH5Ybp/pHPMLNT0ZpgAcn01bGRHTr25YhJuMOvMj1GqOWf864pAZMlurBG83uo /Z6lwQsJ73gZZKk540ROLpwsjuLv5wDrvEe4aKydARHlf2X1xfDhBX8n1DOKwS7XhA/6 FYlUoRmDu43qF2mcI1EzZNFF1vgKgabtNvdd42IBLTQ0byPzO5hV1A1VnH7lJwZavzW8 iC+wKVVP02pjd2vHeRprbCHgCUHNckGDF7pWnJwZNNZKuBPXq3qY+uhv+7cY8u0FVNnS aAPErvVRZZh/ZNcfwWXB0PAV3TfIz8qMxLWqV3sp+faFLU/lEEnB/A74VnKbI+714gmx k1RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5noJEshvLpDK6mPUtdYkDscKxVq2222uVKOMXr6wQg8=; fh=zrf3k9maC4LGn/MmcHhRkqh5cHnarsSKx/fWXfAmYNI=; b=bz/PzI//M0sSmIJuVet/o2hCvt6u1RfSDP6HDl2KcKsjBTmYHHhKvTTF0RaV7sCIhF V+0pS2AdvYVvKObIk1zIMaPSKJOrtx6klXnCMD6KioGHdwe7LUM5j4zY8CJFhxXmWkWf XwNnVUmMaIaa1Ykmqqv0He2251YWdym2yLG3zPMIy8veGkkgQpOYzppmCHbrk+xhNOg3 5uzua535MB5GWBJJUru2XgatVvtyqEzdLkRyAVGylQUSlHDwE28rN/3tI/Yia9sMta+T vYx4mx6nBbcDyC6hvgiMiV/HVgBftHzeajyIN08LxOnrY6Nz6K9We3oue9l1a7Xf5ZX0 aW3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bJ56mFj1; spf=pass (google.com: domain of linux-nfs+bounces-310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-nfs+bounces-310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lt11-20020a170906fa8b00b009fef4061d43si4725060ejb.654.2023.12.04.12.25.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:25:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bJ56mFj1; spf=pass (google.com: domain of linux-nfs+bounces-310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-nfs+bounces-310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BA2581F21256 for ; Mon, 4 Dec 2023 20:25:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FD6D34196; Mon, 4 Dec 2023 20:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bJ56mFj1" X-Original-To: linux-nfs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62A9F35EE2 for ; Mon, 4 Dec 2023 20:25:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D720BC433C8; Mon, 4 Dec 2023 20:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701721516; bh=1t1ghWKHxmd01vbjRyBgBLlT2J0AjWPGwDhH1W5KiVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bJ56mFj1b9JfhTKKr54Piz873QFad0gIj9MlEmPcHDY6rFf3zJJwP4Pq+ypii0ZQU ElBF5V+c1GKym+QLZUARwrhKQe+cCrvrM5oCjte05PlwV/cK47c3c0fCdBEWLW19f3 F4jIOxq8T8oZn/VmTTfPttlwjHUi7X1xbYsAmKUF9cwVFMto3BiCLV5kgOAvcRls4g x7nF+7LPCKvChF6BuME0StsBrwjr3wYolf/zk5A985Em7m6HyiFiempk3706VDk46U cIQEywOosO6HRjN5h6eyetAfdtZAc/S/xUDdbQP+p8v22EFudi/boIQm6g2S7Skgsw pN395YfQw25pg== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH v2 3/4] SUNRPC: Create a helper function for accessing the rpc_clnt's xprt_switch Date: Mon, 4 Dec 2023 15:25:11 -0500 Message-ID: <20231204202512.108047-4-anna@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204202512.108047-1-anna@kernel.org> References: <20231204202512.108047-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Anna Schumaker This function takes the necessary rcu read lock to dereference the client's rpc_xprt_switch and bump the reference count so it doesn't disappear underneath us before returning. This does mean that callers are responsible for calling xprt_switch_put() on the returned object when they are done with it. Reviewed-by: Jeff Layton Signed-off-by: Anna Schumaker --- net/sunrpc/clnt.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 8df944444e9b..0b2c4b5484f5 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -797,15 +797,24 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt, } EXPORT_SYMBOL_GPL(rpc_switch_client_transport); +static struct rpc_xprt_switch *rpc_clnt_xprt_switch_get(struct rpc_clnt *clnt) +{ + struct rpc_xprt_switch *xps; + + rcu_read_lock(); + xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); + rcu_read_unlock(); + + return xps; +} + static int _rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi, void func(struct rpc_xprt_iter *xpi, struct rpc_xprt_switch *xps)) { struct rpc_xprt_switch *xps; - rcu_read_lock(); - xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); - rcu_read_unlock(); + xps = rpc_clnt_xprt_switch_get(clnt); if (xps == NULL) return -EAGAIN; func(xpi, xps); @@ -2206,9 +2215,7 @@ call_connect_status(struct rpc_task *task) struct rpc_xprt *saved = task->tk_xprt; struct rpc_xprt_switch *xps; - rcu_read_lock(); - xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); - rcu_read_unlock(); + xps = rpc_clnt_xprt_switch_get(clnt); if (xps->xps_nxprts > 1) { long value; @@ -3251,22 +3258,23 @@ void rpc_clnt_xprt_set_online(struct rpc_clnt *clnt, struct rpc_xprt *xprt) { struct rpc_xprt_switch *xps; - rcu_read_lock(); - xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch); - rcu_read_unlock(); + xps = rpc_clnt_xprt_switch_get(clnt); xprt_set_online_locked(xprt, xps); + xprt_switch_put(xps); } void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt) { + struct rpc_xprt_switch *xps; + if (rpc_clnt_xprt_switch_has_addr(clnt, (const struct sockaddr *)&xprt->addr)) { return rpc_clnt_xprt_set_online(clnt, xprt); } - rcu_read_lock(); - rpc_xprt_switch_add_xprt(rcu_dereference(clnt->cl_xpi.xpi_xpswitch), - xprt); - rcu_read_unlock(); + + xps = rpc_clnt_xprt_switch_get(clnt); + rpc_xprt_switch_add_xprt(xps, xprt); + xprt_switch_put(xps); } EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_add_xprt); -- 2.43.0