Reflink 引用链接
Reflink is a type of shallow copy of file data that shares the blocks but
otherwise the files are independent and any change to the file will not affect
the other. This builds on the underlying COW mechanism. A reflink will
effectively create only a separate metadata pointing to the shared blocks which
is typically much faster than a deep copy of all blocks.
引用链接是文件数据的一种浅拷贝类型,共享块,但文件本身是独立的,对文件的任何更改都不会影响其他文件。这是基于底层的 COW 机制。引用链接实际上只会创建一个指向共享块的单独元数据,通常比深度复制所有块要快得多。
The reflink is typically meant for whole files but a partial file range can be
also copied, though there are no ready-made tools for that.
reflink 通常用于整个文件,但也可以复制部分文件范围,尽管目前没有现成的工具。
cp --reflink=always source target
There are some constraints:
有一些限制:
cross-filesystem reflink is not possible, there’s nothing in common between so the block sharing can’t work
跨文件系统的 reflink 是不可能的,因为它们之间没有共同之处,所以块共享无法工作。reflink crossing two mount points of the same filesystem support depends on kernel version:
跨越同一文件系统的两个挂载点的 reflink 支持取决于内核版本:until 5.17 it’s not supported and fails with “Cross device link”, can be worked around by performing the operation on the toplevel subvolume
在 5.17 版本之前不支持,并且会出现“跨设备链接”错误,可以通过在顶级子卷上执行操作来解决works since 5.18 从 5.18 版本开始支持
reflink requires source and target file that have the same status regarding NOCOW and checksums, for example if the source file is NOCOW (once created with the chattr +C attribute) then the above command won’t work unless the target file is pre-created with the +C attribute as well, or the NOCOW attribute is inherited from the parent directory (chattr +C on the directory) or if the whole filesystem is mounted with -o nodatacow that would create the NOCOW files by default
reflink 需要源文件和目标文件在 NOCOW 和校验和方面具有相同的状态,例如,如果源文件是 NOCOW(使用 chattr +C 属性创建的),那么上述命令将不起作用,除非目标文件也预先使用 +C 属性创建,或者从父目录继承 NOCOW 属性(在目录上使用 chattr +C),或者整个文件系统被挂载为 -o nodatacow,这将默认创建 NOCOW 文件