]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/fs/pseudofs/pseudofs_internal.h
MFV r361936:
[FreeBSD/FreeBSD.git] / sys / fs / pseudofs / pseudofs_internal.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer
12  *    in this position and unchanged.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  *      $FreeBSD$
31  */
32
33 #ifndef _PSEUDOFS_INTERNAL_H_INCLUDED
34 #define _PSEUDOFS_INTERNAL_H_INCLUDED
35
36 /*
37  * Sysctl subtree
38  */
39 SYSCTL_DECL(_vfs_pfs);
40
41 /*
42  * Vnode data
43  */
44 struct pfs_vdata {
45         struct pfs_node *pvd_pn;
46         pid_t            pvd_pid;
47         struct vnode    *pvd_vnode;
48         SLIST_ENTRY(pfs_vdata) pvd_hash;
49 };
50
51 /*
52  * Vnode cache
53  */
54 void     pfs_vncache_load       (void);
55 void     pfs_vncache_unload     (void);
56 int      pfs_vncache_alloc      (struct mount *, struct vnode **,
57                                  struct pfs_node *, pid_t pid);
58 int      pfs_vncache_free       (struct vnode *);
59
60 /*
61  * File number bitmap
62  */
63 void     pfs_fileno_init        (struct pfs_info *);
64 void     pfs_fileno_uninit      (struct pfs_info *);
65 void     pfs_fileno_alloc       (struct pfs_node *);
66 void     pfs_fileno_free        (struct pfs_node *);
67
68 /*
69  * Debugging
70  */
71 #ifdef PSEUDOFS_TRACE
72 extern int pfs_trace;
73
74 #define PFS_TRACE(foo) \
75         do { \
76                 if (pfs_trace) { \
77                         printf("%s(): line %d: ", __func__, __LINE__); \
78                         printf foo ; \
79                         printf("\n"); \
80                 } \
81         } while (0)
82 #define PFS_RETURN(err) \
83         do { \
84                 if (pfs_trace) { \
85                         printf("%s(): line %d: returning %d\n", \
86                             __func__, __LINE__, err); \
87                 } \
88                 return (err); \
89         } while (0)
90 #else
91 #define PFS_TRACE(foo) \
92         do { /* nothing */ } while (0)
93 #define PFS_RETURN(err) \
94         return (err)
95 #endif
96
97 /*
98  * Inline helpers for locking
99  */
100 static inline void
101 pfs_lock(struct pfs_node *pn)
102 {
103
104         mtx_lock(&pn->pn_mutex);
105 }
106
107 static inline void
108 pfs_unlock(struct pfs_node *pn)
109 {
110
111         mtx_unlock(&pn->pn_mutex);
112 }
113
114 static inline void
115 pfs_assert_owned(struct pfs_node *pn)
116 {
117
118         mtx_assert(&pn->pn_mutex, MA_OWNED);
119 }
120
121 static inline void
122 pfs_assert_not_owned(struct pfs_node *pn)
123 {
124
125         mtx_assert(&pn->pn_mutex, MA_NOTOWNED);
126 }
127
128 static inline int
129 pn_fill(PFS_FILL_ARGS)
130 {
131
132         PFS_TRACE(("%s", pn->pn_name));
133         KASSERT(pn->pn_fill != NULL, ("%s(): no callback", __func__));
134         if (p != NULL) {
135                 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
136                 PROC_ASSERT_HELD(p);
137         }
138         pfs_assert_not_owned(pn);
139         return ((pn->pn_fill)(PFS_FILL_ARGNAMES));
140 }
141
142 static inline int
143 pn_attr(PFS_ATTR_ARGS)
144 {
145
146         PFS_TRACE(("%s", pn->pn_name));
147         KASSERT(pn->pn_attr != NULL, ("%s(): no callback", __func__));
148         if (p != NULL)
149                 PROC_LOCK_ASSERT(p, MA_OWNED);
150         pfs_assert_not_owned(pn);
151         return ((pn->pn_attr)(PFS_ATTR_ARGNAMES));
152 }
153
154 static inline int
155 pn_vis(PFS_VIS_ARGS)
156 {
157
158         PFS_TRACE(("%s", pn->pn_name));
159         KASSERT(pn->pn_vis != NULL, ("%s(): no callback", __func__));
160         KASSERT(p != NULL, ("%s(): no process", __func__));
161         PROC_LOCK_ASSERT(p, MA_OWNED);
162         pfs_assert_not_owned(pn);
163         return ((pn->pn_vis)(PFS_VIS_ARGNAMES));
164 }
165
166 static inline int
167 pn_ioctl(PFS_IOCTL_ARGS)
168 {
169
170         PFS_TRACE(("%s", pn->pn_name));
171         KASSERT(pn->pn_ioctl != NULL, ("%s(): no callback", __func__));
172         if (p != NULL)
173                 PROC_LOCK_ASSERT(p, MA_OWNED);
174         pfs_assert_not_owned(pn);
175         return ((pn->pn_ioctl)(PFS_IOCTL_ARGNAMES));
176 }
177
178 static inline int
179 pn_getextattr(PFS_GETEXTATTR_ARGS)
180 {
181
182         PFS_TRACE(("%s", pn->pn_name));
183         KASSERT(pn->pn_getextattr != NULL, ("%s(): no callback", __func__));
184         if (p != NULL)
185                 PROC_LOCK_ASSERT(p, MA_OWNED);
186         pfs_assert_not_owned(pn);
187         return ((pn->pn_getextattr)(PFS_GETEXTATTR_ARGNAMES));
188 }
189
190 static inline int
191 pn_close(PFS_CLOSE_ARGS)
192 {
193
194         PFS_TRACE(("%s", pn->pn_name));
195         KASSERT(pn->pn_close != NULL, ("%s(): no callback", __func__));
196         if (p != NULL)
197                 PROC_LOCK_ASSERT(p, MA_OWNED);
198         pfs_assert_not_owned(pn);
199         return ((pn->pn_close)(PFS_CLOSE_ARGNAMES));
200 }
201
202 static inline int
203 pn_destroy(PFS_DESTROY_ARGS)
204 {
205
206         PFS_TRACE(("%s", pn->pn_name));
207         KASSERT(pn->pn_destroy != NULL, ("%s(): no callback", __func__));
208         pfs_assert_not_owned(pn);
209         return ((pn->pn_destroy)(PFS_DESTROY_ARGNAMES));
210 }
211
212 #endif