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