blob: 45d654cb77ef6af159edac36338c12e8cfdc4283 [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);
Jan Kara57b09bb2009-10-15 14:54:05 +0200705
706 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
707 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
708 MS_POSIXACL : 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800709 }
710out:
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200711 unlock_kernel();
Mark Fashehccd979b2005-12-15 14:31:24 -0800712 return ret;
713}
714
715static int ocfs2_sb_probe(struct super_block *sb,
716 struct buffer_head **bh,
Joel Becker73be1922009-01-06 14:57:08 -0800717 int *sector_size,
718 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -0800719{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800720 int status, tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800721 struct ocfs1_vol_disk_hdr *hdr;
722 struct ocfs2_dinode *di;
723 int blksize;
724
725 *bh = NULL;
726
727 /* may be > 512 */
Martin K. Petersene1defc42009-05-22 17:17:49 -0400728 *sector_size = bdev_logical_block_size(sb->s_bdev);
Mark Fashehccd979b2005-12-15 14:31:24 -0800729 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
730 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
731 *sector_size, OCFS2_MAX_BLOCKSIZE);
732 status = -EINVAL;
733 goto bail;
734 }
735
736 /* Can this really happen? */
737 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
738 *sector_size = OCFS2_MIN_BLOCKSIZE;
739
740 /* check block zero for old format */
741 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
742 if (status < 0) {
743 mlog_errno(status);
744 goto bail;
745 }
746 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
747 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
748 mlog(ML_ERROR, "incompatible version: %u.%u\n",
749 hdr->major_version, hdr->minor_version);
750 status = -EINVAL;
751 }
752 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
753 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
754 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
755 hdr->signature);
756 status = -EINVAL;
757 }
758 brelse(*bh);
759 *bh = NULL;
760 if (status < 0) {
761 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
762 "upgraded before mounting with ocfs v2\n");
763 goto bail;
764 }
765
766 /*
767 * Now check at magic offset for 512, 1024, 2048, 4096
768 * blocksizes. 4096 is the maximum blocksize because it is
769 * the minimum clustersize.
770 */
771 status = -EINVAL;
772 for (blksize = *sector_size;
773 blksize <= OCFS2_MAX_BLOCKSIZE;
774 blksize <<= 1) {
775 tmpstat = ocfs2_get_sector(sb, bh,
776 OCFS2_SUPER_BLOCK_BLKNO,
777 blksize);
778 if (tmpstat < 0) {
779 status = tmpstat;
780 mlog_errno(status);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700781 break;
Mark Fashehccd979b2005-12-15 14:31:24 -0800782 }
783 di = (struct ocfs2_dinode *) (*bh)->b_data;
Joel Becker73be1922009-01-06 14:57:08 -0800784 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
Jan Kara1c1d9792009-07-22 13:17:19 +0200785 spin_lock_init(&stats->b_lock);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700786 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
787 if (tmpstat < 0) {
788 brelse(*bh);
789 *bh = NULL;
790 }
791 if (tmpstat != -EAGAIN) {
792 status = tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800793 break;
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700794 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800795 }
796
797bail:
798 return status;
799}
800
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800801static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
802{
803 if (ocfs2_mount_local(osb)) {
804 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
805 mlog(ML_ERROR, "Cannot heartbeat on a locally "
806 "mounted device.\n");
807 return -EINVAL;
808 }
809 }
810
Joel Beckerb61817e2008-02-01 15:08:23 -0800811 if (ocfs2_userspace_stack(osb)) {
812 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
813 mlog(ML_ERROR, "Userspace stack expected, but "
814 "o2cb heartbeat arguments passed to mount\n");
815 return -EINVAL;
816 }
817 }
818
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800819 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800820 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
821 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800822 mlog(ML_ERROR, "Heartbeat has to be started to mount "
823 "a read-write clustered device.\n");
824 return -EINVAL;
825 }
826 }
827
828 return 0;
829}
830
Joel Beckerb61817e2008-02-01 15:08:23 -0800831/*
832 * If we're using a userspace stack, mount should have passed
833 * a name that matches the disk. If not, mount should not
834 * have passed a stack.
835 */
836static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
837 struct mount_options *mopt)
838{
839 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
840 mlog(ML_ERROR,
841 "cluster stack passed to mount, but this filesystem "
842 "does not support it\n");
843 return -EINVAL;
844 }
845
846 if (ocfs2_userspace_stack(osb) &&
847 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
848 OCFS2_STACK_LABEL_LEN)) {
849 mlog(ML_ERROR,
850 "cluster stack passed to mount (\"%s\") does not "
851 "match the filesystem (\"%s\")\n",
852 mopt->cluster_stack,
853 osb->osb_cluster_stack);
854 return -EINVAL;
855 }
856
857 return 0;
858}
859
Jan Kara19ece542008-08-21 20:13:17 +0200860static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
861{
862 int type;
863 struct super_block *sb = osb->sb;
864 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
865 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
866 int status = 0;
867
868 for (type = 0; type < MAXQUOTAS; type++) {
869 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
870 continue;
871 if (unsuspend)
872 status = vfs_quota_enable(
873 sb_dqopt(sb)->files[type],
874 type, QFMT_OCFS2,
875 DQUOT_SUSPENDED);
876 else
877 status = vfs_quota_disable(sb, type,
878 DQUOT_SUSPENDED);
879 if (status < 0)
880 break;
881 }
882 if (status < 0)
883 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
884 "remount (error = %d).\n", status);
885 return status;
886}
887
888static int ocfs2_enable_quotas(struct ocfs2_super *osb)
889{
890 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
891 struct super_block *sb = osb->sb;
892 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
893 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
894 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
895 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
896 int status;
897 int type;
898
899 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
900 for (type = 0; type < MAXQUOTAS; type++) {
901 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
902 continue;
903 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
904 osb->slot_num);
905 if (!inode[type]) {
906 status = -ENOENT;
907 goto out_quota_off;
908 }
909 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
910 DQUOT_USAGE_ENABLED);
911 if (status < 0)
912 goto out_quota_off;
913 }
914
915 for (type = 0; type < MAXQUOTAS; type++)
916 iput(inode[type]);
917 return 0;
918out_quota_off:
919 ocfs2_disable_quotas(osb);
920 for (type = 0; type < MAXQUOTAS; type++)
921 iput(inode[type]);
922 mlog_errno(status);
923 return status;
924}
925
926static void ocfs2_disable_quotas(struct ocfs2_super *osb)
927{
928 int type;
929 struct inode *inode;
930 struct super_block *sb = osb->sb;
931
932 /* We mostly ignore errors in this function because there's not much
933 * we can do when we see them */
934 for (type = 0; type < MAXQUOTAS; type++) {
935 if (!sb_has_quota_loaded(sb, type))
936 continue;
937 inode = igrab(sb->s_dquot.files[type]);
938 /* Turn off quotas. This will remove all dquot structures from
939 * memory and so they will be automatically synced to global
940 * quota files */
941 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
942 DQUOT_LIMITS_ENABLED);
943 if (!inode)
944 continue;
945 iput(inode);
946 }
947}
948
949/* Handle quota on quotactl */
950static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
951 char *path, int remount)
952{
953 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
954 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
955
956 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
957 return -EINVAL;
958
959 if (remount)
960 return 0; /* Just ignore it has been handled in
961 * ocfs2_remount() */
962 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
963 format_id, DQUOT_LIMITS_ENABLED);
964}
965
966/* Handle quota off quotactl */
967static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
968{
969 if (remount)
970 return 0; /* Ignore now and handle later in
971 * ocfs2_remount() */
972 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
973}
974
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700975static const struct quotactl_ops ocfs2_quotactl_ops = {
Jan Kara19ece542008-08-21 20:13:17 +0200976 .quota_on = ocfs2_quota_on,
977 .quota_off = ocfs2_quota_off,
978 .quota_sync = vfs_quota_sync,
979 .get_info = vfs_get_dqinfo,
980 .set_info = vfs_set_dqinfo,
981 .get_dqblk = vfs_get_dqblk,
982 .set_dqblk = vfs_set_dqblk,
983};
984
Mark Fashehccd979b2005-12-15 14:31:24 -0800985static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
986{
987 struct dentry *root;
988 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800989 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800990 struct inode *inode = NULL;
991 struct ocfs2_super *osb = NULL;
992 struct buffer_head *bh = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800993 char nodestr[8];
Joel Becker73be1922009-01-06 14:57:08 -0800994 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -0800995
996 mlog_entry("%p, %p, %i", sb, data, silent);
997
Tiger Yangc0123ad2007-09-08 00:16:10 +0800998 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800999 status = -EINVAL;
1000 goto read_super_error;
1001 }
1002
1003 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -08001004 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001005 if (status < 0) {
1006 mlog(ML_ERROR, "superblock probe failed!\n");
1007 goto read_super_error;
1008 }
1009
Joel Becker73be1922009-01-06 14:57:08 -08001010 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001011 osb = OCFS2_SB(sb);
1012 if (status < 0) {
1013 mlog_errno(status);
1014 goto read_super_error;
1015 }
1016 brelse(bh);
1017 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001018
Jan Kara5297aad2009-10-15 14:54:04 +02001019 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1020 status = -EINVAL;
1021 goto read_super_error;
1022 }
Tiger Yangc0123ad2007-09-08 00:16:10 +08001023 osb->s_mount_opt = parsed_options.mount_opt;
1024 osb->s_atime_quantum = parsed_options.atime_quantum;
1025 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001026 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh9c7af402008-07-28 18:02:53 -07001027 osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
1028 osb->local_alloc_bits = osb->local_alloc_default_bits;
Mark Fashehccd979b2005-12-15 14:31:24 -08001029
Joel Beckerb61817e2008-02-01 15:08:23 -08001030 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1031 if (status)
1032 goto read_super_error;
1033
Mark Fashehccd979b2005-12-15 14:31:24 -08001034 sb->s_magic = OCFS2_SUPER_MAGIC;
1035
Tiger Yanga68979b2008-11-14 11:17:52 +08001036 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1037 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1038
Mark Fashehccd979b2005-12-15 14:31:24 -08001039 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1040 * heartbeat=none */
1041 if (bdev_read_only(sb->s_bdev)) {
1042 if (!(sb->s_flags & MS_RDONLY)) {
1043 status = -EACCES;
1044 mlog(ML_ERROR, "Readonly device detected but readonly "
1045 "mount was not specified.\n");
1046 goto read_super_error;
1047 }
1048
1049 /* You should not be able to start a local heartbeat
1050 * on a readonly device. */
1051 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1052 status = -EROFS;
1053 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1054 "device.\n");
1055 goto read_super_error;
1056 }
1057
1058 status = ocfs2_check_journals_nolocks(osb);
1059 if (status < 0) {
1060 if (status == -EROFS)
1061 mlog(ML_ERROR, "Recovery required on readonly "
1062 "file system, but write access is "
1063 "unavailable.\n");
1064 else
1065 mlog_errno(status);
1066 goto read_super_error;
1067 }
1068
1069 ocfs2_set_ro_flag(osb, 1);
1070
1071 printk(KERN_NOTICE "Readonly device detected. No cluster "
1072 "services will be utilized for this mount. Recovery "
1073 "will be skipped.\n");
1074 }
1075
1076 if (!ocfs2_is_hard_readonly(osb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001077 if (sb->s_flags & MS_RDONLY)
1078 ocfs2_set_ro_flag(osb, 0);
1079 }
1080
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001081 status = ocfs2_verify_heartbeat(osb);
1082 if (status < 0) {
1083 mlog_errno(status);
1084 goto read_super_error;
1085 }
1086
Mark Fashehccd979b2005-12-15 14:31:24 -08001087 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1088 ocfs2_debugfs_root);
1089 if (!osb->osb_debug_root) {
1090 status = -EINVAL;
1091 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1092 goto read_super_error;
1093 }
1094
Sunil Mushran50397502008-12-17 14:17:43 -08001095 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1096 osb->osb_debug_root,
1097 osb,
1098 &ocfs2_osb_debug_fops);
1099 if (!osb->osb_ctxt) {
1100 status = -EINVAL;
1101 mlog_errno(status);
1102 goto read_super_error;
1103 }
1104
Joel Becker73be1922009-01-06 14:57:08 -08001105 if (ocfs2_meta_ecc(osb)) {
1106 status = ocfs2_blockcheck_stats_debugfs_install(
1107 &osb->osb_ecc_stats,
1108 osb->osb_debug_root);
1109 if (status) {
1110 mlog(ML_ERROR,
1111 "Unable to create blockcheck statistics "
1112 "files\n");
1113 goto read_super_error;
1114 }
1115 }
1116
Mark Fashehccd979b2005-12-15 14:31:24 -08001117 status = ocfs2_mount_volume(sb);
1118 if (osb->root_inode)
1119 inode = igrab(osb->root_inode);
1120
1121 if (status < 0)
1122 goto read_super_error;
1123
1124 if (!inode) {
1125 status = -EIO;
1126 mlog_errno(status);
1127 goto read_super_error;
1128 }
1129
1130 root = d_alloc_root(inode);
1131 if (!root) {
1132 status = -ENOMEM;
1133 mlog_errno(status);
1134 goto read_super_error;
1135 }
1136
1137 sb->s_root = root;
1138
1139 ocfs2_complete_mount_recovery(osb);
1140
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001141 if (ocfs2_mount_local(osb))
1142 snprintf(nodestr, sizeof(nodestr), "local");
1143 else
Joel Becker19fdb622008-01-30 15:38:24 -08001144 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001145
1146 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001147 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001148 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001149 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1150 "ordered");
1151
1152 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1153 wake_up(&osb->osb_mount_event);
1154
Jan Kara19ece542008-08-21 20:13:17 +02001155 /* Now we can initialize quotas because we can afford to wait
1156 * for cluster locks recovery now. That also means that truncation
1157 * log recovery can happen but that waits for proper quota setup */
1158 if (!(sb->s_flags & MS_RDONLY)) {
1159 status = ocfs2_enable_quotas(osb);
1160 if (status < 0) {
1161 /* We have to err-out specially here because
1162 * s_root is already set */
1163 mlog_errno(status);
1164 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1165 wake_up(&osb->osb_mount_event);
1166 mlog_exit(status);
1167 return status;
1168 }
1169 }
1170
1171 ocfs2_complete_quota_recovery(osb);
1172
1173 /* Now we wake up again for processes waiting for quotas */
1174 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1175 wake_up(&osb->osb_mount_event);
1176
Sunil Mushrandf152c22009-06-22 11:40:07 -07001177 /* Start this when the mount is almost sure of being successful */
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04001178 ocfs2_orphan_scan_start(osb);
Sunil Mushrandf152c22009-06-22 11:40:07 -07001179
Mark Fashehccd979b2005-12-15 14:31:24 -08001180 mlog_exit(status);
1181 return status;
1182
1183read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001184 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001185
1186 if (inode)
1187 iput(inode);
1188
1189 if (osb) {
1190 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1191 wake_up(&osb->osb_mount_event);
1192 ocfs2_dismount_volume(sb, 1);
1193 }
1194
1195 mlog_exit(status);
1196 return status;
1197}
1198
David Howells454e2392006-06-23 02:02:57 -07001199static int ocfs2_get_sb(struct file_system_type *fs_type,
1200 int flags,
1201 const char *dev_name,
1202 void *data,
1203 struct vfsmount *mnt)
Mark Fashehccd979b2005-12-15 14:31:24 -08001204{
David Howells454e2392006-06-23 02:02:57 -07001205 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1206 mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -08001207}
1208
Jan Karaf7b1aa692009-07-20 12:12:36 +02001209static void ocfs2_kill_sb(struct super_block *sb)
1210{
1211 struct ocfs2_super *osb = OCFS2_SB(sb);
1212
Jan Kara5fd13182009-07-30 17:01:53 +02001213 /* Failed mount? */
1214 if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1215 goto out;
1216
Jan Karaf7b1aa692009-07-20 12:12:36 +02001217 /* Prevent further queueing of inode drop events */
1218 spin_lock(&dentry_list_lock);
1219 ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1220 spin_unlock(&dentry_list_lock);
1221 /* Wait for work to finish and/or remove it */
1222 cancel_work_sync(&osb->dentry_lock_work);
Jan Kara5fd13182009-07-30 17:01:53 +02001223out:
Jan Karaf7b1aa692009-07-20 12:12:36 +02001224 kill_block_super(sb);
1225}
1226
Mark Fashehccd979b2005-12-15 14:31:24 -08001227static struct file_system_type ocfs2_fs_type = {
1228 .owner = THIS_MODULE,
1229 .name = "ocfs2",
1230 .get_sb = ocfs2_get_sb, /* is this called when we mount
1231 * the fs? */
Jan Karaf7b1aa692009-07-20 12:12:36 +02001232 .kill_sb = ocfs2_kill_sb,
1233
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001234 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001235 .next = NULL
1236};
1237
Jan Kara5297aad2009-10-15 14:54:04 +02001238static int ocfs2_check_set_options(struct super_block *sb,
1239 struct mount_options *options)
1240{
1241 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1242 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1243 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1244 mlog(ML_ERROR, "User quotas were requested, but this "
1245 "filesystem does not have the feature enabled.\n");
1246 return 0;
1247 }
1248 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1249 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1250 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1251 mlog(ML_ERROR, "Group quotas were requested, but this "
1252 "filesystem does not have the feature enabled.\n");
1253 return 0;
1254 }
1255 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1256 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1257 mlog(ML_ERROR, "ACL support requested but extended attributes "
1258 "feature is not enabled\n");
1259 return 0;
1260 }
1261 /* No ACL setting specified? Use XATTR feature... */
1262 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1263 OCFS2_MOUNT_NO_POSIX_ACL))) {
1264 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1265 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1266 else
1267 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1268 }
1269 return 1;
1270}
1271
Mark Fashehccd979b2005-12-15 14:31:24 -08001272static int ocfs2_parse_options(struct super_block *sb,
1273 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001274 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001275 int is_remount)
1276{
1277 int status;
1278 char *p;
1279
1280 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1281 options ? options : "(none)");
1282
Mark Fashehd147b3d2007-11-07 14:40:36 -08001283 mopt->commit_interval = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001284 mopt->mount_opt = 0;
1285 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1286 mopt->slot = OCFS2_INVALID_SLOT;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001287 mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
Joel Beckerb61817e2008-02-01 15:08:23 -08001288 mopt->cluster_stack[0] = '\0';
Mark Fashehccd979b2005-12-15 14:31:24 -08001289
1290 if (!options) {
1291 status = 1;
1292 goto bail;
1293 }
1294
1295 while ((p = strsep(&options, ",")) != NULL) {
1296 int token, option;
1297 substring_t args[MAX_OPT_ARGS];
1298
1299 if (!*p)
1300 continue;
1301
1302 token = match_token(p, tokens, args);
1303 switch (token) {
1304 case Opt_hb_local:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001305 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001306 break;
1307 case Opt_hb_none:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001308 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001309 break;
1310 case Opt_barrier:
1311 if (match_int(&args[0], &option)) {
1312 status = 0;
1313 goto bail;
1314 }
1315 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001316 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001317 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001318 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001319 break;
1320 case Opt_intr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001321 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001322 break;
1323 case Opt_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001324 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001325 break;
1326 case Opt_err_panic:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001327 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001328 break;
1329 case Opt_err_ro:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001330 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001331 break;
1332 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001333 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001334 break;
1335 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001336 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001337 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001338 case Opt_user_xattr:
1339 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1340 break;
1341 case Opt_nouser_xattr:
1342 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1343 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001344 case Opt_atime_quantum:
1345 if (match_int(&args[0], &option)) {
1346 status = 0;
1347 goto bail;
1348 }
1349 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001350 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001351 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001352 case Opt_slot:
1353 option = 0;
1354 if (match_int(&args[0], &option)) {
1355 status = 0;
1356 goto bail;
1357 }
1358 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001359 mopt->slot = (s16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001360 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001361 case Opt_commit:
1362 option = 0;
1363 if (match_int(&args[0], &option)) {
1364 status = 0;
1365 goto bail;
1366 }
1367 if (option < 0)
1368 return 0;
1369 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001370 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001371 mopt->commit_interval = HZ * option;
1372 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001373 case Opt_localalloc:
1374 option = 0;
1375 if (match_int(&args[0], &option)) {
1376 status = 0;
1377 goto bail;
1378 }
1379 if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1380 mopt->localalloc_opt = option;
1381 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001382 case Opt_localflocks:
1383 /*
1384 * Changing this during remount could race
1385 * flock() requests, or "unbalance" existing
1386 * ones (e.g., a lock is taken in one mode but
1387 * dropped in the other). If users care enough
1388 * to flip locking modes during remount, we
1389 * could add a "local" flag to individual
1390 * flock structures for proper tracking of
1391 * state.
1392 */
1393 if (!is_remount)
1394 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1395 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001396 case Opt_stack:
1397 /* Check both that the option we were passed
1398 * is of the right length and that it is a proper
1399 * string of the right length.
1400 */
1401 if (((args[0].to - args[0].from) !=
1402 OCFS2_STACK_LABEL_LEN) ||
1403 (strnlen(args[0].from,
1404 OCFS2_STACK_LABEL_LEN) !=
1405 OCFS2_STACK_LABEL_LEN)) {
1406 mlog(ML_ERROR,
1407 "Invalid cluster_stack option\n");
1408 status = 0;
1409 goto bail;
1410 }
1411 memcpy(mopt->cluster_stack, args[0].from,
1412 OCFS2_STACK_LABEL_LEN);
1413 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1414 break;
Joel Becker12462f12008-09-03 20:03:40 -07001415 case Opt_inode64:
1416 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1417 break;
Jan Kara19ece542008-08-21 20:13:17 +02001418 case Opt_usrquota:
Jan Kara19ece542008-08-21 20:13:17 +02001419 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1420 break;
1421 case Opt_grpquota:
Jan Kara19ece542008-08-21 20:13:17 +02001422 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1423 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001424 case Opt_acl:
1425 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
Jan Kara5297aad2009-10-15 14:54:04 +02001426 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001427 break;
1428 case Opt_noacl:
Jan Kara5297aad2009-10-15 14:54:04 +02001429 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001430 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1431 break;
Mark Fashehccd979b2005-12-15 14:31:24 -08001432 default:
1433 mlog(ML_ERROR,
1434 "Unrecognized mount option \"%s\" "
1435 "or missing value\n", p);
1436 status = 0;
1437 goto bail;
1438 }
1439 }
1440
1441 status = 1;
1442
1443bail:
1444 mlog_exit(status);
1445 return status;
1446}
1447
Sunil Mushrand5500712007-09-06 13:34:16 -07001448static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1449{
1450 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1451 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001452 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001453
1454 if (opts & OCFS2_MOUNT_HB_LOCAL)
1455 seq_printf(s, ",_netdev,heartbeat=local");
1456 else
1457 seq_printf(s, ",heartbeat=none");
1458
1459 if (opts & OCFS2_MOUNT_NOINTR)
1460 seq_printf(s, ",nointr");
1461
1462 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1463 seq_printf(s, ",data=writeback");
1464 else
1465 seq_printf(s, ",data=ordered");
1466
1467 if (opts & OCFS2_MOUNT_BARRIER)
1468 seq_printf(s, ",barrier=1");
1469
1470 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1471 seq_printf(s, ",errors=panic");
1472 else
1473 seq_printf(s, ",errors=remount-ro");
1474
1475 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1476 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1477
1478 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1479 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1480
Mark Fashehd147b3d2007-11-07 14:40:36 -08001481 if (osb->osb_commit_interval)
1482 seq_printf(s, ",commit=%u",
1483 (unsigned) (osb->osb_commit_interval / HZ));
1484
Mark Fashehebcee4b2008-07-28 14:55:20 -07001485 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1486 if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1487 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001488
Mark Fasheh53fc6222007-12-20 16:49:04 -08001489 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1490 seq_printf(s, ",localflocks,");
1491
Joel Beckerb61817e2008-02-01 15:08:23 -08001492 if (osb->osb_cluster_stack[0])
1493 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1494 osb->osb_cluster_stack);
Jan Kara19ece542008-08-21 20:13:17 +02001495 if (opts & OCFS2_MOUNT_USRQUOTA)
1496 seq_printf(s, ",usrquota");
1497 if (opts & OCFS2_MOUNT_GRPQUOTA)
1498 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001499
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001500 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1501 seq_printf(s, ",nouser_xattr");
1502 else
1503 seq_printf(s, ",user_xattr");
1504
Joel Becker12462f12008-09-03 20:03:40 -07001505 if (opts & OCFS2_MOUNT_INODE64)
1506 seq_printf(s, ",inode64");
1507
Tiger Yanga68979b2008-11-14 11:17:52 +08001508 if (opts & OCFS2_MOUNT_POSIX_ACL)
1509 seq_printf(s, ",acl");
1510 else
1511 seq_printf(s, ",noacl");
Tiger Yanga68979b2008-11-14 11:17:52 +08001512
Sunil Mushrand5500712007-09-06 13:34:16 -07001513 return 0;
1514}
1515
Mark Fashehccd979b2005-12-15 14:31:24 -08001516static int __init ocfs2_init(void)
1517{
1518 int status;
1519
1520 mlog_entry_void();
1521
1522 ocfs2_print_version();
1523
Mark Fashehccd979b2005-12-15 14:31:24 -08001524 status = init_ocfs2_uptodate_cache();
1525 if (status < 0) {
1526 mlog_errno(status);
1527 goto leave;
1528 }
1529
1530 status = ocfs2_initialize_mem_caches();
1531 if (status < 0) {
1532 mlog_errno(status);
1533 goto leave;
1534 }
1535
1536 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1537 if (!ocfs2_wq) {
1538 status = -ENOMEM;
1539 goto leave;
1540 }
1541
Mark Fashehccd979b2005-12-15 14:31:24 -08001542 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1543 if (!ocfs2_debugfs_root) {
1544 status = -EFAULT;
1545 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1546 }
1547
Mark Fasheh171bf932008-10-20 15:36:47 +02001548 status = ocfs2_quota_setup();
1549 if (status)
1550 goto leave;
1551
Joel Becker63e0c482008-01-30 16:58:36 -08001552 ocfs2_set_locking_protocol();
1553
Jan Kara9e33d692008-08-25 19:56:50 +02001554 status = register_quota_format(&ocfs2_quota_format);
Mark Fashehccd979b2005-12-15 14:31:24 -08001555leave:
1556 if (status < 0) {
Mark Fasheh171bf932008-10-20 15:36:47 +02001557 ocfs2_quota_shutdown();
Mark Fashehccd979b2005-12-15 14:31:24 -08001558 ocfs2_free_mem_caches();
1559 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001560 }
1561
1562 mlog_exit(status);
1563
1564 if (status >= 0) {
1565 return register_filesystem(&ocfs2_fs_type);
1566 } else
1567 return -1;
1568}
1569
1570static void __exit ocfs2_exit(void)
1571{
1572 mlog_entry_void();
1573
Mark Fasheh171bf932008-10-20 15:36:47 +02001574 ocfs2_quota_shutdown();
1575
Mark Fashehccd979b2005-12-15 14:31:24 -08001576 if (ocfs2_wq) {
1577 flush_workqueue(ocfs2_wq);
1578 destroy_workqueue(ocfs2_wq);
1579 }
1580
Jan Kara9e33d692008-08-25 19:56:50 +02001581 unregister_quota_format(&ocfs2_quota_format);
1582
Mark Fashehccd979b2005-12-15 14:31:24 -08001583 debugfs_remove(ocfs2_debugfs_root);
1584
1585 ocfs2_free_mem_caches();
1586
1587 unregister_filesystem(&ocfs2_fs_type);
1588
Mark Fashehccd979b2005-12-15 14:31:24 -08001589 exit_ocfs2_uptodate_cache();
1590
1591 mlog_exit_void();
1592}
1593
1594static void ocfs2_put_super(struct super_block *sb)
1595{
1596 mlog_entry("(0x%p)\n", sb);
1597
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001598 lock_kernel();
1599
Mark Fashehccd979b2005-12-15 14:31:24 -08001600 ocfs2_sync_blockdev(sb);
1601 ocfs2_dismount_volume(sb, 0);
1602
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001603 unlock_kernel();
1604
Mark Fashehccd979b2005-12-15 14:31:24 -08001605 mlog_exit_void();
1606}
1607
David Howells726c3342006-06-23 02:02:58 -07001608static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001609{
1610 struct ocfs2_super *osb;
1611 u32 numbits, freebits;
1612 int status;
1613 struct ocfs2_dinode *bm_lock;
1614 struct buffer_head *bh = NULL;
1615 struct inode *inode = NULL;
1616
David Howells726c3342006-06-23 02:02:58 -07001617 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001618
David Howells726c3342006-06-23 02:02:58 -07001619 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001620
1621 inode = ocfs2_get_system_file_inode(osb,
1622 GLOBAL_BITMAP_SYSTEM_INODE,
1623 OCFS2_INVALID_SLOT);
1624 if (!inode) {
1625 mlog(ML_ERROR, "failed to get bitmap inode\n");
1626 status = -EIO;
1627 goto bail;
1628 }
1629
Mark Fashehe63aecb62007-10-18 15:30:42 -07001630 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001631 if (status < 0) {
1632 mlog_errno(status);
1633 goto bail;
1634 }
1635
1636 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1637
1638 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1639 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1640
1641 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001642 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001643 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1644 buf->f_blocks = ((sector_t) numbits) *
1645 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1646 buf->f_bfree = ((sector_t) freebits) *
1647 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1648 buf->f_bavail = buf->f_bfree;
1649 buf->f_files = numbits;
1650 buf->f_ffree = freebits;
1651
1652 brelse(bh);
1653
Mark Fashehe63aecb62007-10-18 15:30:42 -07001654 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001655 status = 0;
1656bail:
1657 if (inode)
1658 iput(inode);
1659
1660 mlog_exit(status);
1661
1662 return status;
1663}
1664
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001665static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001666{
1667 struct ocfs2_inode_info *oi = data;
1668
Christoph Lametera35afb82007-05-16 22:10:57 -07001669 oi->ip_flags = 0;
1670 oi->ip_open_count = 0;
1671 spin_lock_init(&oi->ip_lock);
1672 ocfs2_extent_map_init(&oi->vfs_inode);
1673 INIT_LIST_HEAD(&oi->ip_io_markers);
Christoph Lametera35afb82007-05-16 22:10:57 -07001674 oi->ip_dir_start_lookup = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001675
Christoph Lametera35afb82007-05-16 22:10:57 -07001676 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001677 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001678 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001679
Christoph Lametera35afb82007-05-16 22:10:57 -07001680 oi->ip_blkno = 0ULL;
1681 oi->ip_clusters = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001682
Christoph Lametera35afb82007-05-16 22:10:57 -07001683 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001684 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001685 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001686
Joel Becker8cb471e2009-02-10 20:00:41 -08001687 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
Joel Becker6e5a3d72009-02-10 19:00:37 -08001688 &ocfs2_inode_caching_ops);
Mark Fashehccd979b2005-12-15 14:31:24 -08001689
Christoph Lametera35afb82007-05-16 22:10:57 -07001690 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001691}
1692
1693static int ocfs2_initialize_mem_caches(void)
1694{
1695 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001696 sizeof(struct ocfs2_inode_info),
1697 0,
1698 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1699 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001700 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001701 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1702 sizeof(struct ocfs2_dquot),
1703 0,
1704 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1705 SLAB_MEM_SPREAD),
1706 NULL);
1707 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1708 sizeof(struct ocfs2_quota_chunk),
1709 0,
1710 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1711 NULL);
1712 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1713 !ocfs2_qf_chunk_cachep) {
1714 if (ocfs2_inode_cachep)
1715 kmem_cache_destroy(ocfs2_inode_cachep);
1716 if (ocfs2_dquot_cachep)
1717 kmem_cache_destroy(ocfs2_dquot_cachep);
1718 if (ocfs2_qf_chunk_cachep)
1719 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001720 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001721 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001722
Mark Fashehccd979b2005-12-15 14:31:24 -08001723 return 0;
1724}
1725
1726static void ocfs2_free_mem_caches(void)
1727{
1728 if (ocfs2_inode_cachep)
1729 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001730 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001731
1732 if (ocfs2_dquot_cachep)
1733 kmem_cache_destroy(ocfs2_dquot_cachep);
1734 ocfs2_dquot_cachep = NULL;
1735
1736 if (ocfs2_qf_chunk_cachep)
1737 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1738 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001739}
1740
1741static int ocfs2_get_sector(struct super_block *sb,
1742 struct buffer_head **bh,
1743 int block,
1744 int sect_size)
1745{
1746 if (!sb_set_blocksize(sb, sect_size)) {
1747 mlog(ML_ERROR, "unable to set blocksize\n");
1748 return -EIO;
1749 }
1750
1751 *bh = sb_getblk(sb, block);
1752 if (!*bh) {
1753 mlog_errno(-EIO);
1754 return -EIO;
1755 }
1756 lock_buffer(*bh);
1757 if (!buffer_dirty(*bh))
1758 clear_buffer_uptodate(*bh);
1759 unlock_buffer(*bh);
1760 ll_rw_block(READ, 1, bh);
1761 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001762 if (!buffer_uptodate(*bh)) {
1763 mlog_errno(-EIO);
1764 brelse(*bh);
1765 *bh = NULL;
1766 return -EIO;
1767 }
1768
Mark Fashehccd979b2005-12-15 14:31:24 -08001769 return 0;
1770}
1771
Mark Fashehccd979b2005-12-15 14:31:24 -08001772static int ocfs2_mount_volume(struct super_block *sb)
1773{
1774 int status = 0;
1775 int unlock_super = 0;
1776 struct ocfs2_super *osb = OCFS2_SB(sb);
1777
1778 mlog_entry_void();
1779
1780 if (ocfs2_is_hard_readonly(osb))
1781 goto leave;
1782
Mark Fashehccd979b2005-12-15 14:31:24 -08001783 status = ocfs2_dlm_init(osb);
1784 if (status < 0) {
1785 mlog_errno(status);
1786 goto leave;
1787 }
1788
Mark Fashehccd979b2005-12-15 14:31:24 -08001789 status = ocfs2_super_lock(osb, 1);
1790 if (status < 0) {
1791 mlog_errno(status);
1792 goto leave;
1793 }
1794 unlock_super = 1;
1795
1796 /* This will load up the node map and add ourselves to it. */
1797 status = ocfs2_find_slot(osb);
1798 if (status < 0) {
1799 mlog_errno(status);
1800 goto leave;
1801 }
1802
Mark Fashehccd979b2005-12-15 14:31:24 -08001803 /* load all node-local system inodes */
1804 status = ocfs2_init_local_system_inodes(osb);
1805 if (status < 0) {
1806 mlog_errno(status);
1807 goto leave;
1808 }
1809
1810 status = ocfs2_check_volume(osb);
1811 if (status < 0) {
1812 mlog_errno(status);
1813 goto leave;
1814 }
1815
1816 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001817 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001818 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001819
Mark Fashehccd979b2005-12-15 14:31:24 -08001820leave:
1821 if (unlock_super)
1822 ocfs2_super_unlock(osb, 1);
1823
1824 mlog_exit(status);
1825 return status;
1826}
1827
Mark Fashehccd979b2005-12-15 14:31:24 -08001828static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1829{
Joel Becker286eaa92008-02-01 15:03:57 -08001830 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001831 struct ocfs2_super *osb = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001832 char nodestr[8];
Mark Fashehccd979b2005-12-15 14:31:24 -08001833
1834 mlog_entry("(0x%p)\n", sb);
1835
1836 BUG_ON(!sb);
1837 osb = OCFS2_SB(sb);
1838 BUG_ON(!osb);
1839
Sunil Mushran50397502008-12-17 14:17:43 -08001840 debugfs_remove(osb->osb_ctxt);
1841
Jan Karaf7b1aa692009-07-20 12:12:36 +02001842 /*
1843 * Flush inode dropping work queue so that deletes are
1844 * performed while the filesystem is still working
1845 */
1846 ocfs2_drop_all_dl_inodes(osb);
1847
Sunil Mushran692684e2009-06-19 16:53:17 -07001848 /* Orphan scan should be stopped as early as possible */
1849 ocfs2_orphan_scan_stop(osb);
1850
Jan Kara19ece542008-08-21 20:13:17 +02001851 ocfs2_disable_quotas(osb);
1852
Mark Fashehccd979b2005-12-15 14:31:24 -08001853 ocfs2_shutdown_local_alloc(osb);
1854
1855 ocfs2_truncate_log_shutdown(osb);
1856
Joel Becker553abd02008-02-01 12:03:57 -08001857 /* This will disable recovery and flush any recovery work. */
1858 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001859
1860 ocfs2_journal_shutdown(osb);
1861
1862 ocfs2_sync_blockdev(sb);
1863
Tao Ma374a2632009-08-24 11:13:37 +08001864 ocfs2_purge_refcount_trees(osb);
1865
Joel Becker4670c462008-02-01 14:39:35 -08001866 /* No cluster connection means we've failed during mount, so skip
1867 * all the steps which depended on that to complete. */
1868 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001869 tmp = ocfs2_super_lock(osb, 1);
1870 if (tmp < 0) {
1871 mlog_errno(tmp);
1872 return;
1873 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001874 }
1875
Mark Fasheh19b613d2007-10-04 14:47:09 -07001876 if (osb->slot_num != OCFS2_INVALID_SLOT)
1877 ocfs2_put_slot(osb);
1878
Joel Becker4670c462008-02-01 14:39:35 -08001879 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001880 ocfs2_super_unlock(osb, 1);
1881
Mark Fashehccd979b2005-12-15 14:31:24 -08001882 ocfs2_release_system_inodes(osb);
1883
Joel Becker6953b4c2008-01-29 16:59:56 -08001884 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001885 * If we're dismounting due to mount error, mount.ocfs2 will clean
1886 * up heartbeat. If we're a local mount, there is no heartbeat.
1887 * If we failed before we got a uuid_str yet, we can't stop
1888 * heartbeat. Otherwise, do it.
1889 */
1890 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
Joel Becker286eaa92008-02-01 15:03:57 -08001891 hangup_needed = 1;
1892
1893 if (osb->cconn)
1894 ocfs2_dlm_shutdown(osb, hangup_needed);
1895
Joel Becker73be1922009-01-06 14:57:08 -08001896 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Joel Becker286eaa92008-02-01 15:03:57 -08001897 debugfs_remove(osb->osb_debug_root);
1898
1899 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001900 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001901
1902 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1903
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001904 if (ocfs2_mount_local(osb))
1905 snprintf(nodestr, sizeof(nodestr), "local");
1906 else
Joel Becker19fdb622008-01-30 15:38:24 -08001907 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001908
1909 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1910 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001911
1912 ocfs2_delete_osb(osb);
1913 kfree(osb);
1914 sb->s_dev = 0;
1915 sb->s_fs_info = NULL;
1916}
1917
1918static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1919 unsigned uuid_bytes)
1920{
1921 int i, ret;
1922 char *ptr;
1923
1924 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1925
Robert P. J. Daycd861282006-12-13 00:34:52 -08001926 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001927 if (osb->uuid_str == NULL)
1928 return -ENOMEM;
1929
Mark Fashehccd979b2005-12-15 14:31:24 -08001930 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1931 /* print with null */
1932 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1933 if (ret != 2) /* drop super cleans up */
1934 return -EINVAL;
1935 /* then only advance past the last char */
1936 ptr += 2;
1937 }
1938
1939 return 0;
1940}
1941
1942static int ocfs2_initialize_super(struct super_block *sb,
1943 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08001944 int sector_size,
1945 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08001946{
Denis Chengbddb8eb32007-09-27 02:10:04 +08001947 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07001948 int i, cbits, bbits;
1949 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08001950 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001951 struct ocfs2_journal *journal;
1952 __le32 uuid_net_key;
1953 struct ocfs2_super *osb;
1954
1955 mlog_entry_void();
1956
Robert P. J. Daycd861282006-12-13 00:34:52 -08001957 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001958 if (!osb) {
1959 status = -ENOMEM;
1960 mlog_errno(status);
1961 goto bail;
1962 }
1963
1964 sb->s_fs_info = osb;
1965 sb->s_op = &ocfs2_sops;
1966 sb->s_export_op = &ocfs2_export_ops;
Jan Kara19ece542008-08-21 20:13:17 +02001967 sb->s_qcop = &ocfs2_quotactl_ops;
1968 sb->dq_op = &ocfs2_quota_operations;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001969 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07001970 sb->s_time_gran = 1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001971 sb->s_flags |= MS_NOATIME;
1972 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07001973 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1974 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1975 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001976
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001977 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
1978
1979 for (i = 0; i < 3; i++)
1980 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
1981 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1982
Mark Fashehccd979b2005-12-15 14:31:24 -08001983 osb->sb = sb;
1984 /* Save off for ocfs2_rw_direct */
1985 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01001986 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001987
Mark Fasheh34d024f2007-09-24 15:56:19 -07001988 spin_lock_init(&osb->dc_task_lock);
1989 init_waitqueue_head(&osb->dc_event);
1990 osb->dc_work_sequence = 0;
1991 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001992 INIT_LIST_HEAD(&osb->blocked_lock_list);
1993 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001994 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08001995 spin_lock_init(&osb->osb_xattr_lock);
Tao Ma4d0ddb22008-03-05 16:11:46 +08001996 ocfs2_init_inode_steal_slot(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001997
1998 atomic_set(&osb->alloc_stats.moves, 0);
1999 atomic_set(&osb->alloc_stats.local_data, 0);
2000 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2001 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2002 atomic_set(&osb->alloc_stats.bg_extends, 0);
2003
Joel Becker73be1922009-01-06 14:57:08 -08002004 /* Copy the blockcheck stats from the superblock probe */
2005 osb->osb_ecc_stats = *stats;
2006
Mark Fashehccd979b2005-12-15 14:31:24 -08002007 ocfs2_init_node_maps(osb);
2008
2009 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2010 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2011
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04002012 ocfs2_orphan_scan_init(osb);
2013
Joel Becker553abd02008-02-01 12:03:57 -08002014 status = ocfs2_recovery_init(osb);
2015 if (status) {
2016 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2017 mlog_errno(status);
2018 goto bail;
2019 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002020
2021 init_waitqueue_head(&osb->checkpoint_event);
2022 atomic_set(&osb->needs_checkpoint, 0);
2023
Tiger Yang7f1a37e2006-11-15 15:48:42 +08002024 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2025
Mark Fashehccd979b2005-12-15 14:31:24 -08002026 osb->slot_num = OCFS2_INVALID_SLOT;
2027
Tiger Yang8154da32008-08-18 17:11:46 +08002028 osb->s_xattr_inline_size = le16_to_cpu(
2029 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002030
Mark Fashehccd979b2005-12-15 14:31:24 -08002031 osb->local_alloc_state = OCFS2_LA_UNUSED;
2032 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002033 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002034
Mark Fashehccd979b2005-12-15 14:31:24 -08002035 init_waitqueue_head(&osb->osb_mount_event);
2036
2037 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2038 if (!osb->vol_label) {
2039 mlog(ML_ERROR, "unable to alloc vol label\n");
2040 status = -ENOMEM;
2041 goto bail;
2042 }
2043
Mark Fashehccd979b2005-12-15 14:31:24 -08002044 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2045 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2046 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2047 osb->max_slots);
2048 status = -EINVAL;
2049 goto bail;
2050 }
Sunil Mushran781ee3e2006-04-27 16:41:31 -07002051 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
Mark Fashehccd979b2005-12-15 14:31:24 -08002052
Sunil Mushran539d8262008-07-14 17:31:10 -07002053 osb->slot_recovery_generations =
2054 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2055 GFP_KERNEL);
2056 if (!osb->slot_recovery_generations) {
2057 status = -ENOMEM;
2058 mlog_errno(status);
2059 goto bail;
2060 }
2061
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002062 init_waitqueue_head(&osb->osb_wipe_event);
2063 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2064 sizeof(*osb->osb_orphan_wipes),
2065 GFP_KERNEL);
2066 if (!osb->osb_orphan_wipes) {
2067 status = -ENOMEM;
2068 mlog_errno(status);
2069 goto bail;
2070 }
2071
Tao Ma374a2632009-08-24 11:13:37 +08002072 osb->osb_rf_lock_tree = RB_ROOT;
2073
Mark Fashehccd979b2005-12-15 14:31:24 -08002074 osb->s_feature_compat =
2075 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2076 osb->s_feature_ro_compat =
2077 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2078 osb->s_feature_incompat =
2079 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2080
2081 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2082 mlog(ML_ERROR, "couldn't mount because of unsupported "
2083 "optional features (%x).\n", i);
2084 status = -EINVAL;
2085 goto bail;
2086 }
2087 if (!(osb->sb->s_flags & MS_RDONLY) &&
2088 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2089 mlog(ML_ERROR, "couldn't mount RDWR because of "
2090 "unsupported optional features (%x).\n", i);
2091 status = -EINVAL;
2092 goto bail;
2093 }
2094
Joel Beckerb61817e2008-02-01 15:08:23 -08002095 if (ocfs2_userspace_stack(osb)) {
2096 memcpy(osb->osb_cluster_stack,
2097 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2098 OCFS2_STACK_LABEL_LEN);
2099 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2100 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2101 mlog(ML_ERROR,
2102 "couldn't mount because of an invalid "
2103 "cluster stack label (%s) \n",
2104 osb->osb_cluster_stack);
2105 status = -EINVAL;
2106 goto bail;
2107 }
2108 } else {
2109 /* The empty string is identical with classic tools that
2110 * don't know about s_cluster_info. */
2111 osb->osb_cluster_stack[0] = '\0';
2112 }
2113
Mark Fashehccd979b2005-12-15 14:31:24 -08002114 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2115
2116 /* FIXME
2117 * This should be done in ocfs2_journal_init(), but unknown
2118 * ordering issues will cause the filesystem to crash.
2119 * If anyone wants to figure out what part of the code
2120 * refers to osb->journal before ocfs2_journal_init() is run,
2121 * be my guest.
2122 */
2123 /* initialize our journal structure */
2124
Robert P. J. Daycd861282006-12-13 00:34:52 -08002125 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002126 if (!journal) {
2127 mlog(ML_ERROR, "unable to alloc journal\n");
2128 status = -ENOMEM;
2129 goto bail;
2130 }
2131 osb->journal = journal;
2132 journal->j_osb = osb;
2133
2134 atomic_set(&journal->j_num_trans, 0);
2135 init_rwsem(&journal->j_trans_barrier);
2136 init_waitqueue_head(&journal->j_checkpointed);
2137 spin_lock_init(&journal->j_lock);
2138 journal->j_trans_id = (unsigned long) 1;
2139 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002140 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002141 journal->j_state = OCFS2_JOURNAL_FREE;
2142
Jan Karaea455f82009-01-12 23:20:31 +01002143 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2144 osb->dentry_lock_list = NULL;
2145
Mark Fashehccd979b2005-12-15 14:31:24 -08002146 /* get some pseudo constants for clustersize bits */
2147 osb->s_clustersize_bits =
2148 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2149 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2150 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2151
2152 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2153 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2154 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2155 osb->s_clustersize);
2156 status = -EINVAL;
2157 goto bail;
2158 }
2159
2160 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2161 > (u32)~0UL) {
2162 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2163 "what jbd can address in 32 bits.\n");
2164 status = -EINVAL;
2165 goto bail;
2166 }
2167
2168 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2169 sizeof(di->id2.i_super.s_uuid))) {
2170 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2171 status = -ENOMEM;
2172 goto bail;
2173 }
2174
Mark Fasheh78427042006-05-04 12:03:26 -07002175 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
Mark Fashehccd979b2005-12-15 14:31:24 -08002176
2177 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2178 osb->vol_label[63] = '\0';
2179 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2180 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2181 osb->first_cluster_group_blkno =
2182 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2183 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002184 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Mark Fashehccd979b2005-12-15 14:31:24 -08002185 mlog(0, "vol_label: %s\n", osb->vol_label);
2186 mlog(0, "uuid: %s\n", osb->uuid_str);
Mark Fashehb06970532006-03-03 10:24:33 -08002187 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2188 (unsigned long long)osb->root_blkno,
2189 (unsigned long long)osb->system_dir_blkno);
Mark Fashehccd979b2005-12-15 14:31:24 -08002190
2191 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2192 if (!osb->osb_dlm_debug) {
2193 status = -ENOMEM;
2194 mlog_errno(status);
2195 goto bail;
2196 }
2197
2198 atomic_set(&osb->vol_state, VOLUME_INIT);
2199
2200 /* load root, system_dir, and all global system inodes */
2201 status = ocfs2_init_global_system_inodes(osb);
2202 if (status < 0) {
2203 mlog_errno(status);
2204 goto bail;
2205 }
2206
2207 /*
2208 * global bitmap
2209 */
2210 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2211 OCFS2_INVALID_SLOT);
2212 if (!inode) {
2213 status = -EINVAL;
2214 mlog_errno(status);
2215 goto bail;
2216 }
2217
2218 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fashehccd979b2005-12-15 14:31:24 -08002219 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002220
Tao Mae9d578a2007-12-18 15:46:10 +08002221 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002222
2223 status = ocfs2_init_slot_info(osb);
2224 if (status < 0) {
2225 mlog_errno(status);
2226 goto bail;
2227 }
2228
Mark Fashehccd979b2005-12-15 14:31:24 -08002229bail:
2230 mlog_exit(status);
2231 return status;
2232}
2233
2234/*
2235 * will return: -EAGAIN if it is ok to keep searching for superblocks
2236 * -EINVAL if there is a bad superblock
2237 * 0 on success
2238 */
2239static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2240 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002241 u32 blksz,
2242 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002243{
2244 int status = -EAGAIN;
2245
2246 mlog_entry_void();
2247
2248 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2249 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002250 /* We have to do a raw check of the feature here */
2251 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2252 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2253 status = ocfs2_block_check_validate(bh->b_data,
2254 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002255 &di->i_check,
2256 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002257 if (status)
2258 goto out;
2259 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002260 status = -EINVAL;
2261 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2262 mlog(ML_ERROR, "found superblock with incorrect block "
2263 "size: found %u, should be %u\n",
2264 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2265 blksz);
2266 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2267 OCFS2_MAJOR_REV_LEVEL ||
2268 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2269 OCFS2_MINOR_REV_LEVEL) {
2270 mlog(ML_ERROR, "found superblock with bad version: "
2271 "found %u.%u, should be %u.%u\n",
2272 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2273 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2274 OCFS2_MAJOR_REV_LEVEL,
2275 OCFS2_MINOR_REV_LEVEL);
2276 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2277 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb06970532006-03-03 10:24:33 -08002278 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002279 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb06970532006-03-03 10:24:33 -08002280 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002281 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2282 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2283 mlog(ML_ERROR, "bad cluster size found: %u\n",
2284 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2285 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2286 mlog(ML_ERROR, "bad root_blkno: 0\n");
2287 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2288 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2289 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2290 mlog(ML_ERROR,
2291 "Superblock slots found greater than file system "
2292 "maximum: found %u, max %u\n",
2293 le16_to_cpu(di->id2.i_super.s_max_slots),
2294 OCFS2_MAX_SLOTS);
2295 } else {
2296 /* found it! */
2297 status = 0;
2298 }
2299 }
2300
Joel Beckerd030cc92008-12-11 15:04:14 -08002301out:
Mark Fashehccd979b2005-12-15 14:31:24 -08002302 mlog_exit(status);
2303 return status;
2304}
2305
2306static int ocfs2_check_volume(struct ocfs2_super *osb)
2307{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002308 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002309 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002310 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002311 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2312 * recover
2313 * ourselves. */
2314
2315 mlog_entry_void();
2316
2317 /* Init our journal object. */
2318 status = ocfs2_journal_init(osb->journal, &dirty);
2319 if (status < 0) {
2320 mlog(ML_ERROR, "Could not initialize journal!\n");
2321 goto finally;
2322 }
2323
2324 /* If the journal was unmounted cleanly then we don't want to
2325 * recover anything. Otherwise, journal_load will do that
2326 * dirty work for us :) */
2327 if (!dirty) {
2328 status = ocfs2_journal_wipe(osb->journal, 0);
2329 if (status < 0) {
2330 mlog_errno(status);
2331 goto finally;
2332 }
2333 } else {
2334 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2335 "recovering volume.\n");
2336 }
2337
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002338 local = ocfs2_mount_local(osb);
2339
Mark Fashehccd979b2005-12-15 14:31:24 -08002340 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002341 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002342 if (status < 0) {
2343 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2344 goto finally;
2345 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002346
2347 if (dirty) {
2348 /* recover my local alloc if we didn't unmount cleanly. */
2349 status = ocfs2_begin_local_alloc_recovery(osb,
2350 osb->slot_num,
2351 &local_alloc);
2352 if (status < 0) {
2353 mlog_errno(status);
2354 goto finally;
2355 }
2356 /* we complete the recovery process after we've marked
2357 * ourselves as mounted. */
2358 }
2359
2360 mlog(0, "Journal loaded.\n");
2361
2362 status = ocfs2_load_local_alloc(osb);
2363 if (status < 0) {
2364 mlog_errno(status);
2365 goto finally;
2366 }
2367
2368 if (dirty) {
2369 /* Recovery will be completed after we've mounted the
2370 * rest of the volume. */
2371 osb->dirty = 1;
2372 osb->local_alloc_copy = local_alloc;
2373 local_alloc = NULL;
2374 }
2375
2376 /* go through each journal, trylock it and if you get the
2377 * lock, and it's marked as dirty, set the bit in the recover
2378 * map and launch a recovery thread for it. */
2379 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002380 if (status < 0) {
2381 mlog_errno(status);
2382 goto finally;
2383 }
2384
2385 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002386 if (status < 0)
2387 mlog_errno(status);
2388
2389finally:
2390 if (local_alloc)
2391 kfree(local_alloc);
2392
2393 mlog_exit(status);
2394 return status;
2395}
2396
2397/*
2398 * The routine gets called from dismount or close whenever a dismount on
2399 * volume is requested and the osb open count becomes 1.
2400 * It will remove the osb from the global list and also free up all the
2401 * initialized resources and fileobject.
2402 */
2403static void ocfs2_delete_osb(struct ocfs2_super *osb)
2404{
2405 mlog_entry_void();
2406
2407 /* This function assumes that the caller has the main osb resource */
2408
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002409 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002410
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002411 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002412 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002413 /* FIXME
2414 * This belongs in journal shutdown, but because we have to
2415 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2416 * we free it here.
2417 */
2418 kfree(osb->journal);
2419 if (osb->local_alloc_copy)
2420 kfree(osb->local_alloc_copy);
2421 kfree(osb->uuid_str);
2422 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2423 memset(osb, 0, sizeof(struct ocfs2_super));
2424
2425 mlog_exit_void();
2426}
2427
2428/* Put OCFS2 into a readonly state, or (if the user specifies it),
2429 * panic(). We do not support continue-on-error operation. */
2430static void ocfs2_handle_error(struct super_block *sb)
2431{
2432 struct ocfs2_super *osb = OCFS2_SB(sb);
2433
2434 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2435 panic("OCFS2: (device %s): panic forced after error\n",
2436 sb->s_id);
2437
2438 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2439
2440 if (sb->s_flags & MS_RDONLY &&
2441 (ocfs2_is_soft_readonly(osb) ||
2442 ocfs2_is_hard_readonly(osb)))
2443 return;
2444
2445 printk(KERN_CRIT "File system is now read-only due to the potential "
2446 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2447 "system is unmounted.\n");
2448 sb->s_flags |= MS_RDONLY;
2449 ocfs2_set_ro_flag(osb, 0);
2450}
2451
2452static char error_buf[1024];
2453
2454void __ocfs2_error(struct super_block *sb,
2455 const char *function,
2456 const char *fmt, ...)
2457{
2458 va_list args;
2459
2460 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002461 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002462 va_end(args);
2463
2464 /* Not using mlog here because we want to show the actual
2465 * function the error came from. */
2466 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2467 sb->s_id, function, error_buf);
2468
2469 ocfs2_handle_error(sb);
2470}
2471
2472/* Handle critical errors. This is intentionally more drastic than
2473 * ocfs2_handle_error, so we only use for things like journal errors,
2474 * etc. */
2475void __ocfs2_abort(struct super_block* sb,
2476 const char *function,
2477 const char *fmt, ...)
2478{
2479 va_list args;
2480
2481 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002482 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002483 va_end(args);
2484
2485 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2486 sb->s_id, function, error_buf);
2487
2488 /* We don't have the cluster support yet to go straight to
2489 * hard readonly in here. Until then, we want to keep
2490 * ocfs2_abort() so that we can at least mark critical
2491 * errors.
2492 *
2493 * TODO: This should abort the journal and alert other nodes
2494 * that our slot needs recovery. */
2495
2496 /* Force a panic(). This stinks, but it's better than letting
2497 * things continue without having a proper hard readonly
2498 * here. */
Sunil Mushrana2f2ddb2009-08-19 15:16:01 -07002499 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2500 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08002501 ocfs2_handle_error(sb);
2502}
2503
2504module_init(ocfs2_init);
2505module_exit(ocfs2_exit);