blob: 1ce15706458a7c6499f8bf9489bd468b3ec1482e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
19#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_inum.h"
21#include "xfs_log.h"
22#include "xfs_clnt.h"
23#include "xfs_trans.h"
24#include "xfs_sb.h"
25#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_imap.h"
28#include "xfs_alloc.h"
29#include "xfs_dmapi.h"
30#include "xfs_mount.h"
31#include "xfs_quota.h"
32
33int
34vfs_mount(
35 struct bhv_desc *bdp,
36 struct xfs_mount_args *args,
37 struct cred *cr)
38{
39 struct bhv_desc *next = bdp;
40
41 ASSERT(next);
42 while (! (bhvtovfsops(next))->vfs_mount)
43 next = BHV_NEXT(next);
44 return ((*bhvtovfsops(next)->vfs_mount)(next, args, cr));
45}
46
47int
48vfs_parseargs(
49 struct bhv_desc *bdp,
50 char *s,
51 struct xfs_mount_args *args,
52 int f)
53{
54 struct bhv_desc *next = bdp;
55
56 ASSERT(next);
57 while (! (bhvtovfsops(next))->vfs_parseargs)
58 next = BHV_NEXT(next);
59 return ((*bhvtovfsops(next)->vfs_parseargs)(next, s, args, f));
60}
61
62int
63vfs_showargs(
64 struct bhv_desc *bdp,
65 struct seq_file *m)
66{
67 struct bhv_desc *next = bdp;
68
69 ASSERT(next);
70 while (! (bhvtovfsops(next))->vfs_showargs)
71 next = BHV_NEXT(next);
72 return ((*bhvtovfsops(next)->vfs_showargs)(next, m));
73}
74
75int
76vfs_unmount(
77 struct bhv_desc *bdp,
78 int fl,
79 struct cred *cr)
80{
81 struct bhv_desc *next = bdp;
82
83 ASSERT(next);
84 while (! (bhvtovfsops(next))->vfs_unmount)
85 next = BHV_NEXT(next);
86 return ((*bhvtovfsops(next)->vfs_unmount)(next, fl, cr));
87}
88
89int
90vfs_mntupdate(
91 struct bhv_desc *bdp,
92 int *fl,
93 struct xfs_mount_args *args)
94{
95 struct bhv_desc *next = bdp;
96
97 ASSERT(next);
98 while (! (bhvtovfsops(next))->vfs_mntupdate)
99 next = BHV_NEXT(next);
100 return ((*bhvtovfsops(next)->vfs_mntupdate)(next, fl, args));
101}
102
103int
104vfs_root(
105 struct bhv_desc *bdp,
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000106 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 struct bhv_desc *next = bdp;
109
110 ASSERT(next);
111 while (! (bhvtovfsops(next))->vfs_root)
112 next = BHV_NEXT(next);
113 return ((*bhvtovfsops(next)->vfs_root)(next, vpp));
114}
115
116int
117vfs_statvfs(
118 struct bhv_desc *bdp,
Nathan Scott8285fb52006-06-09 17:07:12 +1000119 bhv_statvfs_t *statp,
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000120 bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 struct bhv_desc *next = bdp;
123
124 ASSERT(next);
125 while (! (bhvtovfsops(next))->vfs_statvfs)
126 next = BHV_NEXT(next);
Nathan Scott8285fb52006-06-09 17:07:12 +1000127 return ((*bhvtovfsops(next)->vfs_statvfs)(next, statp, vp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
130int
131vfs_sync(
132 struct bhv_desc *bdp,
133 int fl,
134 struct cred *cr)
135{
136 struct bhv_desc *next = bdp;
137
138 ASSERT(next);
139 while (! (bhvtovfsops(next))->vfs_sync)
140 next = BHV_NEXT(next);
141 return ((*bhvtovfsops(next)->vfs_sync)(next, fl, cr));
142}
143
144int
145vfs_vget(
146 struct bhv_desc *bdp,
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000147 bhv_vnode_t **vpp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 struct fid *fidp)
149{
150 struct bhv_desc *next = bdp;
151
152 ASSERT(next);
153 while (! (bhvtovfsops(next))->vfs_vget)
154 next = BHV_NEXT(next);
155 return ((*bhvtovfsops(next)->vfs_vget)(next, vpp, fidp));
156}
157
158int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159vfs_quotactl(
160 struct bhv_desc *bdp,
161 int cmd,
162 int id,
163 caddr_t addr)
164{
165 struct bhv_desc *next = bdp;
166
167 ASSERT(next);
168 while (! (bhvtovfsops(next))->vfs_quotactl)
169 next = BHV_NEXT(next);
170 return ((*bhvtovfsops(next)->vfs_quotactl)(next, cmd, id, addr));
171}
172
173void
174vfs_init_vnode(
175 struct bhv_desc *bdp,
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000176 bhv_vnode_t *vp,
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000177 struct xfs_inode *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 int unlock)
179{
180 struct bhv_desc *next = bdp;
181
182 ASSERT(next);
183 while (! (bhvtovfsops(next))->vfs_init_vnode)
184 next = BHV_NEXT(next);
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000185 ((*bhvtovfsops(next)->vfs_init_vnode)(next, vp, ip, unlock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
188void
189vfs_force_shutdown(
190 struct bhv_desc *bdp,
191 int fl,
192 char *file,
193 int line)
194{
195 struct bhv_desc *next = bdp;
196
197 ASSERT(next);
198 while (! (bhvtovfsops(next))->vfs_force_shutdown)
199 next = BHV_NEXT(next);
200 ((*bhvtovfsops(next)->vfs_force_shutdown)(next, fl, file, line));
201}
202
203void
204vfs_freeze(
205 struct bhv_desc *bdp)
206{
207 struct bhv_desc *next = bdp;
208
209 ASSERT(next);
210 while (! (bhvtovfsops(next))->vfs_freeze)
211 next = BHV_NEXT(next);
212 ((*bhvtovfsops(next)->vfs_freeze)(next));
213}
214
Nathan Scottb83bd132006-06-09 16:48:30 +1000215bhv_vfs_t *
Nathan Scottec86dc02006-03-17 17:25:36 +1100216vfs_allocate(
217 struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Nathan Scottb83bd132006-06-09 16:48:30 +1000219 struct bhv_vfs *vfsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Nathan Scottb83bd132006-06-09 16:48:30 +1000221 vfsp = kmem_zalloc(sizeof(bhv_vfs_t), KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 bhv_head_init(VFS_BHVHEAD(vfsp), "vfs");
223 INIT_LIST_HEAD(&vfsp->vfs_sync_list);
224 spin_lock_init(&vfsp->vfs_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 init_waitqueue_head(&vfsp->vfs_wait_single_sync_task);
Nathan Scottec86dc02006-03-17 17:25:36 +1100226
227 vfsp->vfs_super = sb;
228 sb->s_fs_info = vfsp;
229
230 if (sb->s_flags & MS_RDONLY)
231 vfsp->vfs_flag |= VFS_RDONLY;
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return vfsp;
234}
235
Nathan Scottb83bd132006-06-09 16:48:30 +1000236bhv_vfs_t *
Nathan Scottec86dc02006-03-17 17:25:36 +1100237vfs_from_sb(
238 struct super_block *sb)
239{
Nathan Scottb83bd132006-06-09 16:48:30 +1000240 return (bhv_vfs_t *)sb->s_fs_info;
Nathan Scottec86dc02006-03-17 17:25:36 +1100241}
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243void
244vfs_deallocate(
Nathan Scottb83bd132006-06-09 16:48:30 +1000245 struct bhv_vfs *vfsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 bhv_head_destroy(VFS_BHVHEAD(vfsp));
Nathan Scottb83bd132006-06-09 16:48:30 +1000248 kmem_free(vfsp, sizeof(bhv_vfs_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
251void
252vfs_insertops(
Nathan Scottb83bd132006-06-09 16:48:30 +1000253 struct bhv_vfs *vfsp,
254 struct bhv_module_vfsops *vfsops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 struct bhv_desc *bdp;
257
258 bdp = kmem_alloc(sizeof(struct bhv_desc), KM_SLEEP);
259 bhv_desc_init(bdp, NULL, vfsp, vfsops);
260 bhv_insert(&vfsp->vfs_bh, bdp);
261}
262
263void
264vfs_insertbhv(
Nathan Scottb83bd132006-06-09 16:48:30 +1000265 struct bhv_vfs *vfsp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 struct bhv_desc *bdp,
Nathan Scottb83bd132006-06-09 16:48:30 +1000267 struct bhv_vfsops *vfsops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 void *mount)
269{
270 bhv_desc_init(bdp, mount, vfsp, vfsops);
271 bhv_insert_initial(&vfsp->vfs_bh, bdp);
272}
273
274void
275bhv_remove_vfsops(
Nathan Scottb83bd132006-06-09 16:48:30 +1000276 struct bhv_vfs *vfsp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 int pos)
278{
279 struct bhv_desc *bhv;
280
281 bhv = bhv_lookup_range(&vfsp->vfs_bh, pos, pos);
282 if (!bhv)
283 return;
284 bhv_remove(&vfsp->vfs_bh, bhv);
285 kmem_free(bhv, sizeof(*bhv));
286}
287
288void
289bhv_remove_all_vfsops(
Nathan Scottb83bd132006-06-09 16:48:30 +1000290 struct bhv_vfs *vfsp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 int freebase)
292{
293 struct xfs_mount *mp;
294
295 bhv_remove_vfsops(vfsp, VFS_POSITION_QM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (!freebase)
297 return;
Nathan Scott02d7c922006-03-14 13:26:09 +1100298 mp = XFS_VFSTOM(vfsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 VFS_REMOVEBHV(vfsp, &mp->m_bhv);
300 xfs_mount_free(mp, 0);
Christoph Hellwigf541d272007-08-29 11:53:22 +1000301 kmem_free(mp, sizeof(xfs_mount_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
304void
305bhv_insert_all_vfsops(
Nathan Scottb83bd132006-06-09 16:48:30 +1000306 struct bhv_vfs *vfsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
308 struct xfs_mount *mp;
309
310 mp = xfs_mount_init();
311 vfs_insertbhv(vfsp, &mp->m_bhv, &xfs_vfsops, mp);
312 vfs_insertdmapi(vfsp);
313 vfs_insertquota(vfsp);
314}