Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2206869pxb; Fri, 25 Mar 2022 13:03:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkirC3jlQK18Bz+tDHfcbeGQw/GdTPUbM/fc7hycZ0IUdFDu4dT0EcrlDNMOAGyOqVX3rZ X-Received: by 2002:a65:4c4e:0:b0:375:5fb1:6a54 with SMTP id l14-20020a654c4e000000b003755fb16a54mr941381pgr.231.1648238589928; Fri, 25 Mar 2022 13:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648238589; cv=none; d=google.com; s=arc-20160816; b=k3b++YCVsKMs9FL5WDfzM97Xi9vxhDTBrl2LNXImLr5GNsvt2z5D5fYQjJLExQrp/O nPCbDmDD72SE109T4+SP4XdYLdNfVGRhq2eiTAXPED8COTmHb+BOQinhI7ToiML4Rjnl eWd7hLYMUtYexZLPBqccmeIQd3ipeS6oYwm070wt0kqYB5EqdfgupesrJWQhfTw02tB3 M9/eibZuaCOkxKxnAvNiibcg4Ogee+OnkDOJeL4RY5p9oZkkLeysn0MXkztQei8bmdrK 5Ge07A7kUSIs77LLUSd/kQI0i49levVL4JouG3DtNLz6tK8zEhK9oprnE/Uz4W9r1U+E Lw1Q== 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=G8GM4MIV6weXHML5e95nlI1q+yjZ780txx1w6GsVKX8=; b=q86S6+CHPAQmf+XtmUPOWR4X1XyIwQPmb435HP87kcSXMZGesqSDcj9ATLJX70J7T3 ajfqTpVIhQc3MpRMeZY1rCm6hnn3mj6N478hTGBA7WQAQVMK3tdNGVybzER8frRD7/ih FW614n439VTxzr5ur+rD37Ojq7vqjpPoqIh8LELe8QOxQzHRH2DHnDq4esDgFtN9Ngtx aPYpvhkNkVAEllI1B5P1zMyfHUTPrKPaJdnlJkzoWUcoe0JrPbHlvvuLPn6cwVvme2xn FYMHZhM7/28ZJc5YhzdRCoQ1NyLunK1a/iHzoaCWV1gRkhAx819XI6mxWhFXhDXqFpsf vR+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UKmLfqdT; 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 g3-20020aa78183000000b004fa3a8e005csi3394163pfi.275.2022.03.25.13.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 13:03:09 -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=UKmLfqdT; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DD3463ACB86; Fri, 25 Mar 2022 11:53:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350083AbiCYQTp (ORCPT + 99 others); Fri, 25 Mar 2022 12:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354969AbiCYQTn (ORCPT ); Fri, 25 Mar 2022 12:19:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C93EA2634 for ; Fri, 25 Mar 2022 09:18:06 -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 6587A6195E for ; Fri, 25 Mar 2022 16:18:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9641BC340EE for ; Fri, 25 Mar 2022 16:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648225085; bh=yT7k4sUpBRY+2reRl9B0zDvpuVLwS1wH51qi5QKyEbo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UKmLfqdTa98/D8GCT+Y+ccQeL+bhkAsH9MrFM5UtCzFjttRcdxOW24x+fkMx/thyu HdsiczHaVNvPfGddcnDvP0HXUTjEF0ZFupsE0UpHa1r9Y7+bjLYUqQVWB2PLLnTWBh o/I93e1FD8UMVreW30FPiv4PU6PREdX0wVl0Etf0WV3kT681rFq8aLUTlUzDxZYaRt Sc37apKS5i8Tf0FmP1qNQpN2lT4ONS3cOF+Z+6JuLnp8TJuHDPMdQ/hpXPP6H6FCbD C0hLKSJ3vK4AZ37sdu1/8vbcnqy0uNM3TWdcRn+EuMx2aqcpF2Y2vYQ7bGK8FDzeM8 vGVNcYhnmSZZw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 2/2] SUNRPC: Don't return error values in sysfs read of closed files Date: Fri, 25 Mar 2022 12:11:38 -0400 Message-Id: <20220325161138.249905-2-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220325161138.249905-1-trondmy@kernel.org> References: <20220325161138.249905-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 --- 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 60ff32296da3..7a9ff2e6261a 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 + 1; } @@ -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") + 1; } else if (xprt->ops->get_srcaddr) { ret = xprt->ops->get_srcaddr(xprt, buf, buflen); if (ret > 0) { @@ -121,8 +124,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj, buf[ret] = '\0'; ret++; } - } - } + } else + ret = sprintf(buf, "\n") + 1; + } else + ret = sprintf(buf, "\n") + 1; xprt_put(xprt); return ret; } @@ -136,8 +141,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) @@ -155,6 +160,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 + 1; } @@ -168,10 +174,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