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