]> Pileus Git - ~andy/linux/blob - fs/gfs2/ops_super.c
Merge branch 'master'
[~andy/linux] / fs / gfs2 / ops_super.c
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/statfs.h>
16 #include <linux/vmalloc.h>
17 #include <linux/seq_file.h>
18 #include <linux/mount.h>
19 #include <linux/kthread.h>
20 #include <linux/delay.h>
21 #include <linux/gfs2_ondisk.h>
22 #include <asm/semaphore.h>
23
24 #include "gfs2.h"
25 #include "lm_interface.h"
26 #include "incore.h"
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"
39 #include "util.h"
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 {
51         struct gfs2_inode *ip = inode->u.generic_ip;
52
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 {
69         struct gfs2_sbd *sdp = sb->s_fs_info;
70         int error;
71
72         if (!sdp)
73                 return;
74
75         /*  Unfreeze the filesystem, if we need to  */
76
77         mutex_lock(&sdp->sd_freeze_lock);
78         if (sdp->sd_freeze_count)
79                 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
80         mutex_unlock(&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         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
107         gfs2_glock_put(sdp->sd_rename_gl);
108         gfs2_glock_put(sdp->sd_trans_gl);
109
110         if (!sdp->sd_args.ar_spectator) {
111                 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
112                 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
113                 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
114                 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
115                 gfs2_glock_dq_uninit(&sdp->sd_ut_gh);
116                 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
117                 iput(sdp->sd_ir_inode);
118                 iput(sdp->sd_sc_inode);
119                 iput(sdp->sd_ut_inode);
120                 iput(sdp->sd_qc_inode);
121         }
122
123         gfs2_glock_dq_uninit(&sdp->sd_live_gh);
124
125         gfs2_clear_rgrpd(sdp);
126         gfs2_jindex_free(sdp);
127
128         /*  Take apart glock structures and buffer lists  */
129         gfs2_gl_hash_clear(sdp, WAIT);
130
131         /*  Unmount the locking protocol  */
132         gfs2_lm_unmount(sdp);
133
134         /*  At this point, we're through participating in the lockspace  */
135
136         gfs2_sys_fs_del(sdp);
137
138         /*  Get rid of any extra inodes  */
139         while (invalidate_inodes(sb))
140                 yield();
141
142         vfree(sdp);
143
144         sb->s_fs_info = NULL;
145 }
146
147 /**
148  * gfs2_write_super - disk commit all incore transactions
149  * @sb: the filesystem
150  *
151  * This function is called every time sync(2) is called.
152  * After this exits, all dirty buffers and synced.
153  */
154
155 static void gfs2_write_super(struct super_block *sb)
156 {
157         struct gfs2_sbd *sdp = sb->s_fs_info;
158         gfs2_log_flush(sdp);
159 }
160
161 /**
162  * gfs2_write_super_lockfs - prevent further writes to the filesystem
163  * @sb: the VFS structure for the filesystem
164  *
165  */
166
167 static void gfs2_write_super_lockfs(struct super_block *sb)
168 {
169         struct gfs2_sbd *sdp = sb->s_fs_info;
170         int error;
171
172         for (;;) {
173                 error = gfs2_freeze_fs(sdp);
174                 if (!error)
175                         break;
176
177                 switch (error) {
178                 case -EBUSY:
179                         fs_err(sdp, "waiting for recovery before freeze\n");
180                         break;
181
182                 default:
183                         fs_err(sdp, "error freezing FS: %d\n", error);
184                         break;
185                 }
186
187                 fs_err(sdp, "retrying...\n");
188                 msleep(1000);
189         }
190 }
191
192 /**
193  * gfs2_unlockfs - reallow writes to the filesystem
194  * @sb: the VFS structure for the filesystem
195  *
196  */
197
198 static void gfs2_unlockfs(struct super_block *sb)
199 {
200         struct gfs2_sbd *sdp = sb->s_fs_info;
201         gfs2_unfreeze_fs(sdp);
202 }
203
204 /**
205  * gfs2_statfs - Gather and return stats about the filesystem
206  * @sb: The superblock
207  * @statfsbuf: The buffer
208  *
209  * Returns: 0 on success or error code
210  */
211
212 static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf)
213 {
214         struct gfs2_sbd *sdp = sb->s_fs_info;
215         struct gfs2_statfs_change sc;
216         int error;
217
218         if (gfs2_tune_get(sdp, gt_statfs_slow))
219                 error = gfs2_statfs_slow(sdp, &sc);
220         else
221                 error = gfs2_statfs_i(sdp, &sc);
222
223         if (error)
224                 return error;
225
226         memset(buf, 0, sizeof(struct kstatfs));
227
228         buf->f_type = GFS2_MAGIC;
229         buf->f_bsize = sdp->sd_sb.sb_bsize;
230         buf->f_blocks = sc.sc_total;
231         buf->f_bfree = sc.sc_free;
232         buf->f_bavail = sc.sc_free;
233         buf->f_files = sc.sc_dinodes + sc.sc_free;
234         buf->f_ffree = sc.sc_free;
235         buf->f_namelen = GFS2_FNAMESIZE;
236
237         return 0;
238 }
239
240 /**
241  * gfs2_remount_fs - called when the FS is remounted
242  * @sb:  the filesystem
243  * @flags:  the remount flags
244  * @data:  extra data passed in (not used right now)
245  *
246  * Returns: errno
247  */
248
249 static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
250 {
251         struct gfs2_sbd *sdp = sb->s_fs_info;
252         int error;
253
254         error = gfs2_mount_args(sdp, data, 1);
255         if (error)
256                 return error;
257
258         if (sdp->sd_args.ar_spectator)
259                 *flags |= MS_RDONLY;
260         else {
261                 if (*flags & MS_RDONLY) {
262                         if (!(sb->s_flags & MS_RDONLY))
263                                 error = gfs2_make_fs_ro(sdp);
264                 } else if (!(*flags & MS_RDONLY) &&
265                            (sb->s_flags & MS_RDONLY)) {
266                         error = gfs2_make_fs_rw(sdp);
267                 }
268         }
269
270         if (*flags & (MS_NOATIME | MS_NODIRATIME))
271                 set_bit(SDF_NOATIME, &sdp->sd_flags);
272         else
273                 clear_bit(SDF_NOATIME, &sdp->sd_flags);
274
275         /* Don't let the VFS update atimes.  GFS2 handles this itself. */
276         *flags |= MS_NOATIME | MS_NODIRATIME;
277
278         return error;
279 }
280
281 /**
282  * gfs2_clear_inode - Deallocate an inode when VFS is done with it
283  * @inode: The VFS inode
284  *
285  */
286
287 static void gfs2_clear_inode(struct inode *inode)
288 {
289         struct gfs2_inode *ip = inode->u.generic_ip;
290
291         if (ip) {
292                 spin_lock(&ip->i_spin);
293                 ip->i_vnode = NULL;
294                 inode->u.generic_ip = NULL;
295                 spin_unlock(&ip->i_spin);
296
297                 gfs2_glock_schedule_for_reclaim(ip->i_gl);
298                 gfs2_inode_put(ip);
299         }
300 }
301
302 /**
303  * gfs2_show_options - Show mount options for /proc/mounts
304  * @s: seq_file structure
305  * @mnt: vfsmount
306  *
307  * Returns: 0 on success or error code
308  */
309
310 static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
311 {
312         struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
313         struct gfs2_args *args = &sdp->sd_args;
314
315         if (args->ar_lockproto[0])
316                 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
317         if (args->ar_locktable[0])
318                 seq_printf(s, ",locktable=%s", args->ar_locktable);
319         if (args->ar_hostdata[0])
320                 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
321         if (args->ar_spectator)
322                 seq_printf(s, ",spectator");
323         if (args->ar_ignore_local_fs)
324                 seq_printf(s, ",ignore_local_fs");
325         if (args->ar_localflocks)
326                 seq_printf(s, ",localflocks");
327         if (args->ar_localcaching)
328                 seq_printf(s, ",localcaching");
329         if (args->ar_debug)
330                 seq_printf(s, ",debug");
331         if (args->ar_upgrade)
332                 seq_printf(s, ",upgrade");
333         if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT)
334                 seq_printf(s, ",num_glockd=%u", args->ar_num_glockd);
335         if (args->ar_posix_acl)
336                 seq_printf(s, ",acl");
337         if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
338                 char *state;
339                 switch (args->ar_quota) {
340                 case GFS2_QUOTA_OFF:
341                         state = "off";
342                         break;
343                 case GFS2_QUOTA_ACCOUNT:
344                         state = "account";
345                         break;
346                 case GFS2_QUOTA_ON:
347                         state = "on";
348                         break;
349                 default:
350                         state = "unknown";
351                         break;
352                 }
353                 seq_printf(s, ",quota=%s", state);
354         }
355         if (args->ar_suiddir)
356                 seq_printf(s, ",suiddir");
357         if (args->ar_data != GFS2_DATA_DEFAULT) {
358                 char *state;
359                 switch (args->ar_data) {
360                 case GFS2_DATA_WRITEBACK:
361                         state = "writeback";
362                         break;
363                 case GFS2_DATA_ORDERED:
364                         state = "ordered";
365                         break;
366                 default:
367                         state = "unknown";
368                         break;
369                 }
370                 seq_printf(s, ",data=%s", state);
371         }
372
373         return 0;
374 }
375
376 struct super_operations gfs2_super_ops = {
377         .write_inode = gfs2_write_inode,
378         .put_super = gfs2_put_super,
379         .write_super = gfs2_write_super,
380         .write_super_lockfs = gfs2_write_super_lockfs,
381         .unlockfs = gfs2_unlockfs,
382         .statfs = gfs2_statfs,
383         .remount_fs = gfs2_remount_fs,
384         .clear_inode = gfs2_clear_inode,
385         .show_options = gfs2_show_options,
386 };
387