diff mbox series

[3/4] libmultipath: enable defining a static bitfield

Message ID 20220217195533.4251-4-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: Mike Snitzer
Headers show
Series libmultipath: utter less dev_loss_tmo warnings | expand

Commit Message

Martin Wilck Feb. 17, 2022, 7:55 p.m. UTC
From: Martin Wilck <mwilck@suse.com>

The STATIC_BITFIELD macro allows defining a static variable holding
a bitfield of constant length.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/util.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

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);