Lines Matching refs:trans

31 static noinline int extent_front_merge(struct btree_trans *trans,  in extent_front_merge()  argument
37 struct bch_fs *c = trans->c; in extent_front_merge()
41 if (unlikely(trans->journal_replay_not_finished)) in extent_front_merge()
44 update = bch2_bkey_make_mut_noupdate(trans, k); in extent_front_merge()
52 ret = bch2_key_has_snapshot_overwrites(trans, iter->btree_id, k.k->p) ?: in extent_front_merge()
53 bch2_key_has_snapshot_overwrites(trans, iter->btree_id, (*insert)->k.p); in extent_front_merge()
59 ret = bch2_btree_delete_at(trans, iter, flags); in extent_front_merge()
67 static noinline int extent_back_merge(struct btree_trans *trans, in extent_back_merge() argument
72 struct bch_fs *c = trans->c; in extent_back_merge()
75 if (unlikely(trans->journal_replay_not_finished)) in extent_back_merge()
78 ret = bch2_key_has_snapshot_overwrites(trans, iter->btree_id, insert->k.p) ?: in extent_back_merge()
79 bch2_key_has_snapshot_overwrites(trans, iter->btree_id, k.k->p); in extent_back_merge()
93 static int need_whiteout_for_snapshot(struct btree_trans *trans, in need_whiteout_for_snapshot() argument
101 if (!bch2_snapshot_parent(trans->c, pos.snapshot)) in need_whiteout_for_snapshot()
106 for_each_btree_key_norestart(trans, iter, btree_id, pos, in need_whiteout_for_snapshot()
112 if (bch2_snapshot_is_ancestor(trans->c, snapshot, in need_whiteout_for_snapshot()
118 bch2_trans_iter_exit(trans, &iter); in need_whiteout_for_snapshot()
123 int __bch2_insert_snapshot_whiteouts(struct btree_trans *trans, in __bch2_insert_snapshot_whiteouts() argument
128 struct bch_fs *c = trans->c; in __bch2_insert_snapshot_whiteouts()
140 bch2_trans_iter_init(trans, &old_iter, id, old_pos, in __bch2_insert_snapshot_whiteouts()
153 new_k = bch2_bkey_get_iter(trans, &new_iter, id, whiteout_pos, in __bch2_insert_snapshot_whiteouts()
161 update = bch2_trans_kmalloc(trans, sizeof(struct bkey_i)); in __bch2_insert_snapshot_whiteouts()
170 ret = bch2_trans_update(trans, &new_iter, update, in __bch2_insert_snapshot_whiteouts()
173 bch2_trans_iter_exit(trans, &new_iter); in __bch2_insert_snapshot_whiteouts()
179 bch2_trans_iter_exit(trans, &new_iter); in __bch2_insert_snapshot_whiteouts()
180 bch2_trans_iter_exit(trans, &old_iter); in __bch2_insert_snapshot_whiteouts()
186 int bch2_trans_update_extent_overwrite(struct btree_trans *trans, in bch2_trans_update_extent_overwrite() argument
209 trans->extra_disk_res += compressed_sectors * (nr_splits - 1); in bch2_trans_update_extent_overwrite()
212 update = bch2_bkey_make_mut_noupdate(trans, old); in bch2_trans_update_extent_overwrite()
218 ret = bch2_insert_snapshot_whiteouts(trans, btree_id, in bch2_trans_update_extent_overwrite()
220 bch2_btree_insert_nonextent(trans, btree_id, update, in bch2_trans_update_extent_overwrite()
228 update = bch2_bkey_make_mut_noupdate(trans, old); in bch2_trans_update_extent_overwrite()
235 ret = bch2_insert_snapshot_whiteouts(trans, btree_id, in bch2_trans_update_extent_overwrite()
237 bch2_btree_insert_nonextent(trans, btree_id, update, in bch2_trans_update_extent_overwrite()
244 update = bch2_trans_kmalloc(trans, sizeof(*update)); in bch2_trans_update_extent_overwrite()
255 ret = need_whiteout_for_snapshot(trans, btree_id, update->k.p); in bch2_trans_update_extent_overwrite()
262 ret = bch2_btree_insert_nonextent(trans, btree_id, update, in bch2_trans_update_extent_overwrite()
269 update = bch2_bkey_make_mut_noupdate(trans, old); in bch2_trans_update_extent_overwrite()
275 ret = bch2_trans_update_by_path(trans, iter->path, update, in bch2_trans_update_extent_overwrite()
285 static int bch2_trans_update_extent(struct btree_trans *trans, in bch2_trans_update_extent() argument
295 bch2_trans_iter_init(trans, &iter, btree_id, bkey_start_pos(&insert->k), in bch2_trans_update_extent()
307 ret = extent_front_merge(trans, &iter, k, &insert, flags); in bch2_trans_update_extent()
318 ret = bch2_trans_update_extent_overwrite(trans, &iter, flags, k, bkey_i_to_s_c(insert)); in bch2_trans_update_extent()
334 ret = extent_back_merge(trans, &iter, insert, k); in bch2_trans_update_extent()
340 ret = bch2_btree_insert_nonextent(trans, btree_id, insert, flags); in bch2_trans_update_extent()
342 bch2_trans_iter_exit(trans, &iter); in bch2_trans_update_extent()
347 static noinline int flush_new_cached_update(struct btree_trans *trans, in flush_new_cached_update() argument
356 bch2_path_get(trans, i->btree_id, i->old_k.p, 1, 0, in flush_new_cached_update()
358 ret = bch2_btree_path_traverse(trans, path_idx, 0); in flush_new_cached_update()
362 struct btree_path *btree_path = trans->paths + path_idx; in flush_new_cached_update()
377 btree_path_set_should_be_locked(trans, btree_path); in flush_new_cached_update()
378 ret = bch2_trans_update_by_path(trans, path_idx, i->k, flags, ip); in flush_new_cached_update()
380 bch2_path_put(trans, path_idx, true); in flush_new_cached_update()
385 bch2_trans_update_by_path(struct btree_trans *trans, btree_path_idx_t path_idx, in bch2_trans_update_by_path() argument
389 struct bch_fs *c = trans->c; in bch2_trans_update_by_path()
393 struct btree_path *path = trans->paths + path_idx; in bch2_trans_update_by_path()
395 EBUG_ON(trans->nr_updates >= trans->nr_paths); in bch2_trans_update_by_path()
410 trans_for_each_update(trans, i) in bch2_trans_update_by_path()
411 BUG_ON(i != trans->updates && in bch2_trans_update_by_path()
419 for (i = trans->updates; i < trans->updates + trans->nr_updates; i++) { in bch2_trans_update_by_path()
425 bool overwrite = !cmp && i < trans->updates + trans->nr_updates; in bch2_trans_update_by_path()
430 bch2_path_put(trans, i->path, true); in bch2_trans_update_by_path()
437 array_insert_item(trans->updates, trans->nr_updates, in bch2_trans_update_by_path()
438 i - trans->updates, n); in bch2_trans_update_by_path()
443 if (unlikely(trans->journal_replay_not_finished)) { in bch2_trans_update_by_path()
454 __btree_path_get(trans, trans->paths + i->path, true); in bch2_trans_update_by_path()
456 trace_update_by_path(trans, path, i, overwrite); in bch2_trans_update_by_path()
466 return flush_new_cached_update(trans, i, flags, ip); in bch2_trans_update_by_path()
471 static noinline int bch2_trans_update_get_key_cache(struct btree_trans *trans, in bch2_trans_update_get_key_cache() argument
475 struct btree_path *key_cache_path = btree_iter_key_cache_path(trans, iter); in bch2_trans_update_get_key_cache()
485 bch2_path_get(trans, path->btree_id, path->pos, 1, 0, in bch2_trans_update_get_key_cache()
490 bch2_btree_path_set_pos(trans, iter->key_cache_path, path->pos, in bch2_trans_update_get_key_cache()
494 ret = bch2_btree_path_traverse(trans, iter->key_cache_path, BTREE_ITER_cached); in bch2_trans_update_get_key_cache()
498 ck = (void *) trans->paths[iter->key_cache_path].l[0].b; in bch2_trans_update_get_key_cache()
501 trace_and_count(trans->c, trans_restart_key_cache_raced, trans, _RET_IP_); in bch2_trans_update_get_key_cache()
502 return btree_trans_restart(trans, BCH_ERR_transaction_restart_key_cache_raced); in bch2_trans_update_get_key_cache()
505 btree_path_set_should_be_locked(trans, trans->paths + iter->key_cache_path); in bch2_trans_update_get_key_cache()
511 int __must_check bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, in bch2_trans_update() argument
518 return bch2_trans_update_extent(trans, iter, k, flags); in bch2_trans_update()
523 ret = need_whiteout_for_snapshot(trans, iter->btree_id, k->k.p); in bch2_trans_update()
534 struct btree_path *path = trans->paths + path_idx; in bch2_trans_update()
538 btree_id_cached(trans->c, path->btree_id)) { in bch2_trans_update()
539 ret = bch2_trans_update_get_key_cache(trans, iter, path); in bch2_trans_update()
546 return bch2_trans_update_by_path(trans, path_idx, k, flags, _RET_IP_); in bch2_trans_update()
549 int bch2_btree_insert_clone_trans(struct btree_trans *trans, in bch2_btree_insert_clone_trans() argument
553 struct bkey_i *n = bch2_trans_kmalloc(trans, bkey_bytes(&k->k)); in bch2_btree_insert_clone_trans()
559 return bch2_btree_insert_trans(trans, btree, n, 0); in bch2_btree_insert_clone_trans()
562 struct jset_entry *__bch2_trans_jset_entry_alloc(struct btree_trans *trans, unsigned u64s) in __bch2_trans_jset_entry_alloc() argument
564 unsigned new_top = trans->journal_entries_u64s + u64s; in __bch2_trans_jset_entry_alloc()
565 unsigned old_size = trans->journal_entries_size; in __bch2_trans_jset_entry_alloc()
567 if (new_top > trans->journal_entries_size) { in __bch2_trans_jset_entry_alloc()
568 trans->journal_entries_size = roundup_pow_of_two(new_top); in __bch2_trans_jset_entry_alloc()
570 btree_trans_stats(trans)->journal_entries_size = trans->journal_entries_size; in __bch2_trans_jset_entry_alloc()
574 bch2_trans_kmalloc_nomemzero(trans, in __bch2_trans_jset_entry_alloc()
575 trans->journal_entries_size * sizeof(u64)); in __bch2_trans_jset_entry_alloc()
579 if (trans->journal_entries) in __bch2_trans_jset_entry_alloc()
580 memcpy(n, trans->journal_entries, old_size * sizeof(u64)); in __bch2_trans_jset_entry_alloc()
581 trans->journal_entries = n; in __bch2_trans_jset_entry_alloc()
583 struct jset_entry *e = btree_trans_journal_entries_top(trans); in __bch2_trans_jset_entry_alloc()
584 trans->journal_entries_u64s = new_top; in __bch2_trans_jset_entry_alloc()
588 int bch2_bkey_get_empty_slot(struct btree_trans *trans, struct btree_iter *iter, in bch2_bkey_get_empty_slot() argument
594 bch2_trans_iter_init(trans, iter, btree, POS_MAX, BTREE_ITER_intent); in bch2_bkey_get_empty_slot()
615 bch2_trans_iter_exit(trans, iter); in bch2_bkey_get_empty_slot()
619 void bch2_trans_commit_hook(struct btree_trans *trans, in bch2_trans_commit_hook() argument
622 h->next = trans->hooks; in bch2_trans_commit_hook()
623 trans->hooks = h; in bch2_trans_commit_hook()
626 int bch2_btree_insert_nonextent(struct btree_trans *trans, in bch2_btree_insert_nonextent() argument
633 bch2_trans_iter_init(trans, &iter, btree, k->k.p, in bch2_btree_insert_nonextent()
638 bch2_trans_update(trans, &iter, k, flags); in bch2_btree_insert_nonextent()
639 bch2_trans_iter_exit(trans, &iter); in bch2_btree_insert_nonextent()
643 int bch2_btree_insert_trans(struct btree_trans *trans, enum btree_id id, in bch2_btree_insert_trans() argument
647 bch2_trans_iter_init(trans, &iter, id, bkey_start_pos(&k->k), in bch2_btree_insert_trans()
650 bch2_trans_update(trans, &iter, k, flags); in bch2_btree_insert_trans()
651 bch2_trans_iter_exit(trans, &iter); in bch2_btree_insert_trans()
672 bch2_btree_insert_trans(trans, id, k, iter_flags)); in bch2_btree_insert()
675 int bch2_btree_delete_extent_at(struct btree_trans *trans, struct btree_iter *iter, in bch2_btree_delete_extent_at() argument
680 k = bch2_trans_kmalloc(trans, sizeof(*k)); in bch2_btree_delete_extent_at()
687 return bch2_trans_update(trans, iter, k, update_flags); in bch2_btree_delete_extent_at()
690 int bch2_btree_delete_at(struct btree_trans *trans, in bch2_btree_delete_at() argument
693 return bch2_btree_delete_extent_at(trans, iter, 0, update_flags); in bch2_btree_delete_at()
696 int bch2_btree_delete(struct btree_trans *trans, in bch2_btree_delete() argument
703 bch2_trans_iter_init(trans, &iter, btree, pos, in bch2_btree_delete()
707 bch2_btree_delete_at(trans, &iter, update_flags); in bch2_btree_delete()
708 bch2_trans_iter_exit(trans, &iter); in bch2_btree_delete()
713 int bch2_btree_delete_range_trans(struct btree_trans *trans, enum btree_id id, in bch2_btree_delete_range_trans() argument
718 u32 restart_count = trans->restart_count; in bch2_btree_delete_range_trans()
723 bch2_trans_iter_init(trans, &iter, id, start, BTREE_ITER_intent); in bch2_btree_delete_range_trans()
726 bch2_disk_reservation_init(trans->c, 0); in bch2_btree_delete_range_trans()
756 ret = bch2_trans_update(trans, &iter, &delete, update_flags) ?: in bch2_btree_delete_range_trans()
757 bch2_trans_commit(trans, &disk_res, journal_seq, in bch2_btree_delete_range_trans()
759 bch2_disk_reservation_put(trans->c, &disk_res); in bch2_btree_delete_range_trans()
767 bch2_trans_begin(trans); in bch2_btree_delete_range_trans()
774 bch2_trans_iter_exit(trans, &iter); in bch2_btree_delete_range_trans()
776 return ret ?: trans_was_restarted(trans, restart_count); in bch2_btree_delete_range_trans()
790 bch2_btree_delete_range_trans(trans, id, start, end, in bch2_btree_delete_range()
797 int bch2_btree_bit_mod(struct btree_trans *trans, enum btree_id btree, in bch2_btree_bit_mod() argument
800 struct bkey_i *k = bch2_trans_kmalloc(trans, sizeof(*k)); in bch2_btree_bit_mod()
810 bch2_trans_iter_init(trans, &iter, btree, pos, BTREE_ITER_intent); in bch2_btree_bit_mod()
813 bch2_trans_update(trans, &iter, k, 0); in bch2_btree_bit_mod()
814 bch2_trans_iter_exit(trans, &iter); in bch2_btree_bit_mod()
818 int bch2_btree_bit_mod_buffered(struct btree_trans *trans, enum btree_id btree, in bch2_btree_bit_mod_buffered() argument
827 return bch2_trans_update_buffered(trans, btree, &k); in bch2_btree_bit_mod_buffered()
830 static int __bch2_trans_log_msg(struct btree_trans *trans, struct printbuf *buf, unsigned u64s) in __bch2_trans_log_msg() argument
832 struct jset_entry *e = bch2_trans_jset_entry_alloc(trans, jset_u64s(u64s)); in __bch2_trans_log_msg()
870 __bch2_trans_log_msg(trans, &buf, u64s)); in __bch2_fs_log_msg()