int dm_sm_metadata_create(struct dm_space_map *sm,
			  struct dm_transaction_manager *tm,
			  dm_block_t nr_blocks,
			  dm_block_t superblock)
{
	int r;
	dm_block_t i;
	enum allocation_event ev;
	struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);

	smm->begin = superblock + 1;
	smm->recursion_count = 0;
	smm->allocated_this_transaction = 0;
	brb_init(&smm->uncommitted);
	threshold_init(&smm->threshold);

	memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm));

	r = sm_ll_new_metadata(&smm->ll, tm);
	if (r)
		return r;

	if (nr_blocks > DM_SM_METADATA_MAX_BLOCKS)
		nr_blocks = DM_SM_METADATA_MAX_BLOCKS;
	r = sm_ll_extend(&smm->ll, nr_blocks);
	if (r)
		return r;

	memcpy(&smm->sm, &ops, sizeof(smm->sm));

	/*
	 * Now we need to update the newly created data structures with the
	 * allocated blocks that they were built from.
	 */
	for (i = superblock; !r && i < smm->begin; i++)
		r = sm_ll_inc(&smm->ll, i, &ev);

	if (r)
		return r;

	r = apply_bops(smm);
	if (r) {
		DMERR("%s: apply_bops failed", __func__);
		return r;
	}

	return sm_metadata_commit(sm);
}
Пример #2
0
int dm_sm_metadata_open(struct dm_space_map *sm,
                        struct dm_transaction_manager *tm,
                        void *root_le, size_t len)
{
    int r;
    struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);

    r = sm_ll_open_metadata(&smm->ll, tm, root_le, len);
    if (r)
        return r;

    smm->begin = 0;
    smm->recursion_count = 0;
    smm->allocated_this_transaction = 0;
    brb_init(&smm->uncommitted);
    threshold_init(&smm->threshold);

    memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll));
    return 0;
}