summaryrefslogtreecommitdiff
path: root/drivers/md/dm-cache-policy-internal.h
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2015-05-15 17:22:02 +0300
committerMike Snitzer <snitzer@redhat.com>2015-05-29 21:19:05 +0300
commit451b9e0071b2833744db7f518115bc085bc7b23c (patch)
tree40f56515e7d9f5c125e6b4d088729737b648c466 /drivers/md/dm-cache-policy-internal.h
parent20f6814b94fff4a98b123f1c2b691e936be27aaf (diff)
downloadlinux-451b9e0071b2833744db7f518115bc085bc7b23c.tar.xz
dm cache: pull out some bitset utility functions for reuse
Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md/dm-cache-policy-internal.h')
-rw-r--r--drivers/md/dm-cache-policy-internal.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/md/dm-cache-policy-internal.h b/drivers/md/dm-cache-policy-internal.h
index 776c685167e6..9dc05a52369e 100644
--- a/drivers/md/dm-cache-policy-internal.h
+++ b/drivers/md/dm-cache-policy-internal.h
@@ -7,6 +7,7 @@
#ifndef DM_CACHE_POLICY_INTERNAL_H
#define DM_CACHE_POLICY_INTERNAL_H
+#include <linux/vmalloc.h>
#include "dm-cache-policy.h"
/*----------------------------------------------------------------*/
@@ -107,6 +108,33 @@ static inline int policy_set_config_value(struct dm_cache_policy *p,
/*----------------------------------------------------------------*/
/*
+ * Some utility functions commonly used by policies and the core target.
+ */
+static inline size_t bitset_size_in_bytes(unsigned nr_entries)
+{
+ return sizeof(unsigned long) * dm_div_up(nr_entries, BITS_PER_LONG);
+}
+
+static inline unsigned long *alloc_bitset(unsigned nr_entries)
+{
+ size_t s = bitset_size_in_bytes(nr_entries);
+ return vzalloc(s);
+}
+
+static inline void clear_bitset(void *bitset, unsigned nr_entries)
+{
+ size_t s = bitset_size_in_bytes(nr_entries);
+ memset(bitset, 0, s);
+}
+
+static inline void free_bitset(unsigned long *bits)
+{
+ vfree(bits);
+}
+
+/*----------------------------------------------------------------*/
+
+/*
* Creates a new cache policy given a policy name, a cache size, an origin size and the block size.
*/
struct dm_cache_policy *dm_cache_policy_create(const char *name, dm_cblock_t cache_size,