Whamcloud - gitweb
LU-13456 ldlm: fix reprocessing of locks with more bits
[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
38 /** \defgroup ucache ucache
39  *
40  * @{
41  */
42
43 #define UC_CACHE_NEW            0x01
44 #define UC_CACHE_ACQUIRING      0x02
45 #define UC_CACHE_INVALID        0x04
46 #define UC_CACHE_EXPIRED        0x08
47
48 #define UC_CACHE_IS_NEW(i)          ((i)->ue_flags & UC_CACHE_NEW)
49 #define UC_CACHE_IS_INVALID(i)      ((i)->ue_flags & UC_CACHE_INVALID)
50 #define UC_CACHE_IS_ACQUIRING(i)    ((i)->ue_flags & UC_CACHE_ACQUIRING)
51 #define UC_CACHE_IS_EXPIRED(i)      ((i)->ue_flags & UC_CACHE_EXPIRED)
52 #define UC_CACHE_IS_VALID(i)        ((i)->ue_flags == 0)
53
54 #define UC_CACHE_SET_NEW(i)         ((i)->ue_flags |= UC_CACHE_NEW)
55 #define UC_CACHE_SET_INVALID(i)     ((i)->ue_flags |= UC_CACHE_INVALID)
56 #define UC_CACHE_SET_ACQUIRING(i)   ((i)->ue_flags |= UC_CACHE_ACQUIRING)
57 #define UC_CACHE_SET_EXPIRED(i)     ((i)->ue_flags |= UC_CACHE_EXPIRED)
58 #define UC_CACHE_SET_VALID(i)       ((i)->ue_flags = 0)
59
60 #define UC_CACHE_CLEAR_NEW(i)       ((i)->ue_flags &= ~UC_CACHE_NEW)
61 #define UC_CACHE_CLEAR_ACQUIRING(i) ((i)->ue_flags &= ~UC_CACHE_ACQUIRING)
62 #define UC_CACHE_CLEAR_INVALID(i)   ((i)->ue_flags &= ~UC_CACHE_INVALID)
63 #define UC_CACHE_CLEAR_EXPIRED(i)   ((i)->ue_flags &= ~UC_CACHE_EXPIRED)
64
65 struct upcall_cache_entry;
66
67 struct md_perm {
68         lnet_nid_t      mp_nid;
69         uint32_t        mp_perm;
70 };
71
72 struct md_identity {
73         struct upcall_cache_entry *mi_uc_entry;
74         uid_t                      mi_uid;
75         gid_t                      mi_gid;
76         struct group_info          *mi_ginfo;
77         int                        mi_nperms;
78         struct md_perm            *mi_perms;
79 };
80
81 struct upcall_cache_entry {
82         struct list_head        ue_hash;
83         uint64_t                ue_key;
84         atomic_t                ue_refcount;
85         int                     ue_flags;
86         wait_queue_head_t       ue_waitq;
87         time64_t                ue_acquire_expire;
88         time64_t                ue_expire;
89         union {
90                 struct md_identity      identity;
91         } u;
92 };
93
94 #define UC_CACHE_HASH_SIZE        (128)
95 #define UC_CACHE_HASH_INDEX(id)   ((id) & (UC_CACHE_HASH_SIZE - 1))
96 #define UC_CACHE_UPCALL_MAXPATH   (1024UL)
97
98 struct upcall_cache;
99
100 struct upcall_cache_ops {
101         void            (*init_entry)(struct upcall_cache_entry *, void *args);
102         void            (*free_entry)(struct upcall_cache *,
103                                       struct upcall_cache_entry *);
104         int             (*upcall_compare)(struct upcall_cache *,
105                                           struct upcall_cache_entry *,
106                                           __u64 key, void *args);
107         int             (*downcall_compare)(struct upcall_cache *,
108                                             struct upcall_cache_entry *,
109                                             __u64 key, void *args);
110         int             (*do_upcall)(struct upcall_cache *,
111                                      struct upcall_cache_entry *);
112         int             (*parse_downcall)(struct upcall_cache *,
113                                           struct upcall_cache_entry *, void *);
114 };
115
116 struct upcall_cache {
117         struct list_head        uc_hashtable[UC_CACHE_HASH_SIZE];
118         spinlock_t              uc_lock;
119         struct rw_semaphore     uc_upcall_rwsem;
120
121         char                    uc_name[40];            /* for upcall */
122         char                    uc_upcall[UC_CACHE_UPCALL_MAXPATH];
123         time64_t                uc_acquire_expire;      /* seconds */
124         time64_t                uc_entry_expire;        /* seconds */
125         struct upcall_cache_ops *uc_ops;
126 };
127
128 struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
129                                                   __u64 key, void *args);
130 void upcall_cache_put_entry(struct upcall_cache *cache,
131                             struct upcall_cache_entry *entry);
132 int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
133                           void *args);
134 void upcall_cache_flush(struct upcall_cache *cache, int force);
135
136 static inline void upcall_cache_flush_idle(struct upcall_cache *cache)
137 {
138         upcall_cache_flush(cache, 0);
139 }
140
141 static inline void upcall_cache_flush_all(struct upcall_cache *cache)
142 {
143         upcall_cache_flush(cache, 1);
144 }
145
146 void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args);
147 struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
148                                        struct upcall_cache_ops *ops);
149 void upcall_cache_cleanup(struct upcall_cache *cache);
150
151 /** @} ucache */
152
153 #endif /* _UPCALL_CACHE_H */