diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-11-12 20:53:57 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-11-12 20:57:28 -0500 |
commit | 7fd6c3ffe45b3b42c0bc8a8c5d1387a5e3316a54 (patch) | |
tree | d596299da8c34dff74cb13caf9dd47d9154c25b4 /libbcachefs/darray.c | |
parent | a613340b26ad88801666362d2824118396f34c38 (diff) |
Update bcachefs sources to 3ca08ab51ec9 bcachefs: six locks: Simplify optimistic spinning
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'libbcachefs/darray.c')
-rw-r--r-- | libbcachefs/darray.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libbcachefs/darray.c b/libbcachefs/darray.c new file mode 100644 index 00000000..aae07be1 --- /dev/null +++ b/libbcachefs/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; +} |