aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/persistent-data
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2016-10-03 14:15:02 -0400
committerMike Snitzer <snitzer@redhat.com>2017-02-16 13:12:45 -0500
commit6fe28dbf05e329ce136f38219d95a1826ceafebd (patch)
treee5619c3b907f006f72257fc74eccb941e1ae646b /drivers/md/persistent-data
parent9f9ef0657d53d988dc07b096052b3dd07d6e3c46 (diff)
dm bitset: introduce cursor api
Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md/persistent-data')
-rw-r--r--drivers/md/persistent-data/dm-bitset.c69
-rw-r--r--drivers/md/persistent-data/dm-bitset.h22
2 files changed, 91 insertions, 0 deletions
diff --git a/drivers/md/persistent-data/dm-bitset.c b/drivers/md/persistent-data/dm-bitset.c
index 36f7cc2c7109..7cb28516cc19 100644
--- a/drivers/md/persistent-data/dm-bitset.c
+++ b/drivers/md/persistent-data/dm-bitset.c
@@ -168,4 +168,73 @@ int dm_bitset_test_bit(struct dm_disk_bitset *info, dm_block_t root,
168} 168}
169EXPORT_SYMBOL_GPL(dm_bitset_test_bit); 169EXPORT_SYMBOL_GPL(dm_bitset_test_bit);
170 170
171static int cursor_next_array_entry(struct dm_bitset_cursor *c)
172{
173 int r;
174 __le64 *value;
175
176 r = dm_array_cursor_next(&c->cursor);
177 if (r)
178 return r;
179
180 dm_array_cursor_get_value(&c->cursor, (void **) &value);
181 c->array_index++;
182 c->bit_index = 0;
183 c->current_bits = le64_to_cpu(*value);
184 return 0;
185}
186
187int dm_bitset_cursor_begin(struct dm_disk_bitset *info,
188 dm_block_t root, uint32_t nr_entries,
189 struct dm_bitset_cursor *c)
190{
191 int r;
192 __le64 *value;
193
194 if (!nr_entries)
195 return -ENODATA;
196
197 c->info = info;
198 c->entries_remaining = nr_entries;
199
200 r = dm_array_cursor_begin(&info->array_info, root, &c->cursor);
201 if (r)
202 return r;
203
204 dm_array_cursor_get_value(&c->cursor, (void **) &value);
205 c->array_index = 0;
206 c->bit_index = 0;
207 c->current_bits = le64_to_cpu(*value);
208
209 return r;
210}
211EXPORT_SYMBOL_GPL(dm_bitset_cursor_begin);
212
213void dm_bitset_cursor_end(struct dm_bitset_cursor *c)
214{
215 return dm_array_cursor_end(&c->cursor);
216}
217EXPORT_SYMBOL_GPL(dm_bitset_cursor_end);
218
219int dm_bitset_cursor_next(struct dm_bitset_cursor *c)
220{
221 int r = 0;
222
223 if (!c->entries_remaining)
224 return -ENODATA;
225
226 c->entries_remaining--;
227 if (++c->bit_index > 63)
228 r = cursor_next_array_entry(c);
229
230 return r;
231}
232EXPORT_SYMBOL_GPL(dm_bitset_cursor_next);
233
234bool dm_bitset_cursor_get_value(struct dm_bitset_cursor *c)
235{
236 return test_bit(c->bit_index, (unsigned long *) &c->current_bits);
237}
238EXPORT_SYMBOL_GPL(dm_bitset_cursor_get_value);
239
171/*----------------------------------------------------------------*/ 240/*----------------------------------------------------------------*/
diff --git a/drivers/md/persistent-data/dm-bitset.h b/drivers/md/persistent-data/dm-bitset.h
index c2287d672ef5..017c0d42cdbf 100644
--- a/drivers/md/persistent-data/dm-bitset.h
+++ b/drivers/md/persistent-data/dm-bitset.h
@@ -161,6 +161,28 @@ int dm_bitset_test_bit(struct dm_disk_bitset *info, dm_block_t root,
161int dm_bitset_flush(struct dm_disk_bitset *info, dm_block_t root, 161int dm_bitset_flush(struct dm_disk_bitset *info, dm_block_t root,
162 dm_block_t *new_root); 162 dm_block_t *new_root);
163 163
164struct dm_bitset_cursor {
165 struct dm_disk_bitset *info;
166 struct dm_array_cursor cursor;
167
168 uint32_t entries_remaining;
169 uint32_t array_index;
170 uint32_t bit_index;
171 uint64_t current_bits;
172};
173
174/*
175 * Make sure you've flush any dm_disk_bitset and updated the root before
176 * using this.
177 */
178int dm_bitset_cursor_begin(struct dm_disk_bitset *info,
179 dm_block_t root, uint32_t nr_entries,
180 struct dm_bitset_cursor *c);
181void dm_bitset_cursor_end(struct dm_bitset_cursor *c);
182
183int dm_bitset_cursor_next(struct dm_bitset_cursor *c);
184bool dm_bitset_cursor_get_value(struct dm_bitset_cursor *c);
185
164/*----------------------------------------------------------------*/ 186/*----------------------------------------------------------------*/
165 187
166#endif /* _LINUX_DM_BITSET_H */ 188#endif /* _LINUX_DM_BITSET_H */