1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * load/unload driver, mount/dismount volumes
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
26 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h>
31 #include <linux/init.h>
32 #include <linux/random.h>
33 #include <linux/statfs.h>
34 #include <linux/moduleparam.h>
35 #include <linux/blkdev.h>
36 #include <linux/socket.h>
37 #include <linux/inet.h>
38 #include <linux/parser.h>
39 #include <linux/crc32.h>
40 #include <linux/debugfs.h>
41 #include <linux/mount.h>
42 #include <linux/seq_file.h>
43 #include <linux/quotaops.h>
44 #include <linux/smp_lock.h>
46 #define MLOG_MASK_PREFIX ML_SUPER
47 #include <cluster/masklog.h>
51 /* this should be the only file to include a version 1 header */
52 #include "ocfs1_fs_compat.h"
55 #include "blockcheck.h"
58 #include "extent_map.h"
59 #include "heartbeat.h"
62 #include "localalloc.h"
71 #include "refcounttree.h"
74 #include "buffer_head_io.h"
76 static struct kmem_cache *ocfs2_inode_cachep = NULL;
77 struct kmem_cache *ocfs2_dquot_cachep;
78 struct kmem_cache *ocfs2_qf_chunk_cachep;
80 /* OCFS2 needs to schedule several differnt types of work which
81 * require cluster locking, disk I/O, recovery waits, etc. Since these
82 * types of work tend to be heavy we avoid using the kernel events
83 * workqueue and schedule on our own. */
84 struct workqueue_struct *ocfs2_wq = NULL;
86 static struct dentry *ocfs2_debugfs_root = NULL;
88 MODULE_AUTHOR("Oracle");
89 MODULE_LICENSE("GPL");
93 unsigned long commit_interval;
94 unsigned long mount_opt;
95 unsigned int atime_quantum;
98 unsigned int resv_level;
100 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
103 static int ocfs2_parse_options(struct super_block *sb, char *options,
104 struct mount_options *mopt,
106 static int ocfs2_check_set_options(struct super_block *sb,
107 struct mount_options *options);
108 static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
109 static void ocfs2_put_super(struct super_block *sb);
110 static int ocfs2_mount_volume(struct super_block *sb);
111 static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
112 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
113 static int ocfs2_initialize_mem_caches(void);
114 static void ocfs2_free_mem_caches(void);
115 static void ocfs2_delete_osb(struct ocfs2_super *osb);
117 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
119 static int ocfs2_sync_fs(struct super_block *sb, int wait);
121 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
122 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
123 static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
124 static int ocfs2_check_volume(struct ocfs2_super *osb);
125 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
126 struct buffer_head *bh,
128 struct ocfs2_blockcheck_stats *stats);
129 static int ocfs2_initialize_super(struct super_block *sb,
130 struct buffer_head *bh,
132 struct ocfs2_blockcheck_stats *stats);
133 static int ocfs2_get_sector(struct super_block *sb,
134 struct buffer_head **bh,
137 static struct inode *ocfs2_alloc_inode(struct super_block *sb);
138 static void ocfs2_destroy_inode(struct inode *inode);
139 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
140 static int ocfs2_enable_quotas(struct ocfs2_super *osb);
141 static void ocfs2_disable_quotas(struct ocfs2_super *osb);
143 static const struct super_operations ocfs2_sops = {
144 .statfs = ocfs2_statfs,
145 .alloc_inode = ocfs2_alloc_inode,
146 .destroy_inode = ocfs2_destroy_inode,
147 .drop_inode = ocfs2_drop_inode,
148 .clear_inode = ocfs2_clear_inode,
149 .delete_inode = ocfs2_delete_inode,
150 .sync_fs = ocfs2_sync_fs,
151 .put_super = ocfs2_put_super,
152 .remount_fs = ocfs2_remount,
153 .show_options = ocfs2_show_options,
154 .quota_read = ocfs2_quota_read,
155 .quota_write = ocfs2_quota_write,
186 static const match_table_t tokens = {
187 {Opt_barrier, "barrier=%u"},
188 {Opt_err_panic, "errors=panic"},
189 {Opt_err_ro, "errors=remount-ro"},
191 {Opt_nointr, "nointr"},
192 {Opt_hb_none, OCFS2_HB_NONE},
193 {Opt_hb_local, OCFS2_HB_LOCAL},
194 {Opt_data_ordered, "data=ordered"},
195 {Opt_data_writeback, "data=writeback"},
196 {Opt_atime_quantum, "atime_quantum=%u"},
197 {Opt_slot, "preferred_slot=%u"},
198 {Opt_commit, "commit=%u"},
199 {Opt_localalloc, "localalloc=%d"},
200 {Opt_localflocks, "localflocks"},
201 {Opt_stack, "cluster_stack=%s"},
202 {Opt_user_xattr, "user_xattr"},
203 {Opt_nouser_xattr, "nouser_xattr"},
204 {Opt_inode64, "inode64"},
206 {Opt_noacl, "noacl"},
207 {Opt_usrquota, "usrquota"},
208 {Opt_grpquota, "grpquota"},
209 {Opt_resv_level, "resv_level=%u"},
210 {Opt_dir_resv_level, "dir_resv_level=%u"},
214 #ifdef CONFIG_DEBUG_FS
215 static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
217 struct ocfs2_cluster_connection *cconn = osb->cconn;
218 struct ocfs2_recovery_map *rm = osb->recovery_map;
219 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
222 out += snprintf(buf + out, len - out,
223 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
224 "Device", osb->dev_str, osb->uuid_str,
225 osb->fs_generation, osb->vol_label);
227 out += snprintf(buf + out, len - out,
228 "%10s => State: %d Flags: 0x%lX\n", "Volume",
229 atomic_read(&osb->vol_state), osb->osb_flags);
231 out += snprintf(buf + out, len - out,
232 "%10s => Block: %lu Cluster: %d\n", "Sizes",
233 osb->sb->s_blocksize, osb->s_clustersize);
235 out += snprintf(buf + out, len - out,
236 "%10s => Compat: 0x%X Incompat: 0x%X "
238 "Features", osb->s_feature_compat,
239 osb->s_feature_incompat, osb->s_feature_ro_compat);
241 out += snprintf(buf + out, len - out,
242 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
243 osb->s_mount_opt, osb->s_atime_quantum);
246 out += snprintf(buf + out, len - out,
247 "%10s => Stack: %s Name: %*s "
248 "Version: %d.%d\n", "Cluster",
249 (*osb->osb_cluster_stack == '\0' ?
250 "o2cb" : osb->osb_cluster_stack),
251 cconn->cc_namelen, cconn->cc_name,
252 cconn->cc_version.pv_major,
253 cconn->cc_version.pv_minor);
256 spin_lock(&osb->dc_task_lock);
257 out += snprintf(buf + out, len - out,
258 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
259 "WorkSeq: %lu\n", "DownCnvt",
260 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
261 osb->blocked_lock_count, osb->dc_wake_sequence,
262 osb->dc_work_sequence);
263 spin_unlock(&osb->dc_task_lock);
265 spin_lock(&osb->osb_lock);
266 out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
268 (osb->recovery_thread_task ?
269 task_pid_nr(osb->recovery_thread_task) : -1));
270 if (rm->rm_used == 0)
271 out += snprintf(buf + out, len - out, " None\n");
273 for (i = 0; i < rm->rm_used; i++)
274 out += snprintf(buf + out, len - out, " %d",
276 out += snprintf(buf + out, len - out, "\n");
278 spin_unlock(&osb->osb_lock);
280 out += snprintf(buf + out, len - out,
281 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
282 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
283 osb->osb_commit_interval,
284 atomic_read(&osb->needs_checkpoint));
286 out += snprintf(buf + out, len - out,
287 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
288 "Journal", osb->journal->j_state,
289 osb->journal->j_trans_id,
290 atomic_read(&osb->journal->j_num_trans));
292 out += snprintf(buf + out, len - out,
293 "%10s => GlobalAllocs: %d LocalAllocs: %d "
294 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
296 atomic_read(&osb->alloc_stats.bitmap_data),
297 atomic_read(&osb->alloc_stats.local_data),
298 atomic_read(&osb->alloc_stats.bg_allocs),
299 atomic_read(&osb->alloc_stats.moves),
300 atomic_read(&osb->alloc_stats.bg_extends));
302 out += snprintf(buf + out, len - out,
303 "%10s => State: %u Descriptor: %llu Size: %u bits "
304 "Default: %u bits\n",
305 "LocalAlloc", osb->local_alloc_state,
306 (unsigned long long)osb->la_last_gd,
307 osb->local_alloc_bits, osb->local_alloc_default_bits);
309 spin_lock(&osb->osb_lock);
310 out += snprintf(buf + out, len - out,
311 "%10s => InodeSlot: %d StolenInodes: %d, "
312 "MetaSlot: %d StolenMeta: %d\n", "Steal",
313 osb->s_inode_steal_slot,
314 atomic_read(&osb->s_num_inodes_stolen),
315 osb->s_meta_steal_slot,
316 atomic_read(&osb->s_num_meta_stolen));
317 spin_unlock(&osb->osb_lock);
319 out += snprintf(buf + out, len - out, "OrphanScan => ");
320 out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
321 os->os_count, os->os_seqno);
322 out += snprintf(buf + out, len - out, " Last Scan: ");
323 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
324 out += snprintf(buf + out, len - out, "Disabled\n");
326 out += snprintf(buf + out, len - out, "%lu seconds ago\n",
327 (get_seconds() - os->os_scantime.tv_sec));
329 out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
330 "Slots", "Num", "RecoGen");
331 for (i = 0; i < osb->max_slots; ++i) {
332 out += snprintf(buf + out, len - out,
333 "%10s %c %3d %10d\n",
335 (i == osb->slot_num ? '*' : ' '),
336 i, osb->slot_recovery_generations[i]);
342 static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
344 struct ocfs2_super *osb = inode->i_private;
347 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
351 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
353 file->private_data = buf;
360 static int ocfs2_debug_release(struct inode *inode, struct file *file)
362 kfree(file->private_data);
366 static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
367 size_t nbytes, loff_t *ppos)
369 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
370 i_size_read(file->f_mapping->host));
373 static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
377 static int ocfs2_debug_release(struct inode *inode, struct file *file)
381 static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
382 size_t nbytes, loff_t *ppos)
386 #endif /* CONFIG_DEBUG_FS */
388 static const struct file_operations ocfs2_osb_debug_fops = {
389 .open = ocfs2_osb_debug_open,
390 .release = ocfs2_debug_release,
391 .read = ocfs2_debug_read,
392 .llseek = generic_file_llseek,
395 static int ocfs2_sync_fs(struct super_block *sb, int wait)
399 struct ocfs2_super *osb = OCFS2_SB(sb);
401 if (ocfs2_is_hard_readonly(osb))
405 status = ocfs2_flush_truncate_log(osb);
409 ocfs2_schedule_truncate_log_flush(osb, 0);
412 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
415 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
421 static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
423 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
424 && (ino == USER_QUOTA_SYSTEM_INODE
425 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
427 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
428 && (ino == GROUP_QUOTA_SYSTEM_INODE
429 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
434 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
436 struct inode *new = NULL;
442 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
444 status = PTR_ERR(new);
448 osb->root_inode = new;
450 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
452 status = PTR_ERR(new);
456 osb->sys_root_inode = new;
458 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
459 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
460 if (!ocfs2_need_system_inode(osb, i))
462 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
464 ocfs2_release_system_inodes(osb);
467 /* FIXME: Should ERROR_RO_FS */
468 mlog(ML_ERROR, "Unable to load system inode %d, "
469 "possibly corrupt fs?", i);
472 // the array now has one ref, so drop this one
481 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
483 struct inode *new = NULL;
489 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
490 i < NUM_SYSTEM_INODES;
492 if (!ocfs2_need_system_inode(osb, i))
494 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
496 ocfs2_release_system_inodes(osb);
498 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
499 status, i, osb->slot_num);
502 /* the array now has one ref, so drop this one */
511 static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
518 for (i = 0; i < NUM_SYSTEM_INODES; i++) {
519 inode = osb->system_inodes[i];
522 osb->system_inodes[i] = NULL;
526 inode = osb->sys_root_inode;
529 osb->sys_root_inode = NULL;
532 inode = osb->root_inode;
535 osb->root_inode = NULL;
541 /* We're allocating fs objects, use GFP_NOFS */
542 static struct inode *ocfs2_alloc_inode(struct super_block *sb)
544 struct ocfs2_inode_info *oi;
546 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
550 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
551 return &oi->vfs_inode;
554 static void ocfs2_destroy_inode(struct inode *inode)
556 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
559 static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
562 unsigned int bytes = 1 << cbits;
563 unsigned int trim = bytes;
564 unsigned int bitshift = 32;
567 * i_size and all block offsets in ocfs2 are always 64 bits
568 * wide. i_clusters is 32 bits, in cluster-sized units. So on
569 * 64 bit platforms, cluster size will be the limiting factor.
572 #if BITS_PER_LONG == 32
573 # if defined(CONFIG_LBDAF)
574 BUILD_BUG_ON(sizeof(sector_t) != 8);
576 * We might be limited by page cache size.
578 if (bytes > PAGE_CACHE_SIZE) {
579 bytes = PAGE_CACHE_SIZE;
582 * Shift by 31 here so that we don't get larger than
589 * We are limited by the size of sector_t. Use block size, as
590 * that's what we expose to the VFS.
599 * Trim by a whole cluster when we can actually approach the
600 * on-disk limits. Otherwise we can overflow i_clusters when
601 * an extent start is at the max offset.
603 return (((unsigned long long)bytes) << bitshift) - trim;
606 static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
608 int incompat_features;
610 struct mount_options parsed_options;
611 struct ocfs2_super *osb = OCFS2_SB(sb);
615 if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
616 !ocfs2_check_set_options(sb, &parsed_options)) {
621 if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
622 (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
624 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
628 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
629 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
631 mlog(ML_ERROR, "Cannot change data mode on remount\n");
635 /* Probably don't want this on remount; it might
636 * mess with other nodes */
637 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
638 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
640 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
644 /* We're going to/from readonly mode. */
645 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
646 /* Disable quota accounting before remounting RO */
647 if (*flags & MS_RDONLY) {
648 ret = ocfs2_susp_quotas(osb, 0);
652 /* Lock here so the check of HARD_RO and the potential
653 * setting of SOFT_RO is atomic. */
654 spin_lock(&osb->osb_lock);
655 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
656 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
661 if (*flags & MS_RDONLY) {
662 mlog(0, "Going to ro mode.\n");
663 sb->s_flags |= MS_RDONLY;
664 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
666 mlog(0, "Making ro filesystem writeable.\n");
668 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
669 mlog(ML_ERROR, "Cannot remount RDWR "
670 "filesystem due to previous errors.\n");
674 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
675 if (incompat_features) {
676 mlog(ML_ERROR, "Cannot remount RDWR because "
677 "of unsupported optional features "
678 "(%x).\n", incompat_features);
682 sb->s_flags &= ~MS_RDONLY;
683 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
686 spin_unlock(&osb->osb_lock);
687 /* Enable quota accounting after remounting RW */
688 if (!ret && !(*flags & MS_RDONLY)) {
689 if (sb_any_quota_suspended(sb))
690 ret = ocfs2_susp_quotas(osb, 1);
692 ret = ocfs2_enable_quotas(osb);
694 /* Return back changes... */
695 spin_lock(&osb->osb_lock);
696 sb->s_flags |= MS_RDONLY;
697 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
698 spin_unlock(&osb->osb_lock);
705 /* Only save off the new mount options in case of a successful
707 osb->s_mount_opt = parsed_options.mount_opt;
708 osb->s_atime_quantum = parsed_options.atime_quantum;
709 osb->preferred_slot = parsed_options.slot;
710 if (parsed_options.commit_interval)
711 osb->osb_commit_interval = parsed_options.commit_interval;
713 if (!ocfs2_is_hard_readonly(osb))
714 ocfs2_set_journal_params(osb);
716 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
717 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
725 static int ocfs2_sb_probe(struct super_block *sb,
726 struct buffer_head **bh,
728 struct ocfs2_blockcheck_stats *stats)
731 struct ocfs1_vol_disk_hdr *hdr;
732 struct ocfs2_dinode *di;
738 *sector_size = bdev_logical_block_size(sb->s_bdev);
739 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
740 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
741 *sector_size, OCFS2_MAX_BLOCKSIZE);
746 /* Can this really happen? */
747 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
748 *sector_size = OCFS2_MIN_BLOCKSIZE;
750 /* check block zero for old format */
751 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
756 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
757 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
758 mlog(ML_ERROR, "incompatible version: %u.%u\n",
759 hdr->major_version, hdr->minor_version);
762 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
763 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
764 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
771 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
772 "upgraded before mounting with ocfs v2\n");
777 * Now check at magic offset for 512, 1024, 2048, 4096
778 * blocksizes. 4096 is the maximum blocksize because it is
779 * the minimum clustersize.
782 for (blksize = *sector_size;
783 blksize <= OCFS2_MAX_BLOCKSIZE;
785 tmpstat = ocfs2_get_sector(sb, bh,
786 OCFS2_SUPER_BLOCK_BLKNO,
793 di = (struct ocfs2_dinode *) (*bh)->b_data;
794 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
795 spin_lock_init(&stats->b_lock);
796 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
801 if (tmpstat != -EAGAIN) {
811 static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
813 if (ocfs2_mount_local(osb)) {
814 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
815 mlog(ML_ERROR, "Cannot heartbeat on a locally "
816 "mounted device.\n");
821 if (ocfs2_userspace_stack(osb)) {
822 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
823 mlog(ML_ERROR, "Userspace stack expected, but "
824 "o2cb heartbeat arguments passed to mount\n");
829 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
830 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
831 !ocfs2_userspace_stack(osb)) {
832 mlog(ML_ERROR, "Heartbeat has to be started to mount "
833 "a read-write clustered device.\n");
842 * If we're using a userspace stack, mount should have passed
843 * a name that matches the disk. If not, mount should not
844 * have passed a stack.
846 static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
847 struct mount_options *mopt)
849 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
851 "cluster stack passed to mount, but this filesystem "
852 "does not support it\n");
856 if (ocfs2_userspace_stack(osb) &&
857 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
858 OCFS2_STACK_LABEL_LEN)) {
860 "cluster stack passed to mount (\"%s\") does not "
861 "match the filesystem (\"%s\")\n",
863 osb->osb_cluster_stack);
870 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
873 struct super_block *sb = osb->sb;
874 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
875 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
878 for (type = 0; type < MAXQUOTAS; type++) {
879 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
882 status = dquot_resume(sb, type);
884 struct ocfs2_mem_dqinfo *oinfo;
886 /* Cancel periodic syncing before suspending */
887 oinfo = sb_dqinfo(sb, type)->dqi_priv;
888 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
889 status = dquot_suspend(sb, type);
895 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
896 "remount (error = %d).\n", status);
900 static int ocfs2_enable_quotas(struct ocfs2_super *osb)
902 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
903 struct super_block *sb = osb->sb;
904 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
905 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
906 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
907 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
911 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
912 for (type = 0; type < MAXQUOTAS; type++) {
913 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
915 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
921 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
922 DQUOT_USAGE_ENABLED);
927 for (type = 0; type < MAXQUOTAS; type++)
931 ocfs2_disable_quotas(osb);
932 for (type = 0; type < MAXQUOTAS; type++)
938 static void ocfs2_disable_quotas(struct ocfs2_super *osb)
942 struct super_block *sb = osb->sb;
943 struct ocfs2_mem_dqinfo *oinfo;
945 /* We mostly ignore errors in this function because there's not much
946 * we can do when we see them */
947 for (type = 0; type < MAXQUOTAS; type++) {
948 if (!sb_has_quota_loaded(sb, type))
950 /* Cancel periodic syncing before we grab dqonoff_mutex */
951 oinfo = sb_dqinfo(sb, type)->dqi_priv;
952 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
953 inode = igrab(sb->s_dquot.files[type]);
954 /* Turn off quotas. This will remove all dquot structures from
955 * memory and so they will be automatically synced to global
957 dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
958 DQUOT_LIMITS_ENABLED);
965 /* Handle quota on quotactl */
966 static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
967 char *path, int remount)
969 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
970 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
972 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
976 return 0; /* Just ignore it has been handled in
978 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
979 format_id, DQUOT_LIMITS_ENABLED);
982 /* Handle quota off quotactl */
983 static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
986 return 0; /* Ignore now and handle later in
988 return dquot_disable(sb, type, DQUOT_LIMITS_ENABLED);
991 static const struct quotactl_ops ocfs2_quotactl_ops = {
992 .quota_on = ocfs2_quota_on,
993 .quota_off = ocfs2_quota_off,
994 .quota_sync = vfs_quota_sync,
995 .get_info = vfs_get_dqinfo,
996 .set_info = vfs_set_dqinfo,
997 .get_dqblk = vfs_get_dqblk,
998 .set_dqblk = vfs_set_dqblk,
1001 static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
1003 struct dentry *root;
1004 int status, sector_size;
1005 struct mount_options parsed_options;
1006 struct inode *inode = NULL;
1007 struct ocfs2_super *osb = NULL;
1008 struct buffer_head *bh = NULL;
1010 struct ocfs2_blockcheck_stats stats;
1012 mlog_entry("%p, %p, %i", sb, data, silent);
1014 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
1016 goto read_super_error;
1019 /* probe for superblock */
1020 status = ocfs2_sb_probe(sb, &bh, §or_size, &stats);
1022 mlog(ML_ERROR, "superblock probe failed!\n");
1023 goto read_super_error;
1026 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
1030 goto read_super_error;
1035 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1037 goto read_super_error;
1039 osb->s_mount_opt = parsed_options.mount_opt;
1040 osb->s_atime_quantum = parsed_options.atime_quantum;
1041 osb->preferred_slot = parsed_options.slot;
1042 osb->osb_commit_interval = parsed_options.commit_interval;
1044 ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
1045 osb->osb_resv_level = parsed_options.resv_level;
1046 osb->osb_dir_resv_level = parsed_options.resv_level;
1047 if (parsed_options.dir_resv_level == -1)
1048 osb->osb_dir_resv_level = parsed_options.resv_level;
1050 osb->osb_dir_resv_level = parsed_options.dir_resv_level;
1052 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1054 goto read_super_error;
1056 sb->s_magic = OCFS2_SUPER_MAGIC;
1058 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1059 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1061 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1063 if (bdev_read_only(sb->s_bdev)) {
1064 if (!(sb->s_flags & MS_RDONLY)) {
1066 mlog(ML_ERROR, "Readonly device detected but readonly "
1067 "mount was not specified.\n");
1068 goto read_super_error;
1071 /* You should not be able to start a local heartbeat
1072 * on a readonly device. */
1073 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1075 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1077 goto read_super_error;
1080 status = ocfs2_check_journals_nolocks(osb);
1082 if (status == -EROFS)
1083 mlog(ML_ERROR, "Recovery required on readonly "
1084 "file system, but write access is "
1088 goto read_super_error;
1091 ocfs2_set_ro_flag(osb, 1);
1093 printk(KERN_NOTICE "Readonly device detected. No cluster "
1094 "services will be utilized for this mount. Recovery "
1095 "will be skipped.\n");
1098 if (!ocfs2_is_hard_readonly(osb)) {
1099 if (sb->s_flags & MS_RDONLY)
1100 ocfs2_set_ro_flag(osb, 0);
1103 status = ocfs2_verify_heartbeat(osb);
1106 goto read_super_error;
1109 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1110 ocfs2_debugfs_root);
1111 if (!osb->osb_debug_root) {
1113 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1114 goto read_super_error;
1117 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1118 osb->osb_debug_root,
1120 &ocfs2_osb_debug_fops);
1121 if (!osb->osb_ctxt) {
1124 goto read_super_error;
1127 if (ocfs2_meta_ecc(osb)) {
1128 status = ocfs2_blockcheck_stats_debugfs_install(
1129 &osb->osb_ecc_stats,
1130 osb->osb_debug_root);
1133 "Unable to create blockcheck statistics "
1135 goto read_super_error;
1139 status = ocfs2_mount_volume(sb);
1140 if (osb->root_inode)
1141 inode = igrab(osb->root_inode);
1144 goto read_super_error;
1149 goto read_super_error;
1152 root = d_alloc_root(inode);
1156 goto read_super_error;
1161 ocfs2_complete_mount_recovery(osb);
1163 if (ocfs2_mount_local(osb))
1164 snprintf(nodestr, sizeof(nodestr), "local");
1166 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1168 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
1169 "with %s data mode.\n",
1170 osb->dev_str, nodestr, osb->slot_num,
1171 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1174 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1175 wake_up(&osb->osb_mount_event);
1177 /* Now we can initialize quotas because we can afford to wait
1178 * for cluster locks recovery now. That also means that truncation
1179 * log recovery can happen but that waits for proper quota setup */
1180 if (!(sb->s_flags & MS_RDONLY)) {
1181 status = ocfs2_enable_quotas(osb);
1183 /* We have to err-out specially here because
1184 * s_root is already set */
1186 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1187 wake_up(&osb->osb_mount_event);
1193 ocfs2_complete_quota_recovery(osb);
1195 /* Now we wake up again for processes waiting for quotas */
1196 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1197 wake_up(&osb->osb_mount_event);
1199 /* Start this when the mount is almost sure of being successful */
1200 ocfs2_orphan_scan_start(osb);
1212 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1213 wake_up(&osb->osb_mount_event);
1214 ocfs2_dismount_volume(sb, 1);
1221 static int ocfs2_get_sb(struct file_system_type *fs_type,
1223 const char *dev_name,
1225 struct vfsmount *mnt)
1227 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1231 static void ocfs2_kill_sb(struct super_block *sb)
1233 struct ocfs2_super *osb = OCFS2_SB(sb);
1236 if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1239 /* Prevent further queueing of inode drop events */
1240 spin_lock(&dentry_list_lock);
1241 ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1242 spin_unlock(&dentry_list_lock);
1243 /* Wait for work to finish and/or remove it */
1244 cancel_work_sync(&osb->dentry_lock_work);
1246 kill_block_super(sb);
1249 static struct file_system_type ocfs2_fs_type = {
1250 .owner = THIS_MODULE,
1252 .get_sb = ocfs2_get_sb, /* is this called when we mount
1254 .kill_sb = ocfs2_kill_sb,
1256 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
1260 static int ocfs2_check_set_options(struct super_block *sb,
1261 struct mount_options *options)
1263 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1264 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1265 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1266 mlog(ML_ERROR, "User quotas were requested, but this "
1267 "filesystem does not have the feature enabled.\n");
1270 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1271 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1272 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1273 mlog(ML_ERROR, "Group quotas were requested, but this "
1274 "filesystem does not have the feature enabled.\n");
1277 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1278 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1279 mlog(ML_ERROR, "ACL support requested but extended attributes "
1280 "feature is not enabled\n");
1283 /* No ACL setting specified? Use XATTR feature... */
1284 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1285 OCFS2_MOUNT_NO_POSIX_ACL))) {
1286 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1287 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1289 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1294 static int ocfs2_parse_options(struct super_block *sb,
1296 struct mount_options *mopt,
1302 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1303 options ? options : "(none)");
1305 mopt->commit_interval = 0;
1306 mopt->mount_opt = OCFS2_MOUNT_NOINTR;
1307 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1308 mopt->slot = OCFS2_INVALID_SLOT;
1309 mopt->localalloc_opt = -1;
1310 mopt->cluster_stack[0] = '\0';
1311 mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
1312 mopt->dir_resv_level = -1;
1319 while ((p = strsep(&options, ",")) != NULL) {
1321 substring_t args[MAX_OPT_ARGS];
1326 token = match_token(p, tokens, args);
1329 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
1332 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
1335 if (match_int(&args[0], &option)) {
1340 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
1342 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
1345 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
1348 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
1351 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
1354 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1356 case Opt_data_ordered:
1357 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
1359 case Opt_data_writeback:
1360 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
1362 case Opt_user_xattr:
1363 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1365 case Opt_nouser_xattr:
1366 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1368 case Opt_atime_quantum:
1369 if (match_int(&args[0], &option)) {
1374 mopt->atime_quantum = option;
1378 if (match_int(&args[0], &option)) {
1383 mopt->slot = (s16)option;
1387 if (match_int(&args[0], &option)) {
1394 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1395 mopt->commit_interval = HZ * option;
1397 case Opt_localalloc:
1399 if (match_int(&args[0], &option)) {
1404 mopt->localalloc_opt = option;
1406 case Opt_localflocks:
1408 * Changing this during remount could race
1409 * flock() requests, or "unbalance" existing
1410 * ones (e.g., a lock is taken in one mode but
1411 * dropped in the other). If users care enough
1412 * to flip locking modes during remount, we
1413 * could add a "local" flag to individual
1414 * flock structures for proper tracking of
1418 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1421 /* Check both that the option we were passed
1422 * is of the right length and that it is a proper
1423 * string of the right length.
1425 if (((args[0].to - args[0].from) !=
1426 OCFS2_STACK_LABEL_LEN) ||
1427 (strnlen(args[0].from,
1428 OCFS2_STACK_LABEL_LEN) !=
1429 OCFS2_STACK_LABEL_LEN)) {
1431 "Invalid cluster_stack option\n");
1435 memcpy(mopt->cluster_stack, args[0].from,
1436 OCFS2_STACK_LABEL_LEN);
1437 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1440 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1443 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1446 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1449 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1450 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
1453 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1454 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1456 case Opt_resv_level:
1459 if (match_int(&args[0], &option)) {
1463 if (option >= OCFS2_MIN_RESV_LEVEL &&
1464 option < OCFS2_MAX_RESV_LEVEL)
1465 mopt->resv_level = option;
1467 case Opt_dir_resv_level:
1470 if (match_int(&args[0], &option)) {
1474 if (option >= OCFS2_MIN_RESV_LEVEL &&
1475 option < OCFS2_MAX_RESV_LEVEL)
1476 mopt->dir_resv_level = option;
1480 "Unrecognized mount option \"%s\" "
1481 "or missing value\n", p);
1494 static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1496 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1497 unsigned long opts = osb->s_mount_opt;
1498 unsigned int local_alloc_megs;
1500 if (opts & OCFS2_MOUNT_HB_LOCAL)
1501 seq_printf(s, ",_netdev,heartbeat=local");
1503 seq_printf(s, ",heartbeat=none");
1505 if (opts & OCFS2_MOUNT_NOINTR)
1506 seq_printf(s, ",nointr");
1508 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1509 seq_printf(s, ",data=writeback");
1511 seq_printf(s, ",data=ordered");
1513 if (opts & OCFS2_MOUNT_BARRIER)
1514 seq_printf(s, ",barrier=1");
1516 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1517 seq_printf(s, ",errors=panic");
1519 seq_printf(s, ",errors=remount-ro");
1521 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1522 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1524 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1525 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1527 if (osb->osb_commit_interval)
1528 seq_printf(s, ",commit=%u",
1529 (unsigned) (osb->osb_commit_interval / HZ));
1531 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1532 if (local_alloc_megs != ocfs2_la_default_mb(osb))
1533 seq_printf(s, ",localalloc=%d", local_alloc_megs);
1535 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1536 seq_printf(s, ",localflocks,");
1538 if (osb->osb_cluster_stack[0])
1539 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1540 osb->osb_cluster_stack);
1541 if (opts & OCFS2_MOUNT_USRQUOTA)
1542 seq_printf(s, ",usrquota");
1543 if (opts & OCFS2_MOUNT_GRPQUOTA)
1544 seq_printf(s, ",grpquota");
1546 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1547 seq_printf(s, ",nouser_xattr");
1549 seq_printf(s, ",user_xattr");
1551 if (opts & OCFS2_MOUNT_INODE64)
1552 seq_printf(s, ",inode64");
1554 if (opts & OCFS2_MOUNT_POSIX_ACL)
1555 seq_printf(s, ",acl");
1557 seq_printf(s, ",noacl");
1559 if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
1560 seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
1562 if (osb->osb_dir_resv_level != osb->osb_resv_level)
1563 seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
1568 static int __init ocfs2_init(void)
1574 ocfs2_print_version();
1576 status = init_ocfs2_uptodate_cache();
1582 status = ocfs2_initialize_mem_caches();
1588 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1594 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1595 if (!ocfs2_debugfs_root) {
1597 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1600 status = ocfs2_quota_setup();
1604 ocfs2_set_locking_protocol();
1606 status = register_quota_format(&ocfs2_quota_format);
1609 ocfs2_quota_shutdown();
1610 ocfs2_free_mem_caches();
1611 exit_ocfs2_uptodate_cache();
1617 return register_filesystem(&ocfs2_fs_type);
1622 static void __exit ocfs2_exit(void)
1626 ocfs2_quota_shutdown();
1629 flush_workqueue(ocfs2_wq);
1630 destroy_workqueue(ocfs2_wq);
1633 unregister_quota_format(&ocfs2_quota_format);
1635 debugfs_remove(ocfs2_debugfs_root);
1637 ocfs2_free_mem_caches();
1639 unregister_filesystem(&ocfs2_fs_type);
1641 exit_ocfs2_uptodate_cache();
1646 static void ocfs2_put_super(struct super_block *sb)
1648 mlog_entry("(0x%p)\n", sb);
1652 ocfs2_sync_blockdev(sb);
1653 ocfs2_dismount_volume(sb, 0);
1660 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1662 struct ocfs2_super *osb;
1663 u32 numbits, freebits;
1665 struct ocfs2_dinode *bm_lock;
1666 struct buffer_head *bh = NULL;
1667 struct inode *inode = NULL;
1669 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
1671 osb = OCFS2_SB(dentry->d_sb);
1673 inode = ocfs2_get_system_file_inode(osb,
1674 GLOBAL_BITMAP_SYSTEM_INODE,
1675 OCFS2_INVALID_SLOT);
1677 mlog(ML_ERROR, "failed to get bitmap inode\n");
1682 status = ocfs2_inode_lock(inode, &bh, 0);
1688 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1690 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1691 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1693 buf->f_type = OCFS2_SUPER_MAGIC;
1694 buf->f_bsize = dentry->d_sb->s_blocksize;
1695 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1696 buf->f_blocks = ((sector_t) numbits) *
1697 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1698 buf->f_bfree = ((sector_t) freebits) *
1699 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1700 buf->f_bavail = buf->f_bfree;
1701 buf->f_files = numbits;
1702 buf->f_ffree = freebits;
1703 buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1705 buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1706 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
1710 ocfs2_inode_unlock(inode, 0);
1721 static void ocfs2_inode_init_once(void *data)
1723 struct ocfs2_inode_info *oi = data;
1726 oi->ip_open_count = 0;
1727 spin_lock_init(&oi->ip_lock);
1728 ocfs2_extent_map_init(&oi->vfs_inode);
1729 INIT_LIST_HEAD(&oi->ip_io_markers);
1730 oi->ip_dir_start_lookup = 0;
1732 init_rwsem(&oi->ip_alloc_sem);
1733 init_rwsem(&oi->ip_xattr_sem);
1734 mutex_init(&oi->ip_io_mutex);
1736 oi->ip_blkno = 0ULL;
1737 oi->ip_clusters = 0;
1739 ocfs2_resv_init_once(&oi->ip_la_data_resv);
1741 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
1742 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
1743 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
1745 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
1746 &ocfs2_inode_caching_ops);
1748 inode_init_once(&oi->vfs_inode);
1751 static int ocfs2_initialize_mem_caches(void)
1753 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
1754 sizeof(struct ocfs2_inode_info),
1756 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1758 ocfs2_inode_init_once);
1759 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1760 sizeof(struct ocfs2_dquot),
1762 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1765 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1766 sizeof(struct ocfs2_quota_chunk),
1768 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1770 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1771 !ocfs2_qf_chunk_cachep) {
1772 if (ocfs2_inode_cachep)
1773 kmem_cache_destroy(ocfs2_inode_cachep);
1774 if (ocfs2_dquot_cachep)
1775 kmem_cache_destroy(ocfs2_dquot_cachep);
1776 if (ocfs2_qf_chunk_cachep)
1777 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1784 static void ocfs2_free_mem_caches(void)
1786 if (ocfs2_inode_cachep)
1787 kmem_cache_destroy(ocfs2_inode_cachep);
1788 ocfs2_inode_cachep = NULL;
1790 if (ocfs2_dquot_cachep)
1791 kmem_cache_destroy(ocfs2_dquot_cachep);
1792 ocfs2_dquot_cachep = NULL;
1794 if (ocfs2_qf_chunk_cachep)
1795 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1796 ocfs2_qf_chunk_cachep = NULL;
1799 static int ocfs2_get_sector(struct super_block *sb,
1800 struct buffer_head **bh,
1804 if (!sb_set_blocksize(sb, sect_size)) {
1805 mlog(ML_ERROR, "unable to set blocksize\n");
1809 *bh = sb_getblk(sb, block);
1815 if (!buffer_dirty(*bh))
1816 clear_buffer_uptodate(*bh);
1818 ll_rw_block(READ, 1, bh);
1819 wait_on_buffer(*bh);
1820 if (!buffer_uptodate(*bh)) {
1830 static int ocfs2_mount_volume(struct super_block *sb)
1833 int unlock_super = 0;
1834 struct ocfs2_super *osb = OCFS2_SB(sb);
1838 if (ocfs2_is_hard_readonly(osb))
1841 status = ocfs2_dlm_init(osb);
1847 status = ocfs2_super_lock(osb, 1);
1854 /* This will load up the node map and add ourselves to it. */
1855 status = ocfs2_find_slot(osb);
1861 /* load all node-local system inodes */
1862 status = ocfs2_init_local_system_inodes(osb);
1868 status = ocfs2_check_volume(osb);
1874 status = ocfs2_truncate_log_init(osb);
1880 ocfs2_super_unlock(osb, 1);
1886 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1888 int tmp, hangup_needed = 0;
1889 struct ocfs2_super *osb = NULL;
1892 mlog_entry("(0x%p)\n", sb);
1898 debugfs_remove(osb->osb_ctxt);
1901 * Flush inode dropping work queue so that deletes are
1902 * performed while the filesystem is still working
1904 ocfs2_drop_all_dl_inodes(osb);
1906 /* Orphan scan should be stopped as early as possible */
1907 ocfs2_orphan_scan_stop(osb);
1909 ocfs2_disable_quotas(osb);
1911 ocfs2_shutdown_local_alloc(osb);
1913 ocfs2_truncate_log_shutdown(osb);
1915 /* This will disable recovery and flush any recovery work. */
1916 ocfs2_recovery_exit(osb);
1918 ocfs2_journal_shutdown(osb);
1920 ocfs2_sync_blockdev(sb);
1922 ocfs2_purge_refcount_trees(osb);
1924 /* No cluster connection means we've failed during mount, so skip
1925 * all the steps which depended on that to complete. */
1927 tmp = ocfs2_super_lock(osb, 1);
1934 if (osb->slot_num != OCFS2_INVALID_SLOT)
1935 ocfs2_put_slot(osb);
1938 ocfs2_super_unlock(osb, 1);
1940 ocfs2_release_system_inodes(osb);
1943 * If we're dismounting due to mount error, mount.ocfs2 will clean
1944 * up heartbeat. If we're a local mount, there is no heartbeat.
1945 * If we failed before we got a uuid_str yet, we can't stop
1946 * heartbeat. Otherwise, do it.
1948 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
1952 ocfs2_dlm_shutdown(osb, hangup_needed);
1954 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
1955 debugfs_remove(osb->osb_debug_root);
1958 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
1960 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1962 if (ocfs2_mount_local(osb))
1963 snprintf(nodestr, sizeof(nodestr), "local");
1965 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1967 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1968 osb->dev_str, nodestr);
1970 ocfs2_delete_osb(osb);
1973 sb->s_fs_info = NULL;
1976 static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1977 unsigned uuid_bytes)
1982 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1984 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
1985 if (osb->uuid_str == NULL)
1988 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1989 /* print with null */
1990 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1991 if (ret != 2) /* drop super cleans up */
1993 /* then only advance past the last char */
2000 static int ocfs2_initialize_super(struct super_block *sb,
2001 struct buffer_head *bh,
2003 struct ocfs2_blockcheck_stats *stats)
2006 int i, cbits, bbits;
2007 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
2008 struct inode *inode = NULL;
2009 struct ocfs2_journal *journal;
2010 __le32 uuid_net_key;
2011 struct ocfs2_super *osb;
2015 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
2022 sb->s_fs_info = osb;
2023 sb->s_op = &ocfs2_sops;
2024 sb->s_export_op = &ocfs2_export_ops;
2025 sb->s_qcop = &ocfs2_quotactl_ops;
2026 sb->dq_op = &ocfs2_quota_operations;
2027 sb->s_xattr = ocfs2_xattr_handlers;
2028 sb->s_time_gran = 1;
2029 sb->s_flags |= MS_NOATIME;
2030 /* this is needed to support O_LARGEFILE */
2031 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2032 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
2033 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
2035 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
2037 for (i = 0; i < 3; i++)
2038 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
2039 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2042 /* Save off for ocfs2_rw_direct */
2043 osb->s_sectsize_bits = blksize_bits(sector_size);
2044 BUG_ON(!osb->s_sectsize_bits);
2046 spin_lock_init(&osb->dc_task_lock);
2047 init_waitqueue_head(&osb->dc_event);
2048 osb->dc_work_sequence = 0;
2049 osb->dc_wake_sequence = 0;
2050 INIT_LIST_HEAD(&osb->blocked_lock_list);
2051 osb->blocked_lock_count = 0;
2052 spin_lock_init(&osb->osb_lock);
2053 spin_lock_init(&osb->osb_xattr_lock);
2054 ocfs2_init_steal_slots(osb);
2056 atomic_set(&osb->alloc_stats.moves, 0);
2057 atomic_set(&osb->alloc_stats.local_data, 0);
2058 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2059 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2060 atomic_set(&osb->alloc_stats.bg_extends, 0);
2062 /* Copy the blockcheck stats from the superblock probe */
2063 osb->osb_ecc_stats = *stats;
2065 ocfs2_init_node_maps(osb);
2067 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2068 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2070 ocfs2_orphan_scan_init(osb);
2072 status = ocfs2_recovery_init(osb);
2074 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2079 init_waitqueue_head(&osb->checkpoint_event);
2080 atomic_set(&osb->needs_checkpoint, 0);
2082 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2084 osb->slot_num = OCFS2_INVALID_SLOT;
2086 osb->s_xattr_inline_size = le16_to_cpu(
2087 di->id2.i_super.s_xattr_inline_size);
2089 osb->local_alloc_state = OCFS2_LA_UNUSED;
2090 osb->local_alloc_bh = NULL;
2091 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
2093 init_waitqueue_head(&osb->osb_mount_event);
2095 status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
2101 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2102 if (!osb->vol_label) {
2103 mlog(ML_ERROR, "unable to alloc vol label\n");
2108 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2109 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2110 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2115 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
2117 osb->slot_recovery_generations =
2118 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2120 if (!osb->slot_recovery_generations) {
2126 init_waitqueue_head(&osb->osb_wipe_event);
2127 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2128 sizeof(*osb->osb_orphan_wipes),
2130 if (!osb->osb_orphan_wipes) {
2136 osb->osb_rf_lock_tree = RB_ROOT;
2138 osb->s_feature_compat =
2139 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2140 osb->s_feature_ro_compat =
2141 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2142 osb->s_feature_incompat =
2143 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2145 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2146 mlog(ML_ERROR, "couldn't mount because of unsupported "
2147 "optional features (%x).\n", i);
2151 if (!(osb->sb->s_flags & MS_RDONLY) &&
2152 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2153 mlog(ML_ERROR, "couldn't mount RDWR because of "
2154 "unsupported optional features (%x).\n", i);
2159 if (ocfs2_userspace_stack(osb)) {
2160 memcpy(osb->osb_cluster_stack,
2161 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2162 OCFS2_STACK_LABEL_LEN);
2163 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2164 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2166 "couldn't mount because of an invalid "
2167 "cluster stack label (%s) \n",
2168 osb->osb_cluster_stack);
2173 /* The empty string is identical with classic tools that
2174 * don't know about s_cluster_info. */
2175 osb->osb_cluster_stack[0] = '\0';
2178 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2181 * This should be done in ocfs2_journal_init(), but unknown
2182 * ordering issues will cause the filesystem to crash.
2183 * If anyone wants to figure out what part of the code
2184 * refers to osb->journal before ocfs2_journal_init() is run,
2187 /* initialize our journal structure */
2189 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
2191 mlog(ML_ERROR, "unable to alloc journal\n");
2195 osb->journal = journal;
2196 journal->j_osb = osb;
2198 atomic_set(&journal->j_num_trans, 0);
2199 init_rwsem(&journal->j_trans_barrier);
2200 init_waitqueue_head(&journal->j_checkpointed);
2201 spin_lock_init(&journal->j_lock);
2202 journal->j_trans_id = (unsigned long) 1;
2203 INIT_LIST_HEAD(&journal->j_la_cleanups);
2204 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
2205 journal->j_state = OCFS2_JOURNAL_FREE;
2207 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2208 osb->dentry_lock_list = NULL;
2210 /* get some pseudo constants for clustersize bits */
2211 osb->s_clustersize_bits =
2212 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2213 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2214 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2216 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2217 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2218 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2219 osb->s_clustersize);
2224 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2226 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2227 "what jbd can address in 32 bits.\n");
2232 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2233 sizeof(di->id2.i_super.s_uuid))) {
2234 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2239 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
2241 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2242 osb->vol_label[63] = '\0';
2243 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2244 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2245 osb->first_cluster_group_blkno =
2246 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2247 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
2248 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2249 mlog(0, "vol_label: %s\n", osb->vol_label);
2250 mlog(0, "uuid: %s\n", osb->uuid_str);
2251 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2252 (unsigned long long)osb->root_blkno,
2253 (unsigned long long)osb->system_dir_blkno);
2255 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2256 if (!osb->osb_dlm_debug) {
2262 atomic_set(&osb->vol_state, VOLUME_INIT);
2264 /* load root, system_dir, and all global system inodes */
2265 status = ocfs2_init_global_system_inodes(osb);
2274 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2275 OCFS2_INVALID_SLOT);
2282 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
2283 osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
2286 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
2287 osb->s_feature_incompat) * 8;
2289 status = ocfs2_init_slot_info(osb);
2301 * will return: -EAGAIN if it is ok to keep searching for superblocks
2302 * -EINVAL if there is a bad superblock
2305 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2306 struct buffer_head *bh,
2308 struct ocfs2_blockcheck_stats *stats)
2310 int status = -EAGAIN;
2314 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2315 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
2316 /* We have to do a raw check of the feature here */
2317 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2318 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2319 status = ocfs2_block_check_validate(bh->b_data,
2327 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2328 mlog(ML_ERROR, "found superblock with incorrect block "
2329 "size: found %u, should be %u\n",
2330 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2332 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2333 OCFS2_MAJOR_REV_LEVEL ||
2334 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2335 OCFS2_MINOR_REV_LEVEL) {
2336 mlog(ML_ERROR, "found superblock with bad version: "
2337 "found %u.%u, should be %u.%u\n",
2338 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2339 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2340 OCFS2_MAJOR_REV_LEVEL,
2341 OCFS2_MINOR_REV_LEVEL);
2342 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2343 mlog(ML_ERROR, "bad block number on superblock: "
2344 "found %llu, should be %llu\n",
2345 (unsigned long long)le64_to_cpu(di->i_blkno),
2346 (unsigned long long)bh->b_blocknr);
2347 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2348 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2349 mlog(ML_ERROR, "bad cluster size found: %u\n",
2350 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2351 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2352 mlog(ML_ERROR, "bad root_blkno: 0\n");
2353 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2354 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2355 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2357 "Superblock slots found greater than file system "
2358 "maximum: found %u, max %u\n",
2359 le16_to_cpu(di->id2.i_super.s_max_slots),
2372 static int ocfs2_check_volume(struct ocfs2_super *osb)
2377 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2383 /* Init our journal object. */
2384 status = ocfs2_journal_init(osb->journal, &dirty);
2386 mlog(ML_ERROR, "Could not initialize journal!\n");
2390 /* If the journal was unmounted cleanly then we don't want to
2391 * recover anything. Otherwise, journal_load will do that
2392 * dirty work for us :) */
2394 status = ocfs2_journal_wipe(osb->journal, 0);
2400 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2401 "recovering volume.\n");
2404 local = ocfs2_mount_local(osb);
2406 /* will play back anything left in the journal. */
2407 status = ocfs2_journal_load(osb->journal, local, dirty);
2409 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2414 /* recover my local alloc if we didn't unmount cleanly. */
2415 status = ocfs2_begin_local_alloc_recovery(osb,
2422 /* we complete the recovery process after we've marked
2423 * ourselves as mounted. */
2426 mlog(0, "Journal loaded.\n");
2428 status = ocfs2_load_local_alloc(osb);
2435 /* Recovery will be completed after we've mounted the
2436 * rest of the volume. */
2438 osb->local_alloc_copy = local_alloc;
2442 /* go through each journal, trylock it and if you get the
2443 * lock, and it's marked as dirty, set the bit in the recover
2444 * map and launch a recovery thread for it. */
2445 status = ocfs2_mark_dead_nodes(osb);
2451 status = ocfs2_compute_replay_slots(osb);
2464 * The routine gets called from dismount or close whenever a dismount on
2465 * volume is requested and the osb open count becomes 1.
2466 * It will remove the osb from the global list and also free up all the
2467 * initialized resources and fileobject.
2469 static void ocfs2_delete_osb(struct ocfs2_super *osb)
2473 /* This function assumes that the caller has the main osb resource */
2475 ocfs2_free_slot_info(osb);
2477 kfree(osb->osb_orphan_wipes);
2478 kfree(osb->slot_recovery_generations);
2480 * This belongs in journal shutdown, but because we have to
2481 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2484 kfree(osb->journal);
2485 if (osb->local_alloc_copy)
2486 kfree(osb->local_alloc_copy);
2487 kfree(osb->uuid_str);
2488 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2489 memset(osb, 0, sizeof(struct ocfs2_super));
2494 /* Put OCFS2 into a readonly state, or (if the user specifies it),
2495 * panic(). We do not support continue-on-error operation. */
2496 static void ocfs2_handle_error(struct super_block *sb)
2498 struct ocfs2_super *osb = OCFS2_SB(sb);
2500 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2501 panic("OCFS2: (device %s): panic forced after error\n",
2504 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2506 if (sb->s_flags & MS_RDONLY &&
2507 (ocfs2_is_soft_readonly(osb) ||
2508 ocfs2_is_hard_readonly(osb)))
2511 printk(KERN_CRIT "File system is now read-only due to the potential "
2512 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2513 "system is unmounted.\n");
2514 sb->s_flags |= MS_RDONLY;
2515 ocfs2_set_ro_flag(osb, 0);
2518 static char error_buf[1024];
2520 void __ocfs2_error(struct super_block *sb,
2521 const char *function,
2522 const char *fmt, ...)
2526 va_start(args, fmt);
2527 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2530 /* Not using mlog here because we want to show the actual
2531 * function the error came from. */
2532 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2533 sb->s_id, function, error_buf);
2535 ocfs2_handle_error(sb);
2538 /* Handle critical errors. This is intentionally more drastic than
2539 * ocfs2_handle_error, so we only use for things like journal errors,
2541 void __ocfs2_abort(struct super_block* sb,
2542 const char *function,
2543 const char *fmt, ...)
2547 va_start(args, fmt);
2548 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2551 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2552 sb->s_id, function, error_buf);
2554 /* We don't have the cluster support yet to go straight to
2555 * hard readonly in here. Until then, we want to keep
2556 * ocfs2_abort() so that we can at least mark critical
2559 * TODO: This should abort the journal and alert other nodes
2560 * that our slot needs recovery. */
2562 /* Force a panic(). This stinks, but it's better than letting
2563 * things continue without having a proper hard readonly
2565 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2566 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
2567 ocfs2_handle_error(sb);
2571 * Void signal blockers, because in-kernel sigprocmask() only fails
2572 * when SIG_* is wrong.
2574 void ocfs2_block_signals(sigset_t *oldset)
2579 sigfillset(&blocked);
2580 rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
2584 void ocfs2_unblock_signals(sigset_t *oldset)
2586 int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
2590 module_init(ocfs2_init);
2591 module_exit(ocfs2_exit);