]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/gnu/fs/xfs/FreeBSD/xfs_vfs.c
This commit was generated by cvs2svn to compensate for changes in r159063,
[FreeBSD/FreeBSD.git] / sys / gnu / fs / xfs / FreeBSD / xfs_vfs.c
1 /*
2  * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include "xfs.h"
34 #include "xfs_fs.h"
35 #include "xfs_macros.h"
36 #include "xfs_inum.h"
37 #include "xfs_log.h"
38 #include "xfs_clnt.h"
39 #include "xfs_trans.h"
40 #include "xfs_sb.h"
41 #include "xfs_ag.h"
42 #include "xfs_dir.h"
43 #include "xfs_dir2.h"
44 #include "xfs_imap.h"
45 #include "xfs_alloc.h"
46 #include "xfs_dmapi.h"
47 #include "xfs_mount.h"
48 #include "xfs_quota.h"
49
50 #include "xfs_mountops.h"
51
52 int
53 xvfs_mount(
54         struct bhv_desc         *bdp,
55         struct xfs_mount_args   *args,
56         struct cred             *cr)
57 {
58         struct bhv_desc         *next = bdp;
59
60         ASSERT(next);
61         while (! (bhvtovfsops(next))->xvfs_mount)
62                 next = BHV_NEXT(next);
63         return ((*bhvtovfsops(next)->xvfs_mount)(next, args, cr));
64 }
65
66 int
67 xvfs_parseargs(
68         struct bhv_desc         *bdp,
69         char                    *s,
70         struct xfs_mount_args   *args,
71         int                     f)
72 {
73         struct bhv_desc         *next = bdp;
74
75         ASSERT(next);
76         while (! (bhvtovfsops(next))->xvfs_parseargs)
77                 next = BHV_NEXT(next);
78         return ((*bhvtovfsops(next)->xvfs_parseargs)(next, s, args, f));
79 }
80
81 int
82 xvfs_showargs(
83         struct bhv_desc         *bdp,
84         struct sbuf             *m)
85 {
86         struct bhv_desc         *next = bdp;
87
88         ASSERT(next);
89         while (! (bhvtovfsops(next))->xvfs_showargs)
90                 next = BHV_NEXT(next);
91         return ((*bhvtovfsops(next)->xvfs_showargs)(next, m));
92 }
93
94 int
95 xvfs_unmount(
96         struct bhv_desc         *bdp,
97         int                     fl,
98         struct cred             *cr)
99 {
100         struct bhv_desc         *next = bdp;
101
102         ASSERT(next);
103         while (! (bhvtovfsops(next))->xvfs_unmount)
104                 next = BHV_NEXT(next);
105         return ((*bhvtovfsops(next)->xvfs_unmount)(next, fl, cr));
106 }
107
108 int
109 xvfs_mntupdate(
110         struct bhv_desc         *bdp,
111         int                     *fl,
112         struct xfs_mount_args   *args)
113 {
114         struct bhv_desc         *next = bdp;
115
116         ASSERT(next);
117         while (! (bhvtovfsops(next))->xvfs_mntupdate)
118                 next = BHV_NEXT(next);
119         return ((*bhvtovfsops(next)->xvfs_mntupdate)(next, fl, args));
120 }
121
122 int
123 xvfs_root(
124         struct bhv_desc         *bdp,
125         struct xfs_vnode        **vpp)
126 {
127         struct bhv_desc         *next = bdp;
128
129         ASSERT(next);
130         while (! (bhvtovfsops(next))->xvfs_root)
131                 next = BHV_NEXT(next);
132         return ((*bhvtovfsops(next)->xvfs_root)(next, vpp));
133 }
134
135 int
136 xvfs_statvfs(
137         struct bhv_desc         *bdp,
138         struct statfs           *sp,
139         struct xfs_vnode        *vp)
140 {
141         struct bhv_desc         *next = bdp;
142
143         ASSERT(next);
144         while (! (bhvtovfsops(next))->xvfs_statvfs)
145                 next = BHV_NEXT(next);
146         return ((*bhvtovfsops(next)->xvfs_statvfs)(next, sp, vp));
147 }
148
149 int
150 xvfs_sync(
151         struct bhv_desc         *bdp,
152         int                     fl,
153         struct cred             *cr)
154 {
155         struct bhv_desc         *next = bdp;
156
157         ASSERT(next);
158         while (! (bhvtovfsops(next))->xvfs_sync)
159                 next = BHV_NEXT(next);
160         return ((*bhvtovfsops(next)->xvfs_sync)(next, fl, cr));
161 }
162
163 int
164 xvfs_vget(
165         struct bhv_desc         *bdp,
166         struct xfs_vnode        **vpp,
167         struct fid              *fidp)
168 {
169         struct bhv_desc         *next = bdp;
170
171         ASSERT(next);
172         while (! (bhvtovfsops(next))->xvfs_vget)
173                 next = BHV_NEXT(next);
174         return ((*bhvtovfsops(next)->xvfs_vget)(next, vpp, fidp));
175 }
176
177 int
178 xvfs_dmapiops(
179         struct bhv_desc         *bdp,
180         caddr_t                 addr)
181 {
182         struct bhv_desc         *next = bdp;
183
184         ASSERT(next);
185         while (! (bhvtovfsops(next))->xvfs_dmapiops)
186                 next = BHV_NEXT(next);
187         return ((*bhvtovfsops(next)->xvfs_dmapiops)(next, addr));
188 }
189
190 int
191 xvfs_quotactl(
192         struct bhv_desc         *bdp,
193         int                     cmd,
194         int                     id,
195         caddr_t                 addr)
196 {
197         struct bhv_desc         *next = bdp;
198
199         ASSERT(next);
200         while (! (bhvtovfsops(next))->xvfs_quotactl)
201                 next = BHV_NEXT(next);
202         return ((*bhvtovfsops(next)->xvfs_quotactl)(next, cmd, id, addr));
203 }
204
205 struct inode *
206 xvfs_get_inode(
207         struct bhv_desc         *bdp,
208         xfs_ino_t               ino,
209         int                     fl)
210 {
211         struct bhv_desc         *next = bdp;
212
213         while (! (bhvtovfsops(next))->xvfs_get_inode)
214                 next = BHV_NEXTNULL(next);
215         return ((*bhvtovfsops(next)->xvfs_get_inode)(next, ino, fl));
216 }
217
218 void
219 xvfs_init_vnode(
220         struct bhv_desc         *bdp,
221         struct xfs_vnode        *vp,
222         struct bhv_desc         *bp,
223         int                     unlock)
224 {
225         struct bhv_desc         *next = bdp;
226
227         ASSERT(next);
228         while (! (bhvtovfsops(next))->xvfs_init_vnode)
229                 next = BHV_NEXT(next);
230         ((*bhvtovfsops(next)->xvfs_init_vnode)(next, vp, bp, unlock));
231 }
232
233 void
234 xvfs_force_shutdown(
235         struct bhv_desc         *bdp,
236         int                     fl,
237         char                    *file,
238         int                     line)
239 {
240         struct bhv_desc         *next = bdp;
241
242         ASSERT(next);
243         while (! (bhvtovfsops(next))->xvfs_force_shutdown)
244                 next = BHV_NEXT(next);
245         ((*bhvtovfsops(next)->xvfs_force_shutdown)(next, fl, file, line));
246 }
247
248 xfs_vfs_t *
249 vfs_allocate(struct mount *mp)
250 {
251         struct xfs_vfs   *vfsp;
252         struct xfsmount  *xmp;
253
254         xmp  = kmem_zalloc(sizeof(*xmp), KM_SLEEP);
255         vfsp = XFSTOVFS(xmp);
256
257         bhv_head_init(VFS_BHVHEAD(vfsp), "vfs");
258
259         xmp->m_mp = mp;
260         mp->mnt_data = (qaddr_t)xmp;
261         vfsp->vfs_mp = mp;
262
263         return vfsp;
264 }
265
266 void
267 vfs_deallocate(
268         struct xfs_vfs          *vfsp)
269 {
270         struct xfsmount *xmp;
271
272         bhv_head_destroy(VFS_BHVHEAD(vfsp));
273
274         xmp = VFSTOXFS(vfsp);
275         kmem_free(xmp, sizeof(*xmp));
276 }
277
278 /*
279  * Allocate and initialize a new XFS mount structure
280  */
281 struct xfsmount *
282 xfsmount_allocate(struct mount *mp)
283 {
284         xfs_vfs_t       *vfsp;
285
286         vfsp = vfs_allocate(mp);
287
288         ASSERT(vfsp);
289
290         if (mp->mnt_flag & MNT_RDONLY)
291                 vfsp->vfs_flag |= VFS_RDONLY;
292
293         bhv_insert_all_vfsops(vfsp);
294         return (VFSTOXFS(vfsp));
295 }
296
297 void
298 xfsmount_deallocate(struct xfsmount *xmp)
299 {
300         xfs_vfs_t       *vfsp;
301
302         vfsp = XFSTOVFS(xmp);
303         bhv_remove_all_vfsops(vfsp, 1);
304         vfs_deallocate(vfsp);
305 }
306
307
308 void
309 vfs_insertops(
310         struct xfs_vfs          *vfsp,
311         struct bhv_vfsops       *vfsops)
312 {
313         struct bhv_desc         *bdp;
314
315         bdp = kmem_alloc(sizeof(struct bhv_desc), KM_SLEEP);
316         bhv_desc_init(bdp, NULL, vfsp, vfsops);
317         bhv_insert(&vfsp->vfs_bh, bdp);
318 }
319
320 void
321 vfs_insertbhv(
322         struct xfs_vfs          *vfsp,
323         struct bhv_desc         *bdp,
324         struct xvfsops          *vfsops,
325         void                    *mount)
326 {
327         bhv_desc_init(bdp, mount, vfsp, vfsops);
328         bhv_insert_initial(&vfsp->vfs_bh, bdp);
329 }
330
331 void
332 bhv_remove_vfsops(
333         struct xfs_vfs          *vfsp,
334         int                     pos)
335 {
336         struct bhv_desc         *bhv;
337
338         bhv = bhv_lookup_range(&vfsp->vfs_bh, pos, pos);
339         if (bhv) {
340                 bhv_remove(&vfsp->vfs_bh, bhv);
341                 kmem_free(bhv, sizeof(*bhv));
342         }
343 }
344
345 void
346 bhv_remove_all_vfsops(
347         struct xfs_vfs          *vfsp,
348         int                     freebase)
349 {
350         struct xfs_mount        *mp;
351
352         bhv_remove_vfsops(vfsp, VFS_POSITION_QM);
353         bhv_remove_vfsops(vfsp, VFS_POSITION_DM);
354         bhv_remove_vfsops(vfsp, VFS_POSITION_IO);
355         if (!freebase)
356                 return;
357         mp = XFS_BHVTOM(bhv_lookup(VFS_BHVHEAD(vfsp), &xfs_vfsops));
358         VFS_REMOVEBHV(vfsp, &mp->m_bhv);
359         xfs_mount_free(mp, 0);
360 }
361
362 void
363 bhv_insert_all_vfsops(
364         struct xfs_vfs          *vfsp)
365 {
366         struct xfs_mount        *mp;
367
368         mp = xfs_mount_init();
369         vfs_insertbhv(vfsp, &mp->m_bhv, &xfs_vfsops, mp);
370         vfs_insertdmapi(vfsp);
371         vfs_insertquota(vfsp);
372 }