Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2236399pxb; Fri, 25 Mar 2022 13:37:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLTJgqc2rBQuiu8PsvCM32K+hq8x22VCC2JOAhcQ/M5NBrWTmE4nr5MxiRT28wI7VxeQIZ X-Received: by 2002:a17:90a:d195:b0:1bf:a0a8:6c3a with SMTP id fu21-20020a17090ad19500b001bfa0a86c3amr26827794pjb.162.1648240648230; Fri, 25 Mar 2022 13:37:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648240648; cv=none; d=google.com; s=arc-20160816; b=bCTtwp3JDn3J23K/9UdYsSZMpqCiue0idugubB34u6fHdiRAagkBbnWBk7XK6d+Kn7 LrTXyxTkeY+KQj50FRCGz1VZeHdrvBK6783XWFH/FexKzc/c5/TQkvaLhYiR34Qt3bb7 +YxWII9Zon7b+O9suWpCMtzgPlO+fvXkqsA8O3BuoWFOT6ie8udWpYh7w0OnvyHPWKqS DHbEDglRTW+hkI8dglIxIeq5BGGiyYvP7ILDtDkc21750wcipz0bfKHDpOCvGSWrK1jS 9ata1LPop4yu4ZqrU8gkjVBEVX96ny5KWrBNMlOwQrirepG+cahMqG6PJ+T03XHkpdVd z8RA== 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:to:from :dkim-signature; bh=RqLEulVymsNZsyA8cKXIlbNQpp1rQ8JLwPKoZCHUifw=; b=eOpPq7p/+gAOCNo8RUoubqm1IGnYTyvikycZ4JZ7EA/YDI/9dTXBtPSOa6C+JWMcXg j2DKNsKtPSSObQGHCAS/yrBJoaA56ZCoRU02REdVdYq82dreXTwaCOGWZ+Yp/cAqffz5 +5k2v0j+7GbIy1U3KEIHwEg6vGRQ7XwXi/NIkJpDV4ky1DbWYW9J38KkpMO3p9lEfKWp WEonwzDYSRpD/HHXwKl/oOcgS39S0oJOGFMK5dHjWZkCbwBoqQTvZRJnlIYtQ8BdNIVa EAZb5lTUmf+A7lbLdqtv+Bft9+Kfizl3kGwxXuSQSBdNtZEKrdyAAVodoNtejTWb10qD CM4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="i1/tS+HS"; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a16-20020a62e210000000b004fa3a8dff66si3353113pfi.29.2022.03.25.13.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 13:37:28 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="i1/tS+HS"; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 75192286DC; Fri, 25 Mar 2022 13:00:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232125AbiCYUB4 (ORCPT + 99 others); Fri, 25 Mar 2022 16:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbiCYUBn (ORCPT ); Fri, 25 Mar 2022 16:01:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C623B24A765 for ; Fri, 25 Mar 2022 12:52:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4F3CA61BF8 for ; Fri, 25 Mar 2022 18:02:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 802B5C34100 for ; Fri, 25 Mar 2022 18:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648231328; bh=wsVaQ6U8G7kdvaF7wHDkqDE5b0eb1ZOqOyqtvCNtpgI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=i1/tS+HSyaMQ3iqq4UXga+zRsIHLxPqWh15biVft7z8h8jhxhzflekjUmMVoEoPTw K16lCHBjchm3cCe9F88i4KU9jR0RN+hO5VE+28jFBr9Xt8tmzJQUiAGW5vXFIo1LU/ winbaneRPrOhSuzQtvMpvaV026/UtLetjykjATD6uRFhtyCLQr4aGFK2jNrvGaqEaL lmwyLDGhxdVOlFekGRpq9P2Inxhw5bGduw/JvbT6/qFYqYm7WJkqKvgArl/sOiMwZZ fEKYLtgpHgecSQcuVpZCxZZw74XgZEIZ11FuwQ99oSo7ZpOggctyf2gqOzxjkGu4wq fH91GULeQq5XA== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v3 2/2] SUNRPC: Don't return error values in sysfs read of closed files Date: Fri, 25 Mar 2022 13:55:21 -0400 Message-Id: <20220325175521.561344-2-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220325175521.561344-1-trondmy@kernel.org> References: <20220325175521.561344-1-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Instead of returning an error value, which ends up being the return value for the read() system call, it is more elegant to simply return the error as a string value. Signed-off-by: Trond Myklebust --- v2: Rewrite to use transport switch v3: remove '\0' from the pseudo-file net/sunrpc/sysfs.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 9d8a7d9f3e41..a3a2f8aeb80e 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -93,10 +93,13 @@ static ssize_t rpc_sysfs_xprt_dstaddr_show(struct kobject *kobj, struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj); ssize_t ret; - if (!xprt) - return 0; + if (!xprt) { + ret = sprintf(buf, "\n"); + goto out; + } ret = sprintf(buf, "%s\n", xprt->address_strings[RPC_DISPLAY_ADDR]); xprt_put(xprt); +out: return ret; } @@ -106,10 +109,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj, { struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj); size_t buflen = PAGE_SIZE; - ssize_t ret = -ENOTSOCK; + ssize_t ret; if (!xprt || !xprt_connected(xprt)) { - ret = -ENOTCONN; + ret = sprintf(buf, "\n"); } else if (xprt->ops->get_srcaddr) { ret = xprt->ops->get_srcaddr(xprt, buf, buflen); if (ret > 0) { @@ -118,8 +121,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj, ret++; buf[ret] = '\0'; } - } - } + } else + ret = sprintf(buf, "\n"); + } else + ret = sprintf(buf, "\n"); xprt_put(xprt); return ret; } @@ -133,8 +138,8 @@ static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj, ssize_t ret; if (!xprt || !xprt_connected(xprt)) { - xprt_put(xprt); - return -ENOTCONN; + ret = sprintf(buf, "\n"); + goto out; } if (xprt->ops->get_srcport) @@ -152,6 +157,7 @@ static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj, xprt->backlog.qlen, xprt->main, srcport, atomic_long_read(&xprt->queuelen), xprt->address_strings[RPC_DISPLAY_PORT]); +out: xprt_put(xprt); return ret; } @@ -165,10 +171,7 @@ static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj, int locked, connected, connecting, close_wait, bound, binding, closing, congested, cwnd_wait, write_space, offline, remove; - if (!xprt) - return 0; - - if (!xprt->state) { + if (!(xprt && xprt->state)) { ret = sprintf(buf, "state=CLOSED\n"); } else { locked = test_bit(XPRT_LOCKED, &xprt->state); -- 2.35.1