coreutils
[Top][All Lists]
Advanced

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

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


From: Pádraig Brady
Subject: Re: [PATCH] mv: add --reflink to affect fallback copy
Date: Tue, 02 Sep 2014 17:20:36 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 07/22/2014 05:50 PM, David Sterba wrote:
> 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;
> 

cp doesn't default to --reflink=auto as that would break the case where one 
uses copy
for durability reasons to have a second copy of the data.  Also for performance 
reasons
you may want the writes to happen at copy time rather than some latency 
sensitive process
working on a CoW file and being delayed by the writes possibly to a different 
part of a mechanical disk.

This is not the case with mv though, so we might just --reflink=auto by default?
I.E. not have an option. This would preclude allowing to avoid a standard copy,
but I'm not sure that's generally required.

BTW should BTRFS handle the rename() transparently here?
I.E. it could do the reflinking implicitly, if mv could do it?

thanks,
Pádraig.



reply via email to

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