diff options
author | Jim Meyering <meyering@redhat.com> | 2011-01-22 13:09:08 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2011-01-30 20:44:11 +0100 |
commit | 790a4654ae319d0ae7770fa93a5c5cef2acab624 (patch) | |
tree | 96bc9e1bc3a306fbcecb0a8ab5dd29b6b7825b4c | |
parent | ce3c73dddddf04a5f1e03f3830198ecc55e56c75 (diff) | |
download | coreutils-790a4654ae319d0ae7770fa93a5c5cef2acab624.tar.xz |
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.c | 36 |
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; |