|
From: | A L |
Subject: | Re: 'cp -a' does not preserve nocow xattrs on btrfs |
Date: | Sat, 16 May 2020 22:01:30 +0200 |
User-agent: | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 |
On 2020-05-16 13:31, A L wrote:
Hi, Normally, 'cp -a' should preserve xattrs when copying files and folders. From the man page(*): -a, --archive same as -dR --preserve=all --preserve[=ATTR_LIST]preserve the specified attributes (default: mode,ownership,timestamps), if possible additionalattributes: context, links, xattr, allThere are two important xattrs(*) on the Btrfs filesystem; 'no copy-on-writes' ('+C') and 'compression' (+c). They have specific conditions to work.The nocow '+C' attribute can only be set on empty files.The compression '+c' can be set on any file, but only newly written data will be compressed.The problem is that 'cp -a' seems to set the xattrs after creating the file and writing the data to it, which means that the nocow '+C' flags can't be set and that files would not be fully compressed, even though the flag is set.I think that these xattrs should be preserved when doing 'cp -a'. * http://man7.org/linux/man-pages/man1/cp.1.html * http://man7.org/linux/man-pages/man1/chattr.1.html
I realise I had confused the difference between fattr (aka ext2 attributes) and xattrs (extended attributes). In Btrfs, the nocow '+C' is only available as fattr, and not a xattr, which is why it is not copied with cp. Apart from that, the issue still stands with compression flag '+c', since that is also implemented as an xattr ("btrfs.compression") . cp ought to set the xattrs before writing any data to the file, possibly with an fsync in between.
Side note: Why is it that cp -a does not copy file attrs and only xattrs? As a end user, the naming similarity fattr and xattr is somewhat confusing, and the man page does not clearly state that only the latter is supported in cp. http://man7.org/linux/man-pages/man1/cp.1.html
Thank you
[Prev in Thread] | Current Thread | [Next in Thread] |