summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-01-22 13:09:08 +0100
committerJim Meyering <meyering@redhat.com>2011-01-28 23:28:38 +0100
commit700bcaf54e24b937dd094443081d49507164af6d (patch)
treeb3fa32aea7d7872c104cc157eaec51ce26ba4b84
parent395011ce8fb668b3eb0a2b63fdafc6cbd4aa3720 (diff)
downloadcoreutils-700bcaf54e24b937dd094443081d49507164af6d.tar.gz
copy: don't allocate a separate buffer just for extent-based copy
* src/copy.c (copy_reg): Move use of extent_scan to just *after* we allocate the main copying buffer, so we can... (extent_scan): Take a new parameter, BUF, and use that rather than allocating a private buffer. Update caller.
-rw-r--r--src/copy.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/copy.c b/src/copy.c
index fae8dbe0e..c9cc2f737 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -194,7 +194,7 @@ write_zeros (int fd, uint64_t n_bytes)
Upon any other failure, set *NORMAL_COPY_REQUIRED to false and
return false. */
static bool
-extent_copy (int src_fd, int dest_fd, size_t buf_size,
+extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
off_t src_total_size, bool make_holes,
char const *src_name, char const *dst_name,
bool *require_normal_copy)
@@ -268,8 +268,6 @@ extent_copy (int src_fd, int dest_fd, size_t buf_size,
while (ext_len)
{
- char buf[buf_size];
-
/* Avoid reading into the holes if the left extent
length is shorter than the buffer size. */
buf_size = MIN (ext_len, buf_size);
@@ -868,22 +866,6 @@ copy_reg (char const *src_name, char const *dst_name,
#endif
}
- bool normal_copy_required;
- /* Perform an efficient extent-based copy, falling back to the
- standard copy only if the initial extent scan fails. If the
- '--sparse=never' option is specified, write all data but use
- any extents to read more efficiently. */
- if (extent_copy (source_desc, dest_desc, buf_size,
- src_open_sb.st_size, make_holes,
- src_name, dst_name, &normal_copy_required))
- goto preserve_metadata;
-
- if (! normal_copy_required)
- {
- return_val = false;
- goto close_src_and_dst_desc;
- }
-
/* If not making a sparse file, try to use a more-efficient
buffer size. */
if (! make_holes)
@@ -912,6 +894,22 @@ copy_reg (char const *src_name, char const *dst_name,
buf_alloc = xmalloc (buf_size + buf_alignment_slop);
buf = ptr_align (buf_alloc, buf_alignment);
+ bool normal_copy_required;
+ /* Perform an efficient extent-based copy, falling back to the
+ standard copy only if the initial extent scan fails. If the
+ '--sparse=never' option is specified, write all data but use
+ any extents to read more efficiently. */
+ if (extent_copy (source_desc, dest_desc, buf, buf_size,
+ src_open_sb.st_size, make_holes,
+ src_name, dst_name, &normal_copy_required))
+ goto preserve_metadata;
+
+ if (! normal_copy_required)
+ {
+ return_val = false;
+ goto close_src_and_dst_desc;
+ }
+
while (true)
{
word *wp = NULL;