From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2] btrfs-progs: mkfs/rootdir: add the missing xattr for the rootdir inode
Date: Mon, 9 Oct 2023 14:04:08 +1030 [thread overview]
Message-ID: <e1291beb0f3aead7d491e879f7348c4ef58f01e4.1696822345.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1696822345.git.wqu@suse.com>
[BUG]
When using "mkfs.btrfs" with "--rootdir" option, the top level inode
(rootdir) will not get the same xattr from the source dir:
mkdir -p source_dir/
touch source_dir/file
setfattr -n user.rootdir_xattr source_dir/
setfattr -n user.regular_xattr source_dir/file
mkfs.btrfs -f --rootdir source_dir $dev
mount $dev $mnt
getfattr $mnt
# Nothing <<<
getfattr $mnt/file
# file: $mnt/file
user.regular_xattr <<<
[CAUSE]
In function traverse_directory(), we only call add_xattr_item() for all
the child inodes, not really for the rootdir inode itself, leading to
the missing xattr items.
[FIX]
Also call add_xattr_item() for the rootdir inode.
Issue: #688
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
mkfs/rootdir.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/mkfs/rootdir.c b/mkfs/rootdir.c
index a413a31eb2d6..f6328c9df2ec 100644
--- a/mkfs/rootdir.c
+++ b/mkfs/rootdir.c
@@ -466,6 +466,14 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
dir_entry->inum = parent_inum;
list_add_tail(&dir_entry->list, &dir_head->list);
+ ret = add_xattr_item(trans, root, btrfs_root_dirid(&root->root_item),
+ dir_name);
+ if (ret < 0) {
+ errno = -ret;
+ error("failed to add xattr item for the top level inode: %m");
+ goto fail_no_dir;
+ }
+
root_dir_key.objectid = btrfs_root_dirid(&root->root_item);
root_dir_key.offset = 0;
root_dir_key.type = BTRFS_INODE_ITEM_KEY;
--
2.42.0
next prev parent reply other threads:[~2023-10-09 3:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-09 3:34 [PATCH 0/2] btrfs-progs: make sure "mkfs --rootdir" copies the xattr for the rootdir Qu Wenruo
2023-10-09 3:34 ` Qu Wenruo [this message]
2023-10-09 3:34 ` [PATCH 2/2] btrfs-progs: tests/mkfs: make sure rootdir got its xattr copied Qu Wenruo
2023-10-09 13:58 ` David Sterba
2023-10-09 20:40 ` Qu Wenruo
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=e1291beb0f3aead7d491e879f7348c4ef58f01e4.1696822345.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).