Lines Matching refs:tm

103 static int is_shadow(struct dm_transaction_manager *tm, dm_block_t b)
109 spin_lock(&tm->lock);
110 hlist_for_each_entry(si, tm->buckets + bucket, hlist)
115 spin_unlock(&tm->lock);
124 static void insert_shadow(struct dm_transaction_manager *tm, dm_block_t b)
133 spin_lock(&tm->lock);
134 hlist_add_head(&si->hlist, tm->buckets + bucket);
135 spin_unlock(&tm->lock);
139 static void wipe_shadow_table(struct dm_transaction_manager *tm)
146 spin_lock(&tm->lock);
148 bucket = tm->buckets + i;
155 spin_unlock(&tm->lock);
164 struct dm_transaction_manager *tm;
166 tm = kmalloc(sizeof(*tm), GFP_KERNEL);
167 if (!tm)
170 tm->is_clone = 0;
171 tm->real = NULL;
172 tm->bm = bm;
173 tm->sm = sm;
175 spin_lock_init(&tm->lock);
177 INIT_HLIST_HEAD(tm->buckets + i);
179 prefetch_init(&tm->prefetches);
181 return tm;
186 struct dm_transaction_manager *tm;
188 tm = kmalloc(sizeof(*tm), GFP_KERNEL);
189 if (tm) {
190 tm->is_clone = 1;
191 tm->real = real;
194 return tm;
198 void dm_tm_destroy(struct dm_transaction_manager *tm)
200 if (!tm->is_clone)
201 wipe_shadow_table(tm);
203 kfree(tm);
207 int dm_tm_pre_commit(struct dm_transaction_manager *tm)
211 if (tm->is_clone)
214 r = dm_sm_commit(tm->sm);
218 return dm_bm_flush(tm->bm);
222 int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *root)
224 if (tm->is_clone)
227 wipe_shadow_table(tm);
230 return dm_bm_flush(tm->bm);
234 int dm_tm_new_block(struct dm_transaction_manager *tm,
241 if (tm->is_clone)
244 r = dm_sm_new_block(tm->sm, &new_block);
248 r = dm_bm_write_lock_zero(tm->bm, new_block, v, result);
250 dm_sm_dec_block(tm->sm, new_block);
258 insert_shadow(tm, new_block);
263 static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
271 r = dm_sm_new_block(tm->sm, &new);
275 r = dm_sm_dec_block(tm->sm, orig);
279 r = dm_bm_read_lock(tm->bm, orig, v, &orig_block);
290 r = dm_bm_write_lock_zero(tm->bm, new, v, result);
297 dm_bm_block_size(tm->bm));
303 int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
309 if (tm->is_clone)
312 r = dm_sm_count_is_more_than_one(tm->sm, orig, inc_children);
316 if (is_shadow(tm, orig) && !*inc_children)
317 return dm_bm_write_lock(tm->bm, orig, v, result);
319 r = __shadow_block(tm, orig, v, result);
322 insert_shadow(tm, dm_block_location(*result));
328 int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b,
332 if (tm->is_clone) {
333 int r = dm_bm_read_try_lock(tm->real->bm, b, v, blk);
336 prefetch_add(&tm->real->prefetches, b);
341 return dm_bm_read_lock(tm->bm, b, v, blk);
345 void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b)
351 void dm_tm_inc(struct dm_transaction_manager *tm, dm_block_t b)
356 BUG_ON(tm->is_clone);
358 dm_sm_inc_block(tm->sm, b);
362 void dm_tm_dec(struct dm_transaction_manager *tm, dm_block_t b)
367 BUG_ON(tm->is_clone);
369 dm_sm_dec_block(tm->sm, b);
373 int dm_tm_ref(struct dm_transaction_manager *tm, dm_block_t b,
376 if (tm->is_clone)
379 return dm_sm_get_count(tm->sm, b, result);
382 struct dm_block_manager *dm_tm_get_bm(struct dm_transaction_manager *tm)
384 return tm->bm;
387 void dm_tm_issue_prefetches(struct dm_transaction_manager *tm)
389 prefetch_issue(&tm->prefetches, tm->bm);
397 struct dm_transaction_manager **tm,
408 *tm = dm_tm_create(bm, *sm);
409 if (IS_ERR(*tm)) {
411 return PTR_ERR(*tm);
415 r = dm_sm_metadata_create(*sm, *tm, dm_bm_nr_blocks(bm),
423 r = dm_sm_metadata_open(*sm, *tm, sm_root, sm_len);
433 dm_tm_destroy(*tm);
439 struct dm_transaction_manager **tm,
442 return dm_tm_create_internal(bm, sb_location, tm, sm, 1, NULL, 0);
448 struct dm_transaction_manager **tm,
451 return dm_tm_create_internal(bm, sb_location, tm, sm, 0, sm_root, root_len);