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: mail
Subject: Re: 'cp -a' does not preserve nocow xattrs on btrfs
Date: Sun, 17 May 2020 18:48:06 +0000
User-agent: Horde Application Framework 5

"Pádraig Brady" address@hidden – 17 maj 2020 kl. 13:22
> 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'.
> >>
> >>
> >>
> >> * man7.org/linux/man-pages/man1/cp.1.html
> >> * 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. man7.org/linux/man-pages/man1/cp.1.html
>
> Seems the same flags interface is used by ext4, btrfs, and xfs at least:
> git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/misc/chattr.1.in
> 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
>
>

Perhaps it is best to limit my request to fattrs for the moment. I don't know 
how well defined the xattrs are in general.


Looking at the list of available fattrs, I think only the immutable attribute 
can't be set first. There are some attributes that may never be set with 
chattr. Not sure how to handle those.


How should cp react when the target fs does not support one or more attributes?


Regarding nocow. I think all fattrs should only be preserved with -a or 
--preserve=fattr (or all).if you also specify reflink=always/auto then perhaps 
the -a flag should have priority?


Thanks



reply via email to

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