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