Whamcloud - gitweb
Branch: b_new_cmd
[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 #ifdef __KERNEL__
9 #include <linux/sched.h>
10 #else
11 struct group_info {};
12 #endif
13 */
14 #define UC_CACHE_NEW            0x01
15 #define UC_CACHE_ACQUIRING      0x02
16 #define UC_CACHE_INVALID        0x04
17 #define UC_CACHE_EXPIRED        0x08
18
19 #define UC_CACHE_IS_NEW(i)          ((i)->ue_flags & UC_CACHE_NEW)
20 #define UC_CACHE_IS_INVALID(i)      ((i)->ue_flags & UC_CACHE_INVALID)
21 #define UC_CACHE_IS_ACQUIRING(i)    ((i)->ue_flags & UC_CACHE_ACQUIRING)
22 #define UC_CACHE_IS_EXPIRED(i)      ((i)->ue_flags & UC_CACHE_EXPIRED)
23 #define UC_CACHE_IS_VALID(i)        ((i)->ue_flags == 0)
24
25 #define UC_CACHE_SET_NEW(i)         (i)->ue_flags |= UC_CACHE_NEW
26 #define UC_CACHE_SET_INVALID(i)     (i)->ue_flags |= UC_CACHE_INVALID
27 #define UC_CACHE_SET_ACQUIRING(i)   (i)->ue_flags |= UC_CACHE_ACQUIRING
28 #define UC_CACHE_SET_EXPIRED(i)     (i)->ue_flags |= UC_CACHE_EXPIRED
29 #define UC_CACHE_SET_VALID(i)       (i)->ue_flags = 0
30
31 #define UC_CACHE_CLEAR_NEW(i)       (i)->ue_flags &= ~UC_CACHE_NEW
32 #define UC_CACHE_CLEAR_ACQUIRING(i) (i)->ue_flags &= ~UC_CACHE_ACQUIRING
33 #define UC_CACHE_CLEAR_INVALID(i)   (i)->ue_flags &= ~UC_CACHE_INVALID
34 #define UC_CACHE_CLEAR_EXPIRED(i)   (i)->ue_flags &= ~UC_CACHE_EXPIRED
35
36 struct upcall_cache_entry;
37
38 struct mdt_setxid_perm {
39         lnet_nid_t      mp_nid;
40         __u32           mp_perm;
41 };
42
43 struct mdt_identity {
44         struct upcall_cache_entry *mi_uc_entry;
45         uid_t                      mi_uid;
46         gid_t                      mi_gid;
47         struct group_info         *mi_ginfo;
48         int                        mi_nperms;
49         struct mdt_setxid_perm    *mi_perms;
50 };
51
52 struct rmtacl_upcall_data {
53         uid_t                      aud_uid;
54         gid_t                      aud_gid;
55         char                      *aud_cmd;
56 };
57
58 struct mdt_rmtacl {
59         uid_t                      ra_uid;
60         gid_t                      ra_gid;
61         __u32                      ra_handle;
62         char                      *ra_cmd;
63         char                      *ra_buf;
64 };
65
66 struct upcall_cache_entry {
67         struct list_head        ue_hash;
68         __u64                   ue_key;
69 //        __u64                   ue_primary;
70 //        struct group_info      *ue_group_info;
71         atomic_t                ue_refcount;
72         int                     ue_flags;
73         cfs_waitq_t             ue_waitq;
74         cfs_time_t              ue_acquire_expire;
75         cfs_time_t              ue_expire;
76         union {
77                 struct mdt_identity     identity;
78                 struct mdt_rmtacl       acl;
79         } u;
80 };
81
82 #define UC_CACHE_HASH_SIZE        (128)
83 #define UC_CACHE_HASH_INDEX(id)   ((id) & (UC_CACHE_HASH_SIZE - 1))
84 #define UC_CACHE_UPCALL_MAXPATH   (1024UL)
85
86 struct upcall_cache;
87
88 struct upcall_cache_ops {
89         void            (*init_entry)(struct upcall_cache_entry *, void *args);
90         void            (*free_entry)(struct upcall_cache *,
91                                       struct upcall_cache_entry *);
92         int             (*upcall_compare)(struct upcall_cache *,
93                                           struct upcall_cache_entry *,
94                                           __u64 key, void *args);
95         int             (*downcall_compare)(struct upcall_cache *,
96                                             struct upcall_cache_entry *,
97                                             __u64 key, void *args);
98         int             (*do_upcall)(struct upcall_cache *,
99                                      struct upcall_cache_entry *);
100         int             (*parse_downcall)(struct upcall_cache *,
101                                           struct upcall_cache_entry *, void *);
102 };
103
104 struct upcall_cache {
105         struct list_head        uc_hashtable[UC_CACHE_HASH_SIZE];
106         spinlock_t              uc_lock;
107
108         char                    uc_name[40];            /* for upcall */
109         char                    uc_upcall[UC_CACHE_UPCALL_MAXPATH];
110         cfs_time_t              uc_acquire_expire;      /* jiffies */
111         cfs_time_t              uc_entry_expire;        /* jiffies */
112         struct upcall_cache_ops *uc_ops;
113 };
114
115 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
116                                                   __u64 key, void *args);
117 void upcall_cache_put_entry(struct upcall_cache *cache,
118                             struct upcall_cache_entry *entry);
119 int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
120                           void *args);
121 void upcall_cache_flush_idle(struct upcall_cache *cache);
122 void upcall_cache_flush_all(struct upcall_cache *cache);
123 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args);
124 struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
125                                        struct upcall_cache_ops *ops);
126 void upcall_cache_cleanup(struct upcall_cache *cache);
127
128 #if 0
129 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *hash,
130                                                   __u64 key, __u32 primary,
131                                                   __u32 ngroups, __u32 *groups);
132 void upcall_cache_put_entry(struct upcall_cache *hash,
133                             struct upcall_cache_entry *entry);
134 int upcall_cache_downcall(struct upcall_cache *hash, __u32 err, __u64 key,
135                           __u32 primary, __u32 ngroups, __u32 *groups);
136 void upcall_cache_flush_idle(struct upcall_cache *cache);
137 void upcall_cache_flush_all(struct upcall_cache *cache);
138 struct upcall_cache *upcall_cache_init(const char *name);
139 void upcall_cache_cleanup(struct upcall_cache *hash);
140
141 #endif
142 #endif /* _UPCALL_CACHE_H */