Whamcloud - gitweb
LU-8009 utils: Lustre_rsync does not sync files on MDT1
[fs/lustre-release.git] / lustre / utils / lustre_rsync.c
index 404ae58..3e196d5 100644 (file)
 #include <errno.h>
 #include <limits.h>
 #include <utime.h>
+#include <time.h>
 #include <sys/xattr.h>
 
 #include <libcfs/util/string.h>
@@ -391,31 +392,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 */
@@ -1437,7 +1446,8 @@ void lr_print_status(struct lr_info *info)
         if (statuslog != NULL)
                 printf("Statuslog: %s\n", statuslog);
         printf("Changelog registration: %s\n", status->ls_registration);
-        printf("Starting changelog record: "LPD64"\n", status->ls_last_recno);
+       printf("Starting changelog record: %jd\n",
+              (uintmax_t)status->ls_last_recno);
         if (noxattr)
                 printf("Replicate xattrs: no\n");
         if (noclear)
@@ -1512,8 +1522,8 @@ int lr_replicate()
 
        /* Open changelogs for consumption*/
        rc = llapi_changelog_start(&changelog_priv,
-                                  CHANGELOG_FLAG_BLOCK | CHANGELOG_FLAG_JOBID,
-                                  status->ls_source_fs, status->ls_last_recno);
+                               CHANGELOG_FLAG_BLOCK | CHANGELOG_FLAG_JOBID,
+                               status->ls_mdt_device, status->ls_last_recno);
         if (rc < 0) {
                 fprintf(stderr, "Error opening changelog file for fs %s.\n",
                         status->ls_source_fs);