binfmt_elf: fix PT_INTERP bss handling
[linux-2.6/mini2440.git] / fs / ocfs2 / super.c
blob1a0f6327b49b68a24cf68920402a743bcd59397a
1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
4 * super.c
6 * load/unload driver, mount/dismount volumes
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
26 #include <linux/module.h>
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>
42 #include <linux/mount.h>
43 #include <linux/seq_file.h>
44 #include <linux/quotaops.h>
46 #define MLOG_MASK_PREFIX ML_SUPER
47 #include <cluster/masklog.h>
49 #include "ocfs2.h"
51 /* this should be the only file to include a version 1 header */
52 #include "ocfs1_fs_compat.h"
54 #include "alloc.h"
55 #include "blockcheck.h"
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"
69 #include "xattr.h"
70 #include "quota.h"
72 #include "buffer_head_io.h"
74 static struct kmem_cache *ocfs2_inode_cachep = NULL;
75 struct kmem_cache *ocfs2_dquot_cachep;
76 struct kmem_cache *ocfs2_qf_chunk_cachep;
78 /* OCFS2 needs to schedule several differnt types of work which
79 * require cluster locking, disk I/O, recovery waits, etc. Since these
80 * types of work tend to be heavy we avoid using the kernel events
81 * workqueue and schedule on our own. */
82 struct workqueue_struct *ocfs2_wq = NULL;
84 static struct dentry *ocfs2_debugfs_root = NULL;
86 MODULE_AUTHOR("Oracle");
87 MODULE_LICENSE("GPL");
89 struct mount_options
91 unsigned long commit_interval;
92 unsigned long mount_opt;
93 unsigned int atime_quantum;
94 signed short slot;
95 unsigned int localalloc_opt;
96 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
99 static int ocfs2_parse_options(struct super_block *sb, char *options,
100 struct mount_options *mopt,
101 int is_remount);
102 static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
103 static void ocfs2_put_super(struct super_block *sb);
104 static int ocfs2_mount_volume(struct super_block *sb);
105 static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
106 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
107 static int ocfs2_initialize_mem_caches(void);
108 static void ocfs2_free_mem_caches(void);
109 static void ocfs2_delete_osb(struct ocfs2_super *osb);
111 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
113 static int ocfs2_sync_fs(struct super_block *sb, int wait);
115 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
116 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
117 static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
118 static int ocfs2_check_volume(struct ocfs2_super *osb);
119 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
120 struct buffer_head *bh,
121 u32 sectsize);
122 static int ocfs2_initialize_super(struct super_block *sb,
123 struct buffer_head *bh,
124 int sector_size);
125 static int ocfs2_get_sector(struct super_block *sb,
126 struct buffer_head **bh,
127 int block,
128 int sect_size);
129 static void ocfs2_write_super(struct super_block *sb);
130 static struct inode *ocfs2_alloc_inode(struct super_block *sb);
131 static void ocfs2_destroy_inode(struct inode *inode);
132 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
133 static int ocfs2_enable_quotas(struct ocfs2_super *osb);
134 static void ocfs2_disable_quotas(struct ocfs2_super *osb);
136 static const struct super_operations ocfs2_sops = {
137 .statfs = ocfs2_statfs,
138 .alloc_inode = ocfs2_alloc_inode,
139 .destroy_inode = ocfs2_destroy_inode,
140 .drop_inode = ocfs2_drop_inode,
141 .clear_inode = ocfs2_clear_inode,
142 .delete_inode = ocfs2_delete_inode,
143 .sync_fs = ocfs2_sync_fs,
144 .write_super = ocfs2_write_super,
145 .put_super = ocfs2_put_super,
146 .remount_fs = ocfs2_remount,
147 .show_options = ocfs2_show_options,
148 .quota_read = ocfs2_quota_read,
149 .quota_write = ocfs2_quota_write,
152 enum {
153 Opt_barrier,
154 Opt_err_panic,
155 Opt_err_ro,
156 Opt_intr,
157 Opt_nointr,
158 Opt_hb_none,
159 Opt_hb_local,
160 Opt_data_ordered,
161 Opt_data_writeback,
162 Opt_atime_quantum,
163 Opt_slot,
164 Opt_commit,
165 Opt_localalloc,
166 Opt_localflocks,
167 Opt_stack,
168 Opt_user_xattr,
169 Opt_nouser_xattr,
170 Opt_inode64,
171 Opt_acl,
172 Opt_noacl,
173 Opt_usrquota,
174 Opt_grpquota,
175 Opt_err,
178 static const match_table_t tokens = {
179 {Opt_barrier, "barrier=%u"},
180 {Opt_err_panic, "errors=panic"},
181 {Opt_err_ro, "errors=remount-ro"},
182 {Opt_intr, "intr"},
183 {Opt_nointr, "nointr"},
184 {Opt_hb_none, OCFS2_HB_NONE},
185 {Opt_hb_local, OCFS2_HB_LOCAL},
186 {Opt_data_ordered, "data=ordered"},
187 {Opt_data_writeback, "data=writeback"},
188 {Opt_atime_quantum, "atime_quantum=%u"},
189 {Opt_slot, "preferred_slot=%u"},
190 {Opt_commit, "commit=%u"},
191 {Opt_localalloc, "localalloc=%d"},
192 {Opt_localflocks, "localflocks"},
193 {Opt_stack, "cluster_stack=%s"},
194 {Opt_user_xattr, "user_xattr"},
195 {Opt_nouser_xattr, "nouser_xattr"},
196 {Opt_inode64, "inode64"},
197 {Opt_acl, "acl"},
198 {Opt_noacl, "noacl"},
199 {Opt_usrquota, "usrquota"},
200 {Opt_grpquota, "grpquota"},
201 {Opt_err, NULL}
204 #ifdef CONFIG_DEBUG_FS
205 static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
207 int out = 0;
208 int i;
209 struct ocfs2_cluster_connection *cconn = osb->cconn;
210 struct ocfs2_recovery_map *rm = osb->recovery_map;
212 out += snprintf(buf + out, len - out,
213 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
214 "Device", osb->dev_str, osb->uuid_str,
215 osb->fs_generation, osb->vol_label);
217 out += snprintf(buf + out, len - out,
218 "%10s => State: %d Flags: 0x%lX\n", "Volume",
219 atomic_read(&osb->vol_state), osb->osb_flags);
221 out += snprintf(buf + out, len - out,
222 "%10s => Block: %lu Cluster: %d\n", "Sizes",
223 osb->sb->s_blocksize, osb->s_clustersize);
225 out += snprintf(buf + out, len - out,
226 "%10s => Compat: 0x%X Incompat: 0x%X "
227 "ROcompat: 0x%X\n",
228 "Features", osb->s_feature_compat,
229 osb->s_feature_incompat, osb->s_feature_ro_compat);
231 out += snprintf(buf + out, len - out,
232 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
233 osb->s_mount_opt, osb->s_atime_quantum);
235 if (cconn) {
236 out += snprintf(buf + out, len - out,
237 "%10s => Stack: %s Name: %*s "
238 "Version: %d.%d\n", "Cluster",
239 (*osb->osb_cluster_stack == '\0' ?
240 "o2cb" : osb->osb_cluster_stack),
241 cconn->cc_namelen, cconn->cc_name,
242 cconn->cc_version.pv_major,
243 cconn->cc_version.pv_minor);
246 spin_lock(&osb->dc_task_lock);
247 out += snprintf(buf + out, len - out,
248 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
249 "WorkSeq: %lu\n", "DownCnvt",
250 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
251 osb->blocked_lock_count, osb->dc_wake_sequence,
252 osb->dc_work_sequence);
253 spin_unlock(&osb->dc_task_lock);
255 spin_lock(&osb->osb_lock);
256 out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
257 "Recovery",
258 (osb->recovery_thread_task ?
259 task_pid_nr(osb->recovery_thread_task) : -1));
260 if (rm->rm_used == 0)
261 out += snprintf(buf + out, len - out, " None\n");
262 else {
263 for (i = 0; i < rm->rm_used; i++)
264 out += snprintf(buf + out, len - out, " %d",
265 rm->rm_entries[i]);
266 out += snprintf(buf + out, len - out, "\n");
268 spin_unlock(&osb->osb_lock);
270 out += snprintf(buf + out, len - out,
271 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
272 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
273 osb->osb_commit_interval,
274 atomic_read(&osb->needs_checkpoint));
276 out += snprintf(buf + out, len - out,
277 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
278 "Journal", osb->journal->j_state,
279 osb->journal->j_trans_id,
280 atomic_read(&osb->journal->j_num_trans));
282 out += snprintf(buf + out, len - out,
283 "%10s => GlobalAllocs: %d LocalAllocs: %d "
284 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
285 "Stats",
286 atomic_read(&osb->alloc_stats.bitmap_data),
287 atomic_read(&osb->alloc_stats.local_data),
288 atomic_read(&osb->alloc_stats.bg_allocs),
289 atomic_read(&osb->alloc_stats.moves),
290 atomic_read(&osb->alloc_stats.bg_extends));
292 out += snprintf(buf + out, len - out,
293 "%10s => State: %u Descriptor: %llu Size: %u bits "
294 "Default: %u bits\n",
295 "LocalAlloc", osb->local_alloc_state,
296 (unsigned long long)osb->la_last_gd,
297 osb->local_alloc_bits, osb->local_alloc_default_bits);
299 spin_lock(&osb->osb_lock);
300 out += snprintf(buf + out, len - out,
301 "%10s => Slot: %d NumStolen: %d\n", "Steal",
302 osb->s_inode_steal_slot,
303 atomic_read(&osb->s_num_inodes_stolen));
304 spin_unlock(&osb->osb_lock);
306 out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
307 "Slots", "Num", "RecoGen");
308 for (i = 0; i < osb->max_slots; ++i) {
309 out += snprintf(buf + out, len - out,
310 "%10s %c %3d %10d\n",
311 " ",
312 (i == osb->slot_num ? '*' : ' '),
313 i, osb->slot_recovery_generations[i]);
316 return out;
319 static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
321 struct ocfs2_super *osb = inode->i_private;
322 char *buf = NULL;
324 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
325 if (!buf)
326 goto bail;
328 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
330 file->private_data = buf;
332 return 0;
333 bail:
334 return -ENOMEM;
337 static int ocfs2_debug_release(struct inode *inode, struct file *file)
339 kfree(file->private_data);
340 return 0;
343 static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
344 size_t nbytes, loff_t *ppos)
346 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
347 i_size_read(file->f_mapping->host));
349 #else
350 static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
352 return 0;
354 static int ocfs2_debug_release(struct inode *inode, struct file *file)
356 return 0;
358 static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
359 size_t nbytes, loff_t *ppos)
361 return 0;
363 #endif /* CONFIG_DEBUG_FS */
365 static struct file_operations ocfs2_osb_debug_fops = {
366 .open = ocfs2_osb_debug_open,
367 .release = ocfs2_debug_release,
368 .read = ocfs2_debug_read,
369 .llseek = generic_file_llseek,
373 * write_super and sync_fs ripped right out of ext3.
375 static void ocfs2_write_super(struct super_block *sb)
377 if (mutex_trylock(&sb->s_lock) != 0)
378 BUG();
379 sb->s_dirt = 0;
382 static int ocfs2_sync_fs(struct super_block *sb, int wait)
384 int status;
385 tid_t target;
386 struct ocfs2_super *osb = OCFS2_SB(sb);
388 sb->s_dirt = 0;
390 if (ocfs2_is_hard_readonly(osb))
391 return -EROFS;
393 if (wait) {
394 status = ocfs2_flush_truncate_log(osb);
395 if (status < 0)
396 mlog_errno(status);
397 } else {
398 ocfs2_schedule_truncate_log_flush(osb, 0);
401 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
402 &target)) {
403 if (wait)
404 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
405 target);
407 return 0;
410 static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
412 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
413 && (ino == USER_QUOTA_SYSTEM_INODE
414 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
415 return 0;
416 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
417 && (ino == GROUP_QUOTA_SYSTEM_INODE
418 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
419 return 0;
420 return 1;
423 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
425 struct inode *new = NULL;
426 int status = 0;
427 int i;
429 mlog_entry_void();
431 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
432 if (IS_ERR(new)) {
433 status = PTR_ERR(new);
434 mlog_errno(status);
435 goto bail;
437 osb->root_inode = new;
439 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
440 if (IS_ERR(new)) {
441 status = PTR_ERR(new);
442 mlog_errno(status);
443 goto bail;
445 osb->sys_root_inode = new;
447 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
448 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
449 if (!ocfs2_need_system_inode(osb, i))
450 continue;
451 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
452 if (!new) {
453 ocfs2_release_system_inodes(osb);
454 status = -EINVAL;
455 mlog_errno(status);
456 /* FIXME: Should ERROR_RO_FS */
457 mlog(ML_ERROR, "Unable to load system inode %d, "
458 "possibly corrupt fs?", i);
459 goto bail;
461 // the array now has one ref, so drop this one
462 iput(new);
465 bail:
466 mlog_exit(status);
467 return status;
470 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
472 struct inode *new = NULL;
473 int status = 0;
474 int i;
476 mlog_entry_void();
478 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
479 i < NUM_SYSTEM_INODES;
480 i++) {
481 if (!ocfs2_need_system_inode(osb, i))
482 continue;
483 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
484 if (!new) {
485 ocfs2_release_system_inodes(osb);
486 status = -EINVAL;
487 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
488 status, i, osb->slot_num);
489 goto bail;
491 /* the array now has one ref, so drop this one */
492 iput(new);
495 bail:
496 mlog_exit(status);
497 return status;
500 static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
502 int i;
503 struct inode *inode;
505 mlog_entry_void();
507 for (i = 0; i < NUM_SYSTEM_INODES; i++) {
508 inode = osb->system_inodes[i];
509 if (inode) {
510 iput(inode);
511 osb->system_inodes[i] = NULL;
515 inode = osb->sys_root_inode;
516 if (inode) {
517 iput(inode);
518 osb->sys_root_inode = NULL;
521 inode = osb->root_inode;
522 if (inode) {
523 iput(inode);
524 osb->root_inode = NULL;
527 mlog_exit(0);
530 /* We're allocating fs objects, use GFP_NOFS */
531 static struct inode *ocfs2_alloc_inode(struct super_block *sb)
533 struct ocfs2_inode_info *oi;
535 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
536 if (!oi)
537 return NULL;
539 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
540 return &oi->vfs_inode;
543 static void ocfs2_destroy_inode(struct inode *inode)
545 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
548 static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
549 unsigned int cbits)
551 unsigned int bytes = 1 << cbits;
552 unsigned int trim = bytes;
553 unsigned int bitshift = 32;
556 * i_size and all block offsets in ocfs2 are always 64 bits
557 * wide. i_clusters is 32 bits, in cluster-sized units. So on
558 * 64 bit platforms, cluster size will be the limiting factor.
561 #if BITS_PER_LONG == 32
562 # if defined(CONFIG_LBD)
563 BUILD_BUG_ON(sizeof(sector_t) != 8);
565 * We might be limited by page cache size.
567 if (bytes > PAGE_CACHE_SIZE) {
568 bytes = PAGE_CACHE_SIZE;
569 trim = 1;
571 * Shift by 31 here so that we don't get larger than
572 * MAX_LFS_FILESIZE
574 bitshift = 31;
576 # else
578 * We are limited by the size of sector_t. Use block size, as
579 * that's what we expose to the VFS.
581 bytes = 1 << bbits;
582 trim = 1;
583 bitshift = 31;
584 # endif
585 #endif
588 * Trim by a whole cluster when we can actually approach the
589 * on-disk limits. Otherwise we can overflow i_clusters when
590 * an extent start is at the max offset.
592 return (((unsigned long long)bytes) << bitshift) - trim;
595 static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
597 int incompat_features;
598 int ret = 0;
599 struct mount_options parsed_options;
600 struct ocfs2_super *osb = OCFS2_SB(sb);
602 if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) {
603 ret = -EINVAL;
604 goto out;
607 if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
608 (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
609 ret = -EINVAL;
610 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
611 goto out;
614 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
615 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
616 ret = -EINVAL;
617 mlog(ML_ERROR, "Cannot change data mode on remount\n");
618 goto out;
621 /* Probably don't want this on remount; it might
622 * mess with other nodes */
623 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
624 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
625 ret = -EINVAL;
626 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
627 goto out;
630 /* We're going to/from readonly mode. */
631 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
632 /* Disable quota accounting before remounting RO */
633 if (*flags & MS_RDONLY) {
634 ret = ocfs2_susp_quotas(osb, 0);
635 if (ret < 0)
636 goto out;
638 /* Lock here so the check of HARD_RO and the potential
639 * setting of SOFT_RO is atomic. */
640 spin_lock(&osb->osb_lock);
641 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
642 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
643 ret = -EROFS;
644 goto unlock_osb;
647 if (*flags & MS_RDONLY) {
648 mlog(0, "Going to ro mode.\n");
649 sb->s_flags |= MS_RDONLY;
650 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
651 } else {
652 mlog(0, "Making ro filesystem writeable.\n");
654 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
655 mlog(ML_ERROR, "Cannot remount RDWR "
656 "filesystem due to previous errors.\n");
657 ret = -EROFS;
658 goto unlock_osb;
660 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
661 if (incompat_features) {
662 mlog(ML_ERROR, "Cannot remount RDWR because "
663 "of unsupported optional features "
664 "(%x).\n", incompat_features);
665 ret = -EINVAL;
666 goto unlock_osb;
668 sb->s_flags &= ~MS_RDONLY;
669 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
671 unlock_osb:
672 spin_unlock(&osb->osb_lock);
673 /* Enable quota accounting after remounting RW */
674 if (!ret && !(*flags & MS_RDONLY)) {
675 if (sb_any_quota_suspended(sb))
676 ret = ocfs2_susp_quotas(osb, 1);
677 else
678 ret = ocfs2_enable_quotas(osb);
679 if (ret < 0) {
680 /* Return back changes... */
681 spin_lock(&osb->osb_lock);
682 sb->s_flags |= MS_RDONLY;
683 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
684 spin_unlock(&osb->osb_lock);
685 goto out;
690 if (!ret) {
691 /* Only save off the new mount options in case of a successful
692 * remount. */
693 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
694 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
695 osb->s_mount_opt = parsed_options.mount_opt;
696 osb->s_atime_quantum = parsed_options.atime_quantum;
697 osb->preferred_slot = parsed_options.slot;
698 if (parsed_options.commit_interval)
699 osb->osb_commit_interval = parsed_options.commit_interval;
701 if (!ocfs2_is_hard_readonly(osb))
702 ocfs2_set_journal_params(osb);
704 out:
705 return ret;
708 static int ocfs2_sb_probe(struct super_block *sb,
709 struct buffer_head **bh,
710 int *sector_size)
712 int status, tmpstat;
713 struct ocfs1_vol_disk_hdr *hdr;
714 struct ocfs2_dinode *di;
715 int blksize;
717 *bh = NULL;
719 /* may be > 512 */
720 *sector_size = bdev_hardsect_size(sb->s_bdev);
721 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
722 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
723 *sector_size, OCFS2_MAX_BLOCKSIZE);
724 status = -EINVAL;
725 goto bail;
728 /* Can this really happen? */
729 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
730 *sector_size = OCFS2_MIN_BLOCKSIZE;
732 /* check block zero for old format */
733 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
734 if (status < 0) {
735 mlog_errno(status);
736 goto bail;
738 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
739 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
740 mlog(ML_ERROR, "incompatible version: %u.%u\n",
741 hdr->major_version, hdr->minor_version);
742 status = -EINVAL;
744 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
745 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
746 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
747 hdr->signature);
748 status = -EINVAL;
750 brelse(*bh);
751 *bh = NULL;
752 if (status < 0) {
753 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
754 "upgraded before mounting with ocfs v2\n");
755 goto bail;
759 * Now check at magic offset for 512, 1024, 2048, 4096
760 * blocksizes. 4096 is the maximum blocksize because it is
761 * the minimum clustersize.
763 status = -EINVAL;
764 for (blksize = *sector_size;
765 blksize <= OCFS2_MAX_BLOCKSIZE;
766 blksize <<= 1) {
767 tmpstat = ocfs2_get_sector(sb, bh,
768 OCFS2_SUPER_BLOCK_BLKNO,
769 blksize);
770 if (tmpstat < 0) {
771 status = tmpstat;
772 mlog_errno(status);
773 goto bail;
775 di = (struct ocfs2_dinode *) (*bh)->b_data;
776 status = ocfs2_verify_volume(di, *bh, blksize);
777 if (status >= 0)
778 goto bail;
779 brelse(*bh);
780 *bh = NULL;
781 if (status != -EAGAIN)
782 break;
785 bail:
786 return status;
789 static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
791 if (ocfs2_mount_local(osb)) {
792 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
793 mlog(ML_ERROR, "Cannot heartbeat on a locally "
794 "mounted device.\n");
795 return -EINVAL;
799 if (ocfs2_userspace_stack(osb)) {
800 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
801 mlog(ML_ERROR, "Userspace stack expected, but "
802 "o2cb heartbeat arguments passed to mount\n");
803 return -EINVAL;
807 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
808 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
809 !ocfs2_userspace_stack(osb)) {
810 mlog(ML_ERROR, "Heartbeat has to be started to mount "
811 "a read-write clustered device.\n");
812 return -EINVAL;
816 return 0;
820 * If we're using a userspace stack, mount should have passed
821 * a name that matches the disk. If not, mount should not
822 * have passed a stack.
824 static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
825 struct mount_options *mopt)
827 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
828 mlog(ML_ERROR,
829 "cluster stack passed to mount, but this filesystem "
830 "does not support it\n");
831 return -EINVAL;
834 if (ocfs2_userspace_stack(osb) &&
835 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
836 OCFS2_STACK_LABEL_LEN)) {
837 mlog(ML_ERROR,
838 "cluster stack passed to mount (\"%s\") does not "
839 "match the filesystem (\"%s\")\n",
840 mopt->cluster_stack,
841 osb->osb_cluster_stack);
842 return -EINVAL;
845 return 0;
848 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
850 int type;
851 struct super_block *sb = osb->sb;
852 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
853 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
854 int status = 0;
856 for (type = 0; type < MAXQUOTAS; type++) {
857 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
858 continue;
859 if (unsuspend)
860 status = vfs_quota_enable(
861 sb_dqopt(sb)->files[type],
862 type, QFMT_OCFS2,
863 DQUOT_SUSPENDED);
864 else
865 status = vfs_quota_disable(sb, type,
866 DQUOT_SUSPENDED);
867 if (status < 0)
868 break;
870 if (status < 0)
871 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
872 "remount (error = %d).\n", status);
873 return status;
876 static int ocfs2_enable_quotas(struct ocfs2_super *osb)
878 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
879 struct super_block *sb = osb->sb;
880 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
881 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
882 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
883 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
884 int status;
885 int type;
887 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
888 for (type = 0; type < MAXQUOTAS; type++) {
889 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
890 continue;
891 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
892 osb->slot_num);
893 if (!inode[type]) {
894 status = -ENOENT;
895 goto out_quota_off;
897 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
898 DQUOT_USAGE_ENABLED);
899 if (status < 0)
900 goto out_quota_off;
903 for (type = 0; type < MAXQUOTAS; type++)
904 iput(inode[type]);
905 return 0;
906 out_quota_off:
907 ocfs2_disable_quotas(osb);
908 for (type = 0; type < MAXQUOTAS; type++)
909 iput(inode[type]);
910 mlog_errno(status);
911 return status;
914 static void ocfs2_disable_quotas(struct ocfs2_super *osb)
916 int type;
917 struct inode *inode;
918 struct super_block *sb = osb->sb;
920 /* We mostly ignore errors in this function because there's not much
921 * we can do when we see them */
922 for (type = 0; type < MAXQUOTAS; type++) {
923 if (!sb_has_quota_loaded(sb, type))
924 continue;
925 inode = igrab(sb->s_dquot.files[type]);
926 /* Turn off quotas. This will remove all dquot structures from
927 * memory and so they will be automatically synced to global
928 * quota files */
929 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
930 DQUOT_LIMITS_ENABLED);
931 if (!inode)
932 continue;
933 iput(inode);
937 /* Handle quota on quotactl */
938 static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
939 char *path, int remount)
941 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
942 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
944 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
945 return -EINVAL;
947 if (remount)
948 return 0; /* Just ignore it has been handled in
949 * ocfs2_remount() */
950 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
951 format_id, DQUOT_LIMITS_ENABLED);
954 /* Handle quota off quotactl */
955 static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
957 if (remount)
958 return 0; /* Ignore now and handle later in
959 * ocfs2_remount() */
960 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
963 static struct quotactl_ops ocfs2_quotactl_ops = {
964 .quota_on = ocfs2_quota_on,
965 .quota_off = ocfs2_quota_off,
966 .quota_sync = vfs_quota_sync,
967 .get_info = vfs_get_dqinfo,
968 .set_info = vfs_set_dqinfo,
969 .get_dqblk = vfs_get_dqblk,
970 .set_dqblk = vfs_set_dqblk,
973 static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
975 struct dentry *root;
976 int status, sector_size;
977 struct mount_options parsed_options;
978 struct inode *inode = NULL;
979 struct ocfs2_super *osb = NULL;
980 struct buffer_head *bh = NULL;
981 char nodestr[8];
983 mlog_entry("%p, %p, %i", sb, data, silent);
985 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
986 status = -EINVAL;
987 goto read_super_error;
990 /* probe for superblock */
991 status = ocfs2_sb_probe(sb, &bh, &sector_size);
992 if (status < 0) {
993 mlog(ML_ERROR, "superblock probe failed!\n");
994 goto read_super_error;
997 status = ocfs2_initialize_super(sb, bh, sector_size);
998 osb = OCFS2_SB(sb);
999 if (status < 0) {
1000 mlog_errno(status);
1001 goto read_super_error;
1003 brelse(bh);
1004 bh = NULL;
1006 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
1007 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1009 osb->s_mount_opt = parsed_options.mount_opt;
1010 osb->s_atime_quantum = parsed_options.atime_quantum;
1011 osb->preferred_slot = parsed_options.slot;
1012 osb->osb_commit_interval = parsed_options.commit_interval;
1013 osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
1014 osb->local_alloc_bits = osb->local_alloc_default_bits;
1015 if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA &&
1016 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1017 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1018 status = -EINVAL;
1019 mlog(ML_ERROR, "User quotas were requested, but this "
1020 "filesystem does not have the feature enabled.\n");
1021 goto read_super_error;
1023 if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1024 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1025 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1026 status = -EINVAL;
1027 mlog(ML_ERROR, "Group quotas were requested, but this "
1028 "filesystem does not have the feature enabled.\n");
1029 goto read_super_error;
1032 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1033 if (status)
1034 goto read_super_error;
1036 sb->s_magic = OCFS2_SUPER_MAGIC;
1038 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1039 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1041 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1042 * heartbeat=none */
1043 if (bdev_read_only(sb->s_bdev)) {
1044 if (!(sb->s_flags & MS_RDONLY)) {
1045 status = -EACCES;
1046 mlog(ML_ERROR, "Readonly device detected but readonly "
1047 "mount was not specified.\n");
1048 goto read_super_error;
1051 /* You should not be able to start a local heartbeat
1052 * on a readonly device. */
1053 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1054 status = -EROFS;
1055 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1056 "device.\n");
1057 goto read_super_error;
1060 status = ocfs2_check_journals_nolocks(osb);
1061 if (status < 0) {
1062 if (status == -EROFS)
1063 mlog(ML_ERROR, "Recovery required on readonly "
1064 "file system, but write access is "
1065 "unavailable.\n");
1066 else
1067 mlog_errno(status);
1068 goto read_super_error;
1071 ocfs2_set_ro_flag(osb, 1);
1073 printk(KERN_NOTICE "Readonly device detected. No cluster "
1074 "services will be utilized for this mount. Recovery "
1075 "will be skipped.\n");
1078 if (!ocfs2_is_hard_readonly(osb)) {
1079 if (sb->s_flags & MS_RDONLY)
1080 ocfs2_set_ro_flag(osb, 0);
1083 status = ocfs2_verify_heartbeat(osb);
1084 if (status < 0) {
1085 mlog_errno(status);
1086 goto read_super_error;
1089 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1090 ocfs2_debugfs_root);
1091 if (!osb->osb_debug_root) {
1092 status = -EINVAL;
1093 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1094 goto read_super_error;
1097 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1098 osb->osb_debug_root,
1099 osb,
1100 &ocfs2_osb_debug_fops);
1101 if (!osb->osb_ctxt) {
1102 status = -EINVAL;
1103 mlog_errno(status);
1104 goto read_super_error;
1107 status = ocfs2_mount_volume(sb);
1108 if (osb->root_inode)
1109 inode = igrab(osb->root_inode);
1111 if (status < 0)
1112 goto read_super_error;
1114 if (!inode) {
1115 status = -EIO;
1116 mlog_errno(status);
1117 goto read_super_error;
1120 root = d_alloc_root(inode);
1121 if (!root) {
1122 status = -ENOMEM;
1123 mlog_errno(status);
1124 goto read_super_error;
1127 sb->s_root = root;
1129 ocfs2_complete_mount_recovery(osb);
1131 if (ocfs2_mount_local(osb))
1132 snprintf(nodestr, sizeof(nodestr), "local");
1133 else
1134 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1136 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
1137 "with %s data mode.\n",
1138 osb->dev_str, nodestr, osb->slot_num,
1139 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1140 "ordered");
1142 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1143 wake_up(&osb->osb_mount_event);
1145 /* Now we can initialize quotas because we can afford to wait
1146 * for cluster locks recovery now. That also means that truncation
1147 * log recovery can happen but that waits for proper quota setup */
1148 if (!(sb->s_flags & MS_RDONLY)) {
1149 status = ocfs2_enable_quotas(osb);
1150 if (status < 0) {
1151 /* We have to err-out specially here because
1152 * s_root is already set */
1153 mlog_errno(status);
1154 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1155 wake_up(&osb->osb_mount_event);
1156 mlog_exit(status);
1157 return status;
1161 ocfs2_complete_quota_recovery(osb);
1163 /* Now we wake up again for processes waiting for quotas */
1164 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1165 wake_up(&osb->osb_mount_event);
1167 mlog_exit(status);
1168 return status;
1170 read_super_error:
1171 brelse(bh);
1173 if (inode)
1174 iput(inode);
1176 if (osb) {
1177 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1178 wake_up(&osb->osb_mount_event);
1179 ocfs2_dismount_volume(sb, 1);
1182 mlog_exit(status);
1183 return status;
1186 static int ocfs2_get_sb(struct file_system_type *fs_type,
1187 int flags,
1188 const char *dev_name,
1189 void *data,
1190 struct vfsmount *mnt)
1192 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1193 mnt);
1196 static struct file_system_type ocfs2_fs_type = {
1197 .owner = THIS_MODULE,
1198 .name = "ocfs2",
1199 .get_sb = ocfs2_get_sb, /* is this called when we mount
1200 * the fs? */
1201 .kill_sb = kill_block_super, /* set to the generic one
1202 * right now, but do we
1203 * need to change that? */
1204 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
1205 .next = NULL
1208 static int ocfs2_parse_options(struct super_block *sb,
1209 char *options,
1210 struct mount_options *mopt,
1211 int is_remount)
1213 int status;
1214 char *p;
1216 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1217 options ? options : "(none)");
1219 mopt->commit_interval = 0;
1220 mopt->mount_opt = 0;
1221 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1222 mopt->slot = OCFS2_INVALID_SLOT;
1223 mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
1224 mopt->cluster_stack[0] = '\0';
1226 if (!options) {
1227 status = 1;
1228 goto bail;
1231 while ((p = strsep(&options, ",")) != NULL) {
1232 int token, option;
1233 substring_t args[MAX_OPT_ARGS];
1235 if (!*p)
1236 continue;
1238 token = match_token(p, tokens, args);
1239 switch (token) {
1240 case Opt_hb_local:
1241 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
1242 break;
1243 case Opt_hb_none:
1244 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
1245 break;
1246 case Opt_barrier:
1247 if (match_int(&args[0], &option)) {
1248 status = 0;
1249 goto bail;
1251 if (option)
1252 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
1253 else
1254 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
1255 break;
1256 case Opt_intr:
1257 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
1258 break;
1259 case Opt_nointr:
1260 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
1261 break;
1262 case Opt_err_panic:
1263 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
1264 break;
1265 case Opt_err_ro:
1266 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1267 break;
1268 case Opt_data_ordered:
1269 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
1270 break;
1271 case Opt_data_writeback:
1272 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
1273 break;
1274 case Opt_user_xattr:
1275 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1276 break;
1277 case Opt_nouser_xattr:
1278 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1279 break;
1280 case Opt_atime_quantum:
1281 if (match_int(&args[0], &option)) {
1282 status = 0;
1283 goto bail;
1285 if (option >= 0)
1286 mopt->atime_quantum = option;
1287 break;
1288 case Opt_slot:
1289 option = 0;
1290 if (match_int(&args[0], &option)) {
1291 status = 0;
1292 goto bail;
1294 if (option)
1295 mopt->slot = (s16)option;
1296 break;
1297 case Opt_commit:
1298 option = 0;
1299 if (match_int(&args[0], &option)) {
1300 status = 0;
1301 goto bail;
1303 if (option < 0)
1304 return 0;
1305 if (option == 0)
1306 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1307 mopt->commit_interval = HZ * option;
1308 break;
1309 case Opt_localalloc:
1310 option = 0;
1311 if (match_int(&args[0], &option)) {
1312 status = 0;
1313 goto bail;
1315 if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1316 mopt->localalloc_opt = option;
1317 break;
1318 case Opt_localflocks:
1320 * Changing this during remount could race
1321 * flock() requests, or "unbalance" existing
1322 * ones (e.g., a lock is taken in one mode but
1323 * dropped in the other). If users care enough
1324 * to flip locking modes during remount, we
1325 * could add a "local" flag to individual
1326 * flock structures for proper tracking of
1327 * state.
1329 if (!is_remount)
1330 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1331 break;
1332 case Opt_stack:
1333 /* Check both that the option we were passed
1334 * is of the right length and that it is a proper
1335 * string of the right length.
1337 if (((args[0].to - args[0].from) !=
1338 OCFS2_STACK_LABEL_LEN) ||
1339 (strnlen(args[0].from,
1340 OCFS2_STACK_LABEL_LEN) !=
1341 OCFS2_STACK_LABEL_LEN)) {
1342 mlog(ML_ERROR,
1343 "Invalid cluster_stack option\n");
1344 status = 0;
1345 goto bail;
1347 memcpy(mopt->cluster_stack, args[0].from,
1348 OCFS2_STACK_LABEL_LEN);
1349 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1350 break;
1351 case Opt_inode64:
1352 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1353 break;
1354 case Opt_usrquota:
1355 /* We check only on remount, otherwise features
1356 * aren't yet initialized. */
1357 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1358 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1359 mlog(ML_ERROR, "User quota requested but "
1360 "filesystem feature is not set\n");
1361 status = 0;
1362 goto bail;
1364 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1365 break;
1366 case Opt_grpquota:
1367 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1368 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1369 mlog(ML_ERROR, "Group quota requested but "
1370 "filesystem feature is not set\n");
1371 status = 0;
1372 goto bail;
1374 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1375 break;
1376 #ifdef CONFIG_OCFS2_FS_POSIX_ACL
1377 case Opt_acl:
1378 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1379 break;
1380 case Opt_noacl:
1381 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1382 break;
1383 #else
1384 case Opt_acl:
1385 case Opt_noacl:
1386 printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
1387 break;
1388 #endif
1389 default:
1390 mlog(ML_ERROR,
1391 "Unrecognized mount option \"%s\" "
1392 "or missing value\n", p);
1393 status = 0;
1394 goto bail;
1398 status = 1;
1400 bail:
1401 mlog_exit(status);
1402 return status;
1405 static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1407 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1408 unsigned long opts = osb->s_mount_opt;
1409 unsigned int local_alloc_megs;
1411 if (opts & OCFS2_MOUNT_HB_LOCAL)
1412 seq_printf(s, ",_netdev,heartbeat=local");
1413 else
1414 seq_printf(s, ",heartbeat=none");
1416 if (opts & OCFS2_MOUNT_NOINTR)
1417 seq_printf(s, ",nointr");
1419 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1420 seq_printf(s, ",data=writeback");
1421 else
1422 seq_printf(s, ",data=ordered");
1424 if (opts & OCFS2_MOUNT_BARRIER)
1425 seq_printf(s, ",barrier=1");
1427 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1428 seq_printf(s, ",errors=panic");
1429 else
1430 seq_printf(s, ",errors=remount-ro");
1432 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1433 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1435 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1436 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1438 if (osb->osb_commit_interval)
1439 seq_printf(s, ",commit=%u",
1440 (unsigned) (osb->osb_commit_interval / HZ));
1442 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1443 if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1444 seq_printf(s, ",localalloc=%d", local_alloc_megs);
1446 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1447 seq_printf(s, ",localflocks,");
1449 if (osb->osb_cluster_stack[0])
1450 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1451 osb->osb_cluster_stack);
1452 if (opts & OCFS2_MOUNT_USRQUOTA)
1453 seq_printf(s, ",usrquota");
1454 if (opts & OCFS2_MOUNT_GRPQUOTA)
1455 seq_printf(s, ",grpquota");
1457 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1458 seq_printf(s, ",nouser_xattr");
1459 else
1460 seq_printf(s, ",user_xattr");
1462 if (opts & OCFS2_MOUNT_INODE64)
1463 seq_printf(s, ",inode64");
1465 #ifdef CONFIG_OCFS2_FS_POSIX_ACL
1466 if (opts & OCFS2_MOUNT_POSIX_ACL)
1467 seq_printf(s, ",acl");
1468 else
1469 seq_printf(s, ",noacl");
1470 #endif
1472 return 0;
1475 static int __init ocfs2_init(void)
1477 int status;
1479 mlog_entry_void();
1481 ocfs2_print_version();
1483 status = init_ocfs2_uptodate_cache();
1484 if (status < 0) {
1485 mlog_errno(status);
1486 goto leave;
1489 status = ocfs2_initialize_mem_caches();
1490 if (status < 0) {
1491 mlog_errno(status);
1492 goto leave;
1495 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1496 if (!ocfs2_wq) {
1497 status = -ENOMEM;
1498 goto leave;
1501 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1502 if (!ocfs2_debugfs_root) {
1503 status = -EFAULT;
1504 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1507 status = ocfs2_quota_setup();
1508 if (status)
1509 goto leave;
1511 ocfs2_set_locking_protocol();
1513 status = register_quota_format(&ocfs2_quota_format);
1514 leave:
1515 if (status < 0) {
1516 ocfs2_quota_shutdown();
1517 ocfs2_free_mem_caches();
1518 exit_ocfs2_uptodate_cache();
1521 mlog_exit(status);
1523 if (status >= 0) {
1524 return register_filesystem(&ocfs2_fs_type);
1525 } else
1526 return -1;
1529 static void __exit ocfs2_exit(void)
1531 mlog_entry_void();
1533 ocfs2_quota_shutdown();
1535 if (ocfs2_wq) {
1536 flush_workqueue(ocfs2_wq);
1537 destroy_workqueue(ocfs2_wq);
1540 unregister_quota_format(&ocfs2_quota_format);
1542 debugfs_remove(ocfs2_debugfs_root);
1544 ocfs2_free_mem_caches();
1546 unregister_filesystem(&ocfs2_fs_type);
1548 exit_ocfs2_uptodate_cache();
1550 mlog_exit_void();
1553 static void ocfs2_put_super(struct super_block *sb)
1555 mlog_entry("(0x%p)\n", sb);
1557 ocfs2_sync_blockdev(sb);
1558 ocfs2_dismount_volume(sb, 0);
1560 mlog_exit_void();
1563 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1565 struct ocfs2_super *osb;
1566 u32 numbits, freebits;
1567 int status;
1568 struct ocfs2_dinode *bm_lock;
1569 struct buffer_head *bh = NULL;
1570 struct inode *inode = NULL;
1572 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
1574 osb = OCFS2_SB(dentry->d_sb);
1576 inode = ocfs2_get_system_file_inode(osb,
1577 GLOBAL_BITMAP_SYSTEM_INODE,
1578 OCFS2_INVALID_SLOT);
1579 if (!inode) {
1580 mlog(ML_ERROR, "failed to get bitmap inode\n");
1581 status = -EIO;
1582 goto bail;
1585 status = ocfs2_inode_lock(inode, &bh, 0);
1586 if (status < 0) {
1587 mlog_errno(status);
1588 goto bail;
1591 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1593 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1594 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1596 buf->f_type = OCFS2_SUPER_MAGIC;
1597 buf->f_bsize = dentry->d_sb->s_blocksize;
1598 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1599 buf->f_blocks = ((sector_t) numbits) *
1600 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1601 buf->f_bfree = ((sector_t) freebits) *
1602 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1603 buf->f_bavail = buf->f_bfree;
1604 buf->f_files = numbits;
1605 buf->f_ffree = freebits;
1607 brelse(bh);
1609 ocfs2_inode_unlock(inode, 0);
1610 status = 0;
1611 bail:
1612 if (inode)
1613 iput(inode);
1615 mlog_exit(status);
1617 return status;
1620 static void ocfs2_inode_init_once(void *data)
1622 struct ocfs2_inode_info *oi = data;
1624 oi->ip_flags = 0;
1625 oi->ip_open_count = 0;
1626 spin_lock_init(&oi->ip_lock);
1627 ocfs2_extent_map_init(&oi->vfs_inode);
1628 INIT_LIST_HEAD(&oi->ip_io_markers);
1629 oi->ip_created_trans = 0;
1630 oi->ip_last_trans = 0;
1631 oi->ip_dir_start_lookup = 0;
1633 init_rwsem(&oi->ip_alloc_sem);
1634 init_rwsem(&oi->ip_xattr_sem);
1635 mutex_init(&oi->ip_io_mutex);
1637 oi->ip_blkno = 0ULL;
1638 oi->ip_clusters = 0;
1640 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
1641 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
1642 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
1644 ocfs2_metadata_cache_init(&oi->vfs_inode);
1646 inode_init_once(&oi->vfs_inode);
1649 static int ocfs2_initialize_mem_caches(void)
1651 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
1652 sizeof(struct ocfs2_inode_info),
1654 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1655 SLAB_MEM_SPREAD),
1656 ocfs2_inode_init_once);
1657 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1658 sizeof(struct ocfs2_dquot),
1660 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1661 SLAB_MEM_SPREAD),
1662 NULL);
1663 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1664 sizeof(struct ocfs2_quota_chunk),
1666 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1667 NULL);
1668 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1669 !ocfs2_qf_chunk_cachep) {
1670 if (ocfs2_inode_cachep)
1671 kmem_cache_destroy(ocfs2_inode_cachep);
1672 if (ocfs2_dquot_cachep)
1673 kmem_cache_destroy(ocfs2_dquot_cachep);
1674 if (ocfs2_qf_chunk_cachep)
1675 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1676 return -ENOMEM;
1679 return 0;
1682 static void ocfs2_free_mem_caches(void)
1684 if (ocfs2_inode_cachep)
1685 kmem_cache_destroy(ocfs2_inode_cachep);
1686 ocfs2_inode_cachep = NULL;
1688 if (ocfs2_dquot_cachep)
1689 kmem_cache_destroy(ocfs2_dquot_cachep);
1690 ocfs2_dquot_cachep = NULL;
1692 if (ocfs2_qf_chunk_cachep)
1693 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1694 ocfs2_qf_chunk_cachep = NULL;
1697 static int ocfs2_get_sector(struct super_block *sb,
1698 struct buffer_head **bh,
1699 int block,
1700 int sect_size)
1702 if (!sb_set_blocksize(sb, sect_size)) {
1703 mlog(ML_ERROR, "unable to set blocksize\n");
1704 return -EIO;
1707 *bh = sb_getblk(sb, block);
1708 if (!*bh) {
1709 mlog_errno(-EIO);
1710 return -EIO;
1712 lock_buffer(*bh);
1713 if (!buffer_dirty(*bh))
1714 clear_buffer_uptodate(*bh);
1715 unlock_buffer(*bh);
1716 ll_rw_block(READ, 1, bh);
1717 wait_on_buffer(*bh);
1718 if (!buffer_uptodate(*bh)) {
1719 mlog_errno(-EIO);
1720 brelse(*bh);
1721 *bh = NULL;
1722 return -EIO;
1725 return 0;
1728 static int ocfs2_mount_volume(struct super_block *sb)
1730 int status = 0;
1731 int unlock_super = 0;
1732 struct ocfs2_super *osb = OCFS2_SB(sb);
1734 mlog_entry_void();
1736 if (ocfs2_is_hard_readonly(osb))
1737 goto leave;
1739 status = ocfs2_dlm_init(osb);
1740 if (status < 0) {
1741 mlog_errno(status);
1742 goto leave;
1745 status = ocfs2_super_lock(osb, 1);
1746 if (status < 0) {
1747 mlog_errno(status);
1748 goto leave;
1750 unlock_super = 1;
1752 /* This will load up the node map and add ourselves to it. */
1753 status = ocfs2_find_slot(osb);
1754 if (status < 0) {
1755 mlog_errno(status);
1756 goto leave;
1759 /* load all node-local system inodes */
1760 status = ocfs2_init_local_system_inodes(osb);
1761 if (status < 0) {
1762 mlog_errno(status);
1763 goto leave;
1766 status = ocfs2_check_volume(osb);
1767 if (status < 0) {
1768 mlog_errno(status);
1769 goto leave;
1772 status = ocfs2_truncate_log_init(osb);
1773 if (status < 0) {
1774 mlog_errno(status);
1775 goto leave;
1778 if (ocfs2_mount_local(osb))
1779 goto leave;
1781 leave:
1782 if (unlock_super)
1783 ocfs2_super_unlock(osb, 1);
1785 mlog_exit(status);
1786 return status;
1789 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1791 int tmp, hangup_needed = 0;
1792 struct ocfs2_super *osb = NULL;
1793 char nodestr[8];
1795 mlog_entry("(0x%p)\n", sb);
1797 BUG_ON(!sb);
1798 osb = OCFS2_SB(sb);
1799 BUG_ON(!osb);
1801 debugfs_remove(osb->osb_ctxt);
1803 ocfs2_disable_quotas(osb);
1805 ocfs2_shutdown_local_alloc(osb);
1807 ocfs2_truncate_log_shutdown(osb);
1809 /* This will disable recovery and flush any recovery work. */
1810 ocfs2_recovery_exit(osb);
1812 ocfs2_journal_shutdown(osb);
1814 ocfs2_sync_blockdev(sb);
1816 /* No cluster connection means we've failed during mount, so skip
1817 * all the steps which depended on that to complete. */
1818 if (osb->cconn) {
1819 tmp = ocfs2_super_lock(osb, 1);
1820 if (tmp < 0) {
1821 mlog_errno(tmp);
1822 return;
1826 if (osb->slot_num != OCFS2_INVALID_SLOT)
1827 ocfs2_put_slot(osb);
1829 if (osb->cconn)
1830 ocfs2_super_unlock(osb, 1);
1832 ocfs2_release_system_inodes(osb);
1835 * If we're dismounting due to mount error, mount.ocfs2 will clean
1836 * up heartbeat. If we're a local mount, there is no heartbeat.
1837 * If we failed before we got a uuid_str yet, we can't stop
1838 * heartbeat. Otherwise, do it.
1840 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
1841 hangup_needed = 1;
1843 if (osb->cconn)
1844 ocfs2_dlm_shutdown(osb, hangup_needed);
1846 debugfs_remove(osb->osb_debug_root);
1848 if (hangup_needed)
1849 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
1851 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1853 if (ocfs2_mount_local(osb))
1854 snprintf(nodestr, sizeof(nodestr), "local");
1855 else
1856 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1858 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1859 osb->dev_str, nodestr);
1861 ocfs2_delete_osb(osb);
1862 kfree(osb);
1863 sb->s_dev = 0;
1864 sb->s_fs_info = NULL;
1867 static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1868 unsigned uuid_bytes)
1870 int i, ret;
1871 char *ptr;
1873 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1875 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
1876 if (osb->uuid_str == NULL)
1877 return -ENOMEM;
1879 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1880 /* print with null */
1881 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1882 if (ret != 2) /* drop super cleans up */
1883 return -EINVAL;
1884 /* then only advance past the last char */
1885 ptr += 2;
1888 return 0;
1891 static int ocfs2_initialize_super(struct super_block *sb,
1892 struct buffer_head *bh,
1893 int sector_size)
1895 int status;
1896 int i, cbits, bbits;
1897 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
1898 struct inode *inode = NULL;
1899 struct ocfs2_journal *journal;
1900 __le32 uuid_net_key;
1901 struct ocfs2_super *osb;
1903 mlog_entry_void();
1905 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
1906 if (!osb) {
1907 status = -ENOMEM;
1908 mlog_errno(status);
1909 goto bail;
1912 sb->s_fs_info = osb;
1913 sb->s_op = &ocfs2_sops;
1914 sb->s_export_op = &ocfs2_export_ops;
1915 sb->s_qcop = &ocfs2_quotactl_ops;
1916 sb->dq_op = &ocfs2_quota_operations;
1917 sb->s_xattr = ocfs2_xattr_handlers;
1918 sb->s_time_gran = 1;
1919 sb->s_flags |= MS_NOATIME;
1920 /* this is needed to support O_LARGEFILE */
1921 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1922 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1923 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
1925 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
1927 for (i = 0; i < 3; i++)
1928 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
1929 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1931 osb->sb = sb;
1932 /* Save off for ocfs2_rw_direct */
1933 osb->s_sectsize_bits = blksize_bits(sector_size);
1934 BUG_ON(!osb->s_sectsize_bits);
1936 spin_lock_init(&osb->dc_task_lock);
1937 init_waitqueue_head(&osb->dc_event);
1938 osb->dc_work_sequence = 0;
1939 osb->dc_wake_sequence = 0;
1940 INIT_LIST_HEAD(&osb->blocked_lock_list);
1941 osb->blocked_lock_count = 0;
1942 spin_lock_init(&osb->osb_lock);
1943 spin_lock_init(&osb->osb_xattr_lock);
1944 ocfs2_init_inode_steal_slot(osb);
1946 atomic_set(&osb->alloc_stats.moves, 0);
1947 atomic_set(&osb->alloc_stats.local_data, 0);
1948 atomic_set(&osb->alloc_stats.bitmap_data, 0);
1949 atomic_set(&osb->alloc_stats.bg_allocs, 0);
1950 atomic_set(&osb->alloc_stats.bg_extends, 0);
1952 ocfs2_init_node_maps(osb);
1954 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
1955 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
1957 status = ocfs2_recovery_init(osb);
1958 if (status) {
1959 mlog(ML_ERROR, "Unable to initialize recovery state\n");
1960 mlog_errno(status);
1961 goto bail;
1964 init_waitqueue_head(&osb->checkpoint_event);
1965 atomic_set(&osb->needs_checkpoint, 0);
1967 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1969 osb->slot_num = OCFS2_INVALID_SLOT;
1971 osb->s_xattr_inline_size = le16_to_cpu(
1972 di->id2.i_super.s_xattr_inline_size);
1974 osb->local_alloc_state = OCFS2_LA_UNUSED;
1975 osb->local_alloc_bh = NULL;
1976 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
1978 init_waitqueue_head(&osb->osb_mount_event);
1980 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
1981 if (!osb->vol_label) {
1982 mlog(ML_ERROR, "unable to alloc vol label\n");
1983 status = -ENOMEM;
1984 goto bail;
1987 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
1988 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
1989 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
1990 osb->max_slots);
1991 status = -EINVAL;
1992 goto bail;
1994 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
1996 osb->slot_recovery_generations =
1997 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
1998 GFP_KERNEL);
1999 if (!osb->slot_recovery_generations) {
2000 status = -ENOMEM;
2001 mlog_errno(status);
2002 goto bail;
2005 init_waitqueue_head(&osb->osb_wipe_event);
2006 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2007 sizeof(*osb->osb_orphan_wipes),
2008 GFP_KERNEL);
2009 if (!osb->osb_orphan_wipes) {
2010 status = -ENOMEM;
2011 mlog_errno(status);
2012 goto bail;
2015 osb->s_feature_compat =
2016 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2017 osb->s_feature_ro_compat =
2018 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2019 osb->s_feature_incompat =
2020 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2022 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2023 mlog(ML_ERROR, "couldn't mount because of unsupported "
2024 "optional features (%x).\n", i);
2025 status = -EINVAL;
2026 goto bail;
2028 if (!(osb->sb->s_flags & MS_RDONLY) &&
2029 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2030 mlog(ML_ERROR, "couldn't mount RDWR because of "
2031 "unsupported optional features (%x).\n", i);
2032 status = -EINVAL;
2033 goto bail;
2036 if (ocfs2_userspace_stack(osb)) {
2037 memcpy(osb->osb_cluster_stack,
2038 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2039 OCFS2_STACK_LABEL_LEN);
2040 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2041 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2042 mlog(ML_ERROR,
2043 "couldn't mount because of an invalid "
2044 "cluster stack label (%s) \n",
2045 osb->osb_cluster_stack);
2046 status = -EINVAL;
2047 goto bail;
2049 } else {
2050 /* The empty string is identical with classic tools that
2051 * don't know about s_cluster_info. */
2052 osb->osb_cluster_stack[0] = '\0';
2055 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2057 /* FIXME
2058 * This should be done in ocfs2_journal_init(), but unknown
2059 * ordering issues will cause the filesystem to crash.
2060 * If anyone wants to figure out what part of the code
2061 * refers to osb->journal before ocfs2_journal_init() is run,
2062 * be my guest.
2064 /* initialize our journal structure */
2066 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
2067 if (!journal) {
2068 mlog(ML_ERROR, "unable to alloc journal\n");
2069 status = -ENOMEM;
2070 goto bail;
2072 osb->journal = journal;
2073 journal->j_osb = osb;
2075 atomic_set(&journal->j_num_trans, 0);
2076 init_rwsem(&journal->j_trans_barrier);
2077 init_waitqueue_head(&journal->j_checkpointed);
2078 spin_lock_init(&journal->j_lock);
2079 journal->j_trans_id = (unsigned long) 1;
2080 INIT_LIST_HEAD(&journal->j_la_cleanups);
2081 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
2082 journal->j_state = OCFS2_JOURNAL_FREE;
2084 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2085 osb->dentry_lock_list = NULL;
2087 /* get some pseudo constants for clustersize bits */
2088 osb->s_clustersize_bits =
2089 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2090 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2091 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2093 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2094 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2095 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2096 osb->s_clustersize);
2097 status = -EINVAL;
2098 goto bail;
2101 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2102 > (u32)~0UL) {
2103 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2104 "what jbd can address in 32 bits.\n");
2105 status = -EINVAL;
2106 goto bail;
2109 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2110 sizeof(di->id2.i_super.s_uuid))) {
2111 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2112 status = -ENOMEM;
2113 goto bail;
2116 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
2118 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2119 osb->vol_label[63] = '\0';
2120 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2121 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2122 osb->first_cluster_group_blkno =
2123 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2124 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
2125 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2126 mlog(0, "vol_label: %s\n", osb->vol_label);
2127 mlog(0, "uuid: %s\n", osb->uuid_str);
2128 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2129 (unsigned long long)osb->root_blkno,
2130 (unsigned long long)osb->system_dir_blkno);
2132 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2133 if (!osb->osb_dlm_debug) {
2134 status = -ENOMEM;
2135 mlog_errno(status);
2136 goto bail;
2139 atomic_set(&osb->vol_state, VOLUME_INIT);
2141 /* load root, system_dir, and all global system inodes */
2142 status = ocfs2_init_global_system_inodes(osb);
2143 if (status < 0) {
2144 mlog_errno(status);
2145 goto bail;
2149 * global bitmap
2151 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2152 OCFS2_INVALID_SLOT);
2153 if (!inode) {
2154 status = -EINVAL;
2155 mlog_errno(status);
2156 goto bail;
2159 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
2160 iput(inode);
2162 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
2164 status = ocfs2_init_slot_info(osb);
2165 if (status < 0) {
2166 mlog_errno(status);
2167 goto bail;
2170 bail:
2171 mlog_exit(status);
2172 return status;
2176 * will return: -EAGAIN if it is ok to keep searching for superblocks
2177 * -EINVAL if there is a bad superblock
2178 * 0 on success
2180 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2181 struct buffer_head *bh,
2182 u32 blksz)
2184 int status = -EAGAIN;
2186 mlog_entry_void();
2188 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2189 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
2190 /* We have to do a raw check of the feature here */
2191 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2192 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2193 status = ocfs2_block_check_validate(bh->b_data,
2194 bh->b_size,
2195 &di->i_check);
2196 if (status)
2197 goto out;
2199 status = -EINVAL;
2200 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2201 mlog(ML_ERROR, "found superblock with incorrect block "
2202 "size: found %u, should be %u\n",
2203 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2204 blksz);
2205 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2206 OCFS2_MAJOR_REV_LEVEL ||
2207 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2208 OCFS2_MINOR_REV_LEVEL) {
2209 mlog(ML_ERROR, "found superblock with bad version: "
2210 "found %u.%u, should be %u.%u\n",
2211 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2212 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2213 OCFS2_MAJOR_REV_LEVEL,
2214 OCFS2_MINOR_REV_LEVEL);
2215 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2216 mlog(ML_ERROR, "bad block number on superblock: "
2217 "found %llu, should be %llu\n",
2218 (unsigned long long)le64_to_cpu(di->i_blkno),
2219 (unsigned long long)bh->b_blocknr);
2220 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2221 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2222 mlog(ML_ERROR, "bad cluster size found: %u\n",
2223 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2224 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2225 mlog(ML_ERROR, "bad root_blkno: 0\n");
2226 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2227 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2228 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2229 mlog(ML_ERROR,
2230 "Superblock slots found greater than file system "
2231 "maximum: found %u, max %u\n",
2232 le16_to_cpu(di->id2.i_super.s_max_slots),
2233 OCFS2_MAX_SLOTS);
2234 } else {
2235 /* found it! */
2236 status = 0;
2240 out:
2241 mlog_exit(status);
2242 return status;
2245 static int ocfs2_check_volume(struct ocfs2_super *osb)
2247 int status;
2248 int dirty;
2249 int local;
2250 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2251 * recover
2252 * ourselves. */
2254 mlog_entry_void();
2256 /* Init our journal object. */
2257 status = ocfs2_journal_init(osb->journal, &dirty);
2258 if (status < 0) {
2259 mlog(ML_ERROR, "Could not initialize journal!\n");
2260 goto finally;
2263 /* If the journal was unmounted cleanly then we don't want to
2264 * recover anything. Otherwise, journal_load will do that
2265 * dirty work for us :) */
2266 if (!dirty) {
2267 status = ocfs2_journal_wipe(osb->journal, 0);
2268 if (status < 0) {
2269 mlog_errno(status);
2270 goto finally;
2272 } else {
2273 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2274 "recovering volume.\n");
2277 local = ocfs2_mount_local(osb);
2279 /* will play back anything left in the journal. */
2280 status = ocfs2_journal_load(osb->journal, local, dirty);
2281 if (status < 0) {
2282 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2283 goto finally;
2286 if (dirty) {
2287 /* recover my local alloc if we didn't unmount cleanly. */
2288 status = ocfs2_begin_local_alloc_recovery(osb,
2289 osb->slot_num,
2290 &local_alloc);
2291 if (status < 0) {
2292 mlog_errno(status);
2293 goto finally;
2295 /* we complete the recovery process after we've marked
2296 * ourselves as mounted. */
2299 mlog(0, "Journal loaded.\n");
2301 status = ocfs2_load_local_alloc(osb);
2302 if (status < 0) {
2303 mlog_errno(status);
2304 goto finally;
2307 if (dirty) {
2308 /* Recovery will be completed after we've mounted the
2309 * rest of the volume. */
2310 osb->dirty = 1;
2311 osb->local_alloc_copy = local_alloc;
2312 local_alloc = NULL;
2315 /* go through each journal, trylock it and if you get the
2316 * lock, and it's marked as dirty, set the bit in the recover
2317 * map and launch a recovery thread for it. */
2318 status = ocfs2_mark_dead_nodes(osb);
2319 if (status < 0) {
2320 mlog_errno(status);
2321 goto finally;
2324 status = ocfs2_compute_replay_slots(osb);
2325 if (status < 0)
2326 mlog_errno(status);
2328 finally:
2329 if (local_alloc)
2330 kfree(local_alloc);
2332 mlog_exit(status);
2333 return status;
2337 * The routine gets called from dismount or close whenever a dismount on
2338 * volume is requested and the osb open count becomes 1.
2339 * It will remove the osb from the global list and also free up all the
2340 * initialized resources and fileobject.
2342 static void ocfs2_delete_osb(struct ocfs2_super *osb)
2344 mlog_entry_void();
2346 /* This function assumes that the caller has the main osb resource */
2348 ocfs2_free_slot_info(osb);
2350 kfree(osb->osb_orphan_wipes);
2351 kfree(osb->slot_recovery_generations);
2352 /* FIXME
2353 * This belongs in journal shutdown, but because we have to
2354 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2355 * we free it here.
2357 kfree(osb->journal);
2358 if (osb->local_alloc_copy)
2359 kfree(osb->local_alloc_copy);
2360 kfree(osb->uuid_str);
2361 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2362 memset(osb, 0, sizeof(struct ocfs2_super));
2364 mlog_exit_void();
2367 /* Put OCFS2 into a readonly state, or (if the user specifies it),
2368 * panic(). We do not support continue-on-error operation. */
2369 static void ocfs2_handle_error(struct super_block *sb)
2371 struct ocfs2_super *osb = OCFS2_SB(sb);
2373 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2374 panic("OCFS2: (device %s): panic forced after error\n",
2375 sb->s_id);
2377 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2379 if (sb->s_flags & MS_RDONLY &&
2380 (ocfs2_is_soft_readonly(osb) ||
2381 ocfs2_is_hard_readonly(osb)))
2382 return;
2384 printk(KERN_CRIT "File system is now read-only due to the potential "
2385 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2386 "system is unmounted.\n");
2387 sb->s_flags |= MS_RDONLY;
2388 ocfs2_set_ro_flag(osb, 0);
2391 static char error_buf[1024];
2393 void __ocfs2_error(struct super_block *sb,
2394 const char *function,
2395 const char *fmt, ...)
2397 va_list args;
2399 va_start(args, fmt);
2400 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2401 va_end(args);
2403 /* Not using mlog here because we want to show the actual
2404 * function the error came from. */
2405 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2406 sb->s_id, function, error_buf);
2408 ocfs2_handle_error(sb);
2411 /* Handle critical errors. This is intentionally more drastic than
2412 * ocfs2_handle_error, so we only use for things like journal errors,
2413 * etc. */
2414 void __ocfs2_abort(struct super_block* sb,
2415 const char *function,
2416 const char *fmt, ...)
2418 va_list args;
2420 va_start(args, fmt);
2421 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2422 va_end(args);
2424 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2425 sb->s_id, function, error_buf);
2427 /* We don't have the cluster support yet to go straight to
2428 * hard readonly in here. Until then, we want to keep
2429 * ocfs2_abort() so that we can at least mark critical
2430 * errors.
2432 * TODO: This should abort the journal and alert other nodes
2433 * that our slot needs recovery. */
2435 /* Force a panic(). This stinks, but it's better than letting
2436 * things continue without having a proper hard readonly
2437 * here. */
2438 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
2439 ocfs2_handle_error(sb);
2442 module_init(ocfs2_init);
2443 module_exit(ocfs2_exit);