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)) {
995 /* probe for superblock */
996 status = ocfs2_sb_probe(sb, &bh, §or_size, &stats);
998 mlog(ML_ERROR, "superblock probe failed!\n");
1002 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
1010 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1014 osb->s_mount_opt = parsed_options.mount_opt;
1015 osb->s_atime_quantum = parsed_options.atime_quantum;
1016 osb->preferred_slot = parsed_options.slot;
1017 osb->osb_commit_interval = parsed_options.commit_interval;
1019 ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
1020 osb->osb_resv_level = parsed_options.resv_level;
1021 osb->osb_dir_resv_level = parsed_options.resv_level;
1022 if (parsed_options.dir_resv_level == -1)
1023 osb->osb_dir_resv_level = parsed_options.resv_level;
1025 osb->osb_dir_resv_level = parsed_options.dir_resv_level;
1027 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1031 sb->s_magic = OCFS2_SUPER_MAGIC;
1033 sb->s_flags = (sb->s_flags & ~(SB_POSIXACL | SB_NOSEC)) |
1034 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0);
1036 /* Hard readonly mode only if: bdev_read_only, SB_RDONLY,
1038 if (bdev_read_only(sb->s_bdev)) {
1039 if (!sb_rdonly(sb)) {
1041 mlog(ML_ERROR, "Readonly device detected but readonly "
1042 "mount was not specified.\n");
1046 /* You should not be able to start a local heartbeat
1047 * on a readonly device. */
1048 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1050 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1055 status = ocfs2_check_journals_nolocks(osb);
1057 if (status == -EROFS)
1058 mlog(ML_ERROR, "Recovery required on readonly "
1059 "file system, but write access is "
1064 ocfs2_set_ro_flag(osb, 1);
1066 printk(KERN_NOTICE "ocfs2: Readonly device (%s) detected. "
1067 "Cluster services will not be used for this mount. "
1068 "Recovery will be skipped.\n", osb->dev_str);
1071 if (!ocfs2_is_hard_readonly(osb)) {
1073 ocfs2_set_ro_flag(osb, 0);
1076 status = ocfs2_verify_heartbeat(osb);
1080 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1081 ocfs2_debugfs_root);
1083 debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root,
1084 osb, &ocfs2_osb_debug_fops);
1086 if (ocfs2_meta_ecc(osb))
1087 ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats,
1088 osb->osb_debug_root);
1090 status = ocfs2_mount_volume(sb);
1094 if (osb->root_inode)
1095 inode = igrab(osb->root_inode);
1102 osb->osb_dev_kset = kset_create_and_add(sb->s_id, NULL,
1104 if (!osb->osb_dev_kset) {
1106 mlog(ML_ERROR, "Unable to create device kset %s.\n", sb->s_id);
1110 /* Create filecheck sysfs related directories/files at
1111 * /sys/fs/ocfs2/<devname>/filecheck */
1112 if (ocfs2_filecheck_create_sysfs(osb)) {
1114 mlog(ML_ERROR, "Unable to create filecheck sysfs directory at "
1115 "/sys/fs/ocfs2/%s/filecheck.\n", sb->s_id);
1119 root = d_make_root(inode);
1127 ocfs2_complete_mount_recovery(osb);
1129 if (ocfs2_mount_local(osb))
1130 snprintf(nodestr, sizeof(nodestr), "local");
1132 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1134 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
1135 "with %s data mode.\n",
1136 osb->dev_str, nodestr, osb->slot_num,
1137 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1140 if ((osb->s_mount_opt & OCFS2_MOUNT_NOCLUSTER) &&
1141 !(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT))
1142 printk(KERN_NOTICE "ocfs2: The shared device (%s) is mounted "
1143 "without cluster aware mode.\n", osb->dev_str);
1145 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1146 wake_up(&osb->osb_mount_event);
1148 /* Now we can initialize quotas because we can afford to wait
1149 * for cluster locks recovery now. That also means that truncation
1150 * log recovery can happen but that waits for proper quota setup */
1151 if (!sb_rdonly(sb)) {
1152 status = ocfs2_enable_quotas(osb);
1154 /* We have to err-out specially here because
1155 * s_root is already set */
1157 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1158 wake_up(&osb->osb_mount_event);
1163 ocfs2_complete_quota_recovery(osb);
1165 /* Now we wake up again for processes waiting for quotas */
1166 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1167 wake_up(&osb->osb_mount_event);
1169 /* Start this when the mount is almost sure of being successful */
1170 ocfs2_orphan_scan_start(osb);
1175 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1176 wake_up(&osb->osb_mount_event);
1177 ocfs2_dismount_volume(sb, 1);
1181 debugfs_remove_recursive(osb->osb_debug_root);
1183 ocfs2_release_system_inodes(osb);
1184 kfree(osb->recovery_map);
1185 ocfs2_delete_osb(osb);
1193 static struct dentry *ocfs2_mount(struct file_system_type *fs_type,
1195 const char *dev_name,
1198 return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
1201 static struct file_system_type ocfs2_fs_type = {
1202 .owner = THIS_MODULE,
1204 .mount = ocfs2_mount,
1205 .kill_sb = kill_block_super,
1206 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
1209 MODULE_ALIAS_FS("ocfs2");
1211 static int ocfs2_check_set_options(struct super_block *sb,
1212 struct mount_options *options)
1214 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1215 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1216 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1217 mlog(ML_ERROR, "User quotas were requested, but this "
1218 "filesystem does not have the feature enabled.\n");
1221 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1222 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1223 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1224 mlog(ML_ERROR, "Group quotas were requested, but this "
1225 "filesystem does not have the feature enabled.\n");
1228 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1229 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1230 mlog(ML_ERROR, "ACL support requested but extended attributes "
1231 "feature is not enabled\n");
1234 /* No ACL setting specified? Use XATTR feature... */
1235 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1236 OCFS2_MOUNT_NO_POSIX_ACL))) {
1237 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1238 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1240 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1245 static int ocfs2_parse_options(struct super_block *sb,
1247 struct mount_options *mopt,
1250 int status, user_stack = 0;
1254 substring_t args[MAX_OPT_ARGS];
1256 trace_ocfs2_parse_options(is_remount, options ? options : "(none)");
1258 mopt->commit_interval = 0;
1259 mopt->mount_opt = OCFS2_MOUNT_NOINTR;
1260 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1261 mopt->slot = OCFS2_INVALID_SLOT;
1262 mopt->localalloc_opt = -1;
1263 mopt->cluster_stack[0] = '\0';
1264 mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
1265 mopt->dir_resv_level = -1;
1272 while ((p = strsep(&options, ",")) != NULL) {
1276 token = match_token(p, tokens, args);
1279 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
1282 mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
1285 mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
1288 if (match_int(&args[0], &option)) {
1293 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
1295 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
1298 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
1301 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
1304 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
1305 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
1306 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
1309 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
1310 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1311 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_ROFS;
1314 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
1315 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1316 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_CONT;
1318 case Opt_data_ordered:
1319 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
1321 case Opt_data_writeback:
1322 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
1324 case Opt_user_xattr:
1325 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1327 case Opt_nouser_xattr:
1328 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1330 case Opt_atime_quantum:
1331 if (match_int(&args[0], &option)) {
1336 mopt->atime_quantum = option;
1339 if (match_int(&args[0], &option)) {
1344 mopt->slot = (u16)option;
1347 if (match_int(&args[0], &option)) {
1354 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1355 mopt->commit_interval = HZ * option;
1357 case Opt_localalloc:
1358 if (match_int(&args[0], &option)) {
1363 mopt->localalloc_opt = option;
1365 case Opt_localflocks:
1367 * Changing this during remount could race
1368 * flock() requests, or "unbalance" existing
1369 * ones (e.g., a lock is taken in one mode but
1370 * dropped in the other). If users care enough
1371 * to flip locking modes during remount, we
1372 * could add a "local" flag to individual
1373 * flock structures for proper tracking of
1377 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1380 /* Check both that the option we were passed
1381 * is of the right length and that it is a proper
1382 * string of the right length.
1384 if (((args[0].to - args[0].from) !=
1385 OCFS2_STACK_LABEL_LEN) ||
1386 (strnlen(args[0].from,
1387 OCFS2_STACK_LABEL_LEN) !=
1388 OCFS2_STACK_LABEL_LEN)) {
1390 "Invalid cluster_stack option\n");
1394 memcpy(mopt->cluster_stack, args[0].from,
1395 OCFS2_STACK_LABEL_LEN);
1396 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1398 * Open code the memcmp here as we don't have
1400 * ocfs2_userspace_stack().
1402 if (memcmp(mopt->cluster_stack,
1403 OCFS2_CLASSIC_CLUSTER_STACK,
1404 OCFS2_STACK_LABEL_LEN))
1408 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1411 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1414 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1416 case Opt_coherency_buffered:
1417 mopt->mount_opt |= OCFS2_MOUNT_COHERENCY_BUFFERED;
1419 case Opt_coherency_full:
1420 mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED;
1423 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1424 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
1427 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1428 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1430 case Opt_resv_level:
1433 if (match_int(&args[0], &option)) {
1437 if (option >= OCFS2_MIN_RESV_LEVEL &&
1438 option < OCFS2_MAX_RESV_LEVEL)
1439 mopt->resv_level = option;
1441 case Opt_dir_resv_level:
1444 if (match_int(&args[0], &option)) {
1448 if (option >= OCFS2_MIN_RESV_LEVEL &&
1449 option < OCFS2_MAX_RESV_LEVEL)
1450 mopt->dir_resv_level = option;
1452 case Opt_journal_async_commit:
1453 mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
1456 mopt->mount_opt |= OCFS2_MOUNT_NOCLUSTER;
1460 "Unrecognized mount option \"%s\" "
1461 "or missing value\n", p);
1467 if (user_stack == 0) {
1468 /* Ensure only one heartbeat mode */
1469 tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL |
1470 OCFS2_MOUNT_HB_GLOBAL |
1471 OCFS2_MOUNT_HB_NONE);
1472 if (hweight32(tmp) != 1) {
1473 mlog(ML_ERROR, "Invalid heartbeat mount options\n");
1485 static int ocfs2_show_options(struct seq_file *s, struct dentry *root)
1487 struct ocfs2_super *osb = OCFS2_SB(root->d_sb);
1488 unsigned long opts = osb->s_mount_opt;
1489 unsigned int local_alloc_megs;
1491 if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
1492 seq_printf(s, ",_netdev");
1493 if (opts & OCFS2_MOUNT_HB_LOCAL)
1494 seq_printf(s, ",%s", OCFS2_HB_LOCAL);
1496 seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
1498 seq_printf(s, ",%s", OCFS2_HB_NONE);
1500 if (opts & OCFS2_MOUNT_NOINTR)
1501 seq_printf(s, ",nointr");
1503 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1504 seq_printf(s, ",data=writeback");
1506 seq_printf(s, ",data=ordered");
1508 if (opts & OCFS2_MOUNT_BARRIER)
1509 seq_printf(s, ",barrier=1");
1511 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1512 seq_printf(s, ",errors=panic");
1513 else if (opts & OCFS2_MOUNT_ERRORS_CONT)
1514 seq_printf(s, ",errors=continue");
1516 seq_printf(s, ",errors=remount-ro");
1518 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1519 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1521 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1523 if (osb->osb_commit_interval)
1524 seq_printf(s, ",commit=%u",
1525 (unsigned) (osb->osb_commit_interval / HZ));
1527 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1528 if (local_alloc_megs != ocfs2_la_default_mb(osb))
1529 seq_printf(s, ",localalloc=%d", local_alloc_megs);
1531 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1532 seq_printf(s, ",localflocks,");
1534 if (osb->osb_cluster_stack[0])
1535 seq_show_option_n(s, "cluster_stack", osb->osb_cluster_stack,
1536 OCFS2_STACK_LABEL_LEN);
1537 if (opts & OCFS2_MOUNT_USRQUOTA)
1538 seq_printf(s, ",usrquota");
1539 if (opts & OCFS2_MOUNT_GRPQUOTA)
1540 seq_printf(s, ",grpquota");
1542 if (opts & OCFS2_MOUNT_COHERENCY_BUFFERED)
1543 seq_printf(s, ",coherency=buffered");
1545 seq_printf(s, ",coherency=full");
1547 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1548 seq_printf(s, ",nouser_xattr");
1550 seq_printf(s, ",user_xattr");
1552 if (opts & OCFS2_MOUNT_INODE64)
1553 seq_printf(s, ",inode64");
1555 if (opts & OCFS2_MOUNT_POSIX_ACL)
1556 seq_printf(s, ",acl");
1558 seq_printf(s, ",noacl");
1560 if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
1561 seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
1563 if (osb->osb_dir_resv_level != osb->osb_resv_level)
1564 seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
1566 if (opts & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
1567 seq_printf(s, ",journal_async_commit");
1569 if (opts & OCFS2_MOUNT_NOCLUSTER)
1570 seq_printf(s, ",nocluster");
1575 static int __init ocfs2_init(void)
1579 status = init_ocfs2_uptodate_cache();
1583 status = ocfs2_initialize_mem_caches();
1587 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1589 ocfs2_set_locking_protocol();
1591 status = register_quota_format(&ocfs2_quota_format);
1594 status = register_filesystem(&ocfs2_fs_type);
1598 unregister_quota_format(&ocfs2_quota_format);
1600 debugfs_remove(ocfs2_debugfs_root);
1601 ocfs2_free_mem_caches();
1603 exit_ocfs2_uptodate_cache();
1609 static void __exit ocfs2_exit(void)
1611 unregister_quota_format(&ocfs2_quota_format);
1613 debugfs_remove(ocfs2_debugfs_root);
1615 ocfs2_free_mem_caches();
1617 unregister_filesystem(&ocfs2_fs_type);
1619 exit_ocfs2_uptodate_cache();
1622 static void ocfs2_put_super(struct super_block *sb)
1624 trace_ocfs2_put_super(sb);
1626 ocfs2_sync_blockdev(sb);
1627 ocfs2_dismount_volume(sb, 0);
1630 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1632 struct ocfs2_super *osb;
1633 u32 numbits, freebits;
1635 struct ocfs2_dinode *bm_lock;
1636 struct buffer_head *bh = NULL;
1637 struct inode *inode = NULL;
1639 trace_ocfs2_statfs(dentry->d_sb, buf);
1641 osb = OCFS2_SB(dentry->d_sb);
1643 inode = ocfs2_get_system_file_inode(osb,
1644 GLOBAL_BITMAP_SYSTEM_INODE,
1645 OCFS2_INVALID_SLOT);
1647 mlog(ML_ERROR, "failed to get bitmap inode\n");
1652 status = ocfs2_inode_lock(inode, &bh, 0);
1658 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1660 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1661 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1663 buf->f_type = OCFS2_SUPER_MAGIC;
1664 buf->f_bsize = dentry->d_sb->s_blocksize;
1665 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1666 buf->f_blocks = ((sector_t) numbits) *
1667 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1668 buf->f_bfree = ((sector_t) freebits) *
1669 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1670 buf->f_bavail = buf->f_bfree;
1671 buf->f_files = numbits;
1672 buf->f_ffree = freebits;
1673 buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1675 buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1676 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
1680 ocfs2_inode_unlock(inode, 0);
1691 static void ocfs2_inode_init_once(void *data)
1693 struct ocfs2_inode_info *oi = data;
1696 oi->ip_open_count = 0;
1697 spin_lock_init(&oi->ip_lock);
1698 ocfs2_extent_map_init(&oi->vfs_inode);
1699 INIT_LIST_HEAD(&oi->ip_io_markers);
1700 INIT_LIST_HEAD(&oi->ip_unwritten_list);
1701 oi->ip_dir_start_lookup = 0;
1702 init_rwsem(&oi->ip_alloc_sem);
1703 init_rwsem(&oi->ip_xattr_sem);
1704 mutex_init(&oi->ip_io_mutex);
1706 oi->ip_blkno = 0ULL;
1707 oi->ip_clusters = 0;
1708 oi->ip_next_orphan = NULL;
1710 ocfs2_resv_init_once(&oi->ip_la_data_resv);
1712 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
1713 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
1714 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
1716 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
1717 &ocfs2_inode_caching_ops);
1719 inode_init_once(&oi->vfs_inode);
1722 static int ocfs2_initialize_mem_caches(void)
1724 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
1725 sizeof(struct ocfs2_inode_info),
1727 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1728 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
1729 ocfs2_inode_init_once);
1730 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1731 sizeof(struct ocfs2_dquot),
1733 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1736 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1737 sizeof(struct ocfs2_quota_chunk),
1739 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1741 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1742 !ocfs2_qf_chunk_cachep) {
1743 kmem_cache_destroy(ocfs2_inode_cachep);
1744 kmem_cache_destroy(ocfs2_dquot_cachep);
1745 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1752 static void ocfs2_free_mem_caches(void)
1755 * Make sure all delayed rcu free inodes are flushed before we
1759 kmem_cache_destroy(ocfs2_inode_cachep);
1760 ocfs2_inode_cachep = NULL;
1762 kmem_cache_destroy(ocfs2_dquot_cachep);
1763 ocfs2_dquot_cachep = NULL;
1765 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1766 ocfs2_qf_chunk_cachep = NULL;
1769 static int ocfs2_get_sector(struct super_block *sb,
1770 struct buffer_head **bh,
1774 if (!sb_set_blocksize(sb, sect_size)) {
1775 mlog(ML_ERROR, "unable to set blocksize\n");
1779 *bh = sb_getblk(sb, block);
1781 mlog_errno(-ENOMEM);
1785 if (!buffer_dirty(*bh))
1786 clear_buffer_uptodate(*bh);
1788 ll_rw_block(REQ_OP_READ, 0, 1, bh);
1789 wait_on_buffer(*bh);
1790 if (!buffer_uptodate(*bh)) {
1800 static int ocfs2_mount_volume(struct super_block *sb)
1803 struct ocfs2_super *osb = OCFS2_SB(sb);
1805 if (ocfs2_is_hard_readonly(osb))
1808 mutex_init(&osb->obs_trim_fs_mutex);
1810 status = ocfs2_dlm_init(osb);
1813 if (status == -EBADR && ocfs2_userspace_stack(osb))
1814 mlog(ML_ERROR, "couldn't mount because cluster name on"
1815 " disk does not match the running cluster name.\n");
1819 status = ocfs2_super_lock(osb, 1);
1825 /* This will load up the node map and add ourselves to it. */
1826 status = ocfs2_find_slot(osb);
1829 goto out_super_lock;
1832 /* load all node-local system inodes */
1833 status = ocfs2_init_local_system_inodes(osb);
1836 goto out_super_lock;
1839 status = ocfs2_check_volume(osb);
1842 goto out_system_inodes;
1845 status = ocfs2_truncate_log_init(osb);
1848 goto out_system_inodes;
1851 ocfs2_super_unlock(osb, 1);
1855 if (osb->local_alloc_state == OCFS2_LA_ENABLED)
1856 ocfs2_shutdown_local_alloc(osb);
1857 ocfs2_release_system_inodes(osb);
1858 /* before journal shutdown, we should release slot_info */
1859 ocfs2_free_slot_info(osb);
1860 ocfs2_journal_shutdown(osb);
1862 ocfs2_super_unlock(osb, 1);
1864 ocfs2_dlm_shutdown(osb, 0);
1869 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1871 int tmp, hangup_needed = 0;
1872 struct ocfs2_super *osb = NULL;
1875 trace_ocfs2_dismount_volume(sb);
1881 /* Remove file check sysfs related directores/files,
1882 * and wait for the pending file check operations */
1883 ocfs2_filecheck_remove_sysfs(osb);
1885 kset_unregister(osb->osb_dev_kset);
1887 /* Orphan scan should be stopped as early as possible */
1888 ocfs2_orphan_scan_stop(osb);
1890 ocfs2_disable_quotas(osb);
1892 /* All dquots should be freed by now */
1893 WARN_ON(!llist_empty(&osb->dquot_drop_list));
1894 /* Wait for worker to be done with the work structure in osb */
1895 cancel_work_sync(&osb->dquot_drop_work);
1897 ocfs2_shutdown_local_alloc(osb);
1899 ocfs2_truncate_log_shutdown(osb);
1901 /* This will disable recovery and flush any recovery work. */
1902 ocfs2_recovery_exit(osb);
1904 ocfs2_sync_blockdev(sb);
1906 ocfs2_purge_refcount_trees(osb);
1908 /* No cluster connection means we've failed during mount, so skip
1909 * all the steps which depended on that to complete. */
1911 tmp = ocfs2_super_lock(osb, 1);
1918 if (osb->slot_num != OCFS2_INVALID_SLOT)
1919 ocfs2_put_slot(osb);
1922 ocfs2_super_unlock(osb, 1);
1924 ocfs2_release_system_inodes(osb);
1926 ocfs2_journal_shutdown(osb);
1929 * If we're dismounting due to mount error, mount.ocfs2 will clean
1930 * up heartbeat. If we're a local mount, there is no heartbeat.
1931 * If we failed before we got a uuid_str yet, we can't stop
1932 * heartbeat. Otherwise, do it.
1934 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str &&
1935 !ocfs2_is_hard_readonly(osb))
1939 ocfs2_dlm_shutdown(osb, hangup_needed);
1941 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
1942 debugfs_remove_recursive(osb->osb_debug_root);
1945 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
1947 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1949 if (ocfs2_mount_local(osb))
1950 snprintf(nodestr, sizeof(nodestr), "local");
1952 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1954 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1955 osb->dev_str, nodestr);
1957 ocfs2_delete_osb(osb);
1960 sb->s_fs_info = NULL;
1963 static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1964 unsigned uuid_bytes)
1969 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1971 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
1972 if (osb->uuid_str == NULL)
1975 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1976 /* print with null */
1977 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1978 if (ret != 2) /* drop super cleans up */
1980 /* then only advance past the last char */
1987 /* Make sure entire volume is addressable by our journal. Requires
1988 osb_clusters_at_boot to be valid and for the journal to have been
1989 initialized by ocfs2_journal_init(). */
1990 static int ocfs2_journal_addressable(struct ocfs2_super *osb)
1994 ocfs2_clusters_to_blocks(osb->sb,
1995 osb->osb_clusters_at_boot) - 1;
1997 /* 32-bit block number is always OK. */
1998 if (max_block <= (u32)~0ULL)
2001 /* Volume is "huge", so see if our journal is new enough to
2003 if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb,
2004 OCFS2_FEATURE_COMPAT_JBD2_SB) &&
2005 jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0,
2006 JBD2_FEATURE_INCOMPAT_64BIT))) {
2007 mlog(ML_ERROR, "The journal cannot address the entire volume. "
2008 "Enable the 'block64' journal option with tunefs.ocfs2");
2017 static int ocfs2_initialize_super(struct super_block *sb,
2018 struct buffer_head *bh,
2020 struct ocfs2_blockcheck_stats *stats)
2023 int i, cbits, bbits;
2024 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
2025 struct inode *inode = NULL;
2026 struct ocfs2_super *osb;
2029 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
2036 sb->s_fs_info = osb;
2037 sb->s_op = &ocfs2_sops;
2038 sb->s_d_op = &ocfs2_dentry_ops;
2039 sb->s_export_op = &ocfs2_export_ops;
2040 sb->s_qcop = &dquot_quotactl_sysfile_ops;
2041 sb->dq_op = &ocfs2_quota_operations;
2042 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
2043 sb->s_xattr = ocfs2_xattr_handlers;
2044 sb->s_time_gran = 1;
2045 sb->s_flags |= SB_NOATIME;
2046 /* this is needed to support O_LARGEFILE */
2047 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2048 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
2049 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
2050 memcpy(&sb->s_uuid, di->id2.i_super.s_uuid,
2051 sizeof(di->id2.i_super.s_uuid));
2053 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
2055 for (i = 0; i < 3; i++)
2056 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
2057 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2060 osb->s_sectsize_bits = blksize_bits(sector_size);
2061 BUG_ON(!osb->s_sectsize_bits);
2063 spin_lock_init(&osb->dc_task_lock);
2064 init_waitqueue_head(&osb->dc_event);
2065 osb->dc_work_sequence = 0;
2066 osb->dc_wake_sequence = 0;
2067 INIT_LIST_HEAD(&osb->blocked_lock_list);
2068 osb->blocked_lock_count = 0;
2069 spin_lock_init(&osb->osb_lock);
2070 spin_lock_init(&osb->osb_xattr_lock);
2071 ocfs2_init_steal_slots(osb);
2073 mutex_init(&osb->system_file_mutex);
2075 atomic_set(&osb->alloc_stats.moves, 0);
2076 atomic_set(&osb->alloc_stats.local_data, 0);
2077 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2078 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2079 atomic_set(&osb->alloc_stats.bg_extends, 0);
2081 /* Copy the blockcheck stats from the superblock probe */
2082 osb->osb_ecc_stats = *stats;
2084 ocfs2_init_node_maps(osb);
2086 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2087 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2089 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2090 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2091 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2097 ocfs2_orphan_scan_init(osb);
2099 status = ocfs2_recovery_init(osb);
2101 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2106 init_waitqueue_head(&osb->checkpoint_event);
2108 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2110 osb->slot_num = OCFS2_INVALID_SLOT;
2112 osb->s_xattr_inline_size = le16_to_cpu(
2113 di->id2.i_super.s_xattr_inline_size);
2115 osb->local_alloc_state = OCFS2_LA_UNUSED;
2116 osb->local_alloc_bh = NULL;
2117 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
2119 init_waitqueue_head(&osb->osb_mount_event);
2121 ocfs2_resmap_init(osb, &osb->osb_la_resmap);
2123 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2124 if (!osb->vol_label) {
2125 mlog(ML_ERROR, "unable to alloc vol label\n");
2127 goto out_recovery_map;
2130 osb->slot_recovery_generations =
2131 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2133 if (!osb->slot_recovery_generations) {
2139 init_waitqueue_head(&osb->osb_wipe_event);
2140 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2141 sizeof(*osb->osb_orphan_wipes),
2143 if (!osb->osb_orphan_wipes) {
2146 goto out_slot_recovery_gen;
2149 osb->osb_rf_lock_tree = RB_ROOT;
2151 osb->s_feature_compat =
2152 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2153 osb->s_feature_ro_compat =
2154 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2155 osb->s_feature_incompat =
2156 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2158 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2159 mlog(ML_ERROR, "couldn't mount because of unsupported "
2160 "optional features (%x).\n", i);
2162 goto out_orphan_wipes;
2164 if (!sb_rdonly(osb->sb) && (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2165 mlog(ML_ERROR, "couldn't mount RDWR because of "
2166 "unsupported optional features (%x).\n", i);
2168 goto out_orphan_wipes;
2171 if (ocfs2_clusterinfo_valid(osb)) {
2173 * ci_stack and ci_cluster in ocfs2_cluster_info may not be null
2174 * terminated, so make sure no overflow happens here by using
2175 * memcpy. Destination strings will always be null terminated
2176 * because osb is allocated using kzalloc.
2178 osb->osb_stackflags =
2179 OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
2180 memcpy(osb->osb_cluster_stack,
2181 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2182 OCFS2_STACK_LABEL_LEN);
2183 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2185 "couldn't mount because of an invalid "
2186 "cluster stack label (%s) \n",
2187 osb->osb_cluster_stack);
2189 goto out_orphan_wipes;
2191 memcpy(osb->osb_cluster_name,
2192 OCFS2_RAW_SB(di)->s_cluster_info.ci_cluster,
2193 OCFS2_CLUSTER_NAME_LEN);
2195 /* The empty string is identical with classic tools that
2196 * don't know about s_cluster_info. */
2197 osb->osb_cluster_stack[0] = '\0';
2200 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2204 * This should be done in ocfs2_journal_init(), but any inode
2205 * writes back operation will cause the filesystem to crash.
2207 status = ocfs2_journal_alloc(osb);
2209 goto out_orphan_wipes;
2211 INIT_WORK(&osb->dquot_drop_work, ocfs2_drop_dquot_refs);
2212 init_llist_head(&osb->dquot_drop_list);
2214 /* get some pseudo constants for clustersize bits */
2215 osb->s_clustersize_bits =
2216 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2217 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2219 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2220 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2221 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2222 osb->s_clustersize);
2227 total_blocks = ocfs2_clusters_to_blocks(osb->sb,
2228 le32_to_cpu(di->i_clusters));
2230 status = generic_check_addressable(osb->sb->s_blocksize_bits,
2233 mlog(ML_ERROR, "Volume too large "
2234 "to mount safely on this system");
2239 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2240 sizeof(di->id2.i_super.s_uuid))) {
2241 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2246 strlcpy(osb->vol_label, di->id2.i_super.s_label,
2247 OCFS2_MAX_VOL_LABEL_LEN);
2248 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2249 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2250 osb->first_cluster_group_blkno =
2251 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2252 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
2253 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2254 trace_ocfs2_initialize_super(osb->vol_label, osb->uuid_str,
2255 (unsigned long long)osb->root_blkno,
2256 (unsigned long long)osb->system_dir_blkno,
2257 osb->s_clustersize_bits);
2259 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2260 if (!osb->osb_dlm_debug) {
2266 atomic_set(&osb->vol_state, VOLUME_INIT);
2268 /* load root, system_dir, and all global system inodes */
2269 status = ocfs2_init_global_system_inodes(osb);
2278 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2279 OCFS2_INVALID_SLOT);
2283 goto out_system_inodes;
2286 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
2287 osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
2290 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
2291 osb->s_feature_incompat) * 8;
2293 status = ocfs2_init_slot_info(osb);
2296 goto out_system_inodes;
2299 osb->ocfs2_wq = alloc_ordered_workqueue("ocfs2_wq", WQ_MEM_RECLAIM);
2300 if (!osb->ocfs2_wq) {
2309 ocfs2_free_slot_info(osb);
2311 ocfs2_release_system_inodes(osb);
2313 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2315 kfree(osb->uuid_str);
2317 kfree(osb->journal);
2319 kfree(osb->osb_orphan_wipes);
2320 out_slot_recovery_gen:
2321 kfree(osb->slot_recovery_generations);
2323 kfree(osb->vol_label);
2325 kfree(osb->recovery_map);
2328 sb->s_fs_info = NULL;
2333 * will return: -EAGAIN if it is ok to keep searching for superblocks
2334 * -EINVAL if there is a bad superblock
2337 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2338 struct buffer_head *bh,
2340 struct ocfs2_blockcheck_stats *stats)
2342 int status = -EAGAIN;
2344 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2345 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
2346 /* We have to do a raw check of the feature here */
2347 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2348 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2349 status = ocfs2_block_check_validate(bh->b_data,
2357 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2358 mlog(ML_ERROR, "found superblock with incorrect block "
2359 "size: found %u, should be %u\n",
2360 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2362 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2363 OCFS2_MAJOR_REV_LEVEL ||
2364 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2365 OCFS2_MINOR_REV_LEVEL) {
2366 mlog(ML_ERROR, "found superblock with bad version: "
2367 "found %u.%u, should be %u.%u\n",
2368 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2369 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2370 OCFS2_MAJOR_REV_LEVEL,
2371 OCFS2_MINOR_REV_LEVEL);
2372 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2373 mlog(ML_ERROR, "bad block number on superblock: "
2374 "found %llu, should be %llu\n",
2375 (unsigned long long)le64_to_cpu(di->i_blkno),
2376 (unsigned long long)bh->b_blocknr);
2377 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2378 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2379 mlog(ML_ERROR, "bad cluster size found: %u\n",
2380 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2381 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2382 mlog(ML_ERROR, "bad root_blkno: 0\n");
2383 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2384 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2385 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2387 "Superblock slots found greater than file system "
2388 "maximum: found %u, max %u\n",
2389 le16_to_cpu(di->id2.i_super.s_max_slots),
2398 if (status && status != -EAGAIN)
2403 static int ocfs2_check_volume(struct ocfs2_super *osb)
2408 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2412 /* Init our journal object. */
2413 status = ocfs2_journal_init(osb, &dirty);
2415 mlog(ML_ERROR, "Could not initialize journal!\n");
2419 /* Now that journal has been initialized, check to make sure
2420 entire volume is addressable. */
2421 status = ocfs2_journal_addressable(osb);
2425 /* If the journal was unmounted cleanly then we don't want to
2426 * recover anything. Otherwise, journal_load will do that
2427 * dirty work for us :) */
2429 status = ocfs2_journal_wipe(osb->journal, 0);
2435 printk(KERN_NOTICE "ocfs2: File system on device (%s) was not "
2436 "unmounted cleanly, recovering it.\n", osb->dev_str);
2439 local = ocfs2_mount_local(osb);
2441 /* will play back anything left in the journal. */
2442 status = ocfs2_journal_load(osb->journal, local, dirty);
2444 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2448 if (osb->s_mount_opt & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
2449 jbd2_journal_set_features(osb->journal->j_journal,
2450 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2451 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2453 jbd2_journal_clear_features(osb->journal->j_journal,
2454 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2455 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2458 /* recover my local alloc if we didn't unmount cleanly. */
2459 status = ocfs2_begin_local_alloc_recovery(osb,
2466 /* we complete the recovery process after we've marked
2467 * ourselves as mounted. */
2470 status = ocfs2_load_local_alloc(osb);
2477 /* Recovery will be completed after we've mounted the
2478 * rest of the volume. */
2479 osb->local_alloc_copy = local_alloc;
2483 /* go through each journal, trylock it and if you get the
2484 * lock, and it's marked as dirty, set the bit in the recover
2485 * map and launch a recovery thread for it. */
2486 status = ocfs2_mark_dead_nodes(osb);
2492 status = ocfs2_compute_replay_slots(osb);
2505 * The routine gets called from dismount or close whenever a dismount on
2506 * volume is requested and the osb open count becomes 1.
2507 * It will remove the osb from the global list and also free up all the
2508 * initialized resources and fileobject.
2510 static void ocfs2_delete_osb(struct ocfs2_super *osb)
2512 /* This function assumes that the caller has the main osb resource */
2514 /* ocfs2_initializer_super have already created this workqueue */
2516 destroy_workqueue(osb->ocfs2_wq);
2518 ocfs2_free_slot_info(osb);
2520 kfree(osb->osb_orphan_wipes);
2521 kfree(osb->slot_recovery_generations);
2523 * This belongs in journal shutdown, but because we have to
2524 * allocate osb->journal at the middle of ocfs2_initialize_super(),
2527 kfree(osb->journal);
2528 kfree(osb->local_alloc_copy);
2529 kfree(osb->uuid_str);
2530 kfree(osb->vol_label);
2531 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2532 memset(osb, 0, sizeof(struct ocfs2_super));
2535 /* Depending on the mount option passed, perform one of the following:
2536 * Put OCFS2 into a readonly state (default)
2537 * Return EIO so that only the process errs
2538 * Fix the error as if fsck.ocfs2 -y
2541 static int ocfs2_handle_error(struct super_block *sb)
2543 struct ocfs2_super *osb = OCFS2_SB(sb);
2546 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2547 pr_crit("On-disk corruption discovered. "
2548 "Please run fsck.ocfs2 once the filesystem is unmounted.\n");
2550 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) {
2551 panic("OCFS2: (device %s): panic forced after error\n",
2553 } else if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_CONT) {
2554 pr_crit("OCFS2: Returning error to the calling process.\n");
2556 } else { /* default option */
2558 if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)))
2561 pr_crit("OCFS2: File system is now read-only.\n");
2562 sb->s_flags |= SB_RDONLY;
2563 ocfs2_set_ro_flag(osb, 0);
2569 int __ocfs2_error(struct super_block *sb, const char *function,
2570 const char *fmt, ...)
2572 struct va_format vaf;
2575 va_start(args, fmt);
2579 /* Not using mlog here because we want to show the actual
2580 * function the error came from. */
2581 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %pV",
2582 sb->s_id, function, &vaf);
2586 return ocfs2_handle_error(sb);
2589 /* Handle critical errors. This is intentionally more drastic than
2590 * ocfs2_handle_error, so we only use for things like journal errors,
2592 void __ocfs2_abort(struct super_block *sb, const char *function,
2593 const char *fmt, ...)
2595 struct va_format vaf;
2598 va_start(args, fmt);
2603 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %pV",
2604 sb->s_id, function, &vaf);
2608 /* We don't have the cluster support yet to go straight to
2609 * hard readonly in here. Until then, we want to keep
2610 * ocfs2_abort() so that we can at least mark critical
2613 * TODO: This should abort the journal and alert other nodes
2614 * that our slot needs recovery. */
2616 /* Force a panic(). This stinks, but it's better than letting
2617 * things continue without having a proper hard readonly
2619 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2620 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
2621 ocfs2_handle_error(sb);
2625 * Void signal blockers, because in-kernel sigprocmask() only fails
2626 * when SIG_* is wrong.
2628 void ocfs2_block_signals(sigset_t *oldset)
2633 sigfillset(&blocked);
2634 rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
2638 void ocfs2_unblock_signals(sigset_t *oldset)
2640 int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
2644 module_init(ocfs2_init);
2645 module_exit(ocfs2_exit);