1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * load/unload driver, mount/dismount volumes
7 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/slab.h>
14 #include <linux/highmem.h>
15 #include <linux/init.h>
16 #include <linux/random.h>
17 #include <linux/statfs.h>
18 #include <linux/moduleparam.h>
19 #include <linux/blkdev.h>
20 #include <linux/socket.h>
21 #include <linux/inet.h>
22 #include <linux/parser.h>
23 #include <linux/crc32.h>
24 #include <linux/debugfs.h>
25 #include <linux/mount.h>
26 #include <linux/seq_file.h>
27 #include <linux/quotaops.h>
28 #include <linux/cleancache.h>
29 #include <linux/signal.h>
31 #define CREATE_TRACE_POINTS
32 #include "ocfs2_trace.h"
34 #include <cluster/masklog.h>
38 /* this should be the only file to include a version 1 header */
39 #include "ocfs1_fs_compat.h"
43 #include "blockcheck.h"
46 #include "extent_map.h"
47 #include "heartbeat.h"
50 #include "localalloc.h"
58 #include "refcounttree.h"
61 #include "buffer_head_io.h"
62 #include "filecheck.h"
64 static struct kmem_cache *ocfs2_inode_cachep;
65 struct kmem_cache *ocfs2_dquot_cachep;
66 struct kmem_cache *ocfs2_qf_chunk_cachep;
68 static struct dentry *ocfs2_debugfs_root;
70 MODULE_AUTHOR("Oracle");
71 MODULE_LICENSE("GPL");
72 MODULE_DESCRIPTION("OCFS2 cluster file system");
76 unsigned long commit_interval;
77 unsigned long mount_opt;
78 unsigned int atime_quantum;
81 unsigned int resv_level;
83 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
86 static int ocfs2_parse_options(struct super_block *sb, char *options,
87 struct mount_options *mopt,
89 static int ocfs2_check_set_options(struct super_block *sb,
90 struct mount_options *options);
91 static int ocfs2_show_options(struct seq_file *s, struct dentry *root);
92 static void ocfs2_put_super(struct super_block *sb);
93 static int ocfs2_mount_volume(struct super_block *sb);
94 static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
95 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
96 static int ocfs2_initialize_mem_caches(void);
97 static void ocfs2_free_mem_caches(void);
98 static void ocfs2_delete_osb(struct ocfs2_super *osb);
100 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
102 static int ocfs2_sync_fs(struct super_block *sb, int wait);
104 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
105 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
106 static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
107 static int ocfs2_check_volume(struct ocfs2_super *osb);
108 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
109 struct buffer_head *bh,
111 struct ocfs2_blockcheck_stats *stats);
112 static int ocfs2_initialize_super(struct super_block *sb,
113 struct buffer_head *bh,
115 struct ocfs2_blockcheck_stats *stats);
116 static int ocfs2_get_sector(struct super_block *sb,
117 struct buffer_head **bh,
120 static struct inode *ocfs2_alloc_inode(struct super_block *sb);
121 static void ocfs2_free_inode(struct inode *inode);
122 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
123 static int ocfs2_enable_quotas(struct ocfs2_super *osb);
124 static void ocfs2_disable_quotas(struct ocfs2_super *osb);
126 static struct dquot **ocfs2_get_dquots(struct inode *inode)
128 return OCFS2_I(inode)->i_dquot;
131 static const struct super_operations ocfs2_sops = {
132 .statfs = ocfs2_statfs,
133 .alloc_inode = ocfs2_alloc_inode,
134 .free_inode = ocfs2_free_inode,
135 .drop_inode = ocfs2_drop_inode,
136 .evict_inode = ocfs2_evict_inode,
137 .sync_fs = ocfs2_sync_fs,
138 .put_super = ocfs2_put_super,
139 .remount_fs = ocfs2_remount,
140 .show_options = ocfs2_show_options,
141 .quota_read = ocfs2_quota_read,
142 .quota_write = ocfs2_quota_write,
143 .get_dquots = ocfs2_get_dquots,
170 Opt_coherency_buffered,
174 Opt_journal_async_commit,
180 static const match_table_t tokens = {
181 {Opt_barrier, "barrier=%u"},
182 {Opt_err_panic, "errors=panic"},
183 {Opt_err_ro, "errors=remount-ro"},
185 {Opt_nointr, "nointr"},
186 {Opt_hb_none, OCFS2_HB_NONE},
187 {Opt_hb_local, OCFS2_HB_LOCAL},
188 {Opt_hb_global, OCFS2_HB_GLOBAL},
189 {Opt_data_ordered, "data=ordered"},
190 {Opt_data_writeback, "data=writeback"},
191 {Opt_atime_quantum, "atime_quantum=%u"},
192 {Opt_slot, "preferred_slot=%u"},
193 {Opt_commit, "commit=%u"},
194 {Opt_localalloc, "localalloc=%d"},
195 {Opt_localflocks, "localflocks"},
196 {Opt_stack, "cluster_stack=%s"},
197 {Opt_user_xattr, "user_xattr"},
198 {Opt_nouser_xattr, "nouser_xattr"},
199 {Opt_inode64, "inode64"},
201 {Opt_noacl, "noacl"},
202 {Opt_usrquota, "usrquota"},
203 {Opt_grpquota, "grpquota"},
204 {Opt_coherency_buffered, "coherency=buffered"},
205 {Opt_coherency_full, "coherency=full"},
206 {Opt_resv_level, "resv_level=%u"},
207 {Opt_dir_resv_level, "dir_resv_level=%u"},
208 {Opt_journal_async_commit, "journal_async_commit"},
209 {Opt_err_cont, "errors=continue"},
210 {Opt_nocluster, "nocluster"},
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;
223 out += scnprintf(buf + out, len - out,
224 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
225 "Device", osb->dev_str, osb->uuid_str,
226 osb->fs_generation, osb->vol_label);
228 out += scnprintf(buf + out, len - out,
229 "%10s => State: %d Flags: 0x%lX\n", "Volume",
230 atomic_read(&osb->vol_state), osb->osb_flags);
232 out += scnprintf(buf + out, len - out,
233 "%10s => Block: %lu Cluster: %d\n", "Sizes",
234 osb->sb->s_blocksize, osb->s_clustersize);
236 out += scnprintf(buf + out, len - out,
237 "%10s => Compat: 0x%X Incompat: 0x%X "
239 "Features", osb->s_feature_compat,
240 osb->s_feature_incompat, osb->s_feature_ro_compat);
242 out += scnprintf(buf + out, len - out,
243 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
244 osb->s_mount_opt, osb->s_atime_quantum);
247 out += scnprintf(buf + out, len - out,
248 "%10s => Stack: %s Name: %*s "
249 "Version: %d.%d\n", "Cluster",
250 (*osb->osb_cluster_stack == '\0' ?
251 "o2cb" : osb->osb_cluster_stack),
252 cconn->cc_namelen, cconn->cc_name,
253 cconn->cc_version.pv_major,
254 cconn->cc_version.pv_minor);
257 spin_lock_irqsave(&osb->dc_task_lock, flags);
258 out += scnprintf(buf + out, len - out,
259 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
260 "WorkSeq: %lu\n", "DownCnvt",
261 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
262 osb->blocked_lock_count, osb->dc_wake_sequence,
263 osb->dc_work_sequence);
264 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
266 spin_lock(&osb->osb_lock);
267 out += scnprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
269 (osb->recovery_thread_task ?
270 task_pid_nr(osb->recovery_thread_task) : -1));
271 if (rm->rm_used == 0)
272 out += scnprintf(buf + out, len - out, " None\n");
274 for (i = 0; i < rm->rm_used; i++)
275 out += scnprintf(buf + out, len - out, " %d",
277 out += scnprintf(buf + out, len - out, "\n");
279 spin_unlock(&osb->osb_lock);
281 out += scnprintf(buf + out, len - out,
282 "%10s => Pid: %d Interval: %lu\n", "Commit",
283 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
284 osb->osb_commit_interval);
286 out += scnprintf(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 += scnprintf(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 += scnprintf(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 += scnprintf(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 += scnprintf(buf + out, len - out, "OrphanScan => ");
320 out += scnprintf(buf + out, len - out, "Local: %u Global: %u ",
321 os->os_count, os->os_seqno);
322 out += scnprintf(buf + out, len - out, " Last Scan: ");
323 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
324 out += scnprintf(buf + out, len - out, "Disabled\n");
326 out += scnprintf(buf + out, len - out, "%lu seconds ago\n",
327 (unsigned long)(ktime_get_seconds() - os->os_scantime));
329 out += scnprintf(buf + out, len - out, "%10s => %3s %10s\n",
330 "Slots", "Num", "RecoGen");
331 for (i = 0; i < osb->max_slots; ++i) {
332 out += scnprintf(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(osb->journal->j_journal,
415 jbd2_log_wait_commit(osb->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;
440 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
442 status = PTR_ERR(new);
446 osb->root_inode = new;
448 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
450 status = PTR_ERR(new);
454 osb->sys_root_inode = new;
456 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
457 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
458 if (!ocfs2_need_system_inode(osb, i))
460 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
462 ocfs2_release_system_inodes(osb);
463 status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL;
465 mlog(ML_ERROR, "Unable to load system inode %d, "
466 "possibly corrupt fs?", i);
469 // the array now has one ref, so drop this one
479 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
481 struct inode *new = NULL;
485 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
486 i < NUM_SYSTEM_INODES;
488 if (!ocfs2_need_system_inode(osb, i))
490 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
492 ocfs2_release_system_inodes(osb);
493 status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL;
494 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
495 status, i, osb->slot_num);
498 /* the array now has one ref, so drop this one */
508 static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
513 for (i = 0; i < NUM_GLOBAL_SYSTEM_INODES; i++) {
514 inode = osb->global_system_inodes[i];
517 osb->global_system_inodes[i] = NULL;
521 inode = osb->sys_root_inode;
524 osb->sys_root_inode = NULL;
527 inode = osb->root_inode;
530 osb->root_inode = NULL;
533 if (!osb->local_system_inodes)
536 for (i = 0; i < NUM_LOCAL_SYSTEM_INODES * osb->max_slots; i++) {
537 if (osb->local_system_inodes[i]) {
538 iput(osb->local_system_inodes[i]);
539 osb->local_system_inodes[i] = NULL;
543 kfree(osb->local_system_inodes);
544 osb->local_system_inodes = NULL;
547 /* We're allocating fs objects, use GFP_NOFS */
548 static struct inode *ocfs2_alloc_inode(struct super_block *sb)
550 struct ocfs2_inode_info *oi;
552 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
557 oi->i_datasync_tid = 0;
558 memset(&oi->i_dquot, 0, sizeof(oi->i_dquot));
560 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
561 return &oi->vfs_inode;
564 static void ocfs2_free_inode(struct inode *inode)
566 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
569 static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
572 unsigned int bytes = 1 << cbits;
573 unsigned int trim = bytes;
574 unsigned int bitshift = 32;
577 * i_size and all block offsets in ocfs2 are always 64 bits
578 * wide. i_clusters is 32 bits, in cluster-sized units. So on
579 * 64 bit platforms, cluster size will be the limiting factor.
582 #if BITS_PER_LONG == 32
583 BUILD_BUG_ON(sizeof(sector_t) != 8);
585 * We might be limited by page cache size.
587 if (bytes > PAGE_SIZE) {
591 * Shift by 31 here so that we don't get larger than
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);
616 if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
617 !ocfs2_check_set_options(sb, &parsed_options)) {
622 tmp = OCFS2_MOUNT_NOCLUSTER;
623 if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
625 mlog(ML_ERROR, "Cannot change nocluster option on remount\n");
629 tmp = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL |
631 if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
633 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
637 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
638 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
640 mlog(ML_ERROR, "Cannot change data mode on remount\n");
644 /* Probably don't want this on remount; it might
645 * mess with other nodes */
646 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
647 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
649 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
653 /* We're going to/from readonly mode. */
654 if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) {
655 /* Disable quota accounting before remounting RO */
656 if (*flags & SB_RDONLY) {
657 ret = ocfs2_susp_quotas(osb, 0);
661 /* Lock here so the check of HARD_RO and the potential
662 * setting of SOFT_RO is atomic. */
663 spin_lock(&osb->osb_lock);
664 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
665 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
670 if (*flags & SB_RDONLY) {
671 sb->s_flags |= SB_RDONLY;
672 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
674 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
675 mlog(ML_ERROR, "Cannot remount RDWR "
676 "filesystem due to previous errors.\n");
680 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
681 if (incompat_features) {
682 mlog(ML_ERROR, "Cannot remount RDWR because "
683 "of unsupported optional features "
684 "(%x).\n", incompat_features);
688 sb->s_flags &= ~SB_RDONLY;
689 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
691 trace_ocfs2_remount(sb->s_flags, osb->osb_flags, *flags);
693 spin_unlock(&osb->osb_lock);
694 /* Enable quota accounting after remounting RW */
695 if (!ret && !(*flags & SB_RDONLY)) {
696 if (sb_any_quota_suspended(sb))
697 ret = ocfs2_susp_quotas(osb, 1);
699 ret = ocfs2_enable_quotas(osb);
701 /* Return back changes... */
702 spin_lock(&osb->osb_lock);
703 sb->s_flags |= SB_RDONLY;
704 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
705 spin_unlock(&osb->osb_lock);
712 /* Only save off the new mount options in case of a successful
714 osb->s_mount_opt = parsed_options.mount_opt;
715 osb->s_atime_quantum = parsed_options.atime_quantum;
716 osb->preferred_slot = parsed_options.slot;
717 if (parsed_options.commit_interval)
718 osb->osb_commit_interval = parsed_options.commit_interval;
720 if (!ocfs2_is_hard_readonly(osb))
721 ocfs2_set_journal_params(osb);
723 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
724 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
731 static int ocfs2_sb_probe(struct super_block *sb,
732 struct buffer_head **bh,
734 struct ocfs2_blockcheck_stats *stats)
737 struct ocfs1_vol_disk_hdr *hdr;
738 struct ocfs2_dinode *di;
744 *sector_size = bdev_logical_block_size(sb->s_bdev);
745 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
746 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
747 *sector_size, OCFS2_MAX_BLOCKSIZE);
752 /* Can this really happen? */
753 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
754 *sector_size = OCFS2_MIN_BLOCKSIZE;
756 /* check block zero for old format */
757 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
762 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
763 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
764 mlog(ML_ERROR, "incompatible version: %u.%u\n",
765 hdr->major_version, hdr->minor_version);
768 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
769 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
770 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
777 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
778 "upgraded before mounting with ocfs v2\n");
783 * Now check at magic offset for 512, 1024, 2048, 4096
784 * blocksizes. 4096 is the maximum blocksize because it is
785 * the minimum clustersize.
788 for (blksize = *sector_size;
789 blksize <= OCFS2_MAX_BLOCKSIZE;
791 tmpstat = ocfs2_get_sector(sb, bh,
792 OCFS2_SUPER_BLOCK_BLKNO,
799 di = (struct ocfs2_dinode *) (*bh)->b_data;
800 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
801 spin_lock_init(&stats->b_lock);
802 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
807 if (tmpstat != -EAGAIN) {
817 static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
819 u32 hb_enabled = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL;
821 if (osb->s_mount_opt & hb_enabled) {
822 if (ocfs2_mount_local(osb)) {
823 mlog(ML_ERROR, "Cannot heartbeat on a locally "
824 "mounted device.\n");
827 if (ocfs2_userspace_stack(osb)) {
828 mlog(ML_ERROR, "Userspace stack expected, but "
829 "o2cb heartbeat arguments passed to mount\n");
832 if (((osb->s_mount_opt & OCFS2_MOUNT_HB_GLOBAL) &&
833 !ocfs2_cluster_o2cb_global_heartbeat(osb)) ||
834 ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) &&
835 ocfs2_cluster_o2cb_global_heartbeat(osb))) {
836 mlog(ML_ERROR, "Mismatching o2cb heartbeat modes\n");
841 if (!(osb->s_mount_opt & hb_enabled)) {
842 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
843 !ocfs2_userspace_stack(osb)) {
844 mlog(ML_ERROR, "Heartbeat has to be started to mount "
845 "a read-write clustered device.\n");
854 * If we're using a userspace stack, mount should have passed
855 * a name that matches the disk. If not, mount should not
856 * have passed a stack.
858 static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
859 struct mount_options *mopt)
861 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
863 "cluster stack passed to mount, but this filesystem "
864 "does not support it\n");
868 if (ocfs2_userspace_stack(osb) &&
869 !(osb->s_mount_opt & OCFS2_MOUNT_NOCLUSTER) &&
870 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
871 OCFS2_STACK_LABEL_LEN)) {
873 "cluster stack passed to mount (\"%s\") does not "
874 "match the filesystem (\"%s\")\n",
876 osb->osb_cluster_stack);
883 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
886 struct super_block *sb = osb->sb;
887 unsigned int feature[OCFS2_MAXQUOTAS] = {
888 OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
889 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
892 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
893 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
896 status = dquot_resume(sb, type);
898 struct ocfs2_mem_dqinfo *oinfo;
900 /* Cancel periodic syncing before suspending */
901 oinfo = sb_dqinfo(sb, type)->dqi_priv;
902 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
903 status = dquot_suspend(sb, type);
909 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
910 "remount (error = %d).\n", status);
914 static int ocfs2_enable_quotas(struct ocfs2_super *osb)
916 struct inode *inode[OCFS2_MAXQUOTAS] = { NULL, NULL };
917 struct super_block *sb = osb->sb;
918 unsigned int feature[OCFS2_MAXQUOTAS] = {
919 OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
920 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
921 unsigned int ino[OCFS2_MAXQUOTAS] = {
922 LOCAL_USER_QUOTA_SYSTEM_INODE,
923 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
927 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
928 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
929 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
931 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
937 status = dquot_load_quota_inode(inode[type], type, QFMT_OCFS2,
938 DQUOT_USAGE_ENABLED);
943 for (type = 0; type < OCFS2_MAXQUOTAS; type++)
947 ocfs2_disable_quotas(osb);
948 for (type = 0; type < OCFS2_MAXQUOTAS; type++)
954 static void ocfs2_disable_quotas(struct ocfs2_super *osb)
958 struct super_block *sb = osb->sb;
959 struct ocfs2_mem_dqinfo *oinfo;
961 /* We mostly ignore errors in this function because there's not much
962 * we can do when we see them */
963 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
964 if (!sb_has_quota_loaded(sb, type))
966 oinfo = sb_dqinfo(sb, type)->dqi_priv;
967 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
968 inode = igrab(sb->s_dquot.files[type]);
969 /* Turn off quotas. This will remove all dquot structures from
970 * memory and so they will be automatically synced to global
972 dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
973 DQUOT_LIMITS_ENABLED);
978 static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
981 int status, sector_size;
982 struct mount_options parsed_options;
983 struct inode *inode = NULL;
984 struct ocfs2_super *osb = NULL;
985 struct buffer_head *bh = NULL;
987 struct ocfs2_blockcheck_stats stats;
989 trace_ocfs2_fill_super(sb, data, silent);
991 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
993 goto read_super_error;
996 /* probe for superblock */
997 status = ocfs2_sb_probe(sb, &bh, §or_size, &stats);
999 mlog(ML_ERROR, "superblock probe failed!\n");
1000 goto read_super_error;
1003 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
1007 goto read_super_error;
1012 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1014 goto read_super_error;
1016 osb->s_mount_opt = parsed_options.mount_opt;
1017 osb->s_atime_quantum = parsed_options.atime_quantum;
1018 osb->preferred_slot = parsed_options.slot;
1019 osb->osb_commit_interval = parsed_options.commit_interval;
1021 ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
1022 osb->osb_resv_level = parsed_options.resv_level;
1023 osb->osb_dir_resv_level = parsed_options.resv_level;
1024 if (parsed_options.dir_resv_level == -1)
1025 osb->osb_dir_resv_level = parsed_options.resv_level;
1027 osb->osb_dir_resv_level = parsed_options.dir_resv_level;
1029 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1031 goto read_super_error;
1033 sb->s_magic = OCFS2_SUPER_MAGIC;
1035 sb->s_flags = (sb->s_flags & ~(SB_POSIXACL | SB_NOSEC)) |
1036 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0);
1038 /* Hard readonly mode only if: bdev_read_only, SB_RDONLY,
1040 if (bdev_read_only(sb->s_bdev)) {
1041 if (!sb_rdonly(sb)) {
1043 mlog(ML_ERROR, "Readonly device detected but readonly "
1044 "mount was not specified.\n");
1045 goto read_super_error;
1048 /* You should not be able to start a local heartbeat
1049 * on a readonly device. */
1050 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1052 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1054 goto read_super_error;
1057 status = ocfs2_check_journals_nolocks(osb);
1059 if (status == -EROFS)
1060 mlog(ML_ERROR, "Recovery required on readonly "
1061 "file system, but write access is "
1065 goto read_super_error;
1068 ocfs2_set_ro_flag(osb, 1);
1070 printk(KERN_NOTICE "ocfs2: Readonly device (%s) detected. "
1071 "Cluster services will not be used for this mount. "
1072 "Recovery will be skipped.\n", osb->dev_str);
1075 if (!ocfs2_is_hard_readonly(osb)) {
1077 ocfs2_set_ro_flag(osb, 0);
1080 status = ocfs2_verify_heartbeat(osb);
1083 goto read_super_error;
1086 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1087 ocfs2_debugfs_root);
1089 debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root,
1090 osb, &ocfs2_osb_debug_fops);
1092 if (ocfs2_meta_ecc(osb))
1093 ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats,
1094 osb->osb_debug_root);
1096 status = ocfs2_mount_volume(sb);
1098 goto read_super_error;
1100 if (osb->root_inode)
1101 inode = igrab(osb->root_inode);
1106 goto read_super_error;
1109 root = d_make_root(inode);
1113 goto read_super_error;
1118 ocfs2_complete_mount_recovery(osb);
1120 osb->osb_dev_kset = kset_create_and_add(sb->s_id, NULL,
1122 if (!osb->osb_dev_kset) {
1124 mlog(ML_ERROR, "Unable to create device kset %s.\n", sb->s_id);
1125 goto read_super_error;
1128 /* Create filecheck sysfs related directories/files at
1129 * /sys/fs/ocfs2/<devname>/filecheck */
1130 if (ocfs2_filecheck_create_sysfs(osb)) {
1132 mlog(ML_ERROR, "Unable to create filecheck sysfs directory at "
1133 "/sys/fs/ocfs2/%s/filecheck.\n", sb->s_id);
1134 goto read_super_error;
1137 if (ocfs2_mount_local(osb))
1138 snprintf(nodestr, sizeof(nodestr), "local");
1140 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1142 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
1143 "with %s data mode.\n",
1144 osb->dev_str, nodestr, osb->slot_num,
1145 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1148 if ((osb->s_mount_opt & OCFS2_MOUNT_NOCLUSTER) &&
1149 !(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT))
1150 printk(KERN_NOTICE "ocfs2: The shared device (%s) is mounted "
1151 "without cluster aware mode.\n", osb->dev_str);
1153 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1154 wake_up(&osb->osb_mount_event);
1156 /* Now we can initialize quotas because we can afford to wait
1157 * for cluster locks recovery now. That also means that truncation
1158 * log recovery can happen but that waits for proper quota setup */
1159 if (!sb_rdonly(sb)) {
1160 status = ocfs2_enable_quotas(osb);
1162 /* We have to err-out specially here because
1163 * s_root is already set */
1165 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1166 wake_up(&osb->osb_mount_event);
1171 ocfs2_complete_quota_recovery(osb);
1173 /* Now we wake up again for processes waiting for quotas */
1174 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1175 wake_up(&osb->osb_mount_event);
1177 /* Start this when the mount is almost sure of being successful */
1178 ocfs2_orphan_scan_start(osb);
1189 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1190 wake_up(&osb->osb_mount_event);
1191 ocfs2_dismount_volume(sb, 1);
1197 static struct dentry *ocfs2_mount(struct file_system_type *fs_type,
1199 const char *dev_name,
1202 return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
1205 static struct file_system_type ocfs2_fs_type = {
1206 .owner = THIS_MODULE,
1208 .mount = ocfs2_mount,
1209 .kill_sb = kill_block_super,
1210 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
1213 MODULE_ALIAS_FS("ocfs2");
1215 static int ocfs2_check_set_options(struct super_block *sb,
1216 struct mount_options *options)
1218 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1219 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1220 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1221 mlog(ML_ERROR, "User quotas were requested, but this "
1222 "filesystem does not have the feature enabled.\n");
1225 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1226 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1227 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1228 mlog(ML_ERROR, "Group quotas were requested, but this "
1229 "filesystem does not have the feature enabled.\n");
1232 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1233 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1234 mlog(ML_ERROR, "ACL support requested but extended attributes "
1235 "feature is not enabled\n");
1238 /* No ACL setting specified? Use XATTR feature... */
1239 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1240 OCFS2_MOUNT_NO_POSIX_ACL))) {
1241 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1242 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1244 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1249 static int ocfs2_parse_options(struct super_block *sb,
1251 struct mount_options *mopt,
1254 int status, user_stack = 0;
1258 substring_t args[MAX_OPT_ARGS];
1260 trace_ocfs2_parse_options(is_remount, options ? options : "(none)");
1262 mopt->commit_interval = 0;
1263 mopt->mount_opt = OCFS2_MOUNT_NOINTR;
1264 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1265 mopt->slot = OCFS2_INVALID_SLOT;
1266 mopt->localalloc_opt = -1;
1267 mopt->cluster_stack[0] = '\0';
1268 mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
1269 mopt->dir_resv_level = -1;
1276 while ((p = strsep(&options, ",")) != NULL) {
1280 token = match_token(p, tokens, args);
1283 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
1286 mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
1289 mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
1292 if (match_int(&args[0], &option)) {
1297 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
1299 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
1302 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
1305 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
1308 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
1309 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
1310 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
1313 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
1314 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1315 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_ROFS;
1318 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
1319 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1320 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_CONT;
1322 case Opt_data_ordered:
1323 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
1325 case Opt_data_writeback:
1326 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
1328 case Opt_user_xattr:
1329 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1331 case Opt_nouser_xattr:
1332 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1334 case Opt_atime_quantum:
1335 if (match_int(&args[0], &option)) {
1340 mopt->atime_quantum = option;
1343 if (match_int(&args[0], &option)) {
1348 mopt->slot = (u16)option;
1351 if (match_int(&args[0], &option)) {
1358 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1359 mopt->commit_interval = HZ * option;
1361 case Opt_localalloc:
1362 if (match_int(&args[0], &option)) {
1367 mopt->localalloc_opt = option;
1369 case Opt_localflocks:
1371 * Changing this during remount could race
1372 * flock() requests, or "unbalance" existing
1373 * ones (e.g., a lock is taken in one mode but
1374 * dropped in the other). If users care enough
1375 * to flip locking modes during remount, we
1376 * could add a "local" flag to individual
1377 * flock structures for proper tracking of
1381 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1384 /* Check both that the option we were passed
1385 * is of the right length and that it is a proper
1386 * string of the right length.
1388 if (((args[0].to - args[0].from) !=
1389 OCFS2_STACK_LABEL_LEN) ||
1390 (strnlen(args[0].from,
1391 OCFS2_STACK_LABEL_LEN) !=
1392 OCFS2_STACK_LABEL_LEN)) {
1394 "Invalid cluster_stack option\n");
1398 memcpy(mopt->cluster_stack, args[0].from,
1399 OCFS2_STACK_LABEL_LEN);
1400 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1402 * Open code the memcmp here as we don't have
1404 * ocfs2_userspace_stack().
1406 if (memcmp(mopt->cluster_stack,
1407 OCFS2_CLASSIC_CLUSTER_STACK,
1408 OCFS2_STACK_LABEL_LEN))
1412 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1415 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1418 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1420 case Opt_coherency_buffered:
1421 mopt->mount_opt |= OCFS2_MOUNT_COHERENCY_BUFFERED;
1423 case Opt_coherency_full:
1424 mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED;
1427 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1428 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
1431 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1432 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1434 case Opt_resv_level:
1437 if (match_int(&args[0], &option)) {
1441 if (option >= OCFS2_MIN_RESV_LEVEL &&
1442 option < OCFS2_MAX_RESV_LEVEL)
1443 mopt->resv_level = option;
1445 case Opt_dir_resv_level:
1448 if (match_int(&args[0], &option)) {
1452 if (option >= OCFS2_MIN_RESV_LEVEL &&
1453 option < OCFS2_MAX_RESV_LEVEL)
1454 mopt->dir_resv_level = option;
1456 case Opt_journal_async_commit:
1457 mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
1460 mopt->mount_opt |= OCFS2_MOUNT_NOCLUSTER;
1464 "Unrecognized mount option \"%s\" "
1465 "or missing value\n", p);
1471 if (user_stack == 0) {
1472 /* Ensure only one heartbeat mode */
1473 tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL |
1474 OCFS2_MOUNT_HB_GLOBAL |
1475 OCFS2_MOUNT_HB_NONE);
1476 if (hweight32(tmp) != 1) {
1477 mlog(ML_ERROR, "Invalid heartbeat mount options\n");
1489 static int ocfs2_show_options(struct seq_file *s, struct dentry *root)
1491 struct ocfs2_super *osb = OCFS2_SB(root->d_sb);
1492 unsigned long opts = osb->s_mount_opt;
1493 unsigned int local_alloc_megs;
1495 if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
1496 seq_printf(s, ",_netdev");
1497 if (opts & OCFS2_MOUNT_HB_LOCAL)
1498 seq_printf(s, ",%s", OCFS2_HB_LOCAL);
1500 seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
1502 seq_printf(s, ",%s", OCFS2_HB_NONE);
1504 if (opts & OCFS2_MOUNT_NOINTR)
1505 seq_printf(s, ",nointr");
1507 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1508 seq_printf(s, ",data=writeback");
1510 seq_printf(s, ",data=ordered");
1512 if (opts & OCFS2_MOUNT_BARRIER)
1513 seq_printf(s, ",barrier=1");
1515 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1516 seq_printf(s, ",errors=panic");
1517 else if (opts & OCFS2_MOUNT_ERRORS_CONT)
1518 seq_printf(s, ",errors=continue");
1520 seq_printf(s, ",errors=remount-ro");
1522 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1523 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
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_show_option_n(s, "cluster_stack", osb->osb_cluster_stack,
1540 OCFS2_STACK_LABEL_LEN);
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_COHERENCY_BUFFERED)
1547 seq_printf(s, ",coherency=buffered");
1549 seq_printf(s, ",coherency=full");
1551 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1552 seq_printf(s, ",nouser_xattr");
1554 seq_printf(s, ",user_xattr");
1556 if (opts & OCFS2_MOUNT_INODE64)
1557 seq_printf(s, ",inode64");
1559 if (opts & OCFS2_MOUNT_POSIX_ACL)
1560 seq_printf(s, ",acl");
1562 seq_printf(s, ",noacl");
1564 if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
1565 seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
1567 if (osb->osb_dir_resv_level != osb->osb_resv_level)
1568 seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
1570 if (opts & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
1571 seq_printf(s, ",journal_async_commit");
1573 if (opts & OCFS2_MOUNT_NOCLUSTER)
1574 seq_printf(s, ",nocluster");
1579 static int __init ocfs2_init(void)
1583 status = init_ocfs2_uptodate_cache();
1587 status = ocfs2_initialize_mem_caches();
1591 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1593 ocfs2_set_locking_protocol();
1595 status = register_quota_format(&ocfs2_quota_format);
1598 status = register_filesystem(&ocfs2_fs_type);
1602 unregister_quota_format(&ocfs2_quota_format);
1604 debugfs_remove(ocfs2_debugfs_root);
1605 ocfs2_free_mem_caches();
1607 exit_ocfs2_uptodate_cache();
1613 static void __exit ocfs2_exit(void)
1615 unregister_quota_format(&ocfs2_quota_format);
1617 debugfs_remove(ocfs2_debugfs_root);
1619 ocfs2_free_mem_caches();
1621 unregister_filesystem(&ocfs2_fs_type);
1623 exit_ocfs2_uptodate_cache();
1626 static void ocfs2_put_super(struct super_block *sb)
1628 trace_ocfs2_put_super(sb);
1630 ocfs2_sync_blockdev(sb);
1631 ocfs2_dismount_volume(sb, 0);
1634 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1636 struct ocfs2_super *osb;
1637 u32 numbits, freebits;
1639 struct ocfs2_dinode *bm_lock;
1640 struct buffer_head *bh = NULL;
1641 struct inode *inode = NULL;
1643 trace_ocfs2_statfs(dentry->d_sb, buf);
1645 osb = OCFS2_SB(dentry->d_sb);
1647 inode = ocfs2_get_system_file_inode(osb,
1648 GLOBAL_BITMAP_SYSTEM_INODE,
1649 OCFS2_INVALID_SLOT);
1651 mlog(ML_ERROR, "failed to get bitmap inode\n");
1656 status = ocfs2_inode_lock(inode, &bh, 0);
1662 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1664 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1665 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1667 buf->f_type = OCFS2_SUPER_MAGIC;
1668 buf->f_bsize = dentry->d_sb->s_blocksize;
1669 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1670 buf->f_blocks = ((sector_t) numbits) *
1671 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1672 buf->f_bfree = ((sector_t) freebits) *
1673 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1674 buf->f_bavail = buf->f_bfree;
1675 buf->f_files = numbits;
1676 buf->f_ffree = freebits;
1677 buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1679 buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1680 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
1684 ocfs2_inode_unlock(inode, 0);
1695 static void ocfs2_inode_init_once(void *data)
1697 struct ocfs2_inode_info *oi = data;
1700 oi->ip_open_count = 0;
1701 spin_lock_init(&oi->ip_lock);
1702 ocfs2_extent_map_init(&oi->vfs_inode);
1703 INIT_LIST_HEAD(&oi->ip_io_markers);
1704 INIT_LIST_HEAD(&oi->ip_unwritten_list);
1705 oi->ip_dir_start_lookup = 0;
1706 init_rwsem(&oi->ip_alloc_sem);
1707 init_rwsem(&oi->ip_xattr_sem);
1708 mutex_init(&oi->ip_io_mutex);
1710 oi->ip_blkno = 0ULL;
1711 oi->ip_clusters = 0;
1712 oi->ip_next_orphan = NULL;
1714 ocfs2_resv_init_once(&oi->ip_la_data_resv);
1716 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
1717 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
1718 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
1720 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
1721 &ocfs2_inode_caching_ops);
1723 inode_init_once(&oi->vfs_inode);
1726 static int ocfs2_initialize_mem_caches(void)
1728 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
1729 sizeof(struct ocfs2_inode_info),
1731 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1732 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
1733 ocfs2_inode_init_once);
1734 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1735 sizeof(struct ocfs2_dquot),
1737 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1740 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1741 sizeof(struct ocfs2_quota_chunk),
1743 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1745 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1746 !ocfs2_qf_chunk_cachep) {
1747 kmem_cache_destroy(ocfs2_inode_cachep);
1748 kmem_cache_destroy(ocfs2_dquot_cachep);
1749 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1756 static void ocfs2_free_mem_caches(void)
1759 * Make sure all delayed rcu free inodes are flushed before we
1763 kmem_cache_destroy(ocfs2_inode_cachep);
1764 ocfs2_inode_cachep = NULL;
1766 kmem_cache_destroy(ocfs2_dquot_cachep);
1767 ocfs2_dquot_cachep = NULL;
1769 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1770 ocfs2_qf_chunk_cachep = NULL;
1773 static int ocfs2_get_sector(struct super_block *sb,
1774 struct buffer_head **bh,
1778 if (!sb_set_blocksize(sb, sect_size)) {
1779 mlog(ML_ERROR, "unable to set blocksize\n");
1783 *bh = sb_getblk(sb, block);
1785 mlog_errno(-ENOMEM);
1789 if (!buffer_dirty(*bh))
1790 clear_buffer_uptodate(*bh);
1792 ll_rw_block(REQ_OP_READ, 0, 1, bh);
1793 wait_on_buffer(*bh);
1794 if (!buffer_uptodate(*bh)) {
1804 static int ocfs2_mount_volume(struct super_block *sb)
1807 int unlock_super = 0;
1808 struct ocfs2_super *osb = OCFS2_SB(sb);
1810 if (ocfs2_is_hard_readonly(osb))
1813 mutex_init(&osb->obs_trim_fs_mutex);
1815 status = ocfs2_dlm_init(osb);
1818 if (status == -EBADR && ocfs2_userspace_stack(osb))
1819 mlog(ML_ERROR, "couldn't mount because cluster name on"
1820 " disk does not match the running cluster name.\n");
1824 status = ocfs2_super_lock(osb, 1);
1831 /* This will load up the node map and add ourselves to it. */
1832 status = ocfs2_find_slot(osb);
1838 /* load all node-local system inodes */
1839 status = ocfs2_init_local_system_inodes(osb);
1845 status = ocfs2_check_volume(osb);
1851 status = ocfs2_truncate_log_init(osb);
1857 ocfs2_super_unlock(osb, 1);
1862 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1864 int tmp, hangup_needed = 0;
1865 struct ocfs2_super *osb = NULL;
1868 trace_ocfs2_dismount_volume(sb);
1874 /* Remove file check sysfs related directores/files,
1875 * and wait for the pending file check operations */
1876 ocfs2_filecheck_remove_sysfs(osb);
1878 kset_unregister(osb->osb_dev_kset);
1880 /* Orphan scan should be stopped as early as possible */
1881 ocfs2_orphan_scan_stop(osb);
1883 ocfs2_disable_quotas(osb);
1885 /* All dquots should be freed by now */
1886 WARN_ON(!llist_empty(&osb->dquot_drop_list));
1887 /* Wait for worker to be done with the work structure in osb */
1888 cancel_work_sync(&osb->dquot_drop_work);
1890 ocfs2_shutdown_local_alloc(osb);
1892 ocfs2_truncate_log_shutdown(osb);
1894 /* This will disable recovery and flush any recovery work. */
1895 ocfs2_recovery_exit(osb);
1897 ocfs2_journal_shutdown(osb);
1899 ocfs2_sync_blockdev(sb);
1901 ocfs2_purge_refcount_trees(osb);
1903 /* No cluster connection means we've failed during mount, so skip
1904 * all the steps which depended on that to complete. */
1906 tmp = ocfs2_super_lock(osb, 1);
1913 if (osb->slot_num != OCFS2_INVALID_SLOT)
1914 ocfs2_put_slot(osb);
1917 ocfs2_super_unlock(osb, 1);
1919 ocfs2_release_system_inodes(osb);
1922 * If we're dismounting due to mount error, mount.ocfs2 will clean
1923 * up heartbeat. If we're a local mount, there is no heartbeat.
1924 * If we failed before we got a uuid_str yet, we can't stop
1925 * heartbeat. Otherwise, do it.
1927 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str &&
1928 !ocfs2_is_hard_readonly(osb))
1932 ocfs2_dlm_shutdown(osb, hangup_needed);
1934 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
1935 debugfs_remove_recursive(osb->osb_debug_root);
1938 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
1940 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1942 if (ocfs2_mount_local(osb))
1943 snprintf(nodestr, sizeof(nodestr), "local");
1945 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1947 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1948 osb->dev_str, nodestr);
1950 ocfs2_delete_osb(osb);
1953 sb->s_fs_info = NULL;
1956 static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1957 unsigned uuid_bytes)
1962 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1964 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
1965 if (osb->uuid_str == NULL)
1968 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1969 /* print with null */
1970 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1971 if (ret != 2) /* drop super cleans up */
1973 /* then only advance past the last char */
1980 /* Make sure entire volume is addressable by our journal. Requires
1981 osb_clusters_at_boot to be valid and for the journal to have been
1982 initialized by ocfs2_journal_init(). */
1983 static int ocfs2_journal_addressable(struct ocfs2_super *osb)
1987 ocfs2_clusters_to_blocks(osb->sb,
1988 osb->osb_clusters_at_boot) - 1;
1990 /* 32-bit block number is always OK. */
1991 if (max_block <= (u32)~0ULL)
1994 /* Volume is "huge", so see if our journal is new enough to
1996 if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb,
1997 OCFS2_FEATURE_COMPAT_JBD2_SB) &&
1998 jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0,
1999 JBD2_FEATURE_INCOMPAT_64BIT))) {
2000 mlog(ML_ERROR, "The journal cannot address the entire volume. "
2001 "Enable the 'block64' journal option with tunefs.ocfs2");
2010 static int ocfs2_initialize_super(struct super_block *sb,
2011 struct buffer_head *bh,
2013 struct ocfs2_blockcheck_stats *stats)
2016 int i, cbits, bbits;
2017 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
2018 struct inode *inode = NULL;
2019 struct ocfs2_journal *journal;
2020 struct ocfs2_super *osb;
2023 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
2030 sb->s_fs_info = osb;
2031 sb->s_op = &ocfs2_sops;
2032 sb->s_d_op = &ocfs2_dentry_ops;
2033 sb->s_export_op = &ocfs2_export_ops;
2034 sb->s_qcop = &dquot_quotactl_sysfile_ops;
2035 sb->dq_op = &ocfs2_quota_operations;
2036 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
2037 sb->s_xattr = ocfs2_xattr_handlers;
2038 sb->s_time_gran = 1;
2039 sb->s_flags |= SB_NOATIME;
2040 /* this is needed to support O_LARGEFILE */
2041 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2042 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
2043 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
2044 memcpy(&sb->s_uuid, di->id2.i_super.s_uuid,
2045 sizeof(di->id2.i_super.s_uuid));
2047 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
2049 for (i = 0; i < 3; i++)
2050 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
2051 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2054 osb->s_sectsize_bits = blksize_bits(sector_size);
2055 BUG_ON(!osb->s_sectsize_bits);
2057 spin_lock_init(&osb->dc_task_lock);
2058 init_waitqueue_head(&osb->dc_event);
2059 osb->dc_work_sequence = 0;
2060 osb->dc_wake_sequence = 0;
2061 INIT_LIST_HEAD(&osb->blocked_lock_list);
2062 osb->blocked_lock_count = 0;
2063 spin_lock_init(&osb->osb_lock);
2064 spin_lock_init(&osb->osb_xattr_lock);
2065 ocfs2_init_steal_slots(osb);
2067 mutex_init(&osb->system_file_mutex);
2069 atomic_set(&osb->alloc_stats.moves, 0);
2070 atomic_set(&osb->alloc_stats.local_data, 0);
2071 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2072 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2073 atomic_set(&osb->alloc_stats.bg_extends, 0);
2075 /* Copy the blockcheck stats from the superblock probe */
2076 osb->osb_ecc_stats = *stats;
2078 ocfs2_init_node_maps(osb);
2080 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2081 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2083 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2084 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2085 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2091 ocfs2_orphan_scan_init(osb);
2093 status = ocfs2_recovery_init(osb);
2095 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2100 init_waitqueue_head(&osb->checkpoint_event);
2102 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2104 osb->slot_num = OCFS2_INVALID_SLOT;
2106 osb->s_xattr_inline_size = le16_to_cpu(
2107 di->id2.i_super.s_xattr_inline_size);
2109 osb->local_alloc_state = OCFS2_LA_UNUSED;
2110 osb->local_alloc_bh = NULL;
2111 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
2113 init_waitqueue_head(&osb->osb_mount_event);
2115 status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
2121 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2122 if (!osb->vol_label) {
2123 mlog(ML_ERROR, "unable to alloc vol label\n");
2128 osb->slot_recovery_generations =
2129 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2131 if (!osb->slot_recovery_generations) {
2137 init_waitqueue_head(&osb->osb_wipe_event);
2138 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2139 sizeof(*osb->osb_orphan_wipes),
2141 if (!osb->osb_orphan_wipes) {
2147 osb->osb_rf_lock_tree = RB_ROOT;
2149 osb->s_feature_compat =
2150 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2151 osb->s_feature_ro_compat =
2152 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2153 osb->s_feature_incompat =
2154 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2156 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2157 mlog(ML_ERROR, "couldn't mount because of unsupported "
2158 "optional features (%x).\n", i);
2162 if (!sb_rdonly(osb->sb) && (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2163 mlog(ML_ERROR, "couldn't mount RDWR because of "
2164 "unsupported optional features (%x).\n", i);
2169 if (ocfs2_clusterinfo_valid(osb)) {
2170 osb->osb_stackflags =
2171 OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
2172 strlcpy(osb->osb_cluster_stack,
2173 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2174 OCFS2_STACK_LABEL_LEN + 1);
2175 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2177 "couldn't mount because of an invalid "
2178 "cluster stack label (%s) \n",
2179 osb->osb_cluster_stack);
2183 strlcpy(osb->osb_cluster_name,
2184 OCFS2_RAW_SB(di)->s_cluster_info.ci_cluster,
2185 OCFS2_CLUSTER_NAME_LEN + 1);
2187 /* The empty string is identical with classic tools that
2188 * don't know about s_cluster_info. */
2189 osb->osb_cluster_stack[0] = '\0';
2192 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2195 * This should be done in ocfs2_journal_init(), but unknown
2196 * ordering issues will cause the filesystem to crash.
2197 * If anyone wants to figure out what part of the code
2198 * refers to osb->journal before ocfs2_journal_init() is run,
2201 /* initialize our journal structure */
2203 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
2205 mlog(ML_ERROR, "unable to alloc journal\n");
2209 osb->journal = journal;
2210 journal->j_osb = osb;
2212 atomic_set(&journal->j_num_trans, 0);
2213 init_rwsem(&journal->j_trans_barrier);
2214 init_waitqueue_head(&journal->j_checkpointed);
2215 spin_lock_init(&journal->j_lock);
2216 journal->j_trans_id = (unsigned long) 1;
2217 INIT_LIST_HEAD(&journal->j_la_cleanups);
2218 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
2219 journal->j_state = OCFS2_JOURNAL_FREE;
2221 INIT_WORK(&osb->dquot_drop_work, ocfs2_drop_dquot_refs);
2222 init_llist_head(&osb->dquot_drop_list);
2224 /* get some pseudo constants for clustersize bits */
2225 osb->s_clustersize_bits =
2226 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2227 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2229 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2230 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2231 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2232 osb->s_clustersize);
2237 total_blocks = ocfs2_clusters_to_blocks(osb->sb,
2238 le32_to_cpu(di->i_clusters));
2240 status = generic_check_addressable(osb->sb->s_blocksize_bits,
2243 mlog(ML_ERROR, "Volume too large "
2244 "to mount safely on this system");
2249 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2250 sizeof(di->id2.i_super.s_uuid))) {
2251 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2256 strlcpy(osb->vol_label, di->id2.i_super.s_label,
2257 OCFS2_MAX_VOL_LABEL_LEN);
2258 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2259 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2260 osb->first_cluster_group_blkno =
2261 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2262 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
2263 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2264 trace_ocfs2_initialize_super(osb->vol_label, osb->uuid_str,
2265 (unsigned long long)osb->root_blkno,
2266 (unsigned long long)osb->system_dir_blkno,
2267 osb->s_clustersize_bits);
2269 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2270 if (!osb->osb_dlm_debug) {
2276 atomic_set(&osb->vol_state, VOLUME_INIT);
2278 /* load root, system_dir, and all global system inodes */
2279 status = ocfs2_init_global_system_inodes(osb);
2288 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2289 OCFS2_INVALID_SLOT);
2296 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
2297 osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
2300 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
2301 osb->s_feature_incompat) * 8;
2303 status = ocfs2_init_slot_info(osb);
2308 cleancache_init_shared_fs(sb);
2310 osb->ocfs2_wq = alloc_ordered_workqueue("ocfs2_wq", WQ_MEM_RECLAIM);
2311 if (!osb->ocfs2_wq) {
2321 * will return: -EAGAIN if it is ok to keep searching for superblocks
2322 * -EINVAL if there is a bad superblock
2325 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2326 struct buffer_head *bh,
2328 struct ocfs2_blockcheck_stats *stats)
2330 int status = -EAGAIN;
2332 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2333 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
2334 /* We have to do a raw check of the feature here */
2335 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2336 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2337 status = ocfs2_block_check_validate(bh->b_data,
2345 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2346 mlog(ML_ERROR, "found superblock with incorrect block "
2347 "size: found %u, should be %u\n",
2348 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2350 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2351 OCFS2_MAJOR_REV_LEVEL ||
2352 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2353 OCFS2_MINOR_REV_LEVEL) {
2354 mlog(ML_ERROR, "found superblock with bad version: "
2355 "found %u.%u, should be %u.%u\n",
2356 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2357 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2358 OCFS2_MAJOR_REV_LEVEL,
2359 OCFS2_MINOR_REV_LEVEL);
2360 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2361 mlog(ML_ERROR, "bad block number on superblock: "
2362 "found %llu, should be %llu\n",
2363 (unsigned long long)le64_to_cpu(di->i_blkno),
2364 (unsigned long long)bh->b_blocknr);
2365 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2366 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2367 mlog(ML_ERROR, "bad cluster size found: %u\n",
2368 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2369 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2370 mlog(ML_ERROR, "bad root_blkno: 0\n");
2371 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2372 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2373 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2375 "Superblock slots found greater than file system "
2376 "maximum: found %u, max %u\n",
2377 le16_to_cpu(di->id2.i_super.s_max_slots),
2386 if (status && status != -EAGAIN)
2391 static int ocfs2_check_volume(struct ocfs2_super *osb)
2396 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2400 /* Init our journal object. */
2401 status = ocfs2_journal_init(osb->journal, &dirty);
2403 mlog(ML_ERROR, "Could not initialize journal!\n");
2407 /* Now that journal has been initialized, check to make sure
2408 entire volume is addressable. */
2409 status = ocfs2_journal_addressable(osb);
2413 /* If the journal was unmounted cleanly then we don't want to
2414 * recover anything. Otherwise, journal_load will do that
2415 * dirty work for us :) */
2417 status = ocfs2_journal_wipe(osb->journal, 0);
2423 printk(KERN_NOTICE "ocfs2: File system on device (%s) was not "
2424 "unmounted cleanly, recovering it.\n", osb->dev_str);
2427 local = ocfs2_mount_local(osb);
2429 /* will play back anything left in the journal. */
2430 status = ocfs2_journal_load(osb->journal, local, dirty);
2432 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2436 if (osb->s_mount_opt & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
2437 jbd2_journal_set_features(osb->journal->j_journal,
2438 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2439 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2441 jbd2_journal_clear_features(osb->journal->j_journal,
2442 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2443 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2446 /* recover my local alloc if we didn't unmount cleanly. */
2447 status = ocfs2_begin_local_alloc_recovery(osb,
2454 /* we complete the recovery process after we've marked
2455 * ourselves as mounted. */
2458 status = ocfs2_load_local_alloc(osb);
2465 /* Recovery will be completed after we've mounted the
2466 * rest of the volume. */
2467 osb->local_alloc_copy = local_alloc;
2471 /* go through each journal, trylock it and if you get the
2472 * lock, and it's marked as dirty, set the bit in the recover
2473 * map and launch a recovery thread for it. */
2474 status = ocfs2_mark_dead_nodes(osb);
2480 status = ocfs2_compute_replay_slots(osb);
2493 * The routine gets called from dismount or close whenever a dismount on
2494 * volume is requested and the osb open count becomes 1.
2495 * It will remove the osb from the global list and also free up all the
2496 * initialized resources and fileobject.
2498 static void ocfs2_delete_osb(struct ocfs2_super *osb)
2500 /* This function assumes that the caller has the main osb resource */
2502 /* ocfs2_initializer_super have already created this workqueue */
2504 destroy_workqueue(osb->ocfs2_wq);
2506 ocfs2_free_slot_info(osb);
2508 kfree(osb->osb_orphan_wipes);
2509 kfree(osb->slot_recovery_generations);
2511 * This belongs in journal shutdown, but because we have to
2512 * allocate osb->journal at the start of ocfs2_initialize_osb(),
2515 kfree(osb->journal);
2516 kfree(osb->local_alloc_copy);
2517 kfree(osb->uuid_str);
2518 kfree(osb->vol_label);
2519 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2520 memset(osb, 0, sizeof(struct ocfs2_super));
2523 /* Depending on the mount option passed, perform one of the following:
2524 * Put OCFS2 into a readonly state (default)
2525 * Return EIO so that only the process errs
2526 * Fix the error as if fsck.ocfs2 -y
2529 static int ocfs2_handle_error(struct super_block *sb)
2531 struct ocfs2_super *osb = OCFS2_SB(sb);
2534 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2535 pr_crit("On-disk corruption discovered. "
2536 "Please run fsck.ocfs2 once the filesystem is unmounted.\n");
2538 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) {
2539 panic("OCFS2: (device %s): panic forced after error\n",
2541 } else if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_CONT) {
2542 pr_crit("OCFS2: Returning error to the calling process.\n");
2544 } else { /* default option */
2546 if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)))
2549 pr_crit("OCFS2: File system is now read-only.\n");
2550 sb->s_flags |= SB_RDONLY;
2551 ocfs2_set_ro_flag(osb, 0);
2557 int __ocfs2_error(struct super_block *sb, const char *function,
2558 const char *fmt, ...)
2560 struct va_format vaf;
2563 va_start(args, fmt);
2567 /* Not using mlog here because we want to show the actual
2568 * function the error came from. */
2569 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %pV",
2570 sb->s_id, function, &vaf);
2574 return ocfs2_handle_error(sb);
2577 /* Handle critical errors. This is intentionally more drastic than
2578 * ocfs2_handle_error, so we only use for things like journal errors,
2580 void __ocfs2_abort(struct super_block *sb, const char *function,
2581 const char *fmt, ...)
2583 struct va_format vaf;
2586 va_start(args, fmt);
2591 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %pV",
2592 sb->s_id, function, &vaf);
2596 /* We don't have the cluster support yet to go straight to
2597 * hard readonly in here. Until then, we want to keep
2598 * ocfs2_abort() so that we can at least mark critical
2601 * TODO: This should abort the journal and alert other nodes
2602 * that our slot needs recovery. */
2604 /* Force a panic(). This stinks, but it's better than letting
2605 * things continue without having a proper hard readonly
2607 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2608 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
2609 ocfs2_handle_error(sb);
2613 * Void signal blockers, because in-kernel sigprocmask() only fails
2614 * when SIG_* is wrong.
2616 void ocfs2_block_signals(sigset_t *oldset)
2621 sigfillset(&blocked);
2622 rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
2626 void ocfs2_unblock_signals(sigset_t *oldset)
2628 int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
2632 module_init(ocfs2_init);
2633 module_exit(ocfs2_exit);