| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- | 
 | 2 |  * vim: noexpandtab sw=8 ts=8 sts=0: | 
 | 3 |  * | 
 | 4 |  * super.c | 
 | 5 |  * | 
 | 6 |  * load/unload driver, mount/dismount volumes | 
 | 7 |  * | 
 | 8 |  * Copyright (C) 2002, 2004 Oracle.  All rights reserved. | 
 | 9 |  * | 
 | 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. | 
 | 14 |  * | 
 | 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. | 
 | 19 |  * | 
 | 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. | 
 | 24 |  */ | 
 | 25 |  | 
 | 26 | #include <linux/module.h> | 
 | 27 | #include <linux/fs.h> | 
 | 28 | #include <linux/types.h> | 
 | 29 | #include <linux/slab.h> | 
 | 30 | #include <linux/highmem.h> | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 31 | #include <linux/init.h> | 
 | 32 | #include <linux/random.h> | 
 | 33 | #include <linux/statfs.h> | 
 | 34 | #include <linux/moduleparam.h> | 
 | 35 | #include <linux/blkdev.h> | 
 | 36 | #include <linux/socket.h> | 
 | 37 | #include <linux/inet.h> | 
 | 38 | #include <linux/parser.h> | 
 | 39 | #include <linux/crc32.h> | 
 | 40 | #include <linux/debugfs.h> | 
| Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 41 | #include <linux/mount.h> | 
| Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 42 | #include <linux/seq_file.h> | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 43 | #include <linux/quotaops.h> | 
| Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 44 | #include <linux/smp_lock.h> | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 45 |  | 
 | 46 | #define MLOG_MASK_PREFIX ML_SUPER | 
 | 47 | #include <cluster/masklog.h> | 
 | 48 |  | 
 | 49 | #include "ocfs2.h" | 
 | 50 |  | 
 | 51 | /* this should be the only file to include a version 1 header */ | 
 | 52 | #include "ocfs1_fs_compat.h" | 
 | 53 |  | 
 | 54 | #include "alloc.h" | 
| Joel Becker | d030cc9 | 2008-12-11 15:04:14 -0800 | [diff] [blame] | 55 | #include "blockcheck.h" | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 56 | #include "dlmglue.h" | 
 | 57 | #include "export.h" | 
 | 58 | #include "extent_map.h" | 
 | 59 | #include "heartbeat.h" | 
 | 60 | #include "inode.h" | 
 | 61 | #include "journal.h" | 
 | 62 | #include "localalloc.h" | 
 | 63 | #include "namei.h" | 
 | 64 | #include "slot_map.h" | 
 | 65 | #include "super.h" | 
 | 66 | #include "sysfile.h" | 
 | 67 | #include "uptodate.h" | 
 | 68 | #include "ver.h" | 
| Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 69 | #include "xattr.h" | 
| Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 70 | #include "quota.h" | 
| Tao Ma | 374a263 | 2009-08-24 11:13:37 +0800 | [diff] [blame] | 71 | #include "refcounttree.h" | 
| Tiger Yang | b89c542 | 2010-01-25 14:11:06 +0800 | [diff] [blame] | 72 | #include "suballoc.h" | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 73 |  | 
 | 74 | #include "buffer_head_io.h" | 
 | 75 |  | 
| Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 76 | static struct kmem_cache *ocfs2_inode_cachep = NULL; | 
| Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 77 | struct kmem_cache *ocfs2_dquot_cachep; | 
 | 78 | struct kmem_cache *ocfs2_qf_chunk_cachep; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 79 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 80 | /* OCFS2 needs to schedule several differnt types of work which | 
 | 81 |  * require cluster locking, disk I/O, recovery waits, etc. Since these | 
 | 82 |  * types of work tend to be heavy we avoid using the kernel events | 
 | 83 |  * workqueue and schedule on our own. */ | 
 | 84 | struct workqueue_struct *ocfs2_wq = NULL; | 
 | 85 |  | 
 | 86 | static struct dentry *ocfs2_debugfs_root = NULL; | 
 | 87 |  | 
 | 88 | MODULE_AUTHOR("Oracle"); | 
 | 89 | MODULE_LICENSE("GPL"); | 
 | 90 |  | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 91 | struct mount_options | 
 | 92 | { | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 93 | 	unsigned long	commit_interval; | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 94 | 	unsigned long	mount_opt; | 
 | 95 | 	unsigned int	atime_quantum; | 
 | 96 | 	signed short	slot; | 
| Mark Fasheh | 73c8a80 | 2010-04-05 18:17:13 -0700 | [diff] [blame] | 97 | 	int		localalloc_opt; | 
| Mark Fasheh | d02f00c | 2009-12-07 13:10:48 -0800 | [diff] [blame] | 98 | 	unsigned int	resv_level; | 
| Mark Fasheh | 83f9231 | 2010-04-05 18:17:16 -0700 | [diff] [blame] | 99 | 	int		dir_resv_level; | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 100 | 	char		cluster_stack[OCFS2_STACK_LABEL_LEN + 1]; | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 101 | }; | 
 | 102 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 103 | static int ocfs2_parse_options(struct super_block *sb, char *options, | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 104 | 			       struct mount_options *mopt, | 
| Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 105 | 			       int is_remount); | 
| Jan Kara | 5297aad | 2009-10-15 14:54:04 +0200 | [diff] [blame] | 106 | static int ocfs2_check_set_options(struct super_block *sb, | 
 | 107 | 				   struct mount_options *options); | 
| Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 108 | static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 109 | static void ocfs2_put_super(struct super_block *sb); | 
 | 110 | static int ocfs2_mount_volume(struct super_block *sb); | 
 | 111 | static int ocfs2_remount(struct super_block *sb, int *flags, char *data); | 
 | 112 | static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err); | 
 | 113 | static int ocfs2_initialize_mem_caches(void); | 
 | 114 | static void ocfs2_free_mem_caches(void); | 
 | 115 | static void ocfs2_delete_osb(struct ocfs2_super *osb); | 
 | 116 |  | 
| David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 117 | static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 118 |  | 
 | 119 | static int ocfs2_sync_fs(struct super_block *sb, int wait); | 
 | 120 |  | 
 | 121 | static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb); | 
 | 122 | static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb); | 
| Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 123 | static void ocfs2_release_system_inodes(struct ocfs2_super *osb); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 124 | static int ocfs2_check_volume(struct ocfs2_super *osb); | 
 | 125 | static int ocfs2_verify_volume(struct ocfs2_dinode *di, | 
 | 126 | 			       struct buffer_head *bh, | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 127 | 			       u32 sectsize, | 
 | 128 | 			       struct ocfs2_blockcheck_stats *stats); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 129 | static int ocfs2_initialize_super(struct super_block *sb, | 
 | 130 | 				  struct buffer_head *bh, | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 131 | 				  int sector_size, | 
 | 132 | 				  struct ocfs2_blockcheck_stats *stats); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 133 | static int ocfs2_get_sector(struct super_block *sb, | 
 | 134 | 			    struct buffer_head **bh, | 
 | 135 | 			    int block, | 
 | 136 | 			    int sect_size); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 137 | static struct inode *ocfs2_alloc_inode(struct super_block *sb); | 
 | 138 | static void ocfs2_destroy_inode(struct inode *inode); | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 139 | static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend); | 
 | 140 | static int ocfs2_enable_quotas(struct ocfs2_super *osb); | 
 | 141 | static void ocfs2_disable_quotas(struct ocfs2_super *osb); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 142 |  | 
| Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 143 | static const struct super_operations ocfs2_sops = { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 144 | 	.statfs		= ocfs2_statfs, | 
 | 145 | 	.alloc_inode	= ocfs2_alloc_inode, | 
 | 146 | 	.destroy_inode	= ocfs2_destroy_inode, | 
 | 147 | 	.drop_inode	= ocfs2_drop_inode, | 
 | 148 | 	.clear_inode	= ocfs2_clear_inode, | 
 | 149 | 	.delete_inode	= ocfs2_delete_inode, | 
 | 150 | 	.sync_fs	= ocfs2_sync_fs, | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 151 | 	.put_super	= ocfs2_put_super, | 
 | 152 | 	.remount_fs	= ocfs2_remount, | 
| Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 153 | 	.show_options   = ocfs2_show_options, | 
| Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 154 | 	.quota_read	= ocfs2_quota_read, | 
 | 155 | 	.quota_write	= ocfs2_quota_write, | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 156 | }; | 
 | 157 |  | 
 | 158 | enum { | 
 | 159 | 	Opt_barrier, | 
 | 160 | 	Opt_err_panic, | 
 | 161 | 	Opt_err_ro, | 
 | 162 | 	Opt_intr, | 
 | 163 | 	Opt_nointr, | 
 | 164 | 	Opt_hb_none, | 
 | 165 | 	Opt_hb_local, | 
 | 166 | 	Opt_data_ordered, | 
 | 167 | 	Opt_data_writeback, | 
| Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 168 | 	Opt_atime_quantum, | 
| Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 169 | 	Opt_slot, | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 170 | 	Opt_commit, | 
| Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 171 | 	Opt_localalloc, | 
| Mark Fasheh | 53fc622 | 2007-12-20 16:49:04 -0800 | [diff] [blame] | 172 | 	Opt_localflocks, | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 173 | 	Opt_stack, | 
| Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 174 | 	Opt_user_xattr, | 
 | 175 | 	Opt_nouser_xattr, | 
| Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 176 | 	Opt_inode64, | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 177 | 	Opt_acl, | 
 | 178 | 	Opt_noacl, | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 179 | 	Opt_usrquota, | 
 | 180 | 	Opt_grpquota, | 
| Mark Fasheh | d02f00c | 2009-12-07 13:10:48 -0800 | [diff] [blame] | 181 | 	Opt_resv_level, | 
| Mark Fasheh | 83f9231 | 2010-04-05 18:17:16 -0700 | [diff] [blame] | 182 | 	Opt_dir_resv_level, | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 183 | 	Opt_err, | 
 | 184 | }; | 
 | 185 |  | 
| Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 186 | static const match_table_t tokens = { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 187 | 	{Opt_barrier, "barrier=%u"}, | 
 | 188 | 	{Opt_err_panic, "errors=panic"}, | 
 | 189 | 	{Opt_err_ro, "errors=remount-ro"}, | 
 | 190 | 	{Opt_intr, "intr"}, | 
 | 191 | 	{Opt_nointr, "nointr"}, | 
 | 192 | 	{Opt_hb_none, OCFS2_HB_NONE}, | 
 | 193 | 	{Opt_hb_local, OCFS2_HB_LOCAL}, | 
 | 194 | 	{Opt_data_ordered, "data=ordered"}, | 
 | 195 | 	{Opt_data_writeback, "data=writeback"}, | 
| Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 196 | 	{Opt_atime_quantum, "atime_quantum=%u"}, | 
| Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 197 | 	{Opt_slot, "preferred_slot=%u"}, | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 198 | 	{Opt_commit, "commit=%u"}, | 
| Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 199 | 	{Opt_localalloc, "localalloc=%d"}, | 
| Mark Fasheh | 53fc622 | 2007-12-20 16:49:04 -0800 | [diff] [blame] | 200 | 	{Opt_localflocks, "localflocks"}, | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 201 | 	{Opt_stack, "cluster_stack=%s"}, | 
| Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 202 | 	{Opt_user_xattr, "user_xattr"}, | 
 | 203 | 	{Opt_nouser_xattr, "nouser_xattr"}, | 
| Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 204 | 	{Opt_inode64, "inode64"}, | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 205 | 	{Opt_acl, "acl"}, | 
 | 206 | 	{Opt_noacl, "noacl"}, | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 207 | 	{Opt_usrquota, "usrquota"}, | 
 | 208 | 	{Opt_grpquota, "grpquota"}, | 
| Mark Fasheh | d02f00c | 2009-12-07 13:10:48 -0800 | [diff] [blame] | 209 | 	{Opt_resv_level, "resv_level=%u"}, | 
| Mark Fasheh | 83f9231 | 2010-04-05 18:17:16 -0700 | [diff] [blame] | 210 | 	{Opt_dir_resv_level, "dir_resv_level=%u"}, | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 211 | 	{Opt_err, NULL} | 
 | 212 | }; | 
 | 213 |  | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 214 | #ifdef CONFIG_DEBUG_FS | 
 | 215 | static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len) | 
 | 216 | { | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 217 | 	struct ocfs2_cluster_connection *cconn = osb->cconn; | 
 | 218 | 	struct ocfs2_recovery_map *rm = osb->recovery_map; | 
| Sunil Mushran | df152c2 | 2009-06-22 11:40:07 -0700 | [diff] [blame] | 219 | 	struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan; | 
 | 220 | 	int i, out = 0; | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 221 |  | 
 | 222 | 	out += snprintf(buf + out, len - out, | 
 | 223 | 			"%10s => Id: %-s  Uuid: %-s  Gen: 0x%X  Label: %-s\n", | 
 | 224 | 			"Device", osb->dev_str, osb->uuid_str, | 
 | 225 | 			osb->fs_generation, osb->vol_label); | 
 | 226 |  | 
 | 227 | 	out += snprintf(buf + out, len - out, | 
 | 228 | 			"%10s => State: %d  Flags: 0x%lX\n", "Volume", | 
 | 229 | 			atomic_read(&osb->vol_state), osb->osb_flags); | 
 | 230 |  | 
 | 231 | 	out += snprintf(buf + out, len - out, | 
 | 232 | 			"%10s => Block: %lu  Cluster: %d\n", "Sizes", | 
 | 233 | 			osb->sb->s_blocksize, osb->s_clustersize); | 
 | 234 |  | 
 | 235 | 	out += snprintf(buf + out, len - out, | 
 | 236 | 			"%10s => Compat: 0x%X  Incompat: 0x%X  " | 
 | 237 | 			"ROcompat: 0x%X\n", | 
 | 238 | 			"Features", osb->s_feature_compat, | 
 | 239 | 			osb->s_feature_incompat, osb->s_feature_ro_compat); | 
 | 240 |  | 
 | 241 | 	out += snprintf(buf + out, len - out, | 
 | 242 | 			"%10s => Opts: 0x%lX  AtimeQuanta: %u\n", "Mount", | 
 | 243 | 			osb->s_mount_opt, osb->s_atime_quantum); | 
 | 244 |  | 
| Sunil Mushran | c3d3884 | 2009-06-19 14:45:55 -0700 | [diff] [blame] | 245 | 	if (cconn) { | 
 | 246 | 		out += snprintf(buf + out, len - out, | 
 | 247 | 				"%10s => Stack: %s  Name: %*s  " | 
 | 248 | 				"Version: %d.%d\n", "Cluster", | 
 | 249 | 				(*osb->osb_cluster_stack == '\0' ? | 
 | 250 | 				 "o2cb" : osb->osb_cluster_stack), | 
 | 251 | 				cconn->cc_namelen, cconn->cc_name, | 
 | 252 | 				cconn->cc_version.pv_major, | 
 | 253 | 				cconn->cc_version.pv_minor); | 
 | 254 | 	} | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 255 |  | 
 | 256 | 	spin_lock(&osb->dc_task_lock); | 
 | 257 | 	out += snprintf(buf + out, len - out, | 
 | 258 | 			"%10s => Pid: %d  Count: %lu  WakeSeq: %lu  " | 
 | 259 | 			"WorkSeq: %lu\n", "DownCnvt", | 
| Sunil Mushran | c3d3884 | 2009-06-19 14:45:55 -0700 | [diff] [blame] | 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); | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 263 | 	spin_unlock(&osb->dc_task_lock); | 
 | 264 |  | 
 | 265 | 	spin_lock(&osb->osb_lock); | 
 | 266 | 	out += snprintf(buf + out, len - out, "%10s => Pid: %d  Nodes:", | 
 | 267 | 			"Recovery", | 
 | 268 | 			(osb->recovery_thread_task ? | 
 | 269 | 			 task_pid_nr(osb->recovery_thread_task) : -1)); | 
 | 270 | 	if (rm->rm_used == 0) | 
 | 271 | 		out += snprintf(buf + out, len - out, " None\n"); | 
 | 272 | 	else { | 
 | 273 | 		for (i = 0; i < rm->rm_used; i++) | 
 | 274 | 			out += snprintf(buf + out, len - out, " %d", | 
 | 275 | 					rm->rm_entries[i]); | 
 | 276 | 		out += snprintf(buf + out, len - out, "\n"); | 
 | 277 | 	} | 
 | 278 | 	spin_unlock(&osb->osb_lock); | 
 | 279 |  | 
 | 280 | 	out += snprintf(buf + out, len - out, | 
 | 281 | 			"%10s => Pid: %d  Interval: %lu  Needs: %d\n", "Commit", | 
| Sunil Mushran | c3d3884 | 2009-06-19 14:45:55 -0700 | [diff] [blame] | 282 | 			(osb->commit_task ? task_pid_nr(osb->commit_task) : -1), | 
 | 283 | 			osb->osb_commit_interval, | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 284 | 			atomic_read(&osb->needs_checkpoint)); | 
 | 285 |  | 
 | 286 | 	out += snprintf(buf + out, len - out, | 
| Sunil Mushran | c3d3884 | 2009-06-19 14:45:55 -0700 | [diff] [blame] | 287 | 			"%10s => State: %d  TxnId: %lu  NumTxns: %d\n", | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 288 | 			"Journal", osb->journal->j_state, | 
| Sunil Mushran | c3d3884 | 2009-06-19 14:45:55 -0700 | [diff] [blame] | 289 | 			osb->journal->j_trans_id, | 
 | 290 | 			atomic_read(&osb->journal->j_num_trans)); | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 291 |  | 
 | 292 | 	out += snprintf(buf + out, len - out, | 
 | 293 | 			"%10s => GlobalAllocs: %d  LocalAllocs: %d  " | 
 | 294 | 			"SubAllocs: %d  LAWinMoves: %d  SAExtends: %d\n", | 
 | 295 | 			"Stats", | 
 | 296 | 			atomic_read(&osb->alloc_stats.bitmap_data), | 
 | 297 | 			atomic_read(&osb->alloc_stats.local_data), | 
 | 298 | 			atomic_read(&osb->alloc_stats.bg_allocs), | 
 | 299 | 			atomic_read(&osb->alloc_stats.moves), | 
 | 300 | 			atomic_read(&osb->alloc_stats.bg_extends)); | 
 | 301 |  | 
 | 302 | 	out += snprintf(buf + out, len - out, | 
 | 303 | 			"%10s => State: %u  Descriptor: %llu  Size: %u bits  " | 
 | 304 | 			"Default: %u bits\n", | 
 | 305 | 			"LocalAlloc", osb->local_alloc_state, | 
 | 306 | 			(unsigned long long)osb->la_last_gd, | 
 | 307 | 			osb->local_alloc_bits, osb->local_alloc_default_bits); | 
 | 308 |  | 
 | 309 | 	spin_lock(&osb->osb_lock); | 
 | 310 | 	out += snprintf(buf + out, len - out, | 
| Tiger Yang | b89c542 | 2010-01-25 14:11:06 +0800 | [diff] [blame] | 311 | 			"%10s => InodeSlot: %d  StolenInodes: %d, " | 
 | 312 | 			"MetaSlot: %d  StolenMeta: %d\n", "Steal", | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 313 | 			osb->s_inode_steal_slot, | 
| Tiger Yang | b89c542 | 2010-01-25 14:11:06 +0800 | [diff] [blame] | 314 | 			atomic_read(&osb->s_num_inodes_stolen), | 
 | 315 | 			osb->s_meta_steal_slot, | 
 | 316 | 			atomic_read(&osb->s_num_meta_stolen)); | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 317 | 	spin_unlock(&osb->osb_lock); | 
 | 318 |  | 
| Sunil Mushran | df152c2 | 2009-06-22 11:40:07 -0700 | [diff] [blame] | 319 | 	out += snprintf(buf + out, len - out, "OrphanScan => "); | 
 | 320 | 	out += snprintf(buf + out, len - out, "Local: %u  Global: %u ", | 
 | 321 | 			os->os_count, os->os_seqno); | 
 | 322 | 	out += snprintf(buf + out, len - out, " Last Scan: "); | 
 | 323 | 	if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE) | 
 | 324 | 		out += snprintf(buf + out, len - out, "Disabled\n"); | 
 | 325 | 	else | 
 | 326 | 		out += snprintf(buf + out, len - out, "%lu seconds ago\n", | 
 | 327 | 				(get_seconds() - os->os_scantime.tv_sec)); | 
 | 328 |  | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 329 | 	out += snprintf(buf + out, len - out, "%10s => %3s  %10s\n", | 
 | 330 | 			"Slots", "Num", "RecoGen"); | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 331 | 	for (i = 0; i < osb->max_slots; ++i) { | 
 | 332 | 		out += snprintf(buf + out, len - out, | 
 | 333 | 				"%10s  %c %3d  %10d\n", | 
 | 334 | 				" ", | 
 | 335 | 				(i == osb->slot_num ? '*' : ' '), | 
 | 336 | 				i, osb->slot_recovery_generations[i]); | 
 | 337 | 	} | 
 | 338 |  | 
 | 339 | 	return out; | 
 | 340 | } | 
 | 341 |  | 
 | 342 | static int ocfs2_osb_debug_open(struct inode *inode, struct file *file) | 
 | 343 | { | 
 | 344 | 	struct ocfs2_super *osb = inode->i_private; | 
 | 345 | 	char *buf = NULL; | 
 | 346 |  | 
 | 347 | 	buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | 
 | 348 | 	if (!buf) | 
 | 349 | 		goto bail; | 
 | 350 |  | 
 | 351 | 	i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE)); | 
 | 352 |  | 
 | 353 | 	file->private_data = buf; | 
 | 354 |  | 
 | 355 | 	return 0; | 
 | 356 | bail: | 
 | 357 | 	return -ENOMEM; | 
 | 358 | } | 
 | 359 |  | 
 | 360 | static int ocfs2_debug_release(struct inode *inode, struct file *file) | 
 | 361 | { | 
 | 362 | 	kfree(file->private_data); | 
 | 363 | 	return 0; | 
 | 364 | } | 
 | 365 |  | 
 | 366 | static ssize_t ocfs2_debug_read(struct file *file, char __user *buf, | 
 | 367 | 				size_t nbytes, loff_t *ppos) | 
 | 368 | { | 
 | 369 | 	return simple_read_from_buffer(buf, nbytes, ppos, file->private_data, | 
 | 370 | 				       i_size_read(file->f_mapping->host)); | 
 | 371 | } | 
 | 372 | #else | 
 | 373 | static int ocfs2_osb_debug_open(struct inode *inode, struct file *file) | 
 | 374 | { | 
 | 375 | 	return 0; | 
 | 376 | } | 
 | 377 | static int ocfs2_debug_release(struct inode *inode, struct file *file) | 
 | 378 | { | 
 | 379 | 	return 0; | 
 | 380 | } | 
 | 381 | static ssize_t ocfs2_debug_read(struct file *file, char __user *buf, | 
 | 382 | 				size_t nbytes, loff_t *ppos) | 
 | 383 | { | 
 | 384 | 	return 0; | 
 | 385 | } | 
 | 386 | #endif	/* CONFIG_DEBUG_FS */ | 
 | 387 |  | 
| Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 388 | static const struct file_operations ocfs2_osb_debug_fops = { | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 389 | 	.open =		ocfs2_osb_debug_open, | 
 | 390 | 	.release =	ocfs2_debug_release, | 
 | 391 | 	.read =		ocfs2_debug_read, | 
 | 392 | 	.llseek =	generic_file_llseek, | 
 | 393 | }; | 
 | 394 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 395 | static int ocfs2_sync_fs(struct super_block *sb, int wait) | 
 | 396 | { | 
| Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 397 | 	int status; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 398 | 	tid_t target; | 
 | 399 | 	struct ocfs2_super *osb = OCFS2_SB(sb); | 
 | 400 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 401 | 	if (ocfs2_is_hard_readonly(osb)) | 
 | 402 | 		return -EROFS; | 
 | 403 |  | 
 | 404 | 	if (wait) { | 
 | 405 | 		status = ocfs2_flush_truncate_log(osb); | 
 | 406 | 		if (status < 0) | 
 | 407 | 			mlog_errno(status); | 
 | 408 | 	} else { | 
 | 409 | 		ocfs2_schedule_truncate_log_flush(osb, 0); | 
 | 410 | 	} | 
 | 411 |  | 
| Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 412 | 	if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal, | 
 | 413 | 				      &target)) { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 414 | 		if (wait) | 
| Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 415 | 			jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal, | 
 | 416 | 					     target); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 417 | 	} | 
 | 418 | 	return 0; | 
 | 419 | } | 
 | 420 |  | 
| Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 421 | static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino) | 
 | 422 | { | 
 | 423 | 	if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA) | 
 | 424 | 	    && (ino == USER_QUOTA_SYSTEM_INODE | 
 | 425 | 		|| ino == LOCAL_USER_QUOTA_SYSTEM_INODE)) | 
 | 426 | 		return 0; | 
 | 427 | 	if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA) | 
 | 428 | 	    && (ino == GROUP_QUOTA_SYSTEM_INODE | 
 | 429 | 		|| ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE)) | 
 | 430 | 		return 0; | 
 | 431 | 	return 1; | 
 | 432 | } | 
 | 433 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 434 | static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb) | 
 | 435 | { | 
 | 436 | 	struct inode *new = NULL; | 
 | 437 | 	int status = 0; | 
 | 438 | 	int i; | 
 | 439 |  | 
 | 440 | 	mlog_entry_void(); | 
 | 441 |  | 
| Jan Kara | 5fa0613 | 2008-01-11 00:11:45 +0100 | [diff] [blame] | 442 | 	new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 443 | 	if (IS_ERR(new)) { | 
 | 444 | 		status = PTR_ERR(new); | 
 | 445 | 		mlog_errno(status); | 
 | 446 | 		goto bail; | 
 | 447 | 	} | 
 | 448 | 	osb->root_inode = new; | 
 | 449 |  | 
| Jan Kara | 5fa0613 | 2008-01-11 00:11:45 +0100 | [diff] [blame] | 450 | 	new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 451 | 	if (IS_ERR(new)) { | 
 | 452 | 		status = PTR_ERR(new); | 
 | 453 | 		mlog_errno(status); | 
 | 454 | 		goto bail; | 
 | 455 | 	} | 
 | 456 | 	osb->sys_root_inode = new; | 
 | 457 |  | 
 | 458 | 	for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE; | 
 | 459 | 	     i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) { | 
| Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 460 | 		if (!ocfs2_need_system_inode(osb, i)) | 
 | 461 | 			continue; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 462 | 		new = ocfs2_get_system_file_inode(osb, i, osb->slot_num); | 
 | 463 | 		if (!new) { | 
 | 464 | 			ocfs2_release_system_inodes(osb); | 
 | 465 | 			status = -EINVAL; | 
 | 466 | 			mlog_errno(status); | 
 | 467 | 			/* FIXME: Should ERROR_RO_FS */ | 
 | 468 | 			mlog(ML_ERROR, "Unable to load system inode %d, " | 
 | 469 | 			     "possibly corrupt fs?", i); | 
 | 470 | 			goto bail; | 
 | 471 | 		} | 
 | 472 | 		// the array now has one ref, so drop this one | 
 | 473 | 		iput(new); | 
 | 474 | 	} | 
 | 475 |  | 
 | 476 | bail: | 
 | 477 | 	mlog_exit(status); | 
 | 478 | 	return status; | 
 | 479 | } | 
 | 480 |  | 
 | 481 | static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb) | 
 | 482 | { | 
 | 483 | 	struct inode *new = NULL; | 
 | 484 | 	int status = 0; | 
 | 485 | 	int i; | 
 | 486 |  | 
 | 487 | 	mlog_entry_void(); | 
 | 488 |  | 
 | 489 | 	for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1; | 
 | 490 | 	     i < NUM_SYSTEM_INODES; | 
 | 491 | 	     i++) { | 
| Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 492 | 		if (!ocfs2_need_system_inode(osb, i)) | 
 | 493 | 			continue; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 494 | 		new = ocfs2_get_system_file_inode(osb, i, osb->slot_num); | 
 | 495 | 		if (!new) { | 
 | 496 | 			ocfs2_release_system_inodes(osb); | 
 | 497 | 			status = -EINVAL; | 
 | 498 | 			mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n", | 
 | 499 | 			     status, i, osb->slot_num); | 
 | 500 | 			goto bail; | 
 | 501 | 		} | 
 | 502 | 		/* the array now has one ref, so drop this one */ | 
 | 503 | 		iput(new); | 
 | 504 | 	} | 
 | 505 |  | 
 | 506 | bail: | 
 | 507 | 	mlog_exit(status); | 
 | 508 | 	return status; | 
 | 509 | } | 
 | 510 |  | 
| Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 511 | static void ocfs2_release_system_inodes(struct ocfs2_super *osb) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 512 | { | 
| Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 513 | 	int i; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 514 | 	struct inode *inode; | 
 | 515 |  | 
 | 516 | 	mlog_entry_void(); | 
 | 517 |  | 
 | 518 | 	for (i = 0; i < NUM_SYSTEM_INODES; i++) { | 
 | 519 | 		inode = osb->system_inodes[i]; | 
 | 520 | 		if (inode) { | 
 | 521 | 			iput(inode); | 
 | 522 | 			osb->system_inodes[i] = NULL; | 
 | 523 | 		} | 
 | 524 | 	} | 
 | 525 |  | 
 | 526 | 	inode = osb->sys_root_inode; | 
 | 527 | 	if (inode) { | 
 | 528 | 		iput(inode); | 
 | 529 | 		osb->sys_root_inode = NULL; | 
 | 530 | 	} | 
 | 531 |  | 
 | 532 | 	inode = osb->root_inode; | 
 | 533 | 	if (inode) { | 
 | 534 | 		iput(inode); | 
 | 535 | 		osb->root_inode = NULL; | 
 | 536 | 	} | 
 | 537 |  | 
| Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 538 | 	mlog_exit(0); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 539 | } | 
 | 540 |  | 
 | 541 | /* We're allocating fs objects, use GFP_NOFS */ | 
 | 542 | static struct inode *ocfs2_alloc_inode(struct super_block *sb) | 
 | 543 | { | 
 | 544 | 	struct ocfs2_inode_info *oi; | 
 | 545 |  | 
| Christoph Lameter | e6b4f8d | 2006-12-06 20:33:14 -0800 | [diff] [blame] | 546 | 	oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 547 | 	if (!oi) | 
 | 548 | 		return NULL; | 
 | 549 |  | 
| Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 550 | 	jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 551 | 	return &oi->vfs_inode; | 
 | 552 | } | 
 | 553 |  | 
 | 554 | static void ocfs2_destroy_inode(struct inode *inode) | 
 | 555 | { | 
 | 556 | 	kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode)); | 
 | 557 | } | 
 | 558 |  | 
| Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 559 | static unsigned long long ocfs2_max_file_offset(unsigned int bbits, | 
 | 560 | 						unsigned int cbits) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 561 | { | 
| Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 562 | 	unsigned int bytes = 1 << cbits; | 
 | 563 | 	unsigned int trim = bytes; | 
 | 564 | 	unsigned int bitshift = 32; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 565 |  | 
| Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 566 | 	/* | 
 | 567 | 	 * i_size and all block offsets in ocfs2 are always 64 bits | 
 | 568 | 	 * wide. i_clusters is 32 bits, in cluster-sized units. So on | 
 | 569 | 	 * 64 bit platforms, cluster size will be the limiting factor. | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 570 | 	 */ | 
 | 571 |  | 
 | 572 | #if BITS_PER_LONG == 32 | 
| Bartlomiej Zolnierkiewicz | 90c699a | 2009-06-19 08:08:50 +0200 | [diff] [blame] | 573 | # if defined(CONFIG_LBDAF) | 
| Alexey Dobriyan | 2ecd05a | 2006-10-11 01:22:05 -0700 | [diff] [blame] | 574 | 	BUILD_BUG_ON(sizeof(sector_t) != 8); | 
| Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 575 | 	/* | 
 | 576 | 	 * We might be limited by page cache size. | 
 | 577 | 	 */ | 
 | 578 | 	if (bytes > PAGE_CACHE_SIZE) { | 
 | 579 | 		bytes = PAGE_CACHE_SIZE; | 
 | 580 | 		trim = 1; | 
 | 581 | 		/* | 
 | 582 | 		 * Shift by 31 here so that we don't get larger than | 
 | 583 | 		 * MAX_LFS_FILESIZE | 
 | 584 | 		 */ | 
 | 585 | 		bitshift = 31; | 
 | 586 | 	} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 587 | # else | 
| Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 588 | 	/* | 
 | 589 | 	 * We are limited by the size of sector_t. Use block size, as | 
 | 590 | 	 * that's what we expose to the VFS. | 
 | 591 | 	 */ | 
 | 592 | 	bytes = 1 << bbits; | 
 | 593 | 	trim = 1; | 
 | 594 | 	bitshift = 31; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 595 | # endif | 
 | 596 | #endif | 
 | 597 |  | 
| Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 598 | 	/* | 
 | 599 | 	 * Trim by a whole cluster when we can actually approach the | 
 | 600 | 	 * on-disk limits. Otherwise we can overflow i_clusters when | 
 | 601 | 	 * an extent start is at the max offset. | 
 | 602 | 	 */ | 
 | 603 | 	return (((unsigned long long)bytes) << bitshift) - trim; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 604 | } | 
 | 605 |  | 
 | 606 | static int ocfs2_remount(struct super_block *sb, int *flags, char *data) | 
 | 607 | { | 
 | 608 | 	int incompat_features; | 
 | 609 | 	int ret = 0; | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 610 | 	struct mount_options parsed_options; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 611 | 	struct ocfs2_super *osb = OCFS2_SB(sb); | 
 | 612 |  | 
| Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 613 | 	lock_kernel(); | 
 | 614 |  | 
| Jan Kara | 5297aad | 2009-10-15 14:54:04 +0200 | [diff] [blame] | 615 | 	if (!ocfs2_parse_options(sb, data, &parsed_options, 1) || | 
 | 616 | 	    !ocfs2_check_set_options(sb, &parsed_options)) { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 617 | 		ret = -EINVAL; | 
 | 618 | 		goto out; | 
 | 619 | 	} | 
 | 620 |  | 
 | 621 | 	if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) != | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 622 | 	    (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 623 | 		ret = -EINVAL; | 
 | 624 | 		mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n"); | 
 | 625 | 		goto out; | 
 | 626 | 	} | 
 | 627 |  | 
 | 628 | 	if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) != | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 629 | 	    (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 630 | 		ret = -EINVAL; | 
 | 631 | 		mlog(ML_ERROR, "Cannot change data mode on remount\n"); | 
 | 632 | 		goto out; | 
 | 633 | 	} | 
 | 634 |  | 
| Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 635 | 	/* Probably don't want this on remount; it might | 
 | 636 | 	 * mess with other nodes */ | 
 | 637 | 	if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) && | 
 | 638 | 	    (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) { | 
 | 639 | 		ret = -EINVAL; | 
 | 640 | 		mlog(ML_ERROR, "Cannot enable inode64 on remount\n"); | 
 | 641 | 		goto out; | 
 | 642 | 	} | 
 | 643 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 644 | 	/* We're going to/from readonly mode. */ | 
 | 645 | 	if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) { | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 646 | 		/* Disable quota accounting before remounting RO */ | 
 | 647 | 		if (*flags & MS_RDONLY) { | 
 | 648 | 			ret = ocfs2_susp_quotas(osb, 0); | 
 | 649 | 			if (ret < 0) | 
 | 650 | 				goto out; | 
 | 651 | 		} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 652 | 		/* Lock here so the check of HARD_RO and the potential | 
 | 653 | 		 * setting of SOFT_RO is atomic. */ | 
 | 654 | 		spin_lock(&osb->osb_lock); | 
 | 655 | 		if (osb->osb_flags & OCFS2_OSB_HARD_RO) { | 
 | 656 | 			mlog(ML_ERROR, "Remount on readonly device is forbidden.\n"); | 
 | 657 | 			ret = -EROFS; | 
 | 658 | 			goto unlock_osb; | 
 | 659 | 		} | 
 | 660 |  | 
 | 661 | 		if (*flags & MS_RDONLY) { | 
 | 662 | 			mlog(0, "Going to ro mode.\n"); | 
 | 663 | 			sb->s_flags |= MS_RDONLY; | 
 | 664 | 			osb->osb_flags |= OCFS2_OSB_SOFT_RO; | 
 | 665 | 		} else { | 
 | 666 | 			mlog(0, "Making ro filesystem writeable.\n"); | 
 | 667 |  | 
 | 668 | 			if (osb->osb_flags & OCFS2_OSB_ERROR_FS) { | 
 | 669 | 				mlog(ML_ERROR, "Cannot remount RDWR " | 
 | 670 | 				     "filesystem due to previous errors.\n"); | 
 | 671 | 				ret = -EROFS; | 
 | 672 | 				goto unlock_osb; | 
 | 673 | 			} | 
 | 674 | 			incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP); | 
 | 675 | 			if (incompat_features) { | 
 | 676 | 				mlog(ML_ERROR, "Cannot remount RDWR because " | 
 | 677 | 				     "of unsupported optional features " | 
 | 678 | 				     "(%x).\n", incompat_features); | 
 | 679 | 				ret = -EINVAL; | 
 | 680 | 				goto unlock_osb; | 
 | 681 | 			} | 
 | 682 | 			sb->s_flags &= ~MS_RDONLY; | 
 | 683 | 			osb->osb_flags &= ~OCFS2_OSB_SOFT_RO; | 
 | 684 | 		} | 
 | 685 | unlock_osb: | 
 | 686 | 		spin_unlock(&osb->osb_lock); | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 687 | 		/* Enable quota accounting after remounting RW */ | 
 | 688 | 		if (!ret && !(*flags & MS_RDONLY)) { | 
 | 689 | 			if (sb_any_quota_suspended(sb)) | 
 | 690 | 				ret = ocfs2_susp_quotas(osb, 1); | 
 | 691 | 			else | 
 | 692 | 				ret = ocfs2_enable_quotas(osb); | 
 | 693 | 			if (ret < 0) { | 
 | 694 | 				/* Return back changes... */ | 
 | 695 | 				spin_lock(&osb->osb_lock); | 
 | 696 | 				sb->s_flags |= MS_RDONLY; | 
 | 697 | 				osb->osb_flags |= OCFS2_OSB_SOFT_RO; | 
 | 698 | 				spin_unlock(&osb->osb_lock); | 
 | 699 | 				goto out; | 
 | 700 | 			} | 
 | 701 | 		} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 702 | 	} | 
 | 703 |  | 
 | 704 | 	if (!ret) { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 705 | 		/* Only save off the new mount options in case of a successful | 
 | 706 | 		 * remount. */ | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 707 | 		osb->s_mount_opt = parsed_options.mount_opt; | 
 | 708 | 		osb->s_atime_quantum = parsed_options.atime_quantum; | 
 | 709 | 		osb->preferred_slot = parsed_options.slot; | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 710 | 		if (parsed_options.commit_interval) | 
 | 711 | 			osb->osb_commit_interval = parsed_options.commit_interval; | 
| Mark Fasheh | e001e79 | 2007-11-07 14:21:45 -0800 | [diff] [blame] | 712 |  | 
 | 713 | 		if (!ocfs2_is_hard_readonly(osb)) | 
 | 714 | 			ocfs2_set_journal_params(osb); | 
| Jan Kara | 57b09bb | 2009-10-15 14:54:05 +0200 | [diff] [blame] | 715 |  | 
 | 716 | 		sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | | 
 | 717 | 			((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? | 
 | 718 | 							MS_POSIXACL : 0); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 719 | 	} | 
 | 720 | out: | 
| Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 721 | 	unlock_kernel(); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 722 | 	return ret; | 
 | 723 | } | 
 | 724 |  | 
 | 725 | static int ocfs2_sb_probe(struct super_block *sb, | 
 | 726 | 			  struct buffer_head **bh, | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 727 | 			  int *sector_size, | 
 | 728 | 			  struct ocfs2_blockcheck_stats *stats) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 729 | { | 
| Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 730 | 	int status, tmpstat; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 731 | 	struct ocfs1_vol_disk_hdr *hdr; | 
 | 732 | 	struct ocfs2_dinode *di; | 
 | 733 | 	int blksize; | 
 | 734 |  | 
 | 735 | 	*bh = NULL; | 
 | 736 |  | 
 | 737 | 	/* may be > 512 */ | 
| Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 738 | 	*sector_size = bdev_logical_block_size(sb->s_bdev); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 739 | 	if (*sector_size > OCFS2_MAX_BLOCKSIZE) { | 
 | 740 | 		mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n", | 
 | 741 | 		     *sector_size, OCFS2_MAX_BLOCKSIZE); | 
 | 742 | 		status = -EINVAL; | 
 | 743 | 		goto bail; | 
 | 744 | 	} | 
 | 745 |  | 
 | 746 | 	/* Can this really happen? */ | 
 | 747 | 	if (*sector_size < OCFS2_MIN_BLOCKSIZE) | 
 | 748 | 		*sector_size = OCFS2_MIN_BLOCKSIZE; | 
 | 749 |  | 
 | 750 | 	/* check block zero for old format */ | 
 | 751 | 	status = ocfs2_get_sector(sb, bh, 0, *sector_size); | 
 | 752 | 	if (status < 0) { | 
 | 753 | 		mlog_errno(status); | 
 | 754 | 		goto bail; | 
 | 755 | 	} | 
 | 756 | 	hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data; | 
 | 757 | 	if (hdr->major_version == OCFS1_MAJOR_VERSION) { | 
 | 758 | 		mlog(ML_ERROR, "incompatible version: %u.%u\n", | 
 | 759 | 		     hdr->major_version, hdr->minor_version); | 
 | 760 | 		status = -EINVAL; | 
 | 761 | 	} | 
 | 762 | 	if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE, | 
 | 763 | 		   strlen(OCFS1_VOLUME_SIGNATURE)) == 0) { | 
 | 764 | 		mlog(ML_ERROR, "incompatible volume signature: %8s\n", | 
 | 765 | 		     hdr->signature); | 
 | 766 | 		status = -EINVAL; | 
 | 767 | 	} | 
 | 768 | 	brelse(*bh); | 
 | 769 | 	*bh = NULL; | 
 | 770 | 	if (status < 0) { | 
 | 771 | 		mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be " | 
 | 772 | 		     "upgraded before mounting with ocfs v2\n"); | 
 | 773 | 		goto bail; | 
 | 774 | 	} | 
 | 775 |  | 
 | 776 | 	/* | 
 | 777 | 	 * Now check at magic offset for 512, 1024, 2048, 4096 | 
 | 778 | 	 * blocksizes.  4096 is the maximum blocksize because it is | 
 | 779 | 	 * the minimum clustersize. | 
 | 780 | 	 */ | 
 | 781 | 	status = -EINVAL; | 
 | 782 | 	for (blksize = *sector_size; | 
 | 783 | 	     blksize <= OCFS2_MAX_BLOCKSIZE; | 
 | 784 | 	     blksize <<= 1) { | 
 | 785 | 		tmpstat = ocfs2_get_sector(sb, bh, | 
 | 786 | 					   OCFS2_SUPER_BLOCK_BLKNO, | 
 | 787 | 					   blksize); | 
 | 788 | 		if (tmpstat < 0) { | 
 | 789 | 			status = tmpstat; | 
 | 790 | 			mlog_errno(status); | 
| Joel Becker | fb5cbe9 | 2009-10-28 22:28:24 -0700 | [diff] [blame] | 791 | 			break; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 792 | 		} | 
 | 793 | 		di = (struct ocfs2_dinode *) (*bh)->b_data; | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 794 | 		memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats)); | 
| Jan Kara | 1c1d979 | 2009-07-22 13:17:19 +0200 | [diff] [blame] | 795 | 		spin_lock_init(&stats->b_lock); | 
| Joel Becker | fb5cbe9 | 2009-10-28 22:28:24 -0700 | [diff] [blame] | 796 | 		tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats); | 
 | 797 | 		if (tmpstat < 0) { | 
 | 798 | 			brelse(*bh); | 
 | 799 | 			*bh = NULL; | 
 | 800 | 		} | 
 | 801 | 		if (tmpstat != -EAGAIN) { | 
 | 802 | 			status = tmpstat; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 803 | 			break; | 
| Joel Becker | fb5cbe9 | 2009-10-28 22:28:24 -0700 | [diff] [blame] | 804 | 		} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 805 | 	} | 
 | 806 |  | 
 | 807 | bail: | 
 | 808 | 	return status; | 
 | 809 | } | 
 | 810 |  | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 811 | static int ocfs2_verify_heartbeat(struct ocfs2_super *osb) | 
 | 812 | { | 
 | 813 | 	if (ocfs2_mount_local(osb)) { | 
 | 814 | 		if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) { | 
 | 815 | 			mlog(ML_ERROR, "Cannot heartbeat on a locally " | 
 | 816 | 			     "mounted device.\n"); | 
 | 817 | 			return -EINVAL; | 
 | 818 | 		} | 
 | 819 | 	} | 
 | 820 |  | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 821 | 	if (ocfs2_userspace_stack(osb)) { | 
 | 822 | 		if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) { | 
 | 823 | 			mlog(ML_ERROR, "Userspace stack expected, but " | 
 | 824 | 			     "o2cb heartbeat arguments passed to mount\n"); | 
 | 825 | 			return -EINVAL; | 
 | 826 | 		} | 
 | 827 | 	} | 
 | 828 |  | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 829 | 	if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) { | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 830 | 		if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) && | 
 | 831 | 		    !ocfs2_userspace_stack(osb)) { | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 832 | 			mlog(ML_ERROR, "Heartbeat has to be started to mount " | 
 | 833 | 			     "a read-write clustered device.\n"); | 
 | 834 | 			return -EINVAL; | 
 | 835 | 		} | 
 | 836 | 	} | 
 | 837 |  | 
 | 838 | 	return 0; | 
 | 839 | } | 
 | 840 |  | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 841 | /* | 
 | 842 |  * If we're using a userspace stack, mount should have passed | 
 | 843 |  * a name that matches the disk.  If not, mount should not | 
 | 844 |  * have passed a stack. | 
 | 845 |  */ | 
 | 846 | static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb, | 
 | 847 | 					struct mount_options *mopt) | 
 | 848 | { | 
 | 849 | 	if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) { | 
 | 850 | 		mlog(ML_ERROR, | 
 | 851 | 		     "cluster stack passed to mount, but this filesystem " | 
 | 852 | 		     "does not support it\n"); | 
 | 853 | 		return -EINVAL; | 
 | 854 | 	} | 
 | 855 |  | 
 | 856 | 	if (ocfs2_userspace_stack(osb) && | 
 | 857 | 	    strncmp(osb->osb_cluster_stack, mopt->cluster_stack, | 
 | 858 | 		    OCFS2_STACK_LABEL_LEN)) { | 
 | 859 | 		mlog(ML_ERROR, | 
 | 860 | 		     "cluster stack passed to mount (\"%s\") does not " | 
 | 861 | 		     "match the filesystem (\"%s\")\n", | 
 | 862 | 		     mopt->cluster_stack, | 
 | 863 | 		     osb->osb_cluster_stack); | 
 | 864 | 		return -EINVAL; | 
 | 865 | 	} | 
 | 866 |  | 
 | 867 | 	return 0; | 
 | 868 | } | 
 | 869 |  | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 870 | static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend) | 
 | 871 | { | 
 | 872 | 	int type; | 
 | 873 | 	struct super_block *sb = osb->sb; | 
 | 874 | 	unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA, | 
 | 875 | 					     OCFS2_FEATURE_RO_COMPAT_GRPQUOTA}; | 
 | 876 | 	int status = 0; | 
 | 877 |  | 
 | 878 | 	for (type = 0; type < MAXQUOTAS; type++) { | 
 | 879 | 		if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type])) | 
 | 880 | 			continue; | 
 | 881 | 		if (unsuspend) | 
| Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 882 | 			status = dquot_resume(sb, type); | 
| Jan Kara | eea7feb | 2010-05-13 22:14:53 +0200 | [diff] [blame] | 883 | 		else { | 
 | 884 | 			struct ocfs2_mem_dqinfo *oinfo; | 
 | 885 |  | 
 | 886 | 			/* Cancel periodic syncing before suspending */ | 
 | 887 | 			oinfo = sb_dqinfo(sb, type)->dqi_priv; | 
 | 888 | 			cancel_delayed_work_sync(&oinfo->dqi_sync_work); | 
| Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 889 | 			status = dquot_suspend(sb, type); | 
| Jan Kara | eea7feb | 2010-05-13 22:14:53 +0200 | [diff] [blame] | 890 | 		} | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 891 | 		if (status < 0) | 
 | 892 | 			break; | 
 | 893 | 	} | 
 | 894 | 	if (status < 0) | 
 | 895 | 		mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on " | 
 | 896 | 		     "remount (error = %d).\n", status); | 
 | 897 | 	return status; | 
 | 898 | } | 
 | 899 |  | 
 | 900 | static int ocfs2_enable_quotas(struct ocfs2_super *osb) | 
 | 901 | { | 
 | 902 | 	struct inode *inode[MAXQUOTAS] = { NULL, NULL }; | 
 | 903 | 	struct super_block *sb = osb->sb; | 
 | 904 | 	unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA, | 
 | 905 | 					     OCFS2_FEATURE_RO_COMPAT_GRPQUOTA}; | 
 | 906 | 	unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE, | 
 | 907 | 					LOCAL_GROUP_QUOTA_SYSTEM_INODE }; | 
 | 908 | 	int status; | 
 | 909 | 	int type; | 
 | 910 |  | 
 | 911 | 	sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE; | 
 | 912 | 	for (type = 0; type < MAXQUOTAS; type++) { | 
 | 913 | 		if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type])) | 
 | 914 | 			continue; | 
 | 915 | 		inode[type] = ocfs2_get_system_file_inode(osb, ino[type], | 
 | 916 | 							osb->slot_num); | 
 | 917 | 		if (!inode[type]) { | 
 | 918 | 			status = -ENOENT; | 
 | 919 | 			goto out_quota_off; | 
 | 920 | 		} | 
| Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 921 | 		status = dquot_enable(inode[type], type, QFMT_OCFS2, | 
 | 922 | 				      DQUOT_USAGE_ENABLED); | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 923 | 		if (status < 0) | 
 | 924 | 			goto out_quota_off; | 
 | 925 | 	} | 
 | 926 |  | 
 | 927 | 	for (type = 0; type < MAXQUOTAS; type++) | 
 | 928 | 		iput(inode[type]); | 
 | 929 | 	return 0; | 
 | 930 | out_quota_off: | 
 | 931 | 	ocfs2_disable_quotas(osb); | 
 | 932 | 	for (type = 0; type < MAXQUOTAS; type++) | 
 | 933 | 		iput(inode[type]); | 
 | 934 | 	mlog_errno(status); | 
 | 935 | 	return status; | 
 | 936 | } | 
 | 937 |  | 
 | 938 | static void ocfs2_disable_quotas(struct ocfs2_super *osb) | 
 | 939 | { | 
 | 940 | 	int type; | 
 | 941 | 	struct inode *inode; | 
 | 942 | 	struct super_block *sb = osb->sb; | 
| Jan Kara | c06bcbf | 2010-05-13 22:14:53 +0200 | [diff] [blame] | 943 | 	struct ocfs2_mem_dqinfo *oinfo; | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 944 |  | 
 | 945 | 	/* We mostly ignore errors in this function because there's not much | 
 | 946 | 	 * we can do when we see them */ | 
 | 947 | 	for (type = 0; type < MAXQUOTAS; type++) { | 
 | 948 | 		if (!sb_has_quota_loaded(sb, type)) | 
 | 949 | 			continue; | 
| Jan Kara | c06bcbf | 2010-05-13 22:14:53 +0200 | [diff] [blame] | 950 | 		/* Cancel periodic syncing before we grab dqonoff_mutex */ | 
 | 951 | 		oinfo = sb_dqinfo(sb, type)->dqi_priv; | 
 | 952 | 		cancel_delayed_work_sync(&oinfo->dqi_sync_work); | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 953 | 		inode = igrab(sb->s_dquot.files[type]); | 
 | 954 | 		/* Turn off quotas. This will remove all dquot structures from | 
 | 955 | 		 * memory and so they will be automatically synced to global | 
 | 956 | 		 * quota files */ | 
| Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 957 | 		dquot_disable(sb, type, DQUOT_USAGE_ENABLED | | 
 | 958 | 					DQUOT_LIMITS_ENABLED); | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 959 | 		if (!inode) | 
 | 960 | 			continue; | 
 | 961 | 		iput(inode); | 
 | 962 | 	} | 
 | 963 | } | 
 | 964 |  | 
 | 965 | /* Handle quota on quotactl */ | 
 | 966 | static int ocfs2_quota_on(struct super_block *sb, int type, int format_id, | 
| Christoph Hellwig | 307ae18 | 2010-05-19 07:16:43 -0400 | [diff] [blame] | 967 | 			  char *path) | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 968 | { | 
 | 969 | 	unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA, | 
 | 970 | 					     OCFS2_FEATURE_RO_COMPAT_GRPQUOTA}; | 
 | 971 |  | 
 | 972 | 	if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type])) | 
 | 973 | 		return -EINVAL; | 
 | 974 |  | 
| Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 975 | 	return dquot_enable(sb_dqopt(sb)->files[type], type, | 
 | 976 | 			    format_id, DQUOT_LIMITS_ENABLED); | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 977 | } | 
 | 978 |  | 
 | 979 | /* Handle quota off quotactl */ | 
| Christoph Hellwig | 307ae18 | 2010-05-19 07:16:43 -0400 | [diff] [blame] | 980 | static int ocfs2_quota_off(struct super_block *sb, int type) | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 981 | { | 
| Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 982 | 	return dquot_disable(sb, type, DQUOT_LIMITS_ENABLED); | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 983 | } | 
 | 984 |  | 
| Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 985 | static const struct quotactl_ops ocfs2_quotactl_ops = { | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 986 | 	.quota_on	= ocfs2_quota_on, | 
 | 987 | 	.quota_off	= ocfs2_quota_off, | 
| Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 988 | 	.quota_sync	= dquot_quota_sync, | 
 | 989 | 	.get_info	= dquot_get_dqinfo, | 
 | 990 | 	.set_info	= dquot_set_dqinfo, | 
 | 991 | 	.get_dqblk	= dquot_get_dqblk, | 
 | 992 | 	.set_dqblk	= dquot_set_dqblk, | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 993 | }; | 
 | 994 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 995 | static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) | 
 | 996 | { | 
 | 997 | 	struct dentry *root; | 
 | 998 | 	int status, sector_size; | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 999 | 	struct mount_options parsed_options; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1000 | 	struct inode *inode = NULL; | 
 | 1001 | 	struct ocfs2_super *osb = NULL; | 
 | 1002 | 	struct buffer_head *bh = NULL; | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1003 | 	char nodestr[8]; | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 1004 | 	struct ocfs2_blockcheck_stats stats; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1005 |  | 
 | 1006 | 	mlog_entry("%p, %p, %i", sb, data, silent); | 
 | 1007 |  | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1008 | 	if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1009 | 		status = -EINVAL; | 
 | 1010 | 		goto read_super_error; | 
 | 1011 | 	} | 
 | 1012 |  | 
 | 1013 | 	/* probe for superblock */ | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 1014 | 	status = ocfs2_sb_probe(sb, &bh, §or_size, &stats); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1015 | 	if (status < 0) { | 
 | 1016 | 		mlog(ML_ERROR, "superblock probe failed!\n"); | 
 | 1017 | 		goto read_super_error; | 
 | 1018 | 	} | 
 | 1019 |  | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 1020 | 	status = ocfs2_initialize_super(sb, bh, sector_size, &stats); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1021 | 	osb = OCFS2_SB(sb); | 
 | 1022 | 	if (status < 0) { | 
 | 1023 | 		mlog_errno(status); | 
 | 1024 | 		goto read_super_error; | 
 | 1025 | 	} | 
 | 1026 | 	brelse(bh); | 
 | 1027 | 	bh = NULL; | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 1028 |  | 
| Jan Kara | 5297aad | 2009-10-15 14:54:04 +0200 | [diff] [blame] | 1029 | 	if (!ocfs2_check_set_options(sb, &parsed_options)) { | 
 | 1030 | 		status = -EINVAL; | 
 | 1031 | 		goto read_super_error; | 
 | 1032 | 	} | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1033 | 	osb->s_mount_opt = parsed_options.mount_opt; | 
 | 1034 | 	osb->s_atime_quantum = parsed_options.atime_quantum; | 
 | 1035 | 	osb->preferred_slot = parsed_options.slot; | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 1036 | 	osb->osb_commit_interval = parsed_options.commit_interval; | 
| Mark Fasheh | 73c8a80 | 2010-04-05 18:17:13 -0700 | [diff] [blame] | 1037 |  | 
 | 1038 | 	ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt); | 
| Mark Fasheh | d02f00c | 2009-12-07 13:10:48 -0800 | [diff] [blame] | 1039 | 	osb->osb_resv_level = parsed_options.resv_level; | 
| Mark Fasheh | 83f9231 | 2010-04-05 18:17:16 -0700 | [diff] [blame] | 1040 | 	osb->osb_dir_resv_level = parsed_options.resv_level; | 
 | 1041 | 	if (parsed_options.dir_resv_level == -1) | 
 | 1042 | 		osb->osb_dir_resv_level = parsed_options.resv_level; | 
 | 1043 | 	else | 
 | 1044 | 		osb->osb_dir_resv_level = parsed_options.dir_resv_level; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1045 |  | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 1046 | 	status = ocfs2_verify_userspace_stack(osb, &parsed_options); | 
 | 1047 | 	if (status) | 
 | 1048 | 		goto read_super_error; | 
 | 1049 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1050 | 	sb->s_magic = OCFS2_SUPER_MAGIC; | 
 | 1051 |  | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 1052 | 	sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | | 
 | 1053 | 		((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); | 
 | 1054 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1055 | 	/* Hard readonly mode only if: bdev_read_only, MS_RDONLY, | 
 | 1056 | 	 * heartbeat=none */ | 
 | 1057 | 	if (bdev_read_only(sb->s_bdev)) { | 
 | 1058 | 		if (!(sb->s_flags & MS_RDONLY)) { | 
 | 1059 | 			status = -EACCES; | 
 | 1060 | 			mlog(ML_ERROR, "Readonly device detected but readonly " | 
 | 1061 | 			     "mount was not specified.\n"); | 
 | 1062 | 			goto read_super_error; | 
 | 1063 | 		} | 
 | 1064 |  | 
 | 1065 | 		/* You should not be able to start a local heartbeat | 
 | 1066 | 		 * on a readonly device. */ | 
 | 1067 | 		if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) { | 
 | 1068 | 			status = -EROFS; | 
 | 1069 | 			mlog(ML_ERROR, "Local heartbeat specified on readonly " | 
 | 1070 | 			     "device.\n"); | 
 | 1071 | 			goto read_super_error; | 
 | 1072 | 		} | 
 | 1073 |  | 
 | 1074 | 		status = ocfs2_check_journals_nolocks(osb); | 
 | 1075 | 		if (status < 0) { | 
 | 1076 | 			if (status == -EROFS) | 
 | 1077 | 				mlog(ML_ERROR, "Recovery required on readonly " | 
 | 1078 | 				     "file system, but write access is " | 
 | 1079 | 				     "unavailable.\n"); | 
 | 1080 | 			else | 
| Sunil Mushran | 2bd6321 | 2010-01-25 16:57:38 -0800 | [diff] [blame] | 1081 | 				mlog_errno(status); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1082 | 			goto read_super_error; | 
 | 1083 | 		} | 
 | 1084 |  | 
 | 1085 | 		ocfs2_set_ro_flag(osb, 1); | 
 | 1086 |  | 
 | 1087 | 		printk(KERN_NOTICE "Readonly device detected. No cluster " | 
 | 1088 | 		       "services will be utilized for this mount. Recovery " | 
 | 1089 | 		       "will be skipped.\n"); | 
 | 1090 | 	} | 
 | 1091 |  | 
 | 1092 | 	if (!ocfs2_is_hard_readonly(osb)) { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1093 | 		if (sb->s_flags & MS_RDONLY) | 
 | 1094 | 			ocfs2_set_ro_flag(osb, 0); | 
 | 1095 | 	} | 
 | 1096 |  | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1097 | 	status = ocfs2_verify_heartbeat(osb); | 
 | 1098 | 	if (status < 0) { | 
 | 1099 | 		mlog_errno(status); | 
 | 1100 | 		goto read_super_error; | 
 | 1101 | 	} | 
 | 1102 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1103 | 	osb->osb_debug_root = debugfs_create_dir(osb->uuid_str, | 
 | 1104 | 						 ocfs2_debugfs_root); | 
 | 1105 | 	if (!osb->osb_debug_root) { | 
 | 1106 | 		status = -EINVAL; | 
 | 1107 | 		mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n"); | 
 | 1108 | 		goto read_super_error; | 
 | 1109 | 	} | 
 | 1110 |  | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 1111 | 	osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR, | 
 | 1112 | 					    osb->osb_debug_root, | 
 | 1113 | 					    osb, | 
 | 1114 | 					    &ocfs2_osb_debug_fops); | 
 | 1115 | 	if (!osb->osb_ctxt) { | 
 | 1116 | 		status = -EINVAL; | 
 | 1117 | 		mlog_errno(status); | 
 | 1118 | 		goto read_super_error; | 
 | 1119 | 	} | 
 | 1120 |  | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 1121 | 	if (ocfs2_meta_ecc(osb)) { | 
 | 1122 | 		status = ocfs2_blockcheck_stats_debugfs_install( | 
 | 1123 | 						&osb->osb_ecc_stats, | 
 | 1124 | 						osb->osb_debug_root); | 
 | 1125 | 		if (status) { | 
 | 1126 | 			mlog(ML_ERROR, | 
 | 1127 | 			     "Unable to create blockcheck statistics " | 
 | 1128 | 			     "files\n"); | 
 | 1129 | 			goto read_super_error; | 
 | 1130 | 		} | 
 | 1131 | 	} | 
 | 1132 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1133 | 	status = ocfs2_mount_volume(sb); | 
 | 1134 | 	if (osb->root_inode) | 
 | 1135 | 		inode = igrab(osb->root_inode); | 
 | 1136 |  | 
 | 1137 | 	if (status < 0) | 
 | 1138 | 		goto read_super_error; | 
 | 1139 |  | 
 | 1140 | 	if (!inode) { | 
 | 1141 | 		status = -EIO; | 
 | 1142 | 		mlog_errno(status); | 
 | 1143 | 		goto read_super_error; | 
 | 1144 | 	} | 
 | 1145 |  | 
 | 1146 | 	root = d_alloc_root(inode); | 
 | 1147 | 	if (!root) { | 
 | 1148 | 		status = -ENOMEM; | 
 | 1149 | 		mlog_errno(status); | 
 | 1150 | 		goto read_super_error; | 
 | 1151 | 	} | 
 | 1152 |  | 
 | 1153 | 	sb->s_root = root; | 
 | 1154 |  | 
 | 1155 | 	ocfs2_complete_mount_recovery(osb); | 
 | 1156 |  | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1157 | 	if (ocfs2_mount_local(osb)) | 
 | 1158 | 		snprintf(nodestr, sizeof(nodestr), "local"); | 
 | 1159 | 	else | 
| Joel Becker | 19fdb62 | 2008-01-30 15:38:24 -0800 | [diff] [blame] | 1160 | 		snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num); | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1161 |  | 
 | 1162 | 	printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) " | 
| Sunil Mushran | 781ee3e | 2006-04-27 16:41:31 -0700 | [diff] [blame] | 1163 | 	       "with %s data mode.\n", | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1164 | 	       osb->dev_str, nodestr, osb->slot_num, | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1165 | 	       osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" : | 
 | 1166 | 	       "ordered"); | 
 | 1167 |  | 
 | 1168 | 	atomic_set(&osb->vol_state, VOLUME_MOUNTED); | 
 | 1169 | 	wake_up(&osb->osb_mount_event); | 
 | 1170 |  | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1171 | 	/* Now we can initialize quotas because we can afford to wait | 
 | 1172 | 	 * for cluster locks recovery now. That also means that truncation | 
 | 1173 | 	 * log recovery can happen but that waits for proper quota setup */ | 
 | 1174 | 	if (!(sb->s_flags & MS_RDONLY)) { | 
 | 1175 | 		status = ocfs2_enable_quotas(osb); | 
 | 1176 | 		if (status < 0) { | 
 | 1177 | 			/* We have to err-out specially here because | 
 | 1178 | 			 * s_root is already set */ | 
 | 1179 | 			mlog_errno(status); | 
 | 1180 | 			atomic_set(&osb->vol_state, VOLUME_DISABLED); | 
 | 1181 | 			wake_up(&osb->osb_mount_event); | 
 | 1182 | 			mlog_exit(status); | 
 | 1183 | 			return status; | 
 | 1184 | 		} | 
 | 1185 | 	} | 
 | 1186 |  | 
 | 1187 | 	ocfs2_complete_quota_recovery(osb); | 
 | 1188 |  | 
 | 1189 | 	/* Now we wake up again for processes waiting for quotas */ | 
 | 1190 | 	atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS); | 
 | 1191 | 	wake_up(&osb->osb_mount_event); | 
 | 1192 |  | 
| Sunil Mushran | df152c2 | 2009-06-22 11:40:07 -0700 | [diff] [blame] | 1193 | 	/* Start this when the mount is almost sure of being successful */ | 
| Jeff Mahoney | 8b712cd | 2009-07-07 17:22:12 -0400 | [diff] [blame] | 1194 | 	ocfs2_orphan_scan_start(osb); | 
| Sunil Mushran | df152c2 | 2009-06-22 11:40:07 -0700 | [diff] [blame] | 1195 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1196 | 	mlog_exit(status); | 
 | 1197 | 	return status; | 
 | 1198 |  | 
 | 1199 | read_super_error: | 
| Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 1200 | 	brelse(bh); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1201 |  | 
 | 1202 | 	if (inode) | 
 | 1203 | 		iput(inode); | 
 | 1204 |  | 
 | 1205 | 	if (osb) { | 
 | 1206 | 		atomic_set(&osb->vol_state, VOLUME_DISABLED); | 
 | 1207 | 		wake_up(&osb->osb_mount_event); | 
 | 1208 | 		ocfs2_dismount_volume(sb, 1); | 
 | 1209 | 	} | 
 | 1210 |  | 
 | 1211 | 	mlog_exit(status); | 
 | 1212 | 	return status; | 
 | 1213 | } | 
 | 1214 |  | 
| David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1215 | static int ocfs2_get_sb(struct file_system_type *fs_type, | 
 | 1216 | 			int flags, | 
 | 1217 | 			const char *dev_name, | 
 | 1218 | 			void *data, | 
 | 1219 | 			struct vfsmount *mnt) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1220 | { | 
| David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1221 | 	return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super, | 
 | 1222 | 			   mnt); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1223 | } | 
 | 1224 |  | 
| Jan Kara | f7b1aa6 | 2009-07-20 12:12:36 +0200 | [diff] [blame] | 1225 | static void ocfs2_kill_sb(struct super_block *sb) | 
 | 1226 | { | 
 | 1227 | 	struct ocfs2_super *osb = OCFS2_SB(sb); | 
 | 1228 |  | 
| Jan Kara | 5fd1318 | 2009-07-30 17:01:53 +0200 | [diff] [blame] | 1229 | 	/* Failed mount? */ | 
 | 1230 | 	if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED) | 
 | 1231 | 		goto out; | 
 | 1232 |  | 
| Jan Kara | f7b1aa6 | 2009-07-20 12:12:36 +0200 | [diff] [blame] | 1233 | 	/* Prevent further queueing of inode drop events */ | 
 | 1234 | 	spin_lock(&dentry_list_lock); | 
 | 1235 | 	ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED); | 
 | 1236 | 	spin_unlock(&dentry_list_lock); | 
 | 1237 | 	/* Wait for work to finish and/or remove it */ | 
 | 1238 | 	cancel_work_sync(&osb->dentry_lock_work); | 
| Jan Kara | 5fd1318 | 2009-07-30 17:01:53 +0200 | [diff] [blame] | 1239 | out: | 
| Jan Kara | f7b1aa6 | 2009-07-20 12:12:36 +0200 | [diff] [blame] | 1240 | 	kill_block_super(sb); | 
 | 1241 | } | 
 | 1242 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1243 | static struct file_system_type ocfs2_fs_type = { | 
 | 1244 | 	.owner          = THIS_MODULE, | 
 | 1245 | 	.name           = "ocfs2", | 
 | 1246 | 	.get_sb         = ocfs2_get_sb, /* is this called when we mount | 
 | 1247 | 					* the fs? */ | 
| Jan Kara | f7b1aa6 | 2009-07-20 12:12:36 +0200 | [diff] [blame] | 1248 | 	.kill_sb        = ocfs2_kill_sb, | 
 | 1249 |  | 
| Mark Fasheh | 1ba9da2 | 2006-09-08 14:22:54 -0700 | [diff] [blame] | 1250 | 	.fs_flags       = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE, | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1251 | 	.next           = NULL | 
 | 1252 | }; | 
 | 1253 |  | 
| Jan Kara | 5297aad | 2009-10-15 14:54:04 +0200 | [diff] [blame] | 1254 | static int ocfs2_check_set_options(struct super_block *sb, | 
 | 1255 | 				   struct mount_options *options) | 
 | 1256 | { | 
 | 1257 | 	if (options->mount_opt & OCFS2_MOUNT_USRQUOTA && | 
 | 1258 | 	    !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | 
 | 1259 | 					 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) { | 
 | 1260 | 		mlog(ML_ERROR, "User quotas were requested, but this " | 
 | 1261 | 		     "filesystem does not have the feature enabled.\n"); | 
 | 1262 | 		return 0; | 
 | 1263 | 	} | 
 | 1264 | 	if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA && | 
 | 1265 | 	    !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | 
 | 1266 | 					 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) { | 
 | 1267 | 		mlog(ML_ERROR, "Group quotas were requested, but this " | 
 | 1268 | 		     "filesystem does not have the feature enabled.\n"); | 
 | 1269 | 		return 0; | 
 | 1270 | 	} | 
 | 1271 | 	if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL && | 
 | 1272 | 	    !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) { | 
 | 1273 | 		mlog(ML_ERROR, "ACL support requested but extended attributes " | 
 | 1274 | 		     "feature is not enabled\n"); | 
 | 1275 | 		return 0; | 
 | 1276 | 	} | 
 | 1277 | 	/* No ACL setting specified? Use XATTR feature... */ | 
 | 1278 | 	if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL | | 
 | 1279 | 				    OCFS2_MOUNT_NO_POSIX_ACL))) { | 
 | 1280 | 		if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) | 
 | 1281 | 			options->mount_opt |= OCFS2_MOUNT_POSIX_ACL; | 
 | 1282 | 		else | 
 | 1283 | 			options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL; | 
 | 1284 | 	} | 
 | 1285 | 	return 1; | 
 | 1286 | } | 
 | 1287 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1288 | static int ocfs2_parse_options(struct super_block *sb, | 
 | 1289 | 			       char *options, | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1290 | 			       struct mount_options *mopt, | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1291 | 			       int is_remount) | 
 | 1292 | { | 
 | 1293 | 	int status; | 
 | 1294 | 	char *p; | 
 | 1295 |  | 
 | 1296 | 	mlog_entry("remount: %d, options: \"%s\"\n", is_remount, | 
 | 1297 | 		   options ? options : "(none)"); | 
 | 1298 |  | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 1299 | 	mopt->commit_interval = 0; | 
| Sunil Mushran | 4b37fcb | 2010-04-13 18:00:31 -0700 | [diff] [blame] | 1300 | 	mopt->mount_opt = OCFS2_MOUNT_NOINTR; | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1301 | 	mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM; | 
 | 1302 | 	mopt->slot = OCFS2_INVALID_SLOT; | 
| Mark Fasheh | 73c8a80 | 2010-04-05 18:17:13 -0700 | [diff] [blame] | 1303 | 	mopt->localalloc_opt = -1; | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 1304 | 	mopt->cluster_stack[0] = '\0'; | 
| Mark Fasheh | d02f00c | 2009-12-07 13:10:48 -0800 | [diff] [blame] | 1305 | 	mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL; | 
| Mark Fasheh | 83f9231 | 2010-04-05 18:17:16 -0700 | [diff] [blame] | 1306 | 	mopt->dir_resv_level = -1; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1307 |  | 
 | 1308 | 	if (!options) { | 
 | 1309 | 		status = 1; | 
 | 1310 | 		goto bail; | 
 | 1311 | 	} | 
 | 1312 |  | 
 | 1313 | 	while ((p = strsep(&options, ",")) != NULL) { | 
 | 1314 | 		int token, option; | 
 | 1315 | 		substring_t args[MAX_OPT_ARGS]; | 
 | 1316 |  | 
 | 1317 | 		if (!*p) | 
 | 1318 | 			continue; | 
 | 1319 |  | 
 | 1320 | 		token = match_token(p, tokens, args); | 
 | 1321 | 		switch (token) { | 
 | 1322 | 		case Opt_hb_local: | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1323 | 			mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1324 | 			break; | 
 | 1325 | 		case Opt_hb_none: | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1326 | 			mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1327 | 			break; | 
 | 1328 | 		case Opt_barrier: | 
 | 1329 | 			if (match_int(&args[0], &option)) { | 
 | 1330 | 				status = 0; | 
 | 1331 | 				goto bail; | 
 | 1332 | 			} | 
 | 1333 | 			if (option) | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1334 | 				mopt->mount_opt |= OCFS2_MOUNT_BARRIER; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1335 | 			else | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1336 | 				mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1337 | 			break; | 
 | 1338 | 		case Opt_intr: | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1339 | 			mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1340 | 			break; | 
 | 1341 | 		case Opt_nointr: | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1342 | 			mopt->mount_opt |= OCFS2_MOUNT_NOINTR; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1343 | 			break; | 
 | 1344 | 		case Opt_err_panic: | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1345 | 			mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1346 | 			break; | 
 | 1347 | 		case Opt_err_ro: | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1348 | 			mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1349 | 			break; | 
 | 1350 | 		case Opt_data_ordered: | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1351 | 			mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1352 | 			break; | 
 | 1353 | 		case Opt_data_writeback: | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1354 | 			mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1355 | 			break; | 
| Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 1356 | 		case Opt_user_xattr: | 
 | 1357 | 			mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR; | 
 | 1358 | 			break; | 
 | 1359 | 		case Opt_nouser_xattr: | 
 | 1360 | 			mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR; | 
 | 1361 | 			break; | 
| Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 1362 | 		case Opt_atime_quantum: | 
 | 1363 | 			if (match_int(&args[0], &option)) { | 
 | 1364 | 				status = 0; | 
 | 1365 | 				goto bail; | 
 | 1366 | 			} | 
 | 1367 | 			if (option >= 0) | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1368 | 				mopt->atime_quantum = option; | 
| Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 1369 | 			break; | 
| Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 1370 | 		case Opt_slot: | 
 | 1371 | 			option = 0; | 
 | 1372 | 			if (match_int(&args[0], &option)) { | 
 | 1373 | 				status = 0; | 
 | 1374 | 				goto bail; | 
 | 1375 | 			} | 
 | 1376 | 			if (option) | 
| Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 1377 | 				mopt->slot = (s16)option; | 
| Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 1378 | 			break; | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 1379 | 		case Opt_commit: | 
 | 1380 | 			option = 0; | 
 | 1381 | 			if (match_int(&args[0], &option)) { | 
 | 1382 | 				status = 0; | 
 | 1383 | 				goto bail; | 
 | 1384 | 			} | 
 | 1385 | 			if (option < 0) | 
 | 1386 | 				return 0; | 
 | 1387 | 			if (option == 0) | 
| Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 1388 | 				option = JBD2_DEFAULT_MAX_COMMIT_AGE; | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 1389 | 			mopt->commit_interval = HZ * option; | 
 | 1390 | 			break; | 
| Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 1391 | 		case Opt_localalloc: | 
 | 1392 | 			option = 0; | 
 | 1393 | 			if (match_int(&args[0], &option)) { | 
 | 1394 | 				status = 0; | 
 | 1395 | 				goto bail; | 
 | 1396 | 			} | 
| Mark Fasheh | 73c8a80 | 2010-04-05 18:17:13 -0700 | [diff] [blame] | 1397 | 			if (option >= 0) | 
| Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 1398 | 				mopt->localalloc_opt = option; | 
 | 1399 | 			break; | 
| Mark Fasheh | 53fc622 | 2007-12-20 16:49:04 -0800 | [diff] [blame] | 1400 | 		case Opt_localflocks: | 
 | 1401 | 			/* | 
 | 1402 | 			 * Changing this during remount could race | 
 | 1403 | 			 * flock() requests, or "unbalance" existing | 
 | 1404 | 			 * ones (e.g., a lock is taken in one mode but | 
 | 1405 | 			 * dropped in the other). If users care enough | 
 | 1406 | 			 * to flip locking modes during remount, we | 
 | 1407 | 			 * could add a "local" flag to individual | 
 | 1408 | 			 * flock structures for proper tracking of | 
 | 1409 | 			 * state. | 
 | 1410 | 			 */ | 
 | 1411 | 			if (!is_remount) | 
 | 1412 | 				mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS; | 
 | 1413 | 			break; | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 1414 | 		case Opt_stack: | 
 | 1415 | 			/* Check both that the option we were passed | 
 | 1416 | 			 * is of the right length and that it is a proper | 
 | 1417 | 			 * string of the right length. | 
 | 1418 | 			 */ | 
 | 1419 | 			if (((args[0].to - args[0].from) != | 
 | 1420 | 			     OCFS2_STACK_LABEL_LEN) || | 
 | 1421 | 			    (strnlen(args[0].from, | 
 | 1422 | 				     OCFS2_STACK_LABEL_LEN) != | 
 | 1423 | 			     OCFS2_STACK_LABEL_LEN)) { | 
 | 1424 | 				mlog(ML_ERROR, | 
 | 1425 | 				     "Invalid cluster_stack option\n"); | 
 | 1426 | 				status = 0; | 
 | 1427 | 				goto bail; | 
 | 1428 | 			} | 
 | 1429 | 			memcpy(mopt->cluster_stack, args[0].from, | 
 | 1430 | 			       OCFS2_STACK_LABEL_LEN); | 
 | 1431 | 			mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0'; | 
 | 1432 | 			break; | 
| Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 1433 | 		case Opt_inode64: | 
 | 1434 | 			mopt->mount_opt |= OCFS2_MOUNT_INODE64; | 
 | 1435 | 			break; | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1436 | 		case Opt_usrquota: | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1437 | 			mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA; | 
 | 1438 | 			break; | 
 | 1439 | 		case Opt_grpquota: | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1440 | 			mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA; | 
 | 1441 | 			break; | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 1442 | 		case Opt_acl: | 
 | 1443 | 			mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL; | 
| Jan Kara | 5297aad | 2009-10-15 14:54:04 +0200 | [diff] [blame] | 1444 | 			mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL; | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 1445 | 			break; | 
 | 1446 | 		case Opt_noacl: | 
| Jan Kara | 5297aad | 2009-10-15 14:54:04 +0200 | [diff] [blame] | 1447 | 			mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL; | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 1448 | 			mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; | 
 | 1449 | 			break; | 
| Mark Fasheh | d02f00c | 2009-12-07 13:10:48 -0800 | [diff] [blame] | 1450 | 		case Opt_resv_level: | 
 | 1451 | 			if (is_remount) | 
 | 1452 | 				break; | 
 | 1453 | 			if (match_int(&args[0], &option)) { | 
 | 1454 | 				status = 0; | 
 | 1455 | 				goto bail; | 
 | 1456 | 			} | 
 | 1457 | 			if (option >= OCFS2_MIN_RESV_LEVEL && | 
 | 1458 | 			    option < OCFS2_MAX_RESV_LEVEL) | 
 | 1459 | 				mopt->resv_level = option; | 
 | 1460 | 			break; | 
| Mark Fasheh | 83f9231 | 2010-04-05 18:17:16 -0700 | [diff] [blame] | 1461 | 		case Opt_dir_resv_level: | 
 | 1462 | 			if (is_remount) | 
 | 1463 | 				break; | 
 | 1464 | 			if (match_int(&args[0], &option)) { | 
 | 1465 | 				status = 0; | 
 | 1466 | 				goto bail; | 
 | 1467 | 			} | 
 | 1468 | 			if (option >= OCFS2_MIN_RESV_LEVEL && | 
 | 1469 | 			    option < OCFS2_MAX_RESV_LEVEL) | 
 | 1470 | 				mopt->dir_resv_level = option; | 
 | 1471 | 			break; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1472 | 		default: | 
 | 1473 | 			mlog(ML_ERROR, | 
 | 1474 | 			     "Unrecognized mount option \"%s\" " | 
 | 1475 | 			     "or missing value\n", p); | 
 | 1476 | 			status = 0; | 
 | 1477 | 			goto bail; | 
 | 1478 | 		} | 
 | 1479 | 	} | 
 | 1480 |  | 
 | 1481 | 	status = 1; | 
 | 1482 |  | 
 | 1483 | bail: | 
 | 1484 | 	mlog_exit(status); | 
 | 1485 | 	return status; | 
 | 1486 | } | 
 | 1487 |  | 
| Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 1488 | static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt) | 
 | 1489 | { | 
 | 1490 | 	struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb); | 
 | 1491 | 	unsigned long opts = osb->s_mount_opt; | 
| Mark Fasheh | ebcee4b | 2008-07-28 14:55:20 -0700 | [diff] [blame] | 1492 | 	unsigned int local_alloc_megs; | 
| Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 1493 |  | 
 | 1494 | 	if (opts & OCFS2_MOUNT_HB_LOCAL) | 
 | 1495 | 		seq_printf(s, ",_netdev,heartbeat=local"); | 
 | 1496 | 	else | 
 | 1497 | 		seq_printf(s, ",heartbeat=none"); | 
 | 1498 |  | 
 | 1499 | 	if (opts & OCFS2_MOUNT_NOINTR) | 
 | 1500 | 		seq_printf(s, ",nointr"); | 
 | 1501 |  | 
 | 1502 | 	if (opts & OCFS2_MOUNT_DATA_WRITEBACK) | 
 | 1503 | 		seq_printf(s, ",data=writeback"); | 
 | 1504 | 	else | 
 | 1505 | 		seq_printf(s, ",data=ordered"); | 
 | 1506 |  | 
 | 1507 | 	if (opts & OCFS2_MOUNT_BARRIER) | 
 | 1508 | 		seq_printf(s, ",barrier=1"); | 
 | 1509 |  | 
 | 1510 | 	if (opts & OCFS2_MOUNT_ERRORS_PANIC) | 
 | 1511 | 		seq_printf(s, ",errors=panic"); | 
 | 1512 | 	else | 
 | 1513 | 		seq_printf(s, ",errors=remount-ro"); | 
 | 1514 |  | 
 | 1515 | 	if (osb->preferred_slot != OCFS2_INVALID_SLOT) | 
 | 1516 | 		seq_printf(s, ",preferred_slot=%d", osb->preferred_slot); | 
 | 1517 |  | 
 | 1518 | 	if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM) | 
 | 1519 | 		seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum); | 
 | 1520 |  | 
| Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 1521 | 	if (osb->osb_commit_interval) | 
 | 1522 | 		seq_printf(s, ",commit=%u", | 
 | 1523 | 			   (unsigned) (osb->osb_commit_interval / HZ)); | 
 | 1524 |  | 
| Mark Fasheh | ebcee4b | 2008-07-28 14:55:20 -0700 | [diff] [blame] | 1525 | 	local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits); | 
| Mark Fasheh | 6b82021 | 2010-04-05 18:17:14 -0700 | [diff] [blame] | 1526 | 	if (local_alloc_megs != ocfs2_la_default_mb(osb)) | 
| Mark Fasheh | ebcee4b | 2008-07-28 14:55:20 -0700 | [diff] [blame] | 1527 | 		seq_printf(s, ",localalloc=%d", local_alloc_megs); | 
| Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 1528 |  | 
| Mark Fasheh | 53fc622 | 2007-12-20 16:49:04 -0800 | [diff] [blame] | 1529 | 	if (opts & OCFS2_MOUNT_LOCALFLOCKS) | 
 | 1530 | 		seq_printf(s, ",localflocks,"); | 
 | 1531 |  | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 1532 | 	if (osb->osb_cluster_stack[0]) | 
 | 1533 | 		seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN, | 
 | 1534 | 			   osb->osb_cluster_stack); | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1535 | 	if (opts & OCFS2_MOUNT_USRQUOTA) | 
 | 1536 | 		seq_printf(s, ",usrquota"); | 
 | 1537 | 	if (opts & OCFS2_MOUNT_GRPQUOTA) | 
 | 1538 | 		seq_printf(s, ",grpquota"); | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 1539 |  | 
| Sunil Mushran | b0f73cf | 2008-09-05 11:29:14 -0700 | [diff] [blame] | 1540 | 	if (opts & OCFS2_MOUNT_NOUSERXATTR) | 
 | 1541 | 		seq_printf(s, ",nouser_xattr"); | 
 | 1542 | 	else | 
 | 1543 | 		seq_printf(s, ",user_xattr"); | 
 | 1544 |  | 
| Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 1545 | 	if (opts & OCFS2_MOUNT_INODE64) | 
 | 1546 | 		seq_printf(s, ",inode64"); | 
 | 1547 |  | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 1548 | 	if (opts & OCFS2_MOUNT_POSIX_ACL) | 
 | 1549 | 		seq_printf(s, ",acl"); | 
 | 1550 | 	else | 
 | 1551 | 		seq_printf(s, ",noacl"); | 
| Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 1552 |  | 
| Mark Fasheh | d02f00c | 2009-12-07 13:10:48 -0800 | [diff] [blame] | 1553 | 	if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL) | 
 | 1554 | 		seq_printf(s, ",resv_level=%d", osb->osb_resv_level); | 
 | 1555 |  | 
| Mark Fasheh | 83f9231 | 2010-04-05 18:17:16 -0700 | [diff] [blame] | 1556 | 	if (osb->osb_dir_resv_level != osb->osb_resv_level) | 
 | 1557 | 		seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level); | 
 | 1558 |  | 
| Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 1559 | 	return 0; | 
 | 1560 | } | 
 | 1561 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1562 | static int __init ocfs2_init(void) | 
 | 1563 | { | 
 | 1564 | 	int status; | 
 | 1565 |  | 
 | 1566 | 	mlog_entry_void(); | 
 | 1567 |  | 
 | 1568 | 	ocfs2_print_version(); | 
 | 1569 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1570 | 	status = init_ocfs2_uptodate_cache(); | 
 | 1571 | 	if (status < 0) { | 
 | 1572 | 		mlog_errno(status); | 
 | 1573 | 		goto leave; | 
 | 1574 | 	} | 
 | 1575 |  | 
 | 1576 | 	status = ocfs2_initialize_mem_caches(); | 
 | 1577 | 	if (status < 0) { | 
 | 1578 | 		mlog_errno(status); | 
 | 1579 | 		goto leave; | 
 | 1580 | 	} | 
 | 1581 |  | 
 | 1582 | 	ocfs2_wq = create_singlethread_workqueue("ocfs2_wq"); | 
 | 1583 | 	if (!ocfs2_wq) { | 
 | 1584 | 		status = -ENOMEM; | 
 | 1585 | 		goto leave; | 
 | 1586 | 	} | 
 | 1587 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1588 | 	ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL); | 
 | 1589 | 	if (!ocfs2_debugfs_root) { | 
 | 1590 | 		status = -EFAULT; | 
 | 1591 | 		mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n"); | 
 | 1592 | 	} | 
 | 1593 |  | 
| Mark Fasheh | 171bf93 | 2008-10-20 15:36:47 +0200 | [diff] [blame] | 1594 | 	status = ocfs2_quota_setup(); | 
 | 1595 | 	if (status) | 
 | 1596 | 		goto leave; | 
 | 1597 |  | 
| Joel Becker | 63e0c48 | 2008-01-30 16:58:36 -0800 | [diff] [blame] | 1598 | 	ocfs2_set_locking_protocol(); | 
 | 1599 |  | 
| Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 1600 | 	status = register_quota_format(&ocfs2_quota_format); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1601 | leave: | 
 | 1602 | 	if (status < 0) { | 
| Mark Fasheh | 171bf93 | 2008-10-20 15:36:47 +0200 | [diff] [blame] | 1603 | 		ocfs2_quota_shutdown(); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1604 | 		ocfs2_free_mem_caches(); | 
 | 1605 | 		exit_ocfs2_uptodate_cache(); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1606 | 	} | 
 | 1607 |  | 
 | 1608 | 	mlog_exit(status); | 
 | 1609 |  | 
 | 1610 | 	if (status >= 0) { | 
 | 1611 | 		return register_filesystem(&ocfs2_fs_type); | 
 | 1612 | 	} else | 
 | 1613 | 		return -1; | 
 | 1614 | } | 
 | 1615 |  | 
 | 1616 | static void __exit ocfs2_exit(void) | 
 | 1617 | { | 
 | 1618 | 	mlog_entry_void(); | 
 | 1619 |  | 
| Mark Fasheh | 171bf93 | 2008-10-20 15:36:47 +0200 | [diff] [blame] | 1620 | 	ocfs2_quota_shutdown(); | 
 | 1621 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1622 | 	if (ocfs2_wq) { | 
 | 1623 | 		flush_workqueue(ocfs2_wq); | 
 | 1624 | 		destroy_workqueue(ocfs2_wq); | 
 | 1625 | 	} | 
 | 1626 |  | 
| Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 1627 | 	unregister_quota_format(&ocfs2_quota_format); | 
 | 1628 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1629 | 	debugfs_remove(ocfs2_debugfs_root); | 
 | 1630 |  | 
 | 1631 | 	ocfs2_free_mem_caches(); | 
 | 1632 |  | 
 | 1633 | 	unregister_filesystem(&ocfs2_fs_type); | 
 | 1634 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1635 | 	exit_ocfs2_uptodate_cache(); | 
 | 1636 |  | 
 | 1637 | 	mlog_exit_void(); | 
 | 1638 | } | 
 | 1639 |  | 
 | 1640 | static void ocfs2_put_super(struct super_block *sb) | 
 | 1641 | { | 
 | 1642 | 	mlog_entry("(0x%p)\n", sb); | 
 | 1643 |  | 
| Christoph Hellwig | 6cfd014 | 2009-05-05 15:40:36 +0200 | [diff] [blame] | 1644 | 	lock_kernel(); | 
 | 1645 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1646 | 	ocfs2_sync_blockdev(sb); | 
 | 1647 | 	ocfs2_dismount_volume(sb, 0); | 
 | 1648 |  | 
| Christoph Hellwig | 6cfd014 | 2009-05-05 15:40:36 +0200 | [diff] [blame] | 1649 | 	unlock_kernel(); | 
 | 1650 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1651 | 	mlog_exit_void(); | 
 | 1652 | } | 
 | 1653 |  | 
| David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1654 | static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1655 | { | 
 | 1656 | 	struct ocfs2_super *osb; | 
 | 1657 | 	u32 numbits, freebits; | 
 | 1658 | 	int status; | 
 | 1659 | 	struct ocfs2_dinode *bm_lock; | 
 | 1660 | 	struct buffer_head *bh = NULL; | 
 | 1661 | 	struct inode *inode = NULL; | 
 | 1662 |  | 
| David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1663 | 	mlog_entry("(%p, %p)\n", dentry->d_sb, buf); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1664 |  | 
| David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1665 | 	osb = OCFS2_SB(dentry->d_sb); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1666 |  | 
 | 1667 | 	inode = ocfs2_get_system_file_inode(osb, | 
 | 1668 | 					    GLOBAL_BITMAP_SYSTEM_INODE, | 
 | 1669 | 					    OCFS2_INVALID_SLOT); | 
 | 1670 | 	if (!inode) { | 
 | 1671 | 		mlog(ML_ERROR, "failed to get bitmap inode\n"); | 
 | 1672 | 		status = -EIO; | 
 | 1673 | 		goto bail; | 
 | 1674 | 	} | 
 | 1675 |  | 
| Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1676 | 	status = ocfs2_inode_lock(inode, &bh, 0); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1677 | 	if (status < 0) { | 
 | 1678 | 		mlog_errno(status); | 
 | 1679 | 		goto bail; | 
 | 1680 | 	} | 
 | 1681 |  | 
 | 1682 | 	bm_lock = (struct ocfs2_dinode *) bh->b_data; | 
 | 1683 |  | 
 | 1684 | 	numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total); | 
 | 1685 | 	freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used); | 
 | 1686 |  | 
 | 1687 | 	buf->f_type = OCFS2_SUPER_MAGIC; | 
| David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1688 | 	buf->f_bsize = dentry->d_sb->s_blocksize; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1689 | 	buf->f_namelen = OCFS2_MAX_FILENAME_LEN; | 
 | 1690 | 	buf->f_blocks = ((sector_t) numbits) * | 
 | 1691 | 			(osb->s_clustersize >> osb->sb->s_blocksize_bits); | 
 | 1692 | 	buf->f_bfree = ((sector_t) freebits) * | 
 | 1693 | 		       (osb->s_clustersize >> osb->sb->s_blocksize_bits); | 
 | 1694 | 	buf->f_bavail = buf->f_bfree; | 
 | 1695 | 	buf->f_files = numbits; | 
 | 1696 | 	buf->f_ffree = freebits; | 
| Coly Li | 837711f | 2009-01-16 16:33:05 +0800 | [diff] [blame] | 1697 | 	buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN) | 
 | 1698 | 				& 0xFFFFFFFFUL; | 
 | 1699 | 	buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN, | 
 | 1700 | 				OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1701 |  | 
 | 1702 | 	brelse(bh); | 
 | 1703 |  | 
| Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1704 | 	ocfs2_inode_unlock(inode, 0); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1705 | 	status = 0; | 
 | 1706 | bail: | 
 | 1707 | 	if (inode) | 
 | 1708 | 		iput(inode); | 
 | 1709 |  | 
 | 1710 | 	mlog_exit(status); | 
 | 1711 |  | 
 | 1712 | 	return status; | 
 | 1713 | } | 
 | 1714 |  | 
| Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 1715 | static void ocfs2_inode_init_once(void *data) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1716 | { | 
 | 1717 | 	struct ocfs2_inode_info *oi = data; | 
 | 1718 |  | 
| Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1719 | 	oi->ip_flags = 0; | 
 | 1720 | 	oi->ip_open_count = 0; | 
 | 1721 | 	spin_lock_init(&oi->ip_lock); | 
 | 1722 | 	ocfs2_extent_map_init(&oi->vfs_inode); | 
 | 1723 | 	INIT_LIST_HEAD(&oi->ip_io_markers); | 
| Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1724 | 	oi->ip_dir_start_lookup = 0; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1725 |  | 
| Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1726 | 	init_rwsem(&oi->ip_alloc_sem); | 
| Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 1727 | 	init_rwsem(&oi->ip_xattr_sem); | 
| Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1728 | 	mutex_init(&oi->ip_io_mutex); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1729 |  | 
| Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1730 | 	oi->ip_blkno = 0ULL; | 
 | 1731 | 	oi->ip_clusters = 0; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1732 |  | 
| Mark Fasheh | 4fe370a | 2009-12-07 13:15:40 -0800 | [diff] [blame] | 1733 | 	ocfs2_resv_init_once(&oi->ip_la_data_resv); | 
 | 1734 |  | 
| Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1735 | 	ocfs2_lock_res_init_once(&oi->ip_rw_lockres); | 
| Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1736 | 	ocfs2_lock_res_init_once(&oi->ip_inode_lockres); | 
| Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1737 | 	ocfs2_lock_res_init_once(&oi->ip_open_lockres); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1738 |  | 
| Joel Becker | 8cb471e | 2009-02-10 20:00:41 -0800 | [diff] [blame] | 1739 | 	ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode), | 
| Joel Becker | 6e5a3d7 | 2009-02-10 19:00:37 -0800 | [diff] [blame] | 1740 | 				  &ocfs2_inode_caching_ops); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1741 |  | 
| Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1742 | 	inode_init_once(&oi->vfs_inode); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1743 | } | 
 | 1744 |  | 
 | 1745 | static int ocfs2_initialize_mem_caches(void) | 
 | 1746 | { | 
 | 1747 | 	ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache", | 
| Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 1748 | 				       sizeof(struct ocfs2_inode_info), | 
 | 1749 | 				       0, | 
 | 1750 | 				       (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| | 
 | 1751 | 						SLAB_MEM_SPREAD), | 
| Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1752 | 				       ocfs2_inode_init_once); | 
| Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 1753 | 	ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache", | 
 | 1754 | 					sizeof(struct ocfs2_dquot), | 
 | 1755 | 					0, | 
 | 1756 | 					(SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| | 
 | 1757 | 						SLAB_MEM_SPREAD), | 
 | 1758 | 					NULL); | 
 | 1759 | 	ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache", | 
 | 1760 | 					sizeof(struct ocfs2_quota_chunk), | 
 | 1761 | 					0, | 
 | 1762 | 					(SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD), | 
 | 1763 | 					NULL); | 
 | 1764 | 	if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep || | 
 | 1765 | 	    !ocfs2_qf_chunk_cachep) { | 
 | 1766 | 		if (ocfs2_inode_cachep) | 
 | 1767 | 			kmem_cache_destroy(ocfs2_inode_cachep); | 
 | 1768 | 		if (ocfs2_dquot_cachep) | 
 | 1769 | 			kmem_cache_destroy(ocfs2_dquot_cachep); | 
 | 1770 | 		if (ocfs2_qf_chunk_cachep) | 
 | 1771 | 			kmem_cache_destroy(ocfs2_qf_chunk_cachep); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1772 | 		return -ENOMEM; | 
| Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 1773 | 	} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1774 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1775 | 	return 0; | 
 | 1776 | } | 
 | 1777 |  | 
 | 1778 | static void ocfs2_free_mem_caches(void) | 
 | 1779 | { | 
 | 1780 | 	if (ocfs2_inode_cachep) | 
 | 1781 | 		kmem_cache_destroy(ocfs2_inode_cachep); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1782 | 	ocfs2_inode_cachep = NULL; | 
| Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 1783 |  | 
 | 1784 | 	if (ocfs2_dquot_cachep) | 
 | 1785 | 		kmem_cache_destroy(ocfs2_dquot_cachep); | 
 | 1786 | 	ocfs2_dquot_cachep = NULL; | 
 | 1787 |  | 
 | 1788 | 	if (ocfs2_qf_chunk_cachep) | 
 | 1789 | 		kmem_cache_destroy(ocfs2_qf_chunk_cachep); | 
 | 1790 | 	ocfs2_qf_chunk_cachep = NULL; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1791 | } | 
 | 1792 |  | 
 | 1793 | static int ocfs2_get_sector(struct super_block *sb, | 
 | 1794 | 			    struct buffer_head **bh, | 
 | 1795 | 			    int block, | 
 | 1796 | 			    int sect_size) | 
 | 1797 | { | 
 | 1798 | 	if (!sb_set_blocksize(sb, sect_size)) { | 
 | 1799 | 		mlog(ML_ERROR, "unable to set blocksize\n"); | 
 | 1800 | 		return -EIO; | 
 | 1801 | 	} | 
 | 1802 |  | 
 | 1803 | 	*bh = sb_getblk(sb, block); | 
 | 1804 | 	if (!*bh) { | 
 | 1805 | 		mlog_errno(-EIO); | 
 | 1806 | 		return -EIO; | 
 | 1807 | 	} | 
 | 1808 | 	lock_buffer(*bh); | 
 | 1809 | 	if (!buffer_dirty(*bh)) | 
 | 1810 | 		clear_buffer_uptodate(*bh); | 
 | 1811 | 	unlock_buffer(*bh); | 
 | 1812 | 	ll_rw_block(READ, 1, bh); | 
 | 1813 | 	wait_on_buffer(*bh); | 
| wengang wang | 28d57d4 | 2009-02-13 10:11:47 +0800 | [diff] [blame] | 1814 | 	if (!buffer_uptodate(*bh)) { | 
 | 1815 | 		mlog_errno(-EIO); | 
 | 1816 | 		brelse(*bh); | 
 | 1817 | 		*bh = NULL; | 
 | 1818 | 		return -EIO; | 
 | 1819 | 	} | 
 | 1820 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1821 | 	return 0; | 
 | 1822 | } | 
 | 1823 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1824 | static int ocfs2_mount_volume(struct super_block *sb) | 
 | 1825 | { | 
 | 1826 | 	int status = 0; | 
 | 1827 | 	int unlock_super = 0; | 
 | 1828 | 	struct ocfs2_super *osb = OCFS2_SB(sb); | 
 | 1829 |  | 
 | 1830 | 	mlog_entry_void(); | 
 | 1831 |  | 
 | 1832 | 	if (ocfs2_is_hard_readonly(osb)) | 
 | 1833 | 		goto leave; | 
 | 1834 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1835 | 	status = ocfs2_dlm_init(osb); | 
 | 1836 | 	if (status < 0) { | 
 | 1837 | 		mlog_errno(status); | 
 | 1838 | 		goto leave; | 
 | 1839 | 	} | 
 | 1840 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1841 | 	status = ocfs2_super_lock(osb, 1); | 
 | 1842 | 	if (status < 0) { | 
 | 1843 | 		mlog_errno(status); | 
 | 1844 | 		goto leave; | 
 | 1845 | 	} | 
 | 1846 | 	unlock_super = 1; | 
 | 1847 |  | 
 | 1848 | 	/* This will load up the node map and add ourselves to it. */ | 
 | 1849 | 	status = ocfs2_find_slot(osb); | 
 | 1850 | 	if (status < 0) { | 
 | 1851 | 		mlog_errno(status); | 
 | 1852 | 		goto leave; | 
 | 1853 | 	} | 
 | 1854 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1855 | 	/* load all node-local system inodes */ | 
 | 1856 | 	status = ocfs2_init_local_system_inodes(osb); | 
 | 1857 | 	if (status < 0) { | 
 | 1858 | 		mlog_errno(status); | 
 | 1859 | 		goto leave; | 
 | 1860 | 	} | 
 | 1861 |  | 
 | 1862 | 	status = ocfs2_check_volume(osb); | 
 | 1863 | 	if (status < 0) { | 
 | 1864 | 		mlog_errno(status); | 
 | 1865 | 		goto leave; | 
 | 1866 | 	} | 
 | 1867 |  | 
 | 1868 | 	status = ocfs2_truncate_log_init(osb); | 
| Tao Ma | 06c59bb | 2009-05-19 06:47:20 +0800 | [diff] [blame] | 1869 | 	if (status < 0) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1870 | 		mlog_errno(status); | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1871 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1872 | leave: | 
 | 1873 | 	if (unlock_super) | 
 | 1874 | 		ocfs2_super_unlock(osb, 1); | 
 | 1875 |  | 
 | 1876 | 	mlog_exit(status); | 
 | 1877 | 	return status; | 
 | 1878 | } | 
 | 1879 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1880 | static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err) | 
 | 1881 | { | 
| Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 1882 | 	int tmp, hangup_needed = 0; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1883 | 	struct ocfs2_super *osb = NULL; | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1884 | 	char nodestr[8]; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1885 |  | 
 | 1886 | 	mlog_entry("(0x%p)\n", sb); | 
 | 1887 |  | 
 | 1888 | 	BUG_ON(!sb); | 
 | 1889 | 	osb = OCFS2_SB(sb); | 
 | 1890 | 	BUG_ON(!osb); | 
 | 1891 |  | 
| Sunil Mushran | 5039750 | 2008-12-17 14:17:43 -0800 | [diff] [blame] | 1892 | 	debugfs_remove(osb->osb_ctxt); | 
 | 1893 |  | 
| Jan Kara | f7b1aa6 | 2009-07-20 12:12:36 +0200 | [diff] [blame] | 1894 | 	/* | 
 | 1895 | 	 * Flush inode dropping work queue so that deletes are | 
 | 1896 | 	 * performed while the filesystem is still working | 
 | 1897 | 	 */ | 
 | 1898 | 	ocfs2_drop_all_dl_inodes(osb); | 
 | 1899 |  | 
| Sunil Mushran | 692684e | 2009-06-19 16:53:17 -0700 | [diff] [blame] | 1900 | 	/* Orphan scan should be stopped as early as possible */ | 
 | 1901 | 	ocfs2_orphan_scan_stop(osb); | 
 | 1902 |  | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1903 | 	ocfs2_disable_quotas(osb); | 
 | 1904 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1905 | 	ocfs2_shutdown_local_alloc(osb); | 
 | 1906 |  | 
 | 1907 | 	ocfs2_truncate_log_shutdown(osb); | 
 | 1908 |  | 
| Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1909 | 	/* This will disable recovery and flush any recovery work. */ | 
 | 1910 | 	ocfs2_recovery_exit(osb); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1911 |  | 
 | 1912 | 	ocfs2_journal_shutdown(osb); | 
 | 1913 |  | 
 | 1914 | 	ocfs2_sync_blockdev(sb); | 
 | 1915 |  | 
| Tao Ma | 374a263 | 2009-08-24 11:13:37 +0800 | [diff] [blame] | 1916 | 	ocfs2_purge_refcount_trees(osb); | 
 | 1917 |  | 
| Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 1918 | 	/* No cluster connection means we've failed during mount, so skip | 
 | 1919 | 	 * all the steps which depended on that to complete. */ | 
 | 1920 | 	if (osb->cconn) { | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1921 | 		tmp = ocfs2_super_lock(osb, 1); | 
 | 1922 | 		if (tmp < 0) { | 
 | 1923 | 			mlog_errno(tmp); | 
 | 1924 | 			return; | 
 | 1925 | 		} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1926 | 	} | 
 | 1927 |  | 
| Mark Fasheh | 19b613d | 2007-10-04 14:47:09 -0700 | [diff] [blame] | 1928 | 	if (osb->slot_num != OCFS2_INVALID_SLOT) | 
 | 1929 | 		ocfs2_put_slot(osb); | 
 | 1930 |  | 
| Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 1931 | 	if (osb->cconn) | 
| Mark Fasheh | 19b613d | 2007-10-04 14:47:09 -0700 | [diff] [blame] | 1932 | 		ocfs2_super_unlock(osb, 1); | 
 | 1933 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1934 | 	ocfs2_release_system_inodes(osb); | 
 | 1935 |  | 
| Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 1936 | 	/* | 
| Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 1937 | 	 * If we're dismounting due to mount error, mount.ocfs2 will clean | 
 | 1938 | 	 * up heartbeat.  If we're a local mount, there is no heartbeat. | 
 | 1939 | 	 * If we failed before we got a uuid_str yet, we can't stop | 
 | 1940 | 	 * heartbeat.  Otherwise, do it. | 
 | 1941 | 	 */ | 
 | 1942 | 	if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str) | 
| Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 1943 | 		hangup_needed = 1; | 
 | 1944 |  | 
 | 1945 | 	if (osb->cconn) | 
 | 1946 | 		ocfs2_dlm_shutdown(osb, hangup_needed); | 
 | 1947 |  | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 1948 | 	ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats); | 
| Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 1949 | 	debugfs_remove(osb->osb_debug_root); | 
 | 1950 |  | 
 | 1951 | 	if (hangup_needed) | 
| Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 1952 | 		ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str)); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1953 |  | 
 | 1954 | 	atomic_set(&osb->vol_state, VOLUME_DISMOUNTED); | 
 | 1955 |  | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1956 | 	if (ocfs2_mount_local(osb)) | 
 | 1957 | 		snprintf(nodestr, sizeof(nodestr), "local"); | 
 | 1958 | 	else | 
| Joel Becker | 19fdb62 | 2008-01-30 15:38:24 -0800 | [diff] [blame] | 1959 | 		snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num); | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1960 |  | 
 | 1961 | 	printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n", | 
 | 1962 | 	       osb->dev_str, nodestr); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1963 |  | 
 | 1964 | 	ocfs2_delete_osb(osb); | 
 | 1965 | 	kfree(osb); | 
 | 1966 | 	sb->s_dev = 0; | 
 | 1967 | 	sb->s_fs_info = NULL; | 
 | 1968 | } | 
 | 1969 |  | 
 | 1970 | static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid, | 
 | 1971 | 				unsigned uuid_bytes) | 
 | 1972 | { | 
 | 1973 | 	int i, ret; | 
 | 1974 | 	char *ptr; | 
 | 1975 |  | 
 | 1976 | 	BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN); | 
 | 1977 |  | 
| Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 1978 | 	osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1979 | 	if (osb->uuid_str == NULL) | 
 | 1980 | 		return -ENOMEM; | 
 | 1981 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1982 | 	for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) { | 
 | 1983 | 		/* print with null */ | 
 | 1984 | 		ret = snprintf(ptr, 3, "%02X", uuid[i]); | 
 | 1985 | 		if (ret != 2) /* drop super cleans up */ | 
 | 1986 | 			return -EINVAL; | 
 | 1987 | 		/* then only advance past the last char */ | 
 | 1988 | 		ptr += 2; | 
 | 1989 | 	} | 
 | 1990 |  | 
 | 1991 | 	return 0; | 
 | 1992 | } | 
 | 1993 |  | 
 | 1994 | static int ocfs2_initialize_super(struct super_block *sb, | 
 | 1995 | 				  struct buffer_head *bh, | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 1996 | 				  int sector_size, | 
 | 1997 | 				  struct ocfs2_blockcheck_stats *stats) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1998 | { | 
| Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 1999 | 	int status; | 
| Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 2000 | 	int i, cbits, bbits; | 
 | 2001 | 	struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2002 | 	struct inode *inode = NULL; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2003 | 	struct ocfs2_journal *journal; | 
 | 2004 | 	__le32 uuid_net_key; | 
 | 2005 | 	struct ocfs2_super *osb; | 
 | 2006 |  | 
 | 2007 | 	mlog_entry_void(); | 
 | 2008 |  | 
| Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 2009 | 	osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2010 | 	if (!osb) { | 
 | 2011 | 		status = -ENOMEM; | 
 | 2012 | 		mlog_errno(status); | 
 | 2013 | 		goto bail; | 
 | 2014 | 	} | 
 | 2015 |  | 
 | 2016 | 	sb->s_fs_info = osb; | 
 | 2017 | 	sb->s_op = &ocfs2_sops; | 
 | 2018 | 	sb->s_export_op = &ocfs2_export_ops; | 
| Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 2019 | 	sb->s_qcop = &ocfs2_quotactl_ops; | 
 | 2020 | 	sb->dq_op = &ocfs2_quota_operations; | 
| Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 2021 | 	sb->s_xattr = ocfs2_xattr_handlers; | 
| Mark Fasheh | e0dceaf | 2007-08-09 16:52:30 -0700 | [diff] [blame] | 2022 | 	sb->s_time_gran = 1; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2023 | 	sb->s_flags |= MS_NOATIME; | 
 | 2024 | 	/* this is needed to support O_LARGEFILE */ | 
| Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 2025 | 	cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits); | 
 | 2026 | 	bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits); | 
 | 2027 | 	sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2028 |  | 
| Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 2029 | 	osb->osb_dx_mask = (1 << (cbits - bbits)) - 1; | 
 | 2030 |  | 
 | 2031 | 	for (i = 0; i < 3; i++) | 
 | 2032 | 		osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]); | 
 | 2033 | 	osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash); | 
 | 2034 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2035 | 	osb->sb = sb; | 
 | 2036 | 	/* Save off for ocfs2_rw_direct */ | 
 | 2037 | 	osb->s_sectsize_bits = blksize_bits(sector_size); | 
| Eric Sesterhenn / snakebyte | ebdec83 | 2006-01-27 10:32:52 +0100 | [diff] [blame] | 2038 | 	BUG_ON(!osb->s_sectsize_bits); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2039 |  | 
| Mark Fasheh | 34d024f | 2007-09-24 15:56:19 -0700 | [diff] [blame] | 2040 | 	spin_lock_init(&osb->dc_task_lock); | 
 | 2041 | 	init_waitqueue_head(&osb->dc_event); | 
 | 2042 | 	osb->dc_work_sequence = 0; | 
 | 2043 | 	osb->dc_wake_sequence = 0; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2044 | 	INIT_LIST_HEAD(&osb->blocked_lock_list); | 
 | 2045 | 	osb->blocked_lock_count = 0; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2046 | 	spin_lock_init(&osb->osb_lock); | 
| Tao Ma | c8b9cf9 | 2009-02-24 17:40:26 -0800 | [diff] [blame] | 2047 | 	spin_lock_init(&osb->osb_xattr_lock); | 
| Tiger Yang | b89c542 | 2010-01-25 14:11:06 +0800 | [diff] [blame] | 2048 | 	ocfs2_init_steal_slots(osb); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2049 |  | 
 | 2050 | 	atomic_set(&osb->alloc_stats.moves, 0); | 
 | 2051 | 	atomic_set(&osb->alloc_stats.local_data, 0); | 
 | 2052 | 	atomic_set(&osb->alloc_stats.bitmap_data, 0); | 
 | 2053 | 	atomic_set(&osb->alloc_stats.bg_allocs, 0); | 
 | 2054 | 	atomic_set(&osb->alloc_stats.bg_extends, 0); | 
 | 2055 |  | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 2056 | 	/* Copy the blockcheck stats from the superblock probe */ | 
 | 2057 | 	osb->osb_ecc_stats = *stats; | 
 | 2058 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2059 | 	ocfs2_init_node_maps(osb); | 
 | 2060 |  | 
 | 2061 | 	snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u", | 
 | 2062 | 		 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev)); | 
 | 2063 |  | 
| Jeff Mahoney | 8b712cd | 2009-07-07 17:22:12 -0400 | [diff] [blame] | 2064 | 	ocfs2_orphan_scan_init(osb); | 
 | 2065 |  | 
| Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 2066 | 	status = ocfs2_recovery_init(osb); | 
 | 2067 | 	if (status) { | 
 | 2068 | 		mlog(ML_ERROR, "Unable to initialize recovery state\n"); | 
 | 2069 | 		mlog_errno(status); | 
 | 2070 | 		goto bail; | 
 | 2071 | 	} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2072 |  | 
 | 2073 | 	init_waitqueue_head(&osb->checkpoint_event); | 
 | 2074 | 	atomic_set(&osb->needs_checkpoint, 0); | 
 | 2075 |  | 
| Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 2076 | 	osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM; | 
 | 2077 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2078 | 	osb->slot_num = OCFS2_INVALID_SLOT; | 
 | 2079 |  | 
| Tiger Yang | 8154da3 | 2008-08-18 17:11:46 +0800 | [diff] [blame] | 2080 | 	osb->s_xattr_inline_size = le16_to_cpu( | 
 | 2081 | 					di->id2.i_super.s_xattr_inline_size); | 
| Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 2082 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2083 | 	osb->local_alloc_state = OCFS2_LA_UNUSED; | 
 | 2084 | 	osb->local_alloc_bh = NULL; | 
| Mark Fasheh | 9c7af40 | 2008-07-28 18:02:53 -0700 | [diff] [blame] | 2085 | 	INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2086 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2087 | 	init_waitqueue_head(&osb->osb_mount_event); | 
 | 2088 |  | 
| Mark Fasheh | d02f00c | 2009-12-07 13:10:48 -0800 | [diff] [blame] | 2089 | 	status = ocfs2_resmap_init(osb, &osb->osb_la_resmap); | 
 | 2090 | 	if (status) { | 
 | 2091 | 		mlog_errno(status); | 
 | 2092 | 		goto bail; | 
 | 2093 | 	} | 
 | 2094 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2095 | 	osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL); | 
 | 2096 | 	if (!osb->vol_label) { | 
 | 2097 | 		mlog(ML_ERROR, "unable to alloc vol label\n"); | 
 | 2098 | 		status = -ENOMEM; | 
 | 2099 | 		goto bail; | 
 | 2100 | 	} | 
 | 2101 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2102 | 	osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots); | 
 | 2103 | 	if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) { | 
 | 2104 | 		mlog(ML_ERROR, "Invalid number of node slots (%u)\n", | 
 | 2105 | 		     osb->max_slots); | 
 | 2106 | 		status = -EINVAL; | 
 | 2107 | 		goto bail; | 
 | 2108 | 	} | 
| Sunil Mushran | 781ee3e | 2006-04-27 16:41:31 -0700 | [diff] [blame] | 2109 | 	mlog(0, "max_slots for this device: %u\n", osb->max_slots); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2110 |  | 
| Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 2111 | 	osb->slot_recovery_generations = | 
 | 2112 | 		kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations), | 
 | 2113 | 			GFP_KERNEL); | 
 | 2114 | 	if (!osb->slot_recovery_generations) { | 
 | 2115 | 		status = -ENOMEM; | 
 | 2116 | 		mlog_errno(status); | 
 | 2117 | 		goto bail; | 
 | 2118 | 	} | 
 | 2119 |  | 
| Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 2120 | 	init_waitqueue_head(&osb->osb_wipe_event); | 
 | 2121 | 	osb->osb_orphan_wipes = kcalloc(osb->max_slots, | 
 | 2122 | 					sizeof(*osb->osb_orphan_wipes), | 
 | 2123 | 					GFP_KERNEL); | 
 | 2124 | 	if (!osb->osb_orphan_wipes) { | 
 | 2125 | 		status = -ENOMEM; | 
 | 2126 | 		mlog_errno(status); | 
 | 2127 | 		goto bail; | 
 | 2128 | 	} | 
 | 2129 |  | 
| Tao Ma | 374a263 | 2009-08-24 11:13:37 +0800 | [diff] [blame] | 2130 | 	osb->osb_rf_lock_tree = RB_ROOT; | 
 | 2131 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2132 | 	osb->s_feature_compat = | 
 | 2133 | 		le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat); | 
 | 2134 | 	osb->s_feature_ro_compat = | 
 | 2135 | 		le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat); | 
 | 2136 | 	osb->s_feature_incompat = | 
 | 2137 | 		le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat); | 
 | 2138 |  | 
 | 2139 | 	if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) { | 
 | 2140 | 		mlog(ML_ERROR, "couldn't mount because of unsupported " | 
 | 2141 | 		     "optional features (%x).\n", i); | 
 | 2142 | 		status = -EINVAL; | 
 | 2143 | 		goto bail; | 
 | 2144 | 	} | 
 | 2145 | 	if (!(osb->sb->s_flags & MS_RDONLY) && | 
 | 2146 | 	    (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) { | 
 | 2147 | 		mlog(ML_ERROR, "couldn't mount RDWR because of " | 
 | 2148 | 		     "unsupported optional features (%x).\n", i); | 
 | 2149 | 		status = -EINVAL; | 
 | 2150 | 		goto bail; | 
 | 2151 | 	} | 
 | 2152 |  | 
| Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 2153 | 	if (ocfs2_userspace_stack(osb)) { | 
 | 2154 | 		memcpy(osb->osb_cluster_stack, | 
 | 2155 | 		       OCFS2_RAW_SB(di)->s_cluster_info.ci_stack, | 
 | 2156 | 		       OCFS2_STACK_LABEL_LEN); | 
 | 2157 | 		osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0'; | 
 | 2158 | 		if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) { | 
 | 2159 | 			mlog(ML_ERROR, | 
 | 2160 | 			     "couldn't mount because of an invalid " | 
 | 2161 | 			     "cluster stack label (%s) \n", | 
 | 2162 | 			     osb->osb_cluster_stack); | 
 | 2163 | 			status = -EINVAL; | 
 | 2164 | 			goto bail; | 
 | 2165 | 		} | 
 | 2166 | 	} else { | 
 | 2167 | 		/* The empty string is identical with classic tools that | 
 | 2168 | 		 * don't know about s_cluster_info. */ | 
 | 2169 | 		osb->osb_cluster_stack[0] = '\0'; | 
 | 2170 | 	} | 
 | 2171 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2172 | 	get_random_bytes(&osb->s_next_generation, sizeof(u32)); | 
 | 2173 |  | 
 | 2174 | 	/* FIXME | 
 | 2175 | 	 * This should be done in ocfs2_journal_init(), but unknown | 
 | 2176 | 	 * ordering issues will cause the filesystem to crash. | 
 | 2177 | 	 * If anyone wants to figure out what part of the code | 
 | 2178 | 	 * refers to osb->journal before ocfs2_journal_init() is run, | 
 | 2179 | 	 * be my guest. | 
 | 2180 | 	 */ | 
 | 2181 | 	/* initialize our journal structure */ | 
 | 2182 |  | 
| Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 2183 | 	journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2184 | 	if (!journal) { | 
 | 2185 | 		mlog(ML_ERROR, "unable to alloc journal\n"); | 
 | 2186 | 		status = -ENOMEM; | 
 | 2187 | 		goto bail; | 
 | 2188 | 	} | 
 | 2189 | 	osb->journal = journal; | 
 | 2190 | 	journal->j_osb = osb; | 
 | 2191 |  | 
 | 2192 | 	atomic_set(&journal->j_num_trans, 0); | 
 | 2193 | 	init_rwsem(&journal->j_trans_barrier); | 
 | 2194 | 	init_waitqueue_head(&journal->j_checkpointed); | 
 | 2195 | 	spin_lock_init(&journal->j_lock); | 
 | 2196 | 	journal->j_trans_id = (unsigned long) 1; | 
 | 2197 | 	INIT_LIST_HEAD(&journal->j_la_cleanups); | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2198 | 	INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2199 | 	journal->j_state = OCFS2_JOURNAL_FREE; | 
 | 2200 |  | 
| Jan Kara | ea455f8 | 2009-01-12 23:20:31 +0100 | [diff] [blame] | 2201 | 	INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes); | 
 | 2202 | 	osb->dentry_lock_list = NULL; | 
 | 2203 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2204 | 	/* get some pseudo constants for clustersize bits */ | 
 | 2205 | 	osb->s_clustersize_bits = | 
 | 2206 | 		le32_to_cpu(di->id2.i_super.s_clustersize_bits); | 
 | 2207 | 	osb->s_clustersize = 1 << osb->s_clustersize_bits; | 
 | 2208 | 	mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits); | 
 | 2209 |  | 
 | 2210 | 	if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE || | 
 | 2211 | 	    osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) { | 
 | 2212 | 		mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n", | 
 | 2213 | 		     osb->s_clustersize); | 
 | 2214 | 		status = -EINVAL; | 
 | 2215 | 		goto bail; | 
 | 2216 | 	} | 
 | 2217 |  | 
 | 2218 | 	if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1) | 
 | 2219 | 	    > (u32)~0UL) { | 
 | 2220 | 		mlog(ML_ERROR, "Volume might try to write to blocks beyond " | 
 | 2221 | 		     "what jbd can address in 32 bits.\n"); | 
 | 2222 | 		status = -EINVAL; | 
 | 2223 | 		goto bail; | 
 | 2224 | 	} | 
 | 2225 |  | 
 | 2226 | 	if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid, | 
 | 2227 | 				 sizeof(di->id2.i_super.s_uuid))) { | 
 | 2228 | 		mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n"); | 
 | 2229 | 		status = -ENOMEM; | 
 | 2230 | 		goto bail; | 
 | 2231 | 	} | 
 | 2232 |  | 
| Mark Fasheh | 7842704 | 2006-05-04 12:03:26 -0700 | [diff] [blame] | 2233 | 	memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key)); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2234 |  | 
 | 2235 | 	strncpy(osb->vol_label, di->id2.i_super.s_label, 63); | 
 | 2236 | 	osb->vol_label[63] = '\0'; | 
 | 2237 | 	osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno); | 
 | 2238 | 	osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno); | 
 | 2239 | 	osb->first_cluster_group_blkno = | 
 | 2240 | 		le64_to_cpu(di->id2.i_super.s_first_cluster_group); | 
 | 2241 | 	osb->fs_generation = le32_to_cpu(di->i_fs_generation); | 
| Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 2242 | 	osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2243 | 	mlog(0, "vol_label: %s\n", osb->vol_label); | 
 | 2244 | 	mlog(0, "uuid: %s\n", osb->uuid_str); | 
| Mark Fasheh | b069705 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 2245 | 	mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n", | 
 | 2246 | 	     (unsigned long long)osb->root_blkno, | 
 | 2247 | 	     (unsigned long long)osb->system_dir_blkno); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2248 |  | 
 | 2249 | 	osb->osb_dlm_debug = ocfs2_new_dlm_debug(); | 
 | 2250 | 	if (!osb->osb_dlm_debug) { | 
 | 2251 | 		status = -ENOMEM; | 
 | 2252 | 		mlog_errno(status); | 
 | 2253 | 		goto bail; | 
 | 2254 | 	} | 
 | 2255 |  | 
 | 2256 | 	atomic_set(&osb->vol_state, VOLUME_INIT); | 
 | 2257 |  | 
 | 2258 | 	/* load root, system_dir, and all global system inodes */ | 
 | 2259 | 	status = ocfs2_init_global_system_inodes(osb); | 
 | 2260 | 	if (status < 0) { | 
 | 2261 | 		mlog_errno(status); | 
 | 2262 | 		goto bail; | 
 | 2263 | 	} | 
 | 2264 |  | 
 | 2265 | 	/* | 
 | 2266 | 	 * global bitmap | 
 | 2267 | 	 */ | 
 | 2268 | 	inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE, | 
 | 2269 | 					    OCFS2_INVALID_SLOT); | 
 | 2270 | 	if (!inode) { | 
 | 2271 | 		status = -EINVAL; | 
 | 2272 | 		mlog_errno(status); | 
 | 2273 | 		goto bail; | 
 | 2274 | 	} | 
 | 2275 |  | 
 | 2276 | 	osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno; | 
| Mark Fasheh | 6b82021 | 2010-04-05 18:17:14 -0700 | [diff] [blame] | 2277 | 	osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2278 | 	iput(inode); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2279 |  | 
| Tao Ma | 8571882 | 2010-04-13 14:38:06 +0800 | [diff] [blame] | 2280 | 	osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0, | 
 | 2281 | 				 osb->s_feature_incompat) * 8; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2282 |  | 
 | 2283 | 	status = ocfs2_init_slot_info(osb); | 
 | 2284 | 	if (status < 0) { | 
 | 2285 | 		mlog_errno(status); | 
 | 2286 | 		goto bail; | 
 | 2287 | 	} | 
 | 2288 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2289 | bail: | 
 | 2290 | 	mlog_exit(status); | 
 | 2291 | 	return status; | 
 | 2292 | } | 
 | 2293 |  | 
 | 2294 | /* | 
 | 2295 |  * will return: -EAGAIN if it is ok to keep searching for superblocks | 
 | 2296 |  *              -EINVAL if there is a bad superblock | 
 | 2297 |  *              0 on success | 
 | 2298 |  */ | 
 | 2299 | static int ocfs2_verify_volume(struct ocfs2_dinode *di, | 
 | 2300 | 			       struct buffer_head *bh, | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 2301 | 			       u32 blksz, | 
 | 2302 | 			       struct ocfs2_blockcheck_stats *stats) | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2303 | { | 
 | 2304 | 	int status = -EAGAIN; | 
 | 2305 |  | 
 | 2306 | 	mlog_entry_void(); | 
 | 2307 |  | 
 | 2308 | 	if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE, | 
 | 2309 | 		   strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) { | 
| Joel Becker | d030cc9 | 2008-12-11 15:04:14 -0800 | [diff] [blame] | 2310 | 		/* We have to do a raw check of the feature here */ | 
 | 2311 | 		if (le32_to_cpu(di->id2.i_super.s_feature_incompat) & | 
 | 2312 | 		    OCFS2_FEATURE_INCOMPAT_META_ECC) { | 
 | 2313 | 			status = ocfs2_block_check_validate(bh->b_data, | 
 | 2314 | 							    bh->b_size, | 
| Joel Becker | 73be192 | 2009-01-06 14:57:08 -0800 | [diff] [blame] | 2315 | 							    &di->i_check, | 
 | 2316 | 							    stats); | 
| Joel Becker | d030cc9 | 2008-12-11 15:04:14 -0800 | [diff] [blame] | 2317 | 			if (status) | 
 | 2318 | 				goto out; | 
 | 2319 | 		} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2320 | 		status = -EINVAL; | 
 | 2321 | 		if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) { | 
 | 2322 | 			mlog(ML_ERROR, "found superblock with incorrect block " | 
 | 2323 | 			     "size: found %u, should be %u\n", | 
 | 2324 | 			     1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits), | 
 | 2325 | 			       blksz); | 
 | 2326 | 		} else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) != | 
 | 2327 | 			   OCFS2_MAJOR_REV_LEVEL || | 
 | 2328 | 			   le16_to_cpu(di->id2.i_super.s_minor_rev_level) != | 
 | 2329 | 			   OCFS2_MINOR_REV_LEVEL) { | 
 | 2330 | 			mlog(ML_ERROR, "found superblock with bad version: " | 
 | 2331 | 			     "found %u.%u, should be %u.%u\n", | 
 | 2332 | 			     le16_to_cpu(di->id2.i_super.s_major_rev_level), | 
 | 2333 | 			     le16_to_cpu(di->id2.i_super.s_minor_rev_level), | 
 | 2334 | 			     OCFS2_MAJOR_REV_LEVEL, | 
 | 2335 | 			     OCFS2_MINOR_REV_LEVEL); | 
 | 2336 | 		} else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) { | 
 | 2337 | 			mlog(ML_ERROR, "bad block number on superblock: " | 
| Mark Fasheh | b069705 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 2338 | 			     "found %llu, should be %llu\n", | 
| Mark Fasheh | 1ca1a11 | 2007-04-27 16:01:25 -0700 | [diff] [blame] | 2339 | 			     (unsigned long long)le64_to_cpu(di->i_blkno), | 
| Mark Fasheh | b069705 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 2340 | 			     (unsigned long long)bh->b_blocknr); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2341 | 		} else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 || | 
 | 2342 | 			    le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) { | 
 | 2343 | 			mlog(ML_ERROR, "bad cluster size found: %u\n", | 
 | 2344 | 			     1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits)); | 
 | 2345 | 		} else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) { | 
 | 2346 | 			mlog(ML_ERROR, "bad root_blkno: 0\n"); | 
 | 2347 | 		} else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) { | 
 | 2348 | 			mlog(ML_ERROR, "bad system_dir_blkno: 0\n"); | 
 | 2349 | 		} else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) { | 
 | 2350 | 			mlog(ML_ERROR, | 
 | 2351 | 			     "Superblock slots found greater than file system " | 
 | 2352 | 			     "maximum: found %u, max %u\n", | 
 | 2353 | 			     le16_to_cpu(di->id2.i_super.s_max_slots), | 
 | 2354 | 			     OCFS2_MAX_SLOTS); | 
 | 2355 | 		} else { | 
 | 2356 | 			/* found it! */ | 
 | 2357 | 			status = 0; | 
 | 2358 | 		} | 
 | 2359 | 	} | 
 | 2360 |  | 
| Joel Becker | d030cc9 | 2008-12-11 15:04:14 -0800 | [diff] [blame] | 2361 | out: | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2362 | 	mlog_exit(status); | 
 | 2363 | 	return status; | 
 | 2364 | } | 
 | 2365 |  | 
 | 2366 | static int ocfs2_check_volume(struct ocfs2_super *osb) | 
 | 2367 | { | 
| Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 2368 | 	int status; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2369 | 	int dirty; | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 2370 | 	int local; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2371 | 	struct ocfs2_dinode *local_alloc = NULL; /* only used if we | 
 | 2372 | 						  * recover | 
 | 2373 | 						  * ourselves. */ | 
 | 2374 |  | 
 | 2375 | 	mlog_entry_void(); | 
 | 2376 |  | 
 | 2377 | 	/* Init our journal object. */ | 
 | 2378 | 	status = ocfs2_journal_init(osb->journal, &dirty); | 
 | 2379 | 	if (status < 0) { | 
 | 2380 | 		mlog(ML_ERROR, "Could not initialize journal!\n"); | 
 | 2381 | 		goto finally; | 
 | 2382 | 	} | 
 | 2383 |  | 
 | 2384 | 	/* If the journal was unmounted cleanly then we don't want to | 
 | 2385 | 	 * recover anything. Otherwise, journal_load will do that | 
 | 2386 | 	 * dirty work for us :) */ | 
 | 2387 | 	if (!dirty) { | 
 | 2388 | 		status = ocfs2_journal_wipe(osb->journal, 0); | 
 | 2389 | 		if (status < 0) { | 
 | 2390 | 			mlog_errno(status); | 
 | 2391 | 			goto finally; | 
 | 2392 | 		} | 
 | 2393 | 	} else { | 
 | 2394 | 		mlog(ML_NOTICE, "File system was not unmounted cleanly, " | 
 | 2395 | 		     "recovering volume.\n"); | 
 | 2396 | 	} | 
 | 2397 |  | 
| Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 2398 | 	local = ocfs2_mount_local(osb); | 
 | 2399 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2400 | 	/* will play back anything left in the journal. */ | 
| Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 2401 | 	status = ocfs2_journal_load(osb->journal, local, dirty); | 
| Wengang Wang | 01af482 | 2008-06-10 14:24:48 +0800 | [diff] [blame] | 2402 | 	if (status < 0) { | 
 | 2403 | 		mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status); | 
 | 2404 | 		goto finally; | 
 | 2405 | 	} | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2406 |  | 
 | 2407 | 	if (dirty) { | 
 | 2408 | 		/* recover my local alloc if we didn't unmount cleanly. */ | 
 | 2409 | 		status = ocfs2_begin_local_alloc_recovery(osb, | 
 | 2410 | 							  osb->slot_num, | 
 | 2411 | 							  &local_alloc); | 
 | 2412 | 		if (status < 0) { | 
 | 2413 | 			mlog_errno(status); | 
 | 2414 | 			goto finally; | 
 | 2415 | 		} | 
 | 2416 | 		/* we complete the recovery process after we've marked | 
 | 2417 | 		 * ourselves as mounted. */ | 
 | 2418 | 	} | 
 | 2419 |  | 
 | 2420 | 	mlog(0, "Journal loaded.\n"); | 
 | 2421 |  | 
 | 2422 | 	status = ocfs2_load_local_alloc(osb); | 
 | 2423 | 	if (status < 0) { | 
 | 2424 | 		mlog_errno(status); | 
 | 2425 | 		goto finally; | 
 | 2426 | 	} | 
 | 2427 |  | 
 | 2428 | 	if (dirty) { | 
 | 2429 | 		/* Recovery will be completed after we've mounted the | 
 | 2430 | 		 * rest of the volume. */ | 
 | 2431 | 		osb->dirty = 1; | 
 | 2432 | 		osb->local_alloc_copy = local_alloc; | 
 | 2433 | 		local_alloc = NULL; | 
 | 2434 | 	} | 
 | 2435 |  | 
 | 2436 | 	/* go through each journal, trylock it and if you get the | 
 | 2437 | 	 * lock, and it's marked as dirty, set the bit in the recover | 
 | 2438 | 	 * map and launch a recovery thread for it. */ | 
 | 2439 | 	status = ocfs2_mark_dead_nodes(osb); | 
| Srinivas Eeda | 9140db0 | 2009-03-06 14:21:46 -0800 | [diff] [blame] | 2440 | 	if (status < 0) { | 
 | 2441 | 		mlog_errno(status); | 
 | 2442 | 		goto finally; | 
 | 2443 | 	} | 
 | 2444 |  | 
 | 2445 | 	status = ocfs2_compute_replay_slots(osb); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2446 | 	if (status < 0) | 
 | 2447 | 		mlog_errno(status); | 
 | 2448 |  | 
 | 2449 | finally: | 
 | 2450 | 	if (local_alloc) | 
 | 2451 | 		kfree(local_alloc); | 
 | 2452 |  | 
 | 2453 | 	mlog_exit(status); | 
 | 2454 | 	return status; | 
 | 2455 | } | 
 | 2456 |  | 
 | 2457 | /* | 
 | 2458 |  * The routine gets called from dismount or close whenever a dismount on | 
 | 2459 |  * volume is requested and the osb open count becomes 1. | 
 | 2460 |  * It will remove the osb from the global list and also free up all the | 
 | 2461 |  * initialized resources and fileobject. | 
 | 2462 |  */ | 
 | 2463 | static void ocfs2_delete_osb(struct ocfs2_super *osb) | 
 | 2464 | { | 
 | 2465 | 	mlog_entry_void(); | 
 | 2466 |  | 
 | 2467 | 	/* This function assumes that the caller has the main osb resource */ | 
 | 2468 |  | 
| Mark Fasheh | 8e8a460 | 2008-02-01 11:59:09 -0800 | [diff] [blame] | 2469 | 	ocfs2_free_slot_info(osb); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2470 |  | 
| Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 2471 | 	kfree(osb->osb_orphan_wipes); | 
| Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 2472 | 	kfree(osb->slot_recovery_generations); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2473 | 	/* FIXME | 
 | 2474 | 	 * This belongs in journal shutdown, but because we have to | 
| Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 2475 | 	 * allocate osb->journal at the start of ocfs2_initialize_osb(), | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2476 | 	 * we free it here. | 
 | 2477 | 	 */ | 
 | 2478 | 	kfree(osb->journal); | 
 | 2479 | 	if (osb->local_alloc_copy) | 
 | 2480 | 		kfree(osb->local_alloc_copy); | 
 | 2481 | 	kfree(osb->uuid_str); | 
 | 2482 | 	ocfs2_put_dlm_debug(osb->osb_dlm_debug); | 
 | 2483 | 	memset(osb, 0, sizeof(struct ocfs2_super)); | 
 | 2484 |  | 
 | 2485 | 	mlog_exit_void(); | 
 | 2486 | } | 
 | 2487 |  | 
 | 2488 | /* Put OCFS2 into a readonly state, or (if the user specifies it), | 
 | 2489 |  * panic(). We do not support continue-on-error operation. */ | 
 | 2490 | static void ocfs2_handle_error(struct super_block *sb) | 
 | 2491 | { | 
 | 2492 | 	struct ocfs2_super *osb = OCFS2_SB(sb); | 
 | 2493 |  | 
 | 2494 | 	if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) | 
 | 2495 | 		panic("OCFS2: (device %s): panic forced after error\n", | 
 | 2496 | 		      sb->s_id); | 
 | 2497 |  | 
 | 2498 | 	ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS); | 
 | 2499 |  | 
 | 2500 | 	if (sb->s_flags & MS_RDONLY && | 
 | 2501 | 	    (ocfs2_is_soft_readonly(osb) || | 
 | 2502 | 	     ocfs2_is_hard_readonly(osb))) | 
 | 2503 | 		return; | 
 | 2504 |  | 
 | 2505 | 	printk(KERN_CRIT "File system is now read-only due to the potential " | 
 | 2506 | 	       "of on-disk corruption. Please run fsck.ocfs2 once the file " | 
 | 2507 | 	       "system is unmounted.\n"); | 
 | 2508 | 	sb->s_flags |= MS_RDONLY; | 
 | 2509 | 	ocfs2_set_ro_flag(osb, 0); | 
 | 2510 | } | 
 | 2511 |  | 
 | 2512 | static char error_buf[1024]; | 
 | 2513 |  | 
 | 2514 | void __ocfs2_error(struct super_block *sb, | 
 | 2515 | 		   const char *function, | 
 | 2516 | 		   const char *fmt, ...) | 
 | 2517 | { | 
 | 2518 | 	va_list args; | 
 | 2519 |  | 
 | 2520 | 	va_start(args, fmt); | 
| Alexey Dobriyan | 4a6e617 | 2006-12-06 20:37:04 -0800 | [diff] [blame] | 2521 | 	vsnprintf(error_buf, sizeof(error_buf), fmt, args); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2522 | 	va_end(args); | 
 | 2523 |  | 
 | 2524 | 	/* Not using mlog here because we want to show the actual | 
 | 2525 | 	 * function the error came from. */ | 
 | 2526 | 	printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n", | 
 | 2527 | 	       sb->s_id, function, error_buf); | 
 | 2528 |  | 
 | 2529 | 	ocfs2_handle_error(sb); | 
 | 2530 | } | 
 | 2531 |  | 
 | 2532 | /* Handle critical errors. This is intentionally more drastic than | 
 | 2533 |  * ocfs2_handle_error, so we only use for things like journal errors, | 
 | 2534 |  * etc. */ | 
 | 2535 | void __ocfs2_abort(struct super_block* sb, | 
 | 2536 | 		   const char *function, | 
 | 2537 | 		   const char *fmt, ...) | 
 | 2538 | { | 
 | 2539 | 	va_list args; | 
 | 2540 |  | 
 | 2541 | 	va_start(args, fmt); | 
| Alexey Dobriyan | 4a6e617 | 2006-12-06 20:37:04 -0800 | [diff] [blame] | 2542 | 	vsnprintf(error_buf, sizeof(error_buf), fmt, args); | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2543 | 	va_end(args); | 
 | 2544 |  | 
 | 2545 | 	printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n", | 
 | 2546 | 	       sb->s_id, function, error_buf); | 
 | 2547 |  | 
 | 2548 | 	/* We don't have the cluster support yet to go straight to | 
 | 2549 | 	 * hard readonly in here. Until then, we want to keep | 
 | 2550 | 	 * ocfs2_abort() so that we can at least mark critical | 
 | 2551 | 	 * errors. | 
 | 2552 | 	 * | 
 | 2553 | 	 * TODO: This should abort the journal and alert other nodes | 
 | 2554 | 	 * that our slot needs recovery. */ | 
 | 2555 |  | 
 | 2556 | 	/* Force a panic(). This stinks, but it's better than letting | 
 | 2557 | 	 * things continue without having a proper hard readonly | 
 | 2558 | 	 * here. */ | 
| Sunil Mushran | a2f2ddb | 2009-08-19 15:16:01 -0700 | [diff] [blame] | 2559 | 	if (!ocfs2_mount_local(OCFS2_SB(sb))) | 
 | 2560 | 		OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC; | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2561 | 	ocfs2_handle_error(sb); | 
 | 2562 | } | 
 | 2563 |  | 
| Joel Becker | e4b963f | 2009-09-02 17:17:36 -0700 | [diff] [blame] | 2564 | /* | 
 | 2565 |  * Void signal blockers, because in-kernel sigprocmask() only fails | 
 | 2566 |  * when SIG_* is wrong. | 
 | 2567 |  */ | 
 | 2568 | void ocfs2_block_signals(sigset_t *oldset) | 
 | 2569 | { | 
 | 2570 | 	int rc; | 
 | 2571 | 	sigset_t blocked; | 
 | 2572 |  | 
 | 2573 | 	sigfillset(&blocked); | 
 | 2574 | 	rc = sigprocmask(SIG_BLOCK, &blocked, oldset); | 
 | 2575 | 	BUG_ON(rc); | 
 | 2576 | } | 
 | 2577 |  | 
 | 2578 | void ocfs2_unblock_signals(sigset_t *oldset) | 
 | 2579 | { | 
 | 2580 | 	int rc = sigprocmask(SIG_SETMASK, oldset, NULL); | 
 | 2581 | 	BUG_ON(rc); | 
 | 2582 | } | 
 | 2583 |  | 
| Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2584 | module_init(ocfs2_init); | 
 | 2585 | module_exit(ocfs2_exit); |