From: Henri Doreau Date: Thu, 1 May 2014 09:57:34 +0000 (+0200) Subject: LU-4569 hsm: Prevent copytool from importing existing file. X-Git-Tag: 2.5.60~75 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F85%2F10185%2F3;p=fs%2Flustre-release.git 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 --- 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);