Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp526526pxb; Tue, 2 Feb 2021 10:49:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8DjFOaFp7zDVtyB9gKIQQfA15fVH2dLr7C+mOMqFImhyrk7+HKVqQAfakXCoxyRAXnauH X-Received: by 2002:a17:906:c9d8:: with SMTP id hk24mr24551087ejb.468.1612291761704; Tue, 02 Feb 2021 10:49:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612291761; cv=none; d=google.com; s=arc-20160816; b=SMbDN+5ZhbTGEx3Exa39omVsio9cFeqBjHOAh7aylxvOdpKhpBZAfP8Zn5CIcbQ/Wz v3CxOgM99FsXzDAL1z7EEJg8+gWtS99UEpbGpcyFkxObYHpv3XDL31JAbgfKmWo5P3cr SPSvhIZ3962xspLn/wLpACGmKCA8qKPhts9hnKlZKPPZba8rFZ/ndYYQRETCBeG4z+LN EEX+DGThGfAUKCp5gcAHmumvcYxCICdh7W9XG1zBbYSBP0LMgHyaVaXfprIxePl0CwxR 257BrmOYVWGnqh1HlH4JdsHz0mzrk9RP/4mfdAJSiqmLD9UztO0AFRBkkpkGdCQQtvJH 0fkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=dQb0xnCqDeXmHQy6ABEXqRVe5Ozah2A2c9Qh6FPP7/Q=; b=YgFrObgA9u5IOneJ2oufLETFfbFkfbXkiPGyRx1ITGrvd5Y5BCp65wjU+oLH/JiBhS FzcifqdAIlchT9lNEat2fXOzpH/1XEcgG2GvOHNTUrOd+MPiqMcZbRd6iglbSe4LVspR qtpdGlnj3iY0Cs48SMLKh6yUPn9ZVjkyiCF0nCn2RWXO0H1JXyGPvUXs218dvXzWkgfn DkjuMhuEg2qNMrI50rocWFwE1PbAMQxSOqkH13ZwtnYqIchvhzk3+CBrQpQIn0GvUDMD SgegXtWGJwJ1RvwIuDrRF5V/xZg2BHqd/hEiekdJFz5rPXxWBITVi67lkibDtYhbnE78 3Z/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="eZ8/hXee"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qk25si12937632ejb.422.2021.02.02.10.48.56; Tue, 02 Feb 2021 10:49:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="eZ8/hXee"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238935AbhBBSpZ (ORCPT + 99 others); Tue, 2 Feb 2021 13:45:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238836AbhBBSnd (ORCPT ); Tue, 2 Feb 2021 13:43:33 -0500 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7745C061793 for ; Tue, 2 Feb 2021 10:42:52 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id l23so15664252qtq.13 for ; Tue, 02 Feb 2021 10:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dQb0xnCqDeXmHQy6ABEXqRVe5Ozah2A2c9Qh6FPP7/Q=; b=eZ8/hXeezCtmm+7fZodHs9faaMKa8Rab1GNPLN/4VOsZwBvhD6qkkVfEXQ5I9Sbr+B QVX+vh7pal25wROgfLWkVgMWcEi3hakTF8Jr1L38XraL+mu+Qw5KcJAnFGX8gmyyMHHw wyVpBVQo4lp/H2cLJXV0NazuMl0hjW5k3gBapRFRyKLmD2bXt/IeoPBwmOtMPlCw2nEC zHtNmafr4aHQ+dzsVLyS4gVBlAi0zn3rnjkr4YwNQxcWDxHWFluXBjKH01iR94inKaZl a/EmwC67ZsD08S8eI2JZWRLifO9dKj6eXkZQds/y6YzTMq4/JA3euHaf1OLPADrTYNpq 2LjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=dQb0xnCqDeXmHQy6ABEXqRVe5Ozah2A2c9Qh6FPP7/Q=; b=EYdYJLVc3OLcmtiPgpnas4WMAebABE1pgT81L1JwHVD4npzGRkA4hoQxhI+fcx0p3r Suq0rnA90Od3ZMxf6xmaOdYTx7WK5Xjv+V9yuaEWIQWfF9gPKKHS5kyTx8oSispj2e6d KGPTu8LamQuST7KHad5Xp6Kj5XOwKDj7bHh4ui6GlguOASczapk22QY8lVeWGBSYKzVc 6OchJjZ2MVqApO49vQtKsjeij17sIDMCfKdlOHUibuen900Oa48YVLQ9Yosvx2/aG5gO UBiFxRUZ+UjwNs13hBQdjLdroVOiM8b6BgQh+AY+jTfAehRaTp69nikodKbFl+RyuCKI WFrQ== X-Gm-Message-State: AOAM533+MMpWTMOVP1Y52gLAgpp5t55EzI0b5sYnCW6+DdonPtMddMZJ QiOZle/Qrh6rwE3OfuorUfsCRuHQxFTccw== X-Received: by 2002:ac8:6bcf:: with SMTP id b15mr21167736qtt.34.1612291371897; Tue, 02 Feb 2021 10:42:51 -0800 (PST) Received: from gouda.nowheycreamery.com (c-68-32-74-190.hsd1.mi.comcast.net. [68.32.74.190]) by smtp.gmail.com with ESMTPSA id k4sm7415906qtq.13.2021.02.02.10.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 10:42:51 -0800 (PST) Sender: Anna Schumaker From: schumaker.anna@gmail.com X-Google-Original-From: Anna.Schumaker@Netapp.com To: linux-nfs@vger.kernel.org Cc: Anna.Schumaker@Netapp.com Subject: [PATCH v2 5/5] sunrpc: Create a per-rpc_clnt file for managing the destination IP address Date: Tue, 2 Feb 2021 13:42:44 -0500 Message-Id: <20210202184244.288898-6-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210202184244.288898-1-Anna.Schumaker@Netapp.com> References: <20210202184244.288898-1-Anna.Schumaker@Netapp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Anna Schumaker Reading the file displays the current destination address, and writing to it allows users to change the address. And since we're using IP here, restrict to only creating sysfs files for TCP and RDMA connections. Signed-off-by: Anna Schumaker --- v2: Change filename and related functions from "address" to "dstaddr" Combine patches for reading and writing to this file --- net/sunrpc/sysfs.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ net/sunrpc/sysfs.h | 1 + 2 files changed, 48 insertions(+) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 42a690f8bb52..8b01b4df64ee 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -3,6 +3,8 @@ * Copyright (c) 2020 Anna Schumaker */ #include +#include +#include #include #include "sysfs.h" @@ -55,6 +57,37 @@ int rpc_sysfs_init(void) return 0; } +static ssize_t rpc_netns_dstaddr_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct rpc_netns_client *c = container_of(kobj, + struct rpc_netns_client, kobject); + struct rpc_clnt *clnt = c->clnt; + struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt); + + return rpc_ntop((struct sockaddr *)&xprt->addr, buf, PAGE_SIZE); +} + +static ssize_t rpc_netns_dstaddr_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct rpc_netns_client *c = container_of(kobj, + struct rpc_netns_client, kobject); + struct rpc_clnt *clnt = c->clnt; + struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt); + struct sockaddr *saddr = (struct sockaddr *)&xprt->addr; + int port = rpc_get_port(saddr); + + xprt->addrlen = rpc_pton(xprt->xprt_net, buf, count - 1, saddr, sizeof(*saddr)); + rpc_set_port(saddr, port); + + kfree(xprt->address_strings[RPC_DISPLAY_ADDR]); + xprt->address_strings[RPC_DISPLAY_ADDR] = kstrndup(buf, count - 1, GFP_KERNEL); + + xprt->ops->connect(xprt, NULL); + return count; +} + static void rpc_netns_client_release(struct kobject *kobj) { struct rpc_netns_client *c; @@ -68,8 +101,17 @@ static const void *rpc_netns_client_namespace(struct kobject *kobj) return container_of(kobj, struct rpc_netns_client, kobject)->net; } +static struct kobj_attribute rpc_netns_client_dstaddr = __ATTR(dstaddr, + 0644, rpc_netns_dstaddr_show, rpc_netns_dstaddr_store); + +static struct attribute *rpc_netns_client_attrs[] = { + &rpc_netns_client_dstaddr.attr, + NULL, +}; + static struct kobj_type rpc_netns_client_type = { .release = rpc_netns_client_release, + .default_attrs = rpc_netns_client_attrs, .sysfs_ops = &kobj_sysfs_ops, .namespace = rpc_netns_client_namespace, }; @@ -100,10 +142,15 @@ static struct rpc_netns_client *rpc_netns_client_alloc(struct kobject *parent, void rpc_netns_sysfs_setup(struct rpc_clnt *clnt, struct net *net) { struct rpc_netns_client *rpc_client; + struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt); + + if (!(xprt->prot & (IPPROTO_TCP | XPRT_TRANSPORT_RDMA))) + return; rpc_client = rpc_netns_client_alloc(rpc_client_kobj, net, clnt->cl_clid); if (rpc_client) { clnt->cl_sysfs = rpc_client; + rpc_client->clnt = clnt; kobject_uevent(&rpc_client->kobject, KOBJ_ADD); } } diff --git a/net/sunrpc/sysfs.h b/net/sunrpc/sysfs.h index 279a836594e7..137a12c87954 100644 --- a/net/sunrpc/sysfs.h +++ b/net/sunrpc/sysfs.h @@ -8,6 +8,7 @@ struct rpc_netns_client { struct kobject kobject; struct net *net; + struct rpc_clnt *clnt; }; extern struct kobject *rpc_client_kobj; -- 2.29.2