diff options
author | Joe Thornber <ejt@redhat.com> | 2015-05-15 10:22:02 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2015-05-29 14:19:05 -0400 |
commit | 451b9e0071b2833744db7f518115bc085bc7b23c (patch) | |
tree | 40f56515e7d9f5c125e6b4d088729737b648c466 | |
parent | 20f6814b94fff4a98b123f1c2b691e936be27aaf (diff) |
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>
-rw-r--r-- | drivers/md/dm-cache-policy-internal.h | 28 | ||||
-rw-r--r-- | drivers/md/dm-cache-target.c | 24 |
2 files changed, 28 insertions, 24 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 @@ | |||
7 | #ifndef DM_CACHE_POLICY_INTERNAL_H | 7 | #ifndef DM_CACHE_POLICY_INTERNAL_H |
8 | #define DM_CACHE_POLICY_INTERNAL_H | 8 | #define DM_CACHE_POLICY_INTERNAL_H |
9 | 9 | ||
10 | #include <linux/vmalloc.h> | ||
10 | #include "dm-cache-policy.h" | 11 | #include "dm-cache-policy.h" |
11 | 12 | ||
12 | /*----------------------------------------------------------------*/ | 13 | /*----------------------------------------------------------------*/ |
@@ -107,6 +108,33 @@ static inline int policy_set_config_value(struct dm_cache_policy *p, | |||
107 | /*----------------------------------------------------------------*/ | 108 | /*----------------------------------------------------------------*/ |
108 | 109 | ||
109 | /* | 110 | /* |
111 | * Some utility functions commonly used by policies and the core target. | ||
112 | */ | ||
113 | static inline size_t bitset_size_in_bytes(unsigned nr_entries) | ||
114 | { | ||
115 | return sizeof(unsigned long) * dm_div_up(nr_entries, BITS_PER_LONG); | ||
116 | } | ||
117 | |||
118 | static inline unsigned long *alloc_bitset(unsigned nr_entries) | ||
119 | { | ||
120 | size_t s = bitset_size_in_bytes(nr_entries); | ||
121 | return vzalloc(s); | ||
122 | } | ||
123 | |||
124 | static inline void clear_bitset(void *bitset, unsigned nr_entries) | ||
125 | { | ||
126 | size_t s = bitset_size_in_bytes(nr_entries); | ||
127 | memset(bitset, 0, s); | ||
128 | } | ||
129 | |||
130 | static inline void free_bitset(unsigned long *bits) | ||
131 | { | ||
132 | vfree(bits); | ||
133 | } | ||
134 | |||
135 | /*----------------------------------------------------------------*/ | ||
136 | |||
137 | /* | ||
110 | * Creates a new cache policy given a policy name, a cache size, an origin size and the block size. | 138 | * Creates a new cache policy given a policy name, a cache size, an origin size and the block size. |
111 | */ | 139 | */ |
112 | struct dm_cache_policy *dm_cache_policy_create(const char *name, dm_cblock_t cache_size, | 140 | struct dm_cache_policy *dm_cache_policy_create(const char *name, dm_cblock_t cache_size, |
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index 5a9cd2c5a359..5d3b20b91ba3 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c | |||
@@ -111,30 +111,6 @@ static void iot_io_end(struct io_tracker *iot, sector_t len) | |||
111 | 111 | ||
112 | /*----------------------------------------------------------------*/ | 112 | /*----------------------------------------------------------------*/ |
113 | 113 | ||
114 | static size_t bitset_size_in_bytes(unsigned nr_entries) | ||
115 | { | ||
116 | return sizeof(unsigned long) * dm_div_up(nr_entries, BITS_PER_LONG); | ||
117 | } | ||
118 | |||
119 | static unsigned long *alloc_bitset(unsigned nr_entries) | ||
120 | { | ||
121 | size_t s = bitset_size_in_bytes(nr_entries); | ||
122 | return vzalloc(s); | ||
123 | } | ||
124 | |||
125 | static void clear_bitset(void *bitset, unsigned nr_entries) | ||
126 | { | ||
127 | size_t s = bitset_size_in_bytes(nr_entries); | ||
128 | memset(bitset, 0, s); | ||
129 | } | ||
130 | |||
131 | static void free_bitset(unsigned long *bits) | ||
132 | { | ||
133 | vfree(bits); | ||
134 | } | ||
135 | |||
136 | /*----------------------------------------------------------------*/ | ||
137 | |||
138 | /* | 114 | /* |
139 | * There are a couple of places where we let a bio run, but want to do some | 115 | * There are a couple of places where we let a bio run, but want to do some |
140 | * work before calling its endio function. We do this by temporarily | 116 | * work before calling its endio function. We do this by temporarily |