blob: 7efb349fb9bdafe0678bd63786db244bba410b4a [file] [log] [blame]
Mark Fashehccd979b2005-12-15 14:31:24 -08001/* -*- 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/utsname.h>
32#include <linux/init.h>
33#include <linux/random.h>
34#include <linux/statfs.h>
35#include <linux/moduleparam.h>
36#include <linux/blkdev.h>
37#include <linux/socket.h>
38#include <linux/inet.h>
39#include <linux/parser.h>
40#include <linux/crc32.h>
41#include <linux/debugfs.h>
Sunil Mushrand5500712007-09-06 13:34:16 -070042#include <linux/mount.h>
Joel Becker6953b4c2008-01-29 16:59:56 -080043#include <linux/seq_file.h>
Jan Kara19ece542008-08-21 20:13:17 +020044#include <linux/quotaops.h>
Alessio Igor Bogani337eb002009-05-12 15:10:54 +020045#include <linux/smp_lock.h>
Mark Fashehccd979b2005-12-15 14:31:24 -080046
47#define MLOG_MASK_PREFIX ML_SUPER
48#include <cluster/masklog.h>
49
50#include "ocfs2.h"
51
52/* this should be the only file to include a version 1 header */
53#include "ocfs1_fs_compat.h"
54
55#include "alloc.h"
Joel Beckerd030cc92008-12-11 15:04:14 -080056#include "blockcheck.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080057#include "dlmglue.h"
58#include "export.h"
59#include "extent_map.h"
60#include "heartbeat.h"
61#include "inode.h"
62#include "journal.h"
63#include "localalloc.h"
64#include "namei.h"
65#include "slot_map.h"
66#include "super.h"
67#include "sysfile.h"
68#include "uptodate.h"
69#include "ver.h"
Tiger Yangcf1d6c72008-08-18 17:11:00 +080070#include "xattr.h"
Jan Kara9e33d692008-08-25 19:56:50 +020071#include "quota.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080072
73#include "buffer_head_io.h"
74
Christoph Lametere18b8902006-12-06 20:33:20 -080075static struct kmem_cache *ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +020076struct kmem_cache *ocfs2_dquot_cachep;
77struct kmem_cache *ocfs2_qf_chunk_cachep;
Mark Fashehccd979b2005-12-15 14:31:24 -080078
Mark Fashehccd979b2005-12-15 14:31:24 -080079/* 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. */
83struct workqueue_struct *ocfs2_wq = NULL;
84
85static struct dentry *ocfs2_debugfs_root = NULL;
86
87MODULE_AUTHOR("Oracle");
88MODULE_LICENSE("GPL");
89
Tiger Yangc0123ad2007-09-08 00:16:10 +080090struct mount_options
91{
Mark Fashehd147b3d2007-11-07 14:40:36 -080092 unsigned long commit_interval;
Tiger Yangc0123ad2007-09-08 00:16:10 +080093 unsigned long mount_opt;
94 unsigned int atime_quantum;
95 signed short slot;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -080096 unsigned int localalloc_opt;
Joel Beckerb61817e2008-02-01 15:08:23 -080097 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
Tiger Yangc0123ad2007-09-08 00:16:10 +080098};
99
Mark Fashehccd979b2005-12-15 14:31:24 -0800100static int ocfs2_parse_options(struct super_block *sb, char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +0800101 struct mount_options *mopt,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700102 int is_remount);
Sunil Mushrand5500712007-09-06 13:34:16 -0700103static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -0800104static void ocfs2_put_super(struct super_block *sb);
105static int ocfs2_mount_volume(struct super_block *sb);
106static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
107static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
108static int ocfs2_initialize_mem_caches(void);
109static void ocfs2_free_mem_caches(void);
110static void ocfs2_delete_osb(struct ocfs2_super *osb);
111
David Howells726c3342006-06-23 02:02:58 -0700112static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
Mark Fashehccd979b2005-12-15 14:31:24 -0800113
114static int ocfs2_sync_fs(struct super_block *sb, int wait);
115
116static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
117static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
Denis Chengbddb8eb32007-09-27 02:10:04 +0800118static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800119static int ocfs2_check_volume(struct ocfs2_super *osb);
120static int ocfs2_verify_volume(struct ocfs2_dinode *di,
121 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800122 u32 sectsize,
123 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800124static int ocfs2_initialize_super(struct super_block *sb,
125 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800126 int sector_size,
127 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800128static int ocfs2_get_sector(struct super_block *sb,
129 struct buffer_head **bh,
130 int block,
131 int sect_size);
Mark Fashehccd979b2005-12-15 14:31:24 -0800132static struct inode *ocfs2_alloc_inode(struct super_block *sb);
133static void ocfs2_destroy_inode(struct inode *inode);
Jan Kara19ece542008-08-21 20:13:17 +0200134static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
135static int ocfs2_enable_quotas(struct ocfs2_super *osb);
136static void ocfs2_disable_quotas(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800137
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800138static const struct super_operations ocfs2_sops = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800139 .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,
Mark Fashehccd979b2005-12-15 14:31:24 -0800146 .put_super = ocfs2_put_super,
147 .remount_fs = ocfs2_remount,
Sunil Mushrand5500712007-09-06 13:34:16 -0700148 .show_options = ocfs2_show_options,
Jan Kara9e33d692008-08-25 19:56:50 +0200149 .quota_read = ocfs2_quota_read,
150 .quota_write = ocfs2_quota_write,
Mark Fashehccd979b2005-12-15 14:31:24 -0800151};
152
153enum {
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,
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800163 Opt_atime_quantum,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700164 Opt_slot,
Mark Fashehd147b3d2007-11-07 14:40:36 -0800165 Opt_commit,
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800166 Opt_localalloc,
Mark Fasheh53fc6222007-12-20 16:49:04 -0800167 Opt_localflocks,
Joel Beckerb61817e2008-02-01 15:08:23 -0800168 Opt_stack,
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800169 Opt_user_xattr,
170 Opt_nouser_xattr,
Joel Becker12462f12008-09-03 20:03:40 -0700171 Opt_inode64,
Tiger Yanga68979b2008-11-14 11:17:52 +0800172 Opt_acl,
173 Opt_noacl,
Jan Kara19ece542008-08-21 20:13:17 +0200174 Opt_usrquota,
175 Opt_grpquota,
Mark Fashehccd979b2005-12-15 14:31:24 -0800176 Opt_err,
177};
178
Steven Whitehousea447c092008-10-13 10:46:57 +0100179static const match_table_t tokens = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800180 {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"},
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800189 {Opt_atime_quantum, "atime_quantum=%u"},
Sunil Mushranbaf46612007-06-18 17:00:24 -0700190 {Opt_slot, "preferred_slot=%u"},
Mark Fashehd147b3d2007-11-07 14:40:36 -0800191 {Opt_commit, "commit=%u"},
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800192 {Opt_localalloc, "localalloc=%d"},
Mark Fasheh53fc6222007-12-20 16:49:04 -0800193 {Opt_localflocks, "localflocks"},
Joel Beckerb61817e2008-02-01 15:08:23 -0800194 {Opt_stack, "cluster_stack=%s"},
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800195 {Opt_user_xattr, "user_xattr"},
196 {Opt_nouser_xattr, "nouser_xattr"},
Joel Becker12462f12008-09-03 20:03:40 -0700197 {Opt_inode64, "inode64"},
Tiger Yanga68979b2008-11-14 11:17:52 +0800198 {Opt_acl, "acl"},
199 {Opt_noacl, "noacl"},
Jan Kara19ece542008-08-21 20:13:17 +0200200 {Opt_usrquota, "usrquota"},
201 {Opt_grpquota, "grpquota"},
Mark Fashehccd979b2005-12-15 14:31:24 -0800202 {Opt_err, NULL}
203};
204
Sunil Mushran50397502008-12-17 14:17:43 -0800205#ifdef CONFIG_DEBUG_FS
206static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
207{
Sunil Mushran50397502008-12-17 14:17:43 -0800208 struct ocfs2_cluster_connection *cconn = osb->cconn;
209 struct ocfs2_recovery_map *rm = osb->recovery_map;
Sunil Mushrandf152c22009-06-22 11:40:07 -0700210 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
211 int i, out = 0;
Sunil Mushran50397502008-12-17 14:17:43 -0800212
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
Sunil Mushranc3d38842009-06-19 14:45:55 -0700236 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 }
Sunil Mushran50397502008-12-17 14:17:43 -0800246
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",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700251 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
252 osb->blocked_lock_count, osb->dc_wake_sequence,
253 osb->dc_work_sequence);
Sunil Mushran50397502008-12-17 14:17:43 -0800254 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",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700273 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
274 osb->osb_commit_interval,
Sunil Mushran50397502008-12-17 14:17:43 -0800275 atomic_read(&osb->needs_checkpoint));
276
277 out += snprintf(buf + out, len - out,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700278 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
Sunil Mushran50397502008-12-17 14:17:43 -0800279 "Journal", osb->journal->j_state,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700280 osb->journal->j_trans_id,
281 atomic_read(&osb->journal->j_num_trans));
Sunil Mushran50397502008-12-17 14:17:43 -0800282
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
Sunil Mushrandf152c22009-06-22 11:40:07 -0700307 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
Sunil Mushran50397502008-12-17 14:17:43 -0800317 out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
318 "Slots", "Num", "RecoGen");
Sunil Mushran50397502008-12-17 14:17:43 -0800319 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
330static 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;
344bail:
345 return -ENOMEM;
346}
347
348static int ocfs2_debug_release(struct inode *inode, struct file *file)
349{
350 kfree(file->private_data);
351 return 0;
352}
353
354static 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
361static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
362{
363 return 0;
364}
365static int ocfs2_debug_release(struct inode *inode, struct file *file)
366{
367 return 0;
368}
369static 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
376static 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
Mark Fashehccd979b2005-12-15 14:31:24 -0800383static int ocfs2_sync_fs(struct super_block *sb, int wait)
384{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800385 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -0800386 tid_t target;
387 struct ocfs2_super *osb = OCFS2_SB(sb);
388
Mark Fashehccd979b2005-12-15 14:31:24 -0800389 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
Joel Becker2b4e30f2008-09-03 20:03:41 -0700400 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
401 &target)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800402 if (wait)
Joel Becker2b4e30f2008-09-03 20:03:41 -0700403 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
404 target);
Mark Fashehccd979b2005-12-15 14:31:24 -0800405 }
406 return 0;
407}
408
Jan Kara1a224ad2008-08-20 15:43:36 +0200409static 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
Mark Fashehccd979b2005-12-15 14:31:24 -0800422static 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
Jan Kara5fa06132008-01-11 00:11:45 +0100430 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800431 if (IS_ERR(new)) {
432 status = PTR_ERR(new);
433 mlog_errno(status);
434 goto bail;
435 }
436 osb->root_inode = new;
437
Jan Kara5fa06132008-01-11 00:11:45 +0100438 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800439 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++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200448 if (!ocfs2_need_system_inode(osb, i))
449 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800450 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
464bail:
465 mlog_exit(status);
466 return status;
467}
468
469static 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++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200480 if (!ocfs2_need_system_inode(osb, i))
481 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800482 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
494bail:
495 mlog_exit(status);
496 return status;
497}
498
Denis Chengbddb8eb32007-09-27 02:10:04 +0800499static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
Mark Fashehccd979b2005-12-15 14:31:24 -0800500{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800501 int i;
Mark Fashehccd979b2005-12-15 14:31:24 -0800502 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
Denis Chengbddb8eb32007-09-27 02:10:04 +0800526 mlog_exit(0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800527}
528
529/* We're allocating fs objects, use GFP_NOFS */
530static struct inode *ocfs2_alloc_inode(struct super_block *sb)
531{
532 struct ocfs2_inode_info *oi;
533
Christoph Lametere6b4f8d2006-12-06 20:33:14 -0800534 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
Mark Fashehccd979b2005-12-15 14:31:24 -0800535 if (!oi)
536 return NULL;
537
Joel Becker2b4e30f2008-09-03 20:03:41 -0700538 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -0800539 return &oi->vfs_inode;
540}
541
542static void ocfs2_destroy_inode(struct inode *inode)
543{
544 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
545}
546
Mark Fasheh5a254032007-07-20 12:56:16 -0700547static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
548 unsigned int cbits)
Mark Fashehccd979b2005-12-15 14:31:24 -0800549{
Mark Fasheh5a254032007-07-20 12:56:16 -0700550 unsigned int bytes = 1 << cbits;
551 unsigned int trim = bytes;
552 unsigned int bitshift = 32;
Mark Fashehccd979b2005-12-15 14:31:24 -0800553
Mark Fasheh5a254032007-07-20 12:56:16 -0700554 /*
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.
Mark Fashehccd979b2005-12-15 14:31:24 -0800558 */
559
560#if BITS_PER_LONG == 32
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +0200561# if defined(CONFIG_LBDAF)
Alexey Dobriyan2ecd05a2006-10-11 01:22:05 -0700562 BUILD_BUG_ON(sizeof(sector_t) != 8);
Mark Fasheh5a254032007-07-20 12:56:16 -0700563 /*
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 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800575# else
Mark Fasheh5a254032007-07-20 12:56:16 -0700576 /*
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;
Mark Fashehccd979b2005-12-15 14:31:24 -0800583# endif
584#endif
585
Mark Fasheh5a254032007-07-20 12:56:16 -0700586 /*
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;
Mark Fashehccd979b2005-12-15 14:31:24 -0800592}
593
594static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
595{
596 int incompat_features;
597 int ret = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800598 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800599 struct ocfs2_super *osb = OCFS2_SB(sb);
600
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200601 lock_kernel();
602
Tiger Yangc0123ad2007-09-08 00:16:10 +0800603 if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800604 ret = -EINVAL;
605 goto out;
606 }
607
608 if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800609 (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800610 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) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800616 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800617 ret = -EINVAL;
618 mlog(ML_ERROR, "Cannot change data mode on remount\n");
619 goto out;
620 }
621
Joel Becker12462f12008-09-03 20:03:40 -0700622 /* 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
Mark Fashehccd979b2005-12-15 14:31:24 -0800631 /* We're going to/from readonly mode. */
632 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
Jan Kara19ece542008-08-21 20:13:17 +0200633 /* 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 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800639 /* 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 }
672unlock_osb:
673 spin_unlock(&osb->osb_lock);
Jan Kara19ece542008-08-21 20:13:17 +0200674 /* 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 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800689 }
690
691 if (!ret) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800692 /* Only save off the new mount options in case of a successful
693 * remount. */
Tiger Yanga68979b2008-11-14 11:17:52 +0800694 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
695 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800696 osb->s_mount_opt = parsed_options.mount_opt;
697 osb->s_atime_quantum = parsed_options.atime_quantum;
698 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -0800699 if (parsed_options.commit_interval)
700 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fashehe001e792007-11-07 14:21:45 -0800701
702 if (!ocfs2_is_hard_readonly(osb))
703 ocfs2_set_journal_params(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800704 }
705out:
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200706 unlock_kernel();
Mark Fashehccd979b2005-12-15 14:31:24 -0800707 return ret;
708}
709
710static int ocfs2_sb_probe(struct super_block *sb,
711 struct buffer_head **bh,
Joel Becker73be1922009-01-06 14:57:08 -0800712 int *sector_size,
713 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -0800714{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800715 int status, tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800716 struct ocfs1_vol_disk_hdr *hdr;
717 struct ocfs2_dinode *di;
718 int blksize;
719
720 *bh = NULL;
721
722 /* may be > 512 */
Martin K. Petersene1defc42009-05-22 17:17:49 -0400723 *sector_size = bdev_logical_block_size(sb->s_bdev);
Mark Fashehccd979b2005-12-15 14:31:24 -0800724 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
725 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
726 *sector_size, OCFS2_MAX_BLOCKSIZE);
727 status = -EINVAL;
728 goto bail;
729 }
730
731 /* Can this really happen? */
732 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
733 *sector_size = OCFS2_MIN_BLOCKSIZE;
734
735 /* check block zero for old format */
736 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
737 if (status < 0) {
738 mlog_errno(status);
739 goto bail;
740 }
741 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
742 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
743 mlog(ML_ERROR, "incompatible version: %u.%u\n",
744 hdr->major_version, hdr->minor_version);
745 status = -EINVAL;
746 }
747 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
748 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
749 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
750 hdr->signature);
751 status = -EINVAL;
752 }
753 brelse(*bh);
754 *bh = NULL;
755 if (status < 0) {
756 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
757 "upgraded before mounting with ocfs v2\n");
758 goto bail;
759 }
760
761 /*
762 * Now check at magic offset for 512, 1024, 2048, 4096
763 * blocksizes. 4096 is the maximum blocksize because it is
764 * the minimum clustersize.
765 */
766 status = -EINVAL;
767 for (blksize = *sector_size;
768 blksize <= OCFS2_MAX_BLOCKSIZE;
769 blksize <<= 1) {
770 tmpstat = ocfs2_get_sector(sb, bh,
771 OCFS2_SUPER_BLOCK_BLKNO,
772 blksize);
773 if (tmpstat < 0) {
774 status = tmpstat;
775 mlog_errno(status);
776 goto bail;
777 }
778 di = (struct ocfs2_dinode *) (*bh)->b_data;
Joel Becker73be1922009-01-06 14:57:08 -0800779 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
780 status = ocfs2_verify_volume(di, *bh, blksize, stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800781 if (status >= 0)
782 goto bail;
783 brelse(*bh);
784 *bh = NULL;
785 if (status != -EAGAIN)
786 break;
787 }
788
789bail:
790 return status;
791}
792
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800793static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
794{
795 if (ocfs2_mount_local(osb)) {
796 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
797 mlog(ML_ERROR, "Cannot heartbeat on a locally "
798 "mounted device.\n");
799 return -EINVAL;
800 }
801 }
802
Joel Beckerb61817e2008-02-01 15:08:23 -0800803 if (ocfs2_userspace_stack(osb)) {
804 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
805 mlog(ML_ERROR, "Userspace stack expected, but "
806 "o2cb heartbeat arguments passed to mount\n");
807 return -EINVAL;
808 }
809 }
810
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800811 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800812 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
813 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800814 mlog(ML_ERROR, "Heartbeat has to be started to mount "
815 "a read-write clustered device.\n");
816 return -EINVAL;
817 }
818 }
819
820 return 0;
821}
822
Joel Beckerb61817e2008-02-01 15:08:23 -0800823/*
824 * If we're using a userspace stack, mount should have passed
825 * a name that matches the disk. If not, mount should not
826 * have passed a stack.
827 */
828static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
829 struct mount_options *mopt)
830{
831 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
832 mlog(ML_ERROR,
833 "cluster stack passed to mount, but this filesystem "
834 "does not support it\n");
835 return -EINVAL;
836 }
837
838 if (ocfs2_userspace_stack(osb) &&
839 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
840 OCFS2_STACK_LABEL_LEN)) {
841 mlog(ML_ERROR,
842 "cluster stack passed to mount (\"%s\") does not "
843 "match the filesystem (\"%s\")\n",
844 mopt->cluster_stack,
845 osb->osb_cluster_stack);
846 return -EINVAL;
847 }
848
849 return 0;
850}
851
Jan Kara19ece542008-08-21 20:13:17 +0200852static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
853{
854 int type;
855 struct super_block *sb = osb->sb;
856 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
857 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
858 int status = 0;
859
860 for (type = 0; type < MAXQUOTAS; type++) {
861 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
862 continue;
863 if (unsuspend)
864 status = vfs_quota_enable(
865 sb_dqopt(sb)->files[type],
866 type, QFMT_OCFS2,
867 DQUOT_SUSPENDED);
868 else
869 status = vfs_quota_disable(sb, type,
870 DQUOT_SUSPENDED);
871 if (status < 0)
872 break;
873 }
874 if (status < 0)
875 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
876 "remount (error = %d).\n", status);
877 return status;
878}
879
880static int ocfs2_enable_quotas(struct ocfs2_super *osb)
881{
882 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
883 struct super_block *sb = osb->sb;
884 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
885 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
886 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
887 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
888 int status;
889 int type;
890
891 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
892 for (type = 0; type < MAXQUOTAS; type++) {
893 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
894 continue;
895 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
896 osb->slot_num);
897 if (!inode[type]) {
898 status = -ENOENT;
899 goto out_quota_off;
900 }
901 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
902 DQUOT_USAGE_ENABLED);
903 if (status < 0)
904 goto out_quota_off;
905 }
906
907 for (type = 0; type < MAXQUOTAS; type++)
908 iput(inode[type]);
909 return 0;
910out_quota_off:
911 ocfs2_disable_quotas(osb);
912 for (type = 0; type < MAXQUOTAS; type++)
913 iput(inode[type]);
914 mlog_errno(status);
915 return status;
916}
917
918static void ocfs2_disable_quotas(struct ocfs2_super *osb)
919{
920 int type;
921 struct inode *inode;
922 struct super_block *sb = osb->sb;
923
924 /* We mostly ignore errors in this function because there's not much
925 * we can do when we see them */
926 for (type = 0; type < MAXQUOTAS; type++) {
927 if (!sb_has_quota_loaded(sb, type))
928 continue;
929 inode = igrab(sb->s_dquot.files[type]);
930 /* Turn off quotas. This will remove all dquot structures from
931 * memory and so they will be automatically synced to global
932 * quota files */
933 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
934 DQUOT_LIMITS_ENABLED);
935 if (!inode)
936 continue;
937 iput(inode);
938 }
939}
940
941/* Handle quota on quotactl */
942static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
943 char *path, int remount)
944{
945 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
946 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
947
948 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
949 return -EINVAL;
950
951 if (remount)
952 return 0; /* Just ignore it has been handled in
953 * ocfs2_remount() */
954 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
955 format_id, DQUOT_LIMITS_ENABLED);
956}
957
958/* Handle quota off quotactl */
959static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
960{
961 if (remount)
962 return 0; /* Ignore now and handle later in
963 * ocfs2_remount() */
964 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
965}
966
967static struct quotactl_ops ocfs2_quotactl_ops = {
968 .quota_on = ocfs2_quota_on,
969 .quota_off = ocfs2_quota_off,
970 .quota_sync = vfs_quota_sync,
971 .get_info = vfs_get_dqinfo,
972 .set_info = vfs_set_dqinfo,
973 .get_dqblk = vfs_get_dqblk,
974 .set_dqblk = vfs_set_dqblk,
975};
976
Mark Fashehccd979b2005-12-15 14:31:24 -0800977static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
978{
979 struct dentry *root;
980 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800981 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800982 struct inode *inode = NULL;
983 struct ocfs2_super *osb = NULL;
984 struct buffer_head *bh = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800985 char nodestr[8];
Joel Becker73be1922009-01-06 14:57:08 -0800986 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -0800987
988 mlog_entry("%p, %p, %i", sb, data, silent);
989
Tiger Yangc0123ad2007-09-08 00:16:10 +0800990 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800991 status = -EINVAL;
992 goto read_super_error;
993 }
994
995 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -0800996 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800997 if (status < 0) {
998 mlog(ML_ERROR, "superblock probe failed!\n");
999 goto read_super_error;
1000 }
1001
Joel Becker73be1922009-01-06 14:57:08 -08001002 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001003 osb = OCFS2_SB(sb);
1004 if (status < 0) {
1005 mlog_errno(status);
1006 goto read_super_error;
1007 }
1008 brelse(bh);
1009 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001010
1011 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
1012 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1013
Tiger Yangc0123ad2007-09-08 00:16:10 +08001014 osb->s_mount_opt = parsed_options.mount_opt;
1015 osb->s_atime_quantum = parsed_options.atime_quantum;
1016 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001017 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh9c7af402008-07-28 18:02:53 -07001018 osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
1019 osb->local_alloc_bits = osb->local_alloc_default_bits;
Jan Kara19ece542008-08-21 20:13:17 +02001020 if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA &&
1021 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1022 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1023 status = -EINVAL;
1024 mlog(ML_ERROR, "User quotas were requested, but this "
1025 "filesystem does not have the feature enabled.\n");
1026 goto read_super_error;
1027 }
1028 if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1029 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1030 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1031 status = -EINVAL;
1032 mlog(ML_ERROR, "Group quotas were requested, but this "
1033 "filesystem does not have the feature enabled.\n");
1034 goto read_super_error;
1035 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001036
Joel Beckerb61817e2008-02-01 15:08:23 -08001037 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1038 if (status)
1039 goto read_super_error;
1040
Mark Fashehccd979b2005-12-15 14:31:24 -08001041 sb->s_magic = OCFS2_SUPER_MAGIC;
1042
Tiger Yanga68979b2008-11-14 11:17:52 +08001043 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1044 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1045
Mark Fashehccd979b2005-12-15 14:31:24 -08001046 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1047 * heartbeat=none */
1048 if (bdev_read_only(sb->s_bdev)) {
1049 if (!(sb->s_flags & MS_RDONLY)) {
1050 status = -EACCES;
1051 mlog(ML_ERROR, "Readonly device detected but readonly "
1052 "mount was not specified.\n");
1053 goto read_super_error;
1054 }
1055
1056 /* You should not be able to start a local heartbeat
1057 * on a readonly device. */
1058 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1059 status = -EROFS;
1060 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1061 "device.\n");
1062 goto read_super_error;
1063 }
1064
1065 status = ocfs2_check_journals_nolocks(osb);
1066 if (status < 0) {
1067 if (status == -EROFS)
1068 mlog(ML_ERROR, "Recovery required on readonly "
1069 "file system, but write access is "
1070 "unavailable.\n");
1071 else
1072 mlog_errno(status);
1073 goto read_super_error;
1074 }
1075
1076 ocfs2_set_ro_flag(osb, 1);
1077
1078 printk(KERN_NOTICE "Readonly device detected. No cluster "
1079 "services will be utilized for this mount. Recovery "
1080 "will be skipped.\n");
1081 }
1082
1083 if (!ocfs2_is_hard_readonly(osb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001084 if (sb->s_flags & MS_RDONLY)
1085 ocfs2_set_ro_flag(osb, 0);
1086 }
1087
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001088 status = ocfs2_verify_heartbeat(osb);
1089 if (status < 0) {
1090 mlog_errno(status);
1091 goto read_super_error;
1092 }
1093
Mark Fashehccd979b2005-12-15 14:31:24 -08001094 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1095 ocfs2_debugfs_root);
1096 if (!osb->osb_debug_root) {
1097 status = -EINVAL;
1098 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1099 goto read_super_error;
1100 }
1101
Sunil Mushran50397502008-12-17 14:17:43 -08001102 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1103 osb->osb_debug_root,
1104 osb,
1105 &ocfs2_osb_debug_fops);
1106 if (!osb->osb_ctxt) {
1107 status = -EINVAL;
1108 mlog_errno(status);
1109 goto read_super_error;
1110 }
1111
Joel Becker73be1922009-01-06 14:57:08 -08001112 if (ocfs2_meta_ecc(osb)) {
1113 status = ocfs2_blockcheck_stats_debugfs_install(
1114 &osb->osb_ecc_stats,
1115 osb->osb_debug_root);
1116 if (status) {
1117 mlog(ML_ERROR,
1118 "Unable to create blockcheck statistics "
1119 "files\n");
1120 goto read_super_error;
1121 }
1122 }
1123
Mark Fashehccd979b2005-12-15 14:31:24 -08001124 status = ocfs2_mount_volume(sb);
1125 if (osb->root_inode)
1126 inode = igrab(osb->root_inode);
1127
1128 if (status < 0)
1129 goto read_super_error;
1130
1131 if (!inode) {
1132 status = -EIO;
1133 mlog_errno(status);
1134 goto read_super_error;
1135 }
1136
1137 root = d_alloc_root(inode);
1138 if (!root) {
1139 status = -ENOMEM;
1140 mlog_errno(status);
1141 goto read_super_error;
1142 }
1143
1144 sb->s_root = root;
1145
1146 ocfs2_complete_mount_recovery(osb);
1147
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001148 if (ocfs2_mount_local(osb))
1149 snprintf(nodestr, sizeof(nodestr), "local");
1150 else
Joel Becker19fdb622008-01-30 15:38:24 -08001151 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001152
1153 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001154 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001155 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001156 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1157 "ordered");
1158
1159 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1160 wake_up(&osb->osb_mount_event);
1161
Jan Kara19ece542008-08-21 20:13:17 +02001162 /* Now we can initialize quotas because we can afford to wait
1163 * for cluster locks recovery now. That also means that truncation
1164 * log recovery can happen but that waits for proper quota setup */
1165 if (!(sb->s_flags & MS_RDONLY)) {
1166 status = ocfs2_enable_quotas(osb);
1167 if (status < 0) {
1168 /* We have to err-out specially here because
1169 * s_root is already set */
1170 mlog_errno(status);
1171 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1172 wake_up(&osb->osb_mount_event);
1173 mlog_exit(status);
1174 return status;
1175 }
1176 }
1177
1178 ocfs2_complete_quota_recovery(osb);
1179
1180 /* Now we wake up again for processes waiting for quotas */
1181 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1182 wake_up(&osb->osb_mount_event);
1183
Sunil Mushrandf152c22009-06-22 11:40:07 -07001184 /* Start this when the mount is almost sure of being successful */
1185 ocfs2_orphan_scan_init(osb);
1186
Mark Fashehccd979b2005-12-15 14:31:24 -08001187 mlog_exit(status);
1188 return status;
1189
1190read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001191 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001192
1193 if (inode)
1194 iput(inode);
1195
1196 if (osb) {
1197 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1198 wake_up(&osb->osb_mount_event);
1199 ocfs2_dismount_volume(sb, 1);
1200 }
1201
1202 mlog_exit(status);
1203 return status;
1204}
1205
David Howells454e2392006-06-23 02:02:57 -07001206static int ocfs2_get_sb(struct file_system_type *fs_type,
1207 int flags,
1208 const char *dev_name,
1209 void *data,
1210 struct vfsmount *mnt)
Mark Fashehccd979b2005-12-15 14:31:24 -08001211{
David Howells454e2392006-06-23 02:02:57 -07001212 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1213 mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -08001214}
1215
1216static struct file_system_type ocfs2_fs_type = {
1217 .owner = THIS_MODULE,
1218 .name = "ocfs2",
1219 .get_sb = ocfs2_get_sb, /* is this called when we mount
1220 * the fs? */
1221 .kill_sb = kill_block_super, /* set to the generic one
1222 * right now, but do we
1223 * need to change that? */
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001224 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001225 .next = NULL
1226};
1227
1228static int ocfs2_parse_options(struct super_block *sb,
1229 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001230 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001231 int is_remount)
1232{
1233 int status;
1234 char *p;
1235
1236 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1237 options ? options : "(none)");
1238
Mark Fashehd147b3d2007-11-07 14:40:36 -08001239 mopt->commit_interval = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001240 mopt->mount_opt = 0;
1241 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1242 mopt->slot = OCFS2_INVALID_SLOT;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001243 mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
Joel Beckerb61817e2008-02-01 15:08:23 -08001244 mopt->cluster_stack[0] = '\0';
Mark Fashehccd979b2005-12-15 14:31:24 -08001245
1246 if (!options) {
1247 status = 1;
1248 goto bail;
1249 }
1250
1251 while ((p = strsep(&options, ",")) != NULL) {
1252 int token, option;
1253 substring_t args[MAX_OPT_ARGS];
1254
1255 if (!*p)
1256 continue;
1257
1258 token = match_token(p, tokens, args);
1259 switch (token) {
1260 case Opt_hb_local:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001261 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001262 break;
1263 case Opt_hb_none:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001264 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001265 break;
1266 case Opt_barrier:
1267 if (match_int(&args[0], &option)) {
1268 status = 0;
1269 goto bail;
1270 }
1271 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001272 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001273 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001274 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001275 break;
1276 case Opt_intr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001277 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001278 break;
1279 case Opt_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001280 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001281 break;
1282 case Opt_err_panic:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001283 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001284 break;
1285 case Opt_err_ro:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001286 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001287 break;
1288 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001289 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001290 break;
1291 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001292 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001293 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001294 case Opt_user_xattr:
1295 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1296 break;
1297 case Opt_nouser_xattr:
1298 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1299 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001300 case Opt_atime_quantum:
1301 if (match_int(&args[0], &option)) {
1302 status = 0;
1303 goto bail;
1304 }
1305 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001306 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001307 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001308 case Opt_slot:
1309 option = 0;
1310 if (match_int(&args[0], &option)) {
1311 status = 0;
1312 goto bail;
1313 }
1314 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001315 mopt->slot = (s16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001316 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001317 case Opt_commit:
1318 option = 0;
1319 if (match_int(&args[0], &option)) {
1320 status = 0;
1321 goto bail;
1322 }
1323 if (option < 0)
1324 return 0;
1325 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001326 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001327 mopt->commit_interval = HZ * option;
1328 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001329 case Opt_localalloc:
1330 option = 0;
1331 if (match_int(&args[0], &option)) {
1332 status = 0;
1333 goto bail;
1334 }
1335 if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1336 mopt->localalloc_opt = option;
1337 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001338 case Opt_localflocks:
1339 /*
1340 * Changing this during remount could race
1341 * flock() requests, or "unbalance" existing
1342 * ones (e.g., a lock is taken in one mode but
1343 * dropped in the other). If users care enough
1344 * to flip locking modes during remount, we
1345 * could add a "local" flag to individual
1346 * flock structures for proper tracking of
1347 * state.
1348 */
1349 if (!is_remount)
1350 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1351 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001352 case Opt_stack:
1353 /* Check both that the option we were passed
1354 * is of the right length and that it is a proper
1355 * string of the right length.
1356 */
1357 if (((args[0].to - args[0].from) !=
1358 OCFS2_STACK_LABEL_LEN) ||
1359 (strnlen(args[0].from,
1360 OCFS2_STACK_LABEL_LEN) !=
1361 OCFS2_STACK_LABEL_LEN)) {
1362 mlog(ML_ERROR,
1363 "Invalid cluster_stack option\n");
1364 status = 0;
1365 goto bail;
1366 }
1367 memcpy(mopt->cluster_stack, args[0].from,
1368 OCFS2_STACK_LABEL_LEN);
1369 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1370 break;
Joel Becker12462f12008-09-03 20:03:40 -07001371 case Opt_inode64:
1372 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1373 break;
Jan Kara19ece542008-08-21 20:13:17 +02001374 case Opt_usrquota:
1375 /* We check only on remount, otherwise features
1376 * aren't yet initialized. */
1377 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1378 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1379 mlog(ML_ERROR, "User quota requested but "
1380 "filesystem feature is not set\n");
1381 status = 0;
1382 goto bail;
1383 }
1384 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1385 break;
1386 case Opt_grpquota:
1387 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1388 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1389 mlog(ML_ERROR, "Group quota requested but "
1390 "filesystem feature is not set\n");
1391 status = 0;
1392 goto bail;
1393 }
1394 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1395 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001396#ifdef CONFIG_OCFS2_FS_POSIX_ACL
1397 case Opt_acl:
1398 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1399 break;
1400 case Opt_noacl:
1401 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1402 break;
1403#else
1404 case Opt_acl:
1405 case Opt_noacl:
1406 printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
1407 break;
1408#endif
Mark Fashehccd979b2005-12-15 14:31:24 -08001409 default:
1410 mlog(ML_ERROR,
1411 "Unrecognized mount option \"%s\" "
1412 "or missing value\n", p);
1413 status = 0;
1414 goto bail;
1415 }
1416 }
1417
1418 status = 1;
1419
1420bail:
1421 mlog_exit(status);
1422 return status;
1423}
1424
Sunil Mushrand5500712007-09-06 13:34:16 -07001425static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1426{
1427 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1428 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001429 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001430
1431 if (opts & OCFS2_MOUNT_HB_LOCAL)
1432 seq_printf(s, ",_netdev,heartbeat=local");
1433 else
1434 seq_printf(s, ",heartbeat=none");
1435
1436 if (opts & OCFS2_MOUNT_NOINTR)
1437 seq_printf(s, ",nointr");
1438
1439 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1440 seq_printf(s, ",data=writeback");
1441 else
1442 seq_printf(s, ",data=ordered");
1443
1444 if (opts & OCFS2_MOUNT_BARRIER)
1445 seq_printf(s, ",barrier=1");
1446
1447 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1448 seq_printf(s, ",errors=panic");
1449 else
1450 seq_printf(s, ",errors=remount-ro");
1451
1452 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1453 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1454
1455 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1456 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1457
Mark Fashehd147b3d2007-11-07 14:40:36 -08001458 if (osb->osb_commit_interval)
1459 seq_printf(s, ",commit=%u",
1460 (unsigned) (osb->osb_commit_interval / HZ));
1461
Mark Fashehebcee4b2008-07-28 14:55:20 -07001462 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1463 if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1464 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001465
Mark Fasheh53fc6222007-12-20 16:49:04 -08001466 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1467 seq_printf(s, ",localflocks,");
1468
Joel Beckerb61817e2008-02-01 15:08:23 -08001469 if (osb->osb_cluster_stack[0])
1470 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1471 osb->osb_cluster_stack);
Jan Kara19ece542008-08-21 20:13:17 +02001472 if (opts & OCFS2_MOUNT_USRQUOTA)
1473 seq_printf(s, ",usrquota");
1474 if (opts & OCFS2_MOUNT_GRPQUOTA)
1475 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001476
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001477 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1478 seq_printf(s, ",nouser_xattr");
1479 else
1480 seq_printf(s, ",user_xattr");
1481
Joel Becker12462f12008-09-03 20:03:40 -07001482 if (opts & OCFS2_MOUNT_INODE64)
1483 seq_printf(s, ",inode64");
1484
Tiger Yanga68979b2008-11-14 11:17:52 +08001485#ifdef CONFIG_OCFS2_FS_POSIX_ACL
1486 if (opts & OCFS2_MOUNT_POSIX_ACL)
1487 seq_printf(s, ",acl");
1488 else
1489 seq_printf(s, ",noacl");
1490#endif
1491
Sunil Mushrand5500712007-09-06 13:34:16 -07001492 return 0;
1493}
1494
Mark Fashehccd979b2005-12-15 14:31:24 -08001495static int __init ocfs2_init(void)
1496{
1497 int status;
1498
1499 mlog_entry_void();
1500
1501 ocfs2_print_version();
1502
Mark Fashehccd979b2005-12-15 14:31:24 -08001503 status = init_ocfs2_uptodate_cache();
1504 if (status < 0) {
1505 mlog_errno(status);
1506 goto leave;
1507 }
1508
1509 status = ocfs2_initialize_mem_caches();
1510 if (status < 0) {
1511 mlog_errno(status);
1512 goto leave;
1513 }
1514
1515 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1516 if (!ocfs2_wq) {
1517 status = -ENOMEM;
1518 goto leave;
1519 }
1520
Mark Fashehccd979b2005-12-15 14:31:24 -08001521 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1522 if (!ocfs2_debugfs_root) {
1523 status = -EFAULT;
1524 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1525 }
1526
Mark Fasheh171bf932008-10-20 15:36:47 +02001527 status = ocfs2_quota_setup();
1528 if (status)
1529 goto leave;
1530
Joel Becker63e0c482008-01-30 16:58:36 -08001531 ocfs2_set_locking_protocol();
1532
Jan Kara9e33d692008-08-25 19:56:50 +02001533 status = register_quota_format(&ocfs2_quota_format);
Mark Fashehccd979b2005-12-15 14:31:24 -08001534leave:
1535 if (status < 0) {
Mark Fasheh171bf932008-10-20 15:36:47 +02001536 ocfs2_quota_shutdown();
Mark Fashehccd979b2005-12-15 14:31:24 -08001537 ocfs2_free_mem_caches();
1538 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001539 }
1540
1541 mlog_exit(status);
1542
1543 if (status >= 0) {
1544 return register_filesystem(&ocfs2_fs_type);
1545 } else
1546 return -1;
1547}
1548
1549static void __exit ocfs2_exit(void)
1550{
1551 mlog_entry_void();
1552
Mark Fasheh171bf932008-10-20 15:36:47 +02001553 ocfs2_quota_shutdown();
1554
Mark Fashehccd979b2005-12-15 14:31:24 -08001555 if (ocfs2_wq) {
1556 flush_workqueue(ocfs2_wq);
1557 destroy_workqueue(ocfs2_wq);
1558 }
1559
Jan Kara9e33d692008-08-25 19:56:50 +02001560 unregister_quota_format(&ocfs2_quota_format);
1561
Mark Fashehccd979b2005-12-15 14:31:24 -08001562 debugfs_remove(ocfs2_debugfs_root);
1563
1564 ocfs2_free_mem_caches();
1565
1566 unregister_filesystem(&ocfs2_fs_type);
1567
Mark Fashehccd979b2005-12-15 14:31:24 -08001568 exit_ocfs2_uptodate_cache();
1569
1570 mlog_exit_void();
1571}
1572
1573static void ocfs2_put_super(struct super_block *sb)
1574{
1575 mlog_entry("(0x%p)\n", sb);
1576
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001577 lock_kernel();
1578
Mark Fashehccd979b2005-12-15 14:31:24 -08001579 ocfs2_sync_blockdev(sb);
1580 ocfs2_dismount_volume(sb, 0);
1581
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001582 unlock_kernel();
1583
Mark Fashehccd979b2005-12-15 14:31:24 -08001584 mlog_exit_void();
1585}
1586
David Howells726c3342006-06-23 02:02:58 -07001587static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001588{
1589 struct ocfs2_super *osb;
1590 u32 numbits, freebits;
1591 int status;
1592 struct ocfs2_dinode *bm_lock;
1593 struct buffer_head *bh = NULL;
1594 struct inode *inode = NULL;
1595
David Howells726c3342006-06-23 02:02:58 -07001596 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001597
David Howells726c3342006-06-23 02:02:58 -07001598 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001599
1600 inode = ocfs2_get_system_file_inode(osb,
1601 GLOBAL_BITMAP_SYSTEM_INODE,
1602 OCFS2_INVALID_SLOT);
1603 if (!inode) {
1604 mlog(ML_ERROR, "failed to get bitmap inode\n");
1605 status = -EIO;
1606 goto bail;
1607 }
1608
Mark Fashehe63aecb62007-10-18 15:30:42 -07001609 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001610 if (status < 0) {
1611 mlog_errno(status);
1612 goto bail;
1613 }
1614
1615 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1616
1617 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1618 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1619
1620 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001621 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001622 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1623 buf->f_blocks = ((sector_t) numbits) *
1624 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1625 buf->f_bfree = ((sector_t) freebits) *
1626 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1627 buf->f_bavail = buf->f_bfree;
1628 buf->f_files = numbits;
1629 buf->f_ffree = freebits;
1630
1631 brelse(bh);
1632
Mark Fashehe63aecb62007-10-18 15:30:42 -07001633 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001634 status = 0;
1635bail:
1636 if (inode)
1637 iput(inode);
1638
1639 mlog_exit(status);
1640
1641 return status;
1642}
1643
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001644static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001645{
1646 struct ocfs2_inode_info *oi = data;
1647
Christoph Lametera35afb82007-05-16 22:10:57 -07001648 oi->ip_flags = 0;
1649 oi->ip_open_count = 0;
1650 spin_lock_init(&oi->ip_lock);
1651 ocfs2_extent_map_init(&oi->vfs_inode);
1652 INIT_LIST_HEAD(&oi->ip_io_markers);
1653 oi->ip_created_trans = 0;
1654 oi->ip_last_trans = 0;
1655 oi->ip_dir_start_lookup = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001656
Christoph Lametera35afb82007-05-16 22:10:57 -07001657 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001658 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001659 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001660
Christoph Lametera35afb82007-05-16 22:10:57 -07001661 oi->ip_blkno = 0ULL;
1662 oi->ip_clusters = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001663
Christoph Lametera35afb82007-05-16 22:10:57 -07001664 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001665 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001666 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001667
Christoph Lametera35afb82007-05-16 22:10:57 -07001668 ocfs2_metadata_cache_init(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001669
Christoph Lametera35afb82007-05-16 22:10:57 -07001670 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001671}
1672
1673static int ocfs2_initialize_mem_caches(void)
1674{
1675 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001676 sizeof(struct ocfs2_inode_info),
1677 0,
1678 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1679 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001680 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001681 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1682 sizeof(struct ocfs2_dquot),
1683 0,
1684 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1685 SLAB_MEM_SPREAD),
1686 NULL);
1687 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1688 sizeof(struct ocfs2_quota_chunk),
1689 0,
1690 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1691 NULL);
1692 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1693 !ocfs2_qf_chunk_cachep) {
1694 if (ocfs2_inode_cachep)
1695 kmem_cache_destroy(ocfs2_inode_cachep);
1696 if (ocfs2_dquot_cachep)
1697 kmem_cache_destroy(ocfs2_dquot_cachep);
1698 if (ocfs2_qf_chunk_cachep)
1699 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001700 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001701 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001702
Mark Fashehccd979b2005-12-15 14:31:24 -08001703 return 0;
1704}
1705
1706static void ocfs2_free_mem_caches(void)
1707{
1708 if (ocfs2_inode_cachep)
1709 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001710 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001711
1712 if (ocfs2_dquot_cachep)
1713 kmem_cache_destroy(ocfs2_dquot_cachep);
1714 ocfs2_dquot_cachep = NULL;
1715
1716 if (ocfs2_qf_chunk_cachep)
1717 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1718 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001719}
1720
1721static int ocfs2_get_sector(struct super_block *sb,
1722 struct buffer_head **bh,
1723 int block,
1724 int sect_size)
1725{
1726 if (!sb_set_blocksize(sb, sect_size)) {
1727 mlog(ML_ERROR, "unable to set blocksize\n");
1728 return -EIO;
1729 }
1730
1731 *bh = sb_getblk(sb, block);
1732 if (!*bh) {
1733 mlog_errno(-EIO);
1734 return -EIO;
1735 }
1736 lock_buffer(*bh);
1737 if (!buffer_dirty(*bh))
1738 clear_buffer_uptodate(*bh);
1739 unlock_buffer(*bh);
1740 ll_rw_block(READ, 1, bh);
1741 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001742 if (!buffer_uptodate(*bh)) {
1743 mlog_errno(-EIO);
1744 brelse(*bh);
1745 *bh = NULL;
1746 return -EIO;
1747 }
1748
Mark Fashehccd979b2005-12-15 14:31:24 -08001749 return 0;
1750}
1751
Mark Fashehccd979b2005-12-15 14:31:24 -08001752static int ocfs2_mount_volume(struct super_block *sb)
1753{
1754 int status = 0;
1755 int unlock_super = 0;
1756 struct ocfs2_super *osb = OCFS2_SB(sb);
1757
1758 mlog_entry_void();
1759
1760 if (ocfs2_is_hard_readonly(osb))
1761 goto leave;
1762
Mark Fashehccd979b2005-12-15 14:31:24 -08001763 status = ocfs2_dlm_init(osb);
1764 if (status < 0) {
1765 mlog_errno(status);
1766 goto leave;
1767 }
1768
Mark Fashehccd979b2005-12-15 14:31:24 -08001769 status = ocfs2_super_lock(osb, 1);
1770 if (status < 0) {
1771 mlog_errno(status);
1772 goto leave;
1773 }
1774 unlock_super = 1;
1775
1776 /* This will load up the node map and add ourselves to it. */
1777 status = ocfs2_find_slot(osb);
1778 if (status < 0) {
1779 mlog_errno(status);
1780 goto leave;
1781 }
1782
Mark Fashehccd979b2005-12-15 14:31:24 -08001783 /* load all node-local system inodes */
1784 status = ocfs2_init_local_system_inodes(osb);
1785 if (status < 0) {
1786 mlog_errno(status);
1787 goto leave;
1788 }
1789
1790 status = ocfs2_check_volume(osb);
1791 if (status < 0) {
1792 mlog_errno(status);
1793 goto leave;
1794 }
1795
1796 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001797 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001798 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001799
Mark Fashehccd979b2005-12-15 14:31:24 -08001800leave:
1801 if (unlock_super)
1802 ocfs2_super_unlock(osb, 1);
1803
1804 mlog_exit(status);
1805 return status;
1806}
1807
Mark Fashehccd979b2005-12-15 14:31:24 -08001808static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1809{
Joel Becker286eaa92008-02-01 15:03:57 -08001810 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001811 struct ocfs2_super *osb = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001812 char nodestr[8];
Mark Fashehccd979b2005-12-15 14:31:24 -08001813
1814 mlog_entry("(0x%p)\n", sb);
1815
1816 BUG_ON(!sb);
1817 osb = OCFS2_SB(sb);
1818 BUG_ON(!osb);
1819
Sunil Mushran50397502008-12-17 14:17:43 -08001820 debugfs_remove(osb->osb_ctxt);
1821
Sunil Mushran692684e2009-06-19 16:53:17 -07001822 /* Orphan scan should be stopped as early as possible */
1823 ocfs2_orphan_scan_stop(osb);
1824
Jan Kara19ece542008-08-21 20:13:17 +02001825 ocfs2_disable_quotas(osb);
1826
Mark Fashehccd979b2005-12-15 14:31:24 -08001827 ocfs2_shutdown_local_alloc(osb);
1828
1829 ocfs2_truncate_log_shutdown(osb);
1830
Joel Becker553abd02008-02-01 12:03:57 -08001831 /* This will disable recovery and flush any recovery work. */
1832 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001833
1834 ocfs2_journal_shutdown(osb);
1835
1836 ocfs2_sync_blockdev(sb);
1837
Joel Becker4670c462008-02-01 14:39:35 -08001838 /* No cluster connection means we've failed during mount, so skip
1839 * all the steps which depended on that to complete. */
1840 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001841 tmp = ocfs2_super_lock(osb, 1);
1842 if (tmp < 0) {
1843 mlog_errno(tmp);
1844 return;
1845 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001846 }
1847
Mark Fasheh19b613d2007-10-04 14:47:09 -07001848 if (osb->slot_num != OCFS2_INVALID_SLOT)
1849 ocfs2_put_slot(osb);
1850
Joel Becker4670c462008-02-01 14:39:35 -08001851 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001852 ocfs2_super_unlock(osb, 1);
1853
Mark Fashehccd979b2005-12-15 14:31:24 -08001854 ocfs2_release_system_inodes(osb);
1855
Joel Becker6953b4c2008-01-29 16:59:56 -08001856 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001857 * If we're dismounting due to mount error, mount.ocfs2 will clean
1858 * up heartbeat. If we're a local mount, there is no heartbeat.
1859 * If we failed before we got a uuid_str yet, we can't stop
1860 * heartbeat. Otherwise, do it.
1861 */
1862 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
Joel Becker286eaa92008-02-01 15:03:57 -08001863 hangup_needed = 1;
1864
1865 if (osb->cconn)
1866 ocfs2_dlm_shutdown(osb, hangup_needed);
1867
Joel Becker73be1922009-01-06 14:57:08 -08001868 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Joel Becker286eaa92008-02-01 15:03:57 -08001869 debugfs_remove(osb->osb_debug_root);
1870
1871 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001872 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001873
1874 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1875
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001876 if (ocfs2_mount_local(osb))
1877 snprintf(nodestr, sizeof(nodestr), "local");
1878 else
Joel Becker19fdb622008-01-30 15:38:24 -08001879 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001880
1881 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1882 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001883
1884 ocfs2_delete_osb(osb);
1885 kfree(osb);
1886 sb->s_dev = 0;
1887 sb->s_fs_info = NULL;
1888}
1889
1890static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1891 unsigned uuid_bytes)
1892{
1893 int i, ret;
1894 char *ptr;
1895
1896 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1897
Robert P. J. Daycd861282006-12-13 00:34:52 -08001898 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001899 if (osb->uuid_str == NULL)
1900 return -ENOMEM;
1901
Mark Fashehccd979b2005-12-15 14:31:24 -08001902 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1903 /* print with null */
1904 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1905 if (ret != 2) /* drop super cleans up */
1906 return -EINVAL;
1907 /* then only advance past the last char */
1908 ptr += 2;
1909 }
1910
1911 return 0;
1912}
1913
1914static int ocfs2_initialize_super(struct super_block *sb,
1915 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08001916 int sector_size,
1917 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08001918{
Denis Chengbddb8eb32007-09-27 02:10:04 +08001919 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07001920 int i, cbits, bbits;
1921 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08001922 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001923 struct ocfs2_journal *journal;
1924 __le32 uuid_net_key;
1925 struct ocfs2_super *osb;
1926
1927 mlog_entry_void();
1928
Robert P. J. Daycd861282006-12-13 00:34:52 -08001929 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001930 if (!osb) {
1931 status = -ENOMEM;
1932 mlog_errno(status);
1933 goto bail;
1934 }
1935
1936 sb->s_fs_info = osb;
1937 sb->s_op = &ocfs2_sops;
1938 sb->s_export_op = &ocfs2_export_ops;
Jan Kara19ece542008-08-21 20:13:17 +02001939 sb->s_qcop = &ocfs2_quotactl_ops;
1940 sb->dq_op = &ocfs2_quota_operations;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001941 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07001942 sb->s_time_gran = 1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001943 sb->s_flags |= MS_NOATIME;
1944 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07001945 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1946 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1947 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001948
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001949 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
1950
1951 for (i = 0; i < 3; i++)
1952 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
1953 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1954
Mark Fashehccd979b2005-12-15 14:31:24 -08001955 osb->sb = sb;
1956 /* Save off for ocfs2_rw_direct */
1957 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01001958 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001959
Mark Fasheh34d024f2007-09-24 15:56:19 -07001960 spin_lock_init(&osb->dc_task_lock);
1961 init_waitqueue_head(&osb->dc_event);
1962 osb->dc_work_sequence = 0;
1963 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001964 INIT_LIST_HEAD(&osb->blocked_lock_list);
1965 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001966 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08001967 spin_lock_init(&osb->osb_xattr_lock);
Tao Ma4d0ddb22008-03-05 16:11:46 +08001968 ocfs2_init_inode_steal_slot(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001969
1970 atomic_set(&osb->alloc_stats.moves, 0);
1971 atomic_set(&osb->alloc_stats.local_data, 0);
1972 atomic_set(&osb->alloc_stats.bitmap_data, 0);
1973 atomic_set(&osb->alloc_stats.bg_allocs, 0);
1974 atomic_set(&osb->alloc_stats.bg_extends, 0);
1975
Joel Becker73be1922009-01-06 14:57:08 -08001976 /* Copy the blockcheck stats from the superblock probe */
1977 osb->osb_ecc_stats = *stats;
1978
Mark Fashehccd979b2005-12-15 14:31:24 -08001979 ocfs2_init_node_maps(osb);
1980
1981 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
1982 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
1983
Joel Becker553abd02008-02-01 12:03:57 -08001984 status = ocfs2_recovery_init(osb);
1985 if (status) {
1986 mlog(ML_ERROR, "Unable to initialize recovery state\n");
1987 mlog_errno(status);
1988 goto bail;
1989 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001990
1991 init_waitqueue_head(&osb->checkpoint_event);
1992 atomic_set(&osb->needs_checkpoint, 0);
1993
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001994 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1995
Mark Fashehccd979b2005-12-15 14:31:24 -08001996 osb->slot_num = OCFS2_INVALID_SLOT;
1997
Tiger Yang8154da32008-08-18 17:11:46 +08001998 osb->s_xattr_inline_size = le16_to_cpu(
1999 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002000
Mark Fashehccd979b2005-12-15 14:31:24 -08002001 osb->local_alloc_state = OCFS2_LA_UNUSED;
2002 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002003 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002004
Mark Fashehccd979b2005-12-15 14:31:24 -08002005 init_waitqueue_head(&osb->osb_mount_event);
2006
2007 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2008 if (!osb->vol_label) {
2009 mlog(ML_ERROR, "unable to alloc vol label\n");
2010 status = -ENOMEM;
2011 goto bail;
2012 }
2013
Mark Fashehccd979b2005-12-15 14:31:24 -08002014 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2015 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2016 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2017 osb->max_slots);
2018 status = -EINVAL;
2019 goto bail;
2020 }
Sunil Mushran781ee3e2006-04-27 16:41:31 -07002021 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
Mark Fashehccd979b2005-12-15 14:31:24 -08002022
Sunil Mushran539d8262008-07-14 17:31:10 -07002023 osb->slot_recovery_generations =
2024 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2025 GFP_KERNEL);
2026 if (!osb->slot_recovery_generations) {
2027 status = -ENOMEM;
2028 mlog_errno(status);
2029 goto bail;
2030 }
2031
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002032 init_waitqueue_head(&osb->osb_wipe_event);
2033 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2034 sizeof(*osb->osb_orphan_wipes),
2035 GFP_KERNEL);
2036 if (!osb->osb_orphan_wipes) {
2037 status = -ENOMEM;
2038 mlog_errno(status);
2039 goto bail;
2040 }
2041
Mark Fashehccd979b2005-12-15 14:31:24 -08002042 osb->s_feature_compat =
2043 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2044 osb->s_feature_ro_compat =
2045 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2046 osb->s_feature_incompat =
2047 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2048
2049 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2050 mlog(ML_ERROR, "couldn't mount because of unsupported "
2051 "optional features (%x).\n", i);
2052 status = -EINVAL;
2053 goto bail;
2054 }
2055 if (!(osb->sb->s_flags & MS_RDONLY) &&
2056 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2057 mlog(ML_ERROR, "couldn't mount RDWR because of "
2058 "unsupported optional features (%x).\n", i);
2059 status = -EINVAL;
2060 goto bail;
2061 }
2062
Joel Beckerb61817e2008-02-01 15:08:23 -08002063 if (ocfs2_userspace_stack(osb)) {
2064 memcpy(osb->osb_cluster_stack,
2065 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2066 OCFS2_STACK_LABEL_LEN);
2067 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2068 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2069 mlog(ML_ERROR,
2070 "couldn't mount because of an invalid "
2071 "cluster stack label (%s) \n",
2072 osb->osb_cluster_stack);
2073 status = -EINVAL;
2074 goto bail;
2075 }
2076 } else {
2077 /* The empty string is identical with classic tools that
2078 * don't know about s_cluster_info. */
2079 osb->osb_cluster_stack[0] = '\0';
2080 }
2081
Mark Fashehccd979b2005-12-15 14:31:24 -08002082 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2083
2084 /* FIXME
2085 * This should be done in ocfs2_journal_init(), but unknown
2086 * ordering issues will cause the filesystem to crash.
2087 * If anyone wants to figure out what part of the code
2088 * refers to osb->journal before ocfs2_journal_init() is run,
2089 * be my guest.
2090 */
2091 /* initialize our journal structure */
2092
Robert P. J. Daycd861282006-12-13 00:34:52 -08002093 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002094 if (!journal) {
2095 mlog(ML_ERROR, "unable to alloc journal\n");
2096 status = -ENOMEM;
2097 goto bail;
2098 }
2099 osb->journal = journal;
2100 journal->j_osb = osb;
2101
2102 atomic_set(&journal->j_num_trans, 0);
2103 init_rwsem(&journal->j_trans_barrier);
2104 init_waitqueue_head(&journal->j_checkpointed);
2105 spin_lock_init(&journal->j_lock);
2106 journal->j_trans_id = (unsigned long) 1;
2107 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002108 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002109 journal->j_state = OCFS2_JOURNAL_FREE;
2110
Jan Karaea455f82009-01-12 23:20:31 +01002111 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2112 osb->dentry_lock_list = NULL;
2113
Mark Fashehccd979b2005-12-15 14:31:24 -08002114 /* get some pseudo constants for clustersize bits */
2115 osb->s_clustersize_bits =
2116 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2117 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2118 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2119
2120 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2121 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2122 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2123 osb->s_clustersize);
2124 status = -EINVAL;
2125 goto bail;
2126 }
2127
2128 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2129 > (u32)~0UL) {
2130 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2131 "what jbd can address in 32 bits.\n");
2132 status = -EINVAL;
2133 goto bail;
2134 }
2135
2136 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2137 sizeof(di->id2.i_super.s_uuid))) {
2138 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2139 status = -ENOMEM;
2140 goto bail;
2141 }
2142
Mark Fasheh78427042006-05-04 12:03:26 -07002143 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
Mark Fashehccd979b2005-12-15 14:31:24 -08002144
2145 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2146 osb->vol_label[63] = '\0';
2147 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2148 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2149 osb->first_cluster_group_blkno =
2150 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2151 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002152 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Mark Fashehccd979b2005-12-15 14:31:24 -08002153 mlog(0, "vol_label: %s\n", osb->vol_label);
2154 mlog(0, "uuid: %s\n", osb->uuid_str);
Mark Fashehb06970532006-03-03 10:24:33 -08002155 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2156 (unsigned long long)osb->root_blkno,
2157 (unsigned long long)osb->system_dir_blkno);
Mark Fashehccd979b2005-12-15 14:31:24 -08002158
2159 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2160 if (!osb->osb_dlm_debug) {
2161 status = -ENOMEM;
2162 mlog_errno(status);
2163 goto bail;
2164 }
2165
2166 atomic_set(&osb->vol_state, VOLUME_INIT);
2167
2168 /* load root, system_dir, and all global system inodes */
2169 status = ocfs2_init_global_system_inodes(osb);
2170 if (status < 0) {
2171 mlog_errno(status);
2172 goto bail;
2173 }
2174
2175 /*
2176 * global bitmap
2177 */
2178 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2179 OCFS2_INVALID_SLOT);
2180 if (!inode) {
2181 status = -EINVAL;
2182 mlog_errno(status);
2183 goto bail;
2184 }
2185
2186 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fashehccd979b2005-12-15 14:31:24 -08002187 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002188
Tao Mae9d578a2007-12-18 15:46:10 +08002189 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002190
2191 status = ocfs2_init_slot_info(osb);
2192 if (status < 0) {
2193 mlog_errno(status);
2194 goto bail;
2195 }
2196
Mark Fashehccd979b2005-12-15 14:31:24 -08002197bail:
2198 mlog_exit(status);
2199 return status;
2200}
2201
2202/*
2203 * will return: -EAGAIN if it is ok to keep searching for superblocks
2204 * -EINVAL if there is a bad superblock
2205 * 0 on success
2206 */
2207static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2208 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002209 u32 blksz,
2210 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002211{
2212 int status = -EAGAIN;
2213
2214 mlog_entry_void();
2215
2216 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2217 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002218 /* We have to do a raw check of the feature here */
2219 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2220 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2221 status = ocfs2_block_check_validate(bh->b_data,
2222 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002223 &di->i_check,
2224 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002225 if (status)
2226 goto out;
2227 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002228 status = -EINVAL;
2229 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2230 mlog(ML_ERROR, "found superblock with incorrect block "
2231 "size: found %u, should be %u\n",
2232 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2233 blksz);
2234 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2235 OCFS2_MAJOR_REV_LEVEL ||
2236 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2237 OCFS2_MINOR_REV_LEVEL) {
2238 mlog(ML_ERROR, "found superblock with bad version: "
2239 "found %u.%u, should be %u.%u\n",
2240 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2241 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2242 OCFS2_MAJOR_REV_LEVEL,
2243 OCFS2_MINOR_REV_LEVEL);
2244 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2245 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb06970532006-03-03 10:24:33 -08002246 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002247 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb06970532006-03-03 10:24:33 -08002248 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002249 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2250 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2251 mlog(ML_ERROR, "bad cluster size found: %u\n",
2252 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2253 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2254 mlog(ML_ERROR, "bad root_blkno: 0\n");
2255 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2256 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2257 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2258 mlog(ML_ERROR,
2259 "Superblock slots found greater than file system "
2260 "maximum: found %u, max %u\n",
2261 le16_to_cpu(di->id2.i_super.s_max_slots),
2262 OCFS2_MAX_SLOTS);
2263 } else {
2264 /* found it! */
2265 status = 0;
2266 }
2267 }
2268
Joel Beckerd030cc92008-12-11 15:04:14 -08002269out:
Mark Fashehccd979b2005-12-15 14:31:24 -08002270 mlog_exit(status);
2271 return status;
2272}
2273
2274static int ocfs2_check_volume(struct ocfs2_super *osb)
2275{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002276 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002277 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002278 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002279 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2280 * recover
2281 * ourselves. */
2282
2283 mlog_entry_void();
2284
2285 /* Init our journal object. */
2286 status = ocfs2_journal_init(osb->journal, &dirty);
2287 if (status < 0) {
2288 mlog(ML_ERROR, "Could not initialize journal!\n");
2289 goto finally;
2290 }
2291
2292 /* If the journal was unmounted cleanly then we don't want to
2293 * recover anything. Otherwise, journal_load will do that
2294 * dirty work for us :) */
2295 if (!dirty) {
2296 status = ocfs2_journal_wipe(osb->journal, 0);
2297 if (status < 0) {
2298 mlog_errno(status);
2299 goto finally;
2300 }
2301 } else {
2302 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2303 "recovering volume.\n");
2304 }
2305
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002306 local = ocfs2_mount_local(osb);
2307
Mark Fashehccd979b2005-12-15 14:31:24 -08002308 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002309 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002310 if (status < 0) {
2311 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2312 goto finally;
2313 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002314
2315 if (dirty) {
2316 /* recover my local alloc if we didn't unmount cleanly. */
2317 status = ocfs2_begin_local_alloc_recovery(osb,
2318 osb->slot_num,
2319 &local_alloc);
2320 if (status < 0) {
2321 mlog_errno(status);
2322 goto finally;
2323 }
2324 /* we complete the recovery process after we've marked
2325 * ourselves as mounted. */
2326 }
2327
2328 mlog(0, "Journal loaded.\n");
2329
2330 status = ocfs2_load_local_alloc(osb);
2331 if (status < 0) {
2332 mlog_errno(status);
2333 goto finally;
2334 }
2335
2336 if (dirty) {
2337 /* Recovery will be completed after we've mounted the
2338 * rest of the volume. */
2339 osb->dirty = 1;
2340 osb->local_alloc_copy = local_alloc;
2341 local_alloc = NULL;
2342 }
2343
2344 /* go through each journal, trylock it and if you get the
2345 * lock, and it's marked as dirty, set the bit in the recover
2346 * map and launch a recovery thread for it. */
2347 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002348 if (status < 0) {
2349 mlog_errno(status);
2350 goto finally;
2351 }
2352
2353 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002354 if (status < 0)
2355 mlog_errno(status);
2356
2357finally:
2358 if (local_alloc)
2359 kfree(local_alloc);
2360
2361 mlog_exit(status);
2362 return status;
2363}
2364
2365/*
2366 * The routine gets called from dismount or close whenever a dismount on
2367 * volume is requested and the osb open count becomes 1.
2368 * It will remove the osb from the global list and also free up all the
2369 * initialized resources and fileobject.
2370 */
2371static void ocfs2_delete_osb(struct ocfs2_super *osb)
2372{
2373 mlog_entry_void();
2374
2375 /* This function assumes that the caller has the main osb resource */
2376
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002377 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002378
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002379 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002380 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002381 /* FIXME
2382 * This belongs in journal shutdown, but because we have to
2383 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2384 * we free it here.
2385 */
2386 kfree(osb->journal);
2387 if (osb->local_alloc_copy)
2388 kfree(osb->local_alloc_copy);
2389 kfree(osb->uuid_str);
2390 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2391 memset(osb, 0, sizeof(struct ocfs2_super));
2392
2393 mlog_exit_void();
2394}
2395
2396/* Put OCFS2 into a readonly state, or (if the user specifies it),
2397 * panic(). We do not support continue-on-error operation. */
2398static void ocfs2_handle_error(struct super_block *sb)
2399{
2400 struct ocfs2_super *osb = OCFS2_SB(sb);
2401
2402 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2403 panic("OCFS2: (device %s): panic forced after error\n",
2404 sb->s_id);
2405
2406 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2407
2408 if (sb->s_flags & MS_RDONLY &&
2409 (ocfs2_is_soft_readonly(osb) ||
2410 ocfs2_is_hard_readonly(osb)))
2411 return;
2412
2413 printk(KERN_CRIT "File system is now read-only due to the potential "
2414 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2415 "system is unmounted.\n");
2416 sb->s_flags |= MS_RDONLY;
2417 ocfs2_set_ro_flag(osb, 0);
2418}
2419
2420static char error_buf[1024];
2421
2422void __ocfs2_error(struct super_block *sb,
2423 const char *function,
2424 const char *fmt, ...)
2425{
2426 va_list args;
2427
2428 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002429 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002430 va_end(args);
2431
2432 /* Not using mlog here because we want to show the actual
2433 * function the error came from. */
2434 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2435 sb->s_id, function, error_buf);
2436
2437 ocfs2_handle_error(sb);
2438}
2439
2440/* Handle critical errors. This is intentionally more drastic than
2441 * ocfs2_handle_error, so we only use for things like journal errors,
2442 * etc. */
2443void __ocfs2_abort(struct super_block* sb,
2444 const char *function,
2445 const char *fmt, ...)
2446{
2447 va_list args;
2448
2449 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002450 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002451 va_end(args);
2452
2453 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2454 sb->s_id, function, error_buf);
2455
2456 /* We don't have the cluster support yet to go straight to
2457 * hard readonly in here. Until then, we want to keep
2458 * ocfs2_abort() so that we can at least mark critical
2459 * errors.
2460 *
2461 * TODO: This should abort the journal and alert other nodes
2462 * that our slot needs recovery. */
2463
2464 /* Force a panic(). This stinks, but it's better than letting
2465 * things continue without having a proper hard readonly
2466 * here. */
2467 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
2468 ocfs2_handle_error(sb);
2469}
2470
2471module_init(ocfs2_init);
2472module_exit(ocfs2_exit);