blob: 1a08a1d842524f2835a645a3c9648d548542bd11 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000-2004 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "xfs.h"
33#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_inum.h"
35#include "xfs_log.h"
36#include "xfs_clnt.h"
37#include "xfs_trans.h"
38#include "xfs_sb.h"
39#include "xfs_ag.h"
40#include "xfs_dir.h"
41#include "xfs_dir2.h"
42#include "xfs_imap.h"
43#include "xfs_alloc.h"
44#include "xfs_dmapi.h"
45#include "xfs_mount.h"
46#include "xfs_quota.h"
47
48int
49vfs_mount(
50 struct bhv_desc *bdp,
51 struct xfs_mount_args *args,
52 struct cred *cr)
53{
54 struct bhv_desc *next = bdp;
55
56 ASSERT(next);
57 while (! (bhvtovfsops(next))->vfs_mount)
58 next = BHV_NEXT(next);
59 return ((*bhvtovfsops(next)->vfs_mount)(next, args, cr));
60}
61
62int
63vfs_parseargs(
64 struct bhv_desc *bdp,
65 char *s,
66 struct xfs_mount_args *args,
67 int f)
68{
69 struct bhv_desc *next = bdp;
70
71 ASSERT(next);
72 while (! (bhvtovfsops(next))->vfs_parseargs)
73 next = BHV_NEXT(next);
74 return ((*bhvtovfsops(next)->vfs_parseargs)(next, s, args, f));
75}
76
77int
78vfs_showargs(
79 struct bhv_desc *bdp,
80 struct seq_file *m)
81{
82 struct bhv_desc *next = bdp;
83
84 ASSERT(next);
85 while (! (bhvtovfsops(next))->vfs_showargs)
86 next = BHV_NEXT(next);
87 return ((*bhvtovfsops(next)->vfs_showargs)(next, m));
88}
89
90int
91vfs_unmount(
92 struct bhv_desc *bdp,
93 int fl,
94 struct cred *cr)
95{
96 struct bhv_desc *next = bdp;
97
98 ASSERT(next);
99 while (! (bhvtovfsops(next))->vfs_unmount)
100 next = BHV_NEXT(next);
101 return ((*bhvtovfsops(next)->vfs_unmount)(next, fl, cr));
102}
103
104int
105vfs_mntupdate(
106 struct bhv_desc *bdp,
107 int *fl,
108 struct xfs_mount_args *args)
109{
110 struct bhv_desc *next = bdp;
111
112 ASSERT(next);
113 while (! (bhvtovfsops(next))->vfs_mntupdate)
114 next = BHV_NEXT(next);
115 return ((*bhvtovfsops(next)->vfs_mntupdate)(next, fl, args));
116}
117
118int
119vfs_root(
120 struct bhv_desc *bdp,
121 struct vnode **vpp)
122{
123 struct bhv_desc *next = bdp;
124
125 ASSERT(next);
126 while (! (bhvtovfsops(next))->vfs_root)
127 next = BHV_NEXT(next);
128 return ((*bhvtovfsops(next)->vfs_root)(next, vpp));
129}
130
131int
132vfs_statvfs(
133 struct bhv_desc *bdp,
134 xfs_statfs_t *sp,
135 struct vnode *vp)
136{
137 struct bhv_desc *next = bdp;
138
139 ASSERT(next);
140 while (! (bhvtovfsops(next))->vfs_statvfs)
141 next = BHV_NEXT(next);
142 return ((*bhvtovfsops(next)->vfs_statvfs)(next, sp, vp));
143}
144
145int
146vfs_sync(
147 struct bhv_desc *bdp,
148 int fl,
149 struct cred *cr)
150{
151 struct bhv_desc *next = bdp;
152
153 ASSERT(next);
154 while (! (bhvtovfsops(next))->vfs_sync)
155 next = BHV_NEXT(next);
156 return ((*bhvtovfsops(next)->vfs_sync)(next, fl, cr));
157}
158
159int
160vfs_vget(
161 struct bhv_desc *bdp,
162 struct vnode **vpp,
163 struct fid *fidp)
164{
165 struct bhv_desc *next = bdp;
166
167 ASSERT(next);
168 while (! (bhvtovfsops(next))->vfs_vget)
169 next = BHV_NEXT(next);
170 return ((*bhvtovfsops(next)->vfs_vget)(next, vpp, fidp));
171}
172
173int
174vfs_dmapiops(
175 struct bhv_desc *bdp,
176 caddr_t addr)
177{
178 struct bhv_desc *next = bdp;
179
180 ASSERT(next);
181 while (! (bhvtovfsops(next))->vfs_dmapiops)
182 next = BHV_NEXT(next);
183 return ((*bhvtovfsops(next)->vfs_dmapiops)(next, addr));
184}
185
186int
187vfs_quotactl(
188 struct bhv_desc *bdp,
189 int cmd,
190 int id,
191 caddr_t addr)
192{
193 struct bhv_desc *next = bdp;
194
195 ASSERT(next);
196 while (! (bhvtovfsops(next))->vfs_quotactl)
197 next = BHV_NEXT(next);
198 return ((*bhvtovfsops(next)->vfs_quotactl)(next, cmd, id, addr));
199}
200
201void
202vfs_init_vnode(
203 struct bhv_desc *bdp,
204 struct vnode *vp,
205 struct bhv_desc *bp,
206 int unlock)
207{
208 struct bhv_desc *next = bdp;
209
210 ASSERT(next);
211 while (! (bhvtovfsops(next))->vfs_init_vnode)
212 next = BHV_NEXT(next);
213 ((*bhvtovfsops(next)->vfs_init_vnode)(next, vp, bp, unlock));
214}
215
216void
217vfs_force_shutdown(
218 struct bhv_desc *bdp,
219 int fl,
220 char *file,
221 int line)
222{
223 struct bhv_desc *next = bdp;
224
225 ASSERT(next);
226 while (! (bhvtovfsops(next))->vfs_force_shutdown)
227 next = BHV_NEXT(next);
228 ((*bhvtovfsops(next)->vfs_force_shutdown)(next, fl, file, line));
229}
230
231void
232vfs_freeze(
233 struct bhv_desc *bdp)
234{
235 struct bhv_desc *next = bdp;
236
237 ASSERT(next);
238 while (! (bhvtovfsops(next))->vfs_freeze)
239 next = BHV_NEXT(next);
240 ((*bhvtovfsops(next)->vfs_freeze)(next));
241}
242
243vfs_t *
244vfs_allocate( void )
245{
246 struct vfs *vfsp;
247
248 vfsp = kmem_zalloc(sizeof(vfs_t), KM_SLEEP);
249 bhv_head_init(VFS_BHVHEAD(vfsp), "vfs");
250 INIT_LIST_HEAD(&vfsp->vfs_sync_list);
251 spin_lock_init(&vfsp->vfs_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 init_waitqueue_head(&vfsp->vfs_wait_single_sync_task);
253 return vfsp;
254}
255
256void
257vfs_deallocate(
258 struct vfs *vfsp)
259{
260 bhv_head_destroy(VFS_BHVHEAD(vfsp));
261 kmem_free(vfsp, sizeof(vfs_t));
262}
263
264void
265vfs_insertops(
266 struct vfs *vfsp,
267 struct bhv_vfsops *vfsops)
268{
269 struct bhv_desc *bdp;
270
271 bdp = kmem_alloc(sizeof(struct bhv_desc), KM_SLEEP);
272 bhv_desc_init(bdp, NULL, vfsp, vfsops);
273 bhv_insert(&vfsp->vfs_bh, bdp);
274}
275
276void
277vfs_insertbhv(
278 struct vfs *vfsp,
279 struct bhv_desc *bdp,
280 struct vfsops *vfsops,
281 void *mount)
282{
283 bhv_desc_init(bdp, mount, vfsp, vfsops);
284 bhv_insert_initial(&vfsp->vfs_bh, bdp);
285}
286
287void
288bhv_remove_vfsops(
289 struct vfs *vfsp,
290 int pos)
291{
292 struct bhv_desc *bhv;
293
294 bhv = bhv_lookup_range(&vfsp->vfs_bh, pos, pos);
295 if (!bhv)
296 return;
297 bhv_remove(&vfsp->vfs_bh, bhv);
298 kmem_free(bhv, sizeof(*bhv));
299}
300
301void
302bhv_remove_all_vfsops(
303 struct vfs *vfsp,
304 int freebase)
305{
306 struct xfs_mount *mp;
307
308 bhv_remove_vfsops(vfsp, VFS_POSITION_QM);
309 bhv_remove_vfsops(vfsp, VFS_POSITION_DM);
310 if (!freebase)
311 return;
312 mp = XFS_BHVTOM(bhv_lookup(VFS_BHVHEAD(vfsp), &xfs_vfsops));
313 VFS_REMOVEBHV(vfsp, &mp->m_bhv);
314 xfs_mount_free(mp, 0);
315}
316
317void
318bhv_insert_all_vfsops(
319 struct vfs *vfsp)
320{
321 struct xfs_mount *mp;
322
323 mp = xfs_mount_init();
324 vfs_insertbhv(vfsp, &mp->m_bhv, &xfs_vfsops, mp);
325 vfs_insertdmapi(vfsp);
326 vfs_insertquota(vfsp);
327}