Whamcloud - gitweb
LU-1347 build: remove the vim/emacs modelines
[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 #ifndef EXPORT_SYMTAB
39 # define EXPORT_SYMTAB
40 #endif
41
42 #include <libcfs/libcfs.h>
43
44 /** \defgroup ucache ucache
45  *
46  * @{
47  */
48
49 #define UC_CACHE_NEW            0x01
50 #define UC_CACHE_ACQUIRING      0x02
51 #define UC_CACHE_INVALID        0x04
52 #define UC_CACHE_EXPIRED        0x08
53
54 #define UC_CACHE_IS_NEW(i)          ((i)->ue_flags & UC_CACHE_NEW)
55 #define UC_CACHE_IS_INVALID(i)      ((i)->ue_flags & UC_CACHE_INVALID)
56 #define UC_CACHE_IS_ACQUIRING(i)    ((i)->ue_flags & UC_CACHE_ACQUIRING)
57 #define UC_CACHE_IS_EXPIRED(i)      ((i)->ue_flags & UC_CACHE_EXPIRED)
58 #define UC_CACHE_IS_VALID(i)        ((i)->ue_flags == 0)
59
60 #define UC_CACHE_SET_NEW(i)         (i)->ue_flags |= UC_CACHE_NEW
61 #define UC_CACHE_SET_INVALID(i)     (i)->ue_flags |= UC_CACHE_INVALID
62 #define UC_CACHE_SET_ACQUIRING(i)   (i)->ue_flags |= UC_CACHE_ACQUIRING
63 #define UC_CACHE_SET_EXPIRED(i)     (i)->ue_flags |= UC_CACHE_EXPIRED
64 #define UC_CACHE_SET_VALID(i)       (i)->ue_flags = 0
65
66 #define UC_CACHE_CLEAR_NEW(i)       (i)->ue_flags &= ~UC_CACHE_NEW
67 #define UC_CACHE_CLEAR_ACQUIRING(i) (i)->ue_flags &= ~UC_CACHE_ACQUIRING
68 #define UC_CACHE_CLEAR_INVALID(i)   (i)->ue_flags &= ~UC_CACHE_INVALID
69 #define UC_CACHE_CLEAR_EXPIRED(i)   (i)->ue_flags &= ~UC_CACHE_EXPIRED
70
71 struct upcall_cache_entry;
72
73 struct md_perm {
74         lnet_nid_t      mp_nid;
75         __u32           mp_perm;
76 };
77
78 struct md_identity {
79         struct upcall_cache_entry *mi_uc_entry;
80         uid_t                      mi_uid;
81         gid_t                      mi_gid;
82         cfs_group_info_t          *mi_ginfo;
83         int                        mi_nperms;
84         struct md_perm            *mi_perms;
85 };
86
87 struct upcall_cache_entry {
88         cfs_list_t              ue_hash;
89         __u64                   ue_key;
90         cfs_atomic_t            ue_refcount;
91         int                     ue_flags;
92         cfs_waitq_t             ue_waitq;
93         cfs_time_t              ue_acquire_expire;
94         cfs_time_t              ue_expire;
95         union {
96                 struct md_identity     identity;
97         } u;
98 };
99
100 #define UC_CACHE_HASH_SIZE        (128)
101 #define UC_CACHE_HASH_INDEX(id)   ((id) & (UC_CACHE_HASH_SIZE - 1))
102 #define UC_CACHE_UPCALL_MAXPATH   (1024UL)
103
104 struct upcall_cache;
105
106 struct upcall_cache_ops {
107         void            (*init_entry)(struct upcall_cache_entry *, void *args);
108         void            (*free_entry)(struct upcall_cache *,
109                                       struct upcall_cache_entry *);
110         int             (*upcall_compare)(struct upcall_cache *,
111                                           struct upcall_cache_entry *,
112                                           __u64 key, void *args);
113         int             (*downcall_compare)(struct upcall_cache *,
114                                             struct upcall_cache_entry *,
115                                             __u64 key, void *args);
116         int             (*do_upcall)(struct upcall_cache *,
117                                      struct upcall_cache_entry *);
118         int             (*parse_downcall)(struct upcall_cache *,
119                                           struct upcall_cache_entry *, void *);
120 };
121
122 struct upcall_cache {
123         cfs_list_t              uc_hashtable[UC_CACHE_HASH_SIZE];
124         cfs_spinlock_t          uc_lock;
125         cfs_rwlock_t            uc_upcall_rwlock;
126
127         char                    uc_name[40];            /* for upcall */
128         char                    uc_upcall[UC_CACHE_UPCALL_MAXPATH];
129         int                     uc_acquire_expire;      /* seconds */
130         int                     uc_entry_expire;        /* seconds */
131         struct upcall_cache_ops *uc_ops;
132 };
133
134 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
135                                                   __u64 key, void *args);
136 void upcall_cache_put_entry(struct upcall_cache *cache,
137                             struct upcall_cache_entry *entry);
138 int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
139                           void *args);
140 void upcall_cache_flush_idle(struct upcall_cache *cache);
141 void upcall_cache_flush_all(struct upcall_cache *cache);
142 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args);
143 struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
144                                        struct upcall_cache_ops *ops);
145 void upcall_cache_cleanup(struct upcall_cache *cache);
146
147 #if 0
148 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *hash,
149                                                   __u64 key, __u32 primary,
150                                                   __u32 ngroups, __u32 *groups);
151 void upcall_cache_put_entry(struct upcall_cache *hash,
152                             struct upcall_cache_entry *entry);
153 int upcall_cache_downcall(struct upcall_cache *hash, __u32 err, __u64 key,
154                           __u32 primary, __u32 ngroups, __u32 *groups);
155 void upcall_cache_flush_idle(struct upcall_cache *cache);
156 void upcall_cache_flush_all(struct upcall_cache *cache);
157 struct upcall_cache *upcall_cache_init(const char *name);
158 void upcall_cache_cleanup(struct upcall_cache *hash);
159
160 #endif
161
162 /** @} ucache */
163
164 #endif /* _LUCACHE_H */