[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: BTRFS file clone support for cp
From: |
Giuseppe Scrivano |
Subject: |
Re: BTRFS file clone support for cp |
Date: |
Sun, 26 Jul 2009 11:12:56 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.96 (gnu/linux) |
Jim Meyering <address@hidden> writes:
>>> Adding this optimization should not change the meaning of
>>> --sparse=always.
>>
>> So do you want to use it only when --sparse=auto is used?
>
> Precisely.
I cleaned the patch a bit, the clone operation is done only when
--sparse=auto is used.
Regards,
Giuseppe
>From 747c96980acc25220cc436210403cdcaed6239c9 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <address@hidden>
Date: Sat, 25 Jul 2009 16:35:27 +0200
Subject: [PATCH] cp: support the btrfs file system clone operation.
* src/copy.c(copy_reg): Use the btrfs clone operation if it is possible.
---
src/copy.c | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/src/copy.c b/src/copy.c
index 4c8c432..e0ddec5 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -61,6 +61,11 @@
# include "verror.h"
#endif
+#ifdef __linux__
+# include <sys/ioctl.h>
+# define BTRFS_IOC_CLONE 1074041865
+#endif
+
#ifndef HAVE_FCHOWN
# define HAVE_FCHOWN false
# define fchown(fd, uid, gid) (-1)
@@ -444,6 +449,7 @@ copy_reg (char const *src_name, char const *dst_name,
struct stat sb;
struct stat src_open_sb;
bool return_val = true;
+ bool copied = false;
source_desc = open (src_name,
(O_RDONLY | O_BINARY
@@ -589,6 +595,15 @@ copy_reg (char const *src_name, char const *dst_name,
goto close_src_and_dst_desc;
}
+#ifdef __linux__
+ /* Try a btrfs clone operation. If the operation is not supported
+ or it fails then copy the file in the usual way. */
+ if ((x->sparse_mode == SPARSE_AUTO) && !ioctl (dest_desc, BTRFS_IOC_CLONE,
+ source_desc))
+ copied = true;
+#endif
+
+ if (!copied)
{
typedef uintptr_t word;
off_t n_read_total = 0;
--
1.6.3.3
- BTRFS file clone support for cp, Giuseppe Scrivano, 2009/07/25
- Re: BTRFS file clone support for cp, Jim Meyering, 2009/07/25
- Re: BTRFS file clone support for cp, Giuseppe Scrivano, 2009/07/25
- Re: BTRFS file clone support for cp, Jim Meyering, 2009/07/25
- Re: BTRFS file clone support for cp, Giuseppe Scrivano, 2009/07/25
- Re: BTRFS file clone support for cp, Jim Meyering, 2009/07/26
- Re: BTRFS file clone support for cp, Giuseppe Scrivano, 2009/07/26
- Re: BTRFS file clone support for cp, Jim Meyering, 2009/07/26
- Re: BTRFS file clone support for cp,
Giuseppe Scrivano <=
- Re: BTRFS file clone support for cp, Jim Meyering, 2009/07/27
- Re: BTRFS file clone support for cp, Andreas Schwab, 2009/07/27
- Re: BTRFS file clone support for cp, Jim Meyering, 2009/07/28
- Re: BTRFS file clone support for cp, Jim Meyering, 2009/07/29
- Re: BTRFS file clone support for cp, Jim Meyering, 2009/07/29
Re: BTRFS file clone support for cp, Pádraig Brady, 2009/07/26