From f7d45ef99d3ccb94d853b59345243f57ba7eee74 Mon Sep 17 00:00:00 2001 From: Di Wang Date: Tue, 7 May 2024 03:12:43 +0000 Subject: [PATCH] LU-17775 lfs: Use fid for lfs_setstripe copy FID can be used for lfs_setstripe copy. Signed-off-by: Di Wang Change-Id: Ia3f968b0602f7f8640693189c4deec4260fc2bc9 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55081 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Patrick Farrell Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger --- lustre/tests/sanity.sh | 4 +++- lustre/utils/lfs.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 39db647..d293085 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -26130,7 +26130,9 @@ test_270h() { # DOM component in the middle and has other enries in the same mirror, # should succeed but lost DoM component - $LFS setstripe --copy=${dom}_1 $dom || + local fid1=$($LFS path2fid ${dom}_1) + + $LFS setstripe --copy=$fid1 $dom || error "Can't create file from OST|DOM mirror layout" # check new file has no DoM layout after all [[ $($LFS getstripe -L $dom) != "mdt" ]] || diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 2d6191c..a21746b 100755 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -1873,6 +1873,58 @@ static ssize_t mirror_file_compare(int fd_src, int fd_dst) return bytes_done; } +static int +open_by_fid_str(const char *fid_str, const char *path, int *fdp, int flags) +{ + char mntdir[PATH_MAX] = {'\0'}; + struct lu_fid fid; + int fd; + int rc; + + rc = llapi_fid_parse(fid_str, &fid, NULL); + if (rc != 0) + return rc; + + rc = llapi_search_mounts(path, 0, mntdir, NULL); + if (rc < 0 || mntdir[0] == '\0') { + fprintf(stderr, "Cannot find mounted Lustre filesystem: %s\n", + (rc < 0) ? strerror(-rc) : strerror(ENODEV)); + return rc != 0 ? rc : -ENODEV; + } + + fd = llapi_open_by_fid(mntdir, &fid, flags); + if (fd < 0) + return fd; + + *fdp = fd; + return rc; +} + +static struct llapi_layout* +layout_get_by_name_or_fid(const char *name_or_fid, const char *path, + enum llapi_layout_get_flags layout_flags, int flags) +{ + int rc; + + /* Check if name or fid */ + if (isdigit(*name_or_fid) || *name_or_fid == '[') { + int fd; + + rc = open_by_fid_str(name_or_fid, path, &fd, flags); + if (rc == 0) { + struct llapi_layout *layout; + + layout = llapi_layout_get_by_fd(fd, layout_flags); + close(fd); + if (layout != NULL) + return layout; + } + } + + /* Then try getting by name */ + return llapi_layout_get_by_path(name_or_fid, layout_flags); +} + static int mirror_extend_file(const char *fname, const char *victim_file, enum mirror_flags mirror_flags) { @@ -4560,7 +4612,8 @@ static int lfs_setstripe_internal(int argc, char **argv, for (fname = argv[optind]; (optind < argc) && (fname != NULL); fname = argv[++optind]) { if (from_copy) { - layout = llapi_layout_get_by_path(template ?: fname, 0); + layout = layout_get_by_name_or_fid(template ?: fname, + fname, 0, O_RDONLY); if (!layout) { fprintf(stderr, "%s: can't create composite layout from file %s: %s\n", -- 1.8.3.1