linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 2/2] btrfs-progs: tests/mkfs: make sure rootdir inode got its attributes copied
Date: Wed, 11 Oct 2023 10:19:44 +1030	[thread overview]
Message-ID: <31ef017d9cc45ffe7b8c942b4e29a7dc56fc72e8.1696981203.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1696981203.git.wqu@suse.com>

The new test case would:

- Prepare two loopback devices
  One is for storing the source directory (on a btrfs).
  This is to ensure we can set xattr for the directory, as filesystems
  like tmpfs (mostly utilized by mktemp) is not supporting xattr.

  The other one is the real target fs where we call "mkfs.btrfs
  --rootdir" on.

- Create the source directory with the following contents:
  * rootdir inode attributs:
    # mode (750)
    # uid (1000)
    # gid (1000)
    # xattr (user.rootdir)
  * one regular file, with attributes:
    # xattr (user.foorbar)

- Execute "mkfs.btrfs --rootdir" and mount the new fs

- Verify the above attributes
  The target fs should have the same attributes, especially for the
  rootdir inode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tests/mkfs-tests/027-rootdir-inode/test.sh | 60 ++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100755 tests/mkfs-tests/027-rootdir-inode/test.sh

diff --git a/tests/mkfs-tests/027-rootdir-inode/test.sh b/tests/mkfs-tests/027-rootdir-inode/test.sh
new file mode 100755
index 000000000000..e5de1485cc87
--- /dev/null
+++ b/tests/mkfs-tests/027-rootdir-inode/test.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+# Test if "mkfs.btrfs --rootdir" would properly copy all the attributes of the
+# source directory.
+
+source "$TEST_TOP/common" || exit
+
+setup_root_helper
+# Here we need two devices, one as a temporaray btrfs, storing the source
+# directory. As we want to setup xattr, which is not supported by tmpfs
+# (most modern distros go tmpfs for /tmp).
+# So we have to put the source directory on a fs that supports xattr.
+#
+# Then the second fs is the real one we mkfs on.
+setup_loopdevs 2
+prepare_loopdevs
+
+tmp_dev=${loopdevs[1]}
+real_dev=${loopdevs[2]}
+
+check_global_prereq setfattr
+check_global_prereq getfattr
+
+# Here we don't want to use /tmp, as it's pretty common /tmp is tmpfs, which
+# doesn't support xattr.
+# Instead we go $TEST_TOP/btrfs-progs-mkfs-tests-027.XXXXXX/ instead.
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$tmp_dev"
+run_check $SUDO_HELPER mount -t btrfs "$tmp_dev" "$TEST_MNT"
+
+run_check $SUDO_HELPER mkdir "$TEST_MNT/source_dir/"
+run_check $SUDO_HELPER chmod 750 "$TEST_MNT/source_dir/"
+run_check $SUDO_HELPER chown 1000:1000 "$TEST_MNT/source_dir/"
+run_check $SUDO_HELPER setfattr -n user.rootdir "$TEST_MNT/source_dir/"
+
+old_mode=$(run_check_stdout $SUDO_HELPER stat "$TEST_MNT/source_dir/" | grep "Uid:")
+run_check $SUDO_HELPER touch "$TEST_MNT/source_dir/foobar"
+run_check $SUDO_HELPER setfattr -n user.foobar "$TEST_MNT/source_dir/foobar"
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" --rootdir "$TEST_MNT/source_dir" -f "$real_dev"
+run_check $SUDO_HELPER umount "$TEST_MNT"
+
+run_check $SUDO_HELPER mount -t btrfs "$real_dev" "$TEST_MNT"
+
+new_mode=$(run_check_stdout $SUDO_HELPER stat "$TEST_MNT/" | grep "Uid:")
+new_rootdir_attr=$(run_check_stdout $SUDO_HELPER getfattr -n user.rootdir --absolute-names "$src_dir")
+new_foobar_attr=$(run_check_stdout getfattr -n user.foobar --absolute-names "$src_dir/foobar")
+
+run_check_umount_test_dev "$TEST_MNT"
+cleanup_loopdevs
+
+if ! echo "$new_rootdir_attr" | grep -q "user.rootdir" ; then
+	_fail "no rootdir xattr found"
+fi
+
+if ! echo "$new_foobar_attr"| grep -q "user.foobar" ; then
+	_fail "no regular file xattr found"
+fi
+
+if [ "$new_mode" != "$old_mode" ]; then
+	_fail "mode/uid/gid mismatch"
+fi
-- 
2.42.0


      parent reply	other threads:[~2023-10-10 23:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10 23:49 [PATCH v2 0/2] btrfs-progs: make sure "mkfs --rootdir" copies all the attributes for the rootdir Qu Wenruo
2023-10-10 23:49 ` [PATCH v2 1/2] btrfs-progs: mkfs/rootdir: copy missing attributes for the rootdir inode Qu Wenruo
2023-10-10 23:49 ` Qu Wenruo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=31ef017d9cc45ffe7b8c942b4e29a7dc56fc72e8.1696981203.git.wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).