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> |
| 31 | #include <linux/utsname.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/random.h> |
| 34 | #include <linux/statfs.h> |
| 35 | #include <linux/moduleparam.h> |
| 36 | #include <linux/blkdev.h> |
| 37 | #include <linux/socket.h> |
| 38 | #include <linux/inet.h> |
| 39 | #include <linux/parser.h> |
| 40 | #include <linux/crc32.h> |
| 41 | #include <linux/debugfs.h> |
Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 42 | #include <linux/mount.h> |
Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 43 | #include <linux/seq_file.h> |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 44 | |
| 45 | #define MLOG_MASK_PREFIX ML_SUPER |
| 46 | #include <cluster/masklog.h> |
| 47 | |
| 48 | #include "ocfs2.h" |
| 49 | |
| 50 | /* this should be the only file to include a version 1 header */ |
| 51 | #include "ocfs1_fs_compat.h" |
| 52 | |
| 53 | #include "alloc.h" |
| 54 | #include "dlmglue.h" |
| 55 | #include "export.h" |
| 56 | #include "extent_map.h" |
| 57 | #include "heartbeat.h" |
| 58 | #include "inode.h" |
| 59 | #include "journal.h" |
| 60 | #include "localalloc.h" |
| 61 | #include "namei.h" |
| 62 | #include "slot_map.h" |
| 63 | #include "super.h" |
| 64 | #include "sysfile.h" |
| 65 | #include "uptodate.h" |
| 66 | #include "ver.h" |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 67 | #include "xattr.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 68 | |
| 69 | #include "buffer_head_io.h" |
| 70 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 71 | static struct kmem_cache *ocfs2_inode_cachep = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 72 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 73 | /* OCFS2 needs to schedule several differnt types of work which |
| 74 | * require cluster locking, disk I/O, recovery waits, etc. Since these |
| 75 | * types of work tend to be heavy we avoid using the kernel events |
| 76 | * workqueue and schedule on our own. */ |
| 77 | struct workqueue_struct *ocfs2_wq = NULL; |
| 78 | |
| 79 | static struct dentry *ocfs2_debugfs_root = NULL; |
| 80 | |
| 81 | MODULE_AUTHOR("Oracle"); |
| 82 | MODULE_LICENSE("GPL"); |
| 83 | |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 84 | struct mount_options |
| 85 | { |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 86 | unsigned long commit_interval; |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 87 | unsigned long mount_opt; |
| 88 | unsigned int atime_quantum; |
| 89 | signed short slot; |
Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 90 | unsigned int localalloc_opt; |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 91 | char cluster_stack[OCFS2_STACK_LABEL_LEN + 1]; |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 92 | }; |
| 93 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 94 | static int ocfs2_parse_options(struct super_block *sb, char *options, |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 95 | struct mount_options *mopt, |
Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 96 | int is_remount); |
Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 97 | static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 98 | static void ocfs2_put_super(struct super_block *sb); |
| 99 | static int ocfs2_mount_volume(struct super_block *sb); |
| 100 | static int ocfs2_remount(struct super_block *sb, int *flags, char *data); |
| 101 | static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err); |
| 102 | static int ocfs2_initialize_mem_caches(void); |
| 103 | static void ocfs2_free_mem_caches(void); |
| 104 | static void ocfs2_delete_osb(struct ocfs2_super *osb); |
| 105 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 106 | static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 107 | |
| 108 | static int ocfs2_sync_fs(struct super_block *sb, int wait); |
| 109 | |
| 110 | static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb); |
| 111 | static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb); |
Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 112 | static void ocfs2_release_system_inodes(struct ocfs2_super *osb); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 113 | static int ocfs2_check_volume(struct ocfs2_super *osb); |
| 114 | static int ocfs2_verify_volume(struct ocfs2_dinode *di, |
| 115 | struct buffer_head *bh, |
| 116 | u32 sectsize); |
| 117 | static int ocfs2_initialize_super(struct super_block *sb, |
| 118 | struct buffer_head *bh, |
| 119 | int sector_size); |
| 120 | static int ocfs2_get_sector(struct super_block *sb, |
| 121 | struct buffer_head **bh, |
| 122 | int block, |
| 123 | int sect_size); |
| 124 | static void ocfs2_write_super(struct super_block *sb); |
| 125 | static struct inode *ocfs2_alloc_inode(struct super_block *sb); |
| 126 | static void ocfs2_destroy_inode(struct inode *inode); |
| 127 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 128 | static const struct super_operations ocfs2_sops = { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 129 | .statfs = ocfs2_statfs, |
| 130 | .alloc_inode = ocfs2_alloc_inode, |
| 131 | .destroy_inode = ocfs2_destroy_inode, |
| 132 | .drop_inode = ocfs2_drop_inode, |
| 133 | .clear_inode = ocfs2_clear_inode, |
| 134 | .delete_inode = ocfs2_delete_inode, |
| 135 | .sync_fs = ocfs2_sync_fs, |
| 136 | .write_super = ocfs2_write_super, |
| 137 | .put_super = ocfs2_put_super, |
| 138 | .remount_fs = ocfs2_remount, |
Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 139 | .show_options = ocfs2_show_options, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | enum { |
| 143 | Opt_barrier, |
| 144 | Opt_err_panic, |
| 145 | Opt_err_ro, |
| 146 | Opt_intr, |
| 147 | Opt_nointr, |
| 148 | Opt_hb_none, |
| 149 | Opt_hb_local, |
| 150 | Opt_data_ordered, |
| 151 | Opt_data_writeback, |
Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 152 | Opt_atime_quantum, |
Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 153 | Opt_slot, |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 154 | Opt_commit, |
Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 155 | Opt_localalloc, |
Mark Fasheh | 53fc622 | 2007-12-20 16:49:04 -0800 | [diff] [blame] | 156 | Opt_localflocks, |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 157 | Opt_stack, |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 158 | Opt_user_xattr, |
| 159 | Opt_nouser_xattr, |
Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 160 | Opt_inode64, |
Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 161 | Opt_acl, |
| 162 | Opt_noacl, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 163 | Opt_err, |
| 164 | }; |
| 165 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 166 | static const match_table_t tokens = { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 167 | {Opt_barrier, "barrier=%u"}, |
| 168 | {Opt_err_panic, "errors=panic"}, |
| 169 | {Opt_err_ro, "errors=remount-ro"}, |
| 170 | {Opt_intr, "intr"}, |
| 171 | {Opt_nointr, "nointr"}, |
| 172 | {Opt_hb_none, OCFS2_HB_NONE}, |
| 173 | {Opt_hb_local, OCFS2_HB_LOCAL}, |
| 174 | {Opt_data_ordered, "data=ordered"}, |
| 175 | {Opt_data_writeback, "data=writeback"}, |
Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 176 | {Opt_atime_quantum, "atime_quantum=%u"}, |
Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 177 | {Opt_slot, "preferred_slot=%u"}, |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 178 | {Opt_commit, "commit=%u"}, |
Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 179 | {Opt_localalloc, "localalloc=%d"}, |
Mark Fasheh | 53fc622 | 2007-12-20 16:49:04 -0800 | [diff] [blame] | 180 | {Opt_localflocks, "localflocks"}, |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 181 | {Opt_stack, "cluster_stack=%s"}, |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 182 | {Opt_user_xattr, "user_xattr"}, |
| 183 | {Opt_nouser_xattr, "nouser_xattr"}, |
Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 184 | {Opt_inode64, "inode64"}, |
Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 185 | {Opt_acl, "acl"}, |
| 186 | {Opt_noacl, "noacl"}, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 187 | {Opt_err, NULL} |
| 188 | }; |
| 189 | |
| 190 | /* |
| 191 | * write_super and sync_fs ripped right out of ext3. |
| 192 | */ |
| 193 | static void ocfs2_write_super(struct super_block *sb) |
| 194 | { |
Ingo Molnar | 7892f2f | 2006-01-09 15:59:25 -0800 | [diff] [blame] | 195 | if (mutex_trylock(&sb->s_lock) != 0) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 196 | BUG(); |
| 197 | sb->s_dirt = 0; |
| 198 | } |
| 199 | |
| 200 | static int ocfs2_sync_fs(struct super_block *sb, int wait) |
| 201 | { |
Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 202 | int status; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 203 | tid_t target; |
| 204 | struct ocfs2_super *osb = OCFS2_SB(sb); |
| 205 | |
| 206 | sb->s_dirt = 0; |
| 207 | |
| 208 | if (ocfs2_is_hard_readonly(osb)) |
| 209 | return -EROFS; |
| 210 | |
| 211 | if (wait) { |
| 212 | status = ocfs2_flush_truncate_log(osb); |
| 213 | if (status < 0) |
| 214 | mlog_errno(status); |
| 215 | } else { |
| 216 | ocfs2_schedule_truncate_log_flush(osb, 0); |
| 217 | } |
| 218 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 219 | if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal, |
| 220 | &target)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 221 | if (wait) |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 222 | jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal, |
| 223 | target); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 224 | } |
| 225 | return 0; |
| 226 | } |
| 227 | |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame^] | 228 | static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino) |
| 229 | { |
| 230 | if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA) |
| 231 | && (ino == USER_QUOTA_SYSTEM_INODE |
| 232 | || ino == LOCAL_USER_QUOTA_SYSTEM_INODE)) |
| 233 | return 0; |
| 234 | if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA) |
| 235 | && (ino == GROUP_QUOTA_SYSTEM_INODE |
| 236 | || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE)) |
| 237 | return 0; |
| 238 | return 1; |
| 239 | } |
| 240 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 241 | static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb) |
| 242 | { |
| 243 | struct inode *new = NULL; |
| 244 | int status = 0; |
| 245 | int i; |
| 246 | |
| 247 | mlog_entry_void(); |
| 248 | |
Jan Kara | 5fa0613 | 2008-01-11 00:11:45 +0100 | [diff] [blame] | 249 | new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 250 | if (IS_ERR(new)) { |
| 251 | status = PTR_ERR(new); |
| 252 | mlog_errno(status); |
| 253 | goto bail; |
| 254 | } |
| 255 | osb->root_inode = new; |
| 256 | |
Jan Kara | 5fa0613 | 2008-01-11 00:11:45 +0100 | [diff] [blame] | 257 | 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] | 258 | if (IS_ERR(new)) { |
| 259 | status = PTR_ERR(new); |
| 260 | mlog_errno(status); |
| 261 | goto bail; |
| 262 | } |
| 263 | osb->sys_root_inode = new; |
| 264 | |
| 265 | for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE; |
| 266 | i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) { |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame^] | 267 | if (!ocfs2_need_system_inode(osb, i)) |
| 268 | continue; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 269 | new = ocfs2_get_system_file_inode(osb, i, osb->slot_num); |
| 270 | if (!new) { |
| 271 | ocfs2_release_system_inodes(osb); |
| 272 | status = -EINVAL; |
| 273 | mlog_errno(status); |
| 274 | /* FIXME: Should ERROR_RO_FS */ |
| 275 | mlog(ML_ERROR, "Unable to load system inode %d, " |
| 276 | "possibly corrupt fs?", i); |
| 277 | goto bail; |
| 278 | } |
| 279 | // the array now has one ref, so drop this one |
| 280 | iput(new); |
| 281 | } |
| 282 | |
| 283 | bail: |
| 284 | mlog_exit(status); |
| 285 | return status; |
| 286 | } |
| 287 | |
| 288 | static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb) |
| 289 | { |
| 290 | struct inode *new = NULL; |
| 291 | int status = 0; |
| 292 | int i; |
| 293 | |
| 294 | mlog_entry_void(); |
| 295 | |
| 296 | for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1; |
| 297 | i < NUM_SYSTEM_INODES; |
| 298 | i++) { |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame^] | 299 | if (!ocfs2_need_system_inode(osb, i)) |
| 300 | continue; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 301 | new = ocfs2_get_system_file_inode(osb, i, osb->slot_num); |
| 302 | if (!new) { |
| 303 | ocfs2_release_system_inodes(osb); |
| 304 | status = -EINVAL; |
| 305 | mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n", |
| 306 | status, i, osb->slot_num); |
| 307 | goto bail; |
| 308 | } |
| 309 | /* the array now has one ref, so drop this one */ |
| 310 | iput(new); |
| 311 | } |
| 312 | |
| 313 | bail: |
| 314 | mlog_exit(status); |
| 315 | return status; |
| 316 | } |
| 317 | |
Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 318 | static void ocfs2_release_system_inodes(struct ocfs2_super *osb) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 319 | { |
Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 320 | int i; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 321 | struct inode *inode; |
| 322 | |
| 323 | mlog_entry_void(); |
| 324 | |
| 325 | for (i = 0; i < NUM_SYSTEM_INODES; i++) { |
| 326 | inode = osb->system_inodes[i]; |
| 327 | if (inode) { |
| 328 | iput(inode); |
| 329 | osb->system_inodes[i] = NULL; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | inode = osb->sys_root_inode; |
| 334 | if (inode) { |
| 335 | iput(inode); |
| 336 | osb->sys_root_inode = NULL; |
| 337 | } |
| 338 | |
| 339 | inode = osb->root_inode; |
| 340 | if (inode) { |
| 341 | iput(inode); |
| 342 | osb->root_inode = NULL; |
| 343 | } |
| 344 | |
Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 345 | mlog_exit(0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | /* We're allocating fs objects, use GFP_NOFS */ |
| 349 | static struct inode *ocfs2_alloc_inode(struct super_block *sb) |
| 350 | { |
| 351 | struct ocfs2_inode_info *oi; |
| 352 | |
Christoph Lameter | e6b4f8d | 2006-12-06 20:33:14 -0800 | [diff] [blame] | 353 | oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 354 | if (!oi) |
| 355 | return NULL; |
| 356 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 357 | jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 358 | return &oi->vfs_inode; |
| 359 | } |
| 360 | |
| 361 | static void ocfs2_destroy_inode(struct inode *inode) |
| 362 | { |
| 363 | kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode)); |
| 364 | } |
| 365 | |
Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 366 | static unsigned long long ocfs2_max_file_offset(unsigned int bbits, |
| 367 | unsigned int cbits) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 368 | { |
Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 369 | unsigned int bytes = 1 << cbits; |
| 370 | unsigned int trim = bytes; |
| 371 | unsigned int bitshift = 32; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 372 | |
Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 373 | /* |
| 374 | * i_size and all block offsets in ocfs2 are always 64 bits |
| 375 | * wide. i_clusters is 32 bits, in cluster-sized units. So on |
| 376 | * 64 bit platforms, cluster size will be the limiting factor. |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 377 | */ |
| 378 | |
| 379 | #if BITS_PER_LONG == 32 |
| 380 | # if defined(CONFIG_LBD) |
Alexey Dobriyan | 2ecd05a | 2006-10-11 01:22:05 -0700 | [diff] [blame] | 381 | BUILD_BUG_ON(sizeof(sector_t) != 8); |
Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 382 | /* |
| 383 | * We might be limited by page cache size. |
| 384 | */ |
| 385 | if (bytes > PAGE_CACHE_SIZE) { |
| 386 | bytes = PAGE_CACHE_SIZE; |
| 387 | trim = 1; |
| 388 | /* |
| 389 | * Shift by 31 here so that we don't get larger than |
| 390 | * MAX_LFS_FILESIZE |
| 391 | */ |
| 392 | bitshift = 31; |
| 393 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 394 | # else |
Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 395 | /* |
| 396 | * We are limited by the size of sector_t. Use block size, as |
| 397 | * that's what we expose to the VFS. |
| 398 | */ |
| 399 | bytes = 1 << bbits; |
| 400 | trim = 1; |
| 401 | bitshift = 31; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 402 | # endif |
| 403 | #endif |
| 404 | |
Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 405 | /* |
| 406 | * Trim by a whole cluster when we can actually approach the |
| 407 | * on-disk limits. Otherwise we can overflow i_clusters when |
| 408 | * an extent start is at the max offset. |
| 409 | */ |
| 410 | return (((unsigned long long)bytes) << bitshift) - trim; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static int ocfs2_remount(struct super_block *sb, int *flags, char *data) |
| 414 | { |
| 415 | int incompat_features; |
| 416 | int ret = 0; |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 417 | struct mount_options parsed_options; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 418 | struct ocfs2_super *osb = OCFS2_SB(sb); |
| 419 | |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 420 | if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 421 | ret = -EINVAL; |
| 422 | goto out; |
| 423 | } |
| 424 | |
| 425 | if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) != |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 426 | (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 427 | ret = -EINVAL; |
| 428 | mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n"); |
| 429 | goto out; |
| 430 | } |
| 431 | |
| 432 | if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) != |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 433 | (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 434 | ret = -EINVAL; |
| 435 | mlog(ML_ERROR, "Cannot change data mode on remount\n"); |
| 436 | goto out; |
| 437 | } |
| 438 | |
Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 439 | /* Probably don't want this on remount; it might |
| 440 | * mess with other nodes */ |
| 441 | if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) && |
| 442 | (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) { |
| 443 | ret = -EINVAL; |
| 444 | mlog(ML_ERROR, "Cannot enable inode64 on remount\n"); |
| 445 | goto out; |
| 446 | } |
| 447 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 448 | /* We're going to/from readonly mode. */ |
| 449 | if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) { |
| 450 | /* Lock here so the check of HARD_RO and the potential |
| 451 | * setting of SOFT_RO is atomic. */ |
| 452 | spin_lock(&osb->osb_lock); |
| 453 | if (osb->osb_flags & OCFS2_OSB_HARD_RO) { |
| 454 | mlog(ML_ERROR, "Remount on readonly device is forbidden.\n"); |
| 455 | ret = -EROFS; |
| 456 | goto unlock_osb; |
| 457 | } |
| 458 | |
| 459 | if (*flags & MS_RDONLY) { |
| 460 | mlog(0, "Going to ro mode.\n"); |
| 461 | sb->s_flags |= MS_RDONLY; |
| 462 | osb->osb_flags |= OCFS2_OSB_SOFT_RO; |
| 463 | } else { |
| 464 | mlog(0, "Making ro filesystem writeable.\n"); |
| 465 | |
| 466 | if (osb->osb_flags & OCFS2_OSB_ERROR_FS) { |
| 467 | mlog(ML_ERROR, "Cannot remount RDWR " |
| 468 | "filesystem due to previous errors.\n"); |
| 469 | ret = -EROFS; |
| 470 | goto unlock_osb; |
| 471 | } |
| 472 | incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP); |
| 473 | if (incompat_features) { |
| 474 | mlog(ML_ERROR, "Cannot remount RDWR because " |
| 475 | "of unsupported optional features " |
| 476 | "(%x).\n", incompat_features); |
| 477 | ret = -EINVAL; |
| 478 | goto unlock_osb; |
| 479 | } |
| 480 | sb->s_flags &= ~MS_RDONLY; |
| 481 | osb->osb_flags &= ~OCFS2_OSB_SOFT_RO; |
| 482 | } |
| 483 | unlock_osb: |
| 484 | spin_unlock(&osb->osb_lock); |
| 485 | } |
| 486 | |
| 487 | if (!ret) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 488 | /* Only save off the new mount options in case of a successful |
| 489 | * remount. */ |
Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 490 | if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR)) |
| 491 | parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 492 | osb->s_mount_opt = parsed_options.mount_opt; |
| 493 | osb->s_atime_quantum = parsed_options.atime_quantum; |
| 494 | osb->preferred_slot = parsed_options.slot; |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 495 | if (parsed_options.commit_interval) |
| 496 | osb->osb_commit_interval = parsed_options.commit_interval; |
Mark Fasheh | e001e79 | 2007-11-07 14:21:45 -0800 | [diff] [blame] | 497 | |
| 498 | if (!ocfs2_is_hard_readonly(osb)) |
| 499 | ocfs2_set_journal_params(osb); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 500 | } |
| 501 | out: |
| 502 | return ret; |
| 503 | } |
| 504 | |
| 505 | static int ocfs2_sb_probe(struct super_block *sb, |
| 506 | struct buffer_head **bh, |
| 507 | int *sector_size) |
| 508 | { |
Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 509 | int status, tmpstat; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 510 | struct ocfs1_vol_disk_hdr *hdr; |
| 511 | struct ocfs2_dinode *di; |
| 512 | int blksize; |
| 513 | |
| 514 | *bh = NULL; |
| 515 | |
| 516 | /* may be > 512 */ |
| 517 | *sector_size = bdev_hardsect_size(sb->s_bdev); |
| 518 | if (*sector_size > OCFS2_MAX_BLOCKSIZE) { |
| 519 | mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n", |
| 520 | *sector_size, OCFS2_MAX_BLOCKSIZE); |
| 521 | status = -EINVAL; |
| 522 | goto bail; |
| 523 | } |
| 524 | |
| 525 | /* Can this really happen? */ |
| 526 | if (*sector_size < OCFS2_MIN_BLOCKSIZE) |
| 527 | *sector_size = OCFS2_MIN_BLOCKSIZE; |
| 528 | |
| 529 | /* check block zero for old format */ |
| 530 | status = ocfs2_get_sector(sb, bh, 0, *sector_size); |
| 531 | if (status < 0) { |
| 532 | mlog_errno(status); |
| 533 | goto bail; |
| 534 | } |
| 535 | hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data; |
| 536 | if (hdr->major_version == OCFS1_MAJOR_VERSION) { |
| 537 | mlog(ML_ERROR, "incompatible version: %u.%u\n", |
| 538 | hdr->major_version, hdr->minor_version); |
| 539 | status = -EINVAL; |
| 540 | } |
| 541 | if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE, |
| 542 | strlen(OCFS1_VOLUME_SIGNATURE)) == 0) { |
| 543 | mlog(ML_ERROR, "incompatible volume signature: %8s\n", |
| 544 | hdr->signature); |
| 545 | status = -EINVAL; |
| 546 | } |
| 547 | brelse(*bh); |
| 548 | *bh = NULL; |
| 549 | if (status < 0) { |
| 550 | mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be " |
| 551 | "upgraded before mounting with ocfs v2\n"); |
| 552 | goto bail; |
| 553 | } |
| 554 | |
| 555 | /* |
| 556 | * Now check at magic offset for 512, 1024, 2048, 4096 |
| 557 | * blocksizes. 4096 is the maximum blocksize because it is |
| 558 | * the minimum clustersize. |
| 559 | */ |
| 560 | status = -EINVAL; |
| 561 | for (blksize = *sector_size; |
| 562 | blksize <= OCFS2_MAX_BLOCKSIZE; |
| 563 | blksize <<= 1) { |
| 564 | tmpstat = ocfs2_get_sector(sb, bh, |
| 565 | OCFS2_SUPER_BLOCK_BLKNO, |
| 566 | blksize); |
| 567 | if (tmpstat < 0) { |
| 568 | status = tmpstat; |
| 569 | mlog_errno(status); |
| 570 | goto bail; |
| 571 | } |
| 572 | di = (struct ocfs2_dinode *) (*bh)->b_data; |
| 573 | status = ocfs2_verify_volume(di, *bh, blksize); |
| 574 | if (status >= 0) |
| 575 | goto bail; |
| 576 | brelse(*bh); |
| 577 | *bh = NULL; |
| 578 | if (status != -EAGAIN) |
| 579 | break; |
| 580 | } |
| 581 | |
| 582 | bail: |
| 583 | return status; |
| 584 | } |
| 585 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 586 | static int ocfs2_verify_heartbeat(struct ocfs2_super *osb) |
| 587 | { |
| 588 | if (ocfs2_mount_local(osb)) { |
| 589 | if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) { |
| 590 | mlog(ML_ERROR, "Cannot heartbeat on a locally " |
| 591 | "mounted device.\n"); |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | } |
| 595 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 596 | if (ocfs2_userspace_stack(osb)) { |
| 597 | if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) { |
| 598 | mlog(ML_ERROR, "Userspace stack expected, but " |
| 599 | "o2cb heartbeat arguments passed to mount\n"); |
| 600 | return -EINVAL; |
| 601 | } |
| 602 | } |
| 603 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 604 | if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) { |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 605 | if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) && |
| 606 | !ocfs2_userspace_stack(osb)) { |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 607 | mlog(ML_ERROR, "Heartbeat has to be started to mount " |
| 608 | "a read-write clustered device.\n"); |
| 609 | return -EINVAL; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | return 0; |
| 614 | } |
| 615 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 616 | /* |
| 617 | * If we're using a userspace stack, mount should have passed |
| 618 | * a name that matches the disk. If not, mount should not |
| 619 | * have passed a stack. |
| 620 | */ |
| 621 | static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb, |
| 622 | struct mount_options *mopt) |
| 623 | { |
| 624 | if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) { |
| 625 | mlog(ML_ERROR, |
| 626 | "cluster stack passed to mount, but this filesystem " |
| 627 | "does not support it\n"); |
| 628 | return -EINVAL; |
| 629 | } |
| 630 | |
| 631 | if (ocfs2_userspace_stack(osb) && |
| 632 | strncmp(osb->osb_cluster_stack, mopt->cluster_stack, |
| 633 | OCFS2_STACK_LABEL_LEN)) { |
| 634 | mlog(ML_ERROR, |
| 635 | "cluster stack passed to mount (\"%s\") does not " |
| 636 | "match the filesystem (\"%s\")\n", |
| 637 | mopt->cluster_stack, |
| 638 | osb->osb_cluster_stack); |
| 639 | return -EINVAL; |
| 640 | } |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 645 | static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) |
| 646 | { |
| 647 | struct dentry *root; |
| 648 | int status, sector_size; |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 649 | struct mount_options parsed_options; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 650 | struct inode *inode = NULL; |
| 651 | struct ocfs2_super *osb = NULL; |
| 652 | struct buffer_head *bh = NULL; |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 653 | char nodestr[8]; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 654 | |
| 655 | mlog_entry("%p, %p, %i", sb, data, silent); |
| 656 | |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 657 | if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 658 | status = -EINVAL; |
| 659 | goto read_super_error; |
| 660 | } |
| 661 | |
| 662 | /* probe for superblock */ |
| 663 | status = ocfs2_sb_probe(sb, &bh, §or_size); |
| 664 | if (status < 0) { |
| 665 | mlog(ML_ERROR, "superblock probe failed!\n"); |
| 666 | goto read_super_error; |
| 667 | } |
| 668 | |
| 669 | status = ocfs2_initialize_super(sb, bh, sector_size); |
| 670 | osb = OCFS2_SB(sb); |
| 671 | if (status < 0) { |
| 672 | mlog_errno(status); |
| 673 | goto read_super_error; |
| 674 | } |
| 675 | brelse(bh); |
| 676 | bh = NULL; |
Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 677 | |
| 678 | if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR)) |
| 679 | parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; |
| 680 | |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 681 | osb->s_mount_opt = parsed_options.mount_opt; |
| 682 | osb->s_atime_quantum = parsed_options.atime_quantum; |
| 683 | osb->preferred_slot = parsed_options.slot; |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 684 | osb->osb_commit_interval = parsed_options.commit_interval; |
Mark Fasheh | 9c7af40 | 2008-07-28 18:02:53 -0700 | [diff] [blame] | 685 | osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt); |
| 686 | osb->local_alloc_bits = osb->local_alloc_default_bits; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 687 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 688 | status = ocfs2_verify_userspace_stack(osb, &parsed_options); |
| 689 | if (status) |
| 690 | goto read_super_error; |
| 691 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 692 | sb->s_magic = OCFS2_SUPER_MAGIC; |
| 693 | |
Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 694 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
| 695 | ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); |
| 696 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 697 | /* Hard readonly mode only if: bdev_read_only, MS_RDONLY, |
| 698 | * heartbeat=none */ |
| 699 | if (bdev_read_only(sb->s_bdev)) { |
| 700 | if (!(sb->s_flags & MS_RDONLY)) { |
| 701 | status = -EACCES; |
| 702 | mlog(ML_ERROR, "Readonly device detected but readonly " |
| 703 | "mount was not specified.\n"); |
| 704 | goto read_super_error; |
| 705 | } |
| 706 | |
| 707 | /* You should not be able to start a local heartbeat |
| 708 | * on a readonly device. */ |
| 709 | if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) { |
| 710 | status = -EROFS; |
| 711 | mlog(ML_ERROR, "Local heartbeat specified on readonly " |
| 712 | "device.\n"); |
| 713 | goto read_super_error; |
| 714 | } |
| 715 | |
| 716 | status = ocfs2_check_journals_nolocks(osb); |
| 717 | if (status < 0) { |
| 718 | if (status == -EROFS) |
| 719 | mlog(ML_ERROR, "Recovery required on readonly " |
| 720 | "file system, but write access is " |
| 721 | "unavailable.\n"); |
| 722 | else |
| 723 | mlog_errno(status); |
| 724 | goto read_super_error; |
| 725 | } |
| 726 | |
| 727 | ocfs2_set_ro_flag(osb, 1); |
| 728 | |
| 729 | printk(KERN_NOTICE "Readonly device detected. No cluster " |
| 730 | "services will be utilized for this mount. Recovery " |
| 731 | "will be skipped.\n"); |
| 732 | } |
| 733 | |
| 734 | if (!ocfs2_is_hard_readonly(osb)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 735 | if (sb->s_flags & MS_RDONLY) |
| 736 | ocfs2_set_ro_flag(osb, 0); |
| 737 | } |
| 738 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 739 | status = ocfs2_verify_heartbeat(osb); |
| 740 | if (status < 0) { |
| 741 | mlog_errno(status); |
| 742 | goto read_super_error; |
| 743 | } |
| 744 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 745 | osb->osb_debug_root = debugfs_create_dir(osb->uuid_str, |
| 746 | ocfs2_debugfs_root); |
| 747 | if (!osb->osb_debug_root) { |
| 748 | status = -EINVAL; |
| 749 | mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n"); |
| 750 | goto read_super_error; |
| 751 | } |
| 752 | |
| 753 | status = ocfs2_mount_volume(sb); |
| 754 | if (osb->root_inode) |
| 755 | inode = igrab(osb->root_inode); |
| 756 | |
| 757 | if (status < 0) |
| 758 | goto read_super_error; |
| 759 | |
| 760 | if (!inode) { |
| 761 | status = -EIO; |
| 762 | mlog_errno(status); |
| 763 | goto read_super_error; |
| 764 | } |
| 765 | |
| 766 | root = d_alloc_root(inode); |
| 767 | if (!root) { |
| 768 | status = -ENOMEM; |
| 769 | mlog_errno(status); |
| 770 | goto read_super_error; |
| 771 | } |
| 772 | |
| 773 | sb->s_root = root; |
| 774 | |
| 775 | ocfs2_complete_mount_recovery(osb); |
| 776 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 777 | if (ocfs2_mount_local(osb)) |
| 778 | snprintf(nodestr, sizeof(nodestr), "local"); |
| 779 | else |
Joel Becker | 19fdb62 | 2008-01-30 15:38:24 -0800 | [diff] [blame] | 780 | snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num); |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 781 | |
| 782 | printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) " |
Sunil Mushran | 781ee3e | 2006-04-27 16:41:31 -0700 | [diff] [blame] | 783 | "with %s data mode.\n", |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 784 | osb->dev_str, nodestr, osb->slot_num, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 785 | osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" : |
| 786 | "ordered"); |
| 787 | |
| 788 | atomic_set(&osb->vol_state, VOLUME_MOUNTED); |
| 789 | wake_up(&osb->osb_mount_event); |
| 790 | |
| 791 | mlog_exit(status); |
| 792 | return status; |
| 793 | |
| 794 | read_super_error: |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 795 | brelse(bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 796 | |
| 797 | if (inode) |
| 798 | iput(inode); |
| 799 | |
| 800 | if (osb) { |
| 801 | atomic_set(&osb->vol_state, VOLUME_DISABLED); |
| 802 | wake_up(&osb->osb_mount_event); |
| 803 | ocfs2_dismount_volume(sb, 1); |
| 804 | } |
| 805 | |
| 806 | mlog_exit(status); |
| 807 | return status; |
| 808 | } |
| 809 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 810 | static int ocfs2_get_sb(struct file_system_type *fs_type, |
| 811 | int flags, |
| 812 | const char *dev_name, |
| 813 | void *data, |
| 814 | struct vfsmount *mnt) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 815 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 816 | return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super, |
| 817 | mnt); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static struct file_system_type ocfs2_fs_type = { |
| 821 | .owner = THIS_MODULE, |
| 822 | .name = "ocfs2", |
| 823 | .get_sb = ocfs2_get_sb, /* is this called when we mount |
| 824 | * the fs? */ |
| 825 | .kill_sb = kill_block_super, /* set to the generic one |
| 826 | * right now, but do we |
| 827 | * need to change that? */ |
Mark Fasheh | 1ba9da2 | 2006-09-08 14:22:54 -0700 | [diff] [blame] | 828 | .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 829 | .next = NULL |
| 830 | }; |
| 831 | |
| 832 | static int ocfs2_parse_options(struct super_block *sb, |
| 833 | char *options, |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 834 | struct mount_options *mopt, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 835 | int is_remount) |
| 836 | { |
| 837 | int status; |
| 838 | char *p; |
| 839 | |
| 840 | mlog_entry("remount: %d, options: \"%s\"\n", is_remount, |
| 841 | options ? options : "(none)"); |
| 842 | |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 843 | mopt->commit_interval = 0; |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 844 | mopt->mount_opt = 0; |
| 845 | mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM; |
| 846 | mopt->slot = OCFS2_INVALID_SLOT; |
Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 847 | mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE; |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 848 | mopt->cluster_stack[0] = '\0'; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 849 | |
| 850 | if (!options) { |
| 851 | status = 1; |
| 852 | goto bail; |
| 853 | } |
| 854 | |
| 855 | while ((p = strsep(&options, ",")) != NULL) { |
| 856 | int token, option; |
| 857 | substring_t args[MAX_OPT_ARGS]; |
| 858 | |
| 859 | if (!*p) |
| 860 | continue; |
| 861 | |
| 862 | token = match_token(p, tokens, args); |
| 863 | switch (token) { |
| 864 | case Opt_hb_local: |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 865 | mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 866 | break; |
| 867 | case Opt_hb_none: |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 868 | mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 869 | break; |
| 870 | case Opt_barrier: |
| 871 | if (match_int(&args[0], &option)) { |
| 872 | status = 0; |
| 873 | goto bail; |
| 874 | } |
| 875 | if (option) |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 876 | mopt->mount_opt |= OCFS2_MOUNT_BARRIER; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 877 | else |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 878 | mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 879 | break; |
| 880 | case Opt_intr: |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 881 | mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 882 | break; |
| 883 | case Opt_nointr: |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 884 | mopt->mount_opt |= OCFS2_MOUNT_NOINTR; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 885 | break; |
| 886 | case Opt_err_panic: |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 887 | mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 888 | break; |
| 889 | case Opt_err_ro: |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 890 | mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 891 | break; |
| 892 | case Opt_data_ordered: |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 893 | mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 894 | break; |
| 895 | case Opt_data_writeback: |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 896 | mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 897 | break; |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 898 | case Opt_user_xattr: |
| 899 | mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR; |
| 900 | break; |
| 901 | case Opt_nouser_xattr: |
| 902 | mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR; |
| 903 | break; |
Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 904 | case Opt_atime_quantum: |
| 905 | if (match_int(&args[0], &option)) { |
| 906 | status = 0; |
| 907 | goto bail; |
| 908 | } |
| 909 | if (option >= 0) |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 910 | mopt->atime_quantum = option; |
Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 911 | break; |
Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 912 | case Opt_slot: |
| 913 | option = 0; |
| 914 | if (match_int(&args[0], &option)) { |
| 915 | status = 0; |
| 916 | goto bail; |
| 917 | } |
| 918 | if (option) |
Tiger Yang | c0123ad | 2007-09-08 00:16:10 +0800 | [diff] [blame] | 919 | mopt->slot = (s16)option; |
Sunil Mushran | baf4661 | 2007-06-18 17:00:24 -0700 | [diff] [blame] | 920 | break; |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 921 | case Opt_commit: |
| 922 | option = 0; |
| 923 | if (match_int(&args[0], &option)) { |
| 924 | status = 0; |
| 925 | goto bail; |
| 926 | } |
| 927 | if (option < 0) |
| 928 | return 0; |
| 929 | if (option == 0) |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 930 | option = JBD2_DEFAULT_MAX_COMMIT_AGE; |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 931 | mopt->commit_interval = HZ * option; |
| 932 | break; |
Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 933 | case Opt_localalloc: |
| 934 | option = 0; |
| 935 | if (match_int(&args[0], &option)) { |
| 936 | status = 0; |
| 937 | goto bail; |
| 938 | } |
| 939 | if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8)) |
| 940 | mopt->localalloc_opt = option; |
| 941 | break; |
Mark Fasheh | 53fc622 | 2007-12-20 16:49:04 -0800 | [diff] [blame] | 942 | case Opt_localflocks: |
| 943 | /* |
| 944 | * Changing this during remount could race |
| 945 | * flock() requests, or "unbalance" existing |
| 946 | * ones (e.g., a lock is taken in one mode but |
| 947 | * dropped in the other). If users care enough |
| 948 | * to flip locking modes during remount, we |
| 949 | * could add a "local" flag to individual |
| 950 | * flock structures for proper tracking of |
| 951 | * state. |
| 952 | */ |
| 953 | if (!is_remount) |
| 954 | mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS; |
| 955 | break; |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 956 | case Opt_stack: |
| 957 | /* Check both that the option we were passed |
| 958 | * is of the right length and that it is a proper |
| 959 | * string of the right length. |
| 960 | */ |
| 961 | if (((args[0].to - args[0].from) != |
| 962 | OCFS2_STACK_LABEL_LEN) || |
| 963 | (strnlen(args[0].from, |
| 964 | OCFS2_STACK_LABEL_LEN) != |
| 965 | OCFS2_STACK_LABEL_LEN)) { |
| 966 | mlog(ML_ERROR, |
| 967 | "Invalid cluster_stack option\n"); |
| 968 | status = 0; |
| 969 | goto bail; |
| 970 | } |
| 971 | memcpy(mopt->cluster_stack, args[0].from, |
| 972 | OCFS2_STACK_LABEL_LEN); |
| 973 | mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0'; |
| 974 | break; |
Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 975 | case Opt_inode64: |
| 976 | mopt->mount_opt |= OCFS2_MOUNT_INODE64; |
| 977 | break; |
Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 978 | #ifdef CONFIG_OCFS2_FS_POSIX_ACL |
| 979 | case Opt_acl: |
| 980 | mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL; |
| 981 | break; |
| 982 | case Opt_noacl: |
| 983 | mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; |
| 984 | break; |
| 985 | #else |
| 986 | case Opt_acl: |
| 987 | case Opt_noacl: |
| 988 | printk(KERN_INFO "ocfs2 (no)acl options not supported\n"); |
| 989 | break; |
| 990 | #endif |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 991 | default: |
| 992 | mlog(ML_ERROR, |
| 993 | "Unrecognized mount option \"%s\" " |
| 994 | "or missing value\n", p); |
| 995 | status = 0; |
| 996 | goto bail; |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | status = 1; |
| 1001 | |
| 1002 | bail: |
| 1003 | mlog_exit(status); |
| 1004 | return status; |
| 1005 | } |
| 1006 | |
Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 1007 | static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt) |
| 1008 | { |
| 1009 | struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb); |
| 1010 | unsigned long opts = osb->s_mount_opt; |
Mark Fasheh | ebcee4b | 2008-07-28 14:55:20 -0700 | [diff] [blame] | 1011 | unsigned int local_alloc_megs; |
Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 1012 | |
| 1013 | if (opts & OCFS2_MOUNT_HB_LOCAL) |
| 1014 | seq_printf(s, ",_netdev,heartbeat=local"); |
| 1015 | else |
| 1016 | seq_printf(s, ",heartbeat=none"); |
| 1017 | |
| 1018 | if (opts & OCFS2_MOUNT_NOINTR) |
| 1019 | seq_printf(s, ",nointr"); |
| 1020 | |
| 1021 | if (opts & OCFS2_MOUNT_DATA_WRITEBACK) |
| 1022 | seq_printf(s, ",data=writeback"); |
| 1023 | else |
| 1024 | seq_printf(s, ",data=ordered"); |
| 1025 | |
| 1026 | if (opts & OCFS2_MOUNT_BARRIER) |
| 1027 | seq_printf(s, ",barrier=1"); |
| 1028 | |
| 1029 | if (opts & OCFS2_MOUNT_ERRORS_PANIC) |
| 1030 | seq_printf(s, ",errors=panic"); |
| 1031 | else |
| 1032 | seq_printf(s, ",errors=remount-ro"); |
| 1033 | |
| 1034 | if (osb->preferred_slot != OCFS2_INVALID_SLOT) |
| 1035 | seq_printf(s, ",preferred_slot=%d", osb->preferred_slot); |
| 1036 | |
| 1037 | if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM) |
| 1038 | seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum); |
| 1039 | |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 1040 | if (osb->osb_commit_interval) |
| 1041 | seq_printf(s, ",commit=%u", |
| 1042 | (unsigned) (osb->osb_commit_interval / HZ)); |
| 1043 | |
Mark Fasheh | ebcee4b | 2008-07-28 14:55:20 -0700 | [diff] [blame] | 1044 | local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits); |
| 1045 | if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE) |
| 1046 | seq_printf(s, ",localalloc=%d", local_alloc_megs); |
Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 1047 | |
Mark Fasheh | 53fc622 | 2007-12-20 16:49:04 -0800 | [diff] [blame] | 1048 | if (opts & OCFS2_MOUNT_LOCALFLOCKS) |
| 1049 | seq_printf(s, ",localflocks,"); |
| 1050 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 1051 | if (osb->osb_cluster_stack[0]) |
| 1052 | seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN, |
| 1053 | osb->osb_cluster_stack); |
| 1054 | |
Sunil Mushran | b0f73cf | 2008-09-05 11:29:14 -0700 | [diff] [blame] | 1055 | if (opts & OCFS2_MOUNT_NOUSERXATTR) |
| 1056 | seq_printf(s, ",nouser_xattr"); |
| 1057 | else |
| 1058 | seq_printf(s, ",user_xattr"); |
| 1059 | |
Joel Becker | 12462f1 | 2008-09-03 20:03:40 -0700 | [diff] [blame] | 1060 | if (opts & OCFS2_MOUNT_INODE64) |
| 1061 | seq_printf(s, ",inode64"); |
| 1062 | |
Tiger Yang | a68979b | 2008-11-14 11:17:52 +0800 | [diff] [blame] | 1063 | #ifdef CONFIG_OCFS2_FS_POSIX_ACL |
| 1064 | if (opts & OCFS2_MOUNT_POSIX_ACL) |
| 1065 | seq_printf(s, ",acl"); |
| 1066 | else |
| 1067 | seq_printf(s, ",noacl"); |
| 1068 | #endif |
| 1069 | |
Sunil Mushran | d550071 | 2007-09-06 13:34:16 -0700 | [diff] [blame] | 1070 | return 0; |
| 1071 | } |
| 1072 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1073 | static int __init ocfs2_init(void) |
| 1074 | { |
| 1075 | int status; |
| 1076 | |
| 1077 | mlog_entry_void(); |
| 1078 | |
| 1079 | ocfs2_print_version(); |
| 1080 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1081 | status = init_ocfs2_uptodate_cache(); |
| 1082 | if (status < 0) { |
| 1083 | mlog_errno(status); |
| 1084 | goto leave; |
| 1085 | } |
| 1086 | |
| 1087 | status = ocfs2_initialize_mem_caches(); |
| 1088 | if (status < 0) { |
| 1089 | mlog_errno(status); |
| 1090 | goto leave; |
| 1091 | } |
| 1092 | |
| 1093 | ocfs2_wq = create_singlethread_workqueue("ocfs2_wq"); |
| 1094 | if (!ocfs2_wq) { |
| 1095 | status = -ENOMEM; |
| 1096 | goto leave; |
| 1097 | } |
| 1098 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1099 | ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL); |
| 1100 | if (!ocfs2_debugfs_root) { |
| 1101 | status = -EFAULT; |
| 1102 | mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n"); |
| 1103 | } |
| 1104 | |
Joel Becker | 63e0c48 | 2008-01-30 16:58:36 -0800 | [diff] [blame] | 1105 | ocfs2_set_locking_protocol(); |
| 1106 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1107 | leave: |
| 1108 | if (status < 0) { |
| 1109 | ocfs2_free_mem_caches(); |
| 1110 | exit_ocfs2_uptodate_cache(); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | mlog_exit(status); |
| 1114 | |
| 1115 | if (status >= 0) { |
| 1116 | return register_filesystem(&ocfs2_fs_type); |
| 1117 | } else |
| 1118 | return -1; |
| 1119 | } |
| 1120 | |
| 1121 | static void __exit ocfs2_exit(void) |
| 1122 | { |
| 1123 | mlog_entry_void(); |
| 1124 | |
| 1125 | if (ocfs2_wq) { |
| 1126 | flush_workqueue(ocfs2_wq); |
| 1127 | destroy_workqueue(ocfs2_wq); |
| 1128 | } |
| 1129 | |
| 1130 | debugfs_remove(ocfs2_debugfs_root); |
| 1131 | |
| 1132 | ocfs2_free_mem_caches(); |
| 1133 | |
| 1134 | unregister_filesystem(&ocfs2_fs_type); |
| 1135 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1136 | exit_ocfs2_uptodate_cache(); |
| 1137 | |
| 1138 | mlog_exit_void(); |
| 1139 | } |
| 1140 | |
| 1141 | static void ocfs2_put_super(struct super_block *sb) |
| 1142 | { |
| 1143 | mlog_entry("(0x%p)\n", sb); |
| 1144 | |
| 1145 | ocfs2_sync_blockdev(sb); |
| 1146 | ocfs2_dismount_volume(sb, 0); |
| 1147 | |
| 1148 | mlog_exit_void(); |
| 1149 | } |
| 1150 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1151 | static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1152 | { |
| 1153 | struct ocfs2_super *osb; |
| 1154 | u32 numbits, freebits; |
| 1155 | int status; |
| 1156 | struct ocfs2_dinode *bm_lock; |
| 1157 | struct buffer_head *bh = NULL; |
| 1158 | struct inode *inode = NULL; |
| 1159 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1160 | mlog_entry("(%p, %p)\n", dentry->d_sb, buf); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1161 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1162 | osb = OCFS2_SB(dentry->d_sb); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1163 | |
| 1164 | inode = ocfs2_get_system_file_inode(osb, |
| 1165 | GLOBAL_BITMAP_SYSTEM_INODE, |
| 1166 | OCFS2_INVALID_SLOT); |
| 1167 | if (!inode) { |
| 1168 | mlog(ML_ERROR, "failed to get bitmap inode\n"); |
| 1169 | status = -EIO; |
| 1170 | goto bail; |
| 1171 | } |
| 1172 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1173 | status = ocfs2_inode_lock(inode, &bh, 0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1174 | if (status < 0) { |
| 1175 | mlog_errno(status); |
| 1176 | goto bail; |
| 1177 | } |
| 1178 | |
| 1179 | bm_lock = (struct ocfs2_dinode *) bh->b_data; |
| 1180 | |
| 1181 | numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total); |
| 1182 | freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used); |
| 1183 | |
| 1184 | buf->f_type = OCFS2_SUPER_MAGIC; |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1185 | buf->f_bsize = dentry->d_sb->s_blocksize; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1186 | buf->f_namelen = OCFS2_MAX_FILENAME_LEN; |
| 1187 | buf->f_blocks = ((sector_t) numbits) * |
| 1188 | (osb->s_clustersize >> osb->sb->s_blocksize_bits); |
| 1189 | buf->f_bfree = ((sector_t) freebits) * |
| 1190 | (osb->s_clustersize >> osb->sb->s_blocksize_bits); |
| 1191 | buf->f_bavail = buf->f_bfree; |
| 1192 | buf->f_files = numbits; |
| 1193 | buf->f_ffree = freebits; |
| 1194 | |
| 1195 | brelse(bh); |
| 1196 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1197 | ocfs2_inode_unlock(inode, 0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1198 | status = 0; |
| 1199 | bail: |
| 1200 | if (inode) |
| 1201 | iput(inode); |
| 1202 | |
| 1203 | mlog_exit(status); |
| 1204 | |
| 1205 | return status; |
| 1206 | } |
| 1207 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 1208 | static void ocfs2_inode_init_once(void *data) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1209 | { |
| 1210 | struct ocfs2_inode_info *oi = data; |
| 1211 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1212 | oi->ip_flags = 0; |
| 1213 | oi->ip_open_count = 0; |
| 1214 | spin_lock_init(&oi->ip_lock); |
| 1215 | ocfs2_extent_map_init(&oi->vfs_inode); |
| 1216 | INIT_LIST_HEAD(&oi->ip_io_markers); |
| 1217 | oi->ip_created_trans = 0; |
| 1218 | oi->ip_last_trans = 0; |
| 1219 | oi->ip_dir_start_lookup = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1220 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1221 | init_rwsem(&oi->ip_alloc_sem); |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 1222 | init_rwsem(&oi->ip_xattr_sem); |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1223 | mutex_init(&oi->ip_io_mutex); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1224 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1225 | oi->ip_blkno = 0ULL; |
| 1226 | oi->ip_clusters = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1227 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1228 | ocfs2_lock_res_init_once(&oi->ip_rw_lockres); |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1229 | ocfs2_lock_res_init_once(&oi->ip_inode_lockres); |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1230 | ocfs2_lock_res_init_once(&oi->ip_open_lockres); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1231 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1232 | ocfs2_metadata_cache_init(&oi->vfs_inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1233 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1234 | inode_init_once(&oi->vfs_inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | static int ocfs2_initialize_mem_caches(void) |
| 1238 | { |
| 1239 | ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache", |
Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 1240 | sizeof(struct ocfs2_inode_info), |
| 1241 | 0, |
| 1242 | (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| |
| 1243 | SLAB_MEM_SPREAD), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1244 | ocfs2_inode_init_once); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1245 | if (!ocfs2_inode_cachep) |
| 1246 | return -ENOMEM; |
| 1247 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1248 | return 0; |
| 1249 | } |
| 1250 | |
| 1251 | static void ocfs2_free_mem_caches(void) |
| 1252 | { |
| 1253 | if (ocfs2_inode_cachep) |
| 1254 | kmem_cache_destroy(ocfs2_inode_cachep); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1255 | |
| 1256 | ocfs2_inode_cachep = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | static int ocfs2_get_sector(struct super_block *sb, |
| 1260 | struct buffer_head **bh, |
| 1261 | int block, |
| 1262 | int sect_size) |
| 1263 | { |
| 1264 | if (!sb_set_blocksize(sb, sect_size)) { |
| 1265 | mlog(ML_ERROR, "unable to set blocksize\n"); |
| 1266 | return -EIO; |
| 1267 | } |
| 1268 | |
| 1269 | *bh = sb_getblk(sb, block); |
| 1270 | if (!*bh) { |
| 1271 | mlog_errno(-EIO); |
| 1272 | return -EIO; |
| 1273 | } |
| 1274 | lock_buffer(*bh); |
| 1275 | if (!buffer_dirty(*bh)) |
| 1276 | clear_buffer_uptodate(*bh); |
| 1277 | unlock_buffer(*bh); |
| 1278 | ll_rw_block(READ, 1, bh); |
| 1279 | wait_on_buffer(*bh); |
| 1280 | return 0; |
| 1281 | } |
| 1282 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1283 | static int ocfs2_mount_volume(struct super_block *sb) |
| 1284 | { |
| 1285 | int status = 0; |
| 1286 | int unlock_super = 0; |
| 1287 | struct ocfs2_super *osb = OCFS2_SB(sb); |
| 1288 | |
| 1289 | mlog_entry_void(); |
| 1290 | |
| 1291 | if (ocfs2_is_hard_readonly(osb)) |
| 1292 | goto leave; |
| 1293 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1294 | status = ocfs2_dlm_init(osb); |
| 1295 | if (status < 0) { |
| 1296 | mlog_errno(status); |
| 1297 | goto leave; |
| 1298 | } |
| 1299 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1300 | status = ocfs2_super_lock(osb, 1); |
| 1301 | if (status < 0) { |
| 1302 | mlog_errno(status); |
| 1303 | goto leave; |
| 1304 | } |
| 1305 | unlock_super = 1; |
| 1306 | |
| 1307 | /* This will load up the node map and add ourselves to it. */ |
| 1308 | status = ocfs2_find_slot(osb); |
| 1309 | if (status < 0) { |
| 1310 | mlog_errno(status); |
| 1311 | goto leave; |
| 1312 | } |
| 1313 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1314 | /* load all node-local system inodes */ |
| 1315 | status = ocfs2_init_local_system_inodes(osb); |
| 1316 | if (status < 0) { |
| 1317 | mlog_errno(status); |
| 1318 | goto leave; |
| 1319 | } |
| 1320 | |
| 1321 | status = ocfs2_check_volume(osb); |
| 1322 | if (status < 0) { |
| 1323 | mlog_errno(status); |
| 1324 | goto leave; |
| 1325 | } |
| 1326 | |
| 1327 | status = ocfs2_truncate_log_init(osb); |
| 1328 | if (status < 0) { |
| 1329 | mlog_errno(status); |
| 1330 | goto leave; |
| 1331 | } |
| 1332 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1333 | if (ocfs2_mount_local(osb)) |
| 1334 | goto leave; |
| 1335 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1336 | leave: |
| 1337 | if (unlock_super) |
| 1338 | ocfs2_super_unlock(osb, 1); |
| 1339 | |
| 1340 | mlog_exit(status); |
| 1341 | return status; |
| 1342 | } |
| 1343 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1344 | static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err) |
| 1345 | { |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 1346 | int tmp, hangup_needed = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1347 | struct ocfs2_super *osb = NULL; |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1348 | char nodestr[8]; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1349 | |
| 1350 | mlog_entry("(0x%p)\n", sb); |
| 1351 | |
| 1352 | BUG_ON(!sb); |
| 1353 | osb = OCFS2_SB(sb); |
| 1354 | BUG_ON(!osb); |
| 1355 | |
| 1356 | ocfs2_shutdown_local_alloc(osb); |
| 1357 | |
| 1358 | ocfs2_truncate_log_shutdown(osb); |
| 1359 | |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1360 | /* This will disable recovery and flush any recovery work. */ |
| 1361 | ocfs2_recovery_exit(osb); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1362 | |
| 1363 | ocfs2_journal_shutdown(osb); |
| 1364 | |
| 1365 | ocfs2_sync_blockdev(sb); |
| 1366 | |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 1367 | /* No cluster connection means we've failed during mount, so skip |
| 1368 | * all the steps which depended on that to complete. */ |
| 1369 | if (osb->cconn) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1370 | tmp = ocfs2_super_lock(osb, 1); |
| 1371 | if (tmp < 0) { |
| 1372 | mlog_errno(tmp); |
| 1373 | return; |
| 1374 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1375 | } |
| 1376 | |
Mark Fasheh | 19b613d | 2007-10-04 14:47:09 -0700 | [diff] [blame] | 1377 | if (osb->slot_num != OCFS2_INVALID_SLOT) |
| 1378 | ocfs2_put_slot(osb); |
| 1379 | |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 1380 | if (osb->cconn) |
Mark Fasheh | 19b613d | 2007-10-04 14:47:09 -0700 | [diff] [blame] | 1381 | ocfs2_super_unlock(osb, 1); |
| 1382 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1383 | ocfs2_release_system_inodes(osb); |
| 1384 | |
Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 1385 | /* |
Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 1386 | * If we're dismounting due to mount error, mount.ocfs2 will clean |
| 1387 | * up heartbeat. If we're a local mount, there is no heartbeat. |
| 1388 | * If we failed before we got a uuid_str yet, we can't stop |
| 1389 | * heartbeat. Otherwise, do it. |
| 1390 | */ |
| 1391 | if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str) |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 1392 | hangup_needed = 1; |
| 1393 | |
| 1394 | if (osb->cconn) |
| 1395 | ocfs2_dlm_shutdown(osb, hangup_needed); |
| 1396 | |
| 1397 | debugfs_remove(osb->osb_debug_root); |
| 1398 | |
| 1399 | if (hangup_needed) |
Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 1400 | ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1401 | |
| 1402 | atomic_set(&osb->vol_state, VOLUME_DISMOUNTED); |
| 1403 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1404 | if (ocfs2_mount_local(osb)) |
| 1405 | snprintf(nodestr, sizeof(nodestr), "local"); |
| 1406 | else |
Joel Becker | 19fdb62 | 2008-01-30 15:38:24 -0800 | [diff] [blame] | 1407 | snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num); |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1408 | |
| 1409 | printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n", |
| 1410 | osb->dev_str, nodestr); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1411 | |
| 1412 | ocfs2_delete_osb(osb); |
| 1413 | kfree(osb); |
| 1414 | sb->s_dev = 0; |
| 1415 | sb->s_fs_info = NULL; |
| 1416 | } |
| 1417 | |
| 1418 | static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid, |
| 1419 | unsigned uuid_bytes) |
| 1420 | { |
| 1421 | int i, ret; |
| 1422 | char *ptr; |
| 1423 | |
| 1424 | BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN); |
| 1425 | |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 1426 | osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1427 | if (osb->uuid_str == NULL) |
| 1428 | return -ENOMEM; |
| 1429 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1430 | for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) { |
| 1431 | /* print with null */ |
| 1432 | ret = snprintf(ptr, 3, "%02X", uuid[i]); |
| 1433 | if (ret != 2) /* drop super cleans up */ |
| 1434 | return -EINVAL; |
| 1435 | /* then only advance past the last char */ |
| 1436 | ptr += 2; |
| 1437 | } |
| 1438 | |
| 1439 | return 0; |
| 1440 | } |
| 1441 | |
| 1442 | static int ocfs2_initialize_super(struct super_block *sb, |
| 1443 | struct buffer_head *bh, |
| 1444 | int sector_size) |
| 1445 | { |
Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 1446 | int status; |
Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 1447 | int i, cbits, bbits; |
| 1448 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1449 | struct inode *inode = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1450 | struct ocfs2_journal *journal; |
| 1451 | __le32 uuid_net_key; |
| 1452 | struct ocfs2_super *osb; |
| 1453 | |
| 1454 | mlog_entry_void(); |
| 1455 | |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 1456 | osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1457 | if (!osb) { |
| 1458 | status = -ENOMEM; |
| 1459 | mlog_errno(status); |
| 1460 | goto bail; |
| 1461 | } |
| 1462 | |
| 1463 | sb->s_fs_info = osb; |
| 1464 | sb->s_op = &ocfs2_sops; |
| 1465 | sb->s_export_op = &ocfs2_export_ops; |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 1466 | sb->s_xattr = ocfs2_xattr_handlers; |
Mark Fasheh | e0dceaf | 2007-08-09 16:52:30 -0700 | [diff] [blame] | 1467 | sb->s_time_gran = 1; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1468 | sb->s_flags |= MS_NOATIME; |
| 1469 | /* this is needed to support O_LARGEFILE */ |
Mark Fasheh | 5a25403 | 2007-07-20 12:56:16 -0700 | [diff] [blame] | 1470 | cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits); |
| 1471 | bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits); |
| 1472 | sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1473 | |
| 1474 | osb->sb = sb; |
| 1475 | /* Save off for ocfs2_rw_direct */ |
| 1476 | osb->s_sectsize_bits = blksize_bits(sector_size); |
Eric Sesterhenn / snakebyte | ebdec83 | 2006-01-27 10:32:52 +0100 | [diff] [blame] | 1477 | BUG_ON(!osb->s_sectsize_bits); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1478 | |
Mark Fasheh | 34d024f | 2007-09-24 15:56:19 -0700 | [diff] [blame] | 1479 | spin_lock_init(&osb->dc_task_lock); |
| 1480 | init_waitqueue_head(&osb->dc_event); |
| 1481 | osb->dc_work_sequence = 0; |
| 1482 | osb->dc_wake_sequence = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1483 | INIT_LIST_HEAD(&osb->blocked_lock_list); |
| 1484 | osb->blocked_lock_count = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1485 | spin_lock_init(&osb->osb_lock); |
Tao Ma | 4d0ddb2 | 2008-03-05 16:11:46 +0800 | [diff] [blame] | 1486 | ocfs2_init_inode_steal_slot(osb); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1487 | |
| 1488 | atomic_set(&osb->alloc_stats.moves, 0); |
| 1489 | atomic_set(&osb->alloc_stats.local_data, 0); |
| 1490 | atomic_set(&osb->alloc_stats.bitmap_data, 0); |
| 1491 | atomic_set(&osb->alloc_stats.bg_allocs, 0); |
| 1492 | atomic_set(&osb->alloc_stats.bg_extends, 0); |
| 1493 | |
| 1494 | ocfs2_init_node_maps(osb); |
| 1495 | |
| 1496 | snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u", |
| 1497 | MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev)); |
| 1498 | |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1499 | status = ocfs2_recovery_init(osb); |
| 1500 | if (status) { |
| 1501 | mlog(ML_ERROR, "Unable to initialize recovery state\n"); |
| 1502 | mlog_errno(status); |
| 1503 | goto bail; |
| 1504 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1505 | |
| 1506 | init_waitqueue_head(&osb->checkpoint_event); |
| 1507 | atomic_set(&osb->needs_checkpoint, 0); |
| 1508 | |
Tiger Yang | 7f1a37e | 2006-11-15 15:48:42 +0800 | [diff] [blame] | 1509 | osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM; |
| 1510 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1511 | osb->slot_num = OCFS2_INVALID_SLOT; |
| 1512 | |
Tiger Yang | 8154da3 | 2008-08-18 17:11:46 +0800 | [diff] [blame] | 1513 | osb->s_xattr_inline_size = le16_to_cpu( |
| 1514 | di->id2.i_super.s_xattr_inline_size); |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 1515 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1516 | osb->local_alloc_state = OCFS2_LA_UNUSED; |
| 1517 | osb->local_alloc_bh = NULL; |
Mark Fasheh | 9c7af40 | 2008-07-28 18:02:53 -0700 | [diff] [blame] | 1518 | INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1519 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1520 | init_waitqueue_head(&osb->osb_mount_event); |
| 1521 | |
| 1522 | osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL); |
| 1523 | if (!osb->vol_label) { |
| 1524 | mlog(ML_ERROR, "unable to alloc vol label\n"); |
| 1525 | status = -ENOMEM; |
| 1526 | goto bail; |
| 1527 | } |
| 1528 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1529 | osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots); |
| 1530 | if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) { |
| 1531 | mlog(ML_ERROR, "Invalid number of node slots (%u)\n", |
| 1532 | osb->max_slots); |
| 1533 | status = -EINVAL; |
| 1534 | goto bail; |
| 1535 | } |
Sunil Mushran | 781ee3e | 2006-04-27 16:41:31 -0700 | [diff] [blame] | 1536 | mlog(0, "max_slots for this device: %u\n", osb->max_slots); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1537 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1538 | osb->slot_recovery_generations = |
| 1539 | kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations), |
| 1540 | GFP_KERNEL); |
| 1541 | if (!osb->slot_recovery_generations) { |
| 1542 | status = -ENOMEM; |
| 1543 | mlog_errno(status); |
| 1544 | goto bail; |
| 1545 | } |
| 1546 | |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 1547 | init_waitqueue_head(&osb->osb_wipe_event); |
| 1548 | osb->osb_orphan_wipes = kcalloc(osb->max_slots, |
| 1549 | sizeof(*osb->osb_orphan_wipes), |
| 1550 | GFP_KERNEL); |
| 1551 | if (!osb->osb_orphan_wipes) { |
| 1552 | status = -ENOMEM; |
| 1553 | mlog_errno(status); |
| 1554 | goto bail; |
| 1555 | } |
| 1556 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1557 | osb->s_feature_compat = |
| 1558 | le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat); |
| 1559 | osb->s_feature_ro_compat = |
| 1560 | le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat); |
| 1561 | osb->s_feature_incompat = |
| 1562 | le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat); |
| 1563 | |
| 1564 | if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) { |
| 1565 | mlog(ML_ERROR, "couldn't mount because of unsupported " |
| 1566 | "optional features (%x).\n", i); |
| 1567 | status = -EINVAL; |
| 1568 | goto bail; |
| 1569 | } |
| 1570 | if (!(osb->sb->s_flags & MS_RDONLY) && |
| 1571 | (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) { |
| 1572 | mlog(ML_ERROR, "couldn't mount RDWR because of " |
| 1573 | "unsupported optional features (%x).\n", i); |
| 1574 | status = -EINVAL; |
| 1575 | goto bail; |
| 1576 | } |
| 1577 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 1578 | if (ocfs2_userspace_stack(osb)) { |
| 1579 | memcpy(osb->osb_cluster_stack, |
| 1580 | OCFS2_RAW_SB(di)->s_cluster_info.ci_stack, |
| 1581 | OCFS2_STACK_LABEL_LEN); |
| 1582 | osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0'; |
| 1583 | if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) { |
| 1584 | mlog(ML_ERROR, |
| 1585 | "couldn't mount because of an invalid " |
| 1586 | "cluster stack label (%s) \n", |
| 1587 | osb->osb_cluster_stack); |
| 1588 | status = -EINVAL; |
| 1589 | goto bail; |
| 1590 | } |
| 1591 | } else { |
| 1592 | /* The empty string is identical with classic tools that |
| 1593 | * don't know about s_cluster_info. */ |
| 1594 | osb->osb_cluster_stack[0] = '\0'; |
| 1595 | } |
| 1596 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1597 | get_random_bytes(&osb->s_next_generation, sizeof(u32)); |
| 1598 | |
| 1599 | /* FIXME |
| 1600 | * This should be done in ocfs2_journal_init(), but unknown |
| 1601 | * ordering issues will cause the filesystem to crash. |
| 1602 | * If anyone wants to figure out what part of the code |
| 1603 | * refers to osb->journal before ocfs2_journal_init() is run, |
| 1604 | * be my guest. |
| 1605 | */ |
| 1606 | /* initialize our journal structure */ |
| 1607 | |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 1608 | journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1609 | if (!journal) { |
| 1610 | mlog(ML_ERROR, "unable to alloc journal\n"); |
| 1611 | status = -ENOMEM; |
| 1612 | goto bail; |
| 1613 | } |
| 1614 | osb->journal = journal; |
| 1615 | journal->j_osb = osb; |
| 1616 | |
| 1617 | atomic_set(&journal->j_num_trans, 0); |
| 1618 | init_rwsem(&journal->j_trans_barrier); |
| 1619 | init_waitqueue_head(&journal->j_checkpointed); |
| 1620 | spin_lock_init(&journal->j_lock); |
| 1621 | journal->j_trans_id = (unsigned long) 1; |
| 1622 | INIT_LIST_HEAD(&journal->j_la_cleanups); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1623 | INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1624 | journal->j_state = OCFS2_JOURNAL_FREE; |
| 1625 | |
| 1626 | /* get some pseudo constants for clustersize bits */ |
| 1627 | osb->s_clustersize_bits = |
| 1628 | le32_to_cpu(di->id2.i_super.s_clustersize_bits); |
| 1629 | osb->s_clustersize = 1 << osb->s_clustersize_bits; |
| 1630 | mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits); |
| 1631 | |
| 1632 | if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE || |
| 1633 | osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) { |
| 1634 | mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n", |
| 1635 | osb->s_clustersize); |
| 1636 | status = -EINVAL; |
| 1637 | goto bail; |
| 1638 | } |
| 1639 | |
| 1640 | if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1) |
| 1641 | > (u32)~0UL) { |
| 1642 | mlog(ML_ERROR, "Volume might try to write to blocks beyond " |
| 1643 | "what jbd can address in 32 bits.\n"); |
| 1644 | status = -EINVAL; |
| 1645 | goto bail; |
| 1646 | } |
| 1647 | |
| 1648 | if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid, |
| 1649 | sizeof(di->id2.i_super.s_uuid))) { |
| 1650 | mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n"); |
| 1651 | status = -ENOMEM; |
| 1652 | goto bail; |
| 1653 | } |
| 1654 | |
Mark Fasheh | 7842704 | 2006-05-04 12:03:26 -0700 | [diff] [blame] | 1655 | 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] | 1656 | |
| 1657 | strncpy(osb->vol_label, di->id2.i_super.s_label, 63); |
| 1658 | osb->vol_label[63] = '\0'; |
| 1659 | osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno); |
| 1660 | osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno); |
| 1661 | osb->first_cluster_group_blkno = |
| 1662 | le64_to_cpu(di->id2.i_super.s_first_cluster_group); |
| 1663 | osb->fs_generation = le32_to_cpu(di->i_fs_generation); |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 1664 | 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] | 1665 | mlog(0, "vol_label: %s\n", osb->vol_label); |
| 1666 | mlog(0, "uuid: %s\n", osb->uuid_str); |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1667 | mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n", |
| 1668 | (unsigned long long)osb->root_blkno, |
| 1669 | (unsigned long long)osb->system_dir_blkno); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1670 | |
| 1671 | osb->osb_dlm_debug = ocfs2_new_dlm_debug(); |
| 1672 | if (!osb->osb_dlm_debug) { |
| 1673 | status = -ENOMEM; |
| 1674 | mlog_errno(status); |
| 1675 | goto bail; |
| 1676 | } |
| 1677 | |
| 1678 | atomic_set(&osb->vol_state, VOLUME_INIT); |
| 1679 | |
| 1680 | /* load root, system_dir, and all global system inodes */ |
| 1681 | status = ocfs2_init_global_system_inodes(osb); |
| 1682 | if (status < 0) { |
| 1683 | mlog_errno(status); |
| 1684 | goto bail; |
| 1685 | } |
| 1686 | |
| 1687 | /* |
| 1688 | * global bitmap |
| 1689 | */ |
| 1690 | inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE, |
| 1691 | OCFS2_INVALID_SLOT); |
| 1692 | if (!inode) { |
| 1693 | status = -EINVAL; |
| 1694 | mlog_errno(status); |
| 1695 | goto bail; |
| 1696 | } |
| 1697 | |
| 1698 | osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1699 | iput(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1700 | |
Tao Ma | e9d578a | 2007-12-18 15:46:10 +0800 | [diff] [blame] | 1701 | osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1702 | |
| 1703 | status = ocfs2_init_slot_info(osb); |
| 1704 | if (status < 0) { |
| 1705 | mlog_errno(status); |
| 1706 | goto bail; |
| 1707 | } |
| 1708 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1709 | bail: |
| 1710 | mlog_exit(status); |
| 1711 | return status; |
| 1712 | } |
| 1713 | |
| 1714 | /* |
| 1715 | * will return: -EAGAIN if it is ok to keep searching for superblocks |
| 1716 | * -EINVAL if there is a bad superblock |
| 1717 | * 0 on success |
| 1718 | */ |
| 1719 | static int ocfs2_verify_volume(struct ocfs2_dinode *di, |
| 1720 | struct buffer_head *bh, |
| 1721 | u32 blksz) |
| 1722 | { |
| 1723 | int status = -EAGAIN; |
| 1724 | |
| 1725 | mlog_entry_void(); |
| 1726 | |
| 1727 | if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE, |
| 1728 | strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) { |
| 1729 | status = -EINVAL; |
| 1730 | if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) { |
| 1731 | mlog(ML_ERROR, "found superblock with incorrect block " |
| 1732 | "size: found %u, should be %u\n", |
| 1733 | 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits), |
| 1734 | blksz); |
| 1735 | } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) != |
| 1736 | OCFS2_MAJOR_REV_LEVEL || |
| 1737 | le16_to_cpu(di->id2.i_super.s_minor_rev_level) != |
| 1738 | OCFS2_MINOR_REV_LEVEL) { |
| 1739 | mlog(ML_ERROR, "found superblock with bad version: " |
| 1740 | "found %u.%u, should be %u.%u\n", |
| 1741 | le16_to_cpu(di->id2.i_super.s_major_rev_level), |
| 1742 | le16_to_cpu(di->id2.i_super.s_minor_rev_level), |
| 1743 | OCFS2_MAJOR_REV_LEVEL, |
| 1744 | OCFS2_MINOR_REV_LEVEL); |
| 1745 | } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) { |
| 1746 | mlog(ML_ERROR, "bad block number on superblock: " |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1747 | "found %llu, should be %llu\n", |
Mark Fasheh | 1ca1a11 | 2007-04-27 16:01:25 -0700 | [diff] [blame] | 1748 | (unsigned long long)le64_to_cpu(di->i_blkno), |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1749 | (unsigned long long)bh->b_blocknr); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1750 | } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 || |
| 1751 | le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) { |
| 1752 | mlog(ML_ERROR, "bad cluster size found: %u\n", |
| 1753 | 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits)); |
| 1754 | } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) { |
| 1755 | mlog(ML_ERROR, "bad root_blkno: 0\n"); |
| 1756 | } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) { |
| 1757 | mlog(ML_ERROR, "bad system_dir_blkno: 0\n"); |
| 1758 | } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) { |
| 1759 | mlog(ML_ERROR, |
| 1760 | "Superblock slots found greater than file system " |
| 1761 | "maximum: found %u, max %u\n", |
| 1762 | le16_to_cpu(di->id2.i_super.s_max_slots), |
| 1763 | OCFS2_MAX_SLOTS); |
| 1764 | } else { |
| 1765 | /* found it! */ |
| 1766 | status = 0; |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | mlog_exit(status); |
| 1771 | return status; |
| 1772 | } |
| 1773 | |
| 1774 | static int ocfs2_check_volume(struct ocfs2_super *osb) |
| 1775 | { |
Denis Cheng | bddb8eb3 | 2007-09-27 02:10:04 +0800 | [diff] [blame] | 1776 | int status; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1777 | int dirty; |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1778 | int local; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1779 | struct ocfs2_dinode *local_alloc = NULL; /* only used if we |
| 1780 | * recover |
| 1781 | * ourselves. */ |
| 1782 | |
| 1783 | mlog_entry_void(); |
| 1784 | |
| 1785 | /* Init our journal object. */ |
| 1786 | status = ocfs2_journal_init(osb->journal, &dirty); |
| 1787 | if (status < 0) { |
| 1788 | mlog(ML_ERROR, "Could not initialize journal!\n"); |
| 1789 | goto finally; |
| 1790 | } |
| 1791 | |
| 1792 | /* If the journal was unmounted cleanly then we don't want to |
| 1793 | * recover anything. Otherwise, journal_load will do that |
| 1794 | * dirty work for us :) */ |
| 1795 | if (!dirty) { |
| 1796 | status = ocfs2_journal_wipe(osb->journal, 0); |
| 1797 | if (status < 0) { |
| 1798 | mlog_errno(status); |
| 1799 | goto finally; |
| 1800 | } |
| 1801 | } else { |
| 1802 | mlog(ML_NOTICE, "File system was not unmounted cleanly, " |
| 1803 | "recovering volume.\n"); |
| 1804 | } |
| 1805 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 1806 | local = ocfs2_mount_local(osb); |
| 1807 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1808 | /* will play back anything left in the journal. */ |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1809 | status = ocfs2_journal_load(osb->journal, local, dirty); |
Wengang Wang | 01af482 | 2008-06-10 14:24:48 +0800 | [diff] [blame] | 1810 | if (status < 0) { |
| 1811 | mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status); |
| 1812 | goto finally; |
| 1813 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1814 | |
| 1815 | if (dirty) { |
| 1816 | /* recover my local alloc if we didn't unmount cleanly. */ |
| 1817 | status = ocfs2_begin_local_alloc_recovery(osb, |
| 1818 | osb->slot_num, |
| 1819 | &local_alloc); |
| 1820 | if (status < 0) { |
| 1821 | mlog_errno(status); |
| 1822 | goto finally; |
| 1823 | } |
| 1824 | /* we complete the recovery process after we've marked |
| 1825 | * ourselves as mounted. */ |
| 1826 | } |
| 1827 | |
| 1828 | mlog(0, "Journal loaded.\n"); |
| 1829 | |
| 1830 | status = ocfs2_load_local_alloc(osb); |
| 1831 | if (status < 0) { |
| 1832 | mlog_errno(status); |
| 1833 | goto finally; |
| 1834 | } |
| 1835 | |
| 1836 | if (dirty) { |
| 1837 | /* Recovery will be completed after we've mounted the |
| 1838 | * rest of the volume. */ |
| 1839 | osb->dirty = 1; |
| 1840 | osb->local_alloc_copy = local_alloc; |
| 1841 | local_alloc = NULL; |
| 1842 | } |
| 1843 | |
| 1844 | /* go through each journal, trylock it and if you get the |
| 1845 | * lock, and it's marked as dirty, set the bit in the recover |
| 1846 | * map and launch a recovery thread for it. */ |
| 1847 | status = ocfs2_mark_dead_nodes(osb); |
| 1848 | if (status < 0) |
| 1849 | mlog_errno(status); |
| 1850 | |
| 1851 | finally: |
| 1852 | if (local_alloc) |
| 1853 | kfree(local_alloc); |
| 1854 | |
| 1855 | mlog_exit(status); |
| 1856 | return status; |
| 1857 | } |
| 1858 | |
| 1859 | /* |
| 1860 | * The routine gets called from dismount or close whenever a dismount on |
| 1861 | * volume is requested and the osb open count becomes 1. |
| 1862 | * It will remove the osb from the global list and also free up all the |
| 1863 | * initialized resources and fileobject. |
| 1864 | */ |
| 1865 | static void ocfs2_delete_osb(struct ocfs2_super *osb) |
| 1866 | { |
| 1867 | mlog_entry_void(); |
| 1868 | |
| 1869 | /* This function assumes that the caller has the main osb resource */ |
| 1870 | |
Mark Fasheh | 8e8a460 | 2008-02-01 11:59:09 -0800 | [diff] [blame] | 1871 | ocfs2_free_slot_info(osb); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1872 | |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 1873 | kfree(osb->osb_orphan_wipes); |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1874 | kfree(osb->slot_recovery_generations); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1875 | /* FIXME |
| 1876 | * This belongs in journal shutdown, but because we have to |
| 1877 | * allocate osb->journal at the start of ocfs2_initalize_osb(), |
| 1878 | * we free it here. |
| 1879 | */ |
| 1880 | kfree(osb->journal); |
| 1881 | if (osb->local_alloc_copy) |
| 1882 | kfree(osb->local_alloc_copy); |
| 1883 | kfree(osb->uuid_str); |
| 1884 | ocfs2_put_dlm_debug(osb->osb_dlm_debug); |
| 1885 | memset(osb, 0, sizeof(struct ocfs2_super)); |
| 1886 | |
| 1887 | mlog_exit_void(); |
| 1888 | } |
| 1889 | |
| 1890 | /* Put OCFS2 into a readonly state, or (if the user specifies it), |
| 1891 | * panic(). We do not support continue-on-error operation. */ |
| 1892 | static void ocfs2_handle_error(struct super_block *sb) |
| 1893 | { |
| 1894 | struct ocfs2_super *osb = OCFS2_SB(sb); |
| 1895 | |
| 1896 | if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) |
| 1897 | panic("OCFS2: (device %s): panic forced after error\n", |
| 1898 | sb->s_id); |
| 1899 | |
| 1900 | ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS); |
| 1901 | |
| 1902 | if (sb->s_flags & MS_RDONLY && |
| 1903 | (ocfs2_is_soft_readonly(osb) || |
| 1904 | ocfs2_is_hard_readonly(osb))) |
| 1905 | return; |
| 1906 | |
| 1907 | printk(KERN_CRIT "File system is now read-only due to the potential " |
| 1908 | "of on-disk corruption. Please run fsck.ocfs2 once the file " |
| 1909 | "system is unmounted.\n"); |
| 1910 | sb->s_flags |= MS_RDONLY; |
| 1911 | ocfs2_set_ro_flag(osb, 0); |
| 1912 | } |
| 1913 | |
| 1914 | static char error_buf[1024]; |
| 1915 | |
| 1916 | void __ocfs2_error(struct super_block *sb, |
| 1917 | const char *function, |
| 1918 | const char *fmt, ...) |
| 1919 | { |
| 1920 | va_list args; |
| 1921 | |
| 1922 | va_start(args, fmt); |
Alexey Dobriyan | 4a6e617 | 2006-12-06 20:37:04 -0800 | [diff] [blame] | 1923 | vsnprintf(error_buf, sizeof(error_buf), fmt, args); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1924 | va_end(args); |
| 1925 | |
| 1926 | /* Not using mlog here because we want to show the actual |
| 1927 | * function the error came from. */ |
| 1928 | printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n", |
| 1929 | sb->s_id, function, error_buf); |
| 1930 | |
| 1931 | ocfs2_handle_error(sb); |
| 1932 | } |
| 1933 | |
| 1934 | /* Handle critical errors. This is intentionally more drastic than |
| 1935 | * ocfs2_handle_error, so we only use for things like journal errors, |
| 1936 | * etc. */ |
| 1937 | void __ocfs2_abort(struct super_block* sb, |
| 1938 | const char *function, |
| 1939 | const char *fmt, ...) |
| 1940 | { |
| 1941 | va_list args; |
| 1942 | |
| 1943 | va_start(args, fmt); |
Alexey Dobriyan | 4a6e617 | 2006-12-06 20:37:04 -0800 | [diff] [blame] | 1944 | vsnprintf(error_buf, sizeof(error_buf), fmt, args); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1945 | va_end(args); |
| 1946 | |
| 1947 | printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n", |
| 1948 | sb->s_id, function, error_buf); |
| 1949 | |
| 1950 | /* We don't have the cluster support yet to go straight to |
| 1951 | * hard readonly in here. Until then, we want to keep |
| 1952 | * ocfs2_abort() so that we can at least mark critical |
| 1953 | * errors. |
| 1954 | * |
| 1955 | * TODO: This should abort the journal and alert other nodes |
| 1956 | * that our slot needs recovery. */ |
| 1957 | |
| 1958 | /* Force a panic(). This stinks, but it's better than letting |
| 1959 | * things continue without having a proper hard readonly |
| 1960 | * here. */ |
| 1961 | OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC; |
| 1962 | ocfs2_handle_error(sb); |
| 1963 | } |
| 1964 | |
| 1965 | module_init(ocfs2_init); |
| 1966 | module_exit(ocfs2_exit); |