1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef _UPCALL_CACHE_H
38 #define _UPCALL_CACHE_H
40 #define UC_CACHE_NEW 0x01
41 #define UC_CACHE_ACQUIRING 0x02
42 #define UC_CACHE_INVALID 0x04
43 #define UC_CACHE_EXPIRED 0x08
45 #define UC_CACHE_IS_NEW(i) ((i)->ue_flags & UC_CACHE_NEW)
46 #define UC_CACHE_IS_INVALID(i) ((i)->ue_flags & UC_CACHE_INVALID)
47 #define UC_CACHE_IS_ACQUIRING(i) ((i)->ue_flags & UC_CACHE_ACQUIRING)
48 #define UC_CACHE_IS_EXPIRED(i) ((i)->ue_flags & UC_CACHE_EXPIRED)
49 #define UC_CACHE_IS_VALID(i) ((i)->ue_flags == 0)
51 #define UC_CACHE_SET_NEW(i) (i)->ue_flags |= UC_CACHE_NEW
52 #define UC_CACHE_SET_INVALID(i) (i)->ue_flags |= UC_CACHE_INVALID
53 #define UC_CACHE_SET_ACQUIRING(i) (i)->ue_flags |= UC_CACHE_ACQUIRING
54 #define UC_CACHE_SET_EXPIRED(i) (i)->ue_flags |= UC_CACHE_EXPIRED
55 #define UC_CACHE_SET_VALID(i) (i)->ue_flags = 0
57 #define UC_CACHE_CLEAR_NEW(i) (i)->ue_flags &= ~UC_CACHE_NEW
58 #define UC_CACHE_CLEAR_ACQUIRING(i) (i)->ue_flags &= ~UC_CACHE_ACQUIRING
59 #define UC_CACHE_CLEAR_INVALID(i) (i)->ue_flags &= ~UC_CACHE_INVALID
60 #define UC_CACHE_CLEAR_EXPIRED(i) (i)->ue_flags &= ~UC_CACHE_EXPIRED
62 struct upcall_cache_entry;
70 struct upcall_cache_entry *mi_uc_entry;
73 cfs_group_info_t *mi_ginfo;
75 struct md_perm *mi_perms;
78 struct upcall_cache_entry {
81 cfs_atomic_t ue_refcount;
84 cfs_time_t ue_acquire_expire;
87 struct md_identity identity;
91 #define UC_CACHE_HASH_SIZE (128)
92 #define UC_CACHE_HASH_INDEX(id) ((id) & (UC_CACHE_HASH_SIZE - 1))
93 #define UC_CACHE_UPCALL_MAXPATH (1024UL)
97 struct upcall_cache_ops {
98 void (*init_entry)(struct upcall_cache_entry *, void *args);
99 void (*free_entry)(struct upcall_cache *,
100 struct upcall_cache_entry *);
101 int (*upcall_compare)(struct upcall_cache *,
102 struct upcall_cache_entry *,
103 __u64 key, void *args);
104 int (*downcall_compare)(struct upcall_cache *,
105 struct upcall_cache_entry *,
106 __u64 key, void *args);
107 int (*do_upcall)(struct upcall_cache *,
108 struct upcall_cache_entry *);
109 int (*parse_downcall)(struct upcall_cache *,
110 struct upcall_cache_entry *, void *);
113 struct upcall_cache {
114 cfs_list_t uc_hashtable[UC_CACHE_HASH_SIZE];
115 cfs_spinlock_t uc_lock;
116 cfs_rwlock_t uc_upcall_rwlock;
118 char uc_name[40]; /* for upcall */
119 char uc_upcall[UC_CACHE_UPCALL_MAXPATH];
120 cfs_time_t uc_acquire_expire; /* jiffies */
121 cfs_time_t uc_entry_expire; /* jiffies */
122 struct upcall_cache_ops *uc_ops;
125 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
126 __u64 key, void *args);
127 void upcall_cache_put_entry(struct upcall_cache *cache,
128 struct upcall_cache_entry *entry);
129 int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
131 void upcall_cache_flush_idle(struct upcall_cache *cache);
132 void upcall_cache_flush_all(struct upcall_cache *cache);
133 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args);
134 struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
135 struct upcall_cache_ops *ops);
136 void upcall_cache_cleanup(struct upcall_cache *cache);
139 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *hash,
140 __u64 key, __u32 primary,
141 __u32 ngroups, __u32 *groups);
142 void upcall_cache_put_entry(struct upcall_cache *hash,
143 struct upcall_cache_entry *entry);
144 int upcall_cache_downcall(struct upcall_cache *hash, __u32 err, __u64 key,
145 __u32 primary, __u32 ngroups, __u32 *groups);
146 void upcall_cache_flush_idle(struct upcall_cache *cache);
147 void upcall_cache_flush_all(struct upcall_cache *cache);
148 struct upcall_cache *upcall_cache_init(const char *name);
149 void upcall_cache_cleanup(struct upcall_cache *hash);
152 #endif /* _UPCALL_CACHE_H */