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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #ifndef _UPCALL_CACHE_H
33 #define _UPCALL_CACHE_H
35 #include <libcfs/libcfs.h>
36 #include <uapi/linux/lnet/lnet-types.h>
37 #include <uapi/linux/lustre/lustre_disk.h>
39 #include <lustre_sec.h>
41 /** \defgroup ucache ucache
46 #define UC_CACHE_NEW 0x01
47 #define UC_CACHE_ACQUIRING 0x02
48 #define UC_CACHE_INVALID 0x04
49 #define UC_CACHE_EXPIRED 0x08
51 #define UC_CACHE_IS_NEW(i) ((i)->ue_flags & UC_CACHE_NEW)
52 #define UC_CACHE_IS_INVALID(i) ((i)->ue_flags & UC_CACHE_INVALID)
53 #define UC_CACHE_IS_ACQUIRING(i) ((i)->ue_flags & UC_CACHE_ACQUIRING)
54 #define UC_CACHE_IS_EXPIRED(i) ((i)->ue_flags & UC_CACHE_EXPIRED)
55 #define UC_CACHE_IS_VALID(i) ((i)->ue_flags == 0)
57 #define UC_CACHE_SET_NEW(i) ((i)->ue_flags |= UC_CACHE_NEW)
58 #define UC_CACHE_SET_INVALID(i) ((i)->ue_flags |= UC_CACHE_INVALID)
59 #define UC_CACHE_SET_ACQUIRING(i) ((i)->ue_flags |= UC_CACHE_ACQUIRING)
60 #define UC_CACHE_SET_EXPIRED(i) ((i)->ue_flags |= UC_CACHE_EXPIRED)
61 #define UC_CACHE_SET_VALID(i) ((i)->ue_flags = 0)
63 #define UC_CACHE_CLEAR_NEW(i) ((i)->ue_flags &= ~UC_CACHE_NEW)
64 #define UC_CACHE_CLEAR_ACQUIRING(i) ((i)->ue_flags &= ~UC_CACHE_ACQUIRING)
65 #define UC_CACHE_CLEAR_INVALID(i) ((i)->ue_flags &= ~UC_CACHE_INVALID)
66 #define UC_CACHE_CLEAR_EXPIRED(i) ((i)->ue_flags &= ~UC_CACHE_EXPIRED)
68 struct upcall_cache_entry;
71 struct lnet_nid mp_nid;
76 struct upcall_cache_entry *mi_uc_entry;
79 struct group_info *mi_ginfo;
81 struct md_perm *mi_perms;
85 struct upcall_cache_entry *si_uc_entry;
86 lnet_nid_t si_nid4; /* FIXME Support larger NID */
87 char si_nm_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
89 rawobj_t si_in_handle;
91 rawobj_t si_out_handle;
92 rawobj_t si_out_token;
98 struct upcall_cache_entry *sc_uc_entry;
99 struct obd_device *sc_target;
101 struct gss_svc_ctx sc_ctx;
104 struct upcall_cache_entry {
105 struct list_head ue_hash;
107 atomic_t ue_refcount;
109 wait_queue_head_t ue_waitq;
110 time64_t ue_acquire_expire;
113 struct md_identity identity;
119 #define UC_CACHE_HASH_INDEX(id, size) ((id) & ((size) - 1))
120 #define UC_CACHE_UPCALL_MAXPATH (1024UL)
124 struct upcall_cache_ops {
125 void (*init_entry)(struct upcall_cache_entry *, void *args);
126 void (*free_entry)(struct upcall_cache *,
127 struct upcall_cache_entry *);
128 int (*upcall_compare)(struct upcall_cache *,
129 struct upcall_cache_entry *,
130 __u64 key, void *args);
131 int (*downcall_compare)(struct upcall_cache *,
132 struct upcall_cache_entry *,
133 __u64 key, void *args);
134 int (*do_upcall)(struct upcall_cache *,
135 struct upcall_cache_entry *);
136 int (*parse_downcall)(struct upcall_cache *,
137 struct upcall_cache_entry *, void *);
140 struct upcall_cache {
141 struct list_head *uc_hashtable;
144 struct rw_semaphore uc_upcall_rwsem;
146 char uc_name[40]; /* for upcall */
147 char uc_upcall[UC_CACHE_UPCALL_MAXPATH];
148 bool uc_acquire_replay;
149 time64_t uc_acquire_expire; /* seconds */
150 time64_t uc_entry_expire; /* seconds */
151 struct upcall_cache_ops *uc_ops;
154 int upcall_cache_set_upcall(struct upcall_cache *cache, const char *buffer,
155 size_t count, bool path_only);
156 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
157 __u64 key, void *args);
158 void upcall_cache_get_entry_raw(struct upcall_cache_entry *entry);
159 void upcall_cache_update_entry(struct upcall_cache *cache,
160 struct upcall_cache_entry *entry,
161 time64_t expire, int state);
162 void upcall_cache_put_entry(struct upcall_cache *cache,
163 struct upcall_cache_entry *entry);
164 int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
166 void upcall_cache_flush(struct upcall_cache *cache, int force);
168 static inline void upcall_cache_flush_idle(struct upcall_cache *cache)
170 upcall_cache_flush(cache, 0);
173 static inline void upcall_cache_flush_all(struct upcall_cache *cache)
175 upcall_cache_flush(cache, 1);
178 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args);
179 struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
180 int hashsz, time64_t entry_expire,
181 time64_t acquire_expire, bool replayable,
182 struct upcall_cache_ops *ops);
183 void upcall_cache_cleanup(struct upcall_cache *cache);
187 #endif /* _UPCALL_CACHE_H */