1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * load/unload driver, mount/dismount volumes
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
26 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h>
31 #include <linux/utsname.h>
32 #include <linux/init.h>
33 #include <linux/random.h>
34 #include <linux/statfs.h>
35 #include <linux/moduleparam.h>
36 #include <linux/blkdev.h>
37 #include <linux/socket.h>
38 #include <linux/inet.h>
39 #include <linux/parser.h>
40 #include <linux/crc32.h>
41 #include <linux/debugfs.h>
42 #include <linux/mount.h>
43 #include <linux/seq_file.h>
44 #include <linux/quotaops.h>
46 #define MLOG_MASK_PREFIX ML_SUPER
47 #include <cluster/masklog.h>
51 /* this should be the only file to include a version 1 header */
52 #include "ocfs1_fs_compat.h"
57 #include "extent_map.h"
58 #include "heartbeat.h"
61 #include "localalloc.h"
71 #include "buffer_head_io.h"
73 static struct kmem_cache *ocfs2_inode_cachep = NULL;
74 struct kmem_cache *ocfs2_dquot_cachep;
75 struct kmem_cache *ocfs2_qf_chunk_cachep;
77 /* OCFS2 needs to schedule several differnt types of work which
78 * require cluster locking, disk I/O, recovery waits, etc. Since these
79 * types of work tend to be heavy we avoid using the kernel events
80 * workqueue and schedule on our own. */
81 struct workqueue_struct *ocfs2_wq = NULL;
83 static struct dentry *ocfs2_debugfs_root = NULL;
85 MODULE_AUTHOR("Oracle");
86 MODULE_LICENSE("GPL");
90 unsigned long commit_interval;
91 unsigned long mount_opt;
92 unsigned int atime_quantum;
94 unsigned int localalloc_opt;
95 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
98 static int ocfs2_parse_options(struct super_block *sb, char *options,
99 struct mount_options *mopt,
101 static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
102 static void ocfs2_put_super(struct super_block *sb);
103 static int ocfs2_mount_volume(struct super_block *sb);
104 static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
105 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
106 static int ocfs2_initialize_mem_caches(void);
107 static void ocfs2_free_mem_caches(void);
108 static void ocfs2_delete_osb(struct ocfs2_super *osb);
110 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
112 static int ocfs2_sync_fs(struct super_block *sb, int wait);
114 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
115 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
116 static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
117 static int ocfs2_check_volume(struct ocfs2_super *osb);
118 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
119 struct buffer_head *bh,
121 static int ocfs2_initialize_super(struct super_block *sb,
122 struct buffer_head *bh,
124 static int ocfs2_get_sector(struct super_block *sb,
125 struct buffer_head **bh,
128 static void ocfs2_write_super(struct super_block *sb);
129 static struct inode *ocfs2_alloc_inode(struct super_block *sb);
130 static void ocfs2_destroy_inode(struct inode *inode);
131 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
132 static int ocfs2_enable_quotas(struct ocfs2_super *osb);
133 static void ocfs2_disable_quotas(struct ocfs2_super *osb);
135 static const struct super_operations ocfs2_sops = {
136 .statfs = ocfs2_statfs,
137 .alloc_inode = ocfs2_alloc_inode,
138 .destroy_inode = ocfs2_destroy_inode,
139 .drop_inode = ocfs2_drop_inode,
140 .clear_inode = ocfs2_clear_inode,
141 .delete_inode = ocfs2_delete_inode,
142 .sync_fs = ocfs2_sync_fs,
143 .write_super = ocfs2_write_super,
144 .put_super = ocfs2_put_super,
145 .remount_fs = ocfs2_remount,
146 .show_options = ocfs2_show_options,
147 .quota_read = ocfs2_quota_read,
148 .quota_write = ocfs2_quota_write,
177 static const match_table_t tokens = {
178 {Opt_barrier, "barrier=%u"},
179 {Opt_err_panic, "errors=panic"},
180 {Opt_err_ro, "errors=remount-ro"},
182 {Opt_nointr, "nointr"},
183 {Opt_hb_none, OCFS2_HB_NONE},
184 {Opt_hb_local, OCFS2_HB_LOCAL},
185 {Opt_data_ordered, "data=ordered"},
186 {Opt_data_writeback, "data=writeback"},
187 {Opt_atime_quantum, "atime_quantum=%u"},
188 {Opt_slot, "preferred_slot=%u"},
189 {Opt_commit, "commit=%u"},
190 {Opt_localalloc, "localalloc=%d"},
191 {Opt_localflocks, "localflocks"},
192 {Opt_stack, "cluster_stack=%s"},
193 {Opt_user_xattr, "user_xattr"},
194 {Opt_nouser_xattr, "nouser_xattr"},
195 {Opt_inode64, "inode64"},
197 {Opt_noacl, "noacl"},
198 {Opt_usrquota, "usrquota"},
199 {Opt_grpquota, "grpquota"},
204 * write_super and sync_fs ripped right out of ext3.
206 static void ocfs2_write_super(struct super_block *sb)
208 if (mutex_trylock(&sb->s_lock) != 0)
213 static int ocfs2_sync_fs(struct super_block *sb, int wait)
217 struct ocfs2_super *osb = OCFS2_SB(sb);
221 if (ocfs2_is_hard_readonly(osb))
225 status = ocfs2_flush_truncate_log(osb);
229 ocfs2_schedule_truncate_log_flush(osb, 0);
232 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
235 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
241 static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
243 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
244 && (ino == USER_QUOTA_SYSTEM_INODE
245 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
247 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
248 && (ino == GROUP_QUOTA_SYSTEM_INODE
249 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
254 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
256 struct inode *new = NULL;
262 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
264 status = PTR_ERR(new);
268 osb->root_inode = new;
270 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
272 status = PTR_ERR(new);
276 osb->sys_root_inode = new;
278 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
279 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
280 if (!ocfs2_need_system_inode(osb, i))
282 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
284 ocfs2_release_system_inodes(osb);
287 /* FIXME: Should ERROR_RO_FS */
288 mlog(ML_ERROR, "Unable to load system inode %d, "
289 "possibly corrupt fs?", i);
292 // the array now has one ref, so drop this one
301 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
303 struct inode *new = NULL;
309 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
310 i < NUM_SYSTEM_INODES;
312 if (!ocfs2_need_system_inode(osb, i))
314 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
316 ocfs2_release_system_inodes(osb);
318 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
319 status, i, osb->slot_num);
322 /* the array now has one ref, so drop this one */
331 static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
338 for (i = 0; i < NUM_SYSTEM_INODES; i++) {
339 inode = osb->system_inodes[i];
342 osb->system_inodes[i] = NULL;
346 inode = osb->sys_root_inode;
349 osb->sys_root_inode = NULL;
352 inode = osb->root_inode;
355 osb->root_inode = NULL;
361 /* We're allocating fs objects, use GFP_NOFS */
362 static struct inode *ocfs2_alloc_inode(struct super_block *sb)
364 struct ocfs2_inode_info *oi;
366 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
370 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
371 return &oi->vfs_inode;
374 static void ocfs2_destroy_inode(struct inode *inode)
376 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
379 static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
382 unsigned int bytes = 1 << cbits;
383 unsigned int trim = bytes;
384 unsigned int bitshift = 32;
387 * i_size and all block offsets in ocfs2 are always 64 bits
388 * wide. i_clusters is 32 bits, in cluster-sized units. So on
389 * 64 bit platforms, cluster size will be the limiting factor.
392 #if BITS_PER_LONG == 32
393 # if defined(CONFIG_LBD)
394 BUILD_BUG_ON(sizeof(sector_t) != 8);
396 * We might be limited by page cache size.
398 if (bytes > PAGE_CACHE_SIZE) {
399 bytes = PAGE_CACHE_SIZE;
402 * Shift by 31 here so that we don't get larger than
409 * We are limited by the size of sector_t. Use block size, as
410 * that's what we expose to the VFS.
419 * Trim by a whole cluster when we can actually approach the
420 * on-disk limits. Otherwise we can overflow i_clusters when
421 * an extent start is at the max offset.
423 return (((unsigned long long)bytes) << bitshift) - trim;
426 static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
428 int incompat_features;
430 struct mount_options parsed_options;
431 struct ocfs2_super *osb = OCFS2_SB(sb);
433 if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) {
438 if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
439 (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
441 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
445 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
446 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
448 mlog(ML_ERROR, "Cannot change data mode on remount\n");
452 /* Probably don't want this on remount; it might
453 * mess with other nodes */
454 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
455 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
457 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
461 /* We're going to/from readonly mode. */
462 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
463 /* Disable quota accounting before remounting RO */
464 if (*flags & MS_RDONLY) {
465 ret = ocfs2_susp_quotas(osb, 0);
469 /* Lock here so the check of HARD_RO and the potential
470 * setting of SOFT_RO is atomic. */
471 spin_lock(&osb->osb_lock);
472 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
473 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
478 if (*flags & MS_RDONLY) {
479 mlog(0, "Going to ro mode.\n");
480 sb->s_flags |= MS_RDONLY;
481 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
483 mlog(0, "Making ro filesystem writeable.\n");
485 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
486 mlog(ML_ERROR, "Cannot remount RDWR "
487 "filesystem due to previous errors.\n");
491 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
492 if (incompat_features) {
493 mlog(ML_ERROR, "Cannot remount RDWR because "
494 "of unsupported optional features "
495 "(%x).\n", incompat_features);
499 sb->s_flags &= ~MS_RDONLY;
500 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
503 spin_unlock(&osb->osb_lock);
504 /* Enable quota accounting after remounting RW */
505 if (!ret && !(*flags & MS_RDONLY)) {
506 if (sb_any_quota_suspended(sb))
507 ret = ocfs2_susp_quotas(osb, 1);
509 ret = ocfs2_enable_quotas(osb);
511 /* Return back changes... */
512 spin_lock(&osb->osb_lock);
513 sb->s_flags |= MS_RDONLY;
514 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
515 spin_unlock(&osb->osb_lock);
522 /* Only save off the new mount options in case of a successful
524 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
525 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
526 osb->s_mount_opt = parsed_options.mount_opt;
527 osb->s_atime_quantum = parsed_options.atime_quantum;
528 osb->preferred_slot = parsed_options.slot;
529 if (parsed_options.commit_interval)
530 osb->osb_commit_interval = parsed_options.commit_interval;
532 if (!ocfs2_is_hard_readonly(osb))
533 ocfs2_set_journal_params(osb);
539 static int ocfs2_sb_probe(struct super_block *sb,
540 struct buffer_head **bh,
544 struct ocfs1_vol_disk_hdr *hdr;
545 struct ocfs2_dinode *di;
551 *sector_size = bdev_hardsect_size(sb->s_bdev);
552 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
553 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
554 *sector_size, OCFS2_MAX_BLOCKSIZE);
559 /* Can this really happen? */
560 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
561 *sector_size = OCFS2_MIN_BLOCKSIZE;
563 /* check block zero for old format */
564 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
569 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
570 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
571 mlog(ML_ERROR, "incompatible version: %u.%u\n",
572 hdr->major_version, hdr->minor_version);
575 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
576 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
577 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
584 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
585 "upgraded before mounting with ocfs v2\n");
590 * Now check at magic offset for 512, 1024, 2048, 4096
591 * blocksizes. 4096 is the maximum blocksize because it is
592 * the minimum clustersize.
595 for (blksize = *sector_size;
596 blksize <= OCFS2_MAX_BLOCKSIZE;
598 tmpstat = ocfs2_get_sector(sb, bh,
599 OCFS2_SUPER_BLOCK_BLKNO,
606 di = (struct ocfs2_dinode *) (*bh)->b_data;
607 status = ocfs2_verify_volume(di, *bh, blksize);
612 if (status != -EAGAIN)
620 static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
622 if (ocfs2_mount_local(osb)) {
623 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
624 mlog(ML_ERROR, "Cannot heartbeat on a locally "
625 "mounted device.\n");
630 if (ocfs2_userspace_stack(osb)) {
631 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
632 mlog(ML_ERROR, "Userspace stack expected, but "
633 "o2cb heartbeat arguments passed to mount\n");
638 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
639 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
640 !ocfs2_userspace_stack(osb)) {
641 mlog(ML_ERROR, "Heartbeat has to be started to mount "
642 "a read-write clustered device.\n");
651 * If we're using a userspace stack, mount should have passed
652 * a name that matches the disk. If not, mount should not
653 * have passed a stack.
655 static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
656 struct mount_options *mopt)
658 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
660 "cluster stack passed to mount, but this filesystem "
661 "does not support it\n");
665 if (ocfs2_userspace_stack(osb) &&
666 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
667 OCFS2_STACK_LABEL_LEN)) {
669 "cluster stack passed to mount (\"%s\") does not "
670 "match the filesystem (\"%s\")\n",
672 osb->osb_cluster_stack);
679 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
682 struct super_block *sb = osb->sb;
683 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
684 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
687 for (type = 0; type < MAXQUOTAS; type++) {
688 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
691 status = vfs_quota_enable(
692 sb_dqopt(sb)->files[type],
696 status = vfs_quota_disable(sb, type,
702 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
703 "remount (error = %d).\n", status);
707 static int ocfs2_enable_quotas(struct ocfs2_super *osb)
709 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
710 struct super_block *sb = osb->sb;
711 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
712 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
713 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
714 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
718 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
719 for (type = 0; type < MAXQUOTAS; type++) {
720 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
722 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
728 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
729 DQUOT_USAGE_ENABLED);
734 for (type = 0; type < MAXQUOTAS; type++)
738 ocfs2_disable_quotas(osb);
739 for (type = 0; type < MAXQUOTAS; type++)
745 static void ocfs2_disable_quotas(struct ocfs2_super *osb)
749 struct super_block *sb = osb->sb;
751 /* We mostly ignore errors in this function because there's not much
752 * we can do when we see them */
753 for (type = 0; type < MAXQUOTAS; type++) {
754 if (!sb_has_quota_loaded(sb, type))
756 inode = igrab(sb->s_dquot.files[type]);
757 /* Turn off quotas. This will remove all dquot structures from
758 * memory and so they will be automatically synced to global
760 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
761 DQUOT_LIMITS_ENABLED);
768 /* Handle quota on quotactl */
769 static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
770 char *path, int remount)
772 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
773 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
775 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
779 return 0; /* Just ignore it has been handled in
781 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
782 format_id, DQUOT_LIMITS_ENABLED);
785 /* Handle quota off quotactl */
786 static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
789 return 0; /* Ignore now and handle later in
791 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
794 static struct quotactl_ops ocfs2_quotactl_ops = {
795 .quota_on = ocfs2_quota_on,
796 .quota_off = ocfs2_quota_off,
797 .quota_sync = vfs_quota_sync,
798 .get_info = vfs_get_dqinfo,
799 .set_info = vfs_set_dqinfo,
800 .get_dqblk = vfs_get_dqblk,
801 .set_dqblk = vfs_set_dqblk,
804 static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
807 int status, sector_size;
808 struct mount_options parsed_options;
809 struct inode *inode = NULL;
810 struct ocfs2_super *osb = NULL;
811 struct buffer_head *bh = NULL;
814 mlog_entry("%p, %p, %i", sb, data, silent);
816 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
818 goto read_super_error;
821 /* probe for superblock */
822 status = ocfs2_sb_probe(sb, &bh, §or_size);
824 mlog(ML_ERROR, "superblock probe failed!\n");
825 goto read_super_error;
828 status = ocfs2_initialize_super(sb, bh, sector_size);
832 goto read_super_error;
837 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
838 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
840 osb->s_mount_opt = parsed_options.mount_opt;
841 osb->s_atime_quantum = parsed_options.atime_quantum;
842 osb->preferred_slot = parsed_options.slot;
843 osb->osb_commit_interval = parsed_options.commit_interval;
844 osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
845 osb->local_alloc_bits = osb->local_alloc_default_bits;
846 if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA &&
847 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
848 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
850 mlog(ML_ERROR, "User quotas were requested, but this "
851 "filesystem does not have the feature enabled.\n");
852 goto read_super_error;
854 if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA &&
855 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
856 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
858 mlog(ML_ERROR, "Group quotas were requested, but this "
859 "filesystem does not have the feature enabled.\n");
860 goto read_super_error;
863 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
865 goto read_super_error;
867 sb->s_magic = OCFS2_SUPER_MAGIC;
869 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
870 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
872 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
874 if (bdev_read_only(sb->s_bdev)) {
875 if (!(sb->s_flags & MS_RDONLY)) {
877 mlog(ML_ERROR, "Readonly device detected but readonly "
878 "mount was not specified.\n");
879 goto read_super_error;
882 /* You should not be able to start a local heartbeat
883 * on a readonly device. */
884 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
886 mlog(ML_ERROR, "Local heartbeat specified on readonly "
888 goto read_super_error;
891 status = ocfs2_check_journals_nolocks(osb);
893 if (status == -EROFS)
894 mlog(ML_ERROR, "Recovery required on readonly "
895 "file system, but write access is "
899 goto read_super_error;
902 ocfs2_set_ro_flag(osb, 1);
904 printk(KERN_NOTICE "Readonly device detected. No cluster "
905 "services will be utilized for this mount. Recovery "
906 "will be skipped.\n");
909 if (!ocfs2_is_hard_readonly(osb)) {
910 if (sb->s_flags & MS_RDONLY)
911 ocfs2_set_ro_flag(osb, 0);
914 status = ocfs2_verify_heartbeat(osb);
917 goto read_super_error;
920 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
922 if (!osb->osb_debug_root) {
924 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
925 goto read_super_error;
928 status = ocfs2_mount_volume(sb);
930 inode = igrab(osb->root_inode);
933 goto read_super_error;
938 goto read_super_error;
941 root = d_alloc_root(inode);
945 goto read_super_error;
950 ocfs2_complete_mount_recovery(osb);
952 if (ocfs2_mount_local(osb))
953 snprintf(nodestr, sizeof(nodestr), "local");
955 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
957 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
958 "with %s data mode.\n",
959 osb->dev_str, nodestr, osb->slot_num,
960 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
963 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
964 wake_up(&osb->osb_mount_event);
966 /* Now we can initialize quotas because we can afford to wait
967 * for cluster locks recovery now. That also means that truncation
968 * log recovery can happen but that waits for proper quota setup */
969 if (!(sb->s_flags & MS_RDONLY)) {
970 status = ocfs2_enable_quotas(osb);
972 /* We have to err-out specially here because
973 * s_root is already set */
975 atomic_set(&osb->vol_state, VOLUME_DISABLED);
976 wake_up(&osb->osb_mount_event);
982 ocfs2_complete_quota_recovery(osb);
984 /* Now we wake up again for processes waiting for quotas */
985 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
986 wake_up(&osb->osb_mount_event);
998 atomic_set(&osb->vol_state, VOLUME_DISABLED);
999 wake_up(&osb->osb_mount_event);
1000 ocfs2_dismount_volume(sb, 1);
1007 static int ocfs2_get_sb(struct file_system_type *fs_type,
1009 const char *dev_name,
1011 struct vfsmount *mnt)
1013 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1017 static struct file_system_type ocfs2_fs_type = {
1018 .owner = THIS_MODULE,
1020 .get_sb = ocfs2_get_sb, /* is this called when we mount
1022 .kill_sb = kill_block_super, /* set to the generic one
1023 * right now, but do we
1024 * need to change that? */
1025 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
1029 static int ocfs2_parse_options(struct super_block *sb,
1031 struct mount_options *mopt,
1037 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1038 options ? options : "(none)");
1040 mopt->commit_interval = 0;
1041 mopt->mount_opt = 0;
1042 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1043 mopt->slot = OCFS2_INVALID_SLOT;
1044 mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
1045 mopt->cluster_stack[0] = '\0';
1052 while ((p = strsep(&options, ",")) != NULL) {
1054 substring_t args[MAX_OPT_ARGS];
1059 token = match_token(p, tokens, args);
1062 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
1065 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
1068 if (match_int(&args[0], &option)) {
1073 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
1075 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
1078 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
1081 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
1084 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
1087 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1089 case Opt_data_ordered:
1090 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
1092 case Opt_data_writeback:
1093 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
1095 case Opt_user_xattr:
1096 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1098 case Opt_nouser_xattr:
1099 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1101 case Opt_atime_quantum:
1102 if (match_int(&args[0], &option)) {
1107 mopt->atime_quantum = option;
1111 if (match_int(&args[0], &option)) {
1116 mopt->slot = (s16)option;
1120 if (match_int(&args[0], &option)) {
1127 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1128 mopt->commit_interval = HZ * option;
1130 case Opt_localalloc:
1132 if (match_int(&args[0], &option)) {
1136 if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1137 mopt->localalloc_opt = option;
1139 case Opt_localflocks:
1141 * Changing this during remount could race
1142 * flock() requests, or "unbalance" existing
1143 * ones (e.g., a lock is taken in one mode but
1144 * dropped in the other). If users care enough
1145 * to flip locking modes during remount, we
1146 * could add a "local" flag to individual
1147 * flock structures for proper tracking of
1151 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1154 /* Check both that the option we were passed
1155 * is of the right length and that it is a proper
1156 * string of the right length.
1158 if (((args[0].to - args[0].from) !=
1159 OCFS2_STACK_LABEL_LEN) ||
1160 (strnlen(args[0].from,
1161 OCFS2_STACK_LABEL_LEN) !=
1162 OCFS2_STACK_LABEL_LEN)) {
1164 "Invalid cluster_stack option\n");
1168 memcpy(mopt->cluster_stack, args[0].from,
1169 OCFS2_STACK_LABEL_LEN);
1170 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1173 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1176 /* We check only on remount, otherwise features
1177 * aren't yet initialized. */
1178 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1179 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1180 mlog(ML_ERROR, "User quota requested but "
1181 "filesystem feature is not set\n");
1185 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1188 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1189 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1190 mlog(ML_ERROR, "Group quota requested but "
1191 "filesystem feature is not set\n");
1195 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1197 #ifdef CONFIG_OCFS2_FS_POSIX_ACL
1199 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1202 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1207 printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
1212 "Unrecognized mount option \"%s\" "
1213 "or missing value\n", p);
1226 static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1228 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1229 unsigned long opts = osb->s_mount_opt;
1230 unsigned int local_alloc_megs;
1232 if (opts & OCFS2_MOUNT_HB_LOCAL)
1233 seq_printf(s, ",_netdev,heartbeat=local");
1235 seq_printf(s, ",heartbeat=none");
1237 if (opts & OCFS2_MOUNT_NOINTR)
1238 seq_printf(s, ",nointr");
1240 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1241 seq_printf(s, ",data=writeback");
1243 seq_printf(s, ",data=ordered");
1245 if (opts & OCFS2_MOUNT_BARRIER)
1246 seq_printf(s, ",barrier=1");
1248 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1249 seq_printf(s, ",errors=panic");
1251 seq_printf(s, ",errors=remount-ro");
1253 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1254 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1256 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1257 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1259 if (osb->osb_commit_interval)
1260 seq_printf(s, ",commit=%u",
1261 (unsigned) (osb->osb_commit_interval / HZ));
1263 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1264 if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1265 seq_printf(s, ",localalloc=%d", local_alloc_megs);
1267 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1268 seq_printf(s, ",localflocks,");
1270 if (osb->osb_cluster_stack[0])
1271 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1272 osb->osb_cluster_stack);
1273 if (opts & OCFS2_MOUNT_USRQUOTA)
1274 seq_printf(s, ",usrquota");
1275 if (opts & OCFS2_MOUNT_GRPQUOTA)
1276 seq_printf(s, ",grpquota");
1278 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1279 seq_printf(s, ",nouser_xattr");
1281 seq_printf(s, ",user_xattr");
1283 if (opts & OCFS2_MOUNT_INODE64)
1284 seq_printf(s, ",inode64");
1286 #ifdef CONFIG_OCFS2_FS_POSIX_ACL
1287 if (opts & OCFS2_MOUNT_POSIX_ACL)
1288 seq_printf(s, ",acl");
1290 seq_printf(s, ",noacl");
1296 static int __init ocfs2_init(void)
1302 ocfs2_print_version();
1304 status = init_ocfs2_uptodate_cache();
1310 status = ocfs2_initialize_mem_caches();
1316 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1322 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1323 if (!ocfs2_debugfs_root) {
1325 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1328 status = ocfs2_quota_setup();
1332 ocfs2_set_locking_protocol();
1334 status = register_quota_format(&ocfs2_quota_format);
1337 ocfs2_quota_shutdown();
1338 ocfs2_free_mem_caches();
1339 exit_ocfs2_uptodate_cache();
1345 return register_filesystem(&ocfs2_fs_type);
1350 static void __exit ocfs2_exit(void)
1354 ocfs2_quota_shutdown();
1357 flush_workqueue(ocfs2_wq);
1358 destroy_workqueue(ocfs2_wq);
1361 unregister_quota_format(&ocfs2_quota_format);
1363 debugfs_remove(ocfs2_debugfs_root);
1365 ocfs2_free_mem_caches();
1367 unregister_filesystem(&ocfs2_fs_type);
1369 exit_ocfs2_uptodate_cache();
1374 static void ocfs2_put_super(struct super_block *sb)
1376 mlog_entry("(0x%p)\n", sb);
1378 ocfs2_sync_blockdev(sb);
1379 ocfs2_dismount_volume(sb, 0);
1384 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1386 struct ocfs2_super *osb;
1387 u32 numbits, freebits;
1389 struct ocfs2_dinode *bm_lock;
1390 struct buffer_head *bh = NULL;
1391 struct inode *inode = NULL;
1393 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
1395 osb = OCFS2_SB(dentry->d_sb);
1397 inode = ocfs2_get_system_file_inode(osb,
1398 GLOBAL_BITMAP_SYSTEM_INODE,
1399 OCFS2_INVALID_SLOT);
1401 mlog(ML_ERROR, "failed to get bitmap inode\n");
1406 status = ocfs2_inode_lock(inode, &bh, 0);
1412 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1414 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1415 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1417 buf->f_type = OCFS2_SUPER_MAGIC;
1418 buf->f_bsize = dentry->d_sb->s_blocksize;
1419 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1420 buf->f_blocks = ((sector_t) numbits) *
1421 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1422 buf->f_bfree = ((sector_t) freebits) *
1423 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1424 buf->f_bavail = buf->f_bfree;
1425 buf->f_files = numbits;
1426 buf->f_ffree = freebits;
1430 ocfs2_inode_unlock(inode, 0);
1441 static void ocfs2_inode_init_once(void *data)
1443 struct ocfs2_inode_info *oi = data;
1446 oi->ip_open_count = 0;
1447 spin_lock_init(&oi->ip_lock);
1448 ocfs2_extent_map_init(&oi->vfs_inode);
1449 INIT_LIST_HEAD(&oi->ip_io_markers);
1450 oi->ip_created_trans = 0;
1451 oi->ip_last_trans = 0;
1452 oi->ip_dir_start_lookup = 0;
1454 init_rwsem(&oi->ip_alloc_sem);
1455 init_rwsem(&oi->ip_xattr_sem);
1456 mutex_init(&oi->ip_io_mutex);
1458 oi->ip_blkno = 0ULL;
1459 oi->ip_clusters = 0;
1461 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
1462 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
1463 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
1465 ocfs2_metadata_cache_init(&oi->vfs_inode);
1467 inode_init_once(&oi->vfs_inode);
1470 static int ocfs2_initialize_mem_caches(void)
1472 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
1473 sizeof(struct ocfs2_inode_info),
1475 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1477 ocfs2_inode_init_once);
1478 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1479 sizeof(struct ocfs2_dquot),
1481 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1484 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1485 sizeof(struct ocfs2_quota_chunk),
1487 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1489 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1490 !ocfs2_qf_chunk_cachep) {
1491 if (ocfs2_inode_cachep)
1492 kmem_cache_destroy(ocfs2_inode_cachep);
1493 if (ocfs2_dquot_cachep)
1494 kmem_cache_destroy(ocfs2_dquot_cachep);
1495 if (ocfs2_qf_chunk_cachep)
1496 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1503 static void ocfs2_free_mem_caches(void)
1505 if (ocfs2_inode_cachep)
1506 kmem_cache_destroy(ocfs2_inode_cachep);
1507 ocfs2_inode_cachep = NULL;
1509 if (ocfs2_dquot_cachep)
1510 kmem_cache_destroy(ocfs2_dquot_cachep);
1511 ocfs2_dquot_cachep = NULL;
1513 if (ocfs2_qf_chunk_cachep)
1514 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1515 ocfs2_qf_chunk_cachep = NULL;
1518 static int ocfs2_get_sector(struct super_block *sb,
1519 struct buffer_head **bh,
1523 if (!sb_set_blocksize(sb, sect_size)) {
1524 mlog(ML_ERROR, "unable to set blocksize\n");
1528 *bh = sb_getblk(sb, block);
1534 if (!buffer_dirty(*bh))
1535 clear_buffer_uptodate(*bh);
1537 ll_rw_block(READ, 1, bh);
1538 wait_on_buffer(*bh);
1542 static int ocfs2_mount_volume(struct super_block *sb)
1545 int unlock_super = 0;
1546 struct ocfs2_super *osb = OCFS2_SB(sb);
1550 if (ocfs2_is_hard_readonly(osb))
1553 status = ocfs2_dlm_init(osb);
1559 status = ocfs2_super_lock(osb, 1);
1566 /* This will load up the node map and add ourselves to it. */
1567 status = ocfs2_find_slot(osb);
1573 /* load all node-local system inodes */
1574 status = ocfs2_init_local_system_inodes(osb);
1580 status = ocfs2_check_volume(osb);
1586 status = ocfs2_truncate_log_init(osb);
1592 if (ocfs2_mount_local(osb))
1597 ocfs2_super_unlock(osb, 1);
1603 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1605 int tmp, hangup_needed = 0;
1606 struct ocfs2_super *osb = NULL;
1609 mlog_entry("(0x%p)\n", sb);
1615 ocfs2_disable_quotas(osb);
1617 ocfs2_shutdown_local_alloc(osb);
1619 ocfs2_truncate_log_shutdown(osb);
1621 /* This will disable recovery and flush any recovery work. */
1622 ocfs2_recovery_exit(osb);
1624 ocfs2_journal_shutdown(osb);
1626 ocfs2_sync_blockdev(sb);
1628 /* No cluster connection means we've failed during mount, so skip
1629 * all the steps which depended on that to complete. */
1631 tmp = ocfs2_super_lock(osb, 1);
1638 if (osb->slot_num != OCFS2_INVALID_SLOT)
1639 ocfs2_put_slot(osb);
1642 ocfs2_super_unlock(osb, 1);
1644 ocfs2_release_system_inodes(osb);
1647 * If we're dismounting due to mount error, mount.ocfs2 will clean
1648 * up heartbeat. If we're a local mount, there is no heartbeat.
1649 * If we failed before we got a uuid_str yet, we can't stop
1650 * heartbeat. Otherwise, do it.
1652 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
1656 ocfs2_dlm_shutdown(osb, hangup_needed);
1658 debugfs_remove(osb->osb_debug_root);
1661 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
1663 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1665 if (ocfs2_mount_local(osb))
1666 snprintf(nodestr, sizeof(nodestr), "local");
1668 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1670 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1671 osb->dev_str, nodestr);
1673 ocfs2_delete_osb(osb);
1676 sb->s_fs_info = NULL;
1679 static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1680 unsigned uuid_bytes)
1685 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1687 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
1688 if (osb->uuid_str == NULL)
1691 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1692 /* print with null */
1693 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1694 if (ret != 2) /* drop super cleans up */
1696 /* then only advance past the last char */
1703 static int ocfs2_initialize_super(struct super_block *sb,
1704 struct buffer_head *bh,
1708 int i, cbits, bbits;
1709 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
1710 struct inode *inode = NULL;
1711 struct ocfs2_journal *journal;
1712 __le32 uuid_net_key;
1713 struct ocfs2_super *osb;
1717 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
1724 sb->s_fs_info = osb;
1725 sb->s_op = &ocfs2_sops;
1726 sb->s_export_op = &ocfs2_export_ops;
1727 sb->s_qcop = &ocfs2_quotactl_ops;
1728 sb->dq_op = &ocfs2_quota_operations;
1729 sb->s_xattr = ocfs2_xattr_handlers;
1730 sb->s_time_gran = 1;
1731 sb->s_flags |= MS_NOATIME;
1732 /* this is needed to support O_LARGEFILE */
1733 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1734 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1735 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
1738 /* Save off for ocfs2_rw_direct */
1739 osb->s_sectsize_bits = blksize_bits(sector_size);
1740 BUG_ON(!osb->s_sectsize_bits);
1742 spin_lock_init(&osb->dc_task_lock);
1743 init_waitqueue_head(&osb->dc_event);
1744 osb->dc_work_sequence = 0;
1745 osb->dc_wake_sequence = 0;
1746 INIT_LIST_HEAD(&osb->blocked_lock_list);
1747 osb->blocked_lock_count = 0;
1748 spin_lock_init(&osb->osb_lock);
1749 ocfs2_init_inode_steal_slot(osb);
1751 atomic_set(&osb->alloc_stats.moves, 0);
1752 atomic_set(&osb->alloc_stats.local_data, 0);
1753 atomic_set(&osb->alloc_stats.bitmap_data, 0);
1754 atomic_set(&osb->alloc_stats.bg_allocs, 0);
1755 atomic_set(&osb->alloc_stats.bg_extends, 0);
1757 ocfs2_init_node_maps(osb);
1759 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
1760 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
1762 status = ocfs2_recovery_init(osb);
1764 mlog(ML_ERROR, "Unable to initialize recovery state\n");
1769 init_waitqueue_head(&osb->checkpoint_event);
1770 atomic_set(&osb->needs_checkpoint, 0);
1772 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1774 osb->slot_num = OCFS2_INVALID_SLOT;
1776 osb->s_xattr_inline_size = le16_to_cpu(
1777 di->id2.i_super.s_xattr_inline_size);
1779 osb->local_alloc_state = OCFS2_LA_UNUSED;
1780 osb->local_alloc_bh = NULL;
1781 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
1783 init_waitqueue_head(&osb->osb_mount_event);
1785 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
1786 if (!osb->vol_label) {
1787 mlog(ML_ERROR, "unable to alloc vol label\n");
1792 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
1793 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
1794 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
1799 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
1801 osb->slot_recovery_generations =
1802 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
1804 if (!osb->slot_recovery_generations) {
1810 init_waitqueue_head(&osb->osb_wipe_event);
1811 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
1812 sizeof(*osb->osb_orphan_wipes),
1814 if (!osb->osb_orphan_wipes) {
1820 osb->s_feature_compat =
1821 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
1822 osb->s_feature_ro_compat =
1823 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
1824 osb->s_feature_incompat =
1825 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
1827 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
1828 mlog(ML_ERROR, "couldn't mount because of unsupported "
1829 "optional features (%x).\n", i);
1833 if (!(osb->sb->s_flags & MS_RDONLY) &&
1834 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
1835 mlog(ML_ERROR, "couldn't mount RDWR because of "
1836 "unsupported optional features (%x).\n", i);
1841 if (ocfs2_userspace_stack(osb)) {
1842 memcpy(osb->osb_cluster_stack,
1843 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
1844 OCFS2_STACK_LABEL_LEN);
1845 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1846 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
1848 "couldn't mount because of an invalid "
1849 "cluster stack label (%s) \n",
1850 osb->osb_cluster_stack);
1855 /* The empty string is identical with classic tools that
1856 * don't know about s_cluster_info. */
1857 osb->osb_cluster_stack[0] = '\0';
1860 get_random_bytes(&osb->s_next_generation, sizeof(u32));
1863 * This should be done in ocfs2_journal_init(), but unknown
1864 * ordering issues will cause the filesystem to crash.
1865 * If anyone wants to figure out what part of the code
1866 * refers to osb->journal before ocfs2_journal_init() is run,
1869 /* initialize our journal structure */
1871 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
1873 mlog(ML_ERROR, "unable to alloc journal\n");
1877 osb->journal = journal;
1878 journal->j_osb = osb;
1880 atomic_set(&journal->j_num_trans, 0);
1881 init_rwsem(&journal->j_trans_barrier);
1882 init_waitqueue_head(&journal->j_checkpointed);
1883 spin_lock_init(&journal->j_lock);
1884 journal->j_trans_id = (unsigned long) 1;
1885 INIT_LIST_HEAD(&journal->j_la_cleanups);
1886 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
1887 journal->j_state = OCFS2_JOURNAL_FREE;
1889 /* get some pseudo constants for clustersize bits */
1890 osb->s_clustersize_bits =
1891 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1892 osb->s_clustersize = 1 << osb->s_clustersize_bits;
1893 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
1895 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
1896 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
1897 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
1898 osb->s_clustersize);
1903 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
1905 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
1906 "what jbd can address in 32 bits.\n");
1911 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
1912 sizeof(di->id2.i_super.s_uuid))) {
1913 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
1918 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
1920 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
1921 osb->vol_label[63] = '\0';
1922 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
1923 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
1924 osb->first_cluster_group_blkno =
1925 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
1926 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
1927 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1928 mlog(0, "vol_label: %s\n", osb->vol_label);
1929 mlog(0, "uuid: %s\n", osb->uuid_str);
1930 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
1931 (unsigned long long)osb->root_blkno,
1932 (unsigned long long)osb->system_dir_blkno);
1934 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
1935 if (!osb->osb_dlm_debug) {
1941 atomic_set(&osb->vol_state, VOLUME_INIT);
1943 /* load root, system_dir, and all global system inodes */
1944 status = ocfs2_init_global_system_inodes(osb);
1953 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
1954 OCFS2_INVALID_SLOT);
1961 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
1964 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
1966 status = ocfs2_init_slot_info(osb);
1978 * will return: -EAGAIN if it is ok to keep searching for superblocks
1979 * -EINVAL if there is a bad superblock
1982 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
1983 struct buffer_head *bh,
1986 int status = -EAGAIN;
1990 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
1991 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
1993 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
1994 mlog(ML_ERROR, "found superblock with incorrect block "
1995 "size: found %u, should be %u\n",
1996 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
1998 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
1999 OCFS2_MAJOR_REV_LEVEL ||
2000 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2001 OCFS2_MINOR_REV_LEVEL) {
2002 mlog(ML_ERROR, "found superblock with bad version: "
2003 "found %u.%u, should be %u.%u\n",
2004 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2005 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2006 OCFS2_MAJOR_REV_LEVEL,
2007 OCFS2_MINOR_REV_LEVEL);
2008 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2009 mlog(ML_ERROR, "bad block number on superblock: "
2010 "found %llu, should be %llu\n",
2011 (unsigned long long)le64_to_cpu(di->i_blkno),
2012 (unsigned long long)bh->b_blocknr);
2013 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2014 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2015 mlog(ML_ERROR, "bad cluster size found: %u\n",
2016 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2017 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2018 mlog(ML_ERROR, "bad root_blkno: 0\n");
2019 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2020 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2021 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2023 "Superblock slots found greater than file system "
2024 "maximum: found %u, max %u\n",
2025 le16_to_cpu(di->id2.i_super.s_max_slots),
2037 static int ocfs2_check_volume(struct ocfs2_super *osb)
2042 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2048 /* Init our journal object. */
2049 status = ocfs2_journal_init(osb->journal, &dirty);
2051 mlog(ML_ERROR, "Could not initialize journal!\n");
2055 /* If the journal was unmounted cleanly then we don't want to
2056 * recover anything. Otherwise, journal_load will do that
2057 * dirty work for us :) */
2059 status = ocfs2_journal_wipe(osb->journal, 0);
2065 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2066 "recovering volume.\n");
2069 local = ocfs2_mount_local(osb);
2071 /* will play back anything left in the journal. */
2072 status = ocfs2_journal_load(osb->journal, local, dirty);
2074 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2079 /* recover my local alloc if we didn't unmount cleanly. */
2080 status = ocfs2_begin_local_alloc_recovery(osb,
2087 /* we complete the recovery process after we've marked
2088 * ourselves as mounted. */
2091 mlog(0, "Journal loaded.\n");
2093 status = ocfs2_load_local_alloc(osb);
2100 /* Recovery will be completed after we've mounted the
2101 * rest of the volume. */
2103 osb->local_alloc_copy = local_alloc;
2107 /* go through each journal, trylock it and if you get the
2108 * lock, and it's marked as dirty, set the bit in the recover
2109 * map and launch a recovery thread for it. */
2110 status = ocfs2_mark_dead_nodes(osb);
2123 * The routine gets called from dismount or close whenever a dismount on
2124 * volume is requested and the osb open count becomes 1.
2125 * It will remove the osb from the global list and also free up all the
2126 * initialized resources and fileobject.
2128 static void ocfs2_delete_osb(struct ocfs2_super *osb)
2132 /* This function assumes that the caller has the main osb resource */
2134 ocfs2_free_slot_info(osb);
2136 kfree(osb->osb_orphan_wipes);
2137 kfree(osb->slot_recovery_generations);
2139 * This belongs in journal shutdown, but because we have to
2140 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2143 kfree(osb->journal);
2144 if (osb->local_alloc_copy)
2145 kfree(osb->local_alloc_copy);
2146 kfree(osb->uuid_str);
2147 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2148 memset(osb, 0, sizeof(struct ocfs2_super));
2153 /* Put OCFS2 into a readonly state, or (if the user specifies it),
2154 * panic(). We do not support continue-on-error operation. */
2155 static void ocfs2_handle_error(struct super_block *sb)
2157 struct ocfs2_super *osb = OCFS2_SB(sb);
2159 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2160 panic("OCFS2: (device %s): panic forced after error\n",
2163 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2165 if (sb->s_flags & MS_RDONLY &&
2166 (ocfs2_is_soft_readonly(osb) ||
2167 ocfs2_is_hard_readonly(osb)))
2170 printk(KERN_CRIT "File system is now read-only due to the potential "
2171 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2172 "system is unmounted.\n");
2173 sb->s_flags |= MS_RDONLY;
2174 ocfs2_set_ro_flag(osb, 0);
2177 static char error_buf[1024];
2179 void __ocfs2_error(struct super_block *sb,
2180 const char *function,
2181 const char *fmt, ...)
2185 va_start(args, fmt);
2186 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2189 /* Not using mlog here because we want to show the actual
2190 * function the error came from. */
2191 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2192 sb->s_id, function, error_buf);
2194 ocfs2_handle_error(sb);
2197 /* Handle critical errors. This is intentionally more drastic than
2198 * ocfs2_handle_error, so we only use for things like journal errors,
2200 void __ocfs2_abort(struct super_block* sb,
2201 const char *function,
2202 const char *fmt, ...)
2206 va_start(args, fmt);
2207 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2210 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2211 sb->s_id, function, error_buf);
2213 /* We don't have the cluster support yet to go straight to
2214 * hard readonly in here. Until then, we want to keep
2215 * ocfs2_abort() so that we can at least mark critical
2218 * TODO: This should abort the journal and alert other nodes
2219 * that our slot needs recovery. */
2221 /* Force a panic(). This stinks, but it's better than letting
2222 * things continue without having a proper hard readonly
2224 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
2225 ocfs2_handle_error(sb);
2228 module_init(ocfs2_init);
2229 module_exit(ocfs2_exit);