Whamcloud - gitweb
68e37db4bd1bf68eb1d9159293a91bd94934e9f7
[fs/lustre-release.git] / lustre / include / linux / 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;
31
32 struct upcall_cache_entry {
33         struct list_head        ue_hash;
34         atomic_t                ue_refcount;
35         __u64                   ue_key;
36         struct upcall_cache    *ue_cache;
37         int                     ue_flags;
38         wait_queue_head_t       ue_waitq;
39         unsigned long           ue_acquire_expire;
40         unsigned long           ue_expire;
41 };
42
43 #define UC_CACHE_UPCALL_MAXPATH (1024)
44
45 struct upcall_cache {
46         struct list_head       *uc_hashtable;
47         int                     uc_hashsize;
48         rwlock_t                uc_hashlock;
49
50         char                   *uc_name;
51         char                    uc_upcall[UC_CACHE_UPCALL_MAXPATH];
52         unsigned long           uc_acquire_expire;
53         unsigned long           uc_entry_expire;
54
55         /* functions */
56         unsigned int                (*hash)(struct upcall_cache *, __u64);
57         struct upcall_cache_entry*  (*alloc_entry)(struct upcall_cache *, __u64);
58         void                        (*free_entry)(struct upcall_cache *,
59                                                   struct upcall_cache_entry *);
60         int                         (*make_upcall)(struct upcall_cache *,
61                                                    struct upcall_cache_entry *);
62         int                         (*parse_downcall)(struct upcall_cache *,
63                                                       struct upcall_cache_entry *,
64                                                       void *args);
65 };
66
67 void upcall_cache_init_entry(struct upcall_cache *cache,
68                              struct upcall_cache_entry *entry,
69                              __u64 key);
70 struct upcall_cache_entry *
71 upcall_cache_get_entry(struct upcall_cache *cache, __u64 key);
72 void upcall_cache_put_entry(struct upcall_cache_entry *entry);
73 int upcall_cache_downcall(struct upcall_cache *cache, __u64 key,
74                           int err, void *args);
75 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key);
76 void upcall_cache_flush_idle(struct upcall_cache *cache);
77 void upcall_cache_flush_all(struct upcall_cache *cache);
78
79 #endif /* _UPCALL_CACHE_H */