• Home
  • Raw
  • Download

Lines Matching +full:int +full:- +full:threshold

7 #include "dm-space-map.h"
8 #include "dm-space-map-common.h"
9 #include "dm-space-map-metadata.h"
13 #include <linux/device-mapper.h>
18 /*----------------------------------------------------------------*/
21 * An edge triggered threshold.
23 struct threshold { struct
26 dm_block_t threshold; argument
32 static void threshold_init(struct threshold *t) in threshold_init() argument
34 t->threshold_set = false; in threshold_init()
35 t->value_set = false; in threshold_init()
38 static void set_threshold(struct threshold *t, dm_block_t value, in set_threshold()
41 t->threshold_set = true; in set_threshold()
42 t->threshold = value; in set_threshold()
43 t->fn = fn; in set_threshold()
44 t->context = context; in set_threshold()
47 static bool below_threshold(struct threshold *t, dm_block_t value) in below_threshold()
49 return t->threshold_set && value <= t->threshold; in below_threshold()
52 static bool threshold_already_triggered(struct threshold *t) in threshold_already_triggered()
54 return t->value_set && below_threshold(t, t->current_value); in threshold_already_triggered()
57 static void check_threshold(struct threshold *t, dm_block_t value) in check_threshold()
61 t->fn(t->context); in check_threshold()
63 t->value_set = true; in check_threshold()
64 t->current_value = value; in check_threshold()
67 /*----------------------------------------------------------------*/
75 * For this reason we have a pool of pre-allocated blocks large enough to
103 brb->begin = 0; in brb_init()
104 brb->end = 0; in brb_init()
109 return brb->begin == brb->end; in brb_empty()
115 return r >= ARRAY_SIZE(brb->bops) ? 0 : r; in brb_next()
118 static int brb_push(struct bop_ring_buffer *brb, in brb_push()
122 unsigned next = brb_next(brb, brb->end); in brb_push()
128 if (next == brb->begin) in brb_push()
129 return -ENOMEM; in brb_push()
131 bop = brb->bops + brb->end; in brb_push()
132 bop->type = type; in brb_push()
133 bop->block = b; in brb_push()
135 brb->end = next; in brb_push()
140 static int brb_peek(struct bop_ring_buffer *brb, struct block_op *result) in brb_peek()
145 return -ENODATA; in brb_peek()
147 bop = brb->bops + brb->begin; in brb_peek()
148 result->type = bop->type; in brb_peek()
149 result->block = bop->block; in brb_peek()
154 static int brb_pop(struct bop_ring_buffer *brb) in brb_pop()
157 return -ENODATA; in brb_pop()
159 brb->begin = brb_next(brb, brb->begin); in brb_pop()
164 /*----------------------------------------------------------------*/
178 struct threshold threshold; member
181 static int add_bop(struct sm_metadata *smm, enum block_op_type type, dm_block_t b) in add_bop()
183 int r = brb_push(&smm->uncommitted, type, b); in add_bop()
187 return -ENOMEM; in add_bop()
193 static int commit_bop(struct sm_metadata *smm, struct block_op *op) in commit_bop()
195 int r = 0; in commit_bop()
198 switch (op->type) { in commit_bop()
200 r = sm_ll_inc(&smm->ll, op->block, &ev); in commit_bop()
204 r = sm_ll_dec(&smm->ll, op->block, &ev); in commit_bop()
213 smm->recursion_count++; in in()
216 static int apply_bops(struct sm_metadata *smm) in apply_bops()
218 int r = 0; in apply_bops()
220 while (!brb_empty(&smm->uncommitted)) { in apply_bops()
223 r = brb_peek(&smm->uncommitted, &bop); in apply_bops()
233 brb_pop(&smm->uncommitted); in apply_bops()
239 static int out(struct sm_metadata *smm) in out()
241 int r = 0; in out()
246 if (!smm->recursion_count) { in out()
248 return -ENOMEM; in out()
251 if (smm->recursion_count == 1) in out()
254 smm->recursion_count--; in out()
264 static int combine_errors(int r1, int r2) in combine_errors()
269 static int recursing(struct sm_metadata *smm) in recursing()
271 return smm->recursion_count; in recursing()
281 static int sm_metadata_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count) in sm_metadata_get_nr_blocks()
285 *count = smm->ll.nr_blocks; in sm_metadata_get_nr_blocks()
290 static int sm_metadata_get_nr_free(struct dm_space_map *sm, dm_block_t *count) in sm_metadata_get_nr_free()
294 *count = smm->old_ll.nr_blocks - smm->old_ll.nr_allocated - in sm_metadata_get_nr_free()
295 smm->allocated_this_transaction; in sm_metadata_get_nr_free()
300 static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b, in sm_metadata_get_count()
303 int r; in sm_metadata_get_count()
312 for (i = smm->uncommitted.begin; in sm_metadata_get_count()
313 i != smm->uncommitted.end; in sm_metadata_get_count()
314 i = brb_next(&smm->uncommitted, i)) { in sm_metadata_get_count()
315 struct block_op *op = smm->uncommitted.bops + i; in sm_metadata_get_count()
317 if (op->block != b) in sm_metadata_get_count()
320 switch (op->type) { in sm_metadata_get_count()
326 adjustment--; in sm_metadata_get_count()
331 r = sm_ll_lookup(&smm->ll, b, result); in sm_metadata_get_count()
340 static int sm_metadata_count_is_more_than_one(struct dm_space_map *sm, in sm_metadata_count_is_more_than_one()
341 dm_block_t b, int *result) in sm_metadata_count_is_more_than_one()
343 int r, adjustment = 0; in sm_metadata_count_is_more_than_one()
352 for (i = smm->uncommitted.begin; in sm_metadata_count_is_more_than_one()
353 i != smm->uncommitted.end; in sm_metadata_count_is_more_than_one()
354 i = brb_next(&smm->uncommitted, i)) { in sm_metadata_count_is_more_than_one()
356 struct block_op *op = smm->uncommitted.bops + i; in sm_metadata_count_is_more_than_one()
358 if (op->block != b) in sm_metadata_count_is_more_than_one()
361 switch (op->type) { in sm_metadata_count_is_more_than_one()
367 adjustment--; in sm_metadata_count_is_more_than_one()
377 r = sm_ll_lookup_bitmap(&smm->ll, b, &rc); in sm_metadata_count_is_more_than_one()
392 static int sm_metadata_set_count(struct dm_space_map *sm, dm_block_t b, in sm_metadata_set_count()
395 int r, r2; in sm_metadata_set_count()
399 if (smm->recursion_count) { in sm_metadata_set_count()
401 return -EINVAL; in sm_metadata_set_count()
405 r = sm_ll_insert(&smm->ll, b, count, &ev); in sm_metadata_set_count()
411 static int sm_metadata_inc_block(struct dm_space_map *sm, dm_block_t b) in sm_metadata_inc_block()
413 int r, r2 = 0; in sm_metadata_inc_block()
421 r = sm_ll_inc(&smm->ll, b, &ev); in sm_metadata_inc_block()
428 static int sm_metadata_dec_block(struct dm_space_map *sm, dm_block_t b) in sm_metadata_dec_block()
430 int r, r2 = 0; in sm_metadata_dec_block()
438 r = sm_ll_dec(&smm->ll, b, &ev); in sm_metadata_dec_block()
445 static int sm_metadata_new_block_(struct dm_space_map *sm, dm_block_t *b) in sm_metadata_new_block_()
447 int r, r2 = 0; in sm_metadata_new_block_()
454 r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, smm->begin, smm->ll.nr_blocks, b); in sm_metadata_new_block_()
455 if (r == -ENOSPC) { in sm_metadata_new_block_()
457 * There's no free block between smm->begin and the end of the metadata device. in sm_metadata_new_block_()
458 * We search before smm->begin in case something has been freed. in sm_metadata_new_block_()
460 r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, 0, smm->begin, b); in sm_metadata_new_block_()
466 smm->begin = *b + 1; in sm_metadata_new_block_()
472 r = sm_ll_inc(&smm->ll, *b, &ev); in sm_metadata_new_block_()
477 smm->allocated_this_transaction++; in sm_metadata_new_block_()
482 static int sm_metadata_new_block(struct dm_space_map *sm, dm_block_t *b) in sm_metadata_new_block()
487 int r = sm_metadata_new_block_(sm, b); in sm_metadata_new_block()
499 check_threshold(&smm->threshold, count); in sm_metadata_new_block()
504 static int sm_metadata_commit(struct dm_space_map *sm) in sm_metadata_commit()
506 int r; in sm_metadata_commit()
509 r = sm_ll_commit(&smm->ll); in sm_metadata_commit()
513 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll)); in sm_metadata_commit()
514 smm->allocated_this_transaction = 0; in sm_metadata_commit()
519 static int sm_metadata_register_threshold_callback(struct dm_space_map *sm, in sm_metadata_register_threshold_callback()
520 dm_block_t threshold, in sm_metadata_register_threshold_callback() argument
526 set_threshold(&smm->threshold, threshold, fn, context); in sm_metadata_register_threshold_callback()
531 static int sm_metadata_root_size(struct dm_space_map *sm, size_t *result) in sm_metadata_root_size()
538 static int sm_metadata_copy_root(struct dm_space_map *sm, void *where_le, size_t max) in sm_metadata_copy_root()
543 root_le.nr_blocks = cpu_to_le64(smm->ll.nr_blocks); in sm_metadata_copy_root()
544 root_le.nr_allocated = cpu_to_le64(smm->ll.nr_allocated); in sm_metadata_copy_root()
545 root_le.bitmap_root = cpu_to_le64(smm->ll.bitmap_root); in sm_metadata_copy_root()
546 root_le.ref_count_root = cpu_to_le64(smm->ll.ref_count_root); in sm_metadata_copy_root()
549 return -ENOSPC; in sm_metadata_copy_root()
556 static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks);
575 /*----------------------------------------------------------------*/
585 static int sm_bootstrap_extend(struct dm_space_map *sm, dm_block_t extra_blocks) in sm_bootstrap_extend()
589 return -EINVAL; in sm_bootstrap_extend()
592 static int sm_bootstrap_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count) in sm_bootstrap_get_nr_blocks()
596 *count = smm->ll.nr_blocks; in sm_bootstrap_get_nr_blocks()
601 static int sm_bootstrap_get_nr_free(struct dm_space_map *sm, dm_block_t *count) in sm_bootstrap_get_nr_free()
605 *count = smm->ll.nr_blocks - smm->begin; in sm_bootstrap_get_nr_free()
610 static int sm_bootstrap_get_count(struct dm_space_map *sm, dm_block_t b, in sm_bootstrap_get_count()
615 *result = (b < smm->begin) ? 1 : 0; in sm_bootstrap_get_count()
620 static int sm_bootstrap_count_is_more_than_one(struct dm_space_map *sm, in sm_bootstrap_count_is_more_than_one()
621 dm_block_t b, int *result) in sm_bootstrap_count_is_more_than_one()
628 static int sm_bootstrap_set_count(struct dm_space_map *sm, dm_block_t b, in sm_bootstrap_set_count()
633 return -EINVAL; in sm_bootstrap_set_count()
636 static int sm_bootstrap_new_block(struct dm_space_map *sm, dm_block_t *b) in sm_bootstrap_new_block()
643 if (smm->begin == smm->ll.nr_blocks) in sm_bootstrap_new_block()
644 return -ENOSPC; in sm_bootstrap_new_block()
646 *b = smm->begin++; in sm_bootstrap_new_block()
651 static int sm_bootstrap_inc_block(struct dm_space_map *sm, dm_block_t b) in sm_bootstrap_inc_block()
658 static int sm_bootstrap_dec_block(struct dm_space_map *sm, dm_block_t b) in sm_bootstrap_dec_block()
665 static int sm_bootstrap_commit(struct dm_space_map *sm) in sm_bootstrap_commit()
670 static int sm_bootstrap_root_size(struct dm_space_map *sm, size_t *result) in sm_bootstrap_root_size()
674 return -EINVAL; in sm_bootstrap_root_size()
677 static int sm_bootstrap_copy_root(struct dm_space_map *sm, void *where, in sm_bootstrap_copy_root()
682 return -EINVAL; in sm_bootstrap_copy_root()
702 /*----------------------------------------------------------------*/
704 static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks) in sm_metadata_extend()
706 int r, i; in sm_metadata_extend()
708 dm_block_t old_len = smm->ll.nr_blocks; in sm_metadata_extend()
713 smm->begin = old_len; in sm_metadata_extend()
719 r = sm_ll_extend(&smm->ll, extra_blocks); in sm_metadata_extend()
728 for (i = old_len; !r && i < smm->begin; i++) in sm_metadata_extend()
734 old_len = smm->begin; in sm_metadata_extend()
742 r = sm_ll_commit(&smm->ll); in sm_metadata_extend()
746 } while (old_len != smm->begin); in sm_metadata_extend()
756 /*----------------------------------------------------------------*/
764 return ERR_PTR(-ENOMEM); in dm_sm_metadata_init()
766 memcpy(&smm->sm, &ops, sizeof(smm->sm)); in dm_sm_metadata_init()
768 return &smm->sm; in dm_sm_metadata_init()
771 int dm_sm_metadata_create(struct dm_space_map *sm, in dm_sm_metadata_create()
776 int r; in dm_sm_metadata_create()
780 smm->begin = superblock + 1; in dm_sm_metadata_create()
781 smm->recursion_count = 0; in dm_sm_metadata_create()
782 smm->allocated_this_transaction = 0; in dm_sm_metadata_create()
783 brb_init(&smm->uncommitted); in dm_sm_metadata_create()
784 threshold_init(&smm->threshold); in dm_sm_metadata_create()
786 memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm)); in dm_sm_metadata_create()
788 r = sm_ll_new_metadata(&smm->ll, tm); in dm_sm_metadata_create()
792 r = sm_ll_extend(&smm->ll, nr_blocks); in dm_sm_metadata_create()
794 memcpy(&smm->sm, &ops, sizeof(smm->sm)); in dm_sm_metadata_create()
802 for (i = superblock; !r && i < smm->begin; i++) in dm_sm_metadata_create()
817 int dm_sm_metadata_open(struct dm_space_map *sm, in dm_sm_metadata_open()
821 int r; in dm_sm_metadata_open()
824 r = sm_ll_open_metadata(&smm->ll, tm, root_le, len); in dm_sm_metadata_open()
828 smm->begin = 0; in dm_sm_metadata_open()
829 smm->recursion_count = 0; in dm_sm_metadata_open()
830 smm->allocated_this_transaction = 0; in dm_sm_metadata_open()
831 brb_init(&smm->uncommitted); in dm_sm_metadata_open()
832 threshold_init(&smm->threshold); in dm_sm_metadata_open()
834 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll)); in dm_sm_metadata_open()