diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 0f11f81da1f2..e83a6688ecf1 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -1422,6 +1422,8 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans, btrfs_dir = btrfs_iget_logging(parent_objectid, root); if (IS_ERR(btrfs_dir)) { ret = PTR_ERR(btrfs_dir); + if (ret == -ENOENT) + ret = 0; dir = NULL; goto out; } @@ -1455,6 +1457,15 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans, if (IS_ERR(btrfs_dir)) { ret = PTR_ERR(btrfs_dir); dir = NULL; + /* + * A new parent dir may have not been + * logged and not exist in the subvolume + * tree, see the comment above before + * the loop when getting the first + * parent dir. + */ + if (ret == -ENOENT) + ret = 0; goto out; } dir = &btrfs_dir->vfs_inode; @@ -2623,9 +2634,8 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb, key.type == BTRFS_INODE_EXTREF_KEY) { ret = add_inode_ref(wc->trans, root, log, path, eb, i, &key); - if (ret && ret != -ENOENT) + if (ret) break; - ret = 0; } else if (key.type == BTRFS_EXTENT_DATA_KEY) { ret = replay_one_extent(wc->trans, root, path, eb, i, &key);