diff options
author | David Teigland <teigland@redhat.com> | 2006-01-16 11:50:04 -0500 |
---|---|---|
committer | Steven Whitehouse <swhiteho@redhat.com> | 2006-01-16 11:50:04 -0500 |
commit | b3b94faa5fe5968827ba0640ee9fba4b3e7f736e (patch) | |
tree | 70bd6068b050d2c46e338484f8b03fae4365c6c3 /fs/gfs2/ops_super.c | |
parent | f7825dcf8c7301cfd3724eb40c5b443cc85ab7b8 (diff) |
[GFS2] The core of GFS2
This patch contains all the core files for GFS2.
Signed-off-by: David Teigland <teigland@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/ops_super.c')
-rw-r--r-- | fs/gfs2/ops_super.c | 401 |
1 files changed, 401 insertions, 0 deletions
diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c new file mode 100644 index 00000000000..ca6a4d81bc2 --- /dev/null +++ b/fs/gfs2/ops_super.c | |||
@@ -0,0 +1,401 @@ | |||
1 | /* | ||
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | ||
3 | * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. | ||
4 | * | ||
5 | * This copyrighted material is made available to anyone wishing to use, | ||
6 | * modify, copy, or redistribute it subject to the terms and conditions | ||
7 | * of the GNU General Public License v.2. | ||
8 | */ | ||
9 | |||
10 | #include <linux/sched.h> | ||
11 | #include <linux/slab.h> | ||
12 | #include <linux/spinlock.h> | ||
13 | #include <linux/completion.h> | ||
14 | #include <linux/buffer_head.h> | ||
15 | #include <linux/vmalloc.h> | ||
16 | #include <linux/statfs.h> | ||
17 | #include <linux/seq_file.h> | ||
18 | #include <linux/mount.h> | ||
19 | #include <linux/kthread.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <asm/semaphore.h> | ||
22 | |||
23 | #include "gfs2.h" | ||
24 | #include "glock.h" | ||
25 | #include "inode.h" | ||
26 | #include "lm.h" | ||
27 | #include "log.h" | ||
28 | #include "mount.h" | ||
29 | #include "ops_super.h" | ||
30 | #include "page.h" | ||
31 | #include "quota.h" | ||
32 | #include "recovery.h" | ||
33 | #include "rgrp.h" | ||
34 | #include "super.h" | ||
35 | #include "sys.h" | ||
36 | |||
37 | /** | ||
38 | * gfs2_write_inode - Make sure the inode is stable on the disk | ||
39 | * @inode: The inode | ||
40 | * @sync: synchronous write flag | ||
41 | * | ||
42 | * Returns: errno | ||
43 | */ | ||
44 | |||
45 | static int gfs2_write_inode(struct inode *inode, int sync) | ||
46 | { | ||
47 | struct gfs2_inode *ip = get_v2ip(inode); | ||
48 | |||
49 | atomic_inc(&ip->i_sbd->sd_ops_super); | ||
50 | |||
51 | if (current->flags & PF_MEMALLOC) | ||
52 | return 0; | ||
53 | if (ip && sync) | ||
54 | gfs2_log_flush_glock(ip->i_gl); | ||
55 | |||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * gfs2_put_super - Unmount the filesystem | ||
61 | * @sb: The VFS superblock | ||
62 | * | ||
63 | */ | ||
64 | |||
65 | static void gfs2_put_super(struct super_block *sb) | ||
66 | { | ||
67 | struct gfs2_sbd *sdp = get_v2sdp(sb); | ||
68 | int error; | ||
69 | |||
70 | if (!sdp) | ||
71 | return; | ||
72 | |||
73 | atomic_inc(&sdp->sd_ops_super); | ||
74 | |||
75 | /* Unfreeze the filesystem, if we need to */ | ||
76 | |||
77 | down(&sdp->sd_freeze_lock); | ||
78 | if (sdp->sd_freeze_count) | ||
79 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); | ||
80 | up(&sdp->sd_freeze_lock); | ||
81 | |||
82 | kthread_stop(sdp->sd_inoded_process); | ||
83 | kthread_stop(sdp->sd_quotad_process); | ||
84 | kthread_stop(sdp->sd_logd_process); | ||
85 | kthread_stop(sdp->sd_recoverd_process); | ||
86 | while (sdp->sd_glockd_num--) | ||
87 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); | ||
88 | kthread_stop(sdp->sd_scand_process); | ||
89 | |||
90 | if (!(sb->s_flags & MS_RDONLY)) { | ||
91 | error = gfs2_make_fs_ro(sdp); | ||
92 | if (error) | ||
93 | gfs2_io_error(sdp); | ||
94 | } | ||
95 | |||
96 | /* At this point, we're through modifying the disk */ | ||
97 | |||
98 | /* Release stuff */ | ||
99 | |||
100 | gfs2_inode_put(sdp->sd_master_dir); | ||
101 | gfs2_inode_put(sdp->sd_jindex); | ||
102 | gfs2_inode_put(sdp->sd_inum_inode); | ||
103 | gfs2_inode_put(sdp->sd_statfs_inode); | ||
104 | gfs2_inode_put(sdp->sd_rindex); | ||
105 | gfs2_inode_put(sdp->sd_quota_inode); | ||
106 | gfs2_inode_put(sdp->sd_root_dir); | ||
107 | |||
108 | gfs2_glock_put(sdp->sd_rename_gl); | ||
109 | gfs2_glock_put(sdp->sd_trans_gl); | ||
110 | |||
111 | if (!sdp->sd_args.ar_spectator) { | ||
112 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); | ||
113 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); | ||
114 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); | ||
115 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); | ||
116 | gfs2_glock_dq_uninit(&sdp->sd_ut_gh); | ||
117 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); | ||
118 | gfs2_inode_put(sdp->sd_ir_inode); | ||
119 | gfs2_inode_put(sdp->sd_sc_inode); | ||
120 | gfs2_inode_put(sdp->sd_ut_inode); | ||
121 | gfs2_inode_put(sdp->sd_qc_inode); | ||
122 | } | ||
123 | |||
124 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); | ||
125 | |||
126 | gfs2_clear_rgrpd(sdp); | ||
127 | gfs2_jindex_free(sdp); | ||
128 | |||
129 | /* Take apart glock structures and buffer lists */ | ||
130 | gfs2_gl_hash_clear(sdp, WAIT); | ||
131 | |||
132 | /* Unmount the locking protocol */ | ||
133 | gfs2_lm_unmount(sdp); | ||
134 | |||
135 | /* At this point, we're through participating in the lockspace */ | ||
136 | |||
137 | gfs2_sys_fs_del(sdp); | ||
138 | |||
139 | /* Get rid of any extra inodes */ | ||
140 | while (invalidate_inodes(sb)) | ||
141 | yield(); | ||
142 | |||
143 | vfree(sdp); | ||
144 | |||
145 | set_v2sdp(sb, NULL); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * gfs2_write_super - disk commit all incore transactions | ||
150 | * @sb: the filesystem | ||
151 | * | ||
152 | * This function is called every time sync(2) is called. | ||
153 | * After this exits, all dirty buffers and synced. | ||
154 | */ | ||
155 | |||
156 | static void gfs2_write_super(struct super_block *sb) | ||
157 | { | ||
158 | struct gfs2_sbd *sdp = get_v2sdp(sb); | ||
159 | atomic_inc(&sdp->sd_ops_super); | ||
160 | gfs2_log_flush(sdp); | ||
161 | } | ||
162 | |||
163 | /** | ||
164 | * gfs2_write_super_lockfs - prevent further writes to the filesystem | ||
165 | * @sb: the VFS structure for the filesystem | ||
166 | * | ||
167 | */ | ||
168 | |||
169 | static void gfs2_write_super_lockfs(struct super_block *sb) | ||
170 | { | ||
171 | struct gfs2_sbd *sdp = get_v2sdp(sb); | ||
172 | int error; | ||
173 | |||
174 | atomic_inc(&sdp->sd_ops_super); | ||
175 | |||
176 | for (;;) { | ||
177 | error = gfs2_freeze_fs(sdp); | ||
178 | if (!error) | ||
179 | break; | ||
180 | |||
181 | switch (error) { | ||
182 | case -EBUSY: | ||
183 | fs_err(sdp, "waiting for recovery before freeze\n"); | ||
184 | break; | ||
185 | |||
186 | default: | ||
187 | fs_err(sdp, "error freezing FS: %d\n", error); | ||
188 | break; | ||
189 | } | ||
190 | |||
191 | fs_err(sdp, "retrying...\n"); | ||
192 | msleep(1000); | ||
193 | } | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * gfs2_unlockfs - reallow writes to the filesystem | ||
198 | * @sb: the VFS structure for the filesystem | ||
199 | * | ||
200 | */ | ||
201 | |||
202 | static void gfs2_unlockfs(struct super_block *sb) | ||
203 | { | ||
204 | struct gfs2_sbd *sdp = get_v2sdp(sb); | ||
205 | |||
206 | atomic_inc(&sdp->sd_ops_super); | ||
207 | gfs2_unfreeze_fs(sdp); | ||
208 | } | ||
209 | |||
210 | /** | ||
211 | * gfs2_statfs - Gather and return stats about the filesystem | ||
212 | * @sb: The superblock | ||
213 | * @statfsbuf: The buffer | ||
214 | * | ||
215 | * Returns: 0 on success or error code | ||
216 | */ | ||
217 | |||
218 | static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) | ||
219 | { | ||
220 | struct gfs2_sbd *sdp = get_v2sdp(sb); | ||
221 | struct gfs2_statfs_change sc; | ||
222 | int error; | ||
223 | |||
224 | atomic_inc(&sdp->sd_ops_super); | ||
225 | |||
226 | if (gfs2_tune_get(sdp, gt_statfs_slow)) | ||
227 | error = gfs2_statfs_slow(sdp, &sc); | ||
228 | else | ||
229 | error = gfs2_statfs_i(sdp, &sc); | ||
230 | |||
231 | if (error) | ||
232 | return error; | ||
233 | |||
234 | memset(buf, 0, sizeof(struct kstatfs)); | ||
235 | |||
236 | buf->f_type = GFS2_MAGIC; | ||
237 | buf->f_bsize = sdp->sd_sb.sb_bsize; | ||
238 | buf->f_blocks = sc.sc_total; | ||
239 | buf->f_bfree = sc.sc_free; | ||
240 | buf->f_bavail = sc.sc_free; | ||
241 | buf->f_files = sc.sc_dinodes + sc.sc_free; | ||
242 | buf->f_ffree = sc.sc_free; | ||
243 | buf->f_namelen = GFS2_FNAMESIZE; | ||
244 | |||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | /** | ||
249 | * gfs2_remount_fs - called when the FS is remounted | ||
250 | * @sb: the filesystem | ||
251 | * @flags: the remount flags | ||
252 | * @data: extra data passed in (not used right now) | ||
253 | * | ||
254 | * Returns: errno | ||
255 | */ | ||
256 | |||
257 | static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) | ||
258 | { | ||
259 | struct gfs2_sbd *sdp = get_v2sdp(sb); | ||
260 | int error; | ||
261 | |||
262 | atomic_inc(&sdp->sd_ops_super); | ||
263 | |||
264 | error = gfs2_mount_args(sdp, data, 1); | ||
265 | if (error) | ||
266 | return error; | ||
267 | |||
268 | if (sdp->sd_args.ar_spectator) | ||
269 | *flags |= MS_RDONLY; | ||
270 | else { | ||
271 | if (*flags & MS_RDONLY) { | ||
272 | if (!(sb->s_flags & MS_RDONLY)) | ||
273 | error = gfs2_make_fs_ro(sdp); | ||
274 | } else if (!(*flags & MS_RDONLY) && | ||
275 | (sb->s_flags & MS_RDONLY)) { | ||
276 | error = gfs2_make_fs_rw(sdp); | ||
277 | } | ||
278 | } | ||
279 | |||
280 | if (*flags & (MS_NOATIME | MS_NODIRATIME)) | ||
281 | set_bit(SDF_NOATIME, &sdp->sd_flags); | ||
282 | else | ||
283 | clear_bit(SDF_NOATIME, &sdp->sd_flags); | ||
284 | |||
285 | /* Don't let the VFS update atimes. GFS2 handles this itself. */ | ||
286 | *flags |= MS_NOATIME | MS_NODIRATIME; | ||
287 | |||
288 | return error; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * gfs2_clear_inode - Deallocate an inode when VFS is done with it | ||
293 | * @inode: The VFS inode | ||
294 | * | ||
295 | */ | ||
296 | |||
297 | static void gfs2_clear_inode(struct inode *inode) | ||
298 | { | ||
299 | struct gfs2_inode *ip = get_v2ip(inode); | ||
300 | |||
301 | atomic_inc(&get_v2sdp(inode->i_sb)->sd_ops_super); | ||
302 | |||
303 | if (ip) { | ||
304 | spin_lock(&ip->i_spin); | ||
305 | ip->i_vnode = NULL; | ||
306 | set_v2ip(inode, NULL); | ||
307 | spin_unlock(&ip->i_spin); | ||
308 | |||
309 | gfs2_glock_schedule_for_reclaim(ip->i_gl); | ||
310 | gfs2_inode_put(ip); | ||
311 | } | ||
312 | } | ||
313 | |||
314 | /** | ||
315 | * gfs2_show_options - Show mount options for /proc/mounts | ||
316 | * @s: seq_file structure | ||
317 | * @mnt: vfsmount | ||
318 | * | ||
319 | * Returns: 0 on success or error code | ||
320 | */ | ||
321 | |||
322 | static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) | ||
323 | { | ||
324 | struct gfs2_sbd *sdp = get_v2sdp(mnt->mnt_sb); | ||
325 | struct gfs2_args *args = &sdp->sd_args; | ||
326 | |||
327 | atomic_inc(&sdp->sd_ops_super); | ||
328 | |||
329 | if (args->ar_lockproto[0]) | ||
330 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); | ||
331 | if (args->ar_locktable[0]) | ||
332 | seq_printf(s, ",locktable=%s", args->ar_locktable); | ||
333 | if (args->ar_hostdata[0]) | ||
334 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); | ||
335 | if (args->ar_spectator) | ||
336 | seq_printf(s, ",spectator"); | ||
337 | if (args->ar_ignore_local_fs) | ||
338 | seq_printf(s, ",ignore_local_fs"); | ||
339 | if (args->ar_localflocks) | ||
340 | seq_printf(s, ",localflocks"); | ||
341 | if (args->ar_localcaching) | ||
342 | seq_printf(s, ",localcaching"); | ||
343 | if (args->ar_debug) | ||
344 | seq_printf(s, ",debug"); | ||
345 | if (args->ar_upgrade) | ||
346 | seq_printf(s, ",upgrade"); | ||
347 | if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT) | ||
348 | seq_printf(s, ",num_glockd=%u", args->ar_num_glockd); | ||
349 | if (args->ar_posix_acl) | ||
350 | seq_printf(s, ",acl"); | ||
351 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { | ||
352 | char *state; | ||
353 | switch (args->ar_quota) { | ||
354 | case GFS2_QUOTA_OFF: | ||
355 | state = "off"; | ||
356 | break; | ||
357 | case GFS2_QUOTA_ACCOUNT: | ||
358 | state = "account"; | ||
359 | break; | ||
360 | case GFS2_QUOTA_ON: | ||
361 | state = "on"; | ||
362 | break; | ||
363 | default: | ||
364 | state = "unknown"; | ||
365 | break; | ||
366 | } | ||
367 | seq_printf(s, ",quota=%s", state); | ||
368 | } | ||
369 | if (args->ar_suiddir) | ||
370 | seq_printf(s, ",suiddir"); | ||
371 | if (args->ar_data != GFS2_DATA_DEFAULT) { | ||
372 | char *state; | ||
373 | switch (args->ar_data) { | ||
374 | case GFS2_DATA_WRITEBACK: | ||
375 | state = "writeback"; | ||
376 | break; | ||
377 | case GFS2_DATA_ORDERED: | ||
378 | state = "ordered"; | ||
379 | break; | ||
380 | default: | ||
381 | state = "unknown"; | ||
382 | break; | ||
383 | } | ||
384 | seq_printf(s, ",data=%s", state); | ||
385 | } | ||
386 | |||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | struct super_operations gfs2_super_ops = { | ||
391 | .write_inode = gfs2_write_inode, | ||
392 | .put_super = gfs2_put_super, | ||
393 | .write_super = gfs2_write_super, | ||
394 | .write_super_lockfs = gfs2_write_super_lockfs, | ||
395 | .unlockfs = gfs2_unlockfs, | ||
396 | .statfs = gfs2_statfs, | ||
397 | .remount_fs = gfs2_remount_fs, | ||
398 | .clear_inode = gfs2_clear_inode, | ||
399 | .show_options = gfs2_show_options, | ||
400 | }; | ||
401 | |||