From patchwork Thu Jun 20 22:58:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706471 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 CB2116F085 for ; Thu, 20 Jun 2024 22:58:40 +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=1718924321; cv=none; b=QWBJ42sy9dkxSewCQ8GjPJsnCC4V0iS1dDO+jqehTGcyQyHyzQoZ4iAwIoCvQnHu4n4fousCp6o0djtH6kry1eG5s518jc6bx0Pz9oOMKwgB07YCFvV7M1dcA86+iR1BWBNjnTi/XYNwQBmV/WZ+/sMMUj8AV17DzI6tFEkLOWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924321; c=relaxed/simple; bh=FQKasbbOJh4eUgQswplqIC0wbIsww8Q1E681u8rygOc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UV5BInvUj1yhXGz2AAO2Reouc11VAEM3xtwxq92ECWlV16jB6ODT1AynBrSXDAjgZIkXanCwEd+7nCgnVckLKdjVXUHbLSM79ygMb/CUTgZA3Fq/SeNPUGjzUx8Bq+BMoVENurBhl3jLt/veCdXNj0dBlwtc+XFi+EabuCyTCSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ToATMcCh; 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="ToATMcCh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40298C2BD10; Thu, 20 Jun 2024 22:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924320; bh=FQKasbbOJh4eUgQswplqIC0wbIsww8Q1E681u8rygOc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ToATMcChXtHBwyNULKwFrhl0S41cdy4TqwdC/sNvR9GC3B3tgLNc2VUC97i36Auwt GeVGVwnpHVaAh5k3FEl0lUglTBXN7iCjjaEKX4wrJTV1P/nCNybur93Iob3Ku10Kj1 AwowOfzeAgCetFwdpGvk8BLTEP7HPrm1NtDc7VEQWw341yEazwlCU+m0UTtZU0ObKs 0Ltkwhm0mg4vI65j6hq118/6sMIsubC+Z7WZp94njeSj6FTPtFl5D03wvLvbV8Y+Y4 PsRHQuOENiF3IfyA7quyT+bXgfopXKiYfavux+hTkkrXpIlamfmBfEY91n0I8sYOGY TBUHf1OKtE5xQ== Date: Thu, 20 Jun 2024 15:58:39 -0700 Subject: [PATCH 01/24] xfs: use consistent uid/gid when grabbing dquots for inodes From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892417910.3183075.14464477192227662952.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong I noticed that callers of xfs_qm_vop_dqalloc use the following code to compute the anticipated uid of the new file: mapped_fsuid(idmap, &init_user_ns); whereas the VFS uses a slightly different computation for actually assigning i_uid: mapped_fsuid(idmap, i_user_ns(inode)); Technically, these are not the same things. According to Christian Brauner, the only time that inode->i_sb->s_user_ns != &init_user_ns is when the filesystem was mounted in a new mount namespace by an unpriviledged user. XFS does not allow this, which is why we've never seen bug reports about quotas being incorrect or the uid checks in xfs_qm_vop_create_dqattach tripping debug assertions. However, this /is/ a logic bomb, so let's make the code consistent. Link: https://lore.kernel.org/linux-fsdevel/20240617-weitblick-gefertigt-4a41f37119fa@brauner/ Fixes: c14329d39f2d ("fs: port fs{g,u}id helpers to mnt_idmap") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_inode.c | 16 ++++++++++------ fs/xfs/xfs_symlink.c | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index aa134687027ca..5039509785090 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1059,10 +1059,12 @@ xfs_create( prid = xfs_get_initial_prid(dp); /* - * Make sure that we have allocated dquot(s) on disk. + * Make sure that we have allocated dquot(s) on disk. The uid/gid + * computation code must match what the VFS uses to assign i_[ug]id. + * INHERIT adjusts the gid computation for setgid/grpid systems. */ - error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns), - mapped_fsgid(idmap, &init_user_ns), prid, + error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), + mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp, &pdqp); if (error) @@ -1234,10 +1236,12 @@ xfs_create_tmpfile( prid = xfs_get_initial_prid(dp); /* - * Make sure that we have allocated dquot(s) on disk. + * Make sure that we have allocated dquot(s) on disk. The uid/gid + * computation code must match what the VFS uses to assign i_[ug]id. + * INHERIT adjusts the gid computation for setgid/grpid systems. */ - error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns), - mapped_fsgid(idmap, &init_user_ns), prid, + error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), + mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp, &pdqp); if (error) diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 17aee806ec2e1..53ed512c6f211 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -122,10 +122,12 @@ xfs_symlink( prid = xfs_get_initial_prid(dp); /* - * Make sure that we have allocated dquot(s) on disk. + * Make sure that we have allocated dquot(s) on disk. The uid/gid + * computation code must match what the VFS uses to assign i_[ug]id. + * INHERIT adjusts the gid computation for setgid/grpid systems. */ - error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns), - mapped_fsgid(idmap, &init_user_ns), prid, + error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), + mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp, &pdqp); if (error) From patchwork Thu Jun 20 22:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706472 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 44A271422B6 for ; Thu, 20 Jun 2024 22:58:56 +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=1718924336; cv=none; b=d0RZFEu04/XFwPrMokwIIo5ibnp57PloyEZdOPoHiZ4QJ8KRYvEjGR11v91Mf6kmQLBW8DyXFlPFvzBTdTC0hSYGJQ6gH5byf86rFbsO8Kdl4x6sXJ1gwmPDh14yX7y/P8OiOf+6RncHsy8coZlHNhqEzHDPaPOcQ/jgQrD2vWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924336; c=relaxed/simple; bh=lK7YxAgrnHsxBY39At/stVXLQrwODVJ28V8qVVyxRRA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hA30J+ENTrgS3MP8IkEZSQl8CbX6M1wDHqvV9VQwvwd5VPHxv6PcwBjkyeeUFjMllmTjyL2BibSLRkyJnnMscjTdFp3X/WcfVtCLtGaJ5IPmJD+jOXdzoEuBNC20EvdHyjNLIRuUmo9ogADaCSAtthrKt2dy+VXXtVt4m13DTKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G2n2yO2C; 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="G2n2yO2C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7C11C2BD10; Thu, 20 Jun 2024 22:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924335; bh=lK7YxAgrnHsxBY39At/stVXLQrwODVJ28V8qVVyxRRA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=G2n2yO2CgIWiSloj/GGEvORE3mb2IEQw7Ozmmrto3l7+QF9DDSDFeJFBOfVdC2fbu CxD7dv9zQA1xyGpRhjinAgnwjAhovmrKqdqawJSZBC/buiyUBu2W7swFTWe4oM32Il tVqjsC2B3xgHyTyV3m7kmPRIfXQGVw2nfaf1DIlFlFizvJRoMbUQNNtoZFE+GIMcuS QPMVO/rFDGafZ1+ZcfNt23fmFcfQ+wjisR54iUXnQzNqkNDgT0wCjlIaA79L9Ixoql 9nblx6CDphLa5LnG0BbZhX6TqP/l8z9gdNHi3GPRIrJvG02hIgRWeD9YnJyPs8KjUB 10RCRhuPUdPig== Date: Thu, 20 Jun 2024 15:58:55 -0700 Subject: [PATCH 02/24] xfs: move inode copy-on-write predicates to xfs_inode.[ch] From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892417927.3183075.160380352995983091.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move these inode predicate functions to xfs_inode.[ch] since they're not reflink functions. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_inode.c | 8 ++++++++ fs/xfs/xfs_inode.h | 7 +++++++ fs/xfs/xfs_reflink.h | 10 ---------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 5039509785090..03f685c3b6ada 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -4282,3 +4282,11 @@ xfs_inode_alloc_unitsize( return XFS_FSB_TO_B(ip->i_mount, blocks); } + +/* Should we always be using copy on write for file writes? */ +bool +xfs_is_always_cow_inode( + struct xfs_inode *ip) +{ + return ip->i_mount->m_always_cow && xfs_has_reflink(ip->i_mount); +} diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 292b90b5f2ac8..e97b2b838c69b 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -292,6 +292,13 @@ static inline bool xfs_is_metadata_inode(struct xfs_inode *ip) xfs_is_quota_inode(&mp->m_sb, ip->i_ino); } +bool xfs_is_always_cow_inode(struct xfs_inode *ip); + +static inline bool xfs_is_cow_inode(struct xfs_inode *ip) +{ + return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip); +} + /* * Check if an inode has any data in the COW fork. This might be often false * even for inodes with the reflink flag when there is no pending COW operation. diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index 65c5dfe17ecf7..fb55e4ce49fa1 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -6,16 +6,6 @@ #ifndef __XFS_REFLINK_H #define __XFS_REFLINK_H 1 -static inline bool xfs_is_always_cow_inode(struct xfs_inode *ip) -{ - return ip->i_mount->m_always_cow && xfs_has_reflink(ip->i_mount); -} - -static inline bool xfs_is_cow_inode(struct xfs_inode *ip) -{ - return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip); -} - extern int xfs_reflink_trim_around_shared(struct xfs_inode *ip, struct xfs_bmbt_irec *irec, bool *shared); int xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap, From patchwork Thu Jun 20 22:59:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706473 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 1E2FD142E62 for ; Thu, 20 Jun 2024 22:59:11 +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=1718924352; cv=none; b=D97OTICXBwOdMDv8C49rblllA0RW2LgYfBin1yEISNx9hY9e6hqBVu68LhSSZVxBvZpzwzUpchzzOA08aiukaJeTOov0j+hjln+ux5KGGFn0ru9RqQxP5wpj+fyFncO4KB/WMKbfKtTJx0vTRBsAJhPeGeYEM7DfWxeb9M12C9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924352; c=relaxed/simple; bh=1VYzQgM+bAk03Z9B/rZ4F48B06vpVKi5RCLm3i4vfXg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VHBccWHWCLsyrIyGzYZmhGt+FuN3gkSji7yxuGNAnrJAV6Yk+77qPnWMJUrPku7HOBwQcroCdMVWXeJ53jKTydr83kqlsiBAZMN4GF/lgwXl8jRBGW5oG5TwpilrFDo+76pT4QFbw+gLIlMHu+xvh2vLCRUMbBzRrRlPiyS7fTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aHYBcYc5; 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="aHYBcYc5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C871C2BD10; Thu, 20 Jun 2024 22:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924351; bh=1VYzQgM+bAk03Z9B/rZ4F48B06vpVKi5RCLm3i4vfXg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=aHYBcYc5UA+FLgBaFyE+/XZ+mz/Ph1b3u32kdFBXRqf5yyhNUWvBJX3HkKoBIB/9W tHbRjIBh0h3LRkizx1HyySv+BKm3QI8dZ27E+YIdT6MXZXjDlCH4F8KyK8epfguvjl 43sf8He25NQ5zDiqTRlyCv8uDBKWAEhf/0ukerxrXs1KMB/YddyYap6Ddg+lgFP52/ DR+5Bf4oOq0ootFrpJkZtQGBbmx98AuHGgT8xgu7bqBK3C3mzcomXR3CF3COSRsQdb TWKUKmqv2IJpwgM4P9Oq6JUn3F6GliDJUUwDFCA9v37uHiVfbHA9c3JOGn1USCMrWC JvQlK6SYlMNeg== Date: Thu, 20 Jun 2024 15:59:11 -0700 Subject: [PATCH 03/24] xfs: hoist extent size helpers to libxfs From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892417945.3183075.16613633853216031887.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move the extent size helpers to xfs_bmap.c in libxfs since they're used there already. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_bmap.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_bmap.h | 3 +++ fs/xfs/xfs_inode.c | 44 -------------------------------------------- fs/xfs/xfs_inode.h | 3 --- fs/xfs/xfs_iops.c | 1 + 5 files changed, 46 insertions(+), 47 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 6af6f744fdd6a..f889123126d22 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -6454,3 +6454,45 @@ xfs_bmap_query_all( return xfs_btree_query_all(cur, xfs_bmap_query_range_helper, &query); } + +/* Helper function to extract extent size hint from inode */ +xfs_extlen_t +xfs_get_extsz_hint( + struct xfs_inode *ip) +{ + /* + * No point in aligning allocations if we need to COW to actually + * write to them. + */ + if (xfs_is_always_cow_inode(ip)) + return 0; + if ((ip->i_diflags & XFS_DIFLAG_EXTSIZE) && ip->i_extsize) + return ip->i_extsize; + if (XFS_IS_REALTIME_INODE(ip) && + ip->i_mount->m_sb.sb_rextsize > 1) + return ip->i_mount->m_sb.sb_rextsize; + return 0; +} + +/* + * Helper function to extract CoW extent size hint from inode. + * Between the extent size hint and the CoW extent size hint, we + * return the greater of the two. If the value is zero (automatic), + * use the default size. + */ +xfs_extlen_t +xfs_get_cowextsz_hint( + struct xfs_inode *ip) +{ + xfs_extlen_t a, b; + + a = 0; + if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) + a = ip->i_cowextsize; + b = xfs_get_extsz_hint(ip); + + a = max(a, b); + if (a == 0) + return XFS_DEFAULT_COWEXTSZ_HINT; + return a; +} diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index 667b0c2b33d1d..7592d46e97c66 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -296,4 +296,7 @@ typedef int (*xfs_bmap_query_range_fn)( int xfs_bmap_query_all(struct xfs_btree_cur *cur, xfs_bmap_query_range_fn fn, void *priv); +xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip); +xfs_extlen_t xfs_get_cowextsz_hint(struct xfs_inode *ip); + #endif /* __XFS_BMAP_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 03f685c3b6ada..a00072adcb679 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -46,50 +46,6 @@ struct kmem_cache *xfs_inode_cache; -/* - * helper function to extract extent size hint from inode - */ -xfs_extlen_t -xfs_get_extsz_hint( - struct xfs_inode *ip) -{ - /* - * No point in aligning allocations if we need to COW to actually - * write to them. - */ - if (xfs_is_always_cow_inode(ip)) - return 0; - if ((ip->i_diflags & XFS_DIFLAG_EXTSIZE) && ip->i_extsize) - return ip->i_extsize; - if (XFS_IS_REALTIME_INODE(ip) && - ip->i_mount->m_sb.sb_rextsize > 1) - return ip->i_mount->m_sb.sb_rextsize; - return 0; -} - -/* - * Helper function to extract CoW extent size hint from inode. - * Between the extent size hint and the CoW extent size hint, we - * return the greater of the two. If the value is zero (automatic), - * use the default size. - */ -xfs_extlen_t -xfs_get_cowextsz_hint( - struct xfs_inode *ip) -{ - xfs_extlen_t a, b; - - a = 0; - if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) - a = ip->i_cowextsize; - b = xfs_get_extsz_hint(ip); - - a = max(a, b); - if (a == 0) - return XFS_DEFAULT_COWEXTSZ_HINT; - return a; -} - /* * These two are wrapper routines around the xfs_ilock() routine used to * centralize some grungy code. They are used in places that wish to lock the diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index e97b2b838c69b..0e642afa77a7c 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -563,9 +563,6 @@ int xfs_iflush_cluster(struct xfs_buf *); void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode, struct xfs_inode *ip1, uint ip1_mode); -xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip); -xfs_extlen_t xfs_get_cowextsz_hint(struct xfs_inode *ip); - int xfs_init_new_inode(struct mnt_idmap *idmap, struct xfs_trans *tp, struct xfs_inode *pip, xfs_ino_t ino, umode_t mode, xfs_nlink_t nlink, dev_t rdev, prid_t prid, bool init_xattrs, diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index ff222827e5508..35a84790d26e6 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -26,6 +26,7 @@ #include "xfs_ioctl.h" #include "xfs_xattr.h" #include "xfs_file.h" +#include "xfs_bmap.h" #include #include From patchwork Thu Jun 20 22:59:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706474 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 A164F143737 for ; Thu, 20 Jun 2024 22:59:27 +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=1718924367; cv=none; b=HmPO98wlATntzR/6+SREQE/4KaznOBV7Oa4E56nJnOi/GtGQgiJJtvTL36o0Zn+u+ey1db5rBGTdXzsOxXr2+/07ED1DmIlzsGO8Hetlj7TmxxJiM8TMw//1mD1Bl/kM05xYUtf0WtcMAfWNf9WsvXiHbZEKAHLTUOIhHsBK+lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924367; c=relaxed/simple; bh=IrGqgBJQAh+0QAqtfo4dWXx2H6pm9hXvjbI9LVPQhGs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iCZmNkFtV8Edk5AJFsGfndWqzmqacKWFuw19AryvtePUyXgoaioX6A+fuN9nqldyVlXfE7y4Af7BRDNEQL6hXoRLl3yuKO93yxDZu/2fVtOhXErhAplxYsiBG70gvAWCk5bu/W5RRwVwrC160eEhs+4PEXMbLhj4A5p3ypc+8oo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bWpqrN6I; 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="bWpqrN6I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27B15C2BD10; Thu, 20 Jun 2024 22:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924367; bh=IrGqgBJQAh+0QAqtfo4dWXx2H6pm9hXvjbI9LVPQhGs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=bWpqrN6I03/710PH7CpXnA0XW6zmJ7cRoqnuRjjV3G64mbPK2FGQTnkvTbB6Nnd44 jQyW/1DU7r9J/FnXbrO/jJX3lIVl2puxnop3qwnjZYdNu1H2HRFoyCBfEhgqJq36zU MilZC0sJUIu7PBk3R0sdjMAFWOs8+PA/GVRYFIwthqfLUEewsNsmNam+GuLlaBMjZQ hyNToW9Be1CUUmuWV/LbZq7TiW2XB1a8tqDCSS9s97jq3mMei/5/ZqUViH3REEpDRy 3aiQHpGAXENIPmHTgPGsvB9oX9PVF2SqQP70T6MGV9C5aRMxi5UDYFFbuSt3yyWTAi yhuxzxbIbNU8A== Date: Thu, 20 Jun 2024 15:59:26 -0700 Subject: [PATCH 04/24] xfs: hoist inode flag conversion functions to libxfs From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892417963.3183075.6780097546790838079.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Hoist the inode flag conversion functions into libxfs so that we can keep them in sync. Do this by creating a new xfs_inode_util.c file in libxfs. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_bmap.c | 1 fs/xfs/libxfs/xfs_inode_util.c | 124 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 14 +++++ fs/xfs/xfs_inode.c | 49 ---------------- fs/xfs/xfs_inode.h | 2 - fs/xfs/xfs_ioctl.c | 60 ------------------- 7 files changed, 141 insertions(+), 110 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_inode_util.c create mode 100644 fs/xfs/libxfs/xfs_inode_util.h diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index c50447548d655..dd692619bed58 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -40,6 +40,7 @@ xfs-y += $(addprefix libxfs/, \ xfs_iext_tree.o \ xfs_inode_fork.o \ xfs_inode_buf.o \ + xfs_inode_util.o \ xfs_log_rlimit.o \ xfs_ag_resv.o \ xfs_parent.o \ diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index f889123126d22..09e3302a4b72f 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -39,6 +39,7 @@ #include "xfs_health.h" #include "xfs_bmap_item.h" #include "xfs_symlink_remote.h" +#include "xfs_inode_util.h" struct kmem_cache *xfs_bmap_intent_cache; diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c new file mode 100644 index 0000000000000..ed5e1a9b4b8c6 --- /dev/null +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2000-2006 Silicon Graphics, Inc. + * All Rights Reserved. + */ +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_sb.h" +#include "xfs_mount.h" +#include "xfs_inode.h" +#include "xfs_inode_util.h" + +uint16_t +xfs_flags2diflags( + struct xfs_inode *ip, + unsigned int xflags) +{ + /* can't set PREALLOC this way, just preserve it */ + uint16_t di_flags = + (ip->i_diflags & XFS_DIFLAG_PREALLOC); + + if (xflags & FS_XFLAG_IMMUTABLE) + di_flags |= XFS_DIFLAG_IMMUTABLE; + if (xflags & FS_XFLAG_APPEND) + di_flags |= XFS_DIFLAG_APPEND; + if (xflags & FS_XFLAG_SYNC) + di_flags |= XFS_DIFLAG_SYNC; + if (xflags & FS_XFLAG_NOATIME) + di_flags |= XFS_DIFLAG_NOATIME; + if (xflags & FS_XFLAG_NODUMP) + di_flags |= XFS_DIFLAG_NODUMP; + if (xflags & FS_XFLAG_NODEFRAG) + di_flags |= XFS_DIFLAG_NODEFRAG; + if (xflags & FS_XFLAG_FILESTREAM) + di_flags |= XFS_DIFLAG_FILESTREAM; + if (S_ISDIR(VFS_I(ip)->i_mode)) { + if (xflags & FS_XFLAG_RTINHERIT) + di_flags |= XFS_DIFLAG_RTINHERIT; + if (xflags & FS_XFLAG_NOSYMLINKS) + di_flags |= XFS_DIFLAG_NOSYMLINKS; + if (xflags & FS_XFLAG_EXTSZINHERIT) + di_flags |= XFS_DIFLAG_EXTSZINHERIT; + if (xflags & FS_XFLAG_PROJINHERIT) + di_flags |= XFS_DIFLAG_PROJINHERIT; + } else if (S_ISREG(VFS_I(ip)->i_mode)) { + if (xflags & FS_XFLAG_REALTIME) + di_flags |= XFS_DIFLAG_REALTIME; + if (xflags & FS_XFLAG_EXTSIZE) + di_flags |= XFS_DIFLAG_EXTSIZE; + } + + return di_flags; +} + +uint64_t +xfs_flags2diflags2( + struct xfs_inode *ip, + unsigned int xflags) +{ + uint64_t di_flags2 = + (ip->i_diflags2 & (XFS_DIFLAG2_REFLINK | + XFS_DIFLAG2_BIGTIME | + XFS_DIFLAG2_NREXT64)); + + if (xflags & FS_XFLAG_DAX) + di_flags2 |= XFS_DIFLAG2_DAX; + if (xflags & FS_XFLAG_COWEXTSIZE) + di_flags2 |= XFS_DIFLAG2_COWEXTSIZE; + + return di_flags2; +} + +uint32_t +xfs_ip2xflags( + struct xfs_inode *ip) +{ + uint32_t flags = 0; + + if (ip->i_diflags & XFS_DIFLAG_ANY) { + if (ip->i_diflags & XFS_DIFLAG_REALTIME) + flags |= FS_XFLAG_REALTIME; + if (ip->i_diflags & XFS_DIFLAG_PREALLOC) + flags |= FS_XFLAG_PREALLOC; + if (ip->i_diflags & XFS_DIFLAG_IMMUTABLE) + flags |= FS_XFLAG_IMMUTABLE; + if (ip->i_diflags & XFS_DIFLAG_APPEND) + flags |= FS_XFLAG_APPEND; + if (ip->i_diflags & XFS_DIFLAG_SYNC) + flags |= FS_XFLAG_SYNC; + if (ip->i_diflags & XFS_DIFLAG_NOATIME) + flags |= FS_XFLAG_NOATIME; + if (ip->i_diflags & XFS_DIFLAG_NODUMP) + flags |= FS_XFLAG_NODUMP; + if (ip->i_diflags & XFS_DIFLAG_RTINHERIT) + flags |= FS_XFLAG_RTINHERIT; + if (ip->i_diflags & XFS_DIFLAG_PROJINHERIT) + flags |= FS_XFLAG_PROJINHERIT; + if (ip->i_diflags & XFS_DIFLAG_NOSYMLINKS) + flags |= FS_XFLAG_NOSYMLINKS; + if (ip->i_diflags & XFS_DIFLAG_EXTSIZE) + flags |= FS_XFLAG_EXTSIZE; + if (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) + flags |= FS_XFLAG_EXTSZINHERIT; + if (ip->i_diflags & XFS_DIFLAG_NODEFRAG) + flags |= FS_XFLAG_NODEFRAG; + if (ip->i_diflags & XFS_DIFLAG_FILESTREAM) + flags |= FS_XFLAG_FILESTREAM; + } + + if (ip->i_diflags2 & XFS_DIFLAG2_ANY) { + if (ip->i_diflags2 & XFS_DIFLAG2_DAX) + flags |= FS_XFLAG_DAX; + if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) + flags |= FS_XFLAG_COWEXTSIZE; + } + + if (xfs_inode_has_attr_fork(ip)) + flags |= FS_XFLAG_HASATTR; + return flags; +} diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h new file mode 100644 index 0000000000000..6ad1898a0f73f --- /dev/null +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. + * All Rights Reserved. + */ +#ifndef __XFS_INODE_UTIL_H__ +#define __XFS_INODE_UTIL_H__ + +uint16_t xfs_flags2diflags(struct xfs_inode *ip, unsigned int xflags); +uint64_t xfs_flags2diflags2(struct xfs_inode *ip, unsigned int xflags); +uint32_t xfs_dic2xflags(struct xfs_inode *ip); +uint32_t xfs_ip2xflags(struct xfs_inode *ip); + +#endif /* __XFS_INODE_UTIL_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index a00072adcb679..e98b636731417 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -523,55 +523,6 @@ xfs_lock_two_inodes( } } -uint -xfs_ip2xflags( - struct xfs_inode *ip) -{ - uint flags = 0; - - if (ip->i_diflags & XFS_DIFLAG_ANY) { - if (ip->i_diflags & XFS_DIFLAG_REALTIME) - flags |= FS_XFLAG_REALTIME; - if (ip->i_diflags & XFS_DIFLAG_PREALLOC) - flags |= FS_XFLAG_PREALLOC; - if (ip->i_diflags & XFS_DIFLAG_IMMUTABLE) - flags |= FS_XFLAG_IMMUTABLE; - if (ip->i_diflags & XFS_DIFLAG_APPEND) - flags |= FS_XFLAG_APPEND; - if (ip->i_diflags & XFS_DIFLAG_SYNC) - flags |= FS_XFLAG_SYNC; - if (ip->i_diflags & XFS_DIFLAG_NOATIME) - flags |= FS_XFLAG_NOATIME; - if (ip->i_diflags & XFS_DIFLAG_NODUMP) - flags |= FS_XFLAG_NODUMP; - if (ip->i_diflags & XFS_DIFLAG_RTINHERIT) - flags |= FS_XFLAG_RTINHERIT; - if (ip->i_diflags & XFS_DIFLAG_PROJINHERIT) - flags |= FS_XFLAG_PROJINHERIT; - if (ip->i_diflags & XFS_DIFLAG_NOSYMLINKS) - flags |= FS_XFLAG_NOSYMLINKS; - if (ip->i_diflags & XFS_DIFLAG_EXTSIZE) - flags |= FS_XFLAG_EXTSIZE; - if (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) - flags |= FS_XFLAG_EXTSZINHERIT; - if (ip->i_diflags & XFS_DIFLAG_NODEFRAG) - flags |= FS_XFLAG_NODEFRAG; - if (ip->i_diflags & XFS_DIFLAG_FILESTREAM) - flags |= FS_XFLAG_FILESTREAM; - } - - if (ip->i_diflags2 & XFS_DIFLAG2_ANY) { - if (ip->i_diflags2 & XFS_DIFLAG2_DAX) - flags |= FS_XFLAG_DAX; - if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) - flags |= FS_XFLAG_COWEXTSIZE; - } - - if (xfs_inode_has_attr_fork(ip)) - flags |= FS_XFLAG_HASATTR; - return flags; -} - /* * Lookups up an inode from "name". If ci_name is not NULL, then a CI match * is allowed, otherwise it has to be an exact match. If a CI match is found, diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 0e642afa77a7c..b20768962e8d6 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -8,6 +8,7 @@ #include "xfs_inode_buf.h" #include "xfs_inode_fork.h" +#include "xfs_inode_util.h" /* * Kernel only inode definitions @@ -549,7 +550,6 @@ void xfs_assert_ilocked(struct xfs_inode *, uint); uint xfs_ilock_data_map_shared(struct xfs_inode *); uint xfs_ilock_attr_map_shared(struct xfs_inode *); -uint xfs_ip2xflags(struct xfs_inode *); int xfs_ifree(struct xfs_trans *, struct xfs_inode *); int xfs_itruncate_extents_flags(struct xfs_trans **, struct xfs_inode *, int, xfs_fsize_t, int); diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index f0117188f3021..4e933db75b12b 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -469,66 +469,6 @@ xfs_fileattr_get( return 0; } -STATIC uint16_t -xfs_flags2diflags( - struct xfs_inode *ip, - unsigned int xflags) -{ - /* can't set PREALLOC this way, just preserve it */ - uint16_t di_flags = - (ip->i_diflags & XFS_DIFLAG_PREALLOC); - - if (xflags & FS_XFLAG_IMMUTABLE) - di_flags |= XFS_DIFLAG_IMMUTABLE; - if (xflags & FS_XFLAG_APPEND) - di_flags |= XFS_DIFLAG_APPEND; - if (xflags & FS_XFLAG_SYNC) - di_flags |= XFS_DIFLAG_SYNC; - if (xflags & FS_XFLAG_NOATIME) - di_flags |= XFS_DIFLAG_NOATIME; - if (xflags & FS_XFLAG_NODUMP) - di_flags |= XFS_DIFLAG_NODUMP; - if (xflags & FS_XFLAG_NODEFRAG) - di_flags |= XFS_DIFLAG_NODEFRAG; - if (xflags & FS_XFLAG_FILESTREAM) - di_flags |= XFS_DIFLAG_FILESTREAM; - if (S_ISDIR(VFS_I(ip)->i_mode)) { - if (xflags & FS_XFLAG_RTINHERIT) - di_flags |= XFS_DIFLAG_RTINHERIT; - if (xflags & FS_XFLAG_NOSYMLINKS) - di_flags |= XFS_DIFLAG_NOSYMLINKS; - if (xflags & FS_XFLAG_EXTSZINHERIT) - di_flags |= XFS_DIFLAG_EXTSZINHERIT; - if (xflags & FS_XFLAG_PROJINHERIT) - di_flags |= XFS_DIFLAG_PROJINHERIT; - } else if (S_ISREG(VFS_I(ip)->i_mode)) { - if (xflags & FS_XFLAG_REALTIME) - di_flags |= XFS_DIFLAG_REALTIME; - if (xflags & FS_XFLAG_EXTSIZE) - di_flags |= XFS_DIFLAG_EXTSIZE; - } - - return di_flags; -} - -STATIC uint64_t -xfs_flags2diflags2( - struct xfs_inode *ip, - unsigned int xflags) -{ - uint64_t di_flags2 = - (ip->i_diflags2 & (XFS_DIFLAG2_REFLINK | - XFS_DIFLAG2_BIGTIME | - XFS_DIFLAG2_NREXT64)); - - if (xflags & FS_XFLAG_DAX) - di_flags2 |= XFS_DIFLAG2_DAX; - if (xflags & FS_XFLAG_COWEXTSIZE) - di_flags2 |= XFS_DIFLAG2_COWEXTSIZE; - - return di_flags2; -} - static int xfs_ioctl_setattr_xflags( struct xfs_trans *tp, From patchwork Thu Jun 20 22:59:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706475 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 4F63E143737 for ; Thu, 20 Jun 2024 22:59:42 +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=1718924383; cv=none; b=S+SZ/XF3Jt6LCkoriAH5TQHDK/pTUbgb0xZjZYItMpvj2gVb+GjVdk+E7+Ezy98Ff/RsyIwzjtWLCbCJJVTRbqC4/xwPlNuhILEPGI/ga1insn2E9FtaCQfAQhRKDBzulCs5WFxe7WT3nLm3nKTN3MTC9ug0WIO8gXyC4+xCnv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924383; c=relaxed/simple; bh=MR78uyoxbkyloJjBf8hCk2IRWVwvLeSSKINVYvAjbHA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MRoZHgxU2PoxQkbIuXEPPG9pkEYWRJtswnQJwFl78WhBO39OsLJtJHU5ZL2fOLwgJhtrRZwpUMJ1gEmjqwe/mBraJH1S3jFVh60dQSSl/7yFhJ5af+ZjXdJGV3Msf+f1qOuPKLDL59HnP7ZBGq2klCrneKZuJwFd89ij8Xov4S4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B7gbH3aW; 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="B7gbH3aW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9089C2BD10; Thu, 20 Jun 2024 22:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924382; bh=MR78uyoxbkyloJjBf8hCk2IRWVwvLeSSKINVYvAjbHA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=B7gbH3aWHZxP8OmgWyeZbIRlMA91NFKMk5rFpdnKNSzp30q6YsQtA54sTUr583lAJ NQiyl9VfDSbC86DXJYb0zuvhJsUmf8AeWyaAgpLD3Hy5F3iiDX7VP2BiuyBi1rG42X pEZY9f371+VypbqHQLppWTF3++n3YmOByt1T6H+oBuPy2JRDfEYBXeU1MrmbVHtqkZ daBKZCls5x3opcot+PegnltUjA/500JFpq5zRmpPGmj0NDL0lLeiDAp5cmMbVgIgcp zPvwozj2FsKT+0Crjf1Xeq9hv4eeKk76uN6d2e3S5uXSOQos87OOLL6l5Vcd6JFtmF 1uKunmGwJD6qQ== Date: Thu, 20 Jun 2024 15:59:42 -0700 Subject: [PATCH 05/24] xfs: hoist project id get/set functions to libxfs From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892417981.3183075.2780737496009319760.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move the project id get and set functions into libxfs. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_inode_util.c | 10 ++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 2 ++ fs/xfs/xfs_inode.h | 9 --------- fs/xfs/xfs_linux.h | 2 -- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index ed5e1a9b4b8c6..3b5397a3f34f2 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -122,3 +122,13 @@ xfs_ip2xflags( flags |= FS_XFLAG_HASATTR; return flags; } + +prid_t +xfs_get_initial_prid(struct xfs_inode *dp) +{ + if (dp->i_diflags & XFS_DIFLAG_PROJINHERIT) + return dp->i_projid; + + /* Assign to the root project by default. */ + return 0; +} diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h index 6ad1898a0f73f..f7e4d5a8235dd 100644 --- a/fs/xfs/libxfs/xfs_inode_util.h +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -11,4 +11,6 @@ uint64_t xfs_flags2diflags2(struct xfs_inode *ip, unsigned int xflags); uint32_t xfs_dic2xflags(struct xfs_inode *ip); uint32_t xfs_ip2xflags(struct xfs_inode *ip); +prid_t xfs_get_initial_prid(struct xfs_inode *dp); + #endif /* __XFS_INODE_UTIL_H__ */ diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index b20768962e8d6..15ab7a1c79a60 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -271,15 +271,6 @@ xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned long flags) return ret; } -static inline prid_t -xfs_get_initial_prid(struct xfs_inode *dp) -{ - if (dp->i_diflags & XFS_DIFLAG_PROJINHERIT) - return dp->i_projid; - - return XFS_PROJID_DEFAULT; -} - static inline bool xfs_is_reflink_inode(struct xfs_inode *ip) { return ip->i_diflags2 & XFS_DIFLAG2_REFLINK; diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index ac355328121ac..54a098fe72858 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -135,8 +135,6 @@ typedef __u32 xfs_nlink_t; */ #define __this_address ({ __label__ __here; __here: barrier(); &&__here; }) -#define XFS_PROJID_DEFAULT 0 - #define howmany(x, y) (((x)+((y)-1))/(y)) static inline void delay(long ticks) From patchwork Thu Jun 20 22:59:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706476 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 9731F143737 for ; Thu, 20 Jun 2024 22:59:58 +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=1718924398; cv=none; b=Y74ncanL1fpwOBIWp15Pf6rKucANU9rcfwVj78vqo6b6eu6t6sS8hJwOzVShis/iKboJKJUQqV1hDvTiaSwq2Eu6NJu3c/kDx6/9ddTsBTuHC4hD0+nf1gb+OekcWfIer3mXRf6cy1NAAJAdSe1c23nmQNMxNFkA6MFIhnJCBKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924398; c=relaxed/simple; bh=KqJNh5o/YItoA7fsBeC2H/JE34llOt7llK1i4ZDQalg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZD+Bjtwed14RC3ezoURZBURM0bAtZdwd6MRZLm3YUYqnH5NdDVtQXBjGUxE0PE7UdHCszAlRdIcB/NsYUfpBFXQXdZBR9VILO38VpOxNN/R/ao1Gd5wXssv/DwuRaF58d2I4nCuG4HiZ8VOmRQpXSP5fZPtSpbWImL2WaOVYpJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XT6sdlEz; 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="XT6sdlEz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F24DC2BD10; Thu, 20 Jun 2024 22:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924398; bh=KqJNh5o/YItoA7fsBeC2H/JE34llOt7llK1i4ZDQalg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XT6sdlEzuD8JKHmOfaDwyA5/4GjHEfK5YBcjc9qDj2LmhOXwdNHkQbooltKbgPen8 CTG7PZ5Zzbhoab4FxwsvGYa9EkCZ9L9KXVmGijmyBP+Rns6DAF5/8MNUWZp2QGCaZi InZHJ0cWHwfEKqJJSgs1Fsf/KKZCYzMsJ1GqHD74VwSBUSFfg9fei584+Se6g+v2dB THKtP12urRq1SYuxKp+7jQPZZ720E6FlVI4q6VRK6cczKml5e4kCOQwoGz6ahFEMm+ EjIq+d6E5CXY9/KDh81I4a8Mca25zE91c5cKUfHkYQHW/S2NIhnUkeP3i4ePtIndnj pdxSm9cSG91HQ== Date: Thu, 20 Jun 2024 15:59:58 -0700 Subject: [PATCH 06/24] xfs: pack icreate initialization parameters into a separate structure From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892417998.3183075.10914239409938164350.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Callers that want to create an inode currently pass all possible file attribute values for the new inode into xfs_init_new_inode as ten separate parameters. This causes two code maintenance issues: first, we have large multi-line call sites which programmers must read carefully to make sure they did not accidentally invert a value. Second, all three file id parameters must be passed separately to the quota functions; any discrepancy results in quota count errors. Clean this up by creating a new icreate_args structure to hold all this information, some helpers to initialize them properly, and make the callers pass this structure through to the creation function, whose name we shorten to xfs_icreate. This eliminates the issues, enables us to keep the inode init code in sync with userspace via libxfs, and is needed for future metadata directory tree management. (A subsequent cleanup will also fix the quota alloc calls.) Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_inode_util.h | 22 ++++++++++ fs/xfs/scrub/tempfile.c | 12 +++-- fs/xfs/xfs_inode.c | 89 ++++++++++++++++++++++++++-------------- fs/xfs/xfs_inode.h | 6 +-- fs/xfs/xfs_qm.c | 6 ++- fs/xfs/xfs_symlink.c | 12 ++++- 6 files changed, 101 insertions(+), 46 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h index f7e4d5a8235dd..9226482fdee8c 100644 --- a/fs/xfs/libxfs/xfs_inode_util.h +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -13,4 +13,26 @@ uint32_t xfs_ip2xflags(struct xfs_inode *ip); prid_t xfs_get_initial_prid(struct xfs_inode *dp); +/* + * File creation context. + * + * Due to our only partial reliance on the VFS to propagate uid and gid values + * according to accepted Unix behaviors, callers must initialize idmap to the + * correct idmapping structure to get the correct inheritance behaviors when + * XFS_MOUNT_GRPID is set. + * + * To create files detached from the directory tree (e.g. quota inodes), set + * idmap to NULL. To create a tree root, set pip to NULL. + */ +struct xfs_icreate_args { + struct mnt_idmap *idmap; + struct xfs_inode *pip; /* parent inode or null */ + dev_t rdev; + umode_t mode; + +#define XFS_ICREATE_TMPFILE (1U << 0) /* create an unlinked file */ +#define XFS_ICREATE_INIT_XATTRS (1U << 1) /* will set xattrs immediately */ + uint16_t flags; +}; + #endif /* __XFS_INODE_UTIL_H__ */ diff --git a/fs/xfs/scrub/tempfile.c b/fs/xfs/scrub/tempfile.c index b747b625c5ee4..ee6f93e9f7cba 100644 --- a/fs/xfs/scrub/tempfile.c +++ b/fs/xfs/scrub/tempfile.c @@ -40,6 +40,11 @@ xrep_tempfile_create( struct xfs_scrub *sc, uint16_t mode) { + struct xfs_icreate_args args = { + .pip = sc->mp->m_rootip, + .mode = mode, + .flags = XFS_ICREATE_TMPFILE, + }; struct xfs_mount *mp = sc->mp; struct xfs_trans *tp = NULL; struct xfs_dquot *udqp = NULL; @@ -87,14 +92,11 @@ xrep_tempfile_create( error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); if (error) goto out_trans_cancel; - error = xfs_init_new_inode(&nop_mnt_idmap, tp, dp, ino, mode, 0, 0, - 0, false, &sc->tempip); + error = xfs_icreate(tp, ino, &args, &sc->tempip); if (error) goto out_trans_cancel; - /* Change the ownership of the inode to root. */ - VFS_I(sc->tempip)->i_uid = GLOBAL_ROOT_UID; - VFS_I(sc->tempip)->i_gid = GLOBAL_ROOT_GID; + /* We don't touch file data, so drop the realtime flags. */ sc->tempip->i_diflags &= ~(XFS_DIFLAG_REALTIME | XFS_DIFLAG_RTINHERIT); xfs_trans_log_inode(tp, sc->tempip, XFS_ILOG_CORE); diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index e98b636731417..4ceefe32b5854 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -662,18 +662,13 @@ xfs_inode_inherit_flags2( * Caller is responsible for unlocking the inode manually upon return */ int -xfs_init_new_inode( - struct mnt_idmap *idmap, +xfs_icreate( struct xfs_trans *tp, - struct xfs_inode *pip, xfs_ino_t ino, - umode_t mode, - xfs_nlink_t nlink, - dev_t rdev, - prid_t prid, - bool init_xattrs, + const struct xfs_icreate_args *args, struct xfs_inode **ipp) { + struct xfs_inode *pip = args->pip; struct inode *dir = pip ? VFS_I(pip) : NULL; struct xfs_mount *mp = tp->t_mountp; struct xfs_inode *ip; @@ -706,27 +701,44 @@ xfs_init_new_inode( ASSERT(ip != NULL); inode = VFS_I(ip); - set_nlink(inode, nlink); - inode->i_rdev = rdev; - ip->i_projid = prid; - if (dir && !(dir->i_mode & S_ISGID) && xfs_has_grpid(mp)) { - inode_fsuid_set(inode, idmap); - inode->i_gid = dir->i_gid; - inode->i_mode = mode; + if (args->flags & XFS_ICREATE_TMPFILE) + set_nlink(inode, 0); + else if (S_ISDIR(args->mode)) + set_nlink(inode, 2); + else + set_nlink(inode, 1); + inode->i_rdev = args->rdev; + + if (!args->idmap || pip == NULL) { + /* creating a tree root, sb rooted, or detached file */ + inode->i_uid = GLOBAL_ROOT_UID; + inode->i_gid = GLOBAL_ROOT_GID; + ip->i_projid = 0; + inode->i_mode = args->mode; } else { - inode_init_owner(idmap, inode, dir, mode); + /* creating a child in the directory tree */ + if (dir && !(dir->i_mode & S_ISGID) && xfs_has_grpid(mp)) { + inode_fsuid_set(inode, args->idmap); + inode->i_gid = dir->i_gid; + inode->i_mode = args->mode; + } else { + inode_init_owner(args->idmap, inode, dir, args->mode); + } + + /* + * If the group ID of the new file does not match the effective + * group ID or one of the supplementary group IDs, the S_ISGID + * bit is cleared (and only if the irix_sgid_inherit + * compatibility variable is set). + */ + if (irix_sgid_inherit && (inode->i_mode & S_ISGID) && + !vfsgid_in_group_p(i_gid_into_vfsgid(args->idmap, inode))) + inode->i_mode &= ~S_ISGID; + + ip->i_projid = pip ? xfs_get_initial_prid(pip) : 0; } - /* - * If the group ID of the new file does not match the effective group - * ID or one of the supplementary group IDs, the S_ISGID bit is cleared - * (and only if the irix_sgid_inherit compatibility variable is set). - */ - if (irix_sgid_inherit && (inode->i_mode & S_ISGID) && - !vfsgid_in_group_p(i_gid_into_vfsgid(idmap, inode))) - inode->i_mode &= ~S_ISGID; - ip->i_disk_size = 0; ip->i_df.if_nextents = 0; ASSERT(ip->i_nblocks == 0); @@ -745,7 +757,7 @@ xfs_init_new_inode( } flags = XFS_ILOG_CORE; - switch (mode & S_IFMT) { + switch (args->mode & S_IFMT) { case S_IFIFO: case S_IFCHR: case S_IFBLK: @@ -778,7 +790,7 @@ xfs_init_new_inode( * this saves us from needing to run a separate transaction to set the * fork offset in the immediate future. */ - if (init_xattrs) { + if (args->flags & XFS_ICREATE_INIT_XATTRS) { ip->i_forkoff = xfs_default_attroffset(ip) >> 3; xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); @@ -941,6 +953,13 @@ xfs_create( bool init_xattrs, xfs_inode_t **ipp) { + struct xfs_icreate_args args = { + .idmap = idmap, + .pip = dp, + .rdev = rdev, + .mode = mode, + .flags = init_xattrs ? XFS_ICREATE_INIT_XATTRS : 0, + }; int is_dir = S_ISDIR(mode); struct xfs_mount *mp = dp->i_mount; struct xfs_inode *ip = NULL; @@ -1016,8 +1035,7 @@ xfs_create( */ error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); if (!error) - error = xfs_init_new_inode(idmap, tp, dp, ino, mode, - is_dir ? 2 : 1, rdev, prid, init_xattrs, &ip); + error = xfs_icreate(tp, ino, &args, &ip); if (error) goto out_trans_cancel; @@ -1125,11 +1143,17 @@ xfs_create_tmpfile( bool init_xattrs, struct xfs_inode **ipp) { + struct xfs_icreate_args args = { + .idmap = idmap, + .pip = dp, + .mode = mode, + .flags = XFS_ICREATE_TMPFILE, + }; struct xfs_mount *mp = dp->i_mount; struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; int error; - prid_t prid; + prid_t prid; struct xfs_dquot *udqp = NULL; struct xfs_dquot *gdqp = NULL; struct xfs_dquot *pdqp = NULL; @@ -1141,6 +1165,8 @@ xfs_create_tmpfile( return -EIO; prid = xfs_get_initial_prid(dp); + if (init_xattrs) + args.flags |= XFS_ICREATE_INIT_XATTRS; /* * Make sure that we have allocated dquot(s) on disk. The uid/gid @@ -1164,8 +1190,7 @@ xfs_create_tmpfile( error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); if (!error) - error = xfs_init_new_inode(idmap, tp, dp, ino, mode, - 0, 0, prid, init_xattrs, &ip); + error = xfs_icreate(tp, ino, &args, &ip); if (error) goto out_trans_cancel; diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 15ab7a1c79a60..7d3fea66e069e 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -554,10 +554,8 @@ int xfs_iflush_cluster(struct xfs_buf *); void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode, struct xfs_inode *ip1, uint ip1_mode); -int xfs_init_new_inode(struct mnt_idmap *idmap, struct xfs_trans *tp, - struct xfs_inode *pip, xfs_ino_t ino, umode_t mode, - xfs_nlink_t nlink, dev_t rdev, prid_t prid, bool init_xattrs, - struct xfs_inode **ipp); +int xfs_icreate(struct xfs_trans *tp, xfs_ino_t ino, + const struct xfs_icreate_args *args, struct xfs_inode **ipp); static inline int xfs_itruncate_extents( diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 47120b745c47f..78f839630c624 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -793,12 +793,14 @@ xfs_qm_qino_alloc( return error; if (need_alloc) { + struct xfs_icreate_args args = { + .mode = S_IFREG, + }; xfs_ino_t ino; error = xfs_dialloc(&tp, 0, S_IFREG, &ino); if (!error) - error = xfs_init_new_inode(&nop_mnt_idmap, tp, NULL, ino, - S_IFREG, 1, 0, 0, false, ipp); + error = xfs_icreate(tp, ino, &args, ipp); if (error) { xfs_trans_cancel(tp); return error; diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 53ed512c6f211..3b797a39950d5 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -90,6 +90,11 @@ xfs_symlink( struct xfs_inode **ipp) { struct xfs_mount *mp = dp->i_mount; + struct xfs_icreate_args args = { + .idmap = idmap, + .pip = dp, + .mode = S_IFLNK | (mode & ~S_IFMT), + }; struct xfs_trans *tp = NULL; struct xfs_inode *ip = NULL; int error = 0; @@ -111,6 +116,9 @@ xfs_symlink( if (xfs_is_shutdown(mp)) return -EIO; + if (xfs_has_parent(mp)) + args.flags |= XFS_ICREATE_INIT_XATTRS; + /* * Check component lengths of the target path name. */ @@ -170,9 +178,7 @@ xfs_symlink( */ error = xfs_dialloc(&tp, dp->i_ino, S_IFLNK, &ino); if (!error) - error = xfs_init_new_inode(idmap, tp, dp, ino, - S_IFLNK | (mode & ~S_IFMT), 1, 0, prid, - xfs_has_parent(mp), &ip); + error = xfs_icreate(tp, ino, &args, &ip); if (error) goto out_trans_cancel; From patchwork Thu Jun 20 23:00:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706477 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 7F663433CA for ; Thu, 20 Jun 2024 23:00:14 +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=1718924414; cv=none; b=h9lcXiIo6SdQwbG+MRqfsmqgFb0/+YYx6FzcDDS3siGP/ONSEv6LA4vf004m1vv/wuf0JBagbGZy03TSaSdj7VbqRLQR5ckdLQV30pvubdntGKONPQmAli+U1Q3kcsw52UsDYilrJoQa+kcnRcREZDKosWWiylnVbeVXn2/4mog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924414; c=relaxed/simple; bh=mDfB6FmUeK9ikoz5IKK8Zv6J3ELFKo9YoQQ7CEuWuI0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j9l6SDGLeKZMOGOGV8siF+fXcuf6WabrUoFC9JQrYG9dnmmL7NhToFoMQETiw6dqJyLKdTIv/GoPBz/eFsmH9Jjj1kzNy0N3ckDQLj53wxIE2UpYjbzL4WEIdEAoHUyoMYhcB/0deMI2ZQplCb+0kTNJgOXMIshGKyMoqLumDQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AoVmGdeu; 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="AoVmGdeu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 138DEC2BD10; Thu, 20 Jun 2024 23:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924414; bh=mDfB6FmUeK9ikoz5IKK8Zv6J3ELFKo9YoQQ7CEuWuI0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=AoVmGdeuQFHjntSdCUPGcUP3eXwVlWqZNiRC4YHhxHz8Q2M9kp/zJkz+VbVF7ATKE vMNyvAkzs6dy0xm4urqHVmPXiOBBfM7XfKG4oQIfbqu+eLQD++m/sKfzo/m7k9jGA4 w1TP+Rijhmjx3ewgBm2ZbrDJPLg/jPz/rvFFeQDwEqFBTEXnHXG6ypaZZLD2EoA73Y le39DMf1byaOT6bkNhWStQ61bjkKZ1cCC/v+n95ZvqPHHPYOes/5jeR4zM4XfedSQx CTQqrZIl82NT70Li4afpZTgukFSuHNXoIF/Gkm69DnE9SxV1HiDlSLtkUiHq75Havf BcbmvTXh6byag== Date: Thu, 20 Jun 2024 16:00:13 -0700 Subject: [PATCH 07/24] xfs: implement atime updates in xfs_trans_ichgtime From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418016.3183075.9987831252721662701.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Enable xfs_trans_ichgtime to change the inode access time so that we can use this function to set inode times when allocating inodes instead of open-coding it. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_shared.h | 1 + fs/xfs/libxfs/xfs_trans_inode.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/fs/xfs/libxfs/xfs_shared.h b/fs/xfs/libxfs/xfs_shared.h index 34f104ed372c0..9a705381f9e4a 100644 --- a/fs/xfs/libxfs/xfs_shared.h +++ b/fs/xfs/libxfs/xfs_shared.h @@ -183,6 +183,7 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp, #define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */ #define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */ #define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */ +#define XFS_ICHGTIME_ACCESS 0x8 /* last access timestamp */ /* Computed inode geometry for the filesystem. */ struct xfs_ino_geometry { diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c index 69fc5b981352b..3c40f37e82c73 100644 --- a/fs/xfs/libxfs/xfs_trans_inode.c +++ b/fs/xfs/libxfs/xfs_trans_inode.c @@ -68,6 +68,8 @@ xfs_trans_ichgtime( inode_set_mtime_to_ts(inode, tv); if (flags & XFS_ICHGTIME_CHG) inode_set_ctime_to_ts(inode, tv); + if (flags & XFS_ICHGTIME_ACCESS) + inode_set_atime_to_ts(inode, tv); if (flags & XFS_ICHGTIME_CREATE) ip->i_crtime = tv; } From patchwork Thu Jun 20 23:00:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706478 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 E4A33C8FB for ; Thu, 20 Jun 2024 23:00:29 +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=1718924430; cv=none; b=l5D7y8dZqghmxw/rUXwGkdHSilNzRQe7RrlsXM6E+lM+QRd5ZDO3xBr3RTQVEiXeDUjevYP6qbi34uwg3jvJskgX+ChWmJOf2TJzxrvGqkAYoLTWOTo6KDhBrt+WsU6gIQp9hRUaQI1gPha6VK+eDuaPL3Wva5cQvAMd6TPGj/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924430; c=relaxed/simple; bh=N+DAYZ8RIKcGav+5p76aEYvIvWY84mv+kv4o9V7SAp4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dZcLMnQAMBM2exqwu1A5RplWgjd5wnfCW9YC2nfeLXiwRUueRmnNi1r26tOVZ73zaxz687ItTgiMS6wiJvlB69eVxlhSLSG0OkdkNV6n9eDRYec+Nxxoot+QcIjp8qCF6WOdc9ETYxAjzJ02pNcBD1z/lFdleZIjSCXmvwv514o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dvKvD/Zi; 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="dvKvD/Zi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBF7DC2BD10; Thu, 20 Jun 2024 23:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924429; bh=N+DAYZ8RIKcGav+5p76aEYvIvWY84mv+kv4o9V7SAp4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dvKvD/ZiAZCXwq7bfUyc/tWpMeuPRk8Sn23xiK52kgdPM4fFqSgCudQtydsgdEItm 03bZenAnqgEECZL0CuE3YhhJctFujJDaeXtFlelCx2lYCHeIYRv0bkYg5QxacImdhz scfDDqdEsbPqD8KW765jHNt9GWT8bzkEDdBUj2dtbcOyqsElR39419duUqANGTF/0G i1lfV0MffxlidnP6btlERDhuwXlEl7cJQb1oWfwh2aBy2Oyz4cNflPt1JBzG2uNKZ2 hznOFbcX1hDr7hLE/gmEVJ2//q6bH3cPwjsb8HakdObaXzXpgchM6xreGflnaOJGTd ZQj8IzyE7hpVQ== Date: Thu, 20 Jun 2024 16:00:29 -0700 Subject: [PATCH 08/24] xfs: use xfs_trans_ichgtime to set times when allocating inode From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418033.3183075.12663415998312646212.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Use xfs_trans_ichgtime to set the inode times when allocating an inode, instead of open-coding them here. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_inode.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 4ceefe32b5854..44ce7d8307cb6 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -672,10 +672,11 @@ xfs_icreate( struct inode *dir = pip ? VFS_I(pip) : NULL; struct xfs_mount *mp = tp->t_mountp; struct xfs_inode *ip; - unsigned int flags; - int error; - struct timespec64 tv; struct inode *inode; + unsigned int flags; + int times = XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG | + XFS_ICHGTIME_ACCESS; + int error; /* * Protect against obviously corrupt allocation btree records. Later @@ -743,19 +744,17 @@ xfs_icreate( ip->i_df.if_nextents = 0; ASSERT(ip->i_nblocks == 0); - tv = inode_set_ctime_current(inode); - inode_set_mtime_to_ts(inode, tv); - inode_set_atime_to_ts(inode, tv); - ip->i_extsize = 0; ip->i_diflags = 0; if (xfs_has_v3inodes(mp)) { inode_set_iversion(inode, 1); ip->i_cowextsize = 0; - ip->i_crtime = tv; + times |= XFS_ICHGTIME_CREATE; } + xfs_trans_ichgtime(tp, ip, times); + flags = XFS_ILOG_CORE; switch (args->mode & S_IFMT) { case S_IFIFO: From patchwork Thu Jun 20 23:00:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706479 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 AFC9214D45A for ; Thu, 20 Jun 2024 23:00:45 +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=1718924445; cv=none; b=nanZp8XiZb8wdRpggcrhhCdHdM/HHS5hvoAQ0kXAP3c+0rR6ieWuskiQmroCz/xFZbvgfl0XHM0HF0DfBJFWIS6G2M7YATCgXECO50yCZ+o3y+TqV7+QrKBUo5h/ZyxYk2vppetht0N8tRazRB0lvvZh0QRmOAK33+qJxabPfrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924445; c=relaxed/simple; bh=uD3L/5C+6Q6h/wWU/nJU7cfLtb1eLnJZEQPPm/MdR3A=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HVeiwQ3bdNaFuJ3gkS7zHXafanvKR2mw2uRmLgiKAvebGdWafXlh3yYPXL9wchzSshAVW8/787P4t44P1cBQQY3lRuYv3pkBKRMRM96GYsbfz44USV3B2bpOOHmROhMrDXfMD4/l1oP7zHFxnJbDWc+f4iTfQca9+DJ3Vw0byho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ceoFvZWl; 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="ceoFvZWl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8453DC32781; Thu, 20 Jun 2024 23:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924445; bh=uD3L/5C+6Q6h/wWU/nJU7cfLtb1eLnJZEQPPm/MdR3A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ceoFvZWlWncLz1DCtG6OQWCja6mRZFuafpvDvSqz/TCk680a2Ta18WLOJo1JRJ8oy xVA5Q2qgwlT3LiScyJgZAi5notjfiysr2inkTLPXsTerIJvaCS7q5xuAkGwO4gSrOs 2i6Uj9CdhxZIz+8m1YkaH48I6wp1urhygbnv1nsksD6r6CW5/9np2ZZamP0LMnmfxS Sm7dO/d/WgzfsiSzR7R6tfhe+RBpPah650cAuzQz/9MKKvnectu7PEj8ryBdzeyFBY /nwu43ZAYyo/5wcreXO0z0v27NU1PUZ2IRrZzUh/yqB2DEd5vSy/vARH/ovbMe04bW +ni8gHFxiUaqg== Date: Thu, 20 Jun 2024 16:00:44 -0700 Subject: [PATCH 09/24] xfs: split new inode creation into two pieces From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418050.3183075.11885704254562561755.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong There are two parts to initializing a newly allocated inode: setting up the incore structures, and initializing the new inode core based on the parent inode and the current user's environment. The initialization code is not specific to the kernel, so we would like to share that with userspace by hoisting it to libxfs. Therefore, split xfs_icreate into separate functions to prepare for the next few patches. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_ialloc.c | 15 +++++++++ fs/xfs/xfs_inode.c | 77 ++++++++++++++++++++------------------------ 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 14c81f227c5bb..f8d5ed7aedde8 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -1946,6 +1946,21 @@ xfs_dialloc( } return -ENOSPC; } + + /* + * Protect against obviously corrupt allocation btree records. Later + * xfs_iget checks will catch re-allocation of other active in-memory + * and on-disk inodes. If we don't catch reallocating the parent inode + * here we will deadlock in xfs_iget() so we have to do these checks + * first. + */ + if (ino == parent || !xfs_verify_dir_ino(mp, ino)) { + xfs_alert(mp, "Allocated a known in-use inode 0x%llx!", ino); + xfs_agno_mark_sick(mp, XFS_INO_TO_AGNO(mp, ino), + XFS_SICK_AG_INOBT); + return -EFSCORRUPTED; + } + *new_ino = ino; return 0; } diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 44ce7d8307cb6..dfefc473b0607 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -655,53 +655,20 @@ xfs_inode_inherit_flags2( } } -/* - * Initialise a newly allocated inode and return the in-core inode to the - * caller locked exclusively. - * - * Caller is responsible for unlocking the inode manually upon return - */ -int -xfs_icreate( +/* Initialise an inode's attributes. */ +static void +xfs_inode_init( struct xfs_trans *tp, - xfs_ino_t ino, const struct xfs_icreate_args *args, - struct xfs_inode **ipp) + struct xfs_inode *ip) { struct xfs_inode *pip = args->pip; struct inode *dir = pip ? VFS_I(pip) : NULL; struct xfs_mount *mp = tp->t_mountp; - struct xfs_inode *ip; - struct inode *inode; + struct inode *inode = VFS_I(ip); unsigned int flags; int times = XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG | XFS_ICHGTIME_ACCESS; - int error; - - /* - * Protect against obviously corrupt allocation btree records. Later - * xfs_iget checks will catch re-allocation of other active in-memory - * and on-disk inodes. If we don't catch reallocating the parent inode - * here we will deadlock in xfs_iget() so we have to do these checks - * first. - */ - if ((pip && ino == pip->i_ino) || !xfs_verify_dir_ino(mp, ino)) { - xfs_alert(mp, "Allocated a known in-use inode 0x%llx!", ino); - xfs_agno_mark_sick(mp, XFS_INO_TO_AGNO(mp, ino), - XFS_SICK_AG_INOBT); - return -EFSCORRUPTED; - } - - /* - * Get the in-core inode with the lock held exclusively to prevent - * others from looking at until we're done. - */ - error = xfs_iget(mp, tp, ino, XFS_IGET_CREATE, XFS_ILOCK_EXCL, &ip); - if (error) - return error; - - ASSERT(ip != NULL); - inode = VFS_I(ip); if (args->flags & XFS_ICREATE_TMPFILE) set_nlink(inode, 0); @@ -801,11 +768,37 @@ xfs_icreate( } } - /* - * Log the new values stuffed into the inode. - */ - xfs_trans_ijoin(tp, ip, 0); xfs_trans_log_inode(tp, ip, flags); +} + +/* + * Initialise a newly allocated inode and return the in-core inode to the + * caller locked exclusively. + * + * Caller is responsible for unlocking the inode manually upon return + */ +int +xfs_icreate( + struct xfs_trans *tp, + xfs_ino_t ino, + const struct xfs_icreate_args *args, + struct xfs_inode **ipp) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_inode *ip = NULL; + int error; + + /* + * Get the in-core inode with the lock held exclusively to prevent + * others from looking at until we're done. + */ + error = xfs_iget(mp, tp, ino, XFS_IGET_CREATE, XFS_ILOCK_EXCL, &ip); + if (error) + return error; + + ASSERT(ip != NULL); + xfs_trans_ijoin(tp, ip, 0); + xfs_inode_init(tp, args, ip); /* now that we have an i_mode we can setup the inode structure */ xfs_setup_inode(ip); From patchwork Thu Jun 20 23:01:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706480 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 5619E82D83 for ; Thu, 20 Jun 2024 23:01:01 +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=1718924461; cv=none; b=ANNsPwMtA0D9hPdv/p5KP2WOgTiP8/WI/1FtibJ82izMudeQrlGcxtF7Tgz3+k8/E58UDQH5bv4iwcC/37wWSkfAspWR8oWi0t1Sl6loTB4v85wzY4KDKKMCY85aLnuQbM425k4jYUsTySVhMbwolgRm2SxqFMBCsSmT0l3AZyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924461; c=relaxed/simple; bh=bCKpkRU6GnQqs2J0YR11jvZCTyWdYF5Jva4pp7/ztz0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GR7WVSE4+a5Dqxi778nLwS86FTyZ3ou9w4KZAmJsuirnQ2o4o0gcdRzaKNoWbEO2iP9jMoKsjjTc2WwBpch2vITlcVspvxnoNIPNFaEalh4uILjChj123cCIIERJf0qn2dTZUDWd6ORKG5wVSMqtiNm9HME3Y/gPbPzuS+7ecxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OhfIGoly; 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="OhfIGoly" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22183C2BD10; Thu, 20 Jun 2024 23:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924461; bh=bCKpkRU6GnQqs2J0YR11jvZCTyWdYF5Jva4pp7/ztz0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OhfIGolyvZ7SJ0vtP9Zi8qByhCNHgtiPLPLBu4Rfp6xrhd20bq5ElwXHhNoz/7WXG R7ANw2ZYYonJVuKIdkSYxWJex3oVENFcPvtvbh5MV4sK7OFZbih2MNgRBTugOCxD9H Vovr3OXFIRYmxncB/ox8tp/sJ7ww4AQi54JfzxLUKJT6g4bVv/f+6tgeVPE6ISeRPY j5RJgt3dts3WQ9aHrW4j8eKNeYoc0DKPvMpmI+42rlsxPEIiwxThbHsFI+bpKP5SXB XwjomXm3ylWr9yG/jzr2Iv7Hc+O9K8pf0akO4OQnnAVUlBHbiohhMeU7GNn+VBjLLK Cd34t7SNuoVpw== Date: Thu, 20 Jun 2024 16:01:00 -0700 Subject: [PATCH 10/24] xfs: hoist new inode initialization functions to libxfs From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418067.3183075.14394287548193780451.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move all the code that initializes a new inode's attributes from the icreate_args structure and the parent directory into libxfs. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_inode_util.c | 212 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 12 ++ fs/xfs/libxfs/xfs_shared.h | 8 -- fs/xfs/xfs_inode.c | 209 --------------------------------------- fs/xfs/xfs_trans.h | 1 5 files changed, 225 insertions(+), 217 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index 3b5397a3f34f2..8654cb3d79efb 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -3,6 +3,7 @@ * Copyright (c) 2000-2006 Silicon Graphics, Inc. * All Rights Reserved. */ +#include #include "xfs.h" #include "xfs_fs.h" #include "xfs_shared.h" @@ -13,6 +14,10 @@ #include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_inode_util.h" +#include "xfs_trans.h" +#include "xfs_ialloc.h" +#include "xfs_health.h" +#include "xfs_bmap.h" uint16_t xfs_flags2diflags( @@ -132,3 +137,210 @@ xfs_get_initial_prid(struct xfs_inode *dp) /* Assign to the root project by default. */ return 0; } + +/* Propagate di_flags from a parent inode to a child inode. */ +static inline void +xfs_inode_inherit_flags( + struct xfs_inode *ip, + const struct xfs_inode *pip) +{ + unsigned int di_flags = 0; + xfs_failaddr_t failaddr; + umode_t mode = VFS_I(ip)->i_mode; + + if (S_ISDIR(mode)) { + if (pip->i_diflags & XFS_DIFLAG_RTINHERIT) + di_flags |= XFS_DIFLAG_RTINHERIT; + if (pip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) { + di_flags |= XFS_DIFLAG_EXTSZINHERIT; + ip->i_extsize = pip->i_extsize; + } + if (pip->i_diflags & XFS_DIFLAG_PROJINHERIT) + di_flags |= XFS_DIFLAG_PROJINHERIT; + } else if (S_ISREG(mode)) { + if ((pip->i_diflags & XFS_DIFLAG_RTINHERIT) && + xfs_has_realtime(ip->i_mount)) + di_flags |= XFS_DIFLAG_REALTIME; + if (pip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) { + di_flags |= XFS_DIFLAG_EXTSIZE; + ip->i_extsize = pip->i_extsize; + } + } + if ((pip->i_diflags & XFS_DIFLAG_NOATIME) && + xfs_inherit_noatime) + di_flags |= XFS_DIFLAG_NOATIME; + if ((pip->i_diflags & XFS_DIFLAG_NODUMP) && + xfs_inherit_nodump) + di_flags |= XFS_DIFLAG_NODUMP; + if ((pip->i_diflags & XFS_DIFLAG_SYNC) && + xfs_inherit_sync) + di_flags |= XFS_DIFLAG_SYNC; + if ((pip->i_diflags & XFS_DIFLAG_NOSYMLINKS) && + xfs_inherit_nosymlinks) + di_flags |= XFS_DIFLAG_NOSYMLINKS; + if ((pip->i_diflags & XFS_DIFLAG_NODEFRAG) && + xfs_inherit_nodefrag) + di_flags |= XFS_DIFLAG_NODEFRAG; + if (pip->i_diflags & XFS_DIFLAG_FILESTREAM) + di_flags |= XFS_DIFLAG_FILESTREAM; + + ip->i_diflags |= di_flags; + + /* + * Inode verifiers on older kernels only check that the extent size + * hint is an integer multiple of the rt extent size on realtime files. + * They did not check the hint alignment on a directory with both + * rtinherit and extszinherit flags set. If the misaligned hint is + * propagated from a directory into a new realtime file, new file + * allocations will fail due to math errors in the rt allocator and/or + * trip the verifiers. Validate the hint settings in the new file so + * that we don't let broken hints propagate. + */ + failaddr = xfs_inode_validate_extsize(ip->i_mount, ip->i_extsize, + VFS_I(ip)->i_mode, ip->i_diflags); + if (failaddr) { + ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE | + XFS_DIFLAG_EXTSZINHERIT); + ip->i_extsize = 0; + } +} + +/* Propagate di_flags2 from a parent inode to a child inode. */ +static inline void +xfs_inode_inherit_flags2( + struct xfs_inode *ip, + const struct xfs_inode *pip) +{ + xfs_failaddr_t failaddr; + + if (pip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) { + ip->i_diflags2 |= XFS_DIFLAG2_COWEXTSIZE; + ip->i_cowextsize = pip->i_cowextsize; + } + if (pip->i_diflags2 & XFS_DIFLAG2_DAX) + ip->i_diflags2 |= XFS_DIFLAG2_DAX; + + /* Don't let invalid cowextsize hints propagate. */ + failaddr = xfs_inode_validate_cowextsize(ip->i_mount, ip->i_cowextsize, + VFS_I(ip)->i_mode, ip->i_diflags, ip->i_diflags2); + if (failaddr) { + ip->i_diflags2 &= ~XFS_DIFLAG2_COWEXTSIZE; + ip->i_cowextsize = 0; + } +} + +/* Initialise an inode's attributes. */ +void +xfs_inode_init( + struct xfs_trans *tp, + const struct xfs_icreate_args *args, + struct xfs_inode *ip) +{ + struct xfs_inode *pip = args->pip; + struct inode *dir = pip ? VFS_I(pip) : NULL; + struct xfs_mount *mp = tp->t_mountp; + struct inode *inode = VFS_I(ip); + unsigned int flags; + int times = XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG | + XFS_ICHGTIME_ACCESS; + + if (args->flags & XFS_ICREATE_TMPFILE) + set_nlink(inode, 0); + else if (S_ISDIR(args->mode)) + set_nlink(inode, 2); + else + set_nlink(inode, 1); + inode->i_rdev = args->rdev; + + if (!args->idmap || pip == NULL) { + /* creating a tree root, sb rooted, or detached file */ + inode->i_uid = GLOBAL_ROOT_UID; + inode->i_gid = GLOBAL_ROOT_GID; + ip->i_projid = 0; + inode->i_mode = args->mode; + } else { + /* creating a child in the directory tree */ + if (dir && !(dir->i_mode & S_ISGID) && xfs_has_grpid(mp)) { + inode_fsuid_set(inode, args->idmap); + inode->i_gid = dir->i_gid; + inode->i_mode = args->mode; + } else { + inode_init_owner(args->idmap, inode, dir, args->mode); + } + + /* + * If the group ID of the new file does not match the effective + * group ID or one of the supplementary group IDs, the S_ISGID + * bit is cleared (and only if the irix_sgid_inherit + * compatibility variable is set). + */ + if (irix_sgid_inherit && (inode->i_mode & S_ISGID) && + !vfsgid_in_group_p(i_gid_into_vfsgid(args->idmap, inode))) + inode->i_mode &= ~S_ISGID; + + ip->i_projid = pip ? xfs_get_initial_prid(pip) : 0; + } + + ip->i_disk_size = 0; + ip->i_df.if_nextents = 0; + ASSERT(ip->i_nblocks == 0); + + ip->i_extsize = 0; + ip->i_diflags = 0; + + if (xfs_has_v3inodes(mp)) { + inode_set_iversion(inode, 1); + ip->i_cowextsize = 0; + times |= XFS_ICHGTIME_CREATE; + } + + xfs_trans_ichgtime(tp, ip, times); + + flags = XFS_ILOG_CORE; + switch (args->mode & S_IFMT) { + case S_IFIFO: + case S_IFCHR: + case S_IFBLK: + case S_IFSOCK: + ip->i_df.if_format = XFS_DINODE_FMT_DEV; + flags |= XFS_ILOG_DEV; + break; + case S_IFREG: + case S_IFDIR: + if (pip && (pip->i_diflags & XFS_DIFLAG_ANY)) + xfs_inode_inherit_flags(ip, pip); + if (pip && (pip->i_diflags2 & XFS_DIFLAG2_ANY)) + xfs_inode_inherit_flags2(ip, pip); + fallthrough; + case S_IFLNK: + ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; + ip->i_df.if_bytes = 0; + ip->i_df.if_data = NULL; + break; + default: + ASSERT(0); + } + + /* + * If we need to create attributes immediately after allocating the + * inode, initialise an empty attribute fork right now. We use the + * default fork offset for attributes here as we don't know exactly what + * size or how many attributes we might be adding. We can do this + * safely here because we know the data fork is completely empty and + * this saves us from needing to run a separate transaction to set the + * fork offset in the immediate future. + */ + if (args->flags & XFS_ICREATE_INIT_XATTRS) { + ip->i_forkoff = xfs_default_attroffset(ip) >> 3; + xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); + + if (!xfs_has_attr(mp)) { + spin_lock(&mp->m_sb_lock); + xfs_add_attr(mp); + spin_unlock(&mp->m_sb_lock); + xfs_log_sb(tp); + } + } + + xfs_trans_log_inode(tp, ip, flags); +} diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h index 9226482fdee8c..bf5393db4fde6 100644 --- a/fs/xfs/libxfs/xfs_inode_util.h +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -35,4 +35,16 @@ struct xfs_icreate_args { uint16_t flags; }; +/* + * Flags for xfs_trans_ichgtime(). + */ +#define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */ +#define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */ +#define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */ +#define XFS_ICHGTIME_ACCESS 0x8 /* last access timestamp */ +void xfs_trans_ichgtime(struct xfs_trans *tp, struct xfs_inode *ip, int flags); + +void xfs_inode_init(struct xfs_trans *tp, const struct xfs_icreate_args *args, + struct xfs_inode *ip); + #endif /* __XFS_INODE_UTIL_H__ */ diff --git a/fs/xfs/libxfs/xfs_shared.h b/fs/xfs/libxfs/xfs_shared.h index 9a705381f9e4a..2f7413afbf46c 100644 --- a/fs/xfs/libxfs/xfs_shared.h +++ b/fs/xfs/libxfs/xfs_shared.h @@ -177,14 +177,6 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp, #define XFS_REFC_BTREE_REF 1 #define XFS_SSB_REF 0 -/* - * Flags for xfs_trans_ichgtime(). - */ -#define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */ -#define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */ -#define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */ -#define XFS_ICHGTIME_ACCESS 0x8 /* last access timestamp */ - /* Computed inode geometry for the filesystem. */ struct xfs_ino_geometry { /* Maximum inode count in this filesystem. */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index dfefc473b0607..e8d4ddbfbb925 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -42,7 +42,7 @@ #include "xfs_pnfs.h" #include "xfs_parent.h" #include "xfs_xattr.h" -#include "xfs_sb.h" +#include "xfs_inode_util.h" struct kmem_cache *xfs_inode_cache; @@ -564,213 +564,6 @@ xfs_lookup( return error; } -/* Propagate di_flags from a parent inode to a child inode. */ -static void -xfs_inode_inherit_flags( - struct xfs_inode *ip, - const struct xfs_inode *pip) -{ - unsigned int di_flags = 0; - xfs_failaddr_t failaddr; - umode_t mode = VFS_I(ip)->i_mode; - - if (S_ISDIR(mode)) { - if (pip->i_diflags & XFS_DIFLAG_RTINHERIT) - di_flags |= XFS_DIFLAG_RTINHERIT; - if (pip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) { - di_flags |= XFS_DIFLAG_EXTSZINHERIT; - ip->i_extsize = pip->i_extsize; - } - if (pip->i_diflags & XFS_DIFLAG_PROJINHERIT) - di_flags |= XFS_DIFLAG_PROJINHERIT; - } else if (S_ISREG(mode)) { - if ((pip->i_diflags & XFS_DIFLAG_RTINHERIT) && - xfs_has_realtime(ip->i_mount)) - di_flags |= XFS_DIFLAG_REALTIME; - if (pip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) { - di_flags |= XFS_DIFLAG_EXTSIZE; - ip->i_extsize = pip->i_extsize; - } - } - if ((pip->i_diflags & XFS_DIFLAG_NOATIME) && - xfs_inherit_noatime) - di_flags |= XFS_DIFLAG_NOATIME; - if ((pip->i_diflags & XFS_DIFLAG_NODUMP) && - xfs_inherit_nodump) - di_flags |= XFS_DIFLAG_NODUMP; - if ((pip->i_diflags & XFS_DIFLAG_SYNC) && - xfs_inherit_sync) - di_flags |= XFS_DIFLAG_SYNC; - if ((pip->i_diflags & XFS_DIFLAG_NOSYMLINKS) && - xfs_inherit_nosymlinks) - di_flags |= XFS_DIFLAG_NOSYMLINKS; - if ((pip->i_diflags & XFS_DIFLAG_NODEFRAG) && - xfs_inherit_nodefrag) - di_flags |= XFS_DIFLAG_NODEFRAG; - if (pip->i_diflags & XFS_DIFLAG_FILESTREAM) - di_flags |= XFS_DIFLAG_FILESTREAM; - - ip->i_diflags |= di_flags; - - /* - * Inode verifiers on older kernels only check that the extent size - * hint is an integer multiple of the rt extent size on realtime files. - * They did not check the hint alignment on a directory with both - * rtinherit and extszinherit flags set. If the misaligned hint is - * propagated from a directory into a new realtime file, new file - * allocations will fail due to math errors in the rt allocator and/or - * trip the verifiers. Validate the hint settings in the new file so - * that we don't let broken hints propagate. - */ - failaddr = xfs_inode_validate_extsize(ip->i_mount, ip->i_extsize, - VFS_I(ip)->i_mode, ip->i_diflags); - if (failaddr) { - ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE | - XFS_DIFLAG_EXTSZINHERIT); - ip->i_extsize = 0; - } -} - -/* Propagate di_flags2 from a parent inode to a child inode. */ -static void -xfs_inode_inherit_flags2( - struct xfs_inode *ip, - const struct xfs_inode *pip) -{ - xfs_failaddr_t failaddr; - - if (pip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) { - ip->i_diflags2 |= XFS_DIFLAG2_COWEXTSIZE; - ip->i_cowextsize = pip->i_cowextsize; - } - if (pip->i_diflags2 & XFS_DIFLAG2_DAX) - ip->i_diflags2 |= XFS_DIFLAG2_DAX; - - /* Don't let invalid cowextsize hints propagate. */ - failaddr = xfs_inode_validate_cowextsize(ip->i_mount, ip->i_cowextsize, - VFS_I(ip)->i_mode, ip->i_diflags, ip->i_diflags2); - if (failaddr) { - ip->i_diflags2 &= ~XFS_DIFLAG2_COWEXTSIZE; - ip->i_cowextsize = 0; - } -} - -/* Initialise an inode's attributes. */ -static void -xfs_inode_init( - struct xfs_trans *tp, - const struct xfs_icreate_args *args, - struct xfs_inode *ip) -{ - struct xfs_inode *pip = args->pip; - struct inode *dir = pip ? VFS_I(pip) : NULL; - struct xfs_mount *mp = tp->t_mountp; - struct inode *inode = VFS_I(ip); - unsigned int flags; - int times = XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG | - XFS_ICHGTIME_ACCESS; - - if (args->flags & XFS_ICREATE_TMPFILE) - set_nlink(inode, 0); - else if (S_ISDIR(args->mode)) - set_nlink(inode, 2); - else - set_nlink(inode, 1); - inode->i_rdev = args->rdev; - - if (!args->idmap || pip == NULL) { - /* creating a tree root, sb rooted, or detached file */ - inode->i_uid = GLOBAL_ROOT_UID; - inode->i_gid = GLOBAL_ROOT_GID; - ip->i_projid = 0; - inode->i_mode = args->mode; - } else { - /* creating a child in the directory tree */ - if (dir && !(dir->i_mode & S_ISGID) && xfs_has_grpid(mp)) { - inode_fsuid_set(inode, args->idmap); - inode->i_gid = dir->i_gid; - inode->i_mode = args->mode; - } else { - inode_init_owner(args->idmap, inode, dir, args->mode); - } - - /* - * If the group ID of the new file does not match the effective - * group ID or one of the supplementary group IDs, the S_ISGID - * bit is cleared (and only if the irix_sgid_inherit - * compatibility variable is set). - */ - if (irix_sgid_inherit && (inode->i_mode & S_ISGID) && - !vfsgid_in_group_p(i_gid_into_vfsgid(args->idmap, inode))) - inode->i_mode &= ~S_ISGID; - - ip->i_projid = pip ? xfs_get_initial_prid(pip) : 0; - } - - ip->i_disk_size = 0; - ip->i_df.if_nextents = 0; - ASSERT(ip->i_nblocks == 0); - - ip->i_extsize = 0; - ip->i_diflags = 0; - - if (xfs_has_v3inodes(mp)) { - inode_set_iversion(inode, 1); - ip->i_cowextsize = 0; - times |= XFS_ICHGTIME_CREATE; - } - - xfs_trans_ichgtime(tp, ip, times); - - flags = XFS_ILOG_CORE; - switch (args->mode & S_IFMT) { - case S_IFIFO: - case S_IFCHR: - case S_IFBLK: - case S_IFSOCK: - ip->i_df.if_format = XFS_DINODE_FMT_DEV; - flags |= XFS_ILOG_DEV; - break; - case S_IFREG: - case S_IFDIR: - if (pip && (pip->i_diflags & XFS_DIFLAG_ANY)) - xfs_inode_inherit_flags(ip, pip); - if (pip && (pip->i_diflags2 & XFS_DIFLAG2_ANY)) - xfs_inode_inherit_flags2(ip, pip); - fallthrough; - case S_IFLNK: - ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; - ip->i_df.if_bytes = 0; - ip->i_df.if_data = NULL; - break; - default: - ASSERT(0); - } - - /* - * If we need to create attributes immediately after allocating the - * inode, initialise an empty attribute fork right now. We use the - * default fork offset for attributes here as we don't know exactly what - * size or how many attributes we might be adding. We can do this - * safely here because we know the data fork is completely empty and - * this saves us from needing to run a separate transaction to set the - * fork offset in the immediate future. - */ - if (args->flags & XFS_ICREATE_INIT_XATTRS) { - ip->i_forkoff = xfs_default_attroffset(ip) >> 3; - xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); - - if (!xfs_has_attr(mp)) { - spin_lock(&mp->m_sb_lock); - xfs_add_attr(mp); - spin_unlock(&mp->m_sb_lock); - xfs_log_sb(tp); - } - } - - xfs_trans_log_inode(tp, ip, flags); -} - /* * Initialise a newly allocated inode and return the in-core inode to the * caller locked exclusively. diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h index 1636663707dc0..f97e8c68641f0 100644 --- a/fs/xfs/xfs_trans.h +++ b/fs/xfs/xfs_trans.h @@ -224,7 +224,6 @@ void xfs_trans_stale_inode_buf(xfs_trans_t *, struct xfs_buf *); bool xfs_trans_ordered_buf(xfs_trans_t *, struct xfs_buf *); void xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint); void xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *); -void xfs_trans_ichgtime(struct xfs_trans *, struct xfs_inode *, int); void xfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *, uint); void xfs_trans_log_buf(struct xfs_trans *, struct xfs_buf *, uint, uint); From patchwork Thu Jun 20 23:01:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706481 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 EB6631494B9 for ; Thu, 20 Jun 2024 23:01:16 +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=1718924477; cv=none; b=d8v37Micw0XkQXPMnhBMK3kmwqtPtElAA5ETEiJFhOGYGetCFiXVTSj2Z1TqYiwtLZZQrRCisXyBMRJOKrGQM/Y8kIy0T5WO3sA/zXzUCx4fXEULL6kgQsOl+2Kq8/Tj7lbuDjzYhaEYNp75S4LuwfchzEhtooNaE2DwHS5X/+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924477; c=relaxed/simple; bh=zuXFRQE/KdRiQ2SpDZDGE/pEaGGqaVrHySmLCJcTrOE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dtO6nFZfeEMrODNm3y6Fbafr9ZrPLga8tLBwjhSI6h5akhez+rVY06dG0ZZFNYYYQAMGgy7LnpnpQOs9mHyGdv0XlfV8Dz7A2UIm2iCvVkyd3YxrgWWPz1bOS/YjhfEDBZaT+eqiO5vNo9GpqGWWZFGZC4GKpM4z8JmvNmrX42M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sfZhYzj4; 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="sfZhYzj4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C10C8C2BD10; Thu, 20 Jun 2024 23:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924476; bh=zuXFRQE/KdRiQ2SpDZDGE/pEaGGqaVrHySmLCJcTrOE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=sfZhYzj46nnd8c64cuQ1MkeSu7aZtetLGhxKnwMVwocigpWTx6FVhuujBP9qRN4IR QDGKD1ClJsrDBl/4zTbAKd/bQRfgpR3U1iIKVQXLfGduPSTAQDLm1+oQ0nLrybz2N0 xW/nsszum3tmHXx+OSOYiU5Rs7NPNUFXX8EbrgvKrNGSJHB3ptFd1EcHRVVo04e/Cc AYGcjoG4CV4kOqslzUlWruyfUw5d6F1GSqPIxa5gMZUiCQS+qkD6XJ9pXvhfKU0f6G 5B5nYl01GsZiHpTEi9iEvIbzU8dqFfFDjmdkHfC1AEyToMvfYgqwnUpi7LoS7/tVji LbFZQmXCbEA5A== Date: Thu, 20 Jun 2024 16:01:16 -0700 Subject: [PATCH 11/24] xfs: push xfs_icreate_args creation out of xfs_create* From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418085.3183075.6634714056147736408.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move the initialization of the xfs_icreate_args structure out of xfs_create and xfs_create_tempfile into their callers so that we can set the new inode's attributes in one place and pass that through instead of open coding the collection of attributes all over the code. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_inode.c | 86 ++++++++++++++++++++++++---------------------------- fs/xfs/xfs_inode.h | 9 ++--- fs/xfs/xfs_iops.c | 41 +++++++++++++++---------- 3 files changed, 66 insertions(+), 70 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index e8d4ddbfbb925..d026e377fcafa 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -730,35 +730,25 @@ xfs_dir_hook_setup( int xfs_create( - struct mnt_idmap *idmap, - struct xfs_inode *dp, + const struct xfs_icreate_args *args, struct xfs_name *name, - umode_t mode, - dev_t rdev, - bool init_xattrs, - xfs_inode_t **ipp) + struct xfs_inode **ipp) { - struct xfs_icreate_args args = { - .idmap = idmap, - .pip = dp, - .rdev = rdev, - .mode = mode, - .flags = init_xattrs ? XFS_ICREATE_INIT_XATTRS : 0, - }; - int is_dir = S_ISDIR(mode); + struct xfs_inode *dp = args->pip; struct xfs_mount *mp = dp->i_mount; struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; - int error; + struct xfs_dquot *udqp = NULL; + struct xfs_dquot *gdqp = NULL; + struct xfs_dquot *pdqp = NULL; + struct xfs_trans_res *tres; + struct xfs_parent_args *ppargs; + xfs_ino_t ino; + prid_t prid; bool unlock_dp_on_error = false; - prid_t prid; - struct xfs_dquot *udqp = NULL; - struct xfs_dquot *gdqp = NULL; - struct xfs_dquot *pdqp = NULL; - struct xfs_trans_res *tres; + bool is_dir = S_ISDIR(args->mode); uint resblks; - xfs_ino_t ino; - struct xfs_parent_args *ppargs; + int error; trace_xfs_create(dp, name); @@ -774,8 +764,9 @@ xfs_create( * computation code must match what the VFS uses to assign i_[ug]id. * INHERIT adjusts the gid computation for setgid/grpid systems. */ - error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), - mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, + error = xfs_qm_vop_dqalloc(dp, + mapped_fsuid(args->idmap, i_user_ns(VFS_I(dp))), + mapped_fsgid(args->idmap, i_user_ns(VFS_I(dp))), prid, XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp, &pdqp); if (error) @@ -818,9 +809,9 @@ xfs_create( * entry pointing to them, but a directory also the "." entry * pointing to itself. */ - error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); + error = xfs_dialloc(&tp, dp->i_ino, args->mode, &ino); if (!error) - error = xfs_icreate(tp, ino, &args, &ip); + error = xfs_icreate(tp, ino, args, &ip); if (error) goto out_trans_cancel; @@ -922,44 +913,37 @@ xfs_create( int xfs_create_tmpfile( - struct mnt_idmap *idmap, - struct xfs_inode *dp, - umode_t mode, - bool init_xattrs, + const struct xfs_icreate_args *args, struct xfs_inode **ipp) { - struct xfs_icreate_args args = { - .idmap = idmap, - .pip = dp, - .mode = mode, - .flags = XFS_ICREATE_TMPFILE, - }; + struct xfs_inode *dp = args->pip; struct xfs_mount *mp = dp->i_mount; struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; - int error; - prid_t prid; struct xfs_dquot *udqp = NULL; struct xfs_dquot *gdqp = NULL; struct xfs_dquot *pdqp = NULL; struct xfs_trans_res *tres; - uint resblks; xfs_ino_t ino; + prid_t prid; + uint resblks; + int error; + + ASSERT(args->flags & XFS_ICREATE_TMPFILE); if (xfs_is_shutdown(mp)) return -EIO; prid = xfs_get_initial_prid(dp); - if (init_xattrs) - args.flags |= XFS_ICREATE_INIT_XATTRS; /* * Make sure that we have allocated dquot(s) on disk. The uid/gid * computation code must match what the VFS uses to assign i_[ug]id. * INHERIT adjusts the gid computation for setgid/grpid systems. */ - error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), - mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, + error = xfs_qm_vop_dqalloc(dp, + mapped_fsuid(args->idmap, i_user_ns(VFS_I(dp))), + mapped_fsgid(args->idmap, i_user_ns(VFS_I(dp))), prid, XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp, &pdqp); if (error) @@ -973,9 +957,9 @@ xfs_create_tmpfile( if (error) goto out_release_dquots; - error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); + error = xfs_dialloc(&tp, dp->i_ino, args->mode, &ino); if (!error) - error = xfs_icreate(tp, ino, &args, &ip); + error = xfs_icreate(tp, ino, args, &ip); if (error) goto out_trans_cancel; @@ -2839,12 +2823,20 @@ xfs_rename_alloc_whiteout( struct xfs_inode *dp, struct xfs_inode **wip) { + struct xfs_icreate_args args = { + .idmap = idmap, + .pip = dp, + .mode = S_IFCHR | WHITEOUT_MODE, + .flags = XFS_ICREATE_TMPFILE, + }; struct xfs_inode *tmpfile; struct qstr name; int error; - error = xfs_create_tmpfile(idmap, dp, S_IFCHR | WHITEOUT_MODE, - xfs_has_parent(dp->i_mount), &tmpfile); + if (xfs_has_parent(dp->i_mount)) + args.flags |= XFS_ICREATE_INIT_XATTRS; + + error = xfs_create_tmpfile(&args, &tmpfile); if (error) return error; diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 7d3fea66e069e..bc48e81829b5a 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -516,12 +516,9 @@ int xfs_release(struct xfs_inode *ip); int xfs_inactive(struct xfs_inode *ip); int xfs_lookup(struct xfs_inode *dp, const struct xfs_name *name, struct xfs_inode **ipp, struct xfs_name *ci_name); -int xfs_create(struct mnt_idmap *idmap, - struct xfs_inode *dp, struct xfs_name *name, - umode_t mode, dev_t rdev, bool need_xattr, - struct xfs_inode **ipp); -int xfs_create_tmpfile(struct mnt_idmap *idmap, - struct xfs_inode *dp, umode_t mode, bool init_xattrs, +int xfs_create(const struct xfs_icreate_args *iargs, + struct xfs_name *name, struct xfs_inode **ipp); +int xfs_create_tmpfile(const struct xfs_icreate_args *iargs, struct xfs_inode **ipp); int xfs_remove(struct xfs_inode *dp, struct xfs_name *name, struct xfs_inode *ip); diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 35a84790d26e6..4563ba440570b 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -173,38 +173,46 @@ xfs_generic_create( dev_t rdev, struct file *tmpfile) /* unnamed file */ { - struct inode *inode; - struct xfs_inode *ip = NULL; - struct posix_acl *default_acl, *acl; - struct xfs_name name; - int error; + struct xfs_icreate_args args = { + .idmap = idmap, + .pip = XFS_I(dir), + .rdev = rdev, + .mode = mode, + }; + struct inode *inode; + struct xfs_inode *ip = NULL; + struct posix_acl *default_acl, *acl; + struct xfs_name name; + int error; /* * Irix uses Missed'em'V split, but doesn't want to see * the upper 5 bits of (14bit) major. */ - if (S_ISCHR(mode) || S_ISBLK(mode)) { - if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)) + if (S_ISCHR(args.mode) || S_ISBLK(args.mode)) { + if (unlikely(!sysv_valid_dev(args.rdev) || + MAJOR(args.rdev) & ~0x1ff)) return -EINVAL; } else { - rdev = 0; + args.rdev = 0; } - error = posix_acl_create(dir, &mode, &default_acl, &acl); + error = posix_acl_create(dir, &args.mode, &default_acl, &acl); if (error) return error; /* Verify mode is valid also for tmpfile case */ - error = xfs_dentry_mode_to_name(&name, dentry, mode); + error = xfs_dentry_mode_to_name(&name, dentry, args.mode); if (unlikely(error)) goto out_free_acl; if (!tmpfile) { - error = xfs_create(idmap, XFS_I(dir), &name, mode, rdev, - xfs_create_need_xattr(dir, default_acl, acl), - &ip); + if (xfs_create_need_xattr(dir, default_acl, acl)) + args.flags |= XFS_ICREATE_INIT_XATTRS; + + error = xfs_create(&args, &name, &ip); } else { - bool init_xattrs = false; + args.flags |= XFS_ICREATE_TMPFILE; /* * If this temporary file will be linkable, set up the file @@ -212,10 +220,9 @@ xfs_generic_create( */ if (!(tmpfile->f_flags & O_EXCL) && xfs_has_parent(XFS_I(dir)->i_mount)) - init_xattrs = true; + args.flags |= XFS_ICREATE_INIT_XATTRS; - error = xfs_create_tmpfile(idmap, XFS_I(dir), mode, - init_xattrs, &ip); + error = xfs_create_tmpfile(&args, &ip); } if (unlikely(error)) goto out_free_acl; From patchwork Thu Jun 20 23:01:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706482 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 9BBC2C8FB for ; Thu, 20 Jun 2024 23:01: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=1718924492; cv=none; b=TE6XUjwTMXDpR0siI4APFdM38Y+sdpXTpYib1q5V+ccnI9K+x4SYA4+rFjx8MKFxgJ9DRkfRlu9viwDUgdOaKoM8y8pl3i+bT+R7294OM5bmkEEoAnxqFg/HSMj/KekQosDqNBBi9AShBbHn2mgjvOK4oDyEUl7stDY2Rf5VK5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924492; c=relaxed/simple; bh=T6aaSSnnBFWBsxF82yfPMTtNsqkivfUqPVXFYKZ54Ns=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CUJJj8BJovEHHoX4mI3ynNUF+o9zErzQerW7FJyTmG2u3njeW24C4CbKxRaFor9HrXiYhWRbNJh9nCAcArN9siQRpCABy/etstLdRFzg5KtvmhSLufbsId3Ewp0hic15ajkRm/zlxol49ET58jgoDj4o7UaGh28nYw3VVB1e/Wg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fabK/nnv; 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="fabK/nnv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 665C8C2BD10; Thu, 20 Jun 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924492; bh=T6aaSSnnBFWBsxF82yfPMTtNsqkivfUqPVXFYKZ54Ns=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fabK/nnvsxzsJlVuxEO93PJTLOIYR3nA2y/uMW9NkteVqUKerkzGl6b56FdukrjVm 5HszZEjkSSRTtZ6L5I50eDxk/JXb7DjaBJkp9FPydZnS506IuVNauQwy18FPCR1v0K slij/CCodelmyeO/Jgo4rfctGPi3o5zoxm1jfe7ODxFGtyz1YXZCgHotb9oojXdPvw +3ldcaNgHd2+Uk8a711uEmxLr/LPPnLKB7UqFMGUeGBSJDIjGhcBGdslVRZhw8npn9 C+u4Z3Mqjpf20kV19MlalTPPD9pWrBzo82sU1Ws3WDWOb4iaph2F1WvYqNOew98/fh sWz6LQ/+pFGDg== Date: Thu, 20 Jun 2024 16:01:31 -0700 Subject: [PATCH 12/24] xfs: wrap inode creation dqalloc calls From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418102.3183075.3384829090907441660.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a helper that calls dqalloc to allocate and grab a reference to dquots for the user, group, and project ids listed in an icreate structure. This simplifies the creat-related dqalloc callsites scattered around the code base. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/tempfile.c | 9 +++--- fs/xfs/xfs_inode.c | 74 +++++++++++++++++++++++++++-------------------- fs/xfs/xfs_inode.h | 4 +++ fs/xfs/xfs_symlink.c | 20 +++---------- 4 files changed, 55 insertions(+), 52 deletions(-) diff --git a/fs/xfs/scrub/tempfile.c b/fs/xfs/scrub/tempfile.c index ee6f93e9f7cba..523971a15a72a 100644 --- a/fs/xfs/scrub/tempfile.c +++ b/fs/xfs/scrub/tempfile.c @@ -47,9 +47,9 @@ xrep_tempfile_create( }; struct xfs_mount *mp = sc->mp; struct xfs_trans *tp = NULL; - struct xfs_dquot *udqp = NULL; - struct xfs_dquot *gdqp = NULL; - struct xfs_dquot *pdqp = NULL; + struct xfs_dquot *udqp; + struct xfs_dquot *gdqp; + struct xfs_dquot *pdqp; struct xfs_trans_res *tres; struct xfs_inode *dp = mp->m_rootip; xfs_ino_t ino; @@ -70,8 +70,7 @@ xrep_tempfile_create( * inode should be completely root owned so that we don't fail due to * quota limits. */ - error = xfs_qm_vop_dqalloc(dp, GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, 0, - XFS_QMOPT_QUOTALL, &udqp, &gdqp, &pdqp); + error = xfs_icreate_dqalloc(&args, &udqp, &gdqp, &pdqp); if (error) return error; diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index d026e377fcafa..1d7febda38c16 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -728,6 +728,38 @@ xfs_dir_hook_setup( } #endif /* CONFIG_XFS_LIVE_HOOKS */ +/* Return dquots for the ids that will be assigned to a new file. */ +int +xfs_icreate_dqalloc( + const struct xfs_icreate_args *args, + struct xfs_dquot **udqpp, + struct xfs_dquot **gdqpp, + struct xfs_dquot **pdqpp) +{ + struct inode *dir = VFS_I(args->pip); + kuid_t uid = GLOBAL_ROOT_UID; + kgid_t gid = GLOBAL_ROOT_GID; + prid_t prid = 0; + unsigned int flags = XFS_QMOPT_QUOTALL; + + if (args->idmap) { + /* + * The uid/gid computation code must match what the VFS uses to + * assign i_[ug]id. INHERIT adjusts the gid computation for + * setgid/grpid systems. + */ + uid = mapped_fsuid(args->idmap, i_user_ns(dir)); + gid = mapped_fsgid(args->idmap, i_user_ns(dir)); + prid = xfs_get_initial_prid(args->pip); + flags |= XFS_QMOPT_INHERIT; + } + + *udqpp = *gdqpp = *pdqpp = NULL; + + return xfs_qm_vop_dqalloc(args->pip, uid, gid, prid, flags, udqpp, + gdqpp, pdqpp); +} + int xfs_create( const struct xfs_icreate_args *args, @@ -738,13 +770,12 @@ xfs_create( struct xfs_mount *mp = dp->i_mount; struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; - struct xfs_dquot *udqp = NULL; - struct xfs_dquot *gdqp = NULL; - struct xfs_dquot *pdqp = NULL; + struct xfs_dquot *udqp; + struct xfs_dquot *gdqp; + struct xfs_dquot *pdqp; struct xfs_trans_res *tres; struct xfs_parent_args *ppargs; xfs_ino_t ino; - prid_t prid; bool unlock_dp_on_error = false; bool is_dir = S_ISDIR(args->mode); uint resblks; @@ -757,18 +788,8 @@ xfs_create( if (xfs_ifork_zapped(dp, XFS_DATA_FORK)) return -EIO; - prid = xfs_get_initial_prid(dp); - - /* - * Make sure that we have allocated dquot(s) on disk. The uid/gid - * computation code must match what the VFS uses to assign i_[ug]id. - * INHERIT adjusts the gid computation for setgid/grpid systems. - */ - error = xfs_qm_vop_dqalloc(dp, - mapped_fsuid(args->idmap, i_user_ns(VFS_I(dp))), - mapped_fsgid(args->idmap, i_user_ns(VFS_I(dp))), prid, - XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, - &udqp, &gdqp, &pdqp); + /* Make sure that we have allocated dquot(s) on disk. */ + error = xfs_icreate_dqalloc(args, &udqp, &gdqp, &pdqp); if (error) return error; @@ -920,12 +941,11 @@ xfs_create_tmpfile( struct xfs_mount *mp = dp->i_mount; struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; - struct xfs_dquot *udqp = NULL; - struct xfs_dquot *gdqp = NULL; - struct xfs_dquot *pdqp = NULL; + struct xfs_dquot *udqp; + struct xfs_dquot *gdqp; + struct xfs_dquot *pdqp; struct xfs_trans_res *tres; xfs_ino_t ino; - prid_t prid; uint resblks; int error; @@ -934,18 +954,8 @@ xfs_create_tmpfile( if (xfs_is_shutdown(mp)) return -EIO; - prid = xfs_get_initial_prid(dp); - - /* - * Make sure that we have allocated dquot(s) on disk. The uid/gid - * computation code must match what the VFS uses to assign i_[ug]id. - * INHERIT adjusts the gid computation for setgid/grpid systems. - */ - error = xfs_qm_vop_dqalloc(dp, - mapped_fsuid(args->idmap, i_user_ns(VFS_I(dp))), - mapped_fsgid(args->idmap, i_user_ns(VFS_I(dp))), prid, - XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, - &udqp, &gdqp, &pdqp); + /* Make sure that we have allocated dquot(s) on disk. */ + error = xfs_icreate_dqalloc(args, &udqp, &gdqp, &pdqp); if (error) return error; diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index bc48e81829b5a..a905929494bd5 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -660,4 +660,8 @@ void xfs_dir_hook_setup(struct xfs_dir_hook *hook, notifier_fn_t mod_fn); # define xfs_dir_update_hook(dp, ip, delta, name) ((void)0) #endif /* CONFIG_XFS_LIVE_HOOKS */ +int xfs_icreate_dqalloc(const struct xfs_icreate_args *args, + struct xfs_dquot **udqpp, struct xfs_dquot **gdqpp, + struct xfs_dquot **pdqpp); + #endif /* __XFS_INODE_H__ */ diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 3b797a39950d5..6ff736e5c4e7f 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -101,10 +101,9 @@ xfs_symlink( int pathlen; bool unlock_dp_on_error = false; xfs_filblks_t fs_blocks; - prid_t prid; - struct xfs_dquot *udqp = NULL; - struct xfs_dquot *gdqp = NULL; - struct xfs_dquot *pdqp = NULL; + struct xfs_dquot *udqp; + struct xfs_dquot *gdqp; + struct xfs_dquot *pdqp; uint resblks; xfs_ino_t ino; struct xfs_parent_args *ppargs; @@ -127,17 +126,8 @@ xfs_symlink( return -ENAMETOOLONG; ASSERT(pathlen > 0); - prid = xfs_get_initial_prid(dp); - - /* - * Make sure that we have allocated dquot(s) on disk. The uid/gid - * computation code must match what the VFS uses to assign i_[ug]id. - * INHERIT adjusts the gid computation for setgid/grpid systems. - */ - error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), - mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, - XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, - &udqp, &gdqp, &pdqp); + /* Make sure that we have allocated dquot(s) on disk. */ + error = xfs_icreate_dqalloc(&args, &udqp, &gdqp, &pdqp); if (error) return error; From patchwork Thu Jun 20 23:01:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706483 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 43292C8FB for ; Thu, 20 Jun 2024 23:01:48 +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=1718924508; cv=none; b=W9UEdY/k8oYYKuieL6Tf/FlAtMHwCPCGFNCspPhJZ5v4DeTuSQdSXw97i4f6i5mrBn7+Wcq/HPX+YKHw8TpDUYP3iUzmnAdL93m9B3UdAsxVaI+pH6lWvy65W1OpGZ28TW8tTzNfvWoed5JTpjxoz6h5fVzGlnQKzIEz2gTh3EI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924508; c=relaxed/simple; bh=g5ExS2BhJ2B8S7ugaz84F/nUX44UwyTk/cThEPRlJgk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R4+uJ73vUbccnNr6LyGQeRlnA8W5SQ00xZlNqNTN6hGiIlch6vm4UCJ9ekpQ/TassPkG3CjBx2c8C8V0uNCn+pZ9jaiN5JTA4I14jwWOgL8ev/O76TBHB9BB1VJZjbLWNIJCsR7o/57EOjP9lzKbuq6VXJw1/lLX+phB646rzpk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ai7y9kc/; 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="ai7y9kc/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10525C32781; Thu, 20 Jun 2024 23:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924508; bh=g5ExS2BhJ2B8S7ugaz84F/nUX44UwyTk/cThEPRlJgk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ai7y9kc/7uF9w6h5a9JZtbdJjwNgRlUvt74A5ZayhVLWZwLuNIW0rGaa82TLrLnAK GCPI2XLl1b1gqnudJr/c2gI1342Rokns3onaCQAuwwuOe6yay824hDEa+mI84LWx8U QqERbGAuoSvvyIix4amoCB3+4Jw80vqDRjR/SlMBoUCUrM6hZT+Xf54t8DxgaHipY0 iwisiaiqNeqfjRrgxf+bCyMGh6X0LpzUs3lOYDUTliM2xeSNe/s7ltC7KS6ehrKFKG s9l3Po0PgYZEbapAh9E9b7TbNsDDGNrPUBfk47OD39tcr5FOcvBWODQfmgEIUqH28t sMz4Aer8IyxQg== Date: Thu, 20 Jun 2024 16:01:47 -0700 Subject: [PATCH 13/24] xfs: hoist xfs_iunlink to libxfs From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418120.3183075.7790758345120309903.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move xfs_iunlink and xfs_iunlink_remove to libxfs. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_inode_util.c | 282 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 4 + fs/xfs/xfs_inode.c | 280 ---------------------------------------- fs/xfs/xfs_inode.h | 5 - 4 files changed, 289 insertions(+), 282 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index 8654cb3d79efb..5739871ac3705 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -18,6 +18,10 @@ #include "xfs_ialloc.h" #include "xfs_health.h" #include "xfs_bmap.h" +#include "xfs_error.h" +#include "xfs_trace.h" +#include "xfs_ag.h" +#include "xfs_iunlink_item.h" uint16_t xfs_flags2diflags( @@ -344,3 +348,281 @@ xfs_inode_init( xfs_trans_log_inode(tp, ip, flags); } + +/* + * In-Core Unlinked List Lookups + * ============================= + * + * Every inode is supposed to be reachable from some other piece of metadata + * with the exception of the root directory. Inodes with a connection to a + * file descriptor but not linked from anywhere in the on-disk directory tree + * are collectively known as unlinked inodes, though the filesystem itself + * maintains links to these inodes so that on-disk metadata are consistent. + * + * XFS implements a per-AG on-disk hash table of unlinked inodes. The AGI + * header contains a number of buckets that point to an inode, and each inode + * record has a pointer to the next inode in the hash chain. This + * singly-linked list causes scaling problems in the iunlink remove function + * because we must walk that list to find the inode that points to the inode + * being removed from the unlinked hash bucket list. + * + * Hence we keep an in-memory double linked list to link each inode on an + * unlinked list. Because there are 64 unlinked lists per AGI, keeping pointer + * based lists would require having 64 list heads in the perag, one for each + * list. This is expensive in terms of memory (think millions of AGs) and cache + * misses on lookups. Instead, use the fact that inodes on the unlinked list + * must be referenced at the VFS level to keep them on the list and hence we + * have an existence guarantee for inodes on the unlinked list. + * + * Given we have an existence guarantee, we can use lockless inode cache lookups + * to resolve aginos to xfs inodes. This means we only need 8 bytes per inode + * for the double linked unlinked list, and we don't need any extra locking to + * keep the list safe as all manipulations are done under the AGI buffer lock. + * Keeping the list up to date does not require memory allocation, just finding + * the XFS inode and updating the next/prev unlinked list aginos. + */ + +/* + * Update the prev pointer of the next agino. Returns -ENOLINK if the inode + * is not in cache. + */ +static int +xfs_iunlink_update_backref( + struct xfs_perag *pag, + xfs_agino_t prev_agino, + xfs_agino_t next_agino) +{ + struct xfs_inode *ip; + + /* No update necessary if we are at the end of the list. */ + if (next_agino == NULLAGINO) + return 0; + + ip = xfs_iunlink_lookup(pag, next_agino); + if (!ip) + return -ENOLINK; + + ip->i_prev_unlinked = prev_agino; + return 0; +} + +/* + * Point the AGI unlinked bucket at an inode and log the results. The caller + * is responsible for validating the old value. + */ +STATIC int +xfs_iunlink_update_bucket( + struct xfs_trans *tp, + struct xfs_perag *pag, + struct xfs_buf *agibp, + unsigned int bucket_index, + xfs_agino_t new_agino) +{ + struct xfs_agi *agi = agibp->b_addr; + xfs_agino_t old_value; + int offset; + + ASSERT(xfs_verify_agino_or_null(pag, new_agino)); + + old_value = be32_to_cpu(agi->agi_unlinked[bucket_index]); + trace_xfs_iunlink_update_bucket(tp->t_mountp, pag->pag_agno, bucket_index, + old_value, new_agino); + + /* + * We should never find the head of the list already set to the value + * passed in because either we're adding or removing ourselves from the + * head of the list. + */ + if (old_value == new_agino) { + xfs_buf_mark_corrupt(agibp); + xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); + return -EFSCORRUPTED; + } + + agi->agi_unlinked[bucket_index] = cpu_to_be32(new_agino); + offset = offsetof(struct xfs_agi, agi_unlinked) + + (sizeof(xfs_agino_t) * bucket_index); + xfs_trans_log_buf(tp, agibp, offset, offset + sizeof(xfs_agino_t) - 1); + return 0; +} + +static int +xfs_iunlink_insert_inode( + struct xfs_trans *tp, + struct xfs_perag *pag, + struct xfs_buf *agibp, + struct xfs_inode *ip) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_agi *agi = agibp->b_addr; + xfs_agino_t next_agino; + xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ip->i_ino); + short bucket_index = agino % XFS_AGI_UNLINKED_BUCKETS; + int error; + + /* + * Get the index into the agi hash table for the list this inode will + * go on. Make sure the pointer isn't garbage and that this inode + * isn't already on the list. + */ + next_agino = be32_to_cpu(agi->agi_unlinked[bucket_index]); + if (next_agino == agino || + !xfs_verify_agino_or_null(pag, next_agino)) { + xfs_buf_mark_corrupt(agibp); + xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); + return -EFSCORRUPTED; + } + + /* + * Update the prev pointer in the next inode to point back to this + * inode. + */ + error = xfs_iunlink_update_backref(pag, agino, next_agino); + if (error == -ENOLINK) + error = xfs_iunlink_reload_next(tp, agibp, agino, next_agino); + if (error) + return error; + + if (next_agino != NULLAGINO) { + /* + * There is already another inode in the bucket, so point this + * inode to the current head of the list. + */ + error = xfs_iunlink_log_inode(tp, ip, pag, next_agino); + if (error) + return error; + ip->i_next_unlinked = next_agino; + } + + /* Point the head of the list to point to this inode. */ + ip->i_prev_unlinked = NULLAGINO; + return xfs_iunlink_update_bucket(tp, pag, agibp, bucket_index, agino); +} + +/* + * This is called when the inode's link count has gone to 0 or we are creating + * a tmpfile via O_TMPFILE. The inode @ip must have nlink == 0. + * + * We place the on-disk inode on a list in the AGI. It will be pulled from this + * list when the inode is freed. + */ +int +xfs_iunlink( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_perag *pag; + struct xfs_buf *agibp; + int error; + + ASSERT(VFS_I(ip)->i_nlink == 0); + ASSERT(VFS_I(ip)->i_mode != 0); + trace_xfs_iunlink(ip); + + pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); + + /* Get the agi buffer first. It ensures lock ordering on the list. */ + error = xfs_read_agi(pag, tp, 0, &agibp); + if (error) + goto out; + + error = xfs_iunlink_insert_inode(tp, pag, agibp, ip); +out: + xfs_perag_put(pag); + return error; +} + +static int +xfs_iunlink_remove_inode( + struct xfs_trans *tp, + struct xfs_perag *pag, + struct xfs_buf *agibp, + struct xfs_inode *ip) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_agi *agi = agibp->b_addr; + xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ip->i_ino); + xfs_agino_t head_agino; + short bucket_index = agino % XFS_AGI_UNLINKED_BUCKETS; + int error; + + trace_xfs_iunlink_remove(ip); + + /* + * Get the index into the agi hash table for the list this inode will + * go on. Make sure the head pointer isn't garbage. + */ + head_agino = be32_to_cpu(agi->agi_unlinked[bucket_index]); + if (!xfs_verify_agino(pag, head_agino)) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + agi, sizeof(*agi)); + xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); + return -EFSCORRUPTED; + } + + /* + * Set our inode's next_unlinked pointer to NULL and then return + * the old pointer value so that we can update whatever was previous + * to us in the list to point to whatever was next in the list. + */ + error = xfs_iunlink_log_inode(tp, ip, pag, NULLAGINO); + if (error) + return error; + + /* + * Update the prev pointer in the next inode to point back to previous + * inode in the chain. + */ + error = xfs_iunlink_update_backref(pag, ip->i_prev_unlinked, + ip->i_next_unlinked); + if (error == -ENOLINK) + error = xfs_iunlink_reload_next(tp, agibp, ip->i_prev_unlinked, + ip->i_next_unlinked); + if (error) + return error; + + if (head_agino != agino) { + struct xfs_inode *prev_ip; + + prev_ip = xfs_iunlink_lookup(pag, ip->i_prev_unlinked); + if (!prev_ip) { + xfs_inode_mark_sick(ip, XFS_SICK_INO_CORE); + return -EFSCORRUPTED; + } + + error = xfs_iunlink_log_inode(tp, prev_ip, pag, + ip->i_next_unlinked); + prev_ip->i_next_unlinked = ip->i_next_unlinked; + } else { + /* Point the head of the list to the next unlinked inode. */ + error = xfs_iunlink_update_bucket(tp, pag, agibp, bucket_index, + ip->i_next_unlinked); + } + + ip->i_next_unlinked = NULLAGINO; + ip->i_prev_unlinked = 0; + return error; +} + +/* + * Pull the on-disk inode from the AGI unlinked list. + */ +int +xfs_iunlink_remove( + struct xfs_trans *tp, + struct xfs_perag *pag, + struct xfs_inode *ip) +{ + struct xfs_buf *agibp; + int error; + + trace_xfs_iunlink_remove(ip); + + /* Get the agi buffer first. It ensures lock ordering on the list. */ + error = xfs_read_agi(pag, tp, 0, &agibp); + if (error) + return error; + + return xfs_iunlink_remove_inode(tp, pag, agibp, ip); +} diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h index bf5393db4fde6..42a032afe3cac 100644 --- a/fs/xfs/libxfs/xfs_inode_util.h +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -47,4 +47,8 @@ void xfs_trans_ichgtime(struct xfs_trans *tp, struct xfs_inode *ip, int flags); void xfs_inode_init(struct xfs_trans *tp, const struct xfs_icreate_args *args, struct xfs_inode *ip); +int xfs_iunlink(struct xfs_trans *tp, struct xfs_inode *ip); +int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_perag *pag, + struct xfs_inode *ip); + #endif /* __XFS_INODE_UTIL_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 1d7febda38c16..182c63ee36b0e 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1738,39 +1738,6 @@ xfs_inactive( return error; } -/* - * In-Core Unlinked List Lookups - * ============================= - * - * Every inode is supposed to be reachable from some other piece of metadata - * with the exception of the root directory. Inodes with a connection to a - * file descriptor but not linked from anywhere in the on-disk directory tree - * are collectively known as unlinked inodes, though the filesystem itself - * maintains links to these inodes so that on-disk metadata are consistent. - * - * XFS implements a per-AG on-disk hash table of unlinked inodes. The AGI - * header contains a number of buckets that point to an inode, and each inode - * record has a pointer to the next inode in the hash chain. This - * singly-linked list causes scaling problems in the iunlink remove function - * because we must walk that list to find the inode that points to the inode - * being removed from the unlinked hash bucket list. - * - * Hence we keep an in-memory double linked list to link each inode on an - * unlinked list. Because there are 64 unlinked lists per AGI, keeping pointer - * based lists would require having 64 list heads in the perag, one for each - * list. This is expensive in terms of memory (think millions of AGs) and cache - * misses on lookups. Instead, use the fact that inodes on the unlinked list - * must be referenced at the VFS level to keep them on the list and hence we - * have an existence guarantee for inodes on the unlinked list. - * - * Given we have an existence guarantee, we can use lockless inode cache lookups - * to resolve aginos to xfs inodes. This means we only need 8 bytes per inode - * for the double linked unlinked list, and we don't need any extra locking to - * keep the list safe as all manipulations are done under the AGI buffer lock. - * Keeping the list up to date does not require memory allocation, just finding - * the XFS inode and updating the next/prev unlinked list aginos. - */ - /* * Find an inode on the unlinked list. This does not take references to the * inode as we have existence guarantees by holding the AGI buffer lock and that @@ -1805,76 +1772,12 @@ xfs_iunlink_lookup( return ip; } -/* - * Update the prev pointer of the next agino. Returns -ENOLINK if the inode - * is not in cache. - */ -static int -xfs_iunlink_update_backref( - struct xfs_perag *pag, - xfs_agino_t prev_agino, - xfs_agino_t next_agino) -{ - struct xfs_inode *ip; - - /* No update necessary if we are at the end of the list. */ - if (next_agino == NULLAGINO) - return 0; - - ip = xfs_iunlink_lookup(pag, next_agino); - if (!ip) - return -ENOLINK; - - ip->i_prev_unlinked = prev_agino; - return 0; -} - -/* - * Point the AGI unlinked bucket at an inode and log the results. The caller - * is responsible for validating the old value. - */ -STATIC int -xfs_iunlink_update_bucket( - struct xfs_trans *tp, - struct xfs_perag *pag, - struct xfs_buf *agibp, - unsigned int bucket_index, - xfs_agino_t new_agino) -{ - struct xfs_agi *agi = agibp->b_addr; - xfs_agino_t old_value; - int offset; - - ASSERT(xfs_verify_agino_or_null(pag, new_agino)); - - old_value = be32_to_cpu(agi->agi_unlinked[bucket_index]); - trace_xfs_iunlink_update_bucket(tp->t_mountp, pag->pag_agno, bucket_index, - old_value, new_agino); - - /* - * We should never find the head of the list already set to the value - * passed in because either we're adding or removing ourselves from the - * head of the list. - */ - if (old_value == new_agino) { - xfs_buf_mark_corrupt(agibp); - xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); - return -EFSCORRUPTED; - } - - agi->agi_unlinked[bucket_index] = cpu_to_be32(new_agino); - offset = offsetof(struct xfs_agi, agi_unlinked) + - (sizeof(xfs_agino_t) * bucket_index); - xfs_trans_log_buf(tp, agibp, offset, offset + sizeof(xfs_agino_t) - 1); - return 0; -} - /* * Load the inode @next_agino into the cache and set its prev_unlinked pointer * to @prev_agino. Caller must hold the AGI to synchronize with other changes * to the unlinked list. */ -STATIC int +int xfs_iunlink_reload_next( struct xfs_trans *tp, struct xfs_buf *agibp, @@ -1930,187 +1833,6 @@ xfs_iunlink_reload_next( return error; } -static int -xfs_iunlink_insert_inode( - struct xfs_trans *tp, - struct xfs_perag *pag, - struct xfs_buf *agibp, - struct xfs_inode *ip) -{ - struct xfs_mount *mp = tp->t_mountp; - struct xfs_agi *agi = agibp->b_addr; - xfs_agino_t next_agino; - xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ip->i_ino); - short bucket_index = agino % XFS_AGI_UNLINKED_BUCKETS; - int error; - - /* - * Get the index into the agi hash table for the list this inode will - * go on. Make sure the pointer isn't garbage and that this inode - * isn't already on the list. - */ - next_agino = be32_to_cpu(agi->agi_unlinked[bucket_index]); - if (next_agino == agino || - !xfs_verify_agino_or_null(pag, next_agino)) { - xfs_buf_mark_corrupt(agibp); - xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); - return -EFSCORRUPTED; - } - - /* - * Update the prev pointer in the next inode to point back to this - * inode. - */ - error = xfs_iunlink_update_backref(pag, agino, next_agino); - if (error == -ENOLINK) - error = xfs_iunlink_reload_next(tp, agibp, agino, next_agino); - if (error) - return error; - - if (next_agino != NULLAGINO) { - /* - * There is already another inode in the bucket, so point this - * inode to the current head of the list. - */ - error = xfs_iunlink_log_inode(tp, ip, pag, next_agino); - if (error) - return error; - ip->i_next_unlinked = next_agino; - } - - /* Point the head of the list to point to this inode. */ - ip->i_prev_unlinked = NULLAGINO; - return xfs_iunlink_update_bucket(tp, pag, agibp, bucket_index, agino); -} - -/* - * This is called when the inode's link count has gone to 0 or we are creating - * a tmpfile via O_TMPFILE. The inode @ip must have nlink == 0. - * - * We place the on-disk inode on a list in the AGI. It will be pulled from this - * list when the inode is freed. - */ -int -xfs_iunlink( - struct xfs_trans *tp, - struct xfs_inode *ip) -{ - struct xfs_mount *mp = tp->t_mountp; - struct xfs_perag *pag; - struct xfs_buf *agibp; - int error; - - ASSERT(VFS_I(ip)->i_nlink == 0); - ASSERT(VFS_I(ip)->i_mode != 0); - trace_xfs_iunlink(ip); - - pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); - - /* Get the agi buffer first. It ensures lock ordering on the list. */ - error = xfs_read_agi(pag, tp, 0, &agibp); - if (error) - goto out; - - error = xfs_iunlink_insert_inode(tp, pag, agibp, ip); -out: - xfs_perag_put(pag); - return error; -} - -static int -xfs_iunlink_remove_inode( - struct xfs_trans *tp, - struct xfs_perag *pag, - struct xfs_buf *agibp, - struct xfs_inode *ip) -{ - struct xfs_mount *mp = tp->t_mountp; - struct xfs_agi *agi = agibp->b_addr; - xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ip->i_ino); - xfs_agino_t head_agino; - short bucket_index = agino % XFS_AGI_UNLINKED_BUCKETS; - int error; - - trace_xfs_iunlink_remove(ip); - - /* - * Get the index into the agi hash table for the list this inode will - * go on. Make sure the head pointer isn't garbage. - */ - head_agino = be32_to_cpu(agi->agi_unlinked[bucket_index]); - if (!xfs_verify_agino(pag, head_agino)) { - XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - agi, sizeof(*agi)); - xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); - return -EFSCORRUPTED; - } - - /* - * Set our inode's next_unlinked pointer to NULL and then return - * the old pointer value so that we can update whatever was previous - * to us in the list to point to whatever was next in the list. - */ - error = xfs_iunlink_log_inode(tp, ip, pag, NULLAGINO); - if (error) - return error; - - /* - * Update the prev pointer in the next inode to point back to previous - * inode in the chain. - */ - error = xfs_iunlink_update_backref(pag, ip->i_prev_unlinked, - ip->i_next_unlinked); - if (error == -ENOLINK) - error = xfs_iunlink_reload_next(tp, agibp, ip->i_prev_unlinked, - ip->i_next_unlinked); - if (error) - return error; - - if (head_agino != agino) { - struct xfs_inode *prev_ip; - - prev_ip = xfs_iunlink_lookup(pag, ip->i_prev_unlinked); - if (!prev_ip) { - xfs_inode_mark_sick(ip, XFS_SICK_INO_CORE); - return -EFSCORRUPTED; - } - - error = xfs_iunlink_log_inode(tp, prev_ip, pag, - ip->i_next_unlinked); - prev_ip->i_next_unlinked = ip->i_next_unlinked; - } else { - /* Point the head of the list to the next unlinked inode. */ - error = xfs_iunlink_update_bucket(tp, pag, agibp, bucket_index, - ip->i_next_unlinked); - } - - ip->i_next_unlinked = NULLAGINO; - ip->i_prev_unlinked = 0; - return error; -} - -/* - * Pull the on-disk inode from the AGI unlinked list. - */ -int -xfs_iunlink_remove( - struct xfs_trans *tp, - struct xfs_perag *pag, - struct xfs_inode *ip) -{ - struct xfs_buf *agibp; - int error; - - trace_xfs_iunlink_remove(ip); - - /* Get the agi buffer first. It ensures lock ordering on the list. */ - error = xfs_read_agi(pag, tp, 0, &agibp); - if (error) - return error; - - return xfs_iunlink_remove_inode(tp, pag, agibp, ip); -} - /* * Look up the inode number specified and if it is not already marked XFS_ISTALE * mark it stale. We should only find clean inodes in this lookup that aren't diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index a905929494bd5..47d3a11a0e7ef 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -606,10 +606,9 @@ extern struct kmem_cache *xfs_inode_cache; bool xfs_inode_needs_inactive(struct xfs_inode *ip); -int xfs_iunlink(struct xfs_trans *tp, struct xfs_inode *ip); -int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_perag *pag, - struct xfs_inode *ip); struct xfs_inode *xfs_iunlink_lookup(struct xfs_perag *pag, xfs_agino_t agino); +int xfs_iunlink_reload_next(struct xfs_trans *tp, struct xfs_buf *agibp, + xfs_agino_t prev_agino, xfs_agino_t next_agino); void xfs_end_io(struct work_struct *work); From patchwork Thu Jun 20 23:02:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706484 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 37709C8FB for ; Thu, 20 Jun 2024 23:02:03 +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=1718924524; cv=none; b=Dm5SCOzJRLaNAweo1awg1siXN5UlE6b3oMdQCkd4rCsiHyoTLb+Em3nfcl/DLxFmnIpF5puAYlq9/YYIszYom3u3v6mmq3LdM9UEpbF0zLMaKkU03Yo76dbRpq20LQ57LXptZwd5YOKnmu2XVSRIpxy6skVpKxCTIakaJogOWwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924524; c=relaxed/simple; bh=p278gOk07vy+VZJd/sZRA2hso2U/29H7TWSZHiKcdVk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fwQJ8hBHf+y1HcMeF9GAQ475X18Y3C/bfYmBb1i8uOp14Ir0gw/1O2JNrtO+1Uj2htqBFbIZOqjLgz6Vi7HmthFVq9GVljZe1WP2/8gx7fBART2dGdmYDKkTVQjUwDuqqTNUX3Gqkq/rde/gE5CKx/qwvS7kgUrnZRhWOGUrWOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VEhZewIX; 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="VEhZewIX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6912C32781; Thu, 20 Jun 2024 23:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924523; bh=p278gOk07vy+VZJd/sZRA2hso2U/29H7TWSZHiKcdVk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VEhZewIX5XdQQUJnvrkrwhSiFf14TPohpROh4mio2Xt0I6er7yP056e2SuEM6VUsS CdShBbjYIcB4eSF7AHk3ESDzK/bIj8DT9cYWcC9gHRRHGq98DxGfhrqrrvjrD56bgB NdgExlBig0s3TrFrsAggCPZCUfEoxR/jio1vHt6cQpvjHgj4YJ46jsV4acBONOJHV4 By8A87BdbMvDcFMLbC6SWqAqvKp+zTl5ed6TK7+aI9pb7TQ1RivH0U+q6F7UF7V0+k /S2oNePPuiILbuzH1SkZSDS9rsfDL3giKJRgn+DgBQIBzyq1YArGw4joYmGfVyp4yX XCsUmkW0sajbA== Date: Thu, 20 Jun 2024 16:02:03 -0700 Subject: [PATCH 14/24] xfs: hoist xfs_{bump,drop}link to libxfs From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418137.3183075.9161813667351346245.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move xfs_bumplink and xfs_droplink to libxfs. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_inode_util.c | 53 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 2 ++ fs/xfs/xfs_inode.c | 53 ---------------------------------------- fs/xfs/xfs_inode.h | 2 -- 4 files changed, 55 insertions(+), 55 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index 5739871ac3705..214976ecefd77 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -626,3 +626,56 @@ xfs_iunlink_remove( return xfs_iunlink_remove_inode(tp, pag, agibp, ip); } + +/* + * Decrement the link count on an inode & log the change. If this causes the + * link count to go to zero, move the inode to AGI unlinked list so that it can + * be freed when the last active reference goes away via xfs_inactive(). + */ +int +xfs_droplink( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + struct inode *inode = VFS_I(ip); + + xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); + + if (inode->i_nlink == 0) { + xfs_info_ratelimited(tp->t_mountp, + "Inode 0x%llx link count dropped below zero. Pinning link count.", + ip->i_ino); + set_nlink(inode, XFS_NLINK_PINNED); + } + if (inode->i_nlink != XFS_NLINK_PINNED) + drop_nlink(inode); + + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + + if (inode->i_nlink) + return 0; + + return xfs_iunlink(tp, ip); +} + +/* + * Increment the link count on an inode & log the change. + */ +void +xfs_bumplink( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + struct inode *inode = VFS_I(ip); + + xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); + + if (inode->i_nlink == XFS_NLINK_PINNED - 1) + xfs_info_ratelimited(tp->t_mountp, + "Inode 0x%llx link count exceeded maximum. Pinning link count.", + ip->i_ino); + if (inode->i_nlink != XFS_NLINK_PINNED) + inc_nlink(inode); + + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); +} diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h index 42a032afe3cac..50c14ba6ca5a2 100644 --- a/fs/xfs/libxfs/xfs_inode_util.h +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -50,5 +50,7 @@ void xfs_inode_init(struct xfs_trans *tp, const struct xfs_icreate_args *args, int xfs_iunlink(struct xfs_trans *tp, struct xfs_inode *ip); int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_perag *pag, struct xfs_inode *ip); +int xfs_droplink(struct xfs_trans *tp, struct xfs_inode *ip); +void xfs_bumplink(struct xfs_trans *tp, struct xfs_inode *ip); #endif /* __XFS_INODE_UTIL_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 182c63ee36b0e..c59c6321e361a 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -600,59 +600,6 @@ xfs_icreate( return 0; } -/* - * Decrement the link count on an inode & log the change. If this causes the - * link count to go to zero, move the inode to AGI unlinked list so that it can - * be freed when the last active reference goes away via xfs_inactive(). - */ -int -xfs_droplink( - struct xfs_trans *tp, - struct xfs_inode *ip) -{ - struct inode *inode = VFS_I(ip); - - xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); - - if (inode->i_nlink == 0) { - xfs_info_ratelimited(tp->t_mountp, - "Inode 0x%llx link count dropped below zero. Pinning link count.", - ip->i_ino); - set_nlink(inode, XFS_NLINK_PINNED); - } - if (inode->i_nlink != XFS_NLINK_PINNED) - drop_nlink(inode); - - xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); - - if (inode->i_nlink) - return 0; - - return xfs_iunlink(tp, ip); -} - -/* - * Increment the link count on an inode & log the change. - */ -void -xfs_bumplink( - struct xfs_trans *tp, - struct xfs_inode *ip) -{ - struct inode *inode = VFS_I(ip); - - xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); - - if (inode->i_nlink == XFS_NLINK_PINNED - 1) - xfs_info_ratelimited(tp->t_mountp, - "Inode 0x%llx link count exceeded maximum. Pinning link count.", - ip->i_ino); - if (inode->i_nlink != XFS_NLINK_PINNED) - inc_nlink(inode); - - xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); -} - #ifdef CONFIG_XFS_LIVE_HOOKS /* * Use a static key here to reduce the overhead of directory live update hooks. diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 47d3a11a0e7ef..5ee044674c3ab 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -615,8 +615,6 @@ void xfs_end_io(struct work_struct *work); int xfs_ilock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2); void xfs_iunlock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2); void xfs_iunlock2_remapping(struct xfs_inode *ip1, struct xfs_inode *ip2); -int xfs_droplink(struct xfs_trans *tp, struct xfs_inode *ip); -void xfs_bumplink(struct xfs_trans *tp, struct xfs_inode *ip); void xfs_lock_inodes(struct xfs_inode **ips, int inodes, uint lock_mode); void xfs_sort_inodes(struct xfs_inode **i_tab, unsigned int num_inodes); From patchwork Thu Jun 20 23:02:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706485 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 D2FE039856 for ; Thu, 20 Jun 2024 23:02:19 +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=1718924539; cv=none; b=o7/XIAdNOihpfP7cFEYYbU1EiJCEMbWS7Uxrmoq9v1RqpEHbCime9asiHtR5rdzPd5vEynQLaHJpeMJzY8lMAXvzWPGKmhqPoT3WGib9AhA2Lx6bgFG105KmGM1Qt3b0wY7VoXnAIh5MGfpNN9ib1RJejMKAsmMrZOd1yAJxMBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924539; c=relaxed/simple; bh=EiMC1Mxil1ldr7UujNtMLHhzc2+sSi0OdZ9pg212Qn0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g+YBmkjV6UVXSZc411E4S7RsDY8WZEQ1H/z0G6LGBDDSpPcA6RYYSJdoetvePwq908cwfMju1uYhcXQFloFaRrK1Dmvar60dYBLkgQq78TapROiMLM4sjv5osKLu1R4yeq7tA2q8+4fNT1kJNQCnLoYAwqBV9JI3GRC2XWvDOmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VxvXtL0T; 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="VxvXtL0T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C413C2BD10; Thu, 20 Jun 2024 23:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924539; bh=EiMC1Mxil1ldr7UujNtMLHhzc2+sSi0OdZ9pg212Qn0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VxvXtL0TzldQuXbkVcGVBE2E1Zdnfn85axJSdPlryHHuGMpzF4oqe3xbJtyv06qH6 0YjpLN0VpMrP+CvLxCzx7woobuCgngCfFwK10C5Vp28ShYv4ed5xLBsB3+/syMOJ5q SAHcHs/ZbWFd/Omy+lnyIYdSLxQdpriNMFbyGzDbT/t03+Sxkr6eQ92mU78RgOxhwX 25rZ/4Kcl24LvOBkFI3yQJ9OuXTLFhr2K2GTMZQKGo5MoHIF8HrclCzl/2mVVCq/CS U5GpWOAMPcPnYWgkJv3rzwbNXWLUCJHiiXq7fRrqFdZtDRZYkxYCAwfNVs/2Sb1XAP Zil4aa65fXacA== Date: Thu, 20 Jun 2024 16:02:18 -0700 Subject: [PATCH 15/24] xfs: separate the icreate logic around INIT_XATTRS From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418155.3183075.2421928430504613482.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong INIT_XATTRS is overloaded here -- it's set during the creat process when we think that we're immediately going to set some ACL xattrs to save time. However, it's also used by the parent pointers code to enable the attr fork in preparation to receive ppptr xattrs. This results in xfs_has_parent() branches scattered around the codebase to turn on INIT_XATTRS. Linkable files are created far more commonly than unlinkable temporary files or directory tree roots, so we should centralize this logic in xfs_inode_init. For the three callers that don't want parent pointers (online repiar tempfiles, unlinkable tempfiles, rootdir creation) we provide an UNLINKABLE flag to skip attr fork initialization. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_inode_util.c | 36 ++++++++++++++++++++++++++---------- fs/xfs/libxfs/xfs_inode_util.h | 1 + fs/xfs/scrub/tempfile.c | 2 +- fs/xfs/xfs_inode.c | 3 --- fs/xfs/xfs_iops.c | 11 ++++------- fs/xfs/xfs_qm.c | 1 + fs/xfs/xfs_symlink.c | 3 --- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index 214976ecefd77..5795445ef4bd2 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -233,6 +233,31 @@ xfs_inode_inherit_flags2( } } +/* + * If we need to create attributes immediately after allocating the inode, + * initialise an empty attribute fork right now. We use the default fork offset + * for attributes here as we don't know exactly what size or how many + * attributes we might be adding. We can do this safely here because we know + * the data fork is completely empty and this saves us from needing to run a + * separate transaction to set the fork offset in the immediate future. + * + * If we have parent pointers and the caller hasn't told us that the file will + * never be linked into a directory tree, we /must/ create the attr fork. + */ +static inline bool +xfs_icreate_want_attrfork( + struct xfs_mount *mp, + const struct xfs_icreate_args *args) +{ + if (args->flags & XFS_ICREATE_INIT_XATTRS) + return true; + + if (!(args->flags & XFS_ICREATE_UNLINKABLE) && xfs_has_parent(mp)) + return true; + + return false; +} + /* Initialise an inode's attributes. */ void xfs_inode_init( @@ -325,16 +350,7 @@ xfs_inode_init( ASSERT(0); } - /* - * If we need to create attributes immediately after allocating the - * inode, initialise an empty attribute fork right now. We use the - * default fork offset for attributes here as we don't know exactly what - * size or how many attributes we might be adding. We can do this - * safely here because we know the data fork is completely empty and - * this saves us from needing to run a separate transaction to set the - * fork offset in the immediate future. - */ - if (args->flags & XFS_ICREATE_INIT_XATTRS) { + if (xfs_icreate_want_attrfork(mp, args)) { ip->i_forkoff = xfs_default_attroffset(ip) >> 3; xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h index 50c14ba6ca5a2..1c54c3b0cf262 100644 --- a/fs/xfs/libxfs/xfs_inode_util.h +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -32,6 +32,7 @@ struct xfs_icreate_args { #define XFS_ICREATE_TMPFILE (1U << 0) /* create an unlinked file */ #define XFS_ICREATE_INIT_XATTRS (1U << 1) /* will set xattrs immediately */ +#define XFS_ICREATE_UNLINKABLE (1U << 2) /* cannot link into dir tree */ uint16_t flags; }; diff --git a/fs/xfs/scrub/tempfile.c b/fs/xfs/scrub/tempfile.c index 523971a15a72a..d390d56cd8751 100644 --- a/fs/xfs/scrub/tempfile.c +++ b/fs/xfs/scrub/tempfile.c @@ -43,7 +43,7 @@ xrep_tempfile_create( struct xfs_icreate_args args = { .pip = sc->mp->m_rootip, .mode = mode, - .flags = XFS_ICREATE_TMPFILE, + .flags = XFS_ICREATE_TMPFILE | XFS_ICREATE_UNLINKABLE, }; struct xfs_mount *mp = sc->mp; struct xfs_trans *tp = NULL; diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index c59c6321e361a..dd8e189175d53 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2512,9 +2512,6 @@ xfs_rename_alloc_whiteout( struct qstr name; int error; - if (xfs_has_parent(dp->i_mount)) - args.flags |= XFS_ICREATE_INIT_XATTRS; - error = xfs_create_tmpfile(&args, &tmpfile); if (error) return error; diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 4563ba440570b..07f736c42460b 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -158,8 +158,6 @@ xfs_create_need_xattr( if (dir->i_sb->s_security) return true; #endif - if (xfs_has_parent(XFS_I(dir)->i_mount)) - return true; return false; } @@ -215,12 +213,11 @@ xfs_generic_create( args.flags |= XFS_ICREATE_TMPFILE; /* - * If this temporary file will be linkable, set up the file - * with an attr fork to receive a parent pointer. + * If this temporary file will not be linkable, don't bother + * creating an attr fork to receive a parent pointer. */ - if (!(tmpfile->f_flags & O_EXCL) && - xfs_has_parent(XFS_I(dir)->i_mount)) - args.flags |= XFS_ICREATE_INIT_XATTRS; + if (tmpfile->f_flags & O_EXCL) + args.flags |= XFS_ICREATE_UNLINKABLE; error = xfs_create_tmpfile(&args, &ip); } diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 78f839630c624..9490b913a4ab4 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -795,6 +795,7 @@ xfs_qm_qino_alloc( if (need_alloc) { struct xfs_icreate_args args = { .mode = S_IFREG, + .flags = XFS_ICREATE_UNLINKABLE, }; xfs_ino_t ino; diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 6ff736e5c4e7f..e471369f6b634 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -115,9 +115,6 @@ xfs_symlink( if (xfs_is_shutdown(mp)) return -EIO; - if (xfs_has_parent(mp)) - args.flags |= XFS_ICREATE_INIT_XATTRS; - /* * Check component lengths of the target path name. */ From patchwork Thu Jun 20 23:02:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706486 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 7BE1C39856 for ; Thu, 20 Jun 2024 23:02:35 +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=1718924555; cv=none; b=XpTALFn6t632YmR0j1KLrvVM3OlQffb6Xez9oysWRJVmoRxBFRU4BDxGGZZSJD3sYJj5FJsB/CZuQQ0+J45Lgh3tT4GjQJSYi2xDi7hpnIsU9FFWjx/CLs1PZLSX/blciyD8g7zRGHyMFXVbSpbe5/WoYybE9IDR+nUt8FH7kqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924555; c=relaxed/simple; bh=7dVGl+lud3IarO0FE4qbQ+TPuRH+7ceU2ZghOPl5wUo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EfMMmx9dFgZOawpwf+ZV03FPXJyrJBPW+XmYiXLWrAAsBDNcTp83sIsMkJ4wl1pB3ruYXJvqIOBMu5jChs+m/oz22/7/7S+yoZFqQCwT6QB14fmm+DCrscWwVIcUSmc07C2jxZ3q1Nfe1quiwbq4LYB7Gf2dyrS/UfyM6M2jshI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qJlJfkMG; 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="qJlJfkMG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06749C2BD10; Thu, 20 Jun 2024 23:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924555; bh=7dVGl+lud3IarO0FE4qbQ+TPuRH+7ceU2ZghOPl5wUo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qJlJfkMGNXyzuWAyo1U10ecCaioup8aff/Bm4GrNz6o/tgguW87Sgw1QIV538O/t1 NEjwPjNWcw3w8WRpbuODrycTHPuUpRz9sZUKdRV9A9iwcb1ocU9+MeQogmP1M9Do22 cFDNpAH1Br8+AV2yavZC/XAE+J1o8rsVeqIMukcutoCxRpHzNEntzt6vjHZGuYK5iG SLCBmELivchurT6J4ltW8ibiyVENp3Nm8e23L6ev/3CI4+8IxDF5NhrCGHM9uCBWse toiJCfZIimH4DDl9v34ePvlEyVrYJ03eMZMn+8FoExjWR9UaWhYXM95LgMK3EPPWlb 4EVtH/8tl0pFw== Date: Thu, 20 Jun 2024 16:02:34 -0700 Subject: [PATCH 16/24] xfs: create libxfs helper to link a new inode into a directory From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418173.3183075.477214909437232970.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a new libxfs function to link a newly created inode into a directory. The upcoming metadata directory feature will need this to create a metadata directory tree. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_dir2.c | 53 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 12 ++++++++++ fs/xfs/xfs_inode.c | 57 +++++++++++++++------------------------------- fs/xfs/xfs_symlink.c | 45 +++++++++++++++--------------------- 4 files changed, 102 insertions(+), 65 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index 457f9a38f8504..bbed03441f5cc 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -19,6 +19,9 @@ #include "xfs_error.h" #include "xfs_trace.h" #include "xfs_health.h" +#include "xfs_bmap_btree.h" +#include "xfs_trans_space.h" +#include "xfs_parent.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)"..", @@ -756,3 +759,53 @@ xfs_dir2_compname( return xfs_ascii_ci_compname(args, name, len); return xfs_da_compname(args, name, len); } + +/* + * Given a directory @dp, a newly allocated inode @ip, and a @name, link @ip + * into @dp under the given @name. If @ip is a directory, it will be + * initialized. Both inodes must have the ILOCK held and the transaction must + * have sufficient blocks reserved. + */ +int +xfs_dir_create_child( + struct xfs_trans *tp, + unsigned int resblks, + struct xfs_dir_update *du) +{ + struct xfs_inode *dp = du->dp; + const struct xfs_name *name = du->name; + struct xfs_inode *ip = du->ip; + int error; + + xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); + xfs_assert_ilocked(dp, XFS_ILOCK_EXCL); + + error = xfs_dir_createname(tp, dp, name, ip->i_ino, resblks); + if (error) { + ASSERT(error != -ENOSPC); + return error; + } + + xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); + xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); + + if (S_ISDIR(VFS_I(ip)->i_mode)) { + error = xfs_dir_init(tp, ip, dp); + if (error) + return error; + + xfs_bumplink(tp, dp); + } + + /* + * If we have parent pointers, we need to add the attribute containing + * the parent information now. + */ + if (du->ppargs) { + error = xfs_parent_addname(tp, du->ppargs, dp, name, ip); + if (error) + return error; + } + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index 6dbe6e9ecb491..a1ba6fd0a725f 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -309,4 +309,16 @@ static inline unsigned char xfs_ascii_ci_xfrm(unsigned char c) return c; } +struct xfs_parent_args; + +struct xfs_dir_update { + struct xfs_inode *dp; + const struct xfs_name *name; + struct xfs_inode *ip; + struct xfs_parent_args *ppargs; +}; + +int xfs_dir_create_child(struct xfs_trans *tp, unsigned int resblks, + struct xfs_dir_update *du); + #endif /* __XFS_DIR2_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index dd8e189175d53..37f2ac96b7fbe 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -714,14 +714,16 @@ xfs_create( struct xfs_inode **ipp) { struct xfs_inode *dp = args->pip; + struct xfs_dir_update du = { + .dp = dp, + .name = name, + }; struct xfs_mount *mp = dp->i_mount; - struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; struct xfs_dquot *udqp; struct xfs_dquot *gdqp; struct xfs_dquot *pdqp; struct xfs_trans_res *tres; - struct xfs_parent_args *ppargs; xfs_ino_t ino; bool unlock_dp_on_error = false; bool is_dir = S_ISDIR(args->mode); @@ -748,7 +750,7 @@ xfs_create( tres = &M_RES(mp)->tr_create; } - error = xfs_parent_start(mp, &ppargs); + error = xfs_parent_start(mp, &du.ppargs); if (error) goto out_release_dquots; @@ -779,7 +781,7 @@ xfs_create( */ error = xfs_dialloc(&tp, dp->i_ino, args->mode, &ino); if (!error) - error = xfs_icreate(tp, ino, args, &ip); + error = xfs_icreate(tp, ino, args, &du.ip); if (error) goto out_trans_cancel; @@ -792,38 +794,15 @@ xfs_create( */ xfs_trans_ijoin(tp, dp, 0); - error = xfs_dir_createname(tp, dp, name, ip->i_ino, - resblks - XFS_IALLOC_SPACE_RES(mp)); - if (error) { - ASSERT(error != -ENOSPC); + error = xfs_dir_create_child(tp, resblks, &du); + if (error) goto out_trans_cancel; - } - xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); - xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); - - if (is_dir) { - error = xfs_dir_init(tp, ip, dp); - if (error) - goto out_trans_cancel; - - xfs_bumplink(tp, dp); - } - - /* - * If we have parent pointers, we need to add the attribute containing - * the parent information now. - */ - if (ppargs) { - error = xfs_parent_addname(tp, ppargs, dp, name, ip); - if (error) - goto out_trans_cancel; - } /* * Create ip with a reference from dp, and add '.' and '..' references * if it's a directory. */ - xfs_dir_update_hook(dp, ip, 1, name); + xfs_dir_update_hook(dp, du.ip, 1, name); /* * If this is a synchronous mount, make sure that the @@ -838,7 +817,7 @@ xfs_create( * These ids of the inode couldn't have changed since the new * inode has been locked ever since it was created. */ - xfs_qm_vop_create_dqattach(tp, ip, udqp, gdqp, pdqp); + xfs_qm_vop_create_dqattach(tp, du.ip, udqp, gdqp, pdqp); error = xfs_trans_commit(tp); if (error) @@ -848,10 +827,10 @@ xfs_create( xfs_qm_dqrele(gdqp); xfs_qm_dqrele(pdqp); - *ipp = ip; - xfs_iunlock(ip, XFS_ILOCK_EXCL); + *ipp = du.ip; + xfs_iunlock(du.ip, XFS_ILOCK_EXCL); xfs_iunlock(dp, XFS_ILOCK_EXCL); - xfs_parent_finish(mp, ppargs); + xfs_parent_finish(mp, du.ppargs); return 0; out_trans_cancel: @@ -862,13 +841,13 @@ xfs_create( * setup of the inode and release the inode. This prevents recursive * transactions and deadlocks from xfs_inactive. */ - if (ip) { - xfs_iunlock(ip, XFS_ILOCK_EXCL); - xfs_finish_inode_setup(ip); - xfs_irele(ip); + if (du.ip) { + xfs_iunlock(du.ip, XFS_ILOCK_EXCL); + xfs_finish_inode_setup(du.ip); + xfs_irele(du.ip); } out_parent: - xfs_parent_finish(mp, ppargs); + xfs_parent_finish(mp, du.ppargs); out_release_dquots: xfs_qm_dqrele(udqp); xfs_qm_dqrele(gdqp); diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index e471369f6b634..c0f5c2e1f215b 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -95,8 +95,11 @@ xfs_symlink( .pip = dp, .mode = S_IFLNK | (mode & ~S_IFMT), }; + struct xfs_dir_update du = { + .dp = dp, + .name = link_name, + }; struct xfs_trans *tp = NULL; - struct xfs_inode *ip = NULL; int error = 0; int pathlen; bool unlock_dp_on_error = false; @@ -106,7 +109,6 @@ xfs_symlink( struct xfs_dquot *pdqp; uint resblks; xfs_ino_t ino; - struct xfs_parent_args *ppargs; *ipp = NULL; @@ -140,7 +142,7 @@ xfs_symlink( fs_blocks = xfs_symlink_blocks(mp, pathlen); resblks = xfs_symlink_space_res(mp, link_name->len, fs_blocks); - error = xfs_parent_start(mp, &ppargs); + error = xfs_parent_start(mp, &du.ppargs); if (error) goto out_release_dquots; @@ -165,7 +167,7 @@ xfs_symlink( */ error = xfs_dialloc(&tp, dp->i_ino, S_IFLNK, &ino); if (!error) - error = xfs_icreate(tp, ino, &args, &ip); + error = xfs_icreate(tp, ino, &args, &du.ip); if (error) goto out_trans_cancel; @@ -181,33 +183,24 @@ xfs_symlink( /* * Also attach the dquot(s) to it, if applicable. */ - xfs_qm_vop_create_dqattach(tp, ip, udqp, gdqp, pdqp); + xfs_qm_vop_create_dqattach(tp, du.ip, udqp, gdqp, pdqp); resblks -= XFS_IALLOC_SPACE_RES(mp); - error = xfs_symlink_write_target(tp, ip, ip->i_ino, target_path, + error = xfs_symlink_write_target(tp, du.ip, du.ip->i_ino, target_path, pathlen, fs_blocks, resblks); if (error) goto out_trans_cancel; resblks -= fs_blocks; - i_size_write(VFS_I(ip), ip->i_disk_size); + i_size_write(VFS_I(du.ip), du.ip->i_disk_size); /* * Create the directory entry for the symlink. */ - error = xfs_dir_createname(tp, dp, link_name, ip->i_ino, resblks); + error = xfs_dir_create_child(tp, resblks, &du); if (error) goto out_trans_cancel; - xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); - xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); - /* Add parent pointer for the new symlink. */ - if (ppargs) { - error = xfs_parent_addname(tp, ppargs, dp, link_name, ip); - if (error) - goto out_trans_cancel; - } - - xfs_dir_update_hook(dp, ip, 1, link_name); + xfs_dir_update_hook(dp, du.ip, 1, link_name); /* * If this is a synchronous mount, make sure that the @@ -225,10 +218,10 @@ xfs_symlink( xfs_qm_dqrele(gdqp); xfs_qm_dqrele(pdqp); - *ipp = ip; - xfs_iunlock(ip, XFS_ILOCK_EXCL); + *ipp = du.ip; + xfs_iunlock(du.ip, XFS_ILOCK_EXCL); xfs_iunlock(dp, XFS_ILOCK_EXCL); - xfs_parent_finish(mp, ppargs); + xfs_parent_finish(mp, du.ppargs); return 0; out_trans_cancel: @@ -239,13 +232,13 @@ xfs_symlink( * setup of the inode and release the inode. This prevents recursive * transactions and deadlocks from xfs_inactive. */ - if (ip) { - xfs_iunlock(ip, XFS_ILOCK_EXCL); - xfs_finish_inode_setup(ip); - xfs_irele(ip); + if (du.ip) { + xfs_iunlock(du.ip, XFS_ILOCK_EXCL); + xfs_finish_inode_setup(du.ip); + xfs_irele(du.ip); } out_parent: - xfs_parent_finish(mp, ppargs); + xfs_parent_finish(mp, du.ppargs); out_release_dquots: xfs_qm_dqrele(udqp); xfs_qm_dqrele(gdqp); From patchwork Thu Jun 20 23:02:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706487 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 2C64839856 for ; Thu, 20 Jun 2024 23:02:50 +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=1718924571; cv=none; b=OjVwN1ESP26piTFe7p0/0oJlqk23V6KwewGlHHlHw740+KMGypsCzn8Nka+BhszSDtArGEsSKERmk30Kem69x70Ix8awgm028maLW7OJtLsaN5kpN4/WtSeytudRZQ71ixXbg4Er3qUCt4KD67ylIvc5cTujByhk2ucUMoqn4P4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924571; c=relaxed/simple; bh=Hy27MqXUgcv5iEqlV861Q8ws0hiWNNNan282DrL0Geo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AR6lxnu/56tWMHnI7hDf+bo0u2NbOOMJ7XTY46cAEUbNWyruHlNTeycwGwDnFCjiUDrypd9KU4fw02kZ4nujxKR3k/uQj4guepj0oaXHNg2WiYS5YzXFq4sscv5igXDllHFaehaQGnDMp80gJK7a5VYcwt3fBGRLEgv923NFpLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y1zrumi8; 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="Y1zrumi8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EFAAC2BD10; Thu, 20 Jun 2024 23:02:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924570; bh=Hy27MqXUgcv5iEqlV861Q8ws0hiWNNNan282DrL0Geo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Y1zrumi80qoBJWTheMC8e+PE32887Pu/QefQT8t6i3sIfVdOpPy4nvUwmZDnmPDvc Keyx1lTFdZ1U81b/BuRcXXi4U3a5aVeOiABwx+FhwruYXIP4Yb2EGK3KCxq9UYWcp/ KzrNrU7ki4Gh8xOLNRIzlzplFemLOa3zYCeFc7eBFIOZIpboa7RwcMKjBFTL+LGHQG 0jvNR5ZSod6TX3ZMawS6InkUCbrG4e2Ia2WqTmiycw9qJn7kJiT89Wj/ctZXhG6BUo MWTod+/WTFQVYoW3MLi0710wjwarGwhHIhf84Dinv+puFiom9Iud8WAzOWdKQ6vw8J xPqw5AkQqcLwg== Date: Thu, 20 Jun 2024 16:02:50 -0700 Subject: [PATCH 17/24] xfs: create libxfs helper to link an existing inode into a directory From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418191.3183075.12556823901451535807.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a new libxfs function to link an existing inode into a directory. The upcoming metadata directory feature will need this to create a metadata directory tree. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_dir2.c | 71 ++++++++++++++++++++++++++++++++++++++++++++-- fs/xfs/libxfs/xfs_dir2.h | 4 ++- fs/xfs/xfs_inode.c | 52 ++++++---------------------------- 3 files changed, 81 insertions(+), 46 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index bbed03441f5cc..5a75f60e85186 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -22,6 +22,7 @@ #include "xfs_bmap_btree.h" #include "xfs_trans_space.h" #include "xfs_parent.h" +#include "xfs_ag.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)"..", @@ -587,9 +588,9 @@ xfs_dir_replace( */ int xfs_dir_canenter( - xfs_trans_t *tp, - xfs_inode_t *dp, - struct xfs_name *name) /* name of entry to add */ + struct xfs_trans *tp, + struct xfs_inode *dp, + const struct xfs_name *name) /* name of entry to add */ { return xfs_dir_createname(tp, dp, name, 0, 0); } @@ -809,3 +810,67 @@ xfs_dir_create_child( return 0; } + +/* + * Given a directory @dp, an existing non-directory inode @ip, and a @name, + * link @ip into @dp under the given @name. Both inodes must have the ILOCK + * held. + */ +int +xfs_dir_add_child( + struct xfs_trans *tp, + unsigned int resblks, + struct xfs_dir_update *du) +{ + struct xfs_inode *dp = du->dp; + const struct xfs_name *name = du->name; + struct xfs_inode *ip = du->ip; + struct xfs_mount *mp = tp->t_mountp; + int error; + + xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); + xfs_assert_ilocked(dp, XFS_ILOCK_EXCL); + ASSERT(!S_ISDIR(VFS_I(ip)->i_mode)); + + if (!resblks) { + error = xfs_dir_canenter(tp, dp, name); + if (error) + return error; + } + + /* + * Handle initial link state of O_TMPFILE inode + */ + if (VFS_I(ip)->i_nlink == 0) { + struct xfs_perag *pag; + + pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); + error = xfs_iunlink_remove(tp, pag, ip); + xfs_perag_put(pag); + if (error) + return error; + } + + error = xfs_dir_createname(tp, dp, name, ip->i_ino, resblks); + if (error) + return error; + + xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); + xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); + + xfs_bumplink(tp, ip); + + /* + * If we have parent pointers, we now need to add the parent record to + * the attribute fork of the inode. If this is the initial parent + * attribute, we need to create it correctly, otherwise we can just add + * the parent to the inode. + */ + if (du->ppargs) { + error = xfs_parent_addname(tp, du->ppargs, dp, name, ip); + if (error) + return error; + } + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index a1ba6fd0a725f..4f9711509571a 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -74,7 +74,7 @@ extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum, xfs_extlen_t tot); extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_name *name); + const struct xfs_name *name); int xfs_dir_lookup_args(struct xfs_da_args *args); int xfs_dir_createname_args(struct xfs_da_args *args); @@ -320,5 +320,7 @@ struct xfs_dir_update { int xfs_dir_create_child(struct xfs_trans *tp, unsigned int resblks, struct xfs_dir_update *du); +int xfs_dir_add_child(struct xfs_trans *tp, unsigned int resblks, + struct xfs_dir_update *du); #endif /* __XFS_DIR2_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 37f2ac96b7fbe..3ac4ea677ff7d 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -952,11 +952,15 @@ xfs_link( struct xfs_inode *sip, struct xfs_name *target_name) { + struct xfs_dir_update du = { + .dp = tdp, + .name = target_name, + .ip = sip, + }; struct xfs_mount *mp = tdp->i_mount; struct xfs_trans *tp; int error, nospace_error = 0; int resblks; - struct xfs_parent_args *ppargs; trace_xfs_link(tdp, target_name); @@ -975,7 +979,7 @@ xfs_link( if (error) goto std_return; - error = xfs_parent_start(mp, &ppargs); + error = xfs_parent_start(mp, &du.ppargs); if (error) goto std_return; @@ -990,7 +994,7 @@ xfs_link( * pointers are enabled because we can't back out if the xattrs must * grow. */ - if (ppargs && nospace_error) { + if (du.ppargs && nospace_error) { error = nospace_error; goto error_return; } @@ -1017,45 +1021,9 @@ xfs_link( } } - if (!resblks) { - error = xfs_dir_canenter(tp, tdp, target_name); - if (error) - goto error_return; - } - - /* - * Handle initial link state of O_TMPFILE inode - */ - if (VFS_I(sip)->i_nlink == 0) { - struct xfs_perag *pag; - - pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, sip->i_ino)); - error = xfs_iunlink_remove(tp, pag, sip); - xfs_perag_put(pag); - if (error) - goto error_return; - } - - error = xfs_dir_createname(tp, tdp, target_name, sip->i_ino, - resblks); + error = xfs_dir_add_child(tp, resblks, &du); if (error) goto error_return; - xfs_trans_ichgtime(tp, tdp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); - xfs_trans_log_inode(tp, tdp, XFS_ILOG_CORE); - - xfs_bumplink(tp, sip); - - /* - * If we have parent pointers, we now need to add the parent record to - * the attribute fork of the inode. If this is the initial parent - * attribute, we need to create it correctly, otherwise we can just add - * the parent to the inode. - */ - if (ppargs) { - error = xfs_parent_addname(tp, ppargs, tdp, target_name, sip); - if (error) - goto error_return; - } xfs_dir_update_hook(tdp, sip, 1, target_name); @@ -1070,7 +1038,7 @@ xfs_link( error = xfs_trans_commit(tp); xfs_iunlock(tdp, XFS_ILOCK_EXCL); xfs_iunlock(sip, XFS_ILOCK_EXCL); - xfs_parent_finish(mp, ppargs); + xfs_parent_finish(mp, du.ppargs); return error; error_return: @@ -1078,7 +1046,7 @@ xfs_link( xfs_iunlock(tdp, XFS_ILOCK_EXCL); xfs_iunlock(sip, XFS_ILOCK_EXCL); out_parent: - xfs_parent_finish(mp, ppargs); + xfs_parent_finish(mp, du.ppargs); std_return: if (error == -ENOSPC && nospace_error) error = nospace_error; From patchwork Thu Jun 20 23:03:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706488 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 99B017C6EB for ; Thu, 20 Jun 2024 23:03:06 +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=1718924586; cv=none; b=Rb4jxOzdam0z8O0ObmCMoZodcFCCyKl46di/1XzbxGshx4IpprPYFEWZ6H6xTpd1PLGdgSZhSI6fn3T8p9FjLUfspIZ92srfy1FPani1sPx7pKfkSr3kmoZaCpPG0lRjOkBYwQ/BkpJ1IGLb4wflkmptrd/OKnX2I3l09tzr+Oo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924586; c=relaxed/simple; bh=EYyxNql7/Nmk/En7XesoyjCJ6s1MBa52YxDbhdk/tpE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FIgJ2SG6SwLcoCG4XSfEPbKWPUgrqF0oi9UsSeFoOxaaGbtheN3LElfOBkrlHIEuN6B5Y/xvxCoe+Pj/yoy+Vm9GtMnTGORbTFOZZDnsjp5mQWK5W0qLOBNkshJWmIi/DxbgVmYwG8/CHCOP9VAR9E6XXsXLswJ2P5IRUZ+ODXQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HwnaW+an; 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="HwnaW+an" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41CC6C2BD10; Thu, 20 Jun 2024 23:03:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924586; bh=EYyxNql7/Nmk/En7XesoyjCJ6s1MBa52YxDbhdk/tpE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=HwnaW+ansuE/KLHuL50TbNb/x/u5i/E24AnnBwS3TS1DVp8eALK7LzvbQmWTzteZx mzeciWlokf24UG/+F4MLnUJowEahQmDwS70k6ycDAuV+NKtbSYR5wEIeRAsKqQv+uO e1QdDO1kYOSJZzdJwRKwTjP+fZAcHKUszJ/uvfaW0tE9WYwZC6eaUfVU1IdK1bx5cJ 8u4Zb2uzCXt5I5mX6q8uPNtAJNZ86Gei0yuU0JM2hP1vxLojXBHpFfxU4cTRNN6LmD SRjKFm8njhPkBtdLjmhQTAwUl1POvGcxz41M7ZEbySVLcmuUCEn1T1QO2p2mQuPLso OwjLBFhY3cMiw== Date: Thu, 20 Jun 2024 16:03:05 -0700 Subject: [PATCH 18/24] xfs: hoist inode free function to libxfs From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418208.3183075.14235352813217094391.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a libxfs helper function that marks an inode free on disk. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_inode_util.c | 52 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 5 ++++ fs/xfs/xfs_inode.c | 35 +-------------------------- 3 files changed, 58 insertions(+), 34 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index 5795445ef4bd2..032333289113b 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -22,6 +22,7 @@ #include "xfs_trace.h" #include "xfs_ag.h" #include "xfs_iunlink_item.h" +#include "xfs_inode_item.h" uint16_t xfs_flags2diflags( @@ -695,3 +696,54 @@ xfs_bumplink( xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); } + +/* Free an inode in the ondisk index and zero it out. */ +int +xfs_inode_uninit( + struct xfs_trans *tp, + struct xfs_perag *pag, + struct xfs_inode *ip, + struct xfs_icluster *xic) +{ + struct xfs_mount *mp = ip->i_mount; + int error; + + /* + * Free the inode first so that we guarantee that the AGI lock is going + * to be taken before we remove the inode from the unlinked list. This + * makes the AGI lock -> unlinked list modification order the same as + * used in O_TMPFILE creation. + */ + error = xfs_difree(tp, pag, ip->i_ino, xic); + if (error) + return error; + + error = xfs_iunlink_remove(tp, pag, ip); + if (error) + return error; + + /* + * Free any local-format data sitting around before we reset the + * data fork to extents format. Note that the attr fork data has + * already been freed by xfs_attr_inactive. + */ + if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL) { + kfree(ip->i_df.if_data); + ip->i_df.if_data = NULL; + ip->i_df.if_bytes = 0; + } + + VFS_I(ip)->i_mode = 0; /* mark incore inode as free */ + ip->i_diflags = 0; + ip->i_diflags2 = mp->m_ino_geo.new_diflags2; + ip->i_forkoff = 0; /* mark the attr fork not in use */ + ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; + + /* + * Bump the generation count so no one will be confused + * by reincarnations of this inode. + */ + VFS_I(ip)->i_generation++; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + return 0; +} diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h index 1c54c3b0cf262..060242998a230 100644 --- a/fs/xfs/libxfs/xfs_inode_util.h +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -6,6 +6,8 @@ #ifndef __XFS_INODE_UTIL_H__ #define __XFS_INODE_UTIL_H__ +struct xfs_icluster; + uint16_t xfs_flags2diflags(struct xfs_inode *ip, unsigned int xflags); uint64_t xfs_flags2diflags2(struct xfs_inode *ip, unsigned int xflags); uint32_t xfs_dic2xflags(struct xfs_inode *ip); @@ -48,6 +50,9 @@ void xfs_trans_ichgtime(struct xfs_trans *tp, struct xfs_inode *ip, int flags); void xfs_inode_init(struct xfs_trans *tp, const struct xfs_icreate_args *args, struct xfs_inode *ip); +int xfs_inode_uninit(struct xfs_trans *tp, struct xfs_perag *pag, + struct xfs_inode *ip, struct xfs_icluster *xic); + int xfs_iunlink(struct xfs_trans *tp, struct xfs_inode *ip); int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_perag *pag, struct xfs_inode *ip); diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 3ac4ea677ff7d..47d630851398a 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1930,36 +1930,10 @@ xfs_ifree( pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); - /* - * Free the inode first so that we guarantee that the AGI lock is going - * to be taken before we remove the inode from the unlinked list. This - * makes the AGI lock -> unlinked list modification order the same as - * used in O_TMPFILE creation. - */ - error = xfs_difree(tp, pag, ip->i_ino, &xic); + error = xfs_inode_uninit(tp, pag, ip, &xic); if (error) goto out; - error = xfs_iunlink_remove(tp, pag, ip); - if (error) - goto out; - - /* - * Free any local-format data sitting around before we reset the - * data fork to extents format. Note that the attr fork data has - * already been freed by xfs_attr_inactive. - */ - if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL) { - kfree(ip->i_df.if_data); - ip->i_df.if_data = NULL; - ip->i_df.if_bytes = 0; - } - - VFS_I(ip)->i_mode = 0; /* mark incore inode as free */ - ip->i_diflags = 0; - ip->i_diflags2 = mp->m_ino_geo.new_diflags2; - ip->i_forkoff = 0; /* mark the attr fork not in use */ - ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; if (xfs_iflags_test(ip, XFS_IPRESERVE_DM_FIELDS)) xfs_iflags_clear(ip, XFS_IPRESERVE_DM_FIELDS); @@ -1968,13 +1942,6 @@ xfs_ifree( iip->ili_fields &= ~(XFS_ILOG_AOWNER | XFS_ILOG_DOWNER); spin_unlock(&iip->ili_lock); - /* - * Bump the generation count so no one will be confused - * by reincarnations of this inode. - */ - VFS_I(ip)->i_generation++; - xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); - if (xic.deleted) error = xfs_ifree_cluster(tp, pag, ip, &xic); out: From patchwork Thu Jun 20 23:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706489 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 5EF2C7C6EB for ; Thu, 20 Jun 2024 23:03:22 +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=1718924602; cv=none; b=TcewCVJISziEvhMsekyblcx2JQ5vuwevcKR466YKBtx6zZk5zzliP/XMukreEywzwjBXz5hxjEtUZ5/VmFILBgmnVioMjYTu2Zlhq3GhhZgCbfOSMRGgy90GZ2bOKq1x/qzNgzXLQVMJNR6uE+NLvxc3QrW/rXEMaa/YuQAtQJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924602; c=relaxed/simple; bh=+yk9JsDn+DK2VmLSUXwGYrIjyaq/odFQmc1Vs2aqcg0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pyribcjSM5f9/66CX37XEp7yr//E7/nMCgIpBpyin3b07i6tucTgr9LgBq1sRWu4dunk6pP3qASgHFFQXcaopsjGA9aRzxQk1To423VVBZDbucl7qn5RadlfiBGANdVbvvORs8lOVatTsSDjalQJU6K1XAyxosZ79nQhnzxigzU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZFHMc9Bd; 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="ZFHMc9Bd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4C58C2BD10; Thu, 20 Jun 2024 23:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924601; bh=+yk9JsDn+DK2VmLSUXwGYrIjyaq/odFQmc1Vs2aqcg0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZFHMc9BdG3ZN2sLxpIAHguBNYDA0l4P0hmvMD+0zFbesa3Z+Iyaz5Y0wUTAssy+sv IK02PMKdtrCeGXTwjO4jI+Bi1X59tP2I6bwaPkBNksq0Oxf9fk9X4XtcxmvNYifSkH 2ZKq4Z/PTHcmGMtzzo5F3DLrRtHSUGhPYsW8AZd76+YwDPy5IFVsbLYIb9euPRMr1H BuqUe26ZONJ1josoznnLT93oEyLoJC+lCMnAdXzjv1weUblDy9UUU49uAH85IMGQ6V KC6U3d+fTjbN5LRPu/nu67Zlrj7U7DbUB271knFEowhsM/UW8jqd3Iw1ZwTE7kCTPO plGLBMybhlnfQ== Date: Thu, 20 Jun 2024 16:03:21 -0700 Subject: [PATCH 19/24] xfs: create libxfs helper to remove an existing inode/name from a directory From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418225.3183075.15347307047089870669.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a new libxfs function to remove a (name, inode) entry from a directory. The upcoming metadata directory feature will need this to create a metadata directory tree. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_dir2.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 2 + fs/xfs/xfs_inode.c | 74 +++++------------------------------------- 3 files changed, 92 insertions(+), 65 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index 5a75f60e85186..f3ac3d55bc385 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -874,3 +874,84 @@ xfs_dir_add_child( return 0; } + +/* + * Given a directory @dp, a child @ip, and a @name, remove the (@name, @ip) + * entry from the directory. Both inodes must have the ILOCK held. + */ +int +xfs_dir_remove_child( + struct xfs_trans *tp, + unsigned int resblks, + struct xfs_dir_update *du) +{ + struct xfs_inode *dp = du->dp; + const struct xfs_name *name = du->name; + struct xfs_inode *ip = du->ip; + int error; + + xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); + xfs_assert_ilocked(dp, XFS_ILOCK_EXCL); + + /* + * If we're removing a directory perform some additional validation. + */ + if (S_ISDIR(VFS_I(ip)->i_mode)) { + ASSERT(VFS_I(ip)->i_nlink >= 2); + if (VFS_I(ip)->i_nlink != 2) + return -ENOTEMPTY; + if (!xfs_dir_isempty(ip)) + return -ENOTEMPTY; + + /* Drop the link from ip's "..". */ + error = xfs_droplink(tp, dp); + if (error) + return error; + + /* Drop the "." link from ip to self. */ + error = xfs_droplink(tp, ip); + if (error) + return error; + + /* + * Point the unlinked child directory's ".." entry to the root + * directory to eliminate back-references to inodes that may + * get freed before the child directory is closed. If the fs + * gets shrunk, this can lead to dirent inode validation errors. + */ + if (dp->i_ino != tp->t_mountp->m_sb.sb_rootino) { + error = xfs_dir_replace(tp, ip, &xfs_name_dotdot, + tp->t_mountp->m_sb.sb_rootino, 0); + if (error) + return error; + } + } else { + /* + * When removing a non-directory we need to log the parent + * inode here. For a directory this is done implicitly + * by the xfs_droplink call for the ".." entry. + */ + xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); + } + xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); + + /* Drop the link from dp to ip. */ + error = xfs_droplink(tp, ip); + if (error) + return error; + + error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks); + if (error) { + ASSERT(error != -ENOENT); + return error; + } + + /* Remove parent pointer. */ + if (du->ppargs) { + error = xfs_parent_removename(tp, du->ppargs, dp, name, ip); + if (error) + return error; + } + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index 4f9711509571a..c89916d1c040a 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -322,5 +322,7 @@ int xfs_dir_create_child(struct xfs_trans *tp, unsigned int resblks, struct xfs_dir_update *du); int xfs_dir_add_child(struct xfs_trans *tp, unsigned int resblks, struct xfs_dir_update *du); +int xfs_dir_remove_child(struct xfs_trans *tp, unsigned int resblks, + struct xfs_dir_update *du); #endif /* __XFS_DIR2_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 47d630851398a..b70236735339e 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2025,13 +2025,17 @@ xfs_remove( struct xfs_name *name, struct xfs_inode *ip) { + struct xfs_dir_update du = { + .dp = dp, + .name = name, + .ip = ip, + }; struct xfs_mount *mp = dp->i_mount; struct xfs_trans *tp = NULL; int is_dir = S_ISDIR(VFS_I(ip)->i_mode); int dontcare; int error = 0; uint resblks; - struct xfs_parent_args *ppargs; trace_xfs_remove(dp, name); @@ -2048,7 +2052,7 @@ xfs_remove( if (error) goto std_return; - error = xfs_parent_start(mp, &ppargs); + error = xfs_parent_start(mp, &du.ppargs); if (error) goto std_return; @@ -2071,70 +2075,10 @@ xfs_remove( goto out_parent; } - /* - * If we're removing a directory perform some additional validation. - */ - if (is_dir) { - ASSERT(VFS_I(ip)->i_nlink >= 2); - if (VFS_I(ip)->i_nlink != 2) { - error = -ENOTEMPTY; - goto out_trans_cancel; - } - if (!xfs_dir_isempty(ip)) { - error = -ENOTEMPTY; - goto out_trans_cancel; - } - - /* Drop the link from ip's "..". */ - error = xfs_droplink(tp, dp); - if (error) - goto out_trans_cancel; - - /* Drop the "." link from ip to self. */ - error = xfs_droplink(tp, ip); - if (error) - goto out_trans_cancel; - - /* - * Point the unlinked child directory's ".." entry to the root - * directory to eliminate back-references to inodes that may - * get freed before the child directory is closed. If the fs - * gets shrunk, this can lead to dirent inode validation errors. - */ - if (dp->i_ino != tp->t_mountp->m_sb.sb_rootino) { - error = xfs_dir_replace(tp, ip, &xfs_name_dotdot, - tp->t_mountp->m_sb.sb_rootino, 0); - if (error) - goto out_trans_cancel; - } - } else { - /* - * When removing a non-directory we need to log the parent - * inode here. For a directory this is done implicitly - * by the xfs_droplink call for the ".." entry. - */ - xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); - } - xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); - - /* Drop the link from dp to ip. */ - error = xfs_droplink(tp, ip); + error = xfs_dir_remove_child(tp, resblks, &du); if (error) goto out_trans_cancel; - error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks); - if (error) { - ASSERT(error != -ENOENT); - goto out_trans_cancel; - } - - /* Remove parent pointer. */ - if (ppargs) { - error = xfs_parent_removename(tp, ppargs, dp, name, ip); - if (error) - goto out_trans_cancel; - } - /* * Drop the link from dp to ip, and if ip was a directory, remove the * '.' and '..' references since we freed the directory. @@ -2158,7 +2102,7 @@ xfs_remove( xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_iunlock(dp, XFS_ILOCK_EXCL); - xfs_parent_finish(mp, ppargs); + xfs_parent_finish(mp, du.ppargs); return 0; out_trans_cancel: @@ -2167,7 +2111,7 @@ xfs_remove( xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_iunlock(dp, XFS_ILOCK_EXCL); out_parent: - xfs_parent_finish(mp, ppargs); + xfs_parent_finish(mp, du.ppargs); std_return: return error; } From patchwork Thu Jun 20 23:03:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706490 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 AD20E7C6EB for ; Thu, 20 Jun 2024 23:03:37 +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=1718924617; cv=none; b=CvKCwYg2VG4r+2WZ+fZI2/CiPhubyHdAGc9H79qc14HyirYVDIUpLVyx7tCMargHN/wfm48ElH6deM/lsKQ2DxamK05MX3f092k73IjpJFkER9wDgMiR9cp24FzolAFi/MYV4YvdX2pHh9U5USrzMNHX2jSnk5YmqYuc5pLBF4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924617; c=relaxed/simple; bh=LIIc0sZkBQg/7LCrJwJqj0Zefrt9lXasYzZPx4TgBFw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FkKOkGbw3R76ug/ry/EI7BamFfIcgwbCLvZ/mSuIoxjt3fJEsY5878N8/tJ5o/zj1Ga5pTxHsbEAvz9Bd2gZScNZBhtr+dRIR2Xl5kWFfV8+GsiDRQBbkZ/pK/ZNdg+j/x8voBBiYMmAIjn4mlhjwG7XorNcsXuSKdvBJHgmm1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qT1H2TkH; 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="qT1H2TkH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81024C2BD10; Thu, 20 Jun 2024 23:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924617; bh=LIIc0sZkBQg/7LCrJwJqj0Zefrt9lXasYzZPx4TgBFw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qT1H2TkH0XTsLC5y8B4f8bv7brkUNzdfSMj9ocWQcOB/7ZphTsJQfvI3wUmM+6Sk9 68J/XDKtYAStZD99axGZNMstg/T4P6xk5+6eJg5bKvoSd9Er84w+6xd1Kb+4b+1+US B6xbJYEG0givt4qlnRvv3yDoPg79hL4RhZA8NViV60SRAhQdSu7dP1jUjxvsex20uS 2+sBslJuBsdMfCnWw2zz+vUx/c2l4RPFEmQWbTCqQeVFgRB2VidWNC2CTZALprPacl +bJhXToZh8+k0ZLCNozIReDcYo4mo/+U6lrLsN7dEuSsdielAOGUjOKIQSus3tPteN cGwWzsupE1sxA== Date: Thu, 20 Jun 2024 16:03:37 -0700 Subject: [PATCH 20/24] xfs: create libxfs helper to exchange two directory entries From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418243.3183075.4229000093376845892.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a new libxfs function to exchange two directory entries. The upcoming metadata directory feature will need this to replace a metadata inode directory entry. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_dir2.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 3 + fs/xfs/xfs_inode.c | 114 ++++++------------------------------------ 3 files changed, 143 insertions(+), 99 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index f3ac3d55bc385..d650cfa023fdb 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -955,3 +955,128 @@ xfs_dir_remove_child( return 0; } + +/* + * Exchange the entry (@name1, @ip1) in directory @dp1 with the entry (@name2, + * @ip2) in directory @dp2, and update '..' @ip1 and @ip2's entries as needed. + * @ip1 and @ip2 need not be of the same type. + * + * All inodes must have the ILOCK held, and both entries must already exist. + */ +int +xfs_dir_exchange_children( + struct xfs_trans *tp, + struct xfs_dir_update *du1, + struct xfs_dir_update *du2, + unsigned int spaceres) +{ + struct xfs_inode *dp1 = du1->dp; + const struct xfs_name *name1 = du1->name; + struct xfs_inode *ip1 = du1->ip; + struct xfs_inode *dp2 = du2->dp; + const struct xfs_name *name2 = du2->name; + struct xfs_inode *ip2 = du2->ip; + int ip1_flags = 0; + int ip2_flags = 0; + int dp2_flags = 0; + int error; + + /* Swap inode number for dirent in first parent */ + error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres); + if (error) + return error; + + /* Swap inode number for dirent in second parent */ + error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres); + if (error) + return error; + + /* + * If we're renaming one or more directories across different parents, + * update the respective ".." entries (and link counts) to match the new + * parents. + */ + if (dp1 != dp2) { + dp2_flags = XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG; + + if (S_ISDIR(VFS_I(ip2)->i_mode)) { + error = xfs_dir_replace(tp, ip2, &xfs_name_dotdot, + dp1->i_ino, spaceres); + if (error) + return error; + + /* transfer ip2 ".." reference to dp1 */ + if (!S_ISDIR(VFS_I(ip1)->i_mode)) { + error = xfs_droplink(tp, dp2); + if (error) + return error; + xfs_bumplink(tp, dp1); + } + + /* + * Although ip1 isn't changed here, userspace needs + * to be warned about the change, so that applications + * relying on it (like backup ones), will properly + * notify the change + */ + ip1_flags |= XFS_ICHGTIME_CHG; + ip2_flags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG; + } + + if (S_ISDIR(VFS_I(ip1)->i_mode)) { + error = xfs_dir_replace(tp, ip1, &xfs_name_dotdot, + dp2->i_ino, spaceres); + if (error) + return error; + + /* transfer ip1 ".." reference to dp2 */ + if (!S_ISDIR(VFS_I(ip2)->i_mode)) { + error = xfs_droplink(tp, dp1); + if (error) + return error; + xfs_bumplink(tp, dp2); + } + + /* + * Although ip2 isn't changed here, userspace needs + * to be warned about the change, so that applications + * relying on it (like backup ones), will properly + * notify the change + */ + ip1_flags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG; + ip2_flags |= XFS_ICHGTIME_CHG; + } + } + + if (ip1_flags) { + xfs_trans_ichgtime(tp, ip1, ip1_flags); + xfs_trans_log_inode(tp, ip1, XFS_ILOG_CORE); + } + if (ip2_flags) { + xfs_trans_ichgtime(tp, ip2, ip2_flags); + xfs_trans_log_inode(tp, ip2, XFS_ILOG_CORE); + } + if (dp2_flags) { + xfs_trans_ichgtime(tp, dp2, dp2_flags); + xfs_trans_log_inode(tp, dp2, XFS_ILOG_CORE); + } + xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); + xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE); + + /* Schedule parent pointer replacements */ + if (du1->ppargs) { + error = xfs_parent_replacename(tp, du1->ppargs, dp1, name1, + dp2, name2, ip1); + if (error) + return error; + } + + if (du2->ppargs) { + error = xfs_parent_replacename(tp, du2->ppargs, dp2, name2, + dp1, name1, ip2); + if (error) + return error; + } + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index c89916d1c040a..8b1e192bd7a83 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -325,4 +325,7 @@ int xfs_dir_add_child(struct xfs_trans *tp, unsigned int resblks, int xfs_dir_remove_child(struct xfs_trans *tp, unsigned int resblks, struct xfs_dir_update *du); +int xfs_dir_exchange_children(struct xfs_trans *tp, struct xfs_dir_update *du1, + struct xfs_dir_update *du2, unsigned int spaceres); + #endif /* __XFS_DIR2_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index b70236735339e..d65c2dc3af145 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2223,108 +2223,24 @@ xfs_cross_rename( struct xfs_parent_args *ip2_ppargs, int spaceres) { - int error = 0; - int ip1_flags = 0; - int ip2_flags = 0; - int dp2_flags = 0; - - /* Swap inode number for dirent in first parent */ - error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres); - if (error) - goto out_trans_abort; - - /* Swap inode number for dirent in second parent */ - error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres); + struct xfs_dir_update du1 = { + .dp = dp1, + .name = name1, + .ip = ip1, + .ppargs = ip1_ppargs, + }; + struct xfs_dir_update du2 = { + .dp = dp2, + .name = name2, + .ip = ip2, + .ppargs = ip2_ppargs, + }; + int error; + + error = xfs_dir_exchange_children(tp, &du1, &du2, spaceres); if (error) goto out_trans_abort; - /* - * If we're renaming one or more directories across different parents, - * update the respective ".." entries (and link counts) to match the new - * parents. - */ - if (dp1 != dp2) { - dp2_flags = XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG; - - if (S_ISDIR(VFS_I(ip2)->i_mode)) { - error = xfs_dir_replace(tp, ip2, &xfs_name_dotdot, - dp1->i_ino, spaceres); - if (error) - goto out_trans_abort; - - /* transfer ip2 ".." reference to dp1 */ - if (!S_ISDIR(VFS_I(ip1)->i_mode)) { - error = xfs_droplink(tp, dp2); - if (error) - goto out_trans_abort; - xfs_bumplink(tp, dp1); - } - - /* - * Although ip1 isn't changed here, userspace needs - * to be warned about the change, so that applications - * relying on it (like backup ones), will properly - * notify the change - */ - ip1_flags |= XFS_ICHGTIME_CHG; - ip2_flags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG; - } - - if (S_ISDIR(VFS_I(ip1)->i_mode)) { - error = xfs_dir_replace(tp, ip1, &xfs_name_dotdot, - dp2->i_ino, spaceres); - if (error) - goto out_trans_abort; - - /* transfer ip1 ".." reference to dp2 */ - if (!S_ISDIR(VFS_I(ip2)->i_mode)) { - error = xfs_droplink(tp, dp1); - if (error) - goto out_trans_abort; - xfs_bumplink(tp, dp2); - } - - /* - * Although ip2 isn't changed here, userspace needs - * to be warned about the change, so that applications - * relying on it (like backup ones), will properly - * notify the change - */ - ip1_flags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG; - ip2_flags |= XFS_ICHGTIME_CHG; - } - } - - /* Schedule parent pointer replacements */ - if (ip1_ppargs) { - error = xfs_parent_replacename(tp, ip1_ppargs, dp1, name1, dp2, - name2, ip1); - if (error) - goto out_trans_abort; - } - - if (ip2_ppargs) { - error = xfs_parent_replacename(tp, ip2_ppargs, dp2, name2, dp1, - name1, ip2); - if (error) - goto out_trans_abort; - } - - if (ip1_flags) { - xfs_trans_ichgtime(tp, ip1, ip1_flags); - xfs_trans_log_inode(tp, ip1, XFS_ILOG_CORE); - } - if (ip2_flags) { - xfs_trans_ichgtime(tp, ip2, ip2_flags); - xfs_trans_log_inode(tp, ip2, XFS_ILOG_CORE); - } - if (dp2_flags) { - xfs_trans_ichgtime(tp, dp2, dp2_flags); - xfs_trans_log_inode(tp, dp2, XFS_ILOG_CORE); - } - xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); - xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE); - /* * Inform our hook clients that we've finished an exchange operation as * follows: removed the source and target files from their directories; From patchwork Thu Jun 20 23:03:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706491 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 569F87C6EB for ; Thu, 20 Jun 2024 23:03:53 +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=1718924633; cv=none; b=lqh8X42ltQEuoAIOTRMmq8pJjZxv8QX09zS+HVzLLpN/3NbieUH4MUE2eUC2F85WSRnpzgzEh/UZzsM/EeiEK2bdQm4hLOhh3oFyPm6HVJqNq3kUTHR7TiiiXRIzqXN14qCRbWEyaGx3ciHSy1d5P39nfwnbNpiU4LQ2EBbLE9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924633; c=relaxed/simple; bh=52sAslYHwjKb55YV4McTB6nxrsdvESOqq9ppOCTa7p0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MMW85Ht9YBHVRMzsmjy5rou4HWnRAQD8DC7nShA+Biv6VGXifdkmP0oKE55J2qdhK7iSpMXBPkC1u9pR65/qc9dQCSvRwAjsRHoP5CRenS6PmtK9vfbKGV+6kuQcWi7lJ16ZhPYHpaupUZ1QivFJrUArz+DV5dE3tVi9cewfWzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pk4BtJUl; 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="Pk4BtJUl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 299ADC32781; Thu, 20 Jun 2024 23:03:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924633; bh=52sAslYHwjKb55YV4McTB6nxrsdvESOqq9ppOCTa7p0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Pk4BtJUlfbiCjO/KgDhRWtwwpSKJsUDLF3I5rl03ls6LPTeqqgDWoqCnvaC53Rqtn jcbp0vORTP+idwdUMRtDvoun08Fz4hI0UwdXY7C/IxZvCag76ii7JX32kLvsd3TkaF PTpr/VFW9Jfi15cgExblMj1FoFQf0BryFDfnR468dlHZfE71iiIB+n7u0KaBB2GGRn wYbOh9NfHQ0wv2rqMrbXBLItmokoIMzMFcIx0hVuEdmJRl3IaN6m/Kfi2S1T6c9aLt xcEIVvGayV4hudbtLJw/esbsXJum1sdY1SqwdDCxv95lHLaOWFL959TduaMst8tQcU hK0GWwwShplPg== Date: Thu, 20 Jun 2024 16:03:52 -0700 Subject: [PATCH 21/24] xfs: create libxfs helper to rename two directory entries From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418260.3183075.5528355196436694451.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a new libxfs function to rename two directory entries. The upcoming metadata directory feature will need this to replace a metadata inode directory entry. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_dir2.c | 227 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 3 + fs/xfs/xfs_inode.c | 258 ++++++++-------------------------------------- 3 files changed, 273 insertions(+), 215 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index d650cfa023fdb..34b63ba2e4f71 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -23,6 +23,7 @@ #include "xfs_trans_space.h" #include "xfs_parent.h" #include "xfs_ag.h" +#include "xfs_ialloc.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)"..", @@ -1080,3 +1081,229 @@ xfs_dir_exchange_children( return 0; } + +/* + * Given an entry (@src_name, @src_ip) in directory @src_dp, make the entry + * @target_name in directory @target_dp point to @src_ip and remove the + * original entry, cleaning up everything left behind. + * + * Cleanup involves dropping a link count on @target_ip, and either removing + * the (@src_name, @src_ip) entry from @src_dp or simply replacing the entry + * with (@src_name, @wip) if a whiteout inode @wip is supplied. + * + * All inodes must have the ILOCK held. We assume that if @src_ip is a + * directory then its '..' doesn't already point to @target_dp, and that @wip + * is a freshly allocated whiteout. + */ +int +xfs_dir_rename_children( + struct xfs_trans *tp, + struct xfs_dir_update *du_src, + struct xfs_dir_update *du_tgt, + unsigned int spaceres, + struct xfs_dir_update *du_wip) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_inode *src_dp = du_src->dp; + const struct xfs_name *src_name = du_src->name; + struct xfs_inode *src_ip = du_src->ip; + struct xfs_inode *target_dp = du_tgt->dp; + const struct xfs_name *target_name = du_tgt->name; + struct xfs_inode *target_ip = du_tgt->ip; + bool new_parent = (src_dp != target_dp); + bool src_is_directory; + int error; + + src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode); + + /* + * Check for expected errors before we dirty the transaction + * so we can return an error without a transaction abort. + */ + if (target_ip == NULL) { + /* + * If there's no space reservation, check the entry will + * fit before actually inserting it. + */ + if (!spaceres) { + error = xfs_dir_canenter(tp, target_dp, target_name); + if (error) + return error; + } + } else { + /* + * If target exists and it's a directory, check that whether + * it can be destroyed. + */ + if (S_ISDIR(VFS_I(target_ip)->i_mode) && + (!xfs_dir_isempty(target_ip) || + (VFS_I(target_ip)->i_nlink > 2))) + return -EEXIST; + } + + /* + * Directory entry creation below may acquire the AGF. Remove + * the whiteout from the unlinked list first to preserve correct + * AGI/AGF locking order. This dirties the transaction so failures + * after this point will abort and log recovery will clean up the + * mess. + * + * For whiteouts, we need to bump the link count on the whiteout + * inode. After this point, we have a real link, clear the tmpfile + * state flag from the inode so it doesn't accidentally get misused + * in future. + */ + if (du_wip->ip) { + struct xfs_perag *pag; + + ASSERT(VFS_I(du_wip->ip)->i_nlink == 0); + + pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, du_wip->ip->i_ino)); + error = xfs_iunlink_remove(tp, pag, du_wip->ip); + xfs_perag_put(pag); + if (error) + return error; + + xfs_bumplink(tp, du_wip->ip); + } + + /* + * Set up the target. + */ + if (target_ip == NULL) { + /* + * If target does not exist and the rename crosses + * directories, adjust the target directory link count + * to account for the ".." reference from the new entry. + */ + error = xfs_dir_createname(tp, target_dp, target_name, + src_ip->i_ino, spaceres); + if (error) + return error; + + xfs_trans_ichgtime(tp, target_dp, + XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); + + if (new_parent && src_is_directory) { + xfs_bumplink(tp, target_dp); + } + } else { /* target_ip != NULL */ + /* + * Link the source inode under the target name. + * If the source inode is a directory and we are moving + * it across directories, its ".." entry will be + * inconsistent until we replace that down below. + * + * In case there is already an entry with the same + * name at the destination directory, remove it first. + */ + error = xfs_dir_replace(tp, target_dp, target_name, + src_ip->i_ino, spaceres); + if (error) + return error; + + xfs_trans_ichgtime(tp, target_dp, + XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); + + /* + * Decrement the link count on the target since the target + * dir no longer points to it. + */ + error = xfs_droplink(tp, target_ip); + if (error) + return error; + + if (src_is_directory) { + /* + * Drop the link from the old "." entry. + */ + error = xfs_droplink(tp, target_ip); + if (error) + return error; + } + } /* target_ip != NULL */ + + /* + * Remove the source. + */ + if (new_parent && src_is_directory) { + /* + * Rewrite the ".." entry to point to the new + * directory. + */ + error = xfs_dir_replace(tp, src_ip, &xfs_name_dotdot, + target_dp->i_ino, spaceres); + ASSERT(error != -EEXIST); + if (error) + return error; + } + + /* + * We always want to hit the ctime on the source inode. + * + * This isn't strictly required by the standards since the source + * inode isn't really being changed, but old unix file systems did + * it and some incremental backup programs won't work without it. + */ + xfs_trans_ichgtime(tp, src_ip, XFS_ICHGTIME_CHG); + xfs_trans_log_inode(tp, src_ip, XFS_ILOG_CORE); + + /* + * Adjust the link count on src_dp. This is necessary when + * renaming a directory, either within one parent when + * the target existed, or across two parent directories. + */ + if (src_is_directory && (new_parent || target_ip != NULL)) { + + /* + * Decrement link count on src_directory since the + * entry that's moved no longer points to it. + */ + error = xfs_droplink(tp, src_dp); + if (error) + return error; + } + + /* + * For whiteouts, we only need to update the source dirent with the + * inode number of the whiteout inode rather than removing it + * altogether. + */ + if (du_wip->ip) + error = xfs_dir_replace(tp, src_dp, src_name, du_wip->ip->i_ino, + spaceres); + else + error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, + spaceres); + if (error) + return error; + + xfs_trans_ichgtime(tp, src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); + xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE); + if (new_parent) + xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE); + + /* Schedule parent pointer updates. */ + if (du_wip->ppargs) { + error = xfs_parent_addname(tp, du_wip->ppargs, src_dp, + src_name, du_wip->ip); + if (error) + return error; + } + + if (du_src->ppargs) { + error = xfs_parent_replacename(tp, du_src->ppargs, src_dp, + src_name, target_dp, target_name, src_ip); + if (error) + return error; + } + + if (du_tgt->ppargs) { + error = xfs_parent_removename(tp, du_tgt->ppargs, target_dp, + target_name, target_ip); + if (error) + return error; + } + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index 8b1e192bd7a83..df6d4bbe3d6f9 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -327,5 +327,8 @@ int xfs_dir_remove_child(struct xfs_trans *tp, unsigned int resblks, int xfs_dir_exchange_children(struct xfs_trans *tp, struct xfs_dir_update *du1, struct xfs_dir_update *du2, unsigned int spaceres); +int xfs_dir_rename_children(struct xfs_trans *tp, struct xfs_dir_update *du_src, + struct xfs_dir_update *du_tgt, unsigned int spaceres, + struct xfs_dir_update *du_wip); #endif /* __XFS_DIR2_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index d65c2dc3af145..99bd811b309d8 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2326,13 +2326,20 @@ xfs_rename( struct xfs_inode *target_ip, unsigned int flags) { + struct xfs_dir_update du_src = { + .dp = src_dp, + .name = src_name, + .ip = src_ip, + }; + struct xfs_dir_update du_tgt = { + .dp = target_dp, + .name = target_name, + .ip = target_ip, + }; + struct xfs_dir_update du_wip = { }; struct xfs_mount *mp = src_dp->i_mount; struct xfs_trans *tp; - struct xfs_inode *wip = NULL; /* whiteout inode */ struct xfs_inode *inodes[__XFS_SORT_INODES]; - struct xfs_parent_args *src_ppargs = NULL; - struct xfs_parent_args *tgt_ppargs = NULL; - struct xfs_parent_args *wip_ppargs = NULL; int i; int num_inodes = __XFS_SORT_INODES; bool new_parent = (src_dp != target_dp); @@ -2352,8 +2359,8 @@ xfs_rename( * appropriately. */ if (flags & RENAME_WHITEOUT) { - error = xfs_rename_alloc_whiteout(idmap, src_name, - target_dp, &wip); + error = xfs_rename_alloc_whiteout(idmap, src_name, target_dp, + &du_wip.ip); if (error) return error; @@ -2361,21 +2368,21 @@ xfs_rename( src_name->type = XFS_DIR3_FT_CHRDEV; } - xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, wip, - inodes, &num_inodes); + xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, du_wip.ip, + inodes, &num_inodes); - error = xfs_parent_start(mp, &src_ppargs); + error = xfs_parent_start(mp, &du_src.ppargs); if (error) goto out_release_wip; - if (wip) { - error = xfs_parent_start(mp, &wip_ppargs); + if (du_wip.ip) { + error = xfs_parent_start(mp, &du_wip.ppargs); if (error) goto out_src_ppargs; } if (target_ip) { - error = xfs_parent_start(mp, &tgt_ppargs); + error = xfs_parent_start(mp, &du_tgt.ppargs); if (error) goto out_wip_ppargs; } @@ -2383,7 +2390,7 @@ xfs_rename( retry: nospace_error = 0; spaceres = xfs_rename_space_res(mp, src_name->len, target_ip != NULL, - target_name->len, wip != NULL); + target_name->len, du_wip.ip != NULL); error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, spaceres, 0, 0, &tp); if (error == -ENOSPC) { nospace_error = error; @@ -2398,7 +2405,7 @@ xfs_rename( * We don't allow reservationless renaming when parent pointers are * enabled because we can't back out if the xattrs must grow. */ - if (src_ppargs && nospace_error) { + if (du_src.ppargs && nospace_error) { error = nospace_error; xfs_trans_cancel(tp); goto out_tgt_ppargs; @@ -2430,8 +2437,8 @@ xfs_rename( xfs_trans_ijoin(tp, src_ip, 0); if (target_ip) xfs_trans_ijoin(tp, target_ip, 0); - if (wip) - xfs_trans_ijoin(tp, wip, 0); + if (du_wip.ip) + xfs_trans_ijoin(tp, du_wip.ip, 0); /* * If we are using project inheritance, we only allow renames @@ -2447,8 +2454,8 @@ xfs_rename( /* RENAME_EXCHANGE is unique from here on. */ if (flags & RENAME_EXCHANGE) { error = xfs_cross_rename(tp, src_dp, src_name, src_ip, - src_ppargs, target_dp, target_name, target_ip, - tgt_ppargs, spaceres); + du_src.ppargs, target_dp, target_name, + target_ip, du_tgt.ppargs, spaceres); nospace_error = 0; goto out_unlock; } @@ -2483,38 +2490,11 @@ xfs_rename( * We don't allow quotaless renaming when parent pointers are enabled * because we can't back out if the xattrs must grow. */ - if (src_ppargs && nospace_error) { + if (du_src.ppargs && nospace_error) { error = nospace_error; goto out_trans_cancel; } - /* - * Check for expected errors before we dirty the transaction - * so we can return an error without a transaction abort. - */ - if (target_ip == NULL) { - /* - * If there's no space reservation, check the entry will - * fit before actually inserting it. - */ - if (!spaceres) { - error = xfs_dir_canenter(tp, target_dp, target_name); - if (error) - goto out_trans_cancel; - } - } else { - /* - * If target exists and it's a directory, check that whether - * it can be destroyed. - */ - if (S_ISDIR(VFS_I(target_ip)->i_mode) && - (!xfs_dir_isempty(target_ip) || - (VFS_I(target_ip)->i_nlink > 2))) { - error = -EEXIST; - goto out_trans_cancel; - } - } - /* * Lock the AGI buffers we need to handle bumping the nlink of the * whiteout inode off the unlinked list and to handle dropping the @@ -2526,7 +2506,7 @@ xfs_rename( * target_ip is either null or an empty directory. */ for (i = 0; i < num_inodes && inodes[i] != NULL; i++) { - if (inodes[i] == wip || + if (inodes[i] == du_wip.ip || (inodes[i] == target_ip && (VFS_I(target_ip)->i_nlink == 1 || src_is_directory))) { struct xfs_perag *pag; @@ -2541,172 +2521,20 @@ xfs_rename( } } - /* - * Directory entry creation below may acquire the AGF. Remove - * the whiteout from the unlinked list first to preserve correct - * AGI/AGF locking order. This dirties the transaction so failures - * after this point will abort and log recovery will clean up the - * mess. - * - * For whiteouts, we need to bump the link count on the whiteout - * inode. After this point, we have a real link, clear the tmpfile - * state flag from the inode so it doesn't accidentally get misused - * in future. - */ - if (wip) { - struct xfs_perag *pag; - - ASSERT(VFS_I(wip)->i_nlink == 0); - - pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, wip->i_ino)); - error = xfs_iunlink_remove(tp, pag, wip); - xfs_perag_put(pag); - if (error) - goto out_trans_cancel; - - xfs_bumplink(tp, wip); - VFS_I(wip)->i_state &= ~I_LINKABLE; - } - - /* - * Set up the target. - */ - if (target_ip == NULL) { - /* - * If target does not exist and the rename crosses - * directories, adjust the target directory link count - * to account for the ".." reference from the new entry. - */ - error = xfs_dir_createname(tp, target_dp, target_name, - src_ip->i_ino, spaceres); - if (error) - goto out_trans_cancel; - - xfs_trans_ichgtime(tp, target_dp, - XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); - - if (new_parent && src_is_directory) { - xfs_bumplink(tp, target_dp); - } - } else { /* target_ip != NULL */ - /* - * Link the source inode under the target name. - * If the source inode is a directory and we are moving - * it across directories, its ".." entry will be - * inconsistent until we replace that down below. - * - * In case there is already an entry with the same - * name at the destination directory, remove it first. - */ - error = xfs_dir_replace(tp, target_dp, target_name, - src_ip->i_ino, spaceres); - if (error) - goto out_trans_cancel; - - xfs_trans_ichgtime(tp, target_dp, - XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); - - /* - * Decrement the link count on the target since the target - * dir no longer points to it. - */ - error = xfs_droplink(tp, target_ip); - if (error) - goto out_trans_cancel; - - if (src_is_directory) { - /* - * Drop the link from the old "." entry. - */ - error = xfs_droplink(tp, target_ip); - if (error) - goto out_trans_cancel; - } - } /* target_ip != NULL */ - - /* - * Remove the source. - */ - if (new_parent && src_is_directory) { - /* - * Rewrite the ".." entry to point to the new - * directory. - */ - error = xfs_dir_replace(tp, src_ip, &xfs_name_dotdot, - target_dp->i_ino, spaceres); - ASSERT(error != -EEXIST); - if (error) - goto out_trans_cancel; - } - - /* - * We always want to hit the ctime on the source inode. - * - * This isn't strictly required by the standards since the source - * inode isn't really being changed, but old unix file systems did - * it and some incremental backup programs won't work without it. - */ - xfs_trans_ichgtime(tp, src_ip, XFS_ICHGTIME_CHG); - xfs_trans_log_inode(tp, src_ip, XFS_ILOG_CORE); - - /* - * Adjust the link count on src_dp. This is necessary when - * renaming a directory, either within one parent when - * the target existed, or across two parent directories. - */ - if (src_is_directory && (new_parent || target_ip != NULL)) { - - /* - * Decrement link count on src_directory since the - * entry that's moved no longer points to it. - */ - error = xfs_droplink(tp, src_dp); - if (error) - goto out_trans_cancel; - } - - /* - * For whiteouts, we only need to update the source dirent with the - * inode number of the whiteout inode rather than removing it - * altogether. - */ - if (wip) - error = xfs_dir_replace(tp, src_dp, src_name, wip->i_ino, - spaceres); - else - error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, - spaceres); - + error = xfs_dir_rename_children(tp, &du_src, &du_tgt, spaceres, + &du_wip); if (error) goto out_trans_cancel; - /* Schedule parent pointer updates. */ - if (wip_ppargs) { - error = xfs_parent_addname(tp, wip_ppargs, src_dp, src_name, - wip); - if (error) - goto out_trans_cancel; + if (du_wip.ip) { + /* + * Now we have a real link, clear the "I'm a tmpfile" state + * flag from the inode so it doesn't accidentally get misused in + * future. + */ + VFS_I(du_wip.ip)->i_state &= ~I_LINKABLE; } - if (src_ppargs) { - error = xfs_parent_replacename(tp, src_ppargs, src_dp, - src_name, target_dp, target_name, src_ip); - if (error) - goto out_trans_cancel; - } - - if (tgt_ppargs) { - error = xfs_parent_removename(tp, tgt_ppargs, target_dp, - target_name, target_ip); - if (error) - goto out_trans_cancel; - } - - xfs_trans_ichgtime(tp, src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); - xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE); - if (new_parent) - xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE); - /* * Inform our hook clients that we've finished a rename operation as * follows: removed the source and target files from their directories; @@ -2719,8 +2547,8 @@ xfs_rename( xfs_dir_update_hook(target_dp, target_ip, -1, target_name); xfs_dir_update_hook(src_dp, src_ip, -1, src_name); xfs_dir_update_hook(target_dp, src_ip, 1, target_name); - if (wip) - xfs_dir_update_hook(src_dp, wip, 1, src_name); + if (du_wip.ip) + xfs_dir_update_hook(src_dp, du_wip.ip, 1, src_name); error = xfs_finish_rename(tp); nospace_error = 0; @@ -2731,14 +2559,14 @@ xfs_rename( out_unlock: xfs_iunlock_rename(inodes, num_inodes); out_tgt_ppargs: - xfs_parent_finish(mp, tgt_ppargs); + xfs_parent_finish(mp, du_tgt.ppargs); out_wip_ppargs: - xfs_parent_finish(mp, wip_ppargs); + xfs_parent_finish(mp, du_wip.ppargs); out_src_ppargs: - xfs_parent_finish(mp, src_ppargs); + xfs_parent_finish(mp, du_src.ppargs); out_release_wip: - if (wip) - xfs_irele(wip); + if (du_wip.ip) + xfs_irele(du_wip.ip); if (error == -ENOSPC && nospace_error) error = nospace_error; return error; From patchwork Thu Jun 20 23:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706492 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 ECC207C6EB for ; Thu, 20 Jun 2024 23:04:08 +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=1718924649; cv=none; b=JdIpG94xyzF4TlbJ9zSPJVwrGea1ToOF5mX7eJhNY93k9nQ6E0bGMf1f4ONPbIDs64FxtCKzbCVc94BBhBHvnMWWJXf+FTnWOfuLmN6QsehkT41ooNzV8tFTERDNdhy+Vu0KPORf94eNQUmWh8lHejoP1AR4wXNWN3/Z4Yo0aEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924649; c=relaxed/simple; bh=VfmA4h1asL7/Ph1DfPkpRVX/H/BLGhWETEqoUSqHK04=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AB8dTijP5dvX1LfuiQbApP5p5eo4NEzjUyv1jKLge2qO+J7hW6cFAyY5OwmOy72ZjkXC/YM5L/dBMB6+lrzSx3834/oDCsUBg4GiVe7BHN5i8UuP0TPRW+SOZwKvFaLtsL0yqinrsWRZBTId5kriVV7cuOBjNWSLyPF6jjMDVaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Vi6Ec0XT; 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="Vi6Ec0XT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6C65C2BD10; Thu, 20 Jun 2024 23:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924648; bh=VfmA4h1asL7/Ph1DfPkpRVX/H/BLGhWETEqoUSqHK04=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Vi6Ec0XTgjleWj83LblMJWWJVkPZQa/nPADRU9fjBbQB3S7lwmJm4rHGDR0tzlDkP FVWOw7yX+nCERhnmj+tdJoJV+4SOQx5NrARiYgrbHa3pbv5toGZBTarsi+1vDTCRRm oguOxiRjaVzX/H15q1u/VDoPPzUHwqfQdUeK311LFMjseolMUfPuvIl+KaOy1mIFFd JySeAnby+RuQKL8eMZtGTJEGkyCgmkYvm6kPq1oZ7AAKudDN3+TsGoKpeg6xuJYJ56 bW/jLVjuJ5ZTa7fizn8KM6DzaNElSqOq4l9O7L1epovzN7/P6/TwVLEXt9SBHn8iep Wjmfp3mEvGT8g== Date: Thu, 20 Jun 2024 16:04:08 -0700 Subject: [PATCH 22/24] xfs: move dirent update hooks to xfs_dir2.c From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418278.3183075.2874879886308264652.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move the directory entry update hook code to xfs_dir2 so that it is mostly consolidated with the higher level directory functions. Retain the exports so that online fsck can still send notifications through the hooks. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_dir2.c | 104 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 25 ++++++++++ fs/xfs/scrub/common.c | 1 fs/xfs/xfs_inode.c | 117 ---------------------------------------------- fs/xfs/xfs_inode.h | 25 ---------- fs/xfs/xfs_symlink.c | 2 - 6 files changed, 130 insertions(+), 144 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index 34b63ba2e4f71..202468223bf94 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -762,6 +762,81 @@ xfs_dir2_compname( return xfs_da_compname(args, name, len); } +#ifdef CONFIG_XFS_LIVE_HOOKS +/* + * Use a static key here to reduce the overhead of directory live update hooks. + * If the compiler supports jump labels, the static branch will be replaced by + * a nop sled when there are no hook users. Online fsck is currently the only + * caller, so this is a reasonable tradeoff. + * + * Note: Patching the kernel code requires taking the cpu hotplug lock. Other + * parts of the kernel allocate memory with that lock held, which means that + * XFS callers cannot hold any locks that might be used by memory reclaim or + * writeback when calling the static_branch_{inc,dec} functions. + */ +DEFINE_STATIC_XFS_HOOK_SWITCH(xfs_dir_hooks_switch); + +void +xfs_dir_hook_disable(void) +{ + xfs_hooks_switch_off(&xfs_dir_hooks_switch); +} + +void +xfs_dir_hook_enable(void) +{ + xfs_hooks_switch_on(&xfs_dir_hooks_switch); +} + +/* Call hooks for a directory update relating to a child dirent update. */ +inline void +xfs_dir_update_hook( + struct xfs_inode *dp, + struct xfs_inode *ip, + int delta, + const struct xfs_name *name) +{ + if (xfs_hooks_switched_on(&xfs_dir_hooks_switch)) { + struct xfs_dir_update_params p = { + .dp = dp, + .ip = ip, + .delta = delta, + .name = name, + }; + struct xfs_mount *mp = ip->i_mount; + + xfs_hooks_call(&mp->m_dir_update_hooks, 0, &p); + } +} + +/* Call the specified function during a directory update. */ +int +xfs_dir_hook_add( + struct xfs_mount *mp, + struct xfs_dir_hook *hook) +{ + return xfs_hooks_add(&mp->m_dir_update_hooks, &hook->dirent_hook); +} + +/* Stop calling the specified function during a directory update. */ +void +xfs_dir_hook_del( + struct xfs_mount *mp, + struct xfs_dir_hook *hook) +{ + xfs_hooks_del(&mp->m_dir_update_hooks, &hook->dirent_hook); +} + +/* Configure directory update hook functions. */ +void +xfs_dir_hook_setup( + struct xfs_dir_hook *hook, + notifier_fn_t mod_fn) +{ + xfs_hook_setup(&hook->dirent_hook, mod_fn); +} +#endif /* CONFIG_XFS_LIVE_HOOKS */ + /* * Given a directory @dp, a newly allocated inode @ip, and a @name, link @ip * into @dp under the given @name. If @ip is a directory, it will be @@ -809,6 +884,7 @@ xfs_dir_create_child( return error; } + xfs_dir_update_hook(dp, ip, 1, name); return 0; } @@ -873,6 +949,7 @@ xfs_dir_add_child( return error; } + xfs_dir_update_hook(dp, ip, 1, name); return 0; } @@ -954,6 +1031,7 @@ xfs_dir_remove_child( return error; } + xfs_dir_update_hook(dp, ip, -1, name); return 0; } @@ -1079,6 +1157,18 @@ xfs_dir_exchange_children( return error; } + /* + * Inform our hook clients that we've finished an exchange operation as + * follows: removed the source and target files from their directories; + * added the target to the source directory; and added the source to + * the target directory. All inodes are locked, so it's ok to model a + * rename this way so long as we say we deleted entries before we add + * new ones. + */ + xfs_dir_update_hook(dp1, ip1, -1, name1); + xfs_dir_update_hook(dp2, ip2, -1, name2); + xfs_dir_update_hook(dp1, ip2, 1, name1); + xfs_dir_update_hook(dp2, ip1, 1, name2); return 0; } @@ -1305,5 +1395,19 @@ xfs_dir_rename_children( return error; } + /* + * Inform our hook clients that we've finished a rename operation as + * follows: removed the source and target files from their directories; + * that we've added the source to the target directory; and finally + * that we've added the whiteout, if there was one. All inodes are + * locked, so it's ok to model a rename this way so long as we say we + * deleted entries before we add new ones. + */ + if (target_ip) + xfs_dir_update_hook(target_dp, target_ip, -1, target_name); + xfs_dir_update_hook(src_dp, src_ip, -1, src_name); + xfs_dir_update_hook(target_dp, src_ip, 1, target_name); + if (du_wip->ip) + xfs_dir_update_hook(src_dp, du_wip->ip, 1, src_name); return 0; } diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index df6d4bbe3d6f9..576068ed81fac 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -309,6 +309,31 @@ static inline unsigned char xfs_ascii_ci_xfrm(unsigned char c) return c; } +struct xfs_dir_update_params { + const struct xfs_inode *dp; + const struct xfs_inode *ip; + const struct xfs_name *name; + int delta; +}; + +#ifdef CONFIG_XFS_LIVE_HOOKS +void xfs_dir_update_hook(struct xfs_inode *dp, struct xfs_inode *ip, + int delta, const struct xfs_name *name); + +struct xfs_dir_hook { + struct xfs_hook dirent_hook; +}; + +void xfs_dir_hook_disable(void); +void xfs_dir_hook_enable(void); + +int xfs_dir_hook_add(struct xfs_mount *mp, struct xfs_dir_hook *hook); +void xfs_dir_hook_del(struct xfs_mount *mp, struct xfs_dir_hook *hook); +void xfs_dir_hook_setup(struct xfs_dir_hook *hook, notifier_fn_t mod_fn); +#else +# define xfs_dir_update_hook(dp, ip, delta, name) ((void)0) +#endif /* CONFIG_XFS_LIVE_HOOKS */ + struct xfs_parent_args; struct xfs_dir_update { diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c index 1ad8ec63a7f44..22f5f1a9d3f09 100644 --- a/fs/xfs/scrub/common.c +++ b/fs/xfs/scrub/common.c @@ -26,6 +26,7 @@ #include "xfs_da_format.h" #include "xfs_da_btree.h" #include "xfs_dir2_priv.h" +#include "xfs_dir2.h" #include "xfs_attr.h" #include "xfs_reflink.h" #include "xfs_ag.h" diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 99bd811b309d8..d79a191ed6068 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -600,81 +600,6 @@ xfs_icreate( return 0; } -#ifdef CONFIG_XFS_LIVE_HOOKS -/* - * Use a static key here to reduce the overhead of directory live update hooks. - * If the compiler supports jump labels, the static branch will be replaced by - * a nop sled when there are no hook users. Online fsck is currently the only - * caller, so this is a reasonable tradeoff. - * - * Note: Patching the kernel code requires taking the cpu hotplug lock. Other - * parts of the kernel allocate memory with that lock held, which means that - * XFS callers cannot hold any locks that might be used by memory reclaim or - * writeback when calling the static_branch_{inc,dec} functions. - */ -DEFINE_STATIC_XFS_HOOK_SWITCH(xfs_dir_hooks_switch); - -void -xfs_dir_hook_disable(void) -{ - xfs_hooks_switch_off(&xfs_dir_hooks_switch); -} - -void -xfs_dir_hook_enable(void) -{ - xfs_hooks_switch_on(&xfs_dir_hooks_switch); -} - -/* Call hooks for a directory update relating to a child dirent update. */ -inline void -xfs_dir_update_hook( - struct xfs_inode *dp, - struct xfs_inode *ip, - int delta, - const struct xfs_name *name) -{ - if (xfs_hooks_switched_on(&xfs_dir_hooks_switch)) { - struct xfs_dir_update_params p = { - .dp = dp, - .ip = ip, - .delta = delta, - .name = name, - }; - struct xfs_mount *mp = ip->i_mount; - - xfs_hooks_call(&mp->m_dir_update_hooks, 0, &p); - } -} - -/* Call the specified function during a directory update. */ -int -xfs_dir_hook_add( - struct xfs_mount *mp, - struct xfs_dir_hook *hook) -{ - return xfs_hooks_add(&mp->m_dir_update_hooks, &hook->dirent_hook); -} - -/* Stop calling the specified function during a directory update. */ -void -xfs_dir_hook_del( - struct xfs_mount *mp, - struct xfs_dir_hook *hook) -{ - xfs_hooks_del(&mp->m_dir_update_hooks, &hook->dirent_hook); -} - -/* Configure directory update hook functions. */ -void -xfs_dir_hook_setup( - struct xfs_dir_hook *hook, - notifier_fn_t mod_fn) -{ - xfs_hook_setup(&hook->dirent_hook, mod_fn); -} -#endif /* CONFIG_XFS_LIVE_HOOKS */ - /* Return dquots for the ids that will be assigned to a new file. */ int xfs_icreate_dqalloc( @@ -798,12 +723,6 @@ xfs_create( if (error) goto out_trans_cancel; - /* - * Create ip with a reference from dp, and add '.' and '..' references - * if it's a directory. - */ - xfs_dir_update_hook(dp, du.ip, 1, name); - /* * If this is a synchronous mount, make sure that the * create transaction goes to disk before returning to @@ -1025,8 +944,6 @@ xfs_link( if (error) goto error_return; - xfs_dir_update_hook(tdp, sip, 1, target_name); - /* * If this is a synchronous mount, make sure that the * link transaction goes to disk before returning to @@ -2079,12 +1996,6 @@ xfs_remove( if (error) goto out_trans_cancel; - /* - * Drop the link from dp to ip, and if ip was a directory, remove the - * '.' and '..' references since we freed the directory. - */ - xfs_dir_update_hook(dp, ip, -1, name); - /* * If this is a synchronous mount, make sure that the * remove transaction goes to disk before returning to @@ -2241,19 +2152,6 @@ xfs_cross_rename( if (error) goto out_trans_abort; - /* - * Inform our hook clients that we've finished an exchange operation as - * follows: removed the source and target files from their directories; - * added the target to the source directory; and added the source to - * the target directory. All inodes are locked, so it's ok to model a - * rename this way so long as we say we deleted entries before we add - * new ones. - */ - xfs_dir_update_hook(dp1, ip1, -1, name1); - xfs_dir_update_hook(dp2, ip2, -1, name2); - xfs_dir_update_hook(dp1, ip2, 1, name1); - xfs_dir_update_hook(dp2, ip1, 1, name2); - return xfs_finish_rename(tp); out_trans_abort: @@ -2535,21 +2433,6 @@ xfs_rename( VFS_I(du_wip.ip)->i_state &= ~I_LINKABLE; } - /* - * Inform our hook clients that we've finished a rename operation as - * follows: removed the source and target files from their directories; - * that we've added the source to the target directory; and finally - * that we've added the whiteout, if there was one. All inodes are - * locked, so it's ok to model a rename this way so long as we say we - * deleted entries before we add new ones. - */ - if (target_ip) - xfs_dir_update_hook(target_dp, target_ip, -1, target_name); - xfs_dir_update_hook(src_dp, src_ip, -1, src_name); - xfs_dir_update_hook(target_dp, src_ip, 1, target_name); - if (du_wip.ip) - xfs_dir_update_hook(src_dp, du_wip.ip, 1, src_name); - error = xfs_finish_rename(tp); nospace_error = 0; goto out_unlock; diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 5ee044674c3ab..51defdebef30e 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -632,31 +632,6 @@ void xfs_inode_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip, xfs_filblks_t *dblocks, xfs_filblks_t *rblocks); unsigned int xfs_inode_alloc_unitsize(struct xfs_inode *ip); -struct xfs_dir_update_params { - const struct xfs_inode *dp; - const struct xfs_inode *ip; - const struct xfs_name *name; - int delta; -}; - -#ifdef CONFIG_XFS_LIVE_HOOKS -void xfs_dir_update_hook(struct xfs_inode *dp, struct xfs_inode *ip, - int delta, const struct xfs_name *name); - -struct xfs_dir_hook { - struct xfs_hook dirent_hook; -}; - -void xfs_dir_hook_disable(void); -void xfs_dir_hook_enable(void); - -int xfs_dir_hook_add(struct xfs_mount *mp, struct xfs_dir_hook *hook); -void xfs_dir_hook_del(struct xfs_mount *mp, struct xfs_dir_hook *hook); -void xfs_dir_hook_setup(struct xfs_dir_hook *hook, notifier_fn_t mod_fn); -#else -# define xfs_dir_update_hook(dp, ip, delta, name) ((void)0) -#endif /* CONFIG_XFS_LIVE_HOOKS */ - int xfs_icreate_dqalloc(const struct xfs_icreate_args *args, struct xfs_dquot **udqpp, struct xfs_dquot **gdqpp, struct xfs_dquot **pdqpp); diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index c0f5c2e1f215b..77f19e2f66e07 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -200,8 +200,6 @@ xfs_symlink( if (error) goto out_trans_cancel; - xfs_dir_update_hook(dp, du.ip, 1, link_name); - /* * If this is a synchronous mount, make sure that the * symlink transaction goes to disk before returning to From patchwork Thu Jun 20 23:04:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706493 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 91CF113777F for ; Thu, 20 Jun 2024 23:04:24 +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=1718924664; cv=none; b=E+xIkYuMtKA8bN2W0v4cENQsO4zaQoP0IAq9M60pc0DRv8AL4TjNdzgzSeJETL+O9kbcSPAieBkEbqARb296WCC8ZGBqM+pULi+fJ04+TKCZT+fWD/WW/FcLq59QTrROxdfKHv7fBBxCn1b12A91eoiw3xfJcg13vaIOuWsfAXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924664; c=relaxed/simple; bh=3uv/90NBPGOYh60PeL/bnMAOzUV9APwK5o7t5SORifA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u8caioorfrCYpDtQL0XZMYrkq/IvHRn4E9YxTQRW85bIcQbZ6mo21xl8Pbr9C/WoevsDeseKBSJ9D+AL+jYij9HXrdwugsMitX9D7H+9uKp2oYxNdrJSCubPaKFbqNOBI3BtfjNj1ptDROZUXcfVteeXbY0c0y7UvhDx4QnrB9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uAuDfxlb; 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="uAuDfxlb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D7D7C2BD10; Thu, 20 Jun 2024 23:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924664; bh=3uv/90NBPGOYh60PeL/bnMAOzUV9APwK5o7t5SORifA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uAuDfxlbkazAZhsKSSj0fUWZzqywFWzp+4zITiL8tedxSB/dlZl4JYOm3748bwJD8 z2zgoqTwKATl43eDu0suMQo6nQr0G7UKlemuaBRl4VsVqxtesq14xnEFZ55GQAe5Dq ULdpA6eaG0wYm4tpZSFAViRdWYCAnzOYX9x+B99fP9PpCmzRVxFjdykrtPJwAxI9X/ gwGePqwkxqQvcRkOgmgxLtJReXyrREKwwLLkOXdUZAXzq+upgfLONWC63RkxtL+Uxk qa0zWjEIKn04QQ6PQ9jUq1ogH7puI0pWIYlC5eRjedCBNkBDje4YDZPSjSHOOaLDww kjiTRXA+4USog== Date: Thu, 20 Jun 2024 16:04:23 -0700 Subject: [PATCH 23/24] xfs: get rid of trivial rename helpers From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418295.3183075.6650817239063763087.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Get rid of the largely pointless xfs_cross_rename and xfs_finish_rename now that we've refactored its parent. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_inode.c | 77 +++++++++------------------------------------------- 1 file changed, 14 insertions(+), 63 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index d79a191ed6068..d73e6d843f85d 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2102,63 +2102,6 @@ xfs_sort_inodes( } } -static int -xfs_finish_rename( - struct xfs_trans *tp) -{ - /* - * If this is a synchronous mount, make sure that the rename transaction - * goes to disk before returning to the user. - */ - if (xfs_has_wsync(tp->t_mountp) || xfs_has_dirsync(tp->t_mountp)) - xfs_trans_set_sync(tp); - - return xfs_trans_commit(tp); -} - -/* - * xfs_cross_rename() - * - * responsible for handling RENAME_EXCHANGE flag in renameat2() syscall - */ -STATIC int -xfs_cross_rename( - struct xfs_trans *tp, - struct xfs_inode *dp1, - struct xfs_name *name1, - struct xfs_inode *ip1, - struct xfs_parent_args *ip1_ppargs, - struct xfs_inode *dp2, - struct xfs_name *name2, - struct xfs_inode *ip2, - struct xfs_parent_args *ip2_ppargs, - int spaceres) -{ - struct xfs_dir_update du1 = { - .dp = dp1, - .name = name1, - .ip = ip1, - .ppargs = ip1_ppargs, - }; - struct xfs_dir_update du2 = { - .dp = dp2, - .name = name2, - .ip = ip2, - .ppargs = ip2_ppargs, - }; - int error; - - error = xfs_dir_exchange_children(tp, &du1, &du2, spaceres); - if (error) - goto out_trans_abort; - - return xfs_finish_rename(tp); - -out_trans_abort: - xfs_trans_cancel(tp); - return error; -} - /* * xfs_rename_alloc_whiteout() * @@ -2351,11 +2294,11 @@ xfs_rename( /* RENAME_EXCHANGE is unique from here on. */ if (flags & RENAME_EXCHANGE) { - error = xfs_cross_rename(tp, src_dp, src_name, src_ip, - du_src.ppargs, target_dp, target_name, - target_ip, du_tgt.ppargs, spaceres); - nospace_error = 0; - goto out_unlock; + error = xfs_dir_exchange_children(tp, &du_src, &du_tgt, + spaceres); + if (error) + goto out_trans_cancel; + goto out_commit; } /* @@ -2433,7 +2376,15 @@ xfs_rename( VFS_I(du_wip.ip)->i_state &= ~I_LINKABLE; } - error = xfs_finish_rename(tp); +out_commit: + /* + * If this is a synchronous mount, make sure that the rename + * transaction goes to disk before returning to the user. + */ + if (xfs_has_wsync(tp->t_mountp) || xfs_has_dirsync(tp->t_mountp)) + xfs_trans_set_sync(tp); + + error = xfs_trans_commit(tp); nospace_error = 0; goto out_unlock; From patchwork Thu Jun 20 23:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13706494 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 4A9817C6EB for ; Thu, 20 Jun 2024 23:04:40 +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=1718924680; cv=none; b=mtOkg+H41cCrK6Yjbpp8C4kGxdk3ENMoH/7OAYXYEmiBihBDwZPfX3E+WQYIJGxBOtUTLi2LsYKYTJIbjQyduPQ0Azz0KlkN8DeBN5EstVBTO1mlZRi2Ld7SieLo0F/WlrZxYZbxv+jDdDNpUTSbcm8KYzg0le/A6jT/9ImcJmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718924680; c=relaxed/simple; bh=Jdx5Pof0QpUZzwBzRZIpyPHYnekiR0WJ97ylwZUG3bs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JfPD/kBd+v1w+JeEwl3oqorWW4VIZ6gtUoY03W9cHEyF26/oAfIAr2Rypkk0FLHrRr8dyt4H2xkOVXgYqhVaI7xlCWoA45rOCCM+GzzDF98794E0DduZfliJRc+X9YkDADNXb5EYAocENZ467T8aIw6AU4IT0Qhdnkt+VBWcsT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OX7gIO5/; 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="OX7gIO5/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 103FBC2BD10; Thu, 20 Jun 2024 23:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718924680; bh=Jdx5Pof0QpUZzwBzRZIpyPHYnekiR0WJ97ylwZUG3bs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OX7gIO5/F4WyzHeBqv8seRPEhuoeBgehmq8Isd/WBdZCuEPXzzrJkDMqe1mOah+bl Qr2LRL93utQYIcHmzBHh2G0XzDE4OQfPk+Cael2o8cLZUv6wpXLeGt7wPwuCt3Er1O hCzGb8EckYN1RIuUHaVDj6ngEzcXWkd0C/KkS12hKwj2Ao8xg3ySyD+6vxMdvDVYfn rj+TIWRiggHjZodx79RNpy/ybzp5MxMrnuoDQAv9HiDdEWB9Jraii6iuJ7GOAN/XAt BtFRhv2ogQpnanTwhcVKiZZWtkcx135eQEQ/11stwXKYzIqTQEKVMoySl/1LRHRrzU WzlGpI1zwkXJQ== Date: Thu, 20 Jun 2024 16:04:39 -0700 Subject: [PATCH 24/24] xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171892418312.3183075.2680579805332636419.stgit@frogsfrogsfrogs> In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> References: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Currently, the XFS_SB_CRC_OFF macro uses the incore superblock struct (xfs_sb) to compute the address of sb_crc within the ondisk superblock struct (xfs_dsb). This is a landmine if we ever change the layout of the incore superblock (as we're about to do), so redefine the macro to use xfs_dsb to compute the layout of xfs_dsb. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_format.h | 9 ++++----- fs/xfs/libxfs/xfs_ondisk.h | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 61f51becff4f7..e1bfee0c3b1a8 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -90,8 +90,7 @@ struct xfs_ifork; #define XFSLABEL_MAX 12 /* - * Superblock - in core version. Must match the ondisk version below. - * Must be padded to 64 bit alignment. + * Superblock - in core version. Must be padded to 64 bit alignment. */ typedef struct xfs_sb { uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */ @@ -178,10 +177,8 @@ typedef struct xfs_sb { /* must be padded to 64 bit alignment */ } xfs_sb_t; -#define XFS_SB_CRC_OFF offsetof(struct xfs_sb, sb_crc) - /* - * Superblock - on disk version. Must match the in core version above. + * Superblock - on disk version. * Must be padded to 64 bit alignment. */ struct xfs_dsb { @@ -265,6 +262,8 @@ struct xfs_dsb { /* must be padded to 64 bit alignment */ }; +#define XFS_SB_CRC_OFF offsetof(struct xfs_dsb, sb_crc) + /* * Misc. Flags - warning - these will be cleared by xfs_repair unless * a feature bit is set when the flag is used. diff --git a/fs/xfs/libxfs/xfs_ondisk.h b/fs/xfs/libxfs/xfs_ondisk.h index e8cdd77d03fa8..23c133fd36f5b 100644 --- a/fs/xfs/libxfs/xfs_ondisk.h +++ b/fs/xfs/libxfs/xfs_ondisk.h @@ -85,6 +85,7 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_name_remote_t, 12); */ + XFS_CHECK_OFFSET(struct xfs_dsb, sb_crc, 224); XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, valuelen, 0); XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, namelen, 2); XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, nameval, 3);