diff mbox series

[4/8] xfs: create a sparse load xfarray function

Message ID 170659062818.3353369.15735312742710633221.stgit@frogsfrogsfrogs (mailing list archive)
State New
Headers show
Series [1/8] xfs: report the health of quota counts | expand

Commit Message

Darrick J. Wong Jan. 30, 2024, 5:07 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Create a new method to load an xfarray element from the xfile, but with
a twist.  If we've never stored to the array index, zero the caller's
buffer.  This will facilitate RMWs updates of records in a sparse array
without fuss, since the sparse xfarray convention is that uninitialized
array elements default to zeroes.

Christoph requested this as a separate patch to reduce the size
of the upcoming quotacheck patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/scrub/xfarray.h |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Christoph Hellwig Jan. 30, 2024, 8:17 a.m. UTC | #1
Looks good modulo the naming calling that is completely irrelevant to
anyone trying to understand this code in the future:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/fs/xfs/scrub/xfarray.h b/fs/xfs/scrub/xfarray.h
index ec643cc9fc143..acb2f94c56c13 100644
--- a/fs/xfs/scrub/xfarray.h
+++ b/fs/xfs/scrub/xfarray.h
@@ -45,6 +45,25 @@  int xfarray_store(struct xfarray *array, xfarray_idx_t idx, const void *ptr);
 int xfarray_store_anywhere(struct xfarray *array, const void *ptr);
 bool xfarray_element_is_null(struct xfarray *array, const void *ptr);
 
+/*
+ * Load an array element, but zero the buffer if there's no data because we
+ * haven't stored to that array element yet.
+ */
+static inline int
+xfarray_load_sparse(
+	struct xfarray	*array,
+	uint64_t	idx,
+	void		*rec)
+{
+	int		error = xfarray_load(array, idx, rec);
+
+	if (error == -ENODATA) {
+		memset(rec, 0, array->obj_size);
+		return 0;
+	}
+	return error;
+}
+
 /* Append an element to the array. */
 static inline int xfarray_append(struct xfarray *array, const void *ptr)
 {