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"
74 #include "buffer_head_io.h"
76 static struct kmem_cache
*ocfs2_inode_cachep
= NULL
;
77 struct kmem_cache
*ocfs2_dquot_cachep
;
78 struct kmem_cache
*ocfs2_qf_chunk_cachep
;
80 /* OCFS2 needs to schedule several differnt types of work which
81 * require cluster locking, disk I/O, recovery waits, etc. Since these
82 * types of work tend to be heavy we avoid using the kernel events
83 * workqueue and schedule on our own. */
84 struct workqueue_struct
*ocfs2_wq
= NULL
;
86 static struct dentry
*ocfs2_debugfs_root
= NULL
;
88 MODULE_AUTHOR("Oracle");
89 MODULE_LICENSE("GPL");
93 unsigned long commit_interval
;
94 unsigned long mount_opt
;
95 unsigned int atime_quantum
;
97 unsigned int localalloc_opt
;
98 char cluster_stack
[OCFS2_STACK_LABEL_LEN
+ 1];
101 static int ocfs2_parse_options(struct super_block
*sb
, char *options
,
102 struct mount_options
*mopt
,
104 static int ocfs2_check_set_options(struct super_block
*sb
,
105 struct mount_options
*options
);
106 static int ocfs2_show_options(struct seq_file
*s
, struct vfsmount
*mnt
);
107 static void ocfs2_put_super(struct super_block
*sb
);
108 static int ocfs2_mount_volume(struct super_block
*sb
);
109 static int ocfs2_remount(struct super_block
*sb
, int *flags
, char *data
);
110 static void ocfs2_dismount_volume(struct super_block
*sb
, int mnt_err
);
111 static int ocfs2_initialize_mem_caches(void);
112 static void ocfs2_free_mem_caches(void);
113 static void ocfs2_delete_osb(struct ocfs2_super
*osb
);
115 static int ocfs2_statfs(struct dentry
*dentry
, struct kstatfs
*buf
);
117 static int ocfs2_sync_fs(struct super_block
*sb
, int wait
);
119 static int ocfs2_init_global_system_inodes(struct ocfs2_super
*osb
);
120 static int ocfs2_init_local_system_inodes(struct ocfs2_super
*osb
);
121 static void ocfs2_release_system_inodes(struct ocfs2_super
*osb
);
122 static int ocfs2_check_volume(struct ocfs2_super
*osb
);
123 static int ocfs2_verify_volume(struct ocfs2_dinode
*di
,
124 struct buffer_head
*bh
,
126 struct ocfs2_blockcheck_stats
*stats
);
127 static int ocfs2_initialize_super(struct super_block
*sb
,
128 struct buffer_head
*bh
,
130 struct ocfs2_blockcheck_stats
*stats
);
131 static int ocfs2_get_sector(struct super_block
*sb
,
132 struct buffer_head
**bh
,
135 static struct inode
*ocfs2_alloc_inode(struct super_block
*sb
);
136 static void ocfs2_destroy_inode(struct inode
*inode
);
137 static int ocfs2_susp_quotas(struct ocfs2_super
*osb
, int unsuspend
);
138 static int ocfs2_enable_quotas(struct ocfs2_super
*osb
);
139 static void ocfs2_disable_quotas(struct ocfs2_super
*osb
);
141 static const struct super_operations ocfs2_sops
= {
142 .statfs
= ocfs2_statfs
,
143 .alloc_inode
= ocfs2_alloc_inode
,
144 .destroy_inode
= ocfs2_destroy_inode
,
145 .drop_inode
= ocfs2_drop_inode
,
146 .clear_inode
= ocfs2_clear_inode
,
147 .delete_inode
= ocfs2_delete_inode
,
148 .sync_fs
= ocfs2_sync_fs
,
149 .put_super
= ocfs2_put_super
,
150 .remount_fs
= ocfs2_remount
,
151 .show_options
= ocfs2_show_options
,
152 .quota_read
= ocfs2_quota_read
,
153 .quota_write
= ocfs2_quota_write
,
182 static const match_table_t tokens
= {
183 {Opt_barrier
, "barrier=%u"},
184 {Opt_err_panic
, "errors=panic"},
185 {Opt_err_ro
, "errors=remount-ro"},
187 {Opt_nointr
, "nointr"},
188 {Opt_hb_none
, OCFS2_HB_NONE
},
189 {Opt_hb_local
, OCFS2_HB_LOCAL
},
190 {Opt_data_ordered
, "data=ordered"},
191 {Opt_data_writeback
, "data=writeback"},
192 {Opt_atime_quantum
, "atime_quantum=%u"},
193 {Opt_slot
, "preferred_slot=%u"},
194 {Opt_commit
, "commit=%u"},
195 {Opt_localalloc
, "localalloc=%d"},
196 {Opt_localflocks
, "localflocks"},
197 {Opt_stack
, "cluster_stack=%s"},
198 {Opt_user_xattr
, "user_xattr"},
199 {Opt_nouser_xattr
, "nouser_xattr"},
200 {Opt_inode64
, "inode64"},
202 {Opt_noacl
, "noacl"},
203 {Opt_usrquota
, "usrquota"},
204 {Opt_grpquota
, "grpquota"},
208 #ifdef CONFIG_DEBUG_FS
209 static int ocfs2_osb_dump(struct ocfs2_super
*osb
, char *buf
, int len
)
211 struct ocfs2_cluster_connection
*cconn
= osb
->cconn
;
212 struct ocfs2_recovery_map
*rm
= osb
->recovery_map
;
213 struct ocfs2_orphan_scan
*os
= &osb
->osb_orphan_scan
;
216 out
+= snprintf(buf
+ out
, len
- out
,
217 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
218 "Device", osb
->dev_str
, osb
->uuid_str
,
219 osb
->fs_generation
, osb
->vol_label
);
221 out
+= snprintf(buf
+ out
, len
- out
,
222 "%10s => State: %d Flags: 0x%lX\n", "Volume",
223 atomic_read(&osb
->vol_state
), osb
->osb_flags
);
225 out
+= snprintf(buf
+ out
, len
- out
,
226 "%10s => Block: %lu Cluster: %d\n", "Sizes",
227 osb
->sb
->s_blocksize
, osb
->s_clustersize
);
229 out
+= snprintf(buf
+ out
, len
- out
,
230 "%10s => Compat: 0x%X Incompat: 0x%X "
232 "Features", osb
->s_feature_compat
,
233 osb
->s_feature_incompat
, osb
->s_feature_ro_compat
);
235 out
+= snprintf(buf
+ out
, len
- out
,
236 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
237 osb
->s_mount_opt
, osb
->s_atime_quantum
);
240 out
+= snprintf(buf
+ out
, len
- out
,
241 "%10s => Stack: %s Name: %*s "
242 "Version: %d.%d\n", "Cluster",
243 (*osb
->osb_cluster_stack
== '\0' ?
244 "o2cb" : osb
->osb_cluster_stack
),
245 cconn
->cc_namelen
, cconn
->cc_name
,
246 cconn
->cc_version
.pv_major
,
247 cconn
->cc_version
.pv_minor
);
250 spin_lock(&osb
->dc_task_lock
);
251 out
+= snprintf(buf
+ out
, len
- out
,
252 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
253 "WorkSeq: %lu\n", "DownCnvt",
254 (osb
->dc_task
? task_pid_nr(osb
->dc_task
) : -1),
255 osb
->blocked_lock_count
, osb
->dc_wake_sequence
,
256 osb
->dc_work_sequence
);
257 spin_unlock(&osb
->dc_task_lock
);
259 spin_lock(&osb
->osb_lock
);
260 out
+= snprintf(buf
+ out
, len
- out
, "%10s => Pid: %d Nodes:",
262 (osb
->recovery_thread_task
?
263 task_pid_nr(osb
->recovery_thread_task
) : -1));
264 if (rm
->rm_used
== 0)
265 out
+= snprintf(buf
+ out
, len
- out
, " None\n");
267 for (i
= 0; i
< rm
->rm_used
; i
++)
268 out
+= snprintf(buf
+ out
, len
- out
, " %d",
270 out
+= snprintf(buf
+ out
, len
- out
, "\n");
272 spin_unlock(&osb
->osb_lock
);
274 out
+= snprintf(buf
+ out
, len
- out
,
275 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
276 (osb
->commit_task
? task_pid_nr(osb
->commit_task
) : -1),
277 osb
->osb_commit_interval
,
278 atomic_read(&osb
->needs_checkpoint
));
280 out
+= snprintf(buf
+ out
, len
- out
,
281 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
282 "Journal", osb
->journal
->j_state
,
283 osb
->journal
->j_trans_id
,
284 atomic_read(&osb
->journal
->j_num_trans
));
286 out
+= snprintf(buf
+ out
, len
- out
,
287 "%10s => GlobalAllocs: %d LocalAllocs: %d "
288 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
290 atomic_read(&osb
->alloc_stats
.bitmap_data
),
291 atomic_read(&osb
->alloc_stats
.local_data
),
292 atomic_read(&osb
->alloc_stats
.bg_allocs
),
293 atomic_read(&osb
->alloc_stats
.moves
),
294 atomic_read(&osb
->alloc_stats
.bg_extends
));
296 out
+= snprintf(buf
+ out
, len
- out
,
297 "%10s => State: %u Descriptor: %llu Size: %u bits "
298 "Default: %u bits\n",
299 "LocalAlloc", osb
->local_alloc_state
,
300 (unsigned long long)osb
->la_last_gd
,
301 osb
->local_alloc_bits
, osb
->local_alloc_default_bits
);
303 spin_lock(&osb
->osb_lock
);
304 out
+= snprintf(buf
+ out
, len
- out
,
305 "%10s => InodeSlot: %d StolenInodes: %d, "
306 "MetaSlot: %d StolenMeta: %d\n", "Steal",
307 osb
->s_inode_steal_slot
,
308 atomic_read(&osb
->s_num_inodes_stolen
),
309 osb
->s_meta_steal_slot
,
310 atomic_read(&osb
->s_num_meta_stolen
));
311 spin_unlock(&osb
->osb_lock
);
313 out
+= snprintf(buf
+ out
, len
- out
, "OrphanScan => ");
314 out
+= snprintf(buf
+ out
, len
- out
, "Local: %u Global: %u ",
315 os
->os_count
, os
->os_seqno
);
316 out
+= snprintf(buf
+ out
, len
- out
, " Last Scan: ");
317 if (atomic_read(&os
->os_state
) == ORPHAN_SCAN_INACTIVE
)
318 out
+= snprintf(buf
+ out
, len
- out
, "Disabled\n");
320 out
+= snprintf(buf
+ out
, len
- out
, "%lu seconds ago\n",
321 (get_seconds() - os
->os_scantime
.tv_sec
));
323 out
+= snprintf(buf
+ out
, len
- out
, "%10s => %3s %10s\n",
324 "Slots", "Num", "RecoGen");
325 for (i
= 0; i
< osb
->max_slots
; ++i
) {
326 out
+= snprintf(buf
+ out
, len
- out
,
327 "%10s %c %3d %10d\n",
329 (i
== osb
->slot_num
? '*' : ' '),
330 i
, osb
->slot_recovery_generations
[i
]);
336 static int ocfs2_osb_debug_open(struct inode
*inode
, struct file
*file
)
338 struct ocfs2_super
*osb
= inode
->i_private
;
341 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
345 i_size_write(inode
, ocfs2_osb_dump(osb
, buf
, PAGE_SIZE
));
347 file
->private_data
= buf
;
354 static int ocfs2_debug_release(struct inode
*inode
, struct file
*file
)
356 kfree(file
->private_data
);
360 static ssize_t
ocfs2_debug_read(struct file
*file
, char __user
*buf
,
361 size_t nbytes
, loff_t
*ppos
)
363 return simple_read_from_buffer(buf
, nbytes
, ppos
, file
->private_data
,
364 i_size_read(file
->f_mapping
->host
));
367 static int ocfs2_osb_debug_open(struct inode
*inode
, struct file
*file
)
371 static int ocfs2_debug_release(struct inode
*inode
, struct file
*file
)
375 static ssize_t
ocfs2_debug_read(struct file
*file
, char __user
*buf
,
376 size_t nbytes
, loff_t
*ppos
)
380 #endif /* CONFIG_DEBUG_FS */
382 static const struct file_operations ocfs2_osb_debug_fops
= {
383 .open
= ocfs2_osb_debug_open
,
384 .release
= ocfs2_debug_release
,
385 .read
= ocfs2_debug_read
,
386 .llseek
= generic_file_llseek
,
389 static int ocfs2_sync_fs(struct super_block
*sb
, int wait
)
393 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
395 if (ocfs2_is_hard_readonly(osb
))
399 status
= ocfs2_flush_truncate_log(osb
);
403 ocfs2_schedule_truncate_log_flush(osb
, 0);
406 if (jbd2_journal_start_commit(OCFS2_SB(sb
)->journal
->j_journal
,
409 jbd2_log_wait_commit(OCFS2_SB(sb
)->journal
->j_journal
,
415 static int ocfs2_need_system_inode(struct ocfs2_super
*osb
, int ino
)
417 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb
->sb
, OCFS2_FEATURE_RO_COMPAT_USRQUOTA
)
418 && (ino
== USER_QUOTA_SYSTEM_INODE
419 || ino
== LOCAL_USER_QUOTA_SYSTEM_INODE
))
421 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb
->sb
, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
)
422 && (ino
== GROUP_QUOTA_SYSTEM_INODE
423 || ino
== LOCAL_GROUP_QUOTA_SYSTEM_INODE
))
428 static int ocfs2_init_global_system_inodes(struct ocfs2_super
*osb
)
430 struct inode
*new = NULL
;
436 new = ocfs2_iget(osb
, osb
->root_blkno
, OCFS2_FI_FLAG_SYSFILE
, 0);
438 status
= PTR_ERR(new);
442 osb
->root_inode
= new;
444 new = ocfs2_iget(osb
, osb
->system_dir_blkno
, OCFS2_FI_FLAG_SYSFILE
, 0);
446 status
= PTR_ERR(new);
450 osb
->sys_root_inode
= new;
452 for (i
= OCFS2_FIRST_ONLINE_SYSTEM_INODE
;
453 i
<= OCFS2_LAST_GLOBAL_SYSTEM_INODE
; i
++) {
454 if (!ocfs2_need_system_inode(osb
, i
))
456 new = ocfs2_get_system_file_inode(osb
, i
, osb
->slot_num
);
458 ocfs2_release_system_inodes(osb
);
461 /* FIXME: Should ERROR_RO_FS */
462 mlog(ML_ERROR
, "Unable to load system inode %d, "
463 "possibly corrupt fs?", i
);
466 // the array now has one ref, so drop this one
475 static int ocfs2_init_local_system_inodes(struct ocfs2_super
*osb
)
477 struct inode
*new = NULL
;
483 for (i
= OCFS2_LAST_GLOBAL_SYSTEM_INODE
+ 1;
484 i
< NUM_SYSTEM_INODES
;
486 if (!ocfs2_need_system_inode(osb
, i
))
488 new = ocfs2_get_system_file_inode(osb
, i
, osb
->slot_num
);
490 ocfs2_release_system_inodes(osb
);
492 mlog(ML_ERROR
, "status=%d, sysfile=%d, slot=%d\n",
493 status
, i
, osb
->slot_num
);
496 /* the array now has one ref, so drop this one */
505 static void ocfs2_release_system_inodes(struct ocfs2_super
*osb
)
512 for (i
= 0; i
< NUM_SYSTEM_INODES
; i
++) {
513 inode
= osb
->system_inodes
[i
];
516 osb
->system_inodes
[i
] = NULL
;
520 inode
= osb
->sys_root_inode
;
523 osb
->sys_root_inode
= NULL
;
526 inode
= osb
->root_inode
;
529 osb
->root_inode
= NULL
;
535 /* We're allocating fs objects, use GFP_NOFS */
536 static struct inode
*ocfs2_alloc_inode(struct super_block
*sb
)
538 struct ocfs2_inode_info
*oi
;
540 oi
= kmem_cache_alloc(ocfs2_inode_cachep
, GFP_NOFS
);
544 jbd2_journal_init_jbd_inode(&oi
->ip_jinode
, &oi
->vfs_inode
);
545 return &oi
->vfs_inode
;
548 static void ocfs2_destroy_inode(struct inode
*inode
)
550 kmem_cache_free(ocfs2_inode_cachep
, OCFS2_I(inode
));
553 static unsigned long long ocfs2_max_file_offset(unsigned int bbits
,
556 unsigned int bytes
= 1 << cbits
;
557 unsigned int trim
= bytes
;
558 unsigned int bitshift
= 32;
561 * i_size and all block offsets in ocfs2 are always 64 bits
562 * wide. i_clusters is 32 bits, in cluster-sized units. So on
563 * 64 bit platforms, cluster size will be the limiting factor.
566 #if BITS_PER_LONG == 32
567 # if defined(CONFIG_LBDAF)
568 BUILD_BUG_ON(sizeof(sector_t
) != 8);
570 * We might be limited by page cache size.
572 if (bytes
> PAGE_CACHE_SIZE
) {
573 bytes
= PAGE_CACHE_SIZE
;
576 * Shift by 31 here so that we don't get larger than
583 * We are limited by the size of sector_t. Use block size, as
584 * that's what we expose to the VFS.
593 * Trim by a whole cluster when we can actually approach the
594 * on-disk limits. Otherwise we can overflow i_clusters when
595 * an extent start is at the max offset.
597 return (((unsigned long long)bytes
) << bitshift
) - trim
;
600 static int ocfs2_remount(struct super_block
*sb
, int *flags
, char *data
)
602 int incompat_features
;
604 struct mount_options parsed_options
;
605 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
609 if (!ocfs2_parse_options(sb
, data
, &parsed_options
, 1) ||
610 !ocfs2_check_set_options(sb
, &parsed_options
)) {
615 if ((osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
) !=
616 (parsed_options
.mount_opt
& OCFS2_MOUNT_HB_LOCAL
)) {
618 mlog(ML_ERROR
, "Cannot change heartbeat mode on remount\n");
622 if ((osb
->s_mount_opt
& OCFS2_MOUNT_DATA_WRITEBACK
) !=
623 (parsed_options
.mount_opt
& OCFS2_MOUNT_DATA_WRITEBACK
)) {
625 mlog(ML_ERROR
, "Cannot change data mode on remount\n");
629 /* Probably don't want this on remount; it might
630 * mess with other nodes */
631 if (!(osb
->s_mount_opt
& OCFS2_MOUNT_INODE64
) &&
632 (parsed_options
.mount_opt
& OCFS2_MOUNT_INODE64
)) {
634 mlog(ML_ERROR
, "Cannot enable inode64 on remount\n");
638 /* We're going to/from readonly mode. */
639 if ((*flags
& MS_RDONLY
) != (sb
->s_flags
& MS_RDONLY
)) {
640 /* Disable quota accounting before remounting RO */
641 if (*flags
& MS_RDONLY
) {
642 ret
= ocfs2_susp_quotas(osb
, 0);
646 /* Lock here so the check of HARD_RO and the potential
647 * setting of SOFT_RO is atomic. */
648 spin_lock(&osb
->osb_lock
);
649 if (osb
->osb_flags
& OCFS2_OSB_HARD_RO
) {
650 mlog(ML_ERROR
, "Remount on readonly device is forbidden.\n");
655 if (*flags
& MS_RDONLY
) {
656 mlog(0, "Going to ro mode.\n");
657 sb
->s_flags
|= MS_RDONLY
;
658 osb
->osb_flags
|= OCFS2_OSB_SOFT_RO
;
660 mlog(0, "Making ro filesystem writeable.\n");
662 if (osb
->osb_flags
& OCFS2_OSB_ERROR_FS
) {
663 mlog(ML_ERROR
, "Cannot remount RDWR "
664 "filesystem due to previous errors.\n");
668 incompat_features
= OCFS2_HAS_RO_COMPAT_FEATURE(sb
, ~OCFS2_FEATURE_RO_COMPAT_SUPP
);
669 if (incompat_features
) {
670 mlog(ML_ERROR
, "Cannot remount RDWR because "
671 "of unsupported optional features "
672 "(%x).\n", incompat_features
);
676 sb
->s_flags
&= ~MS_RDONLY
;
677 osb
->osb_flags
&= ~OCFS2_OSB_SOFT_RO
;
680 spin_unlock(&osb
->osb_lock
);
681 /* Enable quota accounting after remounting RW */
682 if (!ret
&& !(*flags
& MS_RDONLY
)) {
683 if (sb_any_quota_suspended(sb
))
684 ret
= ocfs2_susp_quotas(osb
, 1);
686 ret
= ocfs2_enable_quotas(osb
);
688 /* Return back changes... */
689 spin_lock(&osb
->osb_lock
);
690 sb
->s_flags
|= MS_RDONLY
;
691 osb
->osb_flags
|= OCFS2_OSB_SOFT_RO
;
692 spin_unlock(&osb
->osb_lock
);
699 /* Only save off the new mount options in case of a successful
701 osb
->s_mount_opt
= parsed_options
.mount_opt
;
702 osb
->s_atime_quantum
= parsed_options
.atime_quantum
;
703 osb
->preferred_slot
= parsed_options
.slot
;
704 if (parsed_options
.commit_interval
)
705 osb
->osb_commit_interval
= parsed_options
.commit_interval
;
707 if (!ocfs2_is_hard_readonly(osb
))
708 ocfs2_set_journal_params(osb
);
710 sb
->s_flags
= (sb
->s_flags
& ~MS_POSIXACL
) |
711 ((osb
->s_mount_opt
& OCFS2_MOUNT_POSIX_ACL
) ?
719 static int ocfs2_sb_probe(struct super_block
*sb
,
720 struct buffer_head
**bh
,
722 struct ocfs2_blockcheck_stats
*stats
)
725 struct ocfs1_vol_disk_hdr
*hdr
;
726 struct ocfs2_dinode
*di
;
732 *sector_size
= bdev_logical_block_size(sb
->s_bdev
);
733 if (*sector_size
> OCFS2_MAX_BLOCKSIZE
) {
734 mlog(ML_ERROR
, "Hardware sector size too large: %d (max=%d)\n",
735 *sector_size
, OCFS2_MAX_BLOCKSIZE
);
740 /* Can this really happen? */
741 if (*sector_size
< OCFS2_MIN_BLOCKSIZE
)
742 *sector_size
= OCFS2_MIN_BLOCKSIZE
;
744 /* check block zero for old format */
745 status
= ocfs2_get_sector(sb
, bh
, 0, *sector_size
);
750 hdr
= (struct ocfs1_vol_disk_hdr
*) (*bh
)->b_data
;
751 if (hdr
->major_version
== OCFS1_MAJOR_VERSION
) {
752 mlog(ML_ERROR
, "incompatible version: %u.%u\n",
753 hdr
->major_version
, hdr
->minor_version
);
756 if (memcmp(hdr
->signature
, OCFS1_VOLUME_SIGNATURE
,
757 strlen(OCFS1_VOLUME_SIGNATURE
)) == 0) {
758 mlog(ML_ERROR
, "incompatible volume signature: %8s\n",
765 mlog(ML_ERROR
, "This is an ocfs v1 filesystem which must be "
766 "upgraded before mounting with ocfs v2\n");
771 * Now check at magic offset for 512, 1024, 2048, 4096
772 * blocksizes. 4096 is the maximum blocksize because it is
773 * the minimum clustersize.
776 for (blksize
= *sector_size
;
777 blksize
<= OCFS2_MAX_BLOCKSIZE
;
779 tmpstat
= ocfs2_get_sector(sb
, bh
,
780 OCFS2_SUPER_BLOCK_BLKNO
,
787 di
= (struct ocfs2_dinode
*) (*bh
)->b_data
;
788 memset(stats
, 0, sizeof(struct ocfs2_blockcheck_stats
));
789 spin_lock_init(&stats
->b_lock
);
790 tmpstat
= ocfs2_verify_volume(di
, *bh
, blksize
, stats
);
795 if (tmpstat
!= -EAGAIN
) {
805 static int ocfs2_verify_heartbeat(struct ocfs2_super
*osb
)
807 if (ocfs2_mount_local(osb
)) {
808 if (osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
) {
809 mlog(ML_ERROR
, "Cannot heartbeat on a locally "
810 "mounted device.\n");
815 if (ocfs2_userspace_stack(osb
)) {
816 if (osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
) {
817 mlog(ML_ERROR
, "Userspace stack expected, but "
818 "o2cb heartbeat arguments passed to mount\n");
823 if (!(osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
)) {
824 if (!ocfs2_mount_local(osb
) && !ocfs2_is_hard_readonly(osb
) &&
825 !ocfs2_userspace_stack(osb
)) {
826 mlog(ML_ERROR
, "Heartbeat has to be started to mount "
827 "a read-write clustered device.\n");
836 * If we're using a userspace stack, mount should have passed
837 * a name that matches the disk. If not, mount should not
838 * have passed a stack.
840 static int ocfs2_verify_userspace_stack(struct ocfs2_super
*osb
,
841 struct mount_options
*mopt
)
843 if (!ocfs2_userspace_stack(osb
) && mopt
->cluster_stack
[0]) {
845 "cluster stack passed to mount, but this filesystem "
846 "does not support it\n");
850 if (ocfs2_userspace_stack(osb
) &&
851 strncmp(osb
->osb_cluster_stack
, mopt
->cluster_stack
,
852 OCFS2_STACK_LABEL_LEN
)) {
854 "cluster stack passed to mount (\"%s\") does not "
855 "match the filesystem (\"%s\")\n",
857 osb
->osb_cluster_stack
);
864 static int ocfs2_susp_quotas(struct ocfs2_super
*osb
, int unsuspend
)
867 struct super_block
*sb
= osb
->sb
;
868 unsigned int feature
[MAXQUOTAS
] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA
,
869 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
};
872 for (type
= 0; type
< MAXQUOTAS
; type
++) {
873 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb
, feature
[type
]))
876 status
= vfs_quota_enable(
877 sb_dqopt(sb
)->files
[type
],
881 status
= vfs_quota_disable(sb
, type
,
887 mlog(ML_ERROR
, "Failed to suspend/unsuspend quotas on "
888 "remount (error = %d).\n", status
);
892 static int ocfs2_enable_quotas(struct ocfs2_super
*osb
)
894 struct inode
*inode
[MAXQUOTAS
] = { NULL
, NULL
};
895 struct super_block
*sb
= osb
->sb
;
896 unsigned int feature
[MAXQUOTAS
] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA
,
897 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
};
898 unsigned int ino
[MAXQUOTAS
] = { LOCAL_USER_QUOTA_SYSTEM_INODE
,
899 LOCAL_GROUP_QUOTA_SYSTEM_INODE
};
903 sb_dqopt(sb
)->flags
|= DQUOT_QUOTA_SYS_FILE
| DQUOT_NEGATIVE_USAGE
;
904 for (type
= 0; type
< MAXQUOTAS
; type
++) {
905 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb
, feature
[type
]))
907 inode
[type
] = ocfs2_get_system_file_inode(osb
, ino
[type
],
913 status
= vfs_quota_enable(inode
[type
], type
, QFMT_OCFS2
,
914 DQUOT_USAGE_ENABLED
);
919 for (type
= 0; type
< MAXQUOTAS
; type
++)
923 ocfs2_disable_quotas(osb
);
924 for (type
= 0; type
< MAXQUOTAS
; type
++)
930 static void ocfs2_disable_quotas(struct ocfs2_super
*osb
)
934 struct super_block
*sb
= osb
->sb
;
936 /* We mostly ignore errors in this function because there's not much
937 * we can do when we see them */
938 for (type
= 0; type
< MAXQUOTAS
; type
++) {
939 if (!sb_has_quota_loaded(sb
, type
))
941 inode
= igrab(sb
->s_dquot
.files
[type
]);
942 /* Turn off quotas. This will remove all dquot structures from
943 * memory and so they will be automatically synced to global
945 vfs_quota_disable(sb
, type
, DQUOT_USAGE_ENABLED
|
946 DQUOT_LIMITS_ENABLED
);
953 /* Handle quota on quotactl */
954 static int ocfs2_quota_on(struct super_block
*sb
, int type
, int format_id
,
955 char *path
, int remount
)
957 unsigned int feature
[MAXQUOTAS
] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA
,
958 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
};
960 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb
, feature
[type
]))
964 return 0; /* Just ignore it has been handled in
966 return vfs_quota_enable(sb_dqopt(sb
)->files
[type
], type
,
967 format_id
, DQUOT_LIMITS_ENABLED
);
970 /* Handle quota off quotactl */
971 static int ocfs2_quota_off(struct super_block
*sb
, int type
, int remount
)
974 return 0; /* Ignore now and handle later in
976 return vfs_quota_disable(sb
, type
, DQUOT_LIMITS_ENABLED
);
979 static const struct quotactl_ops ocfs2_quotactl_ops
= {
980 .quota_on
= ocfs2_quota_on
,
981 .quota_off
= ocfs2_quota_off
,
982 .quota_sync
= vfs_quota_sync
,
983 .get_info
= vfs_get_dqinfo
,
984 .set_info
= vfs_set_dqinfo
,
985 .get_dqblk
= vfs_get_dqblk
,
986 .set_dqblk
= vfs_set_dqblk
,
989 static int ocfs2_fill_super(struct super_block
*sb
, void *data
, int silent
)
992 int status
, sector_size
;
993 struct mount_options parsed_options
;
994 struct inode
*inode
= NULL
;
995 struct ocfs2_super
*osb
= NULL
;
996 struct buffer_head
*bh
= NULL
;
998 struct ocfs2_blockcheck_stats stats
;
1000 mlog_entry("%p, %p, %i", sb
, data
, silent
);
1002 if (!ocfs2_parse_options(sb
, data
, &parsed_options
, 0)) {
1004 goto read_super_error
;
1007 /* probe for superblock */
1008 status
= ocfs2_sb_probe(sb
, &bh
, §or_size
, &stats
);
1010 mlog(ML_ERROR
, "superblock probe failed!\n");
1011 goto read_super_error
;
1014 status
= ocfs2_initialize_super(sb
, bh
, sector_size
, &stats
);
1018 goto read_super_error
;
1023 if (!ocfs2_check_set_options(sb
, &parsed_options
)) {
1025 goto read_super_error
;
1027 osb
->s_mount_opt
= parsed_options
.mount_opt
;
1028 osb
->s_atime_quantum
= parsed_options
.atime_quantum
;
1029 osb
->preferred_slot
= parsed_options
.slot
;
1030 osb
->osb_commit_interval
= parsed_options
.commit_interval
;
1031 osb
->local_alloc_default_bits
= ocfs2_megabytes_to_clusters(sb
, parsed_options
.localalloc_opt
);
1032 osb
->local_alloc_bits
= osb
->local_alloc_default_bits
;
1034 status
= ocfs2_verify_userspace_stack(osb
, &parsed_options
);
1036 goto read_super_error
;
1038 sb
->s_magic
= OCFS2_SUPER_MAGIC
;
1040 sb
->s_flags
= (sb
->s_flags
& ~MS_POSIXACL
) |
1041 ((osb
->s_mount_opt
& OCFS2_MOUNT_POSIX_ACL
) ? MS_POSIXACL
: 0);
1043 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1045 if (bdev_read_only(sb
->s_bdev
)) {
1046 if (!(sb
->s_flags
& MS_RDONLY
)) {
1048 mlog(ML_ERROR
, "Readonly device detected but readonly "
1049 "mount was not specified.\n");
1050 goto read_super_error
;
1053 /* You should not be able to start a local heartbeat
1054 * on a readonly device. */
1055 if (osb
->s_mount_opt
& OCFS2_MOUNT_HB_LOCAL
) {
1057 mlog(ML_ERROR
, "Local heartbeat specified on readonly "
1059 goto read_super_error
;
1062 status
= ocfs2_check_journals_nolocks(osb
);
1064 if (status
== -EROFS
)
1065 mlog(ML_ERROR
, "Recovery required on readonly "
1066 "file system, but write access is "
1070 goto read_super_error
;
1073 ocfs2_set_ro_flag(osb
, 1);
1075 printk(KERN_NOTICE
"Readonly device detected. No cluster "
1076 "services will be utilized for this mount. Recovery "
1077 "will be skipped.\n");
1080 if (!ocfs2_is_hard_readonly(osb
)) {
1081 if (sb
->s_flags
& MS_RDONLY
)
1082 ocfs2_set_ro_flag(osb
, 0);
1085 status
= ocfs2_verify_heartbeat(osb
);
1088 goto read_super_error
;
1091 osb
->osb_debug_root
= debugfs_create_dir(osb
->uuid_str
,
1092 ocfs2_debugfs_root
);
1093 if (!osb
->osb_debug_root
) {
1095 mlog(ML_ERROR
, "Unable to create per-mount debugfs root.\n");
1096 goto read_super_error
;
1099 osb
->osb_ctxt
= debugfs_create_file("fs_state", S_IFREG
|S_IRUSR
,
1100 osb
->osb_debug_root
,
1102 &ocfs2_osb_debug_fops
);
1103 if (!osb
->osb_ctxt
) {
1106 goto read_super_error
;
1109 if (ocfs2_meta_ecc(osb
)) {
1110 status
= ocfs2_blockcheck_stats_debugfs_install(
1111 &osb
->osb_ecc_stats
,
1112 osb
->osb_debug_root
);
1115 "Unable to create blockcheck statistics "
1117 goto read_super_error
;
1121 status
= ocfs2_mount_volume(sb
);
1122 if (osb
->root_inode
)
1123 inode
= igrab(osb
->root_inode
);
1126 goto read_super_error
;
1131 goto read_super_error
;
1134 root
= d_alloc_root(inode
);
1138 goto read_super_error
;
1143 ocfs2_complete_mount_recovery(osb
);
1145 if (ocfs2_mount_local(osb
))
1146 snprintf(nodestr
, sizeof(nodestr
), "local");
1148 snprintf(nodestr
, sizeof(nodestr
), "%u", osb
->node_num
);
1150 printk(KERN_INFO
"ocfs2: Mounting device (%s) on (node %s, slot %d) "
1151 "with %s data mode.\n",
1152 osb
->dev_str
, nodestr
, osb
->slot_num
,
1153 osb
->s_mount_opt
& OCFS2_MOUNT_DATA_WRITEBACK
? "writeback" :
1156 atomic_set(&osb
->vol_state
, VOLUME_MOUNTED
);
1157 wake_up(&osb
->osb_mount_event
);
1159 /* Now we can initialize quotas because we can afford to wait
1160 * for cluster locks recovery now. That also means that truncation
1161 * log recovery can happen but that waits for proper quota setup */
1162 if (!(sb
->s_flags
& MS_RDONLY
)) {
1163 status
= ocfs2_enable_quotas(osb
);
1165 /* We have to err-out specially here because
1166 * s_root is already set */
1168 atomic_set(&osb
->vol_state
, VOLUME_DISABLED
);
1169 wake_up(&osb
->osb_mount_event
);
1175 ocfs2_complete_quota_recovery(osb
);
1177 /* Now we wake up again for processes waiting for quotas */
1178 atomic_set(&osb
->vol_state
, VOLUME_MOUNTED_QUOTAS
);
1179 wake_up(&osb
->osb_mount_event
);
1181 /* Start this when the mount is almost sure of being successful */
1182 ocfs2_orphan_scan_start(osb
);
1194 atomic_set(&osb
->vol_state
, VOLUME_DISABLED
);
1195 wake_up(&osb
->osb_mount_event
);
1196 ocfs2_dismount_volume(sb
, 1);
1203 static int ocfs2_get_sb(struct file_system_type
*fs_type
,
1205 const char *dev_name
,
1207 struct vfsmount
*mnt
)
1209 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, ocfs2_fill_super
,
1213 static void ocfs2_kill_sb(struct super_block
*sb
)
1215 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
1218 if (!osb
|| atomic_read(&osb
->vol_state
) == VOLUME_DISABLED
)
1221 /* Prevent further queueing of inode drop events */
1222 spin_lock(&dentry_list_lock
);
1223 ocfs2_set_osb_flag(osb
, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED
);
1224 spin_unlock(&dentry_list_lock
);
1225 /* Wait for work to finish and/or remove it */
1226 cancel_work_sync(&osb
->dentry_lock_work
);
1228 kill_block_super(sb
);
1231 static struct file_system_type ocfs2_fs_type
= {
1232 .owner
= THIS_MODULE
,
1234 .get_sb
= ocfs2_get_sb
, /* is this called when we mount
1236 .kill_sb
= ocfs2_kill_sb
,
1238 .fs_flags
= FS_REQUIRES_DEV
|FS_RENAME_DOES_D_MOVE
,
1242 static int ocfs2_check_set_options(struct super_block
*sb
,
1243 struct mount_options
*options
)
1245 if (options
->mount_opt
& OCFS2_MOUNT_USRQUOTA
&&
1246 !OCFS2_HAS_RO_COMPAT_FEATURE(sb
,
1247 OCFS2_FEATURE_RO_COMPAT_USRQUOTA
)) {
1248 mlog(ML_ERROR
, "User quotas were requested, but this "
1249 "filesystem does not have the feature enabled.\n");
1252 if (options
->mount_opt
& OCFS2_MOUNT_GRPQUOTA
&&
1253 !OCFS2_HAS_RO_COMPAT_FEATURE(sb
,
1254 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
)) {
1255 mlog(ML_ERROR
, "Group quotas were requested, but this "
1256 "filesystem does not have the feature enabled.\n");
1259 if (options
->mount_opt
& OCFS2_MOUNT_POSIX_ACL
&&
1260 !OCFS2_HAS_INCOMPAT_FEATURE(sb
, OCFS2_FEATURE_INCOMPAT_XATTR
)) {
1261 mlog(ML_ERROR
, "ACL support requested but extended attributes "
1262 "feature is not enabled\n");
1265 /* No ACL setting specified? Use XATTR feature... */
1266 if (!(options
->mount_opt
& (OCFS2_MOUNT_POSIX_ACL
|
1267 OCFS2_MOUNT_NO_POSIX_ACL
))) {
1268 if (OCFS2_HAS_INCOMPAT_FEATURE(sb
, OCFS2_FEATURE_INCOMPAT_XATTR
))
1269 options
->mount_opt
|= OCFS2_MOUNT_POSIX_ACL
;
1271 options
->mount_opt
|= OCFS2_MOUNT_NO_POSIX_ACL
;
1276 static int ocfs2_parse_options(struct super_block
*sb
,
1278 struct mount_options
*mopt
,
1284 mlog_entry("remount: %d, options: \"%s\"\n", is_remount
,
1285 options
? options
: "(none)");
1287 mopt
->commit_interval
= 0;
1288 mopt
->mount_opt
= 0;
1289 mopt
->atime_quantum
= OCFS2_DEFAULT_ATIME_QUANTUM
;
1290 mopt
->slot
= OCFS2_INVALID_SLOT
;
1291 mopt
->localalloc_opt
= OCFS2_DEFAULT_LOCAL_ALLOC_SIZE
;
1292 mopt
->cluster_stack
[0] = '\0';
1299 while ((p
= strsep(&options
, ",")) != NULL
) {
1301 substring_t args
[MAX_OPT_ARGS
];
1306 token
= match_token(p
, tokens
, args
);
1309 mopt
->mount_opt
|= OCFS2_MOUNT_HB_LOCAL
;
1312 mopt
->mount_opt
&= ~OCFS2_MOUNT_HB_LOCAL
;
1315 if (match_int(&args
[0], &option
)) {
1320 mopt
->mount_opt
|= OCFS2_MOUNT_BARRIER
;
1322 mopt
->mount_opt
&= ~OCFS2_MOUNT_BARRIER
;
1325 mopt
->mount_opt
&= ~OCFS2_MOUNT_NOINTR
;
1328 mopt
->mount_opt
|= OCFS2_MOUNT_NOINTR
;
1331 mopt
->mount_opt
|= OCFS2_MOUNT_ERRORS_PANIC
;
1334 mopt
->mount_opt
&= ~OCFS2_MOUNT_ERRORS_PANIC
;
1336 case Opt_data_ordered
:
1337 mopt
->mount_opt
&= ~OCFS2_MOUNT_DATA_WRITEBACK
;
1339 case Opt_data_writeback
:
1340 mopt
->mount_opt
|= OCFS2_MOUNT_DATA_WRITEBACK
;
1342 case Opt_user_xattr
:
1343 mopt
->mount_opt
&= ~OCFS2_MOUNT_NOUSERXATTR
;
1345 case Opt_nouser_xattr
:
1346 mopt
->mount_opt
|= OCFS2_MOUNT_NOUSERXATTR
;
1348 case Opt_atime_quantum
:
1349 if (match_int(&args
[0], &option
)) {
1354 mopt
->atime_quantum
= option
;
1358 if (match_int(&args
[0], &option
)) {
1363 mopt
->slot
= (s16
)option
;
1367 if (match_int(&args
[0], &option
)) {
1374 option
= JBD2_DEFAULT_MAX_COMMIT_AGE
;
1375 mopt
->commit_interval
= HZ
* option
;
1377 case Opt_localalloc
:
1379 if (match_int(&args
[0], &option
)) {
1383 if (option
>= 0 && (option
<= ocfs2_local_alloc_size(sb
) * 8))
1384 mopt
->localalloc_opt
= option
;
1386 case Opt_localflocks
:
1388 * Changing this during remount could race
1389 * flock() requests, or "unbalance" existing
1390 * ones (e.g., a lock is taken in one mode but
1391 * dropped in the other). If users care enough
1392 * to flip locking modes during remount, we
1393 * could add a "local" flag to individual
1394 * flock structures for proper tracking of
1398 mopt
->mount_opt
|= OCFS2_MOUNT_LOCALFLOCKS
;
1401 /* Check both that the option we were passed
1402 * is of the right length and that it is a proper
1403 * string of the right length.
1405 if (((args
[0].to
- args
[0].from
) !=
1406 OCFS2_STACK_LABEL_LEN
) ||
1407 (strnlen(args
[0].from
,
1408 OCFS2_STACK_LABEL_LEN
) !=
1409 OCFS2_STACK_LABEL_LEN
)) {
1411 "Invalid cluster_stack option\n");
1415 memcpy(mopt
->cluster_stack
, args
[0].from
,
1416 OCFS2_STACK_LABEL_LEN
);
1417 mopt
->cluster_stack
[OCFS2_STACK_LABEL_LEN
] = '\0';
1420 mopt
->mount_opt
|= OCFS2_MOUNT_INODE64
;
1423 mopt
->mount_opt
|= OCFS2_MOUNT_USRQUOTA
;
1426 mopt
->mount_opt
|= OCFS2_MOUNT_GRPQUOTA
;
1429 mopt
->mount_opt
|= OCFS2_MOUNT_POSIX_ACL
;
1430 mopt
->mount_opt
&= ~OCFS2_MOUNT_NO_POSIX_ACL
;
1433 mopt
->mount_opt
|= OCFS2_MOUNT_NO_POSIX_ACL
;
1434 mopt
->mount_opt
&= ~OCFS2_MOUNT_POSIX_ACL
;
1438 "Unrecognized mount option \"%s\" "
1439 "or missing value\n", p
);
1452 static int ocfs2_show_options(struct seq_file
*s
, struct vfsmount
*mnt
)
1454 struct ocfs2_super
*osb
= OCFS2_SB(mnt
->mnt_sb
);
1455 unsigned long opts
= osb
->s_mount_opt
;
1456 unsigned int local_alloc_megs
;
1458 if (opts
& OCFS2_MOUNT_HB_LOCAL
)
1459 seq_printf(s
, ",_netdev,heartbeat=local");
1461 seq_printf(s
, ",heartbeat=none");
1463 if (opts
& OCFS2_MOUNT_NOINTR
)
1464 seq_printf(s
, ",nointr");
1466 if (opts
& OCFS2_MOUNT_DATA_WRITEBACK
)
1467 seq_printf(s
, ",data=writeback");
1469 seq_printf(s
, ",data=ordered");
1471 if (opts
& OCFS2_MOUNT_BARRIER
)
1472 seq_printf(s
, ",barrier=1");
1474 if (opts
& OCFS2_MOUNT_ERRORS_PANIC
)
1475 seq_printf(s
, ",errors=panic");
1477 seq_printf(s
, ",errors=remount-ro");
1479 if (osb
->preferred_slot
!= OCFS2_INVALID_SLOT
)
1480 seq_printf(s
, ",preferred_slot=%d", osb
->preferred_slot
);
1482 if (osb
->s_atime_quantum
!= OCFS2_DEFAULT_ATIME_QUANTUM
)
1483 seq_printf(s
, ",atime_quantum=%u", osb
->s_atime_quantum
);
1485 if (osb
->osb_commit_interval
)
1486 seq_printf(s
, ",commit=%u",
1487 (unsigned) (osb
->osb_commit_interval
/ HZ
));
1489 local_alloc_megs
= osb
->local_alloc_bits
>> (20 - osb
->s_clustersize_bits
);
1490 if (local_alloc_megs
!= OCFS2_DEFAULT_LOCAL_ALLOC_SIZE
)
1491 seq_printf(s
, ",localalloc=%d", local_alloc_megs
);
1493 if (opts
& OCFS2_MOUNT_LOCALFLOCKS
)
1494 seq_printf(s
, ",localflocks,");
1496 if (osb
->osb_cluster_stack
[0])
1497 seq_printf(s
, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN
,
1498 osb
->osb_cluster_stack
);
1499 if (opts
& OCFS2_MOUNT_USRQUOTA
)
1500 seq_printf(s
, ",usrquota");
1501 if (opts
& OCFS2_MOUNT_GRPQUOTA
)
1502 seq_printf(s
, ",grpquota");
1504 if (opts
& OCFS2_MOUNT_NOUSERXATTR
)
1505 seq_printf(s
, ",nouser_xattr");
1507 seq_printf(s
, ",user_xattr");
1509 if (opts
& OCFS2_MOUNT_INODE64
)
1510 seq_printf(s
, ",inode64");
1512 if (opts
& OCFS2_MOUNT_POSIX_ACL
)
1513 seq_printf(s
, ",acl");
1515 seq_printf(s
, ",noacl");
1520 static int __init
ocfs2_init(void)
1526 ocfs2_print_version();
1528 status
= init_ocfs2_uptodate_cache();
1534 status
= ocfs2_initialize_mem_caches();
1540 ocfs2_wq
= create_singlethread_workqueue("ocfs2_wq");
1546 ocfs2_debugfs_root
= debugfs_create_dir("ocfs2", NULL
);
1547 if (!ocfs2_debugfs_root
) {
1549 mlog(ML_ERROR
, "Unable to create ocfs2 debugfs root.\n");
1552 status
= ocfs2_quota_setup();
1556 ocfs2_set_locking_protocol();
1558 status
= register_quota_format(&ocfs2_quota_format
);
1561 ocfs2_quota_shutdown();
1562 ocfs2_free_mem_caches();
1563 exit_ocfs2_uptodate_cache();
1569 return register_filesystem(&ocfs2_fs_type
);
1574 static void __exit
ocfs2_exit(void)
1578 ocfs2_quota_shutdown();
1581 flush_workqueue(ocfs2_wq
);
1582 destroy_workqueue(ocfs2_wq
);
1585 unregister_quota_format(&ocfs2_quota_format
);
1587 debugfs_remove(ocfs2_debugfs_root
);
1589 ocfs2_free_mem_caches();
1591 unregister_filesystem(&ocfs2_fs_type
);
1593 exit_ocfs2_uptodate_cache();
1598 static void ocfs2_put_super(struct super_block
*sb
)
1600 mlog_entry("(0x%p)\n", sb
);
1604 ocfs2_sync_blockdev(sb
);
1605 ocfs2_dismount_volume(sb
, 0);
1612 static int ocfs2_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1614 struct ocfs2_super
*osb
;
1615 u32 numbits
, freebits
;
1617 struct ocfs2_dinode
*bm_lock
;
1618 struct buffer_head
*bh
= NULL
;
1619 struct inode
*inode
= NULL
;
1621 mlog_entry("(%p, %p)\n", dentry
->d_sb
, buf
);
1623 osb
= OCFS2_SB(dentry
->d_sb
);
1625 inode
= ocfs2_get_system_file_inode(osb
,
1626 GLOBAL_BITMAP_SYSTEM_INODE
,
1627 OCFS2_INVALID_SLOT
);
1629 mlog(ML_ERROR
, "failed to get bitmap inode\n");
1634 status
= ocfs2_inode_lock(inode
, &bh
, 0);
1640 bm_lock
= (struct ocfs2_dinode
*) bh
->b_data
;
1642 numbits
= le32_to_cpu(bm_lock
->id1
.bitmap1
.i_total
);
1643 freebits
= numbits
- le32_to_cpu(bm_lock
->id1
.bitmap1
.i_used
);
1645 buf
->f_type
= OCFS2_SUPER_MAGIC
;
1646 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
1647 buf
->f_namelen
= OCFS2_MAX_FILENAME_LEN
;
1648 buf
->f_blocks
= ((sector_t
) numbits
) *
1649 (osb
->s_clustersize
>> osb
->sb
->s_blocksize_bits
);
1650 buf
->f_bfree
= ((sector_t
) freebits
) *
1651 (osb
->s_clustersize
>> osb
->sb
->s_blocksize_bits
);
1652 buf
->f_bavail
= buf
->f_bfree
;
1653 buf
->f_files
= numbits
;
1654 buf
->f_ffree
= freebits
;
1655 buf
->f_fsid
.val
[0] = crc32_le(0, osb
->uuid_str
, OCFS2_VOL_UUID_LEN
)
1657 buf
->f_fsid
.val
[1] = crc32_le(0, osb
->uuid_str
+ OCFS2_VOL_UUID_LEN
,
1658 OCFS2_VOL_UUID_LEN
) & 0xFFFFFFFFUL
;
1662 ocfs2_inode_unlock(inode
, 0);
1673 static void ocfs2_inode_init_once(void *data
)
1675 struct ocfs2_inode_info
*oi
= data
;
1678 oi
->ip_open_count
= 0;
1679 spin_lock_init(&oi
->ip_lock
);
1680 ocfs2_extent_map_init(&oi
->vfs_inode
);
1681 INIT_LIST_HEAD(&oi
->ip_io_markers
);
1682 oi
->ip_dir_start_lookup
= 0;
1684 init_rwsem(&oi
->ip_alloc_sem
);
1685 init_rwsem(&oi
->ip_xattr_sem
);
1686 mutex_init(&oi
->ip_io_mutex
);
1688 oi
->ip_blkno
= 0ULL;
1689 oi
->ip_clusters
= 0;
1691 ocfs2_lock_res_init_once(&oi
->ip_rw_lockres
);
1692 ocfs2_lock_res_init_once(&oi
->ip_inode_lockres
);
1693 ocfs2_lock_res_init_once(&oi
->ip_open_lockres
);
1695 ocfs2_metadata_cache_init(INODE_CACHE(&oi
->vfs_inode
),
1696 &ocfs2_inode_caching_ops
);
1698 inode_init_once(&oi
->vfs_inode
);
1701 static int ocfs2_initialize_mem_caches(void)
1703 ocfs2_inode_cachep
= kmem_cache_create("ocfs2_inode_cache",
1704 sizeof(struct ocfs2_inode_info
),
1706 (SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
|
1708 ocfs2_inode_init_once
);
1709 ocfs2_dquot_cachep
= kmem_cache_create("ocfs2_dquot_cache",
1710 sizeof(struct ocfs2_dquot
),
1712 (SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
|
1715 ocfs2_qf_chunk_cachep
= kmem_cache_create("ocfs2_qf_chunk_cache",
1716 sizeof(struct ocfs2_quota_chunk
),
1718 (SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
),
1720 if (!ocfs2_inode_cachep
|| !ocfs2_dquot_cachep
||
1721 !ocfs2_qf_chunk_cachep
) {
1722 if (ocfs2_inode_cachep
)
1723 kmem_cache_destroy(ocfs2_inode_cachep
);
1724 if (ocfs2_dquot_cachep
)
1725 kmem_cache_destroy(ocfs2_dquot_cachep
);
1726 if (ocfs2_qf_chunk_cachep
)
1727 kmem_cache_destroy(ocfs2_qf_chunk_cachep
);
1734 static void ocfs2_free_mem_caches(void)
1736 if (ocfs2_inode_cachep
)
1737 kmem_cache_destroy(ocfs2_inode_cachep
);
1738 ocfs2_inode_cachep
= NULL
;
1740 if (ocfs2_dquot_cachep
)
1741 kmem_cache_destroy(ocfs2_dquot_cachep
);
1742 ocfs2_dquot_cachep
= NULL
;
1744 if (ocfs2_qf_chunk_cachep
)
1745 kmem_cache_destroy(ocfs2_qf_chunk_cachep
);
1746 ocfs2_qf_chunk_cachep
= NULL
;
1749 static int ocfs2_get_sector(struct super_block
*sb
,
1750 struct buffer_head
**bh
,
1754 if (!sb_set_blocksize(sb
, sect_size
)) {
1755 mlog(ML_ERROR
, "unable to set blocksize\n");
1759 *bh
= sb_getblk(sb
, block
);
1765 if (!buffer_dirty(*bh
))
1766 clear_buffer_uptodate(*bh
);
1768 ll_rw_block(READ
, 1, bh
);
1769 wait_on_buffer(*bh
);
1770 if (!buffer_uptodate(*bh
)) {
1780 static int ocfs2_mount_volume(struct super_block
*sb
)
1783 int unlock_super
= 0;
1784 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
1788 if (ocfs2_is_hard_readonly(osb
))
1791 status
= ocfs2_dlm_init(osb
);
1797 status
= ocfs2_super_lock(osb
, 1);
1804 /* This will load up the node map and add ourselves to it. */
1805 status
= ocfs2_find_slot(osb
);
1811 /* load all node-local system inodes */
1812 status
= ocfs2_init_local_system_inodes(osb
);
1818 status
= ocfs2_check_volume(osb
);
1824 status
= ocfs2_truncate_log_init(osb
);
1830 ocfs2_super_unlock(osb
, 1);
1836 static void ocfs2_dismount_volume(struct super_block
*sb
, int mnt_err
)
1838 int tmp
, hangup_needed
= 0;
1839 struct ocfs2_super
*osb
= NULL
;
1842 mlog_entry("(0x%p)\n", sb
);
1848 debugfs_remove(osb
->osb_ctxt
);
1851 * Flush inode dropping work queue so that deletes are
1852 * performed while the filesystem is still working
1854 ocfs2_drop_all_dl_inodes(osb
);
1856 /* Orphan scan should be stopped as early as possible */
1857 ocfs2_orphan_scan_stop(osb
);
1859 ocfs2_disable_quotas(osb
);
1861 ocfs2_shutdown_local_alloc(osb
);
1863 ocfs2_truncate_log_shutdown(osb
);
1865 /* This will disable recovery and flush any recovery work. */
1866 ocfs2_recovery_exit(osb
);
1868 ocfs2_journal_shutdown(osb
);
1870 ocfs2_sync_blockdev(sb
);
1872 ocfs2_purge_refcount_trees(osb
);
1874 /* No cluster connection means we've failed during mount, so skip
1875 * all the steps which depended on that to complete. */
1877 tmp
= ocfs2_super_lock(osb
, 1);
1884 if (osb
->slot_num
!= OCFS2_INVALID_SLOT
)
1885 ocfs2_put_slot(osb
);
1888 ocfs2_super_unlock(osb
, 1);
1890 ocfs2_release_system_inodes(osb
);
1893 * If we're dismounting due to mount error, mount.ocfs2 will clean
1894 * up heartbeat. If we're a local mount, there is no heartbeat.
1895 * If we failed before we got a uuid_str yet, we can't stop
1896 * heartbeat. Otherwise, do it.
1898 if (!mnt_err
&& !ocfs2_mount_local(osb
) && osb
->uuid_str
)
1902 ocfs2_dlm_shutdown(osb
, hangup_needed
);
1904 ocfs2_blockcheck_stats_debugfs_remove(&osb
->osb_ecc_stats
);
1905 debugfs_remove(osb
->osb_debug_root
);
1908 ocfs2_cluster_hangup(osb
->uuid_str
, strlen(osb
->uuid_str
));
1910 atomic_set(&osb
->vol_state
, VOLUME_DISMOUNTED
);
1912 if (ocfs2_mount_local(osb
))
1913 snprintf(nodestr
, sizeof(nodestr
), "local");
1915 snprintf(nodestr
, sizeof(nodestr
), "%u", osb
->node_num
);
1917 printk(KERN_INFO
"ocfs2: Unmounting device (%s) on (node %s)\n",
1918 osb
->dev_str
, nodestr
);
1920 ocfs2_delete_osb(osb
);
1923 sb
->s_fs_info
= NULL
;
1926 static int ocfs2_setup_osb_uuid(struct ocfs2_super
*osb
, const unsigned char *uuid
,
1927 unsigned uuid_bytes
)
1932 BUG_ON(uuid_bytes
!= OCFS2_VOL_UUID_LEN
);
1934 osb
->uuid_str
= kzalloc(OCFS2_VOL_UUID_LEN
* 2 + 1, GFP_KERNEL
);
1935 if (osb
->uuid_str
== NULL
)
1938 for (i
= 0, ptr
= osb
->uuid_str
; i
< OCFS2_VOL_UUID_LEN
; i
++) {
1939 /* print with null */
1940 ret
= snprintf(ptr
, 3, "%02X", uuid
[i
]);
1941 if (ret
!= 2) /* drop super cleans up */
1943 /* then only advance past the last char */
1950 static int ocfs2_initialize_super(struct super_block
*sb
,
1951 struct buffer_head
*bh
,
1953 struct ocfs2_blockcheck_stats
*stats
)
1956 int i
, cbits
, bbits
;
1957 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)bh
->b_data
;
1958 struct inode
*inode
= NULL
;
1959 struct ocfs2_journal
*journal
;
1960 __le32 uuid_net_key
;
1961 struct ocfs2_super
*osb
;
1965 osb
= kzalloc(sizeof(struct ocfs2_super
), GFP_KERNEL
);
1972 sb
->s_fs_info
= osb
;
1973 sb
->s_op
= &ocfs2_sops
;
1974 sb
->s_export_op
= &ocfs2_export_ops
;
1975 sb
->s_qcop
= &ocfs2_quotactl_ops
;
1976 sb
->dq_op
= &ocfs2_quota_operations
;
1977 sb
->s_xattr
= ocfs2_xattr_handlers
;
1978 sb
->s_time_gran
= 1;
1979 sb
->s_flags
|= MS_NOATIME
;
1980 /* this is needed to support O_LARGEFILE */
1981 cbits
= le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
);
1982 bbits
= le32_to_cpu(di
->id2
.i_super
.s_blocksize_bits
);
1983 sb
->s_maxbytes
= ocfs2_max_file_offset(bbits
, cbits
);
1985 osb
->osb_dx_mask
= (1 << (cbits
- bbits
)) - 1;
1987 for (i
= 0; i
< 3; i
++)
1988 osb
->osb_dx_seed
[i
] = le32_to_cpu(di
->id2
.i_super
.s_dx_seed
[i
]);
1989 osb
->osb_dx_seed
[3] = le32_to_cpu(di
->id2
.i_super
.s_uuid_hash
);
1992 /* Save off for ocfs2_rw_direct */
1993 osb
->s_sectsize_bits
= blksize_bits(sector_size
);
1994 BUG_ON(!osb
->s_sectsize_bits
);
1996 spin_lock_init(&osb
->dc_task_lock
);
1997 init_waitqueue_head(&osb
->dc_event
);
1998 osb
->dc_work_sequence
= 0;
1999 osb
->dc_wake_sequence
= 0;
2000 INIT_LIST_HEAD(&osb
->blocked_lock_list
);
2001 osb
->blocked_lock_count
= 0;
2002 spin_lock_init(&osb
->osb_lock
);
2003 spin_lock_init(&osb
->osb_xattr_lock
);
2004 ocfs2_init_steal_slots(osb
);
2006 atomic_set(&osb
->alloc_stats
.moves
, 0);
2007 atomic_set(&osb
->alloc_stats
.local_data
, 0);
2008 atomic_set(&osb
->alloc_stats
.bitmap_data
, 0);
2009 atomic_set(&osb
->alloc_stats
.bg_allocs
, 0);
2010 atomic_set(&osb
->alloc_stats
.bg_extends
, 0);
2012 /* Copy the blockcheck stats from the superblock probe */
2013 osb
->osb_ecc_stats
= *stats
;
2015 ocfs2_init_node_maps(osb
);
2017 snprintf(osb
->dev_str
, sizeof(osb
->dev_str
), "%u,%u",
2018 MAJOR(osb
->sb
->s_dev
), MINOR(osb
->sb
->s_dev
));
2020 ocfs2_orphan_scan_init(osb
);
2022 status
= ocfs2_recovery_init(osb
);
2024 mlog(ML_ERROR
, "Unable to initialize recovery state\n");
2029 init_waitqueue_head(&osb
->checkpoint_event
);
2030 atomic_set(&osb
->needs_checkpoint
, 0);
2032 osb
->s_atime_quantum
= OCFS2_DEFAULT_ATIME_QUANTUM
;
2034 osb
->slot_num
= OCFS2_INVALID_SLOT
;
2036 osb
->s_xattr_inline_size
= le16_to_cpu(
2037 di
->id2
.i_super
.s_xattr_inline_size
);
2039 osb
->local_alloc_state
= OCFS2_LA_UNUSED
;
2040 osb
->local_alloc_bh
= NULL
;
2041 INIT_DELAYED_WORK(&osb
->la_enable_wq
, ocfs2_la_enable_worker
);
2043 init_waitqueue_head(&osb
->osb_mount_event
);
2045 osb
->vol_label
= kmalloc(OCFS2_MAX_VOL_LABEL_LEN
, GFP_KERNEL
);
2046 if (!osb
->vol_label
) {
2047 mlog(ML_ERROR
, "unable to alloc vol label\n");
2052 osb
->max_slots
= le16_to_cpu(di
->id2
.i_super
.s_max_slots
);
2053 if (osb
->max_slots
> OCFS2_MAX_SLOTS
|| osb
->max_slots
== 0) {
2054 mlog(ML_ERROR
, "Invalid number of node slots (%u)\n",
2059 mlog(0, "max_slots for this device: %u\n", osb
->max_slots
);
2061 osb
->slot_recovery_generations
=
2062 kcalloc(osb
->max_slots
, sizeof(*osb
->slot_recovery_generations
),
2064 if (!osb
->slot_recovery_generations
) {
2070 init_waitqueue_head(&osb
->osb_wipe_event
);
2071 osb
->osb_orphan_wipes
= kcalloc(osb
->max_slots
,
2072 sizeof(*osb
->osb_orphan_wipes
),
2074 if (!osb
->osb_orphan_wipes
) {
2080 osb
->osb_rf_lock_tree
= RB_ROOT
;
2082 osb
->s_feature_compat
=
2083 le32_to_cpu(OCFS2_RAW_SB(di
)->s_feature_compat
);
2084 osb
->s_feature_ro_compat
=
2085 le32_to_cpu(OCFS2_RAW_SB(di
)->s_feature_ro_compat
);
2086 osb
->s_feature_incompat
=
2087 le32_to_cpu(OCFS2_RAW_SB(di
)->s_feature_incompat
);
2089 if ((i
= OCFS2_HAS_INCOMPAT_FEATURE(osb
->sb
, ~OCFS2_FEATURE_INCOMPAT_SUPP
))) {
2090 mlog(ML_ERROR
, "couldn't mount because of unsupported "
2091 "optional features (%x).\n", i
);
2095 if (!(osb
->sb
->s_flags
& MS_RDONLY
) &&
2096 (i
= OCFS2_HAS_RO_COMPAT_FEATURE(osb
->sb
, ~OCFS2_FEATURE_RO_COMPAT_SUPP
))) {
2097 mlog(ML_ERROR
, "couldn't mount RDWR because of "
2098 "unsupported optional features (%x).\n", i
);
2103 if (ocfs2_userspace_stack(osb
)) {
2104 memcpy(osb
->osb_cluster_stack
,
2105 OCFS2_RAW_SB(di
)->s_cluster_info
.ci_stack
,
2106 OCFS2_STACK_LABEL_LEN
);
2107 osb
->osb_cluster_stack
[OCFS2_STACK_LABEL_LEN
] = '\0';
2108 if (strlen(osb
->osb_cluster_stack
) != OCFS2_STACK_LABEL_LEN
) {
2110 "couldn't mount because of an invalid "
2111 "cluster stack label (%s) \n",
2112 osb
->osb_cluster_stack
);
2117 /* The empty string is identical with classic tools that
2118 * don't know about s_cluster_info. */
2119 osb
->osb_cluster_stack
[0] = '\0';
2122 get_random_bytes(&osb
->s_next_generation
, sizeof(u32
));
2125 * This should be done in ocfs2_journal_init(), but unknown
2126 * ordering issues will cause the filesystem to crash.
2127 * If anyone wants to figure out what part of the code
2128 * refers to osb->journal before ocfs2_journal_init() is run,
2131 /* initialize our journal structure */
2133 journal
= kzalloc(sizeof(struct ocfs2_journal
), GFP_KERNEL
);
2135 mlog(ML_ERROR
, "unable to alloc journal\n");
2139 osb
->journal
= journal
;
2140 journal
->j_osb
= osb
;
2142 atomic_set(&journal
->j_num_trans
, 0);
2143 init_rwsem(&journal
->j_trans_barrier
);
2144 init_waitqueue_head(&journal
->j_checkpointed
);
2145 spin_lock_init(&journal
->j_lock
);
2146 journal
->j_trans_id
= (unsigned long) 1;
2147 INIT_LIST_HEAD(&journal
->j_la_cleanups
);
2148 INIT_WORK(&journal
->j_recovery_work
, ocfs2_complete_recovery
);
2149 journal
->j_state
= OCFS2_JOURNAL_FREE
;
2151 INIT_WORK(&osb
->dentry_lock_work
, ocfs2_drop_dl_inodes
);
2152 osb
->dentry_lock_list
= NULL
;
2154 /* get some pseudo constants for clustersize bits */
2155 osb
->s_clustersize_bits
=
2156 le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
);
2157 osb
->s_clustersize
= 1 << osb
->s_clustersize_bits
;
2158 mlog(0, "clusterbits=%d\n", osb
->s_clustersize_bits
);
2160 if (osb
->s_clustersize
< OCFS2_MIN_CLUSTERSIZE
||
2161 osb
->s_clustersize
> OCFS2_MAX_CLUSTERSIZE
) {
2162 mlog(ML_ERROR
, "Volume has invalid cluster size (%d)\n",
2163 osb
->s_clustersize
);
2168 if (ocfs2_clusters_to_blocks(osb
->sb
, le32_to_cpu(di
->i_clusters
) - 1)
2170 mlog(ML_ERROR
, "Volume might try to write to blocks beyond "
2171 "what jbd can address in 32 bits.\n");
2176 if (ocfs2_setup_osb_uuid(osb
, di
->id2
.i_super
.s_uuid
,
2177 sizeof(di
->id2
.i_super
.s_uuid
))) {
2178 mlog(ML_ERROR
, "Out of memory trying to setup our uuid.\n");
2183 memcpy(&uuid_net_key
, di
->id2
.i_super
.s_uuid
, sizeof(uuid_net_key
));
2185 strncpy(osb
->vol_label
, di
->id2
.i_super
.s_label
, 63);
2186 osb
->vol_label
[63] = '\0';
2187 osb
->root_blkno
= le64_to_cpu(di
->id2
.i_super
.s_root_blkno
);
2188 osb
->system_dir_blkno
= le64_to_cpu(di
->id2
.i_super
.s_system_dir_blkno
);
2189 osb
->first_cluster_group_blkno
=
2190 le64_to_cpu(di
->id2
.i_super
.s_first_cluster_group
);
2191 osb
->fs_generation
= le32_to_cpu(di
->i_fs_generation
);
2192 osb
->uuid_hash
= le32_to_cpu(di
->id2
.i_super
.s_uuid_hash
);
2193 mlog(0, "vol_label: %s\n", osb
->vol_label
);
2194 mlog(0, "uuid: %s\n", osb
->uuid_str
);
2195 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2196 (unsigned long long)osb
->root_blkno
,
2197 (unsigned long long)osb
->system_dir_blkno
);
2199 osb
->osb_dlm_debug
= ocfs2_new_dlm_debug();
2200 if (!osb
->osb_dlm_debug
) {
2206 atomic_set(&osb
->vol_state
, VOLUME_INIT
);
2208 /* load root, system_dir, and all global system inodes */
2209 status
= ocfs2_init_global_system_inodes(osb
);
2218 inode
= ocfs2_get_system_file_inode(osb
, GLOBAL_BITMAP_SYSTEM_INODE
,
2219 OCFS2_INVALID_SLOT
);
2226 osb
->bitmap_blkno
= OCFS2_I(inode
)->ip_blkno
;
2229 osb
->bitmap_cpg
= ocfs2_group_bitmap_size(sb
) * 8;
2231 status
= ocfs2_init_slot_info(osb
);
2243 * will return: -EAGAIN if it is ok to keep searching for superblocks
2244 * -EINVAL if there is a bad superblock
2247 static int ocfs2_verify_volume(struct ocfs2_dinode
*di
,
2248 struct buffer_head
*bh
,
2250 struct ocfs2_blockcheck_stats
*stats
)
2252 int status
= -EAGAIN
;
2256 if (memcmp(di
->i_signature
, OCFS2_SUPER_BLOCK_SIGNATURE
,
2257 strlen(OCFS2_SUPER_BLOCK_SIGNATURE
)) == 0) {
2258 /* We have to do a raw check of the feature here */
2259 if (le32_to_cpu(di
->id2
.i_super
.s_feature_incompat
) &
2260 OCFS2_FEATURE_INCOMPAT_META_ECC
) {
2261 status
= ocfs2_block_check_validate(bh
->b_data
,
2269 if ((1 << le32_to_cpu(di
->id2
.i_super
.s_blocksize_bits
)) != blksz
) {
2270 mlog(ML_ERROR
, "found superblock with incorrect block "
2271 "size: found %u, should be %u\n",
2272 1 << le32_to_cpu(di
->id2
.i_super
.s_blocksize_bits
),
2274 } else if (le16_to_cpu(di
->id2
.i_super
.s_major_rev_level
) !=
2275 OCFS2_MAJOR_REV_LEVEL
||
2276 le16_to_cpu(di
->id2
.i_super
.s_minor_rev_level
) !=
2277 OCFS2_MINOR_REV_LEVEL
) {
2278 mlog(ML_ERROR
, "found superblock with bad version: "
2279 "found %u.%u, should be %u.%u\n",
2280 le16_to_cpu(di
->id2
.i_super
.s_major_rev_level
),
2281 le16_to_cpu(di
->id2
.i_super
.s_minor_rev_level
),
2282 OCFS2_MAJOR_REV_LEVEL
,
2283 OCFS2_MINOR_REV_LEVEL
);
2284 } else if (bh
->b_blocknr
!= le64_to_cpu(di
->i_blkno
)) {
2285 mlog(ML_ERROR
, "bad block number on superblock: "
2286 "found %llu, should be %llu\n",
2287 (unsigned long long)le64_to_cpu(di
->i_blkno
),
2288 (unsigned long long)bh
->b_blocknr
);
2289 } else if (le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
) < 12 ||
2290 le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
) > 20) {
2291 mlog(ML_ERROR
, "bad cluster size found: %u\n",
2292 1 << le32_to_cpu(di
->id2
.i_super
.s_clustersize_bits
));
2293 } else if (!le64_to_cpu(di
->id2
.i_super
.s_root_blkno
)) {
2294 mlog(ML_ERROR
, "bad root_blkno: 0\n");
2295 } else if (!le64_to_cpu(di
->id2
.i_super
.s_system_dir_blkno
)) {
2296 mlog(ML_ERROR
, "bad system_dir_blkno: 0\n");
2297 } else if (le16_to_cpu(di
->id2
.i_super
.s_max_slots
) > OCFS2_MAX_SLOTS
) {
2299 "Superblock slots found greater than file system "
2300 "maximum: found %u, max %u\n",
2301 le16_to_cpu(di
->id2
.i_super
.s_max_slots
),
2314 static int ocfs2_check_volume(struct ocfs2_super
*osb
)
2319 struct ocfs2_dinode
*local_alloc
= NULL
; /* only used if we
2325 /* Init our journal object. */
2326 status
= ocfs2_journal_init(osb
->journal
, &dirty
);
2328 mlog(ML_ERROR
, "Could not initialize journal!\n");
2332 /* If the journal was unmounted cleanly then we don't want to
2333 * recover anything. Otherwise, journal_load will do that
2334 * dirty work for us :) */
2336 status
= ocfs2_journal_wipe(osb
->journal
, 0);
2342 mlog(ML_NOTICE
, "File system was not unmounted cleanly, "
2343 "recovering volume.\n");
2346 local
= ocfs2_mount_local(osb
);
2348 /* will play back anything left in the journal. */
2349 status
= ocfs2_journal_load(osb
->journal
, local
, dirty
);
2351 mlog(ML_ERROR
, "ocfs2 journal load failed! %d\n", status
);
2356 /* recover my local alloc if we didn't unmount cleanly. */
2357 status
= ocfs2_begin_local_alloc_recovery(osb
,
2364 /* we complete the recovery process after we've marked
2365 * ourselves as mounted. */
2368 mlog(0, "Journal loaded.\n");
2370 status
= ocfs2_load_local_alloc(osb
);
2377 /* Recovery will be completed after we've mounted the
2378 * rest of the volume. */
2380 osb
->local_alloc_copy
= local_alloc
;
2384 /* go through each journal, trylock it and if you get the
2385 * lock, and it's marked as dirty, set the bit in the recover
2386 * map and launch a recovery thread for it. */
2387 status
= ocfs2_mark_dead_nodes(osb
);
2393 status
= ocfs2_compute_replay_slots(osb
);
2406 * The routine gets called from dismount or close whenever a dismount on
2407 * volume is requested and the osb open count becomes 1.
2408 * It will remove the osb from the global list and also free up all the
2409 * initialized resources and fileobject.
2411 static void ocfs2_delete_osb(struct ocfs2_super
*osb
)
2415 /* This function assumes that the caller has the main osb resource */
2417 ocfs2_free_slot_info(osb
);
2419 kfree(osb
->osb_orphan_wipes
);
2420 kfree(osb
->slot_recovery_generations
);
2422 * This belongs in journal shutdown, but because we have to
2423 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2426 kfree(osb
->journal
);
2427 if (osb
->local_alloc_copy
)
2428 kfree(osb
->local_alloc_copy
);
2429 kfree(osb
->uuid_str
);
2430 ocfs2_put_dlm_debug(osb
->osb_dlm_debug
);
2431 memset(osb
, 0, sizeof(struct ocfs2_super
));
2436 /* Put OCFS2 into a readonly state, or (if the user specifies it),
2437 * panic(). We do not support continue-on-error operation. */
2438 static void ocfs2_handle_error(struct super_block
*sb
)
2440 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
2442 if (osb
->s_mount_opt
& OCFS2_MOUNT_ERRORS_PANIC
)
2443 panic("OCFS2: (device %s): panic forced after error\n",
2446 ocfs2_set_osb_flag(osb
, OCFS2_OSB_ERROR_FS
);
2448 if (sb
->s_flags
& MS_RDONLY
&&
2449 (ocfs2_is_soft_readonly(osb
) ||
2450 ocfs2_is_hard_readonly(osb
)))
2453 printk(KERN_CRIT
"File system is now read-only due to the potential "
2454 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2455 "system is unmounted.\n");
2456 sb
->s_flags
|= MS_RDONLY
;
2457 ocfs2_set_ro_flag(osb
, 0);
2460 static char error_buf
[1024];
2462 void __ocfs2_error(struct super_block
*sb
,
2463 const char *function
,
2464 const char *fmt
, ...)
2468 va_start(args
, fmt
);
2469 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
2472 /* Not using mlog here because we want to show the actual
2473 * function the error came from. */
2474 printk(KERN_CRIT
"OCFS2: ERROR (device %s): %s: %s\n",
2475 sb
->s_id
, function
, error_buf
);
2477 ocfs2_handle_error(sb
);
2480 /* Handle critical errors. This is intentionally more drastic than
2481 * ocfs2_handle_error, so we only use for things like journal errors,
2483 void __ocfs2_abort(struct super_block
* sb
,
2484 const char *function
,
2485 const char *fmt
, ...)
2489 va_start(args
, fmt
);
2490 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
2493 printk(KERN_CRIT
"OCFS2: abort (device %s): %s: %s\n",
2494 sb
->s_id
, function
, error_buf
);
2496 /* We don't have the cluster support yet to go straight to
2497 * hard readonly in here. Until then, we want to keep
2498 * ocfs2_abort() so that we can at least mark critical
2501 * TODO: This should abort the journal and alert other nodes
2502 * that our slot needs recovery. */
2504 /* Force a panic(). This stinks, but it's better than letting
2505 * things continue without having a proper hard readonly
2507 if (!ocfs2_mount_local(OCFS2_SB(sb
)))
2508 OCFS2_SB(sb
)->s_mount_opt
|= OCFS2_MOUNT_ERRORS_PANIC
;
2509 ocfs2_handle_error(sb
);
2512 module_init(ocfs2_init
);
2513 module_exit(ocfs2_exit
);