coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] mv: add --reflink to affect fallback copy


From: David Sterba
Subject: [PATCH] mv: add --reflink to affect fallback copy
Date: Tue, 22 Jul 2014 18:50:53 +0200

On some filesystems (btrfs), moving a file within the filesystem may
cross subvolume boundaries and we can use the lightweight reflink copy,
similar to what cp(1) does. This is typically faster than full file
copy. Default mode is unchanged.

* src/mv.c (main): Add case for REFLINK_OPTION.
---
 src/mv.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/mv.c b/src/mv.c
index 1db404ffb603..8b9b573befc5 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -46,9 +46,21 @@
    non-character as a pseudo short option, starting with CHAR_MAX + 1.  */
 enum
 {
-  STRIP_TRAILING_SLASHES_OPTION = CHAR_MAX + 1
+  STRIP_TRAILING_SLASHES_OPTION = CHAR_MAX + 1,
+  REFLINK_OPTION
 };
 
+/* Copied from cp.c */
+static char const *const reflink_type_string[] =
+{
+  "auto", "always", NULL
+};
+static enum Reflink_type const reflink_type[] =
+{
+  REFLINK_AUTO, REFLINK_ALWAYS
+};
+ARGMATCH_VERIFY (reflink_type_string, reflink_type);
+
 /* Remove any trailing slashes from each SOURCE argument.  */
 static bool remove_trailing_slashes;
 
@@ -60,6 +72,7 @@ static struct option const long_options[] =
   {"interactive", no_argument, NULL, 'i'},
   {"no-clobber", no_argument, NULL, 'n'},
   {"no-target-directory", no_argument, NULL, 'T'},
+  {"reflink", optional_argument, NULL, REFLINK_OPTION},
   {"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
   {"suffix", required_argument, NULL, 'S'},
   {"target-directory", required_argument, NULL, 't'},
@@ -309,6 +322,7 @@ If you specify more than one of -i, -f, -n, only the final 
one takes effect.\n\
       fputs (_("\
       --strip-trailing-slashes  remove any trailing slashes from each SOURCE\n\
                                  argument\n\
+  --reflink[=WHEN]             control clone/COW behaviour. See below\n\
   -S, --suffix=SUFFIX          override the usual backup suffix\n\
 "), stdout);
       fputs (_("\
@@ -329,6 +343,15 @@ The backup suffix is '~', unless set with --suffix or 
SIMPLE_BACKUP_SUFFIX.\n\
 The version control method may be selected via the --backup option or 
through\n\
 the VERSION_CONTROL environment variable.  Here are the values:\n\
 \n\
+On some filesystems (btrfs), moving a file within the filesystem may cross\n\
+subvolume boundaries. This will prevent a simple rename and would fall back\n\
+to a full file copy. However, this is not strictly necessary, because the\n\
+lightweight \"reflink\" copy can be used instead. This is typically faster\n\
+as it does not touch the data blocks. Use --reflink=always to perform the\n\
+lightweight copy and fail if it's not possible. Otherwise a fallback to\n\
+standard copy can be selected by --reflink=auto. Default is to use standard\n\
+copy.\n\
+\n\
 "), stdout);
       fputs (_("\
   none, off       never make backups (even if --backup is given)\n\
@@ -392,6 +415,13 @@ main (int argc, char **argv)
         case 'n':
           x.interactive = I_ALWAYS_NO;
           break;
+       case REFLINK_OPTION::
+          if (optarg == NULL)
+            x.reflink_mode = REFLINK_ALWAYS;
+          else
+            x.reflink_mode = XARGMATCH ("--reflink", optarg,
+                                       reflink_type_string, reflink_type);
+         break;
         case STRIP_TRAILING_SLASHES_OPTION:
           remove_trailing_slashes = true;
           break;
-- 
1.9.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]