Whamcloud - gitweb
b=19856
authornathan <nathan>
Wed, 17 Jun 2009 19:45:04 +0000 (19:45 +0000)
committernathan <nathan>
Wed, 17 Jun 2009 19:45:04 +0000 (19:45 +0000)
i=adilger
i=rread
move lu_fid definition into userspace

lustre/include/lustre/liblustreapi.h
lustre/include/lustre/lustre_idl.h
lustre/include/lustre/lustre_user.h
lustre/mdd/mdd_device.c
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 7016d4f..c65018c 100644 (file)
@@ -155,8 +155,7 @@ extern int llapi_is_lustre_mnttype(const char *type);
 extern int llapi_get_obd_count(char *mnt, int *count, int is_mdt);
 extern int parse_size(char *optarg, unsigned long long *size,
                       unsigned long long *size_units, int bytes_spec);
-extern int llapi_path2fid(const char *path, unsigned long long *seq,
-                          unsigned long *oid, unsigned long *ver);
+extern int llapi_path2fid(const char *path, lustre_fid *fid);
 extern int llapi_search_fsname(const char *pathname, char *fsname);
 extern void llapi_ping_target(char *obd_type, char *obd_name,
                               char *obd_uuid, void *args);
@@ -180,7 +179,7 @@ extern int llapi_changelog_clear(const char *mdtname, const char *idstr,
                                  long long endrec);
 extern int llapi_changelog_register(const char *mdtname);
 extern int llapi_changelog_unregister(const char *mdtname, int id);
-extern int llapi_fid2path(char *device, char *fid, char *path, int pathlen,
-                          long long *recno, int *linkno);
+extern int llapi_fid2path(const char *device, const char *fidstr, char *path,
+                          int pathlen, long long *recno, int *linkno);
 #endif
 
index 79fb1f7..3310fac 100644 (file)
@@ -253,34 +253,6 @@ static inline int range_is_exhausted(const struct lu_seq_range *range)
  * @{ */
 
 /**
- * File identifier.
- *
- * Fid is a cluster-wide unique identifier of a file or an object
- * (stripe). Fids are never reused. Fids are transmitted across network (in
- * the sender byte-ordering), and stored on disk in a packed form (struct
- * lu_fid_pack) in a big-endian order.
- */
-struct lu_fid {
-        /**
-         * fid sequence. Sequence is a unit of migration: all files (objects)
-         * with fids from a given sequence are stored on the same
-         * server.
-         *
-         * Lustre should support 2 ^ 64 objects, thus even if one
-         * sequence has one object we will never reach this value.
-         */
-        __u64 f_seq;
-        /** fid number within sequence. */
-        __u32 f_oid;
-        /**
-         * fid version, used to distinguish different versions (in the sense
-         * of snapshots, etc.) of the same file system object. Not currently
-         * used.
-         */
-        __u32 f_ver;
-};
-
-/**
  * Following struct for MDT attributes, that will be kept inode's EA.
  * Introduced in 2.0 release (please see b15993, for details)
  */
@@ -293,7 +265,6 @@ struct lustre_mdt_attrs {
         __u64   lma_som_sectors;
 };
 
-
 /**
  * fid constants
  */
@@ -371,14 +342,10 @@ static inline __u32 lu_igif_gen(const struct lu_fid *fid)
         return fid_oid(fid);
 }
 
-#define DFID "["LPX64":0x%x:0x%x]"
-#define SFID "0x%llx:0x%x:0x%x"
-
-#define PFID(fid)     \
-        fid_seq(fid), \
-        fid_oid(fid), \
-        fid_ver(fid)
-
+/*
+ * Fids are transmitted across network (in the sender byte-ordering),
+ * and stored on disk in big-endian order.
+ */
 static inline void fid_cpu_to_le(struct lu_fid *dst, const struct lu_fid *src)
 {
         /* check that all fields are converted */
index 8336538..8cdb6ec 100644 (file)
@@ -226,6 +226,55 @@ static inline char *obd_uuid2str(struct obd_uuid *uuid)
         return (char *)(uuid->uuid);
 }
 
+
+/**
+ * File IDentifier.
+ *
+ * FID is a cluster-wide unique identifier of a file or an object (stripe).
+ * FIDs are never reused.
+ */
+struct lu_fid {
+        /**
+         * FID sequence. Sequence is a unit of migration: all files (objects)
+         * with FIDs from a given sequence are stored on the same server.
+         * Lustre should support 2^64 objects, so even if each sequence
+         * has only a single object we can still enumerate 2^64 objects.
+         */
+        __u64 f_seq;
+        /** FID number within sequence. */
+        __u32 f_oid;
+        /**
+         * FID version, used to distinguish different versions (in the sense
+         * of snapshots, etc.) of the same file system object. Not currently
+         * used.
+         */
+        __u32 f_ver;
+};
+
+/* Userspace should treat lu_fid as opaque, and only use the following methods
+   to print or parse them.  Other functions (e.g. compare, swab) could be moved
+   here from lustre_idl.h if needed. */
+typedef struct lu_fid lustre_fid;
+
+/* printf display format
+   e.g. printf("file FID is "DFID"\n", PFID(fid)); */
+#define DFID "["LPX64":0x%x:0x%x]"
+#define PFID(fid)     \
+        (fid)->f_seq, \
+        (fid)->f_oid, \
+        (fid)->f_ver
+
+/* scanf input parse format -- strip '[' first.
+   e.g. sscanf(fidstr, SFID, RFID(&fid)); */
+#define SFID "0x%llx:0x%x:0x%x"
+#define RFID(fid)     \
+        &((fid)->f_seq), \
+        &((fid)->f_oid), \
+        &((fid)->f_ver)
+
+
+/********* Quotas **********/
+
 /* these must be explicitly translated into linux Q_* in ll_dir_ioctl */
 #define LUSTRE_Q_QUOTAON    0x800002     /* turn quotas on */
 #define LUSTRE_Q_QUOTAOFF   0x800003     /* turn quotas off */
index b988aa6..58de195 100644 (file)
@@ -683,8 +683,7 @@ static int obf_lookup(const struct lu_env *env, struct md_object *p,
         while (*name == '[')
                 name++;
 
-        sscanf(name, SFID, &(f->f_seq), &(f->f_oid),
-               &(f->f_ver));
+        sscanf(name, SFID, RFID(f));
         if (!fid_is_sane(f)) {
                 CWARN("bad FID format [%s], should be "DFID"\n", lname->ln_name,
                       (__u64)1, 2, 0);
index c3c8ba6..5f6e224 100644 (file)
@@ -2546,22 +2546,21 @@ static int lfs_fid2path(int argc, char **argv)
 static int lfs_path2fid(int argc, char **argv)
 {
         char *path;
-        unsigned long long seq;
-        unsigned long oid, ver;
+        lustre_fid fid;
         int rc;
 
         if (argc != 2)
                 return CMD_HELP;
 
         path = argv[1];
-        rc = llapi_path2fid(path, &seq, &oid, &ver);
+        rc = llapi_path2fid(path, &fid);
         if (rc) {
                 fprintf(stderr, "can't get fid for %s: %s\n", path,
                         strerror(errno = -rc));
                 return rc;
         }
 
-        printf(DFID"\n", seq, (unsigned int)oid, (unsigned int)ver);
+        printf(DFID"\n", PFID(&fid));
 
         return 0;
 }
index 10f6649..fb97e90 100644 (file)
@@ -2521,8 +2521,8 @@ int llapi_changelog_clear(const char *mdtname, const char *idstr,
         return rc;
 }
 
-int llapi_fid2path(char *device, char *fidstr, char *buf, int buflen,
-                   long long *recno, int *linkno)
+int llapi_fid2path(const char *device, const char *fidstr, char *buf,
+                   int buflen, long long *recno, int *linkno)
 {
         char path[PATH_MAX];
         struct lu_fid fid;
@@ -2532,8 +2532,7 @@ int llapi_fid2path(char *device, char *fidstr, char *buf, int buflen,
         while (*fidstr == '[')
                 fidstr++;
 
-        sscanf(fidstr, "0x%llx:0x%x:0x%x", &(fid.f_seq), &(fid.f_oid),
-               &(fid.f_ver));
+        sscanf(fidstr, SFID, RFID(&fid));
         if (!fid_is_sane(&fid)) {
                 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
                           "bad FID format [%s], should be "DFID"\n",
@@ -2545,7 +2544,7 @@ int llapi_fid2path(char *device, char *fidstr, char *buf, int buflen,
         if (device[0] == '/') {
                 strcpy(path, device);
         } else {
-                rc = get_root_path(WANT_PATH, device, NULL, path);
+                rc = get_root_path(WANT_PATH, (char *)device, NULL, path);
                 if (rc < 0)
                         return rc;
         }
@@ -2573,20 +2572,15 @@ int llapi_fid2path(char *device, char *fidstr, char *buf, int buflen,
         return rc;
 }
 
-int llapi_path2fid(const char *path, unsigned long long *seq,
-                   unsigned long *oid, unsigned long *ver)
+int llapi_path2fid(const char *path, lustre_fid *fid)
 {
-        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);
+        rc = ioctl(fd, LL_IOC_PATH2FID, fid);
 
         close(fd);
         return rc;