Whamcloud - gitweb
b=17187
authorkalpak <kalpak>
Tue, 28 Oct 2008 18:19:01 +0000 (18:19 +0000)
committerkalpak <kalpak>
Tue, 28 Oct 2008 18:19:01 +0000 (18:19 +0000)
i=nathan
i=manoj

Add "lfs path2fid" to get fid from path

lustre/include/lustre/liblustreapi.h
lustre/include/lustre/lustre_user.h
lustre/llite/file.c
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index f8c29ed..8717532 100644 (file)
@@ -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);
index d95e221..bd76396 100644 (file)
@@ -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
index 530cefc..76f8269 100644 (file)
@@ -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;
 
index f29ae94..f0d07ff 100644 (file)
@@ -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 <path>"},
         {"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;                                                  \
index 9978cdf..9aad868 100644 (file)
@@ -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;
+}