2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
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 version 2.
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/bio.h>
13 #include <linux/sched.h>
14 #include <linux/slab.h>
15 #include <linux/spinlock.h>
16 #include <linux/completion.h>
17 #include <linux/buffer_head.h>
18 #include <linux/statfs.h>
19 #include <linux/seq_file.h>
20 #include <linux/mount.h>
21 #include <linux/kthread.h>
22 #include <linux/delay.h>
23 #include <linux/gfs2_ondisk.h>
24 #include <linux/crc32.h>
25 #include <linux/time.h>
26 #include <linux/wait.h>
27 #include <linux/writeback.h>
28 #include <linux/backing-dev.h>
29 #include <linux/kernel.h>
49 #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
89 static const match_table_t tokens
= {
90 {Opt_lockproto
, "lockproto=%s"},
91 {Opt_locktable
, "locktable=%s"},
92 {Opt_hostdata
, "hostdata=%s"},
93 {Opt_spectator
, "spectator"},
94 {Opt_spectator
, "norecovery"},
95 {Opt_ignore_local_fs
, "ignore_local_fs"},
96 {Opt_localflocks
, "localflocks"},
97 {Opt_localcaching
, "localcaching"},
99 {Opt_nodebug
, "nodebug"},
100 {Opt_upgrade
, "upgrade"},
102 {Opt_noacl
, "noacl"},
103 {Opt_quota_off
, "quota=off"},
104 {Opt_quota_account
, "quota=account"},
105 {Opt_quota_on
, "quota=on"},
106 {Opt_quota
, "quota"},
107 {Opt_noquota
, "noquota"},
108 {Opt_suiddir
, "suiddir"},
109 {Opt_nosuiddir
, "nosuiddir"},
110 {Opt_data_writeback
, "data=writeback"},
111 {Opt_data_ordered
, "data=ordered"},
113 {Opt_discard
, "discard"},
114 {Opt_nodiscard
, "nodiscard"},
115 {Opt_commit
, "commit=%d"},
116 {Opt_err_withdraw
, "errors=withdraw"},
117 {Opt_err_panic
, "errors=panic"},
118 {Opt_statfs_quantum
, "statfs_quantum=%d"},
119 {Opt_statfs_percent
, "statfs_percent=%d"},
120 {Opt_quota_quantum
, "quota_quantum=%d"},
121 {Opt_barrier
, "barrier"},
122 {Opt_nobarrier
, "nobarrier"},
123 {Opt_rgrplvb
, "rgrplvb"},
124 {Opt_norgrplvb
, "norgrplvb"},
129 * gfs2_mount_args - Parse mount options
130 * @args: The structure into which the parsed options will be written
131 * @options: The options to parse
136 int gfs2_mount_args(struct gfs2_args
*args
, char *options
)
140 substring_t tmp
[MAX_OPT_ARGS
];
143 /* Split the options into tokens with the "," character and
147 o
= strsep(&options
, ",");
153 token
= match_token(o
, tokens
, tmp
);
156 match_strlcpy(args
->ar_lockproto
, &tmp
[0],
160 match_strlcpy(args
->ar_locktable
, &tmp
[0],
164 match_strlcpy(args
->ar_hostdata
, &tmp
[0],
168 args
->ar_spectator
= 1;
170 case Opt_ignore_local_fs
:
171 /* Retained for backwards compat only */
173 case Opt_localflocks
:
174 args
->ar_localflocks
= 1;
176 case Opt_localcaching
:
177 /* Retained for backwards compat only */
180 if (args
->ar_errors
== GFS2_ERRORS_PANIC
) {
181 pr_warn("-o debug and -o errors=panic are mutually exclusive\n");
190 /* Retained for backwards compat only */
193 args
->ar_posix_acl
= 1;
196 args
->ar_posix_acl
= 0;
200 args
->ar_quota
= GFS2_QUOTA_OFF
;
202 case Opt_quota_account
:
203 args
->ar_quota
= GFS2_QUOTA_ACCOUNT
;
207 args
->ar_quota
= GFS2_QUOTA_ON
;
210 args
->ar_suiddir
= 1;
213 args
->ar_suiddir
= 0;
215 case Opt_data_writeback
:
216 args
->ar_data
= GFS2_DATA_WRITEBACK
;
218 case Opt_data_ordered
:
219 args
->ar_data
= GFS2_DATA_ORDERED
;
225 args
->ar_discard
= 1;
228 args
->ar_discard
= 0;
231 rv
= match_int(&tmp
[0], &args
->ar_commit
);
232 if (rv
|| args
->ar_commit
<= 0) {
233 pr_warn("commit mount option requires a positive numeric argument\n");
234 return rv
? rv
: -EINVAL
;
237 case Opt_statfs_quantum
:
238 rv
= match_int(&tmp
[0], &args
->ar_statfs_quantum
);
239 if (rv
|| args
->ar_statfs_quantum
< 0) {
240 pr_warn("statfs_quantum mount option requires a non-negative numeric argument\n");
241 return rv
? rv
: -EINVAL
;
244 case Opt_quota_quantum
:
245 rv
= match_int(&tmp
[0], &args
->ar_quota_quantum
);
246 if (rv
|| args
->ar_quota_quantum
<= 0) {
247 pr_warn("quota_quantum mount option requires a positive numeric argument\n");
248 return rv
? rv
: -EINVAL
;
251 case Opt_statfs_percent
:
252 rv
= match_int(&tmp
[0], &args
->ar_statfs_percent
);
253 if (rv
|| args
->ar_statfs_percent
< 0 ||
254 args
->ar_statfs_percent
> 100) {
255 pr_warn("statfs_percent mount option requires a numeric argument between 0 and 100\n");
256 return rv
? rv
: -EINVAL
;
259 case Opt_err_withdraw
:
260 args
->ar_errors
= GFS2_ERRORS_WITHDRAW
;
263 if (args
->ar_debug
) {
264 pr_warn("-o debug and -o errors=panic are mutually exclusive\n");
267 args
->ar_errors
= GFS2_ERRORS_PANIC
;
270 args
->ar_nobarrier
= 0;
273 args
->ar_nobarrier
= 1;
276 args
->ar_rgrplvb
= 1;
279 args
->ar_rgrplvb
= 0;
283 pr_warn("invalid mount option: %s\n", o
);
292 * gfs2_jindex_free - Clear all the journal index information
293 * @sdp: The GFS2 superblock
297 void gfs2_jindex_free(struct gfs2_sbd
*sdp
)
299 struct list_head list
;
300 struct gfs2_jdesc
*jd
;
302 spin_lock(&sdp
->sd_jindex_spin
);
303 list_add(&list
, &sdp
->sd_jindex_list
);
304 list_del_init(&sdp
->sd_jindex_list
);
305 sdp
->sd_journals
= 0;
306 spin_unlock(&sdp
->sd_jindex_spin
);
308 while (!list_empty(&list
)) {
309 jd
= list_entry(list
.next
, struct gfs2_jdesc
, jd_list
);
310 gfs2_free_journal_extents(jd
);
311 list_del(&jd
->jd_list
);
317 static struct gfs2_jdesc
*jdesc_find_i(struct list_head
*head
, unsigned int jid
)
319 struct gfs2_jdesc
*jd
;
322 list_for_each_entry(jd
, head
, jd_list
) {
323 if (jd
->jd_jid
== jid
) {
335 struct gfs2_jdesc
*gfs2_jdesc_find(struct gfs2_sbd
*sdp
, unsigned int jid
)
337 struct gfs2_jdesc
*jd
;
339 spin_lock(&sdp
->sd_jindex_spin
);
340 jd
= jdesc_find_i(&sdp
->sd_jindex_list
, jid
);
341 spin_unlock(&sdp
->sd_jindex_spin
);
346 int gfs2_jdesc_check(struct gfs2_jdesc
*jd
)
348 struct gfs2_inode
*ip
= GFS2_I(jd
->jd_inode
);
349 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
350 u64 size
= i_size_read(jd
->jd_inode
);
352 if (gfs2_check_internal_file_size(jd
->jd_inode
, 8 << 20, 1 << 30))
355 jd
->jd_blocks
= size
>> sdp
->sd_sb
.sb_bsize_shift
;
357 if (gfs2_write_alloc_required(ip
, 0, size
)) {
358 gfs2_consist_inode(ip
);
365 static int init_threads(struct gfs2_sbd
*sdp
)
367 struct task_struct
*p
;
370 p
= kthread_run(gfs2_logd
, sdp
, "gfs2_logd");
373 fs_err(sdp
, "can't start logd thread: %d\n", error
);
376 sdp
->sd_logd_process
= p
;
378 p
= kthread_run(gfs2_quotad
, sdp
, "gfs2_quotad");
381 fs_err(sdp
, "can't start quotad thread: %d\n", error
);
384 sdp
->sd_quotad_process
= p
;
388 kthread_stop(sdp
->sd_logd_process
);
393 * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
394 * @sdp: the filesystem
399 int gfs2_make_fs_rw(struct gfs2_sbd
*sdp
)
401 struct gfs2_inode
*ip
= GFS2_I(sdp
->sd_jdesc
->jd_inode
);
402 struct gfs2_glock
*j_gl
= ip
->i_gl
;
403 struct gfs2_holder freeze_gh
;
404 struct gfs2_log_header_host head
;
407 error
= init_threads(sdp
);
411 error
= gfs2_glock_nq_init(sdp
->sd_freeze_gl
, LM_ST_SHARED
, 0,
416 j_gl
->gl_ops
->go_inval(j_gl
, DIO_METADATA
);
418 error
= gfs2_find_jhead(sdp
->sd_jdesc
, &head
);
422 if (!(head
.lh_flags
& GFS2_LOG_HEAD_UNMOUNT
)) {
428 /* Initialize some head of the log stuff */
429 sdp
->sd_log_sequence
= head
.lh_sequence
+ 1;
430 gfs2_log_pointers_init(sdp
, head
.lh_blkno
);
432 error
= gfs2_quota_init(sdp
);
436 set_bit(SDF_JOURNAL_LIVE
, &sdp
->sd_flags
);
438 gfs2_glock_dq_uninit(&freeze_gh
);
443 freeze_gh
.gh_flags
|= GL_NOCACHE
;
444 gfs2_glock_dq_uninit(&freeze_gh
);
446 kthread_stop(sdp
->sd_quotad_process
);
447 kthread_stop(sdp
->sd_logd_process
);
451 void gfs2_statfs_change_in(struct gfs2_statfs_change_host
*sc
, const void *buf
)
453 const struct gfs2_statfs_change
*str
= buf
;
455 sc
->sc_total
= be64_to_cpu(str
->sc_total
);
456 sc
->sc_free
= be64_to_cpu(str
->sc_free
);
457 sc
->sc_dinodes
= be64_to_cpu(str
->sc_dinodes
);
460 static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host
*sc
, void *buf
)
462 struct gfs2_statfs_change
*str
= buf
;
464 str
->sc_total
= cpu_to_be64(sc
->sc_total
);
465 str
->sc_free
= cpu_to_be64(sc
->sc_free
);
466 str
->sc_dinodes
= cpu_to_be64(sc
->sc_dinodes
);
469 int gfs2_statfs_init(struct gfs2_sbd
*sdp
)
471 struct gfs2_inode
*m_ip
= GFS2_I(sdp
->sd_statfs_inode
);
472 struct gfs2_statfs_change_host
*m_sc
= &sdp
->sd_statfs_master
;
473 struct gfs2_inode
*l_ip
= GFS2_I(sdp
->sd_sc_inode
);
474 struct gfs2_statfs_change_host
*l_sc
= &sdp
->sd_statfs_local
;
475 struct buffer_head
*m_bh
, *l_bh
;
476 struct gfs2_holder gh
;
479 error
= gfs2_glock_nq_init(m_ip
->i_gl
, LM_ST_EXCLUSIVE
, GL_NOCACHE
,
484 error
= gfs2_meta_inode_buffer(m_ip
, &m_bh
);
488 if (sdp
->sd_args
.ar_spectator
) {
489 spin_lock(&sdp
->sd_statfs_spin
);
490 gfs2_statfs_change_in(m_sc
, m_bh
->b_data
+
491 sizeof(struct gfs2_dinode
));
492 spin_unlock(&sdp
->sd_statfs_spin
);
494 error
= gfs2_meta_inode_buffer(l_ip
, &l_bh
);
498 spin_lock(&sdp
->sd_statfs_spin
);
499 gfs2_statfs_change_in(m_sc
, m_bh
->b_data
+
500 sizeof(struct gfs2_dinode
));
501 gfs2_statfs_change_in(l_sc
, l_bh
->b_data
+
502 sizeof(struct gfs2_dinode
));
503 spin_unlock(&sdp
->sd_statfs_spin
);
511 gfs2_glock_dq_uninit(&gh
);
515 void gfs2_statfs_change(struct gfs2_sbd
*sdp
, s64 total
, s64 free
,
518 struct gfs2_inode
*l_ip
= GFS2_I(sdp
->sd_sc_inode
);
519 struct gfs2_statfs_change_host
*l_sc
= &sdp
->sd_statfs_local
;
520 struct gfs2_statfs_change_host
*m_sc
= &sdp
->sd_statfs_master
;
521 struct buffer_head
*l_bh
;
526 error
= gfs2_meta_inode_buffer(l_ip
, &l_bh
);
530 gfs2_trans_add_meta(l_ip
->i_gl
, l_bh
);
532 spin_lock(&sdp
->sd_statfs_spin
);
533 l_sc
->sc_total
+= total
;
534 l_sc
->sc_free
+= free
;
535 l_sc
->sc_dinodes
+= dinodes
;
536 gfs2_statfs_change_out(l_sc
, l_bh
->b_data
+ sizeof(struct gfs2_dinode
));
537 if (sdp
->sd_args
.ar_statfs_percent
) {
538 x
= 100 * l_sc
->sc_free
;
539 y
= m_sc
->sc_free
* sdp
->sd_args
.ar_statfs_percent
;
540 if (x
>= y
|| x
<= -y
)
543 spin_unlock(&sdp
->sd_statfs_spin
);
547 gfs2_wake_up_statfs(sdp
);
550 void update_statfs(struct gfs2_sbd
*sdp
, struct buffer_head
*m_bh
,
551 struct buffer_head
*l_bh
)
553 struct gfs2_inode
*m_ip
= GFS2_I(sdp
->sd_statfs_inode
);
554 struct gfs2_inode
*l_ip
= GFS2_I(sdp
->sd_sc_inode
);
555 struct gfs2_statfs_change_host
*m_sc
= &sdp
->sd_statfs_master
;
556 struct gfs2_statfs_change_host
*l_sc
= &sdp
->sd_statfs_local
;
558 gfs2_trans_add_meta(l_ip
->i_gl
, l_bh
);
560 spin_lock(&sdp
->sd_statfs_spin
);
561 m_sc
->sc_total
+= l_sc
->sc_total
;
562 m_sc
->sc_free
+= l_sc
->sc_free
;
563 m_sc
->sc_dinodes
+= l_sc
->sc_dinodes
;
564 memset(l_sc
, 0, sizeof(struct gfs2_statfs_change
));
565 memset(l_bh
->b_data
+ sizeof(struct gfs2_dinode
),
566 0, sizeof(struct gfs2_statfs_change
));
567 spin_unlock(&sdp
->sd_statfs_spin
);
569 gfs2_trans_add_meta(m_ip
->i_gl
, m_bh
);
570 gfs2_statfs_change_out(m_sc
, m_bh
->b_data
+ sizeof(struct gfs2_dinode
));
573 int gfs2_statfs_sync(struct super_block
*sb
, int type
)
575 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
576 struct gfs2_inode
*m_ip
= GFS2_I(sdp
->sd_statfs_inode
);
577 struct gfs2_inode
*l_ip
= GFS2_I(sdp
->sd_sc_inode
);
578 struct gfs2_statfs_change_host
*m_sc
= &sdp
->sd_statfs_master
;
579 struct gfs2_statfs_change_host
*l_sc
= &sdp
->sd_statfs_local
;
580 struct gfs2_holder gh
;
581 struct buffer_head
*m_bh
, *l_bh
;
585 error
= gfs2_glock_nq_init(m_ip
->i_gl
, LM_ST_EXCLUSIVE
, GL_NOCACHE
,
590 error
= gfs2_meta_inode_buffer(m_ip
, &m_bh
);
594 spin_lock(&sdp
->sd_statfs_spin
);
595 gfs2_statfs_change_in(m_sc
, m_bh
->b_data
+
596 sizeof(struct gfs2_dinode
));
597 if (!l_sc
->sc_total
&& !l_sc
->sc_free
&& !l_sc
->sc_dinodes
) {
598 spin_unlock(&sdp
->sd_statfs_spin
);
601 spin_unlock(&sdp
->sd_statfs_spin
);
603 error
= gfs2_meta_inode_buffer(l_ip
, &l_bh
);
607 error
= gfs2_trans_begin(sdp
, 2 * RES_DINODE
, 0);
611 update_statfs(sdp
, m_bh
, l_bh
);
612 sdp
->sd_statfs_force_sync
= 0;
621 gfs2_glock_dq_uninit(&gh
);
628 struct list_head list
;
629 struct gfs2_holder gh
;
633 * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all
635 * @sdp: the file system
636 * @state: the state to put the transaction lock into
637 * @t_gh: the hold on the transaction lock
642 static int gfs2_lock_fs_check_clean(struct gfs2_sbd
*sdp
,
643 struct gfs2_holder
*freeze_gh
)
645 struct gfs2_inode
*ip
;
646 struct gfs2_jdesc
*jd
;
649 struct gfs2_log_header_host lh
;
652 list_for_each_entry(jd
, &sdp
->sd_jindex_list
, jd_list
) {
653 lfcc
= kmalloc(sizeof(struct lfcc
), GFP_KERNEL
);
658 ip
= GFS2_I(jd
->jd_inode
);
659 error
= gfs2_glock_nq_init(ip
->i_gl
, LM_ST_SHARED
, 0, &lfcc
->gh
);
664 list_add(&lfcc
->list
, &list
);
667 error
= gfs2_glock_nq_init(sdp
->sd_freeze_gl
, LM_ST_EXCLUSIVE
,
668 GL_NOCACHE
, freeze_gh
);
670 list_for_each_entry(jd
, &sdp
->sd_jindex_list
, jd_list
) {
671 error
= gfs2_jdesc_check(jd
);
674 error
= gfs2_find_jhead(jd
, &lh
);
677 if (!(lh
.lh_flags
& GFS2_LOG_HEAD_UNMOUNT
)) {
684 gfs2_glock_dq_uninit(freeze_gh
);
687 while (!list_empty(&list
)) {
688 lfcc
= list_entry(list
.next
, struct lfcc
, list
);
689 list_del(&lfcc
->list
);
690 gfs2_glock_dq_uninit(&lfcc
->gh
);
696 void gfs2_dinode_out(const struct gfs2_inode
*ip
, void *buf
)
698 struct gfs2_dinode
*str
= buf
;
700 str
->di_header
.mh_magic
= cpu_to_be32(GFS2_MAGIC
);
701 str
->di_header
.mh_type
= cpu_to_be32(GFS2_METATYPE_DI
);
702 str
->di_header
.mh_format
= cpu_to_be32(GFS2_FORMAT_DI
);
703 str
->di_num
.no_addr
= cpu_to_be64(ip
->i_no_addr
);
704 str
->di_num
.no_formal_ino
= cpu_to_be64(ip
->i_no_formal_ino
);
705 str
->di_mode
= cpu_to_be32(ip
->i_inode
.i_mode
);
706 str
->di_uid
= cpu_to_be32(i_uid_read(&ip
->i_inode
));
707 str
->di_gid
= cpu_to_be32(i_gid_read(&ip
->i_inode
));
708 str
->di_nlink
= cpu_to_be32(ip
->i_inode
.i_nlink
);
709 str
->di_size
= cpu_to_be64(i_size_read(&ip
->i_inode
));
710 str
->di_blocks
= cpu_to_be64(gfs2_get_inode_blocks(&ip
->i_inode
));
711 str
->di_atime
= cpu_to_be64(ip
->i_inode
.i_atime
.tv_sec
);
712 str
->di_mtime
= cpu_to_be64(ip
->i_inode
.i_mtime
.tv_sec
);
713 str
->di_ctime
= cpu_to_be64(ip
->i_inode
.i_ctime
.tv_sec
);
715 str
->di_goal_meta
= cpu_to_be64(ip
->i_goal
);
716 str
->di_goal_data
= cpu_to_be64(ip
->i_goal
);
717 str
->di_generation
= cpu_to_be64(ip
->i_generation
);
719 str
->di_flags
= cpu_to_be32(ip
->i_diskflags
);
720 str
->di_height
= cpu_to_be16(ip
->i_height
);
721 str
->di_payload_format
= cpu_to_be32(S_ISDIR(ip
->i_inode
.i_mode
) &&
722 !(ip
->i_diskflags
& GFS2_DIF_EXHASH
) ?
724 str
->di_depth
= cpu_to_be16(ip
->i_depth
);
725 str
->di_entries
= cpu_to_be32(ip
->i_entries
);
727 str
->di_eattr
= cpu_to_be64(ip
->i_eattr
);
728 str
->di_atime_nsec
= cpu_to_be32(ip
->i_inode
.i_atime
.tv_nsec
);
729 str
->di_mtime_nsec
= cpu_to_be32(ip
->i_inode
.i_mtime
.tv_nsec
);
730 str
->di_ctime_nsec
= cpu_to_be32(ip
->i_inode
.i_ctime
.tv_nsec
);
734 * gfs2_write_inode - Make sure the inode is stable on the disk
736 * @wbc: The writeback control structure
741 static int gfs2_write_inode(struct inode
*inode
, struct writeback_control
*wbc
)
743 struct gfs2_inode
*ip
= GFS2_I(inode
);
744 struct gfs2_sbd
*sdp
= GFS2_SB(inode
);
745 struct address_space
*metamapping
= gfs2_glock2aspace(ip
->i_gl
);
746 struct backing_dev_info
*bdi
= inode_to_bdi(metamapping
->host
);
749 if (wbc
->sync_mode
== WB_SYNC_ALL
)
750 gfs2_log_flush(GFS2_SB(inode
), ip
->i_gl
, NORMAL_FLUSH
);
751 if (bdi
->dirty_exceeded
)
752 gfs2_ail1_flush(sdp
, wbc
);
754 filemap_fdatawrite(metamapping
);
755 if (wbc
->sync_mode
== WB_SYNC_ALL
)
756 ret
= filemap_fdatawait(metamapping
);
758 mark_inode_dirty_sync(inode
);
763 * gfs2_dirty_inode - check for atime updates
764 * @inode: The inode in question
765 * @flags: The type of dirty
767 * Unfortunately it can be called under any combination of inode
768 * glock and transaction lock, so we have to check carefully.
770 * At the moment this deals only with atime - it should be possible
771 * to expand that role in future, once a review of the locking has
775 static void gfs2_dirty_inode(struct inode
*inode
, int flags
)
777 struct gfs2_inode
*ip
= GFS2_I(inode
);
778 struct gfs2_sbd
*sdp
= GFS2_SB(inode
);
779 struct buffer_head
*bh
;
780 struct gfs2_holder gh
;
782 int need_endtrans
= 0;
785 if (!(flags
& (I_DIRTY_DATASYNC
|I_DIRTY_SYNC
)))
788 if (!gfs2_glock_is_locked_by_me(ip
->i_gl
)) {
789 ret
= gfs2_glock_nq_init(ip
->i_gl
, LM_ST_EXCLUSIVE
, 0, &gh
);
791 fs_err(sdp
, "dirty_inode: glock %d\n", ret
);
795 } else if (WARN_ON_ONCE(ip
->i_gl
->gl_state
!= LM_ST_EXCLUSIVE
))
798 if (current
->journal_info
== NULL
) {
799 ret
= gfs2_trans_begin(sdp
, RES_DINODE
, 0);
801 fs_err(sdp
, "dirty_inode: gfs2_trans_begin %d\n", ret
);
807 ret
= gfs2_meta_inode_buffer(ip
, &bh
);
809 gfs2_trans_add_meta(ip
->i_gl
, bh
);
810 gfs2_dinode_out(ip
, bh
->b_data
);
818 gfs2_glock_dq_uninit(&gh
);
822 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
823 * @sdp: the filesystem
828 static int gfs2_make_fs_ro(struct gfs2_sbd
*sdp
)
830 struct gfs2_holder freeze_gh
;
833 error
= gfs2_glock_nq_init(sdp
->sd_freeze_gl
, LM_ST_SHARED
, GL_NOCACHE
,
835 if (error
&& !test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
838 kthread_stop(sdp
->sd_quotad_process
);
839 kthread_stop(sdp
->sd_logd_process
);
841 flush_workqueue(gfs2_delete_workqueue
);
842 gfs2_quota_sync(sdp
->sd_vfs
, 0);
843 gfs2_statfs_sync(sdp
->sd_vfs
, 0);
845 down_write(&sdp
->sd_log_flush_lock
);
846 clear_bit(SDF_JOURNAL_LIVE
, &sdp
->sd_flags
);
847 up_write(&sdp
->sd_log_flush_lock
);
849 gfs2_log_flush(sdp
, NULL
, SHUTDOWN_FLUSH
);
850 wait_event(sdp
->sd_reserving_log_wait
, atomic_read(&sdp
->sd_reserving_log
) == 0);
851 gfs2_assert_warn(sdp
, atomic_read(&sdp
->sd_log_blks_free
) == sdp
->sd_jdesc
->jd_blocks
);
854 gfs2_glock_dq_uninit(&freeze_gh
);
856 gfs2_quota_cleanup(sdp
);
862 * gfs2_put_super - Unmount the filesystem
863 * @sb: The VFS superblock
867 static void gfs2_put_super(struct super_block
*sb
)
869 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
871 struct gfs2_jdesc
*jd
;
873 /* No more recovery requests */
874 set_bit(SDF_NORECOVERY
, &sdp
->sd_flags
);
877 /* Wait on outstanding recovery */
879 spin_lock(&sdp
->sd_jindex_spin
);
880 list_for_each_entry(jd
, &sdp
->sd_jindex_list
, jd_list
) {
881 if (!test_bit(JDF_RECOVERY
, &jd
->jd_flags
))
883 spin_unlock(&sdp
->sd_jindex_spin
);
884 wait_on_bit(&jd
->jd_flags
, JDF_RECOVERY
,
885 TASK_UNINTERRUPTIBLE
);
888 spin_unlock(&sdp
->sd_jindex_spin
);
890 if (!(sb
->s_flags
& MS_RDONLY
)) {
891 error
= gfs2_make_fs_ro(sdp
);
895 /* At this point, we're through modifying the disk */
899 iput(sdp
->sd_jindex
);
900 iput(sdp
->sd_statfs_inode
);
901 iput(sdp
->sd_rindex
);
902 iput(sdp
->sd_quota_inode
);
904 gfs2_glock_put(sdp
->sd_rename_gl
);
905 gfs2_glock_put(sdp
->sd_freeze_gl
);
907 if (!sdp
->sd_args
.ar_spectator
) {
908 gfs2_glock_dq_uninit(&sdp
->sd_journal_gh
);
909 gfs2_glock_dq_uninit(&sdp
->sd_jinode_gh
);
910 gfs2_glock_dq_uninit(&sdp
->sd_sc_gh
);
911 gfs2_glock_dq_uninit(&sdp
->sd_qc_gh
);
912 iput(sdp
->sd_sc_inode
);
913 iput(sdp
->sd_qc_inode
);
916 gfs2_glock_dq_uninit(&sdp
->sd_live_gh
);
917 gfs2_clear_rgrpd(sdp
);
918 gfs2_jindex_free(sdp
);
919 /* Take apart glock structures and buffer lists */
920 gfs2_gl_hash_clear(sdp
);
921 /* Unmount the locking protocol */
922 gfs2_lm_unmount(sdp
);
924 /* At this point, we're through participating in the lockspace */
925 gfs2_sys_fs_del(sdp
);
929 * gfs2_sync_fs - sync the filesystem
930 * @sb: the superblock
932 * Flushes the log to disk.
935 static int gfs2_sync_fs(struct super_block
*sb
, int wait
)
937 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
939 gfs2_quota_sync(sb
, -1);
941 gfs2_log_flush(sdp
, NULL
, NORMAL_FLUSH
);
945 void gfs2_freeze_func(struct work_struct
*work
)
948 struct gfs2_holder freeze_gh
;
949 struct gfs2_sbd
*sdp
= container_of(work
, struct gfs2_sbd
, sd_freeze_work
);
950 struct super_block
*sb
= sdp
->sd_vfs
;
952 atomic_inc(&sb
->s_active
);
953 error
= gfs2_glock_nq_init(sdp
->sd_freeze_gl
, LM_ST_SHARED
, 0,
956 printk(KERN_INFO
"GFS2: couln't get freeze lock : %d\n", error
);
957 gfs2_assert_withdraw(sdp
, 0);
960 atomic_set(&sdp
->sd_freeze_state
, SFS_UNFROZEN
);
961 error
= thaw_super(sb
);
963 printk(KERN_INFO
"GFS2: couldn't thaw filesystem: %d\n",
965 gfs2_assert_withdraw(sdp
, 0);
967 if (!test_bit(SDF_JOURNAL_LIVE
, &sdp
->sd_flags
))
968 freeze_gh
.gh_flags
|= GL_NOCACHE
;
969 gfs2_glock_dq_uninit(&freeze_gh
);
971 deactivate_super(sb
);
976 * gfs2_freeze - prevent further writes to the filesystem
977 * @sb: the VFS structure for the filesystem
981 static int gfs2_freeze(struct super_block
*sb
)
983 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
986 mutex_lock(&sdp
->sd_freeze_mutex
);
987 if (atomic_read(&sdp
->sd_freeze_state
) != SFS_UNFROZEN
)
990 if (test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)) {
996 error
= gfs2_lock_fs_check_clean(sdp
, &sdp
->sd_freeze_gh
);
1002 fs_err(sdp
, "waiting for recovery before freeze\n");
1006 fs_err(sdp
, "error freezing FS: %d\n", error
);
1010 fs_err(sdp
, "retrying...\n");
1015 mutex_unlock(&sdp
->sd_freeze_mutex
);
1020 * gfs2_unfreeze - reallow writes to the filesystem
1021 * @sb: the VFS structure for the filesystem
1025 static int gfs2_unfreeze(struct super_block
*sb
)
1027 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
1029 mutex_lock(&sdp
->sd_freeze_mutex
);
1030 if (atomic_read(&sdp
->sd_freeze_state
) != SFS_FROZEN
||
1031 sdp
->sd_freeze_gh
.gh_gl
== NULL
) {
1032 mutex_unlock(&sdp
->sd_freeze_mutex
);
1036 gfs2_glock_dq_uninit(&sdp
->sd_freeze_gh
);
1037 mutex_unlock(&sdp
->sd_freeze_mutex
);
1042 * statfs_fill - fill in the sg for a given RG
1044 * @sc: the sc structure
1046 * Returns: 0 on success, -ESTALE if the LVB is invalid
1049 static int statfs_slow_fill(struct gfs2_rgrpd
*rgd
,
1050 struct gfs2_statfs_change_host
*sc
)
1052 gfs2_rgrp_verify(rgd
);
1053 sc
->sc_total
+= rgd
->rd_data
;
1054 sc
->sc_free
+= rgd
->rd_free
;
1055 sc
->sc_dinodes
+= rgd
->rd_dinodes
;
1060 * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
1061 * @sdp: the filesystem
1062 * @sc: the sc info that will be returned
1064 * Any error (other than a signal) will cause this routine to fall back
1065 * to the synchronous version.
1067 * FIXME: This really shouldn't busy wait like this.
1072 static int gfs2_statfs_slow(struct gfs2_sbd
*sdp
, struct gfs2_statfs_change_host
*sc
)
1074 struct gfs2_rgrpd
*rgd_next
;
1075 struct gfs2_holder
*gha
, *gh
;
1076 unsigned int slots
= 64;
1081 memset(sc
, 0, sizeof(struct gfs2_statfs_change_host
));
1082 gha
= kcalloc(slots
, sizeof(struct gfs2_holder
), GFP_KERNEL
);
1086 rgd_next
= gfs2_rgrpd_get_first(sdp
);
1091 for (x
= 0; x
< slots
; x
++) {
1094 if (gh
->gh_gl
&& gfs2_glock_poll(gh
)) {
1095 err
= gfs2_glock_wait(gh
);
1097 gfs2_holder_uninit(gh
);
1101 error
= statfs_slow_fill(
1102 gh
->gh_gl
->gl_object
, sc
);
1103 gfs2_glock_dq_uninit(gh
);
1109 else if (rgd_next
&& !error
) {
1110 error
= gfs2_glock_nq_init(rgd_next
->rd_gl
,
1114 rgd_next
= gfs2_rgrpd_get_next(rgd_next
);
1118 if (signal_pending(current
))
1119 error
= -ERESTARTSYS
;
1133 * gfs2_statfs_i - Do a statfs
1134 * @sdp: the filesystem
1135 * @sg: the sg structure
1140 static int gfs2_statfs_i(struct gfs2_sbd
*sdp
, struct gfs2_statfs_change_host
*sc
)
1142 struct gfs2_statfs_change_host
*m_sc
= &sdp
->sd_statfs_master
;
1143 struct gfs2_statfs_change_host
*l_sc
= &sdp
->sd_statfs_local
;
1145 spin_lock(&sdp
->sd_statfs_spin
);
1148 sc
->sc_total
+= l_sc
->sc_total
;
1149 sc
->sc_free
+= l_sc
->sc_free
;
1150 sc
->sc_dinodes
+= l_sc
->sc_dinodes
;
1152 spin_unlock(&sdp
->sd_statfs_spin
);
1154 if (sc
->sc_free
< 0)
1156 if (sc
->sc_free
> sc
->sc_total
)
1157 sc
->sc_free
= sc
->sc_total
;
1158 if (sc
->sc_dinodes
< 0)
1165 * gfs2_statfs - Gather and return stats about the filesystem
1166 * @sb: The superblock
1167 * @statfsbuf: The buffer
1169 * Returns: 0 on success or error code
1172 static int gfs2_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1174 struct super_block
*sb
= d_inode(dentry
)->i_sb
;
1175 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
1176 struct gfs2_statfs_change_host sc
;
1179 error
= gfs2_rindex_update(sdp
);
1183 if (gfs2_tune_get(sdp
, gt_statfs_slow
))
1184 error
= gfs2_statfs_slow(sdp
, &sc
);
1186 error
= gfs2_statfs_i(sdp
, &sc
);
1191 buf
->f_type
= GFS2_MAGIC
;
1192 buf
->f_bsize
= sdp
->sd_sb
.sb_bsize
;
1193 buf
->f_blocks
= sc
.sc_total
;
1194 buf
->f_bfree
= sc
.sc_free
;
1195 buf
->f_bavail
= sc
.sc_free
;
1196 buf
->f_files
= sc
.sc_dinodes
+ sc
.sc_free
;
1197 buf
->f_ffree
= sc
.sc_free
;
1198 buf
->f_namelen
= GFS2_FNAMESIZE
;
1204 * gfs2_remount_fs - called when the FS is remounted
1205 * @sb: the filesystem
1206 * @flags: the remount flags
1207 * @data: extra data passed in (not used right now)
1212 static int gfs2_remount_fs(struct super_block
*sb
, int *flags
, char *data
)
1214 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
1215 struct gfs2_args args
= sdp
->sd_args
; /* Default to current settings */
1216 struct gfs2_tune
*gt
= &sdp
->sd_tune
;
1219 sync_filesystem(sb
);
1221 spin_lock(>
->gt_spin
);
1222 args
.ar_commit
= gt
->gt_logd_secs
;
1223 args
.ar_quota_quantum
= gt
->gt_quota_quantum
;
1224 if (gt
->gt_statfs_slow
)
1225 args
.ar_statfs_quantum
= 0;
1227 args
.ar_statfs_quantum
= gt
->gt_statfs_quantum
;
1228 spin_unlock(>
->gt_spin
);
1229 error
= gfs2_mount_args(&args
, data
);
1233 /* Not allowed to change locking details */
1234 if (strcmp(args
.ar_lockproto
, sdp
->sd_args
.ar_lockproto
) ||
1235 strcmp(args
.ar_locktable
, sdp
->sd_args
.ar_locktable
) ||
1236 strcmp(args
.ar_hostdata
, sdp
->sd_args
.ar_hostdata
))
1239 /* Some flags must not be changed */
1240 if (args_neq(&args
, &sdp
->sd_args
, spectator
) ||
1241 args_neq(&args
, &sdp
->sd_args
, localflocks
) ||
1242 args_neq(&args
, &sdp
->sd_args
, meta
))
1245 if (sdp
->sd_args
.ar_spectator
)
1246 *flags
|= MS_RDONLY
;
1248 if ((sb
->s_flags
^ *flags
) & MS_RDONLY
) {
1249 if (*flags
& MS_RDONLY
)
1250 error
= gfs2_make_fs_ro(sdp
);
1252 error
= gfs2_make_fs_rw(sdp
);
1257 sdp
->sd_args
= args
;
1258 if (sdp
->sd_args
.ar_posix_acl
)
1259 sb
->s_flags
|= MS_POSIXACL
;
1261 sb
->s_flags
&= ~MS_POSIXACL
;
1262 if (sdp
->sd_args
.ar_nobarrier
)
1263 set_bit(SDF_NOBARRIERS
, &sdp
->sd_flags
);
1265 clear_bit(SDF_NOBARRIERS
, &sdp
->sd_flags
);
1266 spin_lock(>
->gt_spin
);
1267 gt
->gt_logd_secs
= args
.ar_commit
;
1268 gt
->gt_quota_quantum
= args
.ar_quota_quantum
;
1269 if (args
.ar_statfs_quantum
) {
1270 gt
->gt_statfs_slow
= 0;
1271 gt
->gt_statfs_quantum
= args
.ar_statfs_quantum
;
1274 gt
->gt_statfs_slow
= 1;
1275 gt
->gt_statfs_quantum
= 30;
1277 spin_unlock(>
->gt_spin
);
1279 gfs2_online_uevent(sdp
);
1284 * gfs2_drop_inode - Drop an inode (test for remote unlink)
1285 * @inode: The inode to drop
1287 * If we've received a callback on an iopen lock then its because a
1288 * remote node tried to deallocate the inode but failed due to this node
1289 * still having the inode open. Here we mark the link count zero
1290 * since we know that it must have reached zero if the GLF_DEMOTE flag
1291 * is set on the iopen glock. If we didn't do a disk read since the
1292 * remote node removed the final link then we might otherwise miss
1293 * this event. This check ensures that this node will deallocate the
1294 * inode's blocks, or alternatively pass the baton on to another
1295 * node for later deallocation.
1298 static int gfs2_drop_inode(struct inode
*inode
)
1300 struct gfs2_inode
*ip
= GFS2_I(inode
);
1302 if (!test_bit(GIF_FREE_VFS_INODE
, &ip
->i_flags
) && inode
->i_nlink
) {
1303 struct gfs2_glock
*gl
= ip
->i_iopen_gh
.gh_gl
;
1304 if (gl
&& test_bit(GLF_DEMOTE
, &gl
->gl_flags
))
1307 return generic_drop_inode(inode
);
1310 static int is_ancestor(const struct dentry
*d1
, const struct dentry
*d2
)
1316 } while (!IS_ROOT(d1
));
1321 * gfs2_show_options - Show mount options for /proc/mounts
1322 * @s: seq_file structure
1323 * @root: root of this (sub)tree
1325 * Returns: 0 on success or error code
1328 static int gfs2_show_options(struct seq_file
*s
, struct dentry
*root
)
1330 struct gfs2_sbd
*sdp
= root
->d_sb
->s_fs_info
;
1331 struct gfs2_args
*args
= &sdp
->sd_args
;
1334 if (is_ancestor(root
, sdp
->sd_master_dir
))
1335 seq_puts(s
, ",meta");
1336 if (args
->ar_lockproto
[0])
1337 seq_show_option(s
, "lockproto", args
->ar_lockproto
);
1338 if (args
->ar_locktable
[0])
1339 seq_show_option(s
, "locktable", args
->ar_locktable
);
1340 if (args
->ar_hostdata
[0])
1341 seq_show_option(s
, "hostdata", args
->ar_hostdata
);
1342 if (args
->ar_spectator
)
1343 seq_puts(s
, ",spectator");
1344 if (args
->ar_localflocks
)
1345 seq_puts(s
, ",localflocks");
1347 seq_puts(s
, ",debug");
1348 if (args
->ar_posix_acl
)
1349 seq_puts(s
, ",acl");
1350 if (args
->ar_quota
!= GFS2_QUOTA_DEFAULT
) {
1352 switch (args
->ar_quota
) {
1353 case GFS2_QUOTA_OFF
:
1356 case GFS2_QUOTA_ACCOUNT
:
1366 seq_printf(s
, ",quota=%s", state
);
1368 if (args
->ar_suiddir
)
1369 seq_puts(s
, ",suiddir");
1370 if (args
->ar_data
!= GFS2_DATA_DEFAULT
) {
1372 switch (args
->ar_data
) {
1373 case GFS2_DATA_WRITEBACK
:
1374 state
= "writeback";
1376 case GFS2_DATA_ORDERED
:
1383 seq_printf(s
, ",data=%s", state
);
1385 if (args
->ar_discard
)
1386 seq_puts(s
, ",discard");
1387 val
= sdp
->sd_tune
.gt_logd_secs
;
1389 seq_printf(s
, ",commit=%d", val
);
1390 val
= sdp
->sd_tune
.gt_statfs_quantum
;
1392 seq_printf(s
, ",statfs_quantum=%d", val
);
1393 else if (sdp
->sd_tune
.gt_statfs_slow
)
1394 seq_puts(s
, ",statfs_quantum=0");
1395 val
= sdp
->sd_tune
.gt_quota_quantum
;
1397 seq_printf(s
, ",quota_quantum=%d", val
);
1398 if (args
->ar_statfs_percent
)
1399 seq_printf(s
, ",statfs_percent=%d", args
->ar_statfs_percent
);
1400 if (args
->ar_errors
!= GFS2_ERRORS_DEFAULT
) {
1403 switch (args
->ar_errors
) {
1404 case GFS2_ERRORS_WITHDRAW
:
1407 case GFS2_ERRORS_PANIC
:
1414 seq_printf(s
, ",errors=%s", state
);
1416 if (test_bit(SDF_NOBARRIERS
, &sdp
->sd_flags
))
1417 seq_puts(s
, ",nobarrier");
1418 if (test_bit(SDF_DEMOTE
, &sdp
->sd_flags
))
1419 seq_puts(s
, ",demote_interface_used");
1420 if (args
->ar_rgrplvb
)
1421 seq_puts(s
, ",rgrplvb");
1425 static void gfs2_final_release_pages(struct gfs2_inode
*ip
)
1427 struct inode
*inode
= &ip
->i_inode
;
1428 struct gfs2_glock
*gl
= ip
->i_gl
;
1430 truncate_inode_pages(gfs2_glock2aspace(ip
->i_gl
), 0);
1431 truncate_inode_pages(&inode
->i_data
, 0);
1433 if (atomic_read(&gl
->gl_revokes
) == 0) {
1434 clear_bit(GLF_LFLUSH
, &gl
->gl_flags
);
1435 clear_bit(GLF_DIRTY
, &gl
->gl_flags
);
1439 static int gfs2_dinode_dealloc(struct gfs2_inode
*ip
)
1441 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
1442 struct gfs2_rgrpd
*rgd
;
1443 struct gfs2_holder gh
;
1446 if (gfs2_get_inode_blocks(&ip
->i_inode
) != 1) {
1447 gfs2_consist_inode(ip
);
1451 error
= gfs2_rindex_update(sdp
);
1455 error
= gfs2_quota_hold(ip
, NO_UID_QUOTA_CHANGE
, NO_GID_QUOTA_CHANGE
);
1459 rgd
= gfs2_blk2rgrpd(sdp
, ip
->i_no_addr
, 1);
1461 gfs2_consist_inode(ip
);
1466 error
= gfs2_glock_nq_init(rgd
->rd_gl
, LM_ST_EXCLUSIVE
, 0, &gh
);
1470 error
= gfs2_trans_begin(sdp
, RES_RG_BIT
+ RES_STATFS
+ RES_QUOTA
,
1471 sdp
->sd_jdesc
->jd_blocks
);
1473 goto out_rg_gunlock
;
1475 gfs2_free_di(rgd
, ip
);
1477 gfs2_final_release_pages(ip
);
1479 gfs2_trans_end(sdp
);
1482 gfs2_glock_dq_uninit(&gh
);
1484 gfs2_quota_unhold(ip
);
1489 * gfs2_evict_inode - Remove an inode from cache
1490 * @inode: The inode to evict
1492 * There are three cases to consider:
1493 * 1. i_nlink == 0, we are final opener (and must deallocate)
1494 * 2. i_nlink == 0, we are not the final opener (and cannot deallocate)
1497 * If the fs is read only, then we have to treat all cases as per #3
1498 * since we are unable to do any deallocation. The inode will be
1499 * deallocated by the next read/write node to attempt an allocation
1500 * in the same resource group
1502 * We have to (at the moment) hold the inodes main lock to cover
1503 * the gap between unlocking the shared lock on the iopen lock and
1504 * taking the exclusive lock. I'd rather do a shared -> exclusive
1505 * conversion on the iopen lock, but we can change that later. This
1506 * is safe, just less efficient.
1509 static void gfs2_evict_inode(struct inode
*inode
)
1511 struct super_block
*sb
= inode
->i_sb
;
1512 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
1513 struct gfs2_inode
*ip
= GFS2_I(inode
);
1514 struct gfs2_holder gh
;
1517 if (test_bit(GIF_FREE_VFS_INODE
, &ip
->i_flags
)) {
1522 if (inode
->i_nlink
|| (sb
->s_flags
& MS_RDONLY
))
1525 /* Must not read inode block until block type has been verified */
1526 error
= gfs2_glock_nq_init(ip
->i_gl
, LM_ST_EXCLUSIVE
, GL_SKIP
, &gh
);
1527 if (unlikely(error
)) {
1528 ip
->i_iopen_gh
.gh_flags
|= GL_NOCACHE
;
1529 gfs2_glock_dq_uninit(&ip
->i_iopen_gh
);
1533 if (!test_bit(GIF_ALLOC_FAILED
, &ip
->i_flags
)) {
1534 error
= gfs2_check_blk_type(sdp
, ip
->i_no_addr
, GFS2_BLKST_UNLINKED
);
1539 if (test_bit(GIF_INVALID
, &ip
->i_flags
)) {
1540 error
= gfs2_inode_refresh(ip
);
1545 ip
->i_iopen_gh
.gh_flags
|= GL_NOCACHE
;
1546 gfs2_glock_dq_wait(&ip
->i_iopen_gh
);
1547 gfs2_holder_reinit(LM_ST_EXCLUSIVE
, LM_FLAG_TRY_1CB
| GL_NOCACHE
, &ip
->i_iopen_gh
);
1548 error
= gfs2_glock_nq(&ip
->i_iopen_gh
);
1552 /* Case 1 starts here */
1554 if (S_ISDIR(inode
->i_mode
) &&
1555 (ip
->i_diskflags
& GFS2_DIF_EXHASH
)) {
1556 error
= gfs2_dir_exhash_dealloc(ip
);
1562 error
= gfs2_ea_dealloc(ip
);
1567 if (!gfs2_is_stuffed(ip
)) {
1568 error
= gfs2_file_dealloc(ip
);
1573 error
= gfs2_dinode_dealloc(ip
);
1577 gfs2_log_flush(sdp
, ip
->i_gl
, NORMAL_FLUSH
);
1578 if (test_bit(GLF_DIRTY
, &ip
->i_gl
->gl_flags
)) {
1579 struct address_space
*metamapping
= gfs2_glock2aspace(ip
->i_gl
);
1580 filemap_fdatawrite(metamapping
);
1581 filemap_fdatawait(metamapping
);
1583 write_inode_now(inode
, 1);
1584 gfs2_ail_flush(ip
->i_gl
, 0);
1586 /* Case 2 starts here */
1587 error
= gfs2_trans_begin(sdp
, 0, sdp
->sd_jdesc
->jd_blocks
);
1590 /* Needs to be done before glock release & also in a transaction */
1591 truncate_inode_pages(&inode
->i_data
, 0);
1592 gfs2_trans_end(sdp
);
1595 /* Error path for case 1 */
1596 if (gfs2_rs_active(ip
->i_res
))
1597 gfs2_rs_deltree(ip
->i_res
);
1599 if (test_bit(HIF_HOLDER
, &ip
->i_iopen_gh
.gh_iflags
)) {
1600 ip
->i_iopen_gh
.gh_flags
|= GL_NOCACHE
;
1601 gfs2_glock_dq(&ip
->i_iopen_gh
);
1603 gfs2_holder_uninit(&ip
->i_iopen_gh
);
1604 gfs2_glock_dq_uninit(&gh
);
1605 if (error
&& error
!= GLR_TRYFAILED
&& error
!= -EROFS
)
1606 fs_warn(sdp
, "gfs2_evict_inode: %d\n", error
);
1608 /* Case 3 starts here */
1609 truncate_inode_pages_final(&inode
->i_data
);
1610 gfs2_rs_delete(ip
, NULL
);
1611 gfs2_ordered_del_inode(ip
);
1613 gfs2_dir_hash_inval(ip
);
1614 ip
->i_gl
->gl_object
= NULL
;
1615 flush_delayed_work(&ip
->i_gl
->gl_work
);
1616 gfs2_glock_add_to_lru(ip
->i_gl
);
1617 gfs2_glock_put(ip
->i_gl
);
1619 if (ip
->i_iopen_gh
.gh_gl
) {
1620 ip
->i_iopen_gh
.gh_gl
->gl_object
= NULL
;
1621 ip
->i_iopen_gh
.gh_flags
|= GL_NOCACHE
;
1622 gfs2_glock_dq_uninit(&ip
->i_iopen_gh
);
1626 static struct inode
*gfs2_alloc_inode(struct super_block
*sb
)
1628 struct gfs2_inode
*ip
;
1630 ip
= kmem_cache_alloc(gfs2_inode_cachep
, GFP_KERNEL
);
1637 return &ip
->i_inode
;
1640 static void gfs2_i_callback(struct rcu_head
*head
)
1642 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
1643 kmem_cache_free(gfs2_inode_cachep
, inode
);
1646 static void gfs2_destroy_inode(struct inode
*inode
)
1648 call_rcu(&inode
->i_rcu
, gfs2_i_callback
);
1651 const struct super_operations gfs2_super_ops
= {
1652 .alloc_inode
= gfs2_alloc_inode
,
1653 .destroy_inode
= gfs2_destroy_inode
,
1654 .write_inode
= gfs2_write_inode
,
1655 .dirty_inode
= gfs2_dirty_inode
,
1656 .evict_inode
= gfs2_evict_inode
,
1657 .put_super
= gfs2_put_super
,
1658 .sync_fs
= gfs2_sync_fs
,
1659 .freeze_super
= gfs2_freeze
,
1660 .thaw_super
= gfs2_unfreeze
,
1661 .statfs
= gfs2_statfs
,
1662 .remount_fs
= gfs2_remount_fs
,
1663 .drop_inode
= gfs2_drop_inode
,
1664 .show_options
= gfs2_show_options
,