Whamcloud - gitweb
b=13557
[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
32 struct mdt_setxid_perm {
33         lnet_nid_t      mp_nid;
34         __u32           mp_perm;
35 };
36
37 struct mdt_identity {
38         struct upcall_cache_entry *mi_uc_entry;
39         uid_t                      mi_uid;
40         gid_t                      mi_gid;
41         struct group_info         *mi_ginfo;
42         int                        mi_nperms;
43         struct mdt_setxid_perm    *mi_perms;
44 };
45
46 struct rmtacl_upcall_data {
47         uid_t                      aud_uid;
48         gid_t                      aud_gid;
49         char                      *aud_cmd;
50 };
51
52 struct mdt_rmtacl {
53         uid_t                      ra_uid;
54         gid_t                      ra_gid;
55         __u32                      ra_handle;
56         char                      *ra_cmd;
57         char                      *ra_buf;
58 };
59
60 struct upcall_cache_entry {
61         struct list_head        ue_hash;
62         __u64                   ue_key;
63 //        __u64                   ue_primary;
64 //        struct group_info      *ue_group_info;
65         atomic_t                ue_refcount;
66         int                     ue_flags;
67         cfs_waitq_t             ue_waitq;
68         cfs_time_t              ue_acquire_expire;
69         cfs_time_t              ue_expire;
70         union {
71                 struct mdt_identity     identity;
72                 struct mdt_rmtacl       acl;
73         } u;
74 };
75
76 #define UC_CACHE_HASH_SIZE        (128)
77 #define UC_CACHE_HASH_INDEX(id)   ((id) & (UC_CACHE_HASH_SIZE - 1))
78 #define UC_CACHE_UPCALL_MAXPATH   (1024UL)
79
80 struct upcall_cache;
81
82 struct upcall_cache_ops {
83         void            (*init_entry)(struct upcall_cache_entry *, void *args);
84         void            (*free_entry)(struct upcall_cache *,
85                                       struct upcall_cache_entry *);
86         int             (*upcall_compare)(struct upcall_cache *,
87                                           struct upcall_cache_entry *,
88                                           __u64 key, void *args);
89         int             (*downcall_compare)(struct upcall_cache *,
90                                             struct upcall_cache_entry *,
91                                             __u64 key, void *args);
92         int             (*do_upcall)(struct upcall_cache *,
93                                      struct upcall_cache_entry *);
94         int             (*parse_downcall)(struct upcall_cache *,
95                                           struct upcall_cache_entry *, void *);
96 };
97
98 struct upcall_cache {
99         struct list_head        uc_hashtable[UC_CACHE_HASH_SIZE];
100         spinlock_t              uc_lock;
101
102         char                    uc_name[40];            /* for upcall */
103         char                    uc_upcall[UC_CACHE_UPCALL_MAXPATH];
104         cfs_time_t              uc_acquire_expire;      /* jiffies */
105         cfs_time_t              uc_entry_expire;        /* jiffies */
106         struct upcall_cache_ops *uc_ops;
107 };
108
109 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
110                                                   __u64 key, void *args);
111 void upcall_cache_put_entry(struct upcall_cache *cache,
112                             struct upcall_cache_entry *entry);
113 int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
114                           void *args);
115 void upcall_cache_flush_idle(struct upcall_cache *cache);
116 void upcall_cache_flush_all(struct upcall_cache *cache);
117 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args);
118 struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
119                                        struct upcall_cache_ops *ops);
120 void upcall_cache_cleanup(struct upcall_cache *cache);
121
122 #if 0
123 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *hash,
124                                                   __u64 key, __u32 primary,
125                                                   __u32 ngroups, __u32 *groups);
126 void upcall_cache_put_entry(struct upcall_cache *hash,
127                             struct upcall_cache_entry *entry);
128 int upcall_cache_downcall(struct upcall_cache *hash, __u32 err, __u64 key,
129                           __u32 primary, __u32 ngroups, __u32 *groups);
130 void upcall_cache_flush_idle(struct upcall_cache *cache);
131 void upcall_cache_flush_all(struct upcall_cache *cache);
132 struct upcall_cache *upcall_cache_init(const char *name);
133 void upcall_cache_cleanup(struct upcall_cache *hash);
134
135 #endif
136 #endif /* _UPCALL_CACHE_H */