From 02b06b3e8d3207a3505b7b9724b7bbce7b2359b4 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 30 May 2022 22:21:40 +0200 Subject: [PATCH] btrfs-progs: convert: fix self-reference of directory Creating a simple directory structure leads to the following error: $ btrfs check Checking filesystem on test.img UUID: 8f2292ad-c80e-4ab4-8a72-29aa3a83002c [1/7] checking root items [2/7] checking extents [3/7] checking free space cache [4/7] checking fs roots unresolved ref dir 260 index 0 namelen 2 name .. filetype 0 errors 3, no dir item, no dir index ERROR: errors found in fs roots found 101085184 bytes used, error(s) found total csum bytes: 98460 total tree bytes: 262144 total fs tree bytes: 49152 total extent tree bytes: 16384 btree space waste bytes: 151864 file data blocks allocated: 167931904 referenced 167931904 The self-reference should exist for the toplevel directory, where the parent directory points to itself. Issue: #453 Author: tyan0 Signed-off-by: David Sterba --- convert/source-reiserfs.c | 5 +++-- .../022-reiserfs-parent-ref/test.sh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 tests/convert-tests/022-reiserfs-parent-ref/test.sh 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"