[PATCH] lib/core/coio_file: Use eio_sendfile_sync instead of a chunk mode

Cyrill Gorcunov gorcunov at gmail.com
Wed Apr 10 22:36:24 MSK 2019


eio library provides a portable version of sendfile syscall
which works a way more efficient than explicit copying file
by 4K chunks.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---

Test app/fio.test.lua which uses this helper passed.

 src/lib/core/coio_file.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/lib/core/coio_file.c b/src/lib/core/coio_file.c
index c5b2db781..27806d7d5 100644
--- a/src/lib/core/coio_file.c
+++ b/src/lib/core/coio_file.c
@@ -588,22 +588,14 @@ coio_do_copyfile(eio_req *req)
 		goto error_dest;
 	}
 
-	enum { COPY_FILE_BUF_SIZE = 4096 };
-
-	char buf[COPY_FILE_BUF_SIZE];
-
-	while (true) {
-		ssize_t nread = fio_read(source_fd, buf, sizeof(buf));
-		if (nread < 0)
-			goto error_copy;
-
-		if (nread == 0)
-			break; /* eof */
-
-		ssize_t nwritten = fio_writen(dest_fd, buf, nread);
-		if (nwritten < 0)
-			goto error_copy;
+	ssize_t nwritten = eio_sendfile_sync(dest_fd, source_fd, 0, st.st_size);
+	if (nwritten != st.st_size) {
+		say_syserror("sendfile, [%s -> %s]",
+			     fio_filename(source_fd),
+			     fio_filename(dest_fd));
+		goto error_copy;
 	}
+
 	req->result = 0;
 	close(source_fd);
 	close(dest_fd);
-- 
2.20.1




More information about the Tarantool-patches mailing list