Whamcloud - gitweb
LU-1347 style: removes obsolete EXPORT_SYMTAB macros
[fs/lustre-release.git] / libcfs / include / libcfs / lucache.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #ifndef _LUCACHE_H
36 #define _LUCACHE_H
37
38 #include <libcfs/libcfs.h>
39
40 /** \defgroup ucache ucache
41  *
42  * @{
43  */
44
45 #define UC_CACHE_NEW            0x01
46 #define UC_CACHE_ACQUIRING      0x02
47 #define UC_CACHE_INVALID        0x04
48 #define UC_CACHE_EXPIRED        0x08
49
50 #define UC_CACHE_IS_NEW(i)          ((i)->ue_flags & UC_CACHE_NEW)
51 #define UC_CACHE_IS_INVALID(i)      ((i)->ue_flags & UC_CACHE_INVALID)
52 #define UC_CACHE_IS_ACQUIRING(i)    ((i)->ue_flags & UC_CACHE_ACQUIRING)
53 #define UC_CACHE_IS_EXPIRED(i)      ((i)->ue_flags & UC_CACHE_EXPIRED)
54 #define UC_CACHE_IS_VALID(i)        ((i)->ue_flags == 0)
55
56 #define UC_CACHE_SET_NEW(i)         (i)->ue_flags |= UC_CACHE_NEW
57 #define UC_CACHE_SET_INVALID(i)     (i)->ue_flags |= UC_CACHE_INVALID
58 #define UC_CACHE_SET_ACQUIRING(i)   (i)->ue_flags |= UC_CACHE_ACQUIRING
59 #define UC_CACHE_SET_EXPIRED(i)     (i)->ue_flags |= UC_CACHE_EXPIRED
60 #define UC_CACHE_SET_VALID(i)       (i)->ue_flags = 0
61
62 #define UC_CACHE_CLEAR_NEW(i)       (i)->ue_flags &= ~UC_CACHE_NEW
63 #define UC_CACHE_CLEAR_ACQUIRING(i) (i)->ue_flags &= ~UC_CACHE_ACQUIRING
64 #define UC_CACHE_CLEAR_INVALID(i)   (i)->ue_flags &= ~UC_CACHE_INVALID
65 #define UC_CACHE_CLEAR_EXPIRED(i)   (i)->ue_flags &= ~UC_CACHE_EXPIRED
66
67 struct upcall_cache_entry;
68
69 struct md_perm {
70         lnet_nid_t      mp_nid;
71         __u32           mp_perm;
72 };
73
74 struct md_identity {
75         struct upcall_cache_entry *mi_uc_entry;
76         uid_t                      mi_uid;
77         gid_t                      mi_gid;
78         cfs_group_info_t          *mi_ginfo;
79         int                        mi_nperms;
80         struct md_perm            *mi_perms;
81 };
82
83 struct upcall_cache_entry {
84         cfs_list_t              ue_hash;
85         __u64                   ue_key;
86         cfs_atomic_t            ue_refcount;
87         int                     ue_flags;
88         cfs_waitq_t             ue_waitq;
89         cfs_time_t              ue_acquire_expire;
90         cfs_time_t              ue_expire;
91         union {
92                 struct md_identity     identity;
93         } u;
94 };
95
96 #define UC_CACHE_HASH_SIZE        (128)
97 #define UC_CACHE_HASH_INDEX(id)   ((id) & (UC_CACHE_HASH_SIZE - 1))
98 #define UC_CACHE_UPCALL_MAXPATH   (1024UL)
99
100 struct upcall_cache;
101
102 struct upcall_cache_ops {
103         void            (*init_entry)(struct upcall_cache_entry *, void *args);
104         void            (*free_entry)(struct upcall_cache *,
105                                       struct upcall_cache_entry *);
106         int             (*upcall_compare)(struct upcall_cache *,
107                                           struct upcall_cache_entry *,
108                                           __u64 key, void *args);
109         int             (*downcall_compare)(struct upcall_cache *,
110                                             struct upcall_cache_entry *,
111                                             __u64 key, void *args);
112         int             (*do_upcall)(struct upcall_cache *,
113                                      struct upcall_cache_entry *);
114         int             (*parse_downcall)(struct upcall_cache *,
115                                           struct upcall_cache_entry *, void *);
116 };
117
118 struct upcall_cache {
119         cfs_list_t              uc_hashtable[UC_CACHE_HASH_SIZE];
120         cfs_spinlock_t          uc_lock;
121         cfs_rwlock_t            uc_upcall_rwlock;
122
123         char                    uc_name[40];            /* for upcall */
124         char                    uc_upcall[UC_CACHE_UPCALL_MAXPATH];
125         int                     uc_acquire_expire;      /* seconds */
126         int                     uc_entry_expire;        /* seconds */
127         struct upcall_cache_ops *uc_ops;
128 };
129
130 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
131                                                   __u64 key, void *args);
132 void upcall_cache_put_entry(struct upcall_cache *cache,
133                             struct upcall_cache_entry *entry);
134 int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
135                           void *args);
136 void upcall_cache_flush_idle(struct upcall_cache *cache);
137 void upcall_cache_flush_all(struct upcall_cache *cache);
138 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args);
139 struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
140                                        struct upcall_cache_ops *ops);
141 void upcall_cache_cleanup(struct upcall_cache *cache);
142
143 #if 0
144 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *hash,
145                                                   __u64 key, __u32 primary,
146                                                   __u32 ngroups, __u32 *groups);
147 void upcall_cache_put_entry(struct upcall_cache *hash,
148                             struct upcall_cache_entry *entry);
149 int upcall_cache_downcall(struct upcall_cache *hash, __u32 err, __u64 key,
150                           __u32 primary, __u32 ngroups, __u32 *groups);
151 void upcall_cache_flush_idle(struct upcall_cache *cache);
152 void upcall_cache_flush_all(struct upcall_cache *cache);
153 struct upcall_cache *upcall_cache_init(const char *name);
154 void upcall_cache_cleanup(struct upcall_cache *hash);
155
156 #endif
157
158 /** @} ucache */
159
160 #endif /* _LUCACHE_H */