From patchwork Mon Mar 3 17:35:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13999318 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 74C88229B07 for ; Mon, 3 Mar 2025 17:35:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023332; cv=none; b=PV8nF2nz+qtnBW6x+YE2MRYAmJxfJMDNfyLTWSN/ZRGfrzYMs/BIIQd8qTIvKfp1NcDZh5uLq/sWpiqWWKpyoCEwSoPQuBgqHDNBoLBw8anWde5pZoKHcmWPfx8scWtlm5BaeO8EPCyglFdZ1wwND78dOCoXZbIdg9TxSa94goc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023332; c=relaxed/simple; bh=EpKWPQzTNBw177+7i7o4nHfA55aEQaK6Lpc7ifz2b9k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k01DNgbXdktXG+6+hBSs5rwsARINlBc/nvKgtYos+97kY8jqVrq/fq0t+tdzmVNN2JsYXuMLW9YijdyudiXIGjmWFPmaE90nHq5HZ1Pc5vZmdXEDfC+tmpB/Hw5XnPNUxdjezwsGnr/fy7V40PSFsrPcL2tqZzukjESohTUFAlA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jeCSv0su; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jeCSv0su" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B20A6C4CEE6 for ; Mon, 3 Mar 2025 17:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023331; bh=EpKWPQzTNBw177+7i7o4nHfA55aEQaK6Lpc7ifz2b9k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jeCSv0suN/YfGCvYugTxCw/KDAHERWzEwQzUa4VivzVbUI07tNouaxveM/myZkZqJ mSJmo6FPpns83YWNdqGVsdGJ0XOIxWEXufl34LXMQdqNEH4SdhI/w73yZm7Xjnph6u hBU4PHh+KIU+4w1e0oi1xzGKUqO1LYDZDNNbpNJ0PWo2WWWoevVt2J+/ONDCXqa7mH uCqBGiotvJt4HygDee8JamhA5GLIaCZNsfbrDvnSzFSYt6g/iEw4GFzJhtLk1dqE9z 7/UmGRlNCJ/fKZKPtpcALZffthyJqaa5AfDyVNujyUEFJ5vFqJCpGRMbS/8xHbOSTm LZCWORHcPrtig== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 1/4] NFSv4: Don't trigger uneccessary scans for return-on-close delegations Date: Mon, 3 Mar 2025 12:35:26 -0500 Message-ID: <045c99eddfe99f10c4c16675f7e6955a16a17810.1741023037.git.trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Trond Myklebust The amount of looping through the list of delegations is occasionally leading to soft lockups. Avoid at least some loops by not requiring the NFSv4 state manager to scan for delegations that are marked for return-on-close. Instead, either mark them for immediate return (if possible) or else leave it up to nfs4_inode_return_delegation_on_close() to return them once the file is closed by the application. Fixes: b757144fd77c ("NFSv4: Be less aggressive about returning delegations for open files") Signed-off-by: Trond Myklebust --- fs/nfs/delegation.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 4db912f56230..df77d68d9ff9 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -590,17 +590,6 @@ static bool nfs_delegation_need_return(struct nfs_delegation *delegation) if (test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags)) ret = true; - else if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags)) { - struct inode *inode; - - spin_lock(&delegation->lock); - inode = delegation->inode; - if (inode && list_empty(&NFS_I(inode)->open_files)) - ret = true; - spin_unlock(&delegation->lock); - } - if (ret) - clear_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags); if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags) || test_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags) || test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) @@ -878,11 +867,25 @@ int nfs4_inode_make_writeable(struct inode *inode) return nfs4_inode_return_delegation(inode); } -static void nfs_mark_return_if_closed_delegation(struct nfs_server *server, - struct nfs_delegation *delegation) +static void +nfs_mark_return_if_closed_delegation(struct nfs_server *server, + struct nfs_delegation *delegation) { - set_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags); - set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state); + struct inode *inode; + + if (test_bit(NFS_DELEGATION_RETURN, &delegation->flags) || + test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags)) + return; + spin_lock(&delegation->lock); + inode = delegation->inode; + if (!inode) + goto out; + if (list_empty(&NFS_I(inode)->open_files)) + nfs_mark_return_delegation(server, delegation); + else + set_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags); +out: + spin_unlock(&delegation->lock); } static bool nfs_server_mark_return_all_delegations(struct nfs_server *server) From patchwork Mon Mar 3 17:35:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13999319 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 C336822B5AB for ; Mon, 3 Mar 2025 17:35:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023332; cv=none; b=EkvKXDxy0m4Eurelxj2jBBWyEPPh5uPueOYUbl+tTttTQ20dQ7hYCc/1uW1n5yRMlXiDDTV907lSH8cma6tVM4uCBuK9s5D0g2Xs3xbH+yV0Bk6rCD+4CQE5GTIb9KeKiSo9mDzsiQ9u/n2jc7mXOLKDHvDz9ojZpV+BV7EXbvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023332; c=relaxed/simple; bh=viZH39/Hz7SX5oqB1O1obicG4xEf1225wzArudsgz+U=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QK0XOoz2BkMuvt2GVcNLAIqRRg5YyfwsCTMNKKivGTaR0krtVjs3I22ZCWfeJDRO3W/S9SVg6GDxAfWlwhIIA41W5lKsIIjb7/twiZElRbh6q/GMcbWDTwqjSYY9c1kAZi4Vv3fL/y2ROxeRsoRQ6sMsC4+l5TcJA0Pqbo++jDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fb6xYd7V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fb6xYd7V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2284DC4CEE5 for ; Mon, 3 Mar 2025 17:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023332; bh=viZH39/Hz7SX5oqB1O1obicG4xEf1225wzArudsgz+U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fb6xYd7VLxDl4p6he8h2BfXhW2Vjeh2MZOXFx/rQqknyEptoccwDg+uE2BPo+7TvJ 34sp5QVXscWt0u2Cmu820qVuYEgreTnf+IxzRHwNwUwTL8bErIXoDLc0ncnmGL7nR5 fg+BbwiMgPoAiGxbqaYtSikk+Ih96Hgda+oUlgIAW0kNh1Jmr1No5ZNst61aymx1eN 1Ab7aHSGHrRqLL6VxPmCEPxoSd38242kgjewPj4QXVBiq3nXJRxuoCV8I9VPKcB0KY VhHx9QwQSjzWOiN4DZnhWhUp/2+WVgKdXXWzTuk+kKSi6GfClIhPbwlw2LT4g7tHqy r4RVd50MQ9+gA== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 2/4] NFSv4: Avoid unnecessary scans of filesystems for returning delegations Date: Mon, 3 Mar 2025 12:35:27 -0500 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Trond Myklebust The amount of looping through the list of delegations is occasionally leading to soft lockups. If the state manager was asked to return delegations asynchronously, it should only scan those filesystems that hold delegations that need to be returned. Fixes: af3b61bf6131 ("NFSv4: Clean up nfs_client_return_marked_delegations()") Signed-off-by: Trond Myklebust --- fs/nfs/delegation.c | 5 +++++ include/linux/nfs_fs_sb.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index df77d68d9ff9..d1f5e497729c 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -79,6 +79,7 @@ static void nfs_mark_return_delegation(struct nfs_server *server, struct nfs_delegation *delegation) { set_bit(NFS_DELEGATION_RETURN, &delegation->flags); + set_bit(NFS4SERV_DELEGRETURN, &server->delegation_flags); set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state); } @@ -608,6 +609,9 @@ static int nfs_server_return_marked_delegations(struct nfs_server *server, struct nfs_delegation *place_holder_deleg = NULL; int err = 0; + if (!test_and_clear_bit(NFS4SERV_DELEGRETURN, + &server->delegation_flags)) + return 0; restart: /* * To avoid quadratic looping we hold a reference @@ -659,6 +663,7 @@ static int nfs_server_return_marked_delegations(struct nfs_server *server, cond_resched(); if (!err) goto restart; + set_bit(NFS4SERV_DELEGRETURN, &server->delegation_flags); set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state); goto out; } diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index f00bfcee7120..4e9ad6f6e907 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -250,6 +250,8 @@ struct nfs_server { struct list_head ss_copies; struct list_head ss_src_copies; + unsigned long delegation_flags; +#define NFS4SERV_DELEGRETURN (1) unsigned long delegation_gen; unsigned long mig_gen; unsigned long mig_status; From patchwork Mon Mar 3 17:35:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13999320 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 3B85522CBE3 for ; Mon, 3 Mar 2025 17:35:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023333; cv=none; b=olGIOs6pl8j7Fj6WD3C1hgkUlMhCcW/5+EN0m9m1tkEYn+1Tyvv8jEjvodiY/cfBwezSN8Nj2G1Ny3AgSBdreaCROXEacS4/9U7y2OtgAfebVEjgICKkda2uIk3whCulKD9TVFnAvCjZOu753f9leocFnhDMYpyi2mbuDnRefPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023333; c=relaxed/simple; bh=168Jj55IR5jfTLC3cOhyBBHZQ4MAGt9BkCU0cK/oy28=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gyl0iVMCVNq8yoAN67sr/kKEZEL8n2wQv+ZT77sohHNKNOVzL/PvpLLkA5cnRjgQdTpZhTvZEKiFkgxZRmyg5R9vMdSYSW5Nxm05DT4P6/Y6Rev49FjfnysbTzJDvEwd2KckN5aDvZHcUTa3ICRJD+CRt9QPnF+UotWkLIxh6L4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LcDes4po; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LcDes4po" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8847CC4CEF0 for ; Mon, 3 Mar 2025 17:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023332; bh=168Jj55IR5jfTLC3cOhyBBHZQ4MAGt9BkCU0cK/oy28=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LcDes4poi7GOc2yEmmKNlgz9HIAjxJ3AQtz7gyRYM7ShY6FRxmiJmnp3RFJjhUYQw jhbAlB0pOW1YbF7jHvq6ShTkZBBaV6c51TxtradnHFVi7uvqXAiNBr6Ah5Yb1rg2FC w5Jn8UTXuBVKM9vV2QBYRn4pbROP43Vkml6Nky7blQai0eRLYK7meNjfIDr7C3wvTu EgVN58UtXLew9BSOCFf1BzTE8wUZudbUW9TLMOKAukkcfqKh7/F5zMR/sXLy8eHAZO JYY3ORj8GH2c/K9QN9BdUu2UIq2VGuxWZesWGRtEFuWzWrMWr700ZaXfkDKc7/uxyF LSwB6UdY0VAYA== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 3/4] NFSv4: Avoid unnecessary scans of filesystems for expired delegations Date: Mon, 3 Mar 2025 12:35:28 -0500 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Trond Myklebust The amount of looping through the list of delegations is occasionally leading to soft lockups. If the state manager was asked to reap the expired delegations, it should scan only those filesystems that hold delegations that need to be reaped. Fixes: 7f156ef0bf45 ("NFSv4: Clean up nfs_delegation_reap_expired()") Signed-off-by: Trond Myklebust --- fs/nfs/delegation.c | 7 +++++++ include/linux/nfs_fs_sb.h | 1 + 2 files changed, 8 insertions(+) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index d1f5e497729c..abd952cc47e4 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -1284,6 +1284,7 @@ static void nfs_mark_test_expired_delegation(struct nfs_server *server, return; clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); set_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags); + set_bit(NFS4SERV_DELEGATION_EXPIRED, &server->delegation_flags); set_bit(NFS4CLNT_DELEGATION_EXPIRED, &server->nfs_client->cl_state); } @@ -1362,6 +1363,9 @@ static int nfs_server_reap_expired_delegations(struct nfs_server *server, nfs4_stateid stateid; unsigned long gen = ++server->delegation_gen; + if (!test_and_clear_bit(NFS4SERV_DELEGATION_EXPIRED, + &server->delegation_flags)) + return 0; restart: rcu_read_lock(); list_for_each_entry_rcu(delegation, &server->delegations, super_list) { @@ -1391,6 +1395,9 @@ static int nfs_server_reap_expired_delegations(struct nfs_server *server, goto restart; } nfs_inode_mark_test_expired_delegation(server,inode); + set_bit(NFS4SERV_DELEGATION_EXPIRED, &server->delegation_flags); + set_bit(NFS4CLNT_DELEGATION_EXPIRED, + &server->nfs_client->cl_state); iput(inode); return -EAGAIN; } diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index 4e9ad6f6e907..7d6f164036fa 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -252,6 +252,7 @@ struct nfs_server { unsigned long delegation_flags; #define NFS4SERV_DELEGRETURN (1) +#define NFS4SERV_DELEGATION_EXPIRED (2) unsigned long delegation_gen; unsigned long mig_gen; unsigned long mig_status; From patchwork Mon Mar 3 17:35:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13999321 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 5482E226555 for ; Mon, 3 Mar 2025 17:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023333; cv=none; b=t7DD0E79A6BQRsMqrElwd3rMwixceQwkdFLWNxigeUzsnfEYTBqGX79EoUpFnZZgiPZkRYpq/XQjqZyJ9TxVKXrOkNgVZDNDGzFfD3Hp+pAj1e6uASDyPB8+KIeW4UNAWECwK2VNh7G8zs3wSnxY0vXYexNnJrNVQ4IZpiN6YcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023333; c=relaxed/simple; bh=HWRPD8Jm2WXEs5QuG49E0Pus4tRr6d9oxCT/EDiMLxc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PXh5QBq5v3OvYnrAWZCjlsEuPJ9nE6jac+jHyXysFE/1XHNbPcAAMDrr6iid3xc7kfrUwGUNBh1YxGaladpm8m+AXB5nyi2v9ym2jXIS9D9/E66C4lFwZbVYOUwgzmS9iAMNveE4FiSrokIS3R1+I9hMEbGeadkZ071s3PWCXVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CHc5s4wP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CHc5s4wP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C779C4CED6 for ; Mon, 3 Mar 2025 17:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023333; bh=HWRPD8Jm2WXEs5QuG49E0Pus4tRr6d9oxCT/EDiMLxc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CHc5s4wPZ6jj6YVLnR3eEPBdt69uwYSmYTpUit26wnUp2nns3rsLskphzjWvYSM24 81QL3Xq4qG496q+BHzK087VTmkg5Dxuj4Xa96AiQlWxQYQFrXf6aV87xCR81uQCDYu 3PFIbF1tlQoNGpFp7aVxl/MfmNzalP/1pwyr8bIv7m5TYNhL1xTI1qOP2WgMmtlNmF AGc1IC3shZr3oPYhdVZAyfTUGbJerG6LLXPyKHlk/YHCL0pnxDx+b561JFpWKRI3uS cTNL4YX43pjp8YTiB5PG/CGDLa93MG7L/bc8Va1Ae+/NjKwNLvdBJuaxVUdZWuLkWr fmG6Mr/IBzhmw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 4/4] NFSv4: Avoid unnecessary scans of filesystems for delayed delegations Date: Mon, 3 Mar 2025 12:35:29 -0500 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Trond Myklebust The amount of looping through the list of delegations is occasionally leading to soft lockups. If the state manager was asked to manage the delayed return of delegations, then only scan those filesystems containing delegations that were marked as being delayed. Fixes: be20037725d1 ("NFSv4: Fix delegation return in cases where we have to retry") Signed-off-by: Trond Myklebust --- fs/nfs/delegation.c | 18 ++++++++++++------ include/linux/nfs_fs_sb.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index abd952cc47e4..325ba0663a6d 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -331,14 +331,16 @@ nfs_start_delegation_return(struct nfs_inode *nfsi) } static void nfs_abort_delegation_return(struct nfs_delegation *delegation, - struct nfs_client *clp, int err) + struct nfs_server *server, int err) { - spin_lock(&delegation->lock); clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags); if (err == -EAGAIN) { set_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags); - set_bit(NFS4CLNT_DELEGRETURN_DELAYED, &clp->cl_state); + set_bit(NFS4SERV_DELEGRETURN_DELAYED, + &server->delegation_flags); + set_bit(NFS4CLNT_DELEGRETURN_DELAYED, + &server->nfs_client->cl_state); } spin_unlock(&delegation->lock); } @@ -548,7 +550,7 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred, */ static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation *delegation, int issync) { - struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; + struct nfs_server *server = NFS_SERVER(inode); unsigned int mode = O_WRONLY | O_RDWR; int err = 0; @@ -570,11 +572,11 @@ static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation /* * Guard against state recovery */ - err = nfs4_wait_clnt_recover(clp); + err = nfs4_wait_clnt_recover(server->nfs_client); } if (err) { - nfs_abort_delegation_return(delegation, clp, err); + nfs_abort_delegation_return(delegation, server, err); goto out; } @@ -678,6 +680,9 @@ static bool nfs_server_clear_delayed_delegations(struct nfs_server *server) struct nfs_delegation *d; bool ret = false; + if (!test_and_clear_bit(NFS4SERV_DELEGRETURN_DELAYED, + &server->delegation_flags)) + goto out; list_for_each_entry_rcu (d, &server->delegations, super_list) { if (!test_bit(NFS_DELEGATION_RETURN_DELAYED, &d->flags)) continue; @@ -685,6 +690,7 @@ static bool nfs_server_clear_delayed_delegations(struct nfs_server *server) clear_bit(NFS_DELEGATION_RETURN_DELAYED, &d->flags); ret = true; } +out: return ret; } diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index 7d6f164036fa..108862d81b57 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -253,6 +253,7 @@ struct nfs_server { unsigned long delegation_flags; #define NFS4SERV_DELEGRETURN (1) #define NFS4SERV_DELEGATION_EXPIRED (2) +#define NFS4SERV_DELEGRETURN_DELAYED (3) unsigned long delegation_gen; unsigned long mig_gen; unsigned long mig_status;