summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2011-02-08 19:16:55 +0000
committerPádraig Brady <P@draigBrady.com>2011-02-11 00:13:31 +0000
commit6f95025c9daf8fb3ed785ff1b650ade5066a58f4 (patch)
tree48afd3971dfe45ff94d01c6545304e768ce540f7 /src
parent15571e0c8f4be1170184388f9acd8259ba75b22f (diff)
downloadcoreutils-6f95025c9daf8fb3ed785ff1b650ade5066a58f4.tar.xz
copy: suppress redundant lseeks when using fiemap
* src/copy.c (extent_copy): Suppress redundant lseek()s in both the source and dest files, when there is no hole between extents.
Diffstat (limited to 'src')
-rw-r--r--src/copy.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/copy.c b/src/copy.c
index 9182c1624..5b6ffe334 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -334,33 +334,31 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
{
off_t ext_start = scan.ext_info[i].ext_logical;
uint64_t ext_len = scan.ext_info[i].ext_length;
+ uint64_t hole_size = ext_start - last_ext_start - last_ext_len;
- if (lseek (src_fd, ext_start, SEEK_SET) < 0)
+ if (hole_size)
{
- error (0, errno, _("cannot lseek %s"), quote (src_name));
- fail:
- extent_scan_free (&scan);
- return false;
- }
+ if (lseek (src_fd, ext_start, SEEK_SET) < 0)
+ {
+ error (0, errno, _("cannot lseek %s"), quote (src_name));
+ fail:
+ extent_scan_free (&scan);
+ return false;
+ }
- if (make_holes)
- {
- if (lseek (dest_fd, ext_start, SEEK_SET) < 0)
+ if (make_holes)
{
- error (0, errno, _("cannot lseek %s"), quote (dst_name));
- goto fail;
+ if (lseek (dest_fd, ext_start, SEEK_SET) < 0)
+ {
+ error (0, errno, _("cannot lseek %s"), quote (dst_name));
+ goto fail;
+ }
}
- }
- else
- {
- /* When not inducing holes and when there is a hole between
- the end of the previous extent and the beginning of the
- current one, write zeros to the destination file. */
- if (last_ext_start + last_ext_len < ext_start)
+ else
{
- uint64_t hole_size = (ext_start
- - last_ext_start
- - last_ext_len);
+ /* When not inducing holes and when there is a hole between
+ the end of the previous extent and the beginning of the
+ current one, write zeros to the destination file. */
if (! write_zeros (dest_fd, hole_size))
{
error (0, errno, _("%s: write failed"), quote (dst_name));