- old_dst = mode == BCH_RENAME
- ? bch2_hash_hole_at(bch2_dirent_hash_desc, &dst_iter)
- : bch2_hash_lookup_at(bch2_dirent_hash_desc,
- &dst_dir->ei_str_hash,
- &dst_iter, dst_name);
- if ((ret = btree_iter_err(old_dst)))
- goto err;
-
- switch (mode) {
- case BCH_RENAME:
- bkey_init(&new_src->k);
- dirent_copy_target(new_dst, bkey_s_c_to_dirent(old_src));
+ dst_iter = mode == BCH_RENAME
+ ? bch2_hash_hole(trans, bch2_dirent_hash_desc,
+ dst_hash, dst_dir, dst_name)
+ : bch2_hash_lookup(trans, bch2_dirent_hash_desc,
+ dst_hash, dst_dir, dst_name,
+ BTREE_ITER_INTENT);
+ ret = PTR_ERR_OR_ZERO(dst_iter);
+ if (ret)
+ goto out;
+
+ old_dst = bch2_btree_iter_peek_slot(dst_iter);
+
+ if (mode != BCH_RENAME)
+ *dst_inum = le64_to_cpu(bkey_s_c_to_dirent(old_dst).v->d_inum);
+
+ /* Lookup src: */
+ src_iter = bch2_hash_lookup(trans, bch2_dirent_hash_desc,
+ src_hash, src_dir, src_name,
+ BTREE_ITER_INTENT);
+ ret = PTR_ERR_OR_ZERO(src_iter);
+ if (ret)
+ goto out;
+
+ old_src = bch2_btree_iter_peek_slot(src_iter);
+ *src_inum = le64_to_cpu(bkey_s_c_to_dirent(old_src).v->d_inum);
+
+ /* Create new dst key: */
+ new_dst = dirent_create_key(trans, 0, dst_name, 0);
+ ret = PTR_ERR_OR_ZERO(new_dst);
+ if (ret)
+ goto out;
+
+ dirent_copy_target(new_dst, bkey_s_c_to_dirent(old_src));
+ new_dst->k.p = dst_iter->pos;
+
+ /* Create new src key: */
+ if (mode == BCH_RENAME_EXCHANGE) {
+ new_src = dirent_create_key(trans, 0, src_name, 0);
+ ret = PTR_ERR_OR_ZERO(new_src);
+ if (ret)
+ goto out;