Thread (9 messages) 9 messages, 5 authors, 2021-06-27

Re: reflink copying does not check/set No_COW attribute and fail

From: Tom Yan <hidden>
Date: 2021-06-04 14:38:48

Also cc'ing bug-coreutils@gnu.org.

On Fri, 4 Jun 2021 at 22:33, Tom Yan [off-list ref] wrote:
Hi all,

I've just bumped into a problem that I am not sure what the expected
behavior should be, but there seems to be something flawed.

Say I have a file that was created with the No_COW attributed
(inherited from the directory / subvolume / mount option). Then if I
try to do a reflink copy, the copying will fail with "Invalid
argument" if the copy has no one to inherit the No_COW attribute from.

For example:
[tom@archlinux mnt]$ sudo btrfs subvol list .
ID 256 gen 11 top level 5 path a
ID 257 gen 9 top level 5 path b
[tom@archlinux mnt]$ lsattr
---------------------- ./a
---------------C------ ./b
[tom@archlinux mnt]$ lsattr b/
---------------C------ b/test
[tom@archlinux mnt]$ du -h b/test
512M    b/test
[tom@archlinux mnt]$ lsattr a/
[tom@archlinux mnt]$ cp --reflink=always b/test a/
cp: failed to clone 'a/test' from 'b/test': Invalid argument
[tom@archlinux mnt]$ lsattr a/
---------------------- a/test
[tom@archlinux mnt]$ du a/test
0    a/test
[tom@archlinux mnt]$ du --apparent-size a/test
0    a/test
[tom@archlinux mnt]$ rm a/test
[tom@archlinux mnt]$ sudo chattr +C a/
[tom@archlinux mnt]$ cp --reflink=always b/test a/
[tom@archlinux mnt]$ lsattr a/
---------------C------ a/test
[tom@archlinux mnt]$ cmp b/test a/test
[tom@archlinux mnt]$

I'm not entirely sure if a reflink copy is supposed to work for a
source file that was created with No_COW, but apparently it is. The
problem is just that the reflink copy also needs to have the attribute
set, yet it cannot inherit from the source automatically.

I wonder if this is a kernel-side problem or something that coreutils
missed? It also seems wrong that when it fails there will be an empty
destination file created.

Kernel version: Linux archlinux 5.12.8-arch1-1 #1 SMP PREEMPT Fri, 28
May 2021 15:10:20 +0000 x86_64 GNU/Linux
Coreutils version: 8.32

Regards,
Tom
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help