Skip to contentSkip to conversation

xfsprogs: rollup of libxfs-7.0-sync patches

PATCHBOMB New Darrick J. Wong 2 participants 50 messages Mar 23 – Mar 25

lore
Share & tools
lore
#0 lore raw

Hi folks,

Now that xfsprogs 6.19 has been released, here's a rollup of a couple of pending bugfixes, a pre-cleanup of the kmalloc API wrappers from the kernel, and all the libxfs ports patches, with new review tags.

Unreviewed patches:

[PATCHSET 2/2] xfsprogs: new libxfs code from kernel 7.0
[PATCH 01/38] libxfs: fix XFS_STATS_DEC
[PATCH 02/38] libxfs: port various kernel apis from 7.0

--D

#1 lore raw

PATCH 1/2 xfsprogs: various bug fixes for 7.0

Hi all,

This series contains miscellaneous bugfixes.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=random-fixes

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=random-fixes

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=random-fixes
---
Commits in this patchset:
* xfs_repair: don't fail on INCOMPLETE attrs in leaf blocks

---
 repair/attr_repair.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
#2 lore raw

PATCH 1/1 xfs_repair: don't fail on INCOMPLETE attrs in leaf blocks

From: Darrick J. Wong <[email protected]>

While trying to fix problems in generic/753, I noticed test failures on account of xfs_repair:

attribute entry #4 in attr block 0, inode 131 is INCOMPLETE problem with attribute contents in inode 131 would clear attr fork
bad nblocks 4 for inode 131, would reset to 0
bad anextents 1 for inode 131, would reset to 0

Looking at the dumped filesystem, inode 131 is a linked file, and the "incomplete" xattr was clearly part of an xfs_attr_set operation that failed midway through because the induced log shutdown prevented xfs from finishing the creation of a remote xattr. This kind of thing is expected, but instead xfs_repair deletes the entire attr fork!

It's far too drastic to delete every xattr because doing that destroys things like security labels. The kernel won't show incomplete attrs so it's not a big deal to leave them attached to the file. Note that xfs_scrub can fix such things.

---
 repair/attr_repair.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
repair/attr_repair.c +17 -5
index 50159b9a533875..fe4089026cae74 100644
@@ -571,7 +571,13 @@ process_leaf_attr_remote(
 	    !libxfs_attr_namecheck(entry->flags, remotep->name,
 				   remotep->namelen) ||
 	    be32_to_cpu(entry->hashval) != computed ||
-	    be32_to_cpu(entry->hashval) < last_hashval ||
+	    be32_to_cpu(entry->hashval) < last_hashval) {
+		do_warn(
+	_("inconsistent remote attribute entry %d in attr block %u, ino %" PRIu64 "\n"), i, da_bno, ino);
+		return -1;
+	}
+
+	if (!(entry->flags & XFS_ATTR_INCOMPLETE) &&
 	    be32_to_cpu(remotep->valueblk) == 0) {
 		do_warn(
 	_("inconsistent remote attribute entry %d in attr block %u, ino %" PRIu64 "\n"), i, da_bno, ino);
@@ -592,6 +598,9 @@ process_leaf_attr_remote(
 		return -1;
 	}
 
+	if (entry->flags & XFS_ATTR_INCOMPLETE)
+		goto out;
+
 	value = malloc(be32_to_cpu(remotep->valuelen));
 	if (value == NULL) {
 		do_warn(
@@ -708,12 +717,15 @@ process_leaf_attr_block(
 		}
 
 		if (entry->flags & XFS_ATTR_INCOMPLETE) {
-			/* we are inconsistent state. get rid of us */
-			do_warn(
+			/*
+			 * Warn about incomplete xattrs but don't zap the
+			 * entire attr fork because that causes loss of
+			 * security labels.  The kernel can handle stray
+			 * incomplete attr entries.
+			 */
+			do_log(
 	_("attribute entry #%d in attr block %u, inode %" PRIu64 " is INCOMPLETE\n"),
 				i, da_bno, ino);
-			clearit = 1;
-			break;
 		}
 
 		/* mark the entry used */
#3 lore raw

PATCH 2/2 xfsprogs: new libxfs code from kernel 7.0

In reply to Darrick J. Wong

Hi all,

This series ports kernel libxfs code to userspace from 7.0-rc5.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=libxfs-7.0-sync
---
Commits in this patchset:
* libxfs: fix XFS_STATS_DEC
* libxfs: port various kernel apis from 7.0
* libfrog: hoist some utilities from libxfs
* libfrog: fix missing gettext call in current_fixed_time
* xfs: start creating infrastructure for health monitoring
* xfs: create event queuing, formatting, and discovery infrastructure
* xfs: convey filesystem unmount events to the health monitor
* xfs: convey metadata health events to the health monitor
* xfs: convey filesystem shutdown events to the health monitor
* xfs: convey externally discovered fsdax media errors to the health monitor
* xfs: convey file I/O errors to the health monitor
* xfs: check if an open file is on the health monitored fs
* xfs: add media verification ioctl
* xfs: move struct xfs_log_iovec to xfs_log_priv.h
* xfs: directly include xfs_platform.h
* xfs: remove xfs_attr_leaf_hasname
* xfs: add missing forward declaration in xfs_zones.h
* xfs: add a xfs_rtgroup_raw_size helper
* xfs: split and refactor zone validation
* xfs: delete attr leaf freemap entries when empty
* xfs: fix freemap adjustments when adding xattrs to leaf blocks
* xfs: refactor attr3 leaf table size computation
* xfs: strengthen attr leaf block freemap checking
* xfs: reduce xfs_attr_try_sf_addname parameters
* xfs: speed up parent pointer operations when possible
* xfs: add a method to replace shortform attrs
* xfs: fix spacing style issues in xfs_alloc.c
* xfs: don't validate error tags in the I/O path
* xfs: add zone reset error injection
* xfs: give the defer_relog stat a xs_ prefix
* treewide: Replace kmalloc with kmalloc_obj for non-scalar types
* Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
* xfs: Refactoring the nagcount and delta calculation
* xfs: fix code alignment issues in xfs_ondisk.c
* xfs: remove metafile inodes from the active inode stat
* xfs: Add a comment in xfs_log_sb()
* xfs: remove duplicate static size checks
* xfs: add static size checks for ioctl UABI
* xfs: Remove redundant NULL check after __GFP_NOFAIL
* xfs: fix returned valued from xfs_defer_can_append

---
 include/kmem.h                |   50 ++++++++++
 include/libxfs.h              |    7 -
 include/platform_defs.h       |    8 ++
 include/xfs_fs_compat.h       |    8 --
 include/xfs_trace.h           |    1 
 libfrog/util.h                |   21 ++++
 libxfs/libxfs_api_defs.h      |    2 
 libxfs/xfs_ag.h               |    3 +
 libxfs/xfs_attr.h             |    6 +
 libxfs/xfs_attr_leaf.h        |    1 
 libxfs/xfs_da_format.h        |    2 
 libxfs/xfs_errortag.h         |    8 +-
 libxfs/xfs_fs.h               |  189 +++++++++++++++++++++++++++++++++++++++
 libxfs/xfs_health.h           |    5 +
 libxfs/xfs_log_format.h       |    7 -
 libxfs/xfs_ondisk.h           |   52 +++++++----
 libxfs/xfs_platform.h         |   25 +----
 libxfs/xfs_rtgroup.h          |   15 +++
 libxfs/xfs_zones.h            |    6 +
 libfrog/Makefile              |    4 +
 libfrog/util.c                |  166 +++++++++++++++++++++++++++++++++++
 libxfs/Makefile               |    4 -
 libxfs/buf_mem.c              |    2 
 libxfs/cache.c                |    2 
 libxfs/defer_item.c           |    2 
 libxfs/init.c                 |    2 
 libxfs/inode.c                |    2 
 libxfs/iunlink.c              |    2 
 libxfs/kmem.c                 |    2 
 libxfs/logitem.c              |    2 
 libxfs/rdwr.c                 |    2 
 libxfs/topology.c             |    2 
 libxfs/trans.c                |    2 
 libxfs/util.c                 |  162 ----------------------------------
 libxfs/xfblob.c               |    2 
 libxfs/xfile.c                |    2 
 libxfs/xfs_ag.c               |   32 ++++++-
 libxfs/xfs_ag_resv.c          |    2 
 libxfs/xfs_alloc.c            |   10 +-
 libxfs/xfs_alloc_btree.c      |    2 
 libxfs/xfs_attr.c             |  191 +++++++++++++++++++++++++++-------------
 libxfs/xfs_attr_leaf.c        |  197 ++++++++++++++++++++++++++++++++++-------
 libxfs/xfs_attr_remote.c      |    2 
 libxfs/xfs_bit.c              |    2 
 libxfs/xfs_bmap.c             |    2 
 libxfs/xfs_bmap_btree.c       |    2 
 libxfs/xfs_btree.c            |    2 
 libxfs/xfs_btree_mem.c        |    2 
 libxfs/xfs_btree_staging.c    |    2 
 libxfs/xfs_da_btree.c         |   10 +-
 libxfs/xfs_defer.c            |    8 +-
 libxfs/xfs_dir2.c             |   21 ++--
 libxfs/xfs_dir2_block.c       |    2 
 libxfs/xfs_dir2_data.c        |    2 
 libxfs/xfs_dir2_leaf.c        |    2 
 libxfs/xfs_dir2_node.c        |    2 
 libxfs/xfs_dir2_sf.c          |    2 
 libxfs/xfs_dquot_buf.c        |    2 
 libxfs/xfs_exchmaps.c         |    2 
 libxfs/xfs_group.c            |    2 
 libxfs/xfs_ialloc.c           |    2 
 libxfs/xfs_ialloc_btree.c     |    2 
 libxfs/xfs_iext_tree.c        |    2 
 libxfs/xfs_inode_buf.c        |    6 +
 libxfs/xfs_inode_fork.c       |    2 
 libxfs/xfs_inode_util.c       |    2 
 libxfs/xfs_log_rlimit.c       |    2 
 libxfs/xfs_metadir.c          |    2 
 libxfs/xfs_metafile.c         |    7 +
 libxfs/xfs_parent.c           |   16 ++-
 libxfs/xfs_refcount.c         |    6 +
 libxfs/xfs_refcount_btree.c   |    2 
 libxfs/xfs_rmap.c             |    2 
 libxfs/xfs_rmap_btree.c       |    2 
 libxfs/xfs_rtbitmap.c         |    2 
 libxfs/xfs_rtgroup.c          |    4 -
 libxfs/xfs_rtrefcount_btree.c |    2 
 libxfs/xfs_rtrmap_btree.c     |    2 
 libxfs/xfs_sb.c               |    5 +
 libxfs/xfs_symlink_remote.c   |    2 
 libxfs/xfs_trans_inode.c      |    2 
 libxfs/xfs_trans_resv.c       |    2 
 libxfs/xfs_trans_space.c      |    2 
 libxfs/xfs_types.c            |    2 
 libxfs/xfs_zones.c            |  151 ++++++++-----------------------
 libxlog/xfs_log_recover.c     |    4 -
 repair/zoned.c                |    7 +
 87 files changed, 990 insertions(+), 533 deletions(-)
 rename libxfs/{libxfs_priv.h => xfs_platform.h} (96%)
#4 lore raw

PATCH 1/40 libxfs: fix XFS_STATS_DEC

From: Darrick J. Wong <[email protected]>

This macro only takes two arguments in the kernel, so fix the definition here too. All existing callsites #if 0 it into oblivion which is why we've never noticed, but an upcoming patch in the libxfs sync will not be so lucky.

Cc <[email protected]> # v4.9.0
Fixes ece930fa14a343 ("xfs: refactor xfs_bunmapi_cow")
---
 libxfs/libxfs_priv.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/libxfs_priv.h +1 -1
index 5474865a673e9a..f72f07fabdf21e 100644
@@ -183,7 +183,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 #define XFS_ILOCK_SHARED		0
 #define XFS_IOLOCK_EXCL			0
 #define XFS_STATS_INC(mp, count)	do { (mp) = (mp); } while (0)
-#define XFS_STATS_DEC(mp, count, x)	do { (mp) = (mp); } while (0)
+#define XFS_STATS_DEC(mp, count)	do { (mp) = (mp); } while (0)
 #define XFS_STATS_ADD(mp, count, x)	do { (mp) = (mp); } while (0)
 #define XFS_TEST_ERROR(a,b)		(false)
 
Reviewed-by on v1 1/40
#5 lore raw

Re: [PATCH 01/40] libxfs: fix XFS_STATS_DEC

Quoted 6 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

This macro only takes two arguments in the kernel, so fix the definition here too. All existing callsites #if 0 it into oblivion which is why we've never noticed, but an upcoming patch in the libxfs sync will not be so lucky.

Looks good:

Quoted 4 lines

#define XFS_TEST_ERROR(a,b) (false)

---end quoted text---

#6 lore raw

PATCH 1/40 libxfs: fix XFS_STATS_DEC

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

This macro only takes two arguments in the kernel, so fix the definition here too. All existing callsites #if 0 it into oblivion which is why we've never noticed, but an upcoming patch in the libxfs sync will not be so lucky.

Cc <[email protected]> # v4.9.0
Fixes ece930fa14a343 ("xfs: refactor xfs_bunmapi_cow")

---
v1.1: add rvb tag

---
 libxfs/libxfs_priv.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/libxfs_priv.h +1 -1
index 5474865a673e9a..f72f07fabdf21e 100644
@@ -183,7 +183,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 #define XFS_ILOCK_SHARED		0
 #define XFS_IOLOCK_EXCL			0
 #define XFS_STATS_INC(mp, count)	do { (mp) = (mp); } while (0)
-#define XFS_STATS_DEC(mp, count, x)	do { (mp) = (mp); } while (0)
+#define XFS_STATS_DEC(mp, count)	do { (mp) = (mp); } while (0)
 #define XFS_STATS_ADD(mp, count, x)	do { (mp) = (mp); } while (0)
 #define XFS_TEST_ERROR(a,b)		(false)
 
#7 lore raw

PATCH 2/40 libxfs: port various kernel apis from 7.0

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Port more kernel APIs from Linux 7.0.

---
 include/kmem.h |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
include/kmem.h +50 -0
index 66f8b1fbea8fdf..2c276e929c4808 100644
@@ -61,6 +61,56 @@ static inline void *kmalloc(size_t size, gfp_t flags)
 #define kzalloc(size, gfp)	kvmalloc((size), (gfp) | __GFP_ZERO)
 #define kvzalloc(size, gfp)	kzalloc((size), (gfp))
 
+/**
+ * kmalloc_array - allocate memory for an array.
+ * @n: number of elements.
+ * @size: element size.
+ * @flags: the type of memory to allocate (see kmalloc).
+ */
+static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+	size_t bytes;
+
+	if (unlikely(check_mul_overflow(n, size, &bytes)))
+		return NULL;
+	return kmalloc(bytes, flags);
+}
+#define kcalloc(n, size, gfp)	kmalloc_array((n), (size), (gfp) | __GFP_ZERO)
+
+/**
+ * size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX
+ * @factor1: first factor
+ * @factor2: second factor
+ *
+ * Returns: calculate @factor1 * @factor2, both promoted to size_t,
+ * with any overflow causing the return value to be SIZE_MAX. The
+ * lvalue must be size_t to avoid implicit type conversion.
+ */
+static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
+{
+	size_t bytes;
+
+	if (check_mul_overflow(factor1, factor2, &bytes))
+		return SIZE_MAX;
+
+	return bytes;
+}
+
+#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT)				\
+({									\
+	const size_t __obj_size = size_mul(sizeof(TYPE), COUNT);	\
+	(TYPE *)KMALLOC(__obj_size, GFP);				\
+})
+
+/* Helper macro to avoid gfp flags if they are the default one */
+#define __default_gfp(a,b,...) b
+#define default_gfp(...) __default_gfp(,##__VA_ARGS__,GFP_KERNEL)
+
+#define kzalloc_obj(P, ...) \
+	__alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
+#define kmalloc_obj(VAR_OR_TYPE, ...) \
+	__alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), 1)
+
 static inline void kfree(const void *ptr)
 {
 	free((void *)ptr);
Reviewed-by on v1 2/40
#8 lore raw

Re: [PATCH 02/40] libxfs: port various kernel apis from 7.0

Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Port more kernel APIs from Linux 7.0.

A little nitpicky, but this suggeste they were all added in Linux 7.0. At least kmalloc_array is much older than that.

Quoted 1 line

+#define kcalloc(n, size, gfp) kmalloc_array((n), (size), (gfp) | __GFP_ZERO)

Overly long line.

Otherwise looks good:

#9 lore raw

Re: [PATCH 02/40] libxfs: port various kernel apis from 7.0

Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Port more kernel APIs from Linux 7.0.

A little nitpicky, but this suggeste they were all added in Linux 7.0. At least kmalloc_array is much older than that.

I'll change it to:

"Port more kernel APIs from Linux as of 7.0."

Quoted 3 lines
Quoted 1 line

+#define kcalloc(n, size, gfp) kmalloc_array((n), (size), (gfp) | __GFP_ZERO)

Overly long line.

It is? On my system it only hits column 78.

Quoted 3 lines

Otherwise looks good:

Thanks!

--D

#10 lore raw

Re: [PATCH 02/40] libxfs: port various kernel apis from 7.0

Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Christoph Hellwig
Quoted 2 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Port more kernel APIs from Linux 7.0.

A little nitpicky, but this suggeste they were all added in Linux 7.0. At least kmalloc_array is much older than that.

I'll change it to:

"Port more kernel APIs from Linux as of 7.0."

Sounds good.

Quoted 6 lines
Quoted 4 lines

+#define kcalloc(n, size, gfp) kmalloc_array((n), (size), (gfp) | __GFP_ZERO)

Overly long line.

It is? On my system it only hits column 78.

You're right, the diff messed up the mid-line tab alignment.

#11 lore raw

PATCH 2/40 libxfs: port various kernel apis from 7.0

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Port more kernel APIs from Linux, as of version 7.0.

---
v1.1: add rvb, clarify the commit message

---
 include/kmem.h |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
include/kmem.h +50 -0
index 66f8b1fbea8fdf..2c276e929c4808 100644
@@ -61,6 +61,56 @@ static inline void *kmalloc(size_t size, gfp_t flags)
 #define kzalloc(size, gfp)	kvmalloc((size), (gfp) | __GFP_ZERO)
 #define kvzalloc(size, gfp)	kzalloc((size), (gfp))
 
+/**
+ * kmalloc_array - allocate memory for an array.
+ * @n: number of elements.
+ * @size: element size.
+ * @flags: the type of memory to allocate (see kmalloc).
+ */
+static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+	size_t bytes;
+
+	if (unlikely(check_mul_overflow(n, size, &bytes)))
+		return NULL;
+	return kmalloc(bytes, flags);
+}
+#define kcalloc(n, size, gfp)	kmalloc_array((n), (size), (gfp) | __GFP_ZERO)
+
+/**
+ * size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX
+ * @factor1: first factor
+ * @factor2: second factor
+ *
+ * Returns: calculate @factor1 * @factor2, both promoted to size_t,
+ * with any overflow causing the return value to be SIZE_MAX. The
+ * lvalue must be size_t to avoid implicit type conversion.
+ */
+static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
+{
+	size_t bytes;
+
+	if (check_mul_overflow(factor1, factor2, &bytes))
+		return SIZE_MAX;
+
+	return bytes;
+}
+
+#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT)				\
+({									\
+	const size_t __obj_size = size_mul(sizeof(TYPE), COUNT);	\
+	(TYPE *)KMALLOC(__obj_size, GFP);				\
+})
+
+/* Helper macro to avoid gfp flags if they are the default one */
+#define __default_gfp(a,b,...) b
+#define default_gfp(...) __default_gfp(,##__VA_ARGS__,GFP_KERNEL)
+
+#define kzalloc_obj(P, ...) \
+	__alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
+#define kmalloc_obj(VAR_OR_TYPE, ...) \
+	__alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), 1)
+
 static inline void kfree(const void *ptr)
 {
 	free((void *)ptr);
#12 lore raw

PATCH 3/40 libfrog: hoist some utilities from libxfs

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

This started with a desire to move the duplicate cmn_err declarations in libxfs into libfrog/util.h ahead of the patch that renames libxfs_priv.h to xfs_platform.h.

Then this patch expanded in scope when I realized that there were several other utility functions that weren't specific to xfs; those go in libfrog.

---
 include/libxfs.h        |    7 --
 include/platform_defs.h |    8 ++
 include/xfs_fs_compat.h |    8 --
 libfrog/util.h          |   21 ++++++
 libxfs/libxfs_priv.h    |   17 -----
 libfrog/Makefile        |    4 +
 libfrog/util.c          |  166 +++++++++++++++++++++++++++++++++++++++++++++++
 libxfs/Makefile         |    2 -
 libxfs/util.c           |  160 ---------------------------------------------
 9 files changed, 201 insertions(+), 192 deletions(-)
include/libxfs.h +1 -6
index 1e0d1a48fbb698..68d1f351f70093 100644
@@ -26,6 +26,7 @@
 #include "libfrog/radix-tree.h"
 #include "libfrog/bitmask.h"
 #include "libfrog/div64.h"
+#include "libfrog/util.h"
 #include "atomic.h"
 #include "spinlock.h"
 
@@ -187,12 +188,6 @@ int	libxfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset,
 int	libxfs_file_write(struct xfs_inode *ip, void *buf, off_t pos,
 		size_t len);
 
-/* XXX: this is messy and needs fixing */
-#ifndef __LIBXFS_INTERNAL_XFS_H__
-extern void cmn_err(int, char *, ...);
-enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
-#endif
-
 #include "xfs_ialloc.h"
 
 #include "xfs_attr_leaf.h"
include/platform_defs.h +8 -0
index 09129e0f22dcba..b2d80597a83aa4 100644
@@ -74,6 +74,14 @@ typedef unsigned short umode_t;
 
 extern int	platform_nproc(void);
 
+/* 64-bit seconds counter that works independently of the C library time_t. */
+typedef long long int time64_t;
+
+struct timespec64 {
+	time64_t	tv_sec;			/* seconds */
+	long		tv_nsec;		/* nanoseconds */
+};
+
 #define NSEC_PER_SEC	(1000000000ULL)
 #define NSEC_PER_USEC	(1000ULL)
 
include/xfs_fs_compat.h +0 -8
index 0077f00cb94904..ccf00424b1b85a 100644
@@ -85,14 +85,6 @@ struct xfs_extent_data {
 #define XFS_IOC_CLONE_RANGE	 _IOW (0x94, 13, struct xfs_clone_args)
 #define XFS_IOC_FILE_EXTENT_SAME _IOWR(0x94, 54, struct xfs_extent_data)
 
-/* 64-bit seconds counter that works independently of the C library time_t. */
-typedef long long int time64_t;
-
-struct timespec64 {
-	time64_t	tv_sec;			/* seconds */
-	long		tv_nsec;		/* nanoseconds */
-};
-
 #define U32_MAX		((uint32_t)~0U)
 #define S32_MAX		((int32_t)(U32_MAX >> 1))
 #define S32_MIN		((int32_t)(-S32_MAX - 1))
libfrog/util.h +21 -0
index d1c4dd40fc926c..48df6a691a8f6d 100644
@@ -7,6 +7,8 @@
 #define __LIBFROG_UTIL_H__
 
 #include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
 
 unsigned int	log2_roundup(unsigned int i);
 unsigned int	log2_rounddown(unsigned long long i);
@@ -18,4 +20,23 @@ unsigned int	log2_rounddown(unsigned long long i);
 
 void *memchr_inv(const void *start, int c, size_t bytes);
 
+struct timespec64;
+
+bool current_fixed_time(struct timespec64 *tv);
+bool get_deterministic_seed(uint32_t *result);
+
+#ifdef HAVE_GETRANDOM_NONBLOCK
+uint32_t get_random_u32(void);
+#else
+#define get_random_u32()	(0)
+#endif
+
+extern void cmn_err(int, char *, ...);
+enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
+
+typedef unsigned char u8;
+unsigned int hweight8(unsigned int w);
+unsigned int hweight32(unsigned int w);
+unsigned int hweight64(uint64_t w);
+
 #endif /* __LIBFROG_UTIL_H__ */
libxfs/libxfs_priv.h +0 -17
index f72f07fabdf21e..32b86b1df677c2 100644
@@ -65,9 +65,6 @@
 #include "libfrog/crc32c.h"
 
 #include <sys/xattr.h>
-#ifdef HAVE_GETRANDOM_NONBLOCK
-#include <sys/random.h>
-#endif
 
 /* Zones used in libxfs allocations that aren't in shared header files */
 extern struct kmem_cache *xfs_buf_item_cache;
@@ -133,9 +130,6 @@ extern char    *progname;
 #define XFS_IGET_CREATE			0x1
 #define XFS_IGET_UNTRUSTED		0x2
 
-extern void cmn_err(int, char *, ...);
-enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
-
 #define xfs_info(mp,fmt,args...)	cmn_err(CE_CONT, _(fmt), ## args)
 #define xfs_info_ratelimited(mp,fmt,args...) cmn_err(CE_CONT, _(fmt), ## args)
 #define xfs_notice(mp,fmt,args...)	cmn_err(CE_NOTE, _(fmt), ## args)
@@ -214,12 +208,6 @@ static inline bool WARN_ON(bool expr) {
 #define percpu_counter_read_positive(x)	((*x) > 0 ? (*x) : 0)
 #define percpu_counter_sum_positive(x)	((*x) > 0 ? (*x) : 0)
 
-#ifdef HAVE_GETRANDOM_NONBLOCK
-uint32_t get_random_u32(void);
-#else
-#define get_random_u32()	(0)
-#endif
-
 #define PAGE_SIZE		getpagesize()
 extern unsigned int PAGE_SHIFT;
 
@@ -567,11 +555,6 @@ void xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *lip, int type,
 #define XFS_STATS_INC_OFF(mp, off)
 #define XFS_STATS_ADD_OFF(mp, off, val)
 
-typedef unsigned char u8;
-unsigned int hweight8(unsigned int w);
-unsigned int hweight32(unsigned int w);
-unsigned int hweight64(__u64 w);
-
 #define xfs_buf_cache_init(bch)		(0)
 #define xfs_buf_cache_destroy(bch)	((void)0)
 
libfrog/Makefile +4 -0
index 9f405ffe347566..927bd8d0957fab 100644
@@ -82,6 +82,10 @@ else
 HAVE_GETTEXT = False
 endif
 
+ifeq ($(HAVE_GETRANDOM_NONBLOCK),yes)
+LCFLAGS += -DHAVE_GETRANDOM_NONBLOCK
+endif
+
 default: ltdepend $(LTLIBRARY) $(GETTEXT_PY)
 
 crc32table.h: gen_crc32table.c crc32defs.h
libfrog/util.c +166 -0

175 lines not on this page · raw message

libxfs/Makefile +1 -1
index 61c43529b532b6..c5e2161c33096a 100644
@@ -169,7 +169,7 @@ endif
 
 FCFLAGS = -I.
 
-LTLIBS = $(LIBPTHREAD) $(LIBRT)
+LTLIBS = $(LIBPTHREAD) $(LIBRT) $(LIBFROG)
 
 # don't try linking xfs_repair with a debug libxfs.
 DEBUG = -DNDEBUG
libxfs/util.c +0 -160

184 lines not on this page · raw message

#13 lore raw

PATCH 4/40 libfrog: fix missing gettext call in current_fixed_time

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

This error message can be seen by regular users, so it should be looked up in the internationalization catalogue with gettext.

---
 libfrog/util.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libfrog/util.c +2 -2
index d49cf72426f6c8..5bae5bab46f91d 100644
@@ -83,8 +83,8 @@ current_fixed_time(
 			epoch = strtoll(source_date_epoch, &endp, 10);
 			if (errno != 0 || *endp != '\0') {
 				fprintf(stderr,
-			"%s: SOURCE_DATE_EPOCH '%s' invalid timestamp, ignoring.\n",
-				progname, source_date_epoch);
+ _("%s: SOURCE_DATE_EPOCH '%s' invalid timestamp, ignoring.\n"),
+						progname, source_date_epoch);
 
 				return false;
 			}
#14 lore raw

PATCH 5/40 xfs: start creating infrastructure for health monitoring

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: a48373e7d35a89f6f9b39f0d0da9bf158af054ee

Start creating helper functions and infrastructure to pass filesystem health events to a health monitoring file. Since this is an administrative interface, we only support a single health monitor process per filesystem, so we don't need to use anything fancy such as notifier chains (== tons of indirect calls).

---
 libxfs/xfs_fs.h |    7 +++++++
 1 file changed, 7 insertions(+)
libxfs/xfs_fs.h +7 -0
index 12463ba766da05..c58e55b3df4099 100644
@@ -1003,6 +1003,12 @@ struct xfs_rtgroup_geometry {
 #define XFS_RTGROUP_GEOM_SICK_RMAPBT	(1U << 3)  /* reverse mappings */
 #define XFS_RTGROUP_GEOM_SICK_REFCNTBT	(1U << 4)  /* reference counts */
 
+struct xfs_health_monitor {
+	__u64	flags;		/* flags */
+	__u8	format;		/* output format */
+	__u8	pad[23];	/* zeroes */
+};
+
 /*
  * ioctl commands that are used by Linux filesystems
  */
@@ -1042,6 +1048,7 @@ struct xfs_rtgroup_geometry {
 #define XFS_IOC_GETPARENTS_BY_HANDLE _IOWR('X', 63, struct xfs_getparents_by_handle)
 #define XFS_IOC_SCRUBV_METADATA	_IOWR('X', 64, struct xfs_scrub_vec_head)
 #define XFS_IOC_RTGROUP_GEOMETRY _IOWR('X', 65, struct xfs_rtgroup_geometry)
+#define XFS_IOC_HEALTH_MONITOR	_IOW ('X', 68, struct xfs_health_monitor)
 
 /*
  * ioctl commands that replace IRIX syssgi()'s
#15 lore raw

PATCH 6/40 xfs: create event queuing, formatting, and discovery infrastructure

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: b3a289a2a9397b2e731f334d7d36623a0f9192c5

Create the basic infrastructure that we need to report health events to userspace. We need a compact form for recording critical information about an event and queueing them; a means to notice that we've lost some events; and a means to format the events into something that userspace can handle. Make the kernel export C structures via read().

In a previous iteration of this new subsystem, I wanted to explore data exchange formats that are more flexible and easier for humans to read than C structures. The thought being that when we want to rev (or worse, enlarge) the event format, it ought to be trivially easy to do that in a way that doesn't break old userspace.

I looked at formats such as protobufs and capnproto. These look really nice in that extending the wire format is fairly easy, you can give it a data schema and it generates the serialization code for you, handles endianness problems, etc. The huge downside is that neither support C all that well.

Too hard, and didn't want to port either of those huge sprawling libraries first to the kernel and then again to xfsprogs. Then I thought, how about JSON? Javascript objects are human readable, the kernel can emit json without much fuss (it's all just strings!) and there are plenty of interpreters for python/rust/c/etc.

There's a proposed schema format for json, which means that xfs can publish a description of the events that kernel will emit. Userspace consumers (e.g. xfsprogs/xfs_healer) can embed the same schema document and use it to validate the incoming events from the kernel, which means it can discard events that it doesn't understand, or garbage being emitted due to bugs.

However, json has a huge crutch -- javascript is well known for its vague definitions of what are numbers. This makes expressing a large number rather fraught, because the runtime is free to represent a number in nearly any way it wants. Stupider ones will truncate values to word size, others will roll out doubles for uint52_t (yes, fifty-two) with the resulting loss of precision. Not good when you're dealing with discrete units.

It just so happens that python's json library is smart enough to see a sequence of digits and put them in a u64 (at least on x86_64/aarch64) but an actual javascript interpreter (pasting into Firefox) isn't necessarily so clever.

It turns out that none of the proposed json schemas were ever ratified even in an open-consensus way, so json blobs are still just loosely structured blobs. The parsing in userspace was also noticeably slow and memory-consumptive.

Hence only the C interface survives.

---
 libxfs/xfs_fs.h |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
libxfs/xfs_fs.h +47 -0
index c58e55b3df4099..22b86bc888de5a 100644
@@ -1003,12 +1003,59 @@ struct xfs_rtgroup_geometry {
 #define XFS_RTGROUP_GEOM_SICK_RMAPBT	(1U << 3)  /* reverse mappings */
 #define XFS_RTGROUP_GEOM_SICK_REFCNTBT	(1U << 4)  /* reference counts */
 
+/* Health monitor event domains */
+
+/* affects the whole fs */
+#define XFS_HEALTH_MONITOR_DOMAIN_MOUNT		(0)
+
+/* Health monitor event types */
+
+/* status of the monitor itself */
+#define XFS_HEALTH_MONITOR_TYPE_RUNNING		(0)
+#define XFS_HEALTH_MONITOR_TYPE_LOST		(1)
+
+/* lost events */
+struct xfs_health_monitor_lost {
+	__u64	count;
+};
+
+struct xfs_health_monitor_event {
+	/* XFS_HEALTH_MONITOR_DOMAIN_* */
+	__u32	domain;
+
+	/* XFS_HEALTH_MONITOR_TYPE_* */
+	__u32	type;
+
+	/* Timestamp of the event, in nanoseconds since the Unix epoch */
+	__u64	time_ns;
+
+	/*
+	 * Details of the event.  The primary clients are written in python
+	 * and rust, so break this up because bindgen hates anonymous structs
+	 * and unions.
+	 */
+	union {
+		struct xfs_health_monitor_lost lost;
+	} e;
+
+	/* zeroes */
+	__u64	pad[2];
+};
+
 struct xfs_health_monitor {
 	__u64	flags;		/* flags */
 	__u8	format;		/* output format */
 	__u8	pad[23];	/* zeroes */
 };
 
+/* Return all health status events, not just deltas */
+#define XFS_HEALTH_MONITOR_VERBOSE	(1ULL << 0)
+
+#define XFS_HEALTH_MONITOR_ALL		(XFS_HEALTH_MONITOR_VERBOSE)
+
+/* Initial return format version */
+#define XFS_HEALTH_MONITOR_FMT_V0	(0)
+
 /*
  * ioctl commands that are used by Linux filesystems
  */
#16 lore raw

PATCH 7/40 xfs: convey filesystem unmount events to the health monitor

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: 25ca57fa3624cae9c6b5c6d3fc7f38318ca1402e

In xfs_healthmon_unmount, send events to xfs_healer so that it knows that nothing further can be done for the filesystem.

---
 libxfs/xfs_fs.h |    3 +++
 1 file changed, 3 insertions(+)
libxfs/xfs_fs.h +3 -0
index 22b86bc888de5a..59de6ab69fb319 100644
@@ -1014,6 +1014,9 @@ struct xfs_rtgroup_geometry {
 #define XFS_HEALTH_MONITOR_TYPE_RUNNING		(0)
 #define XFS_HEALTH_MONITOR_TYPE_LOST		(1)
 
+/* filesystem was unmounted */
+#define XFS_HEALTH_MONITOR_TYPE_UNMOUNT		(2)
+
 /* lost events */
 struct xfs_health_monitor_lost {
 	__u64	count;
#17 lore raw

PATCH 8/40 xfs: convey metadata health events to the health monitor

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: 5eb4cb18e445d09f64ef4b7c8fdc3b2296cb0702

Connect the filesystem metadata health event collection system to the health monitor so that xfs can send events to xfs_healer as it collects information.

---
 libxfs/xfs_fs.h     |   35 +++++++++++++++++++++++++++++++++++
 libxfs/xfs_health.h |    5 +++++
 2 files changed, 40 insertions(+)
libxfs/xfs_fs.h +35 -0
index 59de6ab69fb319..04e1dcf61257d0 100644
@@ -1008,6 +1008,12 @@ struct xfs_rtgroup_geometry {
 /* affects the whole fs */
 #define XFS_HEALTH_MONITOR_DOMAIN_MOUNT		(0)
 
+/* metadata health events */
+#define XFS_HEALTH_MONITOR_DOMAIN_FS		(1)
+#define XFS_HEALTH_MONITOR_DOMAIN_AG		(2)
+#define XFS_HEALTH_MONITOR_DOMAIN_INODE		(3)
+#define XFS_HEALTH_MONITOR_DOMAIN_RTGROUP	(4)
+
 /* Health monitor event types */
 
 /* status of the monitor itself */
@@ -1017,11 +1023,37 @@ struct xfs_rtgroup_geometry {
 /* filesystem was unmounted */
 #define XFS_HEALTH_MONITOR_TYPE_UNMOUNT		(2)
 
+/* metadata health events */
+#define XFS_HEALTH_MONITOR_TYPE_SICK		(3)
+#define XFS_HEALTH_MONITOR_TYPE_CORRUPT		(4)
+#define XFS_HEALTH_MONITOR_TYPE_HEALTHY		(5)
+
 /* lost events */
 struct xfs_health_monitor_lost {
 	__u64	count;
 };
 
+/* fs/rt metadata */
+struct xfs_health_monitor_fs {
+	/* XFS_FSOP_GEOM_SICK_* flags */
+	__u32	mask;
+};
+
+/* ag/rtgroup metadata */
+struct xfs_health_monitor_group {
+	/* XFS_{AG,RTGROUP}_SICK_* flags */
+	__u32	mask;
+	__u32	gno;
+};
+
+/* inode metadata */
+struct xfs_health_monitor_inode {
+	/* XFS_BS_SICK_* flags */
+	__u32	mask;
+	__u32	gen;
+	__u64	ino;
+};
+
 struct xfs_health_monitor_event {
 	/* XFS_HEALTH_MONITOR_DOMAIN_* */
 	__u32	domain;
@@ -1039,6 +1071,9 @@ struct xfs_health_monitor_event {
 	 */
 	union {
 		struct xfs_health_monitor_lost lost;
+		struct xfs_health_monitor_fs fs;
+		struct xfs_health_monitor_group group;
+		struct xfs_health_monitor_inode inode;
 	} e;
 
 	/* zeroes */
libxfs/xfs_health.h +5 -0
index b31000f7190ce5..1d45cf5789e864 100644
@@ -289,4 +289,9 @@ void xfs_bulkstat_health(struct xfs_inode *ip, struct xfs_bulkstat *bs);
 #define xfs_metadata_is_sick(error) \
 	(unlikely((error) == -EFSCORRUPTED || (error) == -EFSBADCRC))
 
+unsigned int xfs_healthmon_inode_mask(unsigned int sick_mask);
+unsigned int xfs_healthmon_rtgroup_mask(unsigned int sick_mask);
+unsigned int xfs_healthmon_perag_mask(unsigned int sick_mask);
+unsigned int xfs_healthmon_fs_mask(unsigned int sick_mask);
+
 #endif	/* __XFS_HEALTH_H__ */
#18 lore raw

PATCH 9/40 xfs: convey filesystem shutdown events to the health monitor

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: 74c4795e50f816dbf5cf094691fc4f95bbc729ad

Connect the filesystem shutdown code to the health monitor so that xfs can send events about that to the xfs_healer daemon.

---
 libxfs/xfs_fs.h |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
libxfs/xfs_fs.h +18 -0
index 04e1dcf61257d0..c8f7011a7ef8ef 100644
@@ -1028,6 +1028,9 @@ struct xfs_rtgroup_geometry {
 #define XFS_HEALTH_MONITOR_TYPE_CORRUPT		(4)
 #define XFS_HEALTH_MONITOR_TYPE_HEALTHY		(5)
 
+/* filesystem shutdown */
+#define XFS_HEALTH_MONITOR_TYPE_SHUTDOWN	(6)
+
 /* lost events */
 struct xfs_health_monitor_lost {
 	__u64	count;
@@ -1054,6 +1057,20 @@ struct xfs_health_monitor_inode {
 	__u64	ino;
 };
 
+/* shutdown reasons */
+#define XFS_HEALTH_SHUTDOWN_META_IO_ERROR	(1u << 0)
+#define XFS_HEALTH_SHUTDOWN_LOG_IO_ERROR	(1u << 1)
+#define XFS_HEALTH_SHUTDOWN_FORCE_UMOUNT	(1u << 2)
+#define XFS_HEALTH_SHUTDOWN_CORRUPT_INCORE	(1u << 3)
+#define XFS_HEALTH_SHUTDOWN_CORRUPT_ONDISK	(1u << 4)
+#define XFS_HEALTH_SHUTDOWN_DEVICE_REMOVED	(1u << 5)
+
+/* shutdown */
+struct xfs_health_monitor_shutdown {
+	/* XFS_HEALTH_SHUTDOWN_* flags */
+	__u32	reasons;
+};
+
 struct xfs_health_monitor_event {
 	/* XFS_HEALTH_MONITOR_DOMAIN_* */
 	__u32	domain;
@@ -1074,6 +1091,7 @@ struct xfs_health_monitor_event {
 		struct xfs_health_monitor_fs fs;
 		struct xfs_health_monitor_group group;
 		struct xfs_health_monitor_inode inode;
+		struct xfs_health_monitor_shutdown shutdown;
 	} e;
 
 	/* zeroes */
#19 lore raw

PATCH 10/40 xfs: convey externally discovered fsdax media errors to the health monitor

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: e76e0e3fc9957a5183ddc51dc84c3e471125ab06

Connect the fsdax media failure notification code to the health monitor so that xfs can send events about that to the xfs_healer daemon.

Later on we'll add the ability for the xfs_scrub media scan (phase 6) to report the errors that it finds to the kernel so that those are also logged by xfs_healer.

---
 libxfs/xfs_fs.h |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
libxfs/xfs_fs.h +15 -0
index c8f7011a7ef8ef..38aeb1b0d87b5e 100644
@@ -1014,6 +1014,11 @@ struct xfs_rtgroup_geometry {
 #define XFS_HEALTH_MONITOR_DOMAIN_INODE		(3)
 #define XFS_HEALTH_MONITOR_DOMAIN_RTGROUP	(4)
 
+/* disk events */
+#define XFS_HEALTH_MONITOR_DOMAIN_DATADEV	(5)
+#define XFS_HEALTH_MONITOR_DOMAIN_RTDEV		(6)
+#define XFS_HEALTH_MONITOR_DOMAIN_LOGDEV	(7)
+
 /* Health monitor event types */
 
 /* status of the monitor itself */
@@ -1031,6 +1036,9 @@ struct xfs_rtgroup_geometry {
 /* filesystem shutdown */
 #define XFS_HEALTH_MONITOR_TYPE_SHUTDOWN	(6)
 
+/* media errors */
+#define XFS_HEALTH_MONITOR_TYPE_MEDIA_ERROR	(7)
+
 /* lost events */
 struct xfs_health_monitor_lost {
 	__u64	count;
@@ -1071,6 +1079,12 @@ struct xfs_health_monitor_shutdown {
 	__u32	reasons;
 };
 
+/* disk media errors */
+struct xfs_health_monitor_media {
+	__u64	daddr;
+	__u64	bbcount;
+};
+
 struct xfs_health_monitor_event {
 	/* XFS_HEALTH_MONITOR_DOMAIN_* */
 	__u32	domain;
@@ -1092,6 +1106,7 @@ struct xfs_health_monitor_event {
 		struct xfs_health_monitor_group group;
 		struct xfs_health_monitor_inode inode;
 		struct xfs_health_monitor_shutdown shutdown;
+		struct xfs_health_monitor_media media;
 	} e;
 
 	/* zeroes */
#20 lore raw

PATCH 11/40 xfs: convey file I/O errors to the health monitor

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: dfa8bad3a8796ce1ca4f1d15158e2ecfb9c5c014

Connect the fserror reporting to the health monitor so that xfs can send events about file I/O errors to the xfs_healer daemon. These events are entirely informational because xfs cannot regenerate user data, so hopefully the fsnotify I/O error event gets noticed by the relevant management systems.

---
 libxfs/xfs_fs.h |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
libxfs/xfs_fs.h +24 -0
index 38aeb1b0d87b5e..4ec1b2aede976f 100644
@@ -1019,6 +1019,9 @@ struct xfs_rtgroup_geometry {
 #define XFS_HEALTH_MONITOR_DOMAIN_RTDEV		(6)
 #define XFS_HEALTH_MONITOR_DOMAIN_LOGDEV	(7)
 
+/* file range events */
+#define XFS_HEALTH_MONITOR_DOMAIN_FILERANGE	(8)
+
 /* Health monitor event types */
 
 /* status of the monitor itself */
@@ -1039,6 +1042,17 @@ struct xfs_rtgroup_geometry {
 /* media errors */
 #define XFS_HEALTH_MONITOR_TYPE_MEDIA_ERROR	(7)
 
+/* pagecache I/O to a file range failed */
+#define XFS_HEALTH_MONITOR_TYPE_BUFREAD		(8)
+#define XFS_HEALTH_MONITOR_TYPE_BUFWRITE	(9)
+
+/* direct I/O to a file range failed */
+#define XFS_HEALTH_MONITOR_TYPE_DIOREAD		(10)
+#define XFS_HEALTH_MONITOR_TYPE_DIOWRITE	(11)
+
+/* out of band media error reported for a file range */
+#define XFS_HEALTH_MONITOR_TYPE_DATALOST	(12)
+
 /* lost events */
 struct xfs_health_monitor_lost {
 	__u64	count;
@@ -1079,6 +1093,15 @@ struct xfs_health_monitor_shutdown {
 	__u32	reasons;
 };
 
+/* file range events */
+struct xfs_health_monitor_filerange {
+	__u64	pos;
+	__u64	len;
+	__u64	ino;
+	__u32	gen;
+	__u32	error;
+};
+
 /* disk media errors */
 struct xfs_health_monitor_media {
 	__u64	daddr;
@@ -1107,6 +1130,7 @@ struct xfs_health_monitor_event {
 		struct xfs_health_monitor_inode inode;
 		struct xfs_health_monitor_shutdown shutdown;
 		struct xfs_health_monitor_media media;
+		struct xfs_health_monitor_filerange filerange;
 	} e;
 
 	/* zeroes */
#21 lore raw

PATCH 12/40 xfs: check if an open file is on the health monitored fs

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: 8b85dc4090e1c72c6d42acd823514cce67cd54fc

Create a new ioctl for the healthmon file that checks that a given fd points to the same filesystem that the healthmon file is monitoring. This allows xfs_healer to check that when it reopens a mountpoint to perform repairs, the file that it gets matches the filesystem that generated the corruption report.

(Note that xfs_healer doesn't maintain an open fd to a filesystem that it's monitoring so that it doesn't pin the mount.)

---
 libxfs/xfs_fs.h |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +11 -1
index 4ec1b2aede976f..a01303c5de6ce6 100644
@@ -1151,6 +1151,15 @@ struct xfs_health_monitor {
 /* Initial return format version */
 #define XFS_HEALTH_MONITOR_FMT_V0	(0)
 
+/*
+ * Check that a given fd points to the same filesystem that the health monitor
+ * is monitoring.
+ */
+struct xfs_health_file_on_monitored_fs {
+	__s32		fd;
+	__u32		flags;	/* zero for now */
+};
+
 /*
  * ioctl commands that are used by Linux filesystems
  */
@@ -1191,7 +1200,8 @@ struct xfs_health_monitor {
 #define XFS_IOC_SCRUBV_METADATA	_IOWR('X', 64, struct xfs_scrub_vec_head)
 #define XFS_IOC_RTGROUP_GEOMETRY _IOWR('X', 65, struct xfs_rtgroup_geometry)
 #define XFS_IOC_HEALTH_MONITOR	_IOW ('X', 68, struct xfs_health_monitor)
-
+#define XFS_IOC_HEALTH_FD_ON_MONITORED_FS \
+				_IOW ('X', 69, struct xfs_health_file_on_monitored_fs)
 /*
  * ioctl commands that replace IRIX syssgi()'s
  */
#22 lore raw

PATCH 13/40 xfs: add media verification ioctl

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: b8accfd65d31f25b9df15ec2419179b6fa0b21d5

Add a new privileged ioctl so that xfs_scrub can ask the kernel to verify the media of the devices backing an xfs filesystem, and have any resulting media errors reported to fsnotify and xfs_healer.

To accomplish this, the kernel allocates a folio between the base page size and 1MB, and issues read IOs to a gradually incrementing range of one of the storage devices underlying an xfs filesystem. If any error occurs, that raw error is reported to the calling process. If the error happens to be one of the ones that the kernel considers indicative of data loss, then it will also be reported to xfs_healthmon and fsnotify.

Driving the verification from the kernel enables xfs (and by extension xfs_scrub) to have precise control over the size and error handling of IOs that are issued to the underlying block device, and to emit notifications about problems to other relevant kernel subsystems immediately.

Note that the caller is also allowed to reduce the size of the IO and to ask for a relaxation period after each IO.

---
 libxfs/xfs_fs.h |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
libxfs/xfs_fs.h +30 -0
index a01303c5de6ce6..d165de607d179e 100644
@@ -1160,6 +1160,34 @@ struct xfs_health_file_on_monitored_fs {
 	__u32		flags;	/* zero for now */
 };
 
+/* Verify the media of the underlying devices */
+struct xfs_verify_media {
+	__u32	me_dev;		/* I: XFS_DEV_{DATA,LOG,RT} */
+	__u32	me_flags;	/* I: XFS_VERIFY_MEDIA_* */
+
+	/*
+	 * IO: inclusive start of disk range to verify, in 512b blocks.
+	 * Will be adjusted upwards as media verification succeeds.
+	 */
+	__u64	me_start_daddr;
+
+	/*
+	 * IO: exclusive end of the disk range to verify, in 512b blocks.
+	 * Can be adjusted downwards to match device size.
+	 */
+	__u64	me_end_daddr;
+
+	__u32	me_ioerror;	/* O: I/O error (positive) */
+	__u32	me_max_io_size;	/* I: maximum IO size in bytes */
+
+	__u32	me_rest_us;	/* I: rest time between IOs, usecs */
+	__u32	me_pad;		/* zero */
+};
+
+#define XFS_VERIFY_MEDIA_REPORT	(1 << 0)	/* report to fsnotify */
+
+#define XFS_VERIFY_MEDIA_FLAGS	(XFS_VERIFY_MEDIA_REPORT)
+
 /*
  * ioctl commands that are used by Linux filesystems
  */
@@ -1202,6 +1230,8 @@ struct xfs_health_file_on_monitored_fs {
 #define XFS_IOC_HEALTH_MONITOR	_IOW ('X', 68, struct xfs_health_monitor)
 #define XFS_IOC_HEALTH_FD_ON_MONITORED_FS \
 				_IOW ('X', 69, struct xfs_health_file_on_monitored_fs)
+#define XFS_IOC_VERIFY_MEDIA	_IOWR('X', 70, struct xfs_verify_media)
+
 /*
  * ioctl commands that replace IRIX syssgi()'s
  */
#23 lore raw

PATCH 14/40 xfs: move struct xfs_log_iovec to xfs_log_priv.h

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: 027410591418bded6ba6051151d88fc6fb8a7614

This structure is now only used by the core logging and CIL code.

Also remove the unused typedef.

---
 libxfs/xfs_log_format.h   |    7 -------
 libxlog/xfs_log_recover.c |    4 ++--
 2 files changed, 2 insertions(+), 9 deletions(-)
libxfs/xfs_log_format.h +0 -7
index 908e7060428ccb..3f5a24dda90701 100644
@@ -184,13 +184,6 @@ struct xlog_rec_header {
 #define XLOG_REC_SIZE_OTHER	offsetofend(struct xlog_rec_header, h_size)
 #endif /* __i386__ */
 
-/* not an on-disk structure, but needed by log recovery in userspace */
-struct xfs_log_iovec {
-	void		*i_addr;	/* beginning address of region */
-	int		i_len;		/* length in bytes of region */
-	uint		i_type;		/* type of region */
-};
-
 /*
  * Transaction Header definitions.
  *
libxlog/xfs_log_recover.c +2 -2
index 65e3c782d59674..af72b97d150b75 100644
@@ -1112,8 +1112,8 @@ xlog_recover_add_to_trans(
 		}
 
 		item->ri_total = in_f->ilf_size;
-		item->ri_buf = kzalloc(
-			item->ri_total * sizeof(struct xfs_log_iovec), 0);
+		item->ri_buf = kcalloc(item->ri_total, sizeof(*item->ri_buf),
+				0);
 	}
 	ASSERT(item->ri_total > item->ri_cnt);
 	/* Description region is ri_buf[0] */
#24 lore raw

PATCH 15/40 xfs: directly include xfs_platform.h

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: cf9b52fa7d65362b648927d1d752ec99659f5c43

The xfs.h header conflicts with the public xfs.h in xfsprogs, leading to a spurious difference in all shared libxfs files that have to include libxfs_priv.h in userspace. Directly include xfs_platform.h so that we can add a header of the same name to xfsprogs and remove this major annoyance for the shared code.

---
 libxfs/xfs_platform.h         |    6 +++---
 libxfs/Makefile               |    2 +-
 libxfs/buf_mem.c              |    2 +-
 libxfs/cache.c                |    2 +-
 libxfs/defer_item.c           |    2 +-
 libxfs/init.c                 |    2 +-
 libxfs/inode.c                |    2 +-
 libxfs/iunlink.c              |    2 +-
 libxfs/kmem.c                 |    2 +-
 libxfs/logitem.c              |    2 +-
 libxfs/rdwr.c                 |    2 +-
 libxfs/topology.c             |    2 +-
 libxfs/trans.c                |    2 +-
 libxfs/util.c                 |    2 +-
 libxfs/xfblob.c               |    2 +-
 libxfs/xfile.c                |    2 +-
 libxfs/xfs_ag.c               |    2 +-
 libxfs/xfs_ag_resv.c          |    2 +-
 libxfs/xfs_alloc.c            |    2 +-
 libxfs/xfs_alloc_btree.c      |    2 +-
 libxfs/xfs_attr.c             |    2 +-
 libxfs/xfs_attr_leaf.c        |    2 +-
 libxfs/xfs_attr_remote.c      |    2 +-
 libxfs/xfs_bit.c              |    2 +-
 libxfs/xfs_bmap.c             |    2 +-
 libxfs/xfs_bmap_btree.c       |    2 +-
 libxfs/xfs_btree.c            |    2 +-
 libxfs/xfs_btree_mem.c        |    2 +-
 libxfs/xfs_btree_staging.c    |    2 +-
 libxfs/xfs_da_btree.c         |    2 +-
 libxfs/xfs_defer.c            |    2 +-
 libxfs/xfs_dir2.c             |    2 +-
 libxfs/xfs_dir2_block.c       |    2 +-
 libxfs/xfs_dir2_data.c        |    2 +-
 libxfs/xfs_dir2_leaf.c        |    2 +-
 libxfs/xfs_dir2_node.c        |    2 +-
 libxfs/xfs_dir2_sf.c          |    2 +-
 libxfs/xfs_dquot_buf.c        |    2 +-
 libxfs/xfs_exchmaps.c         |    2 +-
 libxfs/xfs_group.c            |    2 +-
 libxfs/xfs_ialloc.c           |    2 +-
 libxfs/xfs_ialloc_btree.c     |    2 +-
 libxfs/xfs_iext_tree.c        |    2 +-
 libxfs/xfs_inode_buf.c        |    2 +-
 libxfs/xfs_inode_fork.c       |    2 +-
 libxfs/xfs_inode_util.c       |    2 +-
 libxfs/xfs_log_rlimit.c       |    2 +-
 libxfs/xfs_metadir.c          |    2 +-
 libxfs/xfs_metafile.c         |    2 +-
 libxfs/xfs_parent.c           |    2 +-
 libxfs/xfs_refcount.c         |    2 +-
 libxfs/xfs_refcount_btree.c   |    2 +-
 libxfs/xfs_rmap.c             |    2 +-
 libxfs/xfs_rmap_btree.c       |    2 +-
 libxfs/xfs_rtbitmap.c         |    2 +-
 libxfs/xfs_rtgroup.c          |    2 +-
 libxfs/xfs_rtrefcount_btree.c |    2 +-
 libxfs/xfs_rtrmap_btree.c     |    2 +-
 libxfs/xfs_sb.c               |    2 +-
 libxfs/xfs_symlink_remote.c   |    2 +-
 libxfs/xfs_trans_inode.c      |    2 +-
 libxfs/xfs_trans_resv.c       |    2 +-
 libxfs/xfs_trans_space.c      |    2 +-
 libxfs/xfs_types.c            |    2 +-
 libxfs/xfs_zones.c            |    2 +-
 repair/zoned.c                |    2 +-
 66 files changed, 68 insertions(+), 68 deletions(-)
 rename libxfs/{libxfs_priv.h => xfs_platform.h} (99%)
libxfs/xfs_platform.h renamed from libxfs/libxfs_priv.h +3 -3
similarity index 99%
rename from libxfs/libxfs_priv.h
rename to libxfs/xfs_platform.h
index 32b86b1df677c2..5cddfbb82cc88c 100644
@@ -34,8 +34,8 @@
  * define a guard and something we can check to determine what include context
  * we are running from.
  */
-#ifndef __LIBXFS_INTERNAL_XFS_H__
-#define __LIBXFS_INTERNAL_XFS_H__
+#ifndef _XFS_PLATFORM_H
+#define _XFS_PLATFORM_H
 
 /* CONFIG_XFS_* must be defined to 1 to work with IS_ENABLED() */
 #define CONFIG_XFS_RT 1
@@ -604,4 +604,4 @@ int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
 #define irix_sgid_inherit		(false)
 #define vfsgid_in_group_p(...)		(false)
 
-#endif	/* __LIBXFS_INTERNAL_XFS_H__ */
+#endif	/* _XFS_PLATFORM_H */
libxfs/Makefile +1 -1
index c5e2161c33096a..83c8592e5fe536 100644
@@ -26,7 +26,7 @@ HFILES = \
 	listxattr.h \
 	init.h \
 	iunlink.h \
-	libxfs_priv.h \
+	xfs_platform.h \
 	linux-err.h \
 	topology.h \
 	buf_mem.h \
libxfs/buf_mem.c +1 -1
index 77396fa95b4138..15c61966db4384 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2023-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "libxfs.h"
 #include "libxfs/xfile.h"
 #include "libxfs/buf_mem.h"
libxfs/cache.c +1 -1
index af20f3854df93e..389afeff4a1f16 100644
@@ -10,7 +10,7 @@
 #include <unistd.h>
 #include <pthread.h>
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/defer_item.c +1 -1
index 3dc938d514e65e..4fc2c74a548c91 100644
@@ -3,7 +3,7 @@
  * Copyright (C) 2016 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/init.c +1 -1
index a5e898539c9eb2..5d8b4a153e28da 100644
@@ -7,7 +7,7 @@
 #include <sys/stat.h>
 #include "init.h"
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/inode.c +1 -1
index 1ce159fcc9d61a..dc7e227e8ee92f 100644
@@ -4,7 +4,7 @@
  * All Rights Reserved.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "libxfs.h"
 #include "libxfs_io.h"
 #include "init.h"
libxfs/iunlink.c +1 -1
index 53e36cdc3439b2..2d4dd0aee0b87b 100644
@@ -4,7 +4,7 @@
  * All Rights Reserved.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "libxfs.h"
 #include "libxfs_io.h"
 #include "init.h"
libxfs/kmem.c +1 -1
index 2e293518024fe3..718b190ad54607 100644
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 
 /*
  * Simple memory interface
libxfs/logitem.c +1 -1
index 062d6311b942ae..d8d86d919cf4d7 100644
@@ -4,7 +4,7 @@
  * All Rights Reserved.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/rdwr.c +1 -1
index 3419e821ef0a29..6c57bedef54852 100644
@@ -5,7 +5,7 @@
  */
 
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "init.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
libxfs/topology.c +1 -1
index 366165719c84ed..dc2aaa17ab3bda 100644
@@ -10,7 +10,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "libxcmd.h"
 #include <blkid/blkid.h>
 #include "xfs_multidisk.h"
libxfs/trans.c +1 -1
index 64457d1710bbd6..c89b035ffeaf10 100644
@@ -5,7 +5,7 @@
  * All Rights Reserved.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/util.c +1 -1
index 14b746ec705092..143d011ac60ddd 100644
@@ -4,7 +4,7 @@
  * All Rights Reserved.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "libxfs.h"
 #include "libxfs_io.h"
 #include "init.h"
libxfs/xfblob.c +1 -1
index 00f8ed5e5a7bef..597aeb75641641 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2022-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "libxfs.h"
 #include "libxfs/xfile.h"
 #include "libxfs/xfblob.h"
libxfs/xfile.c +1 -1
index b83797751b87ba..6532197ce6ab29 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2021-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "libxfs.h"
 #include "libxfs/xfile.h"
 #include <linux/memfd.h>
libxfs/xfs_ag.c +1 -1
index ea64e9eac58945..8ccd67672b4e00 100644
@@ -5,7 +5,7 @@
  * All rights reserved.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_ag_resv.c +1 -1
index 842e797b2f9c68..052d187330460e 100644
@@ -3,7 +3,7 @@
  * Copyright (C) 2016 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_alloc.c +1 -1
index 311f5342d6e982..9f92bd77fad76c 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_format.h"
 #include "xfs_log_format.h"
libxfs/xfs_alloc_btree.c +1 -1
index 1604e1bb625116..54f0ff75a23805 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_attr.c +1 -1
index 4b985e054ff84c..72b701f1b6dcae 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_attr_leaf.c +1 -1
index 29e9a419d07c8b..ff1085f0b3afe4 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_attr_remote.c +1 -1
index 82217baf405bc1..89d01aa7b051e8 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_bit.c +1 -1
index 3f97fa3e725686..f05a07c0f75da3 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_log_format.h"
 #include "xfs_bit.h"
 
libxfs/xfs_bmap.c +1 -1
index f2f616e521759e..96975f88497add 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_bmap_btree.c +1 -1
index 252da347b06e15..6038c45674557b 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_btree.c +1 -1
index 1404d86fb96394..4ab0d8d3789b18 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_btree_mem.c +1 -1
index 2b98b8d01dce0d..5fa4a9787c99ab 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2021-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_btree_staging.c +1 -1
index d82665ef78398e..4300c058807ba5 100644
@@ -3,7 +3,7 @@
  * Copyright (C) 2020 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_da_btree.c +1 -1
index 37be99bd54c772..969bfc9dee909d 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_defer.c +1 -1
index 8f6708c0f3bfcd..5bd3cbe4cfa1a3 100644
@@ -3,7 +3,7 @@
  * Copyright (C) 2016 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_dir2.c +1 -1
index d5f2e516e5bfea..2ca6bf198ba54f 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_dir2_block.c +1 -1
index 82da0d3275e366..29b5b158c80d1f 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_dir2_data.c +1 -1
index 65e6ed8791ed9f..1fb43cdfdd6d04 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_dir2_leaf.c +1 -1
index 7c0bba51288142..b89350b03b8724 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_dir2_node.c +1 -1
index c94d00eb99c874..9d8bb27f716fe4 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_dir2_sf.c +1 -1
index aaf73cd35ca753..1a67cdd6a70706 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_dquot_buf.c +1 -1
index 599d03ac960b7b..329aceca005db7 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_exchmaps.c +1 -1
index 8e39324d42ca25..5566f9faf45612 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2020-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_group.c +1 -1
index 03c508242d52f6..cb841514750978 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2018 Red Hat, Inc.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
 #include "xfs_trans_resv.h"
libxfs/xfs_ialloc.c +1 -1
index 1da6f07fa030d0..31c818f9870f8d 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_ialloc_btree.c +1 -1
index dab9b61bd2006f..e0d886f324d89c 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_iext_tree.c +1 -1
index cdbb72d6387823..5b2b926ab2285f 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2017 Christoph Hellwig.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
 #include "xfs_bit.h"
libxfs/xfs_inode_buf.c +1 -1
index e2c87ca03cc39b..0802bc376073d8 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_inode_fork.c +1 -1
index 329d52cc524a16..87afe671886ede 100644
@@ -4,7 +4,7 @@
  * All Rights Reserved.
  */
 
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_inode_util.c +1 -1
index 85d4af41d56de5..ccd38f18c3ed55 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_log_rlimit.c +1 -1
index 2b9047f5ffb58b..37712b2f87572e 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2013 Jie Liu.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_metadir.c +1 -1
index 253fbf48e170e0..bffe9ba9129002 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2018-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_metafile.c +1 -1
index 9c3751f58161e0..8d98989349d086 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2018-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_parent.c +1 -1
index 84220f10a1f409..12e4299840b8ef 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2022-2024 Oracle.
  * All rights reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_format.h"
 #include "xfs_da_format.h"
libxfs/xfs_refcount.c +1 -1
index f9714acd9a5a1b..5c362e0e901124 100644
@@ -3,7 +3,7 @@
  * Copyright (C) 2016 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_refcount_btree.c +1 -1
index 44d942e9d098e1..5a39dbbc635ca4 100644
@@ -3,7 +3,7 @@
  * Copyright (C) 2016 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_rmap.c +1 -1
index 33e856875db419..9da10afe3578b5 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2014 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_rmap_btree.c +1 -1
index d7b9fccc3a0f5d..c39faa4aac6c2b 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2014 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_rtbitmap.c +1 -1
index 354ebb8d066e09..7a06305b4e11dd 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_rtgroup.c +1 -1
index d012ca73000d86..af4eafb20bc138 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2022-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_rtrefcount_btree.c +1 -1
index 77191f073a10bb..f893677e0fcd32 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2021-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_rtrmap_btree.c +1 -1
index 633dca0333f4e7..7191bf445c399b 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2018-2024 Oracle.  All Rights Reserved.
  * Author: Darrick J. Wong <[email protected]>
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_sb.c +1 -1
index 3e2d3c6da19631..b29077dcd0aed7 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_symlink_remote.c +1 -1
index 1c355f751e1cc7..d29eae498c493e 100644
@@ -4,7 +4,7 @@
  * Copyright (c) 2012-2013 Red Hat, Inc.
  * All rights reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_format.h"
 #include "xfs_log_format.h"
libxfs/xfs_trans_inode.c +1 -1
index 90eec4d3592dea..ef404e7f0f6e91 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_trans_resv.c +1 -1
index b3b9d22b54515d..9294b72e61b77e 100644
@@ -4,7 +4,7 @@
  * Copyright (C) 2010 Red Hat, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_trans_space.c +1 -1
index 373f5cc24977a8..9b8f495c9049cc 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
 #include "xfs_format.h"
libxfs/xfs_types.c +1 -1
index 4e24599c369397..67c947a47f1478 100644
@@ -4,7 +4,7 @@
  * Copyright (C) 2017 Oracle.
  * All Rights Reserved.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs_fs.h"
 #include "xfs_format.h"
 #include "xfs_shared.h"
libxfs/xfs_zones.c +1 -1
index 90e2ba0908be5d..e31e1dc0913efe 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2023-2025 Christoph Hellwig.
  * Copyright (c) 2024-2025, Western Digital Corporation or its affiliates.
  */
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "xfs.h"
 #include "xfs_fs.h"
 #include "xfs_shared.h"
repair/zoned.c +1 -1
index 07e676ac7fd3f6..c721709d137064 100644
@@ -3,7 +3,7 @@
  * Copyright (c) 2024 Christoph Hellwig.
  */
 #include <ctype.h>
-#include "libxfs_priv.h"
+#include "xfs_platform.h"
 #include "libxfs.h"
 #include "xfs_zones.h"
 #include "libfrog/zones.h"
#25 lore raw

PATCH 16/40 xfs: remove xfs_attr_leaf_hasname

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: 3a65ea768b8094e4699e72f9ab420eb9e0f3f568

The calling convention of xfs_attr_leaf_hasname() is problematic, because it returns a NULL buffer when xfs_attr3_leaf_read fails, a valid buffer when xfs_attr3_leaf_lookup_int returns -ENOATTR or -EEXIST, and a non-NULL buffer pointer for an already released buffer when xfs_attr3_leaf_lookup_int fails with other error values.

Fix this by simply open coding xfs_attr_leaf_hasname in the callers, so that the buffer release code is done by each caller of xfs_attr3_leaf_read.

Fixes 07120f1abdff ("xfs: Add xfs_has_attr and subroutines")
---
 libxfs/xfs_attr.c |   75 +++++++++++++++++------------------------------------
 1 file changed, 24 insertions(+), 51 deletions(-)
libxfs/xfs_attr.c +24 -51
index 72b701f1b6dcae..baf617cfeabe00 100644
@@ -49,7 +49,6 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
  */
 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
-STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
 
 /*
  * Internal routines when attribute list is more than one block.
@@ -978,11 +977,12 @@ xfs_attr_lookup(
 		return error;
 
 	if (xfs_attr_is_leaf(dp)) {
-		error = xfs_attr_leaf_hasname(args, &bp);
-
-		if (bp)
-			xfs_trans_brelse(args->trans, bp);
-
+		error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner,
+				0, &bp);
+		if (error)
+			return error;
+		error = xfs_attr3_leaf_lookup_int(bp, args);
+		xfs_trans_brelse(args->trans, bp);
 		return error;
 	}
 
@@ -1221,27 +1221,6 @@ xfs_attr_shortform_addname(
  * External routines when attribute list is one block
  *========================================================================*/
 
-/*
- * Return EEXIST if attr is found, or ENOATTR if not
- */
-STATIC int
-xfs_attr_leaf_hasname(
-	struct xfs_da_args	*args,
-	struct xfs_buf		**bp)
-{
-	int                     error = 0;
-
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, bp);
-	if (error)
-		return error;
-
-	error = xfs_attr3_leaf_lookup_int(*bp, args);
-	if (error != -ENOATTR && error != -EEXIST)
-		xfs_trans_brelse(args->trans, *bp);
-
-	return error;
-}
-
 /*
  * Remove a name from the leaf attribute list structure
  *
@@ -1252,25 +1231,22 @@ STATIC int
 xfs_attr_leaf_removename(
 	struct xfs_da_args	*args)
 {
-	struct xfs_inode	*dp;
-	struct xfs_buf		*bp;
+	struct xfs_inode	*dp = args->dp;
 	int			error, forkoff;
+	struct xfs_buf		*bp;
 
 	trace_xfs_attr_leaf_removename(args);
 
-	/*
-	 * Remove the attribute.
-	 */
-	dp = args->dp;
-
-	error = xfs_attr_leaf_hasname(args, &bp);
-	if (error == -ENOATTR) {
+	error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, &bp);
+	if (error)
+		return error;
+	error = xfs_attr3_leaf_lookup_int(bp, args);
+	if (error != -EEXIST) {
 		xfs_trans_brelse(args->trans, bp);
-		if (args->op_flags & XFS_DA_OP_RECOVERY)
+		if (error == -ENOATTR && (args->op_flags & XFS_DA_OP_RECOVERY))
 			return 0;
 		return error;
-	} else if (error != -EEXIST)
-		return error;
+	}
 
 	xfs_attr3_leaf_remove(bp, args);
 
@@ -1294,23 +1270,20 @@ xfs_attr_leaf_removename(
  * Returns 0 on successful retrieval, otherwise an error.
  */
 STATIC int
-xfs_attr_leaf_get(xfs_da_args_t *args)
+xfs_attr_leaf_get(
+	struct xfs_da_args	*args)
 {
-	struct xfs_buf *bp;
-	int error;
+	struct xfs_buf		*bp;
+	int			error;
 
 	trace_xfs_attr_leaf_get(args);
 
-	error = xfs_attr_leaf_hasname(args, &bp);
-
-	if (error == -ENOATTR)  {
-		xfs_trans_brelse(args->trans, bp);
+	error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, &bp);
+	if (error)
 		return error;
-	} else if (error != -EEXIST)
-		return error;
-
-
-	error = xfs_attr3_leaf_getvalue(bp, args);
+	error = xfs_attr3_leaf_lookup_int(bp, args);
+	if (error == -EEXIST)
+		error = xfs_attr3_leaf_getvalue(bp, args);
 	xfs_trans_brelse(args->trans, bp);
 	return error;
 }
#26 lore raw

PATCH 17/40 xfs: add missing forward declaration in xfs_zones.h

In reply to Darrick J. Wong

From: Damien Le Moal <[email protected]>

Source kernel commit: 41263267ef26d315b1425eb9c8a8d7092f9db7c8

Add the missing forward declaration for struct blk_zone in xfs_zones.h. This avoids headaches with the order of header file inclusion to avoid compilation errors.

---
 libxfs/xfs_zones.h |    1 +
 1 file changed, 1 insertion(+)
libxfs/xfs_zones.h +1 -0
index 5fefd132e002ee..df10a34da71d64 100644
@@ -3,6 +3,7 @@
 #define _LIBXFS_ZONES_H
 
 struct xfs_rtgroup;
+struct blk_zone;
 
 /*
  * In order to guarantee forward progress for GC we need to reserve at least
#27 lore raw

PATCH 18/40 xfs: add a xfs_rtgroup_raw_size helper

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: fc633b5c5b80c1d840b7a8bc2828be96582c6b55

Add a helper to figure the on-disk size of a group, accounting for the XFS_SB_FEAT_INCOMPAT_ZONE_GAPS feature if needed.

---
 libxfs/xfs_rtgroup.h |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
libxfs/xfs_rtgroup.h +15 -0
index 73cace4d25c791..c0b9f9f2c4131b 100644
@@ -371,4 +371,19 @@ xfs_rtgs_to_rfsbs(
 	return xfs_groups_to_rfsbs(mp, nr_groups, XG_TYPE_RTG);
 }
 
+/*
+ * Return the "raw" size of a group on the hardware device.  This includes the
+ * daddr gaps present for XFS_SB_FEAT_INCOMPAT_ZONE_GAPS file systems.
+ */
+static inline xfs_rgblock_t
+xfs_rtgroup_raw_size(
+	struct xfs_mount	*mp)
+{
+	struct xfs_groups	*g = &mp->m_groups[XG_TYPE_RTG];
+
+	if (g->has_daddr_gaps)
+		return 1U << g->blklog;
+	return g->blocks;
+}
+
 #endif /* __LIBXFS_RTGROUP_H */
#28 lore raw

PATCH 19/40 xfs: split and refactor zone validation

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: 19c5b6051ed62d8c4b1cf92e463c1bcf629107f4

Currently xfs_zone_validate mixes validating the software zone state in the XFS realtime group with validating the hardware state reported in struct blk_zone and deriving the write pointer from that.

Move all code that works on the realtime group to xfs_init_zone, and only keep the hardware state validation in xfs_zone_validate. This makes the code more clear, and allows for better reuse in userspace.

---
 libxfs/libxfs_api_defs.h |    2 -
 libxfs/xfs_zones.h       |    5 +-
 libxfs/xfs_zones.c       |  149 ++++++++++++----------------------------------
 repair/zoned.c           |    5 +-
 4 files changed, 47 insertions(+), 114 deletions(-)
libxfs/libxfs_api_defs.h +1 -1
index fe00e19bada9d8..d7c912e778799c 100644
@@ -412,7 +412,7 @@
 #define xfs_verify_rgbno		libxfs_verify_rgbno
 #define xfs_verify_rtbno		libxfs_verify_rtbno
 #define xfs_zero_extent			libxfs_zero_extent
-#define xfs_zone_validate		libxfs_zone_validate
+#define xfs_validate_blk_zone		libxfs_validate_blk_zone
 
 /* Please keep this list alphabetized. */
 
libxfs/xfs_zones.h +3 -2
index df10a34da71d64..c16089c9a652da 100644
@@ -37,7 +37,8 @@ struct blk_zone;
  */
 #define XFS_DEFAULT_MAX_OPEN_ZONES	128
 
-bool xfs_zone_validate(struct blk_zone *zone, struct xfs_rtgroup *rtg,
-	xfs_rgblock_t *write_pointer);
+bool xfs_validate_blk_zone(struct xfs_mount *mp, struct blk_zone *zone,
+	unsigned int zone_no, uint32_t expected_size,
+	uint32_t expected_capacity, xfs_rgblock_t *write_pointer);
 
 #endif /* _LIBXFS_ZONES_H */
libxfs/xfs_zones.c +39 -110

212 lines not on this page · raw message

repair/zoned.c +4 -1
index c721709d137064..6ab91371d95af6 100644
@@ -39,7 +39,10 @@ report_zones_cb(
 	if (!rtg_rmap(rtg))
 		do_warn(_("no rmap inode for zone %u."), rgno);
 	else
-		libxfs_zone_validate(zone, rtg, &write_pointer);
+		libxfs_validate_blk_zone(mp, zone, rtg_rgno(rtg),
+				xfs_rtgroup_raw_size(mp),
+				mp->m_groups[XG_TYPE_RTG].blocks,
+				&write_pointer);
 	libxfs_rtgroup_rele(rtg);
 }
 
#29 lore raw

PATCH 20/40 xfs: delete attr leaf freemap entries when empty

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: 6f13c1d2a6271c2e73226864a0e83de2770b6f34

Back in commit 2a2b5932db6758 ("xfs: fix attr leaf header freemap.size underflow"), Brian Foster observed that it's possible for a small freemap at the end of the end of the xattr entries array to experience a size underflow when subtracting the space consumed by an expansion of the entries array. There are only three freemap entries, which means that it is not a complete index of all free space in the leaf block.

This code can leave behind a zero-length freemap entry with a nonzero base. Subsequent setxattr operations can increase the base up to the point that it overlaps with another freemap entry. This isn't in and of itself a problem because the code in _leaf_add that finds free space ignores any freemap entry with zero size.

However, there's another bug in the freemap update code in _leaf_add, which is that it fails to update a freemap entry that begins midway through the xattr entry that was just appended to the array. That can result in the freemap containing two entries with the same base but different sizes (0 for the "pushed-up" entry, nonzero for the entry that's actually tracking free space). A subsequent _leaf_add can then allocate xattr namevalue entries on top of the entries array, leading to data loss. But fixing that is for later.

For now, eliminate the possibility of confusion by zeroing out the base of any freemap entry that has zero size. Because the freemap is not intended to be a complete index of free space, a subsequent failure to find any free space for a new xattr will trigger block compaction, which regenerates the freemap.

It looks like this bug has been in the codebase for quite a long time.

Fixes 1da177e4c3f415 ("Linux-2.6.12-rc2")
---
 libxfs/xfs_attr_leaf.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)
libxfs/xfs_attr_leaf.c +13 -0
index ff1085f0b3afe4..f5ea39abf04a35 100644
@@ -1577,6 +1577,19 @@ xfs_attr3_leaf_add_work(
 				min_t(uint16_t, ichdr->freemap[i].size,
 						sizeof(xfs_attr_leaf_entry_t));
 		}
+
+		/*
+		 * Don't leave zero-length freemaps with nonzero base lying
+		 * around, because we don't want the code in _remove that
+		 * matches on base address to get confused and create
+		 * overlapping freemaps.  If we end up with no freemap entries
+		 * then the next _add will compact the leaf block and
+		 * regenerate the freemaps.
+		 */
+		if (ichdr->freemap[i].size == 0 && ichdr->freemap[i].base > 0) {
+			ichdr->freemap[i].base = 0;
+			ichdr->holes = 1;
+		}
 	}
 	ichdr->usedbytes += xfs_attr_leaf_entsize(leaf, args->index);
 }
#30 lore raw

PATCH 21/40 xfs: fix freemap adjustments when adding xattrs to leaf blocks

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: 3eefc0c2b78444b64feeb3783c017d6adc3cd3ce

xfs/592 and xfs/794 both trip this assertion in the leaf block freemap adjustment code after ~20 minutes of running on my test VMs:

ASSERT(ichdr->firstused >= ichdr->count * sizeof(xfs_attr_leaf_entry_t)
+ xfs_attr3_leaf_hdr_size(leaf));

Upon enabling quite a lot more debugging code, I narrowed this down to fsstress trying to set a local extended attribute with namelen=3 and valuelen=71. This results in an entry size of 80 bytes.

At the start of xfs_attr3_leaf_add_work, the freemap looks like this:

i 0 base 448 size 0 rhs 448 count 46
i 1 base 388 size 132 rhs 448 count 46
i 2 base 2120 size 4 rhs 448 count 46
firstused = 520

where "rhs" is the first byte past the end of the leaf entry array. This is inconsistent -- the entries array ends at byte 448, but freemap[1] says there's free space starting at byte 388!

By the end of the function, the freemap is in worse shape:

i 0 base 456 size 0 rhs 456 count 47
i 1 base 388 size 52 rhs 456 count 47
i 2 base 2120 size 4 rhs 456 count 47
firstused = 440

Important note: 388 is not aligned with the entries array element size of 8 bytes.

Based on the incorrect freemap, the name area starts at byte 440, which is below the end of the entries array! That's why the assertion triggers and the filesystem shuts down.

How did we end up here? First, recall from the previous patch that the freemap array in an xattr leaf block is not intended to be a comprehensive map of all free space in the leaf block. In other words, it's perfectly legal to have a leaf block with:

* 376 bytes in use by the entries array
* freemap[0] has [base = 376, size = 8]
* freemap[1] has [base = 388, size = 1500]
* the space between 376 and 388 is free, but the freemap stopped tracking that some time ago

If we add one xattr, the entries array grows to 384 bytes, and freemap[0] becomes [base = 384, size = 0]. So far, so good. But if we add a second xattr, the entries array grows to 392 bytes, and freemap[0] gets pushed up to [base = 392, size = 0]. This is bad, because freemap[1] hasn't been updated, and now the entries array and the free space claim the same space.

The fix here is to adjust all freemap entries so that none of them collide with the entries array. Note that this fix relies on commit 2a2b5932db6758 ("xfs: fix attr leaf header freemap.size underflow") and the previous patch that resets zero length freemap entries to have base = 0.

Fixes 1da177e4c3f415 ("Linux-2.6.12-rc2")
---
 libxfs/xfs_attr_leaf.c |   36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)
libxfs/xfs_attr_leaf.c +28 -8
index f5ea39abf04a35..b8aea9d73c0e4e 100644
@@ -1473,6 +1473,7 @@ xfs_attr3_leaf_add_work(
 	struct xfs_attr_leaf_name_local *name_loc;
 	struct xfs_attr_leaf_name_remote *name_rmt;
 	struct xfs_mount	*mp;
+	int			old_end, new_end;
 	int			tmp;
 	int			i;
 
@@ -1565,17 +1566,36 @@ xfs_attr3_leaf_add_work(
 	if (be16_to_cpu(entry->nameidx) < ichdr->firstused)
 		ichdr->firstused = be16_to_cpu(entry->nameidx);
 
-	ASSERT(ichdr->firstused >= ichdr->count * sizeof(xfs_attr_leaf_entry_t)
-					+ xfs_attr3_leaf_hdr_size(leaf));
-	tmp = (ichdr->count - 1) * sizeof(xfs_attr_leaf_entry_t)
-					+ xfs_attr3_leaf_hdr_size(leaf);
+	new_end = ichdr->count * sizeof(struct xfs_attr_leaf_entry) +
+					xfs_attr3_leaf_hdr_size(leaf);
+	old_end = new_end - sizeof(struct xfs_attr_leaf_entry);
+
+	ASSERT(ichdr->firstused >= new_end);
 
 	for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
-		if (ichdr->freemap[i].base == tmp) {
-			ichdr->freemap[i].base += sizeof(xfs_attr_leaf_entry_t);
+		int		diff = 0;
+
+		if (ichdr->freemap[i].base == old_end) {
+			/*
+			 * This freemap entry starts at the old end of the
+			 * leaf entry array, so we need to adjust its base
+			 * upward to accomodate the larger array.
+			 */
+			diff = sizeof(struct xfs_attr_leaf_entry);
+		} else if (ichdr->freemap[i].size > 0 &&
+			   ichdr->freemap[i].base < new_end) {
+			/*
+			 * This freemap entry starts in the space claimed by
+			 * the new leaf entry.  Adjust its base upward to
+			 * reflect that.
+			 */
+			diff = new_end - ichdr->freemap[i].base;
+		}
+
+		if (diff) {
+			ichdr->freemap[i].base += diff;
 			ichdr->freemap[i].size -=
-				min_t(uint16_t, ichdr->freemap[i].size,
-						sizeof(xfs_attr_leaf_entry_t));
+				min_t(uint16_t, ichdr->freemap[i].size, diff);
 		}
 
 		/*
#31 lore raw

PATCH 22/40 xfs: refactor attr3 leaf table size computation

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: a165f7e7633ee0d83926d29e7909fdd8dd4dfadc

Replace all the open-coded callsites with a single static inline helper.

---
 libxfs/xfs_da_format.h |    2 +-
 libxfs/xfs_attr_leaf.c |   57 ++++++++++++++++++++++++------------------------
 2 files changed, 30 insertions(+), 29 deletions(-)
libxfs/xfs_da_format.h +1 -1
index 86de99e2f75707..7d55307e619fe9 100644
@@ -746,7 +746,7 @@ struct xfs_attr3_leafblock {
 #define	XFS_ATTR_LEAF_NAME_ALIGN	((uint)sizeof(xfs_dablk_t))
 
 static inline int
-xfs_attr3_leaf_hdr_size(struct xfs_attr_leafblock *leafp)
+xfs_attr3_leaf_hdr_size(const struct xfs_attr_leafblock *leafp)
 {
 	if (leafp->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
 		return sizeof(struct xfs_attr3_leaf_hdr);
libxfs/xfs_attr_leaf.c +29 -28

136 lines not on this page · raw message

#32 lore raw

PATCH 23/40 xfs: strengthen attr leaf block freemap checking

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: 27a0c41f33d8d31558d334b07eb58701aab0b3dd

Check for erroneous overlapping freemap regions and collisions between freemap regions and the xattr leaf entry array.

Note that we must explicitly zero out the extra freemaps in xfs_attr3_leaf_compact so that the in-memory buffer has a correctly initialized freemap array to satisfy the new verification code, even if subsequent code changes the contents before unlocking the buffer.

---
 libxfs/xfs_attr_leaf.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
libxfs/xfs_attr_leaf.c +55 -0
index 158864249c8888..f591984c3748ff 100644
@@ -82,6 +82,49 @@ xfs_attr_leaf_entries_end(
 			xfs_attr3_leaf_hdr_size(leaf);
 }
 
+static inline bool
+ichdr_freemaps_overlap(
+	const struct xfs_attr3_icleaf_hdr	*ichdr,
+	unsigned int				x,
+	unsigned int				y)
+{
+	const unsigned int			xend =
+		ichdr->freemap[x].base + ichdr->freemap[x].size;
+	const unsigned int			yend =
+		ichdr->freemap[y].base + ichdr->freemap[y].size;
+
+	/* empty slots do not overlap */
+	if (!ichdr->freemap[x].size || !ichdr->freemap[y].size)
+		return false;
+
+	return ichdr->freemap[x].base < yend && xend > ichdr->freemap[y].base;
+}
+
+static inline xfs_failaddr_t
+xfs_attr_leaf_ichdr_freemaps_verify(
+	const struct xfs_attr3_icleaf_hdr	*ichdr,
+	const struct xfs_attr_leafblock		*leaf)
+{
+	unsigned int				entries_end =
+		xfs_attr_leaf_entries_end(ichdr->count, leaf);
+	int					i;
+
+	if (ichdr_freemaps_overlap(ichdr, 0, 1))
+		return __this_address;
+	if (ichdr_freemaps_overlap(ichdr, 0, 2))
+		return __this_address;
+	if (ichdr_freemaps_overlap(ichdr, 1, 2))
+		return __this_address;
+
+	for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
+		if (ichdr->freemap[i].size > 0 &&
+		    ichdr->freemap[i].base < entries_end)
+			return __this_address;
+	}
+
+	return NULL;
+}
+
 /*
  * attr3 block 'firstused' conversion helpers.
  *
@@ -225,6 +268,8 @@ xfs_attr3_leaf_hdr_to_disk(
 			hdr3->freemap[i].base = cpu_to_be16(from->freemap[i].base);
 			hdr3->freemap[i].size = cpu_to_be16(from->freemap[i].size);
 		}
+
+		ASSERT(xfs_attr_leaf_ichdr_freemaps_verify(from, to) == NULL);
 		return;
 	}
 	to->hdr.info.forw = cpu_to_be32(from->forw);
@@ -240,6 +285,8 @@ xfs_attr3_leaf_hdr_to_disk(
 		to->hdr.freemap[i].base = cpu_to_be16(from->freemap[i].base);
 		to->hdr.freemap[i].size = cpu_to_be16(from->freemap[i].size);
 	}
+
+	ASSERT(xfs_attr_leaf_ichdr_freemaps_verify(from, to) == NULL);
 }
 
 static xfs_failaddr_t
@@ -392,6 +439,10 @@ xfs_attr3_leaf_verify(
 			return __this_address;
 	}
 
+	fa = xfs_attr_leaf_ichdr_freemaps_verify(&ichdr, leaf);
+	if (fa)
+		return fa;
+
 	return NULL;
 }
 
@@ -1661,6 +1712,10 @@ xfs_attr3_leaf_compact(
 	ichdr_dst->freemap[0].base = xfs_attr3_leaf_hdr_size(leaf_src);
 	ichdr_dst->freemap[0].size = ichdr_dst->firstused -
 						ichdr_dst->freemap[0].base;
+	ichdr_dst->freemap[1].base = 0;
+	ichdr_dst->freemap[2].base = 0;
+	ichdr_dst->freemap[1].size = 0;
+	ichdr_dst->freemap[2].size = 0;
 
 	/* write the header back to initialise the underlying buffer */
 	xfs_attr3_leaf_hdr_to_disk(args->geo, leaf_dst, ichdr_dst);
#33 lore raw

PATCH 24/40 xfs: reduce xfs_attr_try_sf_addname parameters

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: 1ef7729df1f0c5f7bb63a121164f54d376d35835

The dp parameter to this function is an alias of args->dp, so remove it for clarity before we go adding new callers.

---
 libxfs/xfs_attr.c |   11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
libxfs/xfs_attr.c +4 -7
index baf617cfeabe00..175f8572b0f930 100644
@@ -349,16 +349,14 @@ xfs_attr_set_resv(
  */
 STATIC int
 xfs_attr_try_sf_addname(
-	struct xfs_inode	*dp,
 	struct xfs_da_args	*args)
 {
-
 	int			error;
 
 	/*
 	 * Build initial attribute list (if required).
 	 */
-	if (dp->i_af.if_format == XFS_DINODE_FMT_EXTENTS)
+	if (args->dp->i_af.if_format == XFS_DINODE_FMT_EXTENTS)
 		xfs_attr_shortform_create(args);
 
 	error = xfs_attr_shortform_addname(args);
@@ -370,9 +368,9 @@ xfs_attr_try_sf_addname(
 	 * NOTE: this is also the error path (EEXIST, etc).
 	 */
 	if (!error)
-		xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
+		xfs_trans_ichgtime(args->trans, args->dp, XFS_ICHGTIME_CHG);
 
-	if (xfs_has_wsync(dp->i_mount))
+	if (xfs_has_wsync(args->dp->i_mount))
 		xfs_trans_set_sync(args->trans);
 
 	return error;
@@ -383,10 +381,9 @@ xfs_attr_sf_addname(
 	struct xfs_attr_intent		*attr)
 {
 	struct xfs_da_args		*args = attr->xattri_da_args;
-	struct xfs_inode		*dp = args->dp;
 	int				error = 0;
 
-	error = xfs_attr_try_sf_addname(dp, args);
+	error = xfs_attr_try_sf_addname(args);
 	if (error != -ENOSPC) {
 		ASSERT(!error || error == -EEXIST);
 		attr->xattri_dela_state = XFS_DAS_DONE;
#34 lore raw

PATCH 25/40 xfs: speed up parent pointer operations when possible

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: d693534513d8dcdaafcf855986d0fe0476a47462

After a recent fsmark benchmarking run, I observed that the overhead of parent pointers on file creation and deletion can be a bit high. On a machine with 20 CPUs, 128G of memory, and an NVME SSD capable of pushing 750000iops, I see the following results:

$ mkfs.xfs -f -l logdev=/dev/nvme1n1,size=1g /dev/nvme0n1 -n parent=0
meta-data=/dev/nvme0n1           isize=512    agcount=40, agsize=9767586 blks
=                       sectsz=4096  attr=2, projid32bit=1
=                       crc=1        finobt=1, sparse=1, rmapbt=1
=                       reflink=1    bigtime=1 inobtcount=1 nrext64=1
=                       exchange=0   metadir=0
data     =                       bsize=4096   blocks=390703440, imaxpct=5
=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1, parent=0
log      =/dev/nvme1n1           bsize=4096   blocks=262144, version=2
=                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
=                       rgcount=0    rgsize=0 extents
=                       zoned=0      start=0 reserved=0

So we created 40 AGs, one per CPU. Now we create 40 directories and run fsmark:

$ time fs_mark  -D  10000  -S  0  -n  100000  -s  0  -L  8 -d ...
# Version 3.3, 40 thread(s) starting at Wed Dec 10 14:22:07 2025
# Sync method: NO SYNC: Test does not issue sync() or fsync() calls.
# Directories:  Time based hash between directories across 10000 subdirectories with 180 seconds per subdirectory.
# File names: 40 bytes long, (16 initial bytes of time stamp with 24 random bytes at end of name)
# Files info: size 0 bytes, written with an IO size of 16384 bytes per write
# App overhead is time in microseconds spent in the test not doing file writing related system calls.
parent=0               parent=1
==================     ==================
real    0m57.573s      real    1m2.934s
user    3m53.578s      user    3m53.508s
sys     19m44.440s     sys     25m14.810s
$ time rm -rf ...
parent=0               parent=1
==================     ==================
real    0m59.649s      real    1m12.505s
user    0m41.196s      user    0m47.489s
sys     13m9.566s      sys     20m33.844s

Parent pointers increase the system time by 28% overhead to create 32 million files that are totally empty. Removing them incurs a system time increase of 56%. Wall time increases by 9% and 22%.

For most filesystems, each file tends to have a single owner and not that many xattrs. If the xattr structure is shortform, then all xattr changes are logged with the inode and do not require the the xattr intent mechanism to persist the parent pointer.

Therefore, we can speed up parent pointer operations by calling the shortform xattr functions directly if the child's xattr is in short format. Now the overhead looks like:

$ time fs_mark  -D  10000  -S  0  -n  100000  -s  0  -L  8 -d ...
parent=0               parent=1
==================     ==================
real    0m58.030s      real    1m0.983s
user    3m54.141s      user    3m53.758s
sys     19m57.003s     sys     21m30.605s
$ time rm -rf ...
parent=0               parent=1
==================     ==================
real    0m58.911s      real    1m4.420s
user    0m41.329s      user    0m45.169s
sys     13m27.857s     sys     15m58.564s

Now parent pointers only increase the system time by 8% for creation and 19% for deletion. Wall time increases by 5% and 9% now.

Close the performance gap by creating helpers for the attr set, remove, and replace operations that will try to make direct shortform updates, and fall back to the attr intent machinery if that doesn't work. This works for regular xattrs and for parent pointers.

---
 libxfs/xfs_attr.h   |    6 +++
 libxfs/xfs_attr.c   |   99 +++++++++++++++++++++++++++++++++++++++++++++++++--
 libxfs/xfs_parent.c |   14 ++++---
 3 files changed, 109 insertions(+), 10 deletions(-)
libxfs/xfs_attr.h +5 -1
index 0e51d0723f9aa3..8244305949deb9 100644
@@ -573,7 +573,7 @@ struct xfs_trans_res xfs_attr_set_resv(const struct xfs_da_args *args);
  */
 static inline bool
 xfs_attr_is_shortform(
-	struct xfs_inode    *ip)
+	const struct xfs_inode    *ip)
 {
 	return ip->i_af.if_format == XFS_DINODE_FMT_LOCAL ||
 	       (ip->i_af.if_format == XFS_DINODE_FMT_EXTENTS &&
@@ -649,4 +649,8 @@ void xfs_attr_intent_destroy_cache(void);
 int xfs_attr_sf_totsize(struct xfs_inode *dp);
 int xfs_attr_add_fork(struct xfs_inode *ip, int size, int rsvd);
 
+int xfs_attr_setname(struct xfs_da_args *args, int rmt_blks);
+int xfs_attr_removename(struct xfs_da_args *args);
+int xfs_attr_replacename(struct xfs_da_args *args, int rmt_blks);
+
 #endif	/* __XFS_ATTR_H__ */
libxfs/xfs_attr.c +96 -3

123 lines not on this page · raw message

libxfs/xfs_parent.c +8 -6
index 12e4299840b8ef..d82c38197f4696 100644
@@ -26,6 +26,7 @@
 #include "xfs_trans_space.h"
 #include "defer_item.h"
 #include "xfs_health.h"
+#include "xfs_attr_leaf.h"
 
 struct kmem_cache		*xfs_parent_args_cache;
 
@@ -199,8 +200,8 @@ xfs_parent_addname(
 	xfs_inode_to_parent_rec(&ppargs->rec, dp);
 	xfs_parent_da_args_init(&ppargs->args, tp, &ppargs->rec, child,
 			child->i_ino, parent_name);
-	xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_SET);
-	return 0;
+
+	return xfs_attr_setname(&ppargs->args, 0);
 }
 
 /* Remove a parent pointer to reflect a dirent removal. */
@@ -221,8 +222,8 @@ xfs_parent_removename(
 	xfs_inode_to_parent_rec(&ppargs->rec, dp);
 	xfs_parent_da_args_init(&ppargs->args, tp, &ppargs->rec, child,
 			child->i_ino, parent_name);
-	xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_REMOVE);
-	return 0;
+
+	return xfs_attr_removename(&ppargs->args);
 }
 
 /* Replace one parent pointer with another to reflect a rename. */
@@ -247,12 +248,13 @@ xfs_parent_replacename(
 			child->i_ino, old_name);
 
 	xfs_inode_to_parent_rec(&ppargs->new_rec, new_dp);
+
 	ppargs->args.new_name = new_name->name;
 	ppargs->args.new_namelen = new_name->len;
 	ppargs->args.new_value = &ppargs->new_rec;
 	ppargs->args.new_valuelen = sizeof(struct xfs_parent_rec);
-	xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_REPLACE);
-	return 0;
+
+	return xfs_attr_replacename(&ppargs->args, 0);
 }
 
 /*
#35 lore raw

PATCH 26/40 xfs: add a method to replace shortform attrs

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Source kernel commit: eaec8aeff31d0679eadb27a13a62942ddbfd7b87

If we're trying to replace an xattr in a shortform attr structure and the old entry fits the new entry, we can just memcpy and exit without having to delete, compact, and re-add the entry (or worse use the attr intent machinery). For parent pointers this only advantages renaming where the filename length stays the same (e.g. mv autoexec.bat scandisk.exe) but for regular xattrs it might be useful for updating security labels and the like.

---
 include/xfs_trace.h    |    1 +
 libxfs/xfs_attr_leaf.h |    1 +
 libxfs/xfs_attr.c      |    4 ++++
 libxfs/xfs_attr_leaf.c |   38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 44 insertions(+)
include/xfs_trace.h +1 -0
index 6bbf4007cbbbd9..be9183fc33ad90 100644
@@ -57,6 +57,7 @@
 #define trace_xfs_attr_defer_replace(...)	((void) 0)
 #define trace_xfs_attr_defer_remove(...)	((void) 0)
 #define trace_xfs_attr_sf_addname_return(...)	((void) 0)
+#define trace_xfs_attr_sf_replace(...)		((void) 0)
 #define trace_xfs_attr_set_iter_return(...)	((void) 0)
 #define trace_xfs_attr_leaf_addname_return(...)	((void) 0)
 #define trace_xfs_attr_node_addname_return(...)	((void) 0)
libxfs/xfs_attr_leaf.h +1 -0
index 589f810eedc0d8..aca46da2bc502e 100644
@@ -46,6 +46,7 @@ struct xfs_attr3_icleaf_hdr {
  * Internal routines when attribute fork size < XFS_LITINO(mp).
  */
 void	xfs_attr_shortform_create(struct xfs_da_args *args);
+int	xfs_attr_shortform_replace(struct xfs_da_args *args);
 void	xfs_attr_shortform_add(struct xfs_da_args *args, int forkoff);
 int	xfs_attr_shortform_getvalue(struct xfs_da_args *args);
 int	xfs_attr_shortform_to_leaf(struct xfs_da_args *args);
libxfs/xfs_attr.c +4 -0
index 0b45e72b5478b4..a2611aace8190f 100644
@@ -1084,6 +1084,10 @@ xfs_attr_replacename(
 		return 0;
 	}
 
+	error = xfs_attr_shortform_replace(args);
+	if (error != -ENOSPC)
+		return error;
+
 	args->op_flags |= XFS_DA_OP_ADDNAME | XFS_DA_OP_REPLACE;
 
 	error = xfs_attr_sf_removename(args);
libxfs/xfs_attr_leaf.c +38 -0
index f591984c3748ff..90be21a3887642 100644
@@ -839,6 +839,44 @@ xfs_attr_sf_findname(
 	return NULL;
 }
 
+/*
+ * Replace a shortform xattr if it's the right length.  Returns 0 on success,
+ * -ENOSPC if the length is wrong, or -ENOATTR if the attr was not found.
+ */
+int
+xfs_attr_shortform_replace(
+	struct xfs_da_args		*args)
+{
+	struct xfs_attr_sf_entry	*sfe;
+
+	ASSERT(args->dp->i_af.if_format == XFS_DINODE_FMT_LOCAL);
+
+	trace_xfs_attr_sf_replace(args);
+
+	sfe = xfs_attr_sf_findname(args);
+	if (!sfe)
+		return -ENOATTR;
+
+	if (args->attr_filter & XFS_ATTR_PARENT) {
+		if (sfe->namelen != args->new_namelen ||
+		    sfe->valuelen != args->new_valuelen)
+			return -ENOSPC;
+
+		memcpy(sfe->nameval, args->new_name, sfe->namelen);
+		memcpy(&sfe->nameval[sfe->namelen], args->new_value,
+				sfe->valuelen);
+	} else {
+		if (sfe->valuelen != args->valuelen)
+			return -ENOSPC;
+		memcpy(&sfe->nameval[sfe->namelen], args->value,
+				sfe->valuelen);
+	}
+
+	xfs_trans_log_inode(args->trans, args->dp,
+			XFS_ILOG_CORE | XFS_ILOG_ADATA);
+	return 0;
+}
+
 /*
  * Add a name/value pair to the shortform attribute list.
  * Overflow from the inode has already been checked for.
#36 lore raw

PATCH 27/40 xfs: fix spacing style issues in xfs_alloc.c

In reply to Darrick J. Wong

From: Shin Seong-jun <[email protected]>

Source kernel commit: 0ead3b72469e52ca02946b2e5b35fff38bfa061f

Fix checkpatch.pl errors regarding missing spaces around assignment operators in xfs_alloc_compute_diff() and xfs_alloc_fixup_trees().

Adhere to the Linux kernel coding style by ensuring spaces are placed around the assignment operator '='.

---
 libxfs/xfs_alloc.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
libxfs/xfs_alloc.c +4 -4
index 9f92bd77fad76c..695ed830d139fe 100644
@@ -372,8 +372,8 @@ xfs_alloc_compute_diff(
 	xfs_agblock_t	freeend;	/* end of freespace extent */
 	xfs_agblock_t	newbno1;	/* return block number */
 	xfs_agblock_t	newbno2;	/* other new block number */
-	xfs_extlen_t	newlen1=0;	/* length with newbno1 */
-	xfs_extlen_t	newlen2=0;	/* length with newbno2 */
+	xfs_extlen_t	newlen1 = 0;	/* length with newbno1 */
+	xfs_extlen_t	newlen2 = 0;	/* length with newbno2 */
 	xfs_agblock_t	wantend;	/* end of target extent */
 	bool		userdata = datatype & XFS_ALLOC_USERDATA;
 
@@ -573,8 +573,8 @@ xfs_alloc_fixup_trees(
 	int		i;		/* operation results */
 	xfs_agblock_t	nfbno1;		/* first new free startblock */
 	xfs_agblock_t	nfbno2;		/* second new free startblock */
-	xfs_extlen_t	nflen1=0;	/* first new free length */
-	xfs_extlen_t	nflen2=0;	/* second new free length */
+	xfs_extlen_t	nflen1 = 0;	/* first new free length */
+	xfs_extlen_t	nflen2 = 0;	/* second new free length */
 	struct xfs_mount *mp;
 	bool		fixup_longest = false;
 
#37 lore raw

PATCH 28/40 xfs: don't validate error tags in the I/O path

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: b8862a09d8256a9037293f1da3b4617b21de26f1

We can trust XFS developers enough to not pass random stuff to XFS_ERROR_TEST/DELAY. Open code the validity check in xfs_errortag_add, which is the only place that receives unvalidated error tag values from user space, and drop the now pointless xfs_errortag_enabled helper.

---
 libxfs/xfs_errortag.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_errortag.h +1 -1
index 57e47077c75a2a..b7d98471684bf1 100644
@@ -53,7 +53,7 @@
  * Drop-writes support removed because write error handling cannot trash
  * pre-existing delalloc extents in any useful way anymore. We retain the
  * definition so that we can reject it as an invalid value in
- * xfs_errortag_valid().
+ * xfs_errortag_add().
  */
 #define XFS_ERRTAG_DROP_WRITES				28
 #define XFS_ERRTAG_LOG_BAD_CRC				29
#38 lore raw

PATCH 29/40 xfs: add zone reset error injection

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: 41374ae69ec3a910950d3888f444f80678c6f308

Add a new errortag to test that zone reset errors are handled correctly.

---
 libxfs/xfs_errortag.h |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
libxfs/xfs_errortag.h +4 -2
index b7d98471684bf1..6de207fed2d892 100644
@@ -74,7 +74,8 @@
 #define XFS_ERRTAG_EXCHMAPS_FINISH_ONE			44
 #define XFS_ERRTAG_METAFILE_RESV_CRITICAL		45
 #define XFS_ERRTAG_FORCE_ZERO_RANGE			46
-#define XFS_ERRTAG_MAX					47
+#define XFS_ERRTAG_ZONE_RESET				47
+#define XFS_ERRTAG_MAX					48
 
 /*
  * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -135,7 +136,8 @@ XFS_ERRTAG(WB_DELAY_MS,		wb_delay_ms,		3000) \
 XFS_ERRTAG(WRITE_DELAY_MS,	write_delay_ms,		3000) \
 XFS_ERRTAG(EXCHMAPS_FINISH_ONE,	exchmaps_finish_one,	1) \
 XFS_ERRTAG(METAFILE_RESV_CRITICAL, metafile_resv_crit,	4) \
-XFS_ERRTAG(FORCE_ZERO_RANGE,	force_zero_range,	4)
+XFS_ERRTAG(FORCE_ZERO_RANGE,	force_zero_range,	4) \
+XFS_ERRTAG(ZONE_RESET,		zone_reset,		1)
 #endif /* XFS_ERRTAG */
 
 #endif /* __XFS_ERRORTAG_H_ */
#39 lore raw

PATCH 30/40 xfs: give the defer_relog stat a xs_ prefix

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: edf6078212c366459d3c70833290579b200128b1

Make this counter naming consistent with all the others.

---
 libxfs/xfs_defer.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_defer.c +1 -1
index 5bd3cbe4cfa1a3..c0d3aa401cbab5 100644
@@ -558,7 +558,7 @@ xfs_defer_relog(
 			continue;
 
 		trace_xfs_defer_relog_intent((*tpp)->t_mountp, dfp);
-		XFS_STATS_INC((*tpp)->t_mountp, defer_relog);
+		XFS_STATS_INC((*tpp)->t_mountp, xs_defer_relog);
 
 		xfs_defer_relog_intent(*tpp, dfp);
 	}
#40 lore raw

PATCH 31/40 treewide: Replace kmalloc with kmalloc_obj for non-scalar types

In reply to Darrick J. Wong

From: Kees Cook <[email protected]>

Source kernel commit: 69050f8d6d075dc01af7a5f2f550a8067510366f

This is the result of running the Coccinelle script from scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to avoid scalar types (which need careful case-by-case checking), and instead replace kmalloc-family calls that allocate struct or union object instances:

Single allocations:     kmalloc(sizeof(TYPE), ...)
are replaced with:      kmalloc_obj(TYPE, ...)
Array allocations:      kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with:      kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with:      kmalloc_flex(*PTR, FAM, COUNT, ...)

(where TYPE may also be *VAR)

The resulting allocations no longer return "void *", instead returning "TYPE *".

---
 libxfs/xfs_ag.c       |    2 +-
 libxfs/xfs_defer.c    |    2 +-
 libxfs/xfs_dir2.c     |   19 +++++++++----------
 libxfs/xfs_refcount.c |    4 ++--
 libxfs/xfs_rtgroup.c  |    2 +-
 5 files changed, 14 insertions(+), 15 deletions(-)
libxfs/xfs_ag.c +1 -1
index 8ccd67672b4e00..0f1eaf5d6e39b8 100644
@@ -222,7 +222,7 @@ xfs_perag_alloc(
 	struct xfs_perag	*pag;
 	int			error;
 
-	pag = kzalloc(sizeof(*pag), GFP_KERNEL);
+	pag = kzalloc_obj(*pag, GFP_KERNEL);
 	if (!pag)
 		return -ENOMEM;
 
libxfs/xfs_defer.c +1 -1
index c0d3aa401cbab5..e4d17177f67faf 100644
@@ -975,7 +975,7 @@ xfs_defer_ops_capture(
 		return ERR_PTR(error);
 
 	/* Create an object to capture the defer ops. */
-	dfc = kzalloc(sizeof(*dfc), GFP_KERNEL | __GFP_NOFAIL);
+	dfc = kzalloc_obj(*dfc, GFP_KERNEL | __GFP_NOFAIL);
 	INIT_LIST_HEAD(&dfc->dfc_list);
 	INIT_LIST_HEAD(&dfc->dfc_dfops);
 
libxfs/xfs_dir2.c +9 -10
index 2ca6bf198ba54f..1a13fec25e15b3 100644
@@ -115,10 +115,10 @@ xfs_da_mount(
 	ASSERT(mp->m_sb.sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
 	ASSERT(xfs_dir2_dirblock_bytes(&mp->m_sb) <= XFS_MAX_BLOCKSIZE);
 
-	mp->m_dir_geo = kzalloc(sizeof(struct xfs_da_geometry),
-				GFP_KERNEL | __GFP_RETRY_MAYFAIL);
-	mp->m_attr_geo = kzalloc(sizeof(struct xfs_da_geometry),
-				GFP_KERNEL | __GFP_RETRY_MAYFAIL);
+	mp->m_dir_geo = kzalloc_obj(struct xfs_da_geometry,
+				    GFP_KERNEL | __GFP_RETRY_MAYFAIL);
+	mp->m_attr_geo = kzalloc_obj(struct xfs_da_geometry,
+				     GFP_KERNEL | __GFP_RETRY_MAYFAIL);
 	if (!mp->m_dir_geo || !mp->m_attr_geo) {
 		kfree(mp->m_dir_geo);
 		kfree(mp->m_attr_geo);
@@ -247,7 +247,7 @@ xfs_dir_init(
 	if (error)
 		return error;
 
-	args = kzalloc(sizeof(*args), GFP_KERNEL | __GFP_NOFAIL);
+	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
 	if (!args)
 		return -ENOMEM;
 
@@ -340,7 +340,7 @@ xfs_dir_createname(
 		XFS_STATS_INC(dp->i_mount, xs_dir_create);
 	}
 
-	args = kzalloc(sizeof(*args), GFP_KERNEL | __GFP_NOFAIL);
+	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
 	if (!args)
 		return -ENOMEM;
 
@@ -436,8 +436,7 @@ xfs_dir_lookup(
 	ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
 	XFS_STATS_INC(dp->i_mount, xs_dir_lookup);
 
-	args = kzalloc(sizeof(*args),
-			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
+	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
 	args->geo = dp->i_mount->m_dir_geo;
 	args->name = name->name;
 	args->namelen = name->len;
@@ -502,7 +501,7 @@ xfs_dir_removename(
 	ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
 	XFS_STATS_INC(dp->i_mount, xs_dir_remove);
 
-	args = kzalloc(sizeof(*args), GFP_KERNEL | __GFP_NOFAIL);
+	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
 	if (!args)
 		return -ENOMEM;
 
@@ -562,7 +561,7 @@ xfs_dir_replace(
 	if (rval)
 		return rval;
 
-	args = kzalloc(sizeof(*args), GFP_KERNEL | __GFP_NOFAIL);
+	args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
 	if (!args)
 		return -ENOMEM;
 
libxfs/xfs_refcount.c +2 -2
index 5c362e0e901124..036497dbb22b70 100644
@@ -2031,8 +2031,8 @@ xfs_refcount_recover_extent(
 		return -EFSCORRUPTED;
 	}
 
-	rr = kmalloc(sizeof(struct xfs_refcount_recovery),
-			GFP_KERNEL | __GFP_NOFAIL);
+	rr = kmalloc_obj(struct xfs_refcount_recovery,
+			 GFP_KERNEL | __GFP_NOFAIL);
 	INIT_LIST_HEAD(&rr->rr_list);
 	xfs_refcount_btrec_to_irec(rec, &rr->rr_rrec);
 
libxfs/xfs_rtgroup.c +1 -1
index af4eafb20bc138..69e71494057a1e 100644
@@ -95,7 +95,7 @@ xfs_rtgroup_alloc(
 	struct xfs_rtgroup	*rtg;
 	int			error;
 
-	rtg = kzalloc(sizeof(struct xfs_rtgroup), GFP_KERNEL);
+	rtg = kzalloc_obj(struct xfs_rtgroup, GFP_KERNEL);
 	if (!rtg)
 		return -ENOMEM;
 
#41 lore raw

PATCH 32/40 Convert 'alloc_obj' family to use the new default GFP_KERNEL argument

In reply to Darrick J. Wong

From: Linus Torvalds <[email protected]>

Source kernel commit: bf4afc53b77aeaa48b5409da5c8da6bb4eff7f43

This was done entirely with mindless brute force, using

git grep -l '\<k[vmz]*alloc_objs*(.*, GFP_KERNEL)' | xargs sed -i 's/\(alloc_objs*(.*\), GFP_KERNEL)/\1)/'

to convert the new alloc_obj() users that had a simple GFP_KERNEL argument to just drop that argument.

Note that due to the extreme simplicity of the scripting, any slightly more complex cases spread over multiple lines would not be triggered:
they definitely exist, but this covers the vast bulk of the cases, and the resulting diff is also then easier to check automatically.

For the same reason the 'flex' versions will be done as a separate conversion.

---
 libxfs/xfs_ag.c      |    2 +-
 libxfs/xfs_rtgroup.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libxfs/xfs_ag.c +1 -1
index 0f1eaf5d6e39b8..5742d59a2659da 100644
@@ -222,7 +222,7 @@ xfs_perag_alloc(
 	struct xfs_perag	*pag;
 	int			error;
 
-	pag = kzalloc_obj(*pag, GFP_KERNEL);
+	pag = kzalloc_obj(*pag);
 	if (!pag)
 		return -ENOMEM;
 
libxfs/xfs_rtgroup.c +1 -1
index 69e71494057a1e..d127ac0d611026 100644
@@ -95,7 +95,7 @@ xfs_rtgroup_alloc(
 	struct xfs_rtgroup	*rtg;
 	int			error;
 
-	rtg = kzalloc_obj(struct xfs_rtgroup, GFP_KERNEL);
+	rtg = kzalloc_obj(struct xfs_rtgroup);
 	if (!rtg)
 		return -ENOMEM;
 
#42 lore raw

PATCH 33/40 xfs: Refactoring the nagcount and delta calculation

In reply to Darrick J. Wong

From: Nirjhar Roy (IBM) <[email protected]>

Source kernel commit: a49b7ff63f98ba1c4503869c568c99ecffa478f2

Introduce xfs_growfs_compute_delta() to calculate the nagcount and delta blocks and refactor the code from xfs_growfs_data_private(). No functional changes.

---
 libxfs/xfs_ag.h |    3 +++
 libxfs/xfs_ag.c |   28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
libxfs/xfs_ag.h +3 -0
index 1f24cfa2732172..3cd4790768ff91 100644
@@ -331,6 +331,9 @@ struct aghdr_init_data {
 int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);
 int xfs_ag_shrink_space(struct xfs_perag *pag, struct xfs_trans **tpp,
 			xfs_extlen_t delta);
+void
+xfs_growfs_compute_deltas(struct xfs_mount *mp, xfs_rfsblock_t nb,
+			int64_t *deltap, xfs_agnumber_t *nagcountp);
 int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp,
 			xfs_extlen_t len);
 int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
libxfs/xfs_ag.c +28 -0
index 5742d59a2659da..fd5f902b052435 100644
@@ -870,6 +870,34 @@ xfs_ag_shrink_space(
 	return err2;
 }
 
+void
+xfs_growfs_compute_deltas(
+	struct xfs_mount	*mp,
+	xfs_rfsblock_t		nb,
+	int64_t			*deltap,
+	xfs_agnumber_t		*nagcountp)
+{
+	xfs_rfsblock_t	nb_div, nb_mod;
+	int64_t		delta;
+	xfs_agnumber_t	nagcount;
+
+	nb_div = nb;
+	nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks);
+	if (nb_mod && nb_mod >= XFS_MIN_AG_BLOCKS)
+		nb_div++;
+	else if (nb_mod)
+		nb = nb_div * mp->m_sb.sb_agblocks;
+
+	if (nb_div > XFS_MAX_AGNUMBER + 1) {
+		nb_div = XFS_MAX_AGNUMBER + 1;
+		nb = nb_div * mp->m_sb.sb_agblocks;
+	}
+	nagcount = nb_div;
+	delta = nb - mp->m_sb.sb_dblocks;
+	*deltap = delta;
+	*nagcountp = nagcount;
+}
+
 /*
  * Extent the AG indicated by the @id by the length passed in
  */
#43 lore raw

PATCH 34/40 xfs: fix code alignment issues in xfs_ondisk.c

In reply to Darrick J. Wong

From: Wilfred Mallawa <[email protected]>

Source kernel commit: fd81d3fd01a5ee4bd26a7dc440e7a2209277d14b

Fixup some code alignment issues in xfs_ondisk.c

---
 libxfs/xfs_ondisk.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libxfs/xfs_ondisk.h +2 -2
index 2e9715cc1641df..70605019383c32 100644
@@ -73,7 +73,7 @@ xfs_check_ondisk_structs(void)
 	XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_free_hdr,		64);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_leaf,		64);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_leaf_hdr,		64);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_attr_leaf_entry,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_attr_leaf_entry,	8);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_attr_leaf_hdr,		32);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_attr_leaf_map,		4);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_attr_leaf_name_local,	4);
@@ -116,7 +116,7 @@ xfs_check_ondisk_structs(void)
 	XFS_CHECK_STRUCT_SIZE(struct xfs_da_intnode,		16);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_da_node_entry,		8);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_da_node_hdr,		16);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_data_free,		4);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_data_free,	4);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_data_hdr,		16);
 	XFS_CHECK_OFFSET(struct xfs_dir2_data_unused, freetag,	0);
 	XFS_CHECK_OFFSET(struct xfs_dir2_data_unused, length,	2);
#44 lore raw

PATCH 35/40 xfs: remove metafile inodes from the active inode stat

In reply to Darrick J. Wong

From: Christoph Hellwig <[email protected]>

Source kernel commit: 47553dd60b1da88df2354f841a4f71dd4de6478a

The active inode (or active vnode until recently) stat can get much larger than expected on file systems with a lot of metafile inodes like zoned file systems on SMR hard disks with 10.000s of rtg rmap inodes.

Remove all metafile inodes from the active counter to make it more useful to track actual workloads and add a separate counter for active metafile inodes.

This fixes xfs/177 on SMR hard drives.

---
 libxfs/xfs_inode_buf.c |    4 ++++
 libxfs/xfs_metafile.c  |    5 +++++
 2 files changed, 9 insertions(+)
libxfs/xfs_inode_buf.c +4 -0
index 0802bc376073d8..f56aef0dbb3db9 100644
@@ -265,6 +265,10 @@ xfs_inode_from_disk(
 	}
 	if (xfs_is_reflink_inode(ip))
 		xfs_ifork_init_cow(ip);
+	if (xfs_is_metadir_inode(ip)) {
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+		XFS_STATS_INC(ip->i_mount, xs_inodes_meta);
+	}
 	return 0;
 
 out_destroy_data_fork:
libxfs/xfs_metafile.c +5 -0
index 8d98989349d086..bab5d7e29ae9a7 100644
@@ -59,6 +59,9 @@ xfs_metafile_set_iflag(
 	ip->i_diflags2 |= XFS_DIFLAG2_METADATA;
 	ip->i_metatype = metafile_type;
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+	XFS_STATS_INC(ip->i_mount, xs_inodes_meta);
 }
 
 /* Clear the metadata directory inode flag. */
@@ -72,6 +75,8 @@ xfs_metafile_clear_iflag(
 
 	ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA;
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	XFS_STATS_INC(ip->i_mount, xs_inodes_active);
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_meta);
 }
 
 /*
#45 lore raw

PATCH 36/40 xfs: Add a comment in xfs_log_sb()

In reply to Darrick J. Wong

From: Nirjhar Roy (IBM) <[email protected]>

Source kernel commit: ac1d977096a17d56c55bd7f90be48e81ac4cec3f

Add a comment explaining why the sb_frextents are updated outside the if (xfs_has_lazycount(mp) check even though it is a lazycounter. RT groups are supported only in v5 filesystems which always have lazycounter enabled - so putting it inside the if(xfs_has_lazycount(mp) check is redundant.

---
 libxfs/xfs_sb.c |    3 +++
 1 file changed, 3 insertions(+)
libxfs/xfs_sb.c +3 -0
index b29077dcd0aed7..7a1d85b86e59ea 100644
@@ -1345,6 +1345,9 @@ xfs_log_sb(
 	 * feature was introduced.  This counter can go negative due to the way
 	 * we handle nearly-lockless reservations, so we must use the _positive
 	 * variant here to avoid writing out nonsense frextents.
+	 *
+	 * RT groups are only supported on v5 file systems, which always
+	 * have lazy SB counters.
 	 */
 	if (xfs_has_rtgroups(mp) && !xfs_has_zoned(mp)) {
 		mp->m_sb.sb_frextents =
#46 lore raw

PATCH 37/40 xfs: remove duplicate static size checks

In reply to Darrick J. Wong

From: Wilfred Mallawa <[email protected]>

Source kernel commit: e97cbf863d8918452c9f81bebdade8d04e2e7b60

In libxfs/xfs_ondisk.h, remove some duplicate entries of XFS_CHECK_STRUCT_SIZE().

---
 libxfs/xfs_ondisk.h |    9 ---------
 1 file changed, 9 deletions(-)
libxfs/xfs_ondisk.h +0 -9
index 70605019383c32..7bccfa7b695c95 100644
@@ -136,16 +136,7 @@ xfs_check_ondisk_structs(void)
 	/* ondisk dir/attr structures from xfs/122 */
 	XFS_CHECK_STRUCT_SIZE(struct xfs_attr_sf_entry,		3);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_data_free,	4);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_data_hdr,		16);
 	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_data_unused,	6);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_free,		16);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_free_hdr,		16);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_leaf,		16);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_leaf_entry,	8);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_leaf_hdr,		16);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_leaf_tail,	4);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_sf_entry,		3);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_dir2_sf_hdr,		10);
 
 	/* log structures */
 	XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format,	88);
#47 lore raw

PATCH 38/40 xfs: add static size checks for ioctl UABI

In reply to Darrick J. Wong

From: Wilfred Mallawa <[email protected]>

Source kernel commit: 650b774cf94495465d6a38c31bb1a6ce697b6b37

The ioctl structures in libxfs/xfs_fs.h are missing static size checks. It is useful to have static size checks for these structures as adding new fields to them could cause issues (e.g. extra padding that may be inserted by the compiler). So add these checks to xfs/xfs_ondisk.h.

Due to different padding/alignment requirements across different architectures, to avoid build failures, some structures are ommited from the size checks. For example, structures with "compat_" definitions in xfs/xfs_ioctl32.h are ommited.

---
 libxfs/xfs_ondisk.h |   39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
libxfs/xfs_ondisk.h +34 -5
index 7bccfa7b695c95..23cde1248f019f 100644
@@ -208,11 +208,6 @@ xfs_check_ondisk_structs(void)
 	XFS_CHECK_OFFSET(struct xfs_dir3_free, hdr.hdr.magic,	0);
 	XFS_CHECK_OFFSET(struct xfs_attr3_leafblock, hdr.info.hdr, 0);
 
-	XFS_CHECK_STRUCT_SIZE(struct xfs_bulkstat,		192);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_inumbers,		24);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_bulkstat_req,		64);
-	XFS_CHECK_STRUCT_SIZE(struct xfs_inumbers_req,		64);
-
 	/*
 	 * Make sure the incore inode timestamp range corresponds to hand
 	 * converted values based on the ondisk format specification.
@@ -292,6 +287,40 @@ xfs_check_ondisk_structs(void)
 	XFS_CHECK_SB_OFFSET(sb_pad,			281);
 	XFS_CHECK_SB_OFFSET(sb_rtstart,			288);
 	XFS_CHECK_SB_OFFSET(sb_rtreserved,		296);
+
+	/*
+	 * ioctl UABI
+	 *
+	 * Due to different padding/alignment requirements across
+	 * different architectures, some structures are ommited from
+	 * the size checks. In addition, structures with architecture
+	 * dependent size fields are also ommited (e.g. __kernel_long_t).
+	 */
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bulkstat,		192);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inumbers,		24);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bulkstat_req,		64);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_inumbers_req,		64);
+	XFS_CHECK_STRUCT_SIZE(struct dioattr,			12);
+	XFS_CHECK_STRUCT_SIZE(struct getbmap,			32);
+	XFS_CHECK_STRUCT_SIZE(struct getbmapx,			48);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_attrlist_cursor,	16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_attrlist,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_attrlist,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_attrlist_ent,		4);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_ag_geometry,		128);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_rtgroup_geometry,	128);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_error_injection,	8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_fsop_geom,		256);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_fsop_geom_v4,		112);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_fsop_counts,		32);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_fsop_resblks,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_growfs_log,		8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_bulk_ireq,		64);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_fs_eofblocks,		128);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_fsid,			8);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_scrub_metadata,	64);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_scrub_vec,		16);
+	XFS_CHECK_STRUCT_SIZE(struct xfs_scrub_vec_head,	40);
 }
 
 #endif /* __XFS_ONDISK_H */
#48 lore raw

PATCH 39/40 xfs: Remove redundant NULL check after __GFP_NOFAIL

In reply to Darrick J. Wong

From: hongao <[email protected]>

Source kernel commit: 281cb17787d4284a7790b9cbd80fded826ca7739

kzalloc() is called with __GFP_NOFAIL, so a NULL return is not expected. Drop the redundant !map check in xfs_dabuf_map().
Also switch the nirecs-sized allocation to kcalloc().

---
 libxfs/xfs_da_btree.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
libxfs/xfs_da_btree.c +2 -6
index 969bfc9dee909d..2fce657af5d0b6 100644
@@ -2712,12 +2712,8 @@ xfs_dabuf_map(
 	 * larger one that needs to be free by the caller.
 	 */
 	if (nirecs > 1) {
-		map = kzalloc(nirecs * sizeof(struct xfs_buf_map),
-				GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-		if (!map) {
-			error = -ENOMEM;
-			goto out_free_irecs;
-		}
+		map = kcalloc(nirecs, sizeof(struct xfs_buf_map),
+			      GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
 		*mapp = map;
 	}
 
#49 lore raw

PATCH 40/40 xfs: fix returned valued from xfs_defer_can_append

In reply to Darrick J. Wong

From: Carlos Maiolino <[email protected]>

Source kernel commit: 54fcd2f95f8d216183965a370ec69e1aab14f5da

xfs_defer_can_append returns a bool, it shouldn't be returning a NULL.

Found by code inspection.

Fixes 4dffb2cbb483 ("xfs: allow pausing of pending deferred work items")
---
 libxfs/xfs_defer.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_defer.c +1 -1
index e4d17177f67faf..3e36865fd1279f 100644
@@ -802,7 +802,7 @@ xfs_defer_can_append(
 
 	/* Paused items cannot absorb more work */
 	if (dfp->dfp_flags & XFS_DEFER_PAUSED)
-		return NULL;
+		return false;
 
 	/* Already full? */
 	if (ops->max_items && dfp->dfp_count >= ops->max_items)