All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org
Cc: allison.henderson@oracle.com, catherine.hoang@oracle.com,
	linux-xfs@vger.kernel.org, hch@lst.de
Subject: [PATCH 19/23] xfs: split xfs_bmap_add_attrfork into two pieces
Date: Mon, 18 Mar 2024 14:52:57 -0700	[thread overview]
Message-ID: <171079803003.3808642.4919701143105996298.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <171079802637.3808642.13167687091088855153.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

Split this function into two pieces -- one to make the actual changes to
the inode core to add the attr fork, and another one to deal with
getting the transaction and locking the inodes.

The next couple of patches will need this to be split into two.  One
patch implements committing new parent pointer recordsets to damaged
files.  If one file has an attr fork and the other does not, we have to
create the missing attr fork before the atomic swap transaction, and can
use the behavior encoded in the current xfs_bmap_add_attrfork.

The second patch adapts /lost+found adoptions to handle parent pointers
correctly.  The adoption process will add a parent pointer to a child
that is being moved to /lost+found, but this requires that the attr fork
already exists.  We don't know if we're actually going to commit the
adoption until we've already reserved a transaction and taken the
ILOCKs, which means that we must have a way to bypass the start of the
current xfs_bmap_add_attrfork.

Therefore, create xfs_attr_add_fork as the helper that creates a
transaction and takes locks; and make xfs_bmap_add_attrfork the function
that updates the inode core and allocates the incore attr fork.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_attr.c |   39 ++++++++++++++++++++++++++++++++++++++-
 fs/xfs/libxfs/xfs_bmap.c |   36 ++++++++++--------------------------
 fs/xfs/libxfs/xfs_bmap.h |    3 ++-
 3 files changed, 50 insertions(+), 28 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
index 1c1ac2232dfad..c5fc3cafbe4e8 100644
--- a/fs/xfs/libxfs/xfs_attr.c
+++ b/fs/xfs/libxfs/xfs_attr.c
@@ -941,6 +941,43 @@ xfs_attr_defer_add(
 	trace_xfs_attr_defer_add(new->xattri_dela_state, args->dp);
 }
 
+STATIC int
+xfs_attr_add_fork(
+	struct xfs_inode	*ip,		/* incore inode pointer */
+	int			size,		/* space new attribute needs */
+	int			rsvd)		/* xact may use reserved blks */
+{
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;		/* transaction pointer */
+	unsigned int		blks;		/* space reservation */
+	int			error;		/* error return value */
+
+	ASSERT(!XFS_NOT_DQATTACHED(mp, ip));
+
+	blks = XFS_ADDAFORK_SPACE_RES(mp);
+
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, 0,
+			rsvd, &tp);
+	if (error)
+		return error;
+
+	if (xfs_inode_has_attr_fork(ip))
+		goto trans_cancel;
+
+	error = xfs_bmap_add_attrfork(tp, ip, size, rsvd);
+	if (error)
+		goto trans_cancel;
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	return error;
+
+trans_cancel:
+	xfs_trans_cancel(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	return error;
+}
+
 /*
  * Note: If args->value is NULL the attribute will be removed, just like the
  * Linux ->setattr API.
@@ -992,7 +1029,7 @@ xfs_attr_set(
 				xfs_attr_sf_entsize_byname(args->namelen,
 						args->valuelen);
 
-			error = xfs_bmap_add_attrfork(dp, sf_size, rsvd);
+			error = xfs_attr_add_fork(dp, sf_size, rsvd);
 			if (error)
 				return error;
 		}
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 83cbefc54e1f3..85194a831b445 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -1025,38 +1025,29 @@ xfs_bmap_set_attrforkoff(
 }
 
 /*
- * Convert inode from non-attributed to attributed.
- * Must not be in a transaction, ip must not be locked.
+ * Convert inode from non-attributed to attributed.  Caller must hold the
+ * ILOCK_EXCL and the file cannot have an attr fork.
  */
 int						/* error code */
 xfs_bmap_add_attrfork(
-	xfs_inode_t		*ip,		/* incore inode pointer */
+	struct xfs_trans	*tp,
+	struct xfs_inode	*ip,		/* incore inode pointer */
 	int			size,		/* space new attribute needs */
 	int			rsvd)		/* xact may use reserved blks */
 {
-	xfs_mount_t		*mp;		/* mount structure */
-	xfs_trans_t		*tp;		/* transaction pointer */
-	int			blks;		/* space reservation */
+	struct xfs_mount	*mp = tp->t_mountp;
 	int			version = 1;	/* superblock attr version */
 	int			logflags;	/* logging flags */
 	int			error;		/* error return value */
 
-	mp = ip->i_mount;
+	ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
 	ASSERT(!XFS_NOT_DQATTACHED(mp, ip));
-
-	blks = XFS_ADDAFORK_SPACE_RES(mp);
-
-	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, 0,
-			rsvd, &tp);
-	if (error)
-		return error;
-	if (xfs_inode_has_attr_fork(ip))
-		goto trans_cancel;
+	ASSERT(!xfs_inode_has_attr_fork(ip));
 
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 	error = xfs_bmap_set_attrforkoff(ip, size, &version);
 	if (error)
-		goto trans_cancel;
+		return error;
 
 	xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0);
 	logflags = 0;
@@ -1077,7 +1068,7 @@ xfs_bmap_add_attrfork(
 	if (logflags)
 		xfs_trans_log_inode(tp, ip, logflags);
 	if (error)
-		goto trans_cancel;
+		return error;
 	if (!xfs_has_attr(mp) ||
 	   (!xfs_has_attr2(mp) && version == 2)) {
 		bool log_sb = false;
@@ -1096,14 +1087,7 @@ xfs_bmap_add_attrfork(
 			xfs_log_sb(tp);
 	}
 
-	error = xfs_trans_commit(tp);
-	xfs_iunlock(ip, XFS_ILOCK_EXCL);
-	return error;
-
-trans_cancel:
-	xfs_trans_cancel(tp);
-	xfs_iunlock(ip, XFS_ILOCK_EXCL);
-	return error;
+	return 0;
 }
 
 /*
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index 32fb2a455c294..e98849eb9bbae 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -176,7 +176,8 @@ int	xfs_bmap_longest_free_extent(struct xfs_perag *pag,
 void	xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno,
 		xfs_filblks_t len);
 unsigned int xfs_bmap_compute_attr_offset(struct xfs_mount *mp);
-int	xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
+int	xfs_bmap_add_attrfork(struct xfs_trans *tp, struct xfs_inode *ip,
+		int size, int rsvd);
 void	xfs_bmap_local_to_extents_empty(struct xfs_trans *tp,
 		struct xfs_inode *ip, int whichfork);
 int xfs_bmap_local_to_extents(struct xfs_trans *tp, struct xfs_inode *ip,


  parent reply	other threads:[~2024-03-18 21:52 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 21:39 [PATCHBOMB v13] xfs: parent pointers Darrick J. Wong
2024-03-18 21:41 ` [PATCHSET v13.0 1/2] xfs: Parent Pointers Darrick J. Wong
2024-03-18 21:42   ` [PATCH 01/23] xfs: Expose init_xattrs in xfs_create_tmpfile Darrick J. Wong
2024-03-18 21:42   ` [PATCH 02/23] xfs: add parent pointer support to attribute code Darrick J. Wong
2024-03-18 21:42   ` [PATCH 03/23] xfs: define parent pointer ondisk extended attribute format Darrick J. Wong
2024-03-18 21:43   ` [PATCH 04/23] xfs: add parent pointer validator functions Darrick J. Wong
2024-03-18 21:43   ` [PATCH 05/23] xfs: extend transaction reservations for parent attributes Darrick J. Wong
2024-03-18 21:43   ` [PATCH 06/23] xfs: parent pointer attribute creation Darrick J. Wong
2024-03-18 21:43   ` [PATCH 07/23] xfs: add parent attributes to link Darrick J. Wong
2024-03-18 21:44   ` [PATCH 08/23] xfs: add parent attributes to symlink Darrick J. Wong
2024-03-18 21:44   ` [PATCH 09/23] xfs: remove parent pointers in unlink Darrick J. Wong
2024-03-18 21:44   ` [PATCH 10/23] xfs: Add parent pointers to rename Darrick J. Wong
2024-03-18 21:44   ` [PATCH 11/23] xfs: Add parent pointers to xfs_cross_rename Darrick J. Wong
2024-03-18 21:45   ` [PATCH 12/23] xfs: Filter XFS_ATTR_PARENT for getfattr Darrick J. Wong
2024-03-18 21:45   ` [PATCH 13/23] xfs: pass the attr value to put_listent when possible Darrick J. Wong
2024-03-18 21:45   ` [PATCH 14/23] xfs: add a libxfs header file for staging new ioctls Darrick J. Wong
2024-03-18 21:45   ` [PATCH 15/23] xfs: Add parent pointer ioctl Darrick J. Wong
2024-03-18 21:46   ` [PATCH 16/23] xfs: fix unit conversion error in xfs_log_calc_max_attrsetm_res Darrick J. Wong
2024-03-18 21:46   ` [PATCH 17/23] xfs: drop compatibility minimum log size computations for reflink Darrick J. Wong
2024-03-18 21:46   ` [PATCH 18/23] xfs: don't remove the attr fork when parent pointers are enabled Darrick J. Wong
2024-03-18 21:46   ` [PATCH 19/23] xfs: Add the parent pointer support to the superblock version 5 Darrick J. Wong
2024-03-18 21:47   ` [PATCH 20/23] xfs: only clear some log incompat bits at unmount Darrick J. Wong
2024-03-18 21:47   ` [PATCH 21/23] xfs: allow adding multiple log incompat feature bits Darrick J. Wong
2024-03-18 21:47   ` [PATCH 22/23] xfs: make XFS_SB_FEAT_INCOMPAT_LOG_XATTRS sticky for parent pointers Darrick J. Wong
2024-03-18 21:47   ` [PATCH 23/23] xfs: make XFS_SB_FEAT_INCOMPAT_LOG_EXCHMAPS " Darrick J. Wong
2024-03-18 21:41 ` [PATCHSET v13.0 2/2] xfs: fsck " Darrick J. Wong
2024-03-18 21:48   ` [PATCH 01/23] xfs: check dirents have " Darrick J. Wong
2024-03-18 21:48   ` [PATCH 02/23] xfs: deferred scrub of dirents Darrick J. Wong
2024-03-18 21:48   ` [PATCH 03/23] xfs: create a parent pointer walk function for scrubbers Darrick J. Wong
2024-03-18 21:49   ` [PATCH 04/23] xfs: scrub parent pointers Darrick J. Wong
2024-03-18 21:49   ` [PATCH 05/23] xfs: deferred scrub of " Darrick J. Wong
2024-03-18 21:49   ` [PATCH 06/23] xfs: walk directory parent pointers to determine backref count Darrick J. Wong
2024-03-18 21:49   ` [PATCH 07/23] xfs: add raw parent pointer apis to support repair Darrick J. Wong
2024-03-18 21:50   ` [PATCH 08/23] xfs: set child file owner in xfs_da_args when changing parent pointers Darrick J. Wong
2024-03-18 21:50   ` [PATCH 09/23] xfs: check parent pointer xattrs when scrubbing Darrick J. Wong
2024-03-18 21:50   ` [PATCH 10/23] xfs: salvage parent pointers when rebuilding xattr structures Darrick J. Wong
2024-03-18 21:50   ` [PATCH 11/23] xfs: replace namebuf with parent pointer in directory repair Darrick J. Wong
2024-03-18 21:51   ` [PATCH 12/23] xfs: repair directories by scanning directory parent pointers Darrick J. Wong
2024-03-18 21:51   ` [PATCH 13/23] xfs: implement live updates for directory repairs Darrick J. Wong
2024-03-18 21:51   ` [PATCH 14/23] xfs: replay unlocked parent pointer updates that accrue during xattr repair Darrick J. Wong
2024-03-18 21:51   ` [PATCH 15/23] xfs: replace namebuf with parent pointer in parent pointer repair Darrick J. Wong
2024-03-18 21:52   ` [PATCH 16/23] xfs: repair directory parent pointers by scanning for dirents Darrick J. Wong
2024-03-18 21:52   ` [PATCH 17/23] xfs: implement live updates for parent pointer repairs Darrick J. Wong
2024-03-18 21:52   ` [PATCH 18/23] xfs: remove pointless unlocked assertion Darrick J. Wong
2024-03-18 21:52   ` Darrick J. Wong [this message]
2024-03-18 21:53   ` [PATCH 20/23] xfs: actually rebuild the parent pointer xattrs Darrick J. Wong
2024-03-18 21:53   ` [PATCH 21/23] xfs: adapt the orphanage code to handle parent pointers Darrick J. Wong
2024-03-18 21:53   ` [PATCH 22/23] xfs: repair link count of nondirectories after rebuilding " Darrick J. Wong
2024-03-18 21:53   ` [PATCH 23/23] xfs: inode repair should ensure there's an attr fork to store " Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=171079803003.3808642.4919701143105996298.stgit@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=allison.henderson@oracle.com \
    --cc=catherine.hoang@oracle.com \
    --cc=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.