• Home
  • Raw
  • Download

Lines Matching refs:ll

191 static int sm_ll_init(struct ll_disk *ll, struct dm_transaction_manager *tm)  in sm_ll_init()  argument
193 ll->tm = tm; in sm_ll_init()
195 ll->bitmap_info.tm = tm; in sm_ll_init()
196 ll->bitmap_info.levels = 1; in sm_ll_init()
203 ll->bitmap_info.value_type.size = sizeof(struct disk_index_entry); in sm_ll_init()
204 ll->bitmap_info.value_type.inc = NULL; in sm_ll_init()
205 ll->bitmap_info.value_type.dec = NULL; in sm_ll_init()
206 ll->bitmap_info.value_type.equal = NULL; in sm_ll_init()
208 ll->ref_count_info.tm = tm; in sm_ll_init()
209 ll->ref_count_info.levels = 1; in sm_ll_init()
210 ll->ref_count_info.value_type.size = sizeof(uint32_t); in sm_ll_init()
211 ll->ref_count_info.value_type.inc = NULL; in sm_ll_init()
212 ll->ref_count_info.value_type.dec = NULL; in sm_ll_init()
213 ll->ref_count_info.value_type.equal = NULL; in sm_ll_init()
215 ll->block_size = dm_bm_block_size(dm_tm_get_bm(tm)); in sm_ll_init()
217 if (ll->block_size > (1 << 30)) { in sm_ll_init()
222 ll->entries_per_block = (ll->block_size - sizeof(struct disk_bitmap_header)) * in sm_ll_init()
224 ll->nr_blocks = 0; in sm_ll_init()
225 ll->bitmap_root = 0; in sm_ll_init()
226 ll->ref_count_root = 0; in sm_ll_init()
227 ll->bitmap_index_changed = false; in sm_ll_init()
232 int sm_ll_extend(struct ll_disk *ll, dm_block_t extra_blocks) in sm_ll_extend() argument
238 nr_blocks = ll->nr_blocks + extra_blocks; in sm_ll_extend()
239 old_blocks = dm_sector_div_up(ll->nr_blocks, ll->entries_per_block); in sm_ll_extend()
240 blocks = dm_sector_div_up(nr_blocks, ll->entries_per_block); in sm_ll_extend()
242 nr_indexes = dm_sector_div_up(nr_blocks, ll->entries_per_block); in sm_ll_extend()
243 if (nr_indexes > ll->max_entries(ll)) { in sm_ll_extend()
252 r = dm_tm_new_block(ll->tm, &dm_sm_bitmap_validator, &b); in sm_ll_extend()
257 r = dm_tm_unlock(ll->tm, b); in sm_ll_extend()
261 idx.nr_free = cpu_to_le32(ll->entries_per_block); in sm_ll_extend()
264 r = ll->save_ie(ll, i, &idx); in sm_ll_extend()
269 ll->nr_blocks = nr_blocks; in sm_ll_extend()
273 int sm_ll_lookup_bitmap(struct ll_disk *ll, dm_block_t b, uint32_t *result) in sm_ll_lookup_bitmap() argument
280 b = do_div(index, ll->entries_per_block); in sm_ll_lookup_bitmap()
281 r = ll->load_ie(ll, index, &ie_disk); in sm_ll_lookup_bitmap()
285 r = dm_tm_read_lock(ll->tm, le64_to_cpu(ie_disk.blocknr), in sm_ll_lookup_bitmap()
292 return dm_tm_unlock(ll->tm, blk); in sm_ll_lookup_bitmap()
295 int sm_ll_lookup(struct ll_disk *ll, dm_block_t b, uint32_t *result) in sm_ll_lookup() argument
298 int r = sm_ll_lookup_bitmap(ll, b, result); in sm_ll_lookup()
306 r = dm_btree_lookup(&ll->ref_count_info, ll->ref_count_root, &b, &le_rc); in sm_ll_lookup()
315 int sm_ll_find_free_block(struct ll_disk *ll, dm_block_t begin, in sm_ll_find_free_block() argument
321 dm_block_t index_end = dm_sector_div_up(end, ll->entries_per_block); in sm_ll_find_free_block()
326 begin = do_div(index_begin, ll->entries_per_block); in sm_ll_find_free_block()
327 end = do_div(end, ll->entries_per_block); in sm_ll_find_free_block()
334 r = ll->load_ie(ll, i, &ie_disk); in sm_ll_find_free_block()
341 r = dm_tm_read_lock(ll->tm, le64_to_cpu(ie_disk.blocknr), in sm_ll_find_free_block()
346 bit_end = (i == index_end - 1) ? end : ll->entries_per_block; in sm_ll_find_free_block()
356 dm_tm_unlock(ll->tm, blk); in sm_ll_find_free_block()
360 dm_tm_unlock(ll->tm, blk); in sm_ll_find_free_block()
364 r = dm_tm_unlock(ll->tm, blk); in sm_ll_find_free_block()
368 *result = i * ll->entries_per_block + (dm_block_t) position; in sm_ll_find_free_block()
375 int sm_ll_insert(struct ll_disk *ll, dm_block_t b, in sm_ll_insert() argument
386 bit = do_div(index, ll->entries_per_block); in sm_ll_insert()
387 r = ll->load_ie(ll, index, &ie_disk); in sm_ll_insert()
391 r = dm_tm_shadow_block(ll->tm, le64_to_cpu(ie_disk.blocknr), in sm_ll_insert()
405 r = dm_tm_unlock(ll->tm, nb); in sm_ll_insert()
410 r = dm_btree_remove(&ll->ref_count_info, in sm_ll_insert()
411 ll->ref_count_root, in sm_ll_insert()
412 &b, &ll->ref_count_root); in sm_ll_insert()
421 r = dm_tm_unlock(ll->tm, nb); in sm_ll_insert()
426 r = dm_btree_insert(&ll->ref_count_info, ll->ref_count_root, in sm_ll_insert()
427 &b, &le_rc, &ll->ref_count_root); in sm_ll_insert()
436 ll->nr_allocated++; in sm_ll_insert()
443 ll->nr_allocated--; in sm_ll_insert()
448 return ll->save_ie(ll, index, &ie_disk); in sm_ll_insert()
451 int sm_ll_inc(struct ll_disk *ll, dm_block_t b, enum allocation_event *ev) in sm_ll_inc() argument
456 r = sm_ll_lookup(ll, b, &rc); in sm_ll_inc()
460 return sm_ll_insert(ll, b, rc + 1, ev); in sm_ll_inc()
463 int sm_ll_dec(struct ll_disk *ll, dm_block_t b, enum allocation_event *ev) in sm_ll_dec() argument
468 r = sm_ll_lookup(ll, b, &rc); in sm_ll_dec()
475 return sm_ll_insert(ll, b, rc - 1, ev); in sm_ll_dec()
478 int sm_ll_commit(struct ll_disk *ll) in sm_ll_commit() argument
482 if (ll->bitmap_index_changed) { in sm_ll_commit()
483 r = ll->commit(ll); in sm_ll_commit()
485 ll->bitmap_index_changed = false; in sm_ll_commit()
493 static int metadata_ll_load_ie(struct ll_disk *ll, dm_block_t index, in metadata_ll_load_ie() argument
496 memcpy(ie, ll->mi_le.index + index, sizeof(*ie)); in metadata_ll_load_ie()
500 static int metadata_ll_save_ie(struct ll_disk *ll, dm_block_t index, in metadata_ll_save_ie() argument
503 ll->bitmap_index_changed = true; in metadata_ll_save_ie()
504 memcpy(ll->mi_le.index + index, ie, sizeof(*ie)); in metadata_ll_save_ie()
508 static int metadata_ll_init_index(struct ll_disk *ll) in metadata_ll_init_index() argument
513 r = dm_tm_new_block(ll->tm, &index_validator, &b); in metadata_ll_init_index()
517 memcpy(dm_block_data(b), &ll->mi_le, sizeof(ll->mi_le)); in metadata_ll_init_index()
518 ll->bitmap_root = dm_block_location(b); in metadata_ll_init_index()
520 return dm_tm_unlock(ll->tm, b); in metadata_ll_init_index()
523 static int metadata_ll_open(struct ll_disk *ll) in metadata_ll_open() argument
528 r = dm_tm_read_lock(ll->tm, ll->bitmap_root, in metadata_ll_open()
533 memcpy(&ll->mi_le, dm_block_data(block), sizeof(ll->mi_le)); in metadata_ll_open()
534 return dm_tm_unlock(ll->tm, block); in metadata_ll_open()
537 static dm_block_t metadata_ll_max_entries(struct ll_disk *ll) in metadata_ll_max_entries() argument
542 static int metadata_ll_commit(struct ll_disk *ll) in metadata_ll_commit() argument
547 r = dm_tm_shadow_block(ll->tm, ll->bitmap_root, &index_validator, &b, &inc); in metadata_ll_commit()
551 memcpy(dm_block_data(b), &ll->mi_le, sizeof(ll->mi_le)); in metadata_ll_commit()
552 ll->bitmap_root = dm_block_location(b); in metadata_ll_commit()
554 return dm_tm_unlock(ll->tm, b); in metadata_ll_commit()
557 int sm_ll_new_metadata(struct ll_disk *ll, struct dm_transaction_manager *tm) in sm_ll_new_metadata() argument
561 r = sm_ll_init(ll, tm); in sm_ll_new_metadata()
565 ll->load_ie = metadata_ll_load_ie; in sm_ll_new_metadata()
566 ll->save_ie = metadata_ll_save_ie; in sm_ll_new_metadata()
567 ll->init_index = metadata_ll_init_index; in sm_ll_new_metadata()
568 ll->open_index = metadata_ll_open; in sm_ll_new_metadata()
569 ll->max_entries = metadata_ll_max_entries; in sm_ll_new_metadata()
570 ll->commit = metadata_ll_commit; in sm_ll_new_metadata()
572 ll->nr_blocks = 0; in sm_ll_new_metadata()
573 ll->nr_allocated = 0; in sm_ll_new_metadata()
575 r = ll->init_index(ll); in sm_ll_new_metadata()
579 r = dm_btree_empty(&ll->ref_count_info, &ll->ref_count_root); in sm_ll_new_metadata()
586 int sm_ll_open_metadata(struct ll_disk *ll, struct dm_transaction_manager *tm, in sm_ll_open_metadata() argument
597 r = sm_ll_init(ll, tm); in sm_ll_open_metadata()
601 ll->load_ie = metadata_ll_load_ie; in sm_ll_open_metadata()
602 ll->save_ie = metadata_ll_save_ie; in sm_ll_open_metadata()
603 ll->init_index = metadata_ll_init_index; in sm_ll_open_metadata()
604 ll->open_index = metadata_ll_open; in sm_ll_open_metadata()
605 ll->max_entries = metadata_ll_max_entries; in sm_ll_open_metadata()
606 ll->commit = metadata_ll_commit; in sm_ll_open_metadata()
608 ll->nr_blocks = le64_to_cpu(smr->nr_blocks); in sm_ll_open_metadata()
609 ll->nr_allocated = le64_to_cpu(smr->nr_allocated); in sm_ll_open_metadata()
610 ll->bitmap_root = le64_to_cpu(smr->bitmap_root); in sm_ll_open_metadata()
611 ll->ref_count_root = le64_to_cpu(smr->ref_count_root); in sm_ll_open_metadata()
613 return ll->open_index(ll); in sm_ll_open_metadata()
618 static int disk_ll_load_ie(struct ll_disk *ll, dm_block_t index, in disk_ll_load_ie() argument
621 return dm_btree_lookup(&ll->bitmap_info, ll->bitmap_root, &index, ie); in disk_ll_load_ie()
624 static int disk_ll_save_ie(struct ll_disk *ll, dm_block_t index, in disk_ll_save_ie() argument
628 return dm_btree_insert(&ll->bitmap_info, ll->bitmap_root, in disk_ll_save_ie()
629 &index, ie, &ll->bitmap_root); in disk_ll_save_ie()
632 static int disk_ll_init_index(struct ll_disk *ll) in disk_ll_init_index() argument
634 return dm_btree_empty(&ll->bitmap_info, &ll->bitmap_root); in disk_ll_init_index()
637 static int disk_ll_open(struct ll_disk *ll) in disk_ll_open() argument
643 static dm_block_t disk_ll_max_entries(struct ll_disk *ll) in disk_ll_max_entries() argument
648 static int disk_ll_commit(struct ll_disk *ll) in disk_ll_commit() argument
653 int sm_ll_new_disk(struct ll_disk *ll, struct dm_transaction_manager *tm) in sm_ll_new_disk() argument
657 r = sm_ll_init(ll, tm); in sm_ll_new_disk()
661 ll->load_ie = disk_ll_load_ie; in sm_ll_new_disk()
662 ll->save_ie = disk_ll_save_ie; in sm_ll_new_disk()
663 ll->init_index = disk_ll_init_index; in sm_ll_new_disk()
664 ll->open_index = disk_ll_open; in sm_ll_new_disk()
665 ll->max_entries = disk_ll_max_entries; in sm_ll_new_disk()
666 ll->commit = disk_ll_commit; in sm_ll_new_disk()
668 ll->nr_blocks = 0; in sm_ll_new_disk()
669 ll->nr_allocated = 0; in sm_ll_new_disk()
671 r = ll->init_index(ll); in sm_ll_new_disk()
675 r = dm_btree_empty(&ll->ref_count_info, &ll->ref_count_root); in sm_ll_new_disk()
682 int sm_ll_open_disk(struct ll_disk *ll, struct dm_transaction_manager *tm, in sm_ll_open_disk() argument
693 r = sm_ll_init(ll, tm); in sm_ll_open_disk()
697 ll->load_ie = disk_ll_load_ie; in sm_ll_open_disk()
698 ll->save_ie = disk_ll_save_ie; in sm_ll_open_disk()
699 ll->init_index = disk_ll_init_index; in sm_ll_open_disk()
700 ll->open_index = disk_ll_open; in sm_ll_open_disk()
701 ll->max_entries = disk_ll_max_entries; in sm_ll_open_disk()
702 ll->commit = disk_ll_commit; in sm_ll_open_disk()
704 ll->nr_blocks = le64_to_cpu(smr->nr_blocks); in sm_ll_open_disk()
705 ll->nr_allocated = le64_to_cpu(smr->nr_allocated); in sm_ll_open_disk()
706 ll->bitmap_root = le64_to_cpu(smr->bitmap_root); in sm_ll_open_disk()
707 ll->ref_count_root = le64_to_cpu(smr->ref_count_root); in sm_ll_open_disk()
709 return ll->open_index(ll); in sm_ll_open_disk()