#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); \
#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;
#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 */
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 &&
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)
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))
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);
* 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;
}
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'},
}
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,
*/
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':