From patchwork Thu Feb 16 21:07:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91D84C636D6 for ; Thu, 16 Feb 2023 21:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbjBPVHH (ORCPT ); Thu, 16 Feb 2023 16:07:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbjBPVHH (ORCPT ); Thu, 16 Feb 2023 16:07:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3142D2B632 for ; Thu, 16 Feb 2023 13:07:06 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C37B960BFE for ; Thu, 16 Feb 2023 21:07:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28E52C433EF; Thu, 16 Feb 2023 21:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581625; bh=AiM0WqRVjRuNiWrv9EzqUofUanAeU1/gOoxJJEzkT8Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Rc8fwVW/NvTxjiV+V0Wf2ws32F4YYwuFsAgWq6orxepwbEBaPXdxuIToy3pxaLvXv lt3kLxBSBOjglv9Nf/CsuNiJOPW36uI58q826gYUj1fHEv29MgzRbNXlwLyVjP8J58 wi5OuuS71utAczBF2T+w9wB6NraJ7BKoRm2v9LAOTffrEZ3ikrH75432A+P2h32APM BO7e8VhDe2giopkdGy8SyrU/UQFO3ORn7MHJxvUH0v8noiEMDdZAmJZzOvD2sAvfAd boo38A1vvj7BXKgRqMW1pZ2+XMSrfRsOoIfuNYw0T+qugUdmQDxMz7Po9mUr1GnjfV zcarSdAOM/k0w== Date: Thu, 16 Feb 2023 13:07:04 -0800 Subject: [PATCH 1/3] xfs: shorten parent pointer function names From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657881038.3477513.11767684665536808344.stgit@magnolia> In-Reply-To: <167657881025.3477513.15490690754847111370.stgit@magnolia> References: <167657881025.3477513.15490690754847111370.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Shorten the function names and add brief comments to each, outlining what they're supposed to be doing. Signed-off-by: Darrick J. Wong --- libxfs/libxfs_api_defs.h | 2 +- libxfs/xfs_parent.c | 18 ++++++++++++------ libxfs/xfs_parent.h | 24 ++++++++++++------------ mkfs/proto.c | 12 ++++++------ 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 6d045867..a5045d2e 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -141,7 +141,7 @@ #define xfs_log_get_max_trans_res libxfs_log_get_max_trans_res #define xfs_log_sb libxfs_log_sb #define xfs_mode_to_ftype libxfs_mode_to_ftype -#define xfs_parent_defer_add libxfs_parent_defer_add +#define xfs_parent_add libxfs_parent_add #define xfs_parent_finish libxfs_parent_finish #define xfs_parent_start libxfs_parent_start #define xfs_perag_get libxfs_perag_get diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 74c7f1f7..89eb531f 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -136,6 +136,10 @@ xfs_parent_irec_from_disk( memset(&irec->p_name[valuelen], 0, sizeof(irec->p_name) - valuelen); } +/* + * Allocate memory to control a logged parent pointer update as part of a + * dirent operation. + */ int __xfs_parent_init( struct xfs_mount *mp, @@ -171,12 +175,13 @@ __xfs_parent_init( return 0; } +/* Add a parent pointer to reflect a dirent addition. */ int -xfs_parent_defer_add( +xfs_parent_add( struct xfs_trans *tp, struct xfs_parent_defer *parent, struct xfs_inode *dp, - struct xfs_name *parent_name, + const struct xfs_name *parent_name, xfs_dir2_dataptr_t diroffset, struct xfs_inode *child) { @@ -195,8 +200,9 @@ xfs_parent_defer_add( return xfs_attr_defer_add(args); } +/* Remove a parent pointer to reflect a dirent removal. */ int -xfs_parent_defer_remove( +xfs_parent_remove( struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_parent_defer *parent, @@ -212,14 +218,14 @@ xfs_parent_defer_remove( return xfs_attr_defer_remove(args); } - +/* Replace one parent pointer with another to reflect a rename. */ int -xfs_parent_defer_replace( +xfs_parent_replace( struct xfs_trans *tp, struct xfs_parent_defer *new_parent, struct xfs_inode *old_dp, xfs_dir2_dataptr_t old_diroffset, - struct xfs_name *parent_name, + const struct xfs_name *parent_name, struct xfs_inode *new_dp, xfs_dir2_dataptr_t new_diroffset, struct xfs_inode *child) diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index f4f5887d..35854e96 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -49,8 +49,9 @@ struct xfs_parent_defer { * Parent pointer attribute prototypes */ void xfs_init_parent_name_rec(struct xfs_parent_name_rec *rec, - struct xfs_inode *ip, - uint32_t p_diroffset); + struct xfs_inode *ip, uint32_t p_diroffset); +void xfs_init_parent_name_irec(struct xfs_parent_name_irec *irec, + struct xfs_parent_name_rec *rec); int __xfs_parent_init(struct xfs_mount *mp, bool grab_log, struct xfs_parent_defer **parentp); @@ -78,18 +79,17 @@ xfs_parent_start_locked( return 0; } -int xfs_parent_defer_add(struct xfs_trans *tp, struct xfs_parent_defer *parent, - struct xfs_inode *dp, struct xfs_name *parent_name, - xfs_dir2_dataptr_t diroffset, struct xfs_inode *child); -int xfs_parent_defer_replace(struct xfs_trans *tp, +int xfs_parent_add(struct xfs_trans *tp, struct xfs_parent_defer *parent, + struct xfs_inode *dp, const struct xfs_name *parent_name, + xfs_dir2_dataptr_t diroffset, struct xfs_inode *child); +int xfs_parent_replace(struct xfs_trans *tp, struct xfs_parent_defer *new_parent, struct xfs_inode *old_dp, - xfs_dir2_dataptr_t old_diroffset, struct xfs_name *parent_name, - struct xfs_inode *new_ip, xfs_dir2_dataptr_t new_diroffset, + xfs_dir2_dataptr_t old_diroffset, + const struct xfs_name *parent_name, struct xfs_inode *new_ip, + xfs_dir2_dataptr_t new_diroffset, struct xfs_inode *child); +int xfs_parent_remove(struct xfs_trans *tp, struct xfs_inode *dp, + struct xfs_parent_defer *parent, xfs_dir2_dataptr_t diroffset, struct xfs_inode *child); -int xfs_parent_defer_remove(struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_parent_defer *parent, - xfs_dir2_dataptr_t diroffset, - struct xfs_inode *child); void __xfs_parent_cancel(struct xfs_mount *mp, struct xfs_parent_defer *parent); diff --git a/mkfs/proto.c b/mkfs/proto.c index e0131df5..b8d7ac96 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -508,8 +508,8 @@ parseproto( newdirent(mp, tp, pip, &xname, ip->i_ino, &offset); libxfs_trans_log_inode(tp, ip, flags); if (parent) { - error = -libxfs_parent_defer_add(tp, parent, pip, - &xname, offset, ip); + error = -libxfs_parent_add(tp, parent, pip, &xname, + offset, ip); if (error) fail(_("committing parent pointers failed."), error); @@ -601,8 +601,8 @@ parseproto( newdirectory(mp, tp, ip, pip); libxfs_trans_log_inode(tp, ip, flags); if (parent) { - error = -libxfs_parent_defer_add(tp, parent, pip, - &xname, offset, ip); + error = -libxfs_parent_add(tp, parent, pip, &xname, + offset, ip); if (error) fail(_("committing parent pointers failed."), error); @@ -636,8 +636,8 @@ parseproto( } libxfs_trans_log_inode(tp, ip, flags); if (parent) { - error = -libxfs_parent_defer_add(tp, parent, pip, &xname, - offset, ip); + error = -libxfs_parent_add(tp, parent, pip, &xname, offset, + ip); if (error) fail(_("committing parent pointers failed."), error); } From patchwork Thu Feb 16 21:07:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E730DC636CC for ; Thu, 16 Feb 2023 21:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbjBPVHZ (ORCPT ); Thu, 16 Feb 2023 16:07:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbjBPVHY (ORCPT ); Thu, 16 Feb 2023 16:07:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73CBA505D3 for ; Thu, 16 Feb 2023 13:07:23 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 201A9B82760 for ; Thu, 16 Feb 2023 21:07:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B79E2C433EF; Thu, 16 Feb 2023 21:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581640; bh=pzwKqmNjab6dKye43OjLRCB8CsdAuVdgKqMv1WlZH/8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=BhCVXdtAA5CJyuF2SNcLwiwObtAhgiFCOqWp3y/AQANf7OTqRZlgCECJ3M7aVifl/ 46oVaCQx9Yvjas3fqWgeQZRoZ2UnyLtCGhfb55xQvV+4niys+XkNETT4ZUd1utpw+R rgX1E8W9Dly358UgRSpPHItbMcdQGzmqDkpMiHaG97hFWZDYIMfESxB3ieNcFDsH0n aUWScU5hRzwqS8EsHfEdf/bKdn8436E77DsJ77pJVnT+gJw0fecDMmhO+p6BQzNxYY YUEySLPOxMs1hD/9h4ygRRa5KwF6Fl2lc3Vg95MRzTv/LpuM7SaQRvtW1Y2Pra9/FA esjsqbFo1/4/w== Date: Thu, 16 Feb 2023 13:07:20 -0800 Subject: [PATCH 2/3] xfs: rearrange bits of the parent pointer apis for fsck From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657881051.3477513.7167485002406826170.stgit@magnolia> In-Reply-To: <167657881025.3477513.15490690754847111370.stgit@magnolia> References: <167657881025.3477513.15490690754847111370.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Rearrange parts of this thing in preparation for fsck code. Signed-off-by: Darrick J. Wong --- libxfs/libxfs_api_defs.h | 1 - libxfs/xfs_da_format.h | 11 +++++++++++ libxfs/xfs_parent.c | 29 ++++++++++++++++++++++++++++- libxfs/xfs_parent.h | 6 ++---- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index a5045d2e..b8ee0247 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -125,7 +125,6 @@ #define xfs_initialize_perag libxfs_initialize_perag #define xfs_initialize_perag_data libxfs_initialize_perag_data #define xfs_init_local_fork libxfs_init_local_fork -#define xfs_init_parent_name_rec libxfs_init_parent_name_rec #define xfs_inobt_maxrecs libxfs_inobt_maxrecs #define xfs_inobt_stage_cursor libxfs_inobt_stage_cursor diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h index 2db1cf97..c07b8166 100644 --- a/libxfs/xfs_da_format.h +++ b/libxfs/xfs_da_format.h @@ -159,6 +159,17 @@ struct xfs_da3_intnode { #define XFS_DIR3_FT_MAX 9 +#define XFS_DIR3_FTYPE_STR \ + { XFS_DIR3_FT_UNKNOWN, "unknown" }, \ + { XFS_DIR3_FT_REG_FILE, "file" }, \ + { XFS_DIR3_FT_DIR, "directory" }, \ + { XFS_DIR3_FT_CHRDEV, "char" }, \ + { XFS_DIR3_FT_BLKDEV, "block" }, \ + { XFS_DIR3_FT_FIFO, "fifo" }, \ + { XFS_DIR3_FT_SOCK, "sock" }, \ + { XFS_DIR3_FT_SYMLINK, "symlink" }, \ + { XFS_DIR3_FT_WHT, "whiteout" } + /* * Byte offset in data block and shortform entry. */ diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 89eb531f..980f0b82 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -92,7 +92,7 @@ xfs_parent_valuecheck( } /* Initializes a xfs_parent_name_rec to be stored as an attribute name */ -void +static inline void xfs_init_parent_name_rec( struct xfs_parent_name_rec *rec, struct xfs_inode *ip, @@ -136,6 +136,33 @@ xfs_parent_irec_from_disk( memset(&irec->p_name[valuelen], 0, sizeof(irec->p_name) - valuelen); } +/* + * Convert an incore parent_name record to its ondisk format. If @value or + * @valuelen are NULL, they will not be written to. + */ +void +xfs_parent_irec_to_disk( + struct xfs_parent_name_rec *rec, + void *value, + int *valuelen, + const struct xfs_parent_name_irec *irec) +{ + rec->p_ino = cpu_to_be64(irec->p_ino); + rec->p_gen = cpu_to_be32(irec->p_gen); + rec->p_diroffset = cpu_to_be32(irec->p_diroffset); + + if (valuelen) { + ASSERT(*valuelen > 0); + ASSERT(*valuelen >= irec->p_namelen); + ASSERT(*valuelen < MAXNAMELEN); + + *valuelen = irec->p_namelen; + } + + if (value) + memcpy(value, irec->p_name, irec->p_namelen); +} + /* * Allocate memory to control a logged parent pointer update as part of a * dirent operation. diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index 35854e96..4eb92fb4 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -33,6 +33,8 @@ struct xfs_parent_name_irec { void xfs_parent_irec_from_disk(struct xfs_parent_name_irec *irec, const struct xfs_parent_name_rec *rec, const void *value, int valuelen); +void xfs_parent_irec_to_disk(struct xfs_parent_name_rec *rec, void *value, + int *valuelen, const struct xfs_parent_name_irec *irec); /* * Dynamically allocd structure used to wrap the needed data to pass around @@ -48,10 +50,6 @@ struct xfs_parent_defer { /* * Parent pointer attribute prototypes */ -void xfs_init_parent_name_rec(struct xfs_parent_name_rec *rec, - struct xfs_inode *ip, uint32_t p_diroffset); -void xfs_init_parent_name_irec(struct xfs_parent_name_irec *irec, - struct xfs_parent_name_rec *rec); int __xfs_parent_init(struct xfs_mount *mp, bool grab_log, struct xfs_parent_defer **parentp); From patchwork Thu Feb 16 21:07:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99EFFC61DA4 for ; Thu, 16 Feb 2023 21:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbjBPVHi (ORCPT ); Thu, 16 Feb 2023 16:07:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbjBPVHi (ORCPT ); Thu, 16 Feb 2023 16:07:38 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D63C505D9 for ; Thu, 16 Feb 2023 13:07:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ED8CD60C48 for ; Thu, 16 Feb 2023 21:07:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55427C433EF; Thu, 16 Feb 2023 21:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581656; bh=Qv6PJB7DqyvyXSmPKdwv/o5AzNrgdLf28MPwceisRzs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jqG8S2DJAMKp7TJAfwGhfEP3DyevsRvXyUSkMlE6uWGlhK2yy7TzNfISZlPUMAATX YCZc8k3OhxPvQuwKZviDPffCWWT+vUkkYBOJdrZ7rAC3W4RtDSFUVxJk3/9g0XNHDC 4bAiw/u3STCOEmENJCIQoCG2fhPij09GtY3xYKIMm3+IoQtWvV9sQHmWJOw7ZqjIzB 85KKbwMyLRs25ddTlpZnNOZVILPTueYmKZm+zCC9tTfDnLCJKxWvIcjpMLHKJBfFLQ gl8sa9/Z+KTkd+EF/4B8h6mhTz76k7+vw1LACiWCgFR4UIgBSqr5aLemI5gJ6Inncj m6kaKlNzUZxiA== Date: Thu, 16 Feb 2023 13:07:35 -0800 Subject: [PATCH 3/3] xfs: add hooks to do directory updates From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657881064.3477513.15240825511730043370.stgit@magnolia> In-Reply-To: <167657881025.3477513.15490690754847111370.stgit@magnolia> References: <167657881025.3477513.15490690754847111370.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong While we're scanning the filesystem, we still need to keep the tempdir up to date with whatever changes get made to the you know what. Signed-off-by: Darrick J. Wong --- libxfs/xfs_dir2.c | 2 +- libxfs/xfs_dir2.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 4bbe83f9..9742ba65 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -439,7 +439,7 @@ int xfs_dir_removename( struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_name *name, + const struct xfs_name *name, xfs_ino_t ino, xfs_extlen_t total, /* bmap's total block count */ xfs_dir2_dataptr_t *offset) /* OUT: offset in directory */ diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index ac360c0b..6ed86b7b 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -46,7 +46,7 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t *inum, struct xfs_name *ci_name); extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_name *name, xfs_ino_t ino, + const struct xfs_name *name, xfs_ino_t ino, xfs_extlen_t tot, xfs_dir2_dataptr_t *offset); extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp,