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/signal.h>
30 #define CREATE_TRACE_POINTS
31 #include "ocfs2_trace.h"
33 #include <cluster/masklog.h>
37 /* this should be the only file to include a version 1 header */
38 #include "ocfs1_fs_compat.h"
42 #include "blockcheck.h"
45 #include "extent_map.h"
46 #include "heartbeat.h"
49 #include "localalloc.h"
57 #include "refcounttree.h"
60 #include "buffer_head_io.h"
61 #include "filecheck.h"
63 static struct kmem_cache *ocfs2_inode_cachep;
64 struct kmem_cache *ocfs2_dquot_cachep;
65 struct kmem_cache *ocfs2_qf_chunk_cachep;
67 static struct dentry *ocfs2_debugfs_root;
69 MODULE_AUTHOR("Oracle");
70 MODULE_LICENSE("GPL");
71 MODULE_DESCRIPTION("OCFS2 cluster file system");
75 unsigned long commit_interval;
76 unsigned long mount_opt;
77 unsigned int atime_quantum;
80 unsigned int resv_level;
82 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
85 static int ocfs2_parse_options(struct super_block *sb, char *options,
86 struct mount_options *mopt,
88 static int ocfs2_check_set_options(struct super_block *sb,
89 struct mount_options *options);
90 static int ocfs2_show_options(struct seq_file *s, struct dentry *root);
91 static void ocfs2_put_super(struct super_block *sb);
92 static int ocfs2_mount_volume(struct super_block *sb);
93 static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
94 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
95 static int ocfs2_initialize_mem_caches(void);
96 static void ocfs2_free_mem_caches(void);
97 static void ocfs2_delete_osb(struct ocfs2_super *osb);
99 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
101 static int ocfs2_sync_fs(struct super_block *sb, int wait);
103 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
104 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
105 static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
106 static int ocfs2_check_volume(struct ocfs2_super *osb);
107 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
108 struct buffer_head *bh,
110 struct ocfs2_blockcheck_stats *stats);
111 static int ocfs2_initialize_super(struct super_block *sb,
112 struct buffer_head *bh,
114 struct ocfs2_blockcheck_stats *stats);
115 static int ocfs2_get_sector(struct super_block *sb,
116 struct buffer_head **bh,
119 static struct inode *ocfs2_alloc_inode(struct super_block *sb);
120 static void ocfs2_free_inode(struct inode *inode);
121 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
122 static int ocfs2_enable_quotas(struct ocfs2_super *osb);
123 static void ocfs2_disable_quotas(struct ocfs2_super *osb);
125 static struct dquot **ocfs2_get_dquots(struct inode *inode)
127 return OCFS2_I(inode)->i_dquot;
130 static const struct super_operations ocfs2_sops = {
131 .statfs = ocfs2_statfs,
132 .alloc_inode = ocfs2_alloc_inode,
133 .free_inode = ocfs2_free_inode,
134 .drop_inode = ocfs2_drop_inode,
135 .evict_inode = ocfs2_evict_inode,
136 .sync_fs = ocfs2_sync_fs,
137 .put_super = ocfs2_put_super,
138 .remount_fs = ocfs2_remount,
139 .show_options = ocfs2_show_options,
140 .quota_read = ocfs2_quota_read,
141 .quota_write = ocfs2_quota_write,
142 .get_dquots = ocfs2_get_dquots,
169 Opt_coherency_buffered,
173 Opt_journal_async_commit,
179 static const match_table_t tokens = {
180 {Opt_barrier, "barrier=%u"},
181 {Opt_err_panic, "errors=panic"},
182 {Opt_err_ro, "errors=remount-ro"},
184 {Opt_nointr, "nointr"},
185 {Opt_hb_none, OCFS2_HB_NONE},
186 {Opt_hb_local, OCFS2_HB_LOCAL},
187 {Opt_hb_global, OCFS2_HB_GLOBAL},
188 {Opt_data_ordered, "data=ordered"},
189 {Opt_data_writeback, "data=writeback"},
190 {Opt_atime_quantum, "atime_quantum=%u"},
191 {Opt_slot, "preferred_slot=%u"},
192 {Opt_commit, "commit=%u"},
193 {Opt_localalloc, "localalloc=%d"},
194 {Opt_localflocks, "localflocks"},
195 {Opt_stack, "cluster_stack=%s"},
196 {Opt_user_xattr, "user_xattr"},
197 {Opt_nouser_xattr, "nouser_xattr"},
198 {Opt_inode64, "inode64"},
200 {Opt_noacl, "noacl"},
201 {Opt_usrquota, "usrquota"},
202 {Opt_grpquota, "grpquota"},
203 {Opt_coherency_buffered, "coherency=buffered"},
204 {Opt_coherency_full, "coherency=full"},
205 {Opt_resv_level, "resv_level=%u"},
206 {Opt_dir_resv_level, "dir_resv_level=%u"},
207 {Opt_journal_async_commit, "journal_async_commit"},
208 {Opt_err_cont, "errors=continue"},
209 {Opt_nocluster, "nocluster"},
213 #ifdef CONFIG_DEBUG_FS
214 static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
216 struct ocfs2_cluster_connection *cconn = osb->cconn;
217 struct ocfs2_recovery_map *rm = osb->recovery_map;
218 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
222 out += scnprintf(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 += scnprintf(buf + out, len - out,
228 "%10s => State: %d Flags: 0x%lX\n", "Volume",
229 atomic_read(&osb->vol_state), osb->osb_flags);
231 out += scnprintf(buf + out, len - out,
232 "%10s => Block: %lu Cluster: %d\n", "Sizes",
233 osb->sb->s_blocksize, osb->s_clustersize);
235 out += scnprintf(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 += scnprintf(buf + out, len - out,
242 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
243 osb->s_mount_opt, osb->s_atime_quantum);
246 out += scnprintf(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_irqsave(&osb->dc_task_lock, flags);
257 out += scnprintf(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_irqrestore(&osb->dc_task_lock, flags);
265 spin_lock(&osb->osb_lock);
266 out += scnprintf(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 += scnprintf(buf + out, len - out, " None\n");
273 for (i = 0; i < rm->rm_used; i++)
274 out += scnprintf(buf + out, len - out, " %d",
276 out += scnprintf(buf + out, len - out, "\n");
278 spin_unlock(&osb->osb_lock);
280 out += scnprintf(buf + out, len - out,
281 "%10s => Pid: %d Interval: %lu\n", "Commit",
282 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
283 osb->osb_commit_interval);
285 out += scnprintf(buf + out, len - out,
286 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
287 "Journal", osb->journal->j_state,
288 osb->journal->j_trans_id,
289 atomic_read(&osb->journal->j_num_trans));
291 out += scnprintf(buf + out, len - out,
292 "%10s => GlobalAllocs: %d LocalAllocs: %d "
293 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
295 atomic_read(&osb->alloc_stats.bitmap_data),
296 atomic_read(&osb->alloc_stats.local_data),
297 atomic_read(&osb->alloc_stats.bg_allocs),
298 atomic_read(&osb->alloc_stats.moves),
299 atomic_read(&osb->alloc_stats.bg_extends));
301 out += scnprintf(buf + out, len - out,
302 "%10s => State: %u Descriptor: %llu Size: %u bits "
303 "Default: %u bits\n",
304 "LocalAlloc", osb->local_alloc_state,
305 (unsigned long long)osb->la_last_gd,
306 osb->local_alloc_bits, osb->local_alloc_default_bits);
308 spin_lock(&osb->osb_lock);
309 out += scnprintf(buf + out, len - out,
310 "%10s => InodeSlot: %d StolenInodes: %d, "
311 "MetaSlot: %d StolenMeta: %d\n", "Steal",
312 osb->s_inode_steal_slot,
313 atomic_read(&osb->s_num_inodes_stolen),
314 osb->s_meta_steal_slot,
315 atomic_read(&osb->s_num_meta_stolen));
316 spin_unlock(&osb->osb_lock);
318 out += scnprintf(buf + out, len - out, "OrphanScan => ");
319 out += scnprintf(buf + out, len - out, "Local: %u Global: %u ",
320 os->os_count, os->os_seqno);
321 out += scnprintf(buf + out, len - out, " Last Scan: ");
322 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
323 out += scnprintf(buf + out, len - out, "Disabled\n");
325 out += scnprintf(buf + out, len - out, "%lu seconds ago\n",
326 (unsigned long)(ktime_get_seconds() - os->os_scantime));
328 out += scnprintf(buf + out, len - out, "%10s => %3s %10s\n",
329 "Slots", "Num", "RecoGen");
330 for (i = 0; i < osb->max_slots; ++i) {
331 out += scnprintf(buf + out, len - out,
332 "%10s %c %3d %10d\n",
334 (i == osb->slot_num ? '*' : ' '),
335 i, osb->slot_recovery_generations[i]);
341 static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
343 struct ocfs2_super *osb = inode->i_private;
346 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
350 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
352 file->private_data = buf;
359 static int ocfs2_debug_release(struct inode *inode, struct file *file)
361 kfree(file->private_data);
365 static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
366 size_t nbytes, loff_t *ppos)
368 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
369 i_size_read(file->f_mapping->host));
372 static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
376 static int ocfs2_debug_release(struct inode *inode, struct file *file)
380 static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
381 size_t nbytes, loff_t *ppos)
385 #endif /* CONFIG_DEBUG_FS */
387 static const struct file_operations ocfs2_osb_debug_fops = {
388 .open = ocfs2_osb_debug_open,
389 .release = ocfs2_debug_release,
390 .read = ocfs2_debug_read,
391 .llseek = generic_file_llseek,
394 static int ocfs2_sync_fs(struct super_block *sb, int wait)
398 struct ocfs2_super *osb = OCFS2_SB(sb);
400 if (ocfs2_is_hard_readonly(osb))
404 status = ocfs2_flush_truncate_log(osb);
408 ocfs2_schedule_truncate_log_flush(osb, 0);
411 if (jbd2_journal_start_commit(osb->journal->j_journal,
414 jbd2_log_wait_commit(osb->journal->j_journal,
420 static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
422 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
423 && (ino == USER_QUOTA_SYSTEM_INODE
424 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
426 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
427 && (ino == GROUP_QUOTA_SYSTEM_INODE
428 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
433 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
435 struct inode *new = NULL;
439 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
441 status = PTR_ERR(new);
445 osb->root_inode = new;
447 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
449 status = PTR_ERR(new);
453 osb->sys_root_inode = new;
455 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
456 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
457 if (!ocfs2_need_system_inode(osb, i))
459 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
461 ocfs2_release_system_inodes(osb);
462 status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL;
464 mlog(ML_ERROR, "Unable to load system inode %d, "
465 "possibly corrupt fs?", i);
468 // the array now has one ref, so drop this one
478 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
480 struct inode *new = NULL;
484 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
485 i < NUM_SYSTEM_INODES;
487 if (!ocfs2_need_system_inode(osb, i))
489 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
491 ocfs2_release_system_inodes(osb);
492 status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL;
493 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
494 status, i, osb->slot_num);
497 /* the array now has one ref, so drop this one */
507 static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
512 for (i = 0; i < NUM_GLOBAL_SYSTEM_INODES; i++) {
513 inode = osb->global_system_inodes[i];
516 osb->global_system_inodes[i] = NULL;
520 inode = osb->sys_root_inode;
523 osb->sys_root_inode = NULL;
526 inode = osb->root_inode;
529 osb->root_inode = NULL;
532 if (!osb->local_system_inodes)
535 for (i = 0; i < NUM_LOCAL_SYSTEM_INODES * osb->max_slots; i++) {
536 if (osb->local_system_inodes[i]) {
537 iput(osb->local_system_inodes[i]);
538 osb->local_system_inodes[i] = NULL;
542 kfree(osb->local_system_inodes);
543 osb->local_system_inodes = NULL;
546 /* We're allocating fs objects, use GFP_NOFS */
547 static struct inode *ocfs2_alloc_inode(struct super_block *sb)
549 struct ocfs2_inode_info *oi;
551 oi = alloc_inode_sb(sb, ocfs2_inode_cachep, GFP_NOFS);
556 oi->i_datasync_tid = 0;
557 memset(&oi->i_dquot, 0, sizeof(oi->i_dquot));
559 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
560 return &oi->vfs_inode;
563 static void ocfs2_free_inode(struct inode *inode)
565 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
568 static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
571 unsigned int bytes = 1 << cbits;
572 unsigned int trim = bytes;
573 unsigned int bitshift = 32;
576 * i_size and all block offsets in ocfs2 are always 64 bits
577 * wide. i_clusters is 32 bits, in cluster-sized units. So on
578 * 64 bit platforms, cluster size will be the limiting factor.
581 #if BITS_PER_LONG == 32
582 BUILD_BUG_ON(sizeof(sector_t) != 8);
584 * We might be limited by page cache size.
586 if (bytes > PAGE_SIZE) {
590 * Shift by 31 here so that we don't get larger than
598 * Trim by a whole cluster when we can actually approach the
599 * on-disk limits. Otherwise we can overflow i_clusters when
600 * an extent start is at the max offset.
602 return (((unsigned long long)bytes) << bitshift) - trim;
605 static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
607 int incompat_features;
609 struct mount_options parsed_options;
610 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 tmp = OCFS2_MOUNT_NOCLUSTER;
622 if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
624 mlog(ML_ERROR, "Cannot change nocluster option on remount\n");
628 tmp = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL |
630 if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
632 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
636 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
637 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
639 mlog(ML_ERROR, "Cannot change data mode on remount\n");
643 /* Probably don't want this on remount; it might
644 * mess with other nodes */
645 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
646 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
648 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
652 /* We're going to/from readonly mode. */
653 if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) {
654 /* Disable quota accounting before remounting RO */
655 if (*flags & SB_RDONLY) {
656 ret = ocfs2_susp_quotas(osb, 0);
660 /* Lock here so the check of HARD_RO and the potential
661 * setting of SOFT_RO is atomic. */
662 spin_lock(&osb->osb_lock);
663 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
664 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
669 if (*flags & SB_RDONLY) {
670 sb->s_flags |= SB_RDONLY;
671 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
673 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
674 mlog(ML_ERROR, "Cannot remount RDWR "
675 "filesystem due to previous errors.\n");
679 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
680 if (incompat_features) {
681 mlog(ML_ERROR, "Cannot remount RDWR because "
682 "of unsupported optional features "
683 "(%x).\n", incompat_features);
687 sb->s_flags &= ~SB_RDONLY;
688 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
690 trace_ocfs2_remount(sb->s_flags, osb->osb_flags, *flags);
692 spin_unlock(&osb->osb_lock);
693 /* Enable quota accounting after remounting RW */
694 if (!ret && !(*flags & SB_RDONLY)) {
695 if (sb_any_quota_suspended(sb))
696 ret = ocfs2_susp_quotas(osb, 1);
698 ret = ocfs2_enable_quotas(osb);
700 /* Return back changes... */
701 spin_lock(&osb->osb_lock);
702 sb->s_flags |= SB_RDONLY;
703 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
704 spin_unlock(&osb->osb_lock);
711 /* Only save off the new mount options in case of a successful
713 osb->s_mount_opt = parsed_options.mount_opt;
714 osb->s_atime_quantum = parsed_options.atime_quantum;
715 osb->preferred_slot = parsed_options.slot;
716 if (parsed_options.commit_interval)
717 osb->osb_commit_interval = parsed_options.commit_interval;
719 if (!ocfs2_is_hard_readonly(osb))
720 ocfs2_set_journal_params(osb);
722 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
723 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
730 static int ocfs2_sb_probe(struct super_block *sb,
731 struct buffer_head **bh,
733 struct ocfs2_blockcheck_stats *stats)
736 struct ocfs1_vol_disk_hdr *hdr;
737 struct ocfs2_dinode *di;
743 *sector_size = bdev_logical_block_size(sb->s_bdev);
744 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
745 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
746 *sector_size, OCFS2_MAX_BLOCKSIZE);
751 /* Can this really happen? */
752 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
753 *sector_size = OCFS2_MIN_BLOCKSIZE;
755 /* check block zero for old format */
756 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
761 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
762 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
763 mlog(ML_ERROR, "incompatible version: %u.%u\n",
764 hdr->major_version, hdr->minor_version);
767 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
768 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
769 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
776 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
777 "upgraded before mounting with ocfs v2\n");
782 * Now check at magic offset for 512, 1024, 2048, 4096
783 * blocksizes. 4096 is the maximum blocksize because it is
784 * the minimum clustersize.
787 for (blksize = *sector_size;
788 blksize <= OCFS2_MAX_BLOCKSIZE;
790 tmpstat = ocfs2_get_sector(sb, bh,
791 OCFS2_SUPER_BLOCK_BLKNO,
798 di = (struct ocfs2_dinode *) (*bh)->b_data;
799 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
800 spin_lock_init(&stats->b_lock);
801 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
806 if (tmpstat != -EAGAIN) {
816 static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
818 u32 hb_enabled = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL;
820 if (osb->s_mount_opt & hb_enabled) {
821 if (ocfs2_mount_local(osb)) {
822 mlog(ML_ERROR, "Cannot heartbeat on a locally "
823 "mounted device.\n");
826 if (ocfs2_userspace_stack(osb)) {
827 mlog(ML_ERROR, "Userspace stack expected, but "
828 "o2cb heartbeat arguments passed to mount\n");
831 if (((osb->s_mount_opt & OCFS2_MOUNT_HB_GLOBAL) &&
832 !ocfs2_cluster_o2cb_global_heartbeat(osb)) ||
833 ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) &&
834 ocfs2_cluster_o2cb_global_heartbeat(osb))) {
835 mlog(ML_ERROR, "Mismatching o2cb heartbeat modes\n");
840 if (!(osb->s_mount_opt & hb_enabled)) {
841 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
842 !ocfs2_userspace_stack(osb)) {
843 mlog(ML_ERROR, "Heartbeat has to be started to mount "
844 "a read-write clustered device.\n");
853 * If we're using a userspace stack, mount should have passed
854 * a name that matches the disk. If not, mount should not
855 * have passed a stack.
857 static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
858 struct mount_options *mopt)
860 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
862 "cluster stack passed to mount, but this filesystem "
863 "does not support it\n");
867 if (ocfs2_userspace_stack(osb) &&
868 !(osb->s_mount_opt & OCFS2_MOUNT_NOCLUSTER) &&
869 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
870 OCFS2_STACK_LABEL_LEN)) {
872 "cluster stack passed to mount (\"%s\") does not "
873 "match the filesystem (\"%s\")\n",
875 osb->osb_cluster_stack);
882 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
885 struct super_block *sb = osb->sb;
886 unsigned int feature[OCFS2_MAXQUOTAS] = {
887 OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
888 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
891 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
892 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
895 status = dquot_resume(sb, type);
897 struct ocfs2_mem_dqinfo *oinfo;
899 /* Cancel periodic syncing before suspending */
900 oinfo = sb_dqinfo(sb, type)->dqi_priv;
901 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
902 status = dquot_suspend(sb, type);
908 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
909 "remount (error = %d).\n", status);
913 static int ocfs2_enable_quotas(struct ocfs2_super *osb)
915 struct inode *inode[OCFS2_MAXQUOTAS] = { NULL, NULL };
916 struct super_block *sb = osb->sb;
917 unsigned int feature[OCFS2_MAXQUOTAS] = {
918 OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
919 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
920 unsigned int ino[OCFS2_MAXQUOTAS] = {
921 LOCAL_USER_QUOTA_SYSTEM_INODE,
922 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
926 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
927 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
928 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
930 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
936 status = dquot_load_quota_inode(inode[type], type, QFMT_OCFS2,
937 DQUOT_USAGE_ENABLED);
942 for (type = 0; type < OCFS2_MAXQUOTAS; type++)
946 ocfs2_disable_quotas(osb);
947 for (type = 0; type < OCFS2_MAXQUOTAS; type++)
953 static void ocfs2_disable_quotas(struct ocfs2_super *osb)
957 struct super_block *sb = osb->sb;
958 struct ocfs2_mem_dqinfo *oinfo;
960 /* We mostly ignore errors in this function because there's not much
961 * we can do when we see them */
962 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
963 if (!sb_has_quota_loaded(sb, type))
965 oinfo = sb_dqinfo(sb, type)->dqi_priv;
966 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
967 inode = igrab(sb->s_dquot.files[type]);
968 /* Turn off quotas. This will remove all dquot structures from
969 * memory and so they will be automatically synced to global
971 dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
972 DQUOT_LIMITS_ENABLED);
977 static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
980 int status, sector_size;
981 struct mount_options parsed_options;
982 struct inode *inode = NULL;
983 struct ocfs2_super *osb = NULL;
984 struct buffer_head *bh = NULL;
986 struct ocfs2_blockcheck_stats stats;
988 trace_ocfs2_fill_super(sb, data, silent);
990 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
992 goto read_super_error;
995 /* probe for superblock */
996 status = ocfs2_sb_probe(sb, &bh, §or_size, &stats);
998 mlog(ML_ERROR, "superblock probe failed!\n");
999 goto read_super_error;
1002 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
1006 goto read_super_error;
1011 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1013 goto read_super_error;
1015 osb->s_mount_opt = parsed_options.mount_opt;
1016 osb->s_atime_quantum = parsed_options.atime_quantum;
1017 osb->preferred_slot = parsed_options.slot;
1018 osb->osb_commit_interval = parsed_options.commit_interval;
1020 ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
1021 osb->osb_resv_level = parsed_options.resv_level;
1022 osb->osb_dir_resv_level = parsed_options.resv_level;
1023 if (parsed_options.dir_resv_level == -1)
1024 osb->osb_dir_resv_level = parsed_options.resv_level;
1026 osb->osb_dir_resv_level = parsed_options.dir_resv_level;
1028 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1030 goto read_super_error;
1032 sb->s_magic = OCFS2_SUPER_MAGIC;
1034 sb->s_flags = (sb->s_flags & ~(SB_POSIXACL | SB_NOSEC)) |
1035 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0);
1037 /* Hard readonly mode only if: bdev_read_only, SB_RDONLY,
1039 if (bdev_read_only(sb->s_bdev)) {
1040 if (!sb_rdonly(sb)) {
1042 mlog(ML_ERROR, "Readonly device detected but readonly "
1043 "mount was not specified.\n");
1044 goto read_super_error;
1047 /* You should not be able to start a local heartbeat
1048 * on a readonly device. */
1049 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1051 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1053 goto read_super_error;
1056 status = ocfs2_check_journals_nolocks(osb);
1058 if (status == -EROFS)
1059 mlog(ML_ERROR, "Recovery required on readonly "
1060 "file system, but write access is "
1064 goto read_super_error;
1067 ocfs2_set_ro_flag(osb, 1);
1069 printk(KERN_NOTICE "ocfs2: Readonly device (%s) detected. "
1070 "Cluster services will not be used for this mount. "
1071 "Recovery will be skipped.\n", osb->dev_str);
1074 if (!ocfs2_is_hard_readonly(osb)) {
1076 ocfs2_set_ro_flag(osb, 0);
1079 status = ocfs2_verify_heartbeat(osb);
1082 goto read_super_error;
1085 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1086 ocfs2_debugfs_root);
1088 debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root,
1089 osb, &ocfs2_osb_debug_fops);
1091 if (ocfs2_meta_ecc(osb))
1092 ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats,
1093 osb->osb_debug_root);
1095 status = ocfs2_mount_volume(sb);
1097 goto read_super_error;
1099 if (osb->root_inode)
1100 inode = igrab(osb->root_inode);
1105 goto read_super_error;
1108 osb->osb_dev_kset = kset_create_and_add(sb->s_id, NULL,
1110 if (!osb->osb_dev_kset) {
1112 mlog(ML_ERROR, "Unable to create device kset %s.\n", sb->s_id);
1113 goto read_super_error;
1116 /* Create filecheck sysfs related directories/files at
1117 * /sys/fs/ocfs2/<devname>/filecheck */
1118 if (ocfs2_filecheck_create_sysfs(osb)) {
1120 mlog(ML_ERROR, "Unable to create filecheck sysfs directory at "
1121 "/sys/fs/ocfs2/%s/filecheck.\n", sb->s_id);
1122 goto read_super_error;
1125 root = d_make_root(inode);
1129 goto read_super_error;
1134 ocfs2_complete_mount_recovery(osb);
1136 if (ocfs2_mount_local(osb))
1137 snprintf(nodestr, sizeof(nodestr), "local");
1139 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1141 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
1142 "with %s data mode.\n",
1143 osb->dev_str, nodestr, osb->slot_num,
1144 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1147 if ((osb->s_mount_opt & OCFS2_MOUNT_NOCLUSTER) &&
1148 !(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT))
1149 printk(KERN_NOTICE "ocfs2: The shared device (%s) is mounted "
1150 "without cluster aware mode.\n", osb->dev_str);
1152 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1153 wake_up(&osb->osb_mount_event);
1155 /* Now we can initialize quotas because we can afford to wait
1156 * for cluster locks recovery now. That also means that truncation
1157 * log recovery can happen but that waits for proper quota setup */
1158 if (!sb_rdonly(sb)) {
1159 status = ocfs2_enable_quotas(osb);
1161 /* We have to err-out specially here because
1162 * s_root is already set */
1164 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1165 wake_up(&osb->osb_mount_event);
1170 ocfs2_complete_quota_recovery(osb);
1172 /* Now we wake up again for processes waiting for quotas */
1173 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1174 wake_up(&osb->osb_mount_event);
1176 /* Start this when the mount is almost sure of being successful */
1177 ocfs2_orphan_scan_start(osb);
1188 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1189 wake_up(&osb->osb_mount_event);
1190 ocfs2_dismount_volume(sb, 1);
1196 static struct dentry *ocfs2_mount(struct file_system_type *fs_type,
1198 const char *dev_name,
1201 return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
1204 static struct file_system_type ocfs2_fs_type = {
1205 .owner = THIS_MODULE,
1207 .mount = ocfs2_mount,
1208 .kill_sb = kill_block_super,
1209 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
1212 MODULE_ALIAS_FS("ocfs2");
1214 static int ocfs2_check_set_options(struct super_block *sb,
1215 struct mount_options *options)
1217 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1218 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1219 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1220 mlog(ML_ERROR, "User quotas were requested, but this "
1221 "filesystem does not have the feature enabled.\n");
1224 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1225 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1226 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1227 mlog(ML_ERROR, "Group quotas were requested, but this "
1228 "filesystem does not have the feature enabled.\n");
1231 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1232 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1233 mlog(ML_ERROR, "ACL support requested but extended attributes "
1234 "feature is not enabled\n");
1237 /* No ACL setting specified? Use XATTR feature... */
1238 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1239 OCFS2_MOUNT_NO_POSIX_ACL))) {
1240 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1241 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1243 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1248 static int ocfs2_parse_options(struct super_block *sb,
1250 struct mount_options *mopt,
1253 int status, user_stack = 0;
1257 substring_t args[MAX_OPT_ARGS];
1259 trace_ocfs2_parse_options(is_remount, options ? options : "(none)");
1261 mopt->commit_interval = 0;
1262 mopt->mount_opt = OCFS2_MOUNT_NOINTR;
1263 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1264 mopt->slot = OCFS2_INVALID_SLOT;
1265 mopt->localalloc_opt = -1;
1266 mopt->cluster_stack[0] = '\0';
1267 mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
1268 mopt->dir_resv_level = -1;
1275 while ((p = strsep(&options, ",")) != NULL) {
1279 token = match_token(p, tokens, args);
1282 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
1285 mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
1288 mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
1291 if (match_int(&args[0], &option)) {
1296 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
1298 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
1301 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
1304 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
1307 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
1308 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
1309 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
1312 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
1313 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1314 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_ROFS;
1317 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
1318 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1319 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_CONT;
1321 case Opt_data_ordered:
1322 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
1324 case Opt_data_writeback:
1325 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
1327 case Opt_user_xattr:
1328 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1330 case Opt_nouser_xattr:
1331 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1333 case Opt_atime_quantum:
1334 if (match_int(&args[0], &option)) {
1339 mopt->atime_quantum = option;
1342 if (match_int(&args[0], &option)) {
1347 mopt->slot = (u16)option;
1350 if (match_int(&args[0], &option)) {
1357 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1358 mopt->commit_interval = HZ * option;
1360 case Opt_localalloc:
1361 if (match_int(&args[0], &option)) {
1366 mopt->localalloc_opt = option;
1368 case Opt_localflocks:
1370 * Changing this during remount could race
1371 * flock() requests, or "unbalance" existing
1372 * ones (e.g., a lock is taken in one mode but
1373 * dropped in the other). If users care enough
1374 * to flip locking modes during remount, we
1375 * could add a "local" flag to individual
1376 * flock structures for proper tracking of
1380 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1383 /* Check both that the option we were passed
1384 * is of the right length and that it is a proper
1385 * string of the right length.
1387 if (((args[0].to - args[0].from) !=
1388 OCFS2_STACK_LABEL_LEN) ||
1389 (strnlen(args[0].from,
1390 OCFS2_STACK_LABEL_LEN) !=
1391 OCFS2_STACK_LABEL_LEN)) {
1393 "Invalid cluster_stack option\n");
1397 memcpy(mopt->cluster_stack, args[0].from,
1398 OCFS2_STACK_LABEL_LEN);
1399 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1401 * Open code the memcmp here as we don't have
1403 * ocfs2_userspace_stack().
1405 if (memcmp(mopt->cluster_stack,
1406 OCFS2_CLASSIC_CLUSTER_STACK,
1407 OCFS2_STACK_LABEL_LEN))
1411 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1414 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1417 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1419 case Opt_coherency_buffered:
1420 mopt->mount_opt |= OCFS2_MOUNT_COHERENCY_BUFFERED;
1422 case Opt_coherency_full:
1423 mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED;
1426 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1427 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
1430 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1431 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1433 case Opt_resv_level:
1436 if (match_int(&args[0], &option)) {
1440 if (option >= OCFS2_MIN_RESV_LEVEL &&
1441 option < OCFS2_MAX_RESV_LEVEL)
1442 mopt->resv_level = option;
1444 case Opt_dir_resv_level:
1447 if (match_int(&args[0], &option)) {
1451 if (option >= OCFS2_MIN_RESV_LEVEL &&
1452 option < OCFS2_MAX_RESV_LEVEL)
1453 mopt->dir_resv_level = option;
1455 case Opt_journal_async_commit:
1456 mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
1459 mopt->mount_opt |= OCFS2_MOUNT_NOCLUSTER;
1463 "Unrecognized mount option \"%s\" "
1464 "or missing value\n", p);
1470 if (user_stack == 0) {
1471 /* Ensure only one heartbeat mode */
1472 tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL |
1473 OCFS2_MOUNT_HB_GLOBAL |
1474 OCFS2_MOUNT_HB_NONE);
1475 if (hweight32(tmp) != 1) {
1476 mlog(ML_ERROR, "Invalid heartbeat mount options\n");
1488 static int ocfs2_show_options(struct seq_file *s, struct dentry *root)
1490 struct ocfs2_super *osb = OCFS2_SB(root->d_sb);
1491 unsigned long opts = osb->s_mount_opt;
1492 unsigned int local_alloc_megs;
1494 if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
1495 seq_printf(s, ",_netdev");
1496 if (opts & OCFS2_MOUNT_HB_LOCAL)
1497 seq_printf(s, ",%s", OCFS2_HB_LOCAL);
1499 seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
1501 seq_printf(s, ",%s", OCFS2_HB_NONE);
1503 if (opts & OCFS2_MOUNT_NOINTR)
1504 seq_printf(s, ",nointr");
1506 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1507 seq_printf(s, ",data=writeback");
1509 seq_printf(s, ",data=ordered");
1511 if (opts & OCFS2_MOUNT_BARRIER)
1512 seq_printf(s, ",barrier=1");
1514 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1515 seq_printf(s, ",errors=panic");
1516 else if (opts & OCFS2_MOUNT_ERRORS_CONT)
1517 seq_printf(s, ",errors=continue");
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 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1526 if (osb->osb_commit_interval)
1527 seq_printf(s, ",commit=%u",
1528 (unsigned) (osb->osb_commit_interval / HZ));
1530 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1531 if (local_alloc_megs != ocfs2_la_default_mb(osb))
1532 seq_printf(s, ",localalloc=%d", local_alloc_megs);
1534 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1535 seq_printf(s, ",localflocks,");
1537 if (osb->osb_cluster_stack[0])
1538 seq_show_option_n(s, "cluster_stack", osb->osb_cluster_stack,
1539 OCFS2_STACK_LABEL_LEN);
1540 if (opts & OCFS2_MOUNT_USRQUOTA)
1541 seq_printf(s, ",usrquota");
1542 if (opts & OCFS2_MOUNT_GRPQUOTA)
1543 seq_printf(s, ",grpquota");
1545 if (opts & OCFS2_MOUNT_COHERENCY_BUFFERED)
1546 seq_printf(s, ",coherency=buffered");
1548 seq_printf(s, ",coherency=full");
1550 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1551 seq_printf(s, ",nouser_xattr");
1553 seq_printf(s, ",user_xattr");
1555 if (opts & OCFS2_MOUNT_INODE64)
1556 seq_printf(s, ",inode64");
1558 if (opts & OCFS2_MOUNT_POSIX_ACL)
1559 seq_printf(s, ",acl");
1561 seq_printf(s, ",noacl");
1563 if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
1564 seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
1566 if (osb->osb_dir_resv_level != osb->osb_resv_level)
1567 seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
1569 if (opts & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
1570 seq_printf(s, ",journal_async_commit");
1572 if (opts & OCFS2_MOUNT_NOCLUSTER)
1573 seq_printf(s, ",nocluster");
1578 static int __init ocfs2_init(void)
1582 status = init_ocfs2_uptodate_cache();
1586 status = ocfs2_initialize_mem_caches();
1590 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1592 ocfs2_set_locking_protocol();
1594 status = register_quota_format(&ocfs2_quota_format);
1597 status = register_filesystem(&ocfs2_fs_type);
1601 unregister_quota_format(&ocfs2_quota_format);
1603 debugfs_remove(ocfs2_debugfs_root);
1604 ocfs2_free_mem_caches();
1606 exit_ocfs2_uptodate_cache();
1612 static void __exit ocfs2_exit(void)
1614 unregister_quota_format(&ocfs2_quota_format);
1616 debugfs_remove(ocfs2_debugfs_root);
1618 ocfs2_free_mem_caches();
1620 unregister_filesystem(&ocfs2_fs_type);
1622 exit_ocfs2_uptodate_cache();
1625 static void ocfs2_put_super(struct super_block *sb)
1627 trace_ocfs2_put_super(sb);
1629 ocfs2_sync_blockdev(sb);
1630 ocfs2_dismount_volume(sb, 0);
1633 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1635 struct ocfs2_super *osb;
1636 u32 numbits, freebits;
1638 struct ocfs2_dinode *bm_lock;
1639 struct buffer_head *bh = NULL;
1640 struct inode *inode = NULL;
1642 trace_ocfs2_statfs(dentry->d_sb, buf);
1644 osb = OCFS2_SB(dentry->d_sb);
1646 inode = ocfs2_get_system_file_inode(osb,
1647 GLOBAL_BITMAP_SYSTEM_INODE,
1648 OCFS2_INVALID_SLOT);
1650 mlog(ML_ERROR, "failed to get bitmap inode\n");
1655 status = ocfs2_inode_lock(inode, &bh, 0);
1661 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1663 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1664 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1666 buf->f_type = OCFS2_SUPER_MAGIC;
1667 buf->f_bsize = dentry->d_sb->s_blocksize;
1668 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1669 buf->f_blocks = ((sector_t) numbits) *
1670 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1671 buf->f_bfree = ((sector_t) freebits) *
1672 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1673 buf->f_bavail = buf->f_bfree;
1674 buf->f_files = numbits;
1675 buf->f_ffree = freebits;
1676 buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1678 buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1679 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
1683 ocfs2_inode_unlock(inode, 0);
1694 static void ocfs2_inode_init_once(void *data)
1696 struct ocfs2_inode_info *oi = data;
1699 oi->ip_open_count = 0;
1700 spin_lock_init(&oi->ip_lock);
1701 ocfs2_extent_map_init(&oi->vfs_inode);
1702 INIT_LIST_HEAD(&oi->ip_io_markers);
1703 INIT_LIST_HEAD(&oi->ip_unwritten_list);
1704 oi->ip_dir_start_lookup = 0;
1705 init_rwsem(&oi->ip_alloc_sem);
1706 init_rwsem(&oi->ip_xattr_sem);
1707 mutex_init(&oi->ip_io_mutex);
1709 oi->ip_blkno = 0ULL;
1710 oi->ip_clusters = 0;
1711 oi->ip_next_orphan = NULL;
1713 ocfs2_resv_init_once(&oi->ip_la_data_resv);
1715 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
1716 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
1717 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
1719 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
1720 &ocfs2_inode_caching_ops);
1722 inode_init_once(&oi->vfs_inode);
1725 static int ocfs2_initialize_mem_caches(void)
1727 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
1728 sizeof(struct ocfs2_inode_info),
1730 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1731 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
1732 ocfs2_inode_init_once);
1733 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1734 sizeof(struct ocfs2_dquot),
1736 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1739 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1740 sizeof(struct ocfs2_quota_chunk),
1742 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1744 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1745 !ocfs2_qf_chunk_cachep) {
1746 kmem_cache_destroy(ocfs2_inode_cachep);
1747 kmem_cache_destroy(ocfs2_dquot_cachep);
1748 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1755 static void ocfs2_free_mem_caches(void)
1758 * Make sure all delayed rcu free inodes are flushed before we
1762 kmem_cache_destroy(ocfs2_inode_cachep);
1763 ocfs2_inode_cachep = NULL;
1765 kmem_cache_destroy(ocfs2_dquot_cachep);
1766 ocfs2_dquot_cachep = NULL;
1768 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1769 ocfs2_qf_chunk_cachep = NULL;
1772 static int ocfs2_get_sector(struct super_block *sb,
1773 struct buffer_head **bh,
1777 if (!sb_set_blocksize(sb, sect_size)) {
1778 mlog(ML_ERROR, "unable to set blocksize\n");
1782 *bh = sb_getblk(sb, block);
1784 mlog_errno(-ENOMEM);
1788 if (!buffer_dirty(*bh))
1789 clear_buffer_uptodate(*bh);
1791 ll_rw_block(REQ_OP_READ, 0, 1, bh);
1792 wait_on_buffer(*bh);
1793 if (!buffer_uptodate(*bh)) {
1803 static int ocfs2_mount_volume(struct super_block *sb)
1806 int unlock_super = 0;
1807 struct ocfs2_super *osb = OCFS2_SB(sb);
1809 if (ocfs2_is_hard_readonly(osb))
1812 mutex_init(&osb->obs_trim_fs_mutex);
1814 status = ocfs2_dlm_init(osb);
1817 if (status == -EBADR && ocfs2_userspace_stack(osb))
1818 mlog(ML_ERROR, "couldn't mount because cluster name on"
1819 " disk does not match the running cluster name.\n");
1823 status = ocfs2_super_lock(osb, 1);
1830 /* This will load up the node map and add ourselves to it. */
1831 status = ocfs2_find_slot(osb);
1837 /* load all node-local system inodes */
1838 status = ocfs2_init_local_system_inodes(osb);
1844 status = ocfs2_check_volume(osb);
1850 status = ocfs2_truncate_log_init(osb);
1856 ocfs2_super_unlock(osb, 1);
1861 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1863 int tmp, hangup_needed = 0;
1864 struct ocfs2_super *osb = NULL;
1867 trace_ocfs2_dismount_volume(sb);
1873 /* Remove file check sysfs related directores/files,
1874 * and wait for the pending file check operations */
1875 ocfs2_filecheck_remove_sysfs(osb);
1877 kset_unregister(osb->osb_dev_kset);
1879 /* Orphan scan should be stopped as early as possible */
1880 ocfs2_orphan_scan_stop(osb);
1882 ocfs2_disable_quotas(osb);
1884 /* All dquots should be freed by now */
1885 WARN_ON(!llist_empty(&osb->dquot_drop_list));
1886 /* Wait for worker to be done with the work structure in osb */
1887 cancel_work_sync(&osb->dquot_drop_work);
1889 ocfs2_shutdown_local_alloc(osb);
1891 ocfs2_truncate_log_shutdown(osb);
1893 /* This will disable recovery and flush any recovery work. */
1894 ocfs2_recovery_exit(osb);
1896 ocfs2_sync_blockdev(sb);
1898 ocfs2_purge_refcount_trees(osb);
1900 /* No cluster connection means we've failed during mount, so skip
1901 * all the steps which depended on that to complete. */
1903 tmp = ocfs2_super_lock(osb, 1);
1910 if (osb->slot_num != OCFS2_INVALID_SLOT)
1911 ocfs2_put_slot(osb);
1914 ocfs2_super_unlock(osb, 1);
1916 ocfs2_release_system_inodes(osb);
1918 ocfs2_journal_shutdown(osb);
1921 * If we're dismounting due to mount error, mount.ocfs2 will clean
1922 * up heartbeat. If we're a local mount, there is no heartbeat.
1923 * If we failed before we got a uuid_str yet, we can't stop
1924 * heartbeat. Otherwise, do it.
1926 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str &&
1927 !ocfs2_is_hard_readonly(osb))
1931 ocfs2_dlm_shutdown(osb, hangup_needed);
1933 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
1934 debugfs_remove_recursive(osb->osb_debug_root);
1937 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
1939 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1941 if (ocfs2_mount_local(osb))
1942 snprintf(nodestr, sizeof(nodestr), "local");
1944 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1946 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1947 osb->dev_str, nodestr);
1949 ocfs2_delete_osb(osb);
1952 sb->s_fs_info = NULL;
1955 static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1956 unsigned uuid_bytes)
1961 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1963 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
1964 if (osb->uuid_str == NULL)
1967 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1968 /* print with null */
1969 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1970 if (ret != 2) /* drop super cleans up */
1972 /* then only advance past the last char */
1979 /* Make sure entire volume is addressable by our journal. Requires
1980 osb_clusters_at_boot to be valid and for the journal to have been
1981 initialized by ocfs2_journal_init(). */
1982 static int ocfs2_journal_addressable(struct ocfs2_super *osb)
1986 ocfs2_clusters_to_blocks(osb->sb,
1987 osb->osb_clusters_at_boot) - 1;
1989 /* 32-bit block number is always OK. */
1990 if (max_block <= (u32)~0ULL)
1993 /* Volume is "huge", so see if our journal is new enough to
1995 if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb,
1996 OCFS2_FEATURE_COMPAT_JBD2_SB) &&
1997 jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0,
1998 JBD2_FEATURE_INCOMPAT_64BIT))) {
1999 mlog(ML_ERROR, "The journal cannot address the entire volume. "
2000 "Enable the 'block64' journal option with tunefs.ocfs2");
2009 static int ocfs2_initialize_super(struct super_block *sb,
2010 struct buffer_head *bh,
2012 struct ocfs2_blockcheck_stats *stats)
2015 int i, cbits, bbits;
2016 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
2017 struct inode *inode = NULL;
2018 struct ocfs2_super *osb;
2021 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
2028 sb->s_fs_info = osb;
2029 sb->s_op = &ocfs2_sops;
2030 sb->s_d_op = &ocfs2_dentry_ops;
2031 sb->s_export_op = &ocfs2_export_ops;
2032 sb->s_qcop = &dquot_quotactl_sysfile_ops;
2033 sb->dq_op = &ocfs2_quota_operations;
2034 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
2035 sb->s_xattr = ocfs2_xattr_handlers;
2036 sb->s_time_gran = 1;
2037 sb->s_flags |= SB_NOATIME;
2038 /* this is needed to support O_LARGEFILE */
2039 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2040 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
2041 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
2042 memcpy(&sb->s_uuid, di->id2.i_super.s_uuid,
2043 sizeof(di->id2.i_super.s_uuid));
2045 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
2047 for (i = 0; i < 3; i++)
2048 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
2049 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2052 osb->s_sectsize_bits = blksize_bits(sector_size);
2053 BUG_ON(!osb->s_sectsize_bits);
2055 spin_lock_init(&osb->dc_task_lock);
2056 init_waitqueue_head(&osb->dc_event);
2057 osb->dc_work_sequence = 0;
2058 osb->dc_wake_sequence = 0;
2059 INIT_LIST_HEAD(&osb->blocked_lock_list);
2060 osb->blocked_lock_count = 0;
2061 spin_lock_init(&osb->osb_lock);
2062 spin_lock_init(&osb->osb_xattr_lock);
2063 ocfs2_init_steal_slots(osb);
2065 mutex_init(&osb->system_file_mutex);
2067 atomic_set(&osb->alloc_stats.moves, 0);
2068 atomic_set(&osb->alloc_stats.local_data, 0);
2069 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2070 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2071 atomic_set(&osb->alloc_stats.bg_extends, 0);
2073 /* Copy the blockcheck stats from the superblock probe */
2074 osb->osb_ecc_stats = *stats;
2076 ocfs2_init_node_maps(osb);
2078 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2079 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2081 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2082 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2083 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2089 ocfs2_orphan_scan_init(osb);
2091 status = ocfs2_recovery_init(osb);
2093 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2098 init_waitqueue_head(&osb->checkpoint_event);
2100 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2102 osb->slot_num = OCFS2_INVALID_SLOT;
2104 osb->s_xattr_inline_size = le16_to_cpu(
2105 di->id2.i_super.s_xattr_inline_size);
2107 osb->local_alloc_state = OCFS2_LA_UNUSED;
2108 osb->local_alloc_bh = NULL;
2109 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
2111 init_waitqueue_head(&osb->osb_mount_event);
2113 status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
2119 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2120 if (!osb->vol_label) {
2121 mlog(ML_ERROR, "unable to alloc vol label\n");
2126 osb->slot_recovery_generations =
2127 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2129 if (!osb->slot_recovery_generations) {
2135 init_waitqueue_head(&osb->osb_wipe_event);
2136 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2137 sizeof(*osb->osb_orphan_wipes),
2139 if (!osb->osb_orphan_wipes) {
2145 osb->osb_rf_lock_tree = RB_ROOT;
2147 osb->s_feature_compat =
2148 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2149 osb->s_feature_ro_compat =
2150 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2151 osb->s_feature_incompat =
2152 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2154 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2155 mlog(ML_ERROR, "couldn't mount because of unsupported "
2156 "optional features (%x).\n", i);
2160 if (!sb_rdonly(osb->sb) && (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2161 mlog(ML_ERROR, "couldn't mount RDWR because of "
2162 "unsupported optional features (%x).\n", i);
2167 if (ocfs2_clusterinfo_valid(osb)) {
2169 * ci_stack and ci_cluster in ocfs2_cluster_info may not be null
2170 * terminated, so make sure no overflow happens here by using
2171 * memcpy. Destination strings will always be null terminated
2172 * because osb is allocated using kzalloc.
2174 osb->osb_stackflags =
2175 OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
2176 memcpy(osb->osb_cluster_stack,
2177 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2178 OCFS2_STACK_LABEL_LEN);
2179 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2181 "couldn't mount because of an invalid "
2182 "cluster stack label (%s) \n",
2183 osb->osb_cluster_stack);
2187 memcpy(osb->osb_cluster_name,
2188 OCFS2_RAW_SB(di)->s_cluster_info.ci_cluster,
2189 OCFS2_CLUSTER_NAME_LEN);
2191 /* The empty string is identical with classic tools that
2192 * don't know about s_cluster_info. */
2193 osb->osb_cluster_stack[0] = '\0';
2196 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2198 INIT_WORK(&osb->dquot_drop_work, ocfs2_drop_dquot_refs);
2199 init_llist_head(&osb->dquot_drop_list);
2201 /* get some pseudo constants for clustersize bits */
2202 osb->s_clustersize_bits =
2203 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2204 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2206 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2207 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2208 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2209 osb->s_clustersize);
2214 total_blocks = ocfs2_clusters_to_blocks(osb->sb,
2215 le32_to_cpu(di->i_clusters));
2217 status = generic_check_addressable(osb->sb->s_blocksize_bits,
2220 mlog(ML_ERROR, "Volume too large "
2221 "to mount safely on this system");
2226 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2227 sizeof(di->id2.i_super.s_uuid))) {
2228 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2233 strlcpy(osb->vol_label, di->id2.i_super.s_label,
2234 OCFS2_MAX_VOL_LABEL_LEN);
2235 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2236 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2237 osb->first_cluster_group_blkno =
2238 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2239 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
2240 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2241 trace_ocfs2_initialize_super(osb->vol_label, osb->uuid_str,
2242 (unsigned long long)osb->root_blkno,
2243 (unsigned long long)osb->system_dir_blkno,
2244 osb->s_clustersize_bits);
2246 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2247 if (!osb->osb_dlm_debug) {
2253 atomic_set(&osb->vol_state, VOLUME_INIT);
2255 /* load root, system_dir, and all global system inodes */
2256 status = ocfs2_init_global_system_inodes(osb);
2265 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2266 OCFS2_INVALID_SLOT);
2273 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
2274 osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
2277 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
2278 osb->s_feature_incompat) * 8;
2280 status = ocfs2_init_slot_info(osb);
2286 osb->ocfs2_wq = alloc_ordered_workqueue("ocfs2_wq", WQ_MEM_RECLAIM);
2287 if (!osb->ocfs2_wq) {
2297 * will return: -EAGAIN if it is ok to keep searching for superblocks
2298 * -EINVAL if there is a bad superblock
2301 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2302 struct buffer_head *bh,
2304 struct ocfs2_blockcheck_stats *stats)
2306 int status = -EAGAIN;
2308 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2309 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
2310 /* We have to do a raw check of the feature here */
2311 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2312 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2313 status = ocfs2_block_check_validate(bh->b_data,
2321 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2322 mlog(ML_ERROR, "found superblock with incorrect block "
2323 "size: found %u, should be %u\n",
2324 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2326 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2327 OCFS2_MAJOR_REV_LEVEL ||
2328 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2329 OCFS2_MINOR_REV_LEVEL) {
2330 mlog(ML_ERROR, "found superblock with bad version: "
2331 "found %u.%u, should be %u.%u\n",
2332 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2333 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2334 OCFS2_MAJOR_REV_LEVEL,
2335 OCFS2_MINOR_REV_LEVEL);
2336 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2337 mlog(ML_ERROR, "bad block number on superblock: "
2338 "found %llu, should be %llu\n",
2339 (unsigned long long)le64_to_cpu(di->i_blkno),
2340 (unsigned long long)bh->b_blocknr);
2341 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2342 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2343 mlog(ML_ERROR, "bad cluster size found: %u\n",
2344 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2345 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2346 mlog(ML_ERROR, "bad root_blkno: 0\n");
2347 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2348 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2349 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2351 "Superblock slots found greater than file system "
2352 "maximum: found %u, max %u\n",
2353 le16_to_cpu(di->id2.i_super.s_max_slots),
2362 if (status && status != -EAGAIN)
2367 static int ocfs2_check_volume(struct ocfs2_super *osb)
2372 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2376 /* Init our journal object. */
2377 status = ocfs2_journal_init(osb, &dirty);
2379 mlog(ML_ERROR, "Could not initialize journal!\n");
2383 /* Now that journal has been initialized, check to make sure
2384 entire volume is addressable. */
2385 status = ocfs2_journal_addressable(osb);
2389 /* If the journal was unmounted cleanly then we don't want to
2390 * recover anything. Otherwise, journal_load will do that
2391 * dirty work for us :) */
2393 status = ocfs2_journal_wipe(osb->journal, 0);
2399 printk(KERN_NOTICE "ocfs2: File system on device (%s) was not "
2400 "unmounted cleanly, recovering it.\n", osb->dev_str);
2403 local = ocfs2_mount_local(osb);
2405 /* will play back anything left in the journal. */
2406 status = ocfs2_journal_load(osb->journal, local, dirty);
2408 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2412 if (osb->s_mount_opt & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
2413 jbd2_journal_set_features(osb->journal->j_journal,
2414 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2415 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2417 jbd2_journal_clear_features(osb->journal->j_journal,
2418 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2419 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2422 /* recover my local alloc if we didn't unmount cleanly. */
2423 status = ocfs2_begin_local_alloc_recovery(osb,
2430 /* we complete the recovery process after we've marked
2431 * ourselves as mounted. */
2434 status = ocfs2_load_local_alloc(osb);
2441 /* Recovery will be completed after we've mounted the
2442 * rest of the volume. */
2443 osb->local_alloc_copy = local_alloc;
2447 /* go through each journal, trylock it and if you get the
2448 * lock, and it's marked as dirty, set the bit in the recover
2449 * map and launch a recovery thread for it. */
2450 status = ocfs2_mark_dead_nodes(osb);
2456 status = ocfs2_compute_replay_slots(osb);
2469 * The routine gets called from dismount or close whenever a dismount on
2470 * volume is requested and the osb open count becomes 1.
2471 * It will remove the osb from the global list and also free up all the
2472 * initialized resources and fileobject.
2474 static void ocfs2_delete_osb(struct ocfs2_super *osb)
2476 /* This function assumes that the caller has the main osb resource */
2478 /* ocfs2_initializer_super have already created this workqueue */
2480 destroy_workqueue(osb->ocfs2_wq);
2482 ocfs2_free_slot_info(osb);
2484 kfree(osb->osb_orphan_wipes);
2485 kfree(osb->slot_recovery_generations);
2486 kfree(osb->local_alloc_copy);
2487 kfree(osb->uuid_str);
2488 kfree(osb->vol_label);
2489 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2490 memset(osb, 0, sizeof(struct ocfs2_super));
2493 /* Depending on the mount option passed, perform one of the following:
2494 * Put OCFS2 into a readonly state (default)
2495 * Return EIO so that only the process errs
2496 * Fix the error as if fsck.ocfs2 -y
2499 static int ocfs2_handle_error(struct super_block *sb)
2501 struct ocfs2_super *osb = OCFS2_SB(sb);
2504 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2505 pr_crit("On-disk corruption discovered. "
2506 "Please run fsck.ocfs2 once the filesystem is unmounted.\n");
2508 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) {
2509 panic("OCFS2: (device %s): panic forced after error\n",
2511 } else if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_CONT) {
2512 pr_crit("OCFS2: Returning error to the calling process.\n");
2514 } else { /* default option */
2516 if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)))
2519 pr_crit("OCFS2: File system is now read-only.\n");
2520 sb->s_flags |= SB_RDONLY;
2521 ocfs2_set_ro_flag(osb, 0);
2527 int __ocfs2_error(struct super_block *sb, const char *function,
2528 const char *fmt, ...)
2530 struct va_format vaf;
2533 va_start(args, fmt);
2537 /* Not using mlog here because we want to show the actual
2538 * function the error came from. */
2539 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %pV",
2540 sb->s_id, function, &vaf);
2544 return ocfs2_handle_error(sb);
2547 /* Handle critical errors. This is intentionally more drastic than
2548 * ocfs2_handle_error, so we only use for things like journal errors,
2550 void __ocfs2_abort(struct super_block *sb, const char *function,
2551 const char *fmt, ...)
2553 struct va_format vaf;
2556 va_start(args, fmt);
2561 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %pV",
2562 sb->s_id, function, &vaf);
2566 /* We don't have the cluster support yet to go straight to
2567 * hard readonly in here. Until then, we want to keep
2568 * ocfs2_abort() so that we can at least mark critical
2571 * TODO: This should abort the journal and alert other nodes
2572 * that our slot needs recovery. */
2574 /* Force a panic(). This stinks, but it's better than letting
2575 * things continue without having a proper hard readonly
2577 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2578 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
2579 ocfs2_handle_error(sb);
2583 * Void signal blockers, because in-kernel sigprocmask() only fails
2584 * when SIG_* is wrong.
2586 void ocfs2_block_signals(sigset_t *oldset)
2591 sigfillset(&blocked);
2592 rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
2596 void ocfs2_unblock_signals(sigset_t *oldset)
2598 int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
2602 module_init(ocfs2_init);
2603 module_exit(ocfs2_exit);