diff --git a/convert/source-reiserfs.c b/convert/source-reiserfs.c index 0181733e..bb9f4eee 100644 --- a/convert/source-reiserfs.c +++ b/convert/source-reiserfs.c @@ -634,8 +634,9 @@ static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root, goto fail; } - ret = btrfs_insert_inode_ref(trans, root, "..", 2, parent, - objectid, 0); + if (parent == objectid) + ret = btrfs_insert_inode_ref(trans, root, "..", 2, parent, + objectid, 0); break; case S_IFLNK: trans = btrfs_start_transaction(root, 1); diff --git a/tests/convert-tests/022-reiserfs-parent-ref/test.sh b/tests/convert-tests/022-reiserfs-parent-ref/test.sh new file mode 100755 index 00000000..66aaff7b --- /dev/null +++ b/tests/convert-tests/022-reiserfs-parent-ref/test.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# Test that only toplevel directory self-reference is created + +source "$TEST_TOP/common" + +setup_root_helper +prepare_test_dev +check_global_prereq mkreiserfs +check_prereq btrfs-convert + +run_check $SUDO_HELPER mkreiserfs -q -f -b 4096 "$TEST_DEV" +run_check_mount_test_dev -t reiserfs +run_check $SUDO_HELPER mkdir "$TEST_MNT/a" +run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_MNT/a/x" bs=1M count=64 +run_check $SUDO_HELPER mkdir "$TEST_MNT/a/y" +run_check_umount_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs-convert" "$TEST_DEV" +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"