diff mbox series

[1/2] btrfs-progs: mkfs/rootdir: add the missing xattr for the rootdir inode

Message ID e1291beb0f3aead7d491e879f7348c4ef58f01e4.1696822345.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: make sure "mkfs --rootdir" copies the xattr for the rootdir | expand

Commit Message

Qu Wenruo Oct. 9, 2023, 3:34 a.m. UTC
[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 mbox series

Patch

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;