26 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/slab.h>
32 #include <linux/random.h>
36 #include <linux/socket.h>
46 #define CREATE_TRACE_POINTS
89 static struct dentry *ocfs2_debugfs_root =
NULL;
111 static int ocfs2_show_options(
struct seq_file *
s,
struct dentry *root);
115 static void ocfs2_dismount_volume(
struct super_block *
sb,
int mnt_err);
116 static int ocfs2_initialize_mem_caches(
void);
117 static void ocfs2_free_mem_caches(
void);
118 static void ocfs2_delete_osb(
struct ocfs2_super *osb);
124 static int ocfs2_init_global_system_inodes(
struct ocfs2_super *osb);
125 static int ocfs2_init_local_system_inodes(
struct ocfs2_super *osb);
126 static void ocfs2_release_system_inodes(
struct ocfs2_super *osb);
127 static int ocfs2_check_volume(
struct ocfs2_super *osb);
129 struct buffer_head *bh,
133 struct buffer_head *bh,
137 struct buffer_head **bh,
141 static void ocfs2_destroy_inode(
struct inode *
inode);
142 static int ocfs2_susp_quotas(
struct ocfs2_super *osb,
int unsuspend);
143 static int ocfs2_enable_quotas(
struct ocfs2_super *osb);
144 static void ocfs2_disable_quotas(
struct ocfs2_super *osb);
147 .statfs = ocfs2_statfs,
148 .alloc_inode = ocfs2_alloc_inode,
149 .destroy_inode = ocfs2_destroy_inode,
152 .sync_fs = ocfs2_sync_fs,
153 .put_super = ocfs2_put_super,
154 .remount_fs = ocfs2_remount,
155 .show_options = ocfs2_show_options,
222 #ifdef CONFIG_DEBUG_FS
223 static int ocfs2_osb_dump(
struct ocfs2_super *osb,
char *
buf,
int len)
230 out +=
snprintf(buf + out, len - out,
231 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
235 out +=
snprintf(buf + out, len - out,
236 "%10s => State: %d Flags: 0x%lX\n",
"Volume",
239 out +=
snprintf(buf + out, len - out,
240 "%10s => Block: %lu Cluster: %d\n",
"Sizes",
243 out +=
snprintf(buf + out, len - out,
244 "%10s => Compat: 0x%X Incompat: 0x%X "
249 out +=
snprintf(buf + out, len - out,
250 "%10s => Opts: 0x%lX AtimeQuanta: %u\n",
"Mount",
254 out +=
snprintf(buf + out, len - out,
255 "%10s => Stack: %s Name: %*s "
256 "Version: %d.%d\n",
"Cluster",
265 out +=
snprintf(buf + out, len - out,
266 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
267 "WorkSeq: %lu\n",
"DownCnvt",
274 out +=
snprintf(buf + out, len - out,
"%10s => Pid: %d Nodes:",
279 out +=
snprintf(buf + out, len - out,
" None\n");
281 for (i = 0; i < rm->
rm_used; i++)
282 out +=
snprintf(buf + out, len - out,
" %d",
284 out +=
snprintf(buf + out, len - out,
"\n");
288 out +=
snprintf(buf + out, len - out,
289 "%10s => Pid: %d Interval: %lu Needs: %d\n",
"Commit",
294 out +=
snprintf(buf + out, len - out,
295 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
296 "Journal", osb->
journal->j_state,
300 out +=
snprintf(buf + out, len - out,
301 "%10s => GlobalAllocs: %d LocalAllocs: %d "
302 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
310 out +=
snprintf(buf + out, len - out,
311 "%10s => State: %u Descriptor: %llu Size: %u bits "
312 "Default: %u bits\n",
318 out +=
snprintf(buf + out, len - out,
319 "%10s => InodeSlot: %d StolenInodes: %d, "
320 "MetaSlot: %d StolenMeta: %d\n",
"Steal",
327 out +=
snprintf(buf + out, len - out,
"OrphanScan => ");
328 out +=
snprintf(buf + out, len - out,
"Local: %u Global: %u ",
330 out +=
snprintf(buf + out, len - out,
" Last Scan: ");
332 out +=
snprintf(buf + out, len - out,
"Disabled\n");
334 out +=
snprintf(buf + out, len - out,
"%lu seconds ago\n",
337 out +=
snprintf(buf + out, len - out,
"%10s => %3s %10s\n",
338 "Slots",
"Num",
"RecoGen");
340 out +=
snprintf(buf + out, len - out,
341 "%10s %c %3d %10d\n",
359 i_size_write(inode, ocfs2_osb_dump(osb, buf,
PAGE_SIZE));
368 static int ocfs2_debug_release(
struct inode *inode,
struct file *file)
374 static ssize_t ocfs2_debug_read(
struct file *file,
char __user *buf,
375 size_t nbytes, loff_t *ppos)
381 static int ocfs2_osb_debug_open(
struct inode *inode,
struct file *file)
385 static int ocfs2_debug_release(
struct inode *inode,
struct file *file)
389 static ssize_t ocfs2_debug_read(
struct file *file,
char __user *buf,
390 size_t nbytes, loff_t *ppos)
397 .open = ocfs2_osb_debug_open,
398 .release = ocfs2_debug_release,
399 .read = ocfs2_debug_read,
409 if (ocfs2_is_hard_readonly(osb))
429 static int ocfs2_need_system_inode(
struct ocfs2_super *osb,
int ino)
442 static int ocfs2_init_global_system_inodes(
struct ocfs2_super *osb)
444 struct inode *
new =
NULL;
450 status = PTR_ERR(
new);
458 status = PTR_ERR(
new);
466 if (!ocfs2_need_system_inode(osb, i))
470 ocfs2_release_system_inodes(osb);
475 "possibly corrupt fs?", i);
488 static int ocfs2_init_local_system_inodes(
struct ocfs2_super *osb)
490 struct inode *
new =
NULL;
497 if (!ocfs2_need_system_inode(osb, i))
501 ocfs2_release_system_inodes(osb);
517 static void ocfs2_release_system_inodes(
struct ocfs2_super *osb)
557 static struct inode *ocfs2_alloc_inode(
struct super_block *sb)
575 static void ocfs2_destroy_inode(
struct inode *inode)
580 static unsigned long long ocfs2_max_file_offset(
unsigned int bbits,
583 unsigned int bytes = 1 << cbits;
584 unsigned int trim =
bytes;
585 unsigned int bitshift = 32;
593 #if BITS_PER_LONG == 32
594 # if defined(CONFIG_LBDAF)
624 return (((
unsigned long long)bytes) << bitshift) - trim;
629 int incompat_features;
635 if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
636 !ocfs2_check_set_options(sb, &parsed_options)) {
643 if ((osb->
s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
645 mlog(
ML_ERROR,
"Cannot change heartbeat mode on remount\n");
668 if (*flags & MS_RDONLY) {
669 ret = ocfs2_susp_quotas(osb, 0);
677 mlog(
ML_ERROR,
"Remount on readonly device is forbidden.\n");
682 if (*flags & MS_RDONLY) {
688 "filesystem due to previous errors.\n");
693 if (incompat_features) {
695 "of unsupported optional features "
696 "(%x).\n", incompat_features);
707 if (!ret && !(*flags & MS_RDONLY)) {
708 if (sb_any_quota_suspended(sb))
709 ret = ocfs2_susp_quotas(osb, 1);
711 ret = ocfs2_enable_quotas(osb);
729 if (parsed_options.commit_interval)
732 if (!ocfs2_is_hard_readonly(osb))
744 struct buffer_head **bh,
756 *sector_size = bdev_logical_block_size(sb->
s_bdev);
758 mlog(
ML_ERROR,
"Hardware sector size too large: %d (max=%d)\n",
769 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
789 mlog(
ML_ERROR,
"This is an ocfs v1 filesystem which must be "
790 "upgraded before mounting with ocfs v2\n");
800 for (blksize = *sector_size;
803 tmpstat = ocfs2_get_sector(sb, bh,
814 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
829 static int ocfs2_verify_heartbeat(
struct ocfs2_super *osb)
834 if (ocfs2_mount_local(osb)) {
836 "mounted device.\n");
839 if (ocfs2_userspace_stack(osb)) {
841 "o2cb heartbeat arguments passed to mount\n");
845 !ocfs2_cluster_o2cb_global_heartbeat(osb)) ||
847 ocfs2_cluster_o2cb_global_heartbeat(osb))) {
854 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
855 !ocfs2_userspace_stack(osb)) {
857 "a read-write clustered device.\n");
870 static int ocfs2_verify_userspace_stack(
struct ocfs2_super *osb,
875 "cluster stack passed to mount, but this filesystem "
876 "does not support it\n");
880 if (ocfs2_userspace_stack(osb) &&
884 "cluster stack passed to mount (\"%s\") does not "
885 "match the filesystem (\"%s\")\n",
894 static int ocfs2_susp_quotas(
struct ocfs2_super *osb,
int unsuspend)
902 for (type = 0; type <
MAXQUOTAS; type++) {
911 oinfo = sb_dqinfo(sb, type)->dqi_priv;
913 status = dquot_suspend(sb, type);
920 "remount (error = %d).\n", status);
924 static int ocfs2_enable_quotas(
struct ocfs2_super *osb)
936 for (type = 0; type <
MAXQUOTAS; type++) {
955 ocfs2_disable_quotas(osb);
962 static void ocfs2_disable_quotas(
struct ocfs2_super *osb)
971 for (type = 0; type <
MAXQUOTAS; type++) {
972 if (!sb_has_quota_loaded(sb, type))
975 oinfo = sb_dqinfo(sb, type)->dqi_priv;
1003 static int ocfs2_quota_off(
struct super_block *sb,
int type)
1008 static const struct quotactl_ops ocfs2_quotactl_ops = {
1009 .quota_on_meta = ocfs2_quota_on,
1010 .quota_off = ocfs2_quota_off,
1018 static int ocfs2_fill_super(
struct super_block *sb,
void *data,
int silent)
1023 struct inode *inode =
NULL;
1025 struct buffer_head *bh =
NULL;
1029 trace_ocfs2_fill_super(sb, data, silent);
1031 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
1033 goto read_super_error;
1037 status = ocfs2_sb_probe(sb, &bh, §or_size, &stats);
1040 goto read_super_error;
1043 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
1047 goto read_super_error;
1052 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1054 goto read_super_error;
1064 if (parsed_options.dir_resv_level == -1)
1069 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1071 goto read_super_error;
1081 if (!(sb->
s_flags & MS_RDONLY)) {
1083 mlog(
ML_ERROR,
"Readonly device detected but readonly "
1084 "mount was not specified.\n");
1085 goto read_super_error;
1092 mlog(
ML_ERROR,
"Local heartbeat specified on readonly "
1094 goto read_super_error;
1099 if (status == -
EROFS)
1101 "file system, but write access is "
1105 goto read_super_error;
1108 ocfs2_set_ro_flag(osb, 1);
1111 "Cluster services will not be used for this mount. "
1112 "Recovery will be skipped.\n", osb->
dev_str);
1115 if (!ocfs2_is_hard_readonly(osb)) {
1117 ocfs2_set_ro_flag(osb, 0);
1120 status = ocfs2_verify_heartbeat(osb);
1123 goto read_super_error;
1127 ocfs2_debugfs_root);
1130 mlog(
ML_ERROR,
"Unable to create per-mount debugfs root.\n");
1131 goto read_super_error;
1137 &ocfs2_osb_debug_fops);
1141 goto read_super_error;
1144 if (ocfs2_meta_ecc(osb)) {
1150 "Unable to create blockcheck statistics "
1152 goto read_super_error;
1156 status = ocfs2_mount_volume(sb);
1158 goto read_super_error;
1166 goto read_super_error;
1173 goto read_super_error;
1180 if (ocfs2_mount_local(osb))
1181 snprintf(nodestr,
sizeof(nodestr),
"local");
1186 "with %s data mode.\n",
1197 if (!(sb->
s_flags & MS_RDONLY)) {
1198 status = ocfs2_enable_quotas(osb);
1226 ocfs2_dismount_volume(sb, 1);
1236 const char *dev_name,
1239 return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
1251 spin_lock(&dentry_list_lock);
1253 spin_unlock(&dentry_list_lock);
1263 .mount = ocfs2_mount,
1264 .kill_sb = ocfs2_kill_sb,
1270 static int ocfs2_check_set_options(
struct super_block *sb,
1277 "filesystem does not have the feature enabled.\n");
1283 mlog(
ML_ERROR,
"Group quotas were requested, but this "
1284 "filesystem does not have the feature enabled.\n");
1289 mlog(
ML_ERROR,
"ACL support requested but extended attributes "
1290 "feature is not enabled\n");
1304 static int ocfs2_parse_options(
struct super_block *sb,
1313 trace_ocfs2_parse_options(is_remount, options ? options :
"(none)");
1329 while ((p =
strsep(&options,
",")) !=
NULL) {
1438 if (((args[0].to - args[0].
from) !=
1444 "Invalid cluster_stack option\n");
1508 "Unrecognized mount option \"%s\" "
1509 "or missing value\n", p);
1515 if (user_stack == 0) {
1533 static int ocfs2_show_options(
struct seq_file *
s,
struct dentry *root)
1537 unsigned int local_alloc_megs;
1575 seq_printf(s,
",localalloc=%d", local_alloc_megs);
1617 static int __init ocfs2_init(
void)
1630 status = ocfs2_initialize_mem_caches();
1641 if (!ocfs2_debugfs_root) {
1643 mlog(
ML_ERROR,
"Unable to create ocfs2 debugfs root.\n");
1660 ocfs2_free_mem_caches();
1668 static void __exit ocfs2_exit(
void)
1679 ocfs2_free_mem_caches();
1686 static void ocfs2_put_super(
struct super_block *sb)
1688 trace_ocfs2_put_super(sb);
1691 ocfs2_dismount_volume(sb, 0);
1697 u32 numbits, freebits;
1700 struct buffer_head *bh =
NULL;
1701 struct inode *inode =
NULL;
1703 trace_ocfs2_statfs(dentry->
d_sb, buf);
1756 static void ocfs2_inode_init_once(
void *data)
1786 static int ocfs2_initialize_mem_caches(
void)
1793 ocfs2_inode_init_once);
1805 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1806 !ocfs2_qf_chunk_cachep) {
1807 if (ocfs2_inode_cachep)
1809 if (ocfs2_dquot_cachep)
1811 if (ocfs2_qf_chunk_cachep)
1819 static void ocfs2_free_mem_caches(
void)
1826 if (ocfs2_inode_cachep)
1828 ocfs2_inode_cachep =
NULL;
1830 if (ocfs2_dquot_cachep)
1832 ocfs2_dquot_cachep =
NULL;
1834 if (ocfs2_qf_chunk_cachep)
1836 ocfs2_qf_chunk_cachep =
NULL;
1839 static int ocfs2_get_sector(
struct super_block *sb,
1840 struct buffer_head **bh,
1849 *bh = sb_getblk(sb, block);
1855 if (!buffer_dirty(*bh))
1856 clear_buffer_uptodate(*bh);
1859 wait_on_buffer(*bh);
1860 if (!buffer_uptodate(*bh)) {
1870 static int ocfs2_mount_volume(
struct super_block *sb)
1876 if (ocfs2_is_hard_readonly(osb))
1900 status = ocfs2_init_local_system_inodes(osb);
1906 status = ocfs2_check_volume(osb);
1923 static void ocfs2_dismount_volume(
struct super_block *sb,
int mnt_err)
1925 int tmp, hangup_needed = 0;
1929 trace_ocfs2_dismount_volume(sb);
1946 ocfs2_disable_quotas(osb);
1977 ocfs2_release_system_inodes(osb);
1985 if (!mnt_err && !ocfs2_mount_local(osb) && osb->
uuid_str &&
1986 !ocfs2_is_hard_readonly(osb))
2000 if (ocfs2_mount_local(osb))
2001 snprintf(nodestr,
sizeof(nodestr),
"local");
2008 ocfs2_delete_osb(osb);
2014 static int ocfs2_setup_osb_uuid(
struct ocfs2_super *osb,
const unsigned char *
uuid,
2015 unsigned uuid_bytes)
2028 ret =
snprintf(ptr, 3,
"%02X", uuid[i]);
2041 static int ocfs2_journal_addressable(
struct ocfs2_super *osb)
2045 ocfs2_clusters_to_blocks(osb->
sb,
2049 if (max_block <= (
u32)~0ULL)
2058 mlog(
ML_ERROR,
"The journal cannot address the entire volume. "
2059 "Enable the 'block64' journal option with tunefs.ocfs2");
2068 static int ocfs2_initialize_super(
struct super_block *sb,
2069 struct buffer_head *bh,
2074 int i, cbits, bbits;
2076 struct inode *inode =
NULL;
2090 sb->
s_op = &ocfs2_sops;
2093 sb->
s_qcop = &ocfs2_quotactl_ops;
2101 sb->
s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
2105 for (i = 0; i < 3; i++)
2150 mlog(
ML_ERROR,
"Unable to initialize recovery state\n");
2213 mlog(
ML_ERROR,
"couldn't mount because of unsupported "
2214 "optional features (%x).\n", i);
2218 if (!(osb->
sb->s_flags & MS_RDONLY) &&
2221 "unsupported optional features (%x).\n", i);
2226 if (ocfs2_clusterinfo_valid(osb)) {
2235 "couldn't mount because of an invalid "
2236 "cluster stack label (%s) \n",
2265 journal->j_osb = osb;
2271 journal->j_trans_id = (
unsigned long) 1;
2272 INIT_LIST_HEAD(&journal->j_la_cleanups);
2286 mlog(
ML_ERROR,
"Volume has invalid cluster size (%d)\n",
2292 total_blocks = ocfs2_clusters_to_blocks(osb->
sb,
2299 "to mount safely on this system");
2304 if (ocfs2_setup_osb_uuid(osb, di->
id2.
i_super.s_uuid,
2306 mlog(
ML_ERROR,
"Out of memory trying to setup our uuid.\n");
2336 status = ocfs2_init_global_system_inodes(osb);
2357 osb->
bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
2365 cleancache_init_shared_fs((
char *)&di->
id2.
i_super.s_uuid, sb);
2376 static int ocfs2_verify_volume(
struct ocfs2_dinode *di,
2377 struct buffer_head *bh,
2397 mlog(
ML_ERROR,
"found superblock with incorrect block "
2398 "size: found %u, should be %u\n",
2406 "found %u.%u, should be %u.%u\n",
2413 "found %llu, should be %llu\n",
2415 (
unsigned long long)bh->b_blocknr);
2426 "Superblock slots found greater than file system "
2427 "maximum: found %u, max %u\n",
2437 if (status && status != -
EAGAIN)
2442 static int ocfs2_check_volume(
struct ocfs2_super *osb)
2460 status = ocfs2_journal_addressable(osb);
2475 "unmounted cleanly, recovering it.\n", osb->
dev_str);
2478 local = ocfs2_mount_local(osb);
2483 mlog(
ML_ERROR,
"ocfs2 journal load failed! %d\n", status);
2542 static void ocfs2_delete_osb(
struct ocfs2_super *osb)
2565 static void ocfs2_handle_error(
struct super_block *sb)
2570 panic(
"OCFS2: (device %s): panic forced after error\n",
2575 if (sb->
s_flags & MS_RDONLY &&
2576 (ocfs2_is_soft_readonly(osb) ||
2577 ocfs2_is_hard_readonly(osb)))
2581 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2582 "system is unmounted.\n");
2584 ocfs2_set_ro_flag(osb, 0);
2587 static char error_buf[1024];
2590 const char *
function,
2591 const char *
fmt, ...)
2596 vsnprintf(error_buf,
sizeof(error_buf), fmt, args);
2602 sb->
s_id,
function, error_buf);
2604 ocfs2_handle_error(sb);
2611 const char *
function,
2612 const char *
fmt, ...)
2617 vsnprintf(error_buf,
sizeof(error_buf), fmt, args);
2621 sb->
s_id,
function, error_buf);
2634 if (!ocfs2_mount_local(
OCFS2_SB(sb)))
2636 ocfs2_handle_error(sb);
2648 sigfillset(&blocked);