From nobody Wed Apr 29 08:07:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80902C43334 for ; Sun, 12 Jun 2022 08:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235000AbiFLIyS (ORCPT ); Sun, 12 Jun 2022 04:54:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234963AbiFLIyP (ORCPT ); Sun, 12 Jun 2022 04:54:15 -0400 Received: from nautica.notk.org (nautica.notk.org [91.121.71.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 368FA517C2 for ; Sun, 12 Jun 2022 01:54:12 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 97D35C020; Sun, 12 Jun 2022 10:54:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024051; bh=diOrVOPA1DrszPTKQ6G1Sn5TRoaAaysLytyk8w/ytPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cEqxsZOpI5UY8L6k/Hyl9zKBUgUhWi3iBUg6SAtx1bW4XJDs8x37Ed3znXtHO5bLH vV6l5qcd9yXSzShsEWowXq9AH5LAPrVIlUypkHj2bA8llA/uKgx2+T9WXfkky8H8HD uy268qCy2OERouN5ewO8UqD8/Rx+LIYYiP1EuxgmSB1QltwB83G3vu8ytmf51YG+t8 pZ0uvws+TWP6bHSlVqTrE9hQg0QmOjy3hbY3n5lcA4nGIggARi2K61OpGQmpJw6hWo laXoHOoWufPuyu2RmHMM5U6/mQcD/Mqzj/eqWW/bxiupIwCZoZyoKdJQLYEtcUE2P+ cxYQ/hTqc+TYA== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 0F523C009; Sun, 12 Jun 2022 10:54:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024050; bh=diOrVOPA1DrszPTKQ6G1Sn5TRoaAaysLytyk8w/ytPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z7+Fyk0YaikTR8PDuzHujHv0wrzZ6pAYvxQ6nilzdjvHQtMbQTqvQF7m7cT5D2lm1 3ZUqWJdzV3yzlq6ob156CtpbKHCood01UscjCfoOh6AfHaMmqoSUqV0s/wH08Bdcf1 RvrBmeKPof54b1OKaWGJKhXuzFJwOGetEVpc86KIMKBMzLyStIU4JurOL08seMZhEd e55j+UTc1NmESduVJLC8FXzlY9JDauq/rZ8AegrtuOoGP8YocXqyG1QhZjSKI8Zrif e/ivgLARLT6UBuSBFgeAEco2IlCNQh6Hw3L7K7naIYVvAioRtSgJYBUfMTP4XnBfag UQICS8ngDN5UQ== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 0605f16d; Sun, 12 Jun 2022 08:54:05 +0000 (UTC) From: Dominique Martinet To: Christian Schoenebeck , Tyler Hicks , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Jianyong Wu Cc: v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 01/06] 9p: fix fid refcount leak in v9fs_vfs_atomic_open_dotl Date: Sun, 12 Jun 2022 17:53:24 +0900 Message-Id: <20220612085330.1451496-2-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220612085330.1451496-1-asmadeus@codewreck.org> References: <20220612085330.1451496-1-asmadeus@codewreck.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We need to release directory fid if we fail halfway through open This fixes fid leaking with xfstests generic 531 Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct") Cc: stable@vger.kernel.org Reported-by: Tyler Hicks Signed-off-by: Dominique Martinet Reviewed-by: Christian Schoenebeck Reviewed-by: Tyler Hicks --- fs/9p/vfs_inode_dotl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index d17502a738a9..b6eb1160296c 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -274,6 +274,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, if (IS_ERR(ofid)) { err =3D PTR_ERR(ofid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); + p9_client_clunk(dfid); goto out; } =20 @@ -285,6 +286,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, if (err) { p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n", err); + p9_client_clunk(dfid); goto error; } err =3D p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags), @@ -292,6 +294,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n", err); + p9_client_clunk(dfid); goto error; } v9fs_invalidate_inode_attr(dir); --=20 2.35.1 From nobody Wed Apr 29 08:07:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B326C43334 for ; Sun, 12 Jun 2022 08:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235013AbiFLIyV (ORCPT ); Sun, 12 Jun 2022 04:54:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234993AbiFLIyR (ORCPT ); Sun, 12 Jun 2022 04:54:17 -0400 Received: from nautica.notk.org (nautica.notk.org [91.121.71.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAEA5517C3 for ; Sun, 12 Jun 2022 01:54:16 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 588EEC022; Sun, 12 Jun 2022 10:54:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024055; bh=NGrM8aOLW3P+D4Rx7zur1lNPPJiOVKsmRGPxJVvnPDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oKvYGL0B9tcmmAYPevuw7CIc9o+pAtZr6haB5YQiuGao/Alip1H1REebw+hGJpFUB jMMRfYcP72Fx5gR8FoFC/Zp7BUuxsaELWTG+Tb8mjbxQHxA7V9SQf/UToasJr9LWaX EQC91qVZtNkDh8Mr6zNBt/89VcQg2/P+j+VKv38XZ5lvU1CQTlARjFDP7ZMcXv7zrZ YVoLifracoufWYgUPjxoyCb+6fwqauLOdLNVpOfM86XK35la4JpbFEeP9nnglEcHGz yCfiJ5cL5AkIaRgQiPbF4as24QyRobtOCaceF79fZk/l5Q4ra6+EycUHyWhPUNAQyB ey8VNNC2Vji5w== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 626F2C01C; Sun, 12 Jun 2022 10:54:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024054; bh=NGrM8aOLW3P+D4Rx7zur1lNPPJiOVKsmRGPxJVvnPDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I8JxRLMQM5jMQ6KIrOGYGqQ2cTmfPMaiDXcawSxqCTrcOe9i7TXA1CdG6yvXQvFF1 P+hMvGTH7qo4uK5y4HYLxqlMdIsqhpiL6/IBHfibkpMMVQEnlyz0qKoXVj6UMN1idn VnoSI0xhPBkzFp+PzsHljfmsQTzDGpPV5F7ot/rgvom9PbQzNM/BT5Tz6S1fx5t0yz 6J558nM8AteTMbpWweNCRspQgPB8K/pMWqyEM5c1nS2NaJspr2kppuFK+a7lHIe/+K 1D2f7tfU2UFzhQVXknU3b/A8P4/4Scq+Y1kbWyPHAAaHBQUevvgOONEyT+nOZFFSGE ISxArtJEqAsRA== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id afea8486; Sun, 12 Jun 2022 08:54:08 +0000 (UTC) From: Dominique Martinet To: Christian Schoenebeck , Tyler Hicks , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Jianyong Wu Cc: v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 02/06] 9p: fix fid refcount leak in v9fs_vfs_get_link Date: Sun, 12 Jun 2022 17:53:25 +0900 Message-Id: <20220612085330.1451496-3-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220612085330.1451496-1-asmadeus@codewreck.org> References: <20220612085330.1451496-1-asmadeus@codewreck.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" we check for protocol version later than required, after a fid has been obtained. Just move the version check earlier. Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct") Cc: stable@vger.kernel.org Signed-off-by: Dominique Martinet Reviewed-by: Christian Schoenebeck Reviewed-by: Tyler Hicks --- fs/9p/vfs_inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 55367ecb9442..18c780ffd4b5 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -1250,15 +1250,15 @@ static const char *v9fs_vfs_get_link(struct dentry = *dentry, return ERR_PTR(-ECHILD); =20 v9ses =3D v9fs_dentry2v9ses(dentry); - fid =3D v9fs_fid_lookup(dentry); + if (!v9fs_proto_dotu(v9ses)) + return ERR_PTR(-EBADF); + p9_debug(P9_DEBUG_VFS, "%pd\n", dentry); + fid =3D v9fs_fid_lookup(dentry); =20 if (IS_ERR(fid)) return ERR_CAST(fid); =20 - if (!v9fs_proto_dotu(v9ses)) - return ERR_PTR(-EBADF); - st =3D p9_client_stat(fid); p9_client_clunk(fid); if (IS_ERR(st)) --=20 2.35.1 From nobody Wed Apr 29 08:07:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DC3DC433EF for ; Sun, 12 Jun 2022 08:54:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235035AbiFLIyY (ORCPT ); Sun, 12 Jun 2022 04:54:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235015AbiFLIyV (ORCPT ); Sun, 12 Jun 2022 04:54:21 -0400 Received: from nautica.notk.org (nautica.notk.org [91.121.71.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4593A517C8 for ; Sun, 12 Jun 2022 01:54:19 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id BF1A1C023; Sun, 12 Jun 2022 10:54:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024058; bh=iguW8VJn2xpk0juxhAsB0Ag6tYkQSGJW6piilwKSWbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c+KTqWdVXotF/5fkqb1pV/VMI9c9zLiYEM6w6IDbaXlExQ05HCqB82C/Pdrf8Jyo/ ZRra4lkx+4MzRSIuMy3jbImDhZUpwoskp0owNHeIlUm3ErMCgruf9kBpAEdaCv6uce PZCQN97OW5ybZ/VgxOLzBHU4isENHCeZa3d0PGlebg4cVUlHERbA2OeUhvmY2WcH1O URWPJPDy0epyKy0mw3r6MfHc5oWF+TE6AHRQPx26rQ/vvhMBYyvCUlKgjtHUwsB57G +JNv4hDUFSRR0dG3fwP4QQT+6rGyCTtEKp02lb94Ffmg9EpzhL2iOl3fclD8ttOzSc kn8iD4Ds9zYtA== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 52F69C01F; Sun, 12 Jun 2022 10:54:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024058; bh=iguW8VJn2xpk0juxhAsB0Ag6tYkQSGJW6piilwKSWbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c+KTqWdVXotF/5fkqb1pV/VMI9c9zLiYEM6w6IDbaXlExQ05HCqB82C/Pdrf8Jyo/ ZRra4lkx+4MzRSIuMy3jbImDhZUpwoskp0owNHeIlUm3ErMCgruf9kBpAEdaCv6uce PZCQN97OW5ybZ/VgxOLzBHU4isENHCeZa3d0PGlebg4cVUlHERbA2OeUhvmY2WcH1O URWPJPDy0epyKy0mw3r6MfHc5oWF+TE6AHRQPx26rQ/vvhMBYyvCUlKgjtHUwsB57G +JNv4hDUFSRR0dG3fwP4QQT+6rGyCTtEKp02lb94Ffmg9EpzhL2iOl3fclD8ttOzSc kn8iD4Ds9zYtA== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 62618ee2; Sun, 12 Jun 2022 08:54:10 +0000 (UTC) From: Dominique Martinet To: Christian Schoenebeck , Tyler Hicks , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet Cc: v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 03/06] 9p: v9fs_fid_lookup_with_uid fix's fix suggestion Date: Sun, 12 Jun 2022 17:53:26 +0900 Message-Id: <20220612085330.1451496-4-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220612085330.1451496-1-asmadeus@codewreck.org> References: <20220612085330.1451496-1-asmadeus@codewreck.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Tyler, I can just squash this in your commit if you're ok with this, as I've already rebased the other patches on top of it. Cc: Tyler Hicks Signed-off-by: Dominique Martinet --- fs/9p/fid.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 5a469b79c1ee..baf2b152229e 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -221,12 +221,15 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct= dentry *dentry, * walk to ensure none of the patch component change */ fid =3D p9_client_walk(fid, l, &wnames[i], clone); - p9_client_clunk(old_fid); + /* non-cloning walk will return the same fid */ + if (fid !=3D old_fid) { + p9_client_clunk(old_fid); + old_fid =3D fid; + } if (IS_ERR(fid)) { kfree(wnames); goto err_out; } - old_fid =3D fid; i +=3D l; clone =3D 0; } --=20 2.35.1 From nobody Wed Apr 29 08:07:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACEE2C433EF for ; Sun, 12 Jun 2022 08:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235117AbiFLIyh (ORCPT ); Sun, 12 Jun 2022 04:54:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235044AbiFLIyd (ORCPT ); Sun, 12 Jun 2022 04:54:33 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19B96517C2 for ; Sun, 12 Jun 2022 01:54:31 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id C3867C026; Sun, 12 Jun 2022 10:54:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024069; bh=4J6pXNWpEbJRPM9jxIh8Lri80dbf+1V/fQicln3jfAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bkHjEplf4FrZFMK2dCFconq4lwra8GRZalGLhcRkjFVkw9bPOF3bXmnD/dKkje4a8 3HSpD7MoSZVOijhIPQDfn1WeYu37S4o9riCC82rhQLT6pBhx6iZ+mZaikLnMHJqbsg 9MPVZdSVk613UmlnRBQ+M5nJLt4eVszYsV5OJ6+xVhcskHVqWYnuqyctRNV5FAKbUg yaCB+7NU865MuCYFWBgvq0Fvi7sGUyTKABY7RGG4QWNqUtu3fx0M1r4b+C/I8uXVqE oeFiI/QvE7VZQsM5whomxbliNdBMfkR44oH9smws46sFSi9fNXlA0OBuWJrgLye2HB gvcAH+cOxfgEw== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 659E5C01E; Sun, 12 Jun 2022 10:54:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024066; bh=4J6pXNWpEbJRPM9jxIh8Lri80dbf+1V/fQicln3jfAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X5DsItDDJXdQrPw1TAb4MN69K5RjifScCjtMNEOxSYBDqaM12pGO8VprfWHjSpbgq LlP00+copVYbN0FiUI9xHJvQnO6U0rTUmiETTijs05rLH7U+q0p/obxwGoNb/LYsj9 KZ2A4eJHpYvJt2KtAHihzGmfBVWc4AoaSN0UNaU8BBKVgJFj0VbyOn+yP3Bs0eKu8I +DAu0EQ12DApUNnFhQ+uE+Igeu6inAgwLrWQwyQ6EUoVWXDLW28Y8Nxt+GFDcqnXmU c6Y6rA9Pj/ofFowsipyTjfUM7plcvdGu/jI+YXzhb6J7gz3yOnjHLgDgEjOdKn0Gk8 XU8GhV0e0ev8Q== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 0453dc69; Sun, 12 Jun 2022 08:54:13 +0000 (UTC) From: Dominique Martinet To: Christian Schoenebeck , Tyler Hicks , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , "David S. Miller" , Jakub Kicinski , Paolo Abeni Cc: v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 04/06] 9p fid refcount: add p9_fid_get/put wrappers Date: Sun, 12 Jun 2022 17:53:27 +0900 Message-Id: <20220612085330.1451496-5-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220612085330.1451496-1-asmadeus@codewreck.org> References: <20220612085330.1451496-1-asmadeus@codewreck.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" I was recently reminded that it is not clear that p9_client_clunk() was actually just decrementing refcount and clunking only when that reaches zero: make it clear through a set of helpers. This will also allow instrumenting refcounting better for debugging next patch, which is the reason these are not defined as static inline: we won't be able to add trace events there... Signed-off-by: Dominique Martinet --- I've kept this commit after the other commits despite the churn so the stable commits are easily backportable. fs/9p/fid.c | 18 ++++++++-------- fs/9p/fid.h | 2 +- fs/9p/vfs_addr.c | 4 ++-- fs/9p/vfs_dentry.c | 4 ++-- fs/9p/vfs_dir.c | 2 +- fs/9p/vfs_file.c | 4 ++-- fs/9p/vfs_inode.c | 48 ++++++++++++++++++++--------------------- fs/9p/vfs_inode_dotl.c | 42 ++++++++++++++++++------------------ fs/9p/vfs_super.c | 6 +++--- fs/9p/xattr.c | 8 +++---- include/net/9p/client.h | 3 +++ net/9p/client.c | 36 ++++++++++++++++++++----------- 12 files changed, 96 insertions(+), 81 deletions(-) diff --git a/fs/9p/fid.c b/fs/9p/fid.c index e8fad28fc5bd..d792499349c4 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -56,7 +56,7 @@ static struct p9_fid *v9fs_fid_find_inode(struct inode *i= node, kuid_t uid) h =3D (struct hlist_head *)&inode->i_private; hlist_for_each_entry(fid, h, ilist) { if (uid_eq(fid->uid, uid)) { - refcount_inc(&fid->count); + p9_fid_get(fid); ret =3D fid; break; } @@ -104,7 +104,7 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dent= ry, kuid_t uid, int any) hlist_for_each_entry(fid, h, dlist) { if (any || uid_eq(fid->uid, uid)) { ret =3D fid; - refcount_inc(&ret->count); + p9_fid_get(ret); break; } } @@ -172,7 +172,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct d= entry *dentry, old_fid =3D fid; =20 fid =3D p9_client_walk(old_fid, 1, &dentry->d_name.name, 1); - p9_client_clunk(old_fid); + p9_fid_put(old_fid); goto fid_out; } up_read(&v9ses->rename_sem); @@ -194,7 +194,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct d= entry *dentry, if (IS_ERR(root_fid)) return root_fid; =20 - refcount_inc(&root_fid->count); + p9_fid_get(root_fid); v9fs_fid_add(dentry->d_sb->s_root, root_fid); } /* If we are root ourself just return that */ @@ -225,7 +225,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct d= entry *dentry, old_fid =3D=3D root_fid /* clone */); /* non-cloning walk will return the same fid */ if (fid !=3D old_fid) { - p9_client_clunk(old_fid); + p9_fid_put(old_fid); old_fid =3D fid; } if (IS_ERR(fid)) { @@ -240,11 +240,11 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct= dentry *dentry, spin_lock(&dentry->d_lock); if (d_unhashed(dentry)) { spin_unlock(&dentry->d_lock); - p9_client_clunk(fid); + p9_fid_put(fid); fid =3D ERR_PTR(-ENOENT); } else { __add_fid(dentry, fid); - refcount_inc(&fid->count); + p9_fid_get(fid); spin_unlock(&dentry->d_lock); } } @@ -301,7 +301,7 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry) fid =3D clone_fid(ofid); if (IS_ERR(fid)) goto error_out; - p9_client_clunk(ofid); + p9_fid_put(ofid); /* * writeback fid will only be used to write back the * dirty pages. We always request for the open fid in read-write @@ -310,7 +310,7 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry) */ err =3D p9_client_open(fid, O_RDWR); if (err < 0) { - p9_client_clunk(fid); + p9_fid_put(fid); fid =3D ERR_PTR(err); goto error_out; } diff --git a/fs/9p/fid.h b/fs/9p/fid.h index f7f33509e169..3168dfad510e 100644 --- a/fs/9p/fid.h +++ b/fs/9p/fid.h @@ -29,7 +29,7 @@ static inline struct p9_fid *v9fs_fid_clone(struct dentry= *dentry) return fid; =20 nfid =3D clone_fid(fid); - p9_client_clunk(fid); + p9_fid_put(fid); return nfid; } #endif diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index 8ce82ff1e40a..ed598160e0c6 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c @@ -60,7 +60,7 @@ static int v9fs_init_request(struct netfs_io_request *rre= q, struct file *file) { struct p9_fid *fid =3D file->private_data; =20 - refcount_inc(&fid->count); + p9_fid_get(fid); rreq->netfs_priv =3D fid; return 0; } @@ -74,7 +74,7 @@ static void v9fs_req_cleanup(struct address_space *mappin= g, void *priv) { struct p9_fid *fid =3D priv; =20 - p9_client_clunk(fid); + p9_fid_put(fid); } =20 /** diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c index 1c609e99d280..f89f01734587 100644 --- a/fs/9p/vfs_dentry.c +++ b/fs/9p/vfs_dentry.c @@ -54,7 +54,7 @@ static void v9fs_dentry_release(struct dentry *dentry) p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n", dentry, dentry); hlist_for_each_safe(p, n, (struct hlist_head *)&dentry->d_fsdata) - p9_client_clunk(hlist_entry(p, struct p9_fid, dlist)); + p9_fid_put(hlist_entry(p, struct p9_fid, dlist)); dentry->d_fsdata =3D NULL; } =20 @@ -85,7 +85,7 @@ static int v9fs_lookup_revalidate(struct dentry *dentry, = unsigned int flags) retval =3D v9fs_refresh_inode_dotl(fid, inode); else retval =3D v9fs_refresh_inode(fid, inode); - p9_client_clunk(fid); + p9_fid_put(fid); =20 if (retval =3D=3D -ENOENT) return 0; diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 958680f7f23e..000fbaae9b18 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -218,7 +218,7 @@ int v9fs_dir_release(struct inode *inode, struct file *= filp) spin_lock(&inode->i_lock); hlist_del(&fid->ilist); spin_unlock(&inode->i_lock); - p9_client_clunk(fid); + p9_fid_put(fid); } =20 if ((filp->f_mode & FMODE_WRITE)) { diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 2573c08f335c..8276f3af35d7 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -63,7 +63,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) =20 err =3D p9_client_open(fid, omode); if (err < 0) { - p9_client_clunk(fid); + p9_fid_put(fid); return err; } if ((file->f_flags & O_APPEND) && @@ -98,7 +98,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) v9fs_open_fid_add(inode, fid); return 0; out_error: - p9_client_clunk(file->private_data); + p9_fid_put(file->private_data); file->private_data =3D NULL; return err; } diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 18c780ffd4b5..38186d1a1440 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -399,7 +399,7 @@ void v9fs_evict_inode(struct inode *inode) fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false); /* clunk the fid stashed in writeback_fid */ if (v9inode->writeback_fid) { - p9_client_clunk(v9inode->writeback_fid); + p9_fid_put(v9inode->writeback_fid); v9inode->writeback_fid =3D NULL; } } @@ -568,7 +568,7 @@ static int v9fs_remove(struct inode *dir, struct dentry= *dentry, int flags) if (v9fs_proto_dotl(v9ses)) retval =3D p9_client_unlinkat(dfid, dentry->d_name.name, v9fs_at_to_dotl_flags(flags)); - p9_client_clunk(dfid); + p9_fid_put(dfid); if (retval =3D=3D -EOPNOTSUPP) { /* Try the one based on path */ v9fid =3D v9fs_fid_clone(dentry); @@ -632,14 +632,14 @@ v9fs_create(struct v9fs_session_info *v9ses, struct i= node *dir, if (IS_ERR(ofid)) { err =3D PTR_ERR(ofid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - p9_client_clunk(dfid); + p9_fid_put(dfid); return ERR_PTR(err); } =20 err =3D p9_client_fcreate(ofid, name, perm, mode, extension); if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err); - p9_client_clunk(dfid); + p9_fid_put(dfid); goto error; } =20 @@ -651,7 +651,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct ino= de *dir, p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); fid =3D NULL; - p9_client_clunk(dfid); + p9_fid_put(dfid); goto error; } /* @@ -662,20 +662,20 @@ v9fs_create(struct v9fs_session_info *v9ses, struct i= node *dir, err =3D PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err); - p9_client_clunk(dfid); + p9_fid_put(dfid); goto error; } v9fs_fid_add(dentry, fid); d_instantiate(dentry, inode); } - p9_client_clunk(dfid); + p9_fid_put(dfid); return ofid; error: if (ofid) - p9_client_clunk(ofid); + p9_fid_put(ofid); =20 if (fid) - p9_client_clunk(fid); + p9_fid_put(fid); =20 return ERR_PTR(err); } @@ -707,7 +707,7 @@ v9fs_vfs_create(struct user_namespace *mnt_userns, stru= ct inode *dir, return PTR_ERR(fid); =20 v9fs_invalidate_inode_attr(dir); - p9_client_clunk(fid); + p9_fid_put(fid); =20 return 0; } @@ -743,7 +743,7 @@ static int v9fs_vfs_mkdir(struct user_namespace *mnt_us= erns, struct inode *dir, } =20 if (fid) - p9_client_clunk(fid); + p9_fid_put(fid); =20 return err; } @@ -784,7 +784,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struc= t dentry *dentry, */ name =3D dentry->d_name.name; fid =3D p9_client_walk(dfid, 1, &name, 1); - p9_client_clunk(dfid); + p9_fid_put(dfid); if (fid =3D=3D ERR_PTR(-ENOENT)) inode =3D NULL; else if (IS_ERR(fid)) @@ -807,7 +807,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struc= t dentry *dentry, else if (!IS_ERR(res)) v9fs_fid_add(res, fid); else - p9_client_clunk(fid); + p9_fid_put(fid); } return res; } @@ -890,7 +890,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *= dentry, =20 error: if (fid) - p9_client_clunk(fid); + p9_fid_put(fid); goto out; } =20 @@ -958,7 +958,7 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, stru= ct inode *old_dir, dfid =3D v9fs_parent_fid(old_dentry); olddirfid =3D clone_fid(dfid); if (dfid && !IS_ERR(dfid)) - p9_client_clunk(dfid); + p9_fid_put(dfid); =20 if (IS_ERR(olddirfid)) { retval =3D PTR_ERR(olddirfid); @@ -967,7 +967,7 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, stru= ct inode *old_dir, =20 dfid =3D v9fs_parent_fid(new_dentry); newdirfid =3D clone_fid(dfid); - p9_client_clunk(dfid); + p9_fid_put(dfid); =20 if (IS_ERR(newdirfid)) { retval =3D PTR_ERR(newdirfid); @@ -1019,13 +1019,13 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, = struct inode *old_dir, d_move(old_dentry, new_dentry); } up_write(&v9ses->rename_sem); - p9_client_clunk(newdirfid); + p9_fid_put(newdirfid); =20 clunk_olddir: - p9_client_clunk(olddirfid); + p9_fid_put(olddirfid); =20 done: - p9_client_clunk(oldfid); + p9_fid_put(oldfid); return retval; } =20 @@ -1059,7 +1059,7 @@ v9fs_vfs_getattr(struct user_namespace *mnt_userns, c= onst struct path *path, return PTR_ERR(fid); =20 st =3D p9_client_stat(fid); - p9_client_clunk(fid); + p9_fid_put(fid); if (IS_ERR(st)) return PTR_ERR(st); =20 @@ -1135,7 +1135,7 @@ static int v9fs_vfs_setattr(struct user_namespace *mn= t_userns, retval =3D p9_client_wstat(fid, &wstat); =20 if (use_dentry) - p9_client_clunk(fid); + p9_fid_put(fid); =20 if (retval < 0) return retval; @@ -1260,7 +1260,7 @@ static const char *v9fs_vfs_get_link(struct dentry *d= entry, return ERR_CAST(fid); =20 st =3D p9_client_stat(fid); - p9_client_clunk(fid); + p9_fid_put(fid); if (IS_ERR(st)) return ERR_CAST(st); =20 @@ -1307,7 +1307,7 @@ static int v9fs_vfs_mkspecial(struct inode *dir, stru= ct dentry *dentry, return PTR_ERR(fid); =20 v9fs_invalidate_inode_attr(dir); - p9_client_clunk(fid); + p9_fid_put(fid); return 0; } =20 @@ -1363,7 +1363,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode= *dir, v9fs_refresh_inode(oldfid, d_inode(old_dentry)); v9fs_invalidate_inode_attr(dir); } - p9_client_clunk(oldfid); + p9_fid_put(oldfid); return retval; } =20 diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index b6eb1160296c..09b124fe349c 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -274,7 +274,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, if (IS_ERR(ofid)) { err =3D PTR_ERR(ofid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - p9_client_clunk(dfid); + p9_fid_put(dfid); goto out; } =20 @@ -286,7 +286,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, if (err) { p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n", err); - p9_client_clunk(dfid); + p9_fid_put(dfid); goto error; } err =3D p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags), @@ -294,14 +294,14 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct d= entry *dentry, if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n", err); - p9_client_clunk(dfid); + p9_fid_put(dfid); goto error; } v9fs_invalidate_inode_attr(dir); =20 /* instantiate inode and assign the unopened fid to the dentry */ fid =3D p9_client_walk(dfid, 1, &name, 1); - p9_client_clunk(dfid); + p9_fid_put(dfid); if (IS_ERR(fid)) { err =3D PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); @@ -358,10 +358,10 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct d= entry *dentry, =20 error: if (fid) - p9_client_clunk(fid); + p9_fid_put(fid); err_clunk_old_fid: if (ofid) - p9_client_clunk(ofid); + p9_fid_put(ofid); goto out; } =20 @@ -458,9 +458,9 @@ static int v9fs_vfs_mkdir_dotl(struct user_namespace *m= nt_userns, v9fs_invalidate_inode_attr(dir); error: if (fid) - p9_client_clunk(fid); + p9_fid_put(fid); v9fs_put_acl(dacl, pacl); - p9_client_clunk(dfid); + p9_fid_put(dfid); return err; } =20 @@ -489,7 +489,7 @@ v9fs_vfs_getattr_dotl(struct user_namespace *mnt_userns, */ =20 st =3D p9_client_getattr_dotl(fid, P9_STATS_ALL); - p9_client_clunk(fid); + p9_fid_put(fid); if (IS_ERR(st)) return PTR_ERR(st); =20 @@ -603,7 +603,7 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_us= erns, retval =3D p9_client_setattr(fid, &p9attr); if (retval < 0) { if (use_dentry) - p9_client_clunk(fid); + p9_fid_put(fid); return retval; } =20 @@ -619,12 +619,12 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_= userns, retval =3D v9fs_acl_chmod(inode, fid); if (retval < 0) { if (use_dentry) - p9_client_clunk(fid); + p9_fid_put(fid); return retval; } } if (use_dentry) - p9_client_clunk(fid); + p9_fid_put(fid); =20 return 0; } @@ -771,9 +771,9 @@ v9fs_vfs_symlink_dotl(struct user_namespace *mnt_userns= , struct inode *dir, =20 error: if (fid) - p9_client_clunk(fid); + p9_fid_put(fid); =20 - p9_client_clunk(dfid); + p9_fid_put(dfid); return err; } =20 @@ -803,14 +803,14 @@ v9fs_vfs_link_dotl(struct dentry *old_dentry, struct = inode *dir, =20 oldfid =3D v9fs_fid_lookup(old_dentry); if (IS_ERR(oldfid)) { - p9_client_clunk(dfid); + p9_fid_put(dfid); return PTR_ERR(oldfid); } =20 err =3D p9_client_link(dfid, oldfid, dentry->d_name.name); =20 - p9_client_clunk(dfid); - p9_client_clunk(oldfid); + p9_fid_put(dfid); + p9_fid_put(oldfid); if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_link failed %d\n", err); return err; @@ -826,7 +826,7 @@ v9fs_vfs_link_dotl(struct dentry *old_dentry, struct in= ode *dir, return PTR_ERR(fid); =20 v9fs_refresh_inode_dotl(fid, d_inode(old_dentry)); - p9_client_clunk(fid); + p9_fid_put(fid); } ihold(d_inode(old_dentry)); d_instantiate(dentry, d_inode(old_dentry)); @@ -924,9 +924,9 @@ v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, = struct inode *dir, } error: if (fid) - p9_client_clunk(fid); + p9_fid_put(fid); v9fs_put_acl(dacl, pacl); - p9_client_clunk(dfid); + p9_fid_put(dfid); =20 return err; } @@ -956,7 +956,7 @@ v9fs_vfs_get_link_dotl(struct dentry *dentry, if (IS_ERR(fid)) return ERR_CAST(fid); retval =3D p9_client_readlink(fid, &target); - p9_client_clunk(fid); + p9_fid_put(fid); if (retval) return ERR_PTR(retval); set_delayed_call(done, kfree_link, target); diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index 97e23b4e6982..bf350fad9500 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c @@ -190,7 +190,7 @@ static struct dentry *v9fs_mount(struct file_system_typ= e *fs_type, int flags, return dget(sb->s_root); =20 clunk_fid: - p9_client_clunk(fid); + p9_fid_put(fid); v9fs_session_close(v9ses); free_session: kfree(v9ses); @@ -203,7 +203,7 @@ static struct dentry *v9fs_mount(struct file_system_typ= e *fs_type, int flags, * attached the fid to dentry so it won't get clunked * automatically. */ - p9_client_clunk(fid); + p9_fid_put(fid); deactivate_locked_super(sb); return ERR_PTR(retval); } @@ -270,7 +270,7 @@ static int v9fs_statfs(struct dentry *dentry, struct ks= tatfs *buf) } res =3D simple_statfs(dentry, buf); done: - p9_client_clunk(fid); + p9_fid_put(fid); return res; } =20 diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c index a824441b95a2..1f9298a4bd42 100644 --- a/fs/9p/xattr.c +++ b/fs/9p/xattr.c @@ -44,7 +44,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char= *name, if (err) retval =3D err; } - p9_client_clunk(attr_fid); + p9_fid_put(attr_fid); return retval; } =20 @@ -71,7 +71,7 @@ ssize_t v9fs_xattr_get(struct dentry *dentry, const char = *name, if (IS_ERR(fid)) return PTR_ERR(fid); ret =3D v9fs_fid_xattr_get(fid, name, buffer, buffer_size); - p9_client_clunk(fid); + p9_fid_put(fid); =20 return ret; } @@ -98,7 +98,7 @@ int v9fs_xattr_set(struct dentry *dentry, const char *nam= e, if (IS_ERR(fid)) return PTR_ERR(fid); ret =3D v9fs_fid_xattr_set(fid, name, value, value_len, flags); - p9_client_clunk(fid); + p9_fid_put(fid); return ret; } =20 @@ -128,7 +128,7 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *= name, retval); else p9_client_write(fid, 0, &from, &retval); - err =3D p9_client_clunk(fid); + err =3D p9_fid_put(fid); if (!retval && err) retval =3D err; return retval; diff --git a/include/net/9p/client.h b/include/net/9p/client.h index ec1d1706f43c..55587ce88181 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h @@ -237,6 +237,9 @@ static inline int p9_req_try_get(struct p9_req_t *r) =20 int p9_req_put(struct p9_req_t *r); =20 +struct p9_fid *p9_fid_get(struct p9_fid *fid); +int p9_fid_put(struct p9_fid *fid); + void p9_client_cb(struct p9_client *c, struct p9_req_t *req, int status); =20 int p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, diff --git a/net/9p/client.c b/net/9p/client.c index 8bba0d9cf975..3e1cda4a8328 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -928,6 +928,27 @@ static void p9_fid_destroy(struct p9_fid *fid) kfree(fid); } =20 +/* these unfortunately can't be declared as static inline in client.h + * because trace_* functions can't be used there easily + */ +struct p9_fid *p9_fid_get(struct p9_fid *fid) { + refcount_inc(&fid->count); + + return fid; +} +EXPORT_SYMBOL(p9_fid_get); + +int p9_fid_put(struct p9_fid *fid) { + if (!fid || IS_ERR(fid)) + return 0; + + if (!refcount_dec_and_test(&fid->count)) + return 0; + + return p9_client_clunk(fid); +} +EXPORT_SYMBOL(p9_fid_put); + static int p9_client_version(struct p9_client *c) { int err =3D 0; @@ -1228,7 +1249,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, = uint16_t nwname, =20 clunk_fid: kfree(wqids); - p9_client_clunk(fid); + p9_fid_put(fid); fid =3D NULL; =20 error: @@ -1459,15 +1480,6 @@ int p9_client_clunk(struct p9_fid *fid) struct p9_req_t *req; int retries =3D 0; =20 - if (!fid || IS_ERR(fid)) { - pr_warn("%s (%d): Trying to clunk with invalid fid\n", - __func__, task_pid_nr(current)); - dump_stack(); - return 0; - } - if (!refcount_dec_and_test(&fid->count)) - return 0; - again: p9_debug(P9_DEBUG_9P, ">>> TCLUNK fid %d (try %d)\n", fid->fid, retries); @@ -1519,7 +1531,7 @@ int p9_client_remove(struct p9_fid *fid) p9_tag_remove(clnt, req); error: if (err =3D=3D -ERESTARTSYS) - p9_client_clunk(fid); + p9_fid_put(fid); else p9_fid_destroy(fid); return err; @@ -2042,7 +2054,7 @@ struct p9_fid *p9_client_xattrwalk(struct p9_fid *fil= e_fid, attr_fid->fid, *attr_size); return attr_fid; clunk_fid: - p9_client_clunk(attr_fid); + p9_fid_put(attr_fid); attr_fid =3D NULL; error: if (attr_fid && attr_fid !=3D file_fid) --=20 2.35.1 From nobody Wed Apr 29 08:07:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33385C43334 for ; Sun, 12 Jun 2022 08:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235096AbiFLIyf (ORCPT ); Sun, 12 Jun 2022 04:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230443AbiFLIyc (ORCPT ); Sun, 12 Jun 2022 04:54:32 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3281517C8 for ; Sun, 12 Jun 2022 01:54:31 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 6CB61C021; Sun, 12 Jun 2022 10:54:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024070; bh=x1O5qqBGdLbV11NrLo/L1WajTuYUw+Z9SA9TZyNmXB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XBe6l9uiXewZxUguj74t9srkVgkJoavvgVwUYu+CQlbYuHm90aU9n+LUAQj+J2Jdz t1kAHiq4dCfiqLgjwJ/8zlID1ozuVMaxX+6QHjeD21lQpeLN8+vSiD7h78W1g6gnPx dKJW6uQta+KjdHiaQAj3NJG20ZY/gQpAlFPImBrCvupsFOPqz+UF+4ibwnz8getD0V FABgntxpNj4D0D+bzll1yahcemS4Y8cacZdhnIkFpW0d+2MTcmoDexF7gcLjrDtP3g gmWA38hynbYL82o7OcVznZ7jkh1g6mq4LFG5irGN+XQi/kiW78K4XIT8L3NRMklESl rpD+BGFEPJ3TQ== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 37E66C01A; Sun, 12 Jun 2022 10:54:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024067; bh=x1O5qqBGdLbV11NrLo/L1WajTuYUw+Z9SA9TZyNmXB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NKwtyPZbH48gZKKLRhrY1oLsgi3HyFwfb8+GRYpgMe3gWn88kQZUqOsaem6OOj6Jd LJHc9nQhHHtsu4RHo1fQIFEIVxJHDgafYc0kZreG9Pw0aHWfZSW5KfQ5AESiloXzd8 NMjoe04t0W62MagYvQSBiPhnRUyxgszjm3zoK20poW+mWYJGn+9Ch4y8qA2IZFeFjq Kt7mDcfQwKBr0YmMwmyhEQTPSC6NmN0VYN4V1bw5s2dsPay72Y0OTyDX51RfkC9g2b fVijnNsAGojeFaciH+2ciDmms7T0I+qd7tIsT9+26WpAJqlJTj3zJcjRqHLca/spkH HGpXhQE5+JhkA== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 6828ecd5; Sun, 12 Jun 2022 08:54:14 +0000 (UTC) From: Dominique Martinet To: Christian Schoenebeck , Tyler Hicks , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Steven Rostedt , Ingo Molnar , "David S. Miller" , Jakub Kicinski , Paolo Abeni Cc: v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 05/06] 9p fid refcount: add a 9p_fid_ref tracepoint Date: Sun, 12 Jun 2022 17:53:28 +0900 Message-Id: <20220612085330.1451496-6-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220612085330.1451496-1-asmadeus@codewreck.org> References: <20220612085330.1451496-1-asmadeus@codewreck.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Dominique Martinet --- This is the first time I add a tracepoint, so if anyone has time to check I didn't make something too stupid please have a look. I've mostly copied from netfs'. Also, a question if someone has time: I'd have liked to use the tracepoint in static inline wrappers for getref/putref, but it's not good to add the tracepoints to a .h, right? Especially with the CREATE_TRACE_POINTS macro... How do people usually go about that, just bite the bullet and make it a real function? include/trace/events/9p.h | 48 +++++++++++++++++++++++++++++++++++++++ net/9p/client.c | 9 +++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/trace/events/9p.h b/include/trace/events/9p.h index 78c5608a1648..4dfa6d7f83ba 100644 --- a/include/trace/events/9p.h +++ b/include/trace/events/9p.h @@ -77,6 +77,13 @@ EM( P9_TWSTAT, "P9_TWSTAT" ) \ EMe(P9_RWSTAT, "P9_RWSTAT" ) =20 + +#define P9_FID_REFTYPE \ + EM( P9_FID_REF_CREATE, "create " ) \ + EM( P9_FID_REF_GET, "get " ) \ + EM( P9_FID_REF_PUT, "put " ) \ + EMe(P9_FID_REF_DESTROY, "destroy" ) + /* Define EM() to export the enums to userspace via TRACE_DEFINE_ENUM() */ #undef EM #undef EMe @@ -84,6 +91,21 @@ #define EMe(a, b) TRACE_DEFINE_ENUM(a); =20 P9_MSG_T +P9_FID_REFTYPE + +/* And also use EM/EMe to define helper enums -- once */ +#ifndef __9P_DECLARE_TRACE_ENUMS_ONLY_ONCE +#define __9P_DECLARE_TRACE_ENUMS_ONLY_ONCE +#undef EM +#undef EMe +#define EM(a, b) a, +#define EMe(a, b) a + +enum p9_fid_reftype { + P9_FID_REFTYPE +} __mode(byte); + +#endif =20 /* * Now redefine the EM() and EMe() macros to map the enums to the strings @@ -96,6 +118,8 @@ P9_MSG_T =20 #define show_9p_op(type) \ __print_symbolic(type, P9_MSG_T) +#define show_9p_fid_reftype(type) \ + __print_symbolic(type, P9_FID_REFTYPE) =20 TRACE_EVENT(9p_client_req, TP_PROTO(struct p9_client *clnt, int8_t type, int tag), @@ -168,6 +192,30 @@ TRACE_EVENT(9p_protocol_dump, __entry->tag, 0, __entry->line, 16, __entry->line + 16) ); =20 + +TRACE_EVENT(9p_fid_ref, + TP_PROTO(struct p9_fid *fid, __u8 type), + + TP_ARGS(fid, type), + + TP_STRUCT__entry( + __field( int, fid ) + __field( int, refcount ) + __field( __u8, type ) + ), + + TP_fast_assign( + __entry->fid =3D fid->fid; + __entry->refcount =3D refcount_read(&fid->count); + __entry->type =3D type; + ), + + TP_printk("%s fid %d, refcount %d", + show_9p_fid_reftype(__entry->type), + __entry->fid, __entry->refcount) +); + + #endif /* _TRACE_9P_H */ =20 /* This part must be outside protection */ diff --git a/net/9p/client.c b/net/9p/client.c index 5531b31e0fb2..fdeeda0a811d 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -907,8 +907,10 @@ static struct p9_fid *p9_fid_create(struct p9_client *= clnt) GFP_NOWAIT); spin_unlock_irq(&clnt->lock); idr_preload_end(); - if (!ret) + if (!ret) { + trace_9p_fid_ref(fid, P9_FID_REF_CREATE); return fid; + } =20 kfree(fid); return NULL; @@ -920,6 +922,7 @@ static void p9_fid_destroy(struct p9_fid *fid) unsigned long flags; =20 p9_debug(P9_DEBUG_FID, "fid %d\n", fid->fid); + trace_9p_fid_ref(fid, P9_FID_REF_DESTROY); clnt =3D fid->clnt; spin_lock_irqsave(&clnt->lock, flags); idr_remove(&clnt->fids, fid->fid); @@ -932,6 +935,8 @@ static void p9_fid_destroy(struct p9_fid *fid) * because trace_* functions can't be used there easily */ struct p9_fid *p9_fid_get(struct p9_fid *fid) { + trace_9p_fid_ref(fid, P9_FID_REF_GET); + refcount_inc(&fid->count); =20 return fid; @@ -941,6 +946,8 @@ int p9_fid_put(struct p9_fid *fid) { if (!fid || IS_ERR(fid)) return 0; =20 + trace_9p_fid_ref(fid, P9_FID_REF_PUT); + if (!refcount_dec_and_test(&fid->count)) return 0; =20 --=20 2.35.1 From nobody Wed Apr 29 08:07:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBBCDC433EF for ; Sun, 12 Jun 2022 08:54:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231637AbiFLIyl (ORCPT ); Sun, 12 Jun 2022 04:54:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235087AbiFLIyf (ORCPT ); Sun, 12 Jun 2022 04:54:35 -0400 Received: from nautica.notk.org (nautica.notk.org [91.121.71.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67743517C8 for ; Sun, 12 Jun 2022 01:54:33 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 0C2D3C024; Sun, 12 Jun 2022 10:54:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024072; bh=V3ZAHrADP+/Qo2GtwYzTC79HVkVXcWQv2SINJiNJxKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELwRADv994wBKmMqWSMrGk4e40UphT0L8S1+X1/3wplCTzODeJnNWgiTEHJZt5vqN +4KczPfWZCYASc5nTUkzA4gEV3HEtf71bXdo3PqdfnqCcOfUIfIHkCNp2Rwgx/RLMY gOGSya6rHkPMY4jCr5nbZOeTz2TEx5fzChJYUcRSKHEMBNKqiqjMWu67L6FQD7rKlJ Hnszv7pitWx5yQ5rFVZeEliWuoMW21N1kH7BAEOHgPZXluBjvnyltXJRJ8s1LRM+8E sdNiUrBfyvhU3ANiTVgG0JVXq6oz59wHMOd6pmgaILjlaSYCGwGlvuSpEtGsgjiHjc ZACNeiEkBsfnA== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 46050C01C; Sun, 12 Jun 2022 10:54:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655024071; bh=V3ZAHrADP+/Qo2GtwYzTC79HVkVXcWQv2SINJiNJxKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aRu4SoD4lXPaRdB2d2Pd/PLCfN1zsIiJ2zZzIi9O21JLMozc/rXWdOvuX7a1889CE IZPTgIgodp/xuU579oDwf5sekGXEzi5bmkZmrR1UtTc2ZYi1z0obAkFAB+5xuSmaZn rhRGRmA2x0tzeaCMpbFwWH6Hb1Yci9lTvulqlx4X1AwNNMKH5jovq8rwbU0XMF35Cn XwGbACmqODOifnlTje65qE3Pv/A5LiA9YRtQOqfqndJasv7bpaCHQerI2MwuO3VSbl eeVJPALtb5XbzKZ6BE12UuYZMav6XhwGZZ0yeKAEGfmi+T52NkvlTRfnjOwy9NVKqd JzOP4lwn/rrtA== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 61f62a1a; Sun, 12 Jun 2022 08:54:17 +0000 (UTC) From: Dominique Martinet To: Christian Schoenebeck , Tyler Hicks , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet Cc: v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 06/06] 9p fid refcount: cleanup p9_fid_put calls Date: Sun, 12 Jun 2022 17:53:29 +0900 Message-Id: <20220612085330.1451496-7-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220612085330.1451496-1-asmadeus@codewreck.org> References: <20220612085330.1451496-1-asmadeus@codewreck.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Simplify p9_fid_put cleanup path in many 9p functions since the function is noop on null or error fids. Also make the *_add_fid() helpers "steal" the fid by nulling its pointer, so put after them will be noop. This should lead to no change of behaviour Signed-off-by: Dominique Martinet Reviewed-by: Tyler Hicks --- fs/9p/fid.c | 24 +++++++++++------ fs/9p/fid.h | 4 +-- fs/9p/vfs_file.c | 5 ++-- fs/9p/vfs_inode.c | 61 +++++++++++++++++------------------------- fs/9p/vfs_inode_dotl.c | 58 +++++++++++++-------------------------- fs/9p/vfs_super.c | 2 +- 6 files changed, 64 insertions(+), 90 deletions(-) diff --git a/fs/9p/fid.c b/fs/9p/fid.c index d792499349c4..289a85eae2ae 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -31,11 +31,15 @@ static inline void __add_fid(struct dentry *dentry, str= uct p9_fid *fid) * @fid: fid to add * */ -void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) +void v9fs_fid_add(struct dentry *dentry, struct p9_fid **pfid) { + struct p9_fid *fid =3D *pfid; + spin_lock(&dentry->d_lock); __add_fid(dentry, fid); spin_unlock(&dentry->d_lock); + + *pfid =3D NULL; } =20 /** @@ -72,11 +76,15 @@ static struct p9_fid *v9fs_fid_find_inode(struct inode = *inode, kuid_t uid) * */ =20 -void v9fs_open_fid_add(struct inode *inode, struct p9_fid *fid) +void v9fs_open_fid_add(struct inode *inode, struct p9_fid **pfid) { + struct p9_fid *fid =3D *pfid; + spin_lock(&inode->i_lock); hlist_add_head(&fid->ilist, (struct hlist_head *)&inode->i_private); spin_unlock(&inode->i_lock); + + *pfid =3D NULL; } =20 =20 @@ -189,13 +197,13 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct= dentry *dentry, else uname =3D v9ses->uname; =20 - root_fid =3D p9_client_attach(v9ses->clnt, NULL, uname, uid, - v9ses->aname); - if (IS_ERR(root_fid)) - return root_fid; + fid =3D p9_client_attach(v9ses->clnt, NULL, uname, uid, + v9ses->aname); + if (IS_ERR(fid)) + return fid; =20 - p9_fid_get(root_fid); - v9fs_fid_add(dentry->d_sb->s_root, root_fid); + root_fid =3D p9_fid_get(fid); + v9fs_fid_add(dentry->d_sb->s_root, &fid); } /* If we are root ourself just return that */ if (dentry->d_sb->s_root =3D=3D dentry) diff --git a/fs/9p/fid.h b/fs/9p/fid.h index 3168dfad510e..8a4e8cd12ca2 100644 --- a/fs/9p/fid.h +++ b/fs/9p/fid.h @@ -13,9 +13,9 @@ static inline struct p9_fid *v9fs_parent_fid(struct dentr= y *dentry) { return v9fs_fid_lookup(dentry->d_parent); } -void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid); +void v9fs_fid_add(struct dentry *dentry, struct p9_fid **fid); struct p9_fid *v9fs_writeback_fid(struct dentry *dentry); -void v9fs_open_fid_add(struct inode *inode, struct p9_fid *fid); +void v9fs_open_fid_add(struct inode *inode, struct p9_fid **fid); static inline struct p9_fid *clone_fid(struct p9_fid *fid) { return IS_ERR(fid) ? fid : p9_client_walk(fid, 0, NULL, 1); diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 8276f3af35d7..aec43ba83799 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -69,9 +69,10 @@ int v9fs_file_open(struct inode *inode, struct file *fil= e) if ((file->f_flags & O_APPEND) && (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses))) generic_file_llseek(file, 0, SEEK_END); + + file->private_data =3D fid; } =20 - file->private_data =3D fid; mutex_lock(&v9inode->v_mutex); if ((v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE= ) && !v9inode->writeback_fid && @@ -95,7 +96,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE) fscache_use_cookie(v9fs_inode_cookie(v9inode), file->f_mode & FMODE_WRITE); - v9fs_open_fid_add(inode, fid); + v9fs_open_fid_add(inode, &fid); return 0; out_error: p9_fid_put(file->private_data); diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 38186d1a1440..1b11a92208fd 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -398,10 +398,8 @@ void v9fs_evict_inode(struct inode *inode) =20 fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false); /* clunk the fid stashed in writeback_fid */ - if (v9inode->writeback_fid) { - p9_fid_put(v9inode->writeback_fid); - v9inode->writeback_fid =3D NULL; - } + p9_fid_put(v9inode->writeback_fid); + v9inode->writeback_fid =3D NULL; } =20 static int v9fs_test_inode(struct inode *inode, void *data) @@ -632,14 +630,12 @@ v9fs_create(struct v9fs_session_info *v9ses, struct i= node *dir, if (IS_ERR(ofid)) { err =3D PTR_ERR(ofid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - p9_fid_put(dfid); - return ERR_PTR(err); + goto error; } =20 err =3D p9_client_fcreate(ofid, name, perm, mode, extension); if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err); - p9_fid_put(dfid); goto error; } =20 @@ -650,8 +646,6 @@ v9fs_create(struct v9fs_session_info *v9ses, struct ino= de *dir, err =3D PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid =3D NULL; - p9_fid_put(dfid); goto error; } /* @@ -662,21 +656,17 @@ v9fs_create(struct v9fs_session_info *v9ses, struct i= node *dir, err =3D PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err); - p9_fid_put(dfid); goto error; } - v9fs_fid_add(dentry, fid); + v9fs_fid_add(dentry, &fid); d_instantiate(dentry, inode); } p9_fid_put(dfid); return ofid; error: - if (ofid) - p9_fid_put(ofid); - - if (fid) - p9_fid_put(fid); - + p9_fid_put(dfid); + p9_fid_put(ofid); + p9_fid_put(fid); return ERR_PTR(err); } =20 @@ -803,9 +793,9 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struc= t dentry *dentry, res =3D d_splice_alias(inode, dentry); if (!IS_ERR(fid)) { if (!res) - v9fs_fid_add(dentry, fid); + v9fs_fid_add(dentry, &fid); else if (!IS_ERR(res)) - v9fs_fid_add(res, fid); + v9fs_fid_add(res, &fid); else p9_fid_put(fid); } @@ -846,7 +836,6 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *= dentry, v9fs_proto_dotu(v9ses))); if (IS_ERR(fid)) { err =3D PTR_ERR(fid); - fid =3D NULL; goto error; } =20 @@ -881,7 +870,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *= dentry, if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE) fscache_use_cookie(v9fs_inode_cookie(v9inode), file->f_mode & FMODE_WRITE); - v9fs_open_fid_add(inode, fid); + v9fs_open_fid_add(inode, &fid); =20 file->f_mode |=3D FMODE_CREATED; out: @@ -889,8 +878,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *= dentry, return err; =20 error: - if (fid) - p9_fid_put(fid); + p9_fid_put(fid); goto out; } =20 @@ -938,9 +926,9 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, stru= ct inode *old_dir, struct inode *old_inode; struct inode *new_inode; struct v9fs_session_info *v9ses; - struct p9_fid *oldfid, *dfid; - struct p9_fid *olddirfid; - struct p9_fid *newdirfid; + struct p9_fid *oldfid =3D NULL, *dfid =3D NULL; + struct p9_fid *olddirfid =3D NULL; + struct p9_fid *newdirfid =3D NULL; struct p9_wstat wstat; =20 if (flags) @@ -957,21 +945,22 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, st= ruct inode *old_dir, =20 dfid =3D v9fs_parent_fid(old_dentry); olddirfid =3D clone_fid(dfid); - if (dfid && !IS_ERR(dfid)) - p9_fid_put(dfid); + p9_fid_put(dfid); + dfid =3D NULL; =20 if (IS_ERR(olddirfid)) { retval =3D PTR_ERR(olddirfid); - goto done; + goto error; } =20 dfid =3D v9fs_parent_fid(new_dentry); newdirfid =3D clone_fid(dfid); p9_fid_put(dfid); + dfid =3D NULL; =20 if (IS_ERR(newdirfid)) { retval =3D PTR_ERR(newdirfid); - goto clunk_olddir; + goto error; } =20 down_write(&v9ses->rename_sem); @@ -982,7 +971,7 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, stru= ct inode *old_dir, retval =3D p9_client_rename(oldfid, newdirfid, new_dentry->d_name.name); if (retval !=3D -EOPNOTSUPP) - goto clunk_newdir; + goto error_locked; } if (old_dentry->d_parent !=3D new_dentry->d_parent) { /* @@ -991,14 +980,14 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, st= ruct inode *old_dir, =20 p9_debug(P9_DEBUG_ERROR, "old dir and new dir are different\n"); retval =3D -EXDEV; - goto clunk_newdir; + goto error_locked; } v9fs_blank_wstat(&wstat); wstat.muid =3D v9ses->uname; wstat.name =3D new_dentry->d_name.name; retval =3D p9_client_wstat(oldfid, &wstat); =20 -clunk_newdir: +error_locked: if (!retval) { if (new_inode) { if (S_ISDIR(new_inode->i_mode)) @@ -1019,12 +1008,10 @@ v9fs_vfs_rename(struct user_namespace *mnt_userns, = struct inode *old_dir, d_move(old_dentry, new_dentry); } up_write(&v9ses->rename_sem); + +error: p9_fid_put(newdirfid); - -clunk_olddir: p9_fid_put(olddirfid); - -done: p9_fid_put(oldfid); return retval; } diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 09b124fe349c..5cfa4b4f070f 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -238,7 +238,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, struct inode *inode; struct p9_fid *fid =3D NULL; struct v9fs_inode *v9inode; - struct p9_fid *dfid, *ofid, *inode_fid; + struct p9_fid *dfid =3D NULL, *ofid =3D NULL, *inode_fid =3D NULL; struct v9fs_session_info *v9ses; struct posix_acl *pacl =3D NULL, *dacl =3D NULL; struct dentry *res =3D NULL; @@ -274,7 +274,6 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, if (IS_ERR(ofid)) { err =3D PTR_ERR(ofid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - p9_fid_put(dfid); goto out; } =20 @@ -286,38 +285,34 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct d= entry *dentry, if (err) { p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n", err); - p9_fid_put(dfid); - goto error; + goto out; } err =3D p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags), mode, gid, &qid); if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n", err); - p9_fid_put(dfid); - goto error; + goto out; } v9fs_invalidate_inode_attr(dir); =20 /* instantiate inode and assign the unopened fid to the dentry */ fid =3D p9_client_walk(dfid, 1, &name, 1); - p9_fid_put(dfid); if (IS_ERR(fid)) { err =3D PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid =3D NULL; - goto error; + goto out; } inode =3D v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); if (IS_ERR(inode)) { err =3D PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err); - goto error; + goto out; } /* Now set the ACL based on the default value */ v9fs_set_create_acl(inode, fid, dacl, pacl); =20 - v9fs_fid_add(dentry, fid); + v9fs_fid_add(dentry, &fid); d_instantiate(dentry, inode); =20 v9inode =3D V9FS_I(inode); @@ -336,7 +331,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, if (IS_ERR(inode_fid)) { err =3D PTR_ERR(inode_fid); mutex_unlock(&v9inode->v_mutex); - goto err_clunk_old_fid; + goto out; } v9inode->writeback_fid =3D (void *) inode_fid; } @@ -344,25 +339,20 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct d= entry *dentry, /* Since we are opening a file, assign the open fid to the file */ err =3D finish_open(file, dentry, generic_file_open); if (err) - goto err_clunk_old_fid; + goto out; file->private_data =3D ofid; if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE) fscache_use_cookie(v9fs_inode_cookie(v9inode), file->f_mode & FMODE_WRITE); - v9fs_open_fid_add(inode, ofid); + v9fs_open_fid_add(inode, &ofid); file->f_mode |=3D FMODE_CREATED; out: + p9_fid_put(dfid); + p9_fid_put(ofid); + p9_fid_put(fid); v9fs_put_acl(dacl, pacl); dput(res); return err; - -error: - if (fid) - p9_fid_put(fid); -err_clunk_old_fid: - if (ofid) - p9_fid_put(ofid); - goto out; } =20 /** @@ -400,7 +390,6 @@ static int v9fs_vfs_mkdir_dotl(struct user_namespace *m= nt_userns, if (IS_ERR(dfid)) { err =3D PTR_ERR(dfid); p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err); - dfid =3D NULL; goto error; } =20 @@ -422,7 +411,6 @@ static int v9fs_vfs_mkdir_dotl(struct user_namespace *m= nt_userns, err =3D PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid =3D NULL; goto error; } =20 @@ -435,10 +423,9 @@ static int v9fs_vfs_mkdir_dotl(struct user_namespace *= mnt_userns, err); goto error; } - v9fs_fid_add(dentry, fid); + v9fs_fid_add(dentry, &fid); v9fs_set_create_acl(inode, fid, dacl, pacl); d_instantiate(dentry, inode); - fid =3D NULL; err =3D 0; } else { /* @@ -457,8 +444,7 @@ static int v9fs_vfs_mkdir_dotl(struct user_namespace *m= nt_userns, inc_nlink(dir); v9fs_invalidate_inode_attr(dir); error: - if (fid) - p9_fid_put(fid); + p9_fid_put(fid); v9fs_put_acl(dacl, pacl); p9_fid_put(dfid); return err; @@ -743,7 +729,6 @@ v9fs_vfs_symlink_dotl(struct user_namespace *mnt_userns= , struct inode *dir, err =3D PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid =3D NULL; goto error; } =20 @@ -755,9 +740,8 @@ v9fs_vfs_symlink_dotl(struct user_namespace *mnt_userns= , struct inode *dir, err); goto error; } - v9fs_fid_add(dentry, fid); + v9fs_fid_add(dentry, &fid); d_instantiate(dentry, inode); - fid =3D NULL; err =3D 0; } else { /* Not in cached mode. No need to populate inode with stat */ @@ -770,9 +754,7 @@ v9fs_vfs_symlink_dotl(struct user_namespace *mnt_userns= , struct inode *dir, } =20 error: - if (fid) - p9_fid_put(fid); - + p9_fid_put(fid); p9_fid_put(dfid); return err; } @@ -866,7 +848,6 @@ v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, = struct inode *dir, if (IS_ERR(dfid)) { err =3D PTR_ERR(dfid); p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err); - dfid =3D NULL; goto error; } =20 @@ -891,7 +872,6 @@ v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, = struct inode *dir, err =3D PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid =3D NULL; goto error; } =20 @@ -905,9 +885,8 @@ v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, = struct inode *dir, goto error; } v9fs_set_create_acl(inode, fid, dacl, pacl); - v9fs_fid_add(dentry, fid); + v9fs_fid_add(dentry, &fid); d_instantiate(dentry, inode); - fid =3D NULL; err =3D 0; } else { /* @@ -923,8 +902,7 @@ v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, = struct inode *dir, d_instantiate(dentry, inode); } error: - if (fid) - p9_fid_put(fid); + p9_fid_put(fid); v9fs_put_acl(dacl, pacl); p9_fid_put(dfid); =20 diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index bf350fad9500..2d9ee073d12c 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c @@ -184,7 +184,7 @@ static struct dentry *v9fs_mount(struct file_system_typ= e *fs_type, int flags, retval =3D v9fs_get_acl(inode, fid); if (retval) goto release_sb; - v9fs_fid_add(root, fid); + v9fs_fid_add(root, &fid); =20 p9_debug(P9_DEBUG_VFS, " simple set mount, return 0\n"); return dget(sb->s_root); --=20 2.35.1