Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / include / lustre_ucache.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 #ifndef _UPCALL_CACHE_H
6 #define _UPCALL_CACHE_H
7
8 #define UC_CACHE_NEW            0x01
9 #define UC_CACHE_ACQUIRING      0x02
10 #define UC_CACHE_INVALID        0x04
11 #define UC_CACHE_EXPIRED        0x08
12
13 #define UC_CACHE_IS_NEW(i)          ((i)->ue_flags & UC_CACHE_NEW)
14 #define UC_CACHE_IS_INVALID(i)      ((i)->ue_flags & UC_CACHE_INVALID)
15 #define UC_CACHE_IS_ACQUIRING(i)    ((i)->ue_flags & UC_CACHE_ACQUIRING)
16 #define UC_CACHE_IS_EXPIRED(i)      ((i)->ue_flags & UC_CACHE_EXPIRED)
17 #define UC_CACHE_IS_VALID(i)        ((i)->ue_flags == 0)
18
19 #define UC_CACHE_SET_NEW(i)         (i)->ue_flags |= UC_CACHE_NEW
20 #define UC_CACHE_SET_INVALID(i)     (i)->ue_flags |= UC_CACHE_INVALID
21 #define UC_CACHE_SET_ACQUIRING(i)   (i)->ue_flags |= UC_CACHE_ACQUIRING
22 #define UC_CACHE_SET_EXPIRED(i)     (i)->ue_flags |= UC_CACHE_EXPIRED
23 #define UC_CACHE_SET_VALID(i)       (i)->ue_flags = 0
24
25 #define UC_CACHE_CLEAR_NEW(i)       (i)->ue_flags &= ~UC_CACHE_NEW
26 #define UC_CACHE_CLEAR_ACQUIRING(i) (i)->ue_flags &= ~UC_CACHE_ACQUIRING
27 #define UC_CACHE_CLEAR_INVALID(i)   (i)->ue_flags &= ~UC_CACHE_INVALID
28 #define UC_CACHE_CLEAR_EXPIRED(i)   (i)->ue_flags &= ~UC_CACHE_EXPIRED
29
30 struct upcall_cache_entry {
31         struct list_head        ue_hash;
32         __u64                   ue_key;
33         __u64                   ue_primary;
34         struct group_info      *ue_group_info;
35         atomic_t                ue_refcount;
36         int                     ue_flags;
37         cfs_waitq_t             ue_waitq;
38         cfs_time_t              ue_acquire_expire;
39         cfs_time_t              ue_expire;
40 };
41
42 #define UC_CACHE_HASH_SIZE        (128)
43 #define UC_CACHE_HASH_INDEX(id)   ((id) & (UC_CACHE_HASH_SIZE - 1))
44 #define UC_CACHE_UPCALL_MAXPATH   (1024UL)
45
46 struct upcall_cache {
47         struct list_head        uc_hashtable[UC_CACHE_HASH_SIZE];
48         spinlock_t              uc_lock;
49
50         char                    uc_name[40];            /* for upcall */
51         char                    uc_upcall[UC_CACHE_UPCALL_MAXPATH];
52         cfs_time_t              uc_acquire_expire;      /* jiffies */
53         cfs_time_t              uc_entry_expire;        /* jiffies */
54 };
55
56 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *hash,
57                                                   __u64 key, __u32 primary,
58                                                   __u32 ngroups, __u32 *groups);
59 void upcall_cache_put_entry(struct upcall_cache *hash,
60                             struct upcall_cache_entry *entry);
61 int upcall_cache_downcall(struct upcall_cache *hash, __u32 err, __u64 key,
62                           __u32 primary, __u32 ngroups, __u32 *groups);
63 void upcall_cache_flush_idle(struct upcall_cache *cache);
64 void upcall_cache_flush_all(struct upcall_cache *cache);
65 struct upcall_cache *upcall_cache_init(const char *name);
66 void upcall_cache_cleanup(struct upcall_cache *hash);
67
68 #endif /* _UPCALL_CACHE_H */