blob: c0e48aeebb1c3877862853ec1761bed05e6f9355 [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>
Mark Fashehccd979b2005-12-15 14:31:24 -080031#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>
Sunil Mushrand5500712007-09-06 13:34:16 -070041#include <linux/mount.h>
Joel Becker6953b4c2008-01-29 16:59:56 -080042#include <linux/seq_file.h>
Jan Kara19ece542008-08-21 20:13:17 +020043#include <linux/quotaops.h>
Alessio Igor Bogani337eb002009-05-12 15:10:54 +020044#include <linux/smp_lock.h>
Mark Fashehccd979b2005-12-15 14:31:24 -080045
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"
Joel Beckerd030cc92008-12-11 15:04:14 -080055#include "blockcheck.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080056#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"
Tiger Yangcf1d6c72008-08-18 17:11:00 +080069#include "xattr.h"
Jan Kara9e33d692008-08-25 19:56:50 +020070#include "quota.h"
Tao Ma374a2632009-08-24 11:13:37 +080071#include "refcounttree.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
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700376static const struct file_operations ocfs2_osb_debug_fops = {
Sunil Mushran50397502008-12-17 14:17:43 -0800377 .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));
Jan Kara1c1d9792009-07-22 13:17:19 +0200780 spin_lock_init(&stats->b_lock);
Joel Becker73be1922009-01-06 14:57:08 -0800781 status = ocfs2_verify_volume(di, *bh, blksize, stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800782 if (status >= 0)
783 goto bail;
784 brelse(*bh);
785 *bh = NULL;
786 if (status != -EAGAIN)
787 break;
788 }
789
790bail:
791 return status;
792}
793
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800794static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
795{
796 if (ocfs2_mount_local(osb)) {
797 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
798 mlog(ML_ERROR, "Cannot heartbeat on a locally "
799 "mounted device.\n");
800 return -EINVAL;
801 }
802 }
803
Joel Beckerb61817e2008-02-01 15:08:23 -0800804 if (ocfs2_userspace_stack(osb)) {
805 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
806 mlog(ML_ERROR, "Userspace stack expected, but "
807 "o2cb heartbeat arguments passed to mount\n");
808 return -EINVAL;
809 }
810 }
811
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800812 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800813 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
814 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800815 mlog(ML_ERROR, "Heartbeat has to be started to mount "
816 "a read-write clustered device.\n");
817 return -EINVAL;
818 }
819 }
820
821 return 0;
822}
823
Joel Beckerb61817e2008-02-01 15:08:23 -0800824/*
825 * If we're using a userspace stack, mount should have passed
826 * a name that matches the disk. If not, mount should not
827 * have passed a stack.
828 */
829static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
830 struct mount_options *mopt)
831{
832 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
833 mlog(ML_ERROR,
834 "cluster stack passed to mount, but this filesystem "
835 "does not support it\n");
836 return -EINVAL;
837 }
838
839 if (ocfs2_userspace_stack(osb) &&
840 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
841 OCFS2_STACK_LABEL_LEN)) {
842 mlog(ML_ERROR,
843 "cluster stack passed to mount (\"%s\") does not "
844 "match the filesystem (\"%s\")\n",
845 mopt->cluster_stack,
846 osb->osb_cluster_stack);
847 return -EINVAL;
848 }
849
850 return 0;
851}
852
Jan Kara19ece542008-08-21 20:13:17 +0200853static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
854{
855 int type;
856 struct super_block *sb = osb->sb;
857 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
858 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
859 int status = 0;
860
861 for (type = 0; type < MAXQUOTAS; type++) {
862 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
863 continue;
864 if (unsuspend)
865 status = vfs_quota_enable(
866 sb_dqopt(sb)->files[type],
867 type, QFMT_OCFS2,
868 DQUOT_SUSPENDED);
869 else
870 status = vfs_quota_disable(sb, type,
871 DQUOT_SUSPENDED);
872 if (status < 0)
873 break;
874 }
875 if (status < 0)
876 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
877 "remount (error = %d).\n", status);
878 return status;
879}
880
881static int ocfs2_enable_quotas(struct ocfs2_super *osb)
882{
883 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
884 struct super_block *sb = osb->sb;
885 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
886 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
887 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
888 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
889 int status;
890 int type;
891
892 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
893 for (type = 0; type < MAXQUOTAS; type++) {
894 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
895 continue;
896 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
897 osb->slot_num);
898 if (!inode[type]) {
899 status = -ENOENT;
900 goto out_quota_off;
901 }
902 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
903 DQUOT_USAGE_ENABLED);
904 if (status < 0)
905 goto out_quota_off;
906 }
907
908 for (type = 0; type < MAXQUOTAS; type++)
909 iput(inode[type]);
910 return 0;
911out_quota_off:
912 ocfs2_disable_quotas(osb);
913 for (type = 0; type < MAXQUOTAS; type++)
914 iput(inode[type]);
915 mlog_errno(status);
916 return status;
917}
918
919static void ocfs2_disable_quotas(struct ocfs2_super *osb)
920{
921 int type;
922 struct inode *inode;
923 struct super_block *sb = osb->sb;
924
925 /* We mostly ignore errors in this function because there's not much
926 * we can do when we see them */
927 for (type = 0; type < MAXQUOTAS; type++) {
928 if (!sb_has_quota_loaded(sb, type))
929 continue;
930 inode = igrab(sb->s_dquot.files[type]);
931 /* Turn off quotas. This will remove all dquot structures from
932 * memory and so they will be automatically synced to global
933 * quota files */
934 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
935 DQUOT_LIMITS_ENABLED);
936 if (!inode)
937 continue;
938 iput(inode);
939 }
940}
941
942/* Handle quota on quotactl */
943static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
944 char *path, int remount)
945{
946 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
947 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
948
949 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
950 return -EINVAL;
951
952 if (remount)
953 return 0; /* Just ignore it has been handled in
954 * ocfs2_remount() */
955 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
956 format_id, DQUOT_LIMITS_ENABLED);
957}
958
959/* Handle quota off quotactl */
960static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
961{
962 if (remount)
963 return 0; /* Ignore now and handle later in
964 * ocfs2_remount() */
965 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
966}
967
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700968static const struct quotactl_ops ocfs2_quotactl_ops = {
Jan Kara19ece542008-08-21 20:13:17 +0200969 .quota_on = ocfs2_quota_on,
970 .quota_off = ocfs2_quota_off,
971 .quota_sync = vfs_quota_sync,
972 .get_info = vfs_get_dqinfo,
973 .set_info = vfs_set_dqinfo,
974 .get_dqblk = vfs_get_dqblk,
975 .set_dqblk = vfs_set_dqblk,
976};
977
Mark Fashehccd979b2005-12-15 14:31:24 -0800978static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
979{
980 struct dentry *root;
981 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800982 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800983 struct inode *inode = NULL;
984 struct ocfs2_super *osb = NULL;
985 struct buffer_head *bh = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800986 char nodestr[8];
Joel Becker73be1922009-01-06 14:57:08 -0800987 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -0800988
989 mlog_entry("%p, %p, %i", sb, data, silent);
990
Tiger Yangc0123ad2007-09-08 00:16:10 +0800991 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800992 status = -EINVAL;
993 goto read_super_error;
994 }
995
996 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -0800997 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800998 if (status < 0) {
999 mlog(ML_ERROR, "superblock probe failed!\n");
1000 goto read_super_error;
1001 }
1002
Joel Becker73be1922009-01-06 14:57:08 -08001003 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001004 osb = OCFS2_SB(sb);
1005 if (status < 0) {
1006 mlog_errno(status);
1007 goto read_super_error;
1008 }
1009 brelse(bh);
1010 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001011
1012 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
1013 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1014
Tiger Yangc0123ad2007-09-08 00:16:10 +08001015 osb->s_mount_opt = parsed_options.mount_opt;
1016 osb->s_atime_quantum = parsed_options.atime_quantum;
1017 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001018 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh9c7af402008-07-28 18:02:53 -07001019 osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
1020 osb->local_alloc_bits = osb->local_alloc_default_bits;
Jan Kara19ece542008-08-21 20:13:17 +02001021 if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA &&
1022 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1023 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1024 status = -EINVAL;
1025 mlog(ML_ERROR, "User quotas were requested, but this "
1026 "filesystem does not have the feature enabled.\n");
1027 goto read_super_error;
1028 }
1029 if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1030 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1031 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1032 status = -EINVAL;
1033 mlog(ML_ERROR, "Group quotas were requested, but this "
1034 "filesystem does not have the feature enabled.\n");
1035 goto read_super_error;
1036 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001037
Joel Beckerb61817e2008-02-01 15:08:23 -08001038 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1039 if (status)
1040 goto read_super_error;
1041
Mark Fashehccd979b2005-12-15 14:31:24 -08001042 sb->s_magic = OCFS2_SUPER_MAGIC;
1043
Tiger Yanga68979b2008-11-14 11:17:52 +08001044 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1045 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1046
Mark Fashehccd979b2005-12-15 14:31:24 -08001047 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1048 * heartbeat=none */
1049 if (bdev_read_only(sb->s_bdev)) {
1050 if (!(sb->s_flags & MS_RDONLY)) {
1051 status = -EACCES;
1052 mlog(ML_ERROR, "Readonly device detected but readonly "
1053 "mount was not specified.\n");
1054 goto read_super_error;
1055 }
1056
1057 /* You should not be able to start a local heartbeat
1058 * on a readonly device. */
1059 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1060 status = -EROFS;
1061 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1062 "device.\n");
1063 goto read_super_error;
1064 }
1065
1066 status = ocfs2_check_journals_nolocks(osb);
1067 if (status < 0) {
1068 if (status == -EROFS)
1069 mlog(ML_ERROR, "Recovery required on readonly "
1070 "file system, but write access is "
1071 "unavailable.\n");
1072 else
1073 mlog_errno(status);
1074 goto read_super_error;
1075 }
1076
1077 ocfs2_set_ro_flag(osb, 1);
1078
1079 printk(KERN_NOTICE "Readonly device detected. No cluster "
1080 "services will be utilized for this mount. Recovery "
1081 "will be skipped.\n");
1082 }
1083
1084 if (!ocfs2_is_hard_readonly(osb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001085 if (sb->s_flags & MS_RDONLY)
1086 ocfs2_set_ro_flag(osb, 0);
1087 }
1088
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001089 status = ocfs2_verify_heartbeat(osb);
1090 if (status < 0) {
1091 mlog_errno(status);
1092 goto read_super_error;
1093 }
1094
Mark Fashehccd979b2005-12-15 14:31:24 -08001095 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1096 ocfs2_debugfs_root);
1097 if (!osb->osb_debug_root) {
1098 status = -EINVAL;
1099 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1100 goto read_super_error;
1101 }
1102
Sunil Mushran50397502008-12-17 14:17:43 -08001103 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1104 osb->osb_debug_root,
1105 osb,
1106 &ocfs2_osb_debug_fops);
1107 if (!osb->osb_ctxt) {
1108 status = -EINVAL;
1109 mlog_errno(status);
1110 goto read_super_error;
1111 }
1112
Joel Becker73be1922009-01-06 14:57:08 -08001113 if (ocfs2_meta_ecc(osb)) {
1114 status = ocfs2_blockcheck_stats_debugfs_install(
1115 &osb->osb_ecc_stats,
1116 osb->osb_debug_root);
1117 if (status) {
1118 mlog(ML_ERROR,
1119 "Unable to create blockcheck statistics "
1120 "files\n");
1121 goto read_super_error;
1122 }
1123 }
1124
Mark Fashehccd979b2005-12-15 14:31:24 -08001125 status = ocfs2_mount_volume(sb);
1126 if (osb->root_inode)
1127 inode = igrab(osb->root_inode);
1128
1129 if (status < 0)
1130 goto read_super_error;
1131
1132 if (!inode) {
1133 status = -EIO;
1134 mlog_errno(status);
1135 goto read_super_error;
1136 }
1137
1138 root = d_alloc_root(inode);
1139 if (!root) {
1140 status = -ENOMEM;
1141 mlog_errno(status);
1142 goto read_super_error;
1143 }
1144
1145 sb->s_root = root;
1146
1147 ocfs2_complete_mount_recovery(osb);
1148
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001149 if (ocfs2_mount_local(osb))
1150 snprintf(nodestr, sizeof(nodestr), "local");
1151 else
Joel Becker19fdb622008-01-30 15:38:24 -08001152 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001153
1154 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001155 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001156 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001157 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1158 "ordered");
1159
1160 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1161 wake_up(&osb->osb_mount_event);
1162
Jan Kara19ece542008-08-21 20:13:17 +02001163 /* Now we can initialize quotas because we can afford to wait
1164 * for cluster locks recovery now. That also means that truncation
1165 * log recovery can happen but that waits for proper quota setup */
1166 if (!(sb->s_flags & MS_RDONLY)) {
1167 status = ocfs2_enable_quotas(osb);
1168 if (status < 0) {
1169 /* We have to err-out specially here because
1170 * s_root is already set */
1171 mlog_errno(status);
1172 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1173 wake_up(&osb->osb_mount_event);
1174 mlog_exit(status);
1175 return status;
1176 }
1177 }
1178
1179 ocfs2_complete_quota_recovery(osb);
1180
1181 /* Now we wake up again for processes waiting for quotas */
1182 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1183 wake_up(&osb->osb_mount_event);
1184
Sunil Mushrandf152c22009-06-22 11:40:07 -07001185 /* Start this when the mount is almost sure of being successful */
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04001186 ocfs2_orphan_scan_start(osb);
Sunil Mushrandf152c22009-06-22 11:40:07 -07001187
Mark Fashehccd979b2005-12-15 14:31:24 -08001188 mlog_exit(status);
1189 return status;
1190
1191read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001192 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001193
1194 if (inode)
1195 iput(inode);
1196
1197 if (osb) {
1198 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1199 wake_up(&osb->osb_mount_event);
1200 ocfs2_dismount_volume(sb, 1);
1201 }
1202
1203 mlog_exit(status);
1204 return status;
1205}
1206
David Howells454e2392006-06-23 02:02:57 -07001207static int ocfs2_get_sb(struct file_system_type *fs_type,
1208 int flags,
1209 const char *dev_name,
1210 void *data,
1211 struct vfsmount *mnt)
Mark Fashehccd979b2005-12-15 14:31:24 -08001212{
David Howells454e2392006-06-23 02:02:57 -07001213 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1214 mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -08001215}
1216
Jan Karaf7b1aa62009-07-20 12:12:36 +02001217static void ocfs2_kill_sb(struct super_block *sb)
1218{
1219 struct ocfs2_super *osb = OCFS2_SB(sb);
1220
Jan Kara5fd13182009-07-30 17:01:53 +02001221 /* Failed mount? */
1222 if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1223 goto out;
1224
Jan Karaf7b1aa62009-07-20 12:12:36 +02001225 /* Prevent further queueing of inode drop events */
1226 spin_lock(&dentry_list_lock);
1227 ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1228 spin_unlock(&dentry_list_lock);
1229 /* Wait for work to finish and/or remove it */
1230 cancel_work_sync(&osb->dentry_lock_work);
Jan Kara5fd13182009-07-30 17:01:53 +02001231out:
Jan Karaf7b1aa62009-07-20 12:12:36 +02001232 kill_block_super(sb);
1233}
1234
Mark Fashehccd979b2005-12-15 14:31:24 -08001235static struct file_system_type ocfs2_fs_type = {
1236 .owner = THIS_MODULE,
1237 .name = "ocfs2",
1238 .get_sb = ocfs2_get_sb, /* is this called when we mount
1239 * the fs? */
Jan Karaf7b1aa62009-07-20 12:12:36 +02001240 .kill_sb = ocfs2_kill_sb,
1241
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001242 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001243 .next = NULL
1244};
1245
1246static int ocfs2_parse_options(struct super_block *sb,
1247 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001248 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001249 int is_remount)
1250{
1251 int status;
1252 char *p;
1253
1254 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1255 options ? options : "(none)");
1256
Mark Fashehd147b3d2007-11-07 14:40:36 -08001257 mopt->commit_interval = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001258 mopt->mount_opt = 0;
1259 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1260 mopt->slot = OCFS2_INVALID_SLOT;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001261 mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
Joel Beckerb61817e2008-02-01 15:08:23 -08001262 mopt->cluster_stack[0] = '\0';
Mark Fashehccd979b2005-12-15 14:31:24 -08001263
1264 if (!options) {
1265 status = 1;
1266 goto bail;
1267 }
1268
1269 while ((p = strsep(&options, ",")) != NULL) {
1270 int token, option;
1271 substring_t args[MAX_OPT_ARGS];
1272
1273 if (!*p)
1274 continue;
1275
1276 token = match_token(p, tokens, args);
1277 switch (token) {
1278 case Opt_hb_local:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001279 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001280 break;
1281 case Opt_hb_none:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001282 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001283 break;
1284 case Opt_barrier:
1285 if (match_int(&args[0], &option)) {
1286 status = 0;
1287 goto bail;
1288 }
1289 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001290 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001291 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001292 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001293 break;
1294 case Opt_intr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001295 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001296 break;
1297 case Opt_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001298 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001299 break;
1300 case Opt_err_panic:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001301 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001302 break;
1303 case Opt_err_ro:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001304 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001305 break;
1306 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001307 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001308 break;
1309 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001310 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001311 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001312 case Opt_user_xattr:
1313 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1314 break;
1315 case Opt_nouser_xattr:
1316 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1317 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001318 case Opt_atime_quantum:
1319 if (match_int(&args[0], &option)) {
1320 status = 0;
1321 goto bail;
1322 }
1323 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001324 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001325 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001326 case Opt_slot:
1327 option = 0;
1328 if (match_int(&args[0], &option)) {
1329 status = 0;
1330 goto bail;
1331 }
1332 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001333 mopt->slot = (s16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001334 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001335 case Opt_commit:
1336 option = 0;
1337 if (match_int(&args[0], &option)) {
1338 status = 0;
1339 goto bail;
1340 }
1341 if (option < 0)
1342 return 0;
1343 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001344 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001345 mopt->commit_interval = HZ * option;
1346 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001347 case Opt_localalloc:
1348 option = 0;
1349 if (match_int(&args[0], &option)) {
1350 status = 0;
1351 goto bail;
1352 }
1353 if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1354 mopt->localalloc_opt = option;
1355 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001356 case Opt_localflocks:
1357 /*
1358 * Changing this during remount could race
1359 * flock() requests, or "unbalance" existing
1360 * ones (e.g., a lock is taken in one mode but
1361 * dropped in the other). If users care enough
1362 * to flip locking modes during remount, we
1363 * could add a "local" flag to individual
1364 * flock structures for proper tracking of
1365 * state.
1366 */
1367 if (!is_remount)
1368 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1369 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001370 case Opt_stack:
1371 /* Check both that the option we were passed
1372 * is of the right length and that it is a proper
1373 * string of the right length.
1374 */
1375 if (((args[0].to - args[0].from) !=
1376 OCFS2_STACK_LABEL_LEN) ||
1377 (strnlen(args[0].from,
1378 OCFS2_STACK_LABEL_LEN) !=
1379 OCFS2_STACK_LABEL_LEN)) {
1380 mlog(ML_ERROR,
1381 "Invalid cluster_stack option\n");
1382 status = 0;
1383 goto bail;
1384 }
1385 memcpy(mopt->cluster_stack, args[0].from,
1386 OCFS2_STACK_LABEL_LEN);
1387 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1388 break;
Joel Becker12462f12008-09-03 20:03:40 -07001389 case Opt_inode64:
1390 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1391 break;
Jan Kara19ece542008-08-21 20:13:17 +02001392 case Opt_usrquota:
1393 /* We check only on remount, otherwise features
1394 * aren't yet initialized. */
1395 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1396 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1397 mlog(ML_ERROR, "User quota requested but "
1398 "filesystem feature is not set\n");
1399 status = 0;
1400 goto bail;
1401 }
1402 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1403 break;
1404 case Opt_grpquota:
1405 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1406 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1407 mlog(ML_ERROR, "Group quota requested but "
1408 "filesystem feature is not set\n");
1409 status = 0;
1410 goto bail;
1411 }
1412 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1413 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001414#ifdef CONFIG_OCFS2_FS_POSIX_ACL
1415 case Opt_acl:
1416 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1417 break;
1418 case Opt_noacl:
1419 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1420 break;
1421#else
1422 case Opt_acl:
1423 case Opt_noacl:
1424 printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
1425 break;
1426#endif
Mark Fashehccd979b2005-12-15 14:31:24 -08001427 default:
1428 mlog(ML_ERROR,
1429 "Unrecognized mount option \"%s\" "
1430 "or missing value\n", p);
1431 status = 0;
1432 goto bail;
1433 }
1434 }
1435
1436 status = 1;
1437
1438bail:
1439 mlog_exit(status);
1440 return status;
1441}
1442
Sunil Mushrand5500712007-09-06 13:34:16 -07001443static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1444{
1445 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1446 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001447 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001448
1449 if (opts & OCFS2_MOUNT_HB_LOCAL)
1450 seq_printf(s, ",_netdev,heartbeat=local");
1451 else
1452 seq_printf(s, ",heartbeat=none");
1453
1454 if (opts & OCFS2_MOUNT_NOINTR)
1455 seq_printf(s, ",nointr");
1456
1457 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1458 seq_printf(s, ",data=writeback");
1459 else
1460 seq_printf(s, ",data=ordered");
1461
1462 if (opts & OCFS2_MOUNT_BARRIER)
1463 seq_printf(s, ",barrier=1");
1464
1465 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1466 seq_printf(s, ",errors=panic");
1467 else
1468 seq_printf(s, ",errors=remount-ro");
1469
1470 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1471 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1472
1473 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1474 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1475
Mark Fashehd147b3d2007-11-07 14:40:36 -08001476 if (osb->osb_commit_interval)
1477 seq_printf(s, ",commit=%u",
1478 (unsigned) (osb->osb_commit_interval / HZ));
1479
Mark Fashehebcee4b2008-07-28 14:55:20 -07001480 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1481 if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1482 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001483
Mark Fasheh53fc6222007-12-20 16:49:04 -08001484 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1485 seq_printf(s, ",localflocks,");
1486
Joel Beckerb61817e2008-02-01 15:08:23 -08001487 if (osb->osb_cluster_stack[0])
1488 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1489 osb->osb_cluster_stack);
Jan Kara19ece542008-08-21 20:13:17 +02001490 if (opts & OCFS2_MOUNT_USRQUOTA)
1491 seq_printf(s, ",usrquota");
1492 if (opts & OCFS2_MOUNT_GRPQUOTA)
1493 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001494
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001495 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1496 seq_printf(s, ",nouser_xattr");
1497 else
1498 seq_printf(s, ",user_xattr");
1499
Joel Becker12462f12008-09-03 20:03:40 -07001500 if (opts & OCFS2_MOUNT_INODE64)
1501 seq_printf(s, ",inode64");
1502
Tiger Yanga68979b2008-11-14 11:17:52 +08001503#ifdef CONFIG_OCFS2_FS_POSIX_ACL
1504 if (opts & OCFS2_MOUNT_POSIX_ACL)
1505 seq_printf(s, ",acl");
1506 else
1507 seq_printf(s, ",noacl");
1508#endif
1509
Sunil Mushrand5500712007-09-06 13:34:16 -07001510 return 0;
1511}
1512
Mark Fashehccd979b2005-12-15 14:31:24 -08001513static int __init ocfs2_init(void)
1514{
1515 int status;
1516
1517 mlog_entry_void();
1518
1519 ocfs2_print_version();
1520
Mark Fashehccd979b2005-12-15 14:31:24 -08001521 status = init_ocfs2_uptodate_cache();
1522 if (status < 0) {
1523 mlog_errno(status);
1524 goto leave;
1525 }
1526
1527 status = ocfs2_initialize_mem_caches();
1528 if (status < 0) {
1529 mlog_errno(status);
1530 goto leave;
1531 }
1532
1533 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1534 if (!ocfs2_wq) {
1535 status = -ENOMEM;
1536 goto leave;
1537 }
1538
Mark Fashehccd979b2005-12-15 14:31:24 -08001539 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1540 if (!ocfs2_debugfs_root) {
1541 status = -EFAULT;
1542 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1543 }
1544
Mark Fasheh171bf932008-10-20 15:36:47 +02001545 status = ocfs2_quota_setup();
1546 if (status)
1547 goto leave;
1548
Joel Becker63e0c482008-01-30 16:58:36 -08001549 ocfs2_set_locking_protocol();
1550
Jan Kara9e33d692008-08-25 19:56:50 +02001551 status = register_quota_format(&ocfs2_quota_format);
Mark Fashehccd979b2005-12-15 14:31:24 -08001552leave:
1553 if (status < 0) {
Mark Fasheh171bf932008-10-20 15:36:47 +02001554 ocfs2_quota_shutdown();
Mark Fashehccd979b2005-12-15 14:31:24 -08001555 ocfs2_free_mem_caches();
1556 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001557 }
1558
1559 mlog_exit(status);
1560
1561 if (status >= 0) {
1562 return register_filesystem(&ocfs2_fs_type);
1563 } else
1564 return -1;
1565}
1566
1567static void __exit ocfs2_exit(void)
1568{
1569 mlog_entry_void();
1570
Mark Fasheh171bf932008-10-20 15:36:47 +02001571 ocfs2_quota_shutdown();
1572
Mark Fashehccd979b2005-12-15 14:31:24 -08001573 if (ocfs2_wq) {
1574 flush_workqueue(ocfs2_wq);
1575 destroy_workqueue(ocfs2_wq);
1576 }
1577
Jan Kara9e33d692008-08-25 19:56:50 +02001578 unregister_quota_format(&ocfs2_quota_format);
1579
Mark Fashehccd979b2005-12-15 14:31:24 -08001580 debugfs_remove(ocfs2_debugfs_root);
1581
1582 ocfs2_free_mem_caches();
1583
1584 unregister_filesystem(&ocfs2_fs_type);
1585
Mark Fashehccd979b2005-12-15 14:31:24 -08001586 exit_ocfs2_uptodate_cache();
1587
1588 mlog_exit_void();
1589}
1590
1591static void ocfs2_put_super(struct super_block *sb)
1592{
1593 mlog_entry("(0x%p)\n", sb);
1594
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001595 lock_kernel();
1596
Mark Fashehccd979b2005-12-15 14:31:24 -08001597 ocfs2_sync_blockdev(sb);
1598 ocfs2_dismount_volume(sb, 0);
1599
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001600 unlock_kernel();
1601
Mark Fashehccd979b2005-12-15 14:31:24 -08001602 mlog_exit_void();
1603}
1604
David Howells726c3342006-06-23 02:02:58 -07001605static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001606{
1607 struct ocfs2_super *osb;
1608 u32 numbits, freebits;
1609 int status;
1610 struct ocfs2_dinode *bm_lock;
1611 struct buffer_head *bh = NULL;
1612 struct inode *inode = NULL;
1613
David Howells726c3342006-06-23 02:02:58 -07001614 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001615
David Howells726c3342006-06-23 02:02:58 -07001616 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001617
1618 inode = ocfs2_get_system_file_inode(osb,
1619 GLOBAL_BITMAP_SYSTEM_INODE,
1620 OCFS2_INVALID_SLOT);
1621 if (!inode) {
1622 mlog(ML_ERROR, "failed to get bitmap inode\n");
1623 status = -EIO;
1624 goto bail;
1625 }
1626
Mark Fashehe63aecb62007-10-18 15:30:42 -07001627 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001628 if (status < 0) {
1629 mlog_errno(status);
1630 goto bail;
1631 }
1632
1633 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1634
1635 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1636 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1637
1638 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001639 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001640 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1641 buf->f_blocks = ((sector_t) numbits) *
1642 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1643 buf->f_bfree = ((sector_t) freebits) *
1644 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1645 buf->f_bavail = buf->f_bfree;
1646 buf->f_files = numbits;
1647 buf->f_ffree = freebits;
1648
1649 brelse(bh);
1650
Mark Fashehe63aecb62007-10-18 15:30:42 -07001651 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001652 status = 0;
1653bail:
1654 if (inode)
1655 iput(inode);
1656
1657 mlog_exit(status);
1658
1659 return status;
1660}
1661
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001662static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001663{
1664 struct ocfs2_inode_info *oi = data;
1665
Christoph Lametera35afb82007-05-16 22:10:57 -07001666 oi->ip_flags = 0;
1667 oi->ip_open_count = 0;
1668 spin_lock_init(&oi->ip_lock);
1669 ocfs2_extent_map_init(&oi->vfs_inode);
1670 INIT_LIST_HEAD(&oi->ip_io_markers);
Christoph Lametera35afb82007-05-16 22:10:57 -07001671 oi->ip_dir_start_lookup = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001672
Christoph Lametera35afb82007-05-16 22:10:57 -07001673 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001674 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001675 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001676
Christoph Lametera35afb82007-05-16 22:10:57 -07001677 oi->ip_blkno = 0ULL;
1678 oi->ip_clusters = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001679
Christoph Lametera35afb82007-05-16 22:10:57 -07001680 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001681 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001682 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001683
Joel Becker8cb471e2009-02-10 20:00:41 -08001684 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
Joel Becker6e5a3d72009-02-10 19:00:37 -08001685 &ocfs2_inode_caching_ops);
Mark Fashehccd979b2005-12-15 14:31:24 -08001686
Christoph Lametera35afb82007-05-16 22:10:57 -07001687 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001688}
1689
1690static int ocfs2_initialize_mem_caches(void)
1691{
1692 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001693 sizeof(struct ocfs2_inode_info),
1694 0,
1695 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1696 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001697 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001698 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1699 sizeof(struct ocfs2_dquot),
1700 0,
1701 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1702 SLAB_MEM_SPREAD),
1703 NULL);
1704 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1705 sizeof(struct ocfs2_quota_chunk),
1706 0,
1707 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1708 NULL);
1709 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1710 !ocfs2_qf_chunk_cachep) {
1711 if (ocfs2_inode_cachep)
1712 kmem_cache_destroy(ocfs2_inode_cachep);
1713 if (ocfs2_dquot_cachep)
1714 kmem_cache_destroy(ocfs2_dquot_cachep);
1715 if (ocfs2_qf_chunk_cachep)
1716 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001717 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001718 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001719
Mark Fashehccd979b2005-12-15 14:31:24 -08001720 return 0;
1721}
1722
1723static void ocfs2_free_mem_caches(void)
1724{
1725 if (ocfs2_inode_cachep)
1726 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001727 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001728
1729 if (ocfs2_dquot_cachep)
1730 kmem_cache_destroy(ocfs2_dquot_cachep);
1731 ocfs2_dquot_cachep = NULL;
1732
1733 if (ocfs2_qf_chunk_cachep)
1734 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1735 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001736}
1737
1738static int ocfs2_get_sector(struct super_block *sb,
1739 struct buffer_head **bh,
1740 int block,
1741 int sect_size)
1742{
1743 if (!sb_set_blocksize(sb, sect_size)) {
1744 mlog(ML_ERROR, "unable to set blocksize\n");
1745 return -EIO;
1746 }
1747
1748 *bh = sb_getblk(sb, block);
1749 if (!*bh) {
1750 mlog_errno(-EIO);
1751 return -EIO;
1752 }
1753 lock_buffer(*bh);
1754 if (!buffer_dirty(*bh))
1755 clear_buffer_uptodate(*bh);
1756 unlock_buffer(*bh);
1757 ll_rw_block(READ, 1, bh);
1758 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001759 if (!buffer_uptodate(*bh)) {
1760 mlog_errno(-EIO);
1761 brelse(*bh);
1762 *bh = NULL;
1763 return -EIO;
1764 }
1765
Mark Fashehccd979b2005-12-15 14:31:24 -08001766 return 0;
1767}
1768
Mark Fashehccd979b2005-12-15 14:31:24 -08001769static int ocfs2_mount_volume(struct super_block *sb)
1770{
1771 int status = 0;
1772 int unlock_super = 0;
1773 struct ocfs2_super *osb = OCFS2_SB(sb);
1774
1775 mlog_entry_void();
1776
1777 if (ocfs2_is_hard_readonly(osb))
1778 goto leave;
1779
Mark Fashehccd979b2005-12-15 14:31:24 -08001780 status = ocfs2_dlm_init(osb);
1781 if (status < 0) {
1782 mlog_errno(status);
1783 goto leave;
1784 }
1785
Mark Fashehccd979b2005-12-15 14:31:24 -08001786 status = ocfs2_super_lock(osb, 1);
1787 if (status < 0) {
1788 mlog_errno(status);
1789 goto leave;
1790 }
1791 unlock_super = 1;
1792
1793 /* This will load up the node map and add ourselves to it. */
1794 status = ocfs2_find_slot(osb);
1795 if (status < 0) {
1796 mlog_errno(status);
1797 goto leave;
1798 }
1799
Mark Fashehccd979b2005-12-15 14:31:24 -08001800 /* load all node-local system inodes */
1801 status = ocfs2_init_local_system_inodes(osb);
1802 if (status < 0) {
1803 mlog_errno(status);
1804 goto leave;
1805 }
1806
1807 status = ocfs2_check_volume(osb);
1808 if (status < 0) {
1809 mlog_errno(status);
1810 goto leave;
1811 }
1812
1813 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001814 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001815 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001816
Mark Fashehccd979b2005-12-15 14:31:24 -08001817leave:
1818 if (unlock_super)
1819 ocfs2_super_unlock(osb, 1);
1820
1821 mlog_exit(status);
1822 return status;
1823}
1824
Mark Fashehccd979b2005-12-15 14:31:24 -08001825static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1826{
Joel Becker286eaa92008-02-01 15:03:57 -08001827 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001828 struct ocfs2_super *osb = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001829 char nodestr[8];
Mark Fashehccd979b2005-12-15 14:31:24 -08001830
1831 mlog_entry("(0x%p)\n", sb);
1832
1833 BUG_ON(!sb);
1834 osb = OCFS2_SB(sb);
1835 BUG_ON(!osb);
1836
Sunil Mushran50397502008-12-17 14:17:43 -08001837 debugfs_remove(osb->osb_ctxt);
1838
Jan Karaf7b1aa62009-07-20 12:12:36 +02001839 /*
1840 * Flush inode dropping work queue so that deletes are
1841 * performed while the filesystem is still working
1842 */
1843 ocfs2_drop_all_dl_inodes(osb);
1844
Sunil Mushran692684e2009-06-19 16:53:17 -07001845 /* Orphan scan should be stopped as early as possible */
1846 ocfs2_orphan_scan_stop(osb);
1847
Jan Kara19ece542008-08-21 20:13:17 +02001848 ocfs2_disable_quotas(osb);
1849
Mark Fashehccd979b2005-12-15 14:31:24 -08001850 ocfs2_shutdown_local_alloc(osb);
1851
1852 ocfs2_truncate_log_shutdown(osb);
1853
Joel Becker553abd02008-02-01 12:03:57 -08001854 /* This will disable recovery and flush any recovery work. */
1855 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001856
1857 ocfs2_journal_shutdown(osb);
1858
1859 ocfs2_sync_blockdev(sb);
1860
Tao Ma374a2632009-08-24 11:13:37 +08001861 ocfs2_purge_refcount_trees(osb);
1862
Joel Becker4670c462008-02-01 14:39:35 -08001863 /* No cluster connection means we've failed during mount, so skip
1864 * all the steps which depended on that to complete. */
1865 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001866 tmp = ocfs2_super_lock(osb, 1);
1867 if (tmp < 0) {
1868 mlog_errno(tmp);
1869 return;
1870 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001871 }
1872
Mark Fasheh19b613d2007-10-04 14:47:09 -07001873 if (osb->slot_num != OCFS2_INVALID_SLOT)
1874 ocfs2_put_slot(osb);
1875
Joel Becker4670c462008-02-01 14:39:35 -08001876 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001877 ocfs2_super_unlock(osb, 1);
1878
Mark Fashehccd979b2005-12-15 14:31:24 -08001879 ocfs2_release_system_inodes(osb);
1880
Joel Becker6953b4c2008-01-29 16:59:56 -08001881 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001882 * If we're dismounting due to mount error, mount.ocfs2 will clean
1883 * up heartbeat. If we're a local mount, there is no heartbeat.
1884 * If we failed before we got a uuid_str yet, we can't stop
1885 * heartbeat. Otherwise, do it.
1886 */
1887 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
Joel Becker286eaa92008-02-01 15:03:57 -08001888 hangup_needed = 1;
1889
1890 if (osb->cconn)
1891 ocfs2_dlm_shutdown(osb, hangup_needed);
1892
Joel Becker73be1922009-01-06 14:57:08 -08001893 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Joel Becker286eaa92008-02-01 15:03:57 -08001894 debugfs_remove(osb->osb_debug_root);
1895
1896 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001897 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001898
1899 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1900
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001901 if (ocfs2_mount_local(osb))
1902 snprintf(nodestr, sizeof(nodestr), "local");
1903 else
Joel Becker19fdb622008-01-30 15:38:24 -08001904 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001905
1906 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1907 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001908
1909 ocfs2_delete_osb(osb);
1910 kfree(osb);
1911 sb->s_dev = 0;
1912 sb->s_fs_info = NULL;
1913}
1914
1915static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1916 unsigned uuid_bytes)
1917{
1918 int i, ret;
1919 char *ptr;
1920
1921 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1922
Robert P. J. Daycd861282006-12-13 00:34:52 -08001923 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001924 if (osb->uuid_str == NULL)
1925 return -ENOMEM;
1926
Mark Fashehccd979b2005-12-15 14:31:24 -08001927 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1928 /* print with null */
1929 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1930 if (ret != 2) /* drop super cleans up */
1931 return -EINVAL;
1932 /* then only advance past the last char */
1933 ptr += 2;
1934 }
1935
1936 return 0;
1937}
1938
1939static int ocfs2_initialize_super(struct super_block *sb,
1940 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08001941 int sector_size,
1942 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08001943{
Denis Chengbddb8eb32007-09-27 02:10:04 +08001944 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07001945 int i, cbits, bbits;
1946 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08001947 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001948 struct ocfs2_journal *journal;
1949 __le32 uuid_net_key;
1950 struct ocfs2_super *osb;
1951
1952 mlog_entry_void();
1953
Robert P. J. Daycd861282006-12-13 00:34:52 -08001954 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001955 if (!osb) {
1956 status = -ENOMEM;
1957 mlog_errno(status);
1958 goto bail;
1959 }
1960
1961 sb->s_fs_info = osb;
1962 sb->s_op = &ocfs2_sops;
1963 sb->s_export_op = &ocfs2_export_ops;
Jan Kara19ece542008-08-21 20:13:17 +02001964 sb->s_qcop = &ocfs2_quotactl_ops;
1965 sb->dq_op = &ocfs2_quota_operations;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001966 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07001967 sb->s_time_gran = 1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001968 sb->s_flags |= MS_NOATIME;
1969 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07001970 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1971 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1972 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001973
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001974 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
1975
1976 for (i = 0; i < 3; i++)
1977 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
1978 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1979
Mark Fashehccd979b2005-12-15 14:31:24 -08001980 osb->sb = sb;
1981 /* Save off for ocfs2_rw_direct */
1982 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01001983 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001984
Mark Fasheh34d024f2007-09-24 15:56:19 -07001985 spin_lock_init(&osb->dc_task_lock);
1986 init_waitqueue_head(&osb->dc_event);
1987 osb->dc_work_sequence = 0;
1988 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001989 INIT_LIST_HEAD(&osb->blocked_lock_list);
1990 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001991 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08001992 spin_lock_init(&osb->osb_xattr_lock);
Tao Ma4d0ddb22008-03-05 16:11:46 +08001993 ocfs2_init_inode_steal_slot(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001994
1995 atomic_set(&osb->alloc_stats.moves, 0);
1996 atomic_set(&osb->alloc_stats.local_data, 0);
1997 atomic_set(&osb->alloc_stats.bitmap_data, 0);
1998 atomic_set(&osb->alloc_stats.bg_allocs, 0);
1999 atomic_set(&osb->alloc_stats.bg_extends, 0);
2000
Joel Becker73be1922009-01-06 14:57:08 -08002001 /* Copy the blockcheck stats from the superblock probe */
2002 osb->osb_ecc_stats = *stats;
2003
Mark Fashehccd979b2005-12-15 14:31:24 -08002004 ocfs2_init_node_maps(osb);
2005
2006 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2007 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2008
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04002009 ocfs2_orphan_scan_init(osb);
2010
Joel Becker553abd02008-02-01 12:03:57 -08002011 status = ocfs2_recovery_init(osb);
2012 if (status) {
2013 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2014 mlog_errno(status);
2015 goto bail;
2016 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002017
2018 init_waitqueue_head(&osb->checkpoint_event);
2019 atomic_set(&osb->needs_checkpoint, 0);
2020
Tiger Yang7f1a37e2006-11-15 15:48:42 +08002021 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2022
Mark Fashehccd979b2005-12-15 14:31:24 -08002023 osb->slot_num = OCFS2_INVALID_SLOT;
2024
Tiger Yang8154da32008-08-18 17:11:46 +08002025 osb->s_xattr_inline_size = le16_to_cpu(
2026 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002027
Mark Fashehccd979b2005-12-15 14:31:24 -08002028 osb->local_alloc_state = OCFS2_LA_UNUSED;
2029 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002030 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002031
Mark Fashehccd979b2005-12-15 14:31:24 -08002032 init_waitqueue_head(&osb->osb_mount_event);
2033
2034 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2035 if (!osb->vol_label) {
2036 mlog(ML_ERROR, "unable to alloc vol label\n");
2037 status = -ENOMEM;
2038 goto bail;
2039 }
2040
Mark Fashehccd979b2005-12-15 14:31:24 -08002041 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2042 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2043 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2044 osb->max_slots);
2045 status = -EINVAL;
2046 goto bail;
2047 }
Sunil Mushran781ee3e2006-04-27 16:41:31 -07002048 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
Mark Fashehccd979b2005-12-15 14:31:24 -08002049
Sunil Mushran539d8262008-07-14 17:31:10 -07002050 osb->slot_recovery_generations =
2051 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2052 GFP_KERNEL);
2053 if (!osb->slot_recovery_generations) {
2054 status = -ENOMEM;
2055 mlog_errno(status);
2056 goto bail;
2057 }
2058
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002059 init_waitqueue_head(&osb->osb_wipe_event);
2060 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2061 sizeof(*osb->osb_orphan_wipes),
2062 GFP_KERNEL);
2063 if (!osb->osb_orphan_wipes) {
2064 status = -ENOMEM;
2065 mlog_errno(status);
2066 goto bail;
2067 }
2068
Tao Ma374a2632009-08-24 11:13:37 +08002069 osb->osb_rf_lock_tree = RB_ROOT;
2070
Mark Fashehccd979b2005-12-15 14:31:24 -08002071 osb->s_feature_compat =
2072 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2073 osb->s_feature_ro_compat =
2074 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2075 osb->s_feature_incompat =
2076 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2077
2078 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2079 mlog(ML_ERROR, "couldn't mount because of unsupported "
2080 "optional features (%x).\n", i);
2081 status = -EINVAL;
2082 goto bail;
2083 }
2084 if (!(osb->sb->s_flags & MS_RDONLY) &&
2085 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2086 mlog(ML_ERROR, "couldn't mount RDWR because of "
2087 "unsupported optional features (%x).\n", i);
2088 status = -EINVAL;
2089 goto bail;
2090 }
2091
Joel Beckerb61817e2008-02-01 15:08:23 -08002092 if (ocfs2_userspace_stack(osb)) {
2093 memcpy(osb->osb_cluster_stack,
2094 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2095 OCFS2_STACK_LABEL_LEN);
2096 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2097 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2098 mlog(ML_ERROR,
2099 "couldn't mount because of an invalid "
2100 "cluster stack label (%s) \n",
2101 osb->osb_cluster_stack);
2102 status = -EINVAL;
2103 goto bail;
2104 }
2105 } else {
2106 /* The empty string is identical with classic tools that
2107 * don't know about s_cluster_info. */
2108 osb->osb_cluster_stack[0] = '\0';
2109 }
2110
Mark Fashehccd979b2005-12-15 14:31:24 -08002111 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2112
2113 /* FIXME
2114 * This should be done in ocfs2_journal_init(), but unknown
2115 * ordering issues will cause the filesystem to crash.
2116 * If anyone wants to figure out what part of the code
2117 * refers to osb->journal before ocfs2_journal_init() is run,
2118 * be my guest.
2119 */
2120 /* initialize our journal structure */
2121
Robert P. J. Daycd861282006-12-13 00:34:52 -08002122 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002123 if (!journal) {
2124 mlog(ML_ERROR, "unable to alloc journal\n");
2125 status = -ENOMEM;
2126 goto bail;
2127 }
2128 osb->journal = journal;
2129 journal->j_osb = osb;
2130
2131 atomic_set(&journal->j_num_trans, 0);
2132 init_rwsem(&journal->j_trans_barrier);
2133 init_waitqueue_head(&journal->j_checkpointed);
2134 spin_lock_init(&journal->j_lock);
2135 journal->j_trans_id = (unsigned long) 1;
2136 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002137 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002138 journal->j_state = OCFS2_JOURNAL_FREE;
2139
Jan Karaea455f82009-01-12 23:20:31 +01002140 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2141 osb->dentry_lock_list = NULL;
2142
Mark Fashehccd979b2005-12-15 14:31:24 -08002143 /* get some pseudo constants for clustersize bits */
2144 osb->s_clustersize_bits =
2145 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2146 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2147 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2148
2149 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2150 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2151 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2152 osb->s_clustersize);
2153 status = -EINVAL;
2154 goto bail;
2155 }
2156
2157 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2158 > (u32)~0UL) {
2159 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2160 "what jbd can address in 32 bits.\n");
2161 status = -EINVAL;
2162 goto bail;
2163 }
2164
2165 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2166 sizeof(di->id2.i_super.s_uuid))) {
2167 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2168 status = -ENOMEM;
2169 goto bail;
2170 }
2171
Mark Fasheh78427042006-05-04 12:03:26 -07002172 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
Mark Fashehccd979b2005-12-15 14:31:24 -08002173
2174 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2175 osb->vol_label[63] = '\0';
2176 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2177 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2178 osb->first_cluster_group_blkno =
2179 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2180 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002181 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Mark Fashehccd979b2005-12-15 14:31:24 -08002182 mlog(0, "vol_label: %s\n", osb->vol_label);
2183 mlog(0, "uuid: %s\n", osb->uuid_str);
Mark Fashehb06970532006-03-03 10:24:33 -08002184 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2185 (unsigned long long)osb->root_blkno,
2186 (unsigned long long)osb->system_dir_blkno);
Mark Fashehccd979b2005-12-15 14:31:24 -08002187
2188 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2189 if (!osb->osb_dlm_debug) {
2190 status = -ENOMEM;
2191 mlog_errno(status);
2192 goto bail;
2193 }
2194
2195 atomic_set(&osb->vol_state, VOLUME_INIT);
2196
2197 /* load root, system_dir, and all global system inodes */
2198 status = ocfs2_init_global_system_inodes(osb);
2199 if (status < 0) {
2200 mlog_errno(status);
2201 goto bail;
2202 }
2203
2204 /*
2205 * global bitmap
2206 */
2207 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2208 OCFS2_INVALID_SLOT);
2209 if (!inode) {
2210 status = -EINVAL;
2211 mlog_errno(status);
2212 goto bail;
2213 }
2214
2215 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fashehccd979b2005-12-15 14:31:24 -08002216 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002217
Tao Mae9d578a2007-12-18 15:46:10 +08002218 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002219
2220 status = ocfs2_init_slot_info(osb);
2221 if (status < 0) {
2222 mlog_errno(status);
2223 goto bail;
2224 }
2225
Mark Fashehccd979b2005-12-15 14:31:24 -08002226bail:
2227 mlog_exit(status);
2228 return status;
2229}
2230
2231/*
2232 * will return: -EAGAIN if it is ok to keep searching for superblocks
2233 * -EINVAL if there is a bad superblock
2234 * 0 on success
2235 */
2236static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2237 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002238 u32 blksz,
2239 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002240{
2241 int status = -EAGAIN;
2242
2243 mlog_entry_void();
2244
2245 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2246 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002247 /* We have to do a raw check of the feature here */
2248 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2249 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2250 status = ocfs2_block_check_validate(bh->b_data,
2251 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002252 &di->i_check,
2253 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002254 if (status)
2255 goto out;
2256 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002257 status = -EINVAL;
2258 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2259 mlog(ML_ERROR, "found superblock with incorrect block "
2260 "size: found %u, should be %u\n",
2261 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2262 blksz);
2263 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2264 OCFS2_MAJOR_REV_LEVEL ||
2265 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2266 OCFS2_MINOR_REV_LEVEL) {
2267 mlog(ML_ERROR, "found superblock with bad version: "
2268 "found %u.%u, should be %u.%u\n",
2269 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2270 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2271 OCFS2_MAJOR_REV_LEVEL,
2272 OCFS2_MINOR_REV_LEVEL);
2273 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2274 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb06970532006-03-03 10:24:33 -08002275 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002276 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb06970532006-03-03 10:24:33 -08002277 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002278 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2279 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2280 mlog(ML_ERROR, "bad cluster size found: %u\n",
2281 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2282 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2283 mlog(ML_ERROR, "bad root_blkno: 0\n");
2284 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2285 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2286 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2287 mlog(ML_ERROR,
2288 "Superblock slots found greater than file system "
2289 "maximum: found %u, max %u\n",
2290 le16_to_cpu(di->id2.i_super.s_max_slots),
2291 OCFS2_MAX_SLOTS);
2292 } else {
2293 /* found it! */
2294 status = 0;
2295 }
2296 }
2297
Joel Beckerd030cc92008-12-11 15:04:14 -08002298out:
Mark Fashehccd979b2005-12-15 14:31:24 -08002299 mlog_exit(status);
2300 return status;
2301}
2302
2303static int ocfs2_check_volume(struct ocfs2_super *osb)
2304{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002305 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002306 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002307 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002308 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2309 * recover
2310 * ourselves. */
2311
2312 mlog_entry_void();
2313
2314 /* Init our journal object. */
2315 status = ocfs2_journal_init(osb->journal, &dirty);
2316 if (status < 0) {
2317 mlog(ML_ERROR, "Could not initialize journal!\n");
2318 goto finally;
2319 }
2320
2321 /* If the journal was unmounted cleanly then we don't want to
2322 * recover anything. Otherwise, journal_load will do that
2323 * dirty work for us :) */
2324 if (!dirty) {
2325 status = ocfs2_journal_wipe(osb->journal, 0);
2326 if (status < 0) {
2327 mlog_errno(status);
2328 goto finally;
2329 }
2330 } else {
2331 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2332 "recovering volume.\n");
2333 }
2334
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002335 local = ocfs2_mount_local(osb);
2336
Mark Fashehccd979b2005-12-15 14:31:24 -08002337 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002338 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002339 if (status < 0) {
2340 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2341 goto finally;
2342 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002343
2344 if (dirty) {
2345 /* recover my local alloc if we didn't unmount cleanly. */
2346 status = ocfs2_begin_local_alloc_recovery(osb,
2347 osb->slot_num,
2348 &local_alloc);
2349 if (status < 0) {
2350 mlog_errno(status);
2351 goto finally;
2352 }
2353 /* we complete the recovery process after we've marked
2354 * ourselves as mounted. */
2355 }
2356
2357 mlog(0, "Journal loaded.\n");
2358
2359 status = ocfs2_load_local_alloc(osb);
2360 if (status < 0) {
2361 mlog_errno(status);
2362 goto finally;
2363 }
2364
2365 if (dirty) {
2366 /* Recovery will be completed after we've mounted the
2367 * rest of the volume. */
2368 osb->dirty = 1;
2369 osb->local_alloc_copy = local_alloc;
2370 local_alloc = NULL;
2371 }
2372
2373 /* go through each journal, trylock it and if you get the
2374 * lock, and it's marked as dirty, set the bit in the recover
2375 * map and launch a recovery thread for it. */
2376 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002377 if (status < 0) {
2378 mlog_errno(status);
2379 goto finally;
2380 }
2381
2382 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002383 if (status < 0)
2384 mlog_errno(status);
2385
2386finally:
2387 if (local_alloc)
2388 kfree(local_alloc);
2389
2390 mlog_exit(status);
2391 return status;
2392}
2393
2394/*
2395 * The routine gets called from dismount or close whenever a dismount on
2396 * volume is requested and the osb open count becomes 1.
2397 * It will remove the osb from the global list and also free up all the
2398 * initialized resources and fileobject.
2399 */
2400static void ocfs2_delete_osb(struct ocfs2_super *osb)
2401{
2402 mlog_entry_void();
2403
2404 /* This function assumes that the caller has the main osb resource */
2405
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002406 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002407
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002408 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002409 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002410 /* FIXME
2411 * This belongs in journal shutdown, but because we have to
2412 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2413 * we free it here.
2414 */
2415 kfree(osb->journal);
2416 if (osb->local_alloc_copy)
2417 kfree(osb->local_alloc_copy);
2418 kfree(osb->uuid_str);
2419 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2420 memset(osb, 0, sizeof(struct ocfs2_super));
2421
2422 mlog_exit_void();
2423}
2424
2425/* Put OCFS2 into a readonly state, or (if the user specifies it),
2426 * panic(). We do not support continue-on-error operation. */
2427static void ocfs2_handle_error(struct super_block *sb)
2428{
2429 struct ocfs2_super *osb = OCFS2_SB(sb);
2430
2431 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2432 panic("OCFS2: (device %s): panic forced after error\n",
2433 sb->s_id);
2434
2435 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2436
2437 if (sb->s_flags & MS_RDONLY &&
2438 (ocfs2_is_soft_readonly(osb) ||
2439 ocfs2_is_hard_readonly(osb)))
2440 return;
2441
2442 printk(KERN_CRIT "File system is now read-only due to the potential "
2443 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2444 "system is unmounted.\n");
2445 sb->s_flags |= MS_RDONLY;
2446 ocfs2_set_ro_flag(osb, 0);
2447}
2448
2449static char error_buf[1024];
2450
2451void __ocfs2_error(struct super_block *sb,
2452 const char *function,
2453 const char *fmt, ...)
2454{
2455 va_list args;
2456
2457 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002458 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002459 va_end(args);
2460
2461 /* Not using mlog here because we want to show the actual
2462 * function the error came from. */
2463 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2464 sb->s_id, function, error_buf);
2465
2466 ocfs2_handle_error(sb);
2467}
2468
2469/* Handle critical errors. This is intentionally more drastic than
2470 * ocfs2_handle_error, so we only use for things like journal errors,
2471 * etc. */
2472void __ocfs2_abort(struct super_block* sb,
2473 const char *function,
2474 const char *fmt, ...)
2475{
2476 va_list args;
2477
2478 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002479 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002480 va_end(args);
2481
2482 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2483 sb->s_id, function, error_buf);
2484
2485 /* We don't have the cluster support yet to go straight to
2486 * hard readonly in here. Until then, we want to keep
2487 * ocfs2_abort() so that we can at least mark critical
2488 * errors.
2489 *
2490 * TODO: This should abort the journal and alert other nodes
2491 * that our slot needs recovery. */
2492
2493 /* Force a panic(). This stinks, but it's better than letting
2494 * things continue without having a proper hard readonly
2495 * here. */
Sunil Mushrana2f2ddb2009-08-19 15:16:01 -07002496 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2497 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08002498 ocfs2_handle_error(sb);
2499}
2500
2501module_init(ocfs2_init);
2502module_exit(ocfs2_exit);