From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Return-Path: From: Cyrill Gorcunov Subject: [PATCH 1/3] core/coio_file: Use eio_sendfile_sync instead of a chunk mode Date: Tue, 16 Apr 2019 23:08:56 +0300 Message-Id: <20190416200858.19473-2-gorcunov@gmail.com> In-Reply-To: <20190416200858.19473-1-gorcunov@gmail.com> References: <20190416200858.19473-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tml Cc: Vladimir Davydov , Cyrill Gorcunov List-ID: 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 --- src/lib/core/coio_file.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/lib/core/coio_file.c b/src/lib/core/coio_file.c index c5b2db781..20053558e 100644 --- a/src/lib/core/coio_file.c +++ b/src/lib/core/coio_file.c @@ -571,7 +571,7 @@ static void coio_do_copyfile(eio_req *req) { struct coio_file_task *eio = (struct coio_file_task *)req->data; - + off_t pos, ret, left; struct stat st; if (stat(eio->copyfile.source, &st) < 0) { goto error; @@ -588,22 +588,18 @@ 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) + for (left = st.st_size, pos = 0; left > 0;) { + ret = eio_sendfile_sync(dest_fd, source_fd, pos, left); + if (ret < 0) { + say_syserror("sendfile, [%s -> %s]", + fio_filename(source_fd), + fio_filename(dest_fd)); goto error_copy; + } + pos += ret; + left -= ret; } + req->result = 0; close(source_fd); close(dest_fd); -- 2.20.1