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