coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'cp -a' does not preserve nocow xattrs on btrfs


From: Pádraig Brady
Subject: Re: 'cp -a' does not preserve nocow xattrs on btrfs
Date: Sun, 17 May 2020 12:22:07 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Thunderbird/76.0

On 16/05/2020 21:01, A L wrote:

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  additional
               attributes: context, links, xattr, all


There 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

Seems the same flags interface is used by ext4, btrfs, and xfs at least:
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/misc/chattr.1.in?id=0796e660859724f304155e094b6cf5739a610ae4
Given the generality, it's plausible we might consider preserving these flags.

Copying all xattrs before writing the data may impact the ability to write data,
so we may need to split which xattrs are written when. Though if we
just considered the fattrs it might simplify (though we may have the same issue 
there).

As for the particular NOCOW flag, is that something you'd always want
to set on new files? It seems like it might be more specific to
the file being written, than the file being read?
This would overlap with the existing cp --reflink flag.
Perhaps cp --reflink=never would preserve the NOCOW flag.
Notes:
 one can have NOCOW set on a dir, which causes each file to be NOCOW.
 one can't reflink a NOWCOW file

thanks for the info,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]