Whamcloud - gitweb
LU-3319 procfs: move mdd/ofd proc handling to seq_files
[fs/lustre-release.git] / lustre / utils / lhsmtool_posix.c
index 6df6af5..7650a8d 100644 (file)
@@ -1392,10 +1392,20 @@ static char *path_concat(const char *dirname, const char *basename)
 
 static int ct_import_fid(const lustre_fid *import_fid)
 {
-       char fid_path[PATH_MAX];
+       char    fid_path[PATH_MAX];
+       int     rc;
+
+       ct_path_lustre(fid_path, sizeof(fid_path), opt.o_mnt, import_fid);
+       rc = access(fid_path, F_OK);
+       if (rc == 0 || errno != ENOENT) {
+               rc = (errno == 0) ? -EEXIST : -errno;
+               CT_ERROR(rc, "cannot import '"DFID"'", PFID(import_fid));
+               return rc;
+       }
 
        ct_path_archive(fid_path, sizeof(fid_path), opt.o_hsm_root,
                        import_fid);
+
        CT_TRACE("Resolving "DFID" to %s", PFID(import_fid), fid_path);
 
        return ct_import_one(fid_path, opt.o_dst);
@@ -1805,8 +1815,6 @@ static int ct_run(void)
                        hai = hai_next(hai);
                }
 
-               llapi_hsm_action_list_free(&hal);
-
                if (opt.o_abort_on_error && err_major)
                        break;
        }
@@ -1836,7 +1844,7 @@ static int ct_setup(void)
        if (rc < 0) {
                CT_ERROR(rc, "cannot find a Lustre filesystem mounted at '%s'",
                         opt.o_mnt);
-               return -rc;
+               return rc;
        }
 
        return rc;
@@ -1869,7 +1877,9 @@ int main(int argc, char **argv)
                return -rc;
        }
 
-       ct_setup();
+       rc = ct_setup();
+       if (rc < 0)
+               goto error_cleanup;
 
        switch (opt.o_action) {
        case CA_IMPORT:
@@ -1891,6 +1901,7 @@ int main(int argc, char **argv)
                         " rc=%d (%s)", err_major, err_minor, rc,
                         strerror(-rc));
 
+error_cleanup:
        ct_cleanup();
 
        return -rc;