}
run_test 10d "Archive a file on the default archive id"
-test_11() {
+test_11a() {
mkdir -p $DIR/$tdir
copy2archive /etc/hosts $tdir/$tfile
local f=$DIR/$tdir/$tfile
local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
error "fid $fid not in archive $HSM_ARCHIVE"
}
-run_test 11 "Import a file"
+run_test 11a "Import a file"
+
+test_11b() {
+ # test needs a running copytool
+ copytool_setup
+
+ mkdir -p $DIR/$tdir
+ local f=$DIR/$tdir/$tfile
+ local fid=$(copy_file /etc/hosts $f)
+ $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
+ error "hsm_archive failed"
+ wait_request_state $fid ARCHIVE SUCCEED
+
+ local FILE_HASH=$(md5sum $f)
+ rm -f $f
+
+ import_file $fid $f
+
+ echo "$FILE_HASH" | md5sum -c
+
+ [[ $? -eq 0 ]] || error "Restored file differs"
+
+ copytool_cleanup
+}
+run_test 11b "Import a deleted file using its FID"
test_12a() {
# test needs a running copytool
*
* This particular tool can also import an existing HSM archive.
*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <dirent.h>
"into a Lustre filesystem.\n"
" Usage:\n"
" %s [options] --import <src> <dst> <lustre_mount_point>\n"
- " import an archived subtree at\n"
- " <src> (relative to hsm_root) into the Lustre filesystem at\n"
- " <dst> (absolute)\n"
+ " import an archived subtree from\n"
+ " <src> (FID or relative path to hsm_root) into the Lustre\n"
+ " filesystem at\n"
+ " <dst> (absolute path)\n"
" %s [options] --rebind <old_FID> <new_FID> <lustre_mount_point>\n"
" rebind an entry in the HSM to a new FID\n"
" <old_FID> old FID the HSM entry is bound to\n"
static char *path_concat(const char *dirname, const char *basename)
{
char *result;
- int dirlen = strlen(dirname);
+ int rc;
- result = malloc(dirlen + strlen(basename) + 2);
- if (result == NULL)
+ rc = asprintf(&result, "%s/%s", dirname, basename);
+ if (rc < 0)
return NULL;
- memcpy(result, dirname, dirlen);
- result[dirlen] = '/';
- strcpy(result + dirlen + 1, basename);
-
return result;
}
+static int ct_import_fid(const lustre_fid *import_fid)
+{
+ char fid_path[PATH_MAX];
+
+ 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);
+}
+
static int ct_import_recurse(const char *relpath)
{
DIR *dir;
struct dirent ent, *cookie = NULL;
char *srcpath, *newpath;
+ lustre_fid import_fid;
int rc;
if (relpath == NULL)
return -EINVAL;
+ /* Is relpath a FID? In which case SFID should expand to three
+ * elements. */
+ rc = sscanf(relpath, SFID, RFID(&import_fid));
+ if (rc == 3)
+ return ct_import_fid(&import_fid);
+
srcpath = path_concat(opt.o_hsm_root, relpath);
if (srcpath == NULL) {
err_major++;
strncat(src, ".lov", sizeof(src) - strlen(src) - 1);
strncat(dst, ".lov", sizeof(dst) - strlen(dst) - 1);
if (rename(src, dst))
- CT_ERROR(errno, "cannot '%s' rename to '%s'", src, dst);
+ CT_ERROR(errno, "cannot rename '%s' to '%s'", src, dst);
}
return 0;