]>
Commit | Line | Data |
---|---|---|
b3b94faa DT |
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> | |
b3b94faa | 15 | #include <linux/statfs.h> |
d92a8d48 | 16 | #include <linux/vmalloc.h> |
b3b94faa DT |
17 | #include <linux/seq_file.h> |
18 | #include <linux/mount.h> | |
19 | #include <linux/kthread.h> | |
20 | #include <linux/delay.h> | |
5c676f6d | 21 | #include <linux/gfs2_ondisk.h> |
b3b94faa DT |
22 | #include <asm/semaphore.h> |
23 | ||
24 | #include "gfs2.h" | |
5c676f6d SW |
25 | #include "lm_interface.h" |
26 | #include "incore.h" | |
b3b94faa DT |
27 | #include "glock.h" |
28 | #include "inode.h" | |
29 | #include "lm.h" | |
30 | #include "log.h" | |
31 | #include "mount.h" | |
32 | #include "ops_super.h" | |
33 | #include "page.h" | |
34 | #include "quota.h" | |
35 | #include "recovery.h" | |
36 | #include "rgrp.h" | |
37 | #include "super.h" | |
38 | #include "sys.h" | |
5c676f6d | 39 | #include "util.h" |
b3b94faa DT |
40 | |
41 | /** | |
42 | * gfs2_write_inode - Make sure the inode is stable on the disk | |
43 | * @inode: The inode | |
44 | * @sync: synchronous write flag | |
45 | * | |
46 | * Returns: errno | |
47 | */ | |
48 | ||
49 | static int gfs2_write_inode(struct inode *inode, int sync) | |
50 | { | |
5c676f6d | 51 | struct gfs2_inode *ip = inode->u.generic_ip; |
b3b94faa | 52 | |
b3b94faa DT |
53 | if (current->flags & PF_MEMALLOC) |
54 | return 0; | |
55 | if (ip && sync) | |
56 | gfs2_log_flush_glock(ip->i_gl); | |
57 | ||
58 | return 0; | |
59 | } | |
60 | ||
61 | /** | |
62 | * gfs2_put_super - Unmount the filesystem | |
63 | * @sb: The VFS superblock | |
64 | * | |
65 | */ | |
66 | ||
67 | static void gfs2_put_super(struct super_block *sb) | |
68 | { | |
5c676f6d | 69 | struct gfs2_sbd *sdp = sb->s_fs_info; |
b3b94faa DT |
70 | int error; |
71 | ||
72 | if (!sdp) | |
73 | return; | |
74 | ||
b3b94faa DT |
75 | /* Unfreeze the filesystem, if we need to */ |
76 | ||
f55ab26a | 77 | mutex_lock(&sdp->sd_freeze_lock); |
b3b94faa DT |
78 | if (sdp->sd_freeze_count) |
79 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); | |
f55ab26a | 80 | mutex_unlock(&sdp->sd_freeze_lock); |
b3b94faa DT |
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 | ||
f42faf4f SW |
100 | iput(sdp->sd_master_dir); |
101 | iput(sdp->sd_jindex); | |
102 | iput(sdp->sd_inum_inode); | |
103 | iput(sdp->sd_statfs_inode); | |
104 | iput(sdp->sd_rindex); | |
105 | iput(sdp->sd_quota_inode); | |
106 | iput(sdp->sd_root_dir); | |
b3b94faa DT |
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); | |
f42faf4f SW |
118 | iput(sdp->sd_ir_inode); |
119 | iput(sdp->sd_sc_inode); | |
120 | iput(sdp->sd_ut_inode); | |
121 | iput(sdp->sd_qc_inode); | |
b3b94faa DT |
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 | ||
5c676f6d | 145 | sb->s_fs_info = NULL; |
b3b94faa DT |
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 | { | |
5c676f6d | 158 | struct gfs2_sbd *sdp = sb->s_fs_info; |
b3b94faa DT |
159 | gfs2_log_flush(sdp); |
160 | } | |
161 | ||
162 | /** | |
163 | * gfs2_write_super_lockfs - prevent further writes to the filesystem | |
164 | * @sb: the VFS structure for the filesystem | |
165 | * | |
166 | */ | |
167 | ||
168 | static void gfs2_write_super_lockfs(struct super_block *sb) | |
169 | { | |
5c676f6d | 170 | struct gfs2_sbd *sdp = sb->s_fs_info; |
b3b94faa DT |
171 | int error; |
172 | ||
b3b94faa DT |
173 | for (;;) { |
174 | error = gfs2_freeze_fs(sdp); | |
175 | if (!error) | |
176 | break; | |
177 | ||
178 | switch (error) { | |
179 | case -EBUSY: | |
180 | fs_err(sdp, "waiting for recovery before freeze\n"); | |
181 | break; | |
182 | ||
183 | default: | |
184 | fs_err(sdp, "error freezing FS: %d\n", error); | |
185 | break; | |
186 | } | |
187 | ||
188 | fs_err(sdp, "retrying...\n"); | |
189 | msleep(1000); | |
190 | } | |
191 | } | |
192 | ||
193 | /** | |
194 | * gfs2_unlockfs - reallow writes to the filesystem | |
195 | * @sb: the VFS structure for the filesystem | |
196 | * | |
197 | */ | |
198 | ||
199 | static void gfs2_unlockfs(struct super_block *sb) | |
200 | { | |
5c676f6d | 201 | struct gfs2_sbd *sdp = sb->s_fs_info; |
b3b94faa DT |
202 | gfs2_unfreeze_fs(sdp); |
203 | } | |
204 | ||
205 | /** | |
206 | * gfs2_statfs - Gather and return stats about the filesystem | |
207 | * @sb: The superblock | |
208 | * @statfsbuf: The buffer | |
209 | * | |
210 | * Returns: 0 on success or error code | |
211 | */ | |
212 | ||
213 | static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) | |
214 | { | |
5c676f6d | 215 | struct gfs2_sbd *sdp = sb->s_fs_info; |
b3b94faa DT |
216 | struct gfs2_statfs_change sc; |
217 | int error; | |
218 | ||
b3b94faa DT |
219 | if (gfs2_tune_get(sdp, gt_statfs_slow)) |
220 | error = gfs2_statfs_slow(sdp, &sc); | |
221 | else | |
222 | error = gfs2_statfs_i(sdp, &sc); | |
223 | ||
224 | if (error) | |
225 | return error; | |
226 | ||
227 | memset(buf, 0, sizeof(struct kstatfs)); | |
228 | ||
229 | buf->f_type = GFS2_MAGIC; | |
230 | buf->f_bsize = sdp->sd_sb.sb_bsize; | |
231 | buf->f_blocks = sc.sc_total; | |
232 | buf->f_bfree = sc.sc_free; | |
233 | buf->f_bavail = sc.sc_free; | |
234 | buf->f_files = sc.sc_dinodes + sc.sc_free; | |
235 | buf->f_ffree = sc.sc_free; | |
236 | buf->f_namelen = GFS2_FNAMESIZE; | |
237 | ||
238 | return 0; | |
239 | } | |
240 | ||
241 | /** | |
242 | * gfs2_remount_fs - called when the FS is remounted | |
243 | * @sb: the filesystem | |
244 | * @flags: the remount flags | |
245 | * @data: extra data passed in (not used right now) | |
246 | * | |
247 | * Returns: errno | |
248 | */ | |
249 | ||
250 | static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) | |
251 | { | |
5c676f6d | 252 | struct gfs2_sbd *sdp = sb->s_fs_info; |
b3b94faa DT |
253 | int error; |
254 | ||
b3b94faa DT |
255 | error = gfs2_mount_args(sdp, data, 1); |
256 | if (error) | |
257 | return error; | |
258 | ||
259 | if (sdp->sd_args.ar_spectator) | |
260 | *flags |= MS_RDONLY; | |
261 | else { | |
262 | if (*flags & MS_RDONLY) { | |
263 | if (!(sb->s_flags & MS_RDONLY)) | |
264 | error = gfs2_make_fs_ro(sdp); | |
265 | } else if (!(*flags & MS_RDONLY) && | |
266 | (sb->s_flags & MS_RDONLY)) { | |
267 | error = gfs2_make_fs_rw(sdp); | |
268 | } | |
269 | } | |
270 | ||
271 | if (*flags & (MS_NOATIME | MS_NODIRATIME)) | |
272 | set_bit(SDF_NOATIME, &sdp->sd_flags); | |
273 | else | |
274 | clear_bit(SDF_NOATIME, &sdp->sd_flags); | |
275 | ||
276 | /* Don't let the VFS update atimes. GFS2 handles this itself. */ | |
277 | *flags |= MS_NOATIME | MS_NODIRATIME; | |
278 | ||
279 | return error; | |
280 | } | |
281 | ||
282 | /** | |
283 | * gfs2_clear_inode - Deallocate an inode when VFS is done with it | |
284 | * @inode: The VFS inode | |
285 | * | |
286 | */ | |
287 | ||
288 | static void gfs2_clear_inode(struct inode *inode) | |
289 | { | |
5c676f6d | 290 | struct gfs2_inode *ip = inode->u.generic_ip; |
b3b94faa | 291 | |
b3b94faa DT |
292 | if (ip) { |
293 | spin_lock(&ip->i_spin); | |
294 | ip->i_vnode = NULL; | |
5c676f6d | 295 | inode->u.generic_ip = NULL; |
b3b94faa DT |
296 | spin_unlock(&ip->i_spin); |
297 | ||
298 | gfs2_glock_schedule_for_reclaim(ip->i_gl); | |
299 | gfs2_inode_put(ip); | |
300 | } | |
301 | } | |
302 | ||
303 | /** | |
304 | * gfs2_show_options - Show mount options for /proc/mounts | |
305 | * @s: seq_file structure | |
306 | * @mnt: vfsmount | |
307 | * | |
308 | * Returns: 0 on success or error code | |
309 | */ | |
310 | ||
311 | static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) | |
312 | { | |
5c676f6d | 313 | struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info; |
b3b94faa DT |
314 | struct gfs2_args *args = &sdp->sd_args; |
315 | ||
b3b94faa DT |
316 | if (args->ar_lockproto[0]) |
317 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); | |
318 | if (args->ar_locktable[0]) | |
319 | seq_printf(s, ",locktable=%s", args->ar_locktable); | |
320 | if (args->ar_hostdata[0]) | |
321 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); | |
322 | if (args->ar_spectator) | |
323 | seq_printf(s, ",spectator"); | |
324 | if (args->ar_ignore_local_fs) | |
325 | seq_printf(s, ",ignore_local_fs"); | |
326 | if (args->ar_localflocks) | |
327 | seq_printf(s, ",localflocks"); | |
328 | if (args->ar_localcaching) | |
329 | seq_printf(s, ",localcaching"); | |
330 | if (args->ar_debug) | |
331 | seq_printf(s, ",debug"); | |
332 | if (args->ar_upgrade) | |
333 | seq_printf(s, ",upgrade"); | |
334 | if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT) | |
335 | seq_printf(s, ",num_glockd=%u", args->ar_num_glockd); | |
336 | if (args->ar_posix_acl) | |
337 | seq_printf(s, ",acl"); | |
338 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { | |
339 | char *state; | |
340 | switch (args->ar_quota) { | |
341 | case GFS2_QUOTA_OFF: | |
342 | state = "off"; | |
343 | break; | |
344 | case GFS2_QUOTA_ACCOUNT: | |
345 | state = "account"; | |
346 | break; | |
347 | case GFS2_QUOTA_ON: | |
348 | state = "on"; | |
349 | break; | |
350 | default: | |
351 | state = "unknown"; | |
352 | break; | |
353 | } | |
354 | seq_printf(s, ",quota=%s", state); | |
355 | } | |
356 | if (args->ar_suiddir) | |
357 | seq_printf(s, ",suiddir"); | |
358 | if (args->ar_data != GFS2_DATA_DEFAULT) { | |
359 | char *state; | |
360 | switch (args->ar_data) { | |
361 | case GFS2_DATA_WRITEBACK: | |
362 | state = "writeback"; | |
363 | break; | |
364 | case GFS2_DATA_ORDERED: | |
365 | state = "ordered"; | |
366 | break; | |
367 | default: | |
368 | state = "unknown"; | |
369 | break; | |
370 | } | |
371 | seq_printf(s, ",data=%s", state); | |
372 | } | |
373 | ||
374 | return 0; | |
375 | } | |
376 | ||
377 | struct super_operations gfs2_super_ops = { | |
378 | .write_inode = gfs2_write_inode, | |
379 | .put_super = gfs2_put_super, | |
380 | .write_super = gfs2_write_super, | |
381 | .write_super_lockfs = gfs2_write_super_lockfs, | |
382 | .unlockfs = gfs2_unlockfs, | |
383 | .statfs = gfs2_statfs, | |
384 | .remount_fs = gfs2_remount_fs, | |
385 | .clear_inode = gfs2_clear_inode, | |
386 | .show_options = gfs2_show_options, | |
387 | }; | |
388 |