Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2574875rwr; Fri, 21 Apr 2023 10:41:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bHb80WitRMYgZT71qhDdDVxkjGbqzcdMVwCqUAAW4I1OeKvbsdobEUUZxC9NmkinGpdoLj X-Received: by 2002:a17:902:f693:b0:1a2:58f1:5e1d with SMTP id l19-20020a170902f69300b001a258f15e1dmr7368659plg.36.1682098867679; Fri, 21 Apr 2023 10:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682098867; cv=none; d=google.com; s=arc-20160816; b=oaxTS/UC4tdM8Y5FZGylPzvb/3eG4twFe8v7uvDijQRSgrxdcVGRHlLqgbm0Bm4KBP RhmsKfAsYjq0CttVUzqar8SfdS7IDud/8/b3yGBLUbuKM3X+N7QlRGK9vJH9N3GiukX+ gDha7ouhqOMRwwnaVjF7K14rWMEfICtdFdzXi2yosRG3f4tqNd8eTxZZyw+XQ7GC7L/m 3CrGyLtfgpLaxcTRlq+Pla80JIeXEMBuDWosLVrkBxqCxlLqqX5WHCdPP7XeRCbWV3JB +eXkAEIxDKa0s7WZb4RqrEq/VXSCwO59Kw+54wR8woOmdFS7cLXppyHGRhYEp5Zyo/lF saZw== 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=9S3EJJd783yVw0y/enXpAp/TWSHq6vt71X8pLPKuEJo=; b=CTmWGJppx0fjxPtAkxl+i/B8Szz2GRW1zVHkiMNrdxwf+pgRxbXStOn41s+UZY05zm 0vivE5ce/wSqB+vah7y0jDVNbP/lwwoXwpuD7gr4ff0yzbu8bHJ/tfvHbSvfdZFFULkW t8Dp2U+mJZMnkdr8AiTui1rRRalf7BrwAOGOZJ8fsx+p4hjUbFcPqnV2LqL/TuJ7wrGL 8XPibEWFuy0N3ABoc9uFtZ3kRePZAOBqPuqUNefTNYq7H37Y+LaDl+7oImqwCH3UWjQM 2NCWCqzy/UBFBLnJKl38c8qgfF4UHeyc1Qr7gVOA2EwHSPR0/LuKx+xTYlU6rh55/Z+m /8Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TN5opxIB; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a170902680800b001a6fafb3661si4786283plk.459.2023.04.21.10.40.54; Fri, 21 Apr 2023 10:41:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TN5opxIB; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232286AbjDURUJ (ORCPT + 99 others); Fri, 21 Apr 2023 13:20:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbjDURUI (ORCPT ); Fri, 21 Apr 2023 13:20:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 611FFD32A for ; Fri, 21 Apr 2023 10:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682097526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9S3EJJd783yVw0y/enXpAp/TWSHq6vt71X8pLPKuEJo=; b=TN5opxIBkkYxHdhhOWrfmFsz5512Zq8Vj1gPqpH0u3DmKkl9o+zLRmBDf02BX2rEY9PgRS fZ7hZcicPEpkN8s7OX6uEJYLH7Uq0Z8vt+XbIA6X/VU/iwTI3+nzuoVcMhfsvP4ln6sxfV QfLypCIrSLJKXc4cl0mtMhx5Satxoyw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-395-FaUiZBQ9OXekfdTAJpnh6A-1; Fri, 21 Apr 2023 13:18:45 -0400 X-MC-Unique: FaUiZBQ9OXekfdTAJpnh6A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A8231382C969 for ; Fri, 21 Apr 2023 17:18:44 +0000 (UTC) Received: from bcodding.csb.redhat.com (ovpn-0-3.rdu2.redhat.com [10.22.0.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 531F440C2064 for ; Fri, 21 Apr 2023 17:18:44 +0000 (UTC) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH 7/9] NFS: add sysfs shutdown knob Date: Fri, 21 Apr 2023 13:18:37 -0400 Message-Id: <2493a957a1c842d5cf32a4c2347dd17e6cb3370d.1682097420.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Within each nfs_server sysfs tree, add an entry named "shutdown". Writing 1 to this file will set the cl_shutdown bit on the rpc_clnt structs associated with that mount. If cl_shutdown is set, the task scheduler immediately returns -EIO for new tasks. Signed-off-by: Benjamin Coddington --- fs/nfs/sysfs.c | 46 +++++++++++++++++++++++++++++++++++++ include/linux/nfs_fs_sb.h | 1 + include/linux/sunrpc/clnt.h | 3 ++- net/sunrpc/clnt.c | 5 ++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c index e1b5df7a3df5..09fde2719495 100644 --- a/fs/nfs/sysfs.c +++ b/fs/nfs/sysfs.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "nfs4_fs.h" #include "netns.h" @@ -191,6 +192,50 @@ void nfs_netns_sysfs_destroy(struct nfs_net *netns) } } +static ssize_t +shutdown_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct nfs_server *server = container_of(kobj, struct nfs_server, kobj); + bool shutdown = server->flags & NFS_MOUNT_SHUTDOWN; + return sysfs_emit(buf, "%d\n", shutdown); +} + +static ssize_t +shutdown_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct nfs_server *server; + int ret, val; + + server = container_of(kobj, struct nfs_server, kobj); + + ret = kstrtoint(buf, 0, &val); + if (ret) + return ret; + + if (val != 1) + return -EINVAL; + + /* already shut down? */ + if (server->flags & NFS_MOUNT_SHUTDOWN) + goto out; + + server->flags |= NFS_MOUNT_SHUTDOWN; + server->client->cl_shutdown = 1; + server->nfs_client->cl_rpcclient->cl_shutdown = 1; + + if (!IS_ERR(server->client_acl)) + server->client_acl->cl_shutdown = 1; + + if (server->nlm_host) + server->nlm_host->h_rpcclnt->cl_shutdown = 1; +out: + return count; +} + +static struct kobj_attribute nfs_sysfs_attr_shutdown = __ATTR_RW(shutdown); + #define RPC_CLIENT_NAME_SIZE 64 void nfs_sysfs_link_rpc_client(struct nfs_server *server, @@ -217,6 +262,7 @@ static void nfs_sysfs_sb_release(struct kobject *kobj) } static struct attribute *nfs_mp_attrs[] = { + &nfs_sysfs_attr_shutdown.attr, NULL, }; diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index dee1664abca8..bc89496384ff 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -153,6 +153,7 @@ struct nfs_server { #define NFS_MOUNT_WRITE_EAGER 0x01000000 #define NFS_MOUNT_WRITE_WAIT 0x02000000 #define NFS_MOUNT_TRUNK_DISCOVERY 0x04000000 +#define NFS_MOUNT_SHUTDOWN 0x08000000 unsigned int fattr_valid; /* Valid attributes */ unsigned int caps; /* server capabilities */ diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index 4ec718aa91f5..9f72c75a2056 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h @@ -63,7 +63,8 @@ struct rpc_clnt { cl_discrtry : 1,/* disconnect before retry */ cl_noretranstimeo: 1,/* No retransmit timeouts */ cl_autobind : 1,/* use getport() */ - cl_chatty : 1;/* be verbose */ + cl_chatty : 1,/* be verbose */ + cl_shutdown : 1;/* rpc immediate -EIO */ struct rpc_rtt * cl_rtt; /* RTO estimator data */ const struct rpc_timeout *cl_timeout; /* Timeout strategy */ diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 0b0b9f1eed46..3c5dca88a918 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -1717,6 +1717,11 @@ call_start(struct rpc_task *task) trace_rpc_request(task); + if (task->tk_client->cl_shutdown) { + rpc_call_rpcerror(task, -EIO); + return; + } + /* Increment call count (version might not be valid for ping) */ if (clnt->cl_program->version[clnt->cl_vers]) clnt->cl_program->version[clnt->cl_vers]->counts[idx]++; -- 2.39.2