Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / lustre / include / upcall_cache.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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #ifndef _UPCALL_CACHE_H
33 #define _UPCALL_CACHE_H
34
35 #include <libcfs/libcfs.h>
36 #include <uapi/linux/lnet/lnet-types.h>
37 #include <uapi/linux/lustre/lustre_disk.h>
38 #include <obd.h>
39 #include <lustre_sec.h>
40
41 /** \defgroup ucache ucache
42  *
43  * @{
44  */
45
46 #define UC_CACHE_NEW            0x01
47 #define UC_CACHE_ACQUIRING      0x02
48 #define UC_CACHE_INVALID        0x04
49 #define UC_CACHE_EXPIRED        0x08
50
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)
56
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)
62
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)
67
68 struct upcall_cache_entry;
69
70 struct md_perm {
71         struct lnet_nid mp_nid;
72         uint32_t        mp_perm;
73 };
74
75 struct md_identity {
76         struct upcall_cache_entry *mi_uc_entry;
77         uid_t                      mi_uid;
78         gid_t                      mi_gid;
79         struct group_info          *mi_ginfo;
80         int                        mi_nperms;
81         struct md_perm            *mi_perms;
82 };
83
84 struct gss_rsi {
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];
88         __u32                      si_lustre_svc;
89         rawobj_t                   si_in_handle;
90         rawobj_t                   si_in_token;
91         rawobj_t                   si_out_handle;
92         rawobj_t                   si_out_token;
93         int                        si_major_status;
94         int                        si_minor_status;
95 };
96
97 struct gss_rsc {
98         struct upcall_cache_entry *sc_uc_entry;
99         struct obd_device         *sc_target;
100         rawobj_t                   sc_handle;
101         struct gss_svc_ctx         sc_ctx;
102 };
103
104 struct upcall_cache_entry {
105         struct list_head        ue_hash;
106         uint64_t                ue_key;
107         atomic_t                ue_refcount;
108         int                     ue_flags;
109         wait_queue_head_t       ue_waitq;
110         time64_t                ue_acquire_expire;
111         time64_t                ue_expire;
112         union {
113                 struct md_identity      identity;
114                 struct gss_rsi          rsi;
115                 struct gss_rsc          rsc;
116         } u;
117 };
118
119 #define UC_CACHE_HASH_INDEX(id, size)   ((id) & ((size) - 1))
120 #define UC_CACHE_UPCALL_MAXPATH   (1024UL)
121
122 struct upcall_cache;
123
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 *);
138 };
139
140 struct upcall_cache {
141         struct list_head        *uc_hashtable;
142         int                     uc_hashsize;
143         rwlock_t                uc_lock;
144         struct rw_semaphore     uc_upcall_rwsem;
145
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;
152 };
153
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,
165                           void *args);
166 void upcall_cache_flush(struct upcall_cache *cache, int force);
167
168 static inline void upcall_cache_flush_idle(struct upcall_cache *cache)
169 {
170         upcall_cache_flush(cache, 0);
171 }
172
173 static inline void upcall_cache_flush_all(struct upcall_cache *cache)
174 {
175         upcall_cache_flush(cache, 1);
176 }
177
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);
184
185 /** @} ucache */
186
187 #endif /* _UPCALL_CACHE_H */