blob: ad36af254fee38e0d67590a679721239e688a6a2 [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"
30#include "mount.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000031#include "quota.h"
32#include "recovery.h"
33#include "rgrp.h"
34#include "super.h"
35#include "sys.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050036#include "util.h"
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040037#include "trans.h"
38#include "dir.h"
39#include "eattr.h"
40#include "bmap.h"
Steven Whitehouse719ee342008-09-18 13:53:59 +010041#include "meta_io.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000042
43/**
44 * gfs2_write_inode - Make sure the inode is stable on the disk
45 * @inode: The inode
46 * @sync: synchronous write flag
47 *
48 * Returns: errno
49 */
50
51static int gfs2_write_inode(struct inode *inode, int sync)
52{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040053 struct gfs2_inode *ip = GFS2_I(inode);
Steven Whitehouse719ee342008-09-18 13:53:59 +010054 struct gfs2_sbd *sdp = GFS2_SB(inode);
55 struct gfs2_holder gh;
56 struct buffer_head *bh;
57 struct timespec atime;
58 struct gfs2_dinode *di;
59 int ret = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +000060
Steven Whitehouse719ee342008-09-18 13:53:59 +010061 /* Check this is a "normal" inode, etc */
62 if (!test_bit(GIF_USER, &ip->i_flags) ||
63 (current->flags & PF_MEMALLOC))
64 return 0;
65 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
66 if (ret)
67 goto do_flush;
68 ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
69 if (ret)
70 goto do_unlock;
71 ret = gfs2_meta_inode_buffer(ip, &bh);
72 if (ret == 0) {
73 di = (struct gfs2_dinode *)bh->b_data;
74 atime.tv_sec = be64_to_cpu(di->di_atime);
75 atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
76 if (timespec_compare(&inode->i_atime, &atime) > 0) {
77 gfs2_trans_add_bh(ip->i_gl, bh, 1);
78 gfs2_dinode_out(ip, bh->b_data);
79 }
80 brelse(bh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040081 }
Steven Whitehouse719ee342008-09-18 13:53:59 +010082 gfs2_trans_end(sdp);
83do_unlock:
84 gfs2_glock_dq_uninit(&gh);
85do_flush:
86 if (sync != 0)
87 gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
88 return ret;
David Teiglandb3b94fa2006-01-16 16:50:04 +000089}
90
91/**
Steven Whitehouse9b8df982008-08-08 13:45:13 +010092 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
93 * @sdp: the filesystem
94 *
95 * Returns: errno
96 */
97
98static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
99{
100 struct gfs2_holder t_gh;
101 int error;
102
103 gfs2_quota_sync(sdp);
104 gfs2_statfs_sync(sdp);
105
106 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
107 &t_gh);
108 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
109 return error;
110
111 gfs2_meta_syncfs(sdp);
112 gfs2_log_shutdown(sdp);
113
114 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
115
116 if (t_gh.gh_gl)
117 gfs2_glock_dq_uninit(&t_gh);
118
119 gfs2_quota_cleanup(sdp);
120
121 return error;
122}
123
124/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000125 * gfs2_put_super - Unmount the filesystem
126 * @sb: The VFS superblock
127 *
128 */
129
130static void gfs2_put_super(struct super_block *sb)
131{
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500132 struct gfs2_sbd *sdp = sb->s_fs_info;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000133 int error;
134
David Teiglandb3b94fa2006-01-16 16:50:04 +0000135 /* Unfreeze the filesystem, if we need to */
136
Steven Whitehousef55ab262006-02-21 12:51:39 +0000137 mutex_lock(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000138 if (sdp->sd_freeze_count)
139 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
Steven Whitehousef55ab262006-02-21 12:51:39 +0000140 mutex_unlock(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000141
David Teiglandb3b94fa2006-01-16 16:50:04 +0000142 kthread_stop(sdp->sd_quotad_process);
143 kthread_stop(sdp->sd_logd_process);
144 kthread_stop(sdp->sd_recoverd_process);
145 while (sdp->sd_glockd_num--)
146 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000147
148 if (!(sb->s_flags & MS_RDONLY)) {
149 error = gfs2_make_fs_ro(sdp);
150 if (error)
151 gfs2_io_error(sdp);
152 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000153 /* At this point, we're through modifying the disk */
154
155 /* Release stuff */
156
Steven Whitehousef42faf42006-01-30 18:34:10 +0000157 iput(sdp->sd_jindex);
158 iput(sdp->sd_inum_inode);
159 iput(sdp->sd_statfs_inode);
160 iput(sdp->sd_rindex);
161 iput(sdp->sd_quota_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000162
163 gfs2_glock_put(sdp->sd_rename_gl);
164 gfs2_glock_put(sdp->sd_trans_gl);
165
166 if (!sdp->sd_args.ar_spectator) {
167 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
168 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
169 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
170 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000171 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000172 iput(sdp->sd_ir_inode);
173 iput(sdp->sd_sc_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000174 iput(sdp->sd_qc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000175 }
176
177 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000178 gfs2_clear_rgrpd(sdp);
179 gfs2_jindex_free(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000180 /* Take apart glock structures and buffer lists */
Steven Whitehouse1bdad602008-06-03 14:09:53 +0100181 gfs2_gl_hash_clear(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000182 /* Unmount the locking protocol */
183 gfs2_lm_unmount(sdp);
184
185 /* At this point, we're through participating in the lockspace */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000186 gfs2_sys_fs_del(sdp);
Steven Whitehouseff6af412006-09-09 16:56:34 -0400187 kfree(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000188}
189
190/**
Steven Whitehouse4a221952006-11-01 09:57:57 -0500191 * gfs2_write_super
192 * @sb: the superblock
David Teiglandb3b94fa2006-01-16 16:50:04 +0000193 *
David Teiglandb3b94fa2006-01-16 16:50:04 +0000194 */
195
196static void gfs2_write_super(struct super_block *sb)
197{
Steven Whitehouse4a221952006-11-01 09:57:57 -0500198 sb->s_dirt = 0;
199}
200
201/**
202 * gfs2_sync_fs - sync the filesystem
203 * @sb: the superblock
204 *
205 * Flushes the log to disk.
206 */
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100207
Steven Whitehouse4a221952006-11-01 09:57:57 -0500208static int gfs2_sync_fs(struct super_block *sb, int wait)
209{
210 sb->s_dirt = 0;
Bob Peterson9171f5a2008-06-09 12:08:23 -0500211 if (wait && sb->s_fs_info)
Steven Whitehouseb0041572006-11-23 10:51:34 -0500212 gfs2_log_flush(sb->s_fs_info, NULL);
Steven Whitehouse4a221952006-11-01 09:57:57 -0500213 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000214}
215
216/**
217 * gfs2_write_super_lockfs - prevent further writes to the filesystem
218 * @sb: the VFS structure for the filesystem
219 *
220 */
221
222static void gfs2_write_super_lockfs(struct super_block *sb)
223{
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500224 struct gfs2_sbd *sdp = sb->s_fs_info;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000225 int error;
226
David Teiglandc3780512006-12-06 11:46:33 -0600227 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
228 return;
229
David Teiglandb3b94fa2006-01-16 16:50:04 +0000230 for (;;) {
231 error = gfs2_freeze_fs(sdp);
232 if (!error)
233 break;
234
235 switch (error) {
236 case -EBUSY:
237 fs_err(sdp, "waiting for recovery before freeze\n");
238 break;
239
240 default:
241 fs_err(sdp, "error freezing FS: %d\n", error);
242 break;
243 }
244
245 fs_err(sdp, "retrying...\n");
246 msleep(1000);
247 }
248}
249
250/**
251 * gfs2_unlockfs - reallow writes to the filesystem
252 * @sb: the VFS structure for the filesystem
253 *
254 */
255
256static void gfs2_unlockfs(struct super_block *sb)
257{
Steven Whitehouse2bdbc5d2006-09-05 09:34:20 -0400258 gfs2_unfreeze_fs(sb->s_fs_info);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000259}
260
261/**
262 * gfs2_statfs - Gather and return stats about the filesystem
263 * @sb: The superblock
264 * @statfsbuf: The buffer
265 *
266 * Returns: 0 on success or error code
267 */
268
Steven Whitehouse0c0834a2006-07-03 11:38:01 -0400269static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000270{
Steven Whitehouse0c0834a2006-07-03 11:38:01 -0400271 struct super_block *sb = dentry->d_inode->i_sb;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500272 struct gfs2_sbd *sdp = sb->s_fs_info;
Al Virobd209cc2006-10-13 23:43:19 -0400273 struct gfs2_statfs_change_host sc;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000274 int error;
275
David Teiglandb3b94fa2006-01-16 16:50:04 +0000276 if (gfs2_tune_get(sdp, gt_statfs_slow))
277 error = gfs2_statfs_slow(sdp, &sc);
278 else
279 error = gfs2_statfs_i(sdp, &sc);
280
281 if (error)
282 return error;
283
David Teiglandb3b94fa2006-01-16 16:50:04 +0000284 buf->f_type = GFS2_MAGIC;
285 buf->f_bsize = sdp->sd_sb.sb_bsize;
286 buf->f_blocks = sc.sc_total;
287 buf->f_bfree = sc.sc_free;
288 buf->f_bavail = sc.sc_free;
289 buf->f_files = sc.sc_dinodes + sc.sc_free;
290 buf->f_ffree = sc.sc_free;
291 buf->f_namelen = GFS2_FNAMESIZE;
292
293 return 0;
294}
295
296/**
297 * gfs2_remount_fs - called when the FS is remounted
298 * @sb: the filesystem
299 * @flags: the remount flags
300 * @data: extra data passed in (not used right now)
301 *
302 * Returns: errno
303 */
304
305static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
306{
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500307 struct gfs2_sbd *sdp = sb->s_fs_info;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000308 int error;
309
David Teiglandb3b94fa2006-01-16 16:50:04 +0000310 error = gfs2_mount_args(sdp, data, 1);
311 if (error)
312 return error;
313
314 if (sdp->sd_args.ar_spectator)
315 *flags |= MS_RDONLY;
316 else {
317 if (*flags & MS_RDONLY) {
318 if (!(sb->s_flags & MS_RDONLY))
319 error = gfs2_make_fs_ro(sdp);
320 } else if (!(*flags & MS_RDONLY) &&
321 (sb->s_flags & MS_RDONLY)) {
322 error = gfs2_make_fs_rw(sdp);
323 }
324 }
325
David Teiglandb3b94fa2006-01-16 16:50:04 +0000326 return error;
327}
328
329/**
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000330 * gfs2_drop_inode - Drop an inode (test for remote unlink)
331 * @inode: The inode to drop
332 *
333 * If we've received a callback on an iopen lock then its because a
334 * remote node tried to deallocate the inode but failed due to this node
335 * still having the inode open. Here we mark the link count zero
336 * since we know that it must have reached zero if the GLF_DEMOTE flag
337 * is set on the iopen glock. If we didn't do a disk read since the
338 * remote node removed the final link then we might otherwise miss
339 * this event. This check ensures that this node will deallocate the
340 * inode's blocks, or alternatively pass the baton on to another
341 * node for later deallocation.
342 */
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100343
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000344static void gfs2_drop_inode(struct inode *inode)
345{
Bob Peterson091806ed2008-04-29 12:35:48 -0500346 struct gfs2_inode *ip = GFS2_I(inode);
347
348 if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000349 struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
350 if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
351 clear_nlink(inode);
352 }
353 generic_drop_inode(inode);
354}
355
356/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000357 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
358 * @inode: The VFS inode
359 *
360 */
361
362static void gfs2_clear_inode(struct inode *inode)
363{
Bob Peterson091806ed2008-04-29 12:35:48 -0500364 struct gfs2_inode *ip = GFS2_I(inode);
365
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400366 /* This tells us its a "real" inode and not one which only
367 * serves to contain an address space (see rgrp.c, meta_io.c)
368 * which therefore doesn't have its own glocks.
369 */
Bob Peterson091806ed2008-04-29 12:35:48 -0500370 if (test_bit(GIF_USER, &ip->i_flags)) {
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400371 ip->i_gl->gl_object = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000372 gfs2_glock_schedule_for_reclaim(ip->i_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400373 gfs2_glock_put(ip->i_gl);
374 ip->i_gl = NULL;
Abhijith Dasd93cfa92007-06-11 08:22:32 +0100375 if (ip->i_iopen_gh.gh_gl) {
376 ip->i_iopen_gh.gh_gl->gl_object = NULL;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400377 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
Abhijith Dasd93cfa92007-06-11 08:22:32 +0100378 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000379 }
380}
381
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100382static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
383{
384 do {
385 if (d1 == d2)
386 return 1;
387 d1 = d1->d_parent;
388 } while (!IS_ROOT(d1));
389 return 0;
390}
391
David Teiglandb3b94fa2006-01-16 16:50:04 +0000392/**
393 * gfs2_show_options - Show mount options for /proc/mounts
394 * @s: seq_file structure
395 * @mnt: vfsmount
396 *
397 * Returns: 0 on success or error code
398 */
399
400static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
401{
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500402 struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000403 struct gfs2_args *args = &sdp->sd_args;
404
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100405 if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
406 seq_printf(s, ",meta");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000407 if (args->ar_lockproto[0])
408 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
409 if (args->ar_locktable[0])
410 seq_printf(s, ",locktable=%s", args->ar_locktable);
411 if (args->ar_hostdata[0])
412 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
413 if (args->ar_spectator)
414 seq_printf(s, ",spectator");
415 if (args->ar_ignore_local_fs)
416 seq_printf(s, ",ignore_local_fs");
417 if (args->ar_localflocks)
418 seq_printf(s, ",localflocks");
419 if (args->ar_localcaching)
420 seq_printf(s, ",localcaching");
421 if (args->ar_debug)
422 seq_printf(s, ",debug");
423 if (args->ar_upgrade)
424 seq_printf(s, ",upgrade");
425 if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT)
426 seq_printf(s, ",num_glockd=%u", args->ar_num_glockd);
427 if (args->ar_posix_acl)
428 seq_printf(s, ",acl");
429 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
430 char *state;
431 switch (args->ar_quota) {
432 case GFS2_QUOTA_OFF:
433 state = "off";
434 break;
435 case GFS2_QUOTA_ACCOUNT:
436 state = "account";
437 break;
438 case GFS2_QUOTA_ON:
439 state = "on";
440 break;
441 default:
442 state = "unknown";
443 break;
444 }
445 seq_printf(s, ",quota=%s", state);
446 }
447 if (args->ar_suiddir)
448 seq_printf(s, ",suiddir");
449 if (args->ar_data != GFS2_DATA_DEFAULT) {
450 char *state;
451 switch (args->ar_data) {
452 case GFS2_DATA_WRITEBACK:
453 state = "writeback";
454 break;
455 case GFS2_DATA_ORDERED:
456 state = "ordered";
457 break;
458 default:
459 state = "unknown";
460 break;
461 }
462 seq_printf(s, ",data=%s", state);
463 }
464
465 return 0;
466}
467
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400468/*
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400469 * We have to (at the moment) hold the inodes main lock to cover
470 * the gap between unlocking the shared lock on the iopen lock and
471 * taking the exclusive lock. I'd rather do a shared -> exclusive
472 * conversion on the iopen lock, but we can change that later. This
473 * is safe, just less efficient.
474 */
Steven Whitehouse9b8df982008-08-08 13:45:13 +0100475
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400476static void gfs2_delete_inode(struct inode *inode)
477{
478 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
479 struct gfs2_inode *ip = GFS2_I(inode);
480 struct gfs2_holder gh;
481 int error;
482
Bob Peterson091806ed2008-04-29 12:35:48 -0500483 if (!test_bit(GIF_USER, &ip->i_flags))
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400484 goto out;
485
Abhijith Dasd93cfa92007-06-11 08:22:32 +0100486 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400487 if (unlikely(error)) {
488 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
489 goto out;
490 }
491
Abhijith Dasd93cfa92007-06-11 08:22:32 +0100492 gfs2_glock_dq_wait(&ip->i_iopen_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400493 gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
494 error = gfs2_glock_nq(&ip->i_iopen_gh);
495 if (error)
Steven Whitehouse1bb73222008-10-15 09:46:39 +0100496 goto out_truncate;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400497
Steven Whitehouseb60623c2006-11-01 12:22:46 -0500498 if (S_ISDIR(inode->i_mode) &&
Steven Whitehouse383f01f2008-11-04 10:05:22 +0000499 (ip->i_diskflags & GFS2_DIF_EXHASH)) {
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400500 error = gfs2_dir_exhash_dealloc(ip);
501 if (error)
502 goto out_unlock;
503 }
504
Steven Whitehouse3767ac22008-11-03 14:28:42 +0000505 if (ip->i_eattr) {
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400506 error = gfs2_ea_dealloc(ip);
507 if (error)
508 goto out_unlock;
509 }
510
511 if (!gfs2_is_stuffed(ip)) {
512 error = gfs2_file_dealloc(ip);
513 if (error)
514 goto out_unlock;
515 }
516
517 error = gfs2_dinode_dealloc(ip);
Steven Whitehouse16615be2007-09-17 10:59:52 +0100518 if (error)
519 goto out_unlock;
520
Steven Whitehouse1bb73222008-10-15 09:46:39 +0100521out_truncate:
Steven Whitehouse16615be2007-09-17 10:59:52 +0100522 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
523 if (error)
524 goto out_unlock;
525 /* Needs to be done before glock release & also in a transaction */
Steven Whitehouse49686f72007-01-08 14:31:40 +0000526 truncate_inode_pages(&inode->i_data, 0);
Steven Whitehouse16615be2007-09-17 10:59:52 +0100527 gfs2_trans_end(sdp);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400528
529out_unlock:
Steven Whitehouse1bb73222008-10-15 09:46:39 +0100530 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
531 gfs2_glock_dq(&ip->i_iopen_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400532 gfs2_holder_uninit(&ip->i_iopen_gh);
533 gfs2_glock_dq_uninit(&gh);
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000534 if (error && error != GLR_TRYFAILED)
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400535 fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
536out:
537 truncate_inode_pages(&inode->i_data, 0);
538 clear_inode(inode);
539}
540
Steven Whitehouse320dd102006-05-18 16:25:27 -0400541static struct inode *gfs2_alloc_inode(struct super_block *sb)
542{
Steven Whitehouse320dd102006-05-18 16:25:27 -0400543 struct gfs2_inode *ip;
544
545 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
546 if (ip) {
547 ip->i_flags = 0;
548 ip->i_gl = NULL;
Steven Whitehouse320dd102006-05-18 16:25:27 -0400549 }
550 return &ip->i_inode;
551}
552
553static void gfs2_destroy_inode(struct inode *inode)
554{
555 kmem_cache_free(gfs2_inode_cachep, inode);
556}
557
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800558const struct super_operations gfs2_super_ops = {
Steven Whitehouse4a221952006-11-01 09:57:57 -0500559 .alloc_inode = gfs2_alloc_inode,
560 .destroy_inode = gfs2_destroy_inode,
561 .write_inode = gfs2_write_inode,
562 .delete_inode = gfs2_delete_inode,
563 .put_super = gfs2_put_super,
564 .write_super = gfs2_write_super,
565 .sync_fs = gfs2_sync_fs,
566 .write_super_lockfs = gfs2_write_super_lockfs,
567 .unlockfs = gfs2_unlockfs,
568 .statfs = gfs2_statfs,
569 .remount_fs = gfs2_remount_fs,
570 .clear_inode = gfs2_clear_inode,
Steven Whitehouse3b8249f2007-03-16 09:40:31 +0000571 .drop_inode = gfs2_drop_inode,
Steven Whitehouse4a221952006-11-01 09:57:57 -0500572 .show_options = gfs2_show_options,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000573};
574