From: Andreas Dilger Date: Wed, 3 Feb 2016 02:48:35 +0000 (-0700) Subject: LU-6389 utils: fix lustre_rsync read retry X-Git-Tag: 2.8.51~69 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=7d165f5fe357010c3b41abf1163aacb09a88816f LU-6389 utils: fix lustre_rsync read retry The read() syscall could return less than the amount of data requested. Retry the read call until all data is read or an error is returned. Even though Lustre will retry the short read internally, the code may as well be written correctly. Signed-off-by: Andreas Dilger Change-Id: I712969c4f920b53fa6dc27ddcb968cb82df88a44 Reviewed-on: http://review.whamcloud.com/18275 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Bob Glossman Reviewed-by: Oleg Drokin --- diff --git a/lustre/utils/lustre_rsync.c b/lustre/utils/lustre_rsync.c index 404ae58..e0f7599 100644 --- a/lustre/utils/lustre_rsync.c +++ b/lustre/utils/lustre_rsync.c @@ -391,31 +391,39 @@ int lr_copy_data(struct lr_info *info) info->bufsize = bufsize; } - while (1) { - rsize = read(fd_src, info->buf, bufsize); - if (rsize == 0) { - break; - } else if (rsize < 0) { - rc = -errno; - goto out; - } - errno = 0; - if (write(fd_dest, info->buf, rsize) != rsize) { - if (errno != 0) - rc = -errno; - else - rc = -EINTR; - } - } - fsync(fd_dest); + while (1) { + char *buf; + int wsize; + + buf = info->buf; + rsize = read(fd_src, buf, bufsize); + if (rsize == 0) { + rc = 0; + break; + } + if (rsize < 0) { + rc = -errno; + break; + } + do { + wsize = write(fd_dest, buf, rsize); + if (wsize <= 0) { + rc = -errno; + break; + } + rsize -= wsize; + buf += wsize; + } while (rsize > 0); + } + fsync(fd_dest); out: - if (fd_src != -1) - close(fd_src); - if (fd_dest != -1) - close(fd_dest); + if (fd_src != -1) + close(fd_src); + if (fd_dest != -1) + close(fd_dest); - return rc; + return rc; } /* Copy data from source to destination */