aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ocfs2/super.c')
-rw-r--r--fs/ocfs2/super.c140
1 files changed, 90 insertions, 50 deletions
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 76b46ebbb10c..6e300a88a47e 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -68,9 +68,7 @@
68 68
69#include "buffer_head_io.h" 69#include "buffer_head_io.h"
70 70
71static kmem_cache_t *ocfs2_inode_cachep = NULL; 71static struct kmem_cache *ocfs2_inode_cachep = NULL;
72
73kmem_cache_t *ocfs2_lock_cache = NULL;
74 72
75/* OCFS2 needs to schedule several differnt types of work which 73/* OCFS2 needs to schedule several differnt types of work which
76 * require cluster locking, disk I/O, recovery waits, etc. Since these 74 * require cluster locking, disk I/O, recovery waits, etc. Since these
@@ -141,6 +139,7 @@ enum {
141 Opt_hb_local, 139 Opt_hb_local,
142 Opt_data_ordered, 140 Opt_data_ordered,
143 Opt_data_writeback, 141 Opt_data_writeback,
142 Opt_atime_quantum,
144 Opt_err, 143 Opt_err,
145}; 144};
146 145
@@ -154,6 +153,7 @@ static match_table_t tokens = {
154 {Opt_hb_local, OCFS2_HB_LOCAL}, 153 {Opt_hb_local, OCFS2_HB_LOCAL},
155 {Opt_data_ordered, "data=ordered"}, 154 {Opt_data_ordered, "data=ordered"},
156 {Opt_data_writeback, "data=writeback"}, 155 {Opt_data_writeback, "data=writeback"},
156 {Opt_atime_quantum, "atime_quantum=%u"},
157 {Opt_err, NULL} 157 {Opt_err, NULL}
158}; 158};
159 159
@@ -303,7 +303,7 @@ static struct inode *ocfs2_alloc_inode(struct super_block *sb)
303{ 303{
304 struct ocfs2_inode_info *oi; 304 struct ocfs2_inode_info *oi;
305 305
306 oi = kmem_cache_alloc(ocfs2_inode_cachep, SLAB_NOFS); 306 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
307 if (!oi) 307 if (!oi)
308 return NULL; 308 return NULL;
309 309
@@ -508,6 +508,27 @@ bail:
508 return status; 508 return status;
509} 509}
510 510
511static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
512{
513 if (ocfs2_mount_local(osb)) {
514 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
515 mlog(ML_ERROR, "Cannot heartbeat on a locally "
516 "mounted device.\n");
517 return -EINVAL;
518 }
519 }
520
521 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
522 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb)) {
523 mlog(ML_ERROR, "Heartbeat has to be started to mount "
524 "a read-write clustered device.\n");
525 return -EINVAL;
526 }
527 }
528
529 return 0;
530}
531
511static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) 532static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
512{ 533{
513 struct dentry *root; 534 struct dentry *root;
@@ -516,16 +537,24 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
516 struct inode *inode = NULL; 537 struct inode *inode = NULL;
517 struct ocfs2_super *osb = NULL; 538 struct ocfs2_super *osb = NULL;
518 struct buffer_head *bh = NULL; 539 struct buffer_head *bh = NULL;
540 char nodestr[8];
519 541
520 mlog_entry("%p, %p, %i", sb, data, silent); 542 mlog_entry("%p, %p, %i", sb, data, silent);
521 543
522 /* for now we only have one cluster/node, make sure we see it 544 if (!ocfs2_parse_options(sb, data, &parsed_opt, 0)) {
523 * in the heartbeat universe */
524 if (!o2hb_check_local_node_heartbeating()) {
525 status = -EINVAL; 545 status = -EINVAL;
526 goto read_super_error; 546 goto read_super_error;
527 } 547 }
528 548
549 /* for now we only have one cluster/node, make sure we see it
550 * in the heartbeat universe */
551 if (parsed_opt & OCFS2_MOUNT_HB_LOCAL) {
552 if (!o2hb_check_local_node_heartbeating()) {
553 status = -EINVAL;
554 goto read_super_error;
555 }
556 }
557
529 /* probe for superblock */ 558 /* probe for superblock */
530 status = ocfs2_sb_probe(sb, &bh, &sector_size); 559 status = ocfs2_sb_probe(sb, &bh, &sector_size);
531 if (status < 0) { 560 if (status < 0) {
@@ -541,11 +570,6 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
541 } 570 }
542 brelse(bh); 571 brelse(bh);
543 bh = NULL; 572 bh = NULL;
544
545 if (!ocfs2_parse_options(sb, data, &parsed_opt, 0)) {
546 status = -EINVAL;
547 goto read_super_error;
548 }
549 osb->s_mount_opt = parsed_opt; 573 osb->s_mount_opt = parsed_opt;
550 574
551 sb->s_magic = OCFS2_SUPER_MAGIC; 575 sb->s_magic = OCFS2_SUPER_MAGIC;
@@ -588,21 +612,16 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
588 } 612 }
589 613
590 if (!ocfs2_is_hard_readonly(osb)) { 614 if (!ocfs2_is_hard_readonly(osb)) {
591 /* If this isn't a hard readonly mount, then we need
592 * to make sure that heartbeat is in a valid state,
593 * and that we mark ourselves soft readonly is -oro
594 * was specified. */
595 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
596 mlog(ML_ERROR, "No heartbeat for device (%s)\n",
597 sb->s_id);
598 status = -EINVAL;
599 goto read_super_error;
600 }
601
602 if (sb->s_flags & MS_RDONLY) 615 if (sb->s_flags & MS_RDONLY)
603 ocfs2_set_ro_flag(osb, 0); 616 ocfs2_set_ro_flag(osb, 0);
604 } 617 }
605 618
619 status = ocfs2_verify_heartbeat(osb);
620 if (status < 0) {
621 mlog_errno(status);
622 goto read_super_error;
623 }
624
606 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str, 625 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
607 ocfs2_debugfs_root); 626 ocfs2_debugfs_root);
608 if (!osb->osb_debug_root) { 627 if (!osb->osb_debug_root) {
@@ -635,9 +654,14 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
635 654
636 ocfs2_complete_mount_recovery(osb); 655 ocfs2_complete_mount_recovery(osb);
637 656
638 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %d, slot %d) " 657 if (ocfs2_mount_local(osb))
658 snprintf(nodestr, sizeof(nodestr), "local");
659 else
660 snprintf(nodestr, sizeof(nodestr), "%d", osb->node_num);
661
662 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
639 "with %s data mode.\n", 663 "with %s data mode.\n",
640 osb->dev_str, osb->node_num, osb->slot_num, 664 osb->dev_str, nodestr, osb->slot_num,
641 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" : 665 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
642 "ordered"); 666 "ordered");
643 667
@@ -707,6 +731,7 @@ static int ocfs2_parse_options(struct super_block *sb,
707 while ((p = strsep(&options, ",")) != NULL) { 731 while ((p = strsep(&options, ",")) != NULL) {
708 int token, option; 732 int token, option;
709 substring_t args[MAX_OPT_ARGS]; 733 substring_t args[MAX_OPT_ARGS];
734 struct ocfs2_super * osb = OCFS2_SB(sb);
710 735
711 if (!*p) 736 if (!*p)
712 continue; 737 continue;
@@ -747,6 +772,16 @@ static int ocfs2_parse_options(struct super_block *sb,
747 case Opt_data_writeback: 772 case Opt_data_writeback:
748 *mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK; 773 *mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
749 break; 774 break;
775 case Opt_atime_quantum:
776 if (match_int(&args[0], &option)) {
777 status = 0;
778 goto bail;
779 }
780 if (option >= 0)
781 osb->s_atime_quantum = option;
782 else
783 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
784 break;
750 default: 785 default:
751 mlog(ML_ERROR, 786 mlog(ML_ERROR,
752 "Unrecognized mount option \"%s\" " 787 "Unrecognized mount option \"%s\" "
@@ -867,7 +902,7 @@ static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
867 goto bail; 902 goto bail;
868 } 903 }
869 904
870 status = ocfs2_meta_lock(inode, NULL, &bh, 0); 905 status = ocfs2_meta_lock(inode, &bh, 0);
871 if (status < 0) { 906 if (status < 0) {
872 mlog_errno(status); 907 mlog_errno(status);
873 goto bail; 908 goto bail;
@@ -903,7 +938,7 @@ bail:
903} 938}
904 939
905static void ocfs2_inode_init_once(void *data, 940static void ocfs2_inode_init_once(void *data,
906 kmem_cache_t *cachep, 941 struct kmem_cache *cachep,
907 unsigned long flags) 942 unsigned long flags)
908{ 943{
909 struct ocfs2_inode_info *oi = data; 944 struct ocfs2_inode_info *oi = data;
@@ -914,9 +949,7 @@ static void ocfs2_inode_init_once(void *data,
914 oi->ip_open_count = 0; 949 oi->ip_open_count = 0;
915 spin_lock_init(&oi->ip_lock); 950 spin_lock_init(&oi->ip_lock);
916 ocfs2_extent_map_init(&oi->vfs_inode); 951 ocfs2_extent_map_init(&oi->vfs_inode);
917 INIT_LIST_HEAD(&oi->ip_handle_list);
918 INIT_LIST_HEAD(&oi->ip_io_markers); 952 INIT_LIST_HEAD(&oi->ip_io_markers);
919 oi->ip_handle = NULL;
920 oi->ip_created_trans = 0; 953 oi->ip_created_trans = 0;
921 oi->ip_last_trans = 0; 954 oi->ip_last_trans = 0;
922 oi->ip_dir_start_lookup = 0; 955 oi->ip_dir_start_lookup = 0;
@@ -948,14 +981,6 @@ static int ocfs2_initialize_mem_caches(void)
948 if (!ocfs2_inode_cachep) 981 if (!ocfs2_inode_cachep)
949 return -ENOMEM; 982 return -ENOMEM;
950 983
951 ocfs2_lock_cache = kmem_cache_create("ocfs2_lock",
952 sizeof(struct ocfs2_journal_lock),
953 0,
954 SLAB_HWCACHE_ALIGN,
955 NULL, NULL);
956 if (!ocfs2_lock_cache)
957 return -ENOMEM;
958
959 return 0; 984 return 0;
960} 985}
961 986
@@ -963,11 +988,8 @@ static void ocfs2_free_mem_caches(void)
963{ 988{
964 if (ocfs2_inode_cachep) 989 if (ocfs2_inode_cachep)
965 kmem_cache_destroy(ocfs2_inode_cachep); 990 kmem_cache_destroy(ocfs2_inode_cachep);
966 if (ocfs2_lock_cache)
967 kmem_cache_destroy(ocfs2_lock_cache);
968 991
969 ocfs2_inode_cachep = NULL; 992 ocfs2_inode_cachep = NULL;
970 ocfs2_lock_cache = NULL;
971} 993}
972 994
973static int ocfs2_get_sector(struct super_block *sb, 995static int ocfs2_get_sector(struct super_block *sb,
@@ -1001,7 +1023,11 @@ static int ocfs2_fill_local_node_info(struct ocfs2_super *osb)
1001 1023
1002 /* XXX hold a ref on the node while mounte? easy enough, if 1024 /* XXX hold a ref on the node while mounte? easy enough, if
1003 * desirable. */ 1025 * desirable. */
1004 osb->node_num = o2nm_this_node(); 1026 if (ocfs2_mount_local(osb))
1027 osb->node_num = 0;
1028 else
1029 osb->node_num = o2nm_this_node();
1030
1005 if (osb->node_num == O2NM_MAX_NODES) { 1031 if (osb->node_num == O2NM_MAX_NODES) {
1006 mlog(ML_ERROR, "could not find this host's node number\n"); 1032 mlog(ML_ERROR, "could not find this host's node number\n");
1007 status = -ENOENT; 1033 status = -ENOENT;
@@ -1086,6 +1112,9 @@ static int ocfs2_mount_volume(struct super_block *sb)
1086 goto leave; 1112 goto leave;
1087 } 1113 }
1088 1114
1115 if (ocfs2_mount_local(osb))
1116 goto leave;
1117
1089 /* This should be sent *after* we recovered our journal as it 1118 /* This should be sent *after* we recovered our journal as it
1090 * will cause other nodes to unmark us as needing 1119 * will cause other nodes to unmark us as needing
1091 * recovery. However, we need to send it *before* dropping the 1120 * recovery. However, we need to send it *before* dropping the
@@ -1116,6 +1145,7 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1116{ 1145{
1117 int tmp; 1146 int tmp;
1118 struct ocfs2_super *osb = NULL; 1147 struct ocfs2_super *osb = NULL;
1148 char nodestr[8];
1119 1149
1120 mlog_entry("(0x%p)\n", sb); 1150 mlog_entry("(0x%p)\n", sb);
1121 1151
@@ -1179,8 +1209,13 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1179 1209
1180 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED); 1210 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1181 1211
1182 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %d)\n", 1212 if (ocfs2_mount_local(osb))
1183 osb->dev_str, osb->node_num); 1213 snprintf(nodestr, sizeof(nodestr), "local");
1214 else
1215 snprintf(nodestr, sizeof(nodestr), "%d", osb->node_num);
1216
1217 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1218 osb->dev_str, nodestr);
1184 1219
1185 ocfs2_delete_osb(osb); 1220 ocfs2_delete_osb(osb);
1186 kfree(osb); 1221 kfree(osb);
@@ -1196,7 +1231,7 @@ static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uu
1196 1231
1197 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN); 1232 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1198 1233
1199 osb->uuid_str = kcalloc(1, OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL); 1234 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
1200 if (osb->uuid_str == NULL) 1235 if (osb->uuid_str == NULL)
1201 return -ENOMEM; 1236 return -ENOMEM;
1202 1237
@@ -1227,7 +1262,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
1227 1262
1228 mlog_entry_void(); 1263 mlog_entry_void();
1229 1264
1230 osb = kcalloc(1, sizeof(struct ocfs2_super), GFP_KERNEL); 1265 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
1231 if (!osb) { 1266 if (!osb) {
1232 status = -ENOMEM; 1267 status = -ENOMEM;
1233 mlog_errno(status); 1268 mlog_errno(status);
@@ -1280,6 +1315,8 @@ static int ocfs2_initialize_super(struct super_block *sb,
1280 init_waitqueue_head(&osb->checkpoint_event); 1315 init_waitqueue_head(&osb->checkpoint_event);
1281 atomic_set(&osb->needs_checkpoint, 0); 1316 atomic_set(&osb->needs_checkpoint, 0);
1282 1317
1318 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1319
1283 osb->node_num = O2NM_INVALID_NODE_NUM; 1320 osb->node_num = O2NM_INVALID_NODE_NUM;
1284 osb->slot_num = OCFS2_INVALID_SLOT; 1321 osb->slot_num = OCFS2_INVALID_SLOT;
1285 1322
@@ -1350,7 +1387,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
1350 */ 1387 */
1351 /* initialize our journal structure */ 1388 /* initialize our journal structure */
1352 1389
1353 journal = kcalloc(1, sizeof(struct ocfs2_journal), GFP_KERNEL); 1390 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
1354 if (!journal) { 1391 if (!journal) {
1355 mlog(ML_ERROR, "unable to alloc journal\n"); 1392 mlog(ML_ERROR, "unable to alloc journal\n");
1356 status = -ENOMEM; 1393 status = -ENOMEM;
@@ -1365,7 +1402,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
1365 spin_lock_init(&journal->j_lock); 1402 spin_lock_init(&journal->j_lock);
1366 journal->j_trans_id = (unsigned long) 1; 1403 journal->j_trans_id = (unsigned long) 1;
1367 INIT_LIST_HEAD(&journal->j_la_cleanups); 1404 INIT_LIST_HEAD(&journal->j_la_cleanups);
1368 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery, osb); 1405 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
1369 journal->j_state = OCFS2_JOURNAL_FREE; 1406 journal->j_state = OCFS2_JOURNAL_FREE;
1370 1407
1371 /* get some pseudo constants for clustersize bits */ 1408 /* get some pseudo constants for clustersize bits */
@@ -1536,6 +1573,7 @@ static int ocfs2_check_volume(struct ocfs2_super *osb)
1536{ 1573{
1537 int status = 0; 1574 int status = 0;
1538 int dirty; 1575 int dirty;
1576 int local;
1539 struct ocfs2_dinode *local_alloc = NULL; /* only used if we 1577 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
1540 * recover 1578 * recover
1541 * ourselves. */ 1579 * ourselves. */
@@ -1563,8 +1601,10 @@ static int ocfs2_check_volume(struct ocfs2_super *osb)
1563 "recovering volume.\n"); 1601 "recovering volume.\n");
1564 } 1602 }
1565 1603
1604 local = ocfs2_mount_local(osb);
1605
1566 /* will play back anything left in the journal. */ 1606 /* will play back anything left in the journal. */
1567 ocfs2_journal_load(osb->journal); 1607 ocfs2_journal_load(osb->journal, local);
1568 1608
1569 if (dirty) { 1609 if (dirty) {
1570 /* recover my local alloc if we didn't unmount cleanly. */ 1610 /* recover my local alloc if we didn't unmount cleanly. */
@@ -1674,7 +1714,7 @@ void __ocfs2_error(struct super_block *sb,
1674 va_list args; 1714 va_list args;
1675 1715
1676 va_start(args, fmt); 1716 va_start(args, fmt);
1677 vsprintf(error_buf, fmt, args); 1717 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1678 va_end(args); 1718 va_end(args);
1679 1719
1680 /* Not using mlog here because we want to show the actual 1720 /* Not using mlog here because we want to show the actual
@@ -1695,7 +1735,7 @@ void __ocfs2_abort(struct super_block* sb,
1695 va_list args; 1735 va_list args;
1696 1736
1697 va_start(args, fmt); 1737 va_start(args, fmt);
1698 vsprintf(error_buf, fmt, args); 1738 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1699 va_end(args); 1739 va_end(args);
1700 1740
1701 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n", 1741 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",