[PATCH 1/1] xfs: repair extended attributes

Darrick J. Wong
2023-12-31T22:34:53Z

If the extended attributes look bad, try to sift through the rubble to
find whatever keys/values we can, stage a new attribute structure in a
temporary file and use the atomic extent swapping mechanism to commit
the results in bulk.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
libxfs/xfs_attr.c | 2 +-
libxfs/xfs_attr.h | 2 ++
libxfs/xfs_da_format.h | 5 +++++
libxfs/xfs_swapext.c | 2 +-
libxfs/xfs_swapext.h | 1 +
5 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c
index 985989b5ade..8f527ac9292 100644
--- a/libxfs/xfs_attr.c
+++ b/libxfs/xfs_attr.c
@@ -1045,7 +1045,7 @@ xfs_attr_set(
* External routines when attribute list is inside the inode
*========================================================================*/

-static inline int xfs_attr_sf_totsize(struct xfs_inode *dp)
+int xfs_attr_sf_totsize(struct xfs_inode *dp)
{
struct xfs_attr_shortform *sf;

diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h
index 81be9b3e400..e4f55008552 100644
--- a/libxfs/xfs_attr.h
+++ b/libxfs/xfs_attr.h
@@ -618,4 +618,6 @@ extern struct kmem_cache *xfs_attr_intent_cache;
int __init xfs_attr_intent_init_cache(void);
void xfs_attr_intent_destroy_cache(void);

+int xfs_attr_sf_totsize(struct xfs_inode *dp);
+
#endif /* __XFS_ATTR_H__ */
diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h
index 44748f1640e..0e1ada44f21 100644
--- a/libxfs/xfs_da_format.h
+++ b/libxfs/xfs_da_format.h
@@ -716,6 +716,11 @@ 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)

+#define XFS_ATTR_NAMESPACE_STR \
+ { XFS_ATTR_LOCAL, "local" }, \
+ { XFS_ATTR_ROOT, "root" }, \
+ { XFS_ATTR_SECURE, "secure" }
+
/*
* Alignment for namelist and valuelist entries (since they are mixed
* there can be only one alignment value)
diff --git a/libxfs/xfs_swapext.c b/libxfs/xfs_swapext.c
index f396593a5c8..1f7fbe76a89 100644
--- a/libxfs/xfs_swapext.c
+++ b/libxfs/xfs_swapext.c
@@ -767,7 +767,7 @@ xfs_swapext_rmapbt_blocks(
}

/* Estimate the bmbt and rmapbt overhead required to exchange extents. */
-static int
+int
xfs_swapext_estimate_overhead(
struct xfs_swapext_req *req)
{
diff --git a/libxfs/xfs_swapext.h b/libxfs/xfs_swapext.h
index 37842a4ee9a..a4768eddc9c 100644
--- a/libxfs/xfs_swapext.h
+++ b/libxfs/xfs_swapext.h
@@ -200,6 +200,7 @@ unsigned int xfs_swapext_reflink_prep(const struct xfs_swapext_req *req);
void xfs_swapext_reflink_finish(struct xfs_trans *tp,
const struct xfs_swapext_req *req, unsigned int reflink_state);

+int xfs_swapext_estimate_overhead(struct xfs_swapext_req *req);
int xfs_swapext_estimate(struct xfs_swapext_req *req);

extern struct kmem_cache *xfs_swapext_intent_cache;