From 7154244354e3275f6a68f7581f7cfe9ef0a6507c Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Wed, 26 Apr 2023 11:21:15 +0530 Subject: [PATCH] LU-16786 utils: Replace open call to WANT_FD Replace open call to WANT_FD with newly added API llapi_root_path_open() which was added under LU-16427 Signed-off-by: Arshad Hussain Change-Id: I97d55321cf32e40eaf7d6284c47f313199a6c406 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50764 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin Reviewed-by: James Simmons Reviewed-by: Andreas Dilger --- lustre/utils/liblustreapi_fid.c | 13 ++++--------- lustre/utils/liblustreapi_hsm.c | 4 ++-- lustre/utils/liblustreapi_pcc.c | 4 ++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lustre/utils/liblustreapi_fid.c b/lustre/utils/liblustreapi_fid.c index d6fb8b5..827d8ad 100644 --- a/lustre/utils/liblustreapi_fid.c +++ b/lustre/utils/liblustreapi_fid.c @@ -233,18 +233,13 @@ int llapi_fid2path(const char *path_or_device, const char *fidstr, char *path, goto out; } - if (path_or_device[0] == '/') - rc = get_root_path(WANT_FD, NULL, &mnt_fd, - (char *)path_or_device, -1, NULL, NULL); - else - rc = get_root_path(WANT_FD, (char *)path_or_device, - &mnt_fd, NULL, -1, NULL, NULL); - + rc = llapi_root_path_open(path_or_device, &mnt_fd); if (rc < 0) goto out; /* mnt_fd is cached internally, no need to close it */ rc = llapi_fid2path_at(mnt_fd, &fid, path, pathlen, recno, linkno); + close(mnt_fd); out: return rc; @@ -479,8 +474,8 @@ int llapi_open_by_fid(const char *lustre_dir, const struct lu_fid *fid, /* this will return a cached FD if available, so only one open needed. * WANT_FD doesn't modify lustre_dir so casting away "const" is OK */ - rc = get_root_path(WANT_FD, NULL, &mnt_fd, (char *)lustre_dir, 0, NULL, - NULL); + + rc = llapi_root_path_open(lustre_dir, &mnt_fd); if (rc) goto out; diff --git a/lustre/utils/liblustreapi_hsm.c b/lustre/utils/liblustreapi_hsm.c index 6c42607..5726730 100644 --- a/lustre/utils/liblustreapi_hsm.c +++ b/lustre/utils/liblustreapi_hsm.c @@ -1647,7 +1647,7 @@ int llapi_hsm_request(const char *path, const struct hsm_user_request *request) int rc; int fd; - rc = get_root_path(WANT_FD, NULL, &fd, (char *)path, -1, NULL, NULL); + rc = llapi_root_path_open(path, &fd); if (rc) return rc; @@ -1655,7 +1655,7 @@ int llapi_hsm_request(const char *path, const struct hsm_user_request *request) /* If error, save errno value */ rc = rc ? -errno : 0; - /* fd is cached internally, no need to close it */ + close(fd); return rc; } diff --git a/lustre/utils/liblustreapi_pcc.c b/lustre/utils/liblustreapi_pcc.c index 0045d7e..47192e5 100644 --- a/lustre/utils/liblustreapi_pcc.c +++ b/lustre/utils/liblustreapi_pcc.c @@ -215,7 +215,7 @@ int llapi_pcc_detach_fid(const char *mntpath, const struct lu_fid *fid, int fd; struct lu_pcc_detach_fid detach; - rc = get_root_path(WANT_FD, NULL, &fd, (char *)mntpath, -1, NULL, NULL); + rc = llapi_root_path_open(mntpath, &fd); if (rc) { llapi_error(LLAPI_MSG_ERROR, rc, "cannot get root path: %s", mntpath); @@ -232,10 +232,10 @@ int llapi_pcc_detach_fid(const char *mntpath, const struct lu_fid *fid, detach.pccd_fid = *fid; detach.pccd_opt = option; - /* fd is cached internally, no need to close */ rc = ioctl(fd, LL_IOC_PCC_DETACH_BY_FID, &detach); rc = rc ? -errno : 0; + close(fd); return rc; } -- 1.8.3.1