4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2014, Intel Corporation.
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 #include <libcfs/libcfs.h>
41 #include <lnet/types.h>
43 /** \defgroup ucache ucache
48 #define UC_CACHE_NEW 0x01
49 #define UC_CACHE_ACQUIRING 0x02
50 #define UC_CACHE_INVALID 0x04
51 #define UC_CACHE_EXPIRED 0x08
53 #define UC_CACHE_IS_NEW(i) ((i)->ue_flags & UC_CACHE_NEW)
54 #define UC_CACHE_IS_INVALID(i) ((i)->ue_flags & UC_CACHE_INVALID)
55 #define UC_CACHE_IS_ACQUIRING(i) ((i)->ue_flags & UC_CACHE_ACQUIRING)
56 #define UC_CACHE_IS_EXPIRED(i) ((i)->ue_flags & UC_CACHE_EXPIRED)
57 #define UC_CACHE_IS_VALID(i) ((i)->ue_flags == 0)
59 #define UC_CACHE_SET_NEW(i) ((i)->ue_flags |= UC_CACHE_NEW)
60 #define UC_CACHE_SET_INVALID(i) ((i)->ue_flags |= UC_CACHE_INVALID)
61 #define UC_CACHE_SET_ACQUIRING(i) ((i)->ue_flags |= UC_CACHE_ACQUIRING)
62 #define UC_CACHE_SET_EXPIRED(i) ((i)->ue_flags |= UC_CACHE_EXPIRED)
63 #define UC_CACHE_SET_VALID(i) ((i)->ue_flags = 0)
65 #define UC_CACHE_CLEAR_NEW(i) ((i)->ue_flags &= ~UC_CACHE_NEW)
66 #define UC_CACHE_CLEAR_ACQUIRING(i) ((i)->ue_flags &= ~UC_CACHE_ACQUIRING)
67 #define UC_CACHE_CLEAR_INVALID(i) ((i)->ue_flags &= ~UC_CACHE_INVALID)
68 #define UC_CACHE_CLEAR_EXPIRED(i) ((i)->ue_flags &= ~UC_CACHE_EXPIRED)
70 struct upcall_cache_entry;
78 struct upcall_cache_entry *mi_uc_entry;
81 struct group_info *mi_ginfo;
83 struct md_perm *mi_perms;
86 struct upcall_cache_entry {
87 struct list_head ue_hash;
91 wait_queue_head_t ue_waitq;
92 cfs_time_t ue_acquire_expire;
95 struct md_identity identity;
99 #define UC_CACHE_HASH_SIZE (128)
100 #define UC_CACHE_HASH_INDEX(id) ((id) & (UC_CACHE_HASH_SIZE - 1))
101 #define UC_CACHE_UPCALL_MAXPATH (1024UL)
105 struct upcall_cache_ops {
106 void (*init_entry)(struct upcall_cache_entry *, void *args);
107 void (*free_entry)(struct upcall_cache *,
108 struct upcall_cache_entry *);
109 int (*upcall_compare)(struct upcall_cache *,
110 struct upcall_cache_entry *,
111 __u64 key, void *args);
112 int (*downcall_compare)(struct upcall_cache *,
113 struct upcall_cache_entry *,
114 __u64 key, void *args);
115 int (*do_upcall)(struct upcall_cache *,
116 struct upcall_cache_entry *);
117 int (*parse_downcall)(struct upcall_cache *,
118 struct upcall_cache_entry *, void *);
121 struct upcall_cache {
122 struct list_head uc_hashtable[UC_CACHE_HASH_SIZE];
124 rwlock_t uc_upcall_rwlock;
126 char uc_name[40]; /* for upcall */
127 char uc_upcall[UC_CACHE_UPCALL_MAXPATH];
128 int uc_acquire_expire; /* seconds */
129 int uc_entry_expire; /* seconds */
130 struct upcall_cache_ops *uc_ops;
133 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
134 __u64 key, void *args);
135 void upcall_cache_put_entry(struct upcall_cache *cache,
136 struct upcall_cache_entry *entry);
137 int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
139 void upcall_cache_flush(struct upcall_cache *cache, int force);
141 static inline void upcall_cache_flush_idle(struct upcall_cache *cache)
143 upcall_cache_flush(cache, 0);
146 static inline void upcall_cache_flush_all(struct upcall_cache *cache)
148 upcall_cache_flush(cache, 1);
151 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args);
152 struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
153 struct upcall_cache_ops *ops);
154 void upcall_cache_cleanup(struct upcall_cache *cache);
158 #endif /* _UPCALL_CACHE_H */