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