Lines Matching refs:tm

105 static int is_shadow(struct dm_transaction_manager *tm, dm_block_t b)
111 spin_lock(&tm->lock);
112 hlist_for_each_entry(si, tm->buckets + bucket, hlist)
117 spin_unlock(&tm->lock);
126 static void insert_shadow(struct dm_transaction_manager *tm, dm_block_t b)
135 spin_lock(&tm->lock);
136 hlist_add_head(&si->hlist, tm->buckets + bucket);
137 spin_unlock(&tm->lock);
141 static void wipe_shadow_table(struct dm_transaction_manager *tm)
148 spin_lock(&tm->lock);
150 bucket = tm->buckets + i;
157 spin_unlock(&tm->lock);
166 struct dm_transaction_manager *tm;
168 tm = kmalloc(sizeof(*tm), GFP_KERNEL);
169 if (!tm)
172 tm->is_clone = 0;
173 tm->real = NULL;
174 tm->bm = bm;
175 tm->sm = sm;
177 spin_lock_init(&tm->lock);
179 INIT_HLIST_HEAD(tm->buckets + i);
181 prefetch_init(&tm->prefetches);
183 return tm;
188 struct dm_transaction_manager *tm;
190 tm = kmalloc(sizeof(*tm), GFP_KERNEL);
191 if (tm) {
192 tm->is_clone = 1;
193 tm->real = real;
196 return tm;
200 void dm_tm_destroy(struct dm_transaction_manager *tm)
202 if (!tm)
205 if (!tm->is_clone)
206 wipe_shadow_table(tm);
208 kfree(tm);
212 int dm_tm_pre_commit(struct dm_transaction_manager *tm)
216 if (tm->is_clone)
219 r = dm_sm_commit(tm->sm);
223 return dm_bm_flush(tm->bm);
227 int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *root)
229 if (tm->is_clone)
232 wipe_shadow_table(tm);
235 return dm_bm_flush(tm->bm);
239 int dm_tm_new_block(struct dm_transaction_manager *tm,
246 if (tm->is_clone)
249 r = dm_sm_new_block(tm->sm, &new_block);
253 r = dm_bm_write_lock_zero(tm->bm, new_block, v, result);
255 dm_sm_dec_block(tm->sm, new_block);
263 insert_shadow(tm, new_block);
268 static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
276 r = dm_sm_new_block(tm->sm, &new);
280 r = dm_sm_dec_block(tm->sm, orig);
284 r = dm_bm_read_lock(tm->bm, orig, v, &orig_block);
295 r = dm_bm_write_lock_zero(tm->bm, new, v, result);
302 dm_bm_block_size(tm->bm));
308 int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
314 if (tm->is_clone)
317 r = dm_sm_count_is_more_than_one(tm->sm, orig, inc_children);
321 if (is_shadow(tm, orig) && !*inc_children)
322 return dm_bm_write_lock(tm->bm, orig, v, result);
324 r = __shadow_block(tm, orig, v, result);
327 insert_shadow(tm, dm_block_location(*result));
333 int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b,
337 if (tm->is_clone) {
338 int r = dm_bm_read_try_lock(tm->real->bm, b, v, blk);
341 prefetch_add(&tm->real->prefetches, b);
346 return dm_bm_read_lock(tm->bm, b, v, blk);
350 void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b)
356 void dm_tm_inc(struct dm_transaction_manager *tm, dm_block_t b)
361 BUG_ON(tm->is_clone);
363 dm_sm_inc_block(tm->sm, b);
367 void dm_tm_inc_range(struct dm_transaction_manager *tm, dm_block_t b, dm_block_t e)
372 BUG_ON(tm->is_clone);
374 dm_sm_inc_blocks(tm->sm, b, e);
378 void dm_tm_dec(struct dm_transaction_manager *tm, dm_block_t b)
383 BUG_ON(tm->is_clone);
385 dm_sm_dec_block(tm->sm, b);
389 void dm_tm_dec_range(struct dm_transaction_manager *tm, dm_block_t b, dm_block_t e)
394 BUG_ON(tm->is_clone);
396 dm_sm_dec_blocks(tm->sm, b, e);
400 void dm_tm_with_runs(struct dm_transaction_manager *tm,
414 fn(tm, begin, end);
426 fn(tm, begin, end);
430 int dm_tm_ref(struct dm_transaction_manager *tm, dm_block_t b,
433 if (tm->is_clone)
436 return dm_sm_get_count(tm->sm, b, result);
439 int dm_tm_block_is_shared(struct dm_transaction_manager *tm, dm_block_t b,
442 if (tm->is_clone)
445 return dm_sm_count_is_more_than_one(tm->sm, b, result);
448 struct dm_block_manager *dm_tm_get_bm(struct dm_transaction_manager *tm)
450 return tm->bm;
453 void dm_tm_issue_prefetches(struct dm_transaction_manager *tm)
455 prefetch_issue(&tm->prefetches, tm->bm);
463 struct dm_transaction_manager **tm,
474 *tm = dm_tm_create(bm, *sm);
475 if (IS_ERR(*tm)) {
477 return PTR_ERR(*tm);
481 r = dm_sm_metadata_create(*sm, *tm, dm_bm_nr_blocks(bm),
489 r = dm_sm_metadata_open(*sm, *tm, sm_root, sm_len);
499 dm_tm_destroy(*tm);
505 struct dm_transaction_manager **tm,
508 return dm_tm_create_internal(bm, sb_location, tm, sm, 1, NULL, 0);
514 struct dm_transaction_manager **tm,
517 return dm_tm_create_internal(bm, sb_location, tm, sm, 0, sm_root, root_len);