Kamil Dudka 5d08d1
From 76126e2831580d0df20530f4d6f72189bd4f0b9a Mon Sep 17 00:00:00 2001
Kamil Dudka 5d08d1
From: Paul Eggert <eggert@cs.ucla.edu>
Kamil Dudka 5d08d1
Date: Thu, 18 Jun 2020 22:16:24 -0700
Kamil Dudka 5d08d1
Subject: [PATCH] cp: default to COW
Kamil Dudka 5d08d1
MIME-Version: 1.0
Kamil Dudka 5d08d1
Content-Type: text/plain; charset=UTF-8
Kamil Dudka 5d08d1
Content-Transfer-Encoding: 8bit
Kamil Dudka 5d08d1
Kamil Dudka 5d08d1
Likewise for ‘install’.  Proposed in Bug#24400, and long past due.
Kamil Dudka 5d08d1
* NEWS:
Kamil Dudka 5d08d1
* doc/coreutils.texi (cp invocation):
Kamil Dudka 5d08d1
* src/copy.h (enum Reflink_type): Document this.
Kamil Dudka 5d08d1
* src/cp.c (cp_option_init):
Kamil Dudka 5d08d1
* src/install.c (cp_option_init): Implement this.
Kamil Dudka 5d08d1
Kamil Dudka 5d08d1
Upstream-commit: 25725f9d41735d176d73a757430739fb71c7d043
Kamil Dudka 5d08d1
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
Kamil Dudka 5d08d1
---
Kamil Dudka 5d08d1
 doc/coreutils.texi | 19 ++++++++++++-------
Kamil Dudka 5d08d1
 src/copy.h         |  4 ++--
Kamil Dudka 5d08d1
 src/cp.c           |  2 +-
Kamil Dudka 5d08d1
 src/install.c      |  2 +-
Kamil Dudka 5d08d1
 4 files changed, 16 insertions(+), 11 deletions(-)
Kamil Dudka 5d08d1
Kamil Dudka 5d08d1
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
Kamil Dudka 5d08d1
index 02e0c1c..2382a16 100644
Kamil Dudka 5d08d1
--- a/doc/coreutils.texi
Kamil Dudka 5d08d1
+++ b/doc/coreutils.texi
Kamil Dudka 5d08d1
@@ -8854,12 +8854,14 @@ The @var{when} value can be one of the following:
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
 @table @samp
Kamil Dudka 5d08d1
 @item always
Kamil Dudka 5d08d1
-The default behavior: if the copy-on-write operation is not supported
Kamil Dudka 5d08d1
+If the copy-on-write operation is not supported
Kamil Dudka 5d08d1
 then report the failure for each file and exit with a failure status.
Kamil Dudka 5d08d1
+Plain @option{--reflink} is equivalent to @option{--reflink=when}.
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
 @item auto
Kamil Dudka 5d08d1
 If the copy-on-write operation is not supported then fall back
Kamil Dudka 5d08d1
 to the standard copy behavior.
Kamil Dudka 5d08d1
+This is the default if no @option{--reflink} option is given.
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
 @item never
Kamil Dudka 5d08d1
 Disable copy-on-write operation and use the standard copy behavior.
Kamil Dudka 5d08d1
@@ -8868,12 +8870,6 @@ Disable copy-on-write operation and use the standard copy behavior.
Kamil Dudka 5d08d1
 This option is overridden by the @option{--link}, @option{--symbolic-link}
Kamil Dudka 5d08d1
 and @option{--attributes-only} options, thus allowing it to be used
Kamil Dudka 5d08d1
 to configure the default data copying behavior for @command{cp}.
Kamil Dudka 5d08d1
-For example, with the following alias, @command{cp} will use the
Kamil Dudka 5d08d1
-minimum amount of space supported by the file system.
Kamil Dudka 5d08d1
-
Kamil Dudka 5d08d1
-@example
Kamil Dudka 5d08d1
-alias cp='cp --reflink=auto --sparse=always'
Kamil Dudka 5d08d1
-@end example
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
 @item --remove-destination
Kamil Dudka 5d08d1
 @opindex --remove-destination
Kamil Dudka 5d08d1
@@ -8918,6 +8914,15 @@ This is useful in creating a file for use with the @command{mkswap} command,
Kamil Dudka 5d08d1
 since such a file must not have any holes.
Kamil Dudka 5d08d1
 @end table
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
+For example, with the following alias, @command{cp} will use the
Kamil Dudka 5d08d1
+minimum amount of space supported by the file system.
Kamil Dudka 5d08d1
+(Older versions of @command{cp} can also benefit from
Kamil Dudka 5d08d1
+@option{--reflink=auto} here.)
Kamil Dudka 5d08d1
+
Kamil Dudka 5d08d1
+@example
Kamil Dudka 5d08d1
+alias cp='cp --sparse=always'
Kamil Dudka 5d08d1
+@end example
Kamil Dudka 5d08d1
+
Kamil Dudka 5d08d1
 @optStripTrailingSlashes
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
 @item -s
Kamil Dudka 5d08d1
diff --git a/src/copy.h b/src/copy.h
Kamil Dudka 5d08d1
index 874d6f7..a0ad494 100644
Kamil Dudka 5d08d1
--- a/src/copy.h
Kamil Dudka 5d08d1
+++ b/src/copy.h
Kamil Dudka 5d08d1
@@ -46,10 +46,10 @@ enum Sparse_type
Kamil Dudka 5d08d1
 /* Control creation of COW files.  */
Kamil Dudka 5d08d1
 enum Reflink_type
Kamil Dudka 5d08d1
 {
Kamil Dudka 5d08d1
-  /* Default to a standard copy.  */
Kamil Dudka 5d08d1
+  /* Do a standard copy.  */
Kamil Dudka 5d08d1
   REFLINK_NEVER,
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
-  /* Try a COW copy and fall back to a standard copy.  */
Kamil Dudka 5d08d1
+  /* Try a COW copy and fall back to a standard copy; this is the default.  */
Kamil Dudka 5d08d1
   REFLINK_AUTO,
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
   /* Require a COW copy and fail if not available.  */
Kamil Dudka 5d08d1
diff --git a/src/cp.c b/src/cp.c
Kamil Dudka 5d08d1
index 0193df8..9e7ad14 100644
Kamil Dudka 5d08d1
--- a/src/cp.c
Kamil Dudka 5d08d1
+++ b/src/cp.c
Kamil Dudka 5d08d1
@@ -796,7 +796,7 @@ cp_option_init (struct cp_options *x)
Kamil Dudka 5d08d1
   x->move_mode = false;
Kamil Dudka 5d08d1
   x->install_mode = false;
Kamil Dudka 5d08d1
   x->one_file_system = false;
Kamil Dudka 5d08d1
-  x->reflink_mode = REFLINK_NEVER;
Kamil Dudka 5d08d1
+  x->reflink_mode = REFLINK_AUTO;
Kamil Dudka 5d08d1
 
Kamil Dudka 5d08d1
   x->preserve_ownership = false;
Kamil Dudka 5d08d1
   x->preserve_links = false;
Kamil Dudka 5d08d1
diff --git a/src/install.c b/src/install.c
Kamil Dudka 5d08d1
index 4ab44a6..aef16ca 100644
Kamil Dudka 5d08d1
--- a/src/install.c
Kamil Dudka 5d08d1
+++ b/src/install.c
Kamil Dudka 5d08d1
@@ -264,7 +264,7 @@ cp_option_init (struct cp_options *x)
Kamil Dudka 5d08d1
 {
Kamil Dudka 5d08d1
   cp_options_default (x);
Kamil Dudka 5d08d1
   x->copy_as_regular = true;
Kamil Dudka 5d08d1
-  x->reflink_mode = REFLINK_NEVER;
Kamil Dudka 5d08d1
+  x->reflink_mode = REFLINK_AUTO;
Kamil Dudka 5d08d1
   x->dereference = DEREF_ALWAYS;
Kamil Dudka 5d08d1
   x->unlink_dest_before_opening = true;
Kamil Dudka 5d08d1
   x->unlink_dest_after_failed_open = false;
Kamil Dudka 5d08d1
-- 
Kamil Dudka 5d08d1
2.25.4
Kamil Dudka 5d08d1