diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-11-08 17:11:44 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-01 11:46:52 -0500 |
commit | 73ab9e03861c22ec6723b7b110d62ba60f37c164 (patch) | |
tree | 433dcdcedf50af693c4b3b4fe25a9a9fcab0a554 /fs/bcachefs/darray.c | |
parent | f87bf892ea9848696ddfd184964d303202dd19dd (diff) |
bcachefs: Factor out darray resize slowpath
Move the slowpath (actually growing the darray) to an out-of-line
function; also, add some helpers for the upcoming btree write buffer
rewrite.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/darray.c')
-rw-r--r-- | fs/bcachefs/darray.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/fs/bcachefs/darray.c b/fs/bcachefs/darray.c new file mode 100644 index 000000000000..aae07be1d911 --- /dev/null +++ b/fs/bcachefs/darray.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/log2.h> +#include <linux/slab.h> +#include "darray.h" + +int __bch2_darray_resize(darray_void *d, size_t element_size, size_t new_size, gfp_t gfp) +{ + if (new_size > d->size) { + new_size = roundup_pow_of_two(new_size); + + void *data = krealloc_array(d->data, new_size, element_size, gfp); + if (!data) + return -ENOMEM; + + d->data = data; + d->size = new_size; + } + + return 0; +} |