1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * load/unload driver, mount/dismount volumes
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
26 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h>
31 #include <linux/init.h>
32 #include <linux/random.h>
33 #include <linux/statfs.h>
34 #include <linux/moduleparam.h>
35 #include <linux/blkdev.h>
36 #include <linux/socket.h>
37 #include <linux/inet.h>
38 #include <linux/parser.h>
39 #include <linux/crc32.h>
40 #include <linux/debugfs.h>
41 #include <linux/mount.h>
42 #include <linux/seq_file.h>
43 #include <linux/quotaops.h>
44 #include <linux/smp_lock.h>
46 #define MLOG_MASK_PREFIX ML_SUPER
47 #include <cluster/masklog.h>
51 /* this should be the only file to include a version 1 header */
52 #include "ocfs1_fs_compat.h"
55 #include "blockcheck.h"
58 #include "extent_map.h"
59 #include "heartbeat.h"
62 #include "localalloc.h"
71 #include "refcounttree.h"
73 #include "buffer_head_io.h"
75 static struct kmem_cache
*ocfs2_inode_cachep
= NULL
;
76 struct kmem_cache
*ocfs2_dquot_cachep
;
77 struct kmem_cache
*ocfs2_qf_chunk_cachep
;
79 /* OCFS2 needs to schedule several differnt types of work which
80 * require cluster locking, disk I/O, recovery waits, etc. Since these
81 * types of work tend to be heavy we avoid using the kernel events
82 * workqueue and schedule on our own. */
83 struct workqueue_struct
*ocfs2_wq
= NULL
;
85 static struct dentry
*ocfs2_debugfs_root
= NULL
;
87 MODULE_AUTHOR("Oracle");
88 MODULE_LICENSE("GPL");
92 unsigned long commit_interval
;
93 unsigned long mount_opt
;
94 unsigned int atime_quantum
;
96 unsigned int localalloc_opt
;
97 char cluster_stack
[OCFS2_STACK_LABEL_LEN
+ 1];
100 static int ocfs2_parse_options(struct super_block
*sb
, char *options
,
101 struct mount_options
*mopt
,
103 static int ocfs2_show_options(struct seq_file
*s
, struct vfsmount
*mnt
);
104 static void ocfs2_put_super(struct super_block
*sb
);
105 static int ocfs2_mount_volume(struct super_block
*sb
);
106 static int ocfs2_remount(struct super_block
*sb
, int *flags
, char *data
);
107 static void ocfs2_dismount_volume(struct super_block
*sb
, int mnt_err
);
108 static int ocfs2_initialize_mem_caches(void);
109 static void ocfs2_free_mem_caches(void);
110 static void ocfs2_delete_osb(struct ocfs2_super
*osb
);
112 static int ocfs2_statfs(struct dentry
*dentry
, struct kstatfs
*buf
);
114 static int ocfs2_sync_fs(struct super_block
*sb
, int wait
);
116 static int ocfs2_init_global_system_inodes(struct ocfs2_super
*osb
);
117 static int ocfs2_init_local_system_inodes(struct ocfs2_super
*osb
);
118 static void ocfs2_release_system_inodes(struct ocfs2_super
*osb
);
119 static int ocfs2_check_volume(struct ocfs2_super
*osb
);
120 static int ocfs2_verify_volume(struct ocfs2_dinode
*di
,
121 struct buffer_head
*bh
,
123 struct ocfs2_blockcheck_stats
*stats
);
124 static int ocfs2_initialize_super(struct super_block
*sb
,
125 struct buffer_head
*bh
,
127 struct ocfs2_blockcheck_stats
*stats
);
128 static int ocfs2_get_sector(struct super_block
*sb
,
129 struct buffer_head
**bh
,
132 static struct inode
*ocfs2_alloc_inode(struct super_block
*sb
);
133 static void ocfs2_destroy_inode(struct inode
*inode
);
134 static int ocfs2_susp_quotas(struct ocfs2_super
*osb
, int unsuspend
);
135 static int ocfs2_enable_quotas(struct ocfs2_super
*osb
);
136 static void ocfs2_disable_quotas(struct ocfs2_super
*osb
);
138 static const struct super_operations ocfs2_sops
= {
139 .statfs
= ocfs2_statfs
,
140 .alloc_inode
= ocfs2_alloc_inode
,
141 .destroy_inode
= ocfs2_destroy_inode
,
142 .drop_inode
= ocfs2_drop_inode
,
143 .clear_inode
= ocfs2_clear_inode
,
144 .delete_inode
= ocfs2_delete_inode
,
145 .sync_fs
= ocfs2_sync_fs
,
146 .put_super
= ocfs2_put_super
,
147 .remount_fs
= ocfs2_remount
,
148 .show_options
= ocfs2_show_options
,
149 .quota_read
= ocfs2_quota_read
,
150 .quota_write
= ocfs2_quota_write
,
179 static const match_table_t tokens
= {
180 {Opt_barrier
, "barrier=%u"},
181 {Opt_err_panic
, "errors=panic"},
182 {Opt_err_ro
, "errors=remount-ro"},
184 {Opt_nointr
, "nointr"},
185 {Opt_hb_none
, OCFS2_HB_NONE
},
186 {Opt_hb_local
, OCFS2_HB_LOCAL
},
187 {Opt_data_ordered
, "data=ordered"},
188 {Opt_data_writeback
, "data=writeback"},
189 {Opt_atime_quantum
, "atime_quantum=%u"},
190 {Opt_slot
, "preferred_slot=%u"},
191 {Opt_commit
, "commit=%u"},
192 {Opt_localalloc
, "localalloc=%d"},
193 {Opt_localflocks
, "localflocks"},
194 {Opt_stack
, "cluster_stack=%s"},
195 {Opt_user_xattr
, "user_xattr"},
196 {Opt_nouser_xattr
, "nouser_xattr"},
197 {Opt_inode64
, "inode64"},
199 {Opt_noacl
, "noacl"},
200 {Opt_usrquota
, "usrquota"},
201 {Opt_grpquota
, "grpquota"},
205 #ifdef CONFIG_DEBUG_FS
206 static int ocfs2_osb_dump(struct ocfs2_super
*osb
, char *buf
, int len
)
208 struct ocfs2_cluster_connection
*cconn
= osb
->cconn
;
209 struct ocfs2_recovery_map
*rm
= osb
->recovery_map
;
210 struct ocfs2_orphan_scan
*os
= &osb
->osb_orphan_scan
;
213 out
+= snprintf(buf
+ out
, len
- out
,
214 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
215 "Device", osb
->dev_str
, osb
->uuid_str
,
216 osb
->fs_generation
, osb
->vol_label
);
218 out
+= snprintf(buf
+ out
, len
- out
,
219 "%10s => State: %d Flags: 0x%lX\n", "Volume",
220 atomic_read(&osb
->vol_state
), osb
->osb_flags
);
222 out
+= snprintf(buf
+ out
, len
- out
,
223 "%10s => Block: %lu Cluster: %d\n", "Sizes",
224 osb
->sb
->s_blocksize
, osb
->s_clustersize
);
226 out
+= snprintf(buf
+ out
, len
- out
,
227 "%10s => Compat: 0x%X Incompat: 0x%X "
229 "Features", osb
->s_feature_compat
,
230 osb
->s_feature_incompat
, osb
->s_feature_ro_compat
);
232 out
+= snprintf(buf
+ out
, len
- out
,
233 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
234 osb
->s_mount_opt
, osb
->s_atime_quantum
);
237 out
+= snprintf(buf
+ out
, len
- out
,
238 "%10s => Stack: %s Name: %*s "
239 "Version: %d.%d\n", "Cluster",
240 (*osb
->osb_cluster_stack
== '\0' ?
241 "o2cb" : osb
->osb_cluster_stack
),
242 cconn
->cc_namelen
, cconn
->cc_name
,
243 cconn
->cc_version
.pv_major
,
244 cconn
->cc_version
.pv_minor
);
247 spin_lock(&osb
->dc_task_lock
);
248 out
+= snprintf(buf
+ out
, len
- out
,
249 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
250 "WorkSeq: %lu\n", "DownCnvt",
251 (osb
->dc_task
? task_pid_nr(osb
->dc_task
) : -1),
252 osb
->blocked_lock_count
, osb
->dc_wake_sequence
,
253 osb
->dc_work_sequence
);
254 spin_unlock(&osb
->dc_task_lock
);
256 spin_lock(&osb
->osb_lock
);
257 out
+= snprintf(buf
+ out
, len
- out
, "%10s => Pid: %d Nodes:",
259 (osb
->recovery_thread_task
?
260 task_pid_nr(osb
->recovery_thread_task
) : -1));
261 if (rm
->rm_used
== 0)
262 out
+= snprintf(buf
+ out
, len
- out
, " None\n");
264 for (i
= 0; i
< rm
->rm_used
; i
++)
265 out
+= snprintf(buf
+ out
, len
- out
, " %d",
267 out
+= snprintf(buf
+ out
, len
- out
, "\n");
269 spin_unlock(&osb
->osb_lock
);
271 out
+= snprintf(buf
+ out
, len
- out
,
272 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
273 (osb
->commit_task
? task_pid_nr(osb
->commit_task
) : -1),
274 osb
->osb_commit_interval
,
275 atomic_read(&osb
->needs_checkpoint
));
277 out
+= snprintf(buf
+ out
, len
- out
,
278 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
279 "Journal", osb
->journal
->j_state
,
280 osb
->journal
->j_trans_id
,
281 atomic_read(&osb
->journal
->j_num_trans
));
283 out
+= snprintf(buf
+ out
, len
- out
,
284 "%10s => GlobalAllocs: %d LocalAllocs: %d "
285 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
287 atomic_read(&osb
->alloc_stats
.bitmap_data
),
288 atomic_read(&osb
->alloc_stats
.local_data
),
289 atomic_read(&osb
->alloc_stats
.bg_allocs
),
290 atomic_read(&osb
->alloc_stats
.moves
),
291 atomic_read(&osb
->alloc_stats
.bg_extends
));
293 out
+= snprintf(buf
+ out
, len
- out
,
294 "%10s => State: %u Descriptor: %llu Size: %u bits "
295 "Default: %u bits\n",
296 "LocalAlloc", osb
->local_alloc_state
,
297 (unsigned long long)osb
->la_last_gd
,
298 osb
->local_alloc_bits
, osb
->local_alloc_default_bits
);
300 spin_lock(&osb
->osb_lock
);
301 out
+= snprintf(buf
+ out
, len
- out
,
302 "%10s => Slot: %d NumStolen: %d\n", "Steal",
303 osb
->s_inode_steal_slot
,
304 atomic_read(&osb
->s_num_inodes_stolen
));
305 spin_unlock(&osb
->osb_lock
);
307 out
+= snprintf(buf
+ out
, len
- out
, "OrphanScan => ");
308 out
+= snprintf(buf
+ out
, len
- out
, "Local: %u Global: %u ",
309 os
->os_count
, os
->os_seqno
);
310 out
+= snprintf(buf
+ out
, len
- out
, " Last Scan: ");
311 if (atomic_read(&os
->os_state
) == ORPHAN_SCAN_INACTIVE
)
312 out
+= snprintf(buf
+ out
, len
- out
, "Disabled\n");
314 out
+= snprintf(buf
+ out
, len
- out
, "%lu seconds ago\n",
315 (get_seconds() - os
->os_scantime
.tv_sec
));
317 out
+= snprintf(buf
+ out
, len
- out
, "%10s => %3s %10s\n",
318 "Slots", "Num", "RecoGen");
319 for (i
= 0; i
< osb
->max_slots
; ++i
) {
320 out
+= snprintf(buf
+ out
, len
- out
,
321 "%10s %c %3d %10d\n",
323 (i
== osb
->slot_num
? '*' : ' '),
324 i
, osb
->slot_recovery_generations
[i
]);
330 static int ocfs2_osb_debug_open(struct inode
*inode
, struct file
*file
)
332 struct ocfs2_super
*osb
= inode
->i_private
;
335 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
339 i_size_write(inode
, ocfs2_osb_dump(osb
, buf
, PAGE_SIZE
));
341 file
->private_data
= buf
;
348 static int ocfs2_debug_release(struct inode
*inode
, struct file
*file
)
350 kfree(file
->private_data
);
354 static ssize_t
ocfs2_debug_read(struct file
*file
, char __user
*buf
,
355 size_t nbytes
, loff_t
*ppos
)
357 return simple_read_from_buffer(buf
, nbytes
, ppos
, file
->private_data
,
358 i_size_read(file
->f_mapping
->host
));
361 static int ocfs2_osb_debug_open(struct inode
*inode
, struct file
*file
)
365 static int ocfs2_debug_release(struct inode
*inode
, struct file
*file
)
369 static ssize_t
ocfs2_debug_read(struct file
*file
, char __user
*buf
,
370 size_t nbytes
, loff_t
*ppos
)
374 #endif /* CONFIG_DEBUG_FS */
376 static const struct file_operations ocfs2_osb_debug_fops
= {
377 .open
= ocfs2_osb_debug_open
,
378 .release
= ocfs2_debug_release
,
379 .read
= ocfs2_debug_read
,
380 .llseek
= generic_file_llseek
,
383 static int ocfs2_sync_fs(struct super_block
*sb
, int wait
)
387 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
389 if (ocfs2_is_hard_readonly(osb
))
393 status
= ocfs2_flush_truncate_log(osb
);
397 ocfs2_schedule_truncate_log_flush(osb
, 0);
400 if (jbd2_journal_start_commit(OCFS2_SB(sb
)->journal
->j_journal
,
403 jbd2_log_wait_commit(OCFS2_SB(sb
)->journal
->j_journal
,
409 static int ocfs2_need_system_inode(struct ocfs2_super
*osb
, int ino
)
411 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb
->sb
, OCFS2_FEATURE_RO_COMPAT_USRQUOTA
)
412 && (ino
== USER_QUOTA_SYSTEM_INODE
413 || ino
== LOCAL_USER_QUOTA_SYSTEM_INODE
))
415 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb
->sb
, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
)
416 && (ino
== GROUP_QUOTA_SYSTEM_INODE
417 || ino
== LOCAL_GROUP_QUOTA_SYSTEM_INODE
))
422 static int ocfs2_init_global_system_inodes(struct ocfs2_super
*osb
)
424 struct inode
*new = NULL
;
430 new = ocfs2_iget(osb
, osb
->root_blkno
, OCFS2_FI_FLAG_SYSFILE
, 0);
432 status
= PTR_ERR(new);
436 osb
->root_inode
= new;
438 new = ocfs2_iget(osb
, osb
->system_dir_blkno
, OCFS2_FI_FLAG_SYSFILE
, 0);
440 status
= PTR_ERR(new);
444 osb
->sys_root_inode
= new;
446 for (i
= OCFS2_FIRST_ONLINE_SYSTEM_INODE
;
447 i
<= OCFS2_LAST_GLOBAL_SYSTEM_INODE
; i
++) {
448 if (!ocfs2_need_system_inode(osb
, i
))
450 new = ocfs2_get_system_file_inode(osb
, i
, osb
->slot_num
);
452 ocfs2_release_system_inodes(osb
);
455 /* FIXME: Should ERROR_RO_FS */
456 mlog(ML_ERROR
, "Unable to load system inode %d, "
457 "possibly corrupt fs?", i
);
460 // the array now has one ref, so drop this one
469 static int ocfs2_init_local_system_inodes(struct ocfs2_super
*osb
)
471 struct inode
*new = NULL
;
477 for (i
= OCFS2_LAST_GLOBAL_SYSTEM_INODE
+ 1;
478 i
< NUM_SYSTEM_INODES
;
480 if (!ocfs2_need_system_inode(osb
, i
))
482 new = ocfs2_get_system_file_inode(osb
, i
, osb
->slot_num
);
484 ocfs2_release_system_inodes(osb
);
486 mlog(ML_ERROR
, "status=%d, sysfile=%d, slot=%d\n",
487 status
, i
, osb
->slot_num
);
490 /* the array now has one ref, so drop this one */
499 static void ocfs2_release_system_inodes(struct ocfs2_super
*osb
)
506 for (i
= 0; i
< NUM_SYSTEM_INODES
; i
++) {
507 inode
= osb
->system_inodes
[i
];
510 osb
->system_inodes
[i
] = NULL
;
514 inode
= osb
->sys_root_inode
;
517 osb
->sys_root_inode
= NULL
;
520 inode
= osb
->root_inode
;
523 osb
->root_inode
= NULL
;
529 /* We're allocating fs objects, use GFP_NOFS */
530 static struct inode
*ocfs2_alloc_inode(struct super_block
*sb
)
532 struct ocfs2_inode_info
*oi
;
534 oi
= kmem_cache_alloc(ocfs2_inode_cachep
, GFP_NOFS
);
538 jbd2_journal_init_jbd_inode(&oi
->ip_jinode
, &oi
->vfs_inode
);
539 return &oi
->vfs_inode
;
542 static void ocfs2_destroy_inode(struct inode
*inode
)
544 kmem_cache_free(ocfs2_inode_cachep
, OCFS2_I(inode
));
547 static unsigned long long ocfs2_max_file_offset(unsigned int bbits
,
550 unsigned int bytes
= 1 << cbits
;
551 unsigned int trim
= bytes
;
552 unsigned int bitshift
= 32;
555 * i_size and all block offsets in ocfs2 are always 64 bits
556 * wide. i_clusters is 32 bits, in cluster-sized units. So on
557 * 64 bit platforms, cluster size will be the limiting factor.
560 #if BITS_PER_LONG == 32
561 # if defined(CONFIG_LBDAF)
562 BUILD_BUG_ON(sizeof(sector_t
) != 8);
564 * We might be limited by page cache size.
566 if (bytes
> PAGE_CACHE_SIZE
) {
567 bytes
= PAGE_CACHE_SIZE
;
570 * Shift by 31 here so that we don't get larger than
577 * We are limited by the size of sector_t. Use block size, as
578 * that's what we expose to the VFS.
587 * Trim by a whole cluster when we can actually approach the
588 * on-disk limits. Otherwise we can overflow i_clusters when
589 * an extent start is at the max offset.
591 return (((unsigned long long)bytes
) << bitshift
) - trim
;
594 static int ocfs2_remount(struct super_block
*sb
, int *flags
, char *data
)
596 int incompat_features
;
598 struct mount_options parsed_options
;
599 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
603 if (!ocfs2_parse_options(sb
, data
, &parsed_options
, 1)) {
608 if ((osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
) !=
609 (parsed_options
.mount_opt
& OCFS2_MOUNT_HB_LOCAL
)) {
611 mlog(ML_ERROR
, "Cannot change heartbeat mode on remount\n");
615 if ((osb
->s_mount_opt
& OCFS2_MOUNT_DATA_WRITEBACK
) !=
616 (parsed_options
.mount_opt
& OCFS2_MOUNT_DATA_WRITEBACK
)) {
618 mlog(ML_ERROR
, "Cannot change data mode on remount\n");
622 /* Probably don't want this on remount; it might
623 * mess with other nodes */
624 if (!(osb
->s_mount_opt
& OCFS2_MOUNT_INODE64
) &&
625 (parsed_options
.mount_opt
& OCFS2_MOUNT_INODE64
)) {
627 mlog(ML_ERROR
, "Cannot enable inode64 on remount\n");
631 /* We're going to/from readonly mode. */
632 if ((*flags
& MS_RDONLY
) != (sb
->s_flags
& MS_RDONLY
)) {
633 /* Disable quota accounting before remounting RO */
634 if (*flags
& MS_RDONLY
) {
635 ret
= ocfs2_susp_quotas(osb
, 0);
639 /* Lock here so the check of HARD_RO and the potential
640 * setting of SOFT_RO is atomic. */
641 spin_lock(&osb
->osb_lock
);
642 if (osb
->osb_flags
& OCFS2_OSB_HARD_RO
) {
643 mlog(ML_ERROR
, "Remount on readonly device is forbidden.\n");
648 if (*flags
& MS_RDONLY
) {
649 mlog(0, "Going to ro mode.\n");
650 sb
->s_flags
|= MS_RDONLY
;
651 osb
->osb_flags
|= OCFS2_OSB_SOFT_RO
;
653 mlog(0, "Making ro filesystem writeable.\n");
655 if (osb
->osb_flags
& OCFS2_OSB_ERROR_FS
) {
656 mlog(ML_ERROR
, "Cannot remount RDWR "
657 "filesystem due to previous errors.\n");
661 incompat_features
= OCFS2_HAS_RO_COMPAT_FEATURE(sb
, ~OCFS2_FEATURE_RO_COMPAT_SUPP
);
662 if (incompat_features
) {
663 mlog(ML_ERROR
, "Cannot remount RDWR because "
664 "of unsupported optional features "
665 "(%x).\n", incompat_features
);
669 sb
->s_flags
&= ~MS_RDONLY
;
670 osb
->osb_flags
&= ~OCFS2_OSB_SOFT_RO
;
673 spin_unlock(&osb
->osb_lock
);
674 /* Enable quota accounting after remounting RW */
675 if (!ret
&& !(*flags
& MS_RDONLY
)) {
676 if (sb_any_quota_suspended(sb
))
677 ret
= ocfs2_susp_quotas(osb
, 1);
679 ret
= ocfs2_enable_quotas(osb
);
681 /* Return back changes... */
682 spin_lock(&osb
->osb_lock
);
683 sb
->s_flags
|= MS_RDONLY
;
684 osb
->osb_flags
|= OCFS2_OSB_SOFT_RO
;
685 spin_unlock(&osb
->osb_lock
);
692 /* Only save off the new mount options in case of a successful
694 if (!(osb
->s_feature_incompat
& OCFS2_FEATURE_INCOMPAT_XATTR
))
695 parsed_options
.mount_opt
&= ~OCFS2_MOUNT_POSIX_ACL
;
696 osb
->s_mount_opt
= parsed_options
.mount_opt
;
697 osb
->s_atime_quantum
= parsed_options
.atime_quantum
;
698 osb
->preferred_slot
= parsed_options
.slot
;
699 if (parsed_options
.commit_interval
)
700 osb
->osb_commit_interval
= parsed_options
.commit_interval
;
702 if (!ocfs2_is_hard_readonly(osb
))
703 ocfs2_set_journal_params(osb
);
710 static int ocfs2_sb_probe(struct super_block
*sb
,
711 struct buffer_head
**bh
,
713 struct ocfs2_blockcheck_stats
*stats
)
716 struct ocfs1_vol_disk_hdr
*hdr
;
717 struct ocfs2_dinode
*di
;
723 *sector_size
= bdev_logical_block_size(sb
->s_bdev
);
724 if (*sector_size
> OCFS2_MAX_BLOCKSIZE
) {
725 mlog(ML_ERROR
, "Hardware sector size too large: %d (max=%d)\n",
726 *sector_size
, OCFS2_MAX_BLOCKSIZE
);
731 /* Can this really happen? */
732 if (*sector_size
< OCFS2_MIN_BLOCKSIZE
)
733 *sector_size
= OCFS2_MIN_BLOCKSIZE
;
735 /* check block zero for old format */
736 status
= ocfs2_get_sector(sb
, bh
, 0, *sector_size
);
741 hdr
= (struct ocfs1_vol_disk_hdr
*) (*bh
)->b_data
;
742 if (hdr
->major_version
== OCFS1_MAJOR_VERSION
) {
743 mlog(ML_ERROR
, "incompatible version: %u.%u\n",
744 hdr
->major_version
, hdr
->minor_version
);
747 if (memcmp(hdr
->signature
, OCFS1_VOLUME_SIGNATURE
,
748 strlen(OCFS1_VOLUME_SIGNATURE
)) == 0) {
749 mlog(ML_ERROR
, "incompatible volume signature: %8s\n",
756 mlog(ML_ERROR
, "This is an ocfs v1 filesystem which must be "
757 "upgraded before mounting with ocfs v2\n");
762 * Now check at magic offset for 512, 1024, 2048, 4096
763 * blocksizes. 4096 is the maximum blocksize because it is
764 * the minimum clustersize.
767 for (blksize
= *sector_size
;
768 blksize
<= OCFS2_MAX_BLOCKSIZE
;
770 tmpstat
= ocfs2_get_sector(sb
, bh
,
771 OCFS2_SUPER_BLOCK_BLKNO
,
778 di
= (struct ocfs2_dinode
*) (*bh
)->b_data
;
779 memset(stats
, 0, sizeof(struct ocfs2_blockcheck_stats
));
780 spin_lock_init(&stats
->b_lock
);
781 tmpstat
= ocfs2_verify_volume(di
, *bh
, blksize
, stats
);
786 if (tmpstat
!= -EAGAIN
) {
796 static int ocfs2_verify_heartbeat(struct ocfs2_super
*osb
)
798 if (ocfs2_mount_local(osb
)) {
799 if (osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
) {
800 mlog(ML_ERROR
, "Cannot heartbeat on a locally "
801 "mounted device.\n");
806 if (ocfs2_userspace_stack(osb
)) {
807 if (osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
) {
808 mlog(ML_ERROR
, "Userspace stack expected, but "
809 "o2cb heartbeat arguments passed to mount\n");
814 if (!(osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
)) {
815 if (!ocfs2_mount_local(osb
) && !ocfs2_is_hard_readonly(osb
) &&
816 !ocfs2_userspace_stack(osb
)) {
817 mlog(ML_ERROR
, "Heartbeat has to be started to mount "
818 "a read-write clustered device.\n");
827 * If we're using a userspace stack, mount should have passed
828 * a name that matches the disk. If not, mount should not
829 * have passed a stack.
831 static int ocfs2_verify_userspace_stack(struct ocfs2_super
*osb
,
832 struct mount_options
*mopt
)
834 if (!ocfs2_userspace_stack(osb
) && mopt
->cluster_stack
[0]) {
836 "cluster stack passed to mount, but this filesystem "
837 "does not support it\n");
841 if (ocfs2_userspace_stack(osb
) &&
842 strncmp(osb
->osb_cluster_stack
, mopt
->cluster_stack
,
843 OCFS2_STACK_LABEL_LEN
)) {
845 "cluster stack passed to mount (\"%s\") does not "
846 "match the filesystem (\"%s\")\n",
848 osb
->osb_cluster_stack
);
855 static int ocfs2_susp_quotas(struct ocfs2_super
*osb
, int unsuspend
)
858 struct super_block
*sb
= osb
->sb
;
859 unsigned int feature
[MAXQUOTAS
] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA
,
860 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
};
863 for (type
= 0; type
< MAXQUOTAS
; type
++) {
864 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb
, feature
[type
]))
867 status
= vfs_quota_enable(
868 sb_dqopt(sb
)->files
[type
],
872 status
= vfs_quota_disable(sb
, type
,
878 mlog(ML_ERROR
, "Failed to suspend/unsuspend quotas on "
879 "remount (error = %d).\n", status
);
883 static int ocfs2_enable_quotas(struct ocfs2_super
*osb
)
885 struct inode
*inode
[MAXQUOTAS
] = { NULL
, NULL
};
886 struct super_block
*sb
= osb
->sb
;
887 unsigned int feature
[MAXQUOTAS
] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA
,
888 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
};
889 unsigned int ino
[MAXQUOTAS
] = { LOCAL_USER_QUOTA_SYSTEM_INODE
,
890 LOCAL_GROUP_QUOTA_SYSTEM_INODE
};
894 sb_dqopt(sb
)->flags
|= DQUOT_QUOTA_SYS_FILE
| DQUOT_NEGATIVE_USAGE
;
895 for (type
= 0; type
< MAXQUOTAS
; type
++) {
896 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb
, feature
[type
]))
898 inode
[type
] = ocfs2_get_system_file_inode(osb
, ino
[type
],
904 status
= vfs_quota_enable(inode
[type
], type
, QFMT_OCFS2
,
905 DQUOT_USAGE_ENABLED
);
910 for (type
= 0; type
< MAXQUOTAS
; type
++)
914 ocfs2_disable_quotas(osb
);
915 for (type
= 0; type
< MAXQUOTAS
; type
++)
921 static void ocfs2_disable_quotas(struct ocfs2_super
*osb
)
925 struct super_block
*sb
= osb
->sb
;
927 /* We mostly ignore errors in this function because there's not much
928 * we can do when we see them */
929 for (type
= 0; type
< MAXQUOTAS
; type
++) {
930 if (!sb_has_quota_loaded(sb
, type
))
932 inode
= igrab(sb
->s_dquot
.files
[type
]);
933 /* Turn off quotas. This will remove all dquot structures from
934 * memory and so they will be automatically synced to global
936 vfs_quota_disable(sb
, type
, DQUOT_USAGE_ENABLED
|
937 DQUOT_LIMITS_ENABLED
);
944 /* Handle quota on quotactl */
945 static int ocfs2_quota_on(struct super_block
*sb
, int type
, int format_id
,
946 char *path
, int remount
)
948 unsigned int feature
[MAXQUOTAS
] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA
,
949 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
};
951 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb
, feature
[type
]))
955 return 0; /* Just ignore it has been handled in
957 return vfs_quota_enable(sb_dqopt(sb
)->files
[type
], type
,
958 format_id
, DQUOT_LIMITS_ENABLED
);
961 /* Handle quota off quotactl */
962 static int ocfs2_quota_off(struct super_block
*sb
, int type
, int remount
)
965 return 0; /* Ignore now and handle later in
967 return vfs_quota_disable(sb
, type
, DQUOT_LIMITS_ENABLED
);
970 static const struct quotactl_ops ocfs2_quotactl_ops
= {
971 .quota_on
= ocfs2_quota_on
,
972 .quota_off
= ocfs2_quota_off
,
973 .quota_sync
= vfs_quota_sync
,
974 .get_info
= vfs_get_dqinfo
,
975 .set_info
= vfs_set_dqinfo
,
976 .get_dqblk
= vfs_get_dqblk
,
977 .set_dqblk
= vfs_set_dqblk
,
980 static int ocfs2_fill_super(struct super_block
*sb
, void *data
, int silent
)
983 int status
, sector_size
;
984 struct mount_options parsed_options
;
985 struct inode
*inode
= NULL
;
986 struct ocfs2_super
*osb
= NULL
;
987 struct buffer_head
*bh
= NULL
;
989 struct ocfs2_blockcheck_stats stats
;
991 mlog_entry("%p, %p, %i", sb
, data
, silent
);
993 if (!ocfs2_parse_options(sb
, data
, &parsed_options
, 0)) {
995 goto read_super_error
;
998 /* probe for superblock */
999 status
= ocfs2_sb_probe(sb
, &bh
, §or_size
, &stats
);
1001 mlog(ML_ERROR
, "superblock probe failed!\n");
1002 goto read_super_error
;
1005 status
= ocfs2_initialize_super(sb
, bh
, sector_size
, &stats
);
1009 goto read_super_error
;
1014 if (!(osb
->s_feature_incompat
& OCFS2_FEATURE_INCOMPAT_XATTR
))
1015 parsed_options
.mount_opt
&= ~OCFS2_MOUNT_POSIX_ACL
;
1017 osb
->s_mount_opt
= parsed_options
.mount_opt
;
1018 osb
->s_atime_quantum
= parsed_options
.atime_quantum
;
1019 osb
->preferred_slot
= parsed_options
.slot
;
1020 osb
->osb_commit_interval
= parsed_options
.commit_interval
;
1021 osb
->local_alloc_default_bits
= ocfs2_megabytes_to_clusters(sb
, parsed_options
.localalloc_opt
);
1022 osb
->local_alloc_bits
= osb
->local_alloc_default_bits
;
1023 if (osb
->s_mount_opt
& OCFS2_MOUNT_USRQUOTA
&&
1024 !OCFS2_HAS_RO_COMPAT_FEATURE(sb
,
1025 OCFS2_FEATURE_RO_COMPAT_USRQUOTA
)) {
1027 mlog(ML_ERROR
, "User quotas were requested, but this "
1028 "filesystem does not have the feature enabled.\n");
1029 goto read_super_error
;
1031 if (osb
->s_mount_opt
& OCFS2_MOUNT_GRPQUOTA
&&
1032 !OCFS2_HAS_RO_COMPAT_FEATURE(sb
,
1033 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
)) {
1035 mlog(ML_ERROR
, "Group quotas were requested, but this "
1036 "filesystem does not have the feature enabled.\n");
1037 goto read_super_error
;
1040 status
= ocfs2_verify_userspace_stack(osb
, &parsed_options
);
1042 goto read_super_error
;
1044 sb
->s_magic
= OCFS2_SUPER_MAGIC
;
1046 sb
->s_flags
= (sb
->s_flags
& ~MS_POSIXACL
) |
1047 ((osb
->s_mount_opt
& OCFS2_MOUNT_POSIX_ACL
) ? MS_POSIXACL
: 0);
1049 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1051 if (bdev_read_only(sb
->s_bdev
)) {
1052 if (!(sb
->s_flags
& MS_RDONLY
)) {
1054 mlog(ML_ERROR
, "Readonly device detected but readonly "
1055 "mount was not specified.\n");
1056 goto read_super_error
;
1059 /* You should not be able to start a local heartbeat
1060 * on a readonly device. */
1061 if (osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
) {
1063 mlog(ML_ERROR
, "Local heartbeat specified on readonly "
1065 goto read_super_error
;
1068 status
= ocfs2_check_journals_nolocks(osb
);
1070 if (status
== -EROFS
)
1071 mlog(ML_ERROR
, "Recovery required on readonly "
1072 "file system, but write access is "
1076 goto read_super_error
;
1079 ocfs2_set_ro_flag(osb
, 1);
1081 printk(KERN_NOTICE
"Readonly device detected. No cluster "
1082 "services will be utilized for this mount. Recovery "
1083 "will be skipped.\n");
1086 if (!ocfs2_is_hard_readonly(osb
)) {
1087 if (sb
->s_flags
& MS_RDONLY
)
1088 ocfs2_set_ro_flag(osb
, 0);
1091 status
= ocfs2_verify_heartbeat(osb
);
1094 goto read_super_error
;
1097 osb
->osb_debug_root
= debugfs_create_dir(osb
->uuid_str
,
1098 ocfs2_debugfs_root
);
1099 if (!osb
->osb_debug_root
) {
1101 mlog(ML_ERROR
, "Unable to create per-mount debugfs root.\n");
1102 goto read_super_error
;
1105 osb
->osb_ctxt
= debugfs_create_file("fs_state", S_IFREG
|S_IRUSR
,
1106 osb
->osb_debug_root
,
1108 &ocfs2_osb_debug_fops
);
1109 if (!osb
->osb_ctxt
) {
1112 goto read_super_error
;
1115 if (ocfs2_meta_ecc(osb
)) {
1116 status
= ocfs2_blockcheck_stats_debugfs_install(
1117 &osb
->osb_ecc_stats
,
1118 osb
->osb_debug_root
);
1121 "Unable to create blockcheck statistics "
1123 goto read_super_error
;
1127 status
= ocfs2_mount_volume(sb
);
1128 if (osb
->root_inode
)
1129 inode
= igrab(osb
->root_inode
);
1132 goto read_super_error
;
1137 goto read_super_error
;
1140 root
= d_alloc_root(inode
);
1144 goto read_super_error
;
1149 ocfs2_complete_mount_recovery(osb
);
1151 if (ocfs2_mount_local(osb
))
1152 snprintf(nodestr
, sizeof(nodestr
), "local");
1154 snprintf(nodestr
, sizeof(nodestr
), "%u", osb
->node_num
);
1156 printk(KERN_INFO
"ocfs2: Mounting device (%s) on (node %s, slot %d) "
1157 "with %s data mode.\n",
1158 osb
->dev_str
, nodestr
, osb
->slot_num
,
1159 osb
->s_mount_opt
& OCFS2_MOUNT_DATA_WRITEBACK
? "writeback" :
1162 atomic_set(&osb
->vol_state
, VOLUME_MOUNTED
);
1163 wake_up(&osb
->osb_mount_event
);
1165 /* Now we can initialize quotas because we can afford to wait
1166 * for cluster locks recovery now. That also means that truncation
1167 * log recovery can happen but that waits for proper quota setup */
1168 if (!(sb
->s_flags
& MS_RDONLY
)) {
1169 status
= ocfs2_enable_quotas(osb
);
1171 /* We have to err-out specially here because
1172 * s_root is already set */
1174 atomic_set(&osb
->vol_state
, VOLUME_DISABLED
);
1175 wake_up(&osb
->osb_mount_event
);
1181 ocfs2_complete_quota_recovery(osb
);
1183 /* Now we wake up again for processes waiting for quotas */
1184 atomic_set(&osb
->vol_state
, VOLUME_MOUNTED_QUOTAS
);
1185 wake_up(&osb
->osb_mount_event
);
1187 /* Start this when the mount is almost sure of being successful */
1188 ocfs2_orphan_scan_start(osb
);
1200 atomic_set(&osb
->vol_state
, VOLUME_DISABLED
);
1201 wake_up(&osb
->osb_mount_event
);
1202 ocfs2_dismount_volume(sb
, 1);
1209 static int ocfs2_get_sb(struct file_system_type
*fs_type
,
1211 const char *dev_name
,
1213 struct vfsmount
*mnt
)
1215 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, ocfs2_fill_super
,
1219 static void ocfs2_kill_sb(struct super_block
*sb
)
1221 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
1224 if (!osb
|| atomic_read(&osb
->vol_state
) == VOLUME_DISABLED
)
1227 /* Prevent further queueing of inode drop events */
1228 spin_lock(&dentry_list_lock
);
1229 ocfs2_set_osb_flag(osb
, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED
);
1230 spin_unlock(&dentry_list_lock
);
1231 /* Wait for work to finish and/or remove it */
1232 cancel_work_sync(&osb
->dentry_lock_work
);
1234 kill_block_super(sb
);
1237 static struct file_system_type ocfs2_fs_type
= {
1238 .owner
= THIS_MODULE
,
1240 .get_sb
= ocfs2_get_sb
, /* is this called when we mount
1242 .kill_sb
= ocfs2_kill_sb
,
1244 .fs_flags
= FS_REQUIRES_DEV
|FS_RENAME_DOES_D_MOVE
,
1248 static int ocfs2_parse_options(struct super_block
*sb
,
1250 struct mount_options
*mopt
,
1256 mlog_entry("remount: %d, options: \"%s\"\n", is_remount
,
1257 options
? options
: "(none)");
1259 mopt
->commit_interval
= 0;
1260 mopt
->mount_opt
= 0;
1261 mopt
->atime_quantum
= OCFS2_DEFAULT_ATIME_QUANTUM
;
1262 mopt
->slot
= OCFS2_INVALID_SLOT
;
1263 mopt
->localalloc_opt
= OCFS2_DEFAULT_LOCAL_ALLOC_SIZE
;
1264 mopt
->cluster_stack
[0] = '\0';
1271 while ((p
= strsep(&options
, ",")) != NULL
) {
1273 substring_t args
[MAX_OPT_ARGS
];
1278 token
= match_token(p
, tokens
, args
);
1281 mopt
->mount_opt
|= OCFS2_MOUNT_HB_LOCAL
;
1284 mopt
->mount_opt
&= ~OCFS2_MOUNT_HB_LOCAL
;
1287 if (match_int(&args
[0], &option
)) {
1292 mopt
->mount_opt
|= OCFS2_MOUNT_BARRIER
;
1294 mopt
->mount_opt
&= ~OCFS2_MOUNT_BARRIER
;
1297 mopt
->mount_opt
&= ~OCFS2_MOUNT_NOINTR
;
1300 mopt
->mount_opt
|= OCFS2_MOUNT_NOINTR
;
1303 mopt
->mount_opt
|= OCFS2_MOUNT_ERRORS_PANIC
;
1306 mopt
->mount_opt
&= ~OCFS2_MOUNT_ERRORS_PANIC
;
1308 case Opt_data_ordered
:
1309 mopt
->mount_opt
&= ~OCFS2_MOUNT_DATA_WRITEBACK
;
1311 case Opt_data_writeback
:
1312 mopt
->mount_opt
|= OCFS2_MOUNT_DATA_WRITEBACK
;
1314 case Opt_user_xattr
:
1315 mopt
->mount_opt
&= ~OCFS2_MOUNT_NOUSERXATTR
;
1317 case Opt_nouser_xattr
:
1318 mopt
->mount_opt
|= OCFS2_MOUNT_NOUSERXATTR
;
1320 case Opt_atime_quantum
:
1321 if (match_int(&args
[0], &option
)) {
1326 mopt
->atime_quantum
= option
;
1330 if (match_int(&args
[0], &option
)) {
1335 mopt
->slot
= (s16
)option
;
1339 if (match_int(&args
[0], &option
)) {
1346 option
= JBD2_DEFAULT_MAX_COMMIT_AGE
;
1347 mopt
->commit_interval
= HZ
* option
;
1349 case Opt_localalloc
:
1351 if (match_int(&args
[0], &option
)) {
1355 if (option
>= 0 && (option
<= ocfs2_local_alloc_size(sb
) * 8))
1356 mopt
->localalloc_opt
= option
;
1358 case Opt_localflocks
:
1360 * Changing this during remount could race
1361 * flock() requests, or "unbalance" existing
1362 * ones (e.g., a lock is taken in one mode but
1363 * dropped in the other). If users care enough
1364 * to flip locking modes during remount, we
1365 * could add a "local" flag to individual
1366 * flock structures for proper tracking of
1370 mopt
->mount_opt
|= OCFS2_MOUNT_LOCALFLOCKS
;
1373 /* Check both that the option we were passed
1374 * is of the right length and that it is a proper
1375 * string of the right length.
1377 if (((args
[0].to
- args
[0].from
) !=
1378 OCFS2_STACK_LABEL_LEN
) ||
1379 (strnlen(args
[0].from
,
1380 OCFS2_STACK_LABEL_LEN
) !=
1381 OCFS2_STACK_LABEL_LEN
)) {
1383 "Invalid cluster_stack option\n");
1387 memcpy(mopt
->cluster_stack
, args
[0].from
,
1388 OCFS2_STACK_LABEL_LEN
);
1389 mopt
->cluster_stack
[OCFS2_STACK_LABEL_LEN
] = '\0';
1392 mopt
->mount_opt
|= OCFS2_MOUNT_INODE64
;
1395 /* We check only on remount, otherwise features
1396 * aren't yet initialized. */
1397 if (is_remount
&& !OCFS2_HAS_RO_COMPAT_FEATURE(sb
,
1398 OCFS2_FEATURE_RO_COMPAT_USRQUOTA
)) {
1399 mlog(ML_ERROR
, "User quota requested but "
1400 "filesystem feature is not set\n");
1404 mopt
->mount_opt
|= OCFS2_MOUNT_USRQUOTA
;
1407 if (is_remount
&& !OCFS2_HAS_RO_COMPAT_FEATURE(sb
,
1408 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
)) {
1409 mlog(ML_ERROR
, "Group quota requested but "
1410 "filesystem feature is not set\n");
1414 mopt
->mount_opt
|= OCFS2_MOUNT_GRPQUOTA
;
1416 #ifdef CONFIG_OCFS2_FS_POSIX_ACL
1418 mopt
->mount_opt
|= OCFS2_MOUNT_POSIX_ACL
;
1421 mopt
->mount_opt
&= ~OCFS2_MOUNT_POSIX_ACL
;
1426 printk(KERN_INFO
"ocfs2 (no)acl options not supported\n");
1431 "Unrecognized mount option \"%s\" "
1432 "or missing value\n", p
);
1445 static int ocfs2_show_options(struct seq_file
*s
, struct vfsmount
*mnt
)
1447 struct ocfs2_super
*osb
= OCFS2_SB(mnt
->mnt_sb
);
1448 unsigned long opts
= osb
->s_mount_opt
;
1449 unsigned int local_alloc_megs
;
1451 if (opts
& OCFS2_MOUNT_HB_LOCAL
)
1452 seq_printf(s
, ",_netdev,heartbeat=local");
1454 seq_printf(s
, ",heartbeat=none");
1456 if (opts
& OCFS2_MOUNT_NOINTR
)
1457 seq_printf(s
, ",nointr");
1459 if (opts
& OCFS2_MOUNT_DATA_WRITEBACK
)
1460 seq_printf(s
, ",data=writeback");
1462 seq_printf(s
, ",data=ordered");
1464 if (opts
& OCFS2_MOUNT_BARRIER
)
1465 seq_printf(s
, ",barrier=1");
1467 if (opts
& OCFS2_MOUNT_ERRORS_PANIC
)
1468 seq_printf(s
, ",errors=panic");
1470 seq_printf(s
, ",errors=remount-ro");
1472 if (osb
->preferred_slot
!= OCFS2_INVALID_SLOT
)
1473 seq_printf(s
, ",preferred_slot=%d", osb
->preferred_slot
);
1475 if (osb
->s_atime_quantum
!= OCFS2_DEFAULT_ATIME_QUANTUM
)
1476 seq_printf(s
, ",atime_quantum=%u", osb
->s_atime_quantum
);
1478 if (osb
->osb_commit_interval
)
1479 seq_printf(s
, ",commit=%u",
1480 (unsigned) (osb
->osb_commit_interval
/ HZ
));
1482 local_alloc_megs
= osb
->local_alloc_bits
>> (20 - osb
->s_clustersize_bits
);
1483 if (local_alloc_megs
!= OCFS2_DEFAULT_LOCAL_ALLOC_SIZE
)
1484 seq_printf(s
, ",localalloc=%d", local_alloc_megs
);
1486 if (opts
& OCFS2_MOUNT_LOCALFLOCKS
)
1487 seq_printf(s
, ",localflocks,");
1489 if (osb
->osb_cluster_stack
[0])
1490 seq_printf(s
, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN
,
1491 osb
->osb_cluster_stack
);
1492 if (opts
& OCFS2_MOUNT_USRQUOTA
)
1493 seq_printf(s
, ",usrquota");
1494 if (opts
& OCFS2_MOUNT_GRPQUOTA
)
1495 seq_printf(s
, ",grpquota");
1497 if (opts
& OCFS2_MOUNT_NOUSERXATTR
)
1498 seq_printf(s
, ",nouser_xattr");
1500 seq_printf(s
, ",user_xattr");
1502 if (opts
& OCFS2_MOUNT_INODE64
)
1503 seq_printf(s
, ",inode64");
1505 #ifdef CONFIG_OCFS2_FS_POSIX_ACL
1506 if (opts
& OCFS2_MOUNT_POSIX_ACL
)
1507 seq_printf(s
, ",acl");
1509 seq_printf(s
, ",noacl");
1515 static int __init
ocfs2_init(void)
1521 ocfs2_print_version();
1523 status
= init_ocfs2_uptodate_cache();
1529 status
= ocfs2_initialize_mem_caches();
1535 ocfs2_wq
= create_singlethread_workqueue("ocfs2_wq");
1541 ocfs2_debugfs_root
= debugfs_create_dir("ocfs2", NULL
);
1542 if (!ocfs2_debugfs_root
) {
1544 mlog(ML_ERROR
, "Unable to create ocfs2 debugfs root.\n");
1547 status
= ocfs2_quota_setup();
1551 ocfs2_set_locking_protocol();
1553 status
= register_quota_format(&ocfs2_quota_format
);
1556 ocfs2_quota_shutdown();
1557 ocfs2_free_mem_caches();
1558 exit_ocfs2_uptodate_cache();
1564 return register_filesystem(&ocfs2_fs_type
);
1569 static void __exit
ocfs2_exit(void)
1573 ocfs2_quota_shutdown();
1576 flush_workqueue(ocfs2_wq
);
1577 destroy_workqueue(ocfs2_wq
);
1580 unregister_quota_format(&ocfs2_quota_format
);
1582 debugfs_remove(ocfs2_debugfs_root
);
1584 ocfs2_free_mem_caches();
1586 unregister_filesystem(&ocfs2_fs_type
);
1588 exit_ocfs2_uptodate_cache();
1593 static void ocfs2_put_super(struct super_block
*sb
)
1595 mlog_entry("(0x%p)\n", sb
);
1599 ocfs2_sync_blockdev(sb
);
1600 ocfs2_dismount_volume(sb
, 0);
1607 static int ocfs2_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1609 struct ocfs2_super
*osb
;
1610 u32 numbits
, freebits
;
1612 struct ocfs2_dinode
*bm_lock
;
1613 struct buffer_head
*bh
= NULL
;
1614 struct inode
*inode
= NULL
;
1616 mlog_entry("(%p, %p)\n", dentry
->d_sb
, buf
);
1618 osb
= OCFS2_SB(dentry
->d_sb
);
1620 inode
= ocfs2_get_system_file_inode(osb
,
1621 GLOBAL_BITMAP_SYSTEM_INODE
,
1622 OCFS2_INVALID_SLOT
);
1624 mlog(ML_ERROR
, "failed to get bitmap inode\n");
1629 status
= ocfs2_inode_lock(inode
, &bh
, 0);
1635 bm_lock
= (struct ocfs2_dinode
*) bh
->b_data
;
1637 numbits
= le32_to_cpu(bm_lock
->id1
.bitmap1
.i_total
);
1638 freebits
= numbits
- le32_to_cpu(bm_lock
->id1
.bitmap1
.i_used
);
1640 buf
->f_type
= OCFS2_SUPER_MAGIC
;
1641 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
1642 buf
->f_namelen
= OCFS2_MAX_FILENAME_LEN
;
1643 buf
->f_blocks
= ((sector_t
) numbits
) *
1644 (osb
->s_clustersize
>> osb
->sb
->s_blocksize_bits
);
1645 buf
->f_bfree
= ((sector_t
) freebits
) *
1646 (osb
->s_clustersize
>> osb
->sb
->s_blocksize_bits
);
1647 buf
->f_bavail
= buf
->f_bfree
;
1648 buf
->f_files
= numbits
;
1649 buf
->f_ffree
= freebits
;
1650 buf
->f_fsid
.val
[0] = crc32_le(0, osb
->uuid_str
, OCFS2_VOL_UUID_LEN
)
1652 buf
->f_fsid
.val
[1] = crc32_le(0, osb
->uuid_str
+ OCFS2_VOL_UUID_LEN
,
1653 OCFS2_VOL_UUID_LEN
) & 0xFFFFFFFFUL
;
1657 ocfs2_inode_unlock(inode
, 0);
1668 static void ocfs2_inode_init_once(void *data
)
1670 struct ocfs2_inode_info
*oi
= data
;
1673 oi
->ip_open_count
= 0;
1674 spin_lock_init(&oi
->ip_lock
);
1675 ocfs2_extent_map_init(&oi
->vfs_inode
);
1676 INIT_LIST_HEAD(&oi
->ip_io_markers
);
1677 oi
->ip_dir_start_lookup
= 0;
1679 init_rwsem(&oi
->ip_alloc_sem
);
1680 init_rwsem(&oi
->ip_xattr_sem
);
1681 mutex_init(&oi
->ip_io_mutex
);
1683 oi
->ip_blkno
= 0ULL;
1684 oi
->ip_clusters
= 0;
1686 ocfs2_lock_res_init_once(&oi
->ip_rw_lockres
);
1687 ocfs2_lock_res_init_once(&oi
->ip_inode_lockres
);
1688 ocfs2_lock_res_init_once(&oi
->ip_open_lockres
);
1690 ocfs2_metadata_cache_init(INODE_CACHE(&oi
->vfs_inode
),
1691 &ocfs2_inode_caching_ops
);
1693 inode_init_once(&oi
->vfs_inode
);
1696 static int ocfs2_initialize_mem_caches(void)
1698 ocfs2_inode_cachep
= kmem_cache_create("ocfs2_inode_cache",
1699 sizeof(struct ocfs2_inode_info
),
1701 (SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
|
1703 ocfs2_inode_init_once
);
1704 ocfs2_dquot_cachep
= kmem_cache_create("ocfs2_dquot_cache",
1705 sizeof(struct ocfs2_dquot
),
1707 (SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
|
1710 ocfs2_qf_chunk_cachep
= kmem_cache_create("ocfs2_qf_chunk_cache",
1711 sizeof(struct ocfs2_quota_chunk
),
1713 (SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
),
1715 if (!ocfs2_inode_cachep
|| !ocfs2_dquot_cachep
||
1716 !ocfs2_qf_chunk_cachep
) {
1717 if (ocfs2_inode_cachep
)
1718 kmem_cache_destroy(ocfs2_inode_cachep
);
1719 if (ocfs2_dquot_cachep
)
1720 kmem_cache_destroy(ocfs2_dquot_cachep
);
1721 if (ocfs2_qf_chunk_cachep
)
1722 kmem_cache_destroy(ocfs2_qf_chunk_cachep
);
1729 static void ocfs2_free_mem_caches(void)
1731 if (ocfs2_inode_cachep
)
1732 kmem_cache_destroy(ocfs2_inode_cachep
);
1733 ocfs2_inode_cachep
= NULL
;
1735 if (ocfs2_dquot_cachep
)
1736 kmem_cache_destroy(ocfs2_dquot_cachep
);
1737 ocfs2_dquot_cachep
= NULL
;
1739 if (ocfs2_qf_chunk_cachep
)
1740 kmem_cache_destroy(ocfs2_qf_chunk_cachep
);
1741 ocfs2_qf_chunk_cachep
= NULL
;
1744 static int ocfs2_get_sector(struct super_block
*sb
,
1745 struct buffer_head
**bh
,
1749 if (!sb_set_blocksize(sb
, sect_size
)) {
1750 mlog(ML_ERROR
, "unable to set blocksize\n");
1754 *bh
= sb_getblk(sb
, block
);
1760 if (!buffer_dirty(*bh
))
1761 clear_buffer_uptodate(*bh
);
1763 ll_rw_block(READ
, 1, bh
);
1764 wait_on_buffer(*bh
);
1765 if (!buffer_uptodate(*bh
)) {
1775 static int ocfs2_mount_volume(struct super_block
*sb
)
1778 int unlock_super
= 0;
1779 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
1783 if (ocfs2_is_hard_readonly(osb
))
1786 status
= ocfs2_dlm_init(osb
);
1792 status
= ocfs2_super_lock(osb
, 1);
1799 /* This will load up the node map and add ourselves to it. */
1800 status
= ocfs2_find_slot(osb
);
1806 /* load all node-local system inodes */
1807 status
= ocfs2_init_local_system_inodes(osb
);
1813 status
= ocfs2_check_volume(osb
);
1819 status
= ocfs2_truncate_log_init(osb
);
1825 ocfs2_super_unlock(osb
, 1);
1831 static void ocfs2_dismount_volume(struct super_block
*sb
, int mnt_err
)
1833 int tmp
, hangup_needed
= 0;
1834 struct ocfs2_super
*osb
= NULL
;
1837 mlog_entry("(0x%p)\n", sb
);
1843 debugfs_remove(osb
->osb_ctxt
);
1846 * Flush inode dropping work queue so that deletes are
1847 * performed while the filesystem is still working
1849 ocfs2_drop_all_dl_inodes(osb
);
1851 /* Orphan scan should be stopped as early as possible */
1852 ocfs2_orphan_scan_stop(osb
);
1854 ocfs2_disable_quotas(osb
);
1856 ocfs2_shutdown_local_alloc(osb
);
1858 ocfs2_truncate_log_shutdown(osb
);
1860 /* This will disable recovery and flush any recovery work. */
1861 ocfs2_recovery_exit(osb
);
1863 ocfs2_journal_shutdown(osb
);
1865 ocfs2_sync_blockdev(sb
);
1867 ocfs2_purge_refcount_trees(osb
);
1869 /* No cluster connection means we've failed during mount, so skip
1870 * all the steps which depended on that to complete. */
1872 tmp
= ocfs2_super_lock(osb
, 1);
1879 if (osb
->slot_num
!= OCFS2_INVALID_SLOT
)
1880 ocfs2_put_slot(osb
);
1883 ocfs2_super_unlock(osb
, 1);
1885 ocfs2_release_system_inodes(osb
);
1888 * If we're dismounting due to mount error, mount.ocfs2 will clean
1889 * up heartbeat. If we're a local mount, there is no heartbeat.
1890 * If we failed before we got a uuid_str yet, we can't stop
1891 * heartbeat. Otherwise, do it.
1893 if (!mnt_err
&& !ocfs2_mount_local(osb
) && osb
->uuid_str
)
1897 ocfs2_dlm_shutdown(osb
, hangup_needed
);
1899 ocfs2_blockcheck_stats_debugfs_remove(&osb
->osb_ecc_stats
);
1900 debugfs_remove(osb
->osb_debug_root
);
1903 ocfs2_cluster_hangup(osb
->uuid_str
, strlen(osb
->uuid_str
));
1905 atomic_set(&osb
->vol_state
, VOLUME_DISMOUNTED
);
1907 if (ocfs2_mount_local(osb
))
1908 snprintf(nodestr
, sizeof(nodestr
), "local");
1910 snprintf(nodestr
, sizeof(nodestr
), "%u", osb
->node_num
);
1912 printk(KERN_INFO
"ocfs2: Unmounting device (%s) on (node %s)\n",
1913 osb
->dev_str
, nodestr
);
1915 ocfs2_delete_osb(osb
);
1918 sb
->s_fs_info
= NULL
;
1921 static int ocfs2_setup_osb_uuid(struct ocfs2_super
*osb
, const unsigned char *uuid
,
1922 unsigned uuid_bytes
)
1927 BUG_ON(uuid_bytes
!= OCFS2_VOL_UUID_LEN
);
1929 osb
->uuid_str
= kzalloc(OCFS2_VOL_UUID_LEN
* 2 + 1, GFP_KERNEL
);
1930 if (osb
->uuid_str
== NULL
)
1933 for (i
= 0, ptr
= osb
->uuid_str
; i
< OCFS2_VOL_UUID_LEN
; i
++) {
1934 /* print with null */
1935 ret
= snprintf(ptr
, 3, "%02X", uuid
[i
]);
1936 if (ret
!= 2) /* drop super cleans up */
1938 /* then only advance past the last char */
1945 static int ocfs2_initialize_super(struct super_block
*sb
,
1946 struct buffer_head
*bh
,
1948 struct ocfs2_blockcheck_stats
*stats
)
1951 int i
, cbits
, bbits
;
1952 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)bh
->b_data
;
1953 struct inode
*inode
= NULL
;
1954 struct ocfs2_journal
*journal
;
1955 __le32 uuid_net_key
;
1956 struct ocfs2_super
*osb
;
1960 osb
= kzalloc(sizeof(struct ocfs2_super
), GFP_KERNEL
);
1967 sb
->s_fs_info
= osb
;
1968 sb
->s_op
= &ocfs2_sops
;
1969 sb
->s_export_op
= &ocfs2_export_ops
;
1970 sb
->s_qcop
= &ocfs2_quotactl_ops
;
1971 sb
->dq_op
= &ocfs2_quota_operations
;
1972 sb
->s_xattr
= ocfs2_xattr_handlers
;
1973 sb
->s_time_gran
= 1;
1974 sb
->s_flags
|= MS_NOATIME
;
1975 /* this is needed to support O_LARGEFILE */
1976 cbits
= le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
);
1977 bbits
= le32_to_cpu(di
->id2
.i_super
.s_blocksize_bits
);
1978 sb
->s_maxbytes
= ocfs2_max_file_offset(bbits
, cbits
);
1980 osb
->osb_dx_mask
= (1 << (cbits
- bbits
)) - 1;
1982 for (i
= 0; i
< 3; i
++)
1983 osb
->osb_dx_seed
[i
] = le32_to_cpu(di
->id2
.i_super
.s_dx_seed
[i
]);
1984 osb
->osb_dx_seed
[3] = le32_to_cpu(di
->id2
.i_super
.s_uuid_hash
);
1987 /* Save off for ocfs2_rw_direct */
1988 osb
->s_sectsize_bits
= blksize_bits(sector_size
);
1989 BUG_ON(!osb
->s_sectsize_bits
);
1991 spin_lock_init(&osb
->dc_task_lock
);
1992 init_waitqueue_head(&osb
->dc_event
);
1993 osb
->dc_work_sequence
= 0;
1994 osb
->dc_wake_sequence
= 0;
1995 INIT_LIST_HEAD(&osb
->blocked_lock_list
);
1996 osb
->blocked_lock_count
= 0;
1997 spin_lock_init(&osb
->osb_lock
);
1998 spin_lock_init(&osb
->osb_xattr_lock
);
1999 ocfs2_init_inode_steal_slot(osb
);
2001 atomic_set(&osb
->alloc_stats
.moves
, 0);
2002 atomic_set(&osb
->alloc_stats
.local_data
, 0);
2003 atomic_set(&osb
->alloc_stats
.bitmap_data
, 0);
2004 atomic_set(&osb
->alloc_stats
.bg_allocs
, 0);
2005 atomic_set(&osb
->alloc_stats
.bg_extends
, 0);
2007 /* Copy the blockcheck stats from the superblock probe */
2008 osb
->osb_ecc_stats
= *stats
;
2010 ocfs2_init_node_maps(osb
);
2012 snprintf(osb
->dev_str
, sizeof(osb
->dev_str
), "%u,%u",
2013 MAJOR(osb
->sb
->s_dev
), MINOR(osb
->sb
->s_dev
));
2015 ocfs2_orphan_scan_init(osb
);
2017 status
= ocfs2_recovery_init(osb
);
2019 mlog(ML_ERROR
, "Unable to initialize recovery state\n");
2024 init_waitqueue_head(&osb
->checkpoint_event
);
2025 atomic_set(&osb
->needs_checkpoint
, 0);
2027 osb
->s_atime_quantum
= OCFS2_DEFAULT_ATIME_QUANTUM
;
2029 osb
->slot_num
= OCFS2_INVALID_SLOT
;
2031 osb
->s_xattr_inline_size
= le16_to_cpu(
2032 di
->id2
.i_super
.s_xattr_inline_size
);
2034 osb
->local_alloc_state
= OCFS2_LA_UNUSED
;
2035 osb
->local_alloc_bh
= NULL
;
2036 INIT_DELAYED_WORK(&osb
->la_enable_wq
, ocfs2_la_enable_worker
);
2038 init_waitqueue_head(&osb
->osb_mount_event
);
2040 osb
->vol_label
= kmalloc(OCFS2_MAX_VOL_LABEL_LEN
, GFP_KERNEL
);
2041 if (!osb
->vol_label
) {
2042 mlog(ML_ERROR
, "unable to alloc vol label\n");
2047 osb
->max_slots
= le16_to_cpu(di
->id2
.i_super
.s_max_slots
);
2048 if (osb
->max_slots
> OCFS2_MAX_SLOTS
|| osb
->max_slots
== 0) {
2049 mlog(ML_ERROR
, "Invalid number of node slots (%u)\n",
2054 mlog(0, "max_slots for this device: %u\n", osb
->max_slots
);
2056 osb
->slot_recovery_generations
=
2057 kcalloc(osb
->max_slots
, sizeof(*osb
->slot_recovery_generations
),
2059 if (!osb
->slot_recovery_generations
) {
2065 init_waitqueue_head(&osb
->osb_wipe_event
);
2066 osb
->osb_orphan_wipes
= kcalloc(osb
->max_slots
,
2067 sizeof(*osb
->osb_orphan_wipes
),
2069 if (!osb
->osb_orphan_wipes
) {
2075 osb
->osb_rf_lock_tree
= RB_ROOT
;
2077 osb
->s_feature_compat
=
2078 le32_to_cpu(OCFS2_RAW_SB(di
)->s_feature_compat
);
2079 osb
->s_feature_ro_compat
=
2080 le32_to_cpu(OCFS2_RAW_SB(di
)->s_feature_ro_compat
);
2081 osb
->s_feature_incompat
=
2082 le32_to_cpu(OCFS2_RAW_SB(di
)->s_feature_incompat
);
2084 if ((i
= OCFS2_HAS_INCOMPAT_FEATURE(osb
->sb
, ~OCFS2_FEATURE_INCOMPAT_SUPP
))) {
2085 mlog(ML_ERROR
, "couldn't mount because of unsupported "
2086 "optional features (%x).\n", i
);
2090 if (!(osb
->sb
->s_flags
& MS_RDONLY
) &&
2091 (i
= OCFS2_HAS_RO_COMPAT_FEATURE(osb
->sb
, ~OCFS2_FEATURE_RO_COMPAT_SUPP
))) {
2092 mlog(ML_ERROR
, "couldn't mount RDWR because of "
2093 "unsupported optional features (%x).\n", i
);
2098 if (ocfs2_userspace_stack(osb
)) {
2099 memcpy(osb
->osb_cluster_stack
,
2100 OCFS2_RAW_SB(di
)->s_cluster_info
.ci_stack
,
2101 OCFS2_STACK_LABEL_LEN
);
2102 osb
->osb_cluster_stack
[OCFS2_STACK_LABEL_LEN
] = '\0';
2103 if (strlen(osb
->osb_cluster_stack
) != OCFS2_STACK_LABEL_LEN
) {
2105 "couldn't mount because of an invalid "
2106 "cluster stack label (%s) \n",
2107 osb
->osb_cluster_stack
);
2112 /* The empty string is identical with classic tools that
2113 * don't know about s_cluster_info. */
2114 osb
->osb_cluster_stack
[0] = '\0';
2117 get_random_bytes(&osb
->s_next_generation
, sizeof(u32
));
2120 * This should be done in ocfs2_journal_init(), but unknown
2121 * ordering issues will cause the filesystem to crash.
2122 * If anyone wants to figure out what part of the code
2123 * refers to osb->journal before ocfs2_journal_init() is run,
2126 /* initialize our journal structure */
2128 journal
= kzalloc(sizeof(struct ocfs2_journal
), GFP_KERNEL
);
2130 mlog(ML_ERROR
, "unable to alloc journal\n");
2134 osb
->journal
= journal
;
2135 journal
->j_osb
= osb
;
2137 atomic_set(&journal
->j_num_trans
, 0);
2138 init_rwsem(&journal
->j_trans_barrier
);
2139 init_waitqueue_head(&journal
->j_checkpointed
);
2140 spin_lock_init(&journal
->j_lock
);
2141 journal
->j_trans_id
= (unsigned long) 1;
2142 INIT_LIST_HEAD(&journal
->j_la_cleanups
);
2143 INIT_WORK(&journal
->j_recovery_work
, ocfs2_complete_recovery
);
2144 journal
->j_state
= OCFS2_JOURNAL_FREE
;
2146 INIT_WORK(&osb
->dentry_lock_work
, ocfs2_drop_dl_inodes
);
2147 osb
->dentry_lock_list
= NULL
;
2149 /* get some pseudo constants for clustersize bits */
2150 osb
->s_clustersize_bits
=
2151 le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
);
2152 osb
->s_clustersize
= 1 << osb
->s_clustersize_bits
;
2153 mlog(0, "clusterbits=%d\n", osb
->s_clustersize_bits
);
2155 if (osb
->s_clustersize
< OCFS2_MIN_CLUSTERSIZE
||
2156 osb
->s_clustersize
> OCFS2_MAX_CLUSTERSIZE
) {
2157 mlog(ML_ERROR
, "Volume has invalid cluster size (%d)\n",
2158 osb
->s_clustersize
);
2163 if (ocfs2_clusters_to_blocks(osb
->sb
, le32_to_cpu(di
->i_clusters
) - 1)
2165 mlog(ML_ERROR
, "Volume might try to write to blocks beyond "
2166 "what jbd can address in 32 bits.\n");
2171 if (ocfs2_setup_osb_uuid(osb
, di
->id2
.i_super
.s_uuid
,
2172 sizeof(di
->id2
.i_super
.s_uuid
))) {
2173 mlog(ML_ERROR
, "Out of memory trying to setup our uuid.\n");
2178 memcpy(&uuid_net_key
, di
->id2
.i_super
.s_uuid
, sizeof(uuid_net_key
));
2180 strncpy(osb
->vol_label
, di
->id2
.i_super
.s_label
, 63);
2181 osb
->vol_label
[63] = '\0';
2182 osb
->root_blkno
= le64_to_cpu(di
->id2
.i_super
.s_root_blkno
);
2183 osb
->system_dir_blkno
= le64_to_cpu(di
->id2
.i_super
.s_system_dir_blkno
);
2184 osb
->first_cluster_group_blkno
=
2185 le64_to_cpu(di
->id2
.i_super
.s_first_cluster_group
);
2186 osb
->fs_generation
= le32_to_cpu(di
->i_fs_generation
);
2187 osb
->uuid_hash
= le32_to_cpu(di
->id2
.i_super
.s_uuid_hash
);
2188 mlog(0, "vol_label: %s\n", osb
->vol_label
);
2189 mlog(0, "uuid: %s\n", osb
->uuid_str
);
2190 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2191 (unsigned long long)osb
->root_blkno
,
2192 (unsigned long long)osb
->system_dir_blkno
);
2194 osb
->osb_dlm_debug
= ocfs2_new_dlm_debug();
2195 if (!osb
->osb_dlm_debug
) {
2201 atomic_set(&osb
->vol_state
, VOLUME_INIT
);
2203 /* load root, system_dir, and all global system inodes */
2204 status
= ocfs2_init_global_system_inodes(osb
);
2213 inode
= ocfs2_get_system_file_inode(osb
, GLOBAL_BITMAP_SYSTEM_INODE
,
2214 OCFS2_INVALID_SLOT
);
2221 osb
->bitmap_blkno
= OCFS2_I(inode
)->ip_blkno
;
2224 osb
->bitmap_cpg
= ocfs2_group_bitmap_size(sb
) * 8;
2226 status
= ocfs2_init_slot_info(osb
);
2238 * will return: -EAGAIN if it is ok to keep searching for superblocks
2239 * -EINVAL if there is a bad superblock
2242 static int ocfs2_verify_volume(struct ocfs2_dinode
*di
,
2243 struct buffer_head
*bh
,
2245 struct ocfs2_blockcheck_stats
*stats
)
2247 int status
= -EAGAIN
;
2251 if (memcmp(di
->i_signature
, OCFS2_SUPER_BLOCK_SIGNATURE
,
2252 strlen(OCFS2_SUPER_BLOCK_SIGNATURE
)) == 0) {
2253 /* We have to do a raw check of the feature here */
2254 if (le32_to_cpu(di
->id2
.i_super
.s_feature_incompat
) &
2255 OCFS2_FEATURE_INCOMPAT_META_ECC
) {
2256 status
= ocfs2_block_check_validate(bh
->b_data
,
2264 if ((1 << le32_to_cpu(di
->id2
.i_super
.s_blocksize_bits
)) != blksz
) {
2265 mlog(ML_ERROR
, "found superblock with incorrect block "
2266 "size: found %u, should be %u\n",
2267 1 << le32_to_cpu(di
->id2
.i_super
.s_blocksize_bits
),
2269 } else if (le16_to_cpu(di
->id2
.i_super
.s_major_rev_level
) !=
2270 OCFS2_MAJOR_REV_LEVEL
||
2271 le16_to_cpu(di
->id2
.i_super
.s_minor_rev_level
) !=
2272 OCFS2_MINOR_REV_LEVEL
) {
2273 mlog(ML_ERROR
, "found superblock with bad version: "
2274 "found %u.%u, should be %u.%u\n",
2275 le16_to_cpu(di
->id2
.i_super
.s_major_rev_level
),
2276 le16_to_cpu(di
->id2
.i_super
.s_minor_rev_level
),
2277 OCFS2_MAJOR_REV_LEVEL
,
2278 OCFS2_MINOR_REV_LEVEL
);
2279 } else if (bh
->b_blocknr
!= le64_to_cpu(di
->i_blkno
)) {
2280 mlog(ML_ERROR
, "bad block number on superblock: "
2281 "found %llu, should be %llu\n",
2282 (unsigned long long)le64_to_cpu(di
->i_blkno
),
2283 (unsigned long long)bh
->b_blocknr
);
2284 } else if (le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
) < 12 ||
2285 le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
) > 20) {
2286 mlog(ML_ERROR
, "bad cluster size found: %u\n",
2287 1 << le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
));
2288 } else if (!le64_to_cpu(di
->id2
.i_super
.s_root_blkno
)) {
2289 mlog(ML_ERROR
, "bad root_blkno: 0\n");
2290 } else if (!le64_to_cpu(di
->id2
.i_super
.s_system_dir_blkno
)) {
2291 mlog(ML_ERROR
, "bad system_dir_blkno: 0\n");
2292 } else if (le16_to_cpu(di
->id2
.i_super
.s_max_slots
) > OCFS2_MAX_SLOTS
) {
2294 "Superblock slots found greater than file system "
2295 "maximum: found %u, max %u\n",
2296 le16_to_cpu(di
->id2
.i_super
.s_max_slots
),
2309 static int ocfs2_check_volume(struct ocfs2_super
*osb
)
2314 struct ocfs2_dinode
*local_alloc
= NULL
; /* only used if we
2320 /* Init our journal object. */
2321 status
= ocfs2_journal_init(osb
->journal
, &dirty
);
2323 mlog(ML_ERROR
, "Could not initialize journal!\n");
2327 /* If the journal was unmounted cleanly then we don't want to
2328 * recover anything. Otherwise, journal_load will do that
2329 * dirty work for us :) */
2331 status
= ocfs2_journal_wipe(osb
->journal
, 0);
2337 mlog(ML_NOTICE
, "File system was not unmounted cleanly, "
2338 "recovering volume.\n");
2341 local
= ocfs2_mount_local(osb
);
2343 /* will play back anything left in the journal. */
2344 status
= ocfs2_journal_load(osb
->journal
, local
, dirty
);
2346 mlog(ML_ERROR
, "ocfs2 journal load failed! %d\n", status
);
2351 /* recover my local alloc if we didn't unmount cleanly. */
2352 status
= ocfs2_begin_local_alloc_recovery(osb
,
2359 /* we complete the recovery process after we've marked
2360 * ourselves as mounted. */
2363 mlog(0, "Journal loaded.\n");
2365 status
= ocfs2_load_local_alloc(osb
);
2372 /* Recovery will be completed after we've mounted the
2373 * rest of the volume. */
2375 osb
->local_alloc_copy
= local_alloc
;
2379 /* go through each journal, trylock it and if you get the
2380 * lock, and it's marked as dirty, set the bit in the recover
2381 * map and launch a recovery thread for it. */
2382 status
= ocfs2_mark_dead_nodes(osb
);
2388 status
= ocfs2_compute_replay_slots(osb
);
2401 * The routine gets called from dismount or close whenever a dismount on
2402 * volume is requested and the osb open count becomes 1.
2403 * It will remove the osb from the global list and also free up all the
2404 * initialized resources and fileobject.
2406 static void ocfs2_delete_osb(struct ocfs2_super
*osb
)
2410 /* This function assumes that the caller has the main osb resource */
2412 ocfs2_free_slot_info(osb
);
2414 kfree(osb
->osb_orphan_wipes
);
2415 kfree(osb
->slot_recovery_generations
);
2417 * This belongs in journal shutdown, but because we have to
2418 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2421 kfree(osb
->journal
);
2422 if (osb
->local_alloc_copy
)
2423 kfree(osb
->local_alloc_copy
);
2424 kfree(osb
->uuid_str
);
2425 ocfs2_put_dlm_debug(osb
->osb_dlm_debug
);
2426 memset(osb
, 0, sizeof(struct ocfs2_super
));
2431 /* Put OCFS2 into a readonly state, or (if the user specifies it),
2432 * panic(). We do not support continue-on-error operation. */
2433 static void ocfs2_handle_error(struct super_block
*sb
)
2435 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
2437 if (osb
->s_mount_opt
& OCFS2_MOUNT_ERRORS_PANIC
)
2438 panic("OCFS2: (device %s): panic forced after error\n",
2441 ocfs2_set_osb_flag(osb
, OCFS2_OSB_ERROR_FS
);
2443 if (sb
->s_flags
& MS_RDONLY
&&
2444 (ocfs2_is_soft_readonly(osb
) ||
2445 ocfs2_is_hard_readonly(osb
)))
2448 printk(KERN_CRIT
"File system is now read-only due to the potential "
2449 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2450 "system is unmounted.\n");
2451 sb
->s_flags
|= MS_RDONLY
;
2452 ocfs2_set_ro_flag(osb
, 0);
2455 static char error_buf
[1024];
2457 void __ocfs2_error(struct super_block
*sb
,
2458 const char *function
,
2459 const char *fmt
, ...)
2463 va_start(args
, fmt
);
2464 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
2467 /* Not using mlog here because we want to show the actual
2468 * function the error came from. */
2469 printk(KERN_CRIT
"OCFS2: ERROR (device %s): %s: %s\n",
2470 sb
->s_id
, function
, error_buf
);
2472 ocfs2_handle_error(sb
);
2475 /* Handle critical errors. This is intentionally more drastic than
2476 * ocfs2_handle_error, so we only use for things like journal errors,
2478 void __ocfs2_abort(struct super_block
* sb
,
2479 const char *function
,
2480 const char *fmt
, ...)
2484 va_start(args
, fmt
);
2485 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
2488 printk(KERN_CRIT
"OCFS2: abort (device %s): %s: %s\n",
2489 sb
->s_id
, function
, error_buf
);
2491 /* We don't have the cluster support yet to go straight to
2492 * hard readonly in here. Until then, we want to keep
2493 * ocfs2_abort() so that we can at least mark critical
2496 * TODO: This should abort the journal and alert other nodes
2497 * that our slot needs recovery. */
2499 /* Force a panic(). This stinks, but it's better than letting
2500 * things continue without having a proper hard readonly
2502 if (!ocfs2_mount_local(OCFS2_SB(sb
)))
2503 OCFS2_SB(sb
)->s_mount_opt
|= OCFS2_MOUNT_ERRORS_PANIC
;
2504 ocfs2_handle_error(sb
);
2507 module_init(ocfs2_init
);
2508 module_exit(ocfs2_exit
);