From 32d982a2714e078321341209ad742052e85c3864 Mon Sep 17 00:00:00 2001 From: kalpak Date: Tue, 28 Oct 2008 18:19:01 +0000 Subject: [PATCH] b=17187 i=nathan i=manoj Add "lfs path2fid" to get fid from path --- lustre/include/lustre/liblustreapi.h | 3 +++ lustre/include/lustre/lustre_user.h | 1 + lustre/llite/file.c | 7 +++++++ lustre/utils/lfs.c | 29 +++++++++++++++++++++++++++++ lustre/utils/liblustreapi.c | 19 +++++++++++++++++++ 5 files changed, 59 insertions(+) diff --git a/lustre/include/lustre/liblustreapi.h b/lustre/include/lustre/liblustreapi.h index f8c29ed..8717532 100644 --- a/lustre/include/lustre/liblustreapi.h +++ b/lustre/include/lustre/liblustreapi.h @@ -153,6 +153,9 @@ extern int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count); extern int llapi_is_lustre_mnttype(const char *type); extern int parse_size(char *optarg, unsigned long long *size, unsigned long long *size_units); +extern int llapi_path2fid(const char *path, unsigned long long *seq, + unsigned long *oid, unsigned long *ver); + struct mntent; #define HAVE_LLAPI_IS_LUSTRE_MNT extern int llapi_is_lustre_mnt(struct mntent *mnt); diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index d95e221..bd76396 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -102,6 +102,7 @@ struct obd_statfs; #define LL_IOC_LLOOP_DETACH _IOWR('f', 170, long) #define LL_IOC_LLOOP_INFO _IOWR('f', 171, long) #define LL_IOC_LLOOP_DETACH_BYDEV _IOWR('f', 172, long) +#define LL_IOC_PATH2FID _IOR ('f', 173, long) #define LL_STATFS_MDC 1 #define LL_STATFS_LOV 2 diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 530cefc..76f8269 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -2722,6 +2722,13 @@ error: */ case LL_IOC_FLUSHCTX: RETURN(ll_flush_ctx(inode)); + case LL_IOC_PATH2FID: { + if (copy_to_user((void *)arg, &ll_i2info(inode)->lli_fid, + sizeof(struct lu_fid))) + RETURN(-EFAULT); + + RETURN(0); + } default: { int err; diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index f29ae94..f0d07ff 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -100,6 +100,7 @@ static int lfs_rgetfacl(int argc, char **argv); static int lfs_cp(int argc, char **argv); static int lfs_ls(int argc, char **argv); static int lfs_poollist(int argc, char **argv); +static int lfs_path2fid(int argc, char **argv); /* all avaialable commands */ command_t cmdlist[] = { @@ -194,6 +195,8 @@ command_t cmdlist[] = { {"ls", lfs_ls, 0, "Remote user list directory contents.\n" "usage: ls [OPTION]... [FILE]..."}, + {"path2fid", lfs_path2fid, 0, "Display the fid for a given path.\n" + "usage: path2fid "}, {"help", Parser_help, 0, "help"}, {"exit", Parser_quit, 0, "quit"}, {"quit", Parser_quit, 0, "quit"}, @@ -875,6 +878,32 @@ static int lfs_osts(int argc, char **argv) return rc; } +static int lfs_path2fid(int argc, char **argv) +{ + char *path; + unsigned long long seq; + unsigned long oid, ver; + int rc; + + if (argc != 2) + return CMD_HELP; + + path = argv[1]; + rc = llapi_path2fid(path, &seq, &oid, &ver); + if (rc) { + fprintf(stderr, "error: can't get fid for %s\n", path); + return rc; + } + + printf("%llu:%lu", seq, oid); + if (ver) + printf(":%lu", ver); + + printf("\n"); + + return 0; +} + #define COOK(value) \ ({ \ int radix = 0; \ diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 9978cdf..9aad868 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -2351,3 +2351,22 @@ int llapi_ls(int argc, char *argv[]) exit(execvp(argv[0], argv)); } + +int llapi_path2fid(const char *path, unsigned long long *seq, + unsigned long *oid, unsigned long *ver) +{ + struct lu_fid fid; + int fd, rc; + + fd = open(path, O_RDONLY); + if (fd < 0) + return -errno; + + rc = ioctl(fd, LL_IOC_PATH2FID, &fid); + *seq = fid_seq(&fid); + *oid = fid_oid(&fid); + *ver = fid_ver(&fid); + + close(fd); + return rc; +} -- 1.8.3.1