mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-18 09:46:33 +02:00
cp: with --sparse=never, avoid COW and copy offload
* src/cp.c (main): Set default reflink mode appropriately with --sparse=never. * src/copy.c (infer_scantype): Add a comment to related code. * tests/cp/sparse-2.sh: Add a test case. * NEWS: Mention the bug.
This commit is contained in:
4
NEWS
4
NEWS
@@ -16,6 +16,10 @@ GNU coreutils NEWS -*- outline -*-
|
||||
Previously it would have failed with a "No such file or directory" error.
|
||||
[bug introduced in coreutils-9.1]
|
||||
|
||||
'cp --sparse=never' will avoid copy-on-write (reflinking) and copy offloading,
|
||||
to ensure no holes present in the destination copy.
|
||||
[bug introduced in coreutils-9.0]
|
||||
|
||||
cksum again diagnoses read errors in its default CRC32 mode.
|
||||
[bug introduced in coreutils-9.0]
|
||||
|
||||
|
||||
@@ -1139,6 +1139,8 @@ infer_scantype (int fd, struct stat const *sb,
|
||||
{
|
||||
scan_inference->ext_start = -1; /* avoid -Wmaybe-uninitialized */
|
||||
|
||||
/* Only attempt SEEK_HOLE if this heuristic
|
||||
suggests the file is sparse. */
|
||||
if (! (HAVE_STRUCT_STAT_ST_BLOCKS
|
||||
&& S_ISREG (sb->st_mode)
|
||||
&& ST_NBLOCKS (*sb) < sb->st_size / ST_NBLOCKSIZE))
|
||||
|
||||
7
src/cp.c
7
src/cp.c
@@ -1201,6 +1201,13 @@ main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* With --sparse=never, disable reflinking so we create a non sparse copy.
|
||||
This will also have the effect of disabling copy offload as that may
|
||||
propagate holes. For e.g. FreeBSD documents that copy_file_range()
|
||||
will try to propagate holes. */
|
||||
if (x.reflink_mode == REFLINK_AUTO && x.sparse_mode == SPARSE_NEVER)
|
||||
x.reflink_mode = REFLINK_NEVER;
|
||||
|
||||
if (x.hard_link && x.symbolic_link)
|
||||
{
|
||||
error (0, 0, _("cannot make both hard and symbolic links"));
|
||||
|
||||
@@ -48,4 +48,9 @@ cp --debug --reflink=never --sparse=always k k2 >cp.out || fail=1
|
||||
cmp k k2 || fail=1
|
||||
grep 'sparse detection: .*zeros' cp.out || { cat cp.out; fail=1; }
|
||||
|
||||
# cp should disable reflink AND copy offload with --sparse=never
|
||||
cp --debug --sparse=never k k2 >cp.out || fail=1
|
||||
cmp k k2 || fail=1
|
||||
grep 'copy offload: avoided, reflink: no' cp.out || { cat cp.out; fail=1; }
|
||||
|
||||
Exit $fail
|
||||
|
||||
Reference in New Issue
Block a user