X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;ds=sidebyside;f=lustre%2Fobdclass%2Fcapa.c;h=92335c61ea296bf4c2aa1b66d24299e60ff4f6fa;hb=f290bcc78bdb6fc235d5e0bab17c93c0de59bade;hp=24d34ec1db7f3b8312195ae7c4c201bf8bbff6e4;hpb=11d21db1c6721cef0426710b291980d31133e1ed;p=fs%2Flustre-release.git diff --git a/lustre/obdclass/capa.c b/lustre/obdclass/capa.c index 24d34ec..92335c6 100644 --- a/lustre/obdclass/capa.c +++ b/lustre/obdclass/capa.c @@ -55,6 +55,8 @@ struct hlist_head *capa_hash; struct list_head capa_list[3]; static int capa_count[3] = { 0 }; +static char *capa_type_name[] = { "client", "mds", "filter" }; + /* TODO: mdc and llite all need this, so define it here. * in the future it will be moved to ll_sb_info to support multi- * mount point */ @@ -66,10 +68,9 @@ EXPORT_SYMBOL(capa_list); EXPORT_SYMBOL(ll_capa_timer); static inline int const -capa_hashfn(unsigned int uid, int capa_op, __u64 mdsid, unsigned long ino) +capa_hashfn(unsigned int uid, __u64 mdsid, unsigned long ino) { - return (ino ^ uid) * (unsigned long)capa_op * (unsigned long)mdsid % - NR_CAPAHASH; + return (ino ^ uid) * (unsigned long)(mdsid + 1) % NR_CAPAHASH; } int capa_op(int flags) @@ -85,15 +86,19 @@ int capa_op(int flags) static struct obd_capa * find_capa(struct hlist_head *head, uid_t uid, int capa_op, __u64 mdsid, - unsigned long ino, int type) + unsigned long ino, __u32 igen, int type) { struct hlist_node *pos; struct obd_capa *ocapa; uid_t ouid; + CDEBUG(D_INODE, "find capa for (uid %u, op %d, mdsid "LPU64", ino %lu" + " igen %u, type %d\n", (unsigned) uid, capa_op, mdsid, ino, igen, type); hlist_for_each_entry(ocapa, pos, head, c_hash) { if (ocapa->c_capa.lc_ino != ino) continue; + if (ocapa->c_capa.lc_igen != igen) + continue; if (ocapa->c_capa.lc_mdsid != mdsid) continue; if ((ocapa->c_capa.lc_op & capa_op) != ocapa->c_capa.lc_op) @@ -109,7 +114,8 @@ find_capa(struct hlist_head *head, uid_t uid, int capa_op, __u64 mdsid, if (ouid != uid) continue; - DEBUG_CAPA(D_CACHE, &ocapa->c_capa, "found"); + DEBUG_CAPA(D_INODE, &ocapa->c_capa, "found %s", + capa_type_name[ocapa->c_type]); return ocapa; } @@ -125,12 +131,12 @@ inline void __capa_get(struct obd_capa *ocapa) static struct obd_capa * find_capa_locked(struct hlist_head *head, uid_t uid, int capa_op, __u64 mdsid, - unsigned long ino, int type) + unsigned long ino, __u32 igen, int type) { struct obd_capa *ocapa; spin_lock(&capa_lock); - ocapa = find_capa(head, uid, capa_op, mdsid, ino, type); + ocapa = find_capa(head, uid, capa_op, mdsid, ino, igen, type); if (ocapa) __capa_get(ocapa); spin_unlock(&capa_lock); @@ -185,13 +191,14 @@ int capa_cache_init(void) void capa_cache_cleanup(void) { - struct obd_capa *ocapa; - struct hlist_node *pos, *n; + struct obd_capa *ocapa, *tmp; + int i; - hlist_for_each_entry_safe(ocapa, pos, n, capa_hash, c_hash) { - LASSERT(ocapa->c_type != CLIENT_CAPA); - __capa_put(ocapa); - destroy_capa(ocapa); + for (i = MDS_CAPA; i <= FILTER_CAPA; i++) { + list_for_each_entry_safe(ocapa, tmp, &capa_list[i], c_list) { + __capa_put(ocapa); + destroy_capa(ocapa); + } } OBD_FREE(capa_hash, PAGE_SIZE); @@ -212,7 +219,7 @@ static inline void list_add_capa(struct obd_capa *ocapa, struct list_head *head) } } - list_add_tail(&ocapa->c_list, head); + list_add(&ocapa->c_list, head); } static inline void do_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa) @@ -234,18 +241,20 @@ get_new_capa_locked(struct hlist_head *head, int type, struct lustre_capa *capa) return NULL; spin_lock(&capa_lock); - old = find_capa(head, uid, capa_op, mdsid, ino, type); + old = find_capa(head, uid, capa_op, mdsid, ino, capa->lc_igen, type); if (!old) { do_update_capa(ocapa, capa); ocapa->c_type = type; list_add_capa(ocapa, &capa_list[type]); - hlist_add_head(&ocapa->c_hash, capa_hash); + hlist_add_head(&ocapa->c_hash, head); if (type == CLIENT_CAPA) INIT_LIST_HEAD(&ocapa->c_lli_list); + __capa_get(ocapa); capa_count[type]++; - DEBUG_CAPA(D_CACHE, &ocapa->c_capa, "new"); + DEBUG_CAPA(D_INODE, &ocapa->c_capa, "new %s", + capa_type_name[type]); if (type != CLIENT_CAPA && capa_count[type] > CAPA_CACHE_SIZE) { struct list_head *node = capa_list[type].next; @@ -259,8 +268,9 @@ get_new_capa_locked(struct hlist_head *head, int type, struct lustre_capa *capa) node = node->next; if (atomic_read(&tcapa->c_refc) > 0) continue; - DEBUG_CAPA(D_CACHE, &ocapa->c_capa, - "free unused"); + DEBUG_CAPA(D_INODE, &tcapa->c_capa, + "free unused %s", + capa_type_name[type]); __capa_put(tcapa); destroy_capa(tcapa); count++; @@ -277,13 +287,13 @@ get_new_capa_locked(struct hlist_head *head, int type, struct lustre_capa *capa) } struct obd_capa * -capa_get(uid_t uid, int capa_op,__u64 mdsid, unsigned long ino, int type) +capa_get(uid_t uid, int capa_op,__u64 mdsid, unsigned long ino, + __u32 igen, int type) { - struct hlist_head *head = capa_hash + - capa_hashfn(uid, capa_op, mdsid, ino); + struct hlist_head *head = capa_hash + capa_hashfn(uid, mdsid, ino); struct obd_capa *ocapa; - ocapa = find_capa_locked(head, uid, capa_op, mdsid, ino, type); + ocapa = find_capa_locked(head, uid, capa_op, mdsid, ino, igen, type); return ocapa; } @@ -293,7 +303,8 @@ void capa_put(struct obd_capa *ocapa) if (!ocapa) return; - DEBUG_CAPA(D_CACHE, &ocapa->c_capa, "put"); + DEBUG_CAPA(D_INODE, &ocapa->c_capa, "put %s", + capa_type_name[ocapa->c_type]); spin_lock(&capa_lock); if (ocapa->c_type == CLIENT_CAPA) { list_del_init(&ocapa->c_lli_list); @@ -305,20 +316,22 @@ void capa_put(struct obd_capa *ocapa) spin_unlock(&capa_lock); } -static struct obd_capa *update_capa_locked(struct lustre_capa *capa, int type) +struct obd_capa *capa_renew(struct lustre_capa *capa, int type) { uid_t uid = capa->lc_uid; int capa_op = capa->lc_op; __u64 mdsid = capa->lc_mdsid; unsigned long ino = capa->lc_ino; struct hlist_head *head = capa_hash + - capa_hashfn(uid, capa_op, mdsid, ino); + capa_hashfn(uid, mdsid, ino); struct obd_capa *ocapa; spin_lock(&capa_lock); - ocapa = find_capa(head, uid, capa_op, mdsid, ino, type); - if (ocapa) + ocapa = find_capa(head, uid, capa_op, mdsid, ino, capa->lc_igen, type); + if (ocapa) { + DEBUG_CAPA(D_INFO, capa, "renew %s", capa_type_name[type]); do_update_capa(ocapa, capa); + } spin_unlock(&capa_lock); if (!ocapa) @@ -327,13 +340,6 @@ static struct obd_capa *update_capa_locked(struct lustre_capa *capa, int type) return ocapa; } -struct obd_capa *capa_renew(struct lustre_capa *capa, int type) -{ - DEBUG_CAPA(D_INFO, capa, "renew"); - - return update_capa_locked(capa, type); -} - void capa_hmac(struct crypto_tfm *tfm, __u8 *key, struct lustre_capa *capa) { int keylen = CAPA_KEY_LEN; @@ -366,24 +372,27 @@ int capa_expired(struct lustre_capa *capa) struct timeval tv; do_gettimeofday(&tv); - return (capa->lc_expiry < tv.tv_sec) ? 1 : 0; + return ((unsigned long )capa->lc_expiry <= tv.tv_sec) ? 1 : 0; } -int __capa_is_to_expire(struct obd_capa *ocapa) +int __capa_is_to_expire(struct obd_capa *ocapa, struct timeval *tv) { - struct timeval tv; int pre_expiry = capa_pre_expiry(&ocapa->c_capa); - do_gettimeofday(&tv); - return (ocapa->c_capa.lc_expiry - pre_expiry - 1 <= tv.tv_sec)? 1 : 0; + /* XXX: in case the clock is inaccurate, minus one more + * pre_expiry to make sure the expiry won't miss */ + return ((unsigned long)ocapa->c_capa.lc_expiry - + 2 * pre_expiry <= tv->tv_sec)? 1 : 0; } int capa_is_to_expire(struct obd_capa *ocapa) { + struct timeval tv; int rc; + do_gettimeofday(&tv); spin_lock(&capa_lock); - rc = __capa_is_to_expire(ocapa); + rc = __capa_is_to_expire(ocapa, &tv); spin_unlock(&capa_lock); return rc;