From f0dfb9fdb3398b010a1b8b3dcc187164d1dda00f Mon Sep 17 00:00:00 2001 From: Henri Doreau Date: Thu, 1 May 2014 11:57:34 +0200 Subject: [PATCH] LU-4569 hsm: Prevent copytool from importing existing file. Requesting import of an already existing FID can lead to data corruption since both inodes in lustre would refer to the same file in the backend. Lustre-change: http://review.whamcloud.com/10185 Lustre-commit: 8dfee22dd5a896144fb913f5f9f0e8f5c0e4ed86 Change-Id: I92d951e3e0796c9bde8bd744f39f242e2aa233eb Signed-off-by: Henri Doreau Tested-by: Jenkins Tested-by: Maloo Reviewed-by: jacques-Charles Lafoucriere Reviewed-by: Jinshan Xiong Reviewed-by: Oleg Drokin Reviewed-on: http://review.whamcloud.com/10479 Reviewed-by: John L. Hammond --- lustre/utils/lhsmtool_posix.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lustre/utils/lhsmtool_posix.c b/lustre/utils/lhsmtool_posix.c index 22ba504..13af205 100644 --- a/lustre/utils/lhsmtool_posix.c +++ b/lustre/utils/lhsmtool_posix.c @@ -1384,10 +1384,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); -- 1.8.3.1