diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-11-17 20:36:59 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2019-11-17 20:36:59 -0500 |
commit | 8c20176f2ce40fc8b0151e5a7d17561dd0eda0b5 (patch) | |
tree | 18c678ddb5aa1842acfbe28021bace8828c8ab7c /libbcachefs/bkey_on_stack.h | |
parent | 1f7098c22213bbe66896f390a529223468a3986e (diff) |
Update bcachefs sources to d372ddcbfa bcachefs: Reorganize extents.c
Diffstat (limited to 'libbcachefs/bkey_on_stack.h')
-rw-r--r-- | libbcachefs/bkey_on_stack.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libbcachefs/bkey_on_stack.h b/libbcachefs/bkey_on_stack.h new file mode 100644 index 00000000..d4739038 --- /dev/null +++ b/libbcachefs/bkey_on_stack.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_BKEY_ON_STACK_H +#define _BCACHEFS_BKEY_ON_STACK_H + +#include "bcachefs.h" + +struct bkey_on_stack { + struct bkey_i *k; + u64 onstack[12]; +}; + +static inline void bkey_on_stack_realloc(struct bkey_on_stack *s, + struct bch_fs *c, unsigned u64s) +{ + if (s->k == (void *) s->onstack && + u64s > ARRAY_SIZE(s->onstack)) { + s->k = mempool_alloc(&c->large_bkey_pool, GFP_NOFS); + memcpy(s->k, s->onstack, sizeof(s->onstack)); + } +} + +static inline void bkey_on_stack_init(struct bkey_on_stack *s) +{ + s->k = (void *) s->onstack; +} + +static inline void bkey_on_stack_exit(struct bkey_on_stack *s, + struct bch_fs *c) +{ + if (s->k != (void *) s->onstack) + mempool_free(s->k, &c->large_bkey_pool); + s->k = NULL; +} + +#endif /* _BCACHEFS_BKEY_ON_STACK_H */ |