blob: 154e62522b0595b1eb859ce90a11c7c2a58e0c11 [file] [log] [blame]
Mark Fashehccd979b2005-12-15 14:31:24 -08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * super.c
5 *
6 * load/unload driver, mount/dismount volumes
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
24 */
25
26#include <linux/module.h>
27#include <linux/fs.h>
28#include <linux/types.h>
29#include <linux/slab.h>
30#include <linux/highmem.h>
31#include <linux/utsname.h>
32#include <linux/init.h>
33#include <linux/random.h>
34#include <linux/statfs.h>
35#include <linux/moduleparam.h>
36#include <linux/blkdev.h>
37#include <linux/socket.h>
38#include <linux/inet.h>
39#include <linux/parser.h>
40#include <linux/crc32.h>
41#include <linux/debugfs.h>
Sunil Mushrand5500712007-09-06 13:34:16 -070042#include <linux/mount.h>
Joel Becker6953b4c2008-01-29 16:59:56 -080043#include <linux/seq_file.h>
Jan Kara19ece542008-08-21 20:13:17 +020044#include <linux/quotaops.h>
Alessio Igor Bogani337eb002009-05-12 15:10:54 +020045#include <linux/smp_lock.h>
Mark Fashehccd979b2005-12-15 14:31:24 -080046
47#define MLOG_MASK_PREFIX ML_SUPER
48#include <cluster/masklog.h>
49
50#include "ocfs2.h"
51
52/* this should be the only file to include a version 1 header */
53#include "ocfs1_fs_compat.h"
54
55#include "alloc.h"
Joel Beckerd030cc92008-12-11 15:04:14 -080056#include "blockcheck.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080057#include "dlmglue.h"
58#include "export.h"
59#include "extent_map.h"
60#include "heartbeat.h"
61#include "inode.h"
62#include "journal.h"
63#include "localalloc.h"
64#include "namei.h"
65#include "slot_map.h"
66#include "super.h"
67#include "sysfile.h"
68#include "uptodate.h"
69#include "ver.h"
Tiger Yangcf1d6c72008-08-18 17:11:00 +080070#include "xattr.h"
Jan Kara9e33d692008-08-25 19:56:50 +020071#include "quota.h"
Tao Ma374a2632009-08-24 11:13:37 +080072#include "refcounttree.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080073
74#include "buffer_head_io.h"
75
Christoph Lametere18b8902006-12-06 20:33:20 -080076static struct kmem_cache *ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +020077struct kmem_cache *ocfs2_dquot_cachep;
78struct kmem_cache *ocfs2_qf_chunk_cachep;
Mark Fashehccd979b2005-12-15 14:31:24 -080079
Mark Fashehccd979b2005-12-15 14:31:24 -080080/* OCFS2 needs to schedule several differnt types of work which
81 * require cluster locking, disk I/O, recovery waits, etc. Since these
82 * types of work tend to be heavy we avoid using the kernel events
83 * workqueue and schedule on our own. */
84struct workqueue_struct *ocfs2_wq = NULL;
85
86static struct dentry *ocfs2_debugfs_root = NULL;
87
88MODULE_AUTHOR("Oracle");
89MODULE_LICENSE("GPL");
90
Tiger Yangc0123ad2007-09-08 00:16:10 +080091struct mount_options
92{
Mark Fashehd147b3d2007-11-07 14:40:36 -080093 unsigned long commit_interval;
Tiger Yangc0123ad2007-09-08 00:16:10 +080094 unsigned long mount_opt;
95 unsigned int atime_quantum;
96 signed short slot;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -080097 unsigned int localalloc_opt;
Joel Beckerb61817e2008-02-01 15:08:23 -080098 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
Tiger Yangc0123ad2007-09-08 00:16:10 +080099};
100
Mark Fashehccd979b2005-12-15 14:31:24 -0800101static int ocfs2_parse_options(struct super_block *sb, char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +0800102 struct mount_options *mopt,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700103 int is_remount);
Sunil Mushrand5500712007-09-06 13:34:16 -0700104static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -0800105static void ocfs2_put_super(struct super_block *sb);
106static int ocfs2_mount_volume(struct super_block *sb);
107static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
108static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
109static int ocfs2_initialize_mem_caches(void);
110static void ocfs2_free_mem_caches(void);
111static void ocfs2_delete_osb(struct ocfs2_super *osb);
112
David Howells726c3342006-06-23 02:02:58 -0700113static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
Mark Fashehccd979b2005-12-15 14:31:24 -0800114
115static int ocfs2_sync_fs(struct super_block *sb, int wait);
116
117static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
118static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
Denis Chengbddb8eb32007-09-27 02:10:04 +0800119static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800120static int ocfs2_check_volume(struct ocfs2_super *osb);
121static int ocfs2_verify_volume(struct ocfs2_dinode *di,
122 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800123 u32 sectsize,
124 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800125static int ocfs2_initialize_super(struct super_block *sb,
126 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800127 int sector_size,
128 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800129static int ocfs2_get_sector(struct super_block *sb,
130 struct buffer_head **bh,
131 int block,
132 int sect_size);
Mark Fashehccd979b2005-12-15 14:31:24 -0800133static struct inode *ocfs2_alloc_inode(struct super_block *sb);
134static void ocfs2_destroy_inode(struct inode *inode);
Jan Kara19ece542008-08-21 20:13:17 +0200135static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
136static int ocfs2_enable_quotas(struct ocfs2_super *osb);
137static void ocfs2_disable_quotas(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800138
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800139static const struct super_operations ocfs2_sops = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800140 .statfs = ocfs2_statfs,
141 .alloc_inode = ocfs2_alloc_inode,
142 .destroy_inode = ocfs2_destroy_inode,
143 .drop_inode = ocfs2_drop_inode,
144 .clear_inode = ocfs2_clear_inode,
145 .delete_inode = ocfs2_delete_inode,
146 .sync_fs = ocfs2_sync_fs,
Mark Fashehccd979b2005-12-15 14:31:24 -0800147 .put_super = ocfs2_put_super,
148 .remount_fs = ocfs2_remount,
Sunil Mushrand5500712007-09-06 13:34:16 -0700149 .show_options = ocfs2_show_options,
Jan Kara9e33d692008-08-25 19:56:50 +0200150 .quota_read = ocfs2_quota_read,
151 .quota_write = ocfs2_quota_write,
Mark Fashehccd979b2005-12-15 14:31:24 -0800152};
153
154enum {
155 Opt_barrier,
156 Opt_err_panic,
157 Opt_err_ro,
158 Opt_intr,
159 Opt_nointr,
160 Opt_hb_none,
161 Opt_hb_local,
162 Opt_data_ordered,
163 Opt_data_writeback,
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800164 Opt_atime_quantum,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700165 Opt_slot,
Mark Fashehd147b3d2007-11-07 14:40:36 -0800166 Opt_commit,
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800167 Opt_localalloc,
Mark Fasheh53fc6222007-12-20 16:49:04 -0800168 Opt_localflocks,
Joel Beckerb61817e2008-02-01 15:08:23 -0800169 Opt_stack,
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800170 Opt_user_xattr,
171 Opt_nouser_xattr,
Joel Becker12462f12008-09-03 20:03:40 -0700172 Opt_inode64,
Tiger Yanga68979b2008-11-14 11:17:52 +0800173 Opt_acl,
174 Opt_noacl,
Jan Kara19ece542008-08-21 20:13:17 +0200175 Opt_usrquota,
176 Opt_grpquota,
Mark Fashehccd979b2005-12-15 14:31:24 -0800177 Opt_err,
178};
179
Steven Whitehousea447c092008-10-13 10:46:57 +0100180static const match_table_t tokens = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800181 {Opt_barrier, "barrier=%u"},
182 {Opt_err_panic, "errors=panic"},
183 {Opt_err_ro, "errors=remount-ro"},
184 {Opt_intr, "intr"},
185 {Opt_nointr, "nointr"},
186 {Opt_hb_none, OCFS2_HB_NONE},
187 {Opt_hb_local, OCFS2_HB_LOCAL},
188 {Opt_data_ordered, "data=ordered"},
189 {Opt_data_writeback, "data=writeback"},
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800190 {Opt_atime_quantum, "atime_quantum=%u"},
Sunil Mushranbaf46612007-06-18 17:00:24 -0700191 {Opt_slot, "preferred_slot=%u"},
Mark Fashehd147b3d2007-11-07 14:40:36 -0800192 {Opt_commit, "commit=%u"},
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800193 {Opt_localalloc, "localalloc=%d"},
Mark Fasheh53fc6222007-12-20 16:49:04 -0800194 {Opt_localflocks, "localflocks"},
Joel Beckerb61817e2008-02-01 15:08:23 -0800195 {Opt_stack, "cluster_stack=%s"},
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800196 {Opt_user_xattr, "user_xattr"},
197 {Opt_nouser_xattr, "nouser_xattr"},
Joel Becker12462f12008-09-03 20:03:40 -0700198 {Opt_inode64, "inode64"},
Tiger Yanga68979b2008-11-14 11:17:52 +0800199 {Opt_acl, "acl"},
200 {Opt_noacl, "noacl"},
Jan Kara19ece542008-08-21 20:13:17 +0200201 {Opt_usrquota, "usrquota"},
202 {Opt_grpquota, "grpquota"},
Mark Fashehccd979b2005-12-15 14:31:24 -0800203 {Opt_err, NULL}
204};
205
Sunil Mushran50397502008-12-17 14:17:43 -0800206#ifdef CONFIG_DEBUG_FS
207static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
208{
Sunil Mushran50397502008-12-17 14:17:43 -0800209 struct ocfs2_cluster_connection *cconn = osb->cconn;
210 struct ocfs2_recovery_map *rm = osb->recovery_map;
Sunil Mushrandf152c22009-06-22 11:40:07 -0700211 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
212 int i, out = 0;
Sunil Mushran50397502008-12-17 14:17:43 -0800213
214 out += snprintf(buf + out, len - out,
215 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
216 "Device", osb->dev_str, osb->uuid_str,
217 osb->fs_generation, osb->vol_label);
218
219 out += snprintf(buf + out, len - out,
220 "%10s => State: %d Flags: 0x%lX\n", "Volume",
221 atomic_read(&osb->vol_state), osb->osb_flags);
222
223 out += snprintf(buf + out, len - out,
224 "%10s => Block: %lu Cluster: %d\n", "Sizes",
225 osb->sb->s_blocksize, osb->s_clustersize);
226
227 out += snprintf(buf + out, len - out,
228 "%10s => Compat: 0x%X Incompat: 0x%X "
229 "ROcompat: 0x%X\n",
230 "Features", osb->s_feature_compat,
231 osb->s_feature_incompat, osb->s_feature_ro_compat);
232
233 out += snprintf(buf + out, len - out,
234 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
235 osb->s_mount_opt, osb->s_atime_quantum);
236
Sunil Mushranc3d38842009-06-19 14:45:55 -0700237 if (cconn) {
238 out += snprintf(buf + out, len - out,
239 "%10s => Stack: %s Name: %*s "
240 "Version: %d.%d\n", "Cluster",
241 (*osb->osb_cluster_stack == '\0' ?
242 "o2cb" : osb->osb_cluster_stack),
243 cconn->cc_namelen, cconn->cc_name,
244 cconn->cc_version.pv_major,
245 cconn->cc_version.pv_minor);
246 }
Sunil Mushran50397502008-12-17 14:17:43 -0800247
248 spin_lock(&osb->dc_task_lock);
249 out += snprintf(buf + out, len - out,
250 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
251 "WorkSeq: %lu\n", "DownCnvt",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700252 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
253 osb->blocked_lock_count, osb->dc_wake_sequence,
254 osb->dc_work_sequence);
Sunil Mushran50397502008-12-17 14:17:43 -0800255 spin_unlock(&osb->dc_task_lock);
256
257 spin_lock(&osb->osb_lock);
258 out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
259 "Recovery",
260 (osb->recovery_thread_task ?
261 task_pid_nr(osb->recovery_thread_task) : -1));
262 if (rm->rm_used == 0)
263 out += snprintf(buf + out, len - out, " None\n");
264 else {
265 for (i = 0; i < rm->rm_used; i++)
266 out += snprintf(buf + out, len - out, " %d",
267 rm->rm_entries[i]);
268 out += snprintf(buf + out, len - out, "\n");
269 }
270 spin_unlock(&osb->osb_lock);
271
272 out += snprintf(buf + out, len - out,
273 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700274 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
275 osb->osb_commit_interval,
Sunil Mushran50397502008-12-17 14:17:43 -0800276 atomic_read(&osb->needs_checkpoint));
277
278 out += snprintf(buf + out, len - out,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700279 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
Sunil Mushran50397502008-12-17 14:17:43 -0800280 "Journal", osb->journal->j_state,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700281 osb->journal->j_trans_id,
282 atomic_read(&osb->journal->j_num_trans));
Sunil Mushran50397502008-12-17 14:17:43 -0800283
284 out += snprintf(buf + out, len - out,
285 "%10s => GlobalAllocs: %d LocalAllocs: %d "
286 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
287 "Stats",
288 atomic_read(&osb->alloc_stats.bitmap_data),
289 atomic_read(&osb->alloc_stats.local_data),
290 atomic_read(&osb->alloc_stats.bg_allocs),
291 atomic_read(&osb->alloc_stats.moves),
292 atomic_read(&osb->alloc_stats.bg_extends));
293
294 out += snprintf(buf + out, len - out,
295 "%10s => State: %u Descriptor: %llu Size: %u bits "
296 "Default: %u bits\n",
297 "LocalAlloc", osb->local_alloc_state,
298 (unsigned long long)osb->la_last_gd,
299 osb->local_alloc_bits, osb->local_alloc_default_bits);
300
301 spin_lock(&osb->osb_lock);
302 out += snprintf(buf + out, len - out,
303 "%10s => Slot: %d NumStolen: %d\n", "Steal",
304 osb->s_inode_steal_slot,
305 atomic_read(&osb->s_num_inodes_stolen));
306 spin_unlock(&osb->osb_lock);
307
Sunil Mushrandf152c22009-06-22 11:40:07 -0700308 out += snprintf(buf + out, len - out, "OrphanScan => ");
309 out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
310 os->os_count, os->os_seqno);
311 out += snprintf(buf + out, len - out, " Last Scan: ");
312 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
313 out += snprintf(buf + out, len - out, "Disabled\n");
314 else
315 out += snprintf(buf + out, len - out, "%lu seconds ago\n",
316 (get_seconds() - os->os_scantime.tv_sec));
317
Sunil Mushran50397502008-12-17 14:17:43 -0800318 out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
319 "Slots", "Num", "RecoGen");
Sunil Mushran50397502008-12-17 14:17:43 -0800320 for (i = 0; i < osb->max_slots; ++i) {
321 out += snprintf(buf + out, len - out,
322 "%10s %c %3d %10d\n",
323 " ",
324 (i == osb->slot_num ? '*' : ' '),
325 i, osb->slot_recovery_generations[i]);
326 }
327
328 return out;
329}
330
331static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
332{
333 struct ocfs2_super *osb = inode->i_private;
334 char *buf = NULL;
335
336 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
337 if (!buf)
338 goto bail;
339
340 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
341
342 file->private_data = buf;
343
344 return 0;
345bail:
346 return -ENOMEM;
347}
348
349static int ocfs2_debug_release(struct inode *inode, struct file *file)
350{
351 kfree(file->private_data);
352 return 0;
353}
354
355static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
356 size_t nbytes, loff_t *ppos)
357{
358 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
359 i_size_read(file->f_mapping->host));
360}
361#else
362static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
363{
364 return 0;
365}
366static int ocfs2_debug_release(struct inode *inode, struct file *file)
367{
368 return 0;
369}
370static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
371 size_t nbytes, loff_t *ppos)
372{
373 return 0;
374}
375#endif /* CONFIG_DEBUG_FS */
376
377static struct file_operations ocfs2_osb_debug_fops = {
378 .open = ocfs2_osb_debug_open,
379 .release = ocfs2_debug_release,
380 .read = ocfs2_debug_read,
381 .llseek = generic_file_llseek,
382};
383
Mark Fashehccd979b2005-12-15 14:31:24 -0800384static int ocfs2_sync_fs(struct super_block *sb, int wait)
385{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800386 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -0800387 tid_t target;
388 struct ocfs2_super *osb = OCFS2_SB(sb);
389
Mark Fashehccd979b2005-12-15 14:31:24 -0800390 if (ocfs2_is_hard_readonly(osb))
391 return -EROFS;
392
393 if (wait) {
394 status = ocfs2_flush_truncate_log(osb);
395 if (status < 0)
396 mlog_errno(status);
397 } else {
398 ocfs2_schedule_truncate_log_flush(osb, 0);
399 }
400
Joel Becker2b4e30f2008-09-03 20:03:41 -0700401 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
402 &target)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800403 if (wait)
Joel Becker2b4e30f2008-09-03 20:03:41 -0700404 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
405 target);
Mark Fashehccd979b2005-12-15 14:31:24 -0800406 }
407 return 0;
408}
409
Jan Kara1a224ad2008-08-20 15:43:36 +0200410static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
411{
412 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
413 && (ino == USER_QUOTA_SYSTEM_INODE
414 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
415 return 0;
416 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
417 && (ino == GROUP_QUOTA_SYSTEM_INODE
418 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
419 return 0;
420 return 1;
421}
422
Mark Fashehccd979b2005-12-15 14:31:24 -0800423static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
424{
425 struct inode *new = NULL;
426 int status = 0;
427 int i;
428
429 mlog_entry_void();
430
Jan Kara5fa06132008-01-11 00:11:45 +0100431 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800432 if (IS_ERR(new)) {
433 status = PTR_ERR(new);
434 mlog_errno(status);
435 goto bail;
436 }
437 osb->root_inode = new;
438
Jan Kara5fa06132008-01-11 00:11:45 +0100439 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800440 if (IS_ERR(new)) {
441 status = PTR_ERR(new);
442 mlog_errno(status);
443 goto bail;
444 }
445 osb->sys_root_inode = new;
446
447 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
448 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200449 if (!ocfs2_need_system_inode(osb, i))
450 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800451 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
452 if (!new) {
453 ocfs2_release_system_inodes(osb);
454 status = -EINVAL;
455 mlog_errno(status);
456 /* FIXME: Should ERROR_RO_FS */
457 mlog(ML_ERROR, "Unable to load system inode %d, "
458 "possibly corrupt fs?", i);
459 goto bail;
460 }
461 // the array now has one ref, so drop this one
462 iput(new);
463 }
464
465bail:
466 mlog_exit(status);
467 return status;
468}
469
470static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
471{
472 struct inode *new = NULL;
473 int status = 0;
474 int i;
475
476 mlog_entry_void();
477
478 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
479 i < NUM_SYSTEM_INODES;
480 i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200481 if (!ocfs2_need_system_inode(osb, i))
482 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800483 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
484 if (!new) {
485 ocfs2_release_system_inodes(osb);
486 status = -EINVAL;
487 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
488 status, i, osb->slot_num);
489 goto bail;
490 }
491 /* the array now has one ref, so drop this one */
492 iput(new);
493 }
494
495bail:
496 mlog_exit(status);
497 return status;
498}
499
Denis Chengbddb8eb32007-09-27 02:10:04 +0800500static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
Mark Fashehccd979b2005-12-15 14:31:24 -0800501{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800502 int i;
Mark Fashehccd979b2005-12-15 14:31:24 -0800503 struct inode *inode;
504
505 mlog_entry_void();
506
507 for (i = 0; i < NUM_SYSTEM_INODES; i++) {
508 inode = osb->system_inodes[i];
509 if (inode) {
510 iput(inode);
511 osb->system_inodes[i] = NULL;
512 }
513 }
514
515 inode = osb->sys_root_inode;
516 if (inode) {
517 iput(inode);
518 osb->sys_root_inode = NULL;
519 }
520
521 inode = osb->root_inode;
522 if (inode) {
523 iput(inode);
524 osb->root_inode = NULL;
525 }
526
Denis Chengbddb8eb32007-09-27 02:10:04 +0800527 mlog_exit(0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800528}
529
530/* We're allocating fs objects, use GFP_NOFS */
531static struct inode *ocfs2_alloc_inode(struct super_block *sb)
532{
533 struct ocfs2_inode_info *oi;
534
Christoph Lametere6b4f8d2006-12-06 20:33:14 -0800535 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
Mark Fashehccd979b2005-12-15 14:31:24 -0800536 if (!oi)
537 return NULL;
538
Joel Becker2b4e30f2008-09-03 20:03:41 -0700539 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -0800540 return &oi->vfs_inode;
541}
542
543static void ocfs2_destroy_inode(struct inode *inode)
544{
545 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
546}
547
Mark Fasheh5a254032007-07-20 12:56:16 -0700548static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
549 unsigned int cbits)
Mark Fashehccd979b2005-12-15 14:31:24 -0800550{
Mark Fasheh5a254032007-07-20 12:56:16 -0700551 unsigned int bytes = 1 << cbits;
552 unsigned int trim = bytes;
553 unsigned int bitshift = 32;
Mark Fashehccd979b2005-12-15 14:31:24 -0800554
Mark Fasheh5a254032007-07-20 12:56:16 -0700555 /*
556 * i_size and all block offsets in ocfs2 are always 64 bits
557 * wide. i_clusters is 32 bits, in cluster-sized units. So on
558 * 64 bit platforms, cluster size will be the limiting factor.
Mark Fashehccd979b2005-12-15 14:31:24 -0800559 */
560
561#if BITS_PER_LONG == 32
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +0200562# if defined(CONFIG_LBDAF)
Alexey Dobriyan2ecd05a2006-10-11 01:22:05 -0700563 BUILD_BUG_ON(sizeof(sector_t) != 8);
Mark Fasheh5a254032007-07-20 12:56:16 -0700564 /*
565 * We might be limited by page cache size.
566 */
567 if (bytes > PAGE_CACHE_SIZE) {
568 bytes = PAGE_CACHE_SIZE;
569 trim = 1;
570 /*
571 * Shift by 31 here so that we don't get larger than
572 * MAX_LFS_FILESIZE
573 */
574 bitshift = 31;
575 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800576# else
Mark Fasheh5a254032007-07-20 12:56:16 -0700577 /*
578 * We are limited by the size of sector_t. Use block size, as
579 * that's what we expose to the VFS.
580 */
581 bytes = 1 << bbits;
582 trim = 1;
583 bitshift = 31;
Mark Fashehccd979b2005-12-15 14:31:24 -0800584# endif
585#endif
586
Mark Fasheh5a254032007-07-20 12:56:16 -0700587 /*
588 * Trim by a whole cluster when we can actually approach the
589 * on-disk limits. Otherwise we can overflow i_clusters when
590 * an extent start is at the max offset.
591 */
592 return (((unsigned long long)bytes) << bitshift) - trim;
Mark Fashehccd979b2005-12-15 14:31:24 -0800593}
594
595static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
596{
597 int incompat_features;
598 int ret = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800599 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800600 struct ocfs2_super *osb = OCFS2_SB(sb);
601
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200602 lock_kernel();
603
Tiger Yangc0123ad2007-09-08 00:16:10 +0800604 if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800605 ret = -EINVAL;
606 goto out;
607 }
608
609 if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800610 (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800611 ret = -EINVAL;
612 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
613 goto out;
614 }
615
616 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800617 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800618 ret = -EINVAL;
619 mlog(ML_ERROR, "Cannot change data mode on remount\n");
620 goto out;
621 }
622
Joel Becker12462f12008-09-03 20:03:40 -0700623 /* Probably don't want this on remount; it might
624 * mess with other nodes */
625 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
626 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
627 ret = -EINVAL;
628 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
629 goto out;
630 }
631
Mark Fashehccd979b2005-12-15 14:31:24 -0800632 /* We're going to/from readonly mode. */
633 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
Jan Kara19ece542008-08-21 20:13:17 +0200634 /* Disable quota accounting before remounting RO */
635 if (*flags & MS_RDONLY) {
636 ret = ocfs2_susp_quotas(osb, 0);
637 if (ret < 0)
638 goto out;
639 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800640 /* Lock here so the check of HARD_RO and the potential
641 * setting of SOFT_RO is atomic. */
642 spin_lock(&osb->osb_lock);
643 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
644 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
645 ret = -EROFS;
646 goto unlock_osb;
647 }
648
649 if (*flags & MS_RDONLY) {
650 mlog(0, "Going to ro mode.\n");
651 sb->s_flags |= MS_RDONLY;
652 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
653 } else {
654 mlog(0, "Making ro filesystem writeable.\n");
655
656 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
657 mlog(ML_ERROR, "Cannot remount RDWR "
658 "filesystem due to previous errors.\n");
659 ret = -EROFS;
660 goto unlock_osb;
661 }
662 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
663 if (incompat_features) {
664 mlog(ML_ERROR, "Cannot remount RDWR because "
665 "of unsupported optional features "
666 "(%x).\n", incompat_features);
667 ret = -EINVAL;
668 goto unlock_osb;
669 }
670 sb->s_flags &= ~MS_RDONLY;
671 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
672 }
673unlock_osb:
674 spin_unlock(&osb->osb_lock);
Jan Kara19ece542008-08-21 20:13:17 +0200675 /* Enable quota accounting after remounting RW */
676 if (!ret && !(*flags & MS_RDONLY)) {
677 if (sb_any_quota_suspended(sb))
678 ret = ocfs2_susp_quotas(osb, 1);
679 else
680 ret = ocfs2_enable_quotas(osb);
681 if (ret < 0) {
682 /* Return back changes... */
683 spin_lock(&osb->osb_lock);
684 sb->s_flags |= MS_RDONLY;
685 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
686 spin_unlock(&osb->osb_lock);
687 goto out;
688 }
689 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800690 }
691
692 if (!ret) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800693 /* Only save off the new mount options in case of a successful
694 * remount. */
Tiger Yanga68979b2008-11-14 11:17:52 +0800695 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
696 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800697 osb->s_mount_opt = parsed_options.mount_opt;
698 osb->s_atime_quantum = parsed_options.atime_quantum;
699 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -0800700 if (parsed_options.commit_interval)
701 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fashehe001e792007-11-07 14:21:45 -0800702
703 if (!ocfs2_is_hard_readonly(osb))
704 ocfs2_set_journal_params(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800705 }
706out:
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200707 unlock_kernel();
Mark Fashehccd979b2005-12-15 14:31:24 -0800708 return ret;
709}
710
711static int ocfs2_sb_probe(struct super_block *sb,
712 struct buffer_head **bh,
Joel Becker73be1922009-01-06 14:57:08 -0800713 int *sector_size,
714 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -0800715{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800716 int status, tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800717 struct ocfs1_vol_disk_hdr *hdr;
718 struct ocfs2_dinode *di;
719 int blksize;
720
721 *bh = NULL;
722
723 /* may be > 512 */
Martin K. Petersene1defc42009-05-22 17:17:49 -0400724 *sector_size = bdev_logical_block_size(sb->s_bdev);
Mark Fashehccd979b2005-12-15 14:31:24 -0800725 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
726 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
727 *sector_size, OCFS2_MAX_BLOCKSIZE);
728 status = -EINVAL;
729 goto bail;
730 }
731
732 /* Can this really happen? */
733 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
734 *sector_size = OCFS2_MIN_BLOCKSIZE;
735
736 /* check block zero for old format */
737 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
738 if (status < 0) {
739 mlog_errno(status);
740 goto bail;
741 }
742 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
743 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
744 mlog(ML_ERROR, "incompatible version: %u.%u\n",
745 hdr->major_version, hdr->minor_version);
746 status = -EINVAL;
747 }
748 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
749 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
750 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
751 hdr->signature);
752 status = -EINVAL;
753 }
754 brelse(*bh);
755 *bh = NULL;
756 if (status < 0) {
757 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
758 "upgraded before mounting with ocfs v2\n");
759 goto bail;
760 }
761
762 /*
763 * Now check at magic offset for 512, 1024, 2048, 4096
764 * blocksizes. 4096 is the maximum blocksize because it is
765 * the minimum clustersize.
766 */
767 status = -EINVAL;
768 for (blksize = *sector_size;
769 blksize <= OCFS2_MAX_BLOCKSIZE;
770 blksize <<= 1) {
771 tmpstat = ocfs2_get_sector(sb, bh,
772 OCFS2_SUPER_BLOCK_BLKNO,
773 blksize);
774 if (tmpstat < 0) {
775 status = tmpstat;
776 mlog_errno(status);
777 goto bail;
778 }
779 di = (struct ocfs2_dinode *) (*bh)->b_data;
Joel Becker73be1922009-01-06 14:57:08 -0800780 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
Jan Kara1c1d9792009-07-22 13:17:19 +0200781 spin_lock_init(&stats->b_lock);
Joel Becker73be1922009-01-06 14:57:08 -0800782 status = ocfs2_verify_volume(di, *bh, blksize, stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800783 if (status >= 0)
784 goto bail;
785 brelse(*bh);
786 *bh = NULL;
787 if (status != -EAGAIN)
788 break;
789 }
790
791bail:
792 return status;
793}
794
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800795static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
796{
797 if (ocfs2_mount_local(osb)) {
798 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
799 mlog(ML_ERROR, "Cannot heartbeat on a locally "
800 "mounted device.\n");
801 return -EINVAL;
802 }
803 }
804
Joel Beckerb61817e2008-02-01 15:08:23 -0800805 if (ocfs2_userspace_stack(osb)) {
806 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
807 mlog(ML_ERROR, "Userspace stack expected, but "
808 "o2cb heartbeat arguments passed to mount\n");
809 return -EINVAL;
810 }
811 }
812
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800813 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800814 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
815 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800816 mlog(ML_ERROR, "Heartbeat has to be started to mount "
817 "a read-write clustered device.\n");
818 return -EINVAL;
819 }
820 }
821
822 return 0;
823}
824
Joel Beckerb61817e2008-02-01 15:08:23 -0800825/*
826 * If we're using a userspace stack, mount should have passed
827 * a name that matches the disk. If not, mount should not
828 * have passed a stack.
829 */
830static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
831 struct mount_options *mopt)
832{
833 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
834 mlog(ML_ERROR,
835 "cluster stack passed to mount, but this filesystem "
836 "does not support it\n");
837 return -EINVAL;
838 }
839
840 if (ocfs2_userspace_stack(osb) &&
841 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
842 OCFS2_STACK_LABEL_LEN)) {
843 mlog(ML_ERROR,
844 "cluster stack passed to mount (\"%s\") does not "
845 "match the filesystem (\"%s\")\n",
846 mopt->cluster_stack,
847 osb->osb_cluster_stack);
848 return -EINVAL;
849 }
850
851 return 0;
852}
853
Jan Kara19ece542008-08-21 20:13:17 +0200854static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
855{
856 int type;
857 struct super_block *sb = osb->sb;
858 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
859 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
860 int status = 0;
861
862 for (type = 0; type < MAXQUOTAS; type++) {
863 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
864 continue;
865 if (unsuspend)
866 status = vfs_quota_enable(
867 sb_dqopt(sb)->files[type],
868 type, QFMT_OCFS2,
869 DQUOT_SUSPENDED);
870 else
871 status = vfs_quota_disable(sb, type,
872 DQUOT_SUSPENDED);
873 if (status < 0)
874 break;
875 }
876 if (status < 0)
877 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
878 "remount (error = %d).\n", status);
879 return status;
880}
881
882static int ocfs2_enable_quotas(struct ocfs2_super *osb)
883{
884 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
885 struct super_block *sb = osb->sb;
886 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
887 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
888 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
889 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
890 int status;
891 int type;
892
893 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
894 for (type = 0; type < MAXQUOTAS; type++) {
895 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
896 continue;
897 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
898 osb->slot_num);
899 if (!inode[type]) {
900 status = -ENOENT;
901 goto out_quota_off;
902 }
903 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
904 DQUOT_USAGE_ENABLED);
905 if (status < 0)
906 goto out_quota_off;
907 }
908
909 for (type = 0; type < MAXQUOTAS; type++)
910 iput(inode[type]);
911 return 0;
912out_quota_off:
913 ocfs2_disable_quotas(osb);
914 for (type = 0; type < MAXQUOTAS; type++)
915 iput(inode[type]);
916 mlog_errno(status);
917 return status;
918}
919
920static void ocfs2_disable_quotas(struct ocfs2_super *osb)
921{
922 int type;
923 struct inode *inode;
924 struct super_block *sb = osb->sb;
925
926 /* We mostly ignore errors in this function because there's not much
927 * we can do when we see them */
928 for (type = 0; type < MAXQUOTAS; type++) {
929 if (!sb_has_quota_loaded(sb, type))
930 continue;
931 inode = igrab(sb->s_dquot.files[type]);
932 /* Turn off quotas. This will remove all dquot structures from
933 * memory and so they will be automatically synced to global
934 * quota files */
935 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
936 DQUOT_LIMITS_ENABLED);
937 if (!inode)
938 continue;
939 iput(inode);
940 }
941}
942
943/* Handle quota on quotactl */
944static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
945 char *path, int remount)
946{
947 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
948 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
949
950 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
951 return -EINVAL;
952
953 if (remount)
954 return 0; /* Just ignore it has been handled in
955 * ocfs2_remount() */
956 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
957 format_id, DQUOT_LIMITS_ENABLED);
958}
959
960/* Handle quota off quotactl */
961static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
962{
963 if (remount)
964 return 0; /* Ignore now and handle later in
965 * ocfs2_remount() */
966 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
967}
968
969static struct quotactl_ops ocfs2_quotactl_ops = {
970 .quota_on = ocfs2_quota_on,
971 .quota_off = ocfs2_quota_off,
972 .quota_sync = vfs_quota_sync,
973 .get_info = vfs_get_dqinfo,
974 .set_info = vfs_set_dqinfo,
975 .get_dqblk = vfs_get_dqblk,
976 .set_dqblk = vfs_set_dqblk,
977};
978
Mark Fashehccd979b2005-12-15 14:31:24 -0800979static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
980{
981 struct dentry *root;
982 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800983 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800984 struct inode *inode = NULL;
985 struct ocfs2_super *osb = NULL;
986 struct buffer_head *bh = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800987 char nodestr[8];
Joel Becker73be1922009-01-06 14:57:08 -0800988 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -0800989
990 mlog_entry("%p, %p, %i", sb, data, silent);
991
Tiger Yangc0123ad2007-09-08 00:16:10 +0800992 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800993 status = -EINVAL;
994 goto read_super_error;
995 }
996
997 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -0800998 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800999 if (status < 0) {
1000 mlog(ML_ERROR, "superblock probe failed!\n");
1001 goto read_super_error;
1002 }
1003
Joel Becker73be1922009-01-06 14:57:08 -08001004 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001005 osb = OCFS2_SB(sb);
1006 if (status < 0) {
1007 mlog_errno(status);
1008 goto read_super_error;
1009 }
1010 brelse(bh);
1011 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001012
1013 if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
1014 parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1015
Tiger Yangc0123ad2007-09-08 00:16:10 +08001016 osb->s_mount_opt = parsed_options.mount_opt;
1017 osb->s_atime_quantum = parsed_options.atime_quantum;
1018 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001019 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh9c7af402008-07-28 18:02:53 -07001020 osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
1021 osb->local_alloc_bits = osb->local_alloc_default_bits;
Jan Kara19ece542008-08-21 20:13:17 +02001022 if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA &&
1023 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1024 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1025 status = -EINVAL;
1026 mlog(ML_ERROR, "User quotas were requested, but this "
1027 "filesystem does not have the feature enabled.\n");
1028 goto read_super_error;
1029 }
1030 if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1031 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1032 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1033 status = -EINVAL;
1034 mlog(ML_ERROR, "Group quotas were requested, but this "
1035 "filesystem does not have the feature enabled.\n");
1036 goto read_super_error;
1037 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001038
Joel Beckerb61817e2008-02-01 15:08:23 -08001039 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1040 if (status)
1041 goto read_super_error;
1042
Mark Fashehccd979b2005-12-15 14:31:24 -08001043 sb->s_magic = OCFS2_SUPER_MAGIC;
1044
Tiger Yanga68979b2008-11-14 11:17:52 +08001045 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1046 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1047
Mark Fashehccd979b2005-12-15 14:31:24 -08001048 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1049 * heartbeat=none */
1050 if (bdev_read_only(sb->s_bdev)) {
1051 if (!(sb->s_flags & MS_RDONLY)) {
1052 status = -EACCES;
1053 mlog(ML_ERROR, "Readonly device detected but readonly "
1054 "mount was not specified.\n");
1055 goto read_super_error;
1056 }
1057
1058 /* You should not be able to start a local heartbeat
1059 * on a readonly device. */
1060 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1061 status = -EROFS;
1062 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1063 "device.\n");
1064 goto read_super_error;
1065 }
1066
1067 status = ocfs2_check_journals_nolocks(osb);
1068 if (status < 0) {
1069 if (status == -EROFS)
1070 mlog(ML_ERROR, "Recovery required on readonly "
1071 "file system, but write access is "
1072 "unavailable.\n");
1073 else
1074 mlog_errno(status);
1075 goto read_super_error;
1076 }
1077
1078 ocfs2_set_ro_flag(osb, 1);
1079
1080 printk(KERN_NOTICE "Readonly device detected. No cluster "
1081 "services will be utilized for this mount. Recovery "
1082 "will be skipped.\n");
1083 }
1084
1085 if (!ocfs2_is_hard_readonly(osb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001086 if (sb->s_flags & MS_RDONLY)
1087 ocfs2_set_ro_flag(osb, 0);
1088 }
1089
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001090 status = ocfs2_verify_heartbeat(osb);
1091 if (status < 0) {
1092 mlog_errno(status);
1093 goto read_super_error;
1094 }
1095
Mark Fashehccd979b2005-12-15 14:31:24 -08001096 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1097 ocfs2_debugfs_root);
1098 if (!osb->osb_debug_root) {
1099 status = -EINVAL;
1100 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1101 goto read_super_error;
1102 }
1103
Sunil Mushran50397502008-12-17 14:17:43 -08001104 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1105 osb->osb_debug_root,
1106 osb,
1107 &ocfs2_osb_debug_fops);
1108 if (!osb->osb_ctxt) {
1109 status = -EINVAL;
1110 mlog_errno(status);
1111 goto read_super_error;
1112 }
1113
Joel Becker73be1922009-01-06 14:57:08 -08001114 if (ocfs2_meta_ecc(osb)) {
1115 status = ocfs2_blockcheck_stats_debugfs_install(
1116 &osb->osb_ecc_stats,
1117 osb->osb_debug_root);
1118 if (status) {
1119 mlog(ML_ERROR,
1120 "Unable to create blockcheck statistics "
1121 "files\n");
1122 goto read_super_error;
1123 }
1124 }
1125
Mark Fashehccd979b2005-12-15 14:31:24 -08001126 status = ocfs2_mount_volume(sb);
1127 if (osb->root_inode)
1128 inode = igrab(osb->root_inode);
1129
1130 if (status < 0)
1131 goto read_super_error;
1132
1133 if (!inode) {
1134 status = -EIO;
1135 mlog_errno(status);
1136 goto read_super_error;
1137 }
1138
1139 root = d_alloc_root(inode);
1140 if (!root) {
1141 status = -ENOMEM;
1142 mlog_errno(status);
1143 goto read_super_error;
1144 }
1145
1146 sb->s_root = root;
1147
1148 ocfs2_complete_mount_recovery(osb);
1149
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001150 if (ocfs2_mount_local(osb))
1151 snprintf(nodestr, sizeof(nodestr), "local");
1152 else
Joel Becker19fdb622008-01-30 15:38:24 -08001153 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001154
1155 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001156 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001157 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001158 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1159 "ordered");
1160
1161 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1162 wake_up(&osb->osb_mount_event);
1163
Jan Kara19ece542008-08-21 20:13:17 +02001164 /* Now we can initialize quotas because we can afford to wait
1165 * for cluster locks recovery now. That also means that truncation
1166 * log recovery can happen but that waits for proper quota setup */
1167 if (!(sb->s_flags & MS_RDONLY)) {
1168 status = ocfs2_enable_quotas(osb);
1169 if (status < 0) {
1170 /* We have to err-out specially here because
1171 * s_root is already set */
1172 mlog_errno(status);
1173 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1174 wake_up(&osb->osb_mount_event);
1175 mlog_exit(status);
1176 return status;
1177 }
1178 }
1179
1180 ocfs2_complete_quota_recovery(osb);
1181
1182 /* Now we wake up again for processes waiting for quotas */
1183 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1184 wake_up(&osb->osb_mount_event);
1185
Sunil Mushrandf152c22009-06-22 11:40:07 -07001186 /* Start this when the mount is almost sure of being successful */
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04001187 ocfs2_orphan_scan_start(osb);
Sunil Mushrandf152c22009-06-22 11:40:07 -07001188
Mark Fashehccd979b2005-12-15 14:31:24 -08001189 mlog_exit(status);
1190 return status;
1191
1192read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001193 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001194
1195 if (inode)
1196 iput(inode);
1197
1198 if (osb) {
1199 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1200 wake_up(&osb->osb_mount_event);
1201 ocfs2_dismount_volume(sb, 1);
1202 }
1203
1204 mlog_exit(status);
1205 return status;
1206}
1207
David Howells454e2392006-06-23 02:02:57 -07001208static int ocfs2_get_sb(struct file_system_type *fs_type,
1209 int flags,
1210 const char *dev_name,
1211 void *data,
1212 struct vfsmount *mnt)
Mark Fashehccd979b2005-12-15 14:31:24 -08001213{
David Howells454e2392006-06-23 02:02:57 -07001214 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1215 mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -08001216}
1217
Jan Karaf7b1aa62009-07-20 12:12:36 +02001218static void ocfs2_kill_sb(struct super_block *sb)
1219{
1220 struct ocfs2_super *osb = OCFS2_SB(sb);
1221
Jan Kara5fd13182009-07-30 17:01:53 +02001222 /* Failed mount? */
1223 if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1224 goto out;
1225
Jan Karaf7b1aa62009-07-20 12:12:36 +02001226 /* Prevent further queueing of inode drop events */
1227 spin_lock(&dentry_list_lock);
1228 ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1229 spin_unlock(&dentry_list_lock);
1230 /* Wait for work to finish and/or remove it */
1231 cancel_work_sync(&osb->dentry_lock_work);
Jan Kara5fd13182009-07-30 17:01:53 +02001232out:
Jan Karaf7b1aa62009-07-20 12:12:36 +02001233 kill_block_super(sb);
1234}
1235
Mark Fashehccd979b2005-12-15 14:31:24 -08001236static struct file_system_type ocfs2_fs_type = {
1237 .owner = THIS_MODULE,
1238 .name = "ocfs2",
1239 .get_sb = ocfs2_get_sb, /* is this called when we mount
1240 * the fs? */
Jan Karaf7b1aa62009-07-20 12:12:36 +02001241 .kill_sb = ocfs2_kill_sb,
1242
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001243 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001244 .next = NULL
1245};
1246
1247static int ocfs2_parse_options(struct super_block *sb,
1248 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001249 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001250 int is_remount)
1251{
1252 int status;
1253 char *p;
1254
1255 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1256 options ? options : "(none)");
1257
Mark Fashehd147b3d2007-11-07 14:40:36 -08001258 mopt->commit_interval = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001259 mopt->mount_opt = 0;
1260 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1261 mopt->slot = OCFS2_INVALID_SLOT;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001262 mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
Joel Beckerb61817e2008-02-01 15:08:23 -08001263 mopt->cluster_stack[0] = '\0';
Mark Fashehccd979b2005-12-15 14:31:24 -08001264
1265 if (!options) {
1266 status = 1;
1267 goto bail;
1268 }
1269
1270 while ((p = strsep(&options, ",")) != NULL) {
1271 int token, option;
1272 substring_t args[MAX_OPT_ARGS];
1273
1274 if (!*p)
1275 continue;
1276
1277 token = match_token(p, tokens, args);
1278 switch (token) {
1279 case Opt_hb_local:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001280 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001281 break;
1282 case Opt_hb_none:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001283 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001284 break;
1285 case Opt_barrier:
1286 if (match_int(&args[0], &option)) {
1287 status = 0;
1288 goto bail;
1289 }
1290 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001291 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001292 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001293 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001294 break;
1295 case Opt_intr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001296 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001297 break;
1298 case Opt_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001299 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001300 break;
1301 case Opt_err_panic:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001302 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001303 break;
1304 case Opt_err_ro:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001305 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001306 break;
1307 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001308 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001309 break;
1310 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001311 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001312 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001313 case Opt_user_xattr:
1314 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1315 break;
1316 case Opt_nouser_xattr:
1317 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1318 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001319 case Opt_atime_quantum:
1320 if (match_int(&args[0], &option)) {
1321 status = 0;
1322 goto bail;
1323 }
1324 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001325 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001326 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001327 case Opt_slot:
1328 option = 0;
1329 if (match_int(&args[0], &option)) {
1330 status = 0;
1331 goto bail;
1332 }
1333 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001334 mopt->slot = (s16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001335 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001336 case Opt_commit:
1337 option = 0;
1338 if (match_int(&args[0], &option)) {
1339 status = 0;
1340 goto bail;
1341 }
1342 if (option < 0)
1343 return 0;
1344 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001345 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001346 mopt->commit_interval = HZ * option;
1347 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001348 case Opt_localalloc:
1349 option = 0;
1350 if (match_int(&args[0], &option)) {
1351 status = 0;
1352 goto bail;
1353 }
1354 if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1355 mopt->localalloc_opt = option;
1356 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001357 case Opt_localflocks:
1358 /*
1359 * Changing this during remount could race
1360 * flock() requests, or "unbalance" existing
1361 * ones (e.g., a lock is taken in one mode but
1362 * dropped in the other). If users care enough
1363 * to flip locking modes during remount, we
1364 * could add a "local" flag to individual
1365 * flock structures for proper tracking of
1366 * state.
1367 */
1368 if (!is_remount)
1369 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1370 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001371 case Opt_stack:
1372 /* Check both that the option we were passed
1373 * is of the right length and that it is a proper
1374 * string of the right length.
1375 */
1376 if (((args[0].to - args[0].from) !=
1377 OCFS2_STACK_LABEL_LEN) ||
1378 (strnlen(args[0].from,
1379 OCFS2_STACK_LABEL_LEN) !=
1380 OCFS2_STACK_LABEL_LEN)) {
1381 mlog(ML_ERROR,
1382 "Invalid cluster_stack option\n");
1383 status = 0;
1384 goto bail;
1385 }
1386 memcpy(mopt->cluster_stack, args[0].from,
1387 OCFS2_STACK_LABEL_LEN);
1388 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1389 break;
Joel Becker12462f12008-09-03 20:03:40 -07001390 case Opt_inode64:
1391 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1392 break;
Jan Kara19ece542008-08-21 20:13:17 +02001393 case Opt_usrquota:
1394 /* We check only on remount, otherwise features
1395 * aren't yet initialized. */
1396 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1397 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1398 mlog(ML_ERROR, "User quota requested but "
1399 "filesystem feature is not set\n");
1400 status = 0;
1401 goto bail;
1402 }
1403 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1404 break;
1405 case Opt_grpquota:
1406 if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1407 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1408 mlog(ML_ERROR, "Group quota requested but "
1409 "filesystem feature is not set\n");
1410 status = 0;
1411 goto bail;
1412 }
1413 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1414 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001415#ifdef CONFIG_OCFS2_FS_POSIX_ACL
1416 case Opt_acl:
1417 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1418 break;
1419 case Opt_noacl:
1420 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1421 break;
1422#else
1423 case Opt_acl:
1424 case Opt_noacl:
1425 printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
1426 break;
1427#endif
Mark Fashehccd979b2005-12-15 14:31:24 -08001428 default:
1429 mlog(ML_ERROR,
1430 "Unrecognized mount option \"%s\" "
1431 "or missing value\n", p);
1432 status = 0;
1433 goto bail;
1434 }
1435 }
1436
1437 status = 1;
1438
1439bail:
1440 mlog_exit(status);
1441 return status;
1442}
1443
Sunil Mushrand5500712007-09-06 13:34:16 -07001444static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1445{
1446 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1447 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001448 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001449
1450 if (opts & OCFS2_MOUNT_HB_LOCAL)
1451 seq_printf(s, ",_netdev,heartbeat=local");
1452 else
1453 seq_printf(s, ",heartbeat=none");
1454
1455 if (opts & OCFS2_MOUNT_NOINTR)
1456 seq_printf(s, ",nointr");
1457
1458 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1459 seq_printf(s, ",data=writeback");
1460 else
1461 seq_printf(s, ",data=ordered");
1462
1463 if (opts & OCFS2_MOUNT_BARRIER)
1464 seq_printf(s, ",barrier=1");
1465
1466 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1467 seq_printf(s, ",errors=panic");
1468 else
1469 seq_printf(s, ",errors=remount-ro");
1470
1471 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1472 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1473
1474 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1475 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1476
Mark Fashehd147b3d2007-11-07 14:40:36 -08001477 if (osb->osb_commit_interval)
1478 seq_printf(s, ",commit=%u",
1479 (unsigned) (osb->osb_commit_interval / HZ));
1480
Mark Fashehebcee4b2008-07-28 14:55:20 -07001481 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1482 if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1483 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001484
Mark Fasheh53fc6222007-12-20 16:49:04 -08001485 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1486 seq_printf(s, ",localflocks,");
1487
Joel Beckerb61817e2008-02-01 15:08:23 -08001488 if (osb->osb_cluster_stack[0])
1489 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1490 osb->osb_cluster_stack);
Jan Kara19ece542008-08-21 20:13:17 +02001491 if (opts & OCFS2_MOUNT_USRQUOTA)
1492 seq_printf(s, ",usrquota");
1493 if (opts & OCFS2_MOUNT_GRPQUOTA)
1494 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001495
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001496 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1497 seq_printf(s, ",nouser_xattr");
1498 else
1499 seq_printf(s, ",user_xattr");
1500
Joel Becker12462f12008-09-03 20:03:40 -07001501 if (opts & OCFS2_MOUNT_INODE64)
1502 seq_printf(s, ",inode64");
1503
Tiger Yanga68979b2008-11-14 11:17:52 +08001504#ifdef CONFIG_OCFS2_FS_POSIX_ACL
1505 if (opts & OCFS2_MOUNT_POSIX_ACL)
1506 seq_printf(s, ",acl");
1507 else
1508 seq_printf(s, ",noacl");
1509#endif
1510
Sunil Mushrand5500712007-09-06 13:34:16 -07001511 return 0;
1512}
1513
Mark Fashehccd979b2005-12-15 14:31:24 -08001514static int __init ocfs2_init(void)
1515{
1516 int status;
1517
1518 mlog_entry_void();
1519
1520 ocfs2_print_version();
1521
Mark Fashehccd979b2005-12-15 14:31:24 -08001522 status = init_ocfs2_uptodate_cache();
1523 if (status < 0) {
1524 mlog_errno(status);
1525 goto leave;
1526 }
1527
1528 status = ocfs2_initialize_mem_caches();
1529 if (status < 0) {
1530 mlog_errno(status);
1531 goto leave;
1532 }
1533
1534 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1535 if (!ocfs2_wq) {
1536 status = -ENOMEM;
1537 goto leave;
1538 }
1539
Mark Fashehccd979b2005-12-15 14:31:24 -08001540 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1541 if (!ocfs2_debugfs_root) {
1542 status = -EFAULT;
1543 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1544 }
1545
Mark Fasheh171bf932008-10-20 15:36:47 +02001546 status = ocfs2_quota_setup();
1547 if (status)
1548 goto leave;
1549
Joel Becker63e0c482008-01-30 16:58:36 -08001550 ocfs2_set_locking_protocol();
1551
Jan Kara9e33d692008-08-25 19:56:50 +02001552 status = register_quota_format(&ocfs2_quota_format);
Mark Fashehccd979b2005-12-15 14:31:24 -08001553leave:
1554 if (status < 0) {
Mark Fasheh171bf932008-10-20 15:36:47 +02001555 ocfs2_quota_shutdown();
Mark Fashehccd979b2005-12-15 14:31:24 -08001556 ocfs2_free_mem_caches();
1557 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001558 }
1559
1560 mlog_exit(status);
1561
1562 if (status >= 0) {
1563 return register_filesystem(&ocfs2_fs_type);
1564 } else
1565 return -1;
1566}
1567
1568static void __exit ocfs2_exit(void)
1569{
1570 mlog_entry_void();
1571
Mark Fasheh171bf932008-10-20 15:36:47 +02001572 ocfs2_quota_shutdown();
1573
Mark Fashehccd979b2005-12-15 14:31:24 -08001574 if (ocfs2_wq) {
1575 flush_workqueue(ocfs2_wq);
1576 destroy_workqueue(ocfs2_wq);
1577 }
1578
Jan Kara9e33d692008-08-25 19:56:50 +02001579 unregister_quota_format(&ocfs2_quota_format);
1580
Mark Fashehccd979b2005-12-15 14:31:24 -08001581 debugfs_remove(ocfs2_debugfs_root);
1582
1583 ocfs2_free_mem_caches();
1584
1585 unregister_filesystem(&ocfs2_fs_type);
1586
Mark Fashehccd979b2005-12-15 14:31:24 -08001587 exit_ocfs2_uptodate_cache();
1588
1589 mlog_exit_void();
1590}
1591
1592static void ocfs2_put_super(struct super_block *sb)
1593{
1594 mlog_entry("(0x%p)\n", sb);
1595
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001596 lock_kernel();
1597
Mark Fashehccd979b2005-12-15 14:31:24 -08001598 ocfs2_sync_blockdev(sb);
1599 ocfs2_dismount_volume(sb, 0);
1600
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001601 unlock_kernel();
1602
Mark Fashehccd979b2005-12-15 14:31:24 -08001603 mlog_exit_void();
1604}
1605
David Howells726c3342006-06-23 02:02:58 -07001606static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001607{
1608 struct ocfs2_super *osb;
1609 u32 numbits, freebits;
1610 int status;
1611 struct ocfs2_dinode *bm_lock;
1612 struct buffer_head *bh = NULL;
1613 struct inode *inode = NULL;
1614
David Howells726c3342006-06-23 02:02:58 -07001615 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001616
David Howells726c3342006-06-23 02:02:58 -07001617 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001618
1619 inode = ocfs2_get_system_file_inode(osb,
1620 GLOBAL_BITMAP_SYSTEM_INODE,
1621 OCFS2_INVALID_SLOT);
1622 if (!inode) {
1623 mlog(ML_ERROR, "failed to get bitmap inode\n");
1624 status = -EIO;
1625 goto bail;
1626 }
1627
Mark Fashehe63aecb62007-10-18 15:30:42 -07001628 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001629 if (status < 0) {
1630 mlog_errno(status);
1631 goto bail;
1632 }
1633
1634 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1635
1636 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1637 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1638
1639 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001640 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001641 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1642 buf->f_blocks = ((sector_t) numbits) *
1643 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1644 buf->f_bfree = ((sector_t) freebits) *
1645 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1646 buf->f_bavail = buf->f_bfree;
1647 buf->f_files = numbits;
1648 buf->f_ffree = freebits;
1649
1650 brelse(bh);
1651
Mark Fashehe63aecb62007-10-18 15:30:42 -07001652 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001653 status = 0;
1654bail:
1655 if (inode)
1656 iput(inode);
1657
1658 mlog_exit(status);
1659
1660 return status;
1661}
1662
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001663static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001664{
1665 struct ocfs2_inode_info *oi = data;
1666
Christoph Lametera35afb82007-05-16 22:10:57 -07001667 oi->ip_flags = 0;
1668 oi->ip_open_count = 0;
1669 spin_lock_init(&oi->ip_lock);
1670 ocfs2_extent_map_init(&oi->vfs_inode);
1671 INIT_LIST_HEAD(&oi->ip_io_markers);
Christoph Lametera35afb82007-05-16 22:10:57 -07001672 oi->ip_dir_start_lookup = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001673
Christoph Lametera35afb82007-05-16 22:10:57 -07001674 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001675 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001676 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001677
Christoph Lametera35afb82007-05-16 22:10:57 -07001678 oi->ip_blkno = 0ULL;
1679 oi->ip_clusters = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001680
Christoph Lametera35afb82007-05-16 22:10:57 -07001681 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001682 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001683 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001684
Joel Becker8cb471e2009-02-10 20:00:41 -08001685 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
Joel Becker6e5a3d72009-02-10 19:00:37 -08001686 &ocfs2_inode_caching_ops);
Mark Fashehccd979b2005-12-15 14:31:24 -08001687
Christoph Lametera35afb82007-05-16 22:10:57 -07001688 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001689}
1690
1691static int ocfs2_initialize_mem_caches(void)
1692{
1693 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001694 sizeof(struct ocfs2_inode_info),
1695 0,
1696 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1697 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001698 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001699 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1700 sizeof(struct ocfs2_dquot),
1701 0,
1702 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1703 SLAB_MEM_SPREAD),
1704 NULL);
1705 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1706 sizeof(struct ocfs2_quota_chunk),
1707 0,
1708 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1709 NULL);
1710 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1711 !ocfs2_qf_chunk_cachep) {
1712 if (ocfs2_inode_cachep)
1713 kmem_cache_destroy(ocfs2_inode_cachep);
1714 if (ocfs2_dquot_cachep)
1715 kmem_cache_destroy(ocfs2_dquot_cachep);
1716 if (ocfs2_qf_chunk_cachep)
1717 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001718 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001719 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001720
Mark Fashehccd979b2005-12-15 14:31:24 -08001721 return 0;
1722}
1723
1724static void ocfs2_free_mem_caches(void)
1725{
1726 if (ocfs2_inode_cachep)
1727 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001728 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001729
1730 if (ocfs2_dquot_cachep)
1731 kmem_cache_destroy(ocfs2_dquot_cachep);
1732 ocfs2_dquot_cachep = NULL;
1733
1734 if (ocfs2_qf_chunk_cachep)
1735 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1736 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001737}
1738
1739static int ocfs2_get_sector(struct super_block *sb,
1740 struct buffer_head **bh,
1741 int block,
1742 int sect_size)
1743{
1744 if (!sb_set_blocksize(sb, sect_size)) {
1745 mlog(ML_ERROR, "unable to set blocksize\n");
1746 return -EIO;
1747 }
1748
1749 *bh = sb_getblk(sb, block);
1750 if (!*bh) {
1751 mlog_errno(-EIO);
1752 return -EIO;
1753 }
1754 lock_buffer(*bh);
1755 if (!buffer_dirty(*bh))
1756 clear_buffer_uptodate(*bh);
1757 unlock_buffer(*bh);
1758 ll_rw_block(READ, 1, bh);
1759 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001760 if (!buffer_uptodate(*bh)) {
1761 mlog_errno(-EIO);
1762 brelse(*bh);
1763 *bh = NULL;
1764 return -EIO;
1765 }
1766
Mark Fashehccd979b2005-12-15 14:31:24 -08001767 return 0;
1768}
1769
Mark Fashehccd979b2005-12-15 14:31:24 -08001770static int ocfs2_mount_volume(struct super_block *sb)
1771{
1772 int status = 0;
1773 int unlock_super = 0;
1774 struct ocfs2_super *osb = OCFS2_SB(sb);
1775
1776 mlog_entry_void();
1777
1778 if (ocfs2_is_hard_readonly(osb))
1779 goto leave;
1780
Mark Fashehccd979b2005-12-15 14:31:24 -08001781 status = ocfs2_dlm_init(osb);
1782 if (status < 0) {
1783 mlog_errno(status);
1784 goto leave;
1785 }
1786
Mark Fashehccd979b2005-12-15 14:31:24 -08001787 status = ocfs2_super_lock(osb, 1);
1788 if (status < 0) {
1789 mlog_errno(status);
1790 goto leave;
1791 }
1792 unlock_super = 1;
1793
1794 /* This will load up the node map and add ourselves to it. */
1795 status = ocfs2_find_slot(osb);
1796 if (status < 0) {
1797 mlog_errno(status);
1798 goto leave;
1799 }
1800
Mark Fashehccd979b2005-12-15 14:31:24 -08001801 /* load all node-local system inodes */
1802 status = ocfs2_init_local_system_inodes(osb);
1803 if (status < 0) {
1804 mlog_errno(status);
1805 goto leave;
1806 }
1807
1808 status = ocfs2_check_volume(osb);
1809 if (status < 0) {
1810 mlog_errno(status);
1811 goto leave;
1812 }
1813
1814 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001815 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001816 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001817
Mark Fashehccd979b2005-12-15 14:31:24 -08001818leave:
1819 if (unlock_super)
1820 ocfs2_super_unlock(osb, 1);
1821
1822 mlog_exit(status);
1823 return status;
1824}
1825
Mark Fashehccd979b2005-12-15 14:31:24 -08001826static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1827{
Joel Becker286eaa92008-02-01 15:03:57 -08001828 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001829 struct ocfs2_super *osb = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001830 char nodestr[8];
Mark Fashehccd979b2005-12-15 14:31:24 -08001831
1832 mlog_entry("(0x%p)\n", sb);
1833
1834 BUG_ON(!sb);
1835 osb = OCFS2_SB(sb);
1836 BUG_ON(!osb);
1837
Sunil Mushran50397502008-12-17 14:17:43 -08001838 debugfs_remove(osb->osb_ctxt);
1839
Jan Karaf7b1aa62009-07-20 12:12:36 +02001840 /*
1841 * Flush inode dropping work queue so that deletes are
1842 * performed while the filesystem is still working
1843 */
1844 ocfs2_drop_all_dl_inodes(osb);
1845
Sunil Mushran692684e2009-06-19 16:53:17 -07001846 /* Orphan scan should be stopped as early as possible */
1847 ocfs2_orphan_scan_stop(osb);
1848
Jan Kara19ece542008-08-21 20:13:17 +02001849 ocfs2_disable_quotas(osb);
1850
Mark Fashehccd979b2005-12-15 14:31:24 -08001851 ocfs2_shutdown_local_alloc(osb);
1852
1853 ocfs2_truncate_log_shutdown(osb);
1854
Joel Becker553abd02008-02-01 12:03:57 -08001855 /* This will disable recovery and flush any recovery work. */
1856 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001857
1858 ocfs2_journal_shutdown(osb);
1859
1860 ocfs2_sync_blockdev(sb);
1861
Tao Ma374a2632009-08-24 11:13:37 +08001862 ocfs2_purge_refcount_trees(osb);
1863
Joel Becker4670c462008-02-01 14:39:35 -08001864 /* No cluster connection means we've failed during mount, so skip
1865 * all the steps which depended on that to complete. */
1866 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001867 tmp = ocfs2_super_lock(osb, 1);
1868 if (tmp < 0) {
1869 mlog_errno(tmp);
1870 return;
1871 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001872 }
1873
Mark Fasheh19b613d2007-10-04 14:47:09 -07001874 if (osb->slot_num != OCFS2_INVALID_SLOT)
1875 ocfs2_put_slot(osb);
1876
Joel Becker4670c462008-02-01 14:39:35 -08001877 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001878 ocfs2_super_unlock(osb, 1);
1879
Mark Fashehccd979b2005-12-15 14:31:24 -08001880 ocfs2_release_system_inodes(osb);
1881
Joel Becker6953b4c2008-01-29 16:59:56 -08001882 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001883 * If we're dismounting due to mount error, mount.ocfs2 will clean
1884 * up heartbeat. If we're a local mount, there is no heartbeat.
1885 * If we failed before we got a uuid_str yet, we can't stop
1886 * heartbeat. Otherwise, do it.
1887 */
1888 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
Joel Becker286eaa92008-02-01 15:03:57 -08001889 hangup_needed = 1;
1890
1891 if (osb->cconn)
1892 ocfs2_dlm_shutdown(osb, hangup_needed);
1893
Joel Becker73be1922009-01-06 14:57:08 -08001894 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Joel Becker286eaa92008-02-01 15:03:57 -08001895 debugfs_remove(osb->osb_debug_root);
1896
1897 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001898 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001899
1900 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1901
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001902 if (ocfs2_mount_local(osb))
1903 snprintf(nodestr, sizeof(nodestr), "local");
1904 else
Joel Becker19fdb622008-01-30 15:38:24 -08001905 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001906
1907 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1908 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001909
1910 ocfs2_delete_osb(osb);
1911 kfree(osb);
1912 sb->s_dev = 0;
1913 sb->s_fs_info = NULL;
1914}
1915
1916static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1917 unsigned uuid_bytes)
1918{
1919 int i, ret;
1920 char *ptr;
1921
1922 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1923
Robert P. J. Daycd861282006-12-13 00:34:52 -08001924 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001925 if (osb->uuid_str == NULL)
1926 return -ENOMEM;
1927
Mark Fashehccd979b2005-12-15 14:31:24 -08001928 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1929 /* print with null */
1930 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1931 if (ret != 2) /* drop super cleans up */
1932 return -EINVAL;
1933 /* then only advance past the last char */
1934 ptr += 2;
1935 }
1936
1937 return 0;
1938}
1939
1940static int ocfs2_initialize_super(struct super_block *sb,
1941 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08001942 int sector_size,
1943 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08001944{
Denis Chengbddb8eb32007-09-27 02:10:04 +08001945 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07001946 int i, cbits, bbits;
1947 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08001948 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001949 struct ocfs2_journal *journal;
1950 __le32 uuid_net_key;
1951 struct ocfs2_super *osb;
1952
1953 mlog_entry_void();
1954
Robert P. J. Daycd861282006-12-13 00:34:52 -08001955 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001956 if (!osb) {
1957 status = -ENOMEM;
1958 mlog_errno(status);
1959 goto bail;
1960 }
1961
1962 sb->s_fs_info = osb;
1963 sb->s_op = &ocfs2_sops;
1964 sb->s_export_op = &ocfs2_export_ops;
Jan Kara19ece542008-08-21 20:13:17 +02001965 sb->s_qcop = &ocfs2_quotactl_ops;
1966 sb->dq_op = &ocfs2_quota_operations;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001967 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07001968 sb->s_time_gran = 1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001969 sb->s_flags |= MS_NOATIME;
1970 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07001971 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1972 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1973 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001974
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001975 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
1976
1977 for (i = 0; i < 3; i++)
1978 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
1979 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1980
Mark Fashehccd979b2005-12-15 14:31:24 -08001981 osb->sb = sb;
1982 /* Save off for ocfs2_rw_direct */
1983 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01001984 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001985
Mark Fasheh34d024f2007-09-24 15:56:19 -07001986 spin_lock_init(&osb->dc_task_lock);
1987 init_waitqueue_head(&osb->dc_event);
1988 osb->dc_work_sequence = 0;
1989 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001990 INIT_LIST_HEAD(&osb->blocked_lock_list);
1991 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001992 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08001993 spin_lock_init(&osb->osb_xattr_lock);
Tao Ma4d0ddb22008-03-05 16:11:46 +08001994 ocfs2_init_inode_steal_slot(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001995
1996 atomic_set(&osb->alloc_stats.moves, 0);
1997 atomic_set(&osb->alloc_stats.local_data, 0);
1998 atomic_set(&osb->alloc_stats.bitmap_data, 0);
1999 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2000 atomic_set(&osb->alloc_stats.bg_extends, 0);
2001
Joel Becker73be1922009-01-06 14:57:08 -08002002 /* Copy the blockcheck stats from the superblock probe */
2003 osb->osb_ecc_stats = *stats;
2004
Mark Fashehccd979b2005-12-15 14:31:24 -08002005 ocfs2_init_node_maps(osb);
2006
2007 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2008 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2009
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04002010 ocfs2_orphan_scan_init(osb);
2011
Joel Becker553abd02008-02-01 12:03:57 -08002012 status = ocfs2_recovery_init(osb);
2013 if (status) {
2014 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2015 mlog_errno(status);
2016 goto bail;
2017 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002018
2019 init_waitqueue_head(&osb->checkpoint_event);
2020 atomic_set(&osb->needs_checkpoint, 0);
2021
Tiger Yang7f1a37e2006-11-15 15:48:42 +08002022 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2023
Mark Fashehccd979b2005-12-15 14:31:24 -08002024 osb->slot_num = OCFS2_INVALID_SLOT;
2025
Tiger Yang8154da32008-08-18 17:11:46 +08002026 osb->s_xattr_inline_size = le16_to_cpu(
2027 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002028
Mark Fashehccd979b2005-12-15 14:31:24 -08002029 osb->local_alloc_state = OCFS2_LA_UNUSED;
2030 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002031 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002032
Mark Fashehccd979b2005-12-15 14:31:24 -08002033 init_waitqueue_head(&osb->osb_mount_event);
2034
2035 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2036 if (!osb->vol_label) {
2037 mlog(ML_ERROR, "unable to alloc vol label\n");
2038 status = -ENOMEM;
2039 goto bail;
2040 }
2041
Mark Fashehccd979b2005-12-15 14:31:24 -08002042 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2043 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2044 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2045 osb->max_slots);
2046 status = -EINVAL;
2047 goto bail;
2048 }
Sunil Mushran781ee3e2006-04-27 16:41:31 -07002049 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
Mark Fashehccd979b2005-12-15 14:31:24 -08002050
Sunil Mushran539d8262008-07-14 17:31:10 -07002051 osb->slot_recovery_generations =
2052 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2053 GFP_KERNEL);
2054 if (!osb->slot_recovery_generations) {
2055 status = -ENOMEM;
2056 mlog_errno(status);
2057 goto bail;
2058 }
2059
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002060 init_waitqueue_head(&osb->osb_wipe_event);
2061 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2062 sizeof(*osb->osb_orphan_wipes),
2063 GFP_KERNEL);
2064 if (!osb->osb_orphan_wipes) {
2065 status = -ENOMEM;
2066 mlog_errno(status);
2067 goto bail;
2068 }
2069
Tao Ma374a2632009-08-24 11:13:37 +08002070 osb->osb_rf_lock_tree = RB_ROOT;
2071
Mark Fashehccd979b2005-12-15 14:31:24 -08002072 osb->s_feature_compat =
2073 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2074 osb->s_feature_ro_compat =
2075 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2076 osb->s_feature_incompat =
2077 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2078
2079 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2080 mlog(ML_ERROR, "couldn't mount because of unsupported "
2081 "optional features (%x).\n", i);
2082 status = -EINVAL;
2083 goto bail;
2084 }
2085 if (!(osb->sb->s_flags & MS_RDONLY) &&
2086 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2087 mlog(ML_ERROR, "couldn't mount RDWR because of "
2088 "unsupported optional features (%x).\n", i);
2089 status = -EINVAL;
2090 goto bail;
2091 }
2092
Joel Beckerb61817e2008-02-01 15:08:23 -08002093 if (ocfs2_userspace_stack(osb)) {
2094 memcpy(osb->osb_cluster_stack,
2095 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2096 OCFS2_STACK_LABEL_LEN);
2097 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2098 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2099 mlog(ML_ERROR,
2100 "couldn't mount because of an invalid "
2101 "cluster stack label (%s) \n",
2102 osb->osb_cluster_stack);
2103 status = -EINVAL;
2104 goto bail;
2105 }
2106 } else {
2107 /* The empty string is identical with classic tools that
2108 * don't know about s_cluster_info. */
2109 osb->osb_cluster_stack[0] = '\0';
2110 }
2111
Mark Fashehccd979b2005-12-15 14:31:24 -08002112 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2113
2114 /* FIXME
2115 * This should be done in ocfs2_journal_init(), but unknown
2116 * ordering issues will cause the filesystem to crash.
2117 * If anyone wants to figure out what part of the code
2118 * refers to osb->journal before ocfs2_journal_init() is run,
2119 * be my guest.
2120 */
2121 /* initialize our journal structure */
2122
Robert P. J. Daycd861282006-12-13 00:34:52 -08002123 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002124 if (!journal) {
2125 mlog(ML_ERROR, "unable to alloc journal\n");
2126 status = -ENOMEM;
2127 goto bail;
2128 }
2129 osb->journal = journal;
2130 journal->j_osb = osb;
2131
2132 atomic_set(&journal->j_num_trans, 0);
2133 init_rwsem(&journal->j_trans_barrier);
2134 init_waitqueue_head(&journal->j_checkpointed);
2135 spin_lock_init(&journal->j_lock);
2136 journal->j_trans_id = (unsigned long) 1;
2137 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002138 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002139 journal->j_state = OCFS2_JOURNAL_FREE;
2140
Jan Karaea455f82009-01-12 23:20:31 +01002141 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2142 osb->dentry_lock_list = NULL;
2143
Mark Fashehccd979b2005-12-15 14:31:24 -08002144 /* get some pseudo constants for clustersize bits */
2145 osb->s_clustersize_bits =
2146 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2147 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2148 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2149
2150 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2151 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2152 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2153 osb->s_clustersize);
2154 status = -EINVAL;
2155 goto bail;
2156 }
2157
2158 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2159 > (u32)~0UL) {
2160 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2161 "what jbd can address in 32 bits.\n");
2162 status = -EINVAL;
2163 goto bail;
2164 }
2165
2166 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2167 sizeof(di->id2.i_super.s_uuid))) {
2168 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2169 status = -ENOMEM;
2170 goto bail;
2171 }
2172
Mark Fasheh78427042006-05-04 12:03:26 -07002173 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
Mark Fashehccd979b2005-12-15 14:31:24 -08002174
2175 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2176 osb->vol_label[63] = '\0';
2177 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2178 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2179 osb->first_cluster_group_blkno =
2180 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2181 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002182 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Mark Fashehccd979b2005-12-15 14:31:24 -08002183 mlog(0, "vol_label: %s\n", osb->vol_label);
2184 mlog(0, "uuid: %s\n", osb->uuid_str);
Mark Fashehb0697052006-03-03 10:24:33 -08002185 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2186 (unsigned long long)osb->root_blkno,
2187 (unsigned long long)osb->system_dir_blkno);
Mark Fashehccd979b2005-12-15 14:31:24 -08002188
2189 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2190 if (!osb->osb_dlm_debug) {
2191 status = -ENOMEM;
2192 mlog_errno(status);
2193 goto bail;
2194 }
2195
2196 atomic_set(&osb->vol_state, VOLUME_INIT);
2197
2198 /* load root, system_dir, and all global system inodes */
2199 status = ocfs2_init_global_system_inodes(osb);
2200 if (status < 0) {
2201 mlog_errno(status);
2202 goto bail;
2203 }
2204
2205 /*
2206 * global bitmap
2207 */
2208 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2209 OCFS2_INVALID_SLOT);
2210 if (!inode) {
2211 status = -EINVAL;
2212 mlog_errno(status);
2213 goto bail;
2214 }
2215
2216 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fashehccd979b2005-12-15 14:31:24 -08002217 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002218
Tao Mae9d578a2007-12-18 15:46:10 +08002219 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002220
2221 status = ocfs2_init_slot_info(osb);
2222 if (status < 0) {
2223 mlog_errno(status);
2224 goto bail;
2225 }
2226
Mark Fashehccd979b2005-12-15 14:31:24 -08002227bail:
2228 mlog_exit(status);
2229 return status;
2230}
2231
2232/*
2233 * will return: -EAGAIN if it is ok to keep searching for superblocks
2234 * -EINVAL if there is a bad superblock
2235 * 0 on success
2236 */
2237static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2238 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002239 u32 blksz,
2240 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002241{
2242 int status = -EAGAIN;
2243
2244 mlog_entry_void();
2245
2246 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2247 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002248 /* We have to do a raw check of the feature here */
2249 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2250 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2251 status = ocfs2_block_check_validate(bh->b_data,
2252 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002253 &di->i_check,
2254 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002255 if (status)
2256 goto out;
2257 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002258 status = -EINVAL;
2259 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2260 mlog(ML_ERROR, "found superblock with incorrect block "
2261 "size: found %u, should be %u\n",
2262 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2263 blksz);
2264 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2265 OCFS2_MAJOR_REV_LEVEL ||
2266 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2267 OCFS2_MINOR_REV_LEVEL) {
2268 mlog(ML_ERROR, "found superblock with bad version: "
2269 "found %u.%u, should be %u.%u\n",
2270 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2271 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2272 OCFS2_MAJOR_REV_LEVEL,
2273 OCFS2_MINOR_REV_LEVEL);
2274 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2275 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb0697052006-03-03 10:24:33 -08002276 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002277 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb0697052006-03-03 10:24:33 -08002278 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002279 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2280 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2281 mlog(ML_ERROR, "bad cluster size found: %u\n",
2282 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2283 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2284 mlog(ML_ERROR, "bad root_blkno: 0\n");
2285 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2286 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2287 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2288 mlog(ML_ERROR,
2289 "Superblock slots found greater than file system "
2290 "maximum: found %u, max %u\n",
2291 le16_to_cpu(di->id2.i_super.s_max_slots),
2292 OCFS2_MAX_SLOTS);
2293 } else {
2294 /* found it! */
2295 status = 0;
2296 }
2297 }
2298
Joel Beckerd030cc92008-12-11 15:04:14 -08002299out:
Mark Fashehccd979b2005-12-15 14:31:24 -08002300 mlog_exit(status);
2301 return status;
2302}
2303
2304static int ocfs2_check_volume(struct ocfs2_super *osb)
2305{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002306 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002307 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002308 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002309 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2310 * recover
2311 * ourselves. */
2312
2313 mlog_entry_void();
2314
2315 /* Init our journal object. */
2316 status = ocfs2_journal_init(osb->journal, &dirty);
2317 if (status < 0) {
2318 mlog(ML_ERROR, "Could not initialize journal!\n");
2319 goto finally;
2320 }
2321
2322 /* If the journal was unmounted cleanly then we don't want to
2323 * recover anything. Otherwise, journal_load will do that
2324 * dirty work for us :) */
2325 if (!dirty) {
2326 status = ocfs2_journal_wipe(osb->journal, 0);
2327 if (status < 0) {
2328 mlog_errno(status);
2329 goto finally;
2330 }
2331 } else {
2332 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2333 "recovering volume.\n");
2334 }
2335
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002336 local = ocfs2_mount_local(osb);
2337
Mark Fashehccd979b2005-12-15 14:31:24 -08002338 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002339 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002340 if (status < 0) {
2341 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2342 goto finally;
2343 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002344
2345 if (dirty) {
2346 /* recover my local alloc if we didn't unmount cleanly. */
2347 status = ocfs2_begin_local_alloc_recovery(osb,
2348 osb->slot_num,
2349 &local_alloc);
2350 if (status < 0) {
2351 mlog_errno(status);
2352 goto finally;
2353 }
2354 /* we complete the recovery process after we've marked
2355 * ourselves as mounted. */
2356 }
2357
2358 mlog(0, "Journal loaded.\n");
2359
2360 status = ocfs2_load_local_alloc(osb);
2361 if (status < 0) {
2362 mlog_errno(status);
2363 goto finally;
2364 }
2365
2366 if (dirty) {
2367 /* Recovery will be completed after we've mounted the
2368 * rest of the volume. */
2369 osb->dirty = 1;
2370 osb->local_alloc_copy = local_alloc;
2371 local_alloc = NULL;
2372 }
2373
2374 /* go through each journal, trylock it and if you get the
2375 * lock, and it's marked as dirty, set the bit in the recover
2376 * map and launch a recovery thread for it. */
2377 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002378 if (status < 0) {
2379 mlog_errno(status);
2380 goto finally;
2381 }
2382
2383 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002384 if (status < 0)
2385 mlog_errno(status);
2386
2387finally:
2388 if (local_alloc)
2389 kfree(local_alloc);
2390
2391 mlog_exit(status);
2392 return status;
2393}
2394
2395/*
2396 * The routine gets called from dismount or close whenever a dismount on
2397 * volume is requested and the osb open count becomes 1.
2398 * It will remove the osb from the global list and also free up all the
2399 * initialized resources and fileobject.
2400 */
2401static void ocfs2_delete_osb(struct ocfs2_super *osb)
2402{
2403 mlog_entry_void();
2404
2405 /* This function assumes that the caller has the main osb resource */
2406
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002407 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002408
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002409 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002410 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002411 /* FIXME
2412 * This belongs in journal shutdown, but because we have to
2413 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2414 * we free it here.
2415 */
2416 kfree(osb->journal);
2417 if (osb->local_alloc_copy)
2418 kfree(osb->local_alloc_copy);
2419 kfree(osb->uuid_str);
2420 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2421 memset(osb, 0, sizeof(struct ocfs2_super));
2422
2423 mlog_exit_void();
2424}
2425
2426/* Put OCFS2 into a readonly state, or (if the user specifies it),
2427 * panic(). We do not support continue-on-error operation. */
2428static void ocfs2_handle_error(struct super_block *sb)
2429{
2430 struct ocfs2_super *osb = OCFS2_SB(sb);
2431
2432 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2433 panic("OCFS2: (device %s): panic forced after error\n",
2434 sb->s_id);
2435
2436 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2437
2438 if (sb->s_flags & MS_RDONLY &&
2439 (ocfs2_is_soft_readonly(osb) ||
2440 ocfs2_is_hard_readonly(osb)))
2441 return;
2442
2443 printk(KERN_CRIT "File system is now read-only due to the potential "
2444 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2445 "system is unmounted.\n");
2446 sb->s_flags |= MS_RDONLY;
2447 ocfs2_set_ro_flag(osb, 0);
2448}
2449
2450static char error_buf[1024];
2451
2452void __ocfs2_error(struct super_block *sb,
2453 const char *function,
2454 const char *fmt, ...)
2455{
2456 va_list args;
2457
2458 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002459 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002460 va_end(args);
2461
2462 /* Not using mlog here because we want to show the actual
2463 * function the error came from. */
2464 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2465 sb->s_id, function, error_buf);
2466
2467 ocfs2_handle_error(sb);
2468}
2469
2470/* Handle critical errors. This is intentionally more drastic than
2471 * ocfs2_handle_error, so we only use for things like journal errors,
2472 * etc. */
2473void __ocfs2_abort(struct super_block* sb,
2474 const char *function,
2475 const char *fmt, ...)
2476{
2477 va_list args;
2478
2479 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002480 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002481 va_end(args);
2482
2483 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2484 sb->s_id, function, error_buf);
2485
2486 /* We don't have the cluster support yet to go straight to
2487 * hard readonly in here. Until then, we want to keep
2488 * ocfs2_abort() so that we can at least mark critical
2489 * errors.
2490 *
2491 * TODO: This should abort the journal and alert other nodes
2492 * that our slot needs recovery. */
2493
2494 /* Force a panic(). This stinks, but it's better than letting
2495 * things continue without having a proper hard readonly
2496 * here. */
Sunil Mushrana2f2ddb2009-08-19 15:16:01 -07002497 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2498 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08002499 ocfs2_handle_error(sb);
2500}
2501
2502module_init(ocfs2_init);
2503module_exit(ocfs2_exit);