blob: a5116b9b7e704b2c03d2ede4d8f3b219549329a0 [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);
Jan Kara5297aad2009-10-15 14:54:04 +0200103static int ocfs2_check_set_options(struct super_block *sb,
104 struct mount_options *options);
Sunil Mushrand5500712007-09-06 13:34:16 -0700105static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -0800106static void ocfs2_put_super(struct super_block *sb);
107static int ocfs2_mount_volume(struct super_block *sb);
108static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
109static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
110static int ocfs2_initialize_mem_caches(void);
111static void ocfs2_free_mem_caches(void);
112static void ocfs2_delete_osb(struct ocfs2_super *osb);
113
David Howells726c3342006-06-23 02:02:58 -0700114static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
Mark Fashehccd979b2005-12-15 14:31:24 -0800115
116static int ocfs2_sync_fs(struct super_block *sb, int wait);
117
118static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
119static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
Denis Chengbddb8eb32007-09-27 02:10:04 +0800120static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800121static int ocfs2_check_volume(struct ocfs2_super *osb);
122static int ocfs2_verify_volume(struct ocfs2_dinode *di,
123 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800124 u32 sectsize,
125 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800126static int ocfs2_initialize_super(struct super_block *sb,
127 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800128 int sector_size,
129 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800130static int ocfs2_get_sector(struct super_block *sb,
131 struct buffer_head **bh,
132 int block,
133 int sect_size);
Mark Fashehccd979b2005-12-15 14:31:24 -0800134static struct inode *ocfs2_alloc_inode(struct super_block *sb);
135static void ocfs2_destroy_inode(struct inode *inode);
Jan Kara19ece542008-08-21 20:13:17 +0200136static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
137static int ocfs2_enable_quotas(struct ocfs2_super *osb);
138static void ocfs2_disable_quotas(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800139
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800140static const struct super_operations ocfs2_sops = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800141 .statfs = ocfs2_statfs,
142 .alloc_inode = ocfs2_alloc_inode,
143 .destroy_inode = ocfs2_destroy_inode,
144 .drop_inode = ocfs2_drop_inode,
145 .clear_inode = ocfs2_clear_inode,
146 .delete_inode = ocfs2_delete_inode,
147 .sync_fs = ocfs2_sync_fs,
Mark Fashehccd979b2005-12-15 14:31:24 -0800148 .put_super = ocfs2_put_super,
149 .remount_fs = ocfs2_remount,
Sunil Mushrand5500712007-09-06 13:34:16 -0700150 .show_options = ocfs2_show_options,
Jan Kara9e33d692008-08-25 19:56:50 +0200151 .quota_read = ocfs2_quota_read,
152 .quota_write = ocfs2_quota_write,
Mark Fashehccd979b2005-12-15 14:31:24 -0800153};
154
155enum {
156 Opt_barrier,
157 Opt_err_panic,
158 Opt_err_ro,
159 Opt_intr,
160 Opt_nointr,
161 Opt_hb_none,
162 Opt_hb_local,
163 Opt_data_ordered,
164 Opt_data_writeback,
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800165 Opt_atime_quantum,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700166 Opt_slot,
Mark Fashehd147b3d2007-11-07 14:40:36 -0800167 Opt_commit,
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800168 Opt_localalloc,
Mark Fasheh53fc6222007-12-20 16:49:04 -0800169 Opt_localflocks,
Joel Beckerb61817e2008-02-01 15:08:23 -0800170 Opt_stack,
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800171 Opt_user_xattr,
172 Opt_nouser_xattr,
Joel Becker12462f12008-09-03 20:03:40 -0700173 Opt_inode64,
Tiger Yanga68979b2008-11-14 11:17:52 +0800174 Opt_acl,
175 Opt_noacl,
Jan Kara19ece542008-08-21 20:13:17 +0200176 Opt_usrquota,
177 Opt_grpquota,
Mark Fashehccd979b2005-12-15 14:31:24 -0800178 Opt_err,
179};
180
Steven Whitehousea447c092008-10-13 10:46:57 +0100181static const match_table_t tokens = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800182 {Opt_barrier, "barrier=%u"},
183 {Opt_err_panic, "errors=panic"},
184 {Opt_err_ro, "errors=remount-ro"},
185 {Opt_intr, "intr"},
186 {Opt_nointr, "nointr"},
187 {Opt_hb_none, OCFS2_HB_NONE},
188 {Opt_hb_local, OCFS2_HB_LOCAL},
189 {Opt_data_ordered, "data=ordered"},
190 {Opt_data_writeback, "data=writeback"},
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800191 {Opt_atime_quantum, "atime_quantum=%u"},
Sunil Mushranbaf46612007-06-18 17:00:24 -0700192 {Opt_slot, "preferred_slot=%u"},
Mark Fashehd147b3d2007-11-07 14:40:36 -0800193 {Opt_commit, "commit=%u"},
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800194 {Opt_localalloc, "localalloc=%d"},
Mark Fasheh53fc6222007-12-20 16:49:04 -0800195 {Opt_localflocks, "localflocks"},
Joel Beckerb61817e2008-02-01 15:08:23 -0800196 {Opt_stack, "cluster_stack=%s"},
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800197 {Opt_user_xattr, "user_xattr"},
198 {Opt_nouser_xattr, "nouser_xattr"},
Joel Becker12462f12008-09-03 20:03:40 -0700199 {Opt_inode64, "inode64"},
Tiger Yanga68979b2008-11-14 11:17:52 +0800200 {Opt_acl, "acl"},
201 {Opt_noacl, "noacl"},
Jan Kara19ece542008-08-21 20:13:17 +0200202 {Opt_usrquota, "usrquota"},
203 {Opt_grpquota, "grpquota"},
Mark Fashehccd979b2005-12-15 14:31:24 -0800204 {Opt_err, NULL}
205};
206
Sunil Mushran50397502008-12-17 14:17:43 -0800207#ifdef CONFIG_DEBUG_FS
208static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
209{
Sunil Mushran50397502008-12-17 14:17:43 -0800210 struct ocfs2_cluster_connection *cconn = osb->cconn;
211 struct ocfs2_recovery_map *rm = osb->recovery_map;
Sunil Mushrandf152c22009-06-22 11:40:07 -0700212 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
213 int i, out = 0;
Sunil Mushran50397502008-12-17 14:17:43 -0800214
215 out += snprintf(buf + out, len - out,
216 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
217 "Device", osb->dev_str, osb->uuid_str,
218 osb->fs_generation, osb->vol_label);
219
220 out += snprintf(buf + out, len - out,
221 "%10s => State: %d Flags: 0x%lX\n", "Volume",
222 atomic_read(&osb->vol_state), osb->osb_flags);
223
224 out += snprintf(buf + out, len - out,
225 "%10s => Block: %lu Cluster: %d\n", "Sizes",
226 osb->sb->s_blocksize, osb->s_clustersize);
227
228 out += snprintf(buf + out, len - out,
229 "%10s => Compat: 0x%X Incompat: 0x%X "
230 "ROcompat: 0x%X\n",
231 "Features", osb->s_feature_compat,
232 osb->s_feature_incompat, osb->s_feature_ro_compat);
233
234 out += snprintf(buf + out, len - out,
235 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
236 osb->s_mount_opt, osb->s_atime_quantum);
237
Sunil Mushranc3d38842009-06-19 14:45:55 -0700238 if (cconn) {
239 out += snprintf(buf + out, len - out,
240 "%10s => Stack: %s Name: %*s "
241 "Version: %d.%d\n", "Cluster",
242 (*osb->osb_cluster_stack == '\0' ?
243 "o2cb" : osb->osb_cluster_stack),
244 cconn->cc_namelen, cconn->cc_name,
245 cconn->cc_version.pv_major,
246 cconn->cc_version.pv_minor);
247 }
Sunil Mushran50397502008-12-17 14:17:43 -0800248
249 spin_lock(&osb->dc_task_lock);
250 out += snprintf(buf + out, len - out,
251 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
252 "WorkSeq: %lu\n", "DownCnvt",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700253 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
254 osb->blocked_lock_count, osb->dc_wake_sequence,
255 osb->dc_work_sequence);
Sunil Mushran50397502008-12-17 14:17:43 -0800256 spin_unlock(&osb->dc_task_lock);
257
258 spin_lock(&osb->osb_lock);
259 out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
260 "Recovery",
261 (osb->recovery_thread_task ?
262 task_pid_nr(osb->recovery_thread_task) : -1));
263 if (rm->rm_used == 0)
264 out += snprintf(buf + out, len - out, " None\n");
265 else {
266 for (i = 0; i < rm->rm_used; i++)
267 out += snprintf(buf + out, len - out, " %d",
268 rm->rm_entries[i]);
269 out += snprintf(buf + out, len - out, "\n");
270 }
271 spin_unlock(&osb->osb_lock);
272
273 out += snprintf(buf + out, len - out,
274 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700275 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
276 osb->osb_commit_interval,
Sunil Mushran50397502008-12-17 14:17:43 -0800277 atomic_read(&osb->needs_checkpoint));
278
279 out += snprintf(buf + out, len - out,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700280 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
Sunil Mushran50397502008-12-17 14:17:43 -0800281 "Journal", osb->journal->j_state,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700282 osb->journal->j_trans_id,
283 atomic_read(&osb->journal->j_num_trans));
Sunil Mushran50397502008-12-17 14:17:43 -0800284
285 out += snprintf(buf + out, len - out,
286 "%10s => GlobalAllocs: %d LocalAllocs: %d "
287 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
288 "Stats",
289 atomic_read(&osb->alloc_stats.bitmap_data),
290 atomic_read(&osb->alloc_stats.local_data),
291 atomic_read(&osb->alloc_stats.bg_allocs),
292 atomic_read(&osb->alloc_stats.moves),
293 atomic_read(&osb->alloc_stats.bg_extends));
294
295 out += snprintf(buf + out, len - out,
296 "%10s => State: %u Descriptor: %llu Size: %u bits "
297 "Default: %u bits\n",
298 "LocalAlloc", osb->local_alloc_state,
299 (unsigned long long)osb->la_last_gd,
300 osb->local_alloc_bits, osb->local_alloc_default_bits);
301
302 spin_lock(&osb->osb_lock);
303 out += snprintf(buf + out, len - out,
304 "%10s => Slot: %d NumStolen: %d\n", "Steal",
305 osb->s_inode_steal_slot,
306 atomic_read(&osb->s_num_inodes_stolen));
307 spin_unlock(&osb->osb_lock);
308
Sunil Mushrandf152c22009-06-22 11:40:07 -0700309 out += snprintf(buf + out, len - out, "OrphanScan => ");
310 out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
311 os->os_count, os->os_seqno);
312 out += snprintf(buf + out, len - out, " Last Scan: ");
313 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
314 out += snprintf(buf + out, len - out, "Disabled\n");
315 else
316 out += snprintf(buf + out, len - out, "%lu seconds ago\n",
317 (get_seconds() - os->os_scantime.tv_sec));
318
Sunil Mushran50397502008-12-17 14:17:43 -0800319 out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
320 "Slots", "Num", "RecoGen");
Sunil Mushran50397502008-12-17 14:17:43 -0800321 for (i = 0; i < osb->max_slots; ++i) {
322 out += snprintf(buf + out, len - out,
323 "%10s %c %3d %10d\n",
324 " ",
325 (i == osb->slot_num ? '*' : ' '),
326 i, osb->slot_recovery_generations[i]);
327 }
328
329 return out;
330}
331
332static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
333{
334 struct ocfs2_super *osb = inode->i_private;
335 char *buf = NULL;
336
337 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
338 if (!buf)
339 goto bail;
340
341 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
342
343 file->private_data = buf;
344
345 return 0;
346bail:
347 return -ENOMEM;
348}
349
350static int ocfs2_debug_release(struct inode *inode, struct file *file)
351{
352 kfree(file->private_data);
353 return 0;
354}
355
356static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
357 size_t nbytes, loff_t *ppos)
358{
359 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
360 i_size_read(file->f_mapping->host));
361}
362#else
363static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
364{
365 return 0;
366}
367static int ocfs2_debug_release(struct inode *inode, struct file *file)
368{
369 return 0;
370}
371static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
372 size_t nbytes, loff_t *ppos)
373{
374 return 0;
375}
376#endif /* CONFIG_DEBUG_FS */
377
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700378static const struct file_operations ocfs2_osb_debug_fops = {
Sunil Mushran50397502008-12-17 14:17:43 -0800379 .open = ocfs2_osb_debug_open,
380 .release = ocfs2_debug_release,
381 .read = ocfs2_debug_read,
382 .llseek = generic_file_llseek,
383};
384
Mark Fashehccd979b2005-12-15 14:31:24 -0800385static int ocfs2_sync_fs(struct super_block *sb, int wait)
386{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800387 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -0800388 tid_t target;
389 struct ocfs2_super *osb = OCFS2_SB(sb);
390
Mark Fashehccd979b2005-12-15 14:31:24 -0800391 if (ocfs2_is_hard_readonly(osb))
392 return -EROFS;
393
394 if (wait) {
395 status = ocfs2_flush_truncate_log(osb);
396 if (status < 0)
397 mlog_errno(status);
398 } else {
399 ocfs2_schedule_truncate_log_flush(osb, 0);
400 }
401
Joel Becker2b4e30f2008-09-03 20:03:41 -0700402 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
403 &target)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800404 if (wait)
Joel Becker2b4e30f2008-09-03 20:03:41 -0700405 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
406 target);
Mark Fashehccd979b2005-12-15 14:31:24 -0800407 }
408 return 0;
409}
410
Jan Kara1a224ad2008-08-20 15:43:36 +0200411static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
412{
413 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
414 && (ino == USER_QUOTA_SYSTEM_INODE
415 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
416 return 0;
417 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
418 && (ino == GROUP_QUOTA_SYSTEM_INODE
419 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
420 return 0;
421 return 1;
422}
423
Mark Fashehccd979b2005-12-15 14:31:24 -0800424static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
425{
426 struct inode *new = NULL;
427 int status = 0;
428 int i;
429
430 mlog_entry_void();
431
Jan Kara5fa06132008-01-11 00:11:45 +0100432 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800433 if (IS_ERR(new)) {
434 status = PTR_ERR(new);
435 mlog_errno(status);
436 goto bail;
437 }
438 osb->root_inode = new;
439
Jan Kara5fa06132008-01-11 00:11:45 +0100440 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800441 if (IS_ERR(new)) {
442 status = PTR_ERR(new);
443 mlog_errno(status);
444 goto bail;
445 }
446 osb->sys_root_inode = new;
447
448 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
449 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200450 if (!ocfs2_need_system_inode(osb, i))
451 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800452 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
453 if (!new) {
454 ocfs2_release_system_inodes(osb);
455 status = -EINVAL;
456 mlog_errno(status);
457 /* FIXME: Should ERROR_RO_FS */
458 mlog(ML_ERROR, "Unable to load system inode %d, "
459 "possibly corrupt fs?", i);
460 goto bail;
461 }
462 // the array now has one ref, so drop this one
463 iput(new);
464 }
465
466bail:
467 mlog_exit(status);
468 return status;
469}
470
471static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
472{
473 struct inode *new = NULL;
474 int status = 0;
475 int i;
476
477 mlog_entry_void();
478
479 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
480 i < NUM_SYSTEM_INODES;
481 i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200482 if (!ocfs2_need_system_inode(osb, i))
483 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800484 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
485 if (!new) {
486 ocfs2_release_system_inodes(osb);
487 status = -EINVAL;
488 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
489 status, i, osb->slot_num);
490 goto bail;
491 }
492 /* the array now has one ref, so drop this one */
493 iput(new);
494 }
495
496bail:
497 mlog_exit(status);
498 return status;
499}
500
Denis Chengbddb8eb32007-09-27 02:10:04 +0800501static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
Mark Fashehccd979b2005-12-15 14:31:24 -0800502{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800503 int i;
Mark Fashehccd979b2005-12-15 14:31:24 -0800504 struct inode *inode;
505
506 mlog_entry_void();
507
508 for (i = 0; i < NUM_SYSTEM_INODES; i++) {
509 inode = osb->system_inodes[i];
510 if (inode) {
511 iput(inode);
512 osb->system_inodes[i] = NULL;
513 }
514 }
515
516 inode = osb->sys_root_inode;
517 if (inode) {
518 iput(inode);
519 osb->sys_root_inode = NULL;
520 }
521
522 inode = osb->root_inode;
523 if (inode) {
524 iput(inode);
525 osb->root_inode = NULL;
526 }
527
Denis Chengbddb8eb32007-09-27 02:10:04 +0800528 mlog_exit(0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800529}
530
531/* We're allocating fs objects, use GFP_NOFS */
532static struct inode *ocfs2_alloc_inode(struct super_block *sb)
533{
534 struct ocfs2_inode_info *oi;
535
Christoph Lametere6b4f8d2006-12-06 20:33:14 -0800536 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
Mark Fashehccd979b2005-12-15 14:31:24 -0800537 if (!oi)
538 return NULL;
539
Joel Becker2b4e30f2008-09-03 20:03:41 -0700540 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -0800541 return &oi->vfs_inode;
542}
543
544static void ocfs2_destroy_inode(struct inode *inode)
545{
546 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
547}
548
Mark Fasheh5a254032007-07-20 12:56:16 -0700549static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
550 unsigned int cbits)
Mark Fashehccd979b2005-12-15 14:31:24 -0800551{
Mark Fasheh5a254032007-07-20 12:56:16 -0700552 unsigned int bytes = 1 << cbits;
553 unsigned int trim = bytes;
554 unsigned int bitshift = 32;
Mark Fashehccd979b2005-12-15 14:31:24 -0800555
Mark Fasheh5a254032007-07-20 12:56:16 -0700556 /*
557 * i_size and all block offsets in ocfs2 are always 64 bits
558 * wide. i_clusters is 32 bits, in cluster-sized units. So on
559 * 64 bit platforms, cluster size will be the limiting factor.
Mark Fashehccd979b2005-12-15 14:31:24 -0800560 */
561
562#if BITS_PER_LONG == 32
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +0200563# if defined(CONFIG_LBDAF)
Alexey Dobriyan2ecd05a2006-10-11 01:22:05 -0700564 BUILD_BUG_ON(sizeof(sector_t) != 8);
Mark Fasheh5a254032007-07-20 12:56:16 -0700565 /*
566 * We might be limited by page cache size.
567 */
568 if (bytes > PAGE_CACHE_SIZE) {
569 bytes = PAGE_CACHE_SIZE;
570 trim = 1;
571 /*
572 * Shift by 31 here so that we don't get larger than
573 * MAX_LFS_FILESIZE
574 */
575 bitshift = 31;
576 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800577# else
Mark Fasheh5a254032007-07-20 12:56:16 -0700578 /*
579 * We are limited by the size of sector_t. Use block size, as
580 * that's what we expose to the VFS.
581 */
582 bytes = 1 << bbits;
583 trim = 1;
584 bitshift = 31;
Mark Fashehccd979b2005-12-15 14:31:24 -0800585# endif
586#endif
587
Mark Fasheh5a254032007-07-20 12:56:16 -0700588 /*
589 * Trim by a whole cluster when we can actually approach the
590 * on-disk limits. Otherwise we can overflow i_clusters when
591 * an extent start is at the max offset.
592 */
593 return (((unsigned long long)bytes) << bitshift) - trim;
Mark Fashehccd979b2005-12-15 14:31:24 -0800594}
595
596static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
597{
598 int incompat_features;
599 int ret = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800600 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800601 struct ocfs2_super *osb = OCFS2_SB(sb);
602
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200603 lock_kernel();
604
Jan Kara5297aad2009-10-15 14:54:04 +0200605 if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
606 !ocfs2_check_set_options(sb, &parsed_options)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800607 ret = -EINVAL;
608 goto out;
609 }
610
611 if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800612 (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800613 ret = -EINVAL;
614 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
615 goto out;
616 }
617
618 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800619 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800620 ret = -EINVAL;
621 mlog(ML_ERROR, "Cannot change data mode on remount\n");
622 goto out;
623 }
624
Joel Becker12462f12008-09-03 20:03:40 -0700625 /* Probably don't want this on remount; it might
626 * mess with other nodes */
627 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
628 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
629 ret = -EINVAL;
630 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
631 goto out;
632 }
633
Mark Fashehccd979b2005-12-15 14:31:24 -0800634 /* We're going to/from readonly mode. */
635 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
Jan Kara19ece542008-08-21 20:13:17 +0200636 /* Disable quota accounting before remounting RO */
637 if (*flags & MS_RDONLY) {
638 ret = ocfs2_susp_quotas(osb, 0);
639 if (ret < 0)
640 goto out;
641 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800642 /* Lock here so the check of HARD_RO and the potential
643 * setting of SOFT_RO is atomic. */
644 spin_lock(&osb->osb_lock);
645 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
646 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
647 ret = -EROFS;
648 goto unlock_osb;
649 }
650
651 if (*flags & MS_RDONLY) {
652 mlog(0, "Going to ro mode.\n");
653 sb->s_flags |= MS_RDONLY;
654 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
655 } else {
656 mlog(0, "Making ro filesystem writeable.\n");
657
658 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
659 mlog(ML_ERROR, "Cannot remount RDWR "
660 "filesystem due to previous errors.\n");
661 ret = -EROFS;
662 goto unlock_osb;
663 }
664 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
665 if (incompat_features) {
666 mlog(ML_ERROR, "Cannot remount RDWR because "
667 "of unsupported optional features "
668 "(%x).\n", incompat_features);
669 ret = -EINVAL;
670 goto unlock_osb;
671 }
672 sb->s_flags &= ~MS_RDONLY;
673 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
674 }
675unlock_osb:
676 spin_unlock(&osb->osb_lock);
Jan Kara19ece542008-08-21 20:13:17 +0200677 /* Enable quota accounting after remounting RW */
678 if (!ret && !(*flags & MS_RDONLY)) {
679 if (sb_any_quota_suspended(sb))
680 ret = ocfs2_susp_quotas(osb, 1);
681 else
682 ret = ocfs2_enable_quotas(osb);
683 if (ret < 0) {
684 /* Return back changes... */
685 spin_lock(&osb->osb_lock);
686 sb->s_flags |= MS_RDONLY;
687 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
688 spin_unlock(&osb->osb_lock);
689 goto out;
690 }
691 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800692 }
693
694 if (!ret) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800695 /* Only save off the new mount options in case of a successful
696 * remount. */
Tiger Yangc0123ad2007-09-08 00:16:10 +0800697 osb->s_mount_opt = parsed_options.mount_opt;
698 osb->s_atime_quantum = parsed_options.atime_quantum;
699 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -0800700 if (parsed_options.commit_interval)
701 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fashehe001e792007-11-07 14:21:45 -0800702
703 if (!ocfs2_is_hard_readonly(osb))
704 ocfs2_set_journal_params(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800705 }
706out:
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200707 unlock_kernel();
Mark Fashehccd979b2005-12-15 14:31:24 -0800708 return ret;
709}
710
711static int ocfs2_sb_probe(struct super_block *sb,
712 struct buffer_head **bh,
Joel Becker73be1922009-01-06 14:57:08 -0800713 int *sector_size,
714 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -0800715{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800716 int status, tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800717 struct ocfs1_vol_disk_hdr *hdr;
718 struct ocfs2_dinode *di;
719 int blksize;
720
721 *bh = NULL;
722
723 /* may be > 512 */
Martin K. Petersene1defc42009-05-22 17:17:49 -0400724 *sector_size = bdev_logical_block_size(sb->s_bdev);
Mark Fashehccd979b2005-12-15 14:31:24 -0800725 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
726 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
727 *sector_size, OCFS2_MAX_BLOCKSIZE);
728 status = -EINVAL;
729 goto bail;
730 }
731
732 /* Can this really happen? */
733 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
734 *sector_size = OCFS2_MIN_BLOCKSIZE;
735
736 /* check block zero for old format */
737 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
738 if (status < 0) {
739 mlog_errno(status);
740 goto bail;
741 }
742 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
743 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
744 mlog(ML_ERROR, "incompatible version: %u.%u\n",
745 hdr->major_version, hdr->minor_version);
746 status = -EINVAL;
747 }
748 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
749 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
750 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
751 hdr->signature);
752 status = -EINVAL;
753 }
754 brelse(*bh);
755 *bh = NULL;
756 if (status < 0) {
757 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
758 "upgraded before mounting with ocfs v2\n");
759 goto bail;
760 }
761
762 /*
763 * Now check at magic offset for 512, 1024, 2048, 4096
764 * blocksizes. 4096 is the maximum blocksize because it is
765 * the minimum clustersize.
766 */
767 status = -EINVAL;
768 for (blksize = *sector_size;
769 blksize <= OCFS2_MAX_BLOCKSIZE;
770 blksize <<= 1) {
771 tmpstat = ocfs2_get_sector(sb, bh,
772 OCFS2_SUPER_BLOCK_BLKNO,
773 blksize);
774 if (tmpstat < 0) {
775 status = tmpstat;
776 mlog_errno(status);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700777 break;
Mark Fashehccd979b2005-12-15 14:31:24 -0800778 }
779 di = (struct ocfs2_dinode *) (*bh)->b_data;
Joel Becker73be1922009-01-06 14:57:08 -0800780 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
Jan Kara1c1d9792009-07-22 13:17:19 +0200781 spin_lock_init(&stats->b_lock);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700782 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
783 if (tmpstat < 0) {
784 brelse(*bh);
785 *bh = NULL;
786 }
787 if (tmpstat != -EAGAIN) {
788 status = tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800789 break;
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700790 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800791 }
792
793bail:
794 return status;
795}
796
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800797static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
798{
799 if (ocfs2_mount_local(osb)) {
800 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
801 mlog(ML_ERROR, "Cannot heartbeat on a locally "
802 "mounted device.\n");
803 return -EINVAL;
804 }
805 }
806
Joel Beckerb61817e2008-02-01 15:08:23 -0800807 if (ocfs2_userspace_stack(osb)) {
808 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
809 mlog(ML_ERROR, "Userspace stack expected, but "
810 "o2cb heartbeat arguments passed to mount\n");
811 return -EINVAL;
812 }
813 }
814
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800815 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800816 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
817 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800818 mlog(ML_ERROR, "Heartbeat has to be started to mount "
819 "a read-write clustered device.\n");
820 return -EINVAL;
821 }
822 }
823
824 return 0;
825}
826
Joel Beckerb61817e2008-02-01 15:08:23 -0800827/*
828 * If we're using a userspace stack, mount should have passed
829 * a name that matches the disk. If not, mount should not
830 * have passed a stack.
831 */
832static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
833 struct mount_options *mopt)
834{
835 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
836 mlog(ML_ERROR,
837 "cluster stack passed to mount, but this filesystem "
838 "does not support it\n");
839 return -EINVAL;
840 }
841
842 if (ocfs2_userspace_stack(osb) &&
843 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
844 OCFS2_STACK_LABEL_LEN)) {
845 mlog(ML_ERROR,
846 "cluster stack passed to mount (\"%s\") does not "
847 "match the filesystem (\"%s\")\n",
848 mopt->cluster_stack,
849 osb->osb_cluster_stack);
850 return -EINVAL;
851 }
852
853 return 0;
854}
855
Jan Kara19ece542008-08-21 20:13:17 +0200856static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
857{
858 int type;
859 struct super_block *sb = osb->sb;
860 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
861 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
862 int status = 0;
863
864 for (type = 0; type < MAXQUOTAS; type++) {
865 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
866 continue;
867 if (unsuspend)
868 status = vfs_quota_enable(
869 sb_dqopt(sb)->files[type],
870 type, QFMT_OCFS2,
871 DQUOT_SUSPENDED);
872 else
873 status = vfs_quota_disable(sb, type,
874 DQUOT_SUSPENDED);
875 if (status < 0)
876 break;
877 }
878 if (status < 0)
879 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
880 "remount (error = %d).\n", status);
881 return status;
882}
883
884static int ocfs2_enable_quotas(struct ocfs2_super *osb)
885{
886 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
887 struct super_block *sb = osb->sb;
888 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
889 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
890 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
891 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
892 int status;
893 int type;
894
895 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
896 for (type = 0; type < MAXQUOTAS; type++) {
897 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
898 continue;
899 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
900 osb->slot_num);
901 if (!inode[type]) {
902 status = -ENOENT;
903 goto out_quota_off;
904 }
905 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
906 DQUOT_USAGE_ENABLED);
907 if (status < 0)
908 goto out_quota_off;
909 }
910
911 for (type = 0; type < MAXQUOTAS; type++)
912 iput(inode[type]);
913 return 0;
914out_quota_off:
915 ocfs2_disable_quotas(osb);
916 for (type = 0; type < MAXQUOTAS; type++)
917 iput(inode[type]);
918 mlog_errno(status);
919 return status;
920}
921
922static void ocfs2_disable_quotas(struct ocfs2_super *osb)
923{
924 int type;
925 struct inode *inode;
926 struct super_block *sb = osb->sb;
927
928 /* We mostly ignore errors in this function because there's not much
929 * we can do when we see them */
930 for (type = 0; type < MAXQUOTAS; type++) {
931 if (!sb_has_quota_loaded(sb, type))
932 continue;
933 inode = igrab(sb->s_dquot.files[type]);
934 /* Turn off quotas. This will remove all dquot structures from
935 * memory and so they will be automatically synced to global
936 * quota files */
937 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
938 DQUOT_LIMITS_ENABLED);
939 if (!inode)
940 continue;
941 iput(inode);
942 }
943}
944
945/* Handle quota on quotactl */
946static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
947 char *path, int remount)
948{
949 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
950 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
951
952 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
953 return -EINVAL;
954
955 if (remount)
956 return 0; /* Just ignore it has been handled in
957 * ocfs2_remount() */
958 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
959 format_id, DQUOT_LIMITS_ENABLED);
960}
961
962/* Handle quota off quotactl */
963static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
964{
965 if (remount)
966 return 0; /* Ignore now and handle later in
967 * ocfs2_remount() */
968 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
969}
970
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700971static const struct quotactl_ops ocfs2_quotactl_ops = {
Jan Kara19ece542008-08-21 20:13:17 +0200972 .quota_on = ocfs2_quota_on,
973 .quota_off = ocfs2_quota_off,
974 .quota_sync = vfs_quota_sync,
975 .get_info = vfs_get_dqinfo,
976 .set_info = vfs_set_dqinfo,
977 .get_dqblk = vfs_get_dqblk,
978 .set_dqblk = vfs_set_dqblk,
979};
980
Mark Fashehccd979b2005-12-15 14:31:24 -0800981static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
982{
983 struct dentry *root;
984 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800985 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800986 struct inode *inode = NULL;
987 struct ocfs2_super *osb = NULL;
988 struct buffer_head *bh = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800989 char nodestr[8];
Joel Becker73be1922009-01-06 14:57:08 -0800990 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -0800991
992 mlog_entry("%p, %p, %i", sb, data, silent);
993
Tiger Yangc0123ad2007-09-08 00:16:10 +0800994 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800995 status = -EINVAL;
996 goto read_super_error;
997 }
998
999 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -08001000 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001001 if (status < 0) {
1002 mlog(ML_ERROR, "superblock probe failed!\n");
1003 goto read_super_error;
1004 }
1005
Joel Becker73be1922009-01-06 14:57:08 -08001006 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001007 osb = OCFS2_SB(sb);
1008 if (status < 0) {
1009 mlog_errno(status);
1010 goto read_super_error;
1011 }
1012 brelse(bh);
1013 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001014
Jan Kara5297aad2009-10-15 14:54:04 +02001015 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1016 status = -EINVAL;
1017 goto read_super_error;
1018 }
Tiger Yangc0123ad2007-09-08 00:16:10 +08001019 osb->s_mount_opt = parsed_options.mount_opt;
1020 osb->s_atime_quantum = parsed_options.atime_quantum;
1021 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001022 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh9c7af402008-07-28 18:02:53 -07001023 osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
1024 osb->local_alloc_bits = osb->local_alloc_default_bits;
Mark Fashehccd979b2005-12-15 14:31:24 -08001025
Joel Beckerb61817e2008-02-01 15:08:23 -08001026 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1027 if (status)
1028 goto read_super_error;
1029
Mark Fashehccd979b2005-12-15 14:31:24 -08001030 sb->s_magic = OCFS2_SUPER_MAGIC;
1031
Tiger Yanga68979b2008-11-14 11:17:52 +08001032 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1033 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1034
Mark Fashehccd979b2005-12-15 14:31:24 -08001035 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1036 * heartbeat=none */
1037 if (bdev_read_only(sb->s_bdev)) {
1038 if (!(sb->s_flags & MS_RDONLY)) {
1039 status = -EACCES;
1040 mlog(ML_ERROR, "Readonly device detected but readonly "
1041 "mount was not specified.\n");
1042 goto read_super_error;
1043 }
1044
1045 /* You should not be able to start a local heartbeat
1046 * on a readonly device. */
1047 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1048 status = -EROFS;
1049 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1050 "device.\n");
1051 goto read_super_error;
1052 }
1053
1054 status = ocfs2_check_journals_nolocks(osb);
1055 if (status < 0) {
1056 if (status == -EROFS)
1057 mlog(ML_ERROR, "Recovery required on readonly "
1058 "file system, but write access is "
1059 "unavailable.\n");
1060 else
1061 mlog_errno(status);
1062 goto read_super_error;
1063 }
1064
1065 ocfs2_set_ro_flag(osb, 1);
1066
1067 printk(KERN_NOTICE "Readonly device detected. No cluster "
1068 "services will be utilized for this mount. Recovery "
1069 "will be skipped.\n");
1070 }
1071
1072 if (!ocfs2_is_hard_readonly(osb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001073 if (sb->s_flags & MS_RDONLY)
1074 ocfs2_set_ro_flag(osb, 0);
1075 }
1076
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001077 status = ocfs2_verify_heartbeat(osb);
1078 if (status < 0) {
1079 mlog_errno(status);
1080 goto read_super_error;
1081 }
1082
Mark Fashehccd979b2005-12-15 14:31:24 -08001083 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1084 ocfs2_debugfs_root);
1085 if (!osb->osb_debug_root) {
1086 status = -EINVAL;
1087 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1088 goto read_super_error;
1089 }
1090
Sunil Mushran50397502008-12-17 14:17:43 -08001091 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1092 osb->osb_debug_root,
1093 osb,
1094 &ocfs2_osb_debug_fops);
1095 if (!osb->osb_ctxt) {
1096 status = -EINVAL;
1097 mlog_errno(status);
1098 goto read_super_error;
1099 }
1100
Joel Becker73be1922009-01-06 14:57:08 -08001101 if (ocfs2_meta_ecc(osb)) {
1102 status = ocfs2_blockcheck_stats_debugfs_install(
1103 &osb->osb_ecc_stats,
1104 osb->osb_debug_root);
1105 if (status) {
1106 mlog(ML_ERROR,
1107 "Unable to create blockcheck statistics "
1108 "files\n");
1109 goto read_super_error;
1110 }
1111 }
1112
Mark Fashehccd979b2005-12-15 14:31:24 -08001113 status = ocfs2_mount_volume(sb);
1114 if (osb->root_inode)
1115 inode = igrab(osb->root_inode);
1116
1117 if (status < 0)
1118 goto read_super_error;
1119
1120 if (!inode) {
1121 status = -EIO;
1122 mlog_errno(status);
1123 goto read_super_error;
1124 }
1125
1126 root = d_alloc_root(inode);
1127 if (!root) {
1128 status = -ENOMEM;
1129 mlog_errno(status);
1130 goto read_super_error;
1131 }
1132
1133 sb->s_root = root;
1134
1135 ocfs2_complete_mount_recovery(osb);
1136
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001137 if (ocfs2_mount_local(osb))
1138 snprintf(nodestr, sizeof(nodestr), "local");
1139 else
Joel Becker19fdb622008-01-30 15:38:24 -08001140 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001141
1142 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001143 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001144 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001145 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1146 "ordered");
1147
1148 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1149 wake_up(&osb->osb_mount_event);
1150
Jan Kara19ece542008-08-21 20:13:17 +02001151 /* Now we can initialize quotas because we can afford to wait
1152 * for cluster locks recovery now. That also means that truncation
1153 * log recovery can happen but that waits for proper quota setup */
1154 if (!(sb->s_flags & MS_RDONLY)) {
1155 status = ocfs2_enable_quotas(osb);
1156 if (status < 0) {
1157 /* We have to err-out specially here because
1158 * s_root is already set */
1159 mlog_errno(status);
1160 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1161 wake_up(&osb->osb_mount_event);
1162 mlog_exit(status);
1163 return status;
1164 }
1165 }
1166
1167 ocfs2_complete_quota_recovery(osb);
1168
1169 /* Now we wake up again for processes waiting for quotas */
1170 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1171 wake_up(&osb->osb_mount_event);
1172
Sunil Mushrandf152c22009-06-22 11:40:07 -07001173 /* Start this when the mount is almost sure of being successful */
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04001174 ocfs2_orphan_scan_start(osb);
Sunil Mushrandf152c22009-06-22 11:40:07 -07001175
Mark Fashehccd979b2005-12-15 14:31:24 -08001176 mlog_exit(status);
1177 return status;
1178
1179read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001180 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001181
1182 if (inode)
1183 iput(inode);
1184
1185 if (osb) {
1186 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1187 wake_up(&osb->osb_mount_event);
1188 ocfs2_dismount_volume(sb, 1);
1189 }
1190
1191 mlog_exit(status);
1192 return status;
1193}
1194
David Howells454e2392006-06-23 02:02:57 -07001195static int ocfs2_get_sb(struct file_system_type *fs_type,
1196 int flags,
1197 const char *dev_name,
1198 void *data,
1199 struct vfsmount *mnt)
Mark Fashehccd979b2005-12-15 14:31:24 -08001200{
David Howells454e2392006-06-23 02:02:57 -07001201 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1202 mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -08001203}
1204
Jan Karaf7b1aa62009-07-20 12:12:36 +02001205static void ocfs2_kill_sb(struct super_block *sb)
1206{
1207 struct ocfs2_super *osb = OCFS2_SB(sb);
1208
Jan Kara5fd13182009-07-30 17:01:53 +02001209 /* Failed mount? */
1210 if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1211 goto out;
1212
Jan Karaf7b1aa62009-07-20 12:12:36 +02001213 /* Prevent further queueing of inode drop events */
1214 spin_lock(&dentry_list_lock);
1215 ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1216 spin_unlock(&dentry_list_lock);
1217 /* Wait for work to finish and/or remove it */
1218 cancel_work_sync(&osb->dentry_lock_work);
Jan Kara5fd13182009-07-30 17:01:53 +02001219out:
Jan Karaf7b1aa62009-07-20 12:12:36 +02001220 kill_block_super(sb);
1221}
1222
Mark Fashehccd979b2005-12-15 14:31:24 -08001223static struct file_system_type ocfs2_fs_type = {
1224 .owner = THIS_MODULE,
1225 .name = "ocfs2",
1226 .get_sb = ocfs2_get_sb, /* is this called when we mount
1227 * the fs? */
Jan Karaf7b1aa62009-07-20 12:12:36 +02001228 .kill_sb = ocfs2_kill_sb,
1229
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001230 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001231 .next = NULL
1232};
1233
Jan Kara5297aad2009-10-15 14:54:04 +02001234static int ocfs2_check_set_options(struct super_block *sb,
1235 struct mount_options *options)
1236{
1237 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1238 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1239 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1240 mlog(ML_ERROR, "User quotas were requested, but this "
1241 "filesystem does not have the feature enabled.\n");
1242 return 0;
1243 }
1244 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1245 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1246 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1247 mlog(ML_ERROR, "Group quotas were requested, but this "
1248 "filesystem does not have the feature enabled.\n");
1249 return 0;
1250 }
1251 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1252 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1253 mlog(ML_ERROR, "ACL support requested but extended attributes "
1254 "feature is not enabled\n");
1255 return 0;
1256 }
1257 /* No ACL setting specified? Use XATTR feature... */
1258 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1259 OCFS2_MOUNT_NO_POSIX_ACL))) {
1260 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1261 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1262 else
1263 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1264 }
1265 return 1;
1266}
1267
Mark Fashehccd979b2005-12-15 14:31:24 -08001268static int ocfs2_parse_options(struct super_block *sb,
1269 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001270 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001271 int is_remount)
1272{
1273 int status;
1274 char *p;
1275
1276 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1277 options ? options : "(none)");
1278
Mark Fashehd147b3d2007-11-07 14:40:36 -08001279 mopt->commit_interval = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001280 mopt->mount_opt = 0;
1281 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1282 mopt->slot = OCFS2_INVALID_SLOT;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001283 mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
Joel Beckerb61817e2008-02-01 15:08:23 -08001284 mopt->cluster_stack[0] = '\0';
Mark Fashehccd979b2005-12-15 14:31:24 -08001285
1286 if (!options) {
1287 status = 1;
1288 goto bail;
1289 }
1290
1291 while ((p = strsep(&options, ",")) != NULL) {
1292 int token, option;
1293 substring_t args[MAX_OPT_ARGS];
1294
1295 if (!*p)
1296 continue;
1297
1298 token = match_token(p, tokens, args);
1299 switch (token) {
1300 case Opt_hb_local:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001301 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001302 break;
1303 case Opt_hb_none:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001304 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001305 break;
1306 case Opt_barrier:
1307 if (match_int(&args[0], &option)) {
1308 status = 0;
1309 goto bail;
1310 }
1311 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001312 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001313 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001314 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001315 break;
1316 case Opt_intr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001317 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001318 break;
1319 case Opt_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001320 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001321 break;
1322 case Opt_err_panic:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001323 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001324 break;
1325 case Opt_err_ro:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001326 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001327 break;
1328 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001329 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001330 break;
1331 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001332 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001333 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001334 case Opt_user_xattr:
1335 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1336 break;
1337 case Opt_nouser_xattr:
1338 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1339 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001340 case Opt_atime_quantum:
1341 if (match_int(&args[0], &option)) {
1342 status = 0;
1343 goto bail;
1344 }
1345 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001346 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001347 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001348 case Opt_slot:
1349 option = 0;
1350 if (match_int(&args[0], &option)) {
1351 status = 0;
1352 goto bail;
1353 }
1354 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001355 mopt->slot = (s16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001356 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001357 case Opt_commit:
1358 option = 0;
1359 if (match_int(&args[0], &option)) {
1360 status = 0;
1361 goto bail;
1362 }
1363 if (option < 0)
1364 return 0;
1365 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001366 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001367 mopt->commit_interval = HZ * option;
1368 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001369 case Opt_localalloc:
1370 option = 0;
1371 if (match_int(&args[0], &option)) {
1372 status = 0;
1373 goto bail;
1374 }
1375 if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1376 mopt->localalloc_opt = option;
1377 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001378 case Opt_localflocks:
1379 /*
1380 * Changing this during remount could race
1381 * flock() requests, or "unbalance" existing
1382 * ones (e.g., a lock is taken in one mode but
1383 * dropped in the other). If users care enough
1384 * to flip locking modes during remount, we
1385 * could add a "local" flag to individual
1386 * flock structures for proper tracking of
1387 * state.
1388 */
1389 if (!is_remount)
1390 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1391 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001392 case Opt_stack:
1393 /* Check both that the option we were passed
1394 * is of the right length and that it is a proper
1395 * string of the right length.
1396 */
1397 if (((args[0].to - args[0].from) !=
1398 OCFS2_STACK_LABEL_LEN) ||
1399 (strnlen(args[0].from,
1400 OCFS2_STACK_LABEL_LEN) !=
1401 OCFS2_STACK_LABEL_LEN)) {
1402 mlog(ML_ERROR,
1403 "Invalid cluster_stack option\n");
1404 status = 0;
1405 goto bail;
1406 }
1407 memcpy(mopt->cluster_stack, args[0].from,
1408 OCFS2_STACK_LABEL_LEN);
1409 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1410 break;
Joel Becker12462f12008-09-03 20:03:40 -07001411 case Opt_inode64:
1412 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1413 break;
Jan Kara19ece542008-08-21 20:13:17 +02001414 case Opt_usrquota:
Jan Kara19ece542008-08-21 20:13:17 +02001415 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1416 break;
1417 case Opt_grpquota:
Jan Kara19ece542008-08-21 20:13:17 +02001418 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1419 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001420 case Opt_acl:
1421 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
Jan Kara5297aad2009-10-15 14:54:04 +02001422 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001423 break;
1424 case Opt_noacl:
Jan Kara5297aad2009-10-15 14:54:04 +02001425 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001426 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1427 break;
Mark Fashehccd979b2005-12-15 14:31:24 -08001428 default:
1429 mlog(ML_ERROR,
1430 "Unrecognized mount option \"%s\" "
1431 "or missing value\n", p);
1432 status = 0;
1433 goto bail;
1434 }
1435 }
1436
1437 status = 1;
1438
1439bail:
1440 mlog_exit(status);
1441 return status;
1442}
1443
Sunil Mushrand5500712007-09-06 13:34:16 -07001444static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1445{
1446 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1447 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001448 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001449
1450 if (opts & OCFS2_MOUNT_HB_LOCAL)
1451 seq_printf(s, ",_netdev,heartbeat=local");
1452 else
1453 seq_printf(s, ",heartbeat=none");
1454
1455 if (opts & OCFS2_MOUNT_NOINTR)
1456 seq_printf(s, ",nointr");
1457
1458 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1459 seq_printf(s, ",data=writeback");
1460 else
1461 seq_printf(s, ",data=ordered");
1462
1463 if (opts & OCFS2_MOUNT_BARRIER)
1464 seq_printf(s, ",barrier=1");
1465
1466 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1467 seq_printf(s, ",errors=panic");
1468 else
1469 seq_printf(s, ",errors=remount-ro");
1470
1471 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1472 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1473
1474 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1475 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1476
Mark Fashehd147b3d2007-11-07 14:40:36 -08001477 if (osb->osb_commit_interval)
1478 seq_printf(s, ",commit=%u",
1479 (unsigned) (osb->osb_commit_interval / HZ));
1480
Mark Fashehebcee4b2008-07-28 14:55:20 -07001481 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1482 if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1483 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001484
Mark Fasheh53fc6222007-12-20 16:49:04 -08001485 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1486 seq_printf(s, ",localflocks,");
1487
Joel Beckerb61817e2008-02-01 15:08:23 -08001488 if (osb->osb_cluster_stack[0])
1489 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1490 osb->osb_cluster_stack);
Jan Kara19ece542008-08-21 20:13:17 +02001491 if (opts & OCFS2_MOUNT_USRQUOTA)
1492 seq_printf(s, ",usrquota");
1493 if (opts & OCFS2_MOUNT_GRPQUOTA)
1494 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001495
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001496 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1497 seq_printf(s, ",nouser_xattr");
1498 else
1499 seq_printf(s, ",user_xattr");
1500
Joel Becker12462f12008-09-03 20:03:40 -07001501 if (opts & OCFS2_MOUNT_INODE64)
1502 seq_printf(s, ",inode64");
1503
Tiger Yanga68979b2008-11-14 11:17:52 +08001504 if (opts & OCFS2_MOUNT_POSIX_ACL)
1505 seq_printf(s, ",acl");
1506 else
1507 seq_printf(s, ",noacl");
Tiger Yanga68979b2008-11-14 11:17:52 +08001508
Sunil Mushrand5500712007-09-06 13:34:16 -07001509 return 0;
1510}
1511
Mark Fashehccd979b2005-12-15 14:31:24 -08001512static int __init ocfs2_init(void)
1513{
1514 int status;
1515
1516 mlog_entry_void();
1517
1518 ocfs2_print_version();
1519
Mark Fashehccd979b2005-12-15 14:31:24 -08001520 status = init_ocfs2_uptodate_cache();
1521 if (status < 0) {
1522 mlog_errno(status);
1523 goto leave;
1524 }
1525
1526 status = ocfs2_initialize_mem_caches();
1527 if (status < 0) {
1528 mlog_errno(status);
1529 goto leave;
1530 }
1531
1532 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1533 if (!ocfs2_wq) {
1534 status = -ENOMEM;
1535 goto leave;
1536 }
1537
Mark Fashehccd979b2005-12-15 14:31:24 -08001538 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1539 if (!ocfs2_debugfs_root) {
1540 status = -EFAULT;
1541 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1542 }
1543
Mark Fasheh171bf932008-10-20 15:36:47 +02001544 status = ocfs2_quota_setup();
1545 if (status)
1546 goto leave;
1547
Joel Becker63e0c482008-01-30 16:58:36 -08001548 ocfs2_set_locking_protocol();
1549
Jan Kara9e33d692008-08-25 19:56:50 +02001550 status = register_quota_format(&ocfs2_quota_format);
Mark Fashehccd979b2005-12-15 14:31:24 -08001551leave:
1552 if (status < 0) {
Mark Fasheh171bf932008-10-20 15:36:47 +02001553 ocfs2_quota_shutdown();
Mark Fashehccd979b2005-12-15 14:31:24 -08001554 ocfs2_free_mem_caches();
1555 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001556 }
1557
1558 mlog_exit(status);
1559
1560 if (status >= 0) {
1561 return register_filesystem(&ocfs2_fs_type);
1562 } else
1563 return -1;
1564}
1565
1566static void __exit ocfs2_exit(void)
1567{
1568 mlog_entry_void();
1569
Mark Fasheh171bf932008-10-20 15:36:47 +02001570 ocfs2_quota_shutdown();
1571
Mark Fashehccd979b2005-12-15 14:31:24 -08001572 if (ocfs2_wq) {
1573 flush_workqueue(ocfs2_wq);
1574 destroy_workqueue(ocfs2_wq);
1575 }
1576
Jan Kara9e33d692008-08-25 19:56:50 +02001577 unregister_quota_format(&ocfs2_quota_format);
1578
Mark Fashehccd979b2005-12-15 14:31:24 -08001579 debugfs_remove(ocfs2_debugfs_root);
1580
1581 ocfs2_free_mem_caches();
1582
1583 unregister_filesystem(&ocfs2_fs_type);
1584
Mark Fashehccd979b2005-12-15 14:31:24 -08001585 exit_ocfs2_uptodate_cache();
1586
1587 mlog_exit_void();
1588}
1589
1590static void ocfs2_put_super(struct super_block *sb)
1591{
1592 mlog_entry("(0x%p)\n", sb);
1593
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001594 lock_kernel();
1595
Mark Fashehccd979b2005-12-15 14:31:24 -08001596 ocfs2_sync_blockdev(sb);
1597 ocfs2_dismount_volume(sb, 0);
1598
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001599 unlock_kernel();
1600
Mark Fashehccd979b2005-12-15 14:31:24 -08001601 mlog_exit_void();
1602}
1603
David Howells726c3342006-06-23 02:02:58 -07001604static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001605{
1606 struct ocfs2_super *osb;
1607 u32 numbits, freebits;
1608 int status;
1609 struct ocfs2_dinode *bm_lock;
1610 struct buffer_head *bh = NULL;
1611 struct inode *inode = NULL;
1612
David Howells726c3342006-06-23 02:02:58 -07001613 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001614
David Howells726c3342006-06-23 02:02:58 -07001615 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001616
1617 inode = ocfs2_get_system_file_inode(osb,
1618 GLOBAL_BITMAP_SYSTEM_INODE,
1619 OCFS2_INVALID_SLOT);
1620 if (!inode) {
1621 mlog(ML_ERROR, "failed to get bitmap inode\n");
1622 status = -EIO;
1623 goto bail;
1624 }
1625
Mark Fashehe63aecb62007-10-18 15:30:42 -07001626 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001627 if (status < 0) {
1628 mlog_errno(status);
1629 goto bail;
1630 }
1631
1632 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1633
1634 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1635 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1636
1637 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001638 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001639 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1640 buf->f_blocks = ((sector_t) numbits) *
1641 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1642 buf->f_bfree = ((sector_t) freebits) *
1643 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1644 buf->f_bavail = buf->f_bfree;
1645 buf->f_files = numbits;
1646 buf->f_ffree = freebits;
1647
1648 brelse(bh);
1649
Mark Fashehe63aecb62007-10-18 15:30:42 -07001650 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001651 status = 0;
1652bail:
1653 if (inode)
1654 iput(inode);
1655
1656 mlog_exit(status);
1657
1658 return status;
1659}
1660
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001661static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001662{
1663 struct ocfs2_inode_info *oi = data;
1664
Christoph Lametera35afb82007-05-16 22:10:57 -07001665 oi->ip_flags = 0;
1666 oi->ip_open_count = 0;
1667 spin_lock_init(&oi->ip_lock);
1668 ocfs2_extent_map_init(&oi->vfs_inode);
1669 INIT_LIST_HEAD(&oi->ip_io_markers);
Christoph Lametera35afb82007-05-16 22:10:57 -07001670 oi->ip_dir_start_lookup = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001671
Christoph Lametera35afb82007-05-16 22:10:57 -07001672 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001673 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001674 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001675
Christoph Lametera35afb82007-05-16 22:10:57 -07001676 oi->ip_blkno = 0ULL;
1677 oi->ip_clusters = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001678
Christoph Lametera35afb82007-05-16 22:10:57 -07001679 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001680 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001681 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001682
Joel Becker8cb471e2009-02-10 20:00:41 -08001683 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
Joel Becker6e5a3d72009-02-10 19:00:37 -08001684 &ocfs2_inode_caching_ops);
Mark Fashehccd979b2005-12-15 14:31:24 -08001685
Christoph Lametera35afb82007-05-16 22:10:57 -07001686 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001687}
1688
1689static int ocfs2_initialize_mem_caches(void)
1690{
1691 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001692 sizeof(struct ocfs2_inode_info),
1693 0,
1694 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1695 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001696 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001697 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1698 sizeof(struct ocfs2_dquot),
1699 0,
1700 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1701 SLAB_MEM_SPREAD),
1702 NULL);
1703 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1704 sizeof(struct ocfs2_quota_chunk),
1705 0,
1706 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1707 NULL);
1708 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1709 !ocfs2_qf_chunk_cachep) {
1710 if (ocfs2_inode_cachep)
1711 kmem_cache_destroy(ocfs2_inode_cachep);
1712 if (ocfs2_dquot_cachep)
1713 kmem_cache_destroy(ocfs2_dquot_cachep);
1714 if (ocfs2_qf_chunk_cachep)
1715 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001716 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001717 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001718
Mark Fashehccd979b2005-12-15 14:31:24 -08001719 return 0;
1720}
1721
1722static void ocfs2_free_mem_caches(void)
1723{
1724 if (ocfs2_inode_cachep)
1725 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001726 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001727
1728 if (ocfs2_dquot_cachep)
1729 kmem_cache_destroy(ocfs2_dquot_cachep);
1730 ocfs2_dquot_cachep = NULL;
1731
1732 if (ocfs2_qf_chunk_cachep)
1733 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1734 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001735}
1736
1737static int ocfs2_get_sector(struct super_block *sb,
1738 struct buffer_head **bh,
1739 int block,
1740 int sect_size)
1741{
1742 if (!sb_set_blocksize(sb, sect_size)) {
1743 mlog(ML_ERROR, "unable to set blocksize\n");
1744 return -EIO;
1745 }
1746
1747 *bh = sb_getblk(sb, block);
1748 if (!*bh) {
1749 mlog_errno(-EIO);
1750 return -EIO;
1751 }
1752 lock_buffer(*bh);
1753 if (!buffer_dirty(*bh))
1754 clear_buffer_uptodate(*bh);
1755 unlock_buffer(*bh);
1756 ll_rw_block(READ, 1, bh);
1757 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001758 if (!buffer_uptodate(*bh)) {
1759 mlog_errno(-EIO);
1760 brelse(*bh);
1761 *bh = NULL;
1762 return -EIO;
1763 }
1764
Mark Fashehccd979b2005-12-15 14:31:24 -08001765 return 0;
1766}
1767
Mark Fashehccd979b2005-12-15 14:31:24 -08001768static int ocfs2_mount_volume(struct super_block *sb)
1769{
1770 int status = 0;
1771 int unlock_super = 0;
1772 struct ocfs2_super *osb = OCFS2_SB(sb);
1773
1774 mlog_entry_void();
1775
1776 if (ocfs2_is_hard_readonly(osb))
1777 goto leave;
1778
Mark Fashehccd979b2005-12-15 14:31:24 -08001779 status = ocfs2_dlm_init(osb);
1780 if (status < 0) {
1781 mlog_errno(status);
1782 goto leave;
1783 }
1784
Mark Fashehccd979b2005-12-15 14:31:24 -08001785 status = ocfs2_super_lock(osb, 1);
1786 if (status < 0) {
1787 mlog_errno(status);
1788 goto leave;
1789 }
1790 unlock_super = 1;
1791
1792 /* This will load up the node map and add ourselves to it. */
1793 status = ocfs2_find_slot(osb);
1794 if (status < 0) {
1795 mlog_errno(status);
1796 goto leave;
1797 }
1798
Mark Fashehccd979b2005-12-15 14:31:24 -08001799 /* load all node-local system inodes */
1800 status = ocfs2_init_local_system_inodes(osb);
1801 if (status < 0) {
1802 mlog_errno(status);
1803 goto leave;
1804 }
1805
1806 status = ocfs2_check_volume(osb);
1807 if (status < 0) {
1808 mlog_errno(status);
1809 goto leave;
1810 }
1811
1812 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001813 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001814 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001815
Mark Fashehccd979b2005-12-15 14:31:24 -08001816leave:
1817 if (unlock_super)
1818 ocfs2_super_unlock(osb, 1);
1819
1820 mlog_exit(status);
1821 return status;
1822}
1823
Mark Fashehccd979b2005-12-15 14:31:24 -08001824static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1825{
Joel Becker286eaa92008-02-01 15:03:57 -08001826 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001827 struct ocfs2_super *osb = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001828 char nodestr[8];
Mark Fashehccd979b2005-12-15 14:31:24 -08001829
1830 mlog_entry("(0x%p)\n", sb);
1831
1832 BUG_ON(!sb);
1833 osb = OCFS2_SB(sb);
1834 BUG_ON(!osb);
1835
Sunil Mushran50397502008-12-17 14:17:43 -08001836 debugfs_remove(osb->osb_ctxt);
1837
Jan Karaf7b1aa62009-07-20 12:12:36 +02001838 /*
1839 * Flush inode dropping work queue so that deletes are
1840 * performed while the filesystem is still working
1841 */
1842 ocfs2_drop_all_dl_inodes(osb);
1843
Sunil Mushran692684e2009-06-19 16:53:17 -07001844 /* Orphan scan should be stopped as early as possible */
1845 ocfs2_orphan_scan_stop(osb);
1846
Jan Kara19ece542008-08-21 20:13:17 +02001847 ocfs2_disable_quotas(osb);
1848
Mark Fashehccd979b2005-12-15 14:31:24 -08001849 ocfs2_shutdown_local_alloc(osb);
1850
1851 ocfs2_truncate_log_shutdown(osb);
1852
Joel Becker553abd02008-02-01 12:03:57 -08001853 /* This will disable recovery and flush any recovery work. */
1854 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001855
1856 ocfs2_journal_shutdown(osb);
1857
1858 ocfs2_sync_blockdev(sb);
1859
Tao Ma374a2632009-08-24 11:13:37 +08001860 ocfs2_purge_refcount_trees(osb);
1861
Joel Becker4670c462008-02-01 14:39:35 -08001862 /* No cluster connection means we've failed during mount, so skip
1863 * all the steps which depended on that to complete. */
1864 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001865 tmp = ocfs2_super_lock(osb, 1);
1866 if (tmp < 0) {
1867 mlog_errno(tmp);
1868 return;
1869 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001870 }
1871
Mark Fasheh19b613d2007-10-04 14:47:09 -07001872 if (osb->slot_num != OCFS2_INVALID_SLOT)
1873 ocfs2_put_slot(osb);
1874
Joel Becker4670c462008-02-01 14:39:35 -08001875 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001876 ocfs2_super_unlock(osb, 1);
1877
Mark Fashehccd979b2005-12-15 14:31:24 -08001878 ocfs2_release_system_inodes(osb);
1879
Joel Becker6953b4c2008-01-29 16:59:56 -08001880 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001881 * If we're dismounting due to mount error, mount.ocfs2 will clean
1882 * up heartbeat. If we're a local mount, there is no heartbeat.
1883 * If we failed before we got a uuid_str yet, we can't stop
1884 * heartbeat. Otherwise, do it.
1885 */
1886 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
Joel Becker286eaa92008-02-01 15:03:57 -08001887 hangup_needed = 1;
1888
1889 if (osb->cconn)
1890 ocfs2_dlm_shutdown(osb, hangup_needed);
1891
Joel Becker73be1922009-01-06 14:57:08 -08001892 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Joel Becker286eaa92008-02-01 15:03:57 -08001893 debugfs_remove(osb->osb_debug_root);
1894
1895 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001896 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001897
1898 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1899
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001900 if (ocfs2_mount_local(osb))
1901 snprintf(nodestr, sizeof(nodestr), "local");
1902 else
Joel Becker19fdb622008-01-30 15:38:24 -08001903 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001904
1905 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1906 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001907
1908 ocfs2_delete_osb(osb);
1909 kfree(osb);
1910 sb->s_dev = 0;
1911 sb->s_fs_info = NULL;
1912}
1913
1914static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1915 unsigned uuid_bytes)
1916{
1917 int i, ret;
1918 char *ptr;
1919
1920 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1921
Robert P. J. Daycd861282006-12-13 00:34:52 -08001922 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001923 if (osb->uuid_str == NULL)
1924 return -ENOMEM;
1925
Mark Fashehccd979b2005-12-15 14:31:24 -08001926 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1927 /* print with null */
1928 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1929 if (ret != 2) /* drop super cleans up */
1930 return -EINVAL;
1931 /* then only advance past the last char */
1932 ptr += 2;
1933 }
1934
1935 return 0;
1936}
1937
1938static int ocfs2_initialize_super(struct super_block *sb,
1939 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08001940 int sector_size,
1941 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08001942{
Denis Chengbddb8eb32007-09-27 02:10:04 +08001943 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07001944 int i, cbits, bbits;
1945 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08001946 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001947 struct ocfs2_journal *journal;
1948 __le32 uuid_net_key;
1949 struct ocfs2_super *osb;
1950
1951 mlog_entry_void();
1952
Robert P. J. Daycd861282006-12-13 00:34:52 -08001953 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001954 if (!osb) {
1955 status = -ENOMEM;
1956 mlog_errno(status);
1957 goto bail;
1958 }
1959
1960 sb->s_fs_info = osb;
1961 sb->s_op = &ocfs2_sops;
1962 sb->s_export_op = &ocfs2_export_ops;
Jan Kara19ece542008-08-21 20:13:17 +02001963 sb->s_qcop = &ocfs2_quotactl_ops;
1964 sb->dq_op = &ocfs2_quota_operations;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001965 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07001966 sb->s_time_gran = 1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001967 sb->s_flags |= MS_NOATIME;
1968 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07001969 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1970 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1971 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001972
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001973 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
1974
1975 for (i = 0; i < 3; i++)
1976 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
1977 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1978
Mark Fashehccd979b2005-12-15 14:31:24 -08001979 osb->sb = sb;
1980 /* Save off for ocfs2_rw_direct */
1981 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01001982 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001983
Mark Fasheh34d024f2007-09-24 15:56:19 -07001984 spin_lock_init(&osb->dc_task_lock);
1985 init_waitqueue_head(&osb->dc_event);
1986 osb->dc_work_sequence = 0;
1987 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001988 INIT_LIST_HEAD(&osb->blocked_lock_list);
1989 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001990 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08001991 spin_lock_init(&osb->osb_xattr_lock);
Tao Ma4d0ddb22008-03-05 16:11:46 +08001992 ocfs2_init_inode_steal_slot(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001993
1994 atomic_set(&osb->alloc_stats.moves, 0);
1995 atomic_set(&osb->alloc_stats.local_data, 0);
1996 atomic_set(&osb->alloc_stats.bitmap_data, 0);
1997 atomic_set(&osb->alloc_stats.bg_allocs, 0);
1998 atomic_set(&osb->alloc_stats.bg_extends, 0);
1999
Joel Becker73be1922009-01-06 14:57:08 -08002000 /* Copy the blockcheck stats from the superblock probe */
2001 osb->osb_ecc_stats = *stats;
2002
Mark Fashehccd979b2005-12-15 14:31:24 -08002003 ocfs2_init_node_maps(osb);
2004
2005 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2006 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2007
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04002008 ocfs2_orphan_scan_init(osb);
2009
Joel Becker553abd02008-02-01 12:03:57 -08002010 status = ocfs2_recovery_init(osb);
2011 if (status) {
2012 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2013 mlog_errno(status);
2014 goto bail;
2015 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002016
2017 init_waitqueue_head(&osb->checkpoint_event);
2018 atomic_set(&osb->needs_checkpoint, 0);
2019
Tiger Yang7f1a37e2006-11-15 15:48:42 +08002020 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2021
Mark Fashehccd979b2005-12-15 14:31:24 -08002022 osb->slot_num = OCFS2_INVALID_SLOT;
2023
Tiger Yang8154da32008-08-18 17:11:46 +08002024 osb->s_xattr_inline_size = le16_to_cpu(
2025 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002026
Mark Fashehccd979b2005-12-15 14:31:24 -08002027 osb->local_alloc_state = OCFS2_LA_UNUSED;
2028 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002029 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002030
Mark Fashehccd979b2005-12-15 14:31:24 -08002031 init_waitqueue_head(&osb->osb_mount_event);
2032
2033 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2034 if (!osb->vol_label) {
2035 mlog(ML_ERROR, "unable to alloc vol label\n");
2036 status = -ENOMEM;
2037 goto bail;
2038 }
2039
Mark Fashehccd979b2005-12-15 14:31:24 -08002040 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2041 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2042 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2043 osb->max_slots);
2044 status = -EINVAL;
2045 goto bail;
2046 }
Sunil Mushran781ee3e2006-04-27 16:41:31 -07002047 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
Mark Fashehccd979b2005-12-15 14:31:24 -08002048
Sunil Mushran539d8262008-07-14 17:31:10 -07002049 osb->slot_recovery_generations =
2050 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2051 GFP_KERNEL);
2052 if (!osb->slot_recovery_generations) {
2053 status = -ENOMEM;
2054 mlog_errno(status);
2055 goto bail;
2056 }
2057
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002058 init_waitqueue_head(&osb->osb_wipe_event);
2059 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2060 sizeof(*osb->osb_orphan_wipes),
2061 GFP_KERNEL);
2062 if (!osb->osb_orphan_wipes) {
2063 status = -ENOMEM;
2064 mlog_errno(status);
2065 goto bail;
2066 }
2067
Tao Ma374a2632009-08-24 11:13:37 +08002068 osb->osb_rf_lock_tree = RB_ROOT;
2069
Mark Fashehccd979b2005-12-15 14:31:24 -08002070 osb->s_feature_compat =
2071 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2072 osb->s_feature_ro_compat =
2073 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2074 osb->s_feature_incompat =
2075 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2076
2077 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2078 mlog(ML_ERROR, "couldn't mount because of unsupported "
2079 "optional features (%x).\n", i);
2080 status = -EINVAL;
2081 goto bail;
2082 }
2083 if (!(osb->sb->s_flags & MS_RDONLY) &&
2084 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2085 mlog(ML_ERROR, "couldn't mount RDWR because of "
2086 "unsupported optional features (%x).\n", i);
2087 status = -EINVAL;
2088 goto bail;
2089 }
2090
Joel Beckerb61817e2008-02-01 15:08:23 -08002091 if (ocfs2_userspace_stack(osb)) {
2092 memcpy(osb->osb_cluster_stack,
2093 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2094 OCFS2_STACK_LABEL_LEN);
2095 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2096 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2097 mlog(ML_ERROR,
2098 "couldn't mount because of an invalid "
2099 "cluster stack label (%s) \n",
2100 osb->osb_cluster_stack);
2101 status = -EINVAL;
2102 goto bail;
2103 }
2104 } else {
2105 /* The empty string is identical with classic tools that
2106 * don't know about s_cluster_info. */
2107 osb->osb_cluster_stack[0] = '\0';
2108 }
2109
Mark Fashehccd979b2005-12-15 14:31:24 -08002110 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2111
2112 /* FIXME
2113 * This should be done in ocfs2_journal_init(), but unknown
2114 * ordering issues will cause the filesystem to crash.
2115 * If anyone wants to figure out what part of the code
2116 * refers to osb->journal before ocfs2_journal_init() is run,
2117 * be my guest.
2118 */
2119 /* initialize our journal structure */
2120
Robert P. J. Daycd861282006-12-13 00:34:52 -08002121 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002122 if (!journal) {
2123 mlog(ML_ERROR, "unable to alloc journal\n");
2124 status = -ENOMEM;
2125 goto bail;
2126 }
2127 osb->journal = journal;
2128 journal->j_osb = osb;
2129
2130 atomic_set(&journal->j_num_trans, 0);
2131 init_rwsem(&journal->j_trans_barrier);
2132 init_waitqueue_head(&journal->j_checkpointed);
2133 spin_lock_init(&journal->j_lock);
2134 journal->j_trans_id = (unsigned long) 1;
2135 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002136 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002137 journal->j_state = OCFS2_JOURNAL_FREE;
2138
Jan Karaea455f82009-01-12 23:20:31 +01002139 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2140 osb->dentry_lock_list = NULL;
2141
Mark Fashehccd979b2005-12-15 14:31:24 -08002142 /* get some pseudo constants for clustersize bits */
2143 osb->s_clustersize_bits =
2144 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2145 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2146 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2147
2148 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2149 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2150 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2151 osb->s_clustersize);
2152 status = -EINVAL;
2153 goto bail;
2154 }
2155
2156 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2157 > (u32)~0UL) {
2158 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2159 "what jbd can address in 32 bits.\n");
2160 status = -EINVAL;
2161 goto bail;
2162 }
2163
2164 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2165 sizeof(di->id2.i_super.s_uuid))) {
2166 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2167 status = -ENOMEM;
2168 goto bail;
2169 }
2170
Mark Fasheh78427042006-05-04 12:03:26 -07002171 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
Mark Fashehccd979b2005-12-15 14:31:24 -08002172
2173 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2174 osb->vol_label[63] = '\0';
2175 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2176 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2177 osb->first_cluster_group_blkno =
2178 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2179 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002180 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Mark Fashehccd979b2005-12-15 14:31:24 -08002181 mlog(0, "vol_label: %s\n", osb->vol_label);
2182 mlog(0, "uuid: %s\n", osb->uuid_str);
Mark Fashehb0697052006-03-03 10:24:33 -08002183 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2184 (unsigned long long)osb->root_blkno,
2185 (unsigned long long)osb->system_dir_blkno);
Mark Fashehccd979b2005-12-15 14:31:24 -08002186
2187 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2188 if (!osb->osb_dlm_debug) {
2189 status = -ENOMEM;
2190 mlog_errno(status);
2191 goto bail;
2192 }
2193
2194 atomic_set(&osb->vol_state, VOLUME_INIT);
2195
2196 /* load root, system_dir, and all global system inodes */
2197 status = ocfs2_init_global_system_inodes(osb);
2198 if (status < 0) {
2199 mlog_errno(status);
2200 goto bail;
2201 }
2202
2203 /*
2204 * global bitmap
2205 */
2206 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2207 OCFS2_INVALID_SLOT);
2208 if (!inode) {
2209 status = -EINVAL;
2210 mlog_errno(status);
2211 goto bail;
2212 }
2213
2214 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fashehccd979b2005-12-15 14:31:24 -08002215 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002216
Tao Mae9d578a2007-12-18 15:46:10 +08002217 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002218
2219 status = ocfs2_init_slot_info(osb);
2220 if (status < 0) {
2221 mlog_errno(status);
2222 goto bail;
2223 }
2224
Mark Fashehccd979b2005-12-15 14:31:24 -08002225bail:
2226 mlog_exit(status);
2227 return status;
2228}
2229
2230/*
2231 * will return: -EAGAIN if it is ok to keep searching for superblocks
2232 * -EINVAL if there is a bad superblock
2233 * 0 on success
2234 */
2235static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2236 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002237 u32 blksz,
2238 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002239{
2240 int status = -EAGAIN;
2241
2242 mlog_entry_void();
2243
2244 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2245 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002246 /* We have to do a raw check of the feature here */
2247 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2248 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2249 status = ocfs2_block_check_validate(bh->b_data,
2250 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002251 &di->i_check,
2252 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002253 if (status)
2254 goto out;
2255 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002256 status = -EINVAL;
2257 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2258 mlog(ML_ERROR, "found superblock with incorrect block "
2259 "size: found %u, should be %u\n",
2260 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2261 blksz);
2262 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2263 OCFS2_MAJOR_REV_LEVEL ||
2264 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2265 OCFS2_MINOR_REV_LEVEL) {
2266 mlog(ML_ERROR, "found superblock with bad version: "
2267 "found %u.%u, should be %u.%u\n",
2268 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2269 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2270 OCFS2_MAJOR_REV_LEVEL,
2271 OCFS2_MINOR_REV_LEVEL);
2272 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2273 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb0697052006-03-03 10:24:33 -08002274 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002275 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb0697052006-03-03 10:24:33 -08002276 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002277 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2278 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2279 mlog(ML_ERROR, "bad cluster size found: %u\n",
2280 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2281 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2282 mlog(ML_ERROR, "bad root_blkno: 0\n");
2283 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2284 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2285 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2286 mlog(ML_ERROR,
2287 "Superblock slots found greater than file system "
2288 "maximum: found %u, max %u\n",
2289 le16_to_cpu(di->id2.i_super.s_max_slots),
2290 OCFS2_MAX_SLOTS);
2291 } else {
2292 /* found it! */
2293 status = 0;
2294 }
2295 }
2296
Joel Beckerd030cc92008-12-11 15:04:14 -08002297out:
Mark Fashehccd979b2005-12-15 14:31:24 -08002298 mlog_exit(status);
2299 return status;
2300}
2301
2302static int ocfs2_check_volume(struct ocfs2_super *osb)
2303{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002304 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002305 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002306 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002307 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2308 * recover
2309 * ourselves. */
2310
2311 mlog_entry_void();
2312
2313 /* Init our journal object. */
2314 status = ocfs2_journal_init(osb->journal, &dirty);
2315 if (status < 0) {
2316 mlog(ML_ERROR, "Could not initialize journal!\n");
2317 goto finally;
2318 }
2319
2320 /* If the journal was unmounted cleanly then we don't want to
2321 * recover anything. Otherwise, journal_load will do that
2322 * dirty work for us :) */
2323 if (!dirty) {
2324 status = ocfs2_journal_wipe(osb->journal, 0);
2325 if (status < 0) {
2326 mlog_errno(status);
2327 goto finally;
2328 }
2329 } else {
2330 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2331 "recovering volume.\n");
2332 }
2333
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002334 local = ocfs2_mount_local(osb);
2335
Mark Fashehccd979b2005-12-15 14:31:24 -08002336 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002337 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002338 if (status < 0) {
2339 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2340 goto finally;
2341 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002342
2343 if (dirty) {
2344 /* recover my local alloc if we didn't unmount cleanly. */
2345 status = ocfs2_begin_local_alloc_recovery(osb,
2346 osb->slot_num,
2347 &local_alloc);
2348 if (status < 0) {
2349 mlog_errno(status);
2350 goto finally;
2351 }
2352 /* we complete the recovery process after we've marked
2353 * ourselves as mounted. */
2354 }
2355
2356 mlog(0, "Journal loaded.\n");
2357
2358 status = ocfs2_load_local_alloc(osb);
2359 if (status < 0) {
2360 mlog_errno(status);
2361 goto finally;
2362 }
2363
2364 if (dirty) {
2365 /* Recovery will be completed after we've mounted the
2366 * rest of the volume. */
2367 osb->dirty = 1;
2368 osb->local_alloc_copy = local_alloc;
2369 local_alloc = NULL;
2370 }
2371
2372 /* go through each journal, trylock it and if you get the
2373 * lock, and it's marked as dirty, set the bit in the recover
2374 * map and launch a recovery thread for it. */
2375 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002376 if (status < 0) {
2377 mlog_errno(status);
2378 goto finally;
2379 }
2380
2381 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002382 if (status < 0)
2383 mlog_errno(status);
2384
2385finally:
2386 if (local_alloc)
2387 kfree(local_alloc);
2388
2389 mlog_exit(status);
2390 return status;
2391}
2392
2393/*
2394 * The routine gets called from dismount or close whenever a dismount on
2395 * volume is requested and the osb open count becomes 1.
2396 * It will remove the osb from the global list and also free up all the
2397 * initialized resources and fileobject.
2398 */
2399static void ocfs2_delete_osb(struct ocfs2_super *osb)
2400{
2401 mlog_entry_void();
2402
2403 /* This function assumes that the caller has the main osb resource */
2404
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002405 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002406
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002407 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002408 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002409 /* FIXME
2410 * This belongs in journal shutdown, but because we have to
2411 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2412 * we free it here.
2413 */
2414 kfree(osb->journal);
2415 if (osb->local_alloc_copy)
2416 kfree(osb->local_alloc_copy);
2417 kfree(osb->uuid_str);
2418 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2419 memset(osb, 0, sizeof(struct ocfs2_super));
2420
2421 mlog_exit_void();
2422}
2423
2424/* Put OCFS2 into a readonly state, or (if the user specifies it),
2425 * panic(). We do not support continue-on-error operation. */
2426static void ocfs2_handle_error(struct super_block *sb)
2427{
2428 struct ocfs2_super *osb = OCFS2_SB(sb);
2429
2430 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2431 panic("OCFS2: (device %s): panic forced after error\n",
2432 sb->s_id);
2433
2434 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2435
2436 if (sb->s_flags & MS_RDONLY &&
2437 (ocfs2_is_soft_readonly(osb) ||
2438 ocfs2_is_hard_readonly(osb)))
2439 return;
2440
2441 printk(KERN_CRIT "File system is now read-only due to the potential "
2442 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2443 "system is unmounted.\n");
2444 sb->s_flags |= MS_RDONLY;
2445 ocfs2_set_ro_flag(osb, 0);
2446}
2447
2448static char error_buf[1024];
2449
2450void __ocfs2_error(struct super_block *sb,
2451 const char *function,
2452 const char *fmt, ...)
2453{
2454 va_list args;
2455
2456 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002457 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002458 va_end(args);
2459
2460 /* Not using mlog here because we want to show the actual
2461 * function the error came from. */
2462 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2463 sb->s_id, function, error_buf);
2464
2465 ocfs2_handle_error(sb);
2466}
2467
2468/* Handle critical errors. This is intentionally more drastic than
2469 * ocfs2_handle_error, so we only use for things like journal errors,
2470 * etc. */
2471void __ocfs2_abort(struct super_block* sb,
2472 const char *function,
2473 const char *fmt, ...)
2474{
2475 va_list args;
2476
2477 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002478 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002479 va_end(args);
2480
2481 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2482 sb->s_id, function, error_buf);
2483
2484 /* We don't have the cluster support yet to go straight to
2485 * hard readonly in here. Until then, we want to keep
2486 * ocfs2_abort() so that we can at least mark critical
2487 * errors.
2488 *
2489 * TODO: This should abort the journal and alert other nodes
2490 * that our slot needs recovery. */
2491
2492 /* Force a panic(). This stinks, but it's better than letting
2493 * things continue without having a proper hard readonly
2494 * here. */
Sunil Mushrana2f2ddb2009-08-19 15:16:01 -07002495 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2496 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08002497 ocfs2_handle_error(sb);
2498}
2499
2500module_init(ocfs2_init);
2501module_exit(ocfs2_exit);