Skip to contentSkip to conversation

Parent Pointers

PATCH Superseded [email protected] 4 participants 75 messages Sep 22, 2022 – Sep 28, 2022 XFS filesystem Page 1 of 2

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v3 cover Parent Pointers

From: Allison Henderson <[email protected]>

Hi all,

This is the latest parent pointer attributes for xfs.
The goal of this patch set is to add a parent pointer attribute to each inode. The attribute name containing the parent inode, generation, and directory offset, while the attribute value contains the file name. This feature will enable future optimizations for online scrub, or any other feature that could make use of quickly deriving an inodes path from the mount point.

This set can be viewed on github here
https://github.com/allisonhenderson/xfs/tree/xfs_new_pptrsv3_rebase4

And the corresponding xfsprogs code is here
https://github.com/allisonhenderson/xfsprogs/tree/xfsprogs_new_pptrs_v3_rebase3

This set has been tested with the below parent pointers tests
https://www.spinics.net/lists/fstests/msg19963.html

Updates since v2:

xfs: Hold inode locks in xfs_rename
NEW

xfs: Expose init_xattrs in xfs_create_tmpfile
NEW

xfs: Add parent pointers to xfs_cross_rename
NEW

xfs: Indent xfs_rename
NEW

xfs: Add parent pointers to rename
Added parent pointers for WIP

xfs: Add xfs_verify_pptr
Fixed indentaion in xfs_verify_pptr
Updates for new name field

xfs: extend transaction reservations for parent attributes
Moved/removed stale comments in xfs_calc_parent_ptr_reservations and xfs_calc_namespace_reservations Reduced resp->tr_rename.tr_logres in xfs_calc_parent_ptr_reservations since logged attrs can separate transaction updates Updated inode reservation in xfs_calc_rename_reservation

xfs: parent pointer attribute creation
Moved target id and name parameters from xfs_parent_init to xfs_parent_defer_add

xfs: add parent attributes to link
Rebase updates to xfs_parent_init and xfs_parent_defer_add

xfs: remove parent pointers in unlink
Rebase updates xfs_parent_init and xfs_parent_defer_remove. Renamed ip to dp in xfs_parent_defer_remove Simplified xfs_has_parent check in xfs_remove

xfs: Add parent pointers to rename
Rebase updates to xfs_parent_init, xfs_parent_defer_remove and
xfs_parent_defer_replace

xfs: Add parent pointers to symlink
NEW

xfs: Filter XFS_ATTR_PARENT for get_fattr
NEW

xfs: Add parent pointer ioctl
Added new XFS_PPTR_FLAG_ALL
Removed namelen from xfs_parent_ptr. Added rsvd Renamed XFS_IOC_GETPPOINTER to XFS_IOC_GETPARENT Added const qualifier to xfs_init_parent
Added XFS_IOC_ATTR_PARENT check in xfs_attrmulti_attr_set and
xfs_ioc_attrmulti_one
Updated SDX headers

In xfs_ioc_get_parent_pointer:
Updated kmem_alloc to kmalloc
Updated return codes for copy to/from user to -EFAULT Updated XFS_PPTR_OFLAG_* handling
Removed GFP_NOFS | __GFP_NOFAIL from realloc

In xfs_attr_get_parent_pointer:
Fixed indentation
Updated error returns to -EFSCORRUPTED Changed xfs_ilock to xfs_ilock_attr_map_shared Added inode checking

xfs: drop compatibility minimum log size computations for reflink
NEW
xfs: Filter XFS_ATTR_PARENT for get_fattr
NEW

Investigated removeing memset in xfs_attr_get_parent_pointer
Trips assertion for non-zeroed context
XFS: Assertion failed: !context->seen_enough, file: fs/xfs/xfs_ioctl.c, line: 317

Questions comments and feedback appreciated!

Thanks all!
Allison

Allison Henderson (26):
xfs: Add new name to attri/d
xfs: Increase XFS_DEFER_OPS_NR_INODES to 5
xfs: Hold inode locks in xfs_ialloc
xfs: Hold inode locks in xfs_trans_alloc_dir
xfs: Hold inode locks in xfs_rename
xfs: Expose init_xattrs in xfs_create_tmpfile
xfs: get directory offset when adding directory name
xfs: get directory offset when removing directory name
xfs: get directory offset when replacing a directory name
xfs: add parent pointer support to attribute code
xfs: define parent pointer xattr format
xfs: Add xfs_verify_pptr
xfs: extend transaction reservations for parent attributes
xfs: parent pointer attribute creation
xfs: add parent attributes to link
xfs: add parent attributes to symlink
xfs: remove parent pointers in unlink
xfs: Add parent pointers to xfs_cross_rename
xfs: Indent xfs_rename
xfs: Add parent pointers to rename
xfs: Add the parent pointer support to the superblock version 5.
xfs: Add helper function xfs_attr_list_context_init
xfs: Filter XFS_ATTR_PARENT for getfattr
xfs: Add parent pointer ioctl
xfs: fix unit conversion error in xfs_log_calc_max_attrsetm_res
xfs: drop compatibility minimum log size computations for reflink

 fs/xfs/Makefile                |   2 +
 fs/xfs/libxfs/xfs_attr.c       |  71 ++++++-
 fs/xfs/libxfs/xfs_attr.h       |  13 +-
 fs/xfs/libxfs/xfs_da_btree.h   |   3 +
 fs/xfs/libxfs/xfs_da_format.h  |  33 ++-
 fs/xfs/libxfs/xfs_defer.c      |  28 ++-
 fs/xfs/libxfs/xfs_defer.h      |   8 +-
 fs/xfs/libxfs/xfs_dir2.c       |  21 +-
 fs/xfs/libxfs/xfs_dir2.h       |   7 +-
 fs/xfs/libxfs/xfs_dir2_block.c |   9 +-
 fs/xfs/libxfs/xfs_dir2_leaf.c  |   8 +-
 fs/xfs/libxfs/xfs_dir2_node.c  |   8 +-
 fs/xfs/libxfs/xfs_dir2_sf.c    |   6 +
 fs/xfs/libxfs/xfs_format.h     |   4 +-
 fs/xfs/libxfs/xfs_fs.h         |  60 ++++++
 fs/xfs/libxfs/xfs_log_format.h |   7 +-
 fs/xfs/libxfs/xfs_log_rlimit.c |  53 +++++
 fs/xfs/libxfs/xfs_parent.c     | 193 +++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h     |  45 ++++
 fs/xfs/libxfs/xfs_sb.c         |   4 +
 fs/xfs/libxfs/xfs_trans_resv.c | 135 +++++++++---
 fs/xfs/scrub/attr.c            |   2 +-
 fs/xfs/xfs_attr_item.c         | 115 ++++++++--
 fs/xfs/xfs_attr_item.h         |   1 +
 fs/xfs/xfs_attr_list.c         |  64 ++++--
 fs/xfs/xfs_file.c              |   1 +
 fs/xfs/xfs_inode.c             | 374 +++++++++++++++++++++++++--------
 fs/xfs/xfs_inode.h             |   3 +-
 fs/xfs/xfs_ioctl.c             | 160 ++++++++++++--
 fs/xfs/xfs_ioctl.h             |   2 +
 fs/xfs/xfs_iops.c              |   3 +-
 fs/xfs/xfs_ondisk.h            |   4 +
 fs/xfs/xfs_parent_utils.c      | 126 +++++++++++
 fs/xfs/xfs_parent_utils.h      |  11 +
 fs/xfs/xfs_qm.c                |   4 +-
 fs/xfs/xfs_super.c             |   4 +
 fs/xfs/xfs_symlink.c           |  35 ++-
 fs/xfs/xfs_trans.c             |   6 +-
 fs/xfs/xfs_xattr.c             |   2 +-
 fs/xfs/xfs_xattr.h             |   1 +
 40 files changed, 1427 insertions(+), 209 deletions(-)
 create mode 100644 fs/xfs/libxfs/xfs_parent.c
 create mode 100644 fs/xfs/libxfs/xfs_parent.h
 create mode 100644 fs/xfs/xfs_parent_utils.c
 create mode 100644 fs/xfs/xfs_parent_utils.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/26 xfs: Add new name to attri/d

From: Allison Henderson <[email protected]>

This patch adds two new fields to the atti/d. They are nname and nnamelen. This will be used for parent pointer updates since a rename operation may cause the parent pointer to update both the name and value. So we need to carry both the new name as well as the target name in the attri/d.

---
 fs/xfs/libxfs/xfs_attr.c       |  12 +++-
 fs/xfs/libxfs/xfs_attr.h       |   4 +-
 fs/xfs/libxfs/xfs_da_btree.h   |   2 +
 fs/xfs/libxfs/xfs_log_format.h |   6 +-
 fs/xfs/xfs_attr_item.c         | 108 ++++++++++++++++++++++++++++-----
 fs/xfs/xfs_attr_item.h         |   1 +
 6 files changed, 113 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +11 -1
index e28d93d232de..b1dbed7655e8 100644
@@ -423,6 +423,12 @@ xfs_attr_complete_op(
 	args->op_flags &= ~XFS_DA_OP_REPLACE;
 	if (do_replace) {
 		args->attr_filter &= ~XFS_ATTR_INCOMPLETE;
+		if (args->new_namelen > 0) {
+			args->name = args->new_name;
+			args->namelen = args->new_namelen;
+			args->hashval = xfs_da_hashname(args->name,
+							args->namelen);
+		}
 		return replace_state;
 	}
 	return XFS_DAS_DONE;
@@ -922,9 +928,13 @@ xfs_attr_defer_replace(
 	struct xfs_da_args	*args)
 {
 	struct xfs_attr_intent	*new;
+	int			op_flag;
 	int			error = 0;
 
-	error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_REPLACE, &new);
+	op_flag = args->new_namelen == 0 ? XFS_ATTRI_OP_FLAGS_REPLACE :
+		  XFS_ATTRI_OP_FLAGS_NVREPLACE;
+
+	error = xfs_attr_intent_init(args, op_flag, &new);
 	if (error)
 		return error;
 
fs/xfs/libxfs/xfs_attr.h +2 -2
index 81be9b3e4004..3e81f3f48560 100644
@@ -510,8 +510,8 @@ struct xfs_attr_intent {
 	struct xfs_da_args		*xattri_da_args;
 
 	/*
-	 * Shared buffer containing the attr name and value so that the logging
-	 * code can share large memory buffers between log items.
+	 * Shared buffer containing the attr name, new name, and value so that
+	 * the logging code can share large memory buffers between log items.
 	 */
 	struct xfs_attri_log_nameval	*xattri_nameval;
 
fs/xfs/libxfs/xfs_da_btree.h +2 -0
index ffa3df5b2893..a4b29827603f 100644
@@ -55,7 +55,9 @@ enum xfs_dacmp {
 typedef struct xfs_da_args {
 	struct xfs_da_geometry *geo;	/* da block geometry */
 	const uint8_t		*name;		/* string (maybe not NULL terminated) */
+	const uint8_t	*new_name;	/* new attr name */
 	int		namelen;	/* length of string (maybe no NULL) */
+	int		new_namelen;	/* new attr name len */
 	uint8_t		filetype;	/* filetype of inode for directories */
 	void		*value;		/* set of bytes (maybe contain NULLs) */
 	int		valuelen;	/* length of value */
fs/xfs/libxfs/xfs_log_format.h +4 -2
index b351b9dc6561..62f40e6353c2 100644
@@ -117,7 +117,8 @@ struct xfs_unmount_log_format {
 #define XLOG_REG_TYPE_ATTRD_FORMAT	28
 #define XLOG_REG_TYPE_ATTR_NAME	29
 #define XLOG_REG_TYPE_ATTR_VALUE	30
-#define XLOG_REG_TYPE_MAX		30
+#define XLOG_REG_TYPE_ATTR_NNAME	31
+#define XLOG_REG_TYPE_MAX		31
 
 
 /*
@@ -909,6 +910,7 @@ struct xfs_icreate_log {
 #define XFS_ATTRI_OP_FLAGS_SET		1	/* Set the attribute */
 #define XFS_ATTRI_OP_FLAGS_REMOVE	2	/* Remove the attribute */
 #define XFS_ATTRI_OP_FLAGS_REPLACE	3	/* Replace the attribute */
+#define XFS_ATTRI_OP_FLAGS_NVREPLACE	4	/* Replace attr name and val */
 #define XFS_ATTRI_OP_FLAGS_TYPE_MASK	0xFF	/* Flags type mask */
 
 /*
@@ -926,7 +928,7 @@ struct xfs_icreate_log {
 struct xfs_attri_log_format {
 	uint16_t	alfi_type;	/* attri log item type */
 	uint16_t	alfi_size;	/* size of this item */
-	uint32_t	__pad;		/* pad to 64 bit aligned */
+	uint32_t	alfi_nname_len;	/* attr new name length */
 	uint64_t	alfi_id;	/* attri identifier */
 	uint64_t	alfi_ino;	/* the inode for this attr operation */
 	uint32_t	alfi_op_flags;	/* marks the op as a set or remove */
fs/xfs/xfs_attr_item.c +93 -15

222 lines not on this page · raw message

fs/xfs/xfs_attr_item.h +1 -0
index 3280a7930287..24d4968dd6cc 100644
@@ -13,6 +13,7 @@ struct kmem_zone;
 
 struct xfs_attri_log_nameval {
 	struct xfs_log_iovec	name;
+	struct xfs_log_iovec	nname;
 	struct xfs_log_iovec	value;
 	refcount_t		refcount;
 
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v3 01/26] xfs: Add new name to attri/d

Quoted 23 lines · On Wed, Sep 21, 2022 at 10:44:33PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch adds two new fields to the atti/d. They are nname and nnamelen. This will be used for parent pointer updates since a rename operation may cause the parent pointer to update both the name and value. So we need to carry both the new name as well as the target name in the attri/d.

---
 fs/xfs/libxfs/xfs_attr.c       |  12 +++-
 fs/xfs/libxfs/xfs_attr.h       |   4 +-
 fs/xfs/libxfs/xfs_da_btree.h   |   2 +
 fs/xfs/libxfs/xfs_log_format.h |   6 +-
 fs/xfs/xfs_attr_item.c         | 108 ++++++++++++++++++++++++++++-----
 fs/xfs/xfs_attr_item.h         |   1 +
 6 files changed, 113 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index e28d93d232de..b1dbed7655e8 100644

fs/xfs/libxfs/xfs_attr.c xfs_attr_complete_op( · line 428

Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
@@ -423,6 +423,12 @@ xfs_attr_complete_op(
 	args->op_flags &= ~XFS_DA_OP_REPLACE;
 	if (do_replace) {
 		args->attr_filter &= ~XFS_ATTR_INCOMPLETE;
+		if (args->new_namelen > 0) {
+			args->name = args->new_name;
+			args->namelen = args->new_namelen;

/me wonders, do we need to null out new_name and new_namelen here?

I /think/ the answer is that the current codebase doesn't care since we're now doing XFS_DA_OP_ADDNAME, and addname looks only at name/namelen and has no idea that new_name/new_namelen even exist?

Quoted 41 lines
fs/xfs/libxfs/xfs_attr.c +8 -1
+			args->hashval = xfs_da_hashname(args->name,
+							args->namelen);
+		}
 		return replace_state;
 	}
 	return XFS_DAS_DONE;
@@ -922,9 +928,13 @@ xfs_attr_defer_replace(
 	struct xfs_da_args	*args)
 {
 	struct xfs_attr_intent	*new;
+	int			op_flag;
 	int			error = 0;
 
-	error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_REPLACE, &new);
+	op_flag = args->new_namelen == 0 ? XFS_ATTRI_OP_FLAGS_REPLACE :
+		  XFS_ATTRI_OP_FLAGS_NVREPLACE;
+
+	error = xfs_attr_intent_init(args, op_flag, &new);
 	if (error)
 		return error;
 
fs/xfs/libxfs/xfs_attr.h +2 -2
index 81be9b3e4004..3e81f3f48560 100644
@@ -510,8 +510,8 @@ struct xfs_attr_intent {
 	struct xfs_da_args		*xattri_da_args;
 
 	/*
-	 * Shared buffer containing the attr name and value so that the logging
-	 * code can share large memory buffers between log items.
+	 * Shared buffer containing the attr name, new name, and value so that
+	 * the logging code can share large memory buffers between log items.
 	 */
 	struct xfs_attri_log_nameval	*xattri_nameval;
 
fs/xfs/libxfs/xfs_da_btree.h +0 -0
index ffa3df5b2893..a4b29827603f 100644

fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 63

Quoted 9 lines
fs/xfs/libxfs/xfs_da_btree.h +2 -0
@@ -55,7 +55,9 @@ enum xfs_dacmp {
 typedef struct xfs_da_args {
 	struct xfs_da_geometry *geo;	/* da block geometry */
 	const uint8_t		*name;		/* string (maybe not NULL terminated) */
+	const uint8_t	*new_name;	/* new attr name */
 	int		namelen;	/* length of string (maybe no NULL) */
+	int		new_namelen;	/* new attr name len */
 	uint8_t		filetype;	/* filetype of inode for directories */
 	void		*value;		/* set of bytes (maybe contain NULLs) */
 	int		valuelen;	/* length of value */

/me starts to wonder if the two name len fields and the value len field ought to be u8/u16 to conserve space in xfs_da_args, but that's an optimization question for after this patchset.

Quoted 132 lines
fs/xfs/libxfs/xfs_log_format.h +4 -2
index b351b9dc6561..62f40e6353c2 100644
@@ -117,7 +117,8 @@ struct xfs_unmount_log_format {
 #define XLOG_REG_TYPE_ATTRD_FORMAT	28
 #define XLOG_REG_TYPE_ATTR_NAME	29
 #define XLOG_REG_TYPE_ATTR_VALUE	30
-#define XLOG_REG_TYPE_MAX		30
+#define XLOG_REG_TYPE_ATTR_NNAME	31
+#define XLOG_REG_TYPE_MAX		31
 
 
 /*
@@ -909,6 +910,7 @@ struct xfs_icreate_log {
 #define XFS_ATTRI_OP_FLAGS_SET		1	/* Set the attribute */
 #define XFS_ATTRI_OP_FLAGS_REMOVE	2	/* Remove the attribute */
 #define XFS_ATTRI_OP_FLAGS_REPLACE	3	/* Replace the attribute */
+#define XFS_ATTRI_OP_FLAGS_NVREPLACE	4	/* Replace attr name and val */
 #define XFS_ATTRI_OP_FLAGS_TYPE_MASK	0xFF	/* Flags type mask */
 
 /*
@@ -926,7 +928,7 @@ struct xfs_icreate_log {
 struct xfs_attri_log_format {
 	uint16_t	alfi_type;	/* attri log item type */
 	uint16_t	alfi_size;	/* size of this item */
-	uint32_t	__pad;		/* pad to 64 bit aligned */
+	uint32_t	alfi_nname_len;	/* attr new name length */
 	uint64_t	alfi_id;	/* attri identifier */
 	uint64_t	alfi_ino;	/* the inode for this attr operation */
 	uint32_t	alfi_op_flags;	/* marks the op as a set or remove */
fs/xfs/xfs_attr_item.c +32 -7
index cf5ce607dc05..9414ee94829c 100644
@@ -75,6 +75,8 @@ static inline struct xfs_attri_log_nameval *
 xfs_attri_log_nameval_alloc(
 	const void			*name,
 	unsigned int			name_len,
+	const void			*nname,
+	unsigned int			nname_len,
 	const void			*value,
 	unsigned int			value_len)
 {
@@ -85,15 +87,25 @@ xfs_attri_log_nameval_alloc(
 	 * this. But kvmalloc() utterly sucks, so we use our own version.
 	 */
 	nv = xlog_kvmalloc(sizeof(struct xfs_attri_log_nameval) +
-					name_len + value_len);
+					name_len + nname_len + value_len);
 
 	nv->name.i_addr = nv + 1;
 	nv->name.i_len = name_len;
 	nv->name.i_type = XLOG_REG_TYPE_ATTR_NAME;
 	memcpy(nv->name.i_addr, name, name_len);
 
+	if (nname_len) {
+		nv->nname.i_addr = nv->name.i_addr + name_len;
+		nv->nname.i_len = nname_len;
+		memcpy(nv->nname.i_addr, nname, nname_len);
+	} else {
+		nv->nname.i_addr = NULL;
+		nv->nname.i_len = 0;
+	}
+	nv->nname.i_type = XLOG_REG_TYPE_ATTR_NNAME;
+
 	if (value_len) {
-		nv->value.i_addr = nv->name.i_addr + name_len;
+		nv->value.i_addr = nv->name.i_addr + nname_len + name_len;
 		nv->value.i_len = value_len;
 		memcpy(nv->value.i_addr, value, value_len);
 	} else {
@@ -147,11 +159,15 @@ xfs_attri_item_size(
 	*nbytes += sizeof(struct xfs_attri_log_format) +
 			xlog_calc_iovec_len(nv->name.i_len);
 
-	if (!nv->value.i_len)
-		return;
+	if (nv->nname.i_len) {
+		*nvecs += 1;
+		*nbytes += xlog_calc_iovec_len(nv->nname.i_len);
+	}
 
-	*nvecs += 1;
-	*nbytes += xlog_calc_iovec_len(nv->value.i_len);
+	if (nv->value.i_len) {
+		*nvecs += 1;
+		*nbytes += xlog_calc_iovec_len(nv->value.i_len);
+	}
 }
 
 /*
@@ -181,6 +197,9 @@ xfs_attri_item_format(
 	ASSERT(nv->name.i_len > 0);
 	attrip->attri_format.alfi_size++;
 
+	if (nv->nname.i_len > 0)
+		attrip->attri_format.alfi_size++;
+
 	if (nv->value.i_len > 0)
 		attrip->attri_format.alfi_size++;
 
@@ -188,6 +207,10 @@ xfs_attri_item_format(
 			&attrip->attri_format,
 			sizeof(struct xfs_attri_log_format));
 	xlog_copy_from_iovec(lv, &vecp, &nv->name);
+
+	if (nv->nname.i_len > 0)
+		xlog_copy_from_iovec(lv, &vecp, &nv->nname);
+
 	if (nv->value.i_len > 0)
 		xlog_copy_from_iovec(lv, &vecp, &nv->value);
 }
@@ -396,6 +419,7 @@ xfs_attr_log_item(
 	attrp->alfi_op_flags = attr->xattri_op_flags;
 	attrp->alfi_value_len = attr->xattri_nameval->value.i_len;
 	attrp->alfi_name_len = attr->xattri_nameval->name.i_len;
+	attrp->alfi_nname_len = attr->xattri_nameval->nname.i_len;
 	ASSERT(!(attr->xattri_da_args->attr_filter & ~XFS_ATTRI_FILTER_MASK));
 	attrp->alfi_attr_filter = attr->xattri_da_args->attr_filter;
 }
@@ -437,7 +461,8 @@ xfs_attr_create_intent(
 		 * deferred work state structure.
 		 */
 		attr->xattri_nameval = xfs_attri_log_nameval_alloc(args->name,
-				args->namelen, args->value, args->valuelen);
+				args->namelen, args->new_name,
+				args->new_namelen, args->value, args->valuelen);
 	}
 
 	attrip = xfs_attri_init(mp, attr->xattri_nameval);

fs/xfs/xfs_attr_item.c xfs_attri_validate( · line 529

Quoted 5 lines
fs/xfs/xfs_attr_item.c +0 -2
@@ -525,9 +550,6 @@ xfs_attri_validate(
 	unsigned int			op = attrp->alfi_op_flags &
 					     XFS_ATTRI_OP_FLAGS_TYPE_MASK;
 
-	if (attrp->__pad != 0)
-		return false;

I don't think it's correct to remove this check entirely -- NVREPLACE is the only operation that uses nname/nname_len, right? Shouldn't this be:

	if (op_flags != XFS_ATTRI_OP_FLAGS_NVREPLACE &&
	    attrp->alfi_nname_len != 0)
		return false;
Quoted 13 lines
fs/xfs/xfs_attr_item.c +1 -1
-
 	if (attrp->alfi_op_flags & ~XFS_ATTRI_OP_FLAGS_TYPE_MASK)
 		return false;
 
@@ -539,6 +561,7 @@ xfs_attri_validate(
 	case XFS_ATTRI_OP_FLAGS_SET:
 	case XFS_ATTRI_OP_FLAGS_REPLACE:
 	case XFS_ATTRI_OP_FLAGS_REMOVE:
+	case XFS_ATTRI_OP_FLAGS_NVREPLACE:
 		break;
 	default:
 		return false;

fs/xfs/xfs_attr_item.c xfs_attri_validate( · line 580

Quoted 10 lines
fs/xfs/xfs_attr_item.c +4 -0
@@ -548,9 +571,14 @@ xfs_attri_validate(
 		return false;
 
 	if ((attrp->alfi_name_len > XATTR_NAME_MAX) ||
+	    (attrp->alfi_nname_len > XATTR_NAME_MAX) ||
 	    (attrp->alfi_name_len == 0))
 		return false;
 
+	if (op == XFS_ATTRI_OP_FLAGS_REMOVE &&
+	    attrp->alfi_value_len != 0)
+		return false;

This change fixes a validation flaw in existing code, right?

If so, it ought to be a separate patc... you know what? 26 patches is enough, I'll let this one slide since LARP is still experimental.

--D

Quoted 128 lines
fs/xfs/xfs_attr_item.c +56 -5
+
 	return xfs_verify_ino(mp, attrp->alfi_ino);
 }
 
@@ -611,6 +639,8 @@ xfs_attri_item_recover(
 	args->whichfork = XFS_ATTR_FORK;
 	args->name = nv->name.i_addr;
 	args->namelen = nv->name.i_len;
+	args->new_name = nv->nname.i_addr;
+	args->new_namelen = nv->nname.i_len;
 	args->hashval = xfs_da_hashname(args->name, args->namelen);
 	args->attr_filter = attrp->alfi_attr_filter & XFS_ATTRI_FILTER_MASK;
 	args->op_flags = XFS_DA_OP_RECOVERY | XFS_DA_OP_OKNOENT |
@@ -621,6 +651,7 @@ xfs_attri_item_recover(
 	switch (attr->xattri_op_flags) {
 	case XFS_ATTRI_OP_FLAGS_SET:
 	case XFS_ATTRI_OP_FLAGS_REPLACE:
+	case XFS_ATTRI_OP_FLAGS_NVREPLACE:
 		args->value = nv->value.i_addr;
 		args->valuelen = nv->value.i_len;
 		args->total = xfs_attr_calc_size(args, &local);
@@ -710,6 +741,7 @@ xfs_attri_item_relog(
 	new_attrp->alfi_op_flags = old_attrp->alfi_op_flags;
 	new_attrp->alfi_value_len = old_attrp->alfi_value_len;
 	new_attrp->alfi_name_len = old_attrp->alfi_name_len;
+	new_attrp->alfi_nname_len = old_attrp->alfi_nname_len;
 	new_attrp->alfi_attr_filter = old_attrp->alfi_attr_filter;
 
 	xfs_trans_add_item(tp, &new_attrip->attri_item);
@@ -731,10 +763,41 @@ xlog_recover_attri_commit_pass2(
 	struct xfs_attri_log_nameval	*nv;
 	const void			*attr_value = NULL;
 	const void			*attr_name;
-	int                             error;
+	const void			*attr_nname = NULL;
+	int				i = 0;
+	int                             op, error = 0;
 
-	attri_formatp = item->ri_buf[0].i_addr;
-	attr_name = item->ri_buf[1].i_addr;
+	if (item->ri_total == 0) {
+		XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
+		return -EFSCORRUPTED;
+	}
+
+	attri_formatp = item->ri_buf[i].i_addr;
+	i++;
+
+	op = attri_formatp->alfi_op_flags & XFS_ATTRI_OP_FLAGS_TYPE_MASK;
+	switch (op) {
+	case XFS_ATTRI_OP_FLAGS_SET:
+	case XFS_ATTRI_OP_FLAGS_REPLACE:
+		if (item->ri_total != 3)
+			error = -EFSCORRUPTED;
+		break;
+	case XFS_ATTRI_OP_FLAGS_REMOVE:
+		if (item->ri_total != 2)
+			error = -EFSCORRUPTED;
+		break;
+	case XFS_ATTRI_OP_FLAGS_NVREPLACE:
+		if (item->ri_total != 4)
+			error = -EFSCORRUPTED;
+		break;
+	default:
+		error = -EFSCORRUPTED;
+	}
+
+	if (error) {
+		XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
+		return error;
+	}
 
 	/* Validate xfs_attri_log_format before the large memory allocation */
 	if (!xfs_attri_validate(mp, attri_formatp)) {
@@ -742,13 +805,27 @@ xlog_recover_attri_commit_pass2(
 		return -EFSCORRUPTED;
 	}
 
+	attr_name = item->ri_buf[i].i_addr;
+	i++;
+
 	if (!xfs_attr_namecheck(attr_name, attri_formatp->alfi_name_len)) {
 		XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
 		return -EFSCORRUPTED;
 	}
 
+	if (attri_formatp->alfi_nname_len) {
+		attr_nname = item->ri_buf[i].i_addr;
+		i++;
+
+		if (!xfs_attr_namecheck(attr_nname,
+				attri_formatp->alfi_nname_len)) {
+			XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
+			return -EFSCORRUPTED;
+		}
+	}
+
 	if (attri_formatp->alfi_value_len)
-		attr_value = item->ri_buf[2].i_addr;
+		attr_value = item->ri_buf[i].i_addr;
 
 	/*
 	 * Memory alloc failure will cause replay to abort.  We attach the
@@ -756,7 +833,8 @@ xlog_recover_attri_commit_pass2(
 	 * reference.
 	 */
 	nv = xfs_attri_log_nameval_alloc(attr_name,
-			attri_formatp->alfi_name_len, attr_value,
+			attri_formatp->alfi_name_len, attr_nname,
+			attri_formatp->alfi_nname_len, attr_value,
 			attri_formatp->alfi_value_len);
 
 	attrip = xfs_attri_init(mp, nv);
fs/xfs/xfs_attr_item.h +1 -0
index 3280a7930287..24d4968dd6cc 100644
@@ -13,6 +13,7 @@ struct kmem_zone;
 
 struct xfs_attri_log_nameval {
 	struct xfs_log_iovec	name;
+	struct xfs_log_iovec	nname;
 	struct xfs_log_iovec	value;
 	refcount_t		refcount;
 
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH v3 01/26] xfs: Add new name to attri/d

Quoted 35 lines · Darrick J. Wong
Quoted 24 lines · On Wed, Sep 21, 2022 at 10:44:33PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch adds two new fields to the atti/d.  They are nname and nnamelen.  This will be used for parent pointer updates since a rename operation may cause the parent pointer to update both the name and value.  So we need to carry both the new name as well as the target name in the attri/d.

---
 fs/xfs/libxfs/xfs_attr.c       |  12 +++- fs/xfs/libxfs/xfs_attr.h       |   4 +- fs/xfs/libxfs/xfs_da_btree.h   |   2 + fs/xfs/libxfs/xfs_log_format.h |   6 +- fs/xfs/xfs_attr_item.c         | 108 ++++++++++++++++++++++++++++-
----
 fs/xfs/xfs_attr_item.h         |   1 +

 6 files changed, 113 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index e28d93d232de..b1dbed7655e8 100644

fs/xfs/libxfs/xfs_attr.c xfs_attr_complete_op( · line 428

Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
@@ -423,6 +423,12 @@ xfs_attr_complete_op(
         args->op_flags &= ~XFS_DA_OP_REPLACE;
         if (do_replace) {
                 args->attr_filter &= ~XFS_ATTR_INCOMPLETE;
+               if (args->new_namelen > 0) {
+                       args->name = args->new_name;
+                       args->namelen = args->new_namelen;

/me wonders, do we need to null out new_name and new_namelen here?

Quoted 4 lines

I /think/ the answer is that the current codebase doesn't care since we're now doing XFS_DA_OP_ADDNAME, and addname looks only at name/namelen and has no idea that new_name/new_namelen even exist?

Right, that's the idea.

Quoted 227 lines
Quoted 53 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
+                       args->hashval = xfs_da_hashname(args->name,
+                                                       args-
 >namelen);
+               }
                 return replace_state;
         }

        return XFS_DAS_DONE;

fs/xfs/libxfs/xfs_attr.c +1 -0
@@ -922,9 +928,13 @@ xfs_attr_defer_replace(
         struct xfs_da_args      *args)
  {
         struct xfs_attr_intent  *new;
+       int                     op_flag;
         int                     error = 0;


-       error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_REPLACE, &new);
+       op_flag = args->new_namelen == 0 ? XFS_ATTRI_OP_FLAGS_REPLACE :
+                 XFS_ATTRI_OP_FLAGS_NVREPLACE;
+
+       error = xfs_attr_intent_init(args, op_flag, &new); if (error)
                return error;

fs/xfs/libxfs/xfs_attr.h +0 -0
index 81be9b3e4004..3e81f3f48560 100644
@@ -510,8 +510,8 @@ struct xfs_attr_intent {
         struct xfs_da_args              *xattri_da_args;


        /*
-        * Shared buffer containing the attr name and value so that the logging
-        * code can share large memory buffers between log items. +        * Shared buffer containing the attr name, new name, and value so that
+        * the logging code can share large memory buffers between log items.
         */
        struct xfs_attri_log_nameval    *xattri_nameval;

fs/xfs/libxfs/xfs_da_btree.h +0 -0
index ffa3df5b2893..a4b29827603f 100644
@@ -55,7 +55,9 @@ enum xfs_dacmp {
  typedef struct xfs_da_args {

        struct xfs_da_geometry *geo;    /* da block geometry */ const uint8_t           *name;          /* string (maybe not NULL terminated) */
+       const uint8_t   *new_name;      /* new attr name */

Quoted 8 lines

        int             namelen;        /* length of string (maybe no NULL) */
+       int             new_namelen;    /* new attr name len */ uint8_t         filetype;       /* filetype of inode for directories */
        void            *value;         /* set of bytes (maybe contain NULLs) */
        int             valuelen;       /* length of value */

/me starts to wonder if the two name len fields and the value len field
ought to be u8/u16 to conserve space in xfs_da_args, but that's an optimization question for after this patchset.

Quoted 148 lines
fs/xfs/libxfs/xfs_log_format.h +2 -1
index b351b9dc6561..62f40e6353c2 100644
@@ -117,7 +117,8 @@ struct xfs_unmount_log_format {
  #define XLOG_REG_TYPE_ATTRD_FORMAT     28
  #define XLOG_REG_TYPE_ATTR_NAME        29
  #define XLOG_REG_TYPE_ATTR_VALUE       30
-#define XLOG_REG_TYPE_MAX              30
+#define XLOG_REG_TYPE_ATTR_NNAME       31
+#define XLOG_REG_TYPE_MAX              31



 /*

fs/xfs/libxfs/xfs_log_format.h +0 -0
@@ -909,6 +910,7 @@ struct xfs_icreate_log {
  #define XFS_ATTRI_OP_FLAGS_SET         1       /* Set the

attribute */
 #define XFS_ATTRI_OP_FLAGS_REMOVE      2       /* Remove the attribute */
 #define XFS_ATTRI_OP_FLAGS_REPLACE     3       /* Replace the attribute */
+#define XFS_ATTRI_OP_FLAGS_NVREPLACE   4       /* Replace attr name and val */
 #define XFS_ATTRI_OP_FLAGS_TYPE_MASK   0xFF    /* Flags type mask */

 /*

fs/xfs/libxfs/xfs_log_format.h +0 -0
@@ -926,7 +928,7 @@ struct xfs_icreate_log {
  struct xfs_attri_log_format {

        uint16_t        alfi_type;      /* attri log item type */ uint16_t        alfi_size;      /* size of this item */ -       uint32_t        __pad;          /* pad to 64 bit aligned */ +       uint32_t        alfi_nname_len; /* attr new name length */ uint64_t        alfi_id;        /* attri identifier */ uint64_t        alfi_ino;       /* the inode for this attr operation */
        uint32_t        alfi_op_flags;  /* marks the op as a set or remove */

fs/xfs/xfs_attr_item.c +0 -0
index cf5ce607dc05..9414ee94829c 100644
@@ -75,6 +75,8 @@ static inline struct xfs_attri_log_nameval *

 xfs_attri_log_nameval_alloc(
        const void                      *name, unsigned int                    name_len, +       const void                      *nname, +       unsigned int                    nname_len, const void                      *value, unsigned int                    value_len) {

fs/xfs/xfs_attr_item.c +0 -0
@@ -85,15 +87,25 @@ xfs_attri_log_nameval_alloc(
          * this. But kvmalloc() utterly sucks, so we use our own

version.
         */
        nv = xlog_kvmalloc(sizeof(struct xfs_attri_log_nameval) + -                                       name_len + value_len); +                                       name_len + nname_len + value_len);

        nv->name.i_addr = nv + 1;
        nv->name.i_len = name_len;
        nv->name.i_type = XLOG_REG_TYPE_ATTR_NAME; memcpy(nv->name.i_addr, name, name_len);

+       if (nname_len) {
+               nv->nname.i_addr = nv->name.i_addr + name_len; +               nv->nname.i_len = nname_len;
+               memcpy(nv->nname.i_addr, nname, nname_len); +       } else {
+               nv->nname.i_addr = NULL;
+               nv->nname.i_len = 0;
+       }
+       nv->nname.i_type = XLOG_REG_TYPE_ATTR_NNAME;
+
        if (value_len) {
-               nv->value.i_addr = nv->name.i_addr + name_len; +               nv->value.i_addr = nv->name.i_addr + nname_len + name_len;
                nv->value.i_len = value_len; memcpy(nv->value.i_addr, value, value_len); } else {

fs/xfs/xfs_attr_item.c +0 -0
@@ -147,11 +159,15 @@ xfs_attri_item_size(
         *nbytes += sizeof(struct xfs_attri_log_format) +
                         xlog_calc_iovec_len(nv->name.i_len);


-       if (!nv->value.i_len)
-               return;
+       if (nv->nname.i_len) {
+               *nvecs += 1;
+               *nbytes += xlog_calc_iovec_len(nv->nname.i_len); +       }

-       *nvecs += 1;
-       *nbytes += xlog_calc_iovec_len(nv->value.i_len); +       if (nv->value.i_len) {
+               *nvecs += 1;
+               *nbytes += xlog_calc_iovec_len(nv->value.i_len); +       }
 }

 /*

fs/xfs/xfs_attr_item.c +0 -0
@@ -181,6 +197,9 @@ xfs_attri_item_format(
         ASSERT(nv->name.i_len > 0);
         attrip->attri_format.alfi_size++;


+       if (nv->nname.i_len > 0)
+               attrip->attri_format.alfi_size++;
+
        if (nv->value.i_len > 0)
                attrip->attri_format.alfi_size++;

fs/xfs/xfs_attr_item.c +5 -0
@@ -188,6 +207,10 @@ xfs_attri_item_format(
                         &attrip->attri_format,
                         sizeof(struct xfs_attri_log_format));
         xlog_copy_from_iovec(lv, &vecp, &nv->name);
+
+       if (nv->nname.i_len > 0)
+               xlog_copy_from_iovec(lv, &vecp, &nv->nname);
+
         if (nv->value.i_len > 0)
                 xlog_copy_from_iovec(lv, &vecp, &nv->value);
  }
@@ -396,6 +419,7 @@ xfs_attr_log_item(
         attrp->alfi_op_flags = attr->xattri_op_flags;
         attrp->alfi_value_len = attr->xattri_nameval->value.i_len;
         attrp->alfi_name_len = attr->xattri_nameval->name.i_len;
+       attrp->alfi_nname_len = attr->xattri_nameval->nname.i_len;

        ASSERT(!(attr->xattri_da_args->attr_filter & ~XFS_ATTRI_FILTER_MASK)); attrp->alfi_attr_filter = attr->xattri_da_args-

Quoted 1 line

attr_filter;

 }

fs/xfs/xfs_attr_item.c +0 -0
@@ -437,7 +461,8 @@ xfs_attr_create_intent(
                  * deferred work state structure.
                  */

                attr->xattri_nameval = xfs_attri_log_nameval_alloc(args->name,
-                               args->namelen, args->value, args-

Quoted 1 line

valuelen);

+                               args->namelen, args->new_name, +                               args->new_namelen, args->value, args->valuelen);
        }

        attrip = xfs_attri_init(mp, attr->xattri_nameval);

fs/xfs/xfs_attr_item.c +0 -0
@@ -525,9 +550,6 @@ xfs_attri_validate(
Quoted 6 lines

        unsigned int                    op = attrp->alfi_op_flags &
XFS_ATTRI_OP_FLAGS_TYPE_MASK;

-       if (attrp->__pad != 0)
-               return false;

I don't think it's correct to remove this check entirely -- NVREPLACE is
the only operation that uses nname/nname_len, right?  Shouldn't this be:

Quoted 3 lines

        if (op_flags != XFS_ATTRI_OP_FLAGS_NVREPLACE && attrp->alfi_nname_len != 0)
                return false;

Ok, I think that makes sense, I dont think there's a path where an NVREPLACE can be zero. Will add.

Quoted 18 lines
Quoted 18 lines

-
        if (attrp->alfi_op_flags & ~XFS_ATTRI_OP_FLAGS_TYPE_MASK) return false;

fs/xfs/xfs_attr_item.c +0 -0
@@ -539,6 +561,7 @@ xfs_attri_validate(

        case XFS_ATTRI_OP_FLAGS_SET:
        case XFS_ATTRI_OP_FLAGS_REPLACE:
        case XFS_ATTRI_OP_FLAGS_REMOVE:
+       case XFS_ATTRI_OP_FLAGS_NVREPLACE:
                break;
        default:
                return false;

fs/xfs/xfs_attr_item.c +0 -0
@@ -548,9 +571,14 @@ xfs_attri_validate(
                 return false;


        if ((attrp->alfi_name_len > XATTR_NAME_MAX) || +           (attrp->alfi_nname_len > XATTR_NAME_MAX) ||

Quoted 8 lines
Quoted 6 lines

            (attrp->alfi_name_len == 0))
                return false;

+       if (op == XFS_ATTRI_OP_FLAGS_REMOVE &&
+           attrp->alfi_value_len != 0)
+               return false;

This change fixes a validation flaw in existing code, right?

I think so, I believe this came up in one of the reviews so i added it.

Quoted 4 lines

If so, it ought to be a separate patc... you know what?  26 patches is
enough, I'll let this one slide since LARP is still experimental.

Alrighty, thanks for the reviews!

Allison

Quoted 137 lines

--D

Quoted 134 lines

+
        return xfs_verify_ino(mp, attrp->alfi_ino); }

fs/xfs/xfs_attr_item.c +2 -0
@@ -611,6 +639,8 @@ xfs_attri_item_recover(
         args->whichfork = XFS_ATTR_FORK;
         args->name = nv->name.i_addr;
         args->namelen = nv->name.i_len;
+       args->new_name = nv->nname.i_addr;
+       args->new_namelen = nv->nname.i_len;
         args->hashval = xfs_da_hashname(args->name, args->namelen);

        args->attr_filter = attrp->alfi_attr_filter & XFS_ATTRI_FILTER_MASK;
        args->op_flags = XFS_DA_OP_RECOVERY | XFS_DA_OP_OKNOENT |

fs/xfs/xfs_attr_item.c +0 -0
@@ -621,6 +651,7 @@ xfs_attri_item_recover(
         switch (attr->xattri_op_flags) {

        case XFS_ATTRI_OP_FLAGS_SET:
        case XFS_ATTRI_OP_FLAGS_REPLACE:
+       case XFS_ATTRI_OP_FLAGS_NVREPLACE:
                args->value = nv->value.i_addr; args->valuelen = nv->value.i_len; args->total = xfs_attr_calc_size(args, &local);

fs/xfs/xfs_attr_item.c +1 -0
@@ -710,6 +741,7 @@ xfs_attri_item_relog(
         new_attrp->alfi_op_flags = old_attrp->alfi_op_flags;
         new_attrp->alfi_value_len = old_attrp->alfi_value_len;
         new_attrp->alfi_name_len = old_attrp->alfi_name_len;
+       new_attrp->alfi_nname_len = old_attrp->alfi_nname_len;
         new_attrp->alfi_attr_filter = old_attrp->alfi_attr_filter;


        xfs_trans_add_item(tp, &new_attrip->attri_item);

fs/xfs/xfs_attr_item.c +3 -1
@@ -731,10 +763,41 @@ xlog_recover_attri_commit_pass2(
         struct xfs_attri_log_nameval    *nv;
         const void                      *attr_value = NULL;
         const void                      *attr_name;
-       int                             error;
+       const void                      *attr_nname = NULL;
+       int                             i = 0;
+       int                             op, error = 0;


-       attri_formatp = item->ri_buf[0].i_addr;
-       attr_name = item->ri_buf[1].i_addr;
+       if (item->ri_total == 0) {
+               XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp); +               return -EFSCORRUPTED;
+       }

fs/xfs/xfs_attr_item.c +5 -0
+
+       attri_formatp = item->ri_buf[i].i_addr;
+       i++;
+
+       op = attri_formatp->alfi_op_flags &

XFS_ATTRI_OP_FLAGS_TYPE_MASK;
+       switch (op) {
+       case XFS_ATTRI_OP_FLAGS_SET:
+       case XFS_ATTRI_OP_FLAGS_REPLACE:
+               if (item->ri_total != 3)
+                       error = -EFSCORRUPTED;
+               break;
+       case XFS_ATTRI_OP_FLAGS_REMOVE:
+               if (item->ri_total != 2)
+                       error = -EFSCORRUPTED;
+               break;
+       case XFS_ATTRI_OP_FLAGS_NVREPLACE:
+               if (item->ri_total != 4)
+                       error = -EFSCORRUPTED;
+               break;
+       default:
+               error = -EFSCORRUPTED;
+       }
+
+       if (error) {
+               XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp); +               return error;
+       }

        /* Validate xfs_attri_log_format before the large memory allocation */
        if (!xfs_attri_validate(mp, attri_formatp)) {

fs/xfs/xfs_attr_item.c +0 -0
@@ -742,13 +805,27 @@ xlog_recover_attri_commit_pass2(
                 return -EFSCORRUPTED;
         }


+       attr_name = item->ri_buf[i].i_addr;
+       i++;
+
        if (!xfs_attr_namecheck(attr_name, attri_formatp-

Quoted 1 line

alfi_name_len)) {

                XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp); return -EFSCORRUPTED;
        }

+       if (attri_formatp->alfi_nname_len) {
+               attr_nname = item->ri_buf[i].i_addr;
+               i++;
+
+               if (!xfs_attr_namecheck(attr_nname,
+                               attri_formatp->alfi_nname_len)) { +                       XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
+                       return -EFSCORRUPTED;
+               }
+       }
+
        if (attri_formatp->alfi_value_len)
-               attr_value = item->ri_buf[2].i_addr;
+               attr_value = item->ri_buf[i].i_addr;

        /*
         * Memory alloc failure will cause replay to abort.  We attach the

fs/xfs/xfs_attr_item.c +2 -1
@@ -756,7 +833,8 @@ xlog_recover_attri_commit_pass2(
          * reference.
          */
         nv = xfs_attri_log_nameval_alloc(attr_name,
-                       attri_formatp->alfi_name_len, attr_value,
+                       attri_formatp->alfi_name_len, attr_nname,
+                       attri_formatp->alfi_nname_len, attr_value,
                         attri_formatp->alfi_value_len);


        attrip = xfs_attri_init(mp, nv);

fs/xfs/xfs_attr_item.h +0 -0
index 3280a7930287..24d4968dd6cc 100644
@@ -13,6 +13,7 @@ struct kmem_zone;


 struct xfs_attri_log_nameval {
        struct xfs_log_iovec    name;
+       struct xfs_log_iovec    nname;
        struct xfs_log_iovec    value;
        refcount_t              refcount;

Signature · 1 line
2.25.1
#4 lore raw

PATCH v3 2/26 xfs: Increase XFS_DEFER_OPS_NR_INODES to 5

In reply to [email protected]

From: Allison Henderson <[email protected]>

Renames that generate parent pointer updates can join up to 5 inodes locked in sorted order. So we need to increase the number of defer ops inodes and relock them in the same way.

---
 fs/xfs/libxfs/xfs_defer.c | 28 ++++++++++++++++++++++++++--
 fs/xfs/libxfs/xfs_defer.h |  8 +++++++-
 fs/xfs/xfs_inode.c        |  2 +-
 fs/xfs/xfs_inode.h        |  1 +
 4 files changed, 35 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_defer.c +26 -2
index 5a321b783398..c0279b57e51d 100644
@@ -820,13 +820,37 @@ xfs_defer_ops_continue(
 	struct xfs_trans		*tp,
 	struct xfs_defer_resources	*dres)
 {
-	unsigned int			i;
+	unsigned int			i, j;
+	struct xfs_inode		*sips[XFS_DEFER_OPS_NR_INODES];
+	struct xfs_inode		*temp;
 
 	ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
 	ASSERT(!(tp->t_flags & XFS_TRANS_DIRTY));
 
 	/* Lock the captured resources to the new transaction. */
-	if (dfc->dfc_held.dr_inos == 2)
+	if (dfc->dfc_held.dr_inos > 2) {
+		/*
+		 * Renames with parent pointer updates can lock up to 5 inodes,
+		 * sorted by their inode number.  So we need to make sure they
+		 * are relocked in the same way.
+		 */
+		memset(sips, 0, sizeof(sips));
+		for (i = 0; i < dfc->dfc_held.dr_inos; i++)
+			sips[i] = dfc->dfc_held.dr_ip[i];
+
+		/* Bubble sort of at most 5 inodes */
+		for (i = 0; i < dfc->dfc_held.dr_inos; i++) {
+			for (j = 1; j < dfc->dfc_held.dr_inos; j++) {
+				if (sips[j]->i_ino < sips[j-1]->i_ino) {
+					temp = sips[j];
+					sips[j] = sips[j-1];
+					sips[j-1] = temp;
+				}
+			}
+		}
+
+		xfs_lock_inodes(sips, dfc->dfc_held.dr_inos, XFS_ILOCK_EXCL);
+	} else if (dfc->dfc_held.dr_inos == 2)
 		xfs_lock_two_inodes(dfc->dfc_held.dr_ip[0], XFS_ILOCK_EXCL,
 				    dfc->dfc_held.dr_ip[1], XFS_ILOCK_EXCL);
 	else if (dfc->dfc_held.dr_inos == 1)
fs/xfs/libxfs/xfs_defer.h +7 -1
index 114a3a4930a3..3e4029d2ce41 100644
@@ -70,7 +70,13 @@ extern const struct xfs_defer_op_type xfs_attr_defer_type;
 /*
  * Deferred operation item relogging limits.
  */
-#define XFS_DEFER_OPS_NR_INODES	2	/* join up to two inodes */
+
+/*
+ * Rename w/ parent pointers can require up to 5 inodes with defered ops to
+ * be joined to the transaction: src_dp, target_dp, src_ip, target_ip, and wip.
+ * These inodes are locked in sorted order by their inode numbers
+ */
+#define XFS_DEFER_OPS_NR_INODES	5
 #define XFS_DEFER_OPS_NR_BUFS	2	/* join up to two buffers */
 
 /* Resources that must be held across a transaction roll. */
fs/xfs/xfs_inode.c +1 -1
index c000b74dd203..5ebbfceb1ada 100644
@@ -447,7 +447,7 @@ xfs_lock_inumorder(
  * lock more than one at a time, lockdep will report false positives saying we
  * have violated locking orders.
  */
-static void
+void
 xfs_lock_inodes(
 	struct xfs_inode	**ips,
 	int			inodes,
fs/xfs/xfs_inode.h +1 -0
index fa780f08dc89..2eaed98af814 100644
@@ -574,5 +574,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_lock_inodes(struct xfs_inode **ips, int inodes, uint lock_mode);
 
 #endif	/* __XFS_INODE_H__ */
Signature · 1 line
2.25.1
Reviewed-by on v3 2/26
#5 lore raw

Re: [PATCH v3 02/26] xfs: Increase XFS_DEFER_OPS_NR_INODES to 5

Quoted 63 lines · On Wed, Sep 21, 2022 at 10:44:34PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Renames that generate parent pointer updates can join up to 5 inodes locked in sorted order. So we need to increase the number of defer ops inodes and relock them in the same way.

---
 fs/xfs/libxfs/xfs_defer.c | 28 ++++++++++++++++++++++++++--
 fs/xfs/libxfs/xfs_defer.h |  8 +++++++-
 fs/xfs/xfs_inode.c        |  2 +-
 fs/xfs/xfs_inode.h        |  1 +
 4 files changed, 35 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_defer.c +26 -2
index 5a321b783398..c0279b57e51d 100644
@@ -820,13 +820,37 @@ xfs_defer_ops_continue(
 	struct xfs_trans		*tp,
 	struct xfs_defer_resources	*dres)
 {
-	unsigned int			i;
+	unsigned int			i, j;
+	struct xfs_inode		*sips[XFS_DEFER_OPS_NR_INODES];
+	struct xfs_inode		*temp;
 
 	ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
 	ASSERT(!(tp->t_flags & XFS_TRANS_DIRTY));
 
 	/* Lock the captured resources to the new transaction. */
-	if (dfc->dfc_held.dr_inos == 2)
+	if (dfc->dfc_held.dr_inos > 2) {
+		/*
+		 * Renames with parent pointer updates can lock up to 5 inodes,
+		 * sorted by their inode number.  So we need to make sure they
+		 * are relocked in the same way.
+		 */
+		memset(sips, 0, sizeof(sips));
+		for (i = 0; i < dfc->dfc_held.dr_inos; i++)
+			sips[i] = dfc->dfc_held.dr_ip[i];
+
+		/* Bubble sort of at most 5 inodes */
+		for (i = 0; i < dfc->dfc_held.dr_inos; i++) {
+			for (j = 1; j < dfc->dfc_held.dr_inos; j++) {
+				if (sips[j]->i_ino < sips[j-1]->i_ino) {
+					temp = sips[j];
+					sips[j] = sips[j-1];
+					sips[j-1] = temp;
+				}
+			}
+		}
+
+		xfs_lock_inodes(sips, dfc->dfc_held.dr_inos, XFS_ILOCK_EXCL);
+	} else if (dfc->dfc_held.dr_inos == 2)
 		xfs_lock_two_inodes(dfc->dfc_held.dr_ip[0], XFS_ILOCK_EXCL,
 				    dfc->dfc_held.dr_ip[1], XFS_ILOCK_EXCL);
 	else if (dfc->dfc_held.dr_inos == 1)
fs/xfs/libxfs/xfs_defer.h +0 -0
index 114a3a4930a3..3e4029d2ce41 100644

fs/xfs/libxfs/xfs_defer.h extern const struct xfs_defer_op_type xfs_attr_defer_type; · line 75

Quoted 7 lines
fs/xfs/libxfs/xfs_defer.h +3 -1
@@ -70,7 +70,13 @@ extern const struct xfs_defer_op_type xfs_attr_defer_type;
 /*
  * Deferred operation item relogging limits.
  */
-#define XFS_DEFER_OPS_NR_INODES	2	/* join up to two inodes */
+
+/*
+ * Rename w/ parent pointers can require up to 5 inodes with defered ops to

s/defered/deferred/

fs/xfs/libxfs/xfs_defer.h extern const struct xfs_defer_op_type xfs_attr_defer_type; · line 78

Quoted 3 lines
fs/xfs/libxfs/xfs_defer.h +3 -0
+ * be joined to the transaction: src_dp, target_dp, src_ip, target_ip, and wip.
+ * These inodes are locked in sorted order by their inode numbers
+ */

When would we be processing *five* different inodes?

Does this happen when src_ip is a child of src_dp, target_ip is a child of target_dp, all four inodes are distinct, and the VFS asks us to move src_ip from src_dp to target_dp, unlink target_ip from target_dp, *and* install a whiteout in the dirent in src_dp? In which case src_ip, target_ip, and wip all need parent pointer adjustments?

So that's three inodes that need to stay locked for deferred operations; what about src_dp and target_dp? I don't think they need to stay locked, but OTOH it's probably easier (for now) to lock everything until the end of the entire rename operation instead of making everyone reason about when they fall off the transaction chain, right?

If the answer to all that is yes and the typo gets fixed, then

--D

Quoted 31 lines
fs/xfs/libxfs/xfs_defer.h +1 -0
+#define XFS_DEFER_OPS_NR_INODES	5
 #define XFS_DEFER_OPS_NR_BUFS	2	/* join up to two buffers */
 
 /* Resources that must be held across a transaction roll. */
fs/xfs/xfs_inode.c +1 -1
index c000b74dd203..5ebbfceb1ada 100644
@@ -447,7 +447,7 @@ xfs_lock_inumorder(
  * lock more than one at a time, lockdep will report false positives saying we
  * have violated locking orders.
  */
-static void
+void
 xfs_lock_inodes(
 	struct xfs_inode	**ips,
 	int			inodes,
fs/xfs/xfs_inode.h +1 -0
index fa780f08dc89..2eaed98af814 100644
@@ -574,5 +574,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_lock_inodes(struct xfs_inode **ips, int inodes, uint lock_mode);
 
 #endif	/* __XFS_INODE_H__ */
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH v3 02/26] xfs: Increase XFS_DEFER_OPS_NR_INODES to 5

Quoted 93 lines · Darrick J. Wong
Quoted 80 lines · On Wed, Sep 21, 2022 at 10:44:34PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Renames that generate parent pointer updates can join up to 5 inodes locked in sorted order.  So we need to increase the number of defer ops inodes and relock them in the same way.

---
 fs/xfs/libxfs/xfs_defer.c | 28 ++++++++++++++++++++++++++-- fs/xfs/libxfs/xfs_defer.h |  8 +++++++- fs/xfs/xfs_inode.c        |  2 +- fs/xfs/xfs_inode.h        |  1 +

 4 files changed, 35 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_defer.c +3 -1
index 5a321b783398..c0279b57e51d 100644
@@ -820,13 +820,37 @@ xfs_defer_ops_continue(
         struct xfs_trans                *tp,
         struct xfs_defer_resources      *dres)
  {
-       unsigned int                    i;
+       unsigned int                    i, j;
+       struct
 xfs_inode                *sips[XFS_DEFER_OPS_NR_INODES];
+       struct xfs_inode                *temp;


        ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); ASSERT(!(tp->t_flags & XFS_TRANS_DIRTY));

        /* Lock the captured resources to the new transaction. */ -       if (dfc->dfc_held.dr_inos == 2)
+       if (dfc->dfc_held.dr_inos > 2) {
+               /*
+                * Renames with parent pointer updates can lock up to 5 inodes,
+                * sorted by their inode number.  So we need to make sure they
+                * are relocked in the same way.
+                */
+               memset(sips, 0, sizeof(sips));
+               for (i = 0; i < dfc->dfc_held.dr_inos; i++) +                       sips[i] = dfc->dfc_held.dr_ip[i]; +
+               /* Bubble sort of at most 5 inodes */
+               for (i = 0; i < dfc->dfc_held.dr_inos; i++) { +                       for (j = 1; j < dfc->dfc_held.dr_inos; j++) {
+                               if (sips[j]->i_ino < sips[j-1]-

Quoted 1 line

i_ino) {

+                                       temp = sips[j]; +                                       sips[j] = sips[j-1]; +                                       sips[j-1] = temp; +                               }
+                       }
+               }
+
+               xfs_lock_inodes(sips, dfc->dfc_held.dr_inos, XFS_ILOCK_EXCL);
+       } else if (dfc->dfc_held.dr_inos == 2) xfs_lock_two_inodes(dfc->dfc_held.dr_ip[0], XFS_ILOCK_EXCL,
                                    dfc->dfc_held.dr_ip[1], XFS_ILOCK_EXCL);
        else if (dfc->dfc_held.dr_inos == 1)

fs/xfs/libxfs/xfs_defer.h +0 -1
index 114a3a4930a3..3e4029d2ce41 100644
@@ -70,7 +70,13 @@ extern const struct xfs_defer_op_type
 xfs_attr_defer_type;
  /*
   * Deferred operation item relogging limits.
   */
-#define XFS_DEFER_OPS_NR_INODES        2       /* join up to two

inodes */

fs/xfs/libxfs/xfs_defer.h +3 -0
+
+/*
+ * Rename w/ parent pointers can require up to 5 inodes with
Quoted 1 line

defered ops to

s/defered/deferred/

Quoted 4 lines

+ * be joined to the transaction: src_dp, target_dp, src_ip, target_ip, and wip.
+ * These inodes are locked in sorted order by their inode numbers
+ */

When would we be processing *five* different inodes?

Quoted 8 lines

Does this happen when src_ip is a child of src_dp, target_ip is a child
of target_dp, all four inodes are distinct, and the VFS asks us to move
src_ip from src_dp to target_dp, unlink target_ip from target_dp, *and*
install a whiteout in the dirent in src_dp?  In which case src_ip, target_ip, and wip all need parent pointer adjustments?

Right, the src_ip is overwriting the target_ip in another directory.

Quoted 4 lines

So that's three inodes that need to stay locked for deferred operations;
what about src_dp and target_dp?

Well they need their directory entries updated, also we need the parents to reconstruct what the old parent pointer for their children were so that we can remove the correct one from the child ips.

Quoted 7 lines

I don't think they need to stay
locked, but OTOH it's probably easier (for now) to lock everything until
the end of the entire rename operation instead of making everyone reason about when they fall off the transaction chain, right?

If the answer to all that is yes and the typo gets fixed, then

It makes sense to me that they should stay locked. Will update the typo.

Thanks for the reviews!
Allison

Quoted 40 lines

--D

Quoted 36 lines

+#define XFS_DEFER_OPS_NR_INODES        5
 #define XFS_DEFER_OPS_NR_BUFS  2       /* join up to two buffers */

 /* Resources that must be held across a transaction roll. */

fs/xfs/xfs_inode.c +0 -0
index c000b74dd203..5ebbfceb1ada 100644
@@ -447,7 +447,7 @@ xfs_lock_inumorder(
   * lock more than one at a time, lockdep will report false

positives saying we
  * have violated locking orders.
  */

fs/xfs/xfs_inode.c +1 -1
-static void
+void

 xfs_lock_inodes(
        struct xfs_inode        **ips,
        int                     inodes,

fs/xfs/xfs_inode.h +0 -0
index fa780f08dc89..2eaed98af814 100644
@@ -574,5 +574,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_lock_inodes(struct xfs_inode **ips, int inodes, uint lock_mode);

 #endif /* __XFS_INODE_H__ */

Signature · 1 line
2.25.1
#7 lore raw

PATCH v3 3/26 xfs: Hold inode locks in xfs_ialloc

In reply to [email protected]

From: Allison Henderson <[email protected]>

Modify xfs_ialloc to hold locks after return. Caller will be responsible for manual unlock. We will need this later to hold locks across parent pointer operations

---
 fs/xfs/xfs_inode.c   | 6 +++++-
 fs/xfs/xfs_qm.c      | 4 +++-
 fs/xfs/xfs_symlink.c | 3 +++
 3 files changed, 11 insertions(+), 2 deletions(-)
fs/xfs/xfs_inode.c +5 -1
index 5ebbfceb1ada..f21f625b428e 100644
@@ -774,6 +774,8 @@ 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_init_new_inode(
@@ -899,7 +901,7 @@ xfs_init_new_inode(
 	/*
 	 * Log the new values stuffed into the inode.
 	 */
-	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, ip, 0);
 	xfs_trans_log_inode(tp, ip, flags);
 
 	/* now that we have an i_mode we can setup the inode structure */
@@ -1076,6 +1078,7 @@ xfs_create(
 	xfs_qm_dqrele(pdqp);
 
 	*ipp = ip;
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 	return 0;
 
  out_trans_cancel:
@@ -1172,6 +1175,7 @@ xfs_create_tmpfile(
 	xfs_qm_dqrele(pdqp);
 
 	*ipp = ip;
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 	return 0;
 
  out_trans_cancel:
fs/xfs/xfs_qm.c +3 -1
index 18bb4ec4d7c9..96e7b4959721 100644
@@ -818,8 +818,10 @@ xfs_qm_qino_alloc(
 		ASSERT(xfs_is_shutdown(mp));
 		xfs_alert(mp, "%s failed (error %d)!", __func__, error);
 	}
-	if (need_alloc)
+	if (need_alloc) {
 		xfs_finish_inode_setup(*ipp);
+		xfs_iunlock(*ipp, XFS_ILOCK_EXCL);
+	}
 	return error;
 }
 
fs/xfs/xfs_symlink.c +3 -0
index 8389f3ef88ef..d8e120913036 100644
@@ -337,6 +337,7 @@ xfs_symlink(
 	xfs_qm_dqrele(pdqp);
 
 	*ipp = ip;
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 	return 0;
 
 out_trans_cancel:
@@ -358,6 +359,8 @@ xfs_symlink(
 
 	if (unlock_dp_on_error)
 		xfs_iunlock(dp, XFS_ILOCK_EXCL);
+	if (ip)
+		xfs_iunlock(ip, XFS_ILOCK_EXCL);
 	return error;
 }
 
Signature · 1 line
2.25.1
#8 lore raw

PATCH v3 4/26 xfs: Hold inode locks in xfs_trans_alloc_dir

In reply to [email protected]

From: Allison Henderson <[email protected]>

Modify xfs_trans_alloc_dir to hold locks after return. Caller will be responsible for manual unlock. We will need this later to hold locks across parent pointer operations

---
 fs/xfs/xfs_inode.c | 14 ++++++++++++--
 fs/xfs/xfs_trans.c |  6 ++++--
 2 files changed, 16 insertions(+), 4 deletions(-)
fs/xfs/xfs_inode.c +12 -2
index f21f625b428e..9a3174a8f895 100644
@@ -1277,10 +1277,15 @@ xfs_link(
 	if (xfs_has_wsync(mp) || xfs_has_dirsync(mp))
 		xfs_trans_set_sync(tp);
 
-	return xfs_trans_commit(tp);
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(tdp, XFS_ILOCK_EXCL);
+	xfs_iunlock(sip, XFS_ILOCK_EXCL);
+	return error;
 
  error_return:
 	xfs_trans_cancel(tp);
+	xfs_iunlock(tdp, XFS_ILOCK_EXCL);
+	xfs_iunlock(sip, XFS_ILOCK_EXCL);
  std_return:
 	if (error == -ENOSPC && nospace_error)
 		error = nospace_error;
@@ -2516,15 +2521,20 @@ xfs_remove(
 
 	error = xfs_trans_commit(tp);
 	if (error)
-		goto std_return;
+		goto out_unlock;
 
 	if (is_dir && xfs_inode_is_filestream(ip))
 		xfs_filestream_deassociate(ip);
 
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	xfs_iunlock(dp, XFS_ILOCK_EXCL);
 	return 0;
 
  out_trans_cancel:
 	xfs_trans_cancel(tp);
+ out_unlock:
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	xfs_iunlock(dp, XFS_ILOCK_EXCL);
  std_return:
 	return error;
 }
fs/xfs/xfs_trans.c +4 -2
index 7bd16fbff534..ac98ff416e54 100644
@@ -1356,6 +1356,8 @@ xfs_trans_alloc_ichange(
  * The caller must ensure that the on-disk dquots attached to this inode have
  * already been allocated and initialized.  The ILOCKs will be dropped when the
  * transaction is committed or cancelled.
+ *
+ * Caller is responsible for unlocking the inodes manually upon return
  */
 int
 xfs_trans_alloc_dir(
@@ -1386,8 +1388,8 @@ xfs_trans_alloc_dir(
 
 	xfs_lock_two_inodes(dp, XFS_ILOCK_EXCL, ip, XFS_ILOCK_EXCL);
 
-	xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
-	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, dp, 0);
+	xfs_trans_ijoin(tp, ip, 0);
 
 	error = xfs_qm_dqattach_locked(dp, false);
 	if (error) {
Signature · 1 line
2.25.1
Reviewed-by on v3 4/26
#9 lore raw

Re: [PATCH v3 04/26] xfs: Hold inode locks in xfs_trans_alloc_dir

Quoted 7 lines · On Wed, Sep 21, 2022 at 10:44:36PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Modify xfs_trans_alloc_dir to hold locks after return. Caller will be responsible for manual unlock. We will need this later to hold locks across parent pointer operations

Looks ok,

--D

Quoted 75 lines
---
 fs/xfs/xfs_inode.c | 14 ++++++++++++--
 fs/xfs/xfs_trans.c |  6 ++++--
 2 files changed, 16 insertions(+), 4 deletions(-)
fs/xfs/xfs_inode.c +12 -2
index f21f625b428e..9a3174a8f895 100644
@@ -1277,10 +1277,15 @@ xfs_link(
 	if (xfs_has_wsync(mp) || xfs_has_dirsync(mp))
 		xfs_trans_set_sync(tp);
 
-	return xfs_trans_commit(tp);
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(tdp, XFS_ILOCK_EXCL);
+	xfs_iunlock(sip, XFS_ILOCK_EXCL);
+	return error;
 
  error_return:
 	xfs_trans_cancel(tp);
+	xfs_iunlock(tdp, XFS_ILOCK_EXCL);
+	xfs_iunlock(sip, XFS_ILOCK_EXCL);
  std_return:
 	if (error == -ENOSPC && nospace_error)
 		error = nospace_error;
@@ -2516,15 +2521,20 @@ xfs_remove(
 
 	error = xfs_trans_commit(tp);
 	if (error)
-		goto std_return;
+		goto out_unlock;
 
 	if (is_dir && xfs_inode_is_filestream(ip))
 		xfs_filestream_deassociate(ip);
 
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	xfs_iunlock(dp, XFS_ILOCK_EXCL);
 	return 0;
 
  out_trans_cancel:
 	xfs_trans_cancel(tp);
+ out_unlock:
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	xfs_iunlock(dp, XFS_ILOCK_EXCL);
  std_return:
 	return error;
 }
fs/xfs/xfs_trans.c +4 -2
index 7bd16fbff534..ac98ff416e54 100644
@@ -1356,6 +1356,8 @@ xfs_trans_alloc_ichange(
  * The caller must ensure that the on-disk dquots attached to this inode have
  * already been allocated and initialized.  The ILOCKs will be dropped when the
  * transaction is committed or cancelled.
+ *
+ * Caller is responsible for unlocking the inodes manually upon return
  */
 int
 xfs_trans_alloc_dir(
@@ -1386,8 +1388,8 @@ xfs_trans_alloc_dir(
 
 	xfs_lock_two_inodes(dp, XFS_ILOCK_EXCL, ip, XFS_ILOCK_EXCL);
 
-	xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
-	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, dp, 0);
+	xfs_trans_ijoin(tp, ip, 0);
 
 	error = xfs_qm_dqattach_locked(dp, false);
 	if (error) {
Signature · 1 line
2.25.1
#10 lore raw

Re: [PATCH v3 04/26] xfs: Hold inode locks in xfs_trans_alloc_dir

Quoted 10 lines · Darrick J. Wong
Quoted 8 lines · On Wed, Sep 21, 2022 at 10:44:36PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Modify xfs_trans_alloc_dir to hold locks after return.  Caller will be
responsible for manual unlock.  We will need this later to hold locks
across parent pointer operations

Quoted 4 lines
Quoted 1 line

Looks ok,

Great, thanks!
Allison

Quoted 82 lines

--D

Quoted 79 lines

---
 fs/xfs/xfs_inode.c | 14 ++++++++++++--
 fs/xfs/xfs_trans.c |  6 ++++--

 2 files changed, 16 insertions(+), 4 deletions(-)
fs/xfs/xfs_inode.c +0 -0
index f21f625b428e..9a3174a8f895 100644
@@ -1277,10 +1277,15 @@ xfs_link(
         if (xfs_has_wsync(mp) || xfs_has_dirsync(mp))
                 xfs_trans_set_sync(tp);


-       return xfs_trans_commit(tp);
+       error = xfs_trans_commit(tp);
+       xfs_iunlock(tdp, XFS_ILOCK_EXCL);
+       xfs_iunlock(sip, XFS_ILOCK_EXCL);
+       return error;

  error_return:
        xfs_trans_cancel(tp);
+       xfs_iunlock(tdp, XFS_ILOCK_EXCL);
+       xfs_iunlock(sip, XFS_ILOCK_EXCL);
  std_return:
        if (error == -ENOSPC && nospace_error)
                error = nospace_error;

fs/xfs/xfs_inode.c +0 -0
@@ -2516,15 +2521,20 @@ xfs_remove(


        error = xfs_trans_commit(tp);
        if (error)
-               goto std_return;
+               goto out_unlock;

        if (is_dir && xfs_inode_is_filestream(ip)) xfs_filestream_deassociate(ip);
+       xfs_iunlock(ip, XFS_ILOCK_EXCL);
+       xfs_iunlock(dp, XFS_ILOCK_EXCL); return 0;

  out_trans_cancel:
        xfs_trans_cancel(tp);
+ out_unlock:
+       xfs_iunlock(ip, XFS_ILOCK_EXCL);
+       xfs_iunlock(dp, XFS_ILOCK_EXCL); std_return:
        return error;
 }

fs/xfs/xfs_trans.c +0 -0
index 7bd16fbff534..ac98ff416e54 100644
@@ -1356,6 +1356,8 @@ xfs_trans_alloc_ichange(
   * The caller must ensure that the on-disk dquots attached to this

inode have
  * already been allocated and initialized.  The ILOCKs will be dropped when the
  * transaction is committed or cancelled.
+ *
+ * Caller is responsible for unlocking the inodes manually upon return
  */
 int
 xfs_trans_alloc_dir(

fs/xfs/xfs_trans.c +0 -0
@@ -1386,8 +1388,8 @@ xfs_trans_alloc_dir(


        xfs_lock_two_inodes(dp, XFS_ILOCK_EXCL, ip, XFS_ILOCK_EXCL);

-       xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); -       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); +       xfs_trans_ijoin(tp, dp, 0);
+       xfs_trans_ijoin(tp, ip, 0);

        error = xfs_qm_dqattach_locked(dp, false); if (error) {

Signature · 1 line
2.25.1
#11 lore raw

PATCH v3 5/26 xfs: Hold inode locks in xfs_rename

In reply to [email protected]

From: Allison Henderson <[email protected]>

Modify xfs_rename to hold all inode locks across a rename operation We will need this later when we add parent pointers

---
 fs/xfs/xfs_inode.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)
fs/xfs/xfs_inode.c +22 -13
index 9a3174a8f895..4bfa4a1579f0 100644
@@ -2837,18 +2837,16 @@ xfs_rename(
 	xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL);
 
 	/*
-	 * Join all the inodes to the transaction. From this point on,
-	 * we can rely on either trans_commit or trans_cancel to unlock
-	 * them.
+	 * Join all the inodes to the transaction.
 	 */
-	xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, src_dp, 0);
 	if (new_parent)
-		xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL);
-	xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
+		xfs_trans_ijoin(tp, target_dp, 0);
+	xfs_trans_ijoin(tp, src_ip, 0);
 	if (target_ip)
-		xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL);
+		xfs_trans_ijoin(tp, target_ip, 0);
 	if (wip)
-		xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL);
+		xfs_trans_ijoin(tp, wip, 0);
 
 	/*
 	 * If we are using project inheritance, we only allow renames
@@ -2862,10 +2860,12 @@ xfs_rename(
 	}
 
 	/* RENAME_EXCHANGE is unique from here on. */
-	if (flags & RENAME_EXCHANGE)
-		return xfs_cross_rename(tp, src_dp, src_name, src_ip,
+	if (flags & RENAME_EXCHANGE) {
+		error = xfs_cross_rename(tp, src_dp, src_name, src_ip,
 					target_dp, target_name, target_ip,
 					spaceres);
+		goto out_unlock;
+	}
 
 	/*
 	 * Try to reserve quota to handle an expansion of the target directory.
@@ -3090,12 +3090,21 @@ xfs_rename(
 		xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);
 
 	error = xfs_finish_rename(tp);
-	if (wip)
-		xfs_irele(wip);
-	return error;
+
+	goto out_unlock;
 
 out_trans_cancel:
 	xfs_trans_cancel(tp);
+out_unlock:
+	/* Unlock inodes in reverse order */
+	for (i = num_inodes - 1; i >= 0; i--) {
+		if (inodes[i])
+			xfs_iunlock(inodes[i], XFS_ILOCK_EXCL);
+
+		/* Skip duplicate inodes if src and target dps are the same */
+		if (i && (inodes[i] == inodes[i - 1]))
+			i--;
+	}
 out_release_wip:
 	if (wip)
 		xfs_irele(wip);
Signature · 1 line
2.25.1
Reviewed-by on v3 5/26
#12 lore raw

Re: [PATCH v3 05/26] xfs: Hold inode locks in xfs_rename

Quoted 66 lines · On Wed, Sep 21, 2022 at 10:44:37PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Modify xfs_rename to hold all inode locks across a rename operation We will need this later when we add parent pointers

---
 fs/xfs/xfs_inode.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)
fs/xfs/xfs_inode.c +12 -13
index 9a3174a8f895..4bfa4a1579f0 100644
@@ -2837,18 +2837,16 @@ xfs_rename(
 	xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL);
 
 	/*
-	 * Join all the inodes to the transaction. From this point on,
-	 * we can rely on either trans_commit or trans_cancel to unlock
-	 * them.
+	 * Join all the inodes to the transaction.
 	 */
-	xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, src_dp, 0);
 	if (new_parent)
-		xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL);
-	xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
+		xfs_trans_ijoin(tp, target_dp, 0);
+	xfs_trans_ijoin(tp, src_ip, 0);
 	if (target_ip)
-		xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL);
+		xfs_trans_ijoin(tp, target_ip, 0);
 	if (wip)
-		xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL);
+		xfs_trans_ijoin(tp, wip, 0);
 
 	/*
 	 * If we are using project inheritance, we only allow renames
@@ -2862,10 +2860,12 @@ xfs_rename(
 	}
 
 	/* RENAME_EXCHANGE is unique from here on. */
-	if (flags & RENAME_EXCHANGE)
-		return xfs_cross_rename(tp, src_dp, src_name, src_ip,
+	if (flags & RENAME_EXCHANGE) {
+		error = xfs_cross_rename(tp, src_dp, src_name, src_ip,
 					target_dp, target_name, target_ip,
 					spaceres);
+		goto out_unlock;
+	}
 
 	/*
 	 * Try to reserve quota to handle an expansion of the target directory.
@@ -3090,12 +3090,21 @@ xfs_rename(
 		xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);
 
 	error = xfs_finish_rename(tp);
-	if (wip)
-		xfs_irele(wip);
-	return error;
+
+	goto out_unlock;
 
 out_trans_cancel:
 	xfs_trans_cancel(tp);

fs/xfs/xfs_inode.c xfs_rename( · line 3107

Quoted 10 lines
fs/xfs/xfs_inode.c +10 -0
+out_unlock:
+	/* Unlock inodes in reverse order */
+	for (i = num_inodes - 1; i >= 0; i--) {
+		if (inodes[i])
+			xfs_iunlock(inodes[i], XFS_ILOCK_EXCL);
+
+		/* Skip duplicate inodes if src and target dps are the same */
+		if (i && (inodes[i] == inodes[i - 1]))
+			i--;
+	}

Could you hoist this to a static inline xfs_iunlock_after_rename function that is adjacent to xfs_sort_for_rename, please? It's easier to verify that it does the right thing w.r.t. multiple array references pointing to the same incore inode when the two array management functions are right next to each other.

static inline void
xfs_iunlock_after_rename(

	struct xfs_inode	**i_tab,
	int			num_inodes)
{
	for (i = num_inodes - 1; i >= 0; i--) {
		/* Skip duplicate inodes if src and target dps are the same */
		if (!i_tab[i] || (i > 0 && i_tab[i] == i_tab[i - 1]))
			continue;
		xfs_iunlock(i_tab[i], XFS_ILOCK_EXCL);
	}
}

With that cleaned up,

--D

Quoted 6 lines
fs/xfs/xfs_inode.c +0 -0
 out_release_wip:
 	if (wip)
 		xfs_irele(wip);
Signature · 1 line
2.25.1
#13 lore raw

Re: [PATCH v3 05/26] xfs: Hold inode locks in xfs_rename

Quoted 95 lines · Darrick J. Wong
Quoted 80 lines · On Wed, Sep 21, 2022 at 10:44:37PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Modify xfs_rename to hold all inode locks across a rename operation We will need this later when we add parent pointers

---
 fs/xfs/xfs_inode.c | 35 ++++++++++++++++++++++-------------

 1 file changed, 22 insertions(+), 13 deletions(-)
fs/xfs/xfs_inode.c +0 -0
index 9a3174a8f895..4bfa4a1579f0 100644
@@ -2837,18 +2837,16 @@ xfs_rename(
         xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL);


        /*
-        * Join all the inodes to the transaction. From this point on,
-        * we can rely on either trans_commit or trans_cancel to unlock
-        * them.
+        * Join all the inodes to the transaction.
         */
-       xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, src_dp, 0);
        if (new_parent)
-               xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL); -       xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
+               xfs_trans_ijoin(tp, target_dp, 0);
+       xfs_trans_ijoin(tp, src_ip, 0);
        if (target_ip)
-               xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL); +               xfs_trans_ijoin(tp, target_ip, 0);
        if (wip)
-               xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); +               xfs_trans_ijoin(tp, wip, 0);

        /*
         * If we are using project inheritance, we only allow renames

fs/xfs/xfs_inode.c +0 -0
@@ -2862,10 +2860,12 @@ xfs_rename(
         }


        /* RENAME_EXCHANGE is unique from here on. */ -       if (flags & RENAME_EXCHANGE)
-               return xfs_cross_rename(tp, src_dp, src_name, src_ip,
+       if (flags & RENAME_EXCHANGE) {
+               error = xfs_cross_rename(tp, src_dp, src_name, src_ip,
                                        target_dp, target_name, target_ip,
                                        spaceres);
+               goto out_unlock;
+       }

        /*
         * Try to reserve quota to handle an expansion of the target directory.

fs/xfs/xfs_inode.c +0 -0
@@ -3090,12 +3090,21 @@ xfs_rename(
                 xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);


        error = xfs_finish_rename(tp);
-       if (wip)
-               xfs_irele(wip);
-       return error;
+
+       goto out_unlock;

 out_trans_cancel:
        xfs_trans_cancel(tp);

fs/xfs/xfs_inode.c +7 -0
+out_unlock:
+       /* Unlock inodes in reverse order */
+       for (i = num_inodes - 1; i >= 0; i--) {
+               if (inodes[i])
+                       xfs_iunlock(inodes[i], XFS_ILOCK_EXCL);
+
+               /* Skip duplicate inodes if src and target dps are
Quoted 4 lines

the same */
+               if (i && (inodes[i] == inodes[i - 1])) +                       i--;
+       }

Could you hoist this to a static inline xfs_iunlock_after_rename function that is adjacent to xfs_sort_for_rename, please?  It's easier
to verify that it does the right thing w.r.t. multiple array references
pointing to the same incore inode when the two array management functions are right next to each other.

Quoted 14 lines

static inline void
xfs_iunlock_after_rename(
        struct xfs_inode        **i_tab,
        int                     num_inodes)
{
        for (i = num_inodes - 1; i >= 0; i--) {
                /* Skip duplicate inodes if src and target dps are the same */
                if (!i_tab[i] || (i > 0 && i_tab[i] == i_tab[i - 1])) continue;
                xfs_iunlock(i_tab[i], XFS_ILOCK_EXCL);
        }
}

Sure, that looks fine. Will do. Thanks!
Allison

Quoted 11 lines

With that cleaned up,

--D

Quoted 6 lines

 out_release_wip:
        if (wip)
                xfs_irele(wip);

Signature · 1 line
2.25.1
#14 lore raw

PATCH v3 6/26 xfs: Expose init_xattrs in xfs_create_tmpfile

In reply to [email protected]

From: Allison Henderson <[email protected]>

Tmp files are used as part of rename operations and will need attr forks initialized for parent pointers. Expose the init_xattrs parameter to the calling function to initialize the fork.

---
 fs/xfs/xfs_inode.c | 8 +++++---
 fs/xfs/xfs_inode.h | 2 +-
 fs/xfs/xfs_iops.c  | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)
fs/xfs/xfs_inode.c +5 -3
index 4bfa4a1579f0..ff680de560d2 100644
@@ -1108,6 +1108,7 @@ xfs_create_tmpfile(
 	struct user_namespace	*mnt_userns,
 	struct xfs_inode	*dp,
 	umode_t			mode,
+	bool			init_xattrs,
 	struct xfs_inode	**ipp)
 {
 	struct xfs_mount	*mp = dp->i_mount;
@@ -1148,7 +1149,7 @@ xfs_create_tmpfile(
 	error = xfs_dialloc(&tp, dp->i_ino, mode, &ino);
 	if (!error)
 		error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode,
-				0, 0, prid, false, &ip);
+				0, 0, prid, init_xattrs, &ip);
 	if (error)
 		goto out_trans_cancel;
 
@@ -2726,6 +2727,7 @@ xfs_rename_alloc_whiteout(
 	struct user_namespace	*mnt_userns,
 	struct xfs_name		*src_name,
 	struct xfs_inode	*dp,
+	bool			init_xattrs,
 	struct xfs_inode	**wip)
 {
 	struct xfs_inode	*tmpfile;
@@ -2733,7 +2735,7 @@ xfs_rename_alloc_whiteout(
 	int			error;
 
 	error = xfs_create_tmpfile(mnt_userns, dp, S_IFCHR | WHITEOUT_MODE,
-				   &tmpfile);
+				   init_xattrs, &tmpfile);
 	if (error)
 		return error;
 
@@ -2797,7 +2799,7 @@ xfs_rename(
 	 */
 	if (flags & RENAME_WHITEOUT) {
 		error = xfs_rename_alloc_whiteout(mnt_userns, src_name,
-						  target_dp, &wip);
+						  target_dp, false, &wip);
 		if (error)
 			return error;
 
fs/xfs/xfs_inode.h +1 -1
index 2eaed98af814..5735de32beeb 100644
@@ -478,7 +478,7 @@ int		xfs_create(struct user_namespace *mnt_userns,
 			   umode_t mode, dev_t rdev, bool need_xattr,
 			   struct xfs_inode **ipp);
 int		xfs_create_tmpfile(struct user_namespace *mnt_userns,
-			   struct xfs_inode *dp, umode_t mode,
+			   struct xfs_inode *dp, umode_t mode, bool init_xattrs,
 			   struct xfs_inode **ipp);
 int		xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
 			   struct xfs_inode *ip);
fs/xfs/xfs_iops.c +2 -1
index 5d670c85dcc2..07a26f4f6348 100644
@@ -200,7 +200,8 @@ xfs_generic_create(
 				xfs_create_need_xattr(dir, default_acl, acl),
 				&ip);
 	} else {
-		error = xfs_create_tmpfile(mnt_userns, XFS_I(dir), mode, &ip);
+		error = xfs_create_tmpfile(mnt_userns, XFS_I(dir), mode, false,
+					   &ip);
 	}
 	if (unlikely(error))
 		goto out_free_acl;
Signature · 1 line
2.25.1
#15 lore raw

Re: [PATCH v3 06/26] xfs: Expose init_xattrs in xfs_create_tmpfile

Quoted 43 lines · On Wed, Sep 21, 2022 at 10:44:38PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Tmp files are used as part of rename operations and will need attr forks initialized for parent pointers. Expose the init_xattrs parameter to the calling function to initialize the fork.

---
 fs/xfs/xfs_inode.c | 8 +++++---
 fs/xfs/xfs_inode.h | 2 +-
 fs/xfs/xfs_iops.c  | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)
fs/xfs/xfs_inode.c +3 -1
index 4bfa4a1579f0..ff680de560d2 100644
@@ -1108,6 +1108,7 @@ xfs_create_tmpfile(
 	struct user_namespace	*mnt_userns,
 	struct xfs_inode	*dp,
 	umode_t			mode,
+	bool			init_xattrs,
 	struct xfs_inode	**ipp)
 {
 	struct xfs_mount	*mp = dp->i_mount;
@@ -1148,7 +1149,7 @@ xfs_create_tmpfile(
 	error = xfs_dialloc(&tp, dp->i_ino, mode, &ino);
 	if (!error)
 		error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode,
-				0, 0, prid, false, &ip);
+				0, 0, prid, init_xattrs, &ip);
 	if (error)
 		goto out_trans_cancel;
 
@@ -2726,6 +2727,7 @@ xfs_rename_alloc_whiteout(
 	struct user_namespace	*mnt_userns,
 	struct xfs_name		*src_name,
 	struct xfs_inode	*dp,
+	bool			init_xattrs,
 	struct xfs_inode	**wip)
 {
 	struct xfs_inode	*tmpfile;

fs/xfs/xfs_inode.c xfs_rename_alloc_whiteout( · line 2738

Quoted 5 lines
fs/xfs/xfs_inode.c +1 -1
@@ -2733,7 +2735,7 @@ xfs_rename_alloc_whiteout(
 	int			error;
 
 	error = xfs_create_tmpfile(mnt_userns, dp, S_IFCHR | WHITEOUT_MODE,
-				   &tmpfile);
+				   init_xattrs, &tmpfile);

Whiteouts are created prior to being added to a directory, right? If so, shouldn't this be s/init_xattrs/true/g to save time?

Everything else in here looks good though!

--D

Quoted 42 lines
fs/xfs/xfs_inode.c +1 -1
 	if (error)
 		return error;
 
@@ -2797,7 +2799,7 @@ xfs_rename(
 	 */
 	if (flags & RENAME_WHITEOUT) {
 		error = xfs_rename_alloc_whiteout(mnt_userns, src_name,
-						  target_dp, &wip);
+						  target_dp, false, &wip);
 		if (error)
 			return error;
 
fs/xfs/xfs_inode.h +1 -1
index 2eaed98af814..5735de32beeb 100644
@@ -478,7 +478,7 @@ int		xfs_create(struct user_namespace *mnt_userns,
 			   umode_t mode, dev_t rdev, bool need_xattr,
 			   struct xfs_inode **ipp);
 int		xfs_create_tmpfile(struct user_namespace *mnt_userns,
-			   struct xfs_inode *dp, umode_t mode,
+			   struct xfs_inode *dp, umode_t mode, bool init_xattrs,
 			   struct xfs_inode **ipp);
 int		xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
 			   struct xfs_inode *ip);
fs/xfs/xfs_iops.c +2 -1
index 5d670c85dcc2..07a26f4f6348 100644
@@ -200,7 +200,8 @@ xfs_generic_create(
 				xfs_create_need_xattr(dir, default_acl, acl),
 				&ip);
 	} else {
-		error = xfs_create_tmpfile(mnt_userns, XFS_I(dir), mode, &ip);
+		error = xfs_create_tmpfile(mnt_userns, XFS_I(dir), mode, false,
+					   &ip);
 	}
 	if (unlikely(error))
 		goto out_free_acl;
Signature · 1 line
2.25.1
#16 lore raw

Re: [PATCH v3 06/26] xfs: Expose init_xattrs in xfs_create_tmpfile

Quoted 49 lines · Darrick J. Wong
Quoted 47 lines · On Wed, Sep 21, 2022 at 10:44:38PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Tmp files are used as part of rename operations and will need attr forks
initialized for parent pointers.  Expose the init_xattrs parameter to
the calling function to initialize the fork.

---
 fs/xfs/xfs_inode.c | 8 +++++---
 fs/xfs/xfs_inode.h | 2 +-
 fs/xfs/xfs_iops.c  | 3 ++-

 3 files changed, 8 insertions(+), 5 deletions(-)
fs/xfs/xfs_inode.c +2 -1
index 4bfa4a1579f0..ff680de560d2 100644
@@ -1108,6 +1108,7 @@ xfs_create_tmpfile(
         struct user_namespace   *mnt_userns,
         struct xfs_inode        *dp,
         umode_t                 mode,
+       bool                    init_xattrs,
         struct xfs_inode        **ipp)
  {
         struct xfs_mount        *mp = dp->i_mount;
@@ -1148,7 +1149,7 @@ xfs_create_tmpfile(
         error = xfs_dialloc(&tp, dp->i_ino, mode, &ino);
         if (!error)
                 error = xfs_init_new_inode(mnt_userns, tp, dp, ino,
 mode,
-                               0, 0, prid, false, &ip);
+                               0, 0, prid, init_xattrs, &ip);
         if (error)
                 goto out_trans_cancel;

fs/xfs/xfs_inode.c +1 -0
@@ -2726,6 +2727,7 @@ xfs_rename_alloc_whiteout(
         struct user_namespace   *mnt_userns,
         struct xfs_name         *src_name,
         struct xfs_inode        *dp,
+       bool                    init_xattrs,
         struct xfs_inode        **wip)
  {
         struct xfs_inode        *tmpfile;
@@ -2733,7 +2735,7 @@ xfs_rename_alloc_whiteout(
         int                     error;
Quoted 8 lines
Quoted 5 lines


        error = xfs_create_tmpfile(mnt_userns, dp, S_IFCHR | WHITEOUT_MODE,
-                                  &tmpfile);
+                                  init_xattrs, &tmpfile);

Whiteouts are created prior to being added to a directory, right? If so, shouldn't this be s/init_xattrs/true/g to save time?

well, replaced with xfs_has_parent(mp) if we want to retain the non parent code functionality. I dont know that it really saves that much time, but we can implement it that way of folks prefer.

Quoted 2 lines

Everything else in here looks good though!

Thanks!
Allison

Quoted 55 lines

--D

Quoted 52 lines

        if (error)
                return error;

fs/xfs/xfs_inode.c +1 -1
@@ -2797,7 +2799,7 @@ xfs_rename(
          */
         if (flags & RENAME_WHITEOUT) {
                 error = xfs_rename_alloc_whiteout(mnt_userns,
 src_name,
-                                                 target_dp, &wip);
+                                                 target_dp, false,
 &wip);
                 if (error)

                        return error;

fs/xfs/xfs_inode.h +0 -0
index 2eaed98af814..5735de32beeb 100644
@@ -478,7 +478,7 @@ int         xfs_create(struct user_namespace
 *mnt_userns,

                           umode_t mode, dev_t rdev, bool need_xattr,
                           struct xfs_inode **ipp);
 int            xfs_create_tmpfile(struct user_namespace *mnt_userns,
-                          struct xfs_inode *dp, umode_t mode, +                          struct xfs_inode *dp, umode_t mode, bool init_xattrs,
                           struct xfs_inode **ipp);
 int            xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
                           struct xfs_inode *ip);

fs/xfs/xfs_iops.c +2 -1
index 5d670c85dcc2..07a26f4f6348 100644
@@ -200,7 +200,8 @@ xfs_generic_create(
                                 xfs_create_need_xattr(dir,
 default_acl, acl),
                                 &ip);
         } else {
-               error = xfs_create_tmpfile(mnt_userns, XFS_I(dir),
 mode, &ip);
+               error = xfs_create_tmpfile(mnt_userns, XFS_I(dir),
 mode, false,
+                                          &ip);

        }
        if (unlikely(error))
                goto out_free_acl;

Signature · 1 line
2.25.1
#17 lore raw

Re: [PATCH v3 06/26] xfs: Expose init_xattrs in xfs_create_tmpfile

Quoted 58 lines · Allison Henderson
Quoted 49 lines · Darrick J. Wong
Quoted 47 lines · On Wed, Sep 21, 2022 at 10:44:38PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Tmp files are used as part of rename operations and will need attr forks
initialized for parent pointers.  Expose the init_xattrs parameter to
the calling function to initialize the fork.

---
 fs/xfs/xfs_inode.c | 8 +++++---
 fs/xfs/xfs_inode.h | 2 +-
 fs/xfs/xfs_iops.c  | 3 ++-

 3 files changed, 8 insertions(+), 5 deletions(-)
fs/xfs/xfs_inode.c +2 -1
index 4bfa4a1579f0..ff680de560d2 100644
@@ -1108,6 +1108,7 @@ xfs_create_tmpfile(
         struct user_namespace   *mnt_userns,
         struct xfs_inode        *dp,
         umode_t                 mode,
+       bool                    init_xattrs,
         struct xfs_inode        **ipp)
  {
         struct xfs_mount        *mp = dp->i_mount;
@@ -1148,7 +1149,7 @@ xfs_create_tmpfile(
         error = xfs_dialloc(&tp, dp->i_ino, mode, &ino);
         if (!error)
                 error = xfs_init_new_inode(mnt_userns, tp, dp, ino,
 mode,
-                               0, 0, prid, false, &ip);
+                               0, 0, prid, init_xattrs, &ip);
         if (error)
                 goto out_trans_cancel;

fs/xfs/xfs_inode.c +1 -0
@@ -2726,6 +2727,7 @@ xfs_rename_alloc_whiteout(
         struct user_namespace   *mnt_userns,
         struct xfs_name         *src_name,
         struct xfs_inode        *dp,
+       bool                    init_xattrs,
         struct xfs_inode        **wip)
  {
         struct xfs_inode        *tmpfile;
@@ -2733,7 +2735,7 @@ xfs_rename_alloc_whiteout(
         int                     error;
Quoted 8 lines
Quoted 5 lines


        error = xfs_create_tmpfile(mnt_userns, dp, S_IFCHR | WHITEOUT_MODE,
-                                  &tmpfile);
+                                  init_xattrs, &tmpfile);

Whiteouts are created prior to being added to a directory, right? If so, shouldn't this be s/init_xattrs/true/g to save time?

Quoted 3 lines

well, replaced with xfs_has_parent(mp) if we want to retain the non parent code functionality. I dont know that it really saves that much time, but we can implement it that way of folks prefer.

I didn't used to think it would make much difference, but the reason why the init_xattrs thing got added is that Dave benchmarked file creation on a system that has selinux enabled (and hence sets selinux security xattrs on every file created) and discovered that it /did/ make a difference.

--D

Quoted 61 lines
Quoted 2 lines

Everything else in here looks good though!

Thanks!
Allison

Quoted 55 lines

--D

Quoted 52 lines

        if (error)
                return error;

fs/xfs/xfs_inode.c +1 -1
@@ -2797,7 +2799,7 @@ xfs_rename(
          */
         if (flags & RENAME_WHITEOUT) {
                 error = xfs_rename_alloc_whiteout(mnt_userns,
 src_name,
-                                                 target_dp, &wip);
+                                                 target_dp, false,
 &wip);
                 if (error)

                        return error;

fs/xfs/xfs_inode.h +0 -0
index 2eaed98af814..5735de32beeb 100644
@@ -478,7 +478,7 @@ int         xfs_create(struct user_namespace
 *mnt_userns,

                           umode_t mode, dev_t rdev, bool need_xattr,
                           struct xfs_inode **ipp);
 int            xfs_create_tmpfile(struct user_namespace *mnt_userns,
-                          struct xfs_inode *dp, umode_t mode, +                          struct xfs_inode *dp, umode_t mode, bool init_xattrs,
                           struct xfs_inode **ipp);
 int            xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
                           struct xfs_inode *ip);

fs/xfs/xfs_iops.c +2 -1
index 5d670c85dcc2..07a26f4f6348 100644
@@ -200,7 +200,8 @@ xfs_generic_create(
                                 xfs_create_need_xattr(dir,
 default_acl, acl),
                                 &ip);
         } else {
-               error = xfs_create_tmpfile(mnt_userns, XFS_I(dir),
 mode, &ip);
+               error = xfs_create_tmpfile(mnt_userns, XFS_I(dir),
 mode, false,
+                                          &ip);

        }
        if (unlikely(error))
                goto out_free_acl;

Signature · 1 line
2.25.1
#18 lore raw

PATCH v3 7/26 xfs: get directory offset when adding directory name

In reply to [email protected]

From: Allison Henderson <[email protected]>

Return the directory offset information when adding an entry to the directory.

This offset will be used as the parent pointer offset in xfs_create, xfs_symlink, xfs_link and xfs_rename.

---
 fs/xfs/libxfs/xfs_da_btree.h   | 1 +
 fs/xfs/libxfs/xfs_dir2.c       | 9 +++++++--
 fs/xfs/libxfs/xfs_dir2.h       | 2 +-
 fs/xfs/libxfs/xfs_dir2_block.c | 1 +
 fs/xfs/libxfs/xfs_dir2_leaf.c  | 2 ++
 fs/xfs/libxfs/xfs_dir2_node.c  | 2 ++
 fs/xfs/libxfs/xfs_dir2_sf.c    | 2 ++
 fs/xfs/xfs_inode.c             | 6 +++---
 fs/xfs/xfs_symlink.c           | 3 ++-
 9 files changed, 21 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_da_btree.h +1 -0
index a4b29827603f..90b86d00258f 100644
@@ -81,6 +81,7 @@ typedef struct xfs_da_args {
 	int		rmtvaluelen2;	/* remote attr value length in bytes */
 	uint32_t	op_flags;	/* operation flags */
 	enum xfs_dacmp	cmpresult;	/* name compare result for lookups */
+	xfs_dir2_dataptr_t offset;	/* OUT: offset in directory */
 } xfs_da_args_t;
 
 /*
fs/xfs/libxfs/xfs_dir2.c +7 -2
index 76eedc2756b3..c0629c2cdecc 100644
@@ -257,7 +257,8 @@ xfs_dir_createname(
 	struct xfs_inode	*dp,
 	const struct xfs_name	*name,
 	xfs_ino_t		inum,		/* new entry inode number */
-	xfs_extlen_t		total)		/* bmap's total block count */
+	xfs_extlen_t		total,		/* bmap's total block count */
+	xfs_dir2_dataptr_t	*offset)	/* OUT entry's dir offset */
 {
 	struct xfs_da_args	*args;
 	int			rval;
@@ -312,6 +313,10 @@ xfs_dir_createname(
 		rval = xfs_dir2_node_addname(args);
 
 out_free:
+	/* return the location that this entry was place in the parent inode */
+	if (offset)
+		*offset = args->offset;
+
 	kmem_free(args);
 	return rval;
 }
@@ -550,7 +555,7 @@ xfs_dir_canenter(
 	xfs_inode_t	*dp,
 	struct xfs_name	*name)		/* name of entry to add */
 {
-	return xfs_dir_createname(tp, dp, name, 0, 0);
+	return xfs_dir_createname(tp, dp, name, 0, 0, NULL);
 }
 
 /*
fs/xfs/libxfs/xfs_dir2.h +1 -1
index b6df3c34b26a..4d1c2570b833 100644
@@ -40,7 +40,7 @@ extern int xfs_dir_init(struct xfs_trans *tp, struct xfs_inode *dp,
 				struct xfs_inode *pdp);
 extern int xfs_dir_createname(struct xfs_trans *tp, struct xfs_inode *dp,
 				const struct xfs_name *name, xfs_ino_t inum,
-				xfs_extlen_t tot);
+				xfs_extlen_t tot, xfs_dir2_dataptr_t *offset);
 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);
fs/xfs/libxfs/xfs_dir2_block.c +1 -0
index 00f960a703b2..70aeab9d2a12 100644
@@ -573,6 +573,7 @@ xfs_dir2_block_addname(
 	xfs_dir2_data_put_ftype(dp->i_mount, dep, args->filetype);
 	tagp = xfs_dir2_data_entry_tag_p(dp->i_mount, dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
+	args->offset = xfs_dir2_byte_to_dataptr((char *)dep - (char *)hdr);
 	/*
 	 * Clean up the bestfree array and log the header, tail, and entry.
 	 */
fs/xfs/libxfs/xfs_dir2_leaf.c +2 -0
index d9b66306a9a7..bd0c2f963545 100644
@@ -865,6 +865,8 @@ xfs_dir2_leaf_addname(
 	xfs_dir2_data_put_ftype(dp->i_mount, dep, args->filetype);
 	tagp = xfs_dir2_data_entry_tag_p(dp->i_mount, dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
+	args->offset = xfs_dir2_db_off_to_dataptr(args->geo, use_block,
+						(char *)dep - (char *)hdr);
 	/*
 	 * Need to scan fix up the bestfree table.
 	 */
fs/xfs/libxfs/xfs_dir2_node.c +2 -0
index 7a03aeb9f4c9..5a9513c036b8 100644
@@ -1974,6 +1974,8 @@ xfs_dir2_node_addname_int(
 	xfs_dir2_data_put_ftype(dp->i_mount, dep, args->filetype);
 	tagp = xfs_dir2_data_entry_tag_p(dp->i_mount, dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
+	args->offset = xfs_dir2_db_off_to_dataptr(args->geo, dbno,
+						  (char *)dep - (char *)hdr);
 	xfs_dir2_data_log_entry(args, dbp, dep);
 
 	/* Rescan the freespace and log the data block if needed. */
fs/xfs/libxfs/xfs_dir2_sf.c +2 -0
index 8cd37e6e9d38..44bc4ba3da8a 100644
@@ -485,6 +485,7 @@ xfs_dir2_sf_addname_easy(
 	memcpy(sfep->name, args->name, sfep->namelen);
 	xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber);
 	xfs_dir2_sf_put_ftype(mp, sfep, args->filetype);
+	args->offset = xfs_dir2_byte_to_dataptr(offset);
 
 	/*
 	 * Update the header and inode.
@@ -575,6 +576,7 @@ xfs_dir2_sf_addname_hard(
 	memcpy(sfep->name, args->name, sfep->namelen);
 	xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber);
 	xfs_dir2_sf_put_ftype(mp, sfep, args->filetype);
+	args->offset = xfs_dir2_byte_to_dataptr(offset);
 	sfp->count++;
 	if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && !objchange)
 		sfp->i8count++;
fs/xfs/xfs_inode.c +3 -3
index ff680de560d2..9d4c9f53c435 100644
@@ -1038,7 +1038,7 @@ xfs_create(
 	unlock_dp_on_error = false;
 
 	error = xfs_dir_createname(tp, dp, name, ip->i_ino,
-					resblks - XFS_IALLOC_SPACE_RES(mp));
+				   resblks - XFS_IALLOC_SPACE_RES(mp), NULL);
 	if (error) {
 		ASSERT(error != -ENOSPC);
 		goto out_trans_cancel;
@@ -1262,7 +1262,7 @@ xfs_link(
 	}
 
 	error = xfs_dir_createname(tp, tdp, target_name, sip->i_ino,
-				   resblks);
+				   resblks, NULL);
 	if (error)
 		goto error_return;
 	xfs_trans_ichgtime(tp, tdp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
@@ -2984,7 +2984,7 @@ xfs_rename(
 		 * to account for the ".." reference from the new entry.
 		 */
 		error = xfs_dir_createname(tp, target_dp, target_name,
-					   src_ip->i_ino, spaceres);
+					   src_ip->i_ino, spaceres, NULL);
 		if (error)
 			goto out_trans_cancel;
 
fs/xfs/xfs_symlink.c +2 -1
index d8e120913036..27a7d7c57015 100644
@@ -314,7 +314,8 @@ xfs_symlink(
 	/*
 	 * Create the directory entry for the symlink.
 	 */
-	error = xfs_dir_createname(tp, dp, link_name, ip->i_ino, resblks);
+	error = xfs_dir_createname(tp, dp, link_name,
+			ip->i_ino, resblks, NULL);
 	if (error)
 		goto out_trans_cancel;
 	xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
Signature · 1 line
2.25.1
#19 lore raw

PATCH v3 8/26 xfs: get directory offset when removing directory name

In reply to [email protected]

From: Allison Henderson <[email protected]>

Return the directory offset information when removing an entry to the directory.

This offset will be used as the parent pointer offset in xfs_remove.

---
 fs/xfs/libxfs/xfs_dir2.c       | 6 +++++-
 fs/xfs/libxfs/xfs_dir2.h       | 3 ++-
 fs/xfs/libxfs/xfs_dir2_block.c | 4 ++--
 fs/xfs/libxfs/xfs_dir2_leaf.c  | 5 +++--
 fs/xfs/libxfs/xfs_dir2_node.c  | 5 +++--
 fs/xfs/libxfs/xfs_dir2_sf.c    | 2 ++
 fs/xfs/xfs_inode.c             | 4 ++--
 7 files changed, 19 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +5 -1
index c0629c2cdecc..e62ec568f42d 100644
@@ -436,7 +436,8 @@ xfs_dir_removename(
 	struct xfs_inode	*dp,
 	struct xfs_name		*name,
 	xfs_ino_t		ino,
-	xfs_extlen_t		total)		/* bmap's total block count */
+	xfs_extlen_t		total,		/* bmap's total block count */
+	xfs_dir2_dataptr_t	*offset)	/* OUT: offset in directory */
 {
 	struct xfs_da_args	*args;
 	int			rval;
@@ -481,6 +482,9 @@ xfs_dir_removename(
 	else
 		rval = xfs_dir2_node_removename(args);
 out_free:
+	if (offset)
+		*offset = args->offset;
+
 	kmem_free(args);
 	return rval;
 }
fs/xfs/libxfs/xfs_dir2.h +2 -1
index 4d1c2570b833..c581d3b19bc6 100644
@@ -46,7 +46,8 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp,
 				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,
-				xfs_extlen_t tot);
+				xfs_extlen_t tot,
+				xfs_dir2_dataptr_t *offset);
 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);
fs/xfs/libxfs/xfs_dir2_block.c +2 -2
index 70aeab9d2a12..d36f3f1491da 100644
@@ -810,9 +810,9 @@ xfs_dir2_block_removename(
 	/*
 	 * Point to the data entry using the leaf entry.
 	 */
+	args->offset = be32_to_cpu(blp[ent].address);
 	dep = (xfs_dir2_data_entry_t *)((char *)hdr +
-			xfs_dir2_dataptr_to_off(args->geo,
-						be32_to_cpu(blp[ent].address)));
+			xfs_dir2_dataptr_to_off(args->geo, args->offset));
 	/*
 	 * Mark the data entry's space free.
 	 */
fs/xfs/libxfs/xfs_dir2_leaf.c +3 -2
index bd0c2f963545..c13763c16095 100644
@@ -1381,9 +1381,10 @@ xfs_dir2_leaf_removename(
 	 * Point to the leaf entry, use that to point to the data entry.
 	 */
 	lep = &leafhdr.ents[index];
-	db = xfs_dir2_dataptr_to_db(geo, be32_to_cpu(lep->address));
+	args->offset = be32_to_cpu(lep->address);
+	db = xfs_dir2_dataptr_to_db(args->geo, args->offset);
 	dep = (xfs_dir2_data_entry_t *)((char *)hdr +
-		xfs_dir2_dataptr_to_off(geo, be32_to_cpu(lep->address)));
+		xfs_dir2_dataptr_to_off(args->geo, args->offset));
 	needscan = needlog = 0;
 	oldbest = be16_to_cpu(bf[0].length);
 	ltp = xfs_dir2_leaf_tail_p(geo, leaf);
fs/xfs/libxfs/xfs_dir2_node.c +3 -2
index 5a9513c036b8..39cbdeafa0f6 100644
@@ -1296,9 +1296,10 @@ xfs_dir2_leafn_remove(
 	/*
 	 * Extract the data block and offset from the entry.
 	 */
-	db = xfs_dir2_dataptr_to_db(geo, be32_to_cpu(lep->address));
+	args->offset = be32_to_cpu(lep->address);
+	db = xfs_dir2_dataptr_to_db(args->geo, args->offset);
 	ASSERT(dblk->blkno == db);
-	off = xfs_dir2_dataptr_to_off(geo, be32_to_cpu(lep->address));
+	off = xfs_dir2_dataptr_to_off(args->geo, args->offset);
 	ASSERT(dblk->index == off);
 
 	/*
fs/xfs/libxfs/xfs_dir2_sf.c +2 -0
index 44bc4ba3da8a..b49578a547b3 100644
@@ -969,6 +969,8 @@ xfs_dir2_sf_removename(
 								XFS_CMP_EXACT) {
 			ASSERT(xfs_dir2_sf_get_ino(mp, sfp, sfep) ==
 			       args->inumber);
+			args->offset = xfs_dir2_byte_to_dataptr(
+						xfs_dir2_sf_get_offset(sfep));
 			break;
 		}
 	}
fs/xfs/xfs_inode.c +2 -2
index 9d4c9f53c435..d77aec375e38 100644
@@ -2506,7 +2506,7 @@ xfs_remove(
 	if (error)
 		goto out_trans_cancel;
 
-	error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks);
+	error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, NULL);
 	if (error) {
 		ASSERT(error != -ENOENT);
 		goto out_trans_cancel;
@@ -3081,7 +3081,7 @@ xfs_rename(
 					spaceres);
 	else
 		error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino,
-					   spaceres);
+					   spaceres, NULL);
 
 	if (error)
 		goto out_trans_cancel;
Signature · 1 line
2.25.1
#20 lore raw

PATCH v3 9/26 xfs: get directory offset when replacing a directory name

In reply to [email protected]

From: Allison Henderson <[email protected]>

Return the directory offset information when replacing an entry to the directory.

This offset will be used as the parent pointer offset in xfs_rename.

---
 fs/xfs/libxfs/xfs_dir2.c       |  8 ++++++--
 fs/xfs/libxfs/xfs_dir2.h       |  2 +-
 fs/xfs/libxfs/xfs_dir2_block.c |  4 ++--
 fs/xfs/libxfs/xfs_dir2_leaf.c  |  1 +
 fs/xfs/libxfs/xfs_dir2_node.c  |  1 +
 fs/xfs/libxfs/xfs_dir2_sf.c    |  2 ++
 fs/xfs/xfs_inode.c             | 16 ++++++++--------
 7 files changed, 21 insertions(+), 13 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +6 -2
index e62ec568f42d..e603323ce7a3 100644
@@ -482,7 +482,7 @@ xfs_dir_removename(
 	else
 		rval = xfs_dir2_node_removename(args);
 out_free:
-	if (offset)
+	if (!rval && offset)
 		*offset = args->offset;
 
 	kmem_free(args);
@@ -498,7 +498,8 @@ xfs_dir_replace(
 	struct xfs_inode	*dp,
 	const struct xfs_name	*name,		/* name of entry to replace */
 	xfs_ino_t		inum,		/* new inode number */
-	xfs_extlen_t		total)		/* bmap's total block count */
+	xfs_extlen_t		total,		/* bmap's total block count */
+	xfs_dir2_dataptr_t	*offset)	/* OUT: offset in directory */
 {
 	struct xfs_da_args	*args;
 	int			rval;
@@ -546,6 +547,9 @@ xfs_dir_replace(
 	else
 		rval = xfs_dir2_node_replace(args);
 out_free:
+	if (offset)
+		*offset = args->offset;
+
 	kmem_free(args);
 	return rval;
 }
fs/xfs/libxfs/xfs_dir2.h +1 -1
index c581d3b19bc6..fd943c0c00a0 100644
@@ -50,7 +50,7 @@ extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp,
 				xfs_dir2_dataptr_t *offset);
 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);
+				xfs_extlen_t tot, xfs_dir2_dataptr_t *offset);
 extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,
 				struct xfs_name *name);
 
fs/xfs/libxfs/xfs_dir2_block.c +2 -2
index d36f3f1491da..0f3a03e87278 100644
@@ -885,9 +885,9 @@ xfs_dir2_block_replace(
 	/*
 	 * Point to the data entry we need to change.
 	 */
+	args->offset = be32_to_cpu(blp[ent].address);
 	dep = (xfs_dir2_data_entry_t *)((char *)hdr +
-			xfs_dir2_dataptr_to_off(args->geo,
-						be32_to_cpu(blp[ent].address)));
+			xfs_dir2_dataptr_to_off(args->geo, args->offset));
 	ASSERT(be64_to_cpu(dep->inumber) != args->inumber);
 	/*
 	 * Change the inode number to the new value.
fs/xfs/libxfs/xfs_dir2_leaf.c +1 -0
index c13763c16095..958b9fea64bd 100644
@@ -1518,6 +1518,7 @@ xfs_dir2_leaf_replace(
 	/*
 	 * Point to the data entry.
 	 */
+	args->offset = be32_to_cpu(lep->address);
 	dep = (xfs_dir2_data_entry_t *)
 	      ((char *)dbp->b_addr +
 	       xfs_dir2_dataptr_to_off(args->geo, be32_to_cpu(lep->address)));
fs/xfs/libxfs/xfs_dir2_node.c +1 -0
index 39cbdeafa0f6..53cd0d5d94f7 100644
@@ -2242,6 +2242,7 @@ xfs_dir2_node_replace(
 		hdr = state->extrablk.bp->b_addr;
 		ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) ||
 		       hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC));
+		args->offset = be32_to_cpu(leafhdr.ents[blk->index].address);
 		dep = (xfs_dir2_data_entry_t *)
 		      ((char *)hdr +
 		       xfs_dir2_dataptr_to_off(args->geo,
fs/xfs/libxfs/xfs_dir2_sf.c +2 -0
index b49578a547b3..032c65804610 100644
@@ -1107,6 +1107,8 @@ xfs_dir2_sf_replace(
 				xfs_dir2_sf_put_ino(mp, sfp, sfep,
 						args->inumber);
 				xfs_dir2_sf_put_ftype(mp, sfep, args->filetype);
+				args->offset = xfs_dir2_byte_to_dataptr(
+						  xfs_dir2_sf_get_offset(sfep));
 				break;
 			}
 		}
fs/xfs/xfs_inode.c +8 -8
index d77aec375e38..6eb264598517 100644
@@ -2487,7 +2487,7 @@ xfs_remove(
 		 */
 		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);
+					tp->t_mountp->m_sb.sb_rootino, 0, NULL);
 			if (error)
 				return error;
 		}
@@ -2627,12 +2627,12 @@ xfs_cross_rename(
 	int		dp2_flags = 0;
 
 	/* Swap inode number for dirent in first parent */
-	error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres);
+	error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, NULL);
 	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);
+	error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, NULL);
 	if (error)
 		goto out_trans_abort;
 
@@ -2646,7 +2646,7 @@ xfs_cross_rename(
 
 		if (S_ISDIR(VFS_I(ip2)->i_mode)) {
 			error = xfs_dir_replace(tp, ip2, &xfs_name_dotdot,
-						dp1->i_ino, spaceres);
+						dp1->i_ino, spaceres, NULL);
 			if (error)
 				goto out_trans_abort;
 
@@ -2670,7 +2670,7 @@ xfs_cross_rename(
 
 		if (S_ISDIR(VFS_I(ip1)->i_mode)) {
 			error = xfs_dir_replace(tp, ip1, &xfs_name_dotdot,
-						dp2->i_ino, spaceres);
+						dp2->i_ino, spaceres, NULL);
 			if (error)
 				goto out_trans_abort;
 
@@ -3005,7 +3005,7 @@ xfs_rename(
 		 * name at the destination directory, remove it first.
 		 */
 		error = xfs_dir_replace(tp, target_dp, target_name,
-					src_ip->i_ino, spaceres);
+					src_ip->i_ino, spaceres, NULL);
 		if (error)
 			goto out_trans_cancel;
 
@@ -3039,7 +3039,7 @@ xfs_rename(
 		 * directory.
 		 */
 		error = xfs_dir_replace(tp, src_ip, &xfs_name_dotdot,
-					target_dp->i_ino, spaceres);
+					target_dp->i_ino, spaceres, NULL);
 		ASSERT(error != -EEXIST);
 		if (error)
 			goto out_trans_cancel;
@@ -3078,7 +3078,7 @@ xfs_rename(
 	 */
 	if (wip)
 		error = xfs_dir_replace(tp, src_dp, src_name, wip->i_ino,
-					spaceres);
+					spaceres, NULL);
 	else
 		error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino,
 					   spaceres, NULL);
Signature · 1 line
2.25.1
#21 lore raw

PATCH v3 10/26 xfs: add parent pointer support to attribute code

In reply to [email protected]

From: Allison Henderson <[email protected]>

Add the new parent attribute type. XFS_ATTR_PARENT is used only for parent pointer entries; it uses reserved blocks like XFS_ATTR_ROOT.

---
 fs/xfs/libxfs/xfs_attr.c       | 4 +++-
 fs/xfs/libxfs/xfs_da_format.h  | 5 ++++-
 fs/xfs/libxfs/xfs_log_format.h | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_attr.c +3 -1
index b1dbed7655e8..101823772bf9 100644
@@ -976,11 +976,13 @@ xfs_attr_set(
 	struct xfs_inode	*dp = args->dp;
 	struct xfs_mount	*mp = dp->i_mount;
 	struct xfs_trans_res	tres;
-	bool			rsvd = (args->attr_filter & XFS_ATTR_ROOT);
+	bool			rsvd;
 	int			error, local;
 	int			rmt_blks = 0;
 	unsigned int		total;
 
+	rsvd = (args->attr_filter & (XFS_ATTR_ROOT | XFS_ATTR_PARENT)) != 0;
+
 	if (xfs_is_shutdown(dp->i_mount))
 		return -EIO;
 
fs/xfs/libxfs/xfs_da_format.h +4 -1
index 25e2841084e1..3dc03968bba6 100644
@@ -688,12 +688,15 @@ struct xfs_attr3_leafblock {
 #define	XFS_ATTR_LOCAL_BIT	0	/* attr is stored locally */
 #define	XFS_ATTR_ROOT_BIT	1	/* limit access to trusted attrs */
 #define	XFS_ATTR_SECURE_BIT	2	/* limit access to secure attrs */
+#define	XFS_ATTR_PARENT_BIT	3	/* parent pointer attrs */
 #define	XFS_ATTR_INCOMPLETE_BIT	7	/* attr in middle of create/delete */
 #define XFS_ATTR_LOCAL		(1u << XFS_ATTR_LOCAL_BIT)
 #define XFS_ATTR_ROOT		(1u << XFS_ATTR_ROOT_BIT)
 #define XFS_ATTR_SECURE		(1u << XFS_ATTR_SECURE_BIT)
+#define XFS_ATTR_PARENT		(1u << XFS_ATTR_PARENT_BIT)
 #define XFS_ATTR_INCOMPLETE	(1u << XFS_ATTR_INCOMPLETE_BIT)
-#define XFS_ATTR_NSP_ONDISK_MASK	(XFS_ATTR_ROOT | XFS_ATTR_SECURE)
+#define XFS_ATTR_NSP_ONDISK_MASK \
+			(XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT)
 
 /*
  * Alignment for namelist and valuelist entries (since they are mixed
fs/xfs/libxfs/xfs_log_format.h +1 -0
index 62f40e6353c2..57814057934d 100644
@@ -919,6 +919,7 @@ struct xfs_icreate_log {
  */
 #define XFS_ATTRI_FILTER_MASK		(XFS_ATTR_ROOT | \
 					 XFS_ATTR_SECURE | \
+					 XFS_ATTR_PARENT | \
 					 XFS_ATTR_INCOMPLETE)
 
 /*
Signature · 1 line
2.25.1
#22 lore raw

PATCH v3 11/26 xfs: define parent pointer xattr format

In reply to [email protected]

From: Allison Henderson <[email protected]>

We need to define the parent pointer attribute format before we start adding support for it into all the code that needs to use it. The EA format we will use encodes the following information:

        name={parent inode #, parent inode generation, dirent offset}
        value={dirent filename}

The inode/gen gives all the information we need to reliably identify the parent without requiring child->parent lock ordering, and allows userspace to do pathname component level reconstruction without the kernel ever needing to verify the parent itself as part of ioctl calls.

By using the dirent offset in the EA name, we have a method of knowing the exact parent pointer EA we need to modify/remove in rename/unlink without an unbound EA name search.

By keeping the dirent name in the value, we have enough information to be able to validate and reconstruct damaged directory trees. While the diroffset of a filename alone is not unique enough to identify the child, the {diroffset,filename,child_inode} tuple is sufficient. That is, if the diroffset gets reused and points to a different filename, we can detect that from the contents of EA. If a link of the same name is created, then we can check whether it points at the same inode as the parent EA we current have.

---
 fs/xfs/libxfs/xfs_da_format.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
fs/xfs/libxfs/xfs_da_format.h +25 -0
index 3dc03968bba6..b02b67f1999e 100644
@@ -805,4 +805,29 @@ static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp)
 xfs_failaddr_t xfs_da3_blkinfo_verify(struct xfs_buf *bp,
 				      struct xfs_da3_blkinfo *hdr3);
 
+/*
+ * Parent pointer attribute format definition
+ *
+ * EA name encodes the parent inode number, generation and the offset of
+ * the dirent that points to the child inode. The EA value contains the
+ * same name as the dirent in the parent directory.
+ */
+struct xfs_parent_name_rec {
+	__be64  p_ino;
+	__be32  p_gen;
+	__be32  p_diroffset;
+};
+
+/*
+ * incore version of the above, also contains name pointers so callers
+ * can pass/obtain all the parent pointer information in a single structure
+ */
+struct xfs_parent_name_irec {
+	xfs_ino_t		p_ino;
+	uint32_t		p_gen;
+	xfs_dir2_dataptr_t	p_diroffset;
+	const char		*p_name;
+	uint8_t			p_namelen;
+};
+
 #endif /* __XFS_DA_FORMAT_H__ */
Signature · 1 line
2.25.1
#23 lore raw

PATCH v3 12/26 xfs: Add xfs_verify_pptr

In reply to [email protected]

From: Allison Henderson <[email protected]>

Attribute names of parent pointers are not strings. So we need to modify attr_namecheck to verify parent pointer records when the XFS_ATTR_PARENT flag is set.

---
 fs/xfs/libxfs/xfs_attr.c | 47 +++++++++++++++++++++++++++++++++++++---
 fs/xfs/libxfs/xfs_attr.h |  3 ++-
 fs/xfs/scrub/attr.c      |  2 +-
 fs/xfs/xfs_attr_item.c   | 11 ++++++----
 fs/xfs/xfs_attr_list.c   | 17 ++++++++++-----
 5 files changed, 66 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +44 -3
index 101823772bf9..0c9589261990 100644
@@ -1577,9 +1577,33 @@ xfs_attr_node_get(
 	return error;
 }
 
-/* Returns true if the attribute entry name is valid. */
-bool
-xfs_attr_namecheck(
+/*
+ * Verify parent pointer attribute is valid.
+ * Return true on success or false on failure
+ */
+STATIC bool
+xfs_verify_pptr(
+	struct xfs_mount		*mp,
+	struct xfs_parent_name_rec	*rec)
+{
+	xfs_ino_t			p_ino;
+	xfs_dir2_dataptr_t		p_diroffset;
+
+	p_ino = be64_to_cpu(rec->p_ino);
+	p_diroffset = be32_to_cpu(rec->p_diroffset);
+
+	if (!xfs_verify_ino(mp, p_ino))
+		return false;
+
+	if (p_diroffset > XFS_DIR2_MAX_DATAPTR)
+		return false;
+
+	return true;
+}
+
+/* Returns true if the string attribute entry name is valid. */
+static bool
+xfs_str_attr_namecheck(
 	const void	*name,
 	size_t		length)
 {
@@ -1594,6 +1618,23 @@ xfs_attr_namecheck(
 	return !memchr(name, 0, length);
 }
 
+/* Returns true if the attribute entry name is valid. */
+bool
+xfs_attr_namecheck(
+	struct xfs_mount	*mp,
+	const void		*name,
+	size_t			length,
+	int			flags)
+{
+	if (flags & XFS_ATTR_PARENT) {
+		if (length != sizeof(struct xfs_parent_name_rec))
+			return false;
+		return xfs_verify_pptr(mp, (struct xfs_parent_name_rec *)name);
+	}
+
+	return xfs_str_attr_namecheck(name, length);
+}
+
 int __init
 xfs_attr_intent_init_cache(void)
 {
fs/xfs/libxfs/xfs_attr.h +2 -1
index 3e81f3f48560..b79dae788cfb 100644
@@ -547,7 +547,8 @@ int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_iter(struct xfs_attr_intent *attr);
 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
-bool xfs_attr_namecheck(const void *name, size_t length);
+bool xfs_attr_namecheck(struct xfs_mount *mp, const void *name, size_t length,
+			int flags);
 int xfs_attr_calc_size(struct xfs_da_args *args, int *local);
 void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
 			 unsigned int *total);
fs/xfs/scrub/attr.c +1 -1
index b6f0c9f3f124..d3e75c077fab 100644
@@ -128,7 +128,7 @@ xchk_xattr_listent(
 	}
 
 	/* Does this name make sense? */
-	if (!xfs_attr_namecheck(name, namelen)) {
+	if (!xfs_attr_namecheck(sx->sc->mp, name, namelen, flags)) {
 		xchk_fblock_set_corrupt(sx->sc, XFS_ATTR_FORK, args.blkno);
 		return;
 	}
fs/xfs/xfs_attr_item.c +7 -4
index 9414ee94829c..6448b44ffc1a 100644
@@ -611,7 +611,8 @@ xfs_attri_item_recover(
 	 */
 	attrp = &attrip->attri_format;
 	if (!xfs_attri_validate(mp, attrp) ||
-	    !xfs_attr_namecheck(nv->name.i_addr, nv->name.i_len))
+	    !xfs_attr_namecheck(mp, nv->name.i_addr, nv->name.i_len,
+				attrp->alfi_attr_filter))
 		return -EFSCORRUPTED;
 
 	error = xlog_recover_iget(mp,  attrp->alfi_ino, &ip);
@@ -808,7 +809,8 @@ xlog_recover_attri_commit_pass2(
 	attr_name = item->ri_buf[i].i_addr;
 	i++;
 
-	if (!xfs_attr_namecheck(attr_name, attri_formatp->alfi_name_len)) {
+	if (!xfs_attr_namecheck(mp, attr_name, attri_formatp->alfi_name_len,
+				attri_formatp->alfi_attr_filter)) {
 		XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
 		return -EFSCORRUPTED;
 	}
@@ -817,8 +819,9 @@ xlog_recover_attri_commit_pass2(
 		attr_nname = item->ri_buf[i].i_addr;
 		i++;
 
-		if (!xfs_attr_namecheck(attr_nname,
-				attri_formatp->alfi_nname_len)) {
+		if (!xfs_attr_namecheck(mp, attr_nname,
+				attri_formatp->alfi_nname_len,
+				attri_formatp->alfi_attr_filter)) {
 			XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
 			return -EFSCORRUPTED;
 		}
fs/xfs/xfs_attr_list.c +12 -5
index 99bbbe1a0e44..a51f7f13a352 100644
@@ -58,9 +58,13 @@ xfs_attr_shortform_list(
 	struct xfs_attr_sf_sort		*sbuf, *sbp;
 	struct xfs_attr_shortform	*sf;
 	struct xfs_attr_sf_entry	*sfe;
+	struct xfs_mount		*mp;
 	int				sbsize, nsbuf, count, i;
 	int				error = 0;
 
+	ASSERT(context != NULL);
+	ASSERT(dp != NULL);
+	mp = dp->i_mount;
 	sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data;
 	ASSERT(sf != NULL);
 	if (!sf->hdr.count)
@@ -82,8 +86,9 @@ xfs_attr_shortform_list(
 	     (dp->i_af.if_bytes + sf->hdr.count * 16) < context->bufsize)) {
 		for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
 			if (XFS_IS_CORRUPT(context->dp->i_mount,
-					   !xfs_attr_namecheck(sfe->nameval,
-							       sfe->namelen)))
+					   !xfs_attr_namecheck(mp, sfe->nameval,
+							       sfe->namelen,
+							       sfe->flags)))
 				return -EFSCORRUPTED;
 			context->put_listent(context,
 					     sfe->flags,
@@ -174,8 +179,9 @@ xfs_attr_shortform_list(
 			cursor->offset = 0;
 		}
 		if (XFS_IS_CORRUPT(context->dp->i_mount,
-				   !xfs_attr_namecheck(sbp->name,
-						       sbp->namelen))) {
+				   !xfs_attr_namecheck(mp, sbp->name,
+						       sbp->namelen,
+						       sbp->flags))) {
 			error = -EFSCORRUPTED;
 			goto out;
 		}
@@ -465,7 +471,8 @@ xfs_attr3_leaf_list_int(
 		}
 
 		if (XFS_IS_CORRUPT(context->dp->i_mount,
-				   !xfs_attr_namecheck(name, namelen)))
+				   !xfs_attr_namecheck(mp, name, namelen,
+						       entry->flags)))
 			return -EFSCORRUPTED;
 		context->put_listent(context, entry->flags,
 					      name, namelen, valuelen);
Signature · 1 line
2.25.1
#24 lore raw

PATCH v3 13/26 xfs: extend transaction reservations for parent attributes

In reply to [email protected]

From: Allison Henderson <[email protected]>

We need to add, remove or modify parent pointer attributes during create/link/unlink/rename operations atomically with the dirents in the parent directories being modified. This means they need to be modified in the same transaction as the parent directories, and so we need to add the required space for the attribute modifications to the transaction reservations.

---
 fs/xfs/libxfs/xfs_trans_resv.c | 135 ++++++++++++++++++++++++++-------
 1 file changed, 106 insertions(+), 29 deletions(-)
fs/xfs/libxfs/xfs_trans_resv.c +106 -29
index 2c4ad6e4bb14..f7799800d556 100644
@@ -19,6 +19,7 @@
 #include "xfs_trans.h"
 #include "xfs_qm.h"
 #include "xfs_trans_space.h"
+#include "xfs_attr_item.h"
 
 #define _ALLOC	true
 #define _FREE	false
@@ -421,28 +422,45 @@ xfs_calc_itruncate_reservation_minlogsize(
 }
 
 /*
- * In renaming a files we can modify:
- *    the four inodes involved: 4 * inode size
+ * In renaming a files we can modify (t1):
+ *    the four inodes involved: 5 * inode size
  *    the two directory btrees: 2 * (max depth + v2) * dir block size
  *    the two directory bmap btrees: 2 * max depth * block size
  * And the bmap_finish transaction can free dir and bmap blocks (two sets
- *	of bmap blocks) giving:
+ *	of bmap blocks) giving (t2):
  *    the agf for the ags in which the blocks live: 3 * sector size
  *    the agfl for the ags in which the blocks live: 3 * sector size
  *    the superblock for the free block count: sector size
  *    the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
+ * If parent pointers are enabled (t3), then each transaction in the chain
+ *    must be capable of setting or removing the extended attribute
+ *    containing the parent information.  It must also be able to handle
+ *    the three xattr intent items that track the progress of the parent
+ *    pointer update.
  */
 STATIC uint
 xfs_calc_rename_reservation(
 	struct xfs_mount	*mp)
 {
-	return XFS_DQUOT_LOGRES(mp) +
-		max((xfs_calc_inode_res(mp, 4) +
-		     xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
-				      XFS_FSB_TO_B(mp, 1))),
-		    (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
-		     xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
-				      XFS_FSB_TO_B(mp, 1))));
+	unsigned int		overhead = XFS_DQUOT_LOGRES(mp);
+	struct xfs_trans_resv	*resp = M_RES(mp);
+	unsigned int		t1, t2, t3 = 0;
+
+	t1 = xfs_calc_inode_res(mp, 5) +
+	     xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
+			XFS_FSB_TO_B(mp, 1));
+
+	t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
+	     xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
+			XFS_FSB_TO_B(mp, 1));
+
+	if (xfs_has_parent(mp)) {
+		t3 = max(resp->tr_attrsetm.tr_logres,
+				resp->tr_attrrm.tr_logres);
+		overhead += 3 * (sizeof(struct xfs_attri_log_item));
+	}
+
+	return overhead + max3(t1, t2, t3);
 }
 
 /*
@@ -909,24 +927,59 @@ xfs_calc_sb_reservation(
 	return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
 }
 
-void
-xfs_trans_resv_calc(
-	struct xfs_mount	*mp,
-	struct xfs_trans_resv	*resp)
+/*
+ * Calculate extra space needed for parent pointer attributes
+ */
+STATIC void
+xfs_calc_parent_ptr_reservations(
+	struct xfs_mount     *mp)
 {
-	int			logcount_adj = 0;
+	struct xfs_trans_resv   *resp = M_RES(mp);
 
-	/*
-	 * The following transactions are logged in physical format and
-	 * require a permanent reservation on space.
-	 */
-	resp->tr_write.tr_logres = xfs_calc_write_reservation(mp, false);
-	resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT;
-	resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+	if (!xfs_has_parent(mp))
+		return;
 
-	resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
-	resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
-	resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+	resp->tr_rename.tr_logres += max(resp->tr_attrsetm.tr_logres,
+					 resp->tr_attrrm.tr_logres);
+	resp->tr_rename.tr_logcount += max(resp->tr_attrsetm.tr_logcount,
+					   resp->tr_attrrm.tr_logcount);
+
+	resp->tr_create.tr_logres += resp->tr_attrsetm.tr_logres;
+	resp->tr_create.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+	resp->tr_mkdir.tr_logres += resp->tr_attrsetm.tr_logres;
+	resp->tr_mkdir.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+	resp->tr_link.tr_logres += resp->tr_attrsetm.tr_logres;
+	resp->tr_link.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+	resp->tr_symlink.tr_logres += resp->tr_attrsetm.tr_logres;
+	resp->tr_symlink.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+	resp->tr_remove.tr_logres += resp->tr_attrrm.tr_logres;
+	resp->tr_remove.tr_logcount += resp->tr_attrrm.tr_logcount;
+}
+
+/*
+ * Namespace reservations.
+ *
+ * These get tricky when parent pointers are enabled as we have attribute
+ * modifications occurring from within these transactions. Rather than confuse
+ * each of these reservation calculations with the conditional attribute
+ * reservations, add them here in a clear and concise manner. This assumes that
+ * the attribute reservations have already been calculated.
+ *
+ * Note that we only include the static attribute reservation here; the runtime
+ * reservation will have to be modified by the size of the attributes being
+ * added/removed/modified. See the comments on the attribute reservation
+ * calculations for more details.
+ */
+STATIC void
+xfs_calc_namespace_reservations(
+	struct xfs_mount	*mp,
+	struct xfs_trans_resv	*resp)
+{
+	ASSERT(resp->tr_attrsetm.tr_logres > 0);
 
 	resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp);
 	resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;
@@ -948,15 +1001,37 @@ xfs_trans_resv_calc(
 	resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
 	resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
 
+	resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
+	resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT;
+	resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
+	xfs_calc_parent_ptr_reservations(mp);
+}
+
+void
+xfs_trans_resv_calc(
+	struct xfs_mount	*mp,
+	struct xfs_trans_resv	*resp)
+{
+	int			logcount_adj = 0;
+
+	/*
+	 * The following transactions are logged in physical format and
+	 * require a permanent reservation on space.
+	 */
+	resp->tr_write.tr_logres = xfs_calc_write_reservation(mp, false);
+	resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT;
+	resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
+	resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
+	resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
+	resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
 	resp->tr_create_tmpfile.tr_logres =
 			xfs_calc_create_tmpfile_reservation(mp);
 	resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT;
 	resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
 
-	resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
-	resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT;
-	resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
-
 	resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp);
 	resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT;
 	resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
@@ -986,6 +1061,8 @@ xfs_trans_resv_calc(
 	resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT;
 	resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
 
+	xfs_calc_namespace_reservations(mp, resp);
+
 	/*
 	 * The following transactions are logged in logical format with
 	 * a default log count.
Signature · 1 line
2.25.1
#25 lore raw

Re: [PATCH v3 13/26] xfs: extend transaction reservations for parent attributes

Quoted 28 lines · On Wed, Sep 21, 2022 at 10:44:45PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

We need to add, remove or modify parent pointer attributes during create/link/unlink/rename operations atomically with the dirents in the parent directories being modified. This means they need to be modified in the same transaction as the parent directories, and so we need to add the required space for the attribute modifications to the transaction reservations.

---
 fs/xfs/libxfs/xfs_trans_resv.c | 135 ++++++++++++++++++++++++++-------
 1 file changed, 106 insertions(+), 29 deletions(-)
fs/xfs/libxfs/xfs_trans_resv.c +1 -0
index 2c4ad6e4bb14..f7799800d556 100644
@@ -19,6 +19,7 @@
 #include "xfs_trans.h"
 #include "xfs_qm.h"
 #include "xfs_trans_space.h"
+#include "xfs_attr_item.h"
 
 #define _ALLOC	true
 #define _FREE	false

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_itruncate_reservation_minlogsize( · line 426

Quoted 7 lines
fs/xfs/libxfs/xfs_trans_resv.c +2 -2
@@ -421,28 +422,45 @@ xfs_calc_itruncate_reservation_minlogsize(
 }
 
 /*
- * In renaming a files we can modify:
- *    the four inodes involved: 4 * inode size
+ * In renaming a files we can modify (t1):
+ *    the four inodes involved: 5 * inode size

...the *five* inodes involved...

Also -- even before parent pointers we could have five inodes involved in a rename transaction, so I think this change needs to be a separate bugfix at the start of the series. Rename isn't experimental, so I can't let this one slide. :/

Quoted 31 lines
fs/xfs/libxfs/xfs_trans_resv.c +11 -8
  *    the two directory btrees: 2 * (max depth + v2) * dir block size
  *    the two directory bmap btrees: 2 * max depth * block size
  * And the bmap_finish transaction can free dir and bmap blocks (two sets
- *	of bmap blocks) giving:
+ *	of bmap blocks) giving (t2):
  *    the agf for the ags in which the blocks live: 3 * sector size
  *    the agfl for the ags in which the blocks live: 3 * sector size
  *    the superblock for the free block count: sector size
  *    the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
+ * If parent pointers are enabled (t3), then each transaction in the chain
+ *    must be capable of setting or removing the extended attribute
+ *    containing the parent information.  It must also be able to handle
+ *    the three xattr intent items that track the progress of the parent
+ *    pointer update.
  */
 STATIC uint
 xfs_calc_rename_reservation(
 	struct xfs_mount	*mp)
 {
-	return XFS_DQUOT_LOGRES(mp) +
-		max((xfs_calc_inode_res(mp, 4) +
-		     xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
-				      XFS_FSB_TO_B(mp, 1))),
-		    (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
-		     xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
-				      XFS_FSB_TO_B(mp, 1))));
+	unsigned int		overhead = XFS_DQUOT_LOGRES(mp);
+	struct xfs_trans_resv	*resp = M_RES(mp);
+	unsigned int		t1, t2, t3 = 0;
+
+	t1 = xfs_calc_inode_res(mp, 5) +

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_itruncate_reservation_minlogsize( · line 459

Quoted 10 lines
fs/xfs/libxfs/xfs_trans_resv.c +10 -0
+	     xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
+			XFS_FSB_TO_B(mp, 1));
+
+	t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
+	     xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
+			XFS_FSB_TO_B(mp, 1));
+
+	if (xfs_has_parent(mp)) {
+		t3 = max(resp->tr_attrsetm.tr_logres,
+				resp->tr_attrrm.tr_logres);

Ooh I like this refactoring of xfs_calc_rename_reservation. :)

I guess we now tr_attr{setm,rm} before computing the rename reservation so this is ok.

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_itruncate_reservation_minlogsize( · line 460

Quoted 1 line
fs/xfs/libxfs/xfs_trans_resv.c +1 -0
+		overhead += 3 * (sizeof(struct xfs_attri_log_item));

Should the size of the name, newname, and value buffers be added into overhead? They take up log space too.

Quoted 31 lines
fs/xfs/libxfs/xfs_trans_resv.c +10 -12
+	}
+
+	return overhead + max3(t1, t2, t3);
 }
 
 /*
@@ -909,24 +927,59 @@ xfs_calc_sb_reservation(
 	return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
 }
 
-void
-xfs_trans_resv_calc(
-	struct xfs_mount	*mp,
-	struct xfs_trans_resv	*resp)
+/*
+ * Calculate extra space needed for parent pointer attributes
+ */
+STATIC void
+xfs_calc_parent_ptr_reservations(
+	struct xfs_mount     *mp)
 {
-	int			logcount_adj = 0;
+	struct xfs_trans_resv   *resp = M_RES(mp);
 
-	/*
-	 * The following transactions are logged in physical format and
-	 * require a permanent reservation on space.
-	 */
-	resp->tr_write.tr_logres = xfs_calc_write_reservation(mp, false);
-	resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT;
-	resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_sb_reservation( · line 945

Quoted 10 lines
fs/xfs/libxfs/xfs_trans_resv.c +6 -3
+	if (!xfs_has_parent(mp))
+		return;
 
-	resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
-	resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
-	resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+	resp->tr_rename.tr_logres += max(resp->tr_attrsetm.tr_logres,
+					 resp->tr_attrrm.tr_logres);
+	resp->tr_rename.tr_logcount += max(resp->tr_attrsetm.tr_logcount,
+					   resp->tr_attrrm.tr_logcount);

Doesn't xfs_calc_rename_reservation add this to tr_rename already?

Quoted 5 lines
fs/xfs/libxfs/xfs_trans_resv.c +5 -0
+
+	resp->tr_create.tr_logres += resp->tr_attrsetm.tr_logres;
+	resp->tr_create.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+	resp->tr_mkdir.tr_logres += resp->tr_attrsetm.tr_logres;

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_sb_reservation( · line 960

Quoted 10 lines
fs/xfs/libxfs/xfs_trans_resv.c +10 -0
+	resp->tr_mkdir.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+	resp->tr_link.tr_logres += resp->tr_attrsetm.tr_logres;
+	resp->tr_link.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+	resp->tr_symlink.tr_logres += resp->tr_attrsetm.tr_logres;
+	resp->tr_symlink.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+	resp->tr_remove.tr_logres += resp->tr_attrrm.tr_logres;
+	resp->tr_remove.tr_logcount += resp->tr_attrrm.tr_logcount;

Shouldn't each of these += additions be made to xfs_calc_{icreate,mkdir,link,symlink,remove}_reservation, respectively?

--D

Quoted 79 lines
fs/xfs/libxfs/xfs_trans_resv.c +50 -4
+}
+
+/*
+ * Namespace reservations.
+ *
+ * These get tricky when parent pointers are enabled as we have attribute
+ * modifications occurring from within these transactions. Rather than confuse
+ * each of these reservation calculations with the conditional attribute
+ * reservations, add them here in a clear and concise manner. This assumes that
+ * the attribute reservations have already been calculated.
+ *
+ * Note that we only include the static attribute reservation here; the runtime
+ * reservation will have to be modified by the size of the attributes being
+ * added/removed/modified. See the comments on the attribute reservation
+ * calculations for more details.
+ */
+STATIC void
+xfs_calc_namespace_reservations(
+	struct xfs_mount	*mp,
+	struct xfs_trans_resv	*resp)
+{
+	ASSERT(resp->tr_attrsetm.tr_logres > 0);
 
 	resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp);
 	resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;
@@ -948,15 +1001,37 @@ xfs_trans_resv_calc(
 	resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
 	resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
 
+	resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
+	resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT;
+	resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
+	xfs_calc_parent_ptr_reservations(mp);
+}
+
+void
+xfs_trans_resv_calc(
+	struct xfs_mount	*mp,
+	struct xfs_trans_resv	*resp)
+{
+	int			logcount_adj = 0;
+
+	/*
+	 * The following transactions are logged in physical format and
+	 * require a permanent reservation on space.
+	 */
+	resp->tr_write.tr_logres = xfs_calc_write_reservation(mp, false);
+	resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT;
+	resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
+	resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
+	resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
+	resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
 	resp->tr_create_tmpfile.tr_logres =
 			xfs_calc_create_tmpfile_reservation(mp);
 	resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT;
 	resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
 
-	resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
-	resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT;
-	resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
-
 	resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp);
 	resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT;
 	resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
@@ -986,6 +1061,8 @@ xfs_trans_resv_calc(
 	resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT;
 	resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
 
+	xfs_calc_namespace_reservations(mp, resp);
+
 	/*
 	 * The following transactions are logged in logical format with
 	 * a default log count.
Signature · 1 line
2.25.1
#26 lore raw

Re: [PATCH v3 13/26] xfs: extend transaction reservations for parent attributes

Quoted 46 lines · Darrick J. Wong
Quoted 35 lines · On Wed, Sep 21, 2022 at 10:44:45PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

We need to add, remove or modify parent pointer attributes during create/link/unlink/rename operations atomically with the dirents in the
parent directories being modified. This means they need to be modified
in the same transaction as the parent directories, and so we need to add
the required space for the attribute modifications to the transaction
reservations.

---
 fs/xfs/libxfs/xfs_trans_resv.c | 135 ++++++++++++++++++++++++++---
----

 1 file changed, 106 insertions(+), 29 deletions(-)
fs/xfs/libxfs/xfs_trans_resv.c +1 -0
index 2c4ad6e4bb14..f7799800d556 100644
@@ -19,6 +19,7 @@
  #include "xfs_trans.h"
  #include "xfs_qm.h"
  #include "xfs_trans_space.h"
+#include "xfs_attr_item.h"


 #define _ALLOC true
 #define _FREE  false

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -421,28 +422,45 @@ xfs_calc_itruncate_reservation_minlogsize(
  }
Quoted 6 lines


 /*
- * In renaming a files we can modify:
- *    the four inodes involved: 4 * inode size
+ * In renaming a files we can modify (t1):
+ *    the four inodes involved: 5 * inode size

...the *five* inodes involved...

Quoted 6 lines

Also -- even before parent pointers we could have five inodes involved
in a rename transaction, so I think this change needs to be a separate
bugfix at the start of the series.  Rename isn't experimental, so I can't let this one slide. :/

I see, ok I will split this one out then

Quoted 59 lines
Quoted 42 lines

  *    the two directory btrees: 2 * (max depth + v2) * dir block size
  *    the two directory bmap btrees: 2 * max depth * block size
  * And the bmap_finish transaction can free dir and bmap blocks (two sets
- *     of bmap blocks) giving:
+ *     of bmap blocks) giving (t2):
  *    the agf for the ags in which the blocks live: 3 * sector size
  *    the agfl for the ags in which the blocks live: 3 * sector size
  *    the superblock for the free block count: sector size *    the allocation btrees: 3 exts * 2 trees * (2 * max depth -
1) * block size
+ * If parent pointers are enabled (t3), then each transaction in the chain
+ *    must be capable of setting or removing the extended attribute
+ *    containing the parent information.  It must also be able to handle
+ *    the three xattr intent items that track the progress of the parent
+ *    pointer update.
  */
 STATIC uint
 xfs_calc_rename_reservation(
        struct xfs_mount        *mp)
 {
-       return XFS_DQUOT_LOGRES(mp) +
-               max((xfs_calc_inode_res(mp, 4) +
-                    xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), -                                     XFS_FSB_TO_B(mp, 1))), -                   (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + -                    xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
-                                     XFS_FSB_TO_B(mp, 1)))); +       unsigned int            overhead = XFS_DQUOT_LOGRES(mp); +       struct xfs_trans_resv   *resp = M_RES(mp);
+       unsigned int            t1, t2, t3 = 0;

fs/xfs/libxfs/xfs_trans_resv.c +2 -0
+
+       t1 = xfs_calc_inode_res(mp, 5) +

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_itruncate_reservation_minlogsize( · line 459

Quoted 10 lines
fs/xfs/libxfs/xfs_trans_resv.c +10 -0
+            xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
+                       XFS_FSB_TO_B(mp, 1));
+
+       t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
+            xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
+                       XFS_FSB_TO_B(mp, 1));
+
+       if (xfs_has_parent(mp)) {
+               t3 = max(resp->tr_attrsetm.tr_logres,
+                               resp->tr_attrrm.tr_logres);

Ooh I like this refactoring of xfs_calc_rename_reservation. :)

I guess we now tr_attr{setm,rm} before computing the rename reservation
so this is ok.

Quoted 5 lines
Quoted 2 lines

+               overhead += 3 * (sizeof(struct
xfs_attri_log_item));

Should the size of the name, newname, and value buffers be added into overhead?  They take up log space too.

That would make sense, but we cant really calculate that ahead of time with out just assuming the max size which is up to 64k for the value. Maybe those sizes should be added on after we know what they are?

Quoted 43 lines
Quoted 43 lines

+       }
+
+       return overhead + max3(t1, t2, t3);
 }

 /*

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -909,24 +927,59 @@ xfs_calc_sb_reservation(
         return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
  }

fs/xfs/libxfs/xfs_trans_resv.c +6 -4
-void
-xfs_trans_resv_calc(
-       struct xfs_mount        *mp,
-       struct xfs_trans_resv   *resp)
+/*
+ * Calculate extra space needed for parent pointer attributes
+ */
+STATIC void
+xfs_calc_parent_ptr_reservations(
+       struct xfs_mount     *mp)

 {
-       int                     logcount_adj = 0;
+       struct xfs_trans_resv   *resp = M_RES(mp);

-       /*
-        * The following transactions are logged in physical format and
-        * require a permanent reservation on space.
-        */
-       resp->tr_write.tr_logres = xfs_calc_write_reservation(mp, false);
-       resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; -       resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +       if (!xfs_has_parent(mp))
+               return;

-       resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
-       resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT; -       resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +       resp->tr_rename.tr_logres += max(resp-

Quoted 1 line

tr_attrsetm.tr_logres,

Quoted 8 lines
Quoted 6 lines

+                                        resp-

Quoted 1 line

tr_attrrm.tr_logres);

+       resp->tr_rename.tr_logcount += max(resp-

Quoted 1 line

tr_attrsetm.tr_logcount,

+                                          resp-

Quoted 1 line

tr_attrrm.tr_logcount);

Doesn't xfs_calc_rename_reservation add this to tr_rename already?

Oh, I think we can remove the tr_rename.tr_logres update. But not the logcount update right?

xfs_calc_rename_reservation just calculates what tr_rename.tr_logres should be, but it doesnt make any additions. It's that's used over in xfs_calc_namespace_reservations, but we still need to update tr_rename.tr_logcount which is separate field from tr_rename.tr_logres.

Quoted 15 lines
Quoted 15 lines

+
+       resp->tr_create.tr_logres += resp->tr_attrsetm.tr_logres; +       resp->tr_create.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_mkdir.tr_logres += resp->tr_attrsetm.tr_logres; +       resp->tr_mkdir.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+
+       resp->tr_link.tr_logres += resp->tr_attrsetm.tr_logres;
+       resp->tr_link.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+       resp->tr_symlink.tr_logres += resp->tr_attrsetm.tr_logres;
+       resp->tr_symlink.tr_logcount += resp-
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_remove.tr_logres += resp->tr_attrrm.tr_logres; +       resp->tr_remove.tr_logcount += resp->tr_attrrm.tr_logcount;

Shouldn't each of these += additions be made to xfs_calc_{icreate,mkdir,link,symlink,remove}_reservation, respectively?

I suppose we could redo it that way? But then not all of the "+=" would disappear if they worked like xfs_calc_rename_reservation. Just the *.tr_logres. Do we really want separate wrappers for just these oneliners though?

Allison

Quoted 95 lines

--D

Quoted 93 lines
fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+}
+
+/*
+ * Namespace reservations.
+ *
+ * These get tricky when parent pointers are enabled as we have

attribute
+ * modifications occurring from within these transactions. Rather than confuse
+ * each of these reservation calculations with the conditional attribute
+ * reservations, add them here in a clear and concise manner. This assumes that
+ * the attribute reservations have already been calculated.
+ *
+ * Note that we only include the static attribute reservation here; the runtime
+ * reservation will have to be modified by the size of the attributes being
+ * added/removed/modified. See the comments on the attribute reservation
+ * calculations for more details.
+ */

fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+STATIC void
+xfs_calc_namespace_reservations(
+       struct xfs_mount        *mp,
+       struct xfs_trans_resv   *resp)
+{
+       ASSERT(resp->tr_attrsetm.tr_logres > 0);


        resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -948,15 +1001,37 @@ xfs_trans_resv_calc(
         resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
         resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;


+       resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); +       resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; +       resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c +13 -0
+
+       xfs_calc_parent_ptr_reservations(mp);
+}
+
+void
+xfs_trans_resv_calc(
+       struct xfs_mount        *mp,
+       struct xfs_trans_resv   *resp)
+{
+       int                     logcount_adj = 0;
+
+       /*
+        * The following transactions are logged in physical format

and
+        * require a permanent reservation on space.
+        */
+       resp->tr_write.tr_logres = xfs_calc_write_reservation(mp, false);
+       resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; +       resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +
+       resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
+       resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT; +       resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +
        resp->tr_create_tmpfile.tr_logres = xfs_calc_create_tmpfile_reservation(mp); resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT; resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

-       resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); -       resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; -       resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; -
        resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp); resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT; resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -986,6 +1061,8 @@ xfs_trans_resv_calc(
         resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT;
         resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;


+       xfs_calc_namespace_reservations(mp, resp);
+
        /*
         * The following transactions are logged in logical format with
         * a default log count.

Signature · 1 line
2.25.1
#27 lore raw

Re: [PATCH v3 13/26] xfs: extend transaction reservations for parent attributes

Quoted 114 lines · Allison Henderson
Quoted 46 lines · Darrick J. Wong
Quoted 35 lines · On Wed, Sep 21, 2022 at 10:44:45PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

We need to add, remove or modify parent pointer attributes during create/link/unlink/rename operations atomically with the dirents in the
parent directories being modified. This means they need to be modified
in the same transaction as the parent directories, and so we need to add
the required space for the attribute modifications to the transaction
reservations.

---
 fs/xfs/libxfs/xfs_trans_resv.c | 135 ++++++++++++++++++++++++++---
----

 1 file changed, 106 insertions(+), 29 deletions(-)
fs/xfs/libxfs/xfs_trans_resv.c +1 -0
index 2c4ad6e4bb14..f7799800d556 100644
@@ -19,6 +19,7 @@
  #include "xfs_trans.h"
  #include "xfs_qm.h"
  #include "xfs_trans_space.h"
+#include "xfs_attr_item.h"


 #define _ALLOC true
 #define _FREE  false

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -421,28 +422,45 @@ xfs_calc_itruncate_reservation_minlogsize(
  }
Quoted 6 lines


 /*
- * In renaming a files we can modify:
- *    the four inodes involved: 4 * inode size
+ * In renaming a files we can modify (t1):
+ *    the four inodes involved: 5 * inode size

...the *five* inodes involved...

Quoted 6 lines

Also -- even before parent pointers we could have five inodes involved
in a rename transaction, so I think this change needs to be a separate
bugfix at the start of the series.  Rename isn't experimental, so I can't let this one slide. :/

I see, ok I will split this one out then

Quoted 59 lines
Quoted 42 lines

  *    the two directory btrees: 2 * (max depth + v2) * dir block size
  *    the two directory bmap btrees: 2 * max depth * block size
  * And the bmap_finish transaction can free dir and bmap blocks (two sets
- *     of bmap blocks) giving:
+ *     of bmap blocks) giving (t2):
  *    the agf for the ags in which the blocks live: 3 * sector size
  *    the agfl for the ags in which the blocks live: 3 * sector size
  *    the superblock for the free block count: sector size *    the allocation btrees: 3 exts * 2 trees * (2 * max depth -
1) * block size
+ * If parent pointers are enabled (t3), then each transaction in the chain
+ *    must be capable of setting or removing the extended attribute
+ *    containing the parent information.  It must also be able to handle
+ *    the three xattr intent items that track the progress of the parent
+ *    pointer update.
  */
 STATIC uint
 xfs_calc_rename_reservation(
        struct xfs_mount        *mp)
 {
-       return XFS_DQUOT_LOGRES(mp) +
-               max((xfs_calc_inode_res(mp, 4) +
-                    xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), -                                     XFS_FSB_TO_B(mp, 1))), -                   (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + -                    xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
-                                     XFS_FSB_TO_B(mp, 1)))); +       unsigned int            overhead = XFS_DQUOT_LOGRES(mp); +       struct xfs_trans_resv   *resp = M_RES(mp);
+       unsigned int            t1, t2, t3 = 0;

fs/xfs/libxfs/xfs_trans_resv.c +2 -0
+
+       t1 = xfs_calc_inode_res(mp, 5) +

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_itruncate_reservation_minlogsize( · line 459

Quoted 10 lines
fs/xfs/libxfs/xfs_trans_resv.c +10 -0
+            xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
+                       XFS_FSB_TO_B(mp, 1));
+
+       t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
+            xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
+                       XFS_FSB_TO_B(mp, 1));
+
+       if (xfs_has_parent(mp)) {
+               t3 = max(resp->tr_attrsetm.tr_logres,
+                               resp->tr_attrrm.tr_logres);

Ooh I like this refactoring of xfs_calc_rename_reservation. :)

I guess we now tr_attr{setm,rm} before computing the rename reservation
so this is ok.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

+               overhead += 3 * (sizeof(struct
xfs_attri_log_item));

Should the size of the name, newname, and value buffers be added into overhead?  They take up log space too.

That would make sense, but we cant really calculate that ahead of time with out just assuming the max size which is up to 64k for the value. Maybe those sizes should be added on after we know what they are?

They have to be worst case values, but fortunately we know what the worst case is:

name: sizeof(ondisk parent ptr structure) + iovec overhead
newname: same for rename, and zero everywhere else iiuc?
value: 255 + iovec_overhead

Quoted 45 lines
Quoted 45 lines
Quoted 45 lines

+       }
+
+       return overhead + max3(t1, t2, t3);
 }

 /*

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -909,24 +927,59 @@ xfs_calc_sb_reservation(
         return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
  }

fs/xfs/libxfs/xfs_trans_resv.c +6 -4
-void
-xfs_trans_resv_calc(
-       struct xfs_mount        *mp,
-       struct xfs_trans_resv   *resp)
+/*
+ * Calculate extra space needed for parent pointer attributes
+ */
+STATIC void
+xfs_calc_parent_ptr_reservations(
+       struct xfs_mount     *mp)

 {
-       int                     logcount_adj = 0;
+       struct xfs_trans_resv   *resp = M_RES(mp);

-       /*
-        * The following transactions are logged in physical format and
-        * require a permanent reservation on space.
-        */
-       resp->tr_write.tr_logres = xfs_calc_write_reservation(mp, false);
-       resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; -       resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +       if (!xfs_has_parent(mp))
+               return;

-       resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
-       resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT; -       resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +       resp->tr_rename.tr_logres += max(resp-

Quoted 1 line

tr_attrsetm.tr_logres,

+                                        resp-

Quoted 1 line

tr_attrrm.tr_logres);

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

+       resp->tr_rename.tr_logcount += max(resp-

Quoted 1 line

tr_attrsetm.tr_logcount,

+                                          resp-

Quoted 1 line

tr_attrrm.tr_logcount);

Doesn't xfs_calc_rename_reservation add this to tr_rename already?

Oh, I think we can remove the tr_rename.tr_logres update. But not the logcount update right?

Right, though you could update XFS_RENAME_LOG_COUNT (or turn it into a helper function).

Quoted 31 lines

xfs_calc_rename_reservation just calculates what tr_rename.tr_logres should be, but it doesnt make any additions. It's that's used over in xfs_calc_namespace_reservations, but we still need to update tr_rename.tr_logcount which is separate field from tr_rename.tr_logres.

Quoted 15 lines
Quoted 15 lines

+
+       resp->tr_create.tr_logres += resp->tr_attrsetm.tr_logres; +       resp->tr_create.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_mkdir.tr_logres += resp->tr_attrsetm.tr_logres; +       resp->tr_mkdir.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+
+       resp->tr_link.tr_logres += resp->tr_attrsetm.tr_logres;
+       resp->tr_link.tr_logcount += resp->tr_attrsetm.tr_logcount;
+
+       resp->tr_symlink.tr_logres += resp->tr_attrsetm.tr_logres;
+       resp->tr_symlink.tr_logcount += resp-
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_remove.tr_logres += resp->tr_attrrm.tr_logres; +       resp->tr_remove.tr_logcount += resp->tr_attrrm.tr_logcount;

Shouldn't each of these += additions be made to xfs_calc_{icreate,mkdir,link,symlink,remove}_reservation, respectively?

Quoted 4 lines

I suppose we could redo it that way? But then not all of the "+=" would disappear if they worked like xfs_calc_rename_reservation. Just the *.tr_logres. Do we really want separate wrappers for just these oneliners though?

Yes, once those macros start acquiring logic, they ought to turn into static inline helpers.

--D

Quoted 98 lines

Allison

Quoted 95 lines

--D

Quoted 93 lines
fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+}
+
+/*
+ * Namespace reservations.
+ *
+ * These get tricky when parent pointers are enabled as we have

attribute
+ * modifications occurring from within these transactions. Rather than confuse
+ * each of these reservation calculations with the conditional attribute
+ * reservations, add them here in a clear and concise manner. This assumes that
+ * the attribute reservations have already been calculated.
+ *
+ * Note that we only include the static attribute reservation here; the runtime
+ * reservation will have to be modified by the size of the attributes being
+ * added/removed/modified. See the comments on the attribute reservation
+ * calculations for more details.
+ */

fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+STATIC void
+xfs_calc_namespace_reservations(
+       struct xfs_mount        *mp,
+       struct xfs_trans_resv   *resp)
+{
+       ASSERT(resp->tr_attrsetm.tr_logres > 0);


        resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -948,15 +1001,37 @@ xfs_trans_resv_calc(
         resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
         resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;


+       resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); +       resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; +       resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c +13 -0
+
+       xfs_calc_parent_ptr_reservations(mp);
+}
+
+void
+xfs_trans_resv_calc(
+       struct xfs_mount        *mp,
+       struct xfs_trans_resv   *resp)
+{
+       int                     logcount_adj = 0;
+
+       /*
+        * The following transactions are logged in physical format

and
+        * require a permanent reservation on space.
+        */
+       resp->tr_write.tr_logres = xfs_calc_write_reservation(mp, false);
+       resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; +       resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +
+       resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
+       resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT; +       resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +
        resp->tr_create_tmpfile.tr_logres = xfs_calc_create_tmpfile_reservation(mp); resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT; resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

-       resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); -       resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; -       resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; -
        resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp); resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT; resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -986,6 +1061,8 @@ xfs_trans_resv_calc(
         resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT;
         resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;


+       xfs_calc_namespace_reservations(mp, resp);
+
        /*
         * The following transactions are logged in logical format with
         * a default log count.

Signature · 1 line
2.25.1
#28 lore raw

Re: [PATCH v3 13/26] xfs: extend transaction reservations for parent attributes

Quoted 145 lines · Darrick J. Wong
Quoted 135 lines · Allison Henderson
Quoted 51 lines · Darrick J. Wong
Quoted 38 lines · On Wed, Sep 21, 2022 at 10:44:45PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

We need to add, remove or modify parent pointer attributes during
create/link/unlink/rename operations atomically with the dirents in
the
parent directories being modified. This means they need to be modified
in the same transaction as the parent directories, and so we need
to add
the required space for the attribute modifications to the transaction
reservations.

---
 fs/xfs/libxfs/xfs_trans_resv.c | 135
++++++++++++++++++++++++++---
----

 1 file changed, 106 insertions(+), 29 deletions(-)
fs/xfs/libxfs/xfs_trans_resv.c +1 -0
index 2c4ad6e4bb14..f7799800d556 100644
@@ -19,6 +19,7 @@
  #include "xfs_trans.h"
  #include "xfs_qm.h"
  #include "xfs_trans_space.h"
+#include "xfs_attr_item.h"


 #define _ALLOC true
 #define _FREE  false

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -421,28 +422,45 @@
Quoted 8 lines

xfs_calc_itruncate_reservation_minlogsize(
 }

 /*
- * In renaming a files we can modify:
- *    the four inodes involved: 4 * inode size
+ * In renaming a files we can modify (t1):
+ *    the four inodes involved: 5 * inode size

...the *five* inodes involved...

Quoted 7 lines

Also -- even before parent pointers we could have five inodes involved
in a rename transaction, so I think this change needs to be a separate
bugfix at the start of the series.  Rename isn't experimental, so I
can't let this one slide. :/

I see, ok I will split this one out then

Quoted 74 lines
Quoted 54 lines

  *    the two directory btrees: 2 * (max depth + v2) * dir block
size
  *    the two directory bmap btrees: 2 * max depth * block size
  * And the bmap_finish transaction can free dir and bmap blocks
(two sets
- *     of bmap blocks) giving:
+ *     of bmap blocks) giving (t2):
  *    the agf for the ags in which the blocks live: 3 * sector size
  *    the agfl for the ags in which the blocks live: 3 * sector
size
  *    the superblock for the free block count: sector size *    the allocation btrees: 3 exts * 2 trees * (2 * max depth -
1) * block size
+ * If parent pointers are enabled (t3), then each transaction in
the chain
+ *    must be capable of setting or removing the extended attribute
+ *    containing the parent information.  It must also be able to
handle
+ *    the three xattr intent items that track the progress of the
parent
+ *    pointer update.
  */
 STATIC uint
 xfs_calc_rename_reservation(
        struct xfs_mount        *mp)
 {
-       return XFS_DQUOT_LOGRES(mp) +
-               max((xfs_calc_inode_res(mp, 4) +
-                    xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
-                                     XFS_FSB_TO_B(mp, 1))), -                   (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
-
xfs_calc_buf_res(xfs_allocfree_block_count(mp,
3),
-                                     XFS_FSB_TO_B(mp, 1)))); +       unsigned int            overhead = XFS_DQUOT_LOGRES(mp);
+       struct xfs_trans_resv   *resp = M_RES(mp);
+       unsigned int            t1, t2, t3 = 0;

fs/xfs/libxfs/xfs_trans_resv.c +2 -0
+
+       t1 = xfs_calc_inode_res(mp, 5) +

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_itruncate_reservation_minlogsize( · line 459

Quoted 10 lines
fs/xfs/libxfs/xfs_trans_resv.c +10 -0
+            xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
+                       XFS_FSB_TO_B(mp, 1));
+
+       t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
+            xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
+                       XFS_FSB_TO_B(mp, 1));
+
+       if (xfs_has_parent(mp)) {
+               t3 = max(resp->tr_attrsetm.tr_logres,
+                               resp->tr_attrrm.tr_logres);

Ooh I like this refactoring of xfs_calc_rename_reservation. :)

I guess we now tr_attr{setm,rm} before computing the rename reservation
so this is ok.

Quoted 2 lines

+               overhead += 3 * (sizeof(struct
xfs_attri_log_item));

Quoted 8 lines
Quoted 3 lines

Should the size of the name, newname, and value buffers be added into
overhead?  They take up log space too.

That would make sense, but we cant really calculate that ahead of time
with out just assuming the max size which is up to 64k for the value.
Maybe those sizes should be added on after we know what they are?

Quoted 7 lines

They have to be worst case values, but fortunately we know what the worst case is:

name: sizeof(ondisk parent ptr structure) + iovec overhead
newname: same for rename, and zero everywhere else iiuc?
value: 255 + iovec_overhead

Ok, I'll see if I can plumb those through xfs_trans_alloc

Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
Quoted 46 lines

+       }
+
+       return overhead + max3(t1, t2, t3);
 }

 /*

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -909,24 +927,59 @@ xfs_calc_sb_reservation(
         return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
  }

fs/xfs/libxfs/xfs_trans_resv.c +6 -4
-void
-xfs_trans_resv_calc(
-       struct xfs_mount        *mp,
-       struct xfs_trans_resv   *resp)
+/*
+ * Calculate extra space needed for parent pointer attributes
+ */
+STATIC void
+xfs_calc_parent_ptr_reservations(
+       struct xfs_mount     *mp)

 {
-       int                     logcount_adj = 0;
+       struct xfs_trans_resv   *resp = M_RES(mp);

-       /*
-        * The following transactions are logged in physical format
and
-        * require a permanent reservation on space. -        */
-       resp->tr_write.tr_logres = xfs_calc_write_reservation(mp,
false);
-       resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; -       resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +       if (!xfs_has_parent(mp))
+               return;

-       resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
-       resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
-       resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+       resp->tr_rename.tr_logres += max(resp-

Quoted 7 lines
Quoted 1 line

tr_attrsetm.tr_logres,

+                                        resp-

Quoted 1 line

tr_attrrm.tr_logres);

+       resp->tr_rename.tr_logcount += max(resp-

Quoted 1 line

tr_attrsetm.tr_logcount,

+                                          resp-

Quoted 1 line

tr_attrrm.tr_logcount);

Doesn't xfs_calc_rename_reservation add this to tr_rename already?

Quoted 7 lines
Quoted 3 lines

Oh, I think we can remove the tr_rename.tr_logres update.  But not the
logcount update right?

Right, though you could update XFS_RENAME_LOG_COUNT (or turn it into a
helper function).

Hmm, updating the #define would affect non pptr code paths, and it seems a bit small for a helper. I may leave the log count here if it doesnt bother folks, I dont think it's out of place along with the other logcount updates.

Quoted 47 lines
Quoted 40 lines

xfs_calc_rename_reservation just calculates what tr_rename.tr_logres
should be, but it doesnt make any additions.  It's that's used over in
xfs_calc_namespace_reservations, but we still need to update tr_rename.tr_logcount which is separate field from tr_rename.tr_logres.

Quoted 20 lines
Quoted 20 lines

+
+       resp->tr_create.tr_logres += resp-

Quoted 1 line

tr_attrsetm.tr_logres;

+       resp->tr_create.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_mkdir.tr_logres += resp-

Quoted 1 line

tr_attrsetm.tr_logres;

+       resp->tr_mkdir.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_link.tr_logres += resp->tr_attrsetm.tr_logres; +       resp->tr_link.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_symlink.tr_logres += resp-

Quoted 1 line

tr_attrsetm.tr_logres;

+       resp->tr_symlink.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

Quoted 9 lines
Quoted 4 lines

+
+       resp->tr_remove.tr_logres += resp->tr_attrrm.tr_logres; +       resp->tr_remove.tr_logcount += resp-

Quoted 1 line

tr_attrrm.tr_logcount;

Shouldn't each of these += additions be made to xfs_calc_{icreate,mkdir,link,symlink,remove}_reservation, respectively?

Quoted 6 lines

I suppose we could redo it that way?  But then not all of the "+=" would disappear if they worked like xfs_calc_rename_reservation. Just
the *.tr_logres.  Do we really want separate wrappers for just these
oneliners though?

Quoted 2 lines

Yes, once those macros start acquiring logic, they ought to turn into static inline helpers.

Ok, I will split those off as needed when I go through the xfs_trans_alloc modifications then.

Thanks!

Quoted 114 lines

--D

Quoted 111 lines

Allison

Quoted 108 lines

--D

Quoted 106 lines
fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+}
+
+/*
+ * Namespace reservations.
+ *
+ * These get tricky when parent pointers are enabled as we

have
attribute
+ * modifications occurring from within these transactions. Rather
than confuse
+ * each of these reservation calculations with the conditional attribute
+ * reservations, add them here in a clear and concise manner. This
assumes that
+ * the attribute reservations have already been calculated.
+ *
+ * Note that we only include the static attribute reservation here; the runtime
+ * reservation will have to be modified by the size of the attributes being
+ * added/removed/modified. See the comments on the attribute reservation
+ * calculations for more details.
+ */

fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+STATIC void
+xfs_calc_namespace_reservations(
+       struct xfs_mount        *mp,
+       struct xfs_trans_resv   *resp)
+{
+       ASSERT(resp->tr_attrsetm.tr_logres > 0);


        resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -948,15 +1001,37 @@ xfs_trans_resv_calc(
         resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
         resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;


+       resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
+       resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; +       resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c +13 -0
+
+       xfs_calc_parent_ptr_reservations(mp);
+}
+
+void
+xfs_trans_resv_calc(
+       struct xfs_mount        *mp,
+       struct xfs_trans_resv   *resp)
+{
+       int                     logcount_adj = 0;
+
+       /*
+        * The following transactions are logged in physical

format
and
+        * require a permanent reservation on space. +        */
+       resp->tr_write.tr_logres = xfs_calc_write_reservation(mp,
false);
+       resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; +       resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +
+       resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
+       resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
+       resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
        resp->tr_create_tmpfile.tr_logres = xfs_calc_create_tmpfile_reservation(mp) ;
        resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT; resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

-       resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
-       resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; -       resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; -
        resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp); resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT; resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -986,6 +1061,8 @@ xfs_trans_resv_calc(
         resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT;

        resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

+       xfs_calc_namespace_reservations(mp, resp); +
        /*
         * The following transactions are logged in logical format
with
         * a default log count.

Signature · 1 line
2.25.1
#29 lore raw

Re: [PATCH v3 13/26] xfs: extend transaction reservations for parent attributes

Quoted 215 lines · Allison Henderson
Quoted 145 lines · Darrick J. Wong
Quoted 135 lines · Allison Henderson
Quoted 51 lines · Darrick J. Wong
Quoted 38 lines · On Wed, Sep 21, 2022 at 10:44:45PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

We need to add, remove or modify parent pointer attributes during
create/link/unlink/rename operations atomically with the dirents in
the
parent directories being modified. This means they need to be modified
in the same transaction as the parent directories, and so we need
to add
the required space for the attribute modifications to the transaction
reservations.

---
 fs/xfs/libxfs/xfs_trans_resv.c | 135
++++++++++++++++++++++++++---
----

 1 file changed, 106 insertions(+), 29 deletions(-)
fs/xfs/libxfs/xfs_trans_resv.c +1 -0
index 2c4ad6e4bb14..f7799800d556 100644
@@ -19,6 +19,7 @@
  #include "xfs_trans.h"
  #include "xfs_qm.h"
  #include "xfs_trans_space.h"
+#include "xfs_attr_item.h"


 #define _ALLOC true
 #define _FREE  false

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -421,28 +422,45 @@
Quoted 8 lines

xfs_calc_itruncate_reservation_minlogsize(
 }

 /*
- * In renaming a files we can modify:
- *    the four inodes involved: 4 * inode size
+ * In renaming a files we can modify (t1):
+ *    the four inodes involved: 5 * inode size

...the *five* inodes involved...

Quoted 7 lines

Also -- even before parent pointers we could have five inodes involved
in a rename transaction, so I think this change needs to be a separate
bugfix at the start of the series.  Rename isn't experimental, so I
can't let this one slide. :/

I see, ok I will split this one out then

Quoted 74 lines
Quoted 54 lines

  *    the two directory btrees: 2 * (max depth + v2) * dir block
size
  *    the two directory bmap btrees: 2 * max depth * block size
  * And the bmap_finish transaction can free dir and bmap blocks
(two sets
- *     of bmap blocks) giving:
+ *     of bmap blocks) giving (t2):
  *    the agf for the ags in which the blocks live: 3 * sector size
  *    the agfl for the ags in which the blocks live: 3 * sector
size
  *    the superblock for the free block count: sector size *    the allocation btrees: 3 exts * 2 trees * (2 * max depth -
1) * block size
+ * If parent pointers are enabled (t3), then each transaction in
the chain
+ *    must be capable of setting or removing the extended attribute
+ *    containing the parent information.  It must also be able to
handle
+ *    the three xattr intent items that track the progress of the
parent
+ *    pointer update.
  */
 STATIC uint
 xfs_calc_rename_reservation(
        struct xfs_mount        *mp)
 {
-       return XFS_DQUOT_LOGRES(mp) +
-               max((xfs_calc_inode_res(mp, 4) +
-                    xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
-                                     XFS_FSB_TO_B(mp, 1))), -                   (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
-
xfs_calc_buf_res(xfs_allocfree_block_count(mp,
3),
-                                     XFS_FSB_TO_B(mp, 1)))); +       unsigned int            overhead = XFS_DQUOT_LOGRES(mp);
+       struct xfs_trans_resv   *resp = M_RES(mp);
+       unsigned int            t1, t2, t3 = 0;

fs/xfs/libxfs/xfs_trans_resv.c +2 -0
+
+       t1 = xfs_calc_inode_res(mp, 5) +

fs/xfs/libxfs/xfs_trans_resv.c xfs_calc_itruncate_reservation_minlogsize( · line 459

Quoted 10 lines
fs/xfs/libxfs/xfs_trans_resv.c +10 -0
+            xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
+                       XFS_FSB_TO_B(mp, 1));
+
+       t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
+            xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3),
+                       XFS_FSB_TO_B(mp, 1));
+
+       if (xfs_has_parent(mp)) {
+               t3 = max(resp->tr_attrsetm.tr_logres,
+                               resp->tr_attrrm.tr_logres);

Ooh I like this refactoring of xfs_calc_rename_reservation. :)

I guess we now tr_attr{setm,rm} before computing the rename reservation
so this is ok.

Quoted 2 lines

+               overhead += 3 * (sizeof(struct
xfs_attri_log_item));

Quoted 8 lines
Quoted 3 lines

Should the size of the name, newname, and value buffers be added into
overhead?  They take up log space too.

That would make sense, but we cant really calculate that ahead of time
with out just assuming the max size which is up to 64k for the value.
Maybe those sizes should be added on after we know what they are?

Quoted 7 lines

They have to be worst case values, but fortunately we know what the worst case is:

name: sizeof(ondisk parent ptr structure) + iovec overhead
newname: same for rename, and zero everywhere else iiuc?
value: 255 + iovec_overhead

Ok, I'll see if I can plumb those through xfs_trans_alloc

Quoted 60 lines
Quoted 59 lines
Quoted 48 lines
Quoted 48 lines

+       }
+
+       return overhead + max3(t1, t2, t3);
 }

 /*

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -909,24 +927,59 @@ xfs_calc_sb_reservation(
         return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
  }

fs/xfs/libxfs/xfs_trans_resv.c +6 -4
-void
-xfs_trans_resv_calc(
-       struct xfs_mount        *mp,
-       struct xfs_trans_resv   *resp)
+/*
+ * Calculate extra space needed for parent pointer attributes
+ */
+STATIC void
+xfs_calc_parent_ptr_reservations(
+       struct xfs_mount     *mp)

 {
-       int                     logcount_adj = 0;
+       struct xfs_trans_resv   *resp = M_RES(mp);

-       /*
-        * The following transactions are logged in physical format
and
-        * require a permanent reservation on space. -        */
-       resp->tr_write.tr_logres = xfs_calc_write_reservation(mp,
false);
-       resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; -       resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +       if (!xfs_has_parent(mp))
+               return;

-       resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
-       resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
-       resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+       resp->tr_rename.tr_logres += max(resp-

Quoted 1 line

tr_attrsetm.tr_logres,

+                                        resp-

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

tr_attrrm.tr_logres);

+       resp->tr_rename.tr_logcount += max(resp-

Quoted 1 line

tr_attrsetm.tr_logcount,

+                                          resp-

Quoted 1 line

tr_attrrm.tr_logcount);

Doesn't xfs_calc_rename_reservation add this to tr_rename already?

Oh, I think we can remove the tr_rename.tr_logres update.  But not the
logcount update right?

Quoted 7 lines
Quoted 3 lines

Right, though you could update XFS_RENAME_LOG_COUNT (or turn it into a
helper function).

Hmm, updating the #define would affect non pptr code paths, and it seems a bit small for a helper. I may leave the log count here if it doesnt bother folks, I dont think it's out of place along with the other logcount updates.

How do you mean?

static inline unsigned int
xfs_rename_log_count(
struct xfs_mount *mp,
struct xfs_trans_resv *resp))

{
	/* One for the rename, one more for freeing blocks */
	unsigned int		ret = 2;

	/*
	 * Pre-reserve enough log reservation to handle the transaction
	 * rolling needed to remove or add one parent pointer.
	 *
	 * XXX: Should we reserve enough space to handle the tx rolls
	 * resulting from removing /and/ adding a pptr?
	 */
	if (xfs_has_parent(mp))
		ret += max(resp->tr_attrsetm.tr_logcount,
			   resp->tr_attrrm.tr_logcount);

	return ret;
}

--D

Quoted 170 lines
Quoted 48 lines
Quoted 41 lines

xfs_calc_rename_reservation just calculates what tr_rename.tr_logres
should be, but it doesnt make any additions.  It's that's used over in
xfs_calc_namespace_reservations, but we still need to update tr_rename.tr_logcount which is separate field from tr_rename.tr_logres.

Quoted 20 lines
Quoted 20 lines

+
+       resp->tr_create.tr_logres += resp-

Quoted 1 line

tr_attrsetm.tr_logres;

+       resp->tr_create.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_mkdir.tr_logres += resp-

Quoted 1 line

tr_attrsetm.tr_logres;

+       resp->tr_mkdir.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_link.tr_logres += resp->tr_attrsetm.tr_logres; +       resp->tr_link.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

+
+       resp->tr_symlink.tr_logres += resp-

Quoted 1 line

tr_attrsetm.tr_logres;

+       resp->tr_symlink.tr_logcount += resp-

Quoted 1 line

tr_attrsetm.tr_logcount;

Quoted 9 lines
Quoted 4 lines

+
+       resp->tr_remove.tr_logres += resp->tr_attrrm.tr_logres; +       resp->tr_remove.tr_logcount += resp-

Quoted 1 line

tr_attrrm.tr_logcount;

Shouldn't each of these += additions be made to xfs_calc_{icreate,mkdir,link,symlink,remove}_reservation, respectively?

Quoted 6 lines

I suppose we could redo it that way?  But then not all of the "+=" would disappear if they worked like xfs_calc_rename_reservation. Just
the *.tr_logres.  Do we really want separate wrappers for just these
oneliners though?

Quoted 2 lines

Yes, once those macros start acquiring logic, they ought to turn into static inline helpers.

Ok, I will split those off as needed when I go through the xfs_trans_alloc modifications then.

Thanks!

Quoted 114 lines

--D

Quoted 111 lines

Allison

Quoted 108 lines

--D

Quoted 106 lines
fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+}
+
+/*
+ * Namespace reservations.
+ *
+ * These get tricky when parent pointers are enabled as we

have
attribute
+ * modifications occurring from within these transactions. Rather
than confuse
+ * each of these reservation calculations with the conditional attribute
+ * reservations, add them here in a clear and concise manner. This
assumes that
+ * the attribute reservations have already been calculated.
+ *
+ * Note that we only include the static attribute reservation here; the runtime
+ * reservation will have to be modified by the size of the attributes being
+ * added/removed/modified. See the comments on the attribute reservation
+ * calculations for more details.
+ */

fs/xfs/libxfs/xfs_trans_resv.c +6 -0
+STATIC void
+xfs_calc_namespace_reservations(
+       struct xfs_mount        *mp,
+       struct xfs_trans_resv   *resp)
+{
+       ASSERT(resp->tr_attrsetm.tr_logres > 0);


        resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT;

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -948,15 +1001,37 @@ xfs_trans_resv_calc(
         resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT;
         resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES;


+       resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
+       resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; +       resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c +13 -0
+
+       xfs_calc_parent_ptr_reservations(mp);
+}
+
+void
+xfs_trans_resv_calc(
+       struct xfs_mount        *mp,
+       struct xfs_trans_resv   *resp)
+{
+       int                     logcount_adj = 0;
+
+       /*
+        * The following transactions are logged in physical

format
and
+        * require a permanent reservation on space. +        */
+       resp->tr_write.tr_logres = xfs_calc_write_reservation(mp,
false);
+       resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; +       resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +
+       resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp, false);
+       resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT;
+       resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES;
+
        resp->tr_create_tmpfile.tr_logres = xfs_calc_create_tmpfile_reservation(mp) ;
        resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT; resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

-       resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp);
-       resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; -       resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; -
        resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp); resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT; resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

fs/xfs/libxfs/xfs_trans_resv.c +0 -0
@@ -986,6 +1061,8 @@ xfs_trans_resv_calc(
         resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT;

        resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES;

+       xfs_calc_namespace_reservations(mp, resp); +
        /*
         * The following transactions are logged in logical format
with
         * a default log count.

Signature · 1 line
2.25.1
#30 lore raw

PATCH v3 14/26 xfs: parent pointer attribute creation

In reply to [email protected]

From: Allison Henderson <[email protected]>

Add parent pointer attribute during xfs_create, and subroutines to initialize attributes

---
 fs/xfs/Makefile            |   1 +
 fs/xfs/libxfs/xfs_attr.c   |   4 +-
 fs/xfs/libxfs/xfs_attr.h   |   4 +-
 fs/xfs/libxfs/xfs_parent.c | 135 +++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  32 +++++++++
 fs/xfs/xfs_inode.c         |  37 ++++++++--
 fs/xfs/xfs_xattr.c         |   2 +-
 fs/xfs/xfs_xattr.h         |   1 +
 8 files changed, 207 insertions(+), 9 deletions(-)
fs/xfs/Makefile +1 -0
index 03135a1c31b6..e2b2cf50ffcf 100644
@@ -40,6 +40,7 @@ xfs-y				+= $(addprefix libxfs/, \
 				   xfs_inode_fork.o \
 				   xfs_inode_buf.o \
 				   xfs_log_rlimit.o \
+				   xfs_parent.o \
 				   xfs_ag_resv.o \
 				   xfs_rmap.o \
 				   xfs_rmap_btree.o \
fs/xfs/libxfs/xfs_attr.c +2 -2
index 0c9589261990..805aaa5639d2 100644
@@ -886,7 +886,7 @@ xfs_attr_lookup(
 	return error;
 }
 
-static int
+int
 xfs_attr_intent_init(
 	struct xfs_da_args	*args,
 	unsigned int		op_flags,	/* op flag (set or remove) */
@@ -904,7 +904,7 @@ xfs_attr_intent_init(
 }
 
 /* Sets an attribute for an inode as a deferred operation */
-static int
+int
 xfs_attr_defer_add(
 	struct xfs_da_args	*args)
 {
fs/xfs/libxfs/xfs_attr.h +3 -1
index b79dae788cfb..0cf23f5117ad 100644
@@ -544,6 +544,7 @@ int xfs_inode_hasattr(struct xfs_inode *ip);
 bool xfs_attr_is_leaf(struct xfs_inode *ip);
 int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
+int xfs_attr_defer_add(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_iter(struct xfs_attr_intent *attr);
 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
@@ -552,7 +553,8 @@ bool xfs_attr_namecheck(struct xfs_mount *mp, const void *name, size_t length,
 int xfs_attr_calc_size(struct xfs_da_args *args, int *local);
 void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
 			 unsigned int *total);
-
+int xfs_attr_intent_init(struct xfs_da_args *args, unsigned int op_flags,
+			 struct xfs_attr_intent  **attr);
 /*
  * Check to see if the attr should be upgraded from non-existent or shortform to
  * single-leaf-block attribute list.
fs/xfs/libxfs/xfs_parent.c new file +135 -0

135 lines not on this page · raw message

fs/xfs/libxfs/xfs_parent.h new file +32 -0
new file mode 100644
index 000000000000..971044458f8a
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All Rights Reserved.
+ */
+#ifndef	__XFS_PARENT_H__
+#define	__XFS_PARENT_H__
+
+/*
+ * Dynamically allocd structure used to wrap the needed data to pass around
+ * the defer ops machinery
+ */
+struct xfs_parent_defer {
+	struct xfs_parent_name_rec	rec;
+	struct xfs_da_args		args;
+};
+
+/*
+ * 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(xfs_mount_t *mp, struct xfs_parent_defer **parentp);
+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);
+void xfs_parent_cancel(xfs_mount_t *mp, struct xfs_parent_defer *parent);
+
+#endif	/* __XFS_PARENT_H__ */
fs/xfs/xfs_inode.c +32 -5
index 6eb264598517..181d6417412e 100644
@@ -37,6 +37,8 @@
 #include "xfs_reflink.h"
 #include "xfs_ag.h"
 #include "xfs_log_priv.h"
+#include "xfs_parent.h"
+#include "xfs_xattr.h"
 
 struct kmem_cache *xfs_inode_cache;
 
@@ -949,7 +951,7 @@ xfs_bumplink(
 int
 xfs_create(
 	struct user_namespace	*mnt_userns,
-	xfs_inode_t		*dp,
+	struct xfs_inode	*dp,
 	struct xfs_name		*name,
 	umode_t			mode,
 	dev_t			rdev,
@@ -961,7 +963,7 @@ xfs_create(
 	struct xfs_inode	*ip = NULL;
 	struct xfs_trans	*tp = NULL;
 	int			error;
-	bool                    unlock_dp_on_error = false;
+	bool			unlock_dp_on_error = false;
 	prid_t			prid;
 	struct xfs_dquot	*udqp = NULL;
 	struct xfs_dquot	*gdqp = NULL;
@@ -969,6 +971,8 @@ xfs_create(
 	struct xfs_trans_res	*tres;
 	uint			resblks;
 	xfs_ino_t		ino;
+	xfs_dir2_dataptr_t	diroffset;
+	struct xfs_parent_defer	*parent = NULL;
 
 	trace_xfs_create(dp, name);
 
@@ -995,6 +999,12 @@ xfs_create(
 		tres = &M_RES(mp)->tr_create;
 	}
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &parent);
+		if (error)
+			goto out_release_dquots;
+	}
+
 	/*
 	 * Initially assume that the file does not exist and
 	 * reserve the resources for that case.  If that is not
@@ -1010,7 +1020,7 @@ xfs_create(
 				resblks, &tp);
 	}
 	if (error)
-		goto out_release_dquots;
+		goto drop_incompat;
 
 	xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
 	unlock_dp_on_error = true;
@@ -1020,6 +1030,7 @@ xfs_create(
 	 * entry pointing to them, but a directory also the "." entry
 	 * pointing to itself.
 	 */
+	init_xattrs = init_xattrs || xfs_has_parent(mp);
 	error = xfs_dialloc(&tp, dp->i_ino, mode, &ino);
 	if (!error)
 		error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode,
@@ -1034,11 +1045,12 @@ xfs_create(
 	 * the transaction cancel unlocking dp so don't do it explicitly in the
 	 * error path.
 	 */
-	xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, dp, 0);
 	unlock_dp_on_error = false;
 
 	error = xfs_dir_createname(tp, dp, name, ip->i_ino,
-				   resblks - XFS_IALLOC_SPACE_RES(mp), NULL);
+				   resblks - XFS_IALLOC_SPACE_RES(mp),
+				   &diroffset);
 	if (error) {
 		ASSERT(error != -ENOSPC);
 		goto out_trans_cancel;
@@ -1054,6 +1066,17 @@ xfs_create(
 		xfs_bumplink(tp, dp);
 	}
 
+	/*
+	 * If we have parent pointers, we need to add the attribute containing
+	 * the parent information now.
+	 */
+	if (parent) {
+		error = xfs_parent_defer_add(tp, parent, dp, name, diroffset,
+					     ip);
+		if (error)
+			goto out_trans_cancel;
+	}
+
 	/*
 	 * If this is a synchronous mount, make sure that the
 	 * create transaction goes to disk before returning to
@@ -1079,6 +1102,7 @@ xfs_create(
 
 	*ipp = ip;
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	xfs_iunlock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
 	return 0;
 
  out_trans_cancel:
@@ -1093,6 +1117,9 @@ xfs_create(
 		xfs_finish_inode_setup(ip);
 		xfs_irele(ip);
 	}
+ drop_incompat:
+	if (parent)
+		xfs_parent_cancel(mp, parent);
  out_release_dquots:
 	xfs_qm_dqrele(udqp);
 	xfs_qm_dqrele(gdqp);
fs/xfs/xfs_xattr.c +1 -1
index c325a28b89a8..d9067c5f6bd6 100644
@@ -27,7 +27,7 @@
  * they must release the permission by calling xlog_drop_incompat_feat
  * when they're done.
  */
-static inline int
+int
 xfs_attr_grab_log_assist(
 	struct xfs_mount	*mp)
 {
fs/xfs/xfs_xattr.h +1 -0
index 2b09133b1b9b..3fd6520a4d69 100644
@@ -7,6 +7,7 @@
 #define __XFS_XATTR_H__
 
 int xfs_attr_change(struct xfs_da_args *args);
+int xfs_attr_grab_log_assist(struct xfs_mount *mp);
 
 extern const struct xattr_handler *xfs_xattr_handlers[];
 
Signature · 1 line
2.25.1
#31 lore raw

Re: [PATCH v3 14/26] xfs: parent pointer attribute creation

Quoted 112 lines · On Wed, Sep 21, 2022 at 10:44:46PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Add parent pointer attribute during xfs_create, and subroutines to initialize attributes

---
 fs/xfs/Makefile            |   1 +
 fs/xfs/libxfs/xfs_attr.c   |   4 +-
 fs/xfs/libxfs/xfs_attr.h   |   4 +-
 fs/xfs/libxfs/xfs_parent.c | 135 +++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  32 +++++++++
 fs/xfs/xfs_inode.c         |  37 ++++++++--
 fs/xfs/xfs_xattr.c         |   2 +-
 fs/xfs/xfs_xattr.h         |   1 +
 8 files changed, 207 insertions(+), 9 deletions(-)
fs/xfs/Makefile +1 -0
index 03135a1c31b6..e2b2cf50ffcf 100644
@@ -40,6 +40,7 @@ xfs-y				+= $(addprefix libxfs/, \
 				   xfs_inode_fork.o \
 				   xfs_inode_buf.o \
 				   xfs_log_rlimit.o \
+				   xfs_parent.o \
 				   xfs_ag_resv.o \
 				   xfs_rmap.o \
 				   xfs_rmap_btree.o \
fs/xfs/libxfs/xfs_attr.c +2 -2
index 0c9589261990..805aaa5639d2 100644
@@ -886,7 +886,7 @@ xfs_attr_lookup(
 	return error;
 }
 
-static int
+int
 xfs_attr_intent_init(
 	struct xfs_da_args	*args,
 	unsigned int		op_flags,	/* op flag (set or remove) */
@@ -904,7 +904,7 @@ xfs_attr_intent_init(
 }
 
 /* Sets an attribute for an inode as a deferred operation */
-static int
+int
 xfs_attr_defer_add(
 	struct xfs_da_args	*args)
 {
fs/xfs/libxfs/xfs_attr.h +3 -1
index b79dae788cfb..0cf23f5117ad 100644
@@ -544,6 +544,7 @@ int xfs_inode_hasattr(struct xfs_inode *ip);
 bool xfs_attr_is_leaf(struct xfs_inode *ip);
 int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
+int xfs_attr_defer_add(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_iter(struct xfs_attr_intent *attr);
 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
@@ -552,7 +553,8 @@ bool xfs_attr_namecheck(struct xfs_mount *mp, const void *name, size_t length,
 int xfs_attr_calc_size(struct xfs_da_args *args, int *local);
 void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
 			 unsigned int *total);
-
+int xfs_attr_intent_init(struct xfs_da_args *args, unsigned int op_flags,
+			 struct xfs_attr_intent  **attr);
 /*
  * Check to see if the attr should be upgraded from non-existent or shortform to
  * single-leaf-block attribute list.
fs/xfs/libxfs/xfs_parent.c new file +32 -0
new file mode 100644
index 000000000000..dddbf096a4b5
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All rights reserved.
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_format.h"
+#include "xfs_da_format.h"
+#include "xfs_log_format.h"
+#include "xfs_shared.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_inode.h"
+#include "xfs_error.h"
+#include "xfs_trace.h"
+#include "xfs_trans.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr_sf.h"
+#include "xfs_bmap.h"
+#include "xfs_defer.h"
+#include "xfs_log.h"
+#include "xfs_xattr.h"
+#include "xfs_parent.h"
+
+/*
+ * Parent pointer attribute handling.
+ *
+ * Because the attribute value is a filename component, it will never be longer

fs/xfs/libxfs/xfs_parent.c line 42

Quoted 10 lines
fs/xfs/libxfs/xfs_parent.c new file +10 -0
+ * than 255 bytes. This means the attribute will always be a local format
+ * attribute as it is xfs_attr_leaf_entsize_local_max() for v5 filesystems will
+ * always be larger than this (max is 75% of block size).
+ *
+ * Creating a new parent attribute will always create a new attribute - there
+ * should never, ever be an existing attribute in the tree for a new inode.
+ * ENOSPC behavior is problematic - creating the inode without the parent
+ * pointer is effectively a corruption, so we allow parent attribute creation
+ * to dip into the reserve block pool to avoid unexpected ENOSPC errors from
+ * occurring.

Hoisting a discussion (that I never replied to; sorry... :( ) from last time around:

Quoted 7 lines
Quoted 5 lines

Shouldn't we increase XFS_LINK_SPACE_RES to avoid this? The reserve pool isn't terribly large (8192 blocks) and was really only supposed to save us from an ENOSPC shutdown if an unwritten extent conversion in the writeback endio handler needs a few more blocks.

Did you maybe mean XFS_IALLOC_SPACE_RES? That looks like the macro that's getting used below in xfs_create

I meant modifying XFS_MKDIR_SPACE_RES and XFS_CREATE_SPACE_RES:

unsigned int
xfs_pptr_calc_space_res(
struct xfs_mount *mp,
unsigned int namelen)
{
/*
* Code lifted from xfs_attr_calc_size, check this for
* correctness since I assumed that a pptr never requires rmt
* blocks...
*/
return XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) +
XFS_NEXTENTADD_SPACE_RES(mp, namelen, XFS_ATTR_FORK);
}

unsigned int
xfs_create_space_res(
struct xfs_mount *mp,
unsigned int namelen)

{
	unsigned int		ret;

	ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, namelen);
	if (xfs_has_parent(mp))
		ret += xfs_pptr_calc_space_res(mp, namelen);

	return ret;
}

unsigned int
xfs_mkdir_space_res(
struct xfs_mount *mp,
unsigned int namelen)

{
	return xfs_create_space_res(mp, namelen);
}

(and then change the function case names as necessary)

Quoted 7 lines
Quoted 2 lines

IOWs, we really ought to ENOSPC at transaction reservation time instead of draining the reserve pool.

It looks like we do that in most cases. I dont actually see rsvd getting set, other than in xfs_attr_set. Which isnt used in parent pointer updating, and should probably be removed. I suspect it's a relic of the pre-larp version of the set. So perhaps the comment is stale and should be removed as well.

The block reservations for create/mkdir/link/unlink all need to be adjusted upwards, which will eliminate the need for the comment.

Quoted 22 lines

+ */

fs/xfs/libxfs/xfs_parent.c new file +21 -0
+
+
+/* Initializes a xfs_parent_name_rec to be stored as an attribute name */
+void
+xfs_init_parent_name_rec(
+	struct xfs_parent_name_rec	*rec,
+	struct xfs_inode		*ip,
+	uint32_t			p_diroffset)
+{
+	xfs_ino_t			p_ino = ip->i_ino;
+	uint32_t			p_gen = VFS_I(ip)->i_generation;
+
+	rec->p_ino = cpu_to_be64(p_ino);
+	rec->p_gen = cpu_to_be32(p_gen);
+	rec->p_diroffset = cpu_to_be32(p_diroffset);
+}
+
+/* Initializes a xfs_parent_name_irec from an xfs_parent_name_rec */
+void
+xfs_init_parent_name_irec(
+	struct xfs_parent_name_irec	*irec,

fs/xfs/libxfs/xfs_parent.c line 74

Quoted 10 lines
fs/xfs/libxfs/xfs_parent.c new file +10 -0
+	struct xfs_parent_name_rec	*rec)
+{
+	irec->p_ino = be64_to_cpu(rec->p_ino);
+	irec->p_gen = be32_to_cpu(rec->p_gen);
+	irec->p_diroffset = be32_to_cpu(rec->p_diroffset);
+}
+
+int
+xfs_parent_init(
+	xfs_mount_t                     *mp,

Nit: typedef usage.

Everything else below here looks good though. :)

--D

Quoted 248 lines
fs/xfs/libxfs/xfs_parent.c new file +61 -0
+	struct xfs_parent_defer		**parentp)
+{
+	struct xfs_parent_defer		*parent;
+	int				error;
+
+	if (!xfs_has_parent(mp))
+		return 0;
+
+	error = xfs_attr_grab_log_assist(mp);
+	if (error)
+		return error;
+
+	parent = kzalloc(sizeof(*parent), GFP_KERNEL);
+	if (!parent)
+		return -ENOMEM;
+
+	/* init parent da_args */
+	parent->args.geo = mp->m_attr_geo;
+	parent->args.whichfork = XFS_ATTR_FORK;
+	parent->args.attr_filter = XFS_ATTR_PARENT;
+	parent->args.op_flags = XFS_DA_OP_OKNOENT | XFS_DA_OP_LOGGED;
+	parent->args.name = (const uint8_t *)&parent->rec;
+	parent->args.namelen = sizeof(struct xfs_parent_name_rec);
+
+	*parentp = parent;
+	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)
+{
+	struct xfs_da_args	*args = &parent->args;
+
+	xfs_init_parent_name_rec(&parent->rec, dp, diroffset);
+	args->hashval = xfs_da_hashname(args->name, args->namelen);
+
+	args->trans = tp;
+	args->dp = child;
+	if (parent_name) {
+		parent->args.value = (void *)parent_name->name;
+		parent->args.valuelen = parent_name->len;
+	}
+
+	return xfs_attr_defer_add(args);
+}
+
+void
+xfs_parent_cancel(
+	xfs_mount_t		*mp,
+	struct xfs_parent_defer *parent)
+{
+	xlog_drop_incompat_feat(mp->m_log);
+	kfree(parent);
+}
+
fs/xfs/libxfs/xfs_parent.h new file +32 -0
new file mode 100644
index 000000000000..971044458f8a
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All Rights Reserved.
+ */
+#ifndef	__XFS_PARENT_H__
+#define	__XFS_PARENT_H__
+
+/*
+ * Dynamically allocd structure used to wrap the needed data to pass around
+ * the defer ops machinery
+ */
+struct xfs_parent_defer {
+	struct xfs_parent_name_rec	rec;
+	struct xfs_da_args		args;
+};
+
+/*
+ * 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(xfs_mount_t *mp, struct xfs_parent_defer **parentp);
+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);
+void xfs_parent_cancel(xfs_mount_t *mp, struct xfs_parent_defer *parent);
+
+#endif	/* __XFS_PARENT_H__ */
fs/xfs/xfs_inode.c +32 -5
index 6eb264598517..181d6417412e 100644
@@ -37,6 +37,8 @@
 #include "xfs_reflink.h"
 #include "xfs_ag.h"
 #include "xfs_log_priv.h"
+#include "xfs_parent.h"
+#include "xfs_xattr.h"
 
 struct kmem_cache *xfs_inode_cache;
 
@@ -949,7 +951,7 @@ xfs_bumplink(
 int
 xfs_create(
 	struct user_namespace	*mnt_userns,
-	xfs_inode_t		*dp,
+	struct xfs_inode	*dp,
 	struct xfs_name		*name,
 	umode_t			mode,
 	dev_t			rdev,
@@ -961,7 +963,7 @@ xfs_create(
 	struct xfs_inode	*ip = NULL;
 	struct xfs_trans	*tp = NULL;
 	int			error;
-	bool                    unlock_dp_on_error = false;
+	bool			unlock_dp_on_error = false;
 	prid_t			prid;
 	struct xfs_dquot	*udqp = NULL;
 	struct xfs_dquot	*gdqp = NULL;
@@ -969,6 +971,8 @@ xfs_create(
 	struct xfs_trans_res	*tres;
 	uint			resblks;
 	xfs_ino_t		ino;
+	xfs_dir2_dataptr_t	diroffset;
+	struct xfs_parent_defer	*parent = NULL;
 
 	trace_xfs_create(dp, name);
 
@@ -995,6 +999,12 @@ xfs_create(
 		tres = &M_RES(mp)->tr_create;
 	}
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &parent);
+		if (error)
+			goto out_release_dquots;
+	}
+
 	/*
 	 * Initially assume that the file does not exist and
 	 * reserve the resources for that case.  If that is not
@@ -1010,7 +1020,7 @@ xfs_create(
 				resblks, &tp);
 	}
 	if (error)
-		goto out_release_dquots;
+		goto drop_incompat;
 
 	xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
 	unlock_dp_on_error = true;
@@ -1020,6 +1030,7 @@ xfs_create(
 	 * entry pointing to them, but a directory also the "." entry
 	 * pointing to itself.
 	 */
+	init_xattrs = init_xattrs || xfs_has_parent(mp);
 	error = xfs_dialloc(&tp, dp->i_ino, mode, &ino);
 	if (!error)
 		error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode,
@@ -1034,11 +1045,12 @@ xfs_create(
 	 * the transaction cancel unlocking dp so don't do it explicitly in the
 	 * error path.
 	 */
-	xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, dp, 0);
 	unlock_dp_on_error = false;
 
 	error = xfs_dir_createname(tp, dp, name, ip->i_ino,
-				   resblks - XFS_IALLOC_SPACE_RES(mp), NULL);
+				   resblks - XFS_IALLOC_SPACE_RES(mp),
+				   &diroffset);
 	if (error) {
 		ASSERT(error != -ENOSPC);
 		goto out_trans_cancel;
@@ -1054,6 +1066,17 @@ xfs_create(
 		xfs_bumplink(tp, dp);
 	}
 
+	/*
+	 * If we have parent pointers, we need to add the attribute containing
+	 * the parent information now.
+	 */
+	if (parent) {
+		error = xfs_parent_defer_add(tp, parent, dp, name, diroffset,
+					     ip);
+		if (error)
+			goto out_trans_cancel;
+	}
+
 	/*
 	 * If this is a synchronous mount, make sure that the
 	 * create transaction goes to disk before returning to
@@ -1079,6 +1102,7 @@ xfs_create(
 
 	*ipp = ip;
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	xfs_iunlock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
 	return 0;
 
  out_trans_cancel:
@@ -1093,6 +1117,9 @@ xfs_create(
 		xfs_finish_inode_setup(ip);
 		xfs_irele(ip);
 	}
+ drop_incompat:
+	if (parent)
+		xfs_parent_cancel(mp, parent);
  out_release_dquots:
 	xfs_qm_dqrele(udqp);
 	xfs_qm_dqrele(gdqp);
fs/xfs/xfs_xattr.c +1 -1
index c325a28b89a8..d9067c5f6bd6 100644
@@ -27,7 +27,7 @@
  * they must release the permission by calling xlog_drop_incompat_feat
  * when they're done.
  */
-static inline int
+int
 xfs_attr_grab_log_assist(
 	struct xfs_mount	*mp)
 {
fs/xfs/xfs_xattr.h +1 -0
index 2b09133b1b9b..3fd6520a4d69 100644
@@ -7,6 +7,7 @@
 #define __XFS_XATTR_H__
 
 int xfs_attr_change(struct xfs_da_args *args);
+int xfs_attr_grab_log_assist(struct xfs_mount *mp);
 
 extern const struct xattr_handler *xfs_xattr_handlers[];
 
Signature · 1 line
2.25.1
#32 lore raw

Re: [PATCH v3 14/26] xfs: parent pointer attribute creation

Quoted 195 lines · Darrick J. Wong
Quoted 130 lines · On Wed, Sep 21, 2022 at 10:44:46PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Add parent pointer attribute during xfs_create, and subroutines to initialize attributes

---
 fs/xfs/Makefile            |   1 +
 fs/xfs/libxfs/xfs_attr.c   |   4 +-
 fs/xfs/libxfs/xfs_attr.h   |   4 +-
 fs/xfs/libxfs/xfs_parent.c | 135
+++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  32 +++++++++

 fs/xfs/xfs_inode.c         |  37 ++++++++--
 fs/xfs/xfs_xattr.c         |   2 +-
 fs/xfs/xfs_xattr.h         |   1 +
 8 files changed, 207 insertions(+), 9 deletions(-)
fs/xfs/Makefile +1 -0
index 03135a1c31b6..e2b2cf50ffcf 100644
@@ -40,6 +40,7 @@ xfs-y                         += $(addprefix
 libxfs/, \
                                    xfs_inode_fork.o \
                                    xfs_inode_buf.o \
                                    xfs_log_rlimit.o \
+                                  xfs_parent.o \
                                    xfs_ag_resv.o \
                                    xfs_rmap.o \

                                   xfs_rmap_btree.o \

fs/xfs/libxfs/xfs_attr.c +0 -0
index 0c9589261990..805aaa5639d2 100644
@@ -886,7 +886,7 @@ xfs_attr_lookup(
         return error;
  }

fs/xfs/libxfs/xfs_attr.c +1 -1
-static int
+int

 xfs_attr_intent_init(
        struct xfs_da_args      *args,
        unsigned int            op_flags,       /* op flag (set or remove) */

fs/xfs/libxfs/xfs_attr.c +0 -0
@@ -904,7 +904,7 @@ xfs_attr_intent_init(
  }


 /* Sets an attribute for an inode as a deferred operation */

fs/xfs/libxfs/xfs_attr.c +1 -1
-static int
+int

 xfs_attr_defer_add(
        struct xfs_da_args      *args)
 {

fs/xfs/libxfs/xfs_attr.h +1 -0
index b79dae788cfb..0cf23f5117ad 100644
@@ -544,6 +544,7 @@ int xfs_inode_hasattr(struct xfs_inode *ip);
  bool xfs_attr_is_leaf(struct xfs_inode *ip);
  int xfs_attr_get_ilocked(struct xfs_da_args *args);
  int xfs_attr_get(struct xfs_da_args *args);
+int xfs_attr_defer_add(struct xfs_da_args *args);
  int xfs_attr_set(struct xfs_da_args *args);
  int xfs_attr_set_iter(struct xfs_attr_intent *attr);
  int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
@@ -552,7 +553,8 @@ bool xfs_attr_namecheck(struct xfs_mount *mp,
 const void *name, size_t length,
  int xfs_attr_calc_size(struct xfs_da_args *args, int *local);

 void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
                         unsigned int *total);

fs/xfs/libxfs/xfs_attr.h +1 -1
-
+int xfs_attr_intent_init(struct xfs_da_args *args, unsigned int

op_flags,
+                        struct xfs_attr_intent  **attr); /*
  * Check to see if the attr should be upgraded from non-existent or shortform to
  * single-leaf-block attribute list.

fs/xfs/libxfs/xfs_parent.c new file +32 -0
new file mode 100644
index 000000000000..dddbf096a4b5
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All rights reserved.
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_format.h"
+#include "xfs_da_format.h"
+#include "xfs_log_format.h"
+#include "xfs_shared.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_inode.h"
+#include "xfs_error.h"
+#include "xfs_trace.h"
+#include "xfs_trans.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr_sf.h"
+#include "xfs_bmap.h"
+#include "xfs_defer.h"
+#include "xfs_log.h"
+#include "xfs_xattr.h"
+#include "xfs_parent.h"
+
+/*
+ * Parent pointer attribute handling.
+ *
+ * Because the attribute value is a filename component, it will

never be longer
+ * than 255 bytes. This means the attribute will always be a local format
+ * attribute as it is xfs_attr_leaf_entsize_local_max() for v5 filesystems will
+ * always be larger than this (max is 75% of block size).
+ *
+ * Creating a new parent attribute will always create a new attribute - there
+ * should never, ever be an existing attribute in the tree for a

Quoted 8 lines

new inode.
+ * ENOSPC behavior is problematic - creating the inode without the parent
+ * pointer is effectively a corruption, so we allow parent attribute creation
+ * to dip into the reserve block pool to avoid unexpected ENOSPC errors from
+ * occurring.

Hoisting a discussion (that I never replied to; sorry... :( ) from last
time around:

Quoted 10 lines
Quoted 8 lines

Shouldn't we increase XFS_LINK_SPACE_RES to avoid this?  The reserve
pool isn't terribly large (8192 blocks) and was really only supposed
to save us from an ENOSPC shutdown if an unwritten extent conversion
in the writeback endio handler needs a few more blocks.

Did you maybe mean XFS_IALLOC_SPACE_RES?  That looks like the macro that's getting used below in xfs_create

I meant modifying XFS_MKDIR_SPACE_RES and XFS_CREATE_SPACE_RES:

unsigned int
xfs_pptr_calc_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        /*
         * Code lifted from xfs_attr_calc_size, check this for
         * correctness since I assumed that a pptr never requires rmt
         * blocks...
         */
        return XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_NEXTENTADD_SPACE_RES(mp, namelen, XFS_ATTR_FORK); }

unsigned int
xfs_create_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        unsigned int            ret;

        ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, namelen);
        if (xfs_has_parent(mp))
                ret += xfs_pptr_calc_space_res(mp, namelen);

        return ret;
}

unsigned int
xfs_mkdir_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        return xfs_create_space_res(mp, namelen);
}

Quoted 2 lines

(and then change the function case names as necessary)

Oooh ok... So you're saying you want wrappers to XFS_IALLOC_SPACE_RES, right? Do you want these helpers corralled in a common area, or do you just want them to be static in the same file where they are used?

Quoted 40 lines
Quoted 7 lines
Quoted 2 lines

IOWs, we really ought to ENOSPC at transaction reservation time instead of draining the reserve pool.

It looks like we do that in most cases.  I dont actually see rsvd getting set, other than in xfs_attr_set.  Which isnt used in parent pointer updating, and should probably be removed.  I suspect it's a relic of the pre-larp version of the set. So perhaps the comment is stale and should be removed as well.

The block reservations for create/mkdir/link/unlink all need to be adjusted upwards, which will eliminate the need for the comment.

Quoted 29 lines

+ */

fs/xfs/libxfs/xfs_parent.c new file +3 -0
+
+
+/* Initializes a xfs_parent_name_rec to be stored as an attribute

name */

fs/xfs/libxfs/xfs_parent.c new file +8 -0
+void
+xfs_init_parent_name_rec(
+       struct xfs_parent_name_rec      *rec,
+       struct xfs_inode                *ip,
+       uint32_t                        p_diroffset)
+{
+       xfs_ino_t                       p_ino = ip->i_ino;
+       uint32_t                        p_gen = VFS_I(ip)-
Quoted 1 line

i_generation;

fs/xfs/libxfs/xfs_parent.c new file +7 -0
+
+       rec->p_ino = cpu_to_be64(p_ino);
+       rec->p_gen = cpu_to_be32(p_gen);
+       rec->p_diroffset = cpu_to_be32(p_diroffset);
+}
+
+/* Initializes a xfs_parent_name_irec from an xfs_parent_name_rec

*/

fs/xfs/libxfs/xfs_parent.c new file +7 -0
+void
+xfs_init_parent_name_irec(
+       struct xfs_parent_name_irec     *irec,
+       struct xfs_parent_name_rec      *rec)
+{
+       irec->p_ino = be64_to_cpu(rec->p_ino);
+       irec->p_gen = be32_to_cpu(rec->p_gen);
Quoted 8 lines

fs/xfs/libxfs/xfs_parent.c line 74

Quoted 6 lines

+       irec->p_diroffset = be32_to_cpu(rec->p_diroffset);

fs/xfs/libxfs/xfs_parent.c new file +5 -0
+}
+
+int
+xfs_parent_init(
+       xfs_mount_t                     *mp,

Nit: typedef usage.

Will fix

Quoted 3 lines

Everything else below here looks good though. :)

Thanks for the reviews!

Allison

Quoted 266 lines

--D

Quoted 264 lines

+       struct xfs_parent_defer         **parentp)

fs/xfs/libxfs/xfs_parent.c new file +20 -0
+{
+       struct xfs_parent_defer         *parent;
+       int                             error;
+
+       if (!xfs_has_parent(mp))
+               return 0;
+
+       error = xfs_attr_grab_log_assist(mp);
+       if (error)
+               return error;
+
+       parent = kzalloc(sizeof(*parent), GFP_KERNEL);
+       if (!parent)
+               return -ENOMEM;
+
+       /* init parent da_args */
+       parent->args.geo = mp->m_attr_geo;
+       parent->args.whichfork = XFS_ATTR_FORK;
+       parent->args.attr_filter = XFS_ATTR_PARENT;
+       parent->args.op_flags = XFS_DA_OP_OKNOENT |

XFS_DA_OP_LOGGED;
+       parent->args.name = (const uint8_t *)&parent->rec; +       parent->args.namelen = sizeof(struct xfs_parent_name_rec);

fs/xfs/libxfs/xfs_parent.c new file +38 -0
+
+       *parentp = parent;
+       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)
+{
+       struct xfs_da_args      *args = &parent->args;
+
+       xfs_init_parent_name_rec(&parent->rec, dp, diroffset);
+       args->hashval = xfs_da_hashname(args->name, args->namelen);
+
+       args->trans = tp;
+       args->dp = child;
+       if (parent_name) {
+               parent->args.value = (void *)parent_name->name;
+               parent->args.valuelen = parent_name->len;
+       }
+
+       return xfs_attr_defer_add(args);
+}
+
+void
+xfs_parent_cancel(
+       xfs_mount_t             *mp,
+       struct xfs_parent_defer *parent)
+{
+       xlog_drop_incompat_feat(mp->m_log);
+       kfree(parent);
+}
+
fs/xfs/libxfs/xfs_parent.h new file +10 -0
new file mode 100644
index 000000000000..971044458f8a
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All Rights Reserved.
+ */
+#ifndef        __XFS_PARENT_H__
+#define        __XFS_PARENT_H__
+
+/*
+ * Dynamically allocd structure used to wrap the needed data to

pass around
+ * the defer ops machinery
+ */

fs/xfs/libxfs/xfs_parent.h new file +14 -0
+struct xfs_parent_defer {
+       struct xfs_parent_name_rec      rec;
+       struct xfs_da_args              args;
+};
+
+/*
+ * 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(xfs_mount_t *mp, struct xfs_parent_defer

**parentp);
+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);
+void xfs_parent_cancel(xfs_mount_t *mp, struct xfs_parent_defer *parent);

fs/xfs/libxfs/xfs_parent.h new file +2 -0
+
+#endif /* __XFS_PARENT_H__ */
fs/xfs/xfs_inode.c +2 -0
index 6eb264598517..181d6417412e 100644
@@ -37,6 +37,8 @@
  #include "xfs_reflink.h"
  #include "xfs_ag.h"
  #include "xfs_log_priv.h"
+#include "xfs_parent.h"
+#include "xfs_xattr.h"


 struct kmem_cache *xfs_inode_cache;

fs/xfs/xfs_inode.c +0 -0
@@ -949,7 +951,7 @@ xfs_bumplink(

 int
 xfs_create(
        struct user_namespace   *mnt_userns,
-       xfs_inode_t             *dp,
+       struct xfs_inode        *dp,
        struct xfs_name         *name,
        umode_t                 mode,
        dev_t                   rdev,

fs/xfs/xfs_inode.c +3 -1
@@ -961,7 +963,7 @@ xfs_create(
         struct xfs_inode        *ip = NULL;
         struct xfs_trans        *tp = NULL;
         int                     error;
-       bool                    unlock_dp_on_error = false;
+       bool                    unlock_dp_on_error = false;
         prid_t                  prid;
         struct xfs_dquot        *udqp = NULL;
         struct xfs_dquot        *gdqp = NULL;
@@ -969,6 +971,8 @@ xfs_create(
         struct xfs_trans_res    *tres;
         uint                    resblks;
         xfs_ino_t               ino;
+       xfs_dir2_dataptr_t      diroffset;
+       struct xfs_parent_defer *parent = NULL;


        trace_xfs_create(dp, name);

fs/xfs/xfs_inode.c +0 -0
@@ -995,6 +999,12 @@ xfs_create(
                 tres = &M_RES(mp)->tr_create;
         }


+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &parent); +               if (error)
+                       goto out_release_dquots;
+       }
+
        /*
         * Initially assume that the file does not exist and
         * reserve the resources for that case.  If that is not

fs/xfs/xfs_inode.c +1 -1
@@ -1010,7 +1020,7 @@ xfs_create(
                                 resblks, &tp);
         }
         if (error)
-               goto out_release_dquots;
+               goto drop_incompat;


        xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); unlock_dp_on_error = true;

fs/xfs/xfs_inode.c +0 -0
@@ -1020,6 +1030,7 @@ xfs_create(
          * entry pointing to them, but a directory also the "."

entry
         * pointing to itself.
         */
+       init_xattrs = init_xattrs || xfs_has_parent(mp); error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); if (!error)
                error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode,

fs/xfs/xfs_inode.c +0 -0
@@ -1034,11 +1045,12 @@ xfs_create(
          * the transaction cancel unlocking dp so don't do it

explicitly in the
         * error path.
         */
-       xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, dp, 0); unlock_dp_on_error = false;

        error = xfs_dir_createname(tp, dp, name, ip->i_ino, -                                  resblks - XFS_IALLOC_SPACE_RES(mp), NULL);
+                                  resblks - XFS_IALLOC_SPACE_RES(mp),
+                                  &diroffset);
        if (error) {
                ASSERT(error != -ENOSPC);
                goto out_trans_cancel;

fs/xfs/xfs_inode.c +0 -0
@@ -1054,6 +1066,17 @@ xfs_create(
                 xfs_bumplink(tp, dp);
         }


+       /*
+        * If we have parent pointers, we need to add the attribute containing
+        * the parent information now.
+        */
+       if (parent) {
+               error = xfs_parent_defer_add(tp, parent, dp, name, diroffset,
+                                            ip);
+               if (error)
+                       goto out_trans_cancel;
+       }
+
        /*
         * If this is a synchronous mount, make sure that the
         * create transaction goes to disk before returning to

fs/xfs/xfs_inode.c +0 -0
@@ -1079,6 +1102,7 @@ xfs_create(


        *ipp = ip;
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
+       xfs_iunlock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); return 0;

  out_trans_cancel:

fs/xfs/xfs_inode.c +3 -0
@@ -1093,6 +1117,9 @@ xfs_create(
                 xfs_finish_inode_setup(ip);
                 xfs_irele(ip);
         }
+ drop_incompat:
+       if (parent)
+               xfs_parent_cancel(mp, parent);

  out_release_dquots:
        xfs_qm_dqrele(udqp);
        xfs_qm_dqrele(gdqp);

fs/xfs/xfs_xattr.c +0 -0
index c325a28b89a8..d9067c5f6bd6 100644
@@ -27,7 +27,7 @@
   * they must release the permission by calling

xlog_drop_incompat_feat
  * when they're done.
  */

fs/xfs/xfs_xattr.c +1 -1
-static inline int
+int

 xfs_attr_grab_log_assist(
        struct xfs_mount        *mp)
 {

fs/xfs/xfs_xattr.h +0 -0
index 2b09133b1b9b..3fd6520a4d69 100644
@@ -7,6 +7,7 @@
  #define __XFS_XATTR_H__


 int xfs_attr_change(struct xfs_da_args *args); +int xfs_attr_grab_log_assist(struct xfs_mount *mp);
 extern const struct xattr_handler *xfs_xattr_handlers[];

Signature · 1 line
2.25.1
#33 lore raw

Re: [PATCH v3 14/26] xfs: parent pointer attribute creation

Quoted 196 lines · Allison Henderson
Quoted 195 lines · Darrick J. Wong
Quoted 130 lines · On Wed, Sep 21, 2022 at 10:44:46PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Add parent pointer attribute during xfs_create, and subroutines to initialize attributes

---
 fs/xfs/Makefile            |   1 +
 fs/xfs/libxfs/xfs_attr.c   |   4 +-
 fs/xfs/libxfs/xfs_attr.h   |   4 +-
 fs/xfs/libxfs/xfs_parent.c | 135
+++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  32 +++++++++

 fs/xfs/xfs_inode.c         |  37 ++++++++--
 fs/xfs/xfs_xattr.c         |   2 +-
 fs/xfs/xfs_xattr.h         |   1 +
 8 files changed, 207 insertions(+), 9 deletions(-)
fs/xfs/Makefile +1 -0
index 03135a1c31b6..e2b2cf50ffcf 100644
@@ -40,6 +40,7 @@ xfs-y                         += $(addprefix
 libxfs/, \
                                    xfs_inode_fork.o \
                                    xfs_inode_buf.o \
                                    xfs_log_rlimit.o \
+                                  xfs_parent.o \
                                    xfs_ag_resv.o \
                                    xfs_rmap.o \

                                   xfs_rmap_btree.o \

fs/xfs/libxfs/xfs_attr.c +0 -0
index 0c9589261990..805aaa5639d2 100644
@@ -886,7 +886,7 @@ xfs_attr_lookup(
         return error;
  }

fs/xfs/libxfs/xfs_attr.c +1 -1
-static int
+int

 xfs_attr_intent_init(
        struct xfs_da_args      *args,
        unsigned int            op_flags,       /* op flag (set or remove) */

fs/xfs/libxfs/xfs_attr.c +0 -0
@@ -904,7 +904,7 @@ xfs_attr_intent_init(
  }


 /* Sets an attribute for an inode as a deferred operation */

fs/xfs/libxfs/xfs_attr.c +1 -1
-static int
+int

 xfs_attr_defer_add(
        struct xfs_da_args      *args)
 {

fs/xfs/libxfs/xfs_attr.h +1 -0
index b79dae788cfb..0cf23f5117ad 100644
@@ -544,6 +544,7 @@ int xfs_inode_hasattr(struct xfs_inode *ip);
  bool xfs_attr_is_leaf(struct xfs_inode *ip);
  int xfs_attr_get_ilocked(struct xfs_da_args *args);
  int xfs_attr_get(struct xfs_da_args *args);
+int xfs_attr_defer_add(struct xfs_da_args *args);
  int xfs_attr_set(struct xfs_da_args *args);
  int xfs_attr_set_iter(struct xfs_attr_intent *attr);
  int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
@@ -552,7 +553,8 @@ bool xfs_attr_namecheck(struct xfs_mount *mp,
 const void *name, size_t length,
  int xfs_attr_calc_size(struct xfs_da_args *args, int *local);

 void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
                         unsigned int *total);

fs/xfs/libxfs/xfs_attr.h +1 -1
-
+int xfs_attr_intent_init(struct xfs_da_args *args, unsigned int

op_flags,
+                        struct xfs_attr_intent  **attr); /*
  * Check to see if the attr should be upgraded from non-existent or shortform to
  * single-leaf-block attribute list.

fs/xfs/libxfs/xfs_parent.c new file +32 -0
new file mode 100644
index 000000000000..dddbf096a4b5
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All rights reserved.
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_format.h"
+#include "xfs_da_format.h"
+#include "xfs_log_format.h"
+#include "xfs_shared.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_inode.h"
+#include "xfs_error.h"
+#include "xfs_trace.h"
+#include "xfs_trans.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr_sf.h"
+#include "xfs_bmap.h"
+#include "xfs_defer.h"
+#include "xfs_log.h"
+#include "xfs_xattr.h"
+#include "xfs_parent.h"
+
+/*
+ * Parent pointer attribute handling.
+ *
+ * Because the attribute value is a filename component, it will

never be longer
+ * than 255 bytes. This means the attribute will always be a local format
+ * attribute as it is xfs_attr_leaf_entsize_local_max() for v5 filesystems will
+ * always be larger than this (max is 75% of block size).
+ *
+ * Creating a new parent attribute will always create a new attribute - there
+ * should never, ever be an existing attribute in the tree for a

Quoted 8 lines

new inode.
+ * ENOSPC behavior is problematic - creating the inode without the parent
+ * pointer is effectively a corruption, so we allow parent attribute creation
+ * to dip into the reserve block pool to avoid unexpected ENOSPC errors from
+ * occurring.

Hoisting a discussion (that I never replied to; sorry... :( ) from last
time around:

Quoted 10 lines
Quoted 8 lines

Shouldn't we increase XFS_LINK_SPACE_RES to avoid this?  The reserve
pool isn't terribly large (8192 blocks) and was really only supposed
to save us from an ENOSPC shutdown if an unwritten extent conversion
in the writeback endio handler needs a few more blocks.

Did you maybe mean XFS_IALLOC_SPACE_RES?  That looks like the macro that's getting used below in xfs_create

I meant modifying XFS_MKDIR_SPACE_RES and XFS_CREATE_SPACE_RES:

unsigned int
xfs_pptr_calc_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        /*
         * Code lifted from xfs_attr_calc_size, check this for
         * correctness since I assumed that a pptr never requires rmt
         * blocks...
         */
        return XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_NEXTENTADD_SPACE_RES(mp, namelen, XFS_ATTR_FORK); }

unsigned int
xfs_create_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        unsigned int            ret;

        ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, namelen);
        if (xfs_has_parent(mp))
                ret += xfs_pptr_calc_space_res(mp, namelen);

        return ret;
}

unsigned int
xfs_mkdir_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        return xfs_create_space_res(mp, namelen);
}

Quoted 5 lines
Quoted 2 lines

(and then change the function case names as necessary)

Oooh ok... So you're saying you want wrappers to XFS_IALLOC_SPACE_RES, right? Do you want these helpers corralled in a common area, or do you just want them to be static in the same file where they are used?

Ideally the same place as the macros are #define'd now (as static inline functions), though if that generates a ton of gcc errors then it might be time to create an xfs_trans_space.c.

--D

Quoted 322 lines
Quoted 40 lines
Quoted 7 lines
Quoted 2 lines

IOWs, we really ought to ENOSPC at transaction reservation time instead of draining the reserve pool.

It looks like we do that in most cases.  I dont actually see rsvd getting set, other than in xfs_attr_set.  Which isnt used in parent pointer updating, and should probably be removed.  I suspect it's a relic of the pre-larp version of the set. So perhaps the comment is stale and should be removed as well.

The block reservations for create/mkdir/link/unlink all need to be adjusted upwards, which will eliminate the need for the comment.

Quoted 29 lines

+ */

fs/xfs/libxfs/xfs_parent.c new file +3 -0
+
+
+/* Initializes a xfs_parent_name_rec to be stored as an attribute

name */

fs/xfs/libxfs/xfs_parent.c new file +8 -0
+void
+xfs_init_parent_name_rec(
+       struct xfs_parent_name_rec      *rec,
+       struct xfs_inode                *ip,
+       uint32_t                        p_diroffset)
+{
+       xfs_ino_t                       p_ino = ip->i_ino;
+       uint32_t                        p_gen = VFS_I(ip)-
Quoted 1 line

i_generation;

fs/xfs/libxfs/xfs_parent.c new file +7 -0
+
+       rec->p_ino = cpu_to_be64(p_ino);
+       rec->p_gen = cpu_to_be32(p_gen);
+       rec->p_diroffset = cpu_to_be32(p_diroffset);
+}
+
+/* Initializes a xfs_parent_name_irec from an xfs_parent_name_rec

*/

fs/xfs/libxfs/xfs_parent.c new file +7 -0
+void
+xfs_init_parent_name_irec(
+       struct xfs_parent_name_irec     *irec,
+       struct xfs_parent_name_rec      *rec)
+{
+       irec->p_ino = be64_to_cpu(rec->p_ino);
+       irec->p_gen = be32_to_cpu(rec->p_gen);
Quoted 8 lines

fs/xfs/libxfs/xfs_parent.c line 74

Quoted 6 lines

+       irec->p_diroffset = be32_to_cpu(rec->p_diroffset);

fs/xfs/libxfs/xfs_parent.c new file +5 -0
+}
+
+int
+xfs_parent_init(
+       xfs_mount_t                     *mp,

Nit: typedef usage.

Will fix

Quoted 3 lines

Everything else below here looks good though. :)

Thanks for the reviews!

Allison

Quoted 266 lines

--D

Quoted 264 lines

+       struct xfs_parent_defer         **parentp)

fs/xfs/libxfs/xfs_parent.c new file +20 -0
+{
+       struct xfs_parent_defer         *parent;
+       int                             error;
+
+       if (!xfs_has_parent(mp))
+               return 0;
+
+       error = xfs_attr_grab_log_assist(mp);
+       if (error)
+               return error;
+
+       parent = kzalloc(sizeof(*parent), GFP_KERNEL);
+       if (!parent)
+               return -ENOMEM;
+
+       /* init parent da_args */
+       parent->args.geo = mp->m_attr_geo;
+       parent->args.whichfork = XFS_ATTR_FORK;
+       parent->args.attr_filter = XFS_ATTR_PARENT;
+       parent->args.op_flags = XFS_DA_OP_OKNOENT |

XFS_DA_OP_LOGGED;
+       parent->args.name = (const uint8_t *)&parent->rec; +       parent->args.namelen = sizeof(struct xfs_parent_name_rec);

fs/xfs/libxfs/xfs_parent.c new file +38 -0
+
+       *parentp = parent;
+       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)
+{
+       struct xfs_da_args      *args = &parent->args;
+
+       xfs_init_parent_name_rec(&parent->rec, dp, diroffset);
+       args->hashval = xfs_da_hashname(args->name, args->namelen);
+
+       args->trans = tp;
+       args->dp = child;
+       if (parent_name) {
+               parent->args.value = (void *)parent_name->name;
+               parent->args.valuelen = parent_name->len;
+       }
+
+       return xfs_attr_defer_add(args);
+}
+
+void
+xfs_parent_cancel(
+       xfs_mount_t             *mp,
+       struct xfs_parent_defer *parent)
+{
+       xlog_drop_incompat_feat(mp->m_log);
+       kfree(parent);
+}
+
fs/xfs/libxfs/xfs_parent.h new file +10 -0
new file mode 100644
index 000000000000..971044458f8a
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All Rights Reserved.
+ */
+#ifndef        __XFS_PARENT_H__
+#define        __XFS_PARENT_H__
+
+/*
+ * Dynamically allocd structure used to wrap the needed data to

pass around
+ * the defer ops machinery
+ */

fs/xfs/libxfs/xfs_parent.h new file +14 -0
+struct xfs_parent_defer {
+       struct xfs_parent_name_rec      rec;
+       struct xfs_da_args              args;
+};
+
+/*
+ * 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(xfs_mount_t *mp, struct xfs_parent_defer

**parentp);
+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);
+void xfs_parent_cancel(xfs_mount_t *mp, struct xfs_parent_defer *parent);

fs/xfs/libxfs/xfs_parent.h new file +2 -0
+
+#endif /* __XFS_PARENT_H__ */
fs/xfs/xfs_inode.c +2 -0
index 6eb264598517..181d6417412e 100644
@@ -37,6 +37,8 @@
  #include "xfs_reflink.h"
  #include "xfs_ag.h"
  #include "xfs_log_priv.h"
+#include "xfs_parent.h"
+#include "xfs_xattr.h"


 struct kmem_cache *xfs_inode_cache;

fs/xfs/xfs_inode.c +0 -0
@@ -949,7 +951,7 @@ xfs_bumplink(

 int
 xfs_create(
        struct user_namespace   *mnt_userns,
-       xfs_inode_t             *dp,
+       struct xfs_inode        *dp,
        struct xfs_name         *name,
        umode_t                 mode,
        dev_t                   rdev,

fs/xfs/xfs_inode.c +3 -1
@@ -961,7 +963,7 @@ xfs_create(
         struct xfs_inode        *ip = NULL;
         struct xfs_trans        *tp = NULL;
         int                     error;
-       bool                    unlock_dp_on_error = false;
+       bool                    unlock_dp_on_error = false;
         prid_t                  prid;
         struct xfs_dquot        *udqp = NULL;
         struct xfs_dquot        *gdqp = NULL;
@@ -969,6 +971,8 @@ xfs_create(
         struct xfs_trans_res    *tres;
         uint                    resblks;
         xfs_ino_t               ino;
+       xfs_dir2_dataptr_t      diroffset;
+       struct xfs_parent_defer *parent = NULL;


        trace_xfs_create(dp, name);

fs/xfs/xfs_inode.c +0 -0
@@ -995,6 +999,12 @@ xfs_create(
                 tres = &M_RES(mp)->tr_create;
         }


+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &parent); +               if (error)
+                       goto out_release_dquots;
+       }
+
        /*
         * Initially assume that the file does not exist and
         * reserve the resources for that case.  If that is not

fs/xfs/xfs_inode.c +1 -1
@@ -1010,7 +1020,7 @@ xfs_create(
                                 resblks, &tp);
         }
         if (error)
-               goto out_release_dquots;
+               goto drop_incompat;


        xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); unlock_dp_on_error = true;

fs/xfs/xfs_inode.c +0 -0
@@ -1020,6 +1030,7 @@ xfs_create(
          * entry pointing to them, but a directory also the "."

entry
         * pointing to itself.
         */
+       init_xattrs = init_xattrs || xfs_has_parent(mp); error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); if (!error)
                error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode,

fs/xfs/xfs_inode.c +0 -0
@@ -1034,11 +1045,12 @@ xfs_create(
          * the transaction cancel unlocking dp so don't do it

explicitly in the
         * error path.
         */
-       xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, dp, 0); unlock_dp_on_error = false;

        error = xfs_dir_createname(tp, dp, name, ip->i_ino, -                                  resblks - XFS_IALLOC_SPACE_RES(mp), NULL);
+                                  resblks - XFS_IALLOC_SPACE_RES(mp),
+                                  &diroffset);
        if (error) {
                ASSERT(error != -ENOSPC);
                goto out_trans_cancel;

fs/xfs/xfs_inode.c +0 -0
@@ -1054,6 +1066,17 @@ xfs_create(
                 xfs_bumplink(tp, dp);
         }


+       /*
+        * If we have parent pointers, we need to add the attribute containing
+        * the parent information now.
+        */
+       if (parent) {
+               error = xfs_parent_defer_add(tp, parent, dp, name, diroffset,
+                                            ip);
+               if (error)
+                       goto out_trans_cancel;
+       }
+
        /*
         * If this is a synchronous mount, make sure that the
         * create transaction goes to disk before returning to

fs/xfs/xfs_inode.c +0 -0
@@ -1079,6 +1102,7 @@ xfs_create(


        *ipp = ip;
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
+       xfs_iunlock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); return 0;

  out_trans_cancel:

fs/xfs/xfs_inode.c +3 -0
@@ -1093,6 +1117,9 @@ xfs_create(
                 xfs_finish_inode_setup(ip);
                 xfs_irele(ip);
         }
+ drop_incompat:
+       if (parent)
+               xfs_parent_cancel(mp, parent);

  out_release_dquots:
        xfs_qm_dqrele(udqp);
        xfs_qm_dqrele(gdqp);

fs/xfs/xfs_xattr.c +0 -0
index c325a28b89a8..d9067c5f6bd6 100644
@@ -27,7 +27,7 @@
   * they must release the permission by calling

xlog_drop_incompat_feat
  * when they're done.
  */

fs/xfs/xfs_xattr.c +1 -1
-static inline int
+int

 xfs_attr_grab_log_assist(
        struct xfs_mount        *mp)
 {

fs/xfs/xfs_xattr.h +0 -0
index 2b09133b1b9b..3fd6520a4d69 100644
@@ -7,6 +7,7 @@
  #define __XFS_XATTR_H__


 int xfs_attr_change(struct xfs_da_args *args); +int xfs_attr_grab_log_assist(struct xfs_mount *mp);
 extern const struct xattr_handler *xfs_xattr_handlers[];

Signature · 1 line
2.25.1
#34 lore raw

Re: [PATCH v3 14/26] xfs: parent pointer attribute creation

Quoted 223 lines · Darrick J. Wong
Quoted 214 lines · Allison Henderson
Quoted 213 lines · Darrick J. Wong
Quoted 143 lines · On Wed, Sep 21, 2022 at 10:44:46PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Add parent pointer attribute during xfs_create, and subroutines to
initialize attributes

---
 fs/xfs/Makefile            |   1 +
 fs/xfs/libxfs/xfs_attr.c   |   4 +-
 fs/xfs/libxfs/xfs_attr.h   |   4 +-
 fs/xfs/libxfs/xfs_parent.c | 135
+++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  32 +++++++++

 fs/xfs/xfs_inode.c         |  37 ++++++++--
 fs/xfs/xfs_xattr.c         |   2 +-
 fs/xfs/xfs_xattr.h         |   1 +
 8 files changed, 207 insertions(+), 9 deletions(-)
fs/xfs/Makefile +1 -0
index 03135a1c31b6..e2b2cf50ffcf 100644
@@ -40,6 +40,7 @@ xfs-y                         += $(addprefix
 libxfs/, \
                                    xfs_inode_fork.o \
                                    xfs_inode_buf.o \
                                    xfs_log_rlimit.o \
+                                  xfs_parent.o \
                                    xfs_ag_resv.o \
                                    xfs_rmap.o \

                                   xfs_rmap_btree.o \

fs/xfs/libxfs/xfs_attr.c +0 -0
index 0c9589261990..805aaa5639d2 100644
@@ -886,7 +886,7 @@ xfs_attr_lookup(
         return error;
  }

fs/xfs/libxfs/xfs_attr.c +1 -1
-static int
+int

 xfs_attr_intent_init(
        struct xfs_da_args      *args,
        unsigned int            op_flags,       /* op flag (set or
remove) */

fs/xfs/libxfs/xfs_attr.c +0 -0
@@ -904,7 +904,7 @@ xfs_attr_intent_init(
  }


 /* Sets an attribute for an inode as a deferred operation */

fs/xfs/libxfs/xfs_attr.c +1 -1
-static int
+int

 xfs_attr_defer_add(
        struct xfs_da_args      *args)
 {

fs/xfs/libxfs/xfs_attr.h +1 -0
index b79dae788cfb..0cf23f5117ad 100644
@@ -544,6 +544,7 @@ int xfs_inode_hasattr(struct xfs_inode
 *ip);
  bool xfs_attr_is_leaf(struct xfs_inode *ip);
  int xfs_attr_get_ilocked(struct xfs_da_args *args);
  int xfs_attr_get(struct xfs_da_args *args);
+int xfs_attr_defer_add(struct xfs_da_args *args);
  int xfs_attr_set(struct xfs_da_args *args);
  int xfs_attr_set_iter(struct xfs_attr_intent *attr);

 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);

fs/xfs/libxfs/xfs_attr.h +0 -0
@@ -552,7 +553,8 @@ bool xfs_attr_namecheck(struct xfs_mount
 *mp,
 const void *name, size_t length,
  int xfs_attr_calc_size(struct xfs_da_args *args, int *local);

 void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
                         unsigned int *total);

fs/xfs/libxfs/xfs_attr.h +1 -1
-
+int xfs_attr_intent_init(struct xfs_da_args *args, unsigned

int
op_flags,
+                        struct xfs_attr_intent  **attr); /*
  * Check to see if the attr should be upgraded from non- existent
or shortform to
  * single-leaf-block attribute list.

fs/xfs/libxfs/xfs_parent.c new file +32 -0
new file mode 100644
index 000000000000..dddbf096a4b5
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All rights reserved.
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_format.h"
+#include "xfs_da_format.h"
+#include "xfs_log_format.h"
+#include "xfs_shared.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_inode.h"
+#include "xfs_error.h"
+#include "xfs_trace.h"
+#include "xfs_trans.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr_sf.h"
+#include "xfs_bmap.h"
+#include "xfs_defer.h"
+#include "xfs_log.h"
+#include "xfs_xattr.h"
+#include "xfs_parent.h"
+
+/*
+ * Parent pointer attribute handling.
+ *
+ * Because the attribute value is a filename component, it

will
never be longer
+ * than 255 bytes. This means the attribute will always be a local
format
+ * attribute as it is xfs_attr_leaf_entsize_local_max() for v5 filesystems will
+ * always be larger than this (max is 75% of block size).
+ *
+ * Creating a new parent attribute will always create a new attribute - there
+ * should never, ever be an existing attribute in the tree for a
new inode.
+ * ENOSPC behavior is problematic - creating the inode without

Quoted 8 lines

the
parent
+ * pointer is effectively a corruption, so we allow parent attribute creation
+ * to dip into the reserve block pool to avoid unexpected ENOSPC
errors from
+ * occurring.

Hoisting a discussion (that I never replied to; sorry... :( ) from
last
time around:

Quoted 11 lines
Quoted 8 lines

Shouldn't we increase XFS_LINK_SPACE_RES to avoid this?  The reserve
pool isn't terribly large (8192 blocks) and was really only supposed
to save us from an ENOSPC shutdown if an unwritten extent conversion
in the writeback endio handler needs a few more blocks.

Did you maybe mean XFS_IALLOC_SPACE_RES?  That looks like the macro
that's getting used below in xfs_create

I meant modifying XFS_MKDIR_SPACE_RES and XFS_CREATE_SPACE_RES:

unsigned int
xfs_pptr_calc_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        /*
         * Code lifted from xfs_attr_calc_size, check this for
         * correctness since I assumed that a pptr never requires rmt
         * blocks...
         */
        return XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_NEXTENTADD_SPACE_RES(mp, namelen, XFS_ATTR_FORK);
}

unsigned int
xfs_create_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        unsigned int            ret;

        ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,
namelen);
        if (xfs_has_parent(mp))
                ret += xfs_pptr_calc_space_res(mp, namelen);

        return ret;
}

unsigned int
xfs_mkdir_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        return xfs_create_space_res(mp, namelen);
}

Quoted 7 lines
Quoted 2 lines

(and then change the function case names as necessary)

Oooh ok...  So you're saying you want wrappers to XFS_IALLOC_SPACE_RES,
right?  Do you want these helpers corralled in a common area, or do you
just want them to be static in the same file where they are used?

Quoted 5 lines

Ideally the same place as the macros are #define'd now (as static inline
functions), though if that generates a ton of gcc errors then it might
be time to create an xfs_trans_space.c.

Ok, maybe I'll just drop the common xfs_pptr_calc_space_res helper there, and then keep the rest as static helpers. Thanks!

Allison

Quoted 342 lines

--D

Quoted 339 lines
Quoted 48 lines
Quoted 12 lines
Quoted 3 lines

IOWs, we really ought to ENOSPC at transaction reservation time
instead of draining the reserve pool.

It looks like we do that in most cases.  I dont actually see rsvd
getting set, other than in xfs_attr_set.  Which isnt used in parent
pointer updating, and should probably be removed.  I suspect it's a
relic of the pre-larp version of the set. So perhaps the comment is
stale and should be removed as well.

The block reservations for create/mkdir/link/unlink all need to be
adjusted upwards, which will eliminate the need for the comment.

Quoted 31 lines

+ */

fs/xfs/libxfs/xfs_parent.c new file +3 -0
+
+
+/* Initializes a xfs_parent_name_rec to be stored as an

attribute
name */

fs/xfs/libxfs/xfs_parent.c new file +8 -0
+void
+xfs_init_parent_name_rec(
+       struct xfs_parent_name_rec      *rec,
+       struct xfs_inode                *ip,
+       uint32_t                        p_diroffset)
+{
+       xfs_ino_t                       p_ino = ip->i_ino;
+       uint32_t                        p_gen = VFS_I(ip)-
Quoted 1 line

i_generation;

fs/xfs/libxfs/xfs_parent.c new file +7 -0
+
+       rec->p_ino = cpu_to_be64(p_ino);
+       rec->p_gen = cpu_to_be32(p_gen);
+       rec->p_diroffset = cpu_to_be32(p_diroffset);
+}
+
+/* Initializes a xfs_parent_name_irec from an

xfs_parent_name_rec
*/

fs/xfs/libxfs/xfs_parent.c new file +7 -0
+void
+xfs_init_parent_name_irec(
+       struct xfs_parent_name_irec     *irec,
+       struct xfs_parent_name_rec      *rec)
+{
+       irec->p_ino = be64_to_cpu(rec->p_ino);
+       irec->p_gen = be32_to_cpu(rec->p_gen);
Quoted 8 lines

fs/xfs/libxfs/xfs_parent.c line 74

Quoted 6 lines

+       irec->p_diroffset = be32_to_cpu(rec->p_diroffset);

fs/xfs/libxfs/xfs_parent.c new file +5 -0
+}
+
+int
+xfs_parent_init(
+       xfs_mount_t                     *mp,

Nit: typedef usage.

Will fix

Quoted 3 lines

Everything else below here looks good though. :)

Thanks for the reviews!

Allison

Quoted 275 lines

--D

Quoted 273 lines

+       struct xfs_parent_defer         **parentp)

fs/xfs/libxfs/xfs_parent.c new file +20 -0
+{
+       struct xfs_parent_defer         *parent;
+       int                             error;
+
+       if (!xfs_has_parent(mp))
+               return 0;
+
+       error = xfs_attr_grab_log_assist(mp);
+       if (error)
+               return error;
+
+       parent = kzalloc(sizeof(*parent), GFP_KERNEL);
+       if (!parent)
+               return -ENOMEM;
+
+       /* init parent da_args */
+       parent->args.geo = mp->m_attr_geo;
+       parent->args.whichfork = XFS_ATTR_FORK;
+       parent->args.attr_filter = XFS_ATTR_PARENT;
+       parent->args.op_flags = XFS_DA_OP_OKNOENT |

XFS_DA_OP_LOGGED;
+       parent->args.name = (const uint8_t *)&parent->rec; +       parent->args.namelen = sizeof(struct xfs_parent_name_rec);

fs/xfs/libxfs/xfs_parent.c new file +18 -0
+
+       *parentp = parent;
+       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)
+{
+       struct xfs_da_args      *args = &parent->args;
+
+       xfs_init_parent_name_rec(&parent->rec, dp, diroffset);
+       args->hashval = xfs_da_hashname(args->name, args-
Quoted 1 line

namelen);

fs/xfs/libxfs/xfs_parent.c new file +20 -0
+
+       args->trans = tp;
+       args->dp = child;
+       if (parent_name) {
+               parent->args.value = (void *)parent_name->name;
+               parent->args.valuelen = parent_name->len;
+       }
+
+       return xfs_attr_defer_add(args);
+}
+
+void
+xfs_parent_cancel(
+       xfs_mount_t             *mp,
+       struct xfs_parent_defer *parent)
+{
+       xlog_drop_incompat_feat(mp->m_log);
+       kfree(parent);
+}
+
fs/xfs/libxfs/xfs_parent.h new file +10 -0
new file mode 100644
index 000000000000..971044458f8a
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Oracle, Inc.
+ * All Rights Reserved.
+ */
+#ifndef        __XFS_PARENT_H__
+#define        __XFS_PARENT_H__
+
+/*
+ * Dynamically allocd structure used to wrap the needed data

to
pass around
+ * the defer ops machinery
+ */

fs/xfs/libxfs/xfs_parent.h new file +12 -0
+struct xfs_parent_defer {
+       struct xfs_parent_name_rec      rec;
+       struct xfs_da_args              args;
+};
+
+/*
+ * 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(xfs_mount_t *mp, struct xfs_parent_defer **parentp);
+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);
+void xfs_parent_cancel(xfs_mount_t *mp, struct xfs_parent_defer
*parent);

fs/xfs/libxfs/xfs_parent.h new file +2 -0
+
+#endif /* __XFS_PARENT_H__ */
fs/xfs/xfs_inode.c +2 -0
index 6eb264598517..181d6417412e 100644
@@ -37,6 +37,8 @@
  #include "xfs_reflink.h"
  #include "xfs_ag.h"
  #include "xfs_log_priv.h"
+#include "xfs_parent.h"
+#include "xfs_xattr.h"


 struct kmem_cache *xfs_inode_cache;

fs/xfs/xfs_inode.c +0 -0
@@ -949,7 +951,7 @@ xfs_bumplink(

 int
 xfs_create(
        struct user_namespace   *mnt_userns,
-       xfs_inode_t             *dp,
+       struct xfs_inode        *dp,
        struct xfs_name         *name,
        umode_t                 mode,
        dev_t                   rdev,

fs/xfs/xfs_inode.c +3 -1
@@ -961,7 +963,7 @@ xfs_create(
         struct xfs_inode        *ip = NULL;
         struct xfs_trans        *tp = NULL;
         int                     error;
-       bool                    unlock_dp_on_error = false;
+       bool                    unlock_dp_on_error = false;
         prid_t                  prid;
         struct xfs_dquot        *udqp = NULL;
         struct xfs_dquot        *gdqp = NULL;
@@ -969,6 +971,8 @@ xfs_create(
         struct xfs_trans_res    *tres;
         uint                    resblks;
         xfs_ino_t               ino;
+       xfs_dir2_dataptr_t      diroffset;
+       struct xfs_parent_defer *parent = NULL;


        trace_xfs_create(dp, name);

fs/xfs/xfs_inode.c +0 -0
@@ -995,6 +999,12 @@ xfs_create(
                 tres = &M_RES(mp)->tr_create;
         }


+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &parent); +               if (error)
+                       goto out_release_dquots;
+       }
+
        /*
         * Initially assume that the file does not exist and
         * reserve the resources for that case.  If that is not

fs/xfs/xfs_inode.c +1 -1
@@ -1010,7 +1020,7 @@ xfs_create(
                                 resblks, &tp);
         }
         if (error)
-               goto out_release_dquots;
+               goto drop_incompat;


        xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); unlock_dp_on_error = true;

fs/xfs/xfs_inode.c +0 -0
@@ -1020,6 +1030,7 @@ xfs_create(
          * entry pointing to them, but a directory also the "."

entry
         * pointing to itself.
         */
+       init_xattrs = init_xattrs || xfs_has_parent(mp); error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); if (!error)
                error = xfs_init_new_inode(mnt_userns, tp, dp, ino,
mode,

fs/xfs/xfs_inode.c +0 -0
@@ -1034,11 +1045,12 @@ xfs_create(
          * the transaction cancel unlocking dp so don't do it

explicitly in the
         * error path.
         */
-       xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, dp, 0); unlock_dp_on_error = false;

        error = xfs_dir_createname(tp, dp, name, ip->i_ino, -                                  resblks - XFS_IALLOC_SPACE_RES(mp), NULL);
+                                  resblks - XFS_IALLOC_SPACE_RES(mp),
+                                  &diroffset);
        if (error) {
                ASSERT(error != -ENOSPC);
                goto out_trans_cancel;

fs/xfs/xfs_inode.c +0 -0
@@ -1054,6 +1066,17 @@ xfs_create(
                 xfs_bumplink(tp, dp);
         }


+       /*
+        * If we have parent pointers, we need to add the attribute
containing
+        * the parent information now.
+        */
+       if (parent) {
+               error = xfs_parent_defer_add(tp, parent, dp, name,
diroffset,
+                                            ip);
+               if (error)
+                       goto out_trans_cancel;
+       }
+
        /*
         * If this is a synchronous mount, make sure that the
         * create transaction goes to disk before returning to

fs/xfs/xfs_inode.c +0 -0
@@ -1079,6 +1102,7 @@ xfs_create(


        *ipp = ip;
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
+       xfs_iunlock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); return 0;

  out_trans_cancel:

fs/xfs/xfs_inode.c +3 -0
@@ -1093,6 +1117,9 @@ xfs_create(
                 xfs_finish_inode_setup(ip);
                 xfs_irele(ip);
         }
+ drop_incompat:
+       if (parent)
+               xfs_parent_cancel(mp, parent);

  out_release_dquots:
        xfs_qm_dqrele(udqp);
        xfs_qm_dqrele(gdqp);

fs/xfs/xfs_xattr.c +0 -0
index c325a28b89a8..d9067c5f6bd6 100644
@@ -27,7 +27,7 @@
   * they must release the permission by calling

xlog_drop_incompat_feat
  * when they're done.
  */

fs/xfs/xfs_xattr.c +1 -1
-static inline int
+int

 xfs_attr_grab_log_assist(
        struct xfs_mount        *mp)
 {

fs/xfs/xfs_xattr.h +0 -0
index 2b09133b1b9b..3fd6520a4d69 100644
@@ -7,6 +7,7 @@
  #define __XFS_XATTR_H__


 int xfs_attr_change(struct xfs_da_args *args); +int xfs_attr_grab_log_assist(struct xfs_mount *mp);
 extern const struct xattr_handler *xfs_xattr_handlers[];

Signature · 1 line
2.25.1
#35 lore raw

PATCH v3 15/26 xfs: add parent attributes to link

In reply to [email protected]

From: Allison Henderson <[email protected]>

This patch modifies xfs_link to add a parent pointer to the inode.

---
 fs/xfs/xfs_inode.c | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)
fs/xfs/xfs_inode.c +35 -9
index 181d6417412e..af3f5edb7319 100644
@@ -1228,14 +1228,16 @@ xfs_create_tmpfile(
 
 int
 xfs_link(
-	xfs_inode_t		*tdp,
-	xfs_inode_t		*sip,
+	struct xfs_inode	*tdp,
+	struct xfs_inode	*sip,
 	struct xfs_name		*target_name)
 {
-	xfs_mount_t		*mp = tdp->i_mount;
-	xfs_trans_t		*tp;
+	struct xfs_mount	*mp = tdp->i_mount;
+	struct xfs_trans	*tp;
 	int			error, nospace_error = 0;
 	int			resblks;
+	xfs_dir2_dataptr_t	diroffset;
+	struct xfs_parent_defer	*parent = NULL;
 
 	trace_xfs_link(tdp, target_name);
 
@@ -1252,11 +1254,17 @@ xfs_link(
 	if (error)
 		goto std_return;
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &parent);
+		if (error)
+			goto std_return;
+	}
+
 	resblks = XFS_LINK_SPACE_RES(mp, target_name->len);
 	error = xfs_trans_alloc_dir(tdp, &M_RES(mp)->tr_link, sip, &resblks,
 			&tp, &nospace_error);
 	if (error)
-		goto std_return;
+		goto drop_incompat;
 
 	/*
 	 * If we are using project inheritance, we only allow hard link
@@ -1289,14 +1297,27 @@ xfs_link(
 	}
 
 	error = xfs_dir_createname(tp, tdp, target_name, sip->i_ino,
-				   resblks, NULL);
+				   resblks, &diroffset);
 	if (error)
-		goto error_return;
+		goto out_defer_cancel;
 	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 (parent) {
+		error = xfs_parent_defer_add(tp, parent, tdp, target_name,
+					     diroffset, sip);
+		if (error)
+			goto out_defer_cancel;
+	}
+
 	/*
 	 * If this is a synchronous mount, make sure that the
 	 * link transaction goes to disk before returning to
@@ -1310,11 +1331,16 @@ xfs_link(
 	xfs_iunlock(sip, XFS_ILOCK_EXCL);
 	return error;
 
- error_return:
+out_defer_cancel:
+	xfs_defer_cancel(tp);
+error_return:
 	xfs_trans_cancel(tp);
 	xfs_iunlock(tdp, XFS_ILOCK_EXCL);
 	xfs_iunlock(sip, XFS_ILOCK_EXCL);
- std_return:
+drop_incompat:
+	if (parent)
+		xfs_parent_cancel(mp, parent);
+std_return:
 	if (error == -ENOSPC && nospace_error)
 		error = nospace_error;
 	return error;
Signature · 1 line
2.25.1
#36 lore raw

Re: [PATCH v3 15/26] xfs: add parent attributes to link

Quoted 36 lines · On Wed, Sep 21, 2022 at 10:44:47PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch modifies xfs_link to add a parent pointer to the inode.

---
 fs/xfs/xfs_inode.c | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)
fs/xfs/xfs_inode.c +6 -4
index 181d6417412e..af3f5edb7319 100644
@@ -1228,14 +1228,16 @@ xfs_create_tmpfile(
 
 int
 xfs_link(
-	xfs_inode_t		*tdp,
-	xfs_inode_t		*sip,
+	struct xfs_inode	*tdp,
+	struct xfs_inode	*sip,
 	struct xfs_name		*target_name)
 {
-	xfs_mount_t		*mp = tdp->i_mount;
-	xfs_trans_t		*tp;
+	struct xfs_mount	*mp = tdp->i_mount;
+	struct xfs_trans	*tp;
 	int			error, nospace_error = 0;
 	int			resblks;
+	xfs_dir2_dataptr_t	diroffset;
+	struct xfs_parent_defer	*parent = NULL;
 
 	trace_xfs_link(tdp, target_name);
 

fs/xfs/xfs_inode.c xfs_link( · line 1263

Quoted 10 lines
fs/xfs/xfs_inode.c +6 -0
@@ -1252,11 +1254,17 @@ xfs_link(
 	if (error)
 		goto std_return;
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &parent);
+		if (error)
+			goto std_return;
+	}
+
 	resblks = XFS_LINK_SPACE_RES(mp, target_name->len);

Forwarding on from the v2 series --

This patch ought to be modifying XFS_LINK_SPACE_RES so that each link() update reserves enough space to handle an expansion in the tdp directory (as it does now) *and* an expansion in the xattr structure of the sip child file. This is how we avoid dipping into the free space reserve pool midway through a transaction, and avoid shutdowns when space is tight.

tr_res == space we reserve in the *log* to record updates.

XFS_LINK_SPACE_RES == block we reserve from the filesystem free space to handle expansions of metadata structures.

At this point in this version of the patchset, you've increased the log space reservations in anticipation of logging more information per transaction. However, you've not increased the free space reservations to handle potential node splitting in the ondisk xattr btree.

(The rest of the patchset looks ok.)

--D

Quoted 60 lines
fs/xfs/xfs_inode.c +23 -5
 	error = xfs_trans_alloc_dir(tdp, &M_RES(mp)->tr_link, sip, &resblks,
 			&tp, &nospace_error);
 	if (error)
-		goto std_return;
+		goto drop_incompat;
 
 	/*
 	 * If we are using project inheritance, we only allow hard link
@@ -1289,14 +1297,27 @@ xfs_link(
 	}
 
 	error = xfs_dir_createname(tp, tdp, target_name, sip->i_ino,
-				   resblks, NULL);
+				   resblks, &diroffset);
 	if (error)
-		goto error_return;
+		goto out_defer_cancel;
 	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 (parent) {
+		error = xfs_parent_defer_add(tp, parent, tdp, target_name,
+					     diroffset, sip);
+		if (error)
+			goto out_defer_cancel;
+	}
+
 	/*
 	 * If this is a synchronous mount, make sure that the
 	 * link transaction goes to disk before returning to
@@ -1310,11 +1331,16 @@ xfs_link(
 	xfs_iunlock(sip, XFS_ILOCK_EXCL);
 	return error;
 
- error_return:
+out_defer_cancel:
+	xfs_defer_cancel(tp);
+error_return:
 	xfs_trans_cancel(tp);
 	xfs_iunlock(tdp, XFS_ILOCK_EXCL);
 	xfs_iunlock(sip, XFS_ILOCK_EXCL);
- std_return:
+drop_incompat:
+	if (parent)
+		xfs_parent_cancel(mp, parent);
+std_return:
 	if (error == -ENOSPC && nospace_error)
 		error = nospace_error;
 	return error;
Signature · 1 line
2.25.1
#37 lore raw

Re: [PATCH v3 15/26] xfs: add parent attributes to link

Quoted 67 lines · Darrick J. Wong
Quoted 39 lines · On Wed, Sep 21, 2022 at 10:44:47PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch modifies xfs_link to add a parent pointer to the inode.

---
 fs/xfs/xfs_inode.c | 44 +++++++++++++++++++++++++++++++++++------- --

 1 file changed, 35 insertions(+), 9 deletions(-)
fs/xfs/xfs_inode.c +0 -0
index 181d6417412e..af3f5edb7319 100644
@@ -1228,14 +1228,16 @@ xfs_create_tmpfile(


 int
 xfs_link(
-       xfs_inode_t             *tdp,
-       xfs_inode_t             *sip,
+       struct xfs_inode        *tdp,
+       struct xfs_inode        *sip,
        struct xfs_name         *target_name)
 {
-       xfs_mount_t             *mp = tdp->i_mount; -       xfs_trans_t             *tp;
+       struct xfs_mount        *mp = tdp->i_mount; +       struct xfs_trans        *tp;
        int                     error, nospace_error = 0; int                     resblks;
+       xfs_dir2_dataptr_t      diroffset;
+       struct xfs_parent_defer *parent = NULL;

        trace_xfs_link(tdp, target_name);

fs/xfs/xfs_inode.c +0 -0
@@ -1252,11 +1254,17 @@ xfs_link(
         if (error)
                 goto std_return;
Quoted 8 lines


+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &parent); +               if (error)
+                       goto std_return;
+       }
+
        resblks = XFS_LINK_SPACE_RES(mp, target_name->len);

Forwarding on from the v2 series --

This patch ought to be modifying XFS_LINK_SPACE_RES so that each link()
update reserves enough space to handle an expansion in the tdp directory
(as it does now) *and* an expansion in the xattr structure of the sip child file.  This is how we avoid dipping into the free space reserve pool midway through a transaction, and avoid shutdowns when space is tight.

tr_res == space we reserve in the *log* to record updates.

XFS_LINK_SPACE_RES == block we reserve from the filesystem free space to
handle expansions of metadata structures.

Quoted 8 lines

At this point in this version of the patchset, you've increased the log
space reservations in anticipation of logging more information per transaction.  However, you've not increased the free space reservations
to handle potential node splitting in the ondisk xattr btree.

(The rest of the patchset looks ok.)

Ok, looking at the later reviews, I'll add a similar helper function here to use in place of XFS_LINK_SPACE_RES:

unsigned int
xfs_link_space_res(
struct xfs_mount *mp,
unsigned int namelen)

 {
         unsigned int            ret;
 
         ret = XFS_DIRENTER_SPACE_RES(mp, namelen);
         if (xfs_has_parent(mp))
                 ret += xfs_pptr_calc_space_res(mp, namelen);
 
         return ret;

}

Thanks!
Allison

Quoted 71 lines

--D

Quoted 68 lines

        error = xfs_trans_alloc_dir(tdp, &M_RES(mp)->tr_link, sip, &resblks,
                        &tp, &nospace_error);
        if (error)
-               goto std_return;
+               goto drop_incompat;

        /*
         * If we are using project inheritance, we only allow hard link

fs/xfs/xfs_inode.c +0 -0
@@ -1289,14 +1297,27 @@ xfs_link(
         }


        error = xfs_dir_createname(tp, tdp, target_name, sip-

Quoted 1 line

i_ino,

-                                  resblks, NULL);
+                                  resblks, &diroffset); if (error)
-               goto error_return;
+               goto out_defer_cancel; 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 (parent) {
+               error = xfs_parent_defer_add(tp, parent, tdp, target_name,
+                                            diroffset, sip); +               if (error)
+                       goto out_defer_cancel;
+       }
+
        /*
         * If this is a synchronous mount, make sure that the
         * link transaction goes to disk before returning to

fs/xfs/xfs_inode.c +0 -0
@@ -1310,11 +1331,16 @@ xfs_link(
         xfs_iunlock(sip, XFS_ILOCK_EXCL);
         return error;


- error_return:

fs/xfs/xfs_inode.c +3 -0
+out_defer_cancel:
+       xfs_defer_cancel(tp);
+error_return:

        xfs_trans_cancel(tp);
        xfs_iunlock(tdp, XFS_ILOCK_EXCL);
        xfs_iunlock(sip, XFS_ILOCK_EXCL);
- std_return:

fs/xfs/xfs_inode.c +4 -0
+drop_incompat:
+       if (parent)
+               xfs_parent_cancel(mp, parent);
+std_return:

        if (error == -ENOSPC && nospace_error)
                error = nospace_error;
        return error;

Signature · 1 line
2.25.1
#38 lore raw

Re: [PATCH v3 15/26] xfs: add parent attributes to link

Quoted 92 lines · Allison Henderson
Quoted 67 lines · Darrick J. Wong
Quoted 39 lines · On Wed, Sep 21, 2022 at 10:44:47PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch modifies xfs_link to add a parent pointer to the inode.

---
 fs/xfs/xfs_inode.c | 44 +++++++++++++++++++++++++++++++++++------- --

 1 file changed, 35 insertions(+), 9 deletions(-)
fs/xfs/xfs_inode.c +0 -0
index 181d6417412e..af3f5edb7319 100644
@@ -1228,14 +1228,16 @@ xfs_create_tmpfile(


 int
 xfs_link(
-       xfs_inode_t             *tdp,
-       xfs_inode_t             *sip,
+       struct xfs_inode        *tdp,
+       struct xfs_inode        *sip,
        struct xfs_name         *target_name)
 {
-       xfs_mount_t             *mp = tdp->i_mount; -       xfs_trans_t             *tp;
+       struct xfs_mount        *mp = tdp->i_mount; +       struct xfs_trans        *tp;
        int                     error, nospace_error = 0; int                     resblks;
+       xfs_dir2_dataptr_t      diroffset;
+       struct xfs_parent_defer *parent = NULL;

        trace_xfs_link(tdp, target_name);

fs/xfs/xfs_inode.c +0 -0
@@ -1252,11 +1254,17 @@ xfs_link(
         if (error)
                 goto std_return;
Quoted 8 lines


+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &parent); +               if (error)
+                       goto std_return;
+       }
+
        resblks = XFS_LINK_SPACE_RES(mp, target_name->len);

Forwarding on from the v2 series --

This patch ought to be modifying XFS_LINK_SPACE_RES so that each link()
update reserves enough space to handle an expansion in the tdp directory
(as it does now) *and* an expansion in the xattr structure of the sip child file.  This is how we avoid dipping into the free space reserve pool midway through a transaction, and avoid shutdowns when space is tight.

tr_res == space we reserve in the *log* to record updates.

XFS_LINK_SPACE_RES == block we reserve from the filesystem free space to
handle expansions of metadata structures.

Quoted 8 lines

At this point in this version of the patchset, you've increased the log
space reservations in anticipation of logging more information per transaction.  However, you've not increased the free space reservations
to handle potential node splitting in the ondisk xattr btree.

(The rest of the patchset looks ok.)

Ok, looking at the later reviews, I'll add a similar helper function here to use in place of XFS_LINK_SPACE_RES:

unsigned int
xfs_link_space_res(
struct xfs_mount *mp,
unsigned int namelen)

 {
         unsigned int            ret;
 
         ret = XFS_DIRENTER_SPACE_RES(mp, namelen);
         if (xfs_has_parent(mp))
                 ret += xfs_pptr_calc_space_res(mp, namelen);
 
         return ret;
Quoted 1 line

}

<nod>

--D

Quoted 74 lines

Thanks!
Allison

Quoted 71 lines

--D

Quoted 68 lines

        error = xfs_trans_alloc_dir(tdp, &M_RES(mp)->tr_link, sip, &resblks,
                        &tp, &nospace_error);
        if (error)
-               goto std_return;
+               goto drop_incompat;

        /*
         * If we are using project inheritance, we only allow hard link

fs/xfs/xfs_inode.c +0 -0
@@ -1289,14 +1297,27 @@ xfs_link(
         }


        error = xfs_dir_createname(tp, tdp, target_name, sip-

Quoted 1 line

i_ino,

-                                  resblks, NULL);
+                                  resblks, &diroffset); if (error)
-               goto error_return;
+               goto out_defer_cancel; 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 (parent) {
+               error = xfs_parent_defer_add(tp, parent, tdp, target_name,
+                                            diroffset, sip); +               if (error)
+                       goto out_defer_cancel;
+       }
+
        /*
         * If this is a synchronous mount, make sure that the
         * link transaction goes to disk before returning to

fs/xfs/xfs_inode.c +0 -0
@@ -1310,11 +1331,16 @@ xfs_link(
         xfs_iunlock(sip, XFS_ILOCK_EXCL);
         return error;


- error_return:

fs/xfs/xfs_inode.c +3 -0
+out_defer_cancel:
+       xfs_defer_cancel(tp);
+error_return:

        xfs_trans_cancel(tp);
        xfs_iunlock(tdp, XFS_ILOCK_EXCL);
        xfs_iunlock(sip, XFS_ILOCK_EXCL);
- std_return:

fs/xfs/xfs_inode.c +4 -0
+drop_incompat:
+       if (parent)
+               xfs_parent_cancel(mp, parent);
+std_return:

        if (error == -ENOSPC && nospace_error)
                error = nospace_error;
        return error;

Signature · 1 line
2.25.1
#39 lore raw

PATCH v3 16/26 xfs: add parent attributes to symlink

In reply to [email protected]

From: Allison Henderson <[email protected]>

This patch modifies xfs_symlink to add a parent pointer to the inode.

---
 fs/xfs/xfs_symlink.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
fs/xfs/xfs_symlink.c +27 -4
index 27a7d7c57015..14079367335b 100644
@@ -23,6 +23,8 @@
 #include "xfs_trans.h"
 #include "xfs_ialloc.h"
 #include "xfs_error.h"
+#include "xfs_parent.h"
+#include "xfs_defer.h"
 
 /* ----- Kernel only functions below ----- */
 int
@@ -172,6 +174,8 @@ xfs_symlink(
 	struct xfs_dquot	*pdqp = NULL;
 	uint			resblks;
 	xfs_ino_t		ino;
+	xfs_dir2_dataptr_t      diroffset;
+	struct xfs_parent_defer *parent = NULL;
 
 	*ipp = NULL;
 
@@ -179,10 +183,10 @@ xfs_symlink(
 
 	if (xfs_is_shutdown(mp))
 		return -EIO;
-
 	/*
 	 * Check component lengths of the target path name.
 	 */
+
 	pathlen = strlen(target_path);
 	if (pathlen >= XFS_SYMLINK_MAXLEN)      /* total string too long */
 		return -ENAMETOOLONG;
@@ -204,12 +208,18 @@ xfs_symlink(
 	 * The symlink will fit into the inode data fork?
 	 * There can't be any attributes so we get the whole variable part.
 	 */
-	if (pathlen <= XFS_LITINO(mp))
+	if (pathlen <= XFS_LITINO(mp) && !xfs_has_parent(mp))
 		fs_blocks = 0;
 	else
 		fs_blocks = xfs_symlink_blocks(mp, pathlen);
 	resblks = XFS_SYMLINK_SPACE_RES(mp, link_name->len, fs_blocks);
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &parent);
+		if (error)
+			return error;
+	}
+
 	error = xfs_trans_alloc_icreate(mp, &M_RES(mp)->tr_symlink, udqp, gdqp,
 			pdqp, resblks, &tp);
 	if (error)
@@ -233,7 +243,7 @@ xfs_symlink(
 	if (!error)
 		error = xfs_init_new_inode(mnt_userns, tp, dp, ino,
 				S_IFLNK | (mode & ~S_IFMT), 1, 0, prid,
-				false, &ip);
+				xfs_has_parent(mp), &ip);
 	if (error)
 		goto out_trans_cancel;
 
@@ -315,12 +325,20 @@ xfs_symlink(
 	 * Create the directory entry for the symlink.
 	 */
 	error = xfs_dir_createname(tp, dp, link_name,
-			ip->i_ino, resblks, NULL);
+			ip->i_ino, resblks, &diroffset);
 	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 (parent) {
+		error = xfs_parent_defer_add(tp, parent, dp, link_name,
+					     diroffset, ip);
+		if (error)
+			goto out_trans_cancel;
+	}
+
+
 	/*
 	 * If this is a synchronous mount, make sure that the
 	 * symlink transaction goes to disk before returning to
@@ -344,6 +362,8 @@ xfs_symlink(
 out_trans_cancel:
 	xfs_trans_cancel(tp);
 out_release_inode:
+	xfs_defer_cancel(tp);
+
 	/*
 	 * Wait until after the current transaction is aborted to finish the
 	 * setup of the inode and release the inode.  This prevents recursive
@@ -362,6 +382,9 @@ xfs_symlink(
 		xfs_iunlock(dp, XFS_ILOCK_EXCL);
 	if (ip)
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (parent)
+		xfs_parent_cancel(mp, parent);
+
 	return error;
 }
 
Signature · 1 line
2.25.1
#40 lore raw

Re: [PATCH v3 16/26] xfs: add parent attributes to symlink

Quoted 5 lines · On Wed, Sep 21, 2022 at 10:44:48PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch modifies xfs_symlink to add a parent pointer to the inode.

Ooh, a new patch.

Quoted 39 lines
---
 fs/xfs/xfs_symlink.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
fs/xfs/xfs_symlink.c +5 -1
index 27a7d7c57015..14079367335b 100644
@@ -23,6 +23,8 @@
 #include "xfs_trans.h"
 #include "xfs_ialloc.h"
 #include "xfs_error.h"
+#include "xfs_parent.h"
+#include "xfs_defer.h"
 
 /* ----- Kernel only functions below ----- */
 int
@@ -172,6 +174,8 @@ xfs_symlink(
 	struct xfs_dquot	*pdqp = NULL;
 	uint			resblks;
 	xfs_ino_t		ino;
+	xfs_dir2_dataptr_t      diroffset;
+	struct xfs_parent_defer *parent = NULL;
 
 	*ipp = NULL;
 
@@ -179,10 +183,10 @@ xfs_symlink(
 
 	if (xfs_is_shutdown(mp))
 		return -EIO;
-
 	/*
 	 * Check component lengths of the target path name.
 	 */
+
 	pathlen = strlen(target_path);
 	if (pathlen >= XFS_SYMLINK_MAXLEN)      /* total string too long */
 		return -ENAMETOOLONG;

fs/xfs/xfs_symlink.c xfs_symlink( · line 215

Quoted 9 lines
fs/xfs/xfs_symlink.c +1 -1
@@ -204,12 +208,18 @@ xfs_symlink(
 	 * The symlink will fit into the inode data fork?
 	 * There can't be any attributes so we get the whole variable part.
 	 */
-	if (pathlen <= XFS_LITINO(mp))
+	if (pathlen <= XFS_LITINO(mp) && !xfs_has_parent(mp))
 		fs_blocks = 0;
 	else
 		fs_blocks = xfs_symlink_blocks(mp, pathlen);
 	resblks = XFS_SYMLINK_SPACE_RES(mp, link_name->len, fs_blocks);

Same comment as the last two patches: Please update xfs_symlink_space_res to handle the free space that might be needed to expand the xattr structure ondisk:

unsigned int
xfs_symlink_space_res(
struct xfs_mount *mp,
unsigned int namelen,
unsigned int fsblocks)

{
	unsigned int		ret;

	ret = XFS_IALLOC_SPACE_RES(mp) +
	      XFS_DIRENTER_SPACE_RES(mp, namelen) +
	      fsblocks;

	if (xfs_has_parent(mp))
		ret += xfs_pptr_calc_space_res(mp, namelen);

	return ret;
}

Everything else in here otherwise looks good to me.

--D

Quoted 63 lines
fs/xfs/xfs_symlink.c +21 -2
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &parent);
+		if (error)
+			return error;
+	}
+
 	error = xfs_trans_alloc_icreate(mp, &M_RES(mp)->tr_symlink, udqp, gdqp,
 			pdqp, resblks, &tp);
 	if (error)
@@ -233,7 +243,7 @@ xfs_symlink(
 	if (!error)
 		error = xfs_init_new_inode(mnt_userns, tp, dp, ino,
 				S_IFLNK | (mode & ~S_IFMT), 1, 0, prid,
-				false, &ip);
+				xfs_has_parent(mp), &ip);
 	if (error)
 		goto out_trans_cancel;
 
@@ -315,12 +325,20 @@ xfs_symlink(
 	 * Create the directory entry for the symlink.
 	 */
 	error = xfs_dir_createname(tp, dp, link_name,
-			ip->i_ino, resblks, NULL);
+			ip->i_ino, resblks, &diroffset);
 	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 (parent) {
+		error = xfs_parent_defer_add(tp, parent, dp, link_name,
+					     diroffset, ip);
+		if (error)
+			goto out_trans_cancel;
+	}
+
+
 	/*
 	 * If this is a synchronous mount, make sure that the
 	 * symlink transaction goes to disk before returning to
@@ -344,6 +362,8 @@ xfs_symlink(
 out_trans_cancel:
 	xfs_trans_cancel(tp);
 out_release_inode:
+	xfs_defer_cancel(tp);
+
 	/*
 	 * Wait until after the current transaction is aborted to finish the
 	 * setup of the inode and release the inode.  This prevents recursive
@@ -362,6 +382,9 @@ xfs_symlink(
 		xfs_iunlock(dp, XFS_ILOCK_EXCL);
 	if (ip)
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (parent)
+		xfs_parent_cancel(mp, parent);
+
 	return error;
 }
 
Signature · 1 line
2.25.1
#41 lore raw

Re: [PATCH v3 16/26] xfs: add parent attributes to symlink

Quoted 80 lines · Darrick J. Wong
Quoted 6 lines · On Wed, Sep 21, 2022 at 10:44:48PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch modifies xfs_symlink to add a parent pointer to the inode.

Ooh, a new patch.

Quoted 43 lines

---
 fs/xfs/xfs_symlink.c | 31 +++++++++++++++++++++++++++----

 1 file changed, 27 insertions(+), 4 deletions(-)
fs/xfs/xfs_symlink.c +2 -0
index 27a7d7c57015..14079367335b 100644
@@ -23,6 +23,8 @@
  #include "xfs_trans.h"
  #include "xfs_ialloc.h"
  #include "xfs_error.h"
+#include "xfs_parent.h"
+#include "xfs_defer.h"


 /* ----- Kernel only functions below ----- */
 int

fs/xfs/xfs_symlink.c +2 -0
@@ -172,6 +174,8 @@ xfs_symlink(
         struct xfs_dquot        *pdqp = NULL;
         uint                    resblks;
         xfs_ino_t               ino;
+       xfs_dir2_dataptr_t      diroffset;
+       struct xfs_parent_defer *parent = NULL;


        *ipp = NULL;

fs/xfs/xfs_symlink.c +0 -0
@@ -179,10 +183,10 @@ xfs_symlink(


        if (xfs_is_shutdown(mp))
                return -EIO;
-
        /*
         * Check component lengths of the target path name. */
+
        pathlen = strlen(target_path);
        if (pathlen >= XFS_SYMLINK_MAXLEN)      /* total string too long */
                return -ENAMETOOLONG;

fs/xfs/xfs_symlink.c +0 -0
@@ -204,12 +208,18 @@ xfs_symlink(
          * The symlink will fit into the inode data fork?
          * There can't be any attributes so we get the whole

variable part.

Quoted 8 lines

         */
-       if (pathlen <= XFS_LITINO(mp))
+       if (pathlen <= XFS_LITINO(mp) && !xfs_has_parent(mp)) fs_blocks = 0;
        else
                fs_blocks = xfs_symlink_blocks(mp, pathlen); resblks = XFS_SYMLINK_SPACE_RES(mp, link_name->len, fs_blocks);

Same comment as the last two patches: Please update xfs_symlink_space_res to handle the free space that might be needed to
expand the xattr structure ondisk:

unsigned int
xfs_symlink_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen,
        unsigned int            fsblocks)
{
        unsigned int            ret;

        ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, namelen) + fsblocks;

Quoted 7 lines

        if (xfs_has_parent(mp))
                ret += xfs_pptr_calc_space_res(mp, namelen);

        return ret;
}

Everything else in here otherwise looks good to me.

Alrighty, will add. Thanks!

Quoted 72 lines

--D

Quoted 69 lines


+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &parent);
+               if (error)
+                       return error;
+       }
+
        error = xfs_trans_alloc_icreate(mp, &M_RES(mp)->tr_symlink, udqp, gdqp,
                        pdqp, resblks, &tp);
        if (error)

fs/xfs/xfs_symlink.c +1 -1
@@ -233,7 +243,7 @@ xfs_symlink(
         if (!error)
                 error = xfs_init_new_inode(mnt_userns, tp, dp, ino,
                                 S_IFLNK | (mode & ~S_IFMT), 1, 0,
 prid,
-                               false, &ip);
+                               xfs_has_parent(mp), &ip);
         if (error)
                 goto out_trans_cancel;

fs/xfs/xfs_symlink.c +1 -1
@@ -315,12 +325,20 @@ xfs_symlink(
          * Create the directory entry for the symlink.
          */
         error = xfs_dir_createname(tp, dp, link_name,
-                       ip->i_ino, resblks, NULL);
+                       ip->i_ino, resblks, &diroffset);
         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 (parent) {
+               error = xfs_parent_defer_add(tp, parent, dp, link_name,
+                                            diroffset, ip); +               if (error)
+                       goto out_trans_cancel;
+       }

fs/xfs/xfs_symlink.c +2 -0
+
+

        /*
         * If this is a synchronous mount, make sure that the
         * symlink transaction goes to disk before returning to

fs/xfs/xfs_symlink.c +0 -0
@@ -344,6 +362,8 @@ xfs_symlink(

 out_trans_cancel:
        xfs_trans_cancel(tp);
 out_release_inode:
+       xfs_defer_cancel(tp);
+
        /*
         * Wait until after the current transaction is aborted to finish the
         * setup of the inode and release the inode.  This prevents recursive

fs/xfs/xfs_symlink.c +3 -0
@@ -362,6 +382,9 @@ xfs_symlink(
                 xfs_iunlock(dp, XFS_ILOCK_EXCL);
         if (ip)
                 xfs_iunlock(ip, XFS_ILOCK_EXCL);
+       if (parent)
+               xfs_parent_cancel(mp, parent);
+
         return error;
  }

Signature · 1 line
2.25.1
#42 lore raw

PATCH v3 17/26 xfs: remove parent pointers in unlink

In reply to [email protected]

From: Allison Henderson <[email protected]>

This patch removes the parent pointer attribute during unlink

---
 fs/xfs/libxfs/xfs_attr.c   |  2 +-
 fs/xfs/libxfs/xfs_attr.h   |  1 +
 fs/xfs/libxfs/xfs_parent.c | 17 +++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  4 ++++
 fs/xfs/xfs_inode.c         | 29 +++++++++++++++++++++++------
 5 files changed, 46 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index 805aaa5639d2..e967728d1ee7 100644
@@ -946,7 +946,7 @@ xfs_attr_defer_replace(
 }
 
 /* Removes an attribute for an inode as a deferred operation */
-static int
+int
 xfs_attr_defer_remove(
 	struct xfs_da_args	*args)
 {
fs/xfs/libxfs/xfs_attr.h +1 -0
index 0cf23f5117ad..033005542b9e 100644
@@ -545,6 +545,7 @@ bool xfs_attr_is_leaf(struct xfs_inode *ip);
 int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_defer_add(struct xfs_da_args *args);
+int xfs_attr_defer_remove(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_iter(struct xfs_attr_intent *attr);
 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
fs/xfs/libxfs/xfs_parent.c +17 -0
index dddbf096a4b5..378fa227b87f 100644
@@ -124,6 +124,23 @@ xfs_parent_defer_add(
 	return xfs_attr_defer_add(args);
 }
 
+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)
+{
+	struct xfs_da_args	*args = &parent->args;
+
+	xfs_init_parent_name_rec(&parent->rec, dp, diroffset);
+	args->trans = tp;
+	args->dp = child;
+	args->hashval = xfs_da_hashname(args->name, args->namelen);
+	return xfs_attr_defer_remove(args);
+}
+
 void
 xfs_parent_cancel(
 	xfs_mount_t		*mp,
fs/xfs/libxfs/xfs_parent.h +4 -0
index 971044458f8a..79d3fabb5e56 100644
@@ -27,6 +27,10 @@ int xfs_parent_init(xfs_mount_t *mp, struct xfs_parent_defer **parentp);
 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_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(xfs_mount_t *mp, struct xfs_parent_defer *parent);
 
 #endif	/* __XFS_PARENT_H__ */
fs/xfs/xfs_inode.c +23 -6
index af3f5edb7319..1a35dc972d4d 100644
@@ -2465,16 +2465,18 @@ xfs_iunpin_wait(
  */
 int
 xfs_remove(
-	xfs_inode_t             *dp,
+	struct xfs_inode	*dp,
 	struct xfs_name		*name,
-	xfs_inode_t		*ip)
+	struct xfs_inode	*ip)
 {
-	xfs_mount_t		*mp = dp->i_mount;
-	xfs_trans_t             *tp = NULL;
+	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;
+	xfs_dir2_dataptr_t	dir_offset;
+	struct xfs_parent_defer	*parent = NULL;
 
 	trace_xfs_remove(dp, name);
 
@@ -2489,6 +2491,12 @@ xfs_remove(
 	if (error)
 		goto std_return;
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &parent);
+		if (error)
+			goto std_return;
+	}
+
 	/*
 	 * We try to get the real space reservation first, allowing for
 	 * directory btree deletion(s) implying possible bmap insert(s).  If we
@@ -2505,7 +2513,7 @@ xfs_remove(
 			&tp, &dontcare);
 	if (error) {
 		ASSERT(error != -ENOSPC);
-		goto std_return;
+		goto drop_incompat;
 	}
 
 	/*
@@ -2559,12 +2567,18 @@ xfs_remove(
 	if (error)
 		goto out_trans_cancel;
 
-	error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, NULL);
+	error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, &dir_offset);
 	if (error) {
 		ASSERT(error != -ENOENT);
 		goto out_trans_cancel;
 	}
 
+	if (parent) {
+		error = xfs_parent_defer_remove(tp, dp, parent, dir_offset, ip);
+		if (error)
+			goto out_trans_cancel;
+	}
+
 	/*
 	 * If this is a synchronous mount, make sure that the
 	 * remove transaction goes to disk before returning to
@@ -2589,6 +2603,9 @@ xfs_remove(
  out_unlock:
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 	xfs_iunlock(dp, XFS_ILOCK_EXCL);
+ drop_incompat:
+	if (parent)
+		xfs_parent_cancel(mp, parent);
  std_return:
 	return error;
 }
Signature · 1 line
2.25.1
#43 lore raw

Re: [PATCH v3 17/26] xfs: remove parent pointers in unlink

Quoted 112 lines · On Wed, Sep 21, 2022 at 10:44:49PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch removes the parent pointer attribute during unlink

---
 fs/xfs/libxfs/xfs_attr.c   |  2 +-
 fs/xfs/libxfs/xfs_attr.h   |  1 +
 fs/xfs/libxfs/xfs_parent.c | 17 +++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  4 ++++
 fs/xfs/xfs_inode.c         | 29 +++++++++++++++++++++++------
 5 files changed, 46 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index 805aaa5639d2..e967728d1ee7 100644
@@ -946,7 +946,7 @@ xfs_attr_defer_replace(
 }
 
 /* Removes an attribute for an inode as a deferred operation */
-static int
+int
 xfs_attr_defer_remove(
 	struct xfs_da_args	*args)
 {
fs/xfs/libxfs/xfs_attr.h +1 -0
index 0cf23f5117ad..033005542b9e 100644
@@ -545,6 +545,7 @@ bool xfs_attr_is_leaf(struct xfs_inode *ip);
 int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_defer_add(struct xfs_da_args *args);
+int xfs_attr_defer_remove(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_iter(struct xfs_attr_intent *attr);
 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
fs/xfs/libxfs/xfs_parent.c +17 -0
index dddbf096a4b5..378fa227b87f 100644
@@ -124,6 +124,23 @@ xfs_parent_defer_add(
 	return xfs_attr_defer_add(args);
 }
 
+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)
+{
+	struct xfs_da_args	*args = &parent->args;
+
+	xfs_init_parent_name_rec(&parent->rec, dp, diroffset);
+	args->trans = tp;
+	args->dp = child;
+	args->hashval = xfs_da_hashname(args->name, args->namelen);
+	return xfs_attr_defer_remove(args);
+}
+
 void
 xfs_parent_cancel(
 	xfs_mount_t		*mp,
fs/xfs/libxfs/xfs_parent.h +4 -0
index 971044458f8a..79d3fabb5e56 100644
@@ -27,6 +27,10 @@ int xfs_parent_init(xfs_mount_t *mp, struct xfs_parent_defer **parentp);
 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_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(xfs_mount_t *mp, struct xfs_parent_defer *parent);
 
 #endif	/* __XFS_PARENT_H__ */
fs/xfs/xfs_inode.c +6 -4
index af3f5edb7319..1a35dc972d4d 100644
@@ -2465,16 +2465,18 @@ xfs_iunpin_wait(
  */
 int
 xfs_remove(
-	xfs_inode_t             *dp,
+	struct xfs_inode	*dp,
 	struct xfs_name		*name,
-	xfs_inode_t		*ip)
+	struct xfs_inode	*ip)
 {
-	xfs_mount_t		*mp = dp->i_mount;
-	xfs_trans_t             *tp = NULL;
+	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;
+	xfs_dir2_dataptr_t	dir_offset;
+	struct xfs_parent_defer	*parent = NULL;
 
 	trace_xfs_remove(dp, name);
 
@@ -2489,6 +2491,12 @@ xfs_remove(
 	if (error)
 		goto std_return;

fs/xfs/xfs_inode.c xfs_remove( · line 2502

Quoted 10 lines
fs/xfs/xfs_inode.c +6 -0
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &parent);
+		if (error)
+			goto std_return;
+	}
+
 	/*
 	 * We try to get the real space reservation first, allowing for
 	 * directory btree deletion(s) implying possible bmap insert(s).  If we

Same thing here:

unsigned int
xfs_remove_space_res(
struct xfs_mount *mp,
unsigned int namelen)

{
        unsigned int            ret = XFS_DIRREMOVE_SPACE_RES(mp);

        if (xfs_has_parent(mp))
                ret += xfs_pptr_calc_space_res(mp, namelen);

        return ret;
}

xfs_remove(..)

{
	/* ... */

	resblks = xfs_remove_space_res(mp, name->len);
	error = xfs_trans_alloc_dir(dp, &M_RES(mp)->tr_remove, ip,
			&resblks, &tp, &dontcare);
	/* removal code... */
}

--D

Quoted 42 lines
fs/xfs/xfs_inode.c +11 -2
@@ -2505,7 +2513,7 @@ xfs_remove(
 			&tp, &dontcare);
 	if (error) {
 		ASSERT(error != -ENOSPC);
-		goto std_return;
+		goto drop_incompat;
 	}
 
 	/*
@@ -2559,12 +2567,18 @@ xfs_remove(
 	if (error)
 		goto out_trans_cancel;
 
-	error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, NULL);
+	error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, &dir_offset);
 	if (error) {
 		ASSERT(error != -ENOENT);
 		goto out_trans_cancel;
 	}
 
+	if (parent) {
+		error = xfs_parent_defer_remove(tp, dp, parent, dir_offset, ip);
+		if (error)
+			goto out_trans_cancel;
+	}
+
 	/*
 	 * If this is a synchronous mount, make sure that the
 	 * remove transaction goes to disk before returning to
@@ -2589,6 +2603,9 @@ xfs_remove(
  out_unlock:
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 	xfs_iunlock(dp, XFS_ILOCK_EXCL);
+ drop_incompat:
+	if (parent)
+		xfs_parent_cancel(mp, parent);
  std_return:
 	return error;
 }
Signature · 1 line
2.25.1
#44 lore raw

Re: [PATCH v3 17/26] xfs: remove parent pointers in unlink

Quoted 155 lines · Darrick J. Wong
Quoted 125 lines · On Wed, Sep 21, 2022 at 10:44:49PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch removes the parent pointer attribute during unlink

---
 fs/xfs/libxfs/xfs_attr.c   |  2 +- fs/xfs/libxfs/xfs_attr.h   |  1 + fs/xfs/libxfs/xfs_parent.c | 17 +++++++++++++++++ fs/xfs/libxfs/xfs_parent.h |  4 ++++ fs/xfs/xfs_inode.c         | 29 +++++++++++++++++++++++------

 5 files changed, 46 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 805aaa5639d2..e967728d1ee7 100644
@@ -946,7 +946,7 @@ xfs_attr_defer_replace(
  }


 /* Removes an attribute for an inode as a deferred operation */

fs/xfs/libxfs/xfs_attr.c +1 -1
-static int
+int

 xfs_attr_defer_remove(
        struct xfs_da_args      *args)
 {

fs/xfs/libxfs/xfs_attr.h +1 -0
index 0cf23f5117ad..033005542b9e 100644
@@ -545,6 +545,7 @@ bool xfs_attr_is_leaf(struct xfs_inode *ip);
  int xfs_attr_get_ilocked(struct xfs_da_args *args);
  int xfs_attr_get(struct xfs_da_args *args);
  int xfs_attr_defer_add(struct xfs_da_args *args);
+int xfs_attr_defer_remove(struct xfs_da_args *args);
  int xfs_attr_set(struct xfs_da_args *args);
  int xfs_attr_set_iter(struct xfs_attr_intent *attr);
  int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
fs/xfs/libxfs/xfs_parent.c +0 -0
index dddbf096a4b5..378fa227b87f 100644
@@ -124,6 +124,23 @@ xfs_parent_defer_add(
         return xfs_attr_defer_add(args);
  }

fs/xfs/libxfs/xfs_parent.c +17 -0
+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)
+{
+       struct xfs_da_args      *args = &parent->args;
+
+       xfs_init_parent_name_rec(&parent->rec, dp, diroffset);
+       args->trans = tp;
+       args->dp = child;
+       args->hashval = xfs_da_hashname(args->name, args->namelen);
+       return xfs_attr_defer_remove(args);
+}
+

 void
 xfs_parent_cancel(
        xfs_mount_t             *mp,

fs/xfs/libxfs/xfs_parent.h +0 -0
index 971044458f8a..79d3fabb5e56 100644
@@ -27,6 +27,10 @@ int xfs_parent_init(xfs_mount_t *mp, struct
 xfs_parent_defer **parentp);

 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_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(xfs_mount_t *mp, struct xfs_parent_defer *parent);

 #endif /* __XFS_PARENT_H__ */

fs/xfs/xfs_inode.c +0 -0
index af3f5edb7319..1a35dc972d4d 100644
@@ -2465,16 +2465,18 @@ xfs_iunpin_wait(
   */

 int
 xfs_remove(
-       xfs_inode_t             *dp,
+       struct xfs_inode        *dp,
        struct xfs_name         *name,
-       xfs_inode_t             *ip)
+       struct xfs_inode        *ip)
 {
-       xfs_mount_t             *mp = dp->i_mount; -       xfs_trans_t             *tp = NULL;
+       struct xfs_mount        *mp = dp->i_mount; +       struct xfs_trans        *tp = NULL;
        int                     is_dir = S_ISDIR(VFS_I(ip)-

Quoted 1 line

i_mode);

        int                     dontcare;
        int                     error = 0;
        uint                    resblks;
+       xfs_dir2_dataptr_t      dir_offset;
+       struct xfs_parent_defer *parent = NULL;

        trace_xfs_remove(dp, name);

fs/xfs/xfs_inode.c +0 -0
@@ -2489,6 +2491,12 @@ xfs_remove(
         if (error)
                 goto std_return;


+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &parent); +               if (error)

Quoted 8 lines

+                       goto std_return;
+       }
+
        /*
         * We try to get the real space reservation first, allowing for
         * directory btree deletion(s) implying possible bmap insert(s).  If we

Same thing here:

unsigned int
xfs_remove_space_res(
        struct xfs_mount        *mp,
        unsigned int            namelen)
{
        unsigned int            ret = XFS_DIRREMOVE_SPACE_RES(mp);

        if (xfs_has_parent(mp))
                ret += xfs_pptr_calc_space_res(mp, namelen);

        return ret;
}

xfs_remove(..)
{
        /* ... */

Quoted 5 lines

        resblks = xfs_remove_space_res(mp, name->len); error = xfs_trans_alloc_dir(dp, &M_RES(mp)->tr_remove, ip, &resblks, &tp, &dontcare);
        /* removal code... */
}

Ok, will add these helpers too. Thanks!
Allison

Quoted 48 lines

--D

Quoted 45 lines
fs/xfs/xfs_inode.c +1 -1
@@ -2505,7 +2513,7 @@ xfs_remove(
                         &tp, &dontcare);
         if (error) {
                 ASSERT(error != -ENOSPC);
-               goto std_return;
+               goto drop_incompat;
         }


        /*

fs/xfs/xfs_inode.c +0 -0
@@ -2559,12 +2567,18 @@ xfs_remove(
         if (error)
                 goto out_trans_cancel;


-       error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, NULL);
+       error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, &dir_offset);
        if (error) {
                ASSERT(error != -ENOENT);
                goto out_trans_cancel;
        }

+       if (parent) {
+               error = xfs_parent_defer_remove(tp, dp, parent, dir_offset, ip);
+               if (error)
+                       goto out_trans_cancel;
+       }
+
        /*
         * If this is a synchronous mount, make sure that the
         * remove transaction goes to disk before returning to

fs/xfs/xfs_inode.c +0 -0
@@ -2589,6 +2603,9 @@ xfs_remove(

  out_unlock:
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
        xfs_iunlock(dp, XFS_ILOCK_EXCL);
+ drop_incompat:
+       if (parent)
+               xfs_parent_cancel(mp, parent);
  std_return:
        return error;
 }

Signature · 1 line
2.25.1
#45 lore raw

PATCH v3 18/26 xfs: Add parent pointers to xfs_cross_rename

In reply to [email protected]

From: Allison Henderson <[email protected]>

Cross renames are handled separately from standard renames, and need different handling to update the parent attributes correctly.

---
 fs/xfs/xfs_inode.c | 85 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 70 insertions(+), 15 deletions(-)
fs/xfs/xfs_inode.c +70 -15
index 1a35dc972d4d..51724af22bf9 100644
@@ -2682,27 +2682,49 @@ xfs_finish_rename(
  */
 STATIC int
 xfs_cross_rename(
-	struct xfs_trans	*tp,
-	struct xfs_inode	*dp1,
-	struct xfs_name		*name1,
-	struct xfs_inode	*ip1,
-	struct xfs_inode	*dp2,
-	struct xfs_name		*name2,
-	struct xfs_inode	*ip2,
-	int			spaceres)
+	struct xfs_trans		*tp,
+	struct xfs_inode		*dp1,
+	struct xfs_name			*name1,
+	struct xfs_inode		*ip1,
+	struct xfs_inode		*dp2,
+	struct xfs_name			*name2,
+	struct xfs_inode		*ip2,
+	int				spaceres)
 {
-	int		error = 0;
-	int		ip1_flags = 0;
-	int		ip2_flags = 0;
-	int		dp2_flags = 0;
+	struct xfs_mount		*mp = dp1->i_mount;
+	int				error = 0;
+	int				ip1_flags = 0;
+	int				ip2_flags = 0;
+	int				dp2_flags = 0;
+	int				new_diroffset, old_diroffset;
+	struct xfs_parent_defer		*old_parent_ptr = NULL;
+	struct xfs_parent_defer		*new_parent_ptr = NULL;
+	struct xfs_parent_defer		*old_parent_ptr2 = NULL;
+	struct xfs_parent_defer		*new_parent_ptr2 = NULL;
+
+
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &old_parent_ptr);
+		if (error)
+			goto out_trans_abort;
+		error = xfs_parent_init(mp, &new_parent_ptr);
+		if (error)
+			goto out_trans_abort;
+		error = xfs_parent_init(mp, &old_parent_ptr2);
+		if (error)
+			goto out_trans_abort;
+		error = xfs_parent_init(mp, &new_parent_ptr2);
+		if (error)
+			goto out_trans_abort;
+	}
 
 	/* Swap inode number for dirent in first parent */
-	error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, NULL);
+	error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, &old_diroffset);
 	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, NULL);
+	error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, &new_diroffset);
 	if (error)
 		goto out_trans_abort;
 
@@ -2763,6 +2785,28 @@ xfs_cross_rename(
 		}
 	}
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_defer_replace(tp, dp1,
+						  old_parent_ptr,
+						  old_diroffset,
+						  name2,
+						  dp2,
+						  new_parent_ptr,
+						  new_diroffset, ip1);
+		if (error)
+			goto out_trans_abort;
+
+		error = xfs_parent_defer_replace(tp, dp2,
+						  new_parent_ptr2,
+						  new_diroffset,
+						  name1,
+						  dp1,
+						  old_parent_ptr2,
+						  old_diroffset, 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);
@@ -2777,10 +2821,21 @@ xfs_cross_rename(
 	}
 	xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
 	xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE);
-	return xfs_finish_rename(tp);
 
+	error = xfs_finish_rename(tp);
+	goto out;
 out_trans_abort:
 	xfs_trans_cancel(tp);
+out:
+	if (new_parent_ptr)
+		xfs_parent_cancel(mp, new_parent_ptr);
+	if (old_parent_ptr)
+		xfs_parent_cancel(mp, old_parent_ptr);
+	if (new_parent_ptr2)
+		xfs_parent_cancel(mp, new_parent_ptr2);
+	if (old_parent_ptr2)
+		xfs_parent_cancel(mp, old_parent_ptr2);
+
 	return error;
 }
 
Signature · 1 line
2.25.1
#46 lore raw

Re: [PATCH v3 18/26] xfs: Add parent pointers to xfs_cross_rename

Quoted 54 lines · On Wed, Sep 21, 2022 at 10:44:50PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Cross renames are handled separately from standard renames, and need different handling to update the parent attributes correctly.

---
 fs/xfs/xfs_inode.c | 85 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 70 insertions(+), 15 deletions(-)
fs/xfs/xfs_inode.c +23 -12
index 1a35dc972d4d..51724af22bf9 100644
@@ -2682,27 +2682,49 @@ xfs_finish_rename(
  */
 STATIC int
 xfs_cross_rename(
-	struct xfs_trans	*tp,
-	struct xfs_inode	*dp1,
-	struct xfs_name		*name1,
-	struct xfs_inode	*ip1,
-	struct xfs_inode	*dp2,
-	struct xfs_name		*name2,
-	struct xfs_inode	*ip2,
-	int			spaceres)
+	struct xfs_trans		*tp,
+	struct xfs_inode		*dp1,
+	struct xfs_name			*name1,
+	struct xfs_inode		*ip1,
+	struct xfs_inode		*dp2,
+	struct xfs_name			*name2,
+	struct xfs_inode		*ip2,
+	int				spaceres)
 {
-	int		error = 0;
-	int		ip1_flags = 0;
-	int		ip2_flags = 0;
-	int		dp2_flags = 0;
+	struct xfs_mount		*mp = dp1->i_mount;
+	int				error = 0;
+	int				ip1_flags = 0;
+	int				ip2_flags = 0;
+	int				dp2_flags = 0;
+	int				new_diroffset, old_diroffset;
+	struct xfs_parent_defer		*old_parent_ptr = NULL;
+	struct xfs_parent_defer		*new_parent_ptr = NULL;
+	struct xfs_parent_defer		*old_parent_ptr2 = NULL;
+	struct xfs_parent_defer		*new_parent_ptr2 = NULL;
+
+
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &old_parent_ptr);
+		if (error)

fs/xfs/xfs_inode.c xfs_finish_rename( · line 2718

Quoted 10 lines
fs/xfs/xfs_inode.c +10 -0
+			goto out_trans_abort;
+		error = xfs_parent_init(mp, &new_parent_ptr);
+		if (error)
+			goto out_trans_abort;
+		error = xfs_parent_init(mp, &old_parent_ptr2);
+		if (error)
+			goto out_trans_abort;
+		error = xfs_parent_init(mp, &new_parent_ptr2);
+		if (error)
+			goto out_trans_abort;

Four? I think this means that xfs_calc_rename_reservation needs to do:

	overhead += 4 * (sizeof(struct xfs_attri_log_item) +
				whatever_else);

Right?

The rest of the patch looks fine, though...

Quoted 16 lines
fs/xfs/xfs_inode.c +3 -2
+	}
 
 	/* Swap inode number for dirent in first parent */
-	error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, NULL);
+	error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, &old_diroffset);
 	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, NULL);
+	error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, &new_diroffset);
 	if (error)
 		goto out_trans_abort;
 
@@ -2763,6 +2785,28 @@ xfs_cross_rename(
 		}

fs/xfs/xfs_inode.c xfs_cross_rename( · line 2795

Quoted 10 lines
fs/xfs/xfs_inode.c +8 -0
 	}
 
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_defer_replace(tp, dp1,
+						  old_parent_ptr,
+						  old_diroffset,
+						  name2,
+						  dp2,
+						  new_parent_ptr,
+						  new_diroffset, ip1);

...if you reflowed this to do two-tab indenting instead of kernel-style indenting I wouldn't be sad. ;)

--D

Quoted 43 lines
fs/xfs/xfs_inode.c +26 -1
+		if (error)
+			goto out_trans_abort;
+
+		error = xfs_parent_defer_replace(tp, dp2,
+						  new_parent_ptr2,
+						  new_diroffset,
+						  name1,
+						  dp1,
+						  old_parent_ptr2,
+						  old_diroffset, 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);
@@ -2777,10 +2821,21 @@ xfs_cross_rename(
 	}
 	xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
 	xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE);
-	return xfs_finish_rename(tp);
 
+	error = xfs_finish_rename(tp);
+	goto out;
 out_trans_abort:
 	xfs_trans_cancel(tp);
+out:
+	if (new_parent_ptr)
+		xfs_parent_cancel(mp, new_parent_ptr);
+	if (old_parent_ptr)
+		xfs_parent_cancel(mp, old_parent_ptr);
+	if (new_parent_ptr2)
+		xfs_parent_cancel(mp, new_parent_ptr2);
+	if (old_parent_ptr2)
+		xfs_parent_cancel(mp, old_parent_ptr2);
+
 	return error;
 }
 
Signature · 1 line
2.25.1
#47 lore raw

Re: [PATCH v3 18/26] xfs: Add parent pointers to xfs_cross_rename

Quoted 72 lines · Darrick J. Wong
Quoted 56 lines · On Wed, Sep 21, 2022 at 10:44:50PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Cross renames are handled separately from standard renames, and need different handling to update the parent attributes correctly.

---
 fs/xfs/xfs_inode.c | 85 ++++++++++++++++++++++++++++++++++++++----
----

 1 file changed, 70 insertions(+), 15 deletions(-)
fs/xfs/xfs_inode.c +0 -0
index 1a35dc972d4d..51724af22bf9 100644
@@ -2682,27 +2682,49 @@ xfs_finish_rename(
   */

 STATIC int
 xfs_cross_rename(
-       struct xfs_trans        *tp,
-       struct xfs_inode        *dp1,
-       struct xfs_name         *name1,
-       struct xfs_inode        *ip1,
-       struct xfs_inode        *dp2,
-       struct xfs_name         *name2,
-       struct xfs_inode        *ip2,
-       int                     spaceres)
+       struct xfs_trans                *tp,
+       struct xfs_inode                *dp1,
+       struct xfs_name                 *name1,
+       struct xfs_inode                *ip1,
+       struct xfs_inode                *dp2,
+       struct xfs_name                 *name2,
+       struct xfs_inode                *ip2,
+       int                             spaceres)
 {
-       int             error = 0;
-       int             ip1_flags = 0;
-       int             ip2_flags = 0;
-       int             dp2_flags = 0;
+       struct xfs_mount                *mp = dp1->i_mount; +       int                             error = 0;
+       int                             ip1_flags = 0; +       int                             ip2_flags = 0; +       int                             dp2_flags = 0; +       int                             new_diroffset, old_diroffset;
+       struct xfs_parent_defer         *old_parent_ptr = NULL; +       struct xfs_parent_defer         *new_parent_ptr = NULL; +       struct xfs_parent_defer         *old_parent_ptr2 = NULL; +       struct xfs_parent_defer         *new_parent_ptr2 = NULL;

fs/xfs/xfs_inode.c +5 -0
+
+
+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &old_parent_ptr);
+               if (error)

fs/xfs/xfs_inode.c xfs_finish_rename( · line 2718

Quoted 10 lines
fs/xfs/xfs_inode.c +10 -0
+                       goto out_trans_abort;
+               error = xfs_parent_init(mp, &new_parent_ptr);
+               if (error)
+                       goto out_trans_abort;
+               error = xfs_parent_init(mp, &old_parent_ptr2);
+               if (error)
+                       goto out_trans_abort;
+               error = xfs_parent_init(mp, &new_parent_ptr2);
+               if (error)
+                       goto out_trans_abort;

Four?  I think this means that xfs_calc_rename_reservation needs to do:

Quoted 4 lines

        overhead += 4 * (sizeof(struct xfs_attri_log_item) + whatever_else);

Right?

Ok, I will bump up the overhead in xfs_calc_rename_reservation and see if I can plumb another param through xfs_trans_alloc to add in the additional name/value sizes

Allison

Quoted 85 lines

The rest of the patch looks fine, though...

Quoted 23 lines

+       }

        /* Swap inode number for dirent in first parent */ -       error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, NULL);
+       error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, &old_diroffset);
        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, NULL);
+       error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, &new_diroffset);
        if (error)
                goto out_trans_abort;

fs/xfs/xfs_inode.c +0 -0
@@ -2763,6 +2785,28 @@ xfs_cross_rename(
                 }
         }


+       if (xfs_has_parent(mp)) {

Quoted 8 lines

+               error = xfs_parent_defer_replace(tp, dp1, +                                                 old_parent_ptr, +                                                 old_diroffset, +                                                 name2, +                                                 dp2, +                                                 new_parent_ptr, +                                                 new_diroffset, ip1);

...if you reflowed this to do two-tab indenting instead of kernel- style
indenting I wouldn't be sad. ;)

--D

Quoted 45 lines

+               if (error)
+                       goto out_trans_abort;
+
+               error = xfs_parent_defer_replace(tp, dp2, +                                                 new_parent_ptr2, +                                                 new_diroffset, +                                                 name1, +                                                 dp1, +                                                 old_parent_ptr2, +                                                 old_diroffset, 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);

fs/xfs/xfs_inode.c +0 -0
@@ -2777,10 +2821,21 @@ xfs_cross_rename(
         }

        xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
        xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE); -       return xfs_finish_rename(tp);

+       error = xfs_finish_rename(tp);
+       goto out;
 out_trans_abort:
        xfs_trans_cancel(tp);

fs/xfs/xfs_inode.c +10 -0
+out:
+       if (new_parent_ptr)
+               xfs_parent_cancel(mp, new_parent_ptr);
+       if (old_parent_ptr)
+               xfs_parent_cancel(mp, old_parent_ptr);
+       if (new_parent_ptr2)
+               xfs_parent_cancel(mp, new_parent_ptr2);
+       if (old_parent_ptr2)
+               xfs_parent_cancel(mp, old_parent_ptr2);
+

        return error;
 }

Signature · 1 line
2.25.1
#48 lore raw

PATCH v3 19/26 xfs: Indent xfs_rename

In reply to [email protected]

From: Allison Henderson <[email protected]>

Indent variables and parameters in xfs_rename in preparation for parent pointer modifications. White space only, no functional changes. This will make reviewing new code easier on reviewers.

---
 fs/xfs/xfs_inode.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
fs/xfs/xfs_inode.c +20 -19
index 51724af22bf9..4a8399d35b17 100644
@@ -2891,26 +2891,27 @@ xfs_rename_alloc_whiteout(
  */
 int
 xfs_rename(
-	struct user_namespace	*mnt_userns,
-	struct xfs_inode	*src_dp,
-	struct xfs_name		*src_name,
-	struct xfs_inode	*src_ip,
-	struct xfs_inode	*target_dp,
-	struct xfs_name		*target_name,
-	struct xfs_inode	*target_ip,
-	unsigned int		flags)
+	struct user_namespace		*mnt_userns,
+	struct xfs_inode		*src_dp,
+	struct xfs_name			*src_name,
+	struct xfs_inode		*src_ip,
+	struct xfs_inode		*target_dp,
+	struct xfs_name			*target_name,
+	struct xfs_inode		*target_ip,
+	unsigned int			flags)
 {
-	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];
-	int			i;
-	int			num_inodes = __XFS_SORT_INODES;
-	bool			new_parent = (src_dp != target_dp);
-	bool			src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode);
-	int			spaceres;
-	bool			retried = false;
-	int			error, nospace_error = 0;
+	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];
+	int				i;
+	int				num_inodes = __XFS_SORT_INODES;
+	bool				new_parent = (src_dp != target_dp);
+	bool				src_is_directory =
+						S_ISDIR(VFS_I(src_ip)->i_mode);
+	int				spaceres;
+	bool				retried = false;
+	int				error, nospace_error = 0;
 
 	trace_xfs_rename(src_dp, target_dp, src_name, target_name);
 
Signature · 1 line
2.25.1
Reviewed-by on v3 19/26
#49 lore raw

Re: [PATCH v3 19/26] xfs: Indent xfs_rename

Quoted 7 lines · On Wed, Sep 21, 2022 at 10:44:51PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Indent variables and parameters in xfs_rename in preparation for parent pointer modifications. White space only, no functional changes. This will make reviewing new code easier on reviewers.

Easy enough :)

--D

Quoted 58 lines
---
 fs/xfs/xfs_inode.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
fs/xfs/xfs_inode.c +20 -19
index 51724af22bf9..4a8399d35b17 100644
@@ -2891,26 +2891,27 @@ xfs_rename_alloc_whiteout(
  */
 int
 xfs_rename(
-	struct user_namespace	*mnt_userns,
-	struct xfs_inode	*src_dp,
-	struct xfs_name		*src_name,
-	struct xfs_inode	*src_ip,
-	struct xfs_inode	*target_dp,
-	struct xfs_name		*target_name,
-	struct xfs_inode	*target_ip,
-	unsigned int		flags)
+	struct user_namespace		*mnt_userns,
+	struct xfs_inode		*src_dp,
+	struct xfs_name			*src_name,
+	struct xfs_inode		*src_ip,
+	struct xfs_inode		*target_dp,
+	struct xfs_name			*target_name,
+	struct xfs_inode		*target_ip,
+	unsigned int			flags)
 {
-	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];
-	int			i;
-	int			num_inodes = __XFS_SORT_INODES;
-	bool			new_parent = (src_dp != target_dp);
-	bool			src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode);
-	int			spaceres;
-	bool			retried = false;
-	int			error, nospace_error = 0;
+	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];
+	int				i;
+	int				num_inodes = __XFS_SORT_INODES;
+	bool				new_parent = (src_dp != target_dp);
+	bool				src_is_directory =
+						S_ISDIR(VFS_I(src_ip)->i_mode);
+	int				spaceres;
+	bool				retried = false;
+	int				error, nospace_error = 0;
 
 	trace_xfs_rename(src_dp, target_dp, src_name, target_name);
 
Signature · 1 line
2.25.1
#50 lore raw

Re: [PATCH v3 19/26] xfs: Indent xfs_rename

Quoted 4 lines · Darrick J. Wong
Quoted 2 lines · On Wed, Sep 21, 2022 at 10:44:51PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Quoted 8 lines
Quoted 5 lines

Indent variables and parameters in xfs_rename in preparation for parent pointer modifications.  White space only, no functional changes.  This will make reviewing new code easier on reviewers.

Easy enough :)

Thank you!
Allison

Quoted 67 lines

--D

Quoted 64 lines

---
 fs/xfs/xfs_inode.c | 39 ++++++++++++++++++++-------------------

 1 file changed, 20 insertions(+), 19 deletions(-)
fs/xfs/xfs_inode.c +0 -0
index 51724af22bf9..4a8399d35b17 100644
@@ -2891,26 +2891,27 @@ xfs_rename_alloc_whiteout(
   */

 int
 xfs_rename(
-       struct user_namespace   *mnt_userns,
-       struct xfs_inode        *src_dp,
-       struct xfs_name         *src_name,
-       struct xfs_inode        *src_ip,
-       struct xfs_inode        *target_dp,
-       struct xfs_name         *target_name,
-       struct xfs_inode        *target_ip,
-       unsigned int            flags)
+       struct user_namespace           *mnt_userns,
+       struct xfs_inode                *src_dp,
+       struct xfs_name                 *src_name,
+       struct xfs_inode                *src_ip,
+       struct xfs_inode                *target_dp,
+       struct xfs_name                 *target_name,
+       struct xfs_inode                *target_ip,
+       unsigned int                    flags)
 {
-       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]; -       int                     i;
-       int                     num_inodes = __XFS_SORT_INODES; -       bool                    new_parent = (src_dp != target_dp); -       bool                    src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode);
-       int                     spaceres;
-       bool                    retried = false;
-       int                     error, nospace_error = 0; +       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]; +       int                             i;
+       int                             num_inodes = __XFS_SORT_INODES;
+       bool                            new_parent = (src_dp != target_dp);
+       bool                            src_is_directory = +                                               S_ISDIR(VFS_I(src_i p)->i_mode);
+       int                             spaceres;
+       bool                            retried = false; +       int                             error, nospace_error = 0;
        trace_xfs_rename(src_dp, target_dp, src_name, target_name);

Signature · 1 line
2.25.1
#51 lore raw

PATCH v3 20/26 xfs: Add parent pointers to rename

In reply to [email protected]

From: Allison Henderson <[email protected]>

This patch removes the old parent pointer attribute during the rename operation, and re-adds the updated parent pointer. In the case of xfs_cross_rename, we modify the routine not to roll the transaction just yet. We will do this after the parent pointer is added in the calling xfs_rename function.

---
 fs/xfs/libxfs/xfs_attr.c   |  2 +-
 fs/xfs/libxfs/xfs_attr.h   |  1 +
 fs/xfs/libxfs/xfs_parent.c | 31 +++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  7 ++++
 fs/xfs/xfs_inode.c         | 69 +++++++++++++++++++++++++++++++++++---
 5 files changed, 104 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index e967728d1ee7..3f9bd8401f33 100644
@@ -923,7 +923,7 @@ xfs_attr_defer_add(
 }
 
 /* Sets an attribute for an inode as a deferred operation */
-static int
+int
 xfs_attr_defer_replace(
 	struct xfs_da_args	*args)
 {
fs/xfs/libxfs/xfs_attr.h +1 -0
index 033005542b9e..985761264d1f 100644
@@ -546,6 +546,7 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_defer_add(struct xfs_da_args *args);
 int xfs_attr_defer_remove(struct xfs_da_args *args);
+int xfs_attr_defer_replace(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_iter(struct xfs_attr_intent *attr);
 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
fs/xfs/libxfs/xfs_parent.c +31 -0
index 378fa227b87f..7db1570e1841 100644
@@ -141,6 +141,37 @@ xfs_parent_defer_remove(
 	return xfs_attr_defer_remove(args);
 }
 
+
+int
+xfs_parent_defer_replace(
+	struct xfs_trans	*tp,
+	struct xfs_inode	*old_ip,
+	struct xfs_parent_defer	*old_parent,
+	xfs_dir2_dataptr_t	old_diroffset,
+	struct xfs_name		*parent_name,
+	struct xfs_inode	*new_ip,
+	struct xfs_parent_defer	*new_parent,
+	xfs_dir2_dataptr_t	new_diroffset,
+	struct xfs_inode	*child)
+{
+	struct xfs_da_args	*args = &new_parent->args;
+
+	xfs_init_parent_name_rec(&old_parent->rec, old_ip, old_diroffset);
+	xfs_init_parent_name_rec(&new_parent->rec, new_ip, new_diroffset);
+	new_parent->args.name = (const uint8_t *)&old_parent->rec;
+	new_parent->args.namelen = sizeof(struct xfs_parent_name_rec);
+	new_parent->args.new_name = (const uint8_t *)&new_parent->rec;
+	new_parent->args.new_namelen = sizeof(struct xfs_parent_name_rec);
+	args->trans = tp;
+	args->dp = child;
+	if (parent_name) {
+		new_parent->args.value = (void *)parent_name->name;
+		new_parent->args.valuelen = parent_name->len;
+	}
+	args->hashval = xfs_da_hashname(args->name, args->namelen);
+	return xfs_attr_defer_replace(args);
+}
+
 void
 xfs_parent_cancel(
 	xfs_mount_t		*mp,
fs/xfs/libxfs/xfs_parent.h +7 -0
index 79d3fabb5e56..b2ed4f373799 100644
@@ -27,6 +27,13 @@ int xfs_parent_init(xfs_mount_t *mp, struct xfs_parent_defer **parentp);
 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, struct xfs_inode *old_ip,
+			 struct xfs_parent_defer *old_parent,
+			 xfs_dir2_dataptr_t old_diroffset,
+			 struct xfs_name *parent_name, struct xfs_inode *new_ip,
+			 struct xfs_parent_defer *new_parent,
+			 xfs_dir2_dataptr_t new_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,
fs/xfs/xfs_inode.c +64 -5

117 lines not on this page · raw message

Signature · 1 line
2.25.1
#52 lore raw

Re: [PATCH v3 20/26] xfs: Add parent pointers to rename

Quoted 144 lines · On Wed, Sep 21, 2022 at 10:44:52PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch removes the old parent pointer attribute during the rename operation, and re-adds the updated parent pointer. In the case of xfs_cross_rename, we modify the routine not to roll the transaction just yet. We will do this after the parent pointer is added in the calling xfs_rename function.

---
 fs/xfs/libxfs/xfs_attr.c   |  2 +-
 fs/xfs/libxfs/xfs_attr.h   |  1 +
 fs/xfs/libxfs/xfs_parent.c | 31 +++++++++++++++++
 fs/xfs/libxfs/xfs_parent.h |  7 ++++
 fs/xfs/xfs_inode.c         | 69 +++++++++++++++++++++++++++++++++++---
 5 files changed, 104 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index e967728d1ee7..3f9bd8401f33 100644
@@ -923,7 +923,7 @@ xfs_attr_defer_add(
 }
 
 /* Sets an attribute for an inode as a deferred operation */
-static int
+int
 xfs_attr_defer_replace(
 	struct xfs_da_args	*args)
 {
fs/xfs/libxfs/xfs_attr.h +1 -0
index 033005542b9e..985761264d1f 100644
@@ -546,6 +546,7 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_defer_add(struct xfs_da_args *args);
 int xfs_attr_defer_remove(struct xfs_da_args *args);
+int xfs_attr_defer_replace(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_iter(struct xfs_attr_intent *attr);
 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
fs/xfs/libxfs/xfs_parent.c +31 -0
index 378fa227b87f..7db1570e1841 100644
@@ -141,6 +141,37 @@ xfs_parent_defer_remove(
 	return xfs_attr_defer_remove(args);
 }
 
+
+int
+xfs_parent_defer_replace(
+	struct xfs_trans	*tp,
+	struct xfs_inode	*old_ip,
+	struct xfs_parent_defer	*old_parent,
+	xfs_dir2_dataptr_t	old_diroffset,
+	struct xfs_name		*parent_name,
+	struct xfs_inode	*new_ip,
+	struct xfs_parent_defer	*new_parent,
+	xfs_dir2_dataptr_t	new_diroffset,
+	struct xfs_inode	*child)
+{
+	struct xfs_da_args	*args = &new_parent->args;
+
+	xfs_init_parent_name_rec(&old_parent->rec, old_ip, old_diroffset);
+	xfs_init_parent_name_rec(&new_parent->rec, new_ip, new_diroffset);
+	new_parent->args.name = (const uint8_t *)&old_parent->rec;
+	new_parent->args.namelen = sizeof(struct xfs_parent_name_rec);
+	new_parent->args.new_name = (const uint8_t *)&new_parent->rec;
+	new_parent->args.new_namelen = sizeof(struct xfs_parent_name_rec);
+	args->trans = tp;
+	args->dp = child;
+	if (parent_name) {
+		new_parent->args.value = (void *)parent_name->name;
+		new_parent->args.valuelen = parent_name->len;
+	}
+	args->hashval = xfs_da_hashname(args->name, args->namelen);
+	return xfs_attr_defer_replace(args);
+}
+
 void
 xfs_parent_cancel(
 	xfs_mount_t		*mp,
fs/xfs/libxfs/xfs_parent.h +7 -0
index 79d3fabb5e56..b2ed4f373799 100644
@@ -27,6 +27,13 @@ int xfs_parent_init(xfs_mount_t *mp, struct xfs_parent_defer **parentp);
 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, struct xfs_inode *old_ip,
+			 struct xfs_parent_defer *old_parent,
+			 xfs_dir2_dataptr_t old_diroffset,
+			 struct xfs_name *parent_name, struct xfs_inode *new_ip,
+			 struct xfs_parent_defer *new_parent,
+			 xfs_dir2_dataptr_t new_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,
fs/xfs/xfs_inode.c +19 -1
index 4a8399d35b17..3a2bec4ba228 100644
@@ -2912,6 +2912,12 @@ xfs_rename(
 	int				spaceres;
 	bool				retried = false;
 	int				error, nospace_error = 0;
+	xfs_dir2_dataptr_t		new_diroffset;
+	xfs_dir2_dataptr_t		old_diroffset;
+	struct xfs_parent_defer		*old_parent_ptr = NULL;
+	struct xfs_parent_defer		*new_parent_ptr = NULL;
+	struct xfs_parent_defer		*target_parent_ptr = NULL;
+	struct xfs_parent_defer		*wip_parent_ptr = NULL;
 
 	trace_xfs_rename(src_dp, target_dp, src_name, target_name);
 
@@ -2925,7 +2931,8 @@ xfs_rename(
 	 */
 	if (flags & RENAME_WHITEOUT) {
 		error = xfs_rename_alloc_whiteout(mnt_userns, src_name,
-						  target_dp, false, &wip);
+						  target_dp, xfs_has_parent(mp),
+						  &wip);
 		if (error)
 			return error;
 
@@ -2935,6 +2942,24 @@ xfs_rename(
 
 	xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, wip,
 				inodes, &num_inodes);
+	if (xfs_has_parent(mp)) {
+		error = xfs_parent_init(mp, &old_parent_ptr);
+		if (error)
+			goto out_release_wip;
+		error = xfs_parent_init(mp, &new_parent_ptr);
+		if (error)
+			goto out_release_wip;
+		if (wip) {
+			error = xfs_parent_init(mp, &wip_parent_ptr);
+			if (error)
+				goto out_release_wip;

fs/xfs/xfs_inode.c xfs_rename( · line 2965

Quoted 10 lines
fs/xfs/xfs_inode.c +7 -0
+		}
+		if (target_ip != NULL) {
+			error = xfs_parent_init(mp, &target_parent_ptr);
+			if (error)
+				goto out_release_wip;
+		}
+	}
 
 retry:
 	nospace_error = 0;

Same block reservation comment as most of the previous ones, except this one is super nasty:

unsigned int
xfs_rename_space_res(
struct xfs_mount *mp,
struct xfs_name *src_name,
struct xfs_parent_defer *target_parent_ptr,
struct xfs_name *target_name,
struct xfs_parent_defer *new_parent_ptr,
struct xfs_inode *wip)

{
	unsigned int		ret;

	/* XXX is the target_name->len usage below correct? */
	ret = XFS_DIRREMOVE_SPACE_RES(mp) +
			XFS_DIRENTER_SPACE_RES(mp, target_name->len);

	if (new_parent_ptr) {
		if (wip)
			ret += xfs_pptr_calc_space_res(mp, src_name->len);
		ret += 2 * xfs_pptr_calc_space_res(mp, target_name->len);
	}
	if (target_parent_ptr)
		ret += xfs_pptr_calc_space_res(mp, target_name->len);

	return ret;
}

xfs_rename(...)

{
	spacres = xfs_rename_space_res(mp, src_name, target_parent_ptr,
			target_name, new_parent_ptr, wip);
	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, spaceres, 0,
			0, &tp);
	/* ... */
}

(The rest of the logic looks ok now.)

--D

Quoted 79 lines
fs/xfs/xfs_inode.c +38 -4
@@ -3110,7 +3135,7 @@ xfs_rename(
 		 * to account for the ".." reference from the new entry.
 		 */
 		error = xfs_dir_createname(tp, target_dp, target_name,
-					   src_ip->i_ino, spaceres, NULL);
+					   src_ip->i_ino, spaceres, &new_diroffset);
 		if (error)
 			goto out_trans_cancel;
 
@@ -3131,7 +3156,7 @@ xfs_rename(
 		 * name at the destination directory, remove it first.
 		 */
 		error = xfs_dir_replace(tp, target_dp, target_name,
-					src_ip->i_ino, spaceres, NULL);
+					src_ip->i_ino, spaceres, &new_diroffset);
 		if (error)
 			goto out_trans_cancel;
 
@@ -3204,14 +3229,39 @@ xfs_rename(
 	 */
 	if (wip)
 		error = xfs_dir_replace(tp, src_dp, src_name, wip->i_ino,
-					spaceres, NULL);
+					spaceres, &old_diroffset);
 	else
 		error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino,
-					   spaceres, NULL);
+					   spaceres, &old_diroffset);
 
 	if (error)
 		goto out_trans_cancel;
 
+	if (new_parent_ptr) {
+		if (wip) {
+			error = xfs_parent_defer_add(tp, wip_parent_ptr,
+						     src_dp, src_name,
+						     old_diroffset, wip);
+			if (error)
+				goto out_trans_cancel;
+		}
+
+		error = xfs_parent_defer_replace(tp, src_dp, old_parent_ptr,
+						 old_diroffset, target_name,
+						 target_dp, new_parent_ptr,
+						 new_diroffset, src_ip);
+		if (error)
+			goto out_trans_cancel;
+	}
+
+	if (target_parent_ptr) {
+		error = xfs_parent_defer_remove(tp, target_dp,
+						target_parent_ptr,
+						new_diroffset, 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)
@@ -3234,6 +3284,15 @@ xfs_rename(
 			i--;
 	}
 out_release_wip:
+	if (new_parent_ptr)
+		xfs_parent_cancel(mp, new_parent_ptr);
+	if (old_parent_ptr)
+		xfs_parent_cancel(mp, old_parent_ptr);
+	if (target_parent_ptr)
+		xfs_parent_cancel(mp, target_parent_ptr);
+	if (wip_parent_ptr)
+		xfs_parent_cancel(mp, wip_parent_ptr);
+
 	if (wip)
 		xfs_irele(wip);
 	if (error == -ENOSPC && nospace_error)
Signature · 1 line
2.25.1
#53 lore raw

Re: [PATCH v3 20/26] xfs: Add parent pointers to rename

Quoted 214 lines · Darrick J. Wong
Quoted 171 lines · On Wed, Sep 21, 2022 at 10:44:52PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

This patch removes the old parent pointer attribute during the rename
operation, and re-adds the updated parent pointer.  In the case of xfs_cross_rename, we modify the routine not to roll the transaction just
yet.  We will do this after the parent pointer is added in the calling
xfs_rename function.

---
 fs/xfs/libxfs/xfs_attr.c   |  2 +- fs/xfs/libxfs/xfs_attr.h   |  1 + fs/xfs/libxfs/xfs_parent.c | 31 +++++++++++++++++ fs/xfs/libxfs/xfs_parent.h |  7 ++++ fs/xfs/xfs_inode.c         | 69
+++++++++++++++++++++++++++++++++++---

 5 files changed, 104 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index e967728d1ee7..3f9bd8401f33 100644
@@ -923,7 +923,7 @@ xfs_attr_defer_add(
  }


 /* Sets an attribute for an inode as a deferred operation */

fs/xfs/libxfs/xfs_attr.c +1 -1
-static int
+int

 xfs_attr_defer_replace(
        struct xfs_da_args      *args)
 {

fs/xfs/libxfs/xfs_attr.h +1 -0
index 033005542b9e..985761264d1f 100644
@@ -546,6 +546,7 @@ int xfs_attr_get_ilocked(struct xfs_da_args
 *args);
  int xfs_attr_get(struct xfs_da_args *args);
  int xfs_attr_defer_add(struct xfs_da_args *args);
  int xfs_attr_defer_remove(struct xfs_da_args *args);
+int xfs_attr_defer_replace(struct xfs_da_args *args);
  int xfs_attr_set(struct xfs_da_args *args);
  int xfs_attr_set_iter(struct xfs_attr_intent *attr);

 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);

fs/xfs/libxfs/xfs_parent.c +0 -0
index 378fa227b87f..7db1570e1841 100644
@@ -141,6 +141,37 @@ xfs_parent_defer_remove(
         return xfs_attr_defer_remove(args);
  }

fs/xfs/libxfs/xfs_parent.c +16 -0
+
+int
+xfs_parent_defer_replace(
+       struct xfs_trans        *tp,
+       struct xfs_inode        *old_ip,
+       struct xfs_parent_defer *old_parent,
+       xfs_dir2_dataptr_t      old_diroffset,
+       struct xfs_name         *parent_name,
+       struct xfs_inode        *new_ip,
+       struct xfs_parent_defer *new_parent,
+       xfs_dir2_dataptr_t      new_diroffset,
+       struct xfs_inode        *child)
+{
+       struct xfs_da_args      *args = &new_parent->args;
+
+       xfs_init_parent_name_rec(&old_parent->rec, old_ip,

old_diroffset);
+       xfs_init_parent_name_rec(&new_parent->rec, new_ip, new_diroffset);
+       new_parent->args.name = (const uint8_t *)&old_parent->rec; +       new_parent->args.namelen = sizeof(struct xfs_parent_name_rec);
+       new_parent->args.new_name = (const uint8_t *)&new_parent-

Quoted 1 line

rec;

+       new_parent->args.new_namelen = sizeof(struct xfs_parent_name_rec);
+       args->trans = tp;
+       args->dp = child;
+       if (parent_name) {
+               new_parent->args.value = (void *)parent_name->name; +               new_parent->args.valuelen = parent_name->len; +       }
+       args->hashval = xfs_da_hashname(args->name, args->namelen); +       return xfs_attr_defer_replace(args);

fs/xfs/libxfs/xfs_parent.c +2 -0
+}
+

 void
 xfs_parent_cancel(
        xfs_mount_t             *mp,

fs/xfs/libxfs/xfs_parent.h +0 -0
index 79d3fabb5e56..b2ed4f373799 100644
@@ -27,6 +27,13 @@ int xfs_parent_init(xfs_mount_t *mp, struct
 xfs_parent_defer **parentp);

 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, struct xfs_inode *old_ip,
+                        struct xfs_parent_defer *old_parent, +                        xfs_dir2_dataptr_t old_diroffset, +                        struct xfs_name *parent_name, struct xfs_inode *new_ip,
+                        struct xfs_parent_defer *new_parent, +                        xfs_dir2_dataptr_t new_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,

fs/xfs/xfs_inode.c +6 -0
index 4a8399d35b17..3a2bec4ba228 100644
@@ -2912,6 +2912,12 @@ xfs_rename(
         int                             spaceres;
         bool                            retried = false;
         int                             error, nospace_error = 0;
+       xfs_dir2_dataptr_t              new_diroffset;
+       xfs_dir2_dataptr_t              old_diroffset;
+       struct xfs_parent_defer         *old_parent_ptr = NULL;
+       struct xfs_parent_defer         *new_parent_ptr = NULL;
+       struct xfs_parent_defer         *target_parent_ptr = NULL;
+       struct xfs_parent_defer         *wip_parent_ptr = NULL;


        trace_xfs_rename(src_dp, target_dp, src_name, target_name);

fs/xfs/xfs_inode.c +2 -1
@@ -2925,7 +2931,8 @@ xfs_rename(
          */
         if (flags & RENAME_WHITEOUT) {
                 error = xfs_rename_alloc_whiteout(mnt_userns,
 src_name,
-                                                 target_dp, false,
 &wip);
+                                                 target_dp,
 xfs_has_parent(mp),
+                                                 &wip);

                if (error)
                        return error;

fs/xfs/xfs_inode.c +0 -0
@@ -2935,6 +2942,24 @@ xfs_rename(


        xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, wip,
                                inodes, &num_inodes);
+       if (xfs_has_parent(mp)) {
+               error = xfs_parent_init(mp, &old_parent_ptr); +               if (error)
+                       goto out_release_wip;
+               error = xfs_parent_init(mp, &new_parent_ptr); +               if (error)
+                       goto out_release_wip;
+               if (wip) {
+                       error = xfs_parent_init(mp, &wip_parent_ptr);
+                       if (error)
+                               goto out_release_wip;
+               }
+               if (target_ip != NULL) {
+                       error = xfs_parent_init(mp,

Quoted 8 lines

&target_parent_ptr);
+                       if (error)
+                               goto out_release_wip; +               }
+       }

 retry:
        nospace_error = 0;

Same block reservation comment as most of the previous ones, except this
one is super nasty:

unsigned int
xfs_rename_space_res(
        struct xfs_mount        *mp,
        struct xfs_name         *src_name, struct xfs_parent_defer *target_parent_ptr, struct xfs_name         *target_name, struct xfs_parent_defer *new_parent_ptr, struct xfs_inode        *wip)
{
        unsigned int            ret;

        /* XXX is the target_name->len usage below correct? */ ret = XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, target_name->len);

        if (new_parent_ptr) {
                if (wip)
                        ret += xfs_pptr_calc_space_res(mp, src_name-

Quoted 1 line

len);

                ret += 2 * xfs_pptr_calc_space_res(mp, target_name-

Quoted 1 line

len);

        }
        if (target_parent_ptr)
                ret += xfs_pptr_calc_space_res(mp, target_name->len);

        return ret;
}

Quoted 11 lines

xfs_rename(...)
{
        spacres = xfs_rename_space_res(mp, src_name, target_parent_ptr,
                        target_name, new_parent_ptr, wip); error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, spaceres, 0,
                        0, &tp);
        /* ... */
}

Ok, will add these helpers to the xfs_*_space_res collection. Thanks!

Allison

Quoted 102 lines

(The rest of the logic looks ok now.)

--D

Quoted 98 lines
fs/xfs/xfs_inode.c +0 -0
@@ -3110,7 +3135,7 @@ xfs_rename(
                  * to account for the ".." reference from the new

entry.
                 */
                error = xfs_dir_createname(tp, target_dp, target_name,
-                                          src_ip->i_ino, spaceres, NULL);
+                                          src_ip->i_ino, spaceres, &new_diroffset);
                if (error)
                        goto out_trans_cancel;

fs/xfs/xfs_inode.c +0 -0
@@ -3131,7 +3156,7 @@ xfs_rename(
                  * name at the destination directory, remove it

first.
                 */
                error = xfs_dir_replace(tp, target_dp, target_name, -                                       src_ip->i_ino, spaceres, NULL);
+                                       src_ip->i_ino, spaceres, &new_diroffset);
                if (error)
                        goto out_trans_cancel;

fs/xfs/xfs_inode.c +0 -0
@@ -3204,14 +3229,39 @@ xfs_rename(
          */
         if (wip)

                error = xfs_dir_replace(tp, src_dp, src_name, wip-

Quoted 1 line

i_ino,

-                                       spaceres, NULL); +                                       spaceres, &old_diroffset); else
                error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino,
-                                          spaceres, NULL); +                                          spaceres, &old_diroffset);

        if (error)
                goto out_trans_cancel;

+       if (new_parent_ptr) {
+               if (wip) {
+                       error = xfs_parent_defer_add(tp, wip_parent_ptr,
+                                                    src_dp, src_name,
+                                                    old_diroffset, wip);
+                       if (error)
+                               goto out_trans_cancel;
+               }
+
+               error = xfs_parent_defer_replace(tp, src_dp, old_parent_ptr,
+                                                old_diroffset, target_name,
+                                                target_dp, new_parent_ptr,
+                                                new_diroffset, src_ip);
+               if (error)
+                       goto out_trans_cancel;
+       }
+
+       if (target_parent_ptr) {
+               error = xfs_parent_defer_remove(tp, target_dp, +                                               target_parent_ptr, +                                               new_diroffset, 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)

fs/xfs/xfs_inode.c +0 -0
@@ -3234,6 +3284,15 @@ xfs_rename(
                         i--;
         }

 out_release_wip:
+       if (new_parent_ptr)
+               xfs_parent_cancel(mp, new_parent_ptr); +       if (old_parent_ptr)
+               xfs_parent_cancel(mp, old_parent_ptr); +       if (target_parent_ptr)
+               xfs_parent_cancel(mp, target_parent_ptr); +       if (wip_parent_ptr)
+               xfs_parent_cancel(mp, wip_parent_ptr); +
        if (wip)
                xfs_irele(wip);
        if (error == -ENOSPC && nospace_error)

Signature · 1 line
2.25.1
#54 lore raw

PATCH v3 21/26 xfs: Add the parent pointer support to the superblock version 5.

In reply to [email protected]

From: Allison Henderson <[email protected]>

---
 fs/xfs/libxfs/xfs_format.h | 4 +++-
 fs/xfs/libxfs/xfs_fs.h     | 1 +
 fs/xfs/libxfs/xfs_sb.c     | 4 ++++
 fs/xfs/xfs_super.c         | 4 ++++
 4 files changed, 12 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_format.h +3 -1
index b55bdfa9c8a8..0343f8586be3 100644
@@ -373,13 +373,15 @@ xfs_sb_has_ro_compat_feature(
 #define XFS_SB_FEAT_INCOMPAT_BIGTIME	(1 << 3)	/* large timestamps */
 #define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4)	/* needs xfs_repair */
 #define XFS_SB_FEAT_INCOMPAT_NREXT64	(1 << 5)	/* large extent counters */
+#define XFS_SB_FEAT_INCOMPAT_PARENT	(1 << 6)	/* parent pointers */
 #define XFS_SB_FEAT_INCOMPAT_ALL \
 		(XFS_SB_FEAT_INCOMPAT_FTYPE|	\
 		 XFS_SB_FEAT_INCOMPAT_SPINODES|	\
 		 XFS_SB_FEAT_INCOMPAT_META_UUID| \
 		 XFS_SB_FEAT_INCOMPAT_BIGTIME| \
 		 XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR| \
-		 XFS_SB_FEAT_INCOMPAT_NREXT64)
+		 XFS_SB_FEAT_INCOMPAT_NREXT64| \
+		 XFS_SB_FEAT_INCOMPAT_PARENT)
 
 #define XFS_SB_FEAT_INCOMPAT_UNKNOWN	~XFS_SB_FEAT_INCOMPAT_ALL
 static inline bool
fs/xfs/libxfs/xfs_fs.h +1 -0
index 1cfd5bc6520a..b0b4d7a3aa15 100644
@@ -237,6 +237,7 @@ typedef struct xfs_fsop_resblks {
 #define XFS_FSOP_GEOM_FLAGS_BIGTIME	(1 << 21) /* 64-bit nsec timestamps */
 #define XFS_FSOP_GEOM_FLAGS_INOBTCNT	(1 << 22) /* inobt btree counter */
 #define XFS_FSOP_GEOM_FLAGS_NREXT64	(1 << 23) /* large extent counters */
+#define XFS_FSOP_GEOM_FLAGS_PARENT	(1 << 24) /* parent pointers 	    */
 
 /*
  * Minimum and maximum sizes need for growth checks.
fs/xfs/libxfs/xfs_sb.c +4 -0
index a20cade590e9..75e893e93629 100644
@@ -173,6 +173,8 @@ xfs_sb_version_to_features(
 		features |= XFS_FEAT_NEEDSREPAIR;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NREXT64)
 		features |= XFS_FEAT_NREXT64;
+	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_PARENT)
+		features |= XFS_FEAT_PARENT;
 
 	return features;
 }
@@ -1187,6 +1189,8 @@ xfs_fs_geometry(
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_BIGTIME;
 	if (xfs_has_inobtcounts(mp))
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_INOBTCNT;
+	if (xfs_has_parent(mp))
+		geo->flags |= XFS_FSOP_GEOM_FLAGS_PARENT;
 	if (xfs_has_sector(mp)) {
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR;
 		geo->logsectsize = sbp->sb_logsectsize;
fs/xfs/xfs_super.c +4 -0
index 9ac59814bbb6..55957e53526a 100644
@@ -1657,6 +1657,10 @@ xfs_fs_fill_super(
 		xfs_warn(mp,
 	"EXPERIMENTAL Large extent counts feature in use. Use at your own risk!");
 
+	if (xfs_has_parent(mp))
+		xfs_alert(mp,
+	"EXPERIMENTAL parent pointer feature enabled. Use at your own risk!");
+
 	error = xfs_mountfs(mp);
 	if (error)
 		goto out_filestream_unmount;
Signature · 1 line
2.25.1
#55 lore raw

PATCH v3 22/26 xfs: Add helper function xfs_attr_list_context_init

In reply to [email protected]

From: Allison Henderson <[email protected]>

This patch adds a helper function xfs_attr_list_context_init used by xfs_attr_list. This function initializes the xfs_attr_list_context structure passed to xfs_attr_list_int. We will need this later to call xfs_attr_list_int_ilocked when the node is already locked.

---
 fs/xfs/xfs_file.c  |  1 +
 fs/xfs/xfs_ioctl.c | 54 ++++++++++++++++++++++++++++++++--------------
 fs/xfs/xfs_ioctl.h |  2 ++
 3 files changed, 41 insertions(+), 16 deletions(-)
fs/xfs/xfs_file.c +1 -0
index c6c80265c0b2..cb456fd92b72 100644
@@ -17,6 +17,7 @@
 #include "xfs_bmap_util.h"
 #include "xfs_dir2.h"
 #include "xfs_dir2_priv.h"
+#include "xfs_attr.h"
 #include "xfs_ioctl.h"
 #include "xfs_trace.h"
 #include "xfs_log.h"
fs/xfs/xfs_ioctl.c +38 -16

72 lines not on this page · raw message

fs/xfs/xfs_ioctl.h +2 -0
index d4abba2c13c1..ca60e1c427a3 100644
@@ -35,6 +35,8 @@ int xfs_ioc_attrmulti_one(struct file *parfilp, struct inode *inode,
 int xfs_ioc_attr_list(struct xfs_inode *dp, void __user *ubuf,
 		      size_t bufsize, int flags,
 		      struct xfs_attrlist_cursor __user *ucursor);
+int xfs_ioc_attr_list_context_init(struct xfs_inode *dp, char *buffer,
+		int bufsize, int flags, struct xfs_attr_list_context *context);
 
 extern struct dentry *
 xfs_handle_to_dentry(
Signature · 1 line
2.25.1
#56 lore raw

PATCH v3 23/26 xfs: Filter XFS_ATTR_PARENT for getfattr

In reply to [email protected]

From: Allison Henderson <[email protected]>

Parent pointers returned to the get_fattr tool cause errors since the tool cannot parse parent pointers. Fix this by filtering parent parent pointers from xfs_attr_list.

---
 fs/xfs/libxfs/xfs_da_format.h |  3 +++
 fs/xfs/xfs_attr_list.c        | 47 +++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_da_format.h +3 -0
index b02b67f1999e..e9c323fab6f3 100644
@@ -697,6 +697,9 @@ struct xfs_attr3_leafblock {
 #define XFS_ATTR_INCOMPLETE	(1u << XFS_ATTR_INCOMPLETE_BIT)
 #define XFS_ATTR_NSP_ONDISK_MASK \
 			(XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT)
+#define XFS_ATTR_ALL \
+	(XFS_ATTR_LOCAL_BIT | XFS_ATTR_ROOT | XFS_ATTR_SECURE | \
+	 XFS_ATTR_PARENT | XFS_ATTR_INCOMPLETE_BIT)
 
 /*
  * Alignment for namelist and valuelist entries (since they are mixed
fs/xfs/xfs_attr_list.c +36 -11

78 lines not on this page · raw message

Signature · 1 line
2.25.1
#57 lore raw

Re: [PATCH v3 23/26] xfs: Filter XFS_ATTR_PARENT for getfattr

Some additional comments on this new one. I think maybe this should have been an rfc since xfs_attr_list doesnt have any existing filtration logic. So with out assuming what behavior people would prefer it to have, I've applied the minimal amount of change that solves the problem for now. Suggestions welcome though, I assumed probably people will want to discuss other solutions during the review. Thanks!

Allison

Quoted 126 lines · On Wed, 2022-09-21 at 22:44 -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Parent pointers returned to the get_fattr tool cause errors since the tool cannot parse parent pointers.  Fix this by filtering parent parent pointers from xfs_attr_list.

---
 fs/xfs/libxfs/xfs_da_format.h |  3 +++ fs/xfs/xfs_attr_list.c        | 47 +++++++++++++++++++++++++++------ --

 2 files changed, 39 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_da_format.h +0 -0
index b02b67f1999e..e9c323fab6f3 100644
@@ -697,6 +697,9 @@ struct xfs_attr3_leafblock {
  #define XFS_ATTR_INCOMPLETE    (1u << XFS_ATTR_INCOMPLETE_BIT)
  #define XFS_ATTR_NSP_ONDISK_MASK \

                        (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT)
+#define XFS_ATTR_ALL \
+       (XFS_ATTR_LOCAL_BIT | XFS_ATTR_ROOT | XFS_ATTR_SECURE | \
+        XFS_ATTR_PARENT | XFS_ATTR_INCOMPLETE_BIT)

 /*
  * Alignment for namelist and valuelist entries (since they are mixed

fs/xfs/xfs_attr_list.c +0 -0
index a51f7f13a352..13de597c4996 100644
@@ -39,6 +39,23 @@ xfs_attr_shortform_compare(const void *a, const
 void *b)
         }
  }

fs/xfs/xfs_attr_list.c +17 -0
+/*
+ * Returns true or false if the parent attribute should be listed
+ */
+static bool
+xfs_attr_filter_parent(
+       struct xfs_attr_list_context    *context,
+       int                             flags)
+{
+       if (!(flags & XFS_ATTR_PARENT))
+               return true;
+
+       if (context->attr_filter & XFS_ATTR_PARENT)
+               return true;
+
+       return false;
+}
+

 #define XFS_ISRESET_CURSOR(cursor) \
        (!((cursor)->initted) && !((cursor)->hashval) && \
         !((cursor)->blkno) && !((cursor)->offset))

fs/xfs/xfs_attr_list.c +0 -0
@@ -90,11 +107,12 @@ xfs_attr_shortform_list(

                                                               sfe-

Quoted 1 line

namelen,

                                                               sfe-

Quoted 1 line

flags)))

                                return -EFSCORRUPTED;
-                       context->put_listent(context,
-                                            sfe->flags, -                                            sfe->nameval, -                                            (int)sfe->namelen, -                                            (int)sfe->valuelen); +                       if (xfs_attr_filter_parent(context, sfe-

Quoted 1 line

flags))

+                               context->put_listent(context, +                                                    sfe->flags, +                                                    sfe->nameval, +                                                    (int)sfe-

Quoted 1 line

namelen,

+                                                    (int)sfe-

Quoted 1 line

valuelen);

                        /*
                         * Either search callback finished early or
                         * didn't fit it all in the buffer after all.

fs/xfs/xfs_attr_list.c +6 -5
@@ -185,11 +203,12 @@ xfs_attr_shortform_list(
                         error = -EFSCORRUPTED;
                         goto out;
                 }
-               context->put_listent(context,
-                                    sbp->flags,
-                                    sbp->name,
-                                    sbp->namelen,
-                                    sbp->valuelen);
+               if (xfs_attr_filter_parent(context, sbp->flags))
+                       context->put_listent(context,
+                                            sbp->flags,
+                                            sbp->name,
+                                            sbp->namelen,
+                                            sbp->valuelen);
                 if (context->seen_enough)
                         break;
                 cursor->offset++;
@@ -474,8 +493,10 @@ xfs_attr3_leaf_list_int(
                                    !xfs_attr_namecheck(mp, name,
 namelen,

                                                       entry-

Quoted 1 line

flags)))

                        return -EFSCORRUPTED;
-               context->put_listent(context, entry->flags, +               if (xfs_attr_filter_parent(context, entry->flags)) +                       context->put_listent(context, entry->flags, name, namelen, valuelen);
+
                if (context->seen_enough)
                        break;
                cursor->offset++;

fs/xfs/xfs_attr_list.c +0 -0
@@ -539,6 +560,10 @@ xfs_attr_list(
         if (xfs_is_shutdown(dp->i_mount))
                 return -EIO;


+       if (context->attr_filter == 0)
+               context->attr_filter =
+                       XFS_ATTR_ALL & ~XFS_ATTR_PARENT; +
        lock_mode = xfs_ilock_attr_map_shared(dp); error = xfs_attr_list_ilocked(context); xfs_iunlock(dp, lock_mode);

#58 lore raw

Re: [PATCH v3 23/26] xfs: Filter XFS_ATTR_PARENT for getfattr

In reply to [email protected]
Quoted 5 lines · On Wed, Sep 21, 2022 at 10:44:55PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Parent pointers returned to the get_fattr tool cause errors since the tool cannot parse parent pointers. Fix this by filtering parent parent pointers from xfs_attr_list.

Yes!! Parent pointers should /never/ be accessible by the standard VFS xattr syscalls, nor should the XFS ATTR_MULTI calls handle them.

Changes to parent pointers are performed via separate syscalls (link/unlink/mknod/creat/etc), and I see you've created a separate parent pointer ioctl later on for userspace to retrieve them. I think this is the correct access model.

To check that assertion -- getxattr/setxattr/removexattr (and the ATTRMULTI equivalents) are prevented from accessing parent pointers directly because you'd have to be able to set XFS_ATTR_PARENT in xfs_da_args.attr_filter, right?

And for the VFS to get/set/remove a parent pointer, XFS would have to provide a struct xattr_handler with ->flags = XFS_ATTR_PARENT, which XFS will never do, right?

And for ATTR_MULTI to touch a parent pointer, xfs_attr_filter (and the ioctl api) would have to learn about XFS_ATTR_PARENT, which XFS will also never do, right?

If the answers to these three questions are all yes then you're 95% of the way to an RVB, except...

Quoted 33 lines
---
 fs/xfs/libxfs/xfs_da_format.h |  3 +++
 fs/xfs/xfs_attr_list.c        | 47 +++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_da_format.h +3 -0
index b02b67f1999e..e9c323fab6f3 100644
@@ -697,6 +697,9 @@ struct xfs_attr3_leafblock {
 #define XFS_ATTR_INCOMPLETE	(1u << XFS_ATTR_INCOMPLETE_BIT)
 #define XFS_ATTR_NSP_ONDISK_MASK \
 			(XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT)
+#define XFS_ATTR_ALL \
+	(XFS_ATTR_LOCAL_BIT | XFS_ATTR_ROOT | XFS_ATTR_SECURE | \
+	 XFS_ATTR_PARENT | XFS_ATTR_INCOMPLETE_BIT)
 
 /*
  * Alignment for namelist and valuelist entries (since they are mixed
fs/xfs/xfs_attr_list.c +5 -0
index a51f7f13a352..13de597c4996 100644
@@ -39,6 +39,23 @@ xfs_attr_shortform_compare(const void *a, const void *b)
 	}
 }
 
+/*
+ * Returns true or false if the parent attribute should be listed
+ */
+static bool
+xfs_attr_filter_parent(

fs/xfs/xfs_attr_list.c xfs_attr_shortform_compare(const void *a, const void *b) · line 56

Quoted 10 lines
fs/xfs/xfs_attr_list.c +10 -0
+	struct xfs_attr_list_context	*context,
+	int				flags)
+{
+	if (!(flags & XFS_ATTR_PARENT))
+		return true;
+
+	if (context->attr_filter & XFS_ATTR_PARENT)
+		return true;
+
+	return false;

...wouldn't it suffice to do:

static inline bool
xfs_attr_filter_listent(

	struct xfs_attr_list_context    *context,
	int				flags)
{
	return context->attr_filter != (flags & XFS_ATTR_NSP_ONDISK_MASK);
}

like how xfs_ioc_attr_put_listent does? And then...

Quoted 54 lines
fs/xfs/xfs_attr_list.c +17 -11
+}
+
 #define XFS_ISRESET_CURSOR(cursor) \
 	(!((cursor)->initted) && !((cursor)->hashval) && \
 	 !((cursor)->blkno) && !((cursor)->offset))
@@ -90,11 +107,12 @@ xfs_attr_shortform_list(
 							       sfe->namelen,
 							       sfe->flags)))
 				return -EFSCORRUPTED;
-			context->put_listent(context,
-					     sfe->flags,
-					     sfe->nameval,
-					     (int)sfe->namelen,
-					     (int)sfe->valuelen);
+			if (xfs_attr_filter_parent(context, sfe->flags))
+				context->put_listent(context,
+						     sfe->flags,
+						     sfe->nameval,
+						     (int)sfe->namelen,
+						     (int)sfe->valuelen);
 			/*
 			 * Either search callback finished early or
 			 * didn't fit it all in the buffer after all.
@@ -185,11 +203,12 @@ xfs_attr_shortform_list(
 			error = -EFSCORRUPTED;
 			goto out;
 		}
-		context->put_listent(context,
-				     sbp->flags,
-				     sbp->name,
-				     sbp->namelen,
-				     sbp->valuelen);
+		if (xfs_attr_filter_parent(context, sbp->flags))
+			context->put_listent(context,
+					     sbp->flags,
+					     sbp->name,
+					     sbp->namelen,
+					     sbp->valuelen);
 		if (context->seen_enough)
 			break;
 		cursor->offset++;
@@ -474,8 +493,10 @@ xfs_attr3_leaf_list_int(
 				   !xfs_attr_namecheck(mp, name, namelen,
 						       entry->flags)))
 			return -EFSCORRUPTED;
-		context->put_listent(context, entry->flags,
+		if (xfs_attr_filter_parent(context, entry->flags))
+			context->put_listent(context, entry->flags,
 					      name, namelen, valuelen);
+
 		if (context->seen_enough)
 			break;
 		cursor->offset++;

fs/xfs/xfs_attr_list.c xfs_attr_list( · line 565

Quoted 6 lines
fs/xfs/xfs_attr_list.c +3 -0
@@ -539,6 +560,10 @@ xfs_attr_list(
 	if (xfs_is_shutdown(dp->i_mount))
 		return -EIO;
 
+	if (context->attr_filter == 0)
+		context->attr_filter =
+			XFS_ATTR_ALL & ~XFS_ATTR_PARENT;

...I think this is unnecessary since none of the callers can actually set XFS_ATTR_PARENT in the first place, right?

--D

Quoted 7 lines
fs/xfs/xfs_attr_list.c +1 -0
+
 	lock_mode = xfs_ilock_attr_map_shared(dp);
 	error = xfs_attr_list_ilocked(context);
 	xfs_iunlock(dp, lock_mode);
Signature · 1 line
2.25.1
#59 lore raw

Re: [PATCH v3 23/26] xfs: Filter XFS_ATTR_PARENT for getfattr

Quoted 19 lines · Darrick J. Wong
Quoted 6 lines · On Wed, Sep 21, 2022 at 10:44:55PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Parent pointers returned to the get_fattr tool cause errors since the tool cannot parse parent pointers.  Fix this by filtering parent
parent pointers from xfs_attr_list.

Yes!!  Parent pointers should /never/ be accessible by the standard VFS
xattr syscalls, nor should the XFS ATTR_MULTI calls handle them.

Changes to parent pointers are performed via separate syscalls (link/unlink/mknod/creat/etc), and I see you've created a separate parent pointer ioctl later on for userspace to retrieve them.  I think
this is the correct access model.

Quoted 5 lines

To check that assertion -- getxattr/setxattr/removexattr (and the ATTRMULTI
equivalents) are prevented from accessing parent pointers directly because you'd have to be able to set XFS_ATTR_PARENT in xfs_da_args.attr_filter, right?

Well, you set XFS_IOC_ATTR_PARENT which later translates to XFS_ATTR_PARENT. I do that later in the set, but I see you've already commented on it

Quoted 5 lines

And for the VFS to get/set/remove a parent pointer, XFS would have to provide a struct xattr_handler with ->flags = XFS_ATTR_PARENT, which XFS
will never do, right?

Well, this set does not plan to make any vfs modifications at least :-)

Quoted 5 lines

And for ATTR_MULTI to touch a parent pointer, xfs_attr_filter (and the
ioctl api) would have to learn about XFS_ATTR_PARENT, which XFS will also never do, right?

I think we do have to publish that XFS_ATTR_PARENT exists, but I don't think we have to implement the XFS_IOC_ATTR_PARENT translation

Quoted 56 lines

If the answers to these three questions are all yes then you're 95% of
the way to an RVB, except...

Quoted 38 lines

---
 fs/xfs/libxfs/xfs_da_format.h |  3 +++ fs/xfs/xfs_attr_list.c        | 47 +++++++++++++++++++++++++++----
----

 2 files changed, 39 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_da_format.h +0 -0
index b02b67f1999e..e9c323fab6f3 100644
@@ -697,6 +697,9 @@ struct xfs_attr3_leafblock {
  #define XFS_ATTR_INCOMPLETE    (1u << XFS_ATTR_INCOMPLETE_BIT)
  #define XFS_ATTR_NSP_ONDISK_MASK \

                        (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT)
+#define XFS_ATTR_ALL \
+       (XFS_ATTR_LOCAL_BIT | XFS_ATTR_ROOT | XFS_ATTR_SECURE | \
+        XFS_ATTR_PARENT | XFS_ATTR_INCOMPLETE_BIT)

 /*
  * Alignment for namelist and valuelist entries (since they are mixed

fs/xfs/xfs_attr_list.c +0 -0
index a51f7f13a352..13de597c4996 100644
@@ -39,6 +39,23 @@ xfs_attr_shortform_compare(const void *a, const
 void *b)
         }
  }

fs/xfs/xfs_attr_list.c +5 -0
+/*
+ * Returns true or false if the parent attribute should be listed
+ */
+static bool
+xfs_attr_filter_parent(

fs/xfs/xfs_attr_list.c xfs_attr_shortform_compare(const void *a, const void *b) · line 56

Quoted 10 lines
fs/xfs/xfs_attr_list.c +10 -0
+       struct xfs_attr_list_context    *context,
+       int                             flags)
+{
+       if (!(flags & XFS_ATTR_PARENT))
+               return true;
+
+       if (context->attr_filter & XFS_ATTR_PARENT)
+               return true;
+
+       return false;

...wouldn't it suffice to do:

Quoted 8 lines

static inline bool
xfs_attr_filter_listent(
        struct xfs_attr_list_context    *context,
        int                             flags)
{
        return context->attr_filter != (flags &
XFS_ATTR_NSP_ONDISK_MASK);
}

Almost.... XFS_ATTR_NSP_ONDISK_MASK includes XFS_ATTR_PARENT, so here we'd want XFS_ATTR_NSP_ONDISK_MASK & ~XFS_ATTR_PARENT

Also, XFS_ATTR_NSP_ONDISK_MASK doesnt include XFS_ATTR_LOCAL which was previously allowable

Hmm, how bout just:

	return context->attr_filter != flags & (XFS_ATTR_ROOT |

XFS_ATTR_SECURE | XFS_ATTR_LOCAL)

I think that preserves the existing behavior

Quoted 67 lines

like how xfs_ioc_attr_put_listent does?  And then...

Quoted 64 lines
fs/xfs/xfs_attr_list.c +2 -0
+}
+

 #define XFS_ISRESET_CURSOR(cursor) \
        (!((cursor)->initted) && !((cursor)->hashval) && \
         !((cursor)->blkno) && !((cursor)->offset))

fs/xfs/xfs_attr_list.c +0 -0
@@ -90,11 +107,12 @@ xfs_attr_shortform_list(

                                                               sfe-

Quoted 1 line

namelen,

                                                               sfe-

Quoted 1 line

flags)))

                                return -EFSCORRUPTED;
-                       context->put_listent(context,
-                                            sfe->flags, -                                            sfe->nameval, -                                            (int)sfe->namelen, -                                            (int)sfe->valuelen); +                       if (xfs_attr_filter_parent(context, sfe-

Quoted 1 line

flags))

+                               context->put_listent(context, +                                                    sfe->flags, +                                                    sfe->nameval, +                                                    (int)sfe-

Quoted 1 line

namelen,

+                                                    (int)sfe-

Quoted 1 line

valuelen);

                        /*
                         * Either search callback finished early or
                         * didn't fit it all in the buffer after all.

fs/xfs/xfs_attr_list.c +6 -5
@@ -185,11 +203,12 @@ xfs_attr_shortform_list(
                         error = -EFSCORRUPTED;
                         goto out;
                 }
-               context->put_listent(context,
-                                    sbp->flags,
-                                    sbp->name,
-                                    sbp->namelen,
-                                    sbp->valuelen);
+               if (xfs_attr_filter_parent(context, sbp->flags))
+                       context->put_listent(context,
+                                            sbp->flags,
+                                            sbp->name,
+                                            sbp->namelen,
+                                            sbp->valuelen);
                 if (context->seen_enough)
                         break;
                 cursor->offset++;
@@ -474,8 +493,10 @@ xfs_attr3_leaf_list_int(
                                    !xfs_attr_namecheck(mp, name,
 namelen,

                                                       entry-

Quoted 1 line

flags)))

                        return -EFSCORRUPTED;
-               context->put_listent(context, entry->flags, +               if (xfs_attr_filter_parent(context, entry->flags)) +                       context->put_listent(context, entry->flags, name, namelen, valuelen);
+
                if (context->seen_enough)
                        break;
                cursor->offset++;

fs/xfs/xfs_attr_list.c +0 -0
@@ -539,6 +560,10 @@ xfs_attr_list(
         if (xfs_is_shutdown(dp->i_mount))
Quoted 9 lines
Quoted 5 lines
fs/xfs/xfs_attr_list.c +0 -0
                 return -EIO;


+       if (context->attr_filter == 0)
+               context->attr_filter =
+                       XFS_ATTR_ALL & ~XFS_ATTR_PARENT;

...I think this is unnecessary since none of the callers can actually set XFS_ATTR_PARENT in the first place, right?

The caller can stuff any bit in there they want, but until now it didn't matter because context->attr_filter was unused (getfattr appears to just leave it as 0). So the existing behavior was that requesting nothing resulted in everything. Now we're flipping that (at least internally).

If we use the filter logic above, this would need to turn into context->attr_filter = (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_LOCAL)

Quoted 9 lines

--D

Quoted 7 lines

+
        lock_mode = xfs_ilock_attr_map_shared(dp); error = xfs_attr_list_ilocked(context); xfs_iunlock(dp, lock_mode);

Signature · 1 line
2.25.1
#60 lore raw

Re: [PATCH v3 23/26] xfs: Filter XFS_ATTR_PARENT for getfattr

Quoted 20 lines · Allison Henderson
Quoted 19 lines · Darrick J. Wong
Quoted 6 lines · On Wed, Sep 21, 2022 at 10:44:55PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Parent pointers returned to the get_fattr tool cause errors since the tool cannot parse parent pointers.  Fix this by filtering parent
parent pointers from xfs_attr_list.

Yes!!  Parent pointers should /never/ be accessible by the standard VFS
xattr syscalls, nor should the XFS ATTR_MULTI calls handle them.

Changes to parent pointers are performed via separate syscalls (link/unlink/mknod/creat/etc), and I see you've created a separate parent pointer ioctl later on for userspace to retrieve them.  I think
this is the correct access model.

Quoted 8 lines
Quoted 5 lines

To check that assertion -- getxattr/setxattr/removexattr (and the ATTRMULTI
equivalents) are prevented from accessing parent pointers directly because you'd have to be able to set XFS_ATTR_PARENT in xfs_da_args.attr_filter, right?

Well, you set XFS_IOC_ATTR_PARENT which later translates to XFS_ATTR_PARENT. I do that later in the set, but I see you've already commented on it

<nod>

Quoted 8 lines
Quoted 5 lines

And for the VFS to get/set/remove a parent pointer, XFS would have to provide a struct xattr_handler with ->flags = XFS_ATTR_PARENT, which XFS
will never do, right?

Well, this set does not plan to make any vfs modifications at least :-)

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

And for ATTR_MULTI to touch a parent pointer, xfs_attr_filter (and the
ioctl api) would have to learn about XFS_ATTR_PARENT, which XFS will also never do, right?

I think we do have to publish that XFS_ATTR_PARENT exists, but I don't think we have to implement the XFS_IOC_ATTR_PARENT translation

Agreed. The fewer symbols that end up in xfs_fs.h the better, because anything we publish in there becomes a part of the userspace ABI and has to be supported "forever".

Quoted 66 lines
Quoted 55 lines

If the answers to these three questions are all yes then you're 95% of
the way to an RVB, except...

Quoted 38 lines

---
 fs/xfs/libxfs/xfs_da_format.h |  3 +++ fs/xfs/xfs_attr_list.c        | 47 +++++++++++++++++++++++++++----
----

 2 files changed, 39 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_da_format.h +0 -0
index b02b67f1999e..e9c323fab6f3 100644
@@ -697,6 +697,9 @@ struct xfs_attr3_leafblock {
  #define XFS_ATTR_INCOMPLETE    (1u << XFS_ATTR_INCOMPLETE_BIT)
  #define XFS_ATTR_NSP_ONDISK_MASK \

                        (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT)
+#define XFS_ATTR_ALL \
+       (XFS_ATTR_LOCAL_BIT | XFS_ATTR_ROOT | XFS_ATTR_SECURE | \
+        XFS_ATTR_PARENT | XFS_ATTR_INCOMPLETE_BIT)

 /*
  * Alignment for namelist and valuelist entries (since they are mixed

fs/xfs/xfs_attr_list.c +0 -0
index a51f7f13a352..13de597c4996 100644
@@ -39,6 +39,23 @@ xfs_attr_shortform_compare(const void *a, const
 void *b)
         }
  }

fs/xfs/xfs_attr_list.c +5 -0
+/*
+ * Returns true or false if the parent attribute should be listed
+ */
+static bool
+xfs_attr_filter_parent(

fs/xfs/xfs_attr_list.c xfs_attr_shortform_compare(const void *a, const void *b) · line 56

Quoted 10 lines
fs/xfs/xfs_attr_list.c +10 -0
+       struct xfs_attr_list_context    *context,
+       int                             flags)
+{
+       if (!(flags & XFS_ATTR_PARENT))
+               return true;
+
+       if (context->attr_filter & XFS_ATTR_PARENT)
+               return true;
+
+       return false;

...wouldn't it suffice to do:

Quoted 8 lines

static inline bool
xfs_attr_filter_listent(
        struct xfs_attr_list_context    *context,
        int                             flags)
{
        return context->attr_filter != (flags &
XFS_ATTR_NSP_ONDISK_MASK);
}

Almost.... XFS_ATTR_NSP_ONDISK_MASK includes XFS_ATTR_PARENT, so here we'd want XFS_ATTR_NSP_ONDISK_MASK & ~XFS_ATTR_PARENT

Quoted 8 lines

Also, XFS_ATTR_NSP_ONDISK_MASK doesnt include XFS_ATTR_LOCAL which was previously allowable

Hmm, how bout just:

	return context->attr_filter != flags & (XFS_ATTR_ROOT |

XFS_ATTR_SECURE | XFS_ATTR_LOCAL)

I think that preserves the existing behavior

It does, but I think it'll cause conflicts with future online fsck code.

(Let me check my understanding of the xfs_attr_list callers first:

There are /three/ namespaces, but only two of them have defined flag bits. "root.*" and "secure.*" have XFS_ATTR_{ROOT,SECURE}, but "user.*" is recorded by the absence of any XFS_ATTR_ flag. IOWs, attr_filter isn't a bit mask of all the namespaces that the caller wants; it's a cookie value to coordinate between the xfs_attr_list caller and the supplied putent function.

vfs_listxattr doesn't allow userspace to specify an xattr namespace, so it returns xattrs from user.*, root.*, and secure.*. xfs_vn_listxattr doesn't set attr_filter, and xfs_xattr_put_listent doesn't check.

XFS_IOC_ATTRLIST_BY_HANDLE, on the other hand, requires userspace to specify which namespace they want to list. That's why it's the one caller that sets context.attr_filter, and xfs_ioc_attr_put_listent does a comparison to filter attributes from other namespaces.

The xattr scrubber calls xfs_attr_list_ilocked to walk every xattr attached to the file. For each call to ->put_listent, it uses the built-in hash information to look up the attr name provided to confirm that hashed lookups also work. For /this/ usecase, we want xfs_attr_list_* to return all xattrs because we need to check all xattr namespaces. Hence it doesn't set context.attr_filter, and xchk_xattr_listent doesn't check it either.

...right?)

((Come to think of it -- shouldn't the ifork and attr leaf block verifiers check that each attr entry struct have at most one of the namespace bits set?))

After the addition of parent pointers, xfs_xattr_put_listent needs to filter out (flags & XFS_ATTR_PARENT) cases. XFS_IOC_ATTRLIST_BY_HANDLE won't need any changes if we drop the XFS_IOC_ATTR_PARENT flag, since there won't be any way for XFS_ATTR_PARENT to be set in attr_filter. The xattr scrubber still needs to walk every xattr to perform a complete scan. Hence it will still not touch context.attr_filter, nor will it want any filtering to be applied at all.

For the forthcoming totally-doesn't-exist-yet parent pointer online fsck code, I'd sorta like to reuse that function to walk only the parent pointers. I'm not 100% sure I will end up doing that -- the cursoring code would be useful if I have to use a live inode scan to do the checking and repair, but OTOH it's a little annoying to deal with the warts of the xfs_attr_list_context. But in theory, I'd have xchk_parent_listent or whatever the function ends up being named ignore anything that wasn't XFS_ATTR_PARENT. This mechanism also does not want the xfs_attr_list_* functions to perform any filtering.

In terms of APIs, xfs_attr_filter_parent doesn't really make a lot of sense -- if you set context.attr_filter = XFS_ATTR_PARENT, you'll get all the xattrs (including the non-parent ones), but if you set any other value (e.g. XFS_ATTR_SECURE), you'll get all the non-parent xattrs, including the root.* and user.* attrs. The ->put_listent function still has to do its own filtering. Right?

What if xfs_xattr_put_listent exited early if (flags & XFS_ATTR_PARENT) and we never define a XFS_IOC_ATTR_ROOT? Won't that suffice to prevent the userspace xattr APIs from ever returning a parent pointer by accident?

Looking ahead to the GETPARENTS code, I think the filtering code in xfs_ioc_attr_put_listent would work for returning only the parent pointers, right? Since it does set context.attr_filter to XFS_ATTR_PARENT on its own? And you wouldn't need any of the other changes here?

--D

Quoted 96 lines
Quoted 67 lines

like how xfs_ioc_attr_put_listent does?  And then...

Quoted 64 lines
fs/xfs/xfs_attr_list.c +2 -0
+}
+

 #define XFS_ISRESET_CURSOR(cursor) \
        (!((cursor)->initted) && !((cursor)->hashval) && \
         !((cursor)->blkno) && !((cursor)->offset))

fs/xfs/xfs_attr_list.c +0 -0
@@ -90,11 +107,12 @@ xfs_attr_shortform_list(

                                                               sfe-

Quoted 1 line

namelen,

                                                               sfe-

Quoted 1 line

flags)))

                                return -EFSCORRUPTED;
-                       context->put_listent(context,
-                                            sfe->flags, -                                            sfe->nameval, -                                            (int)sfe->namelen, -                                            (int)sfe->valuelen); +                       if (xfs_attr_filter_parent(context, sfe-

Quoted 1 line

flags))

+                               context->put_listent(context, +                                                    sfe->flags, +                                                    sfe->nameval, +                                                    (int)sfe-

Quoted 1 line

namelen,

+                                                    (int)sfe-

Quoted 1 line

valuelen);

                        /*
                         * Either search callback finished early or
                         * didn't fit it all in the buffer after all.

fs/xfs/xfs_attr_list.c +6 -5
@@ -185,11 +203,12 @@ xfs_attr_shortform_list(
                         error = -EFSCORRUPTED;
                         goto out;
                 }
-               context->put_listent(context,
-                                    sbp->flags,
-                                    sbp->name,
-                                    sbp->namelen,
-                                    sbp->valuelen);
+               if (xfs_attr_filter_parent(context, sbp->flags))
+                       context->put_listent(context,
+                                            sbp->flags,
+                                            sbp->name,
+                                            sbp->namelen,
+                                            sbp->valuelen);
                 if (context->seen_enough)
                         break;
                 cursor->offset++;
@@ -474,8 +493,10 @@ xfs_attr3_leaf_list_int(
                                    !xfs_attr_namecheck(mp, name,
 namelen,

                                                       entry-

Quoted 1 line

flags)))

                        return -EFSCORRUPTED;
-               context->put_listent(context, entry->flags, +               if (xfs_attr_filter_parent(context, entry->flags)) +                       context->put_listent(context, entry->flags, name, namelen, valuelen);
+
                if (context->seen_enough)
                        break;
                cursor->offset++;

fs/xfs/xfs_attr_list.c +0 -0
@@ -539,6 +560,10 @@ xfs_attr_list(
         if (xfs_is_shutdown(dp->i_mount))
Quoted 9 lines
Quoted 5 lines
fs/xfs/xfs_attr_list.c +0 -0
                 return -EIO;


+       if (context->attr_filter == 0)
+               context->attr_filter =
+                       XFS_ATTR_ALL & ~XFS_ATTR_PARENT;

...I think this is unnecessary since none of the callers can actually set XFS_ATTR_PARENT in the first place, right?

The caller can stuff any bit in there they want, but until now it didn't matter because context->attr_filter was unused (getfattr appears to just leave it as 0). So the existing behavior was that requesting nothing resulted in everything. Now we're flipping that (at least internally).

If we use the filter logic above, this would need to turn into context->attr_filter = (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_LOCAL)

Quoted 9 lines

--D

Quoted 7 lines

+
        lock_mode = xfs_ilock_attr_map_shared(dp); error = xfs_attr_list_ilocked(context); xfs_iunlock(dp, lock_mode);

Signature · 1 line
2.25.1
#61 lore raw

Re: [PATCH v3 23/26] xfs: Filter XFS_ATTR_PARENT for getfattr

Quoted 228 lines · Darrick J. Wong
Quoted 29 lines · Allison Henderson
Quoted 22 lines · Darrick J. Wong
Quoted 7 lines · On Wed, Sep 21, 2022 at 10:44:55PM -0700, [email protected] wrote:

From: Allison Henderson <[email protected]>

Parent pointers returned to the get_fattr tool cause errors since
the tool cannot parse parent pointers.  Fix this by filtering parent
parent pointers from xfs_attr_list.

Yes!!  Parent pointers should /never/ be accessible by the standard
VFS
xattr syscalls, nor should the XFS ATTR_MULTI calls handle them.

Changes to parent pointers are performed via separate syscalls (link/unlink/mknod/creat/etc), and I see you've created a separate
parent pointer ioctl later on for userspace to retrieve them.  I think
this is the correct access model.

Quoted 6 lines

To check that assertion -- getxattr/setxattr/removexattr (and the ATTRMULTI
equivalents) are prevented from accessing parent pointers directly
because you'd have to be able to set XFS_ATTR_PARENT in xfs_da_args.attr_filter, right?

Quoted 4 lines

Well, you set XFS_IOC_ATTR_PARENT which later translates to XFS_ATTR_PARENT.  I do that later in the set, but I see you've already
commented on it

<nod>

Quoted 17 lines
Quoted 7 lines

And for the VFS to get/set/remove a parent pointer, XFS would have to
provide a struct xattr_handler with ->flags = XFS_ATTR_PARENT, which
XFS
will never do, right?

Well, this set does not plan to make any vfs modifications at least :-)

Quoted 7 lines

And for ATTR_MULTI to touch a parent pointer, xfs_attr_filter (and
the
ioctl api) would have to learn about XFS_ATTR_PARENT, which XFS will
also never do, right?

Quoted 3 lines

I think we do have to publish that XFS_ATTR_PARENT exists, but I don't
think we have to implement the XFS_IOC_ATTR_PARENT translation

Agreed.  The fewer symbols that end up in xfs_fs.h the better, because
anything we publish in there becomes a part of the userspace ABI and has
to be supported "forever".

Quoted 77 lines
Quoted 61 lines

If the answers to these three questions are all yes then you're 95%
of
the way to an RVB, except...

Quoted 43 lines

---
 fs/xfs/libxfs/xfs_da_format.h |  3 +++
 fs/xfs/xfs_attr_list.c        | 47
+++++++++++++++++++++++++++----
----

 2 files changed, 39 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_da_format.h +0 -0
index b02b67f1999e..e9c323fab6f3 100644
@@ -697,6 +697,9 @@ struct xfs_attr3_leafblock {
  #define XFS_ATTR_INCOMPLETE    (1u << XFS_ATTR_INCOMPLETE_BIT)
  #define XFS_ATTR_NSP_ONDISK_MASK \

                        (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT)
+#define XFS_ATTR_ALL \
+       (XFS_ATTR_LOCAL_BIT | XFS_ATTR_ROOT | XFS_ATTR_SECURE | \
+        XFS_ATTR_PARENT | XFS_ATTR_INCOMPLETE_BIT)

 /*
  * Alignment for namelist and valuelist entries (since they are
mixed

fs/xfs/xfs_attr_list.c +0 -0
index a51f7f13a352..13de597c4996 100644
@@ -39,6 +39,23 @@ xfs_attr_shortform_compare(const void *a,

const
void *b)
        }
 }

+/*
+ * Returns true or false if the parent attribute should be listed
+ */

fs/xfs/xfs_attr_list.c +2 -0
+static bool
+xfs_attr_filter_parent(

fs/xfs/xfs_attr_list.c xfs_attr_shortform_compare(const void *a, const void *b) · line 56

Quoted 10 lines
fs/xfs/xfs_attr_list.c +10 -0
+       struct xfs_attr_list_context    *context,
+       int                             flags)
+{
+       if (!(flags & XFS_ATTR_PARENT))
+               return true;
+
+       if (context->attr_filter & XFS_ATTR_PARENT)
+               return true;
+
+       return false;

...wouldn't it suffice to do:

Quoted 8 lines

static inline bool
xfs_attr_filter_listent(
        struct xfs_attr_list_context    *context,
        int                             flags)
{
        return context->attr_filter != (flags &
XFS_ATTR_NSP_ONDISK_MASK);
}

Almost.... XFS_ATTR_NSP_ONDISK_MASK includes XFS_ATTR_PARENT, so here
we'd want XFS_ATTR_NSP_ONDISK_MASK & ~XFS_ATTR_PARENT

Also, XFS_ATTR_NSP_ONDISK_MASK doesnt include XFS_ATTR_LOCAL which was
previously allowable

Quoted 5 lines

Hmm, how bout just:
        return context->attr_filter != flags & (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_LOCAL)

I think that preserves the existing behavior

It does, but I think it'll cause conflicts with future online fsck code.

(Let me check my understanding of the xfs_attr_list callers first:

There are /three/ namespaces, but only two of them have defined flag bits.  "root.*" and "secure.*" have XFS_ATTR_{ROOT,SECURE}, but "user.*"
is recorded by the absence of any XFS_ATTR_ flag.  IOWs, attr_filter isn't a bit mask of all the namespaces that the caller wants; it's a cookie value to coordinate between the xfs_attr_list caller and the supplied putent function.

vfs_listxattr doesn't allow userspace to specify an xattr namespace, so
it returns xattrs from user.*, root.*, and secure.*. xfs_vn_listxattr
doesn't set attr_filter, and xfs_xattr_put_listent doesn't check.

XFS_IOC_ATTRLIST_BY_HANDLE, on the other hand, requires userspace to specify which namespace they want to list.  That's why it's the one caller that sets context.attr_filter, and xfs_ioc_attr_put_listent does
a comparison to filter attributes from other namespaces.

The xattr scrubber calls xfs_attr_list_ilocked to walk every xattr attached to the file.  For each call to ->put_listent, it uses the built-in hash information to look up the attr name provided to confirm
that hashed lookups also work.  For /this/ usecase, we want xfs_attr_list_* to return all xattrs because we need to check all xattr
namespaces.  Hence it doesn't set context.attr_filter, and xchk_xattr_listent doesn't check it either.

...right?)

((Come to think of it -- shouldn't the ifork and attr leaf block verifiers check that each attr entry struct have at most one of the namespace bits set?))

After the addition of parent pointers, xfs_xattr_put_listent needs to filter out (flags & XFS_ATTR_PARENT) cases. XFS_IOC_ATTRLIST_BY_HANDLE
won't need any changes if we drop the XFS_IOC_ATTR_PARENT flag, since there won't be any way for XFS_ATTR_PARENT to be set in attr_filter. The xattr scrubber still needs to walk every xattr to perform a complete
scan.  Hence it will still not touch context.attr_filter, nor will it want any filtering to be applied at all.

For the forthcoming totally-doesn't-exist-yet parent pointer online fsck
code, I'd sorta like to reuse that function to walk only the parent pointers.  I'm not 100% sure I will end up doing that -- the cursoring
code would be useful if I have to use a live inode scan to do the checking and repair, but OTOH it's a little annoying to deal with the warts of the xfs_attr_list_context.  But in theory, I'd have xchk_parent_listent or whatever the function ends up being named ignore
anything that wasn't XFS_ATTR_PARENT.  This mechanism also does not want
the xfs_attr_list_* functions to perform any filtering.

In terms of APIs, xfs_attr_filter_parent doesn't really make a lot of sense -- if you set context.attr_filter = XFS_ATTR_PARENT, you'll get all the xattrs (including the non-parent ones), but if you set any other
value (e.g. XFS_ATTR_SECURE), you'll get all the non-parent xattrs, including the root.* and user.* attrs.  The ->put_listent function still
has to do its own filtering.  Right?

What if xfs_xattr_put_listent exited early if (flags & XFS_ATTR_PARENT)
and we never define a XFS_IOC_ATTR_ROOT?  Won't that suffice to prevent
the userspace xattr APIs from ever returning a parent pointer by accident?

Quoted 5 lines

Looking ahead to the GETPARENTS code, I think the filtering code in xfs_ioc_attr_put_listent would work for returning only the parent pointers, right?  Since it does set context.attr_filter to XFS_ATTR_PARENT on its own?  And you wouldn't need any of the other changes here?

Ok, I tried this out and it seems to work, so I will add this in the next revision. Thanks for the reviews!

Allison

Quoted 114 lines

--D

Quoted 111 lines
Quoted 80 lines

like how xfs_ioc_attr_put_listent does?  And then...

Quoted 77 lines
fs/xfs/xfs_attr_list.c +2 -0
+}
+

 #define XFS_ISRESET_CURSOR(cursor) \
        (!((cursor)->initted) && !((cursor)->hashval) && \
         !((cursor)->blkno) && !((cursor)->offset))

fs/xfs/xfs_attr_list.c +0 -0
@@ -90,11 +107,12 @@ xfs_attr_shortform_list(


sfe-

Quoted 1 line

namelen,


sfe-

Quoted 1 line

flags)))

                                return -EFSCORRUPTED; -                       context->put_listent(context, -                                            sfe->flags, -                                            sfe->nameval, -                                            (int)sfe->namelen, -                                            (int)sfe-

Quoted 1 line

valuelen);

+                       if (xfs_attr_filter_parent(context, sfe-

Quoted 1 line

flags))

+                               context->put_listent(context, +                                                    sfe-

Quoted 1 line

flags,

+                                                    sfe-

Quoted 1 line

nameval,

+                                                    (int)sfe-

Quoted 1 line

namelen,

+                                                    (int)sfe-

Quoted 1 line

valuelen);

                        /*
                         * Either search callback finished early or
                         * didn't fit it all in the buffer after
all.

fs/xfs/xfs_attr_list.c +6 -5
@@ -185,11 +203,12 @@ xfs_attr_shortform_list(
                         error = -EFSCORRUPTED;
                         goto out;
                 }
-               context->put_listent(context,
-                                    sbp->flags,
-                                    sbp->name,
-                                    sbp->namelen,
-                                    sbp->valuelen);
+               if (xfs_attr_filter_parent(context, sbp-
 >flags))
+                       context->put_listent(context,
+                                            sbp->flags,
+                                            sbp->name,
+                                            sbp->namelen,
+                                            sbp->valuelen);
                 if (context->seen_enough)
                         break;

                cursor->offset++;

fs/xfs/xfs_attr_list.c +0 -0
@@ -474,8 +493,10 @@ xfs_attr3_leaf_list_int(
                                    !xfs_attr_namecheck(mp,
 name,
 namelen,

                                                       entry-

Quoted 1 line

flags)))

                        return -EFSCORRUPTED;
-               context->put_listent(context, entry->flags, +               if (xfs_attr_filter_parent(context, entry-

Quoted 1 line

flags))

+                       context->put_listent(context, entry-

Quoted 1 line

flags,

                                              name, namelen, valuelen);
+
                if (context->seen_enough)
                        break;
                cursor->offset++;

fs/xfs/xfs_attr_list.c +0 -0
@@ -539,6 +560,10 @@ xfs_attr_list(
         if (xfs_is_shutdown(dp->i_mount))
                 return -EIO;
Quoted 9 lines
Quoted 4 lines


+       if (context->attr_filter == 0)
+               context->attr_filter =
+                       XFS_ATTR_ALL & ~XFS_ATTR_PARENT;

...I think this is unnecessary since none of the callers can actually
set XFS_ATTR_PARENT in the first place, right?

The caller can stuff any bit in there they want, but until now it didn't matter because context->attr_filter was unused (getfattr appears
to just leave it as 0).  So the existing behavior was that requesting
nothing resulted in everything.  Now we're flipping that (at least internally).

If we use the filter logic above, this would need to turn into context->attr_filter = (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_LOCAL)

Quoted 9 lines

--D

Quoted 7 lines

+
        lock_mode = xfs_ilock_attr_map_shared(dp); error = xfs_attr_list_ilocked(context); xfs_iunlock(dp, lock_mode);

Signature · 1 line
2.25.1