X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi_fid.c;h=578c6e6c797f055cfa6bc23ee55064de43f5117c;hp=5c39b14affb43d30b6a9d45652df27600e455da5;hb=c45558bf560cf43d440af5679b86ba7e4d2542f3;hpb=4cfe77df6f2499effa1644e6ad5a594abb11be23 diff --git a/lustre/utils/liblustreapi_fid.c b/lustre/utils/liblustreapi_fid.c index 5c39b14..578c6e6 100644 --- a/lustre/utils/liblustreapi_fid.c +++ b/lustre/utils/liblustreapi_fid.c @@ -160,11 +160,51 @@ out: return rc; } +int llapi_fid2path_at(int mnt_fd, const struct lu_fid *fid, + char *path_buf, int path_buf_size, + long long *recno, int *linkno) +{ + struct getinfo_fid2path *gf = NULL; + int rc; + + gf = calloc(1, sizeof(*gf) + path_buf_size); + if (gf == NULL) { + rc = -ENOMEM; + goto out; + } + + gf->gf_fid = *fid; + if (recno != NULL) + gf->gf_recno = *recno; + + if (linkno != NULL) + gf->gf_linkno = *linkno; + + gf->gf_pathlen = path_buf_size; + + rc = ioctl(mnt_fd, OBD_IOC_FID2PATH, gf); + if (rc) { + rc = -errno; + goto out; + } + + rc = copy_strip_dne_path(gf->gf_u.gf_path, path_buf, path_buf_size); + + if (recno != NULL) + *recno = gf->gf_recno; + + if (linkno != NULL) + *linkno = gf->gf_linkno; +out: + free(gf); + + return rc; +} + int llapi_fid2path(const char *path_or_device, const char *fidstr, char *path, int pathlen, long long *recno, int *linkno) { struct lu_fid fid; - struct getinfo_fid2path *gf = NULL; int mnt_fd = -1; int rc; @@ -192,41 +232,11 @@ int llapi_fid2path(const char *path_or_device, const char *fidstr, char *path, goto out; } - gf = calloc(1, sizeof(*gf) + pathlen); - if (gf == NULL) { - rc = -ENOMEM; - goto out; - } - - gf->gf_fid = fid; - if (recno) - gf->gf_recno = *recno; - if (linkno) - gf->gf_linkno = *linkno; - gf->gf_pathlen = pathlen; - - rc = ioctl(mnt_fd, OBD_IOC_FID2PATH, gf); - if (rc < 0) { - rc = -errno; - goto out; - } - - rc = copy_strip_dne_path(gf->gf_u.gf_path, path, pathlen); - - if (recno) - *recno = gf->gf_recno; - - if (linkno) - *linkno = gf->gf_linkno; - + rc = llapi_fid2path_at(mnt_fd, &fid, path, pathlen, recno, linkno); out: if (!(mnt_fd < 0)) close(mnt_fd); - free(gf); - - errno = -rc; - return rc; }