Whamcloud - gitweb
New tag 2.15.63
[fs/lustre-release.git] / lustre / utils / llsom_sync.c
index 1c2e5c3..e7ad285 100644 (file)
@@ -49,7 +49,6 @@
 #include <linux/lustre/lustre_fid.h>
 #include <libcfs/util/hash.h>
 #include <libcfs/util/list.h>
-#include <libcfs/util/parser.h>
 
 #define container_of(ptr, type, member) ({                      \
        const typeof(((type *) 0)->member) * __mptr = (ptr);     \
@@ -58,6 +57,7 @@
 #define CHLG_POLL_INTV 60
 #define REC_MIN_AGE    600
 #define DEF_CACHE_SIZE (256 * 1048576) /* 256MB */
+#define ONE_MB 0x100000
 
 struct options {
        const char      *o_chlg_user;
@@ -87,14 +87,6 @@ static const int fid_hash_shift = 6;
 #define FID_HASH_ENTRIES       (1 << fid_hash_shift)
 #define FID_ON_HASH(f)         (!hlist_unhashed(&(f)->fr_node))
 
-#if __BITS_PER_LONG == 32
-#define FID_HASH_FN(f) (hash_long(fid_flatten32(f), fid_hash_shift))
-#elif __BITS_PER_LONG == 64
-#define FID_HASH_FN(f) (hash_long(fid_flatten(f), fid_hash_shift))
-#else
-#error Wordsize not 32 or 64
-#endif
-
 struct lsom_head {
        struct hlist_head       *lh_hash;
        struct list_head         lh_list; /* ordered list by record index */
@@ -115,51 +107,6 @@ static void usage(char *prog)
        exit(0);
 }
 
-static inline __u64 fid_flatten(const struct lu_fid *fid)
-{
-       __u64 ino;
-       __u64 seq;
-
-       if (fid_is_igif(fid)) {
-               ino = lu_igif_ino(fid);
-               return ino;
-       }
-
-       seq = fid_seq(fid);
-
-       ino = (seq << 24) + ((seq >> 24) & 0xffffff0000ULL) + fid_oid(fid);
-
-       return ino ?: fid_oid(fid);
-}
-
-/**
- * map fid to 32 bit value for ino on 32bit systems.
- */
-static inline __u32 fid_flatten32(const struct lu_fid *fid)
-{
-       __u32 ino;
-       __u64 seq;
-
-       if (fid_is_igif(fid)) {
-               ino = lu_igif_ino(fid);
-               return ino;
-       }
-
-       seq = fid_seq(fid) - FID_SEQ_START;
-
-       /* Map the high bits of the OID into higher bits of the inode number so
-        * that inodes generated at about the same time have a reduced chance
-        * of collisions. This will give a period of 2^12 = 1024 unique clients
-        * (from SEQ) and up to min(LUSTRE_SEQ_MAX_WIDTH, 2^20) = 128k objects
-        * (from OID), or up to 128M inodes without collisions for new files.
-        */
-       ino = ((seq & 0x000fffffULL) << 12) + ((seq >> 8) & 0xfffff000) +
-             (seq >> (64 - (40-8)) & 0xffffff00) +
-             (fid_oid(fid) & 0xff000fff) + ((fid_oid(fid) & 0x00fff000) << 8);
-
-       return ino ?: fid_oid(fid);
-}
-
 static inline bool fid_eq(const lustre_fid *f1, const lustre_fid *f2)
 {
        return f1->f_seq == f2->f_seq && f1->f_oid == f2->f_oid &&
@@ -175,7 +122,9 @@ static void fid_hash_del(struct fid_rec *f)
 static void fid_hash_add(struct fid_rec *f)
 {
        assert(!FID_ON_HASH(f));
-       hlist_add_head(&f->fr_node, &head.lh_hash[FID_HASH_FN(&f->fr_fid)]);
+       hlist_add_head(&f->fr_node,
+                      &head.lh_hash[llapi_fid_hash(&f->fr_fid,
+                                             fid_hash_shift)]);
 }
 
 static struct fid_rec *fid_hash_find(const lustre_fid *fid)
@@ -184,7 +133,7 @@ static struct fid_rec *fid_hash_find(const lustre_fid *fid)
        struct hlist_node *entry, *next;
        struct fid_rec *f;
 
-       hash_list = &head.lh_hash[FID_HASH_FN(fid)];
+       hash_list = &head.lh_hash[llapi_fid_hash(fid, fid_hash_shift)];
        hlist_for_each_entry_safe(f, entry, next, hash_list, fr_node) {
                assert(FID_ON_HASH(f));
                if (fid_eq(fid, &f->fr_fid))
@@ -272,7 +221,9 @@ static int lsom_update_one(struct fid_rec *f)
 
        llapi_printf(LLAPI_MSG_DEBUG,
                     "record %llu:%llu, updated LSOM for fid " DFID
-                    " size:%lu blocks:%lu\n", f->fr_time, f->fr_index,
+                    " size:%lu blocks:%lu\n",
+                    (unsigned long long)f->fr_time,
+                    (unsigned long long)f->fr_index,
                     PFID(&f->fr_fid), st.st_size, st.st_blocks);
 
 clean_up:
@@ -281,7 +232,7 @@ clean_up:
        if (rc)
                llapi_error(LLAPI_MSG_ERROR, rc,
                            "failed to clear changelog record: %s:%llu",
-                           opt.o_chlg_user, f->fr_index);
+                           opt.o_chlg_user, (unsigned long long)f->fr_index);
        return rc;
 }
 
@@ -295,7 +246,7 @@ static int lsom_start_update(int count)
        while (i < count) {
                struct fid_rec *f;
 
-               f = list_entry(head.lh_list.next, struct fid_rec, fr_link);
+               f = list_first_entry(&head.lh_list, struct fid_rec, fr_link);
                rc = lsom_update_one(f);
                if (rc == 0) {
                        list_del_init(&f->fr_link);
@@ -333,7 +284,7 @@ repeated:
                 * pop the record, start to handle it immediately.
                 */
                now = time(NULL);
-               f = list_entry(head.lh_list.next, struct fid_rec, fr_link);
+               f = list_first_entry(&head.lh_list, struct fid_rec, fr_link);
                if (now > ((f->fr_time >> 30) + opt.o_min_age))
                        count = 1;
        }
@@ -404,8 +355,9 @@ static int process_record(struct changelog_rec *rec)
                }
        }
 
-       llapi_printf(LLAPI_MSG_DEBUG, "Processed changelog record index:%llu "
-                    "type:%s(0x%x) FID:"DFID"\n", index,
+       llapi_printf(LLAPI_MSG_DEBUG,
+                    "Processed changelog record index:%llu type:%s(0x%x) FID:"DFID"\n",
+                    (unsigned long long)index,
                     changelog_type2str(__le32_to_cpu(rec->cr_type)),
                     __le32_to_cpu(rec->cr_type), PFID(&rec->cr_tfid));
 
@@ -437,14 +389,15 @@ static unsigned long get_fid_cache_size(int pct)
 
 int main(int argc, char **argv)
 {
-       int                      c;
-       int                      rc;
-       void                    *chglog_hdlr;
-       struct changelog_rec    *rec;
-       bool                     stop = 0;
-       int                      ret = 0;
-       unsigned long            cache_size = DEF_CACHE_SIZE;
-       char                     fsname[MAX_OBD_NAME + 1];
+       int c;
+       int rc;
+       void *chglog_hdlr;
+       struct changelog_rec *rec;
+       bool stop = 0;
+       int ret = 0;
+       unsigned long long cache_size = DEF_CACHE_SIZE;
+       char fsname[MAX_OBD_NAME + 1];
+       unsigned long long unit;
        static struct option options[] = {
                { "mdt", required_argument, NULL, 'm' },
                { "user", required_argument, 0, 'u'},
@@ -470,7 +423,7 @@ int main(int argc, char **argv)
                default:
                        rc = -EINVAL;
                        llapi_error(LLAPI_MSG_ERROR, rc,
-                                   "%s: unknown option '-%c'\n",
+                                   "%s: unknown option '%c'",
                                    argv[0], optopt);
                        return rc;
                case 'u':
@@ -504,7 +457,8 @@ int main(int argc, char **argv)
                        }
                        break;
                case 'c':
-                       rc = Parser_size(&cache_size, optarg);
+                       unit = ONE_MB;
+                       rc = llapi_parse_size(optarg, &cache_size, &unit, 0);
                        if (rc < 0) {
                                rc = -EINVAL;
                                llapi_error(LLAPI_MSG_ERROR, rc,
@@ -517,7 +471,7 @@ int main(int argc, char **argv)
                         */
                        if (cache_size < 100)
                                cache_size = get_fid_cache_size(cache_size);
-                       llapi_printf(LLAPI_MSG_INFO, "Cache size: %lu\n",
+                       llapi_printf(LLAPI_MSG_INFO, "Cache size: %llu\n",
                                     cache_size);
                        break;
                case 'v':
@@ -579,7 +533,7 @@ int main(int argc, char **argv)
                                           opt.o_mdtname, 0);
                if (rc) {
                        llapi_error(LLAPI_MSG_ERROR, rc,
-                                   "unable to open changelog of MDT [%s]\n",
+                                   "unable to open changelog of MDT '%s'",
                                    opt.o_mdtname);
                        return rc;
                }
@@ -625,7 +579,7 @@ int main(int argc, char **argv)
                rc = llapi_changelog_fini(&chglog_hdlr);
                if (rc) {
                        llapi_error(LLAPI_MSG_ERROR, rc,
-                                   "unable to close changelog of MDT [%s]",
+                                   "unable to close changelog of MDT '%s'",
                                    opt.o_mdtname);
                        ret = rc;
                        return rc;