blob: f0699ac453f763f6166a5e80c07b6a2aa5c536da [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Bob Peterson091806ed2008-04-29 12:35:48 -05003 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
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>
David Teiglandb3b94fa2006-01-16 16:50:04 +000015#include <linux/statfs.h>
16#include <linux/seq_file.h>
17#include <linux/mount.h>
18#include <linux/kthread.h>
19#include <linux/delay.h>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050020#include <linux/gfs2_ondisk.h>
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040021#include <linux/crc32.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020022#include <linux/lm_interface.h>
Steven Whitehouse719ee342008-09-18 13:53:59 +010023#include <linux/time.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000024
25#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050026#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000027#include "glock.h"
28#include "inode.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000029#include "log.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000030#include "quota.h"
31#include "recovery.h"
32#include "rgrp.h"
33#include "super.h"
34#include "sys.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050035#include "util.h"
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040036#include "trans.h"
37#include "dir.h"
38#include "eattr.h"
39#include "bmap.h"
Steven Whitehouse719ee342008-09-18 13:53:59 +010040#include "meta_io.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000041
Steven Whitehouse6f04c1c2009-01-06 11:52:25 +000042#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
43
David Teiglandb3b94fa2006-01-16 16:50:04 +000044/**
45 * gfs2_write_inode - Make sure the inode is stable on the disk
46 * @inode: The inode
47 * @sync: synchronous write flag
48 *
49 * Returns: errno
50 */
51
52static int gfs2_write_inode(struct inode *inode, int sync)
53{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040054 struct gfs2_inode *ip = GFS2_I(inode);
Steven Whitehouse719ee342008-09-18 13:53:59 +010055 struct gfs2_sbd *sdp = GFS2_SB(inode);
56 struct gfs2_holder gh;
57 struct buffer_head *bh;
58 struct timespec atime;
59 struct gfs2_dinode *di;
60 int ret = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +000061
Steven Whitehouse719ee342008-09-18 13:53:59 +010062 /* Check this is a "normal" inode, etc */
63 if (!test_bit(GIF_USER, &ip->i_flags) ||
64 (current->flags & PF_MEMALLOC))
65 return 0;
66 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
67 if (ret)
68 goto do_flush;
69 ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
70 if (ret)
71 goto do_unlock;
72 ret = gfs2_meta_inode_buffer(ip, &bh);
73 if (ret == 0) {
74 di = (struct gfs2_dinode *)bh->b_data;
75 atime.tv_sec = be64_to_cpu(di->di_atime);
76 atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
77 if (timespec_compare(&inode->i_atime, &atime) > 0) {
78 gfs2_trans_add_bh(ip->i_gl, bh, 1);
79 gfs2_dinode_out(ip, bh->b_data);
80 }
81 brelse(bh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040082 }
Steven Whitehouse719ee342008-09-18 13:53:59 +010083 gfs2_trans_end(sdp);
84do_unlock:
85 gfs2_glock_dq_uninit(&gh);
86do_flush:
87 if (sync != 0)
88 gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
89 return ret;
David Teiglandb3b94fa2006-01-16 16:50:04 +000090}
91
92/**
Steven Whitehouse9b8df982008-08-08 13:45:13 +010093 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
94 * @sdp: the filesystem
95 *
96 * Returns: errno
97 */
98
Steven Whitehousefefc03b2008-12-19 15:32:06 +000099static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100100{
101 struct gfs2_holder t_gh;
102 int error;
103
104 gfs2_quota_sync(sdp);
105 gfs2_statfs_sync(sdp);
106
107 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
108 &t_gh);
109 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
110 return error;
111
112 gfs2_meta_syncfs(sdp);
113 gfs2_log_shutdown(sdp);
114
115 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
116
117 if (t_gh.gh_gl)
118 gfs2_glock_dq_uninit(&t_gh);
119
120 gfs2_quota_cleanup(sdp);
121
122 return error;
123}
124
125/**
Steven Whitehousefefc03b2008-12-19 15:32:06 +0000126 * gfs2_put_super - Unmount the filesystem
127 * @sb: The VFS superblock
128 *
129 */
130
131static void gfs2_put_super(struct super_block *sb)
132{
133 struct gfs2_sbd *sdp = sb->s_fs_info;
134 int error;
135
136 /* Unfreeze the filesystem, if we need to */
137
138 mutex_lock(&sdp->sd_freeze_lock);
139 if (sdp->sd_freeze_count)
140 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
141 mutex_unlock(&sdp->sd_freeze_lock);
142
143 kthread_stop(sdp->sd_quotad_process);
144 kthread_stop(sdp->sd_logd_process);
145 kthread_stop(sdp->sd_recoverd_process);
146
147 if (!(sb->s_flags & MS_RDONLY)) {
148 error = gfs2_make_fs_ro(sdp);
149 if (error)
150 gfs2_io_error(sdp);
151 }
152 /* At this point, we're through modifying the disk */
153
154 /* Release stuff */
155
156 iput(sdp->sd_jindex);
157 iput(sdp->sd_inum_inode);
158 iput(sdp->sd_statfs_inode);
159 iput(sdp->sd_rindex);
160 iput(sdp->sd_quota_inode);
161
162 gfs2_glock_put(sdp->sd_rename_gl);
163 gfs2_glock_put(sdp->sd_trans_gl);
164
165 if (!sdp->sd_args.ar_spectator) {
166 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
167 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
168 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
169 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
170 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
171 iput(sdp->sd_ir_inode);
172 iput(sdp->sd_sc_inode);
173 iput(sdp->sd_qc_inode);
174 }
175
176 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
177 gfs2_clear_rgrpd(sdp);
178 gfs2_jindex_free(sdp);
179 /* Take apart glock structures and buffer lists */
180 gfs2_gl_hash_clear(sdp);
181 /* Unmount the locking protocol */
182 gfs2_lm_unmount(sdp);
183
184 /* At this point, we're through participating in the lockspace */
185 gfs2_sys_fs_del(sdp);
Steven Whitehousefefc03b2008-12-19 15:32:06 +0000186}
187
188/**
Steven Whitehouse4a221952006-11-01 09:57:57 -0500189 * gfs2_write_super
190 * @sb: the superblock
David Teiglandb3b94fa2006-01-16 16:50:04 +0000191 *
David Teiglandb3b94fa2006-01-16 16:50:04 +0000192 */
193
194static void gfs2_write_super(struct super_block *sb)
195{
Steven Whitehouse4a221952006-11-01 09:57:57 -0500196 sb->s_dirt = 0;
197}
198
199/**
200 * gfs2_sync_fs - sync the filesystem
201 * @sb: the superblock
202 *
203 * Flushes the log to disk.
204 */
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100205
Steven Whitehouse4a221952006-11-01 09:57:57 -0500206static int gfs2_sync_fs(struct super_block *sb, int wait)
207{
208 sb->s_dirt = 0;
Bob Peterson9171f5a2008-06-09 12:08:23 -0500209 if (wait && sb->s_fs_info)
Steven Whitehouseb0041572006-11-23 10:51:34 -0500210 gfs2_log_flush(sb->s_fs_info, NULL);
Steven Whitehouse4a221952006-11-01 09:57:57 -0500211 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000212}
213
214/**
Takashi Satoc4be0c12009-01-09 16:40:58 -0800215 * gfs2_freeze - prevent further writes to the filesystem
David Teiglandb3b94fa2006-01-16 16:50:04 +0000216 * @sb: the VFS structure for the filesystem
217 *
218 */
219
Takashi Satoc4be0c12009-01-09 16:40:58 -0800220static int gfs2_freeze(struct super_block *sb)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000221{
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500222 struct gfs2_sbd *sdp = sb->s_fs_info;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000223 int error;
224
David Teiglandc3780512006-12-06 11:46:33 -0600225 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
Takashi Satoc4be0c12009-01-09 16:40:58 -0800226 return -EINVAL;
David Teiglandc3780512006-12-06 11:46:33 -0600227
David Teiglandb3b94fa2006-01-16 16:50:04 +0000228 for (;;) {
229 error = gfs2_freeze_fs(sdp);
230 if (!error)
231 break;
232
233 switch (error) {
234 case -EBUSY:
235 fs_err(sdp, "waiting for recovery before freeze\n");
236 break;
237
238 default:
239 fs_err(sdp, "error freezing FS: %d\n", error);
240 break;
241 }
242
243 fs_err(sdp, "retrying...\n");
244 msleep(1000);
245 }
Takashi Satoc4be0c12009-01-09 16:40:58 -0800246 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000247}
248
249/**
Takashi Satoc4be0c12009-01-09 16:40:58 -0800250 * gfs2_unfreeze - reallow writes to the filesystem
David Teiglandb3b94fa2006-01-16 16:50:04 +0000251 * @sb: the VFS structure for the filesystem
252 *
253 */
254
Takashi Satoc4be0c12009-01-09 16:40:58 -0800255static int gfs2_unfreeze(struct super_block *sb)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000256{
Steven Whitehouse2bdbc5d2006-09-05 09:34:20 -0400257 gfs2_unfreeze_fs(sb->s_fs_info);
Takashi Satoc4be0c12009-01-09 16:40:58 -0800258 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000259}
260
261/**
Steven Whitehouse2bfb6442008-11-26 13:30:49 +0000262 * statfs_fill - fill in the sg for a given RG
263 * @rgd: the RG
264 * @sc: the sc structure
265 *
266 * Returns: 0 on success, -ESTALE if the LVB is invalid
267 */
268
269static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
270 struct gfs2_statfs_change_host *sc)
271{
272 gfs2_rgrp_verify(rgd);
273 sc->sc_total += rgd->rd_data;
274 sc->sc_free += rgd->rd_free;
275 sc->sc_dinodes += rgd->rd_dinodes;
276 return 0;
277}
278
279/**
280 * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
281 * @sdp: the filesystem
282 * @sc: the sc info that will be returned
283 *
284 * Any error (other than a signal) will cause this routine to fall back
285 * to the synchronous version.
286 *
287 * FIXME: This really shouldn't busy wait like this.
288 *
289 * Returns: errno
290 */
291
292static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
293{
294 struct gfs2_holder ri_gh;
295 struct gfs2_rgrpd *rgd_next;
296 struct gfs2_holder *gha, *gh;
297 unsigned int slots = 64;
298 unsigned int x;
299 int done;
300 int error = 0, err;
301
302 memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
303 gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
304 if (!gha)
305 return -ENOMEM;
306
307 error = gfs2_rindex_hold(sdp, &ri_gh);
308 if (error)
309 goto out;
310
311 rgd_next = gfs2_rgrpd_get_first(sdp);
312
313 for (;;) {
314 done = 1;
315
316 for (x = 0; x < slots; x++) {
317 gh = gha + x;
318
319 if (gh->gh_gl && gfs2_glock_poll(gh)) {
320 err = gfs2_glock_wait(gh);
321 if (err) {
322 gfs2_holder_uninit(gh);
323 error = err;
324 } else {
325 if (!error)
326 error = statfs_slow_fill(
327 gh->gh_gl->gl_object, sc);
328 gfs2_glock_dq_uninit(gh);
329 }
330 }
331
332 if (gh->gh_gl)
333 done = 0;
334 else if (rgd_next && !error) {
335 error = gfs2_glock_nq_init(rgd_next->rd_gl,
336 LM_ST_SHARED,
337 GL_ASYNC,
338 gh);
339 rgd_next = gfs2_rgrpd_get_next(rgd_next);
340 done = 0;
341 }
342
343 if (signal_pending(current))
344 error = -ERESTARTSYS;
345 }
346
347 if (done)
348 break;
349
350 yield();
351 }
352
353 gfs2_glock_dq_uninit(&ri_gh);
354
355out:
356 kfree(gha);
357 return error;
358}
359
360/**
361 * gfs2_statfs_i - Do a statfs
362 * @sdp: the filesystem
363 * @sg: the sg structure
364 *
365 * Returns: errno
366 */
367
368static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
369{
370 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
371 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
372
373 spin_lock(&sdp->sd_statfs_spin);
374
375 *sc = *m_sc;
376 sc->sc_total += l_sc->sc_total;
377 sc->sc_free += l_sc->sc_free;
378 sc->sc_dinodes += l_sc->sc_dinodes;
379
380 spin_unlock(&sdp->sd_statfs_spin);
381
382 if (sc->sc_free < 0)
383 sc->sc_free = 0;
384 if (sc->sc_free > sc->sc_total)
385 sc->sc_free = sc->sc_total;
386 if (sc->sc_dinodes < 0)
387 sc->sc_dinodes = 0;
388
389 return 0;
390}
391
392/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000393 * gfs2_statfs - Gather and return stats about the filesystem
394 * @sb: The superblock
395 * @statfsbuf: The buffer
396 *
397 * Returns: 0 on success or error code
398 */
399
Steven Whitehouse0c0834a2006-07-03 11:38:01 -0400400static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000401{
Steven Whitehouse0c0834a2006-07-03 11:38:01 -0400402 struct super_block *sb = dentry->d_inode->i_sb;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500403 struct gfs2_sbd *sdp = sb->s_fs_info;
Al Virobd209cc2006-10-13 23:43:19 -0400404 struct gfs2_statfs_change_host sc;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000405 int error;
406
David Teiglandb3b94fa2006-01-16 16:50:04 +0000407 if (gfs2_tune_get(sdp, gt_statfs_slow))
408 error = gfs2_statfs_slow(sdp, &sc);
409 else
410 error = gfs2_statfs_i(sdp, &sc);
411
412 if (error)
413 return error;
414
David Teiglandb3b94fa2006-01-16 16:50:04 +0000415 buf->f_type = GFS2_MAGIC;
416 buf->f_bsize = sdp->sd_sb.sb_bsize;
417 buf->f_blocks = sc.sc_total;
418 buf->f_bfree = sc.sc_free;
419 buf->f_bavail = sc.sc_free;
420 buf->f_files = sc.sc_dinodes + sc.sc_free;
421 buf->f_ffree = sc.sc_free;
422 buf->f_namelen = GFS2_FNAMESIZE;
423
424 return 0;
425}
426
427/**
428 * gfs2_remount_fs - called when the FS is remounted
429 * @sb: the filesystem
430 * @flags: the remount flags
431 * @data: extra data passed in (not used right now)
432 *
433 * Returns: errno
434 */
435
436static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
437{
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500438 struct gfs2_sbd *sdp = sb->s_fs_info;
Steven Whitehouse6f04c1c2009-01-06 11:52:25 +0000439 struct gfs2_args args = sdp->sd_args; /* Default to current settings */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000440 int error;
441
Steven Whitehouse6f04c1c2009-01-06 11:52:25 +0000442 error = gfs2_mount_args(sdp, &args, data);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000443 if (error)
444 return error;
445
Steven Whitehouse6f04c1c2009-01-06 11:52:25 +0000446 /* Not allowed to change locking details */
447 if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
448 strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
449 strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
450 return -EINVAL;
451
452 /* Some flags must not be changed */
453 if (args_neq(&args, &sdp->sd_args, spectator) ||
454 args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
455 args_neq(&args, &sdp->sd_args, localflocks) ||
456 args_neq(&args, &sdp->sd_args, localcaching) ||
457 args_neq(&args, &sdp->sd_args, meta))
458 return -EINVAL;
459
David Teiglandb3b94fa2006-01-16 16:50:04 +0000460 if (sdp->sd_args.ar_spectator)
461 *flags |= MS_RDONLY;
Steven Whitehouse6f04c1c2009-01-06 11:52:25 +0000462
463 if ((sb->s_flags ^ *flags) & MS_RDONLY) {
464 if (*flags & MS_RDONLY)
465 error = gfs2_make_fs_ro(sdp);
466 else
David Teiglandb3b94fa2006-01-16 16:50:04 +0000467 error = gfs2_make_fs_rw(sdp);
Steven Whitehouse6f04c1c2009-01-06 11:52:25 +0000468 if (error)
469 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000470 }
471
Steven Whitehouse6f04c1c2009-01-06 11:52:25 +0000472 sdp->sd_args = args;
473 if (sdp->sd_args.ar_posix_acl)
474 sb->s_flags |= MS_POSIXACL;
475 else
476 sb->s_flags &= ~MS_POSIXACL;
477 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000478}
479
480/**
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000481 * gfs2_drop_inode - Drop an inode (test for remote unlink)
482 * @inode: The inode to drop
483 *
484 * If we've received a callback on an iopen lock then its because a
485 * remote node tried to deallocate the inode but failed due to this node
486 * still having the inode open. Here we mark the link count zero
487 * since we know that it must have reached zero if the GLF_DEMOTE flag
488 * is set on the iopen glock. If we didn't do a disk read since the
489 * remote node removed the final link then we might otherwise miss
490 * this event. This check ensures that this node will deallocate the
491 * inode's blocks, or alternatively pass the baton on to another
492 * node for later deallocation.
493 */
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100494
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000495static void gfs2_drop_inode(struct inode *inode)
496{
Bob Peterson091806ed2008-04-29 12:35:48 -0500497 struct gfs2_inode *ip = GFS2_I(inode);
498
499 if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000500 struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
501 if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
502 clear_nlink(inode);
503 }
504 generic_drop_inode(inode);
505}
506
507/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000508 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
509 * @inode: The VFS inode
510 *
511 */
512
513static void gfs2_clear_inode(struct inode *inode)
514{
Bob Peterson091806ed2008-04-29 12:35:48 -0500515 struct gfs2_inode *ip = GFS2_I(inode);
516
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400517 /* This tells us its a "real" inode and not one which only
518 * serves to contain an address space (see rgrp.c, meta_io.c)
519 * which therefore doesn't have its own glocks.
520 */
Bob Peterson091806ed2008-04-29 12:35:48 -0500521 if (test_bit(GIF_USER, &ip->i_flags)) {
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400522 ip->i_gl->gl_object = NULL;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400523 gfs2_glock_put(ip->i_gl);
524 ip->i_gl = NULL;
Abhijith Dasd93cfa92007-06-11 08:22:32 +0100525 if (ip->i_iopen_gh.gh_gl) {
526 ip->i_iopen_gh.gh_gl->gl_object = NULL;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400527 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
Abhijith Dasd93cfa92007-06-11 08:22:32 +0100528 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000529 }
530}
531
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100532static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
533{
534 do {
535 if (d1 == d2)
536 return 1;
537 d1 = d1->d_parent;
538 } while (!IS_ROOT(d1));
539 return 0;
540}
541
David Teiglandb3b94fa2006-01-16 16:50:04 +0000542/**
543 * gfs2_show_options - Show mount options for /proc/mounts
544 * @s: seq_file structure
545 * @mnt: vfsmount
546 *
547 * Returns: 0 on success or error code
548 */
549
550static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
551{
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500552 struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000553 struct gfs2_args *args = &sdp->sd_args;
554
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100555 if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
556 seq_printf(s, ",meta");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000557 if (args->ar_lockproto[0])
558 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
559 if (args->ar_locktable[0])
560 seq_printf(s, ",locktable=%s", args->ar_locktable);
561 if (args->ar_hostdata[0])
562 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
563 if (args->ar_spectator)
564 seq_printf(s, ",spectator");
565 if (args->ar_ignore_local_fs)
566 seq_printf(s, ",ignore_local_fs");
567 if (args->ar_localflocks)
568 seq_printf(s, ",localflocks");
569 if (args->ar_localcaching)
570 seq_printf(s, ",localcaching");
571 if (args->ar_debug)
572 seq_printf(s, ",debug");
573 if (args->ar_upgrade)
574 seq_printf(s, ",upgrade");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000575 if (args->ar_posix_acl)
576 seq_printf(s, ",acl");
577 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
578 char *state;
579 switch (args->ar_quota) {
580 case GFS2_QUOTA_OFF:
581 state = "off";
582 break;
583 case GFS2_QUOTA_ACCOUNT:
584 state = "account";
585 break;
586 case GFS2_QUOTA_ON:
587 state = "on";
588 break;
589 default:
590 state = "unknown";
591 break;
592 }
593 seq_printf(s, ",quota=%s", state);
594 }
595 if (args->ar_suiddir)
596 seq_printf(s, ",suiddir");
597 if (args->ar_data != GFS2_DATA_DEFAULT) {
598 char *state;
599 switch (args->ar_data) {
600 case GFS2_DATA_WRITEBACK:
601 state = "writeback";
602 break;
603 case GFS2_DATA_ORDERED:
604 state = "ordered";
605 break;
606 default:
607 state = "unknown";
608 break;
609 }
610 seq_printf(s, ",data=%s", state);
611 }
612
613 return 0;
614}
615
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400616/*
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400617 * We have to (at the moment) hold the inodes main lock to cover
618 * the gap between unlocking the shared lock on the iopen lock and
619 * taking the exclusive lock. I'd rather do a shared -> exclusive
620 * conversion on the iopen lock, but we can change that later. This
621 * is safe, just less efficient.
622 */
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100623
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400624static void gfs2_delete_inode(struct inode *inode)
625{
626 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
627 struct gfs2_inode *ip = GFS2_I(inode);
628 struct gfs2_holder gh;
629 int error;
630
Bob Peterson091806ed2008-04-29 12:35:48 -0500631 if (!test_bit(GIF_USER, &ip->i_flags))
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400632 goto out;
633
Abhijith Dasd93cfa92007-06-11 08:22:32 +0100634 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400635 if (unlikely(error)) {
636 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
637 goto out;
638 }
639
Abhijith Dasd93cfa92007-06-11 08:22:32 +0100640 gfs2_glock_dq_wait(&ip->i_iopen_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400641 gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
642 error = gfs2_glock_nq(&ip->i_iopen_gh);
643 if (error)
Steven Whitehouse1bb73222008-10-15 09:46:39 +0100644 goto out_truncate;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400645
Steven Whitehouseb60623c2006-11-01 12:22:46 -0500646 if (S_ISDIR(inode->i_mode) &&
Steven Whitehouse383f01f2008-11-04 10:05:22 +0000647 (ip->i_diskflags & GFS2_DIF_EXHASH)) {
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400648 error = gfs2_dir_exhash_dealloc(ip);
649 if (error)
650 goto out_unlock;
651 }
652
Steven Whitehouse3767ac22008-11-03 14:28:42 +0000653 if (ip->i_eattr) {
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400654 error = gfs2_ea_dealloc(ip);
655 if (error)
656 goto out_unlock;
657 }
658
659 if (!gfs2_is_stuffed(ip)) {
660 error = gfs2_file_dealloc(ip);
661 if (error)
662 goto out_unlock;
663 }
664
665 error = gfs2_dinode_dealloc(ip);
Steven Whitehouse16615be2007-09-17 10:59:52 +0100666 if (error)
667 goto out_unlock;
668
Steven Whitehouse1bb73222008-10-15 09:46:39 +0100669out_truncate:
Steven Whitehouse16615be2007-09-17 10:59:52 +0100670 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
671 if (error)
672 goto out_unlock;
673 /* Needs to be done before glock release & also in a transaction */
Steven Whitehouse49686f72007-01-08 14:31:40 +0000674 truncate_inode_pages(&inode->i_data, 0);
Steven Whitehouse16615be2007-09-17 10:59:52 +0100675 gfs2_trans_end(sdp);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400676
677out_unlock:
Steven Whitehouse1bb73222008-10-15 09:46:39 +0100678 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
679 gfs2_glock_dq(&ip->i_iopen_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400680 gfs2_holder_uninit(&ip->i_iopen_gh);
681 gfs2_glock_dq_uninit(&gh);
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000682 if (error && error != GLR_TRYFAILED)
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400683 fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
684out:
685 truncate_inode_pages(&inode->i_data, 0);
686 clear_inode(inode);
687}
688
Steven Whitehouse320dd102006-05-18 16:25:27 -0400689static struct inode *gfs2_alloc_inode(struct super_block *sb)
690{
Steven Whitehouse320dd102006-05-18 16:25:27 -0400691 struct gfs2_inode *ip;
692
693 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
694 if (ip) {
695 ip->i_flags = 0;
696 ip->i_gl = NULL;
Steven Whitehouse320dd102006-05-18 16:25:27 -0400697 }
698 return &ip->i_inode;
699}
700
701static void gfs2_destroy_inode(struct inode *inode)
702{
703 kmem_cache_free(gfs2_inode_cachep, inode);
704}
705
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800706const struct super_operations gfs2_super_ops = {
Steven Whitehouse4a221952006-11-01 09:57:57 -0500707 .alloc_inode = gfs2_alloc_inode,
708 .destroy_inode = gfs2_destroy_inode,
709 .write_inode = gfs2_write_inode,
710 .delete_inode = gfs2_delete_inode,
Steven Whitehousefefc03b2008-12-19 15:32:06 +0000711 .put_super = gfs2_put_super,
Steven Whitehouse4a221952006-11-01 09:57:57 -0500712 .write_super = gfs2_write_super,
713 .sync_fs = gfs2_sync_fs,
Takashi Satoc4be0c12009-01-09 16:40:58 -0800714 .freeze_fs = gfs2_freeze,
715 .unfreeze_fs = gfs2_unfreeze,
Steven Whitehouse4a221952006-11-01 09:57:57 -0500716 .statfs = gfs2_statfs,
717 .remount_fs = gfs2_remount_fs,
718 .clear_inode = gfs2_clear_inode,
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000719 .drop_inode = gfs2_drop_inode,
Steven Whitehouse4a221952006-11-01 09:57:57 -0500720 .show_options = gfs2_show_options,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000721};
722