if (BTRFS_I(dir)->index_cnt == (u64)-1) {
                ret = btrfs_set_inode_index_count(dir);
-               if (ret)
+               if (ret) {
                        return ret;
+               }
        }
 
        *index = BTRFS_I(dir)->index_cnt;
 
                inode->i_nlink = nlink;
                btrfs_update_inode(trans, root, inode);
        }
+       BTRFS_I(inode)->index_cnt = (u64)-1;
 
        return 0;
 }
        struct btrfs_key tmp_key;
        struct btrfs_root *log;
        struct btrfs_fs_info *fs_info = log_root_tree->fs_info;
+       u64 highest_inode;
        struct walk_control wc = {
                .process_func = process_one_buffer,
                .stage = 0,
                                                      path);
                        BUG_ON(ret);
                }
+               ret = btrfs_find_highest_inode(wc.replay_dest, &highest_inode);
+               if (ret == 0) {
+                       wc.replay_dest->highest_inode = highest_inode;
+                       wc.replay_dest->last_inode_alloc = highest_inode;
+               }
 
                key.offset = found_key.offset - 1;
                free_extent_buffer(log->node);