Whamcloud - gitweb
LU-5030 util: migrate lctl params functions to use cfs_get_paths()
[fs/lustre-release.git] / lustre / utils / lustre_rsync.c
index 04b6c22..404ae58 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <getopt.h>
 #include <stdarg.h>
 #include <fcntl.h>
+#include <signal.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <errno.h>
 #include <utime.h>
 #include <sys/xattr.h>
 
-#include <libcfs/libcfsutil.h>
+#include <libcfs/util/string.h>
+#include <libcfs/util/parser.h>
 #include <lustre/lustreapi.h>
 #include <lustre/lustre_idl.h>
 #include "lustre_rsync.h"
@@ -674,11 +676,11 @@ void lr_cascade_move(const char *fid, const char *dest, struct lr_info *info)
                                         info->src, d, errno);
                                 errors++;
                         }
-                        lr_cascade_move(curr->pc_log.pcl_tfid, d, info);
                         if (curr == parents)
                                 parents = curr->pc_next;
                         else
                                 prev->pc_next = curr->pc_next;
+                       lr_cascade_move(curr->pc_log.pcl_tfid, d, info);
                         free(curr);
                         prev = curr = parents;
 
@@ -958,12 +960,12 @@ int lr_move(struct lr_info *info)
                        lr_debug(DINFO, "rename returns %d\n", rc1);
                 }
 
-               if (special_src) {
+               if (special_src)
                        rc1 = lr_remove_pc(info->spfid, info->sfid);
-                       if (!special_dest)
-                               lr_cascade_move(info->sfid, info->dest, info);
-                }
-               if (special_dest)
+
+               if (!special_dest)
+                       lr_cascade_move(info->sfid, info->dest, info);
+               else
                        rc1 = lr_add_pc(info->pfid, info->sfid, info->name);
 
                 lr_debug(DINFO, "move: %s [to] %s rc1=%d, errno=%d\n",
@@ -1005,7 +1007,7 @@ int lr_link(struct lr_info *info)
                                 break;
 
                         len = strlen(info->path) - strlen(info->name);
-                        if (len > 0 && strcmp(info->path + len,
+                       if (len >= 0 && strcmp(info->path + len,
                                               info->name) == 0)
                                 snprintf(info->dest, PATH_MAX, "%s/%s",
                                         status->ls_targets[info->target_no],
@@ -1114,7 +1116,7 @@ int lr_parse_line(void *priv, struct lr_info *info)
        struct changelog_rec            *rec;
        struct changelog_ext_rename     *rnm;
        size_t                           namelen;
-       size_t                           copylen;
+       size_t                           copylen = sizeof(info->name);
 
        if (llapi_changelog_recv(priv, &rec) != 0)
                return -1;
@@ -1126,18 +1128,22 @@ int lr_parse_line(void *priv, struct lr_info *info)
        snprintf(info->pfid, sizeof(info->pfid), DFID, PFID(&rec->cr_pfid));
 
        namelen = strnlen(changelog_rec_name(rec), rec->cr_namelen);
-       copylen = min(sizeof(info->name), namelen + 1);
+       if (copylen > namelen + 1)
+               copylen = namelen + 1;
        strlcpy(info->name, changelog_rec_name(rec), copylen);
 
        /* Don't use rnm if CLF_RENAME isn't set */
        rnm = changelog_rec_rename(rec);
        if (rec->cr_flags & CLF_RENAME && !fid_is_zero(&rnm->cr_sfid)) {
+               copylen = sizeof(info->sname);
+
                snprintf(info->sfid, sizeof(info->sfid), DFID,
                         PFID(&rnm->cr_sfid));
                snprintf(info->spfid, sizeof(info->spfid), DFID,
                         PFID(&rnm->cr_spfid));
                namelen = changelog_rec_snamelen(rec);
-               copylen = min(sizeof(info->sname), namelen + 1);
+               if (copylen > namelen + 1)
+                       copylen = namelen + 1;
                strlcpy(info->sname, changelog_rec_sname(rec), copylen);
 
                if (verbose > 1)