diff options
author | Darrick J. Wong <djwong@kernel.org> | 2024-02-22 12:30:54 -0800 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2024-02-22 12:30:54 -0800 |
commit | 5a3ab5849583217090e29299c7bee88b827c12d8 (patch) | |
tree | 27895c5804fdfdf1fd4d9163a4c9964bb644185c /fs/xfs/scrub | |
parent | ebd610fe82c1d2a94c6fe27cd04d5cf911b5e171 (diff) | |
download | linux-5a3ab5849583217090e29299c7bee88b827c12d8.tar.gz linux-5a3ab5849583217090e29299c7bee88b827c12d8.tar.bz2 linux-5a3ab5849583217090e29299c7bee88b827c12d8.zip |
xfs: create a sparse load xfarray function
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.
This is a separate patch to reduce the size of the upcoming quotacheck
patch.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/scrub')
-rw-r--r-- | fs/xfs/scrub/xfarray.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/fs/xfs/scrub/xfarray.h b/fs/xfs/scrub/xfarray.h index ec643cc9fc14..acb2f94c56c1 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) { |