Btrfs: Fix uninitialized root flags for subvolumes
[firefly-linux-kernel-4.4.55.git] / fs / ocfs2 / super.c
1 /* -*- mode: c; c-basic-offset: 8; -*-
2  * vim: noexpandtab sw=8 ts=8 sts=0:
3  *
4  * super.c
5  *
6  * load/unload driver, mount/dismount volumes
7  *
8  * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
9  *
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.
14  *
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.
19  *
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.
24  */
25
26 #include <linux/module.h>
27 #include <linux/fs.h>
28 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h>
31 #include <linux/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>
45
46 #define MLOG_MASK_PREFIX ML_SUPER
47 #include <cluster/masklog.h>
48
49 #include "ocfs2.h"
50
51 /* this should be the only file to include a version 1 header */
52 #include "ocfs1_fs_compat.h"
53
54 #include "alloc.h"
55 #include "blockcheck.h"
56 #include "dlmglue.h"
57 #include "export.h"
58 #include "extent_map.h"
59 #include "heartbeat.h"
60 #include "inode.h"
61 #include "journal.h"
62 #include "localalloc.h"
63 #include "namei.h"
64 #include "slot_map.h"
65 #include "super.h"
66 #include "sysfile.h"
67 #include "uptodate.h"
68 #include "ver.h"
69 #include "xattr.h"
70 #include "quota.h"
71 #include "refcounttree.h"
72
73 #include "buffer_head_io.h"
74
75 static struct kmem_cache *ocfs2_inode_cachep = NULL;
76 struct kmem_cache *ocfs2_dquot_cachep;
77 struct kmem_cache *ocfs2_qf_chunk_cachep;
78
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;
84
85 static struct dentry *ocfs2_debugfs_root = NULL;
86
87 MODULE_AUTHOR("Oracle");
88 MODULE_LICENSE("GPL");
89
90 struct mount_options
91 {
92         unsigned long   commit_interval;
93         unsigned long   mount_opt;
94         unsigned int    atime_quantum;
95         signed short    slot;
96         unsigned int    localalloc_opt;
97         char            cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
98 };
99
100 static int ocfs2_parse_options(struct super_block *sb, char *options,
101                                struct mount_options *mopt,
102                                int is_remount);
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);
111
112 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
113
114 static int ocfs2_sync_fs(struct super_block *sb, int wait);
115
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,
122                                u32 sectsize,
123                                struct ocfs2_blockcheck_stats *stats);
124 static int ocfs2_initialize_super(struct super_block *sb,
125                                   struct buffer_head *bh,
126                                   int sector_size,
127                                   struct ocfs2_blockcheck_stats *stats);
128 static int ocfs2_get_sector(struct super_block *sb,
129                             struct buffer_head **bh,
130                             int block,
131                             int sect_size);
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);
137
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,
151 };
152
153 enum {
154         Opt_barrier,
155         Opt_err_panic,
156         Opt_err_ro,
157         Opt_intr,
158         Opt_nointr,
159         Opt_hb_none,
160         Opt_hb_local,
161         Opt_data_ordered,
162         Opt_data_writeback,
163         Opt_atime_quantum,
164         Opt_slot,
165         Opt_commit,
166         Opt_localalloc,
167         Opt_localflocks,
168         Opt_stack,
169         Opt_user_xattr,
170         Opt_nouser_xattr,
171         Opt_inode64,
172         Opt_acl,
173         Opt_noacl,
174         Opt_usrquota,
175         Opt_grpquota,
176         Opt_err,
177 };
178
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"},
183         {Opt_intr, "intr"},
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"},
198         {Opt_acl, "acl"},
199         {Opt_noacl, "noacl"},
200         {Opt_usrquota, "usrquota"},
201         {Opt_grpquota, "grpquota"},
202         {Opt_err, NULL}
203 };
204
205 #ifdef CONFIG_DEBUG_FS
206 static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
207 {
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;
211         int i, out = 0;
212
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);
217
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);
221
222         out += snprintf(buf + out, len - out,
223                         "%10s => Block: %lu  Cluster: %d\n", "Sizes",
224                         osb->sb->s_blocksize, osb->s_clustersize);
225
226         out += snprintf(buf + out, len - out,
227                         "%10s => Compat: 0x%X  Incompat: 0x%X  "
228                         "ROcompat: 0x%X\n",
229                         "Features", osb->s_feature_compat,
230                         osb->s_feature_incompat, osb->s_feature_ro_compat);
231
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);
235
236         if (cconn) {
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);
245         }
246
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);
255
256         spin_lock(&osb->osb_lock);
257         out += snprintf(buf + out, len - out, "%10s => Pid: %d  Nodes:",
258                         "Recovery",
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");
263         else {
264                 for (i = 0; i < rm->rm_used; i++)
265                         out += snprintf(buf + out, len - out, " %d",
266                                         rm->rm_entries[i]);
267                 out += snprintf(buf + out, len - out, "\n");
268         }
269         spin_unlock(&osb->osb_lock);
270
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));
276
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));
282
283         out += snprintf(buf + out, len - out,
284                         "%10s => GlobalAllocs: %d  LocalAllocs: %d  "
285                         "SubAllocs: %d  LAWinMoves: %d  SAExtends: %d\n",
286                         "Stats",
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));
292
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);
299
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);
306
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");
313         else
314                 out += snprintf(buf + out, len - out, "%lu seconds ago\n",
315                                 (get_seconds() - os->os_scantime.tv_sec));
316
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",
322                                 " ",
323                                 (i == osb->slot_num ? '*' : ' '),
324                                 i, osb->slot_recovery_generations[i]);
325         }
326
327         return out;
328 }
329
330 static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
331 {
332         struct ocfs2_super *osb = inode->i_private;
333         char *buf = NULL;
334
335         buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
336         if (!buf)
337                 goto bail;
338
339         i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
340
341         file->private_data = buf;
342
343         return 0;
344 bail:
345         return -ENOMEM;
346 }
347
348 static int ocfs2_debug_release(struct inode *inode, struct file *file)
349 {
350         kfree(file->private_data);
351         return 0;
352 }
353
354 static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
355                                 size_t nbytes, loff_t *ppos)
356 {
357         return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
358                                        i_size_read(file->f_mapping->host));
359 }
360 #else
361 static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
362 {
363         return 0;
364 }
365 static int ocfs2_debug_release(struct inode *inode, struct file *file)
366 {
367         return 0;
368 }
369 static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
370                                 size_t nbytes, loff_t *ppos)
371 {
372         return 0;
373 }
374 #endif  /* CONFIG_DEBUG_FS */
375
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,
381 };
382
383 static int ocfs2_sync_fs(struct super_block *sb, int wait)
384 {
385         int status;
386         tid_t target;
387         struct ocfs2_super *osb = OCFS2_SB(sb);
388
389         if (ocfs2_is_hard_readonly(osb))
390                 return -EROFS;
391
392         if (wait) {
393                 status = ocfs2_flush_truncate_log(osb);
394                 if (status < 0)
395                         mlog_errno(status);
396         } else {
397                 ocfs2_schedule_truncate_log_flush(osb, 0);
398         }
399
400         if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
401                                       &target)) {
402                 if (wait)
403                         jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
404                                              target);
405         }
406         return 0;
407 }
408
409 static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
410 {
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))
414                 return 0;
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))
418                 return 0;
419         return 1;
420 }
421
422 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
423 {
424         struct inode *new = NULL;
425         int status = 0;
426         int i;
427
428         mlog_entry_void();
429
430         new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
431         if (IS_ERR(new)) {
432                 status = PTR_ERR(new);
433                 mlog_errno(status);
434                 goto bail;
435         }
436         osb->root_inode = new;
437
438         new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
439         if (IS_ERR(new)) {
440                 status = PTR_ERR(new);
441                 mlog_errno(status);
442                 goto bail;
443         }
444         osb->sys_root_inode = new;
445
446         for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
447              i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
448                 if (!ocfs2_need_system_inode(osb, i))
449                         continue;
450                 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
451                 if (!new) {
452                         ocfs2_release_system_inodes(osb);
453                         status = -EINVAL;
454                         mlog_errno(status);
455                         /* FIXME: Should ERROR_RO_FS */
456                         mlog(ML_ERROR, "Unable to load system inode %d, "
457                              "possibly corrupt fs?", i);
458                         goto bail;
459                 }
460                 // the array now has one ref, so drop this one
461                 iput(new);
462         }
463
464 bail:
465         mlog_exit(status);
466         return status;
467 }
468
469 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
470 {
471         struct inode *new = NULL;
472         int status = 0;
473         int i;
474
475         mlog_entry_void();
476
477         for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
478              i < NUM_SYSTEM_INODES;
479              i++) {
480                 if (!ocfs2_need_system_inode(osb, i))
481                         continue;
482                 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
483                 if (!new) {
484                         ocfs2_release_system_inodes(osb);
485                         status = -EINVAL;
486                         mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
487                              status, i, osb->slot_num);
488                         goto bail;
489                 }
490                 /* the array now has one ref, so drop this one */
491                 iput(new);
492         }
493
494 bail:
495         mlog_exit(status);
496         return status;
497 }
498
499 static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
500 {
501         int i;
502         struct inode *inode;
503
504         mlog_entry_void();
505
506         for (i = 0; i < NUM_SYSTEM_INODES; i++) {
507                 inode = osb->system_inodes[i];
508                 if (inode) {
509                         iput(inode);
510                         osb->system_inodes[i] = NULL;
511                 }
512         }
513
514         inode = osb->sys_root_inode;
515         if (inode) {
516                 iput(inode);
517                 osb->sys_root_inode = NULL;
518         }
519
520         inode = osb->root_inode;
521         if (inode) {
522                 iput(inode);
523                 osb->root_inode = NULL;
524         }
525
526         mlog_exit(0);
527 }
528
529 /* We're allocating fs objects, use GFP_NOFS */
530 static struct inode *ocfs2_alloc_inode(struct super_block *sb)
531 {
532         struct ocfs2_inode_info *oi;
533
534         oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
535         if (!oi)
536                 return NULL;
537
538         jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
539         return &oi->vfs_inode;
540 }
541
542 static void ocfs2_destroy_inode(struct inode *inode)
543 {
544         kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
545 }
546
547 static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
548                                                 unsigned int cbits)
549 {
550         unsigned int bytes = 1 << cbits;
551         unsigned int trim = bytes;
552         unsigned int bitshift = 32;
553
554         /*
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.
558          */
559
560 #if BITS_PER_LONG == 32
561 # if defined(CONFIG_LBDAF)
562         BUILD_BUG_ON(sizeof(sector_t) != 8);
563         /*
564          * We might be limited by page cache size.
565          */
566         if (bytes > PAGE_CACHE_SIZE) {
567                 bytes = PAGE_CACHE_SIZE;
568                 trim = 1;
569                 /*
570                  * Shift by 31 here so that we don't get larger than
571                  * MAX_LFS_FILESIZE
572                  */
573                 bitshift = 31;
574         }
575 # else
576         /*
577          * We are limited by the size of sector_t. Use block size, as
578          * that's what we expose to the VFS.
579          */
580         bytes = 1 << bbits;
581         trim = 1;
582         bitshift = 31;
583 # endif
584 #endif
585
586         /*
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.
590          */
591         return (((unsigned long long)bytes) << bitshift) - trim;
592 }
593
594 static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
595 {
596         int incompat_features;
597         int ret = 0;
598         struct mount_options parsed_options;
599         struct ocfs2_super *osb = OCFS2_SB(sb);
600
601         lock_kernel();
602
603         if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) {
604                 ret = -EINVAL;
605                 goto out;
606         }
607
608         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
609             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
610                 ret = -EINVAL;
611                 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
612                 goto out;
613         }
614
615         if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
616             (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
617                 ret = -EINVAL;
618                 mlog(ML_ERROR, "Cannot change data mode on remount\n");
619                 goto out;
620         }
621
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)) {
626                 ret = -EINVAL;
627                 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
628                 goto out;
629         }
630
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);
636                         if (ret < 0)
637                                 goto out;
638                 }
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");
644                         ret = -EROFS;
645                         goto unlock_osb;
646                 }
647
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;
652                 } else {
653                         mlog(0, "Making ro filesystem writeable.\n");
654
655                         if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
656                                 mlog(ML_ERROR, "Cannot remount RDWR "
657                                      "filesystem due to previous errors.\n");
658                                 ret = -EROFS;
659                                 goto unlock_osb;
660                         }
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);
666                                 ret = -EINVAL;
667                                 goto unlock_osb;
668                         }
669                         sb->s_flags &= ~MS_RDONLY;
670                         osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
671                 }
672 unlock_osb:
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);
678                         else
679                                 ret = ocfs2_enable_quotas(osb);
680                         if (ret < 0) {
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);
686                                 goto out;
687                         }
688                 }
689         }
690
691         if (!ret) {
692                 /* Only save off the new mount options in case of a successful
693                  * remount. */
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;
701
702                 if (!ocfs2_is_hard_readonly(osb))
703                         ocfs2_set_journal_params(osb);
704
705                 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
706                         ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
707                                                         MS_POSIXACL : 0);
708         }
709 out:
710         unlock_kernel();
711         return ret;
712 }
713
714 static int ocfs2_sb_probe(struct super_block *sb,
715                           struct buffer_head **bh,
716                           int *sector_size,
717                           struct ocfs2_blockcheck_stats *stats)
718 {
719         int status, tmpstat;
720         struct ocfs1_vol_disk_hdr *hdr;
721         struct ocfs2_dinode *di;
722         int blksize;
723
724         *bh = NULL;
725
726         /* may be > 512 */
727         *sector_size = bdev_logical_block_size(sb->s_bdev);
728         if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
729                 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
730                      *sector_size, OCFS2_MAX_BLOCKSIZE);
731                 status = -EINVAL;
732                 goto bail;
733         }
734
735         /* Can this really happen? */
736         if (*sector_size < OCFS2_MIN_BLOCKSIZE)
737                 *sector_size = OCFS2_MIN_BLOCKSIZE;
738
739         /* check block zero for old format */
740         status = ocfs2_get_sector(sb, bh, 0, *sector_size);
741         if (status < 0) {
742                 mlog_errno(status);
743                 goto bail;
744         }
745         hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
746         if (hdr->major_version == OCFS1_MAJOR_VERSION) {
747                 mlog(ML_ERROR, "incompatible version: %u.%u\n",
748                      hdr->major_version, hdr->minor_version);
749                 status = -EINVAL;
750         }
751         if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
752                    strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
753                 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
754                      hdr->signature);
755                 status = -EINVAL;
756         }
757         brelse(*bh);
758         *bh = NULL;
759         if (status < 0) {
760                 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
761                      "upgraded before mounting with ocfs v2\n");
762                 goto bail;
763         }
764
765         /*
766          * Now check at magic offset for 512, 1024, 2048, 4096
767          * blocksizes.  4096 is the maximum blocksize because it is
768          * the minimum clustersize.
769          */
770         status = -EINVAL;
771         for (blksize = *sector_size;
772              blksize <= OCFS2_MAX_BLOCKSIZE;
773              blksize <<= 1) {
774                 tmpstat = ocfs2_get_sector(sb, bh,
775                                            OCFS2_SUPER_BLOCK_BLKNO,
776                                            blksize);
777                 if (tmpstat < 0) {
778                         status = tmpstat;
779                         mlog_errno(status);
780                         break;
781                 }
782                 di = (struct ocfs2_dinode *) (*bh)->b_data;
783                 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
784                 spin_lock_init(&stats->b_lock);
785                 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
786                 if (tmpstat < 0) {
787                         brelse(*bh);
788                         *bh = NULL;
789                 }
790                 if (tmpstat != -EAGAIN) {
791                         status = tmpstat;
792                         break;
793                 }
794         }
795
796 bail:
797         return status;
798 }
799
800 static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
801 {
802         if (ocfs2_mount_local(osb)) {
803                 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
804                         mlog(ML_ERROR, "Cannot heartbeat on a locally "
805                              "mounted device.\n");
806                         return -EINVAL;
807                 }
808         }
809
810         if (ocfs2_userspace_stack(osb)) {
811                 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
812                         mlog(ML_ERROR, "Userspace stack expected, but "
813                              "o2cb heartbeat arguments passed to mount\n");
814                         return -EINVAL;
815                 }
816         }
817
818         if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
819                 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
820                     !ocfs2_userspace_stack(osb)) {
821                         mlog(ML_ERROR, "Heartbeat has to be started to mount "
822                              "a read-write clustered device.\n");
823                         return -EINVAL;
824                 }
825         }
826
827         return 0;
828 }
829
830 /*
831  * If we're using a userspace stack, mount should have passed
832  * a name that matches the disk.  If not, mount should not
833  * have passed a stack.
834  */
835 static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
836                                         struct mount_options *mopt)
837 {
838         if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
839                 mlog(ML_ERROR,
840                      "cluster stack passed to mount, but this filesystem "
841                      "does not support it\n");
842                 return -EINVAL;
843         }
844
845         if (ocfs2_userspace_stack(osb) &&
846             strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
847                     OCFS2_STACK_LABEL_LEN)) {
848                 mlog(ML_ERROR,
849                      "cluster stack passed to mount (\"%s\") does not "
850                      "match the filesystem (\"%s\")\n",
851                      mopt->cluster_stack,
852                      osb->osb_cluster_stack);
853                 return -EINVAL;
854         }
855
856         return 0;
857 }
858
859 static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
860 {
861         int type;
862         struct super_block *sb = osb->sb;
863         unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
864                                              OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
865         int status = 0;
866
867         for (type = 0; type < MAXQUOTAS; type++) {
868                 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
869                         continue;
870                 if (unsuspend)
871                         status = vfs_quota_enable(
872                                         sb_dqopt(sb)->files[type],
873                                         type, QFMT_OCFS2,
874                                         DQUOT_SUSPENDED);
875                 else
876                         status = vfs_quota_disable(sb, type,
877                                                    DQUOT_SUSPENDED);
878                 if (status < 0)
879                         break;
880         }
881         if (status < 0)
882                 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
883                      "remount (error = %d).\n", status);
884         return status;
885 }
886
887 static int ocfs2_enable_quotas(struct ocfs2_super *osb)
888 {
889         struct inode *inode[MAXQUOTAS] = { NULL, NULL };
890         struct super_block *sb = osb->sb;
891         unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
892                                              OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
893         unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
894                                         LOCAL_GROUP_QUOTA_SYSTEM_INODE };
895         int status;
896         int type;
897
898         sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
899         for (type = 0; type < MAXQUOTAS; type++) {
900                 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
901                         continue;
902                 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
903                                                         osb->slot_num);
904                 if (!inode[type]) {
905                         status = -ENOENT;
906                         goto out_quota_off;
907                 }
908                 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
909                                                 DQUOT_USAGE_ENABLED);
910                 if (status < 0)
911                         goto out_quota_off;
912         }
913
914         for (type = 0; type < MAXQUOTAS; type++)
915                 iput(inode[type]);
916         return 0;
917 out_quota_off:
918         ocfs2_disable_quotas(osb);
919         for (type = 0; type < MAXQUOTAS; type++)
920                 iput(inode[type]);
921         mlog_errno(status);
922         return status;
923 }
924
925 static void ocfs2_disable_quotas(struct ocfs2_super *osb)
926 {
927         int type;
928         struct inode *inode;
929         struct super_block *sb = osb->sb;
930
931         /* We mostly ignore errors in this function because there's not much
932          * we can do when we see them */
933         for (type = 0; type < MAXQUOTAS; type++) {
934                 if (!sb_has_quota_loaded(sb, type))
935                         continue;
936                 inode = igrab(sb->s_dquot.files[type]);
937                 /* Turn off quotas. This will remove all dquot structures from
938                  * memory and so they will be automatically synced to global
939                  * quota files */
940                 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
941                                             DQUOT_LIMITS_ENABLED);
942                 if (!inode)
943                         continue;
944                 iput(inode);
945         }
946 }
947
948 /* Handle quota on quotactl */
949 static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
950                           char *path, int remount)
951 {
952         unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
953                                              OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
954
955         if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
956                 return -EINVAL;
957
958         if (remount)
959                 return 0;       /* Just ignore it has been handled in
960                                  * ocfs2_remount() */
961         return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
962                                     format_id, DQUOT_LIMITS_ENABLED);
963 }
964
965 /* Handle quota off quotactl */
966 static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
967 {
968         if (remount)
969                 return 0;       /* Ignore now and handle later in
970                                  * ocfs2_remount() */
971         return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
972 }
973
974 static const struct quotactl_ops ocfs2_quotactl_ops = {
975         .quota_on       = ocfs2_quota_on,
976         .quota_off      = ocfs2_quota_off,
977         .quota_sync     = vfs_quota_sync,
978         .get_info       = vfs_get_dqinfo,
979         .set_info       = vfs_set_dqinfo,
980         .get_dqblk      = vfs_get_dqblk,
981         .set_dqblk      = vfs_set_dqblk,
982 };
983
984 static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
985 {
986         struct dentry *root;
987         int status, sector_size;
988         struct mount_options parsed_options;
989         struct inode *inode = NULL;
990         struct ocfs2_super *osb = NULL;
991         struct buffer_head *bh = NULL;
992         char nodestr[8];
993         struct ocfs2_blockcheck_stats stats;
994
995         mlog_entry("%p, %p, %i", sb, data, silent);
996
997         if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
998                 status = -EINVAL;
999                 goto read_super_error;
1000         }
1001
1002         /* probe for superblock */
1003         status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
1004         if (status < 0) {
1005                 mlog(ML_ERROR, "superblock probe failed!\n");
1006                 goto read_super_error;
1007         }
1008
1009         status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
1010         osb = OCFS2_SB(sb);
1011         if (status < 0) {
1012                 mlog_errno(status);
1013                 goto read_super_error;
1014         }
1015         brelse(bh);
1016         bh = NULL;
1017
1018         if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
1019                 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1020
1021         osb->s_mount_opt = parsed_options.mount_opt;
1022         osb->s_atime_quantum = parsed_options.atime_quantum;
1023         osb->preferred_slot = parsed_options.slot;
1024         osb->osb_commit_interval = parsed_options.commit_interval;
1025         osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
1026         osb->local_alloc_bits = osb->local_alloc_default_bits;
1027         if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA &&
1028             !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1029                                          OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1030                 status = -EINVAL;
1031                 mlog(ML_ERROR, "User quotas were requested, but this "
1032                      "filesystem does not have the feature enabled.\n");
1033                 goto read_super_error;
1034         }
1035         if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1036             !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1037                                          OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1038                 status = -EINVAL;
1039                 mlog(ML_ERROR, "Group quotas were requested, but this "
1040                      "filesystem does not have the feature enabled.\n");
1041                 goto read_super_error;
1042         }
1043
1044         status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1045         if (status)
1046                 goto read_super_error;
1047
1048         sb->s_magic = OCFS2_SUPER_MAGIC;
1049
1050         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1051                 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1052
1053         /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1054          * heartbeat=none */
1055         if (bdev_read_only(sb->s_bdev)) {
1056                 if (!(sb->s_flags & MS_RDONLY)) {
1057                         status = -EACCES;
1058                         mlog(ML_ERROR, "Readonly device detected but readonly "
1059                              "mount was not specified.\n");
1060                         goto read_super_error;
1061                 }
1062
1063                 /* You should not be able to start a local heartbeat
1064                  * on a readonly device. */
1065                 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1066                         status = -EROFS;
1067                         mlog(ML_ERROR, "Local heartbeat specified on readonly "
1068                              "device.\n");
1069                         goto read_super_error;
1070                 }
1071
1072                 status = ocfs2_check_journals_nolocks(osb);
1073                 if (status < 0) {
1074                         if (status == -EROFS)
1075                                 mlog(ML_ERROR, "Recovery required on readonly "
1076                                      "file system, but write access is "
1077                                      "unavailable.\n");
1078                         else
1079                                 mlog_errno(status);                     
1080                         goto read_super_error;
1081                 }
1082
1083                 ocfs2_set_ro_flag(osb, 1);
1084
1085                 printk(KERN_NOTICE "Readonly device detected. No cluster "
1086                        "services will be utilized for this mount. Recovery "
1087                        "will be skipped.\n");
1088         }
1089
1090         if (!ocfs2_is_hard_readonly(osb)) {
1091                 if (sb->s_flags & MS_RDONLY)
1092                         ocfs2_set_ro_flag(osb, 0);
1093         }
1094
1095         status = ocfs2_verify_heartbeat(osb);
1096         if (status < 0) {
1097                 mlog_errno(status);
1098                 goto read_super_error;
1099         }
1100
1101         osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1102                                                  ocfs2_debugfs_root);
1103         if (!osb->osb_debug_root) {
1104                 status = -EINVAL;
1105                 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1106                 goto read_super_error;
1107         }
1108
1109         osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1110                                             osb->osb_debug_root,
1111                                             osb,
1112                                             &ocfs2_osb_debug_fops);
1113         if (!osb->osb_ctxt) {
1114                 status = -EINVAL;
1115                 mlog_errno(status);
1116                 goto read_super_error;
1117         }
1118
1119         if (ocfs2_meta_ecc(osb)) {
1120                 status = ocfs2_blockcheck_stats_debugfs_install(
1121                                                 &osb->osb_ecc_stats,
1122                                                 osb->osb_debug_root);
1123                 if (status) {
1124                         mlog(ML_ERROR,
1125                              "Unable to create blockcheck statistics "
1126                              "files\n");
1127                         goto read_super_error;
1128                 }
1129         }
1130
1131         status = ocfs2_mount_volume(sb);
1132         if (osb->root_inode)
1133                 inode = igrab(osb->root_inode);
1134
1135         if (status < 0)
1136                 goto read_super_error;
1137
1138         if (!inode) {
1139                 status = -EIO;
1140                 mlog_errno(status);
1141                 goto read_super_error;
1142         }
1143
1144         root = d_alloc_root(inode);
1145         if (!root) {
1146                 status = -ENOMEM;
1147                 mlog_errno(status);
1148                 goto read_super_error;
1149         }
1150
1151         sb->s_root = root;
1152
1153         ocfs2_complete_mount_recovery(osb);
1154
1155         if (ocfs2_mount_local(osb))
1156                 snprintf(nodestr, sizeof(nodestr), "local");
1157         else
1158                 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1159
1160         printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
1161                "with %s data mode.\n",
1162                osb->dev_str, nodestr, osb->slot_num,
1163                osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1164                "ordered");
1165
1166         atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1167         wake_up(&osb->osb_mount_event);
1168
1169         /* Now we can initialize quotas because we can afford to wait
1170          * for cluster locks recovery now. That also means that truncation
1171          * log recovery can happen but that waits for proper quota setup */
1172         if (!(sb->s_flags & MS_RDONLY)) {
1173                 status = ocfs2_enable_quotas(osb);
1174                 if (status < 0) {
1175                         /* We have to err-out specially here because
1176                          * s_root is already set */
1177                         mlog_errno(status);
1178                         atomic_set(&osb->vol_state, VOLUME_DISABLED);
1179                         wake_up(&osb->osb_mount_event);
1180                         mlog_exit(status);
1181                         return status;
1182                 }
1183         }
1184
1185         ocfs2_complete_quota_recovery(osb);
1186
1187         /* Now we wake up again for processes waiting for quotas */
1188         atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1189         wake_up(&osb->osb_mount_event);
1190
1191         /* Start this when the mount is almost sure of being successful */
1192         ocfs2_orphan_scan_start(osb);
1193
1194         mlog_exit(status);
1195         return status;
1196
1197 read_super_error:
1198         brelse(bh);
1199
1200         if (inode)
1201                 iput(inode);
1202
1203         if (osb) {
1204                 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1205                 wake_up(&osb->osb_mount_event);
1206                 ocfs2_dismount_volume(sb, 1);
1207         }
1208
1209         mlog_exit(status);
1210         return status;
1211 }
1212
1213 static int ocfs2_get_sb(struct file_system_type *fs_type,
1214                         int flags,
1215                         const char *dev_name,
1216                         void *data,
1217                         struct vfsmount *mnt)
1218 {
1219         return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1220                            mnt);
1221 }
1222
1223 static void ocfs2_kill_sb(struct super_block *sb)
1224 {
1225         struct ocfs2_super *osb = OCFS2_SB(sb);
1226
1227         /* Failed mount? */
1228         if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1229                 goto out;
1230
1231         /* Prevent further queueing of inode drop events */
1232         spin_lock(&dentry_list_lock);
1233         ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1234         spin_unlock(&dentry_list_lock);
1235         /* Wait for work to finish and/or remove it */
1236         cancel_work_sync(&osb->dentry_lock_work);
1237 out:
1238         kill_block_super(sb);
1239 }
1240
1241 static struct file_system_type ocfs2_fs_type = {
1242         .owner          = THIS_MODULE,
1243         .name           = "ocfs2",
1244         .get_sb         = ocfs2_get_sb, /* is this called when we mount
1245                                         * the fs? */
1246         .kill_sb        = ocfs2_kill_sb,
1247
1248         .fs_flags       = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
1249         .next           = NULL
1250 };
1251
1252 static int ocfs2_parse_options(struct super_block *sb,
1253                                char *options,
1254                                struct mount_options *mopt,
1255                                int is_remount)
1256 {
1257         int status;
1258         char *p;
1259
1260         mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1261                    options ? options : "(none)");
1262
1263         mopt->commit_interval = 0;
1264         mopt->mount_opt = 0;
1265         mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1266         mopt->slot = OCFS2_INVALID_SLOT;
1267         mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
1268         mopt->cluster_stack[0] = '\0';
1269
1270         if (!options) {
1271                 status = 1;
1272                 goto bail;
1273         }
1274
1275         while ((p = strsep(&options, ",")) != NULL) {
1276                 int token, option;
1277                 substring_t args[MAX_OPT_ARGS];
1278
1279                 if (!*p)
1280                         continue;
1281
1282                 token = match_token(p, tokens, args);
1283                 switch (token) {
1284                 case Opt_hb_local:
1285                         mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
1286                         break;
1287                 case Opt_hb_none:
1288                         mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
1289                         break;
1290                 case Opt_barrier:
1291                         if (match_int(&args[0], &option)) {
1292                                 status = 0;
1293                                 goto bail;
1294                         }
1295                         if (option)
1296                                 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
1297                         else
1298                                 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
1299                         break;
1300                 case Opt_intr:
1301                         mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
1302                         break;
1303                 case Opt_nointr:
1304                         mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
1305                         break;
1306                 case Opt_err_panic:
1307                         mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
1308                         break;
1309                 case Opt_err_ro:
1310                         mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1311                         break;
1312                 case Opt_data_ordered:
1313                         mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
1314                         break;
1315                 case Opt_data_writeback:
1316                         mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
1317                         break;
1318                 case Opt_user_xattr:
1319                         mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1320                         break;
1321                 case Opt_nouser_xattr:
1322                         mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1323                         break;
1324                 case Opt_atime_quantum:
1325                         if (match_int(&args[0], &option)) {
1326                                 status = 0;
1327                                 goto bail;
1328                         }
1329                         if (option >= 0)
1330                                 mopt->atime_quantum = option;
1331                         break;
1332                 case Opt_slot:
1333                         option = 0;
1334                         if (match_int(&args[0], &option)) {
1335                                 status = 0;
1336                                 goto bail;
1337                         }
1338                         if (option)
1339                                 mopt->slot = (s16)option;
1340                         break;
1341                 case Opt_commit:
1342                         option = 0;
1343                         if (match_int(&args[0], &option)) {
1344                                 status = 0;
1345                                 goto bail;
1346                         }
1347                         if (option < 0)
1348                                 return 0;
1349                         if (option == 0)
1350                                 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1351                         mopt->commit_interval = HZ * option;
1352                         break;
1353                 case Opt_localalloc:
1354                         option = 0;
1355                         if (match_int(&args[0], &option)) {
1356                                 status = 0;
1357                                 goto bail;
1358                         }
1359                         if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1360                                 mopt->localalloc_opt = option;
1361                         break;
1362                 case Opt_localflocks:
1363                         /*
1364                          * Changing this during remount could race
1365                          * flock() requests, or "unbalance" existing
1366                          * ones (e.g., a lock is taken in one mode but
1367                          * dropped in the other). If users care enough
1368                          * to flip locking modes during remount, we
1369                          * could add a "local" flag to individual
1370                          * flock structures for proper tracking of
1371                          * state.
1372                          */
1373                         if (!is_remount)
1374                                 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1375                         break;
1376                 case Opt_stack:
1377                         /* Check both that the option we were passed
1378                          * is of the right length and that it is a proper
1379                          * string of the right length.
1380                          */
1381                         if (((args[0].to - args[0].from) !=
1382                              OCFS2_STACK_LABEL_LEN) ||
1383                             (strnlen(args[0].from,
1384                                      OCFS2_STACK_LABEL_LEN) !=
1385                              OCFS2_STACK_LABEL_LEN)) {
1386                                 mlog(ML_ERROR,
1387                                      "Invalid cluster_stack option\n");
1388                                 status = 0;
1389                                 goto bail;
1390                         }
1391                         memcpy(mopt->cluster_stack, args[0].from,
1392                                OCFS2_STACK_LABEL_LEN);
1393                         mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1394                         break;
1395                 case Opt_inode64:
1396                         mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1397                         break;
1398                 case Opt_usrquota:
1399                         /* We check only on remount, otherwise features
1400                          * aren't yet initialized. */
1401                         if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1402                             OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1403                                 mlog(ML_ERROR, "User quota requested but "
1404                                      "filesystem feature is not set\n");
1405                                 status = 0;
1406                                 goto bail;
1407                         }
1408                         mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1409                         break;
1410                 case Opt_grpquota:
1411                         if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1412                             OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1413                                 mlog(ML_ERROR, "Group quota requested but "
1414                                      "filesystem feature is not set\n");
1415                                 status = 0;
1416                                 goto bail;
1417                         }
1418                         mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1419                         break;
1420 #ifdef CONFIG_OCFS2_FS_POSIX_ACL
1421                 case Opt_acl:
1422                         mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1423                         break;
1424                 case Opt_noacl:
1425                         mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1426                         break;
1427 #else
1428                 case Opt_acl:
1429                 case Opt_noacl:
1430                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
1431                         break;
1432 #endif
1433                 default:
1434                         mlog(ML_ERROR,
1435                              "Unrecognized mount option \"%s\" "
1436                              "or missing value\n", p);
1437                         status = 0;
1438                         goto bail;
1439                 }
1440         }
1441
1442         status = 1;
1443
1444 bail:
1445         mlog_exit(status);
1446         return status;
1447 }
1448
1449 static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1450 {
1451         struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1452         unsigned long opts = osb->s_mount_opt;
1453         unsigned int local_alloc_megs;
1454
1455         if (opts & OCFS2_MOUNT_HB_LOCAL)
1456                 seq_printf(s, ",_netdev,heartbeat=local");
1457         else
1458                 seq_printf(s, ",heartbeat=none");
1459
1460         if (opts & OCFS2_MOUNT_NOINTR)
1461                 seq_printf(s, ",nointr");
1462
1463         if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1464                 seq_printf(s, ",data=writeback");
1465         else
1466                 seq_printf(s, ",data=ordered");
1467
1468         if (opts & OCFS2_MOUNT_BARRIER)
1469                 seq_printf(s, ",barrier=1");
1470
1471         if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1472                 seq_printf(s, ",errors=panic");
1473         else
1474                 seq_printf(s, ",errors=remount-ro");
1475
1476         if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1477                 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1478
1479         if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1480                 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1481
1482         if (osb->osb_commit_interval)
1483                 seq_printf(s, ",commit=%u",
1484                            (unsigned) (osb->osb_commit_interval / HZ));
1485
1486         local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1487         if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1488                 seq_printf(s, ",localalloc=%d", local_alloc_megs);
1489
1490         if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1491                 seq_printf(s, ",localflocks,");
1492
1493         if (osb->osb_cluster_stack[0])
1494                 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1495                            osb->osb_cluster_stack);
1496         if (opts & OCFS2_MOUNT_USRQUOTA)
1497                 seq_printf(s, ",usrquota");
1498         if (opts & OCFS2_MOUNT_GRPQUOTA)
1499                 seq_printf(s, ",grpquota");
1500
1501         if (opts & OCFS2_MOUNT_NOUSERXATTR)
1502                 seq_printf(s, ",nouser_xattr");
1503         else
1504                 seq_printf(s, ",user_xattr");
1505
1506         if (opts & OCFS2_MOUNT_INODE64)
1507                 seq_printf(s, ",inode64");
1508
1509 #ifdef CONFIG_OCFS2_FS_POSIX_ACL
1510         if (opts & OCFS2_MOUNT_POSIX_ACL)
1511                 seq_printf(s, ",acl");
1512         else
1513                 seq_printf(s, ",noacl");
1514 #endif
1515
1516         return 0;
1517 }
1518
1519 static int __init ocfs2_init(void)
1520 {
1521         int status;
1522
1523         mlog_entry_void();
1524
1525         ocfs2_print_version();
1526
1527         status = init_ocfs2_uptodate_cache();
1528         if (status < 0) {
1529                 mlog_errno(status);
1530                 goto leave;
1531         }
1532
1533         status = ocfs2_initialize_mem_caches();
1534         if (status < 0) {
1535                 mlog_errno(status);
1536                 goto leave;
1537         }
1538
1539         ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1540         if (!ocfs2_wq) {
1541                 status = -ENOMEM;
1542                 goto leave;
1543         }
1544
1545         ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1546         if (!ocfs2_debugfs_root) {
1547                 status = -EFAULT;
1548                 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1549         }
1550
1551         status = ocfs2_quota_setup();
1552         if (status)
1553                 goto leave;
1554
1555         ocfs2_set_locking_protocol();
1556
1557         status = register_quota_format(&ocfs2_quota_format);
1558 leave:
1559         if (status < 0) {
1560                 ocfs2_quota_shutdown();
1561                 ocfs2_free_mem_caches();
1562                 exit_ocfs2_uptodate_cache();
1563         }
1564
1565         mlog_exit(status);
1566
1567         if (status >= 0) {
1568                 return register_filesystem(&ocfs2_fs_type);
1569         } else
1570                 return -1;
1571 }
1572
1573 static void __exit ocfs2_exit(void)
1574 {
1575         mlog_entry_void();
1576
1577         ocfs2_quota_shutdown();
1578
1579         if (ocfs2_wq) {
1580                 flush_workqueue(ocfs2_wq);
1581                 destroy_workqueue(ocfs2_wq);
1582         }
1583
1584         unregister_quota_format(&ocfs2_quota_format);
1585
1586         debugfs_remove(ocfs2_debugfs_root);
1587
1588         ocfs2_free_mem_caches();
1589
1590         unregister_filesystem(&ocfs2_fs_type);
1591
1592         exit_ocfs2_uptodate_cache();
1593
1594         mlog_exit_void();
1595 }
1596
1597 static void ocfs2_put_super(struct super_block *sb)
1598 {
1599         mlog_entry("(0x%p)\n", sb);
1600
1601         lock_kernel();
1602
1603         ocfs2_sync_blockdev(sb);
1604         ocfs2_dismount_volume(sb, 0);
1605
1606         unlock_kernel();
1607
1608         mlog_exit_void();
1609 }
1610
1611 static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1612 {
1613         struct ocfs2_super *osb;
1614         u32 numbits, freebits;
1615         int status;
1616         struct ocfs2_dinode *bm_lock;
1617         struct buffer_head *bh = NULL;
1618         struct inode *inode = NULL;
1619
1620         mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
1621
1622         osb = OCFS2_SB(dentry->d_sb);
1623
1624         inode = ocfs2_get_system_file_inode(osb,
1625                                             GLOBAL_BITMAP_SYSTEM_INODE,
1626                                             OCFS2_INVALID_SLOT);
1627         if (!inode) {
1628                 mlog(ML_ERROR, "failed to get bitmap inode\n");
1629                 status = -EIO;
1630                 goto bail;
1631         }
1632
1633         status = ocfs2_inode_lock(inode, &bh, 0);
1634         if (status < 0) {
1635                 mlog_errno(status);
1636                 goto bail;
1637         }
1638
1639         bm_lock = (struct ocfs2_dinode *) bh->b_data;
1640
1641         numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1642         freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1643
1644         buf->f_type = OCFS2_SUPER_MAGIC;
1645         buf->f_bsize = dentry->d_sb->s_blocksize;
1646         buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1647         buf->f_blocks = ((sector_t) numbits) *
1648                         (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1649         buf->f_bfree = ((sector_t) freebits) *
1650                        (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1651         buf->f_bavail = buf->f_bfree;
1652         buf->f_files = numbits;
1653         buf->f_ffree = freebits;
1654         buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1655                                 & 0xFFFFFFFFUL;
1656         buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1657                                 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
1658
1659         brelse(bh);
1660
1661         ocfs2_inode_unlock(inode, 0);
1662         status = 0;
1663 bail:
1664         if (inode)
1665                 iput(inode);
1666
1667         mlog_exit(status);
1668
1669         return status;
1670 }
1671
1672 static void ocfs2_inode_init_once(void *data)
1673 {
1674         struct ocfs2_inode_info *oi = data;
1675
1676         oi->ip_flags = 0;
1677         oi->ip_open_count = 0;
1678         spin_lock_init(&oi->ip_lock);
1679         ocfs2_extent_map_init(&oi->vfs_inode);
1680         INIT_LIST_HEAD(&oi->ip_io_markers);
1681         oi->ip_dir_start_lookup = 0;
1682
1683         init_rwsem(&oi->ip_alloc_sem);
1684         init_rwsem(&oi->ip_xattr_sem);
1685         mutex_init(&oi->ip_io_mutex);
1686
1687         oi->ip_blkno = 0ULL;
1688         oi->ip_clusters = 0;
1689
1690         ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
1691         ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
1692         ocfs2_lock_res_init_once(&oi->ip_open_lockres);
1693
1694         ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
1695                                   &ocfs2_inode_caching_ops);
1696
1697         inode_init_once(&oi->vfs_inode);
1698 }
1699
1700 static int ocfs2_initialize_mem_caches(void)
1701 {
1702         ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
1703                                        sizeof(struct ocfs2_inode_info),
1704                                        0,
1705                                        (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1706                                                 SLAB_MEM_SPREAD),
1707                                        ocfs2_inode_init_once);
1708         ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1709                                         sizeof(struct ocfs2_dquot),
1710                                         0,
1711                                         (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1712                                                 SLAB_MEM_SPREAD),
1713                                         NULL);
1714         ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1715                                         sizeof(struct ocfs2_quota_chunk),
1716                                         0,
1717                                         (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1718                                         NULL);
1719         if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1720             !ocfs2_qf_chunk_cachep) {
1721                 if (ocfs2_inode_cachep)
1722                         kmem_cache_destroy(ocfs2_inode_cachep);
1723                 if (ocfs2_dquot_cachep)
1724                         kmem_cache_destroy(ocfs2_dquot_cachep);
1725                 if (ocfs2_qf_chunk_cachep)
1726                         kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1727                 return -ENOMEM;
1728         }
1729
1730         return 0;
1731 }
1732
1733 static void ocfs2_free_mem_caches(void)
1734 {
1735         if (ocfs2_inode_cachep)
1736                 kmem_cache_destroy(ocfs2_inode_cachep);
1737         ocfs2_inode_cachep = NULL;
1738
1739         if (ocfs2_dquot_cachep)
1740                 kmem_cache_destroy(ocfs2_dquot_cachep);
1741         ocfs2_dquot_cachep = NULL;
1742
1743         if (ocfs2_qf_chunk_cachep)
1744                 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1745         ocfs2_qf_chunk_cachep = NULL;
1746 }
1747
1748 static int ocfs2_get_sector(struct super_block *sb,
1749                             struct buffer_head **bh,
1750                             int block,
1751                             int sect_size)
1752 {
1753         if (!sb_set_blocksize(sb, sect_size)) {
1754                 mlog(ML_ERROR, "unable to set blocksize\n");
1755                 return -EIO;
1756         }
1757
1758         *bh = sb_getblk(sb, block);
1759         if (!*bh) {
1760                 mlog_errno(-EIO);
1761                 return -EIO;
1762         }
1763         lock_buffer(*bh);
1764         if (!buffer_dirty(*bh))
1765                 clear_buffer_uptodate(*bh);
1766         unlock_buffer(*bh);
1767         ll_rw_block(READ, 1, bh);
1768         wait_on_buffer(*bh);
1769         if (!buffer_uptodate(*bh)) {
1770                 mlog_errno(-EIO);
1771                 brelse(*bh);
1772                 *bh = NULL;
1773                 return -EIO;
1774         }
1775
1776         return 0;
1777 }
1778
1779 static int ocfs2_mount_volume(struct super_block *sb)
1780 {
1781         int status = 0;
1782         int unlock_super = 0;
1783         struct ocfs2_super *osb = OCFS2_SB(sb);
1784
1785         mlog_entry_void();
1786
1787         if (ocfs2_is_hard_readonly(osb))
1788                 goto leave;
1789
1790         status = ocfs2_dlm_init(osb);
1791         if (status < 0) {
1792                 mlog_errno(status);
1793                 goto leave;
1794         }
1795
1796         status = ocfs2_super_lock(osb, 1);
1797         if (status < 0) {
1798                 mlog_errno(status);
1799                 goto leave;
1800         }
1801         unlock_super = 1;
1802
1803         /* This will load up the node map and add ourselves to it. */
1804         status = ocfs2_find_slot(osb);
1805         if (status < 0) {
1806                 mlog_errno(status);
1807                 goto leave;
1808         }
1809
1810         /* load all node-local system inodes */
1811         status = ocfs2_init_local_system_inodes(osb);
1812         if (status < 0) {
1813                 mlog_errno(status);
1814                 goto leave;
1815         }
1816
1817         status = ocfs2_check_volume(osb);
1818         if (status < 0) {
1819                 mlog_errno(status);
1820                 goto leave;
1821         }
1822
1823         status = ocfs2_truncate_log_init(osb);
1824         if (status < 0)
1825                 mlog_errno(status);
1826
1827 leave:
1828         if (unlock_super)
1829                 ocfs2_super_unlock(osb, 1);
1830
1831         mlog_exit(status);
1832         return status;
1833 }
1834
1835 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1836 {
1837         int tmp, hangup_needed = 0;
1838         struct ocfs2_super *osb = NULL;
1839         char nodestr[8];
1840
1841         mlog_entry("(0x%p)\n", sb);
1842
1843         BUG_ON(!sb);
1844         osb = OCFS2_SB(sb);
1845         BUG_ON(!osb);
1846
1847         debugfs_remove(osb->osb_ctxt);
1848
1849         /*
1850          * Flush inode dropping work queue so that deletes are
1851          * performed while the filesystem is still working
1852          */
1853         ocfs2_drop_all_dl_inodes(osb);
1854
1855         /* Orphan scan should be stopped as early as possible */
1856         ocfs2_orphan_scan_stop(osb);
1857
1858         ocfs2_disable_quotas(osb);
1859
1860         ocfs2_shutdown_local_alloc(osb);
1861
1862         ocfs2_truncate_log_shutdown(osb);
1863
1864         /* This will disable recovery and flush any recovery work. */
1865         ocfs2_recovery_exit(osb);
1866
1867         ocfs2_journal_shutdown(osb);
1868
1869         ocfs2_sync_blockdev(sb);
1870
1871         ocfs2_purge_refcount_trees(osb);
1872
1873         /* No cluster connection means we've failed during mount, so skip
1874          * all the steps which depended on that to complete. */
1875         if (osb->cconn) {
1876                 tmp = ocfs2_super_lock(osb, 1);
1877                 if (tmp < 0) {
1878                         mlog_errno(tmp);
1879                         return;
1880                 }
1881         }
1882
1883         if (osb->slot_num != OCFS2_INVALID_SLOT)
1884                 ocfs2_put_slot(osb);
1885
1886         if (osb->cconn)
1887                 ocfs2_super_unlock(osb, 1);
1888
1889         ocfs2_release_system_inodes(osb);
1890
1891         /*
1892          * If we're dismounting due to mount error, mount.ocfs2 will clean
1893          * up heartbeat.  If we're a local mount, there is no heartbeat.
1894          * If we failed before we got a uuid_str yet, we can't stop
1895          * heartbeat.  Otherwise, do it.
1896          */
1897         if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
1898                 hangup_needed = 1;
1899
1900         if (osb->cconn)
1901                 ocfs2_dlm_shutdown(osb, hangup_needed);
1902
1903         ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
1904         debugfs_remove(osb->osb_debug_root);
1905
1906         if (hangup_needed)
1907                 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
1908
1909         atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1910
1911         if (ocfs2_mount_local(osb))
1912                 snprintf(nodestr, sizeof(nodestr), "local");
1913         else
1914                 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
1915
1916         printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1917                osb->dev_str, nodestr);
1918
1919         ocfs2_delete_osb(osb);
1920         kfree(osb);
1921         sb->s_dev = 0;
1922         sb->s_fs_info = NULL;
1923 }
1924
1925 static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1926                                 unsigned uuid_bytes)
1927 {
1928         int i, ret;
1929         char *ptr;
1930
1931         BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1932
1933         osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
1934         if (osb->uuid_str == NULL)
1935                 return -ENOMEM;
1936
1937         for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1938                 /* print with null */
1939                 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1940                 if (ret != 2) /* drop super cleans up */
1941                         return -EINVAL;
1942                 /* then only advance past the last char */
1943                 ptr += 2;
1944         }
1945
1946         return 0;
1947 }
1948
1949 static int ocfs2_initialize_super(struct super_block *sb,
1950                                   struct buffer_head *bh,
1951                                   int sector_size,
1952                                   struct ocfs2_blockcheck_stats *stats)
1953 {
1954         int status;
1955         int i, cbits, bbits;
1956         struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
1957         struct inode *inode = NULL;
1958         struct ocfs2_journal *journal;
1959         __le32 uuid_net_key;
1960         struct ocfs2_super *osb;
1961
1962         mlog_entry_void();
1963
1964         osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
1965         if (!osb) {
1966                 status = -ENOMEM;
1967                 mlog_errno(status);
1968                 goto bail;
1969         }
1970
1971         sb->s_fs_info = osb;
1972         sb->s_op = &ocfs2_sops;
1973         sb->s_export_op = &ocfs2_export_ops;
1974         sb->s_qcop = &ocfs2_quotactl_ops;
1975         sb->dq_op = &ocfs2_quota_operations;
1976         sb->s_xattr = ocfs2_xattr_handlers;
1977         sb->s_time_gran = 1;
1978         sb->s_flags |= MS_NOATIME;
1979         /* this is needed to support O_LARGEFILE */
1980         cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1981         bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1982         sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
1983
1984         osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
1985
1986         for (i = 0; i < 3; i++)
1987                 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
1988         osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1989
1990         osb->sb = sb;
1991         /* Save off for ocfs2_rw_direct */
1992         osb->s_sectsize_bits = blksize_bits(sector_size);
1993         BUG_ON(!osb->s_sectsize_bits);
1994
1995         spin_lock_init(&osb->dc_task_lock);
1996         init_waitqueue_head(&osb->dc_event);
1997         osb->dc_work_sequence = 0;
1998         osb->dc_wake_sequence = 0;
1999         INIT_LIST_HEAD(&osb->blocked_lock_list);
2000         osb->blocked_lock_count = 0;
2001         spin_lock_init(&osb->osb_lock);
2002         spin_lock_init(&osb->osb_xattr_lock);
2003         ocfs2_init_inode_steal_slot(osb);
2004
2005         atomic_set(&osb->alloc_stats.moves, 0);
2006         atomic_set(&osb->alloc_stats.local_data, 0);
2007         atomic_set(&osb->alloc_stats.bitmap_data, 0);
2008         atomic_set(&osb->alloc_stats.bg_allocs, 0);
2009         atomic_set(&osb->alloc_stats.bg_extends, 0);
2010
2011         /* Copy the blockcheck stats from the superblock probe */
2012         osb->osb_ecc_stats = *stats;
2013
2014         ocfs2_init_node_maps(osb);
2015
2016         snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2017                  MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2018
2019         ocfs2_orphan_scan_init(osb);
2020
2021         status = ocfs2_recovery_init(osb);
2022         if (status) {
2023                 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2024                 mlog_errno(status);
2025                 goto bail;
2026         }
2027
2028         init_waitqueue_head(&osb->checkpoint_event);
2029         atomic_set(&osb->needs_checkpoint, 0);
2030
2031         osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2032
2033         osb->slot_num = OCFS2_INVALID_SLOT;
2034
2035         osb->s_xattr_inline_size = le16_to_cpu(
2036                                         di->id2.i_super.s_xattr_inline_size);
2037
2038         osb->local_alloc_state = OCFS2_LA_UNUSED;
2039         osb->local_alloc_bh = NULL;
2040         INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
2041
2042         init_waitqueue_head(&osb->osb_mount_event);
2043
2044         osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2045         if (!osb->vol_label) {
2046                 mlog(ML_ERROR, "unable to alloc vol label\n");
2047                 status = -ENOMEM;
2048                 goto bail;
2049         }
2050
2051         osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2052         if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2053                 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2054                      osb->max_slots);
2055                 status = -EINVAL;
2056                 goto bail;
2057         }
2058         mlog(0, "max_slots for this device: %u\n", osb->max_slots);
2059
2060         osb->slot_recovery_generations =
2061                 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2062                         GFP_KERNEL);
2063         if (!osb->slot_recovery_generations) {
2064                 status = -ENOMEM;
2065                 mlog_errno(status);
2066                 goto bail;
2067         }
2068
2069         init_waitqueue_head(&osb->osb_wipe_event);
2070         osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2071                                         sizeof(*osb->osb_orphan_wipes),
2072                                         GFP_KERNEL);
2073         if (!osb->osb_orphan_wipes) {
2074                 status = -ENOMEM;
2075                 mlog_errno(status);
2076                 goto bail;
2077         }
2078
2079         osb->osb_rf_lock_tree = RB_ROOT;
2080
2081         osb->s_feature_compat =
2082                 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2083         osb->s_feature_ro_compat =
2084                 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2085         osb->s_feature_incompat =
2086                 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2087
2088         if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2089                 mlog(ML_ERROR, "couldn't mount because of unsupported "
2090                      "optional features (%x).\n", i);
2091                 status = -EINVAL;
2092                 goto bail;
2093         }
2094         if (!(osb->sb->s_flags & MS_RDONLY) &&
2095             (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2096                 mlog(ML_ERROR, "couldn't mount RDWR because of "
2097                      "unsupported optional features (%x).\n", i);
2098                 status = -EINVAL;
2099                 goto bail;
2100         }
2101
2102         if (ocfs2_userspace_stack(osb)) {
2103                 memcpy(osb->osb_cluster_stack,
2104                        OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2105                        OCFS2_STACK_LABEL_LEN);
2106                 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2107                 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2108                         mlog(ML_ERROR,
2109                              "couldn't mount because of an invalid "
2110                              "cluster stack label (%s) \n",
2111                              osb->osb_cluster_stack);
2112                         status = -EINVAL;
2113                         goto bail;
2114                 }
2115         } else {
2116                 /* The empty string is identical with classic tools that
2117                  * don't know about s_cluster_info. */
2118                 osb->osb_cluster_stack[0] = '\0';
2119         }
2120
2121         get_random_bytes(&osb->s_next_generation, sizeof(u32));
2122
2123         /* FIXME
2124          * This should be done in ocfs2_journal_init(), but unknown
2125          * ordering issues will cause the filesystem to crash.
2126          * If anyone wants to figure out what part of the code
2127          * refers to osb->journal before ocfs2_journal_init() is run,
2128          * be my guest.
2129          */
2130         /* initialize our journal structure */
2131
2132         journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
2133         if (!journal) {
2134                 mlog(ML_ERROR, "unable to alloc journal\n");
2135                 status = -ENOMEM;
2136                 goto bail;
2137         }
2138         osb->journal = journal;
2139         journal->j_osb = osb;
2140
2141         atomic_set(&journal->j_num_trans, 0);
2142         init_rwsem(&journal->j_trans_barrier);
2143         init_waitqueue_head(&journal->j_checkpointed);
2144         spin_lock_init(&journal->j_lock);
2145         journal->j_trans_id = (unsigned long) 1;
2146         INIT_LIST_HEAD(&journal->j_la_cleanups);
2147         INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
2148         journal->j_state = OCFS2_JOURNAL_FREE;
2149
2150         INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2151         osb->dentry_lock_list = NULL;
2152
2153         /* get some pseudo constants for clustersize bits */
2154         osb->s_clustersize_bits =
2155                 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2156         osb->s_clustersize = 1 << osb->s_clustersize_bits;
2157         mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2158
2159         if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2160             osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2161                 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2162                      osb->s_clustersize);
2163                 status = -EINVAL;
2164                 goto bail;
2165         }
2166
2167         if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2168             > (u32)~0UL) {
2169                 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2170                      "what jbd can address in 32 bits.\n");
2171                 status = -EINVAL;
2172                 goto bail;
2173         }
2174
2175         if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2176                                  sizeof(di->id2.i_super.s_uuid))) {
2177                 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2178                 status = -ENOMEM;
2179                 goto bail;
2180         }
2181
2182         memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
2183
2184         strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2185         osb->vol_label[63] = '\0';
2186         osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2187         osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2188         osb->first_cluster_group_blkno =
2189                 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2190         osb->fs_generation = le32_to_cpu(di->i_fs_generation);
2191         osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2192         mlog(0, "vol_label: %s\n", osb->vol_label);
2193         mlog(0, "uuid: %s\n", osb->uuid_str);
2194         mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2195              (unsigned long long)osb->root_blkno,
2196              (unsigned long long)osb->system_dir_blkno);
2197
2198         osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2199         if (!osb->osb_dlm_debug) {
2200                 status = -ENOMEM;
2201                 mlog_errno(status);
2202                 goto bail;
2203         }
2204
2205         atomic_set(&osb->vol_state, VOLUME_INIT);
2206
2207         /* load root, system_dir, and all global system inodes */
2208         status = ocfs2_init_global_system_inodes(osb);
2209         if (status < 0) {
2210                 mlog_errno(status);
2211                 goto bail;
2212         }
2213
2214         /*
2215          * global bitmap
2216          */
2217         inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2218                                             OCFS2_INVALID_SLOT);
2219         if (!inode) {
2220                 status = -EINVAL;
2221                 mlog_errno(status);
2222                 goto bail;
2223         }
2224
2225         osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
2226         iput(inode);
2227
2228         osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
2229
2230         status = ocfs2_init_slot_info(osb);
2231         if (status < 0) {
2232                 mlog_errno(status);
2233                 goto bail;
2234         }
2235
2236 bail:
2237         mlog_exit(status);
2238         return status;
2239 }
2240
2241 /*
2242  * will return: -EAGAIN if it is ok to keep searching for superblocks
2243  *              -EINVAL if there is a bad superblock
2244  *              0 on success
2245  */
2246 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2247                                struct buffer_head *bh,
2248                                u32 blksz,
2249                                struct ocfs2_blockcheck_stats *stats)
2250 {
2251         int status = -EAGAIN;
2252
2253         mlog_entry_void();
2254
2255         if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2256                    strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
2257                 /* We have to do a raw check of the feature here */
2258                 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2259                     OCFS2_FEATURE_INCOMPAT_META_ECC) {
2260                         status = ocfs2_block_check_validate(bh->b_data,
2261                                                             bh->b_size,
2262                                                             &di->i_check,
2263                                                             stats);
2264                         if (status)
2265                                 goto out;
2266                 }
2267                 status = -EINVAL;
2268                 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2269                         mlog(ML_ERROR, "found superblock with incorrect block "
2270                              "size: found %u, should be %u\n",
2271                              1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2272                                blksz);
2273                 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2274                            OCFS2_MAJOR_REV_LEVEL ||
2275                            le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2276                            OCFS2_MINOR_REV_LEVEL) {
2277                         mlog(ML_ERROR, "found superblock with bad version: "
2278                              "found %u.%u, should be %u.%u\n",
2279                              le16_to_cpu(di->id2.i_super.s_major_rev_level),
2280                              le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2281                              OCFS2_MAJOR_REV_LEVEL,
2282                              OCFS2_MINOR_REV_LEVEL);
2283                 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2284                         mlog(ML_ERROR, "bad block number on superblock: "
2285                              "found %llu, should be %llu\n",
2286                              (unsigned long long)le64_to_cpu(di->i_blkno),
2287                              (unsigned long long)bh->b_blocknr);
2288                 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2289                             le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2290                         mlog(ML_ERROR, "bad cluster size found: %u\n",
2291                              1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2292                 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2293                         mlog(ML_ERROR, "bad root_blkno: 0\n");
2294                 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2295                         mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2296                 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2297                         mlog(ML_ERROR,
2298                              "Superblock slots found greater than file system "
2299                              "maximum: found %u, max %u\n",
2300                              le16_to_cpu(di->id2.i_super.s_max_slots),
2301                              OCFS2_MAX_SLOTS);
2302                 } else {
2303                         /* found it! */
2304                         status = 0;
2305                 }
2306         }
2307
2308 out:
2309         mlog_exit(status);
2310         return status;
2311 }
2312
2313 static int ocfs2_check_volume(struct ocfs2_super *osb)
2314 {
2315         int status;
2316         int dirty;
2317         int local;
2318         struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2319                                                   * recover
2320                                                   * ourselves. */
2321
2322         mlog_entry_void();
2323
2324         /* Init our journal object. */
2325         status = ocfs2_journal_init(osb->journal, &dirty);
2326         if (status < 0) {
2327                 mlog(ML_ERROR, "Could not initialize journal!\n");
2328                 goto finally;
2329         }
2330
2331         /* If the journal was unmounted cleanly then we don't want to
2332          * recover anything. Otherwise, journal_load will do that
2333          * dirty work for us :) */
2334         if (!dirty) {
2335                 status = ocfs2_journal_wipe(osb->journal, 0);
2336                 if (status < 0) {
2337                         mlog_errno(status);
2338                         goto finally;
2339                 }
2340         } else {
2341                 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2342                      "recovering volume.\n");
2343         }
2344
2345         local = ocfs2_mount_local(osb);
2346
2347         /* will play back anything left in the journal. */
2348         status = ocfs2_journal_load(osb->journal, local, dirty);
2349         if (status < 0) {
2350                 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2351                 goto finally;
2352         }
2353
2354         if (dirty) {
2355                 /* recover my local alloc if we didn't unmount cleanly. */
2356                 status = ocfs2_begin_local_alloc_recovery(osb,
2357                                                           osb->slot_num,
2358                                                           &local_alloc);
2359                 if (status < 0) {
2360                         mlog_errno(status);
2361                         goto finally;
2362                 }
2363                 /* we complete the recovery process after we've marked
2364                  * ourselves as mounted. */
2365         }
2366
2367         mlog(0, "Journal loaded.\n");
2368
2369         status = ocfs2_load_local_alloc(osb);
2370         if (status < 0) {
2371                 mlog_errno(status);
2372                 goto finally;
2373         }
2374
2375         if (dirty) {
2376                 /* Recovery will be completed after we've mounted the
2377                  * rest of the volume. */
2378                 osb->dirty = 1;
2379                 osb->local_alloc_copy = local_alloc;
2380                 local_alloc = NULL;
2381         }
2382
2383         /* go through each journal, trylock it and if you get the
2384          * lock, and it's marked as dirty, set the bit in the recover
2385          * map and launch a recovery thread for it. */
2386         status = ocfs2_mark_dead_nodes(osb);
2387         if (status < 0) {
2388                 mlog_errno(status);
2389                 goto finally;
2390         }
2391
2392         status = ocfs2_compute_replay_slots(osb);
2393         if (status < 0)
2394                 mlog_errno(status);
2395
2396 finally:
2397         if (local_alloc)
2398                 kfree(local_alloc);
2399
2400         mlog_exit(status);
2401         return status;
2402 }
2403
2404 /*
2405  * The routine gets called from dismount or close whenever a dismount on
2406  * volume is requested and the osb open count becomes 1.
2407  * It will remove the osb from the global list and also free up all the
2408  * initialized resources and fileobject.
2409  */
2410 static void ocfs2_delete_osb(struct ocfs2_super *osb)
2411 {
2412         mlog_entry_void();
2413
2414         /* This function assumes that the caller has the main osb resource */
2415
2416         ocfs2_free_slot_info(osb);
2417
2418         kfree(osb->osb_orphan_wipes);
2419         kfree(osb->slot_recovery_generations);
2420         /* FIXME
2421          * This belongs in journal shutdown, but because we have to
2422          * allocate osb->journal at the start of ocfs2_initalize_osb(),
2423          * we free it here.
2424          */
2425         kfree(osb->journal);
2426         if (osb->local_alloc_copy)
2427                 kfree(osb->local_alloc_copy);
2428         kfree(osb->uuid_str);
2429         ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2430         memset(osb, 0, sizeof(struct ocfs2_super));
2431
2432         mlog_exit_void();
2433 }
2434
2435 /* Put OCFS2 into a readonly state, or (if the user specifies it),
2436  * panic(). We do not support continue-on-error operation. */
2437 static void ocfs2_handle_error(struct super_block *sb)
2438 {
2439         struct ocfs2_super *osb = OCFS2_SB(sb);
2440
2441         if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2442                 panic("OCFS2: (device %s): panic forced after error\n",
2443                       sb->s_id);
2444
2445         ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2446
2447         if (sb->s_flags & MS_RDONLY &&
2448             (ocfs2_is_soft_readonly(osb) ||
2449              ocfs2_is_hard_readonly(osb)))
2450                 return;
2451
2452         printk(KERN_CRIT "File system is now read-only due to the potential "
2453                "of on-disk corruption. Please run fsck.ocfs2 once the file "
2454                "system is unmounted.\n");
2455         sb->s_flags |= MS_RDONLY;
2456         ocfs2_set_ro_flag(osb, 0);
2457 }
2458
2459 static char error_buf[1024];
2460
2461 void __ocfs2_error(struct super_block *sb,
2462                    const char *function,
2463                    const char *fmt, ...)
2464 {
2465         va_list args;
2466
2467         va_start(args, fmt);
2468         vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2469         va_end(args);
2470
2471         /* Not using mlog here because we want to show the actual
2472          * function the error came from. */
2473         printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2474                sb->s_id, function, error_buf);
2475
2476         ocfs2_handle_error(sb);
2477 }
2478
2479 /* Handle critical errors. This is intentionally more drastic than
2480  * ocfs2_handle_error, so we only use for things like journal errors,
2481  * etc. */
2482 void __ocfs2_abort(struct super_block* sb,
2483                    const char *function,
2484                    const char *fmt, ...)
2485 {
2486         va_list args;
2487
2488         va_start(args, fmt);
2489         vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2490         va_end(args);
2491
2492         printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2493                sb->s_id, function, error_buf);
2494
2495         /* We don't have the cluster support yet to go straight to
2496          * hard readonly in here. Until then, we want to keep
2497          * ocfs2_abort() so that we can at least mark critical
2498          * errors.
2499          *
2500          * TODO: This should abort the journal and alert other nodes
2501          * that our slot needs recovery. */
2502
2503         /* Force a panic(). This stinks, but it's better than letting
2504          * things continue without having a proper hard readonly
2505          * here. */
2506         if (!ocfs2_mount_local(OCFS2_SB(sb)))
2507                 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
2508         ocfs2_handle_error(sb);
2509 }
2510
2511 module_init(ocfs2_init);
2512 module_exit(ocfs2_exit);