From 8dfee22dd5a896144fb913f5f9f0e8f5c0e4ed86 Mon Sep 17 00:00:00 2001 From: Henri Doreau Date: Thu, 1 May 2014 11:57:34 +0200 Subject: [PATCH 1/1] 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. Signed-off-by: Henri Doreau Change-Id: I38bab1c890ff84b22f8816597f6d0b367aba4b38 Reviewed-on: http://review.whamcloud.com/10185 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: jacques-Charles Lafoucriere Reviewed-by: Jinshan Xiong Reviewed-by: Oleg Drokin --- 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 6df6af5..8c8ac00 100644 --- a/lustre/utils/lhsmtool_posix.c +++ b/lustre/utils/lhsmtool_posix.c @@ -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); -- 1.8.3.1