[Top][All Lists]

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

Re: [RFC][PATCH][cp] btrfs, nocow and cp --reflink

From: Forza
Subject: Re: [RFC][PATCH][cp] btrfs, nocow and cp --reflink
Date: Fri, 27 May 2022 16:59:57 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0

On 2022-05-27 16:00, Pádraig Brady wrote:
On 25/05/2022 18:05, Goffredo Baroncelli wrote:
Hi All,

recently I discovered that BTRFS allow to reflink a file only if the flag FS_NOCOW_FL is the same on both source and destination. In the end of this email I added a patch to "cp" to set the FS_NOCOW_FL flag according to the source.

Even tough this works, I am wondering if this is the expected/the least surprise behavior by/for any user. This is the reason why this email is tagged as RFC.

Without reflink, the default behavior is that the new file has the FS_NOCOW_FL flag set according to the parent directory; with this patch the flag would be the same as the source.

I am not sure that this is the correct behviour without warning the user of this change.

Another possibility, is to flip the NOCOW flag only if --reflink=always is passed.

Thoughts ?

This flag corresponds to the 'C' chattr attribute,
to allow users to explicitly disable CoW on certain files
or files within certain dirs.

I don't think cp should be overriding that explicit config.  I.e.:
   cp --reflink=auto => try reflink but fall back to normal copy
   cp --reflink=always => try reflink and fail if not possible

We would need another option to bypass system config
(like --reflink=force), however I don't think that's
appropriate functionality for cp.


The solution is that 'cp' should set +C on the target file before appending data to it. I don't think that we need any additional mode, but the default should be that '--reflink=auto|always' sets the fsattrs in the correct order on the target file. This is important for other fsattrs as well, such as +i (immutable), +c (compress) and +m (nocompress).

There is thread from two years about about the same issue:

There is also an existing bug report about this issue:


reply via email to

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