On 17/06/18 17:50, Adam Borowski wrote: > Hi! > I see requests for cp --reflink=auto as the default happening a lot on the > mailing list. But, assuming there is a reason to ever want a heavy-weight > copy[1], people might want to disable reflinking. This applies regardless > of what's the default: aliases or wrappers can be used for personal > preferences. > > Thus, if there's alias cp='cp --reflink=auto', there's no obvious way to > skip it. > > Here's a patch that implements --reflink=never, useful to override an > earlier argument. > > > Meow! > > [1]. As a btrfs mailing list regular and occassional kernel/-progs > contributor, I can't even think of any; nocow files are already handled.
We are probably going to change to trying reflink by default in a new major release of coreutils (v9). Though it's a significant behavior change and best done in a major version bump. As for --reflink=never, that will be needed as you say, and useful now in the edge case of people using --reflink=auto in aliases. I will apply this for the upcoming 8.30 release. The attached has added a bit more --help and a test case. cheers, Pádraig
>From f49f4f2403dd3888844c8269a5a5bfd850254418 Mon Sep 17 00:00:00 2001 From: Adam Borowski <[email protected]> Date: Mon, 18 Jun 2018 00:38:04 +0200 Subject: [PATCH] cp: add --reflink=never to force standard copy mode This mode is currently the default, but most if not all users of reflink-capable filesystems want --reflink=auto, which is often encapsulated into an alias. Adding --reflink=never allows overriding such an alias. * doc/coreutils.texi (cp invocation): Describe the new option. * src/cp.c: Support --reflink=never. * tests/cp/reflink-auto.sh: Add a test case. * NEWS: Mention the new feature. --- doc/coreutils.texi | 3 +++ src/cp.c | 7 +++++-- tests/cp/reflink-auto.sh | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/coreutils.texi b/doc/coreutils.texi index c28b8d0..9b7d8e0 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -8740,6 +8740,9 @@ then report the failure for each file and exit with a failure status. @item auto If the copy-on-write operation is not supported then fall back to the standard copy behavior. + +@item never +Disable copy-on-write operation and use the standard copy behavior. @end table This option is overridden by the @option{--link}, @option{--symbolic-link} diff --git a/src/cp.c b/src/cp.c index 04cbd4b..21dd444 100644 --- a/src/cp.c +++ b/src/cp.c @@ -96,11 +96,11 @@ ARGMATCH_VERIFY (sparse_type_string, sparse_type); static char const *const reflink_type_string[] = { - "auto", "always", NULL + "auto", "always", "never", NULL }; static enum Reflink_type const reflink_type[] = { - REFLINK_AUTO, REFLINK_ALWAYS + REFLINK_AUTO, REFLINK_ALWAYS, REFLINK_NEVER }; ARGMATCH_VERIFY (reflink_type_string, reflink_type); @@ -235,10 +235,13 @@ corresponding DEST file is made sparse as well. That is the behavior\n\ selected by --sparse=auto. Specify --sparse=always to create a sparse DEST\n\ file whenever the SOURCE file contains a long enough sequence of zero bytes.\n\ Use --sparse=never to inhibit creation of sparse files.\n\ +"), stdout); + fputs (_("\ \n\ When --reflink[=always] is specified, perform a lightweight copy, where the\n\ data blocks are copied only when modified. If this is not possible the copy\n\ fails, or if --reflink=auto is specified, fall back to a standard copy.\n\ +Use --reflink=never to ensure a standard copy is performed.\n\ "), stdout); emit_backup_suffix_note (); fputs (_("\ diff --git a/tests/cp/reflink-auto.sh b/tests/cp/reflink-auto.sh index 7258a6a..82f41bc 100755 --- a/tests/cp/reflink-auto.sh +++ b/tests/cp/reflink-auto.sh @@ -38,4 +38,8 @@ test -s b || fail=1 cp --reflink=auto --sparse=always "$a_other" b || fail=1 test -s b || fail=1 +# --reflink=auto should be overridden by --reflink=never +cp --reflink=auto --reflink=never "$a_other" b || fail=1 +test -s b || fail=1 + Exit $fail -- 2.9.3
