Lines Matching refs:smm
183 static int add_bop(struct sm_metadata *smm, enum block_op_type type, dm_block_t b, dm_block_t e)
185 int r = brb_push(&smm->uncommitted, type, b, e);
195 static int commit_bop(struct sm_metadata *smm, struct block_op *op)
202 r = sm_ll_inc(&smm->ll, op->b, op->e, &nr_allocations);
206 r = sm_ll_dec(&smm->ll, op->b, op->e, &nr_allocations);
213 static void in(struct sm_metadata *smm)
215 smm->recursion_count++;
218 static int apply_bops(struct sm_metadata *smm)
222 while (!brb_empty(&smm->uncommitted)) {
225 r = brb_peek(&smm->uncommitted, &bop);
231 r = commit_bop(smm, &bop);
235 brb_pop(&smm->uncommitted);
241 static int out(struct sm_metadata *smm)
248 if (!smm->recursion_count) {
253 if (smm->recursion_count == 1)
254 r = apply_bops(smm);
256 smm->recursion_count--;
271 static int recursing(struct sm_metadata *smm)
273 return smm->recursion_count;
278 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
280 kfree(smm);
285 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
287 *count = smm->ll.nr_blocks;
294 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
296 *count = smm->old_ll.nr_blocks - smm->old_ll.nr_allocated -
297 smm->allocated_this_transaction;
307 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
314 for (i = smm->uncommitted.begin;
315 i != smm->uncommitted.end;
316 i = brb_next(&smm->uncommitted, i)) {
317 struct block_op *op = smm->uncommitted.bops + i;
333 r = sm_ll_lookup(&smm->ll, b, result);
347 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
354 for (i = smm->uncommitted.begin;
355 i != smm->uncommitted.end;
356 i = brb_next(&smm->uncommitted, i)) {
358 struct block_op *op = smm->uncommitted.bops + i;
379 r = sm_ll_lookup_bitmap(&smm->ll, b, &rc);
399 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
401 if (smm->recursion_count) {
406 in(smm);
407 r = sm_ll_insert(&smm->ll, b, count, &nr_allocations);
408 r2 = out(smm);
417 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
419 if (recursing(smm)) {
420 r = add_bop(smm, BOP_INC, b, e);
424 in(smm);
425 r = sm_ll_inc(&smm->ll, b, e, &nr_allocations);
426 r2 = out(smm);
436 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
438 if (recursing(smm))
439 r = add_bop(smm, BOP_DEC, b, e);
441 in(smm);
442 r = sm_ll_dec(&smm->ll, b, e, &nr_allocations);
443 r2 = out(smm);
453 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
458 r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, smm->begin, smm->ll.nr_blocks, b);
461 * There's no free block between smm->begin and the end of the metadata device.
462 * We search before smm->begin in case something has been freed.
464 r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, 0, smm->begin, b);
470 smm->begin = *b + 1;
472 if (recursing(smm))
473 r = add_bop(smm, BOP_INC, *b, *b + 1);
475 in(smm);
476 r = sm_ll_inc(&smm->ll, *b, *b + 1, &nr_allocations);
477 r2 = out(smm);
481 smm->allocated_this_transaction++;
489 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
504 check_threshold(&smm->threshold, count);
512 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
514 r = sm_ll_commit(&smm->ll);
518 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll));
519 smm->allocated_this_transaction = 0;
529 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
531 set_threshold(&smm->threshold, threshold, fn, context);
545 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
548 root_le.nr_blocks = cpu_to_le64(smm->ll.nr_blocks);
549 root_le.nr_allocated = cpu_to_le64(smm->ll.nr_allocated);
550 root_le.bitmap_root = cpu_to_le64(smm->ll.bitmap_root);
551 root_le.ref_count_root = cpu_to_le64(smm->ll.ref_count_root);
599 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
601 *count = smm->ll.nr_blocks;
608 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
610 *count = smm->ll.nr_blocks - smm->begin;
618 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
620 *result = (b < smm->begin) ? 1 : 0;
643 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
648 if (smm->begin == smm->ll.nr_blocks)
651 *b = smm->begin++;
659 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
661 r = add_bop(smm, BOP_INC, b, e);
671 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
673 r = add_bop(smm, BOP_DEC, b, e);
722 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
723 dm_block_t old_len = smm->ll.nr_blocks;
728 smm->begin = old_len;
734 r = sm_ll_extend(&smm->ll, extra_blocks);
743 r = add_bop(smm, BOP_INC, old_len, smm->begin);
747 old_len = smm->begin;
749 r = apply_bops(smm);
755 r = sm_ll_commit(&smm->ll);
759 } while (old_len != smm->begin);
773 struct sm_metadata *smm;
775 smm = kmalloc(sizeof(*smm), GFP_KERNEL);
776 if (!smm)
779 memcpy(&smm->sm, &ops, sizeof(smm->sm));
781 return &smm->sm;
790 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
792 smm->begin = superblock + 1;
793 smm->recursion_count = 0;
794 smm->allocated_this_transaction = 0;
795 brb_init(&smm->uncommitted);
796 threshold_init(&smm->threshold);
798 memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm));
800 r = sm_ll_new_metadata(&smm->ll, tm);
804 r = sm_ll_extend(&smm->ll, nr_blocks);
806 memcpy(&smm->sm, &ops, sizeof(smm->sm));
814 r = add_bop(smm, BOP_INC, superblock, smm->begin);
818 r = apply_bops(smm);
832 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
834 r = sm_ll_open_metadata(&smm->ll, tm, root_le, len);
838 smm->begin = 0;
839 smm->recursion_count = 0;
840 smm->allocated_this_transaction = 0;
841 brb_init(&smm->uncommitted);
842 threshold_init(&smm->threshold);
844 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll));