[dm-devel] [PATCH 3/4] libmultipath: enable defining a static bitfield
mwilck at suse.com
mwilck at suse.com
Thu Feb 17 19:55:32 UTC 2022
From: Martin Wilck <mwilck at suse.com>
The STATIC_BITFIELD macro allows defining a static variable holding
a bitfield of constant length.
Signed-off-by: Martin Wilck <mwilck at suse.com>
---
libmultipath/util.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/libmultipath/util.h b/libmultipath/util.h
index 79d9f32..5a44018 100644
--- a/libmultipath/util.h
+++ b/libmultipath/util.h
@@ -82,6 +82,16 @@ struct bitfield {
bitfield_t bits[];
};
+#define STATIC_BITFIELD(name, length) \
+ static struct { \
+ unsigned int len; \
+ bitfield_t bits[((length) - 1) / bits_per_slot + 1]; \
+ } __static__ ## name = { \
+ .len = (length), \
+ .bits = { 0, }, \
+ }; \
+ struct bitfield *name = (struct bitfield *)& __static__ ## name
+
struct bitfield *alloc_bitfield(unsigned int maxbit);
void _log_bitfield_overflow(const char *f, unsigned int bit, unsigned int len);
--
2.35.1
More information about the dm-devel
mailing list