blob: dee03197a4940b62b985f3e68d74c358aa214379 [file] [log] [blame]
Mark Fashehccd979b2005-12-15 14:31:24 -08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * super.c
5 *
6 * load/unload driver, mount/dismount volumes
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
24 */
25
26#include <linux/module.h>
27#include <linux/fs.h>
28#include <linux/types.h>
29#include <linux/slab.h>
30#include <linux/highmem.h>
Mark Fashehccd979b2005-12-15 14:31:24 -080031#include <linux/init.h>
32#include <linux/random.h>
33#include <linux/statfs.h>
34#include <linux/moduleparam.h>
35#include <linux/blkdev.h>
36#include <linux/socket.h>
37#include <linux/inet.h>
38#include <linux/parser.h>
39#include <linux/crc32.h>
40#include <linux/debugfs.h>
Sunil Mushrand5500712007-09-06 13:34:16 -070041#include <linux/mount.h>
Joel Becker6953b4c2008-01-29 16:59:56 -080042#include <linux/seq_file.h>
Jan Kara19ece542008-08-21 20:13:17 +020043#include <linux/quotaops.h>
Alessio Igor Bogani337eb002009-05-12 15:10:54 +020044#include <linux/smp_lock.h>
Mark Fashehccd979b2005-12-15 14:31:24 -080045
46#define MLOG_MASK_PREFIX ML_SUPER
47#include <cluster/masklog.h>
48
49#include "ocfs2.h"
50
51/* this should be the only file to include a version 1 header */
52#include "ocfs1_fs_compat.h"
53
54#include "alloc.h"
Joel Beckerd030cc92008-12-11 15:04:14 -080055#include "blockcheck.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080056#include "dlmglue.h"
57#include "export.h"
58#include "extent_map.h"
59#include "heartbeat.h"
60#include "inode.h"
61#include "journal.h"
62#include "localalloc.h"
63#include "namei.h"
64#include "slot_map.h"
65#include "super.h"
66#include "sysfile.h"
67#include "uptodate.h"
68#include "ver.h"
Tiger Yangcf1d6c72008-08-18 17:11:00 +080069#include "xattr.h"
Jan Kara9e33d692008-08-25 19:56:50 +020070#include "quota.h"
Tao Ma374a2632009-08-24 11:13:37 +080071#include "refcounttree.h"
Tiger Yangb89c5422010-01-25 14:11:06 +080072#include "suballoc.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);
Jan Kara5297aad2009-10-15 14:54:04 +0200104static int ocfs2_check_set_options(struct super_block *sb,
105 struct mount_options *options);
Sunil Mushrand5500712007-09-06 13:34:16 -0700106static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -0800107static void ocfs2_put_super(struct super_block *sb);
108static int ocfs2_mount_volume(struct super_block *sb);
109static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
110static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
111static int ocfs2_initialize_mem_caches(void);
112static void ocfs2_free_mem_caches(void);
113static void ocfs2_delete_osb(struct ocfs2_super *osb);
114
David Howells726c3342006-06-23 02:02:58 -0700115static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
Mark Fashehccd979b2005-12-15 14:31:24 -0800116
117static int ocfs2_sync_fs(struct super_block *sb, int wait);
118
119static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
120static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
Denis Chengbddb8eb32007-09-27 02:10:04 +0800121static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800122static int ocfs2_check_volume(struct ocfs2_super *osb);
123static int ocfs2_verify_volume(struct ocfs2_dinode *di,
124 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800125 u32 sectsize,
126 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800127static int ocfs2_initialize_super(struct super_block *sb,
128 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800129 int sector_size,
130 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800131static int ocfs2_get_sector(struct super_block *sb,
132 struct buffer_head **bh,
133 int block,
134 int sect_size);
Mark Fashehccd979b2005-12-15 14:31:24 -0800135static struct inode *ocfs2_alloc_inode(struct super_block *sb);
136static void ocfs2_destroy_inode(struct inode *inode);
Jan Kara19ece542008-08-21 20:13:17 +0200137static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
138static int ocfs2_enable_quotas(struct ocfs2_super *osb);
139static void ocfs2_disable_quotas(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800140
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800141static const struct super_operations ocfs2_sops = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800142 .statfs = ocfs2_statfs,
143 .alloc_inode = ocfs2_alloc_inode,
144 .destroy_inode = ocfs2_destroy_inode,
145 .drop_inode = ocfs2_drop_inode,
146 .clear_inode = ocfs2_clear_inode,
147 .delete_inode = ocfs2_delete_inode,
148 .sync_fs = ocfs2_sync_fs,
Mark Fashehccd979b2005-12-15 14:31:24 -0800149 .put_super = ocfs2_put_super,
150 .remount_fs = ocfs2_remount,
Sunil Mushrand5500712007-09-06 13:34:16 -0700151 .show_options = ocfs2_show_options,
Jan Kara9e33d692008-08-25 19:56:50 +0200152 .quota_read = ocfs2_quota_read,
153 .quota_write = ocfs2_quota_write,
Mark Fashehccd979b2005-12-15 14:31:24 -0800154};
155
156enum {
157 Opt_barrier,
158 Opt_err_panic,
159 Opt_err_ro,
160 Opt_intr,
161 Opt_nointr,
162 Opt_hb_none,
163 Opt_hb_local,
164 Opt_data_ordered,
165 Opt_data_writeback,
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800166 Opt_atime_quantum,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700167 Opt_slot,
Mark Fashehd147b3d2007-11-07 14:40:36 -0800168 Opt_commit,
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800169 Opt_localalloc,
Mark Fasheh53fc6222007-12-20 16:49:04 -0800170 Opt_localflocks,
Joel Beckerb61817e2008-02-01 15:08:23 -0800171 Opt_stack,
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800172 Opt_user_xattr,
173 Opt_nouser_xattr,
Joel Becker12462f12008-09-03 20:03:40 -0700174 Opt_inode64,
Tiger Yanga68979b2008-11-14 11:17:52 +0800175 Opt_acl,
176 Opt_noacl,
Jan Kara19ece542008-08-21 20:13:17 +0200177 Opt_usrquota,
178 Opt_grpquota,
Mark Fashehccd979b2005-12-15 14:31:24 -0800179 Opt_err,
180};
181
Steven Whitehousea447c092008-10-13 10:46:57 +0100182static const match_table_t tokens = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800183 {Opt_barrier, "barrier=%u"},
184 {Opt_err_panic, "errors=panic"},
185 {Opt_err_ro, "errors=remount-ro"},
186 {Opt_intr, "intr"},
187 {Opt_nointr, "nointr"},
188 {Opt_hb_none, OCFS2_HB_NONE},
189 {Opt_hb_local, OCFS2_HB_LOCAL},
190 {Opt_data_ordered, "data=ordered"},
191 {Opt_data_writeback, "data=writeback"},
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800192 {Opt_atime_quantum, "atime_quantum=%u"},
Sunil Mushranbaf46612007-06-18 17:00:24 -0700193 {Opt_slot, "preferred_slot=%u"},
Mark Fashehd147b3d2007-11-07 14:40:36 -0800194 {Opt_commit, "commit=%u"},
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800195 {Opt_localalloc, "localalloc=%d"},
Mark Fasheh53fc6222007-12-20 16:49:04 -0800196 {Opt_localflocks, "localflocks"},
Joel Beckerb61817e2008-02-01 15:08:23 -0800197 {Opt_stack, "cluster_stack=%s"},
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800198 {Opt_user_xattr, "user_xattr"},
199 {Opt_nouser_xattr, "nouser_xattr"},
Joel Becker12462f12008-09-03 20:03:40 -0700200 {Opt_inode64, "inode64"},
Tiger Yanga68979b2008-11-14 11:17:52 +0800201 {Opt_acl, "acl"},
202 {Opt_noacl, "noacl"},
Jan Kara19ece542008-08-21 20:13:17 +0200203 {Opt_usrquota, "usrquota"},
204 {Opt_grpquota, "grpquota"},
Mark Fashehccd979b2005-12-15 14:31:24 -0800205 {Opt_err, NULL}
206};
207
Sunil Mushran50397502008-12-17 14:17:43 -0800208#ifdef CONFIG_DEBUG_FS
209static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
210{
Sunil Mushran50397502008-12-17 14:17:43 -0800211 struct ocfs2_cluster_connection *cconn = osb->cconn;
212 struct ocfs2_recovery_map *rm = osb->recovery_map;
Sunil Mushrandf152c22009-06-22 11:40:07 -0700213 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
214 int i, out = 0;
Sunil Mushran50397502008-12-17 14:17:43 -0800215
216 out += snprintf(buf + out, len - out,
217 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
218 "Device", osb->dev_str, osb->uuid_str,
219 osb->fs_generation, osb->vol_label);
220
221 out += snprintf(buf + out, len - out,
222 "%10s => State: %d Flags: 0x%lX\n", "Volume",
223 atomic_read(&osb->vol_state), osb->osb_flags);
224
225 out += snprintf(buf + out, len - out,
226 "%10s => Block: %lu Cluster: %d\n", "Sizes",
227 osb->sb->s_blocksize, osb->s_clustersize);
228
229 out += snprintf(buf + out, len - out,
230 "%10s => Compat: 0x%X Incompat: 0x%X "
231 "ROcompat: 0x%X\n",
232 "Features", osb->s_feature_compat,
233 osb->s_feature_incompat, osb->s_feature_ro_compat);
234
235 out += snprintf(buf + out, len - out,
236 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
237 osb->s_mount_opt, osb->s_atime_quantum);
238
Sunil Mushranc3d38842009-06-19 14:45:55 -0700239 if (cconn) {
240 out += snprintf(buf + out, len - out,
241 "%10s => Stack: %s Name: %*s "
242 "Version: %d.%d\n", "Cluster",
243 (*osb->osb_cluster_stack == '\0' ?
244 "o2cb" : osb->osb_cluster_stack),
245 cconn->cc_namelen, cconn->cc_name,
246 cconn->cc_version.pv_major,
247 cconn->cc_version.pv_minor);
248 }
Sunil Mushran50397502008-12-17 14:17:43 -0800249
250 spin_lock(&osb->dc_task_lock);
251 out += snprintf(buf + out, len - out,
252 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
253 "WorkSeq: %lu\n", "DownCnvt",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700254 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
255 osb->blocked_lock_count, osb->dc_wake_sequence,
256 osb->dc_work_sequence);
Sunil Mushran50397502008-12-17 14:17:43 -0800257 spin_unlock(&osb->dc_task_lock);
258
259 spin_lock(&osb->osb_lock);
260 out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
261 "Recovery",
262 (osb->recovery_thread_task ?
263 task_pid_nr(osb->recovery_thread_task) : -1));
264 if (rm->rm_used == 0)
265 out += snprintf(buf + out, len - out, " None\n");
266 else {
267 for (i = 0; i < rm->rm_used; i++)
268 out += snprintf(buf + out, len - out, " %d",
269 rm->rm_entries[i]);
270 out += snprintf(buf + out, len - out, "\n");
271 }
272 spin_unlock(&osb->osb_lock);
273
274 out += snprintf(buf + out, len - out,
275 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700276 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
277 osb->osb_commit_interval,
Sunil Mushran50397502008-12-17 14:17:43 -0800278 atomic_read(&osb->needs_checkpoint));
279
280 out += snprintf(buf + out, len - out,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700281 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
Sunil Mushran50397502008-12-17 14:17:43 -0800282 "Journal", osb->journal->j_state,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700283 osb->journal->j_trans_id,
284 atomic_read(&osb->journal->j_num_trans));
Sunil Mushran50397502008-12-17 14:17:43 -0800285
286 out += snprintf(buf + out, len - out,
287 "%10s => GlobalAllocs: %d LocalAllocs: %d "
288 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
289 "Stats",
290 atomic_read(&osb->alloc_stats.bitmap_data),
291 atomic_read(&osb->alloc_stats.local_data),
292 atomic_read(&osb->alloc_stats.bg_allocs),
293 atomic_read(&osb->alloc_stats.moves),
294 atomic_read(&osb->alloc_stats.bg_extends));
295
296 out += snprintf(buf + out, len - out,
297 "%10s => State: %u Descriptor: %llu Size: %u bits "
298 "Default: %u bits\n",
299 "LocalAlloc", osb->local_alloc_state,
300 (unsigned long long)osb->la_last_gd,
301 osb->local_alloc_bits, osb->local_alloc_default_bits);
302
303 spin_lock(&osb->osb_lock);
304 out += snprintf(buf + out, len - out,
Tiger Yangb89c5422010-01-25 14:11:06 +0800305 "%10s => InodeSlot: %d StolenInodes: %d, "
306 "MetaSlot: %d StolenMeta: %d\n", "Steal",
Sunil Mushran50397502008-12-17 14:17:43 -0800307 osb->s_inode_steal_slot,
Tiger Yangb89c5422010-01-25 14:11:06 +0800308 atomic_read(&osb->s_num_inodes_stolen),
309 osb->s_meta_steal_slot,
310 atomic_read(&osb->s_num_meta_stolen));
Sunil Mushran50397502008-12-17 14:17:43 -0800311 spin_unlock(&osb->osb_lock);
312
Sunil Mushrandf152c22009-06-22 11:40:07 -0700313 out += snprintf(buf + out, len - out, "OrphanScan => ");
314 out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
315 os->os_count, os->os_seqno);
316 out += snprintf(buf + out, len - out, " Last Scan: ");
317 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
318 out += snprintf(buf + out, len - out, "Disabled\n");
319 else
320 out += snprintf(buf + out, len - out, "%lu seconds ago\n",
321 (get_seconds() - os->os_scantime.tv_sec));
322
Sunil Mushran50397502008-12-17 14:17:43 -0800323 out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
324 "Slots", "Num", "RecoGen");
Sunil Mushran50397502008-12-17 14:17:43 -0800325 for (i = 0; i < osb->max_slots; ++i) {
326 out += snprintf(buf + out, len - out,
327 "%10s %c %3d %10d\n",
328 " ",
329 (i == osb->slot_num ? '*' : ' '),
330 i, osb->slot_recovery_generations[i]);
331 }
332
333 return out;
334}
335
336static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
337{
338 struct ocfs2_super *osb = inode->i_private;
339 char *buf = NULL;
340
341 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
342 if (!buf)
343 goto bail;
344
345 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
346
347 file->private_data = buf;
348
349 return 0;
350bail:
351 return -ENOMEM;
352}
353
354static int ocfs2_debug_release(struct inode *inode, struct file *file)
355{
356 kfree(file->private_data);
357 return 0;
358}
359
360static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
361 size_t nbytes, loff_t *ppos)
362{
363 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
364 i_size_read(file->f_mapping->host));
365}
366#else
367static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
368{
369 return 0;
370}
371static int ocfs2_debug_release(struct inode *inode, struct file *file)
372{
373 return 0;
374}
375static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
376 size_t nbytes, loff_t *ppos)
377{
378 return 0;
379}
380#endif /* CONFIG_DEBUG_FS */
381
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700382static const struct file_operations ocfs2_osb_debug_fops = {
Sunil Mushran50397502008-12-17 14:17:43 -0800383 .open = ocfs2_osb_debug_open,
384 .release = ocfs2_debug_release,
385 .read = ocfs2_debug_read,
386 .llseek = generic_file_llseek,
387};
388
Mark Fashehccd979b2005-12-15 14:31:24 -0800389static int ocfs2_sync_fs(struct super_block *sb, int wait)
390{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800391 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -0800392 tid_t target;
393 struct ocfs2_super *osb = OCFS2_SB(sb);
394
Mark Fashehccd979b2005-12-15 14:31:24 -0800395 if (ocfs2_is_hard_readonly(osb))
396 return -EROFS;
397
398 if (wait) {
399 status = ocfs2_flush_truncate_log(osb);
400 if (status < 0)
401 mlog_errno(status);
402 } else {
403 ocfs2_schedule_truncate_log_flush(osb, 0);
404 }
405
Joel Becker2b4e30f2008-09-03 20:03:41 -0700406 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
407 &target)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800408 if (wait)
Joel Becker2b4e30f2008-09-03 20:03:41 -0700409 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
410 target);
Mark Fashehccd979b2005-12-15 14:31:24 -0800411 }
412 return 0;
413}
414
Jan Kara1a224ad2008-08-20 15:43:36 +0200415static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
416{
417 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
418 && (ino == USER_QUOTA_SYSTEM_INODE
419 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
420 return 0;
421 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
422 && (ino == GROUP_QUOTA_SYSTEM_INODE
423 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
424 return 0;
425 return 1;
426}
427
Mark Fashehccd979b2005-12-15 14:31:24 -0800428static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
429{
430 struct inode *new = NULL;
431 int status = 0;
432 int i;
433
434 mlog_entry_void();
435
Jan Kara5fa06132008-01-11 00:11:45 +0100436 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800437 if (IS_ERR(new)) {
438 status = PTR_ERR(new);
439 mlog_errno(status);
440 goto bail;
441 }
442 osb->root_inode = new;
443
Jan Kara5fa06132008-01-11 00:11:45 +0100444 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800445 if (IS_ERR(new)) {
446 status = PTR_ERR(new);
447 mlog_errno(status);
448 goto bail;
449 }
450 osb->sys_root_inode = new;
451
452 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
453 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200454 if (!ocfs2_need_system_inode(osb, i))
455 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800456 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
457 if (!new) {
458 ocfs2_release_system_inodes(osb);
459 status = -EINVAL;
460 mlog_errno(status);
461 /* FIXME: Should ERROR_RO_FS */
462 mlog(ML_ERROR, "Unable to load system inode %d, "
463 "possibly corrupt fs?", i);
464 goto bail;
465 }
466 // the array now has one ref, so drop this one
467 iput(new);
468 }
469
470bail:
471 mlog_exit(status);
472 return status;
473}
474
475static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
476{
477 struct inode *new = NULL;
478 int status = 0;
479 int i;
480
481 mlog_entry_void();
482
483 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
484 i < NUM_SYSTEM_INODES;
485 i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200486 if (!ocfs2_need_system_inode(osb, i))
487 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800488 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
489 if (!new) {
490 ocfs2_release_system_inodes(osb);
491 status = -EINVAL;
492 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
493 status, i, osb->slot_num);
494 goto bail;
495 }
496 /* the array now has one ref, so drop this one */
497 iput(new);
498 }
499
500bail:
501 mlog_exit(status);
502 return status;
503}
504
Denis Chengbddb8eb32007-09-27 02:10:04 +0800505static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
Mark Fashehccd979b2005-12-15 14:31:24 -0800506{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800507 int i;
Mark Fashehccd979b2005-12-15 14:31:24 -0800508 struct inode *inode;
509
510 mlog_entry_void();
511
512 for (i = 0; i < NUM_SYSTEM_INODES; i++) {
513 inode = osb->system_inodes[i];
514 if (inode) {
515 iput(inode);
516 osb->system_inodes[i] = NULL;
517 }
518 }
519
520 inode = osb->sys_root_inode;
521 if (inode) {
522 iput(inode);
523 osb->sys_root_inode = NULL;
524 }
525
526 inode = osb->root_inode;
527 if (inode) {
528 iput(inode);
529 osb->root_inode = NULL;
530 }
531
Denis Chengbddb8eb32007-09-27 02:10:04 +0800532 mlog_exit(0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800533}
534
535/* We're allocating fs objects, use GFP_NOFS */
536static struct inode *ocfs2_alloc_inode(struct super_block *sb)
537{
538 struct ocfs2_inode_info *oi;
539
Christoph Lametere6b4f8d2006-12-06 20:33:14 -0800540 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
Mark Fashehccd979b2005-12-15 14:31:24 -0800541 if (!oi)
542 return NULL;
543
Joel Becker2b4e30f2008-09-03 20:03:41 -0700544 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -0800545 return &oi->vfs_inode;
546}
547
548static void ocfs2_destroy_inode(struct inode *inode)
549{
550 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
551}
552
Mark Fasheh5a254032007-07-20 12:56:16 -0700553static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
554 unsigned int cbits)
Mark Fashehccd979b2005-12-15 14:31:24 -0800555{
Mark Fasheh5a254032007-07-20 12:56:16 -0700556 unsigned int bytes = 1 << cbits;
557 unsigned int trim = bytes;
558 unsigned int bitshift = 32;
Mark Fashehccd979b2005-12-15 14:31:24 -0800559
Mark Fasheh5a254032007-07-20 12:56:16 -0700560 /*
561 * i_size and all block offsets in ocfs2 are always 64 bits
562 * wide. i_clusters is 32 bits, in cluster-sized units. So on
563 * 64 bit platforms, cluster size will be the limiting factor.
Mark Fashehccd979b2005-12-15 14:31:24 -0800564 */
565
566#if BITS_PER_LONG == 32
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +0200567# if defined(CONFIG_LBDAF)
Alexey Dobriyan2ecd05a2006-10-11 01:22:05 -0700568 BUILD_BUG_ON(sizeof(sector_t) != 8);
Mark Fasheh5a254032007-07-20 12:56:16 -0700569 /*
570 * We might be limited by page cache size.
571 */
572 if (bytes > PAGE_CACHE_SIZE) {
573 bytes = PAGE_CACHE_SIZE;
574 trim = 1;
575 /*
576 * Shift by 31 here so that we don't get larger than
577 * MAX_LFS_FILESIZE
578 */
579 bitshift = 31;
580 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800581# else
Mark Fasheh5a254032007-07-20 12:56:16 -0700582 /*
583 * We are limited by the size of sector_t. Use block size, as
584 * that's what we expose to the VFS.
585 */
586 bytes = 1 << bbits;
587 trim = 1;
588 bitshift = 31;
Mark Fashehccd979b2005-12-15 14:31:24 -0800589# endif
590#endif
591
Mark Fasheh5a254032007-07-20 12:56:16 -0700592 /*
593 * Trim by a whole cluster when we can actually approach the
594 * on-disk limits. Otherwise we can overflow i_clusters when
595 * an extent start is at the max offset.
596 */
597 return (((unsigned long long)bytes) << bitshift) - trim;
Mark Fashehccd979b2005-12-15 14:31:24 -0800598}
599
600static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
601{
602 int incompat_features;
603 int ret = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800604 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800605 struct ocfs2_super *osb = OCFS2_SB(sb);
606
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200607 lock_kernel();
608
Jan Kara5297aad2009-10-15 14:54:04 +0200609 if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
610 !ocfs2_check_set_options(sb, &parsed_options)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800611 ret = -EINVAL;
612 goto out;
613 }
614
615 if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800616 (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800617 ret = -EINVAL;
618 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
619 goto out;
620 }
621
622 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800623 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800624 ret = -EINVAL;
625 mlog(ML_ERROR, "Cannot change data mode on remount\n");
626 goto out;
627 }
628
Joel Becker12462f12008-09-03 20:03:40 -0700629 /* Probably don't want this on remount; it might
630 * mess with other nodes */
631 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
632 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
633 ret = -EINVAL;
634 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
635 goto out;
636 }
637
Mark Fashehccd979b2005-12-15 14:31:24 -0800638 /* We're going to/from readonly mode. */
639 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
Jan Kara19ece542008-08-21 20:13:17 +0200640 /* Disable quota accounting before remounting RO */
641 if (*flags & MS_RDONLY) {
642 ret = ocfs2_susp_quotas(osb, 0);
643 if (ret < 0)
644 goto out;
645 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800646 /* Lock here so the check of HARD_RO and the potential
647 * setting of SOFT_RO is atomic. */
648 spin_lock(&osb->osb_lock);
649 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
650 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
651 ret = -EROFS;
652 goto unlock_osb;
653 }
654
655 if (*flags & MS_RDONLY) {
656 mlog(0, "Going to ro mode.\n");
657 sb->s_flags |= MS_RDONLY;
658 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
659 } else {
660 mlog(0, "Making ro filesystem writeable.\n");
661
662 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
663 mlog(ML_ERROR, "Cannot remount RDWR "
664 "filesystem due to previous errors.\n");
665 ret = -EROFS;
666 goto unlock_osb;
667 }
668 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
669 if (incompat_features) {
670 mlog(ML_ERROR, "Cannot remount RDWR because "
671 "of unsupported optional features "
672 "(%x).\n", incompat_features);
673 ret = -EINVAL;
674 goto unlock_osb;
675 }
676 sb->s_flags &= ~MS_RDONLY;
677 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
678 }
679unlock_osb:
680 spin_unlock(&osb->osb_lock);
Jan Kara19ece542008-08-21 20:13:17 +0200681 /* Enable quota accounting after remounting RW */
682 if (!ret && !(*flags & MS_RDONLY)) {
683 if (sb_any_quota_suspended(sb))
684 ret = ocfs2_susp_quotas(osb, 1);
685 else
686 ret = ocfs2_enable_quotas(osb);
687 if (ret < 0) {
688 /* Return back changes... */
689 spin_lock(&osb->osb_lock);
690 sb->s_flags |= MS_RDONLY;
691 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
692 spin_unlock(&osb->osb_lock);
693 goto out;
694 }
695 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800696 }
697
698 if (!ret) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800699 /* Only save off the new mount options in case of a successful
700 * remount. */
Tiger Yangc0123ad2007-09-08 00:16:10 +0800701 osb->s_mount_opt = parsed_options.mount_opt;
702 osb->s_atime_quantum = parsed_options.atime_quantum;
703 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -0800704 if (parsed_options.commit_interval)
705 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fashehe001e792007-11-07 14:21:45 -0800706
707 if (!ocfs2_is_hard_readonly(osb))
708 ocfs2_set_journal_params(osb);
Jan Kara57b09bb2009-10-15 14:54:05 +0200709
710 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
711 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
712 MS_POSIXACL : 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800713 }
714out:
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200715 unlock_kernel();
Mark Fashehccd979b2005-12-15 14:31:24 -0800716 return ret;
717}
718
719static int ocfs2_sb_probe(struct super_block *sb,
720 struct buffer_head **bh,
Joel Becker73be1922009-01-06 14:57:08 -0800721 int *sector_size,
722 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -0800723{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800724 int status, tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800725 struct ocfs1_vol_disk_hdr *hdr;
726 struct ocfs2_dinode *di;
727 int blksize;
728
729 *bh = NULL;
730
731 /* may be > 512 */
Martin K. Petersene1defc42009-05-22 17:17:49 -0400732 *sector_size = bdev_logical_block_size(sb->s_bdev);
Mark Fashehccd979b2005-12-15 14:31:24 -0800733 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
734 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
735 *sector_size, OCFS2_MAX_BLOCKSIZE);
736 status = -EINVAL;
737 goto bail;
738 }
739
740 /* Can this really happen? */
741 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
742 *sector_size = OCFS2_MIN_BLOCKSIZE;
743
744 /* check block zero for old format */
745 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
746 if (status < 0) {
747 mlog_errno(status);
748 goto bail;
749 }
750 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
751 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
752 mlog(ML_ERROR, "incompatible version: %u.%u\n",
753 hdr->major_version, hdr->minor_version);
754 status = -EINVAL;
755 }
756 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
757 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
758 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
759 hdr->signature);
760 status = -EINVAL;
761 }
762 brelse(*bh);
763 *bh = NULL;
764 if (status < 0) {
765 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
766 "upgraded before mounting with ocfs v2\n");
767 goto bail;
768 }
769
770 /*
771 * Now check at magic offset for 512, 1024, 2048, 4096
772 * blocksizes. 4096 is the maximum blocksize because it is
773 * the minimum clustersize.
774 */
775 status = -EINVAL;
776 for (blksize = *sector_size;
777 blksize <= OCFS2_MAX_BLOCKSIZE;
778 blksize <<= 1) {
779 tmpstat = ocfs2_get_sector(sb, bh,
780 OCFS2_SUPER_BLOCK_BLKNO,
781 blksize);
782 if (tmpstat < 0) {
783 status = tmpstat;
784 mlog_errno(status);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700785 break;
Mark Fashehccd979b2005-12-15 14:31:24 -0800786 }
787 di = (struct ocfs2_dinode *) (*bh)->b_data;
Joel Becker73be1922009-01-06 14:57:08 -0800788 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
Jan Kara1c1d9792009-07-22 13:17:19 +0200789 spin_lock_init(&stats->b_lock);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700790 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
791 if (tmpstat < 0) {
792 brelse(*bh);
793 *bh = NULL;
794 }
795 if (tmpstat != -EAGAIN) {
796 status = tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800797 break;
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700798 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800799 }
800
801bail:
802 return status;
803}
804
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800805static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
806{
807 if (ocfs2_mount_local(osb)) {
808 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
809 mlog(ML_ERROR, "Cannot heartbeat on a locally "
810 "mounted device.\n");
811 return -EINVAL;
812 }
813 }
814
Joel Beckerb61817e2008-02-01 15:08:23 -0800815 if (ocfs2_userspace_stack(osb)) {
816 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
817 mlog(ML_ERROR, "Userspace stack expected, but "
818 "o2cb heartbeat arguments passed to mount\n");
819 return -EINVAL;
820 }
821 }
822
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800823 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800824 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
825 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800826 mlog(ML_ERROR, "Heartbeat has to be started to mount "
827 "a read-write clustered device.\n");
828 return -EINVAL;
829 }
830 }
831
832 return 0;
833}
834
Joel Beckerb61817e2008-02-01 15:08:23 -0800835/*
836 * If we're using a userspace stack, mount should have passed
837 * a name that matches the disk. If not, mount should not
838 * have passed a stack.
839 */
840static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
841 struct mount_options *mopt)
842{
843 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
844 mlog(ML_ERROR,
845 "cluster stack passed to mount, but this filesystem "
846 "does not support it\n");
847 return -EINVAL;
848 }
849
850 if (ocfs2_userspace_stack(osb) &&
851 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
852 OCFS2_STACK_LABEL_LEN)) {
853 mlog(ML_ERROR,
854 "cluster stack passed to mount (\"%s\") does not "
855 "match the filesystem (\"%s\")\n",
856 mopt->cluster_stack,
857 osb->osb_cluster_stack);
858 return -EINVAL;
859 }
860
861 return 0;
862}
863
Jan Kara19ece542008-08-21 20:13:17 +0200864static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
865{
866 int type;
867 struct super_block *sb = osb->sb;
868 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
869 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
870 int status = 0;
871
872 for (type = 0; type < MAXQUOTAS; type++) {
873 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
874 continue;
875 if (unsuspend)
876 status = vfs_quota_enable(
877 sb_dqopt(sb)->files[type],
878 type, QFMT_OCFS2,
879 DQUOT_SUSPENDED);
880 else
881 status = vfs_quota_disable(sb, type,
882 DQUOT_SUSPENDED);
883 if (status < 0)
884 break;
885 }
886 if (status < 0)
887 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
888 "remount (error = %d).\n", status);
889 return status;
890}
891
892static int ocfs2_enable_quotas(struct ocfs2_super *osb)
893{
894 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
895 struct super_block *sb = osb->sb;
896 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
897 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
898 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
899 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
900 int status;
901 int type;
902
903 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
904 for (type = 0; type < MAXQUOTAS; type++) {
905 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
906 continue;
907 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
908 osb->slot_num);
909 if (!inode[type]) {
910 status = -ENOENT;
911 goto out_quota_off;
912 }
913 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
914 DQUOT_USAGE_ENABLED);
915 if (status < 0)
916 goto out_quota_off;
917 }
918
919 for (type = 0; type < MAXQUOTAS; type++)
920 iput(inode[type]);
921 return 0;
922out_quota_off:
923 ocfs2_disable_quotas(osb);
924 for (type = 0; type < MAXQUOTAS; type++)
925 iput(inode[type]);
926 mlog_errno(status);
927 return status;
928}
929
930static void ocfs2_disable_quotas(struct ocfs2_super *osb)
931{
932 int type;
933 struct inode *inode;
934 struct super_block *sb = osb->sb;
935
936 /* We mostly ignore errors in this function because there's not much
937 * we can do when we see them */
938 for (type = 0; type < MAXQUOTAS; type++) {
939 if (!sb_has_quota_loaded(sb, type))
940 continue;
941 inode = igrab(sb->s_dquot.files[type]);
942 /* Turn off quotas. This will remove all dquot structures from
943 * memory and so they will be automatically synced to global
944 * quota files */
945 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
946 DQUOT_LIMITS_ENABLED);
947 if (!inode)
948 continue;
949 iput(inode);
950 }
951}
952
953/* Handle quota on quotactl */
954static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
955 char *path, int remount)
956{
957 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
958 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
959
960 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
961 return -EINVAL;
962
963 if (remount)
964 return 0; /* Just ignore it has been handled in
965 * ocfs2_remount() */
966 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
967 format_id, DQUOT_LIMITS_ENABLED);
968}
969
970/* Handle quota off quotactl */
971static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
972{
973 if (remount)
974 return 0; /* Ignore now and handle later in
975 * ocfs2_remount() */
976 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
977}
978
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700979static const struct quotactl_ops ocfs2_quotactl_ops = {
Jan Kara19ece542008-08-21 20:13:17 +0200980 .quota_on = ocfs2_quota_on,
981 .quota_off = ocfs2_quota_off,
982 .quota_sync = vfs_quota_sync,
983 .get_info = vfs_get_dqinfo,
984 .set_info = vfs_set_dqinfo,
985 .get_dqblk = vfs_get_dqblk,
986 .set_dqblk = vfs_set_dqblk,
987};
988
Mark Fashehccd979b2005-12-15 14:31:24 -0800989static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
990{
991 struct dentry *root;
992 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800993 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800994 struct inode *inode = NULL;
995 struct ocfs2_super *osb = NULL;
996 struct buffer_head *bh = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800997 char nodestr[8];
Joel Becker73be1922009-01-06 14:57:08 -0800998 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -0800999
1000 mlog_entry("%p, %p, %i", sb, data, silent);
1001
Tiger Yangc0123ad2007-09-08 00:16:10 +08001002 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001003 status = -EINVAL;
1004 goto read_super_error;
1005 }
1006
1007 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -08001008 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001009 if (status < 0) {
1010 mlog(ML_ERROR, "superblock probe failed!\n");
1011 goto read_super_error;
1012 }
1013
Joel Becker73be1922009-01-06 14:57:08 -08001014 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001015 osb = OCFS2_SB(sb);
1016 if (status < 0) {
1017 mlog_errno(status);
1018 goto read_super_error;
1019 }
1020 brelse(bh);
1021 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001022
Jan Kara5297aad2009-10-15 14:54:04 +02001023 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1024 status = -EINVAL;
1025 goto read_super_error;
1026 }
Tiger Yangc0123ad2007-09-08 00:16:10 +08001027 osb->s_mount_opt = parsed_options.mount_opt;
1028 osb->s_atime_quantum = parsed_options.atime_quantum;
1029 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001030 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh9c7af402008-07-28 18:02:53 -07001031 osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
1032 osb->local_alloc_bits = osb->local_alloc_default_bits;
Mark Fashehccd979b2005-12-15 14:31:24 -08001033
Joel Beckerb61817e2008-02-01 15:08:23 -08001034 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1035 if (status)
1036 goto read_super_error;
1037
Mark Fashehccd979b2005-12-15 14:31:24 -08001038 sb->s_magic = OCFS2_SUPER_MAGIC;
1039
Tiger Yanga68979b2008-11-14 11:17:52 +08001040 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1041 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1042
Mark Fashehccd979b2005-12-15 14:31:24 -08001043 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1044 * heartbeat=none */
1045 if (bdev_read_only(sb->s_bdev)) {
1046 if (!(sb->s_flags & MS_RDONLY)) {
1047 status = -EACCES;
1048 mlog(ML_ERROR, "Readonly device detected but readonly "
1049 "mount was not specified.\n");
1050 goto read_super_error;
1051 }
1052
1053 /* You should not be able to start a local heartbeat
1054 * on a readonly device. */
1055 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1056 status = -EROFS;
1057 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1058 "device.\n");
1059 goto read_super_error;
1060 }
1061
1062 status = ocfs2_check_journals_nolocks(osb);
1063 if (status < 0) {
1064 if (status == -EROFS)
1065 mlog(ML_ERROR, "Recovery required on readonly "
1066 "file system, but write access is "
1067 "unavailable.\n");
1068 else
Sunil Mushran2bd63212010-01-25 16:57:38 -08001069 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -08001070 goto read_super_error;
1071 }
1072
1073 ocfs2_set_ro_flag(osb, 1);
1074
1075 printk(KERN_NOTICE "Readonly device detected. No cluster "
1076 "services will be utilized for this mount. Recovery "
1077 "will be skipped.\n");
1078 }
1079
1080 if (!ocfs2_is_hard_readonly(osb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001081 if (sb->s_flags & MS_RDONLY)
1082 ocfs2_set_ro_flag(osb, 0);
1083 }
1084
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001085 status = ocfs2_verify_heartbeat(osb);
1086 if (status < 0) {
1087 mlog_errno(status);
1088 goto read_super_error;
1089 }
1090
Mark Fashehccd979b2005-12-15 14:31:24 -08001091 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1092 ocfs2_debugfs_root);
1093 if (!osb->osb_debug_root) {
1094 status = -EINVAL;
1095 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1096 goto read_super_error;
1097 }
1098
Sunil Mushran50397502008-12-17 14:17:43 -08001099 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1100 osb->osb_debug_root,
1101 osb,
1102 &ocfs2_osb_debug_fops);
1103 if (!osb->osb_ctxt) {
1104 status = -EINVAL;
1105 mlog_errno(status);
1106 goto read_super_error;
1107 }
1108
Joel Becker73be1922009-01-06 14:57:08 -08001109 if (ocfs2_meta_ecc(osb)) {
1110 status = ocfs2_blockcheck_stats_debugfs_install(
1111 &osb->osb_ecc_stats,
1112 osb->osb_debug_root);
1113 if (status) {
1114 mlog(ML_ERROR,
1115 "Unable to create blockcheck statistics "
1116 "files\n");
1117 goto read_super_error;
1118 }
1119 }
1120
Mark Fashehccd979b2005-12-15 14:31:24 -08001121 status = ocfs2_mount_volume(sb);
1122 if (osb->root_inode)
1123 inode = igrab(osb->root_inode);
1124
1125 if (status < 0)
1126 goto read_super_error;
1127
1128 if (!inode) {
1129 status = -EIO;
1130 mlog_errno(status);
1131 goto read_super_error;
1132 }
1133
1134 root = d_alloc_root(inode);
1135 if (!root) {
1136 status = -ENOMEM;
1137 mlog_errno(status);
1138 goto read_super_error;
1139 }
1140
1141 sb->s_root = root;
1142
1143 ocfs2_complete_mount_recovery(osb);
1144
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001145 if (ocfs2_mount_local(osb))
1146 snprintf(nodestr, sizeof(nodestr), "local");
1147 else
Joel Becker19fdb622008-01-30 15:38:24 -08001148 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001149
1150 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001151 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001152 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001153 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1154 "ordered");
1155
1156 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1157 wake_up(&osb->osb_mount_event);
1158
Jan Kara19ece542008-08-21 20:13:17 +02001159 /* Now we can initialize quotas because we can afford to wait
1160 * for cluster locks recovery now. That also means that truncation
1161 * log recovery can happen but that waits for proper quota setup */
1162 if (!(sb->s_flags & MS_RDONLY)) {
1163 status = ocfs2_enable_quotas(osb);
1164 if (status < 0) {
1165 /* We have to err-out specially here because
1166 * s_root is already set */
1167 mlog_errno(status);
1168 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1169 wake_up(&osb->osb_mount_event);
1170 mlog_exit(status);
1171 return status;
1172 }
1173 }
1174
1175 ocfs2_complete_quota_recovery(osb);
1176
1177 /* Now we wake up again for processes waiting for quotas */
1178 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1179 wake_up(&osb->osb_mount_event);
1180
Sunil Mushrandf152c22009-06-22 11:40:07 -07001181 /* Start this when the mount is almost sure of being successful */
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04001182 ocfs2_orphan_scan_start(osb);
Sunil Mushrandf152c22009-06-22 11:40:07 -07001183
Mark Fashehccd979b2005-12-15 14:31:24 -08001184 mlog_exit(status);
1185 return status;
1186
1187read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001188 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001189
1190 if (inode)
1191 iput(inode);
1192
1193 if (osb) {
1194 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1195 wake_up(&osb->osb_mount_event);
1196 ocfs2_dismount_volume(sb, 1);
1197 }
1198
1199 mlog_exit(status);
1200 return status;
1201}
1202
David Howells454e2392006-06-23 02:02:57 -07001203static int ocfs2_get_sb(struct file_system_type *fs_type,
1204 int flags,
1205 const char *dev_name,
1206 void *data,
1207 struct vfsmount *mnt)
Mark Fashehccd979b2005-12-15 14:31:24 -08001208{
David Howells454e2392006-06-23 02:02:57 -07001209 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1210 mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -08001211}
1212
Jan Karaf7b1aa62009-07-20 12:12:36 +02001213static void ocfs2_kill_sb(struct super_block *sb)
1214{
1215 struct ocfs2_super *osb = OCFS2_SB(sb);
1216
Jan Kara5fd13182009-07-30 17:01:53 +02001217 /* Failed mount? */
1218 if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1219 goto out;
1220
Jan Karaf7b1aa62009-07-20 12:12:36 +02001221 /* Prevent further queueing of inode drop events */
1222 spin_lock(&dentry_list_lock);
1223 ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1224 spin_unlock(&dentry_list_lock);
1225 /* Wait for work to finish and/or remove it */
1226 cancel_work_sync(&osb->dentry_lock_work);
Jan Kara5fd13182009-07-30 17:01:53 +02001227out:
Jan Karaf7b1aa62009-07-20 12:12:36 +02001228 kill_block_super(sb);
1229}
1230
Mark Fashehccd979b2005-12-15 14:31:24 -08001231static struct file_system_type ocfs2_fs_type = {
1232 .owner = THIS_MODULE,
1233 .name = "ocfs2",
1234 .get_sb = ocfs2_get_sb, /* is this called when we mount
1235 * the fs? */
Jan Karaf7b1aa62009-07-20 12:12:36 +02001236 .kill_sb = ocfs2_kill_sb,
1237
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001238 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001239 .next = NULL
1240};
1241
Jan Kara5297aad2009-10-15 14:54:04 +02001242static int ocfs2_check_set_options(struct super_block *sb,
1243 struct mount_options *options)
1244{
1245 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1246 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1247 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1248 mlog(ML_ERROR, "User quotas were requested, but this "
1249 "filesystem does not have the feature enabled.\n");
1250 return 0;
1251 }
1252 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1253 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1254 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1255 mlog(ML_ERROR, "Group quotas were requested, but this "
1256 "filesystem does not have the feature enabled.\n");
1257 return 0;
1258 }
1259 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1260 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1261 mlog(ML_ERROR, "ACL support requested but extended attributes "
1262 "feature is not enabled\n");
1263 return 0;
1264 }
1265 /* No ACL setting specified? Use XATTR feature... */
1266 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1267 OCFS2_MOUNT_NO_POSIX_ACL))) {
1268 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1269 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1270 else
1271 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1272 }
1273 return 1;
1274}
1275
Mark Fashehccd979b2005-12-15 14:31:24 -08001276static int ocfs2_parse_options(struct super_block *sb,
1277 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001278 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001279 int is_remount)
1280{
1281 int status;
1282 char *p;
1283
1284 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1285 options ? options : "(none)");
1286
Mark Fashehd147b3d2007-11-07 14:40:36 -08001287 mopt->commit_interval = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001288 mopt->mount_opt = 0;
1289 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1290 mopt->slot = OCFS2_INVALID_SLOT;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001291 mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
Joel Beckerb61817e2008-02-01 15:08:23 -08001292 mopt->cluster_stack[0] = '\0';
Mark Fashehccd979b2005-12-15 14:31:24 -08001293
1294 if (!options) {
1295 status = 1;
1296 goto bail;
1297 }
1298
1299 while ((p = strsep(&options, ",")) != NULL) {
1300 int token, option;
1301 substring_t args[MAX_OPT_ARGS];
1302
1303 if (!*p)
1304 continue;
1305
1306 token = match_token(p, tokens, args);
1307 switch (token) {
1308 case Opt_hb_local:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001309 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001310 break;
1311 case Opt_hb_none:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001312 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001313 break;
1314 case Opt_barrier:
1315 if (match_int(&args[0], &option)) {
1316 status = 0;
1317 goto bail;
1318 }
1319 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001320 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001321 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001322 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001323 break;
1324 case Opt_intr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001325 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001326 break;
1327 case Opt_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001328 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001329 break;
1330 case Opt_err_panic:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001331 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001332 break;
1333 case Opt_err_ro:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001334 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001335 break;
1336 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001337 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001338 break;
1339 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001340 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001341 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001342 case Opt_user_xattr:
1343 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1344 break;
1345 case Opt_nouser_xattr:
1346 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1347 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001348 case Opt_atime_quantum:
1349 if (match_int(&args[0], &option)) {
1350 status = 0;
1351 goto bail;
1352 }
1353 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001354 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001355 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001356 case Opt_slot:
1357 option = 0;
1358 if (match_int(&args[0], &option)) {
1359 status = 0;
1360 goto bail;
1361 }
1362 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001363 mopt->slot = (s16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001364 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001365 case Opt_commit:
1366 option = 0;
1367 if (match_int(&args[0], &option)) {
1368 status = 0;
1369 goto bail;
1370 }
1371 if (option < 0)
1372 return 0;
1373 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001374 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001375 mopt->commit_interval = HZ * option;
1376 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001377 case Opt_localalloc:
1378 option = 0;
1379 if (match_int(&args[0], &option)) {
1380 status = 0;
1381 goto bail;
1382 }
1383 if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
1384 mopt->localalloc_opt = option;
1385 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001386 case Opt_localflocks:
1387 /*
1388 * Changing this during remount could race
1389 * flock() requests, or "unbalance" existing
1390 * ones (e.g., a lock is taken in one mode but
1391 * dropped in the other). If users care enough
1392 * to flip locking modes during remount, we
1393 * could add a "local" flag to individual
1394 * flock structures for proper tracking of
1395 * state.
1396 */
1397 if (!is_remount)
1398 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1399 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001400 case Opt_stack:
1401 /* Check both that the option we were passed
1402 * is of the right length and that it is a proper
1403 * string of the right length.
1404 */
1405 if (((args[0].to - args[0].from) !=
1406 OCFS2_STACK_LABEL_LEN) ||
1407 (strnlen(args[0].from,
1408 OCFS2_STACK_LABEL_LEN) !=
1409 OCFS2_STACK_LABEL_LEN)) {
1410 mlog(ML_ERROR,
1411 "Invalid cluster_stack option\n");
1412 status = 0;
1413 goto bail;
1414 }
1415 memcpy(mopt->cluster_stack, args[0].from,
1416 OCFS2_STACK_LABEL_LEN);
1417 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1418 break;
Joel Becker12462f12008-09-03 20:03:40 -07001419 case Opt_inode64:
1420 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1421 break;
Jan Kara19ece542008-08-21 20:13:17 +02001422 case Opt_usrquota:
Jan Kara19ece542008-08-21 20:13:17 +02001423 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1424 break;
1425 case Opt_grpquota:
Jan Kara19ece542008-08-21 20:13:17 +02001426 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1427 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001428 case Opt_acl:
1429 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
Jan Kara5297aad2009-10-15 14:54:04 +02001430 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001431 break;
1432 case Opt_noacl:
Jan Kara5297aad2009-10-15 14:54:04 +02001433 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001434 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1435 break;
Mark Fashehccd979b2005-12-15 14:31:24 -08001436 default:
1437 mlog(ML_ERROR,
1438 "Unrecognized mount option \"%s\" "
1439 "or missing value\n", p);
1440 status = 0;
1441 goto bail;
1442 }
1443 }
1444
1445 status = 1;
1446
1447bail:
1448 mlog_exit(status);
1449 return status;
1450}
1451
Sunil Mushrand5500712007-09-06 13:34:16 -07001452static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1453{
1454 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1455 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001456 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001457
1458 if (opts & OCFS2_MOUNT_HB_LOCAL)
1459 seq_printf(s, ",_netdev,heartbeat=local");
1460 else
1461 seq_printf(s, ",heartbeat=none");
1462
1463 if (opts & OCFS2_MOUNT_NOINTR)
1464 seq_printf(s, ",nointr");
1465
1466 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1467 seq_printf(s, ",data=writeback");
1468 else
1469 seq_printf(s, ",data=ordered");
1470
1471 if (opts & OCFS2_MOUNT_BARRIER)
1472 seq_printf(s, ",barrier=1");
1473
1474 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1475 seq_printf(s, ",errors=panic");
1476 else
1477 seq_printf(s, ",errors=remount-ro");
1478
1479 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1480 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1481
1482 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1483 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1484
Mark Fashehd147b3d2007-11-07 14:40:36 -08001485 if (osb->osb_commit_interval)
1486 seq_printf(s, ",commit=%u",
1487 (unsigned) (osb->osb_commit_interval / HZ));
1488
Mark Fashehebcee4b2008-07-28 14:55:20 -07001489 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
1490 if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
1491 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001492
Mark Fasheh53fc6222007-12-20 16:49:04 -08001493 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1494 seq_printf(s, ",localflocks,");
1495
Joel Beckerb61817e2008-02-01 15:08:23 -08001496 if (osb->osb_cluster_stack[0])
1497 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1498 osb->osb_cluster_stack);
Jan Kara19ece542008-08-21 20:13:17 +02001499 if (opts & OCFS2_MOUNT_USRQUOTA)
1500 seq_printf(s, ",usrquota");
1501 if (opts & OCFS2_MOUNT_GRPQUOTA)
1502 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001503
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001504 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1505 seq_printf(s, ",nouser_xattr");
1506 else
1507 seq_printf(s, ",user_xattr");
1508
Joel Becker12462f12008-09-03 20:03:40 -07001509 if (opts & OCFS2_MOUNT_INODE64)
1510 seq_printf(s, ",inode64");
1511
Tiger Yanga68979b2008-11-14 11:17:52 +08001512 if (opts & OCFS2_MOUNT_POSIX_ACL)
1513 seq_printf(s, ",acl");
1514 else
1515 seq_printf(s, ",noacl");
Tiger Yanga68979b2008-11-14 11:17:52 +08001516
Sunil Mushrand5500712007-09-06 13:34:16 -07001517 return 0;
1518}
1519
Mark Fashehccd979b2005-12-15 14:31:24 -08001520static int __init ocfs2_init(void)
1521{
1522 int status;
1523
1524 mlog_entry_void();
1525
1526 ocfs2_print_version();
1527
Mark Fashehccd979b2005-12-15 14:31:24 -08001528 status = init_ocfs2_uptodate_cache();
1529 if (status < 0) {
1530 mlog_errno(status);
1531 goto leave;
1532 }
1533
1534 status = ocfs2_initialize_mem_caches();
1535 if (status < 0) {
1536 mlog_errno(status);
1537 goto leave;
1538 }
1539
1540 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1541 if (!ocfs2_wq) {
1542 status = -ENOMEM;
1543 goto leave;
1544 }
1545
Mark Fashehccd979b2005-12-15 14:31:24 -08001546 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1547 if (!ocfs2_debugfs_root) {
1548 status = -EFAULT;
1549 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1550 }
1551
Mark Fasheh171bf932008-10-20 15:36:47 +02001552 status = ocfs2_quota_setup();
1553 if (status)
1554 goto leave;
1555
Joel Becker63e0c482008-01-30 16:58:36 -08001556 ocfs2_set_locking_protocol();
1557
Jan Kara9e33d692008-08-25 19:56:50 +02001558 status = register_quota_format(&ocfs2_quota_format);
Mark Fashehccd979b2005-12-15 14:31:24 -08001559leave:
1560 if (status < 0) {
Mark Fasheh171bf932008-10-20 15:36:47 +02001561 ocfs2_quota_shutdown();
Mark Fashehccd979b2005-12-15 14:31:24 -08001562 ocfs2_free_mem_caches();
1563 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001564 }
1565
1566 mlog_exit(status);
1567
1568 if (status >= 0) {
1569 return register_filesystem(&ocfs2_fs_type);
1570 } else
1571 return -1;
1572}
1573
1574static void __exit ocfs2_exit(void)
1575{
1576 mlog_entry_void();
1577
Mark Fasheh171bf932008-10-20 15:36:47 +02001578 ocfs2_quota_shutdown();
1579
Mark Fashehccd979b2005-12-15 14:31:24 -08001580 if (ocfs2_wq) {
1581 flush_workqueue(ocfs2_wq);
1582 destroy_workqueue(ocfs2_wq);
1583 }
1584
Jan Kara9e33d692008-08-25 19:56:50 +02001585 unregister_quota_format(&ocfs2_quota_format);
1586
Mark Fashehccd979b2005-12-15 14:31:24 -08001587 debugfs_remove(ocfs2_debugfs_root);
1588
1589 ocfs2_free_mem_caches();
1590
1591 unregister_filesystem(&ocfs2_fs_type);
1592
Mark Fashehccd979b2005-12-15 14:31:24 -08001593 exit_ocfs2_uptodate_cache();
1594
1595 mlog_exit_void();
1596}
1597
1598static void ocfs2_put_super(struct super_block *sb)
1599{
1600 mlog_entry("(0x%p)\n", sb);
1601
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001602 lock_kernel();
1603
Mark Fashehccd979b2005-12-15 14:31:24 -08001604 ocfs2_sync_blockdev(sb);
1605 ocfs2_dismount_volume(sb, 0);
1606
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001607 unlock_kernel();
1608
Mark Fashehccd979b2005-12-15 14:31:24 -08001609 mlog_exit_void();
1610}
1611
David Howells726c3342006-06-23 02:02:58 -07001612static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001613{
1614 struct ocfs2_super *osb;
1615 u32 numbits, freebits;
1616 int status;
1617 struct ocfs2_dinode *bm_lock;
1618 struct buffer_head *bh = NULL;
1619 struct inode *inode = NULL;
1620
David Howells726c3342006-06-23 02:02:58 -07001621 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001622
David Howells726c3342006-06-23 02:02:58 -07001623 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001624
1625 inode = ocfs2_get_system_file_inode(osb,
1626 GLOBAL_BITMAP_SYSTEM_INODE,
1627 OCFS2_INVALID_SLOT);
1628 if (!inode) {
1629 mlog(ML_ERROR, "failed to get bitmap inode\n");
1630 status = -EIO;
1631 goto bail;
1632 }
1633
Mark Fashehe63aecb62007-10-18 15:30:42 -07001634 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001635 if (status < 0) {
1636 mlog_errno(status);
1637 goto bail;
1638 }
1639
1640 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1641
1642 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1643 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1644
1645 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001646 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001647 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1648 buf->f_blocks = ((sector_t) numbits) *
1649 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1650 buf->f_bfree = ((sector_t) freebits) *
1651 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1652 buf->f_bavail = buf->f_bfree;
1653 buf->f_files = numbits;
1654 buf->f_ffree = freebits;
Coly Li837711f2009-01-16 16:33:05 +08001655 buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1656 & 0xFFFFFFFFUL;
1657 buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1658 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001659
1660 brelse(bh);
1661
Mark Fashehe63aecb62007-10-18 15:30:42 -07001662 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001663 status = 0;
1664bail:
1665 if (inode)
1666 iput(inode);
1667
1668 mlog_exit(status);
1669
1670 return status;
1671}
1672
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001673static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001674{
1675 struct ocfs2_inode_info *oi = data;
1676
Christoph Lametera35afb82007-05-16 22:10:57 -07001677 oi->ip_flags = 0;
1678 oi->ip_open_count = 0;
1679 spin_lock_init(&oi->ip_lock);
1680 ocfs2_extent_map_init(&oi->vfs_inode);
1681 INIT_LIST_HEAD(&oi->ip_io_markers);
Christoph Lametera35afb82007-05-16 22:10:57 -07001682 oi->ip_dir_start_lookup = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001683
Christoph Lametera35afb82007-05-16 22:10:57 -07001684 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001685 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001686 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001687
Christoph Lametera35afb82007-05-16 22:10:57 -07001688 oi->ip_blkno = 0ULL;
1689 oi->ip_clusters = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001690
Christoph Lametera35afb82007-05-16 22:10:57 -07001691 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001692 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001693 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001694
Joel Becker8cb471e2009-02-10 20:00:41 -08001695 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
Joel Becker6e5a3d72009-02-10 19:00:37 -08001696 &ocfs2_inode_caching_ops);
Mark Fashehccd979b2005-12-15 14:31:24 -08001697
Christoph Lametera35afb82007-05-16 22:10:57 -07001698 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001699}
1700
1701static int ocfs2_initialize_mem_caches(void)
1702{
1703 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001704 sizeof(struct ocfs2_inode_info),
1705 0,
1706 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1707 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001708 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001709 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1710 sizeof(struct ocfs2_dquot),
1711 0,
1712 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1713 SLAB_MEM_SPREAD),
1714 NULL);
1715 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1716 sizeof(struct ocfs2_quota_chunk),
1717 0,
1718 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1719 NULL);
1720 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1721 !ocfs2_qf_chunk_cachep) {
1722 if (ocfs2_inode_cachep)
1723 kmem_cache_destroy(ocfs2_inode_cachep);
1724 if (ocfs2_dquot_cachep)
1725 kmem_cache_destroy(ocfs2_dquot_cachep);
1726 if (ocfs2_qf_chunk_cachep)
1727 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001728 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001729 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001730
Mark Fashehccd979b2005-12-15 14:31:24 -08001731 return 0;
1732}
1733
1734static void ocfs2_free_mem_caches(void)
1735{
1736 if (ocfs2_inode_cachep)
1737 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001738 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001739
1740 if (ocfs2_dquot_cachep)
1741 kmem_cache_destroy(ocfs2_dquot_cachep);
1742 ocfs2_dquot_cachep = NULL;
1743
1744 if (ocfs2_qf_chunk_cachep)
1745 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1746 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001747}
1748
1749static int ocfs2_get_sector(struct super_block *sb,
1750 struct buffer_head **bh,
1751 int block,
1752 int sect_size)
1753{
1754 if (!sb_set_blocksize(sb, sect_size)) {
1755 mlog(ML_ERROR, "unable to set blocksize\n");
1756 return -EIO;
1757 }
1758
1759 *bh = sb_getblk(sb, block);
1760 if (!*bh) {
1761 mlog_errno(-EIO);
1762 return -EIO;
1763 }
1764 lock_buffer(*bh);
1765 if (!buffer_dirty(*bh))
1766 clear_buffer_uptodate(*bh);
1767 unlock_buffer(*bh);
1768 ll_rw_block(READ, 1, bh);
1769 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001770 if (!buffer_uptodate(*bh)) {
1771 mlog_errno(-EIO);
1772 brelse(*bh);
1773 *bh = NULL;
1774 return -EIO;
1775 }
1776
Mark Fashehccd979b2005-12-15 14:31:24 -08001777 return 0;
1778}
1779
Mark Fashehccd979b2005-12-15 14:31:24 -08001780static int ocfs2_mount_volume(struct super_block *sb)
1781{
1782 int status = 0;
1783 int unlock_super = 0;
1784 struct ocfs2_super *osb = OCFS2_SB(sb);
1785
1786 mlog_entry_void();
1787
1788 if (ocfs2_is_hard_readonly(osb))
1789 goto leave;
1790
Mark Fashehccd979b2005-12-15 14:31:24 -08001791 status = ocfs2_dlm_init(osb);
1792 if (status < 0) {
1793 mlog_errno(status);
1794 goto leave;
1795 }
1796
Mark Fashehccd979b2005-12-15 14:31:24 -08001797 status = ocfs2_super_lock(osb, 1);
1798 if (status < 0) {
1799 mlog_errno(status);
1800 goto leave;
1801 }
1802 unlock_super = 1;
1803
1804 /* This will load up the node map and add ourselves to it. */
1805 status = ocfs2_find_slot(osb);
1806 if (status < 0) {
1807 mlog_errno(status);
1808 goto leave;
1809 }
1810
Mark Fashehccd979b2005-12-15 14:31:24 -08001811 /* load all node-local system inodes */
1812 status = ocfs2_init_local_system_inodes(osb);
1813 if (status < 0) {
1814 mlog_errno(status);
1815 goto leave;
1816 }
1817
1818 status = ocfs2_check_volume(osb);
1819 if (status < 0) {
1820 mlog_errno(status);
1821 goto leave;
1822 }
1823
1824 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001825 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001826 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001827
Mark Fashehccd979b2005-12-15 14:31:24 -08001828leave:
1829 if (unlock_super)
1830 ocfs2_super_unlock(osb, 1);
1831
1832 mlog_exit(status);
1833 return status;
1834}
1835
Mark Fashehccd979b2005-12-15 14:31:24 -08001836static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1837{
Joel Becker286eaa92008-02-01 15:03:57 -08001838 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001839 struct ocfs2_super *osb = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001840 char nodestr[8];
Mark Fashehccd979b2005-12-15 14:31:24 -08001841
1842 mlog_entry("(0x%p)\n", sb);
1843
1844 BUG_ON(!sb);
1845 osb = OCFS2_SB(sb);
1846 BUG_ON(!osb);
1847
Sunil Mushran50397502008-12-17 14:17:43 -08001848 debugfs_remove(osb->osb_ctxt);
1849
Jan Karaf7b1aa62009-07-20 12:12:36 +02001850 /*
1851 * Flush inode dropping work queue so that deletes are
1852 * performed while the filesystem is still working
1853 */
1854 ocfs2_drop_all_dl_inodes(osb);
1855
Sunil Mushran692684e2009-06-19 16:53:17 -07001856 /* Orphan scan should be stopped as early as possible */
1857 ocfs2_orphan_scan_stop(osb);
1858
Jan Kara19ece542008-08-21 20:13:17 +02001859 ocfs2_disable_quotas(osb);
1860
Mark Fashehccd979b2005-12-15 14:31:24 -08001861 ocfs2_shutdown_local_alloc(osb);
1862
1863 ocfs2_truncate_log_shutdown(osb);
1864
Joel Becker553abd02008-02-01 12:03:57 -08001865 /* This will disable recovery and flush any recovery work. */
1866 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001867
1868 ocfs2_journal_shutdown(osb);
1869
1870 ocfs2_sync_blockdev(sb);
1871
Tao Ma374a2632009-08-24 11:13:37 +08001872 ocfs2_purge_refcount_trees(osb);
1873
Joel Becker4670c462008-02-01 14:39:35 -08001874 /* No cluster connection means we've failed during mount, so skip
1875 * all the steps which depended on that to complete. */
1876 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001877 tmp = ocfs2_super_lock(osb, 1);
1878 if (tmp < 0) {
1879 mlog_errno(tmp);
1880 return;
1881 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001882 }
1883
Mark Fasheh19b613d2007-10-04 14:47:09 -07001884 if (osb->slot_num != OCFS2_INVALID_SLOT)
1885 ocfs2_put_slot(osb);
1886
Joel Becker4670c462008-02-01 14:39:35 -08001887 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001888 ocfs2_super_unlock(osb, 1);
1889
Mark Fashehccd979b2005-12-15 14:31:24 -08001890 ocfs2_release_system_inodes(osb);
1891
Joel Becker6953b4c2008-01-29 16:59:56 -08001892 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001893 * If we're dismounting due to mount error, mount.ocfs2 will clean
1894 * up heartbeat. If we're a local mount, there is no heartbeat.
1895 * If we failed before we got a uuid_str yet, we can't stop
1896 * heartbeat. Otherwise, do it.
1897 */
1898 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
Joel Becker286eaa92008-02-01 15:03:57 -08001899 hangup_needed = 1;
1900
1901 if (osb->cconn)
1902 ocfs2_dlm_shutdown(osb, hangup_needed);
1903
Joel Becker73be1922009-01-06 14:57:08 -08001904 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Joel Becker286eaa92008-02-01 15:03:57 -08001905 debugfs_remove(osb->osb_debug_root);
1906
1907 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001908 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001909
1910 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1911
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001912 if (ocfs2_mount_local(osb))
1913 snprintf(nodestr, sizeof(nodestr), "local");
1914 else
Joel Becker19fdb622008-01-30 15:38:24 -08001915 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001916
1917 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1918 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001919
1920 ocfs2_delete_osb(osb);
1921 kfree(osb);
1922 sb->s_dev = 0;
1923 sb->s_fs_info = NULL;
1924}
1925
1926static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1927 unsigned uuid_bytes)
1928{
1929 int i, ret;
1930 char *ptr;
1931
1932 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1933
Robert P. J. Daycd861282006-12-13 00:34:52 -08001934 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001935 if (osb->uuid_str == NULL)
1936 return -ENOMEM;
1937
Mark Fashehccd979b2005-12-15 14:31:24 -08001938 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1939 /* print with null */
1940 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1941 if (ret != 2) /* drop super cleans up */
1942 return -EINVAL;
1943 /* then only advance past the last char */
1944 ptr += 2;
1945 }
1946
1947 return 0;
1948}
1949
1950static int ocfs2_initialize_super(struct super_block *sb,
1951 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08001952 int sector_size,
1953 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08001954{
Denis Chengbddb8eb32007-09-27 02:10:04 +08001955 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07001956 int i, cbits, bbits;
1957 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08001958 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001959 struct ocfs2_journal *journal;
1960 __le32 uuid_net_key;
1961 struct ocfs2_super *osb;
1962
1963 mlog_entry_void();
1964
Robert P. J. Daycd861282006-12-13 00:34:52 -08001965 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001966 if (!osb) {
1967 status = -ENOMEM;
1968 mlog_errno(status);
1969 goto bail;
1970 }
1971
1972 sb->s_fs_info = osb;
1973 sb->s_op = &ocfs2_sops;
1974 sb->s_export_op = &ocfs2_export_ops;
Jan Kara19ece542008-08-21 20:13:17 +02001975 sb->s_qcop = &ocfs2_quotactl_ops;
1976 sb->dq_op = &ocfs2_quota_operations;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001977 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07001978 sb->s_time_gran = 1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001979 sb->s_flags |= MS_NOATIME;
1980 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07001981 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
1982 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
1983 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001984
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001985 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
1986
1987 for (i = 0; i < 3; i++)
1988 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
1989 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
1990
Mark Fashehccd979b2005-12-15 14:31:24 -08001991 osb->sb = sb;
1992 /* Save off for ocfs2_rw_direct */
1993 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01001994 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08001995
Mark Fasheh34d024f2007-09-24 15:56:19 -07001996 spin_lock_init(&osb->dc_task_lock);
1997 init_waitqueue_head(&osb->dc_event);
1998 osb->dc_work_sequence = 0;
1999 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002000 INIT_LIST_HEAD(&osb->blocked_lock_list);
2001 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002002 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08002003 spin_lock_init(&osb->osb_xattr_lock);
Tiger Yangb89c5422010-01-25 14:11:06 +08002004 ocfs2_init_steal_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002005
2006 atomic_set(&osb->alloc_stats.moves, 0);
2007 atomic_set(&osb->alloc_stats.local_data, 0);
2008 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2009 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2010 atomic_set(&osb->alloc_stats.bg_extends, 0);
2011
Joel Becker73be1922009-01-06 14:57:08 -08002012 /* Copy the blockcheck stats from the superblock probe */
2013 osb->osb_ecc_stats = *stats;
2014
Mark Fashehccd979b2005-12-15 14:31:24 -08002015 ocfs2_init_node_maps(osb);
2016
2017 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2018 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2019
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04002020 ocfs2_orphan_scan_init(osb);
2021
Joel Becker553abd02008-02-01 12:03:57 -08002022 status = ocfs2_recovery_init(osb);
2023 if (status) {
2024 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2025 mlog_errno(status);
2026 goto bail;
2027 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002028
2029 init_waitqueue_head(&osb->checkpoint_event);
2030 atomic_set(&osb->needs_checkpoint, 0);
2031
Tiger Yang7f1a37e2006-11-15 15:48:42 +08002032 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2033
Mark Fashehccd979b2005-12-15 14:31:24 -08002034 osb->slot_num = OCFS2_INVALID_SLOT;
2035
Tiger Yang8154da32008-08-18 17:11:46 +08002036 osb->s_xattr_inline_size = le16_to_cpu(
2037 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002038
Mark Fashehccd979b2005-12-15 14:31:24 -08002039 osb->local_alloc_state = OCFS2_LA_UNUSED;
2040 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002041 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002042
Mark Fashehccd979b2005-12-15 14:31:24 -08002043 init_waitqueue_head(&osb->osb_mount_event);
2044
2045 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2046 if (!osb->vol_label) {
2047 mlog(ML_ERROR, "unable to alloc vol label\n");
2048 status = -ENOMEM;
2049 goto bail;
2050 }
2051
Mark Fashehccd979b2005-12-15 14:31:24 -08002052 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2053 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2054 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2055 osb->max_slots);
2056 status = -EINVAL;
2057 goto bail;
2058 }
Sunil Mushran781ee3e2006-04-27 16:41:31 -07002059 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
Mark Fashehccd979b2005-12-15 14:31:24 -08002060
Sunil Mushran539d8262008-07-14 17:31:10 -07002061 osb->slot_recovery_generations =
2062 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2063 GFP_KERNEL);
2064 if (!osb->slot_recovery_generations) {
2065 status = -ENOMEM;
2066 mlog_errno(status);
2067 goto bail;
2068 }
2069
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002070 init_waitqueue_head(&osb->osb_wipe_event);
2071 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2072 sizeof(*osb->osb_orphan_wipes),
2073 GFP_KERNEL);
2074 if (!osb->osb_orphan_wipes) {
2075 status = -ENOMEM;
2076 mlog_errno(status);
2077 goto bail;
2078 }
2079
Tao Ma374a2632009-08-24 11:13:37 +08002080 osb->osb_rf_lock_tree = RB_ROOT;
2081
Mark Fashehccd979b2005-12-15 14:31:24 -08002082 osb->s_feature_compat =
2083 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2084 osb->s_feature_ro_compat =
2085 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2086 osb->s_feature_incompat =
2087 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2088
2089 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2090 mlog(ML_ERROR, "couldn't mount because of unsupported "
2091 "optional features (%x).\n", i);
2092 status = -EINVAL;
2093 goto bail;
2094 }
2095 if (!(osb->sb->s_flags & MS_RDONLY) &&
2096 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2097 mlog(ML_ERROR, "couldn't mount RDWR because of "
2098 "unsupported optional features (%x).\n", i);
2099 status = -EINVAL;
2100 goto bail;
2101 }
2102
Joel Beckerb61817e2008-02-01 15:08:23 -08002103 if (ocfs2_userspace_stack(osb)) {
2104 memcpy(osb->osb_cluster_stack,
2105 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2106 OCFS2_STACK_LABEL_LEN);
2107 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2108 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2109 mlog(ML_ERROR,
2110 "couldn't mount because of an invalid "
2111 "cluster stack label (%s) \n",
2112 osb->osb_cluster_stack);
2113 status = -EINVAL;
2114 goto bail;
2115 }
2116 } else {
2117 /* The empty string is identical with classic tools that
2118 * don't know about s_cluster_info. */
2119 osb->osb_cluster_stack[0] = '\0';
2120 }
2121
Mark Fashehccd979b2005-12-15 14:31:24 -08002122 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2123
2124 /* FIXME
2125 * This should be done in ocfs2_journal_init(), but unknown
2126 * ordering issues will cause the filesystem to crash.
2127 * If anyone wants to figure out what part of the code
2128 * refers to osb->journal before ocfs2_journal_init() is run,
2129 * be my guest.
2130 */
2131 /* initialize our journal structure */
2132
Robert P. J. Daycd861282006-12-13 00:34:52 -08002133 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002134 if (!journal) {
2135 mlog(ML_ERROR, "unable to alloc journal\n");
2136 status = -ENOMEM;
2137 goto bail;
2138 }
2139 osb->journal = journal;
2140 journal->j_osb = osb;
2141
2142 atomic_set(&journal->j_num_trans, 0);
2143 init_rwsem(&journal->j_trans_barrier);
2144 init_waitqueue_head(&journal->j_checkpointed);
2145 spin_lock_init(&journal->j_lock);
2146 journal->j_trans_id = (unsigned long) 1;
2147 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002148 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002149 journal->j_state = OCFS2_JOURNAL_FREE;
2150
Jan Karaea455f82009-01-12 23:20:31 +01002151 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2152 osb->dentry_lock_list = NULL;
2153
Mark Fashehccd979b2005-12-15 14:31:24 -08002154 /* get some pseudo constants for clustersize bits */
2155 osb->s_clustersize_bits =
2156 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2157 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2158 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2159
2160 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2161 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2162 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2163 osb->s_clustersize);
2164 status = -EINVAL;
2165 goto bail;
2166 }
2167
2168 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2169 > (u32)~0UL) {
2170 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2171 "what jbd can address in 32 bits.\n");
2172 status = -EINVAL;
2173 goto bail;
2174 }
2175
2176 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2177 sizeof(di->id2.i_super.s_uuid))) {
2178 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2179 status = -ENOMEM;
2180 goto bail;
2181 }
2182
Mark Fasheh78427042006-05-04 12:03:26 -07002183 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
Mark Fashehccd979b2005-12-15 14:31:24 -08002184
2185 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2186 osb->vol_label[63] = '\0';
2187 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2188 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2189 osb->first_cluster_group_blkno =
2190 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2191 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002192 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Mark Fashehccd979b2005-12-15 14:31:24 -08002193 mlog(0, "vol_label: %s\n", osb->vol_label);
2194 mlog(0, "uuid: %s\n", osb->uuid_str);
Mark Fashehb06970532006-03-03 10:24:33 -08002195 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2196 (unsigned long long)osb->root_blkno,
2197 (unsigned long long)osb->system_dir_blkno);
Mark Fashehccd979b2005-12-15 14:31:24 -08002198
2199 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2200 if (!osb->osb_dlm_debug) {
2201 status = -ENOMEM;
2202 mlog_errno(status);
2203 goto bail;
2204 }
2205
2206 atomic_set(&osb->vol_state, VOLUME_INIT);
2207
2208 /* load root, system_dir, and all global system inodes */
2209 status = ocfs2_init_global_system_inodes(osb);
2210 if (status < 0) {
2211 mlog_errno(status);
2212 goto bail;
2213 }
2214
2215 /*
2216 * global bitmap
2217 */
2218 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2219 OCFS2_INVALID_SLOT);
2220 if (!inode) {
2221 status = -EINVAL;
2222 mlog_errno(status);
2223 goto bail;
2224 }
2225
2226 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fashehccd979b2005-12-15 14:31:24 -08002227 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002228
Tao Mae9d578a2007-12-18 15:46:10 +08002229 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002230
2231 status = ocfs2_init_slot_info(osb);
2232 if (status < 0) {
2233 mlog_errno(status);
2234 goto bail;
2235 }
2236
Mark Fashehccd979b2005-12-15 14:31:24 -08002237bail:
2238 mlog_exit(status);
2239 return status;
2240}
2241
2242/*
2243 * will return: -EAGAIN if it is ok to keep searching for superblocks
2244 * -EINVAL if there is a bad superblock
2245 * 0 on success
2246 */
2247static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2248 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002249 u32 blksz,
2250 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002251{
2252 int status = -EAGAIN;
2253
2254 mlog_entry_void();
2255
2256 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2257 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002258 /* We have to do a raw check of the feature here */
2259 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2260 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2261 status = ocfs2_block_check_validate(bh->b_data,
2262 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002263 &di->i_check,
2264 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002265 if (status)
2266 goto out;
2267 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002268 status = -EINVAL;
2269 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2270 mlog(ML_ERROR, "found superblock with incorrect block "
2271 "size: found %u, should be %u\n",
2272 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2273 blksz);
2274 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2275 OCFS2_MAJOR_REV_LEVEL ||
2276 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2277 OCFS2_MINOR_REV_LEVEL) {
2278 mlog(ML_ERROR, "found superblock with bad version: "
2279 "found %u.%u, should be %u.%u\n",
2280 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2281 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2282 OCFS2_MAJOR_REV_LEVEL,
2283 OCFS2_MINOR_REV_LEVEL);
2284 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2285 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb06970532006-03-03 10:24:33 -08002286 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002287 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb06970532006-03-03 10:24:33 -08002288 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002289 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2290 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2291 mlog(ML_ERROR, "bad cluster size found: %u\n",
2292 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2293 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2294 mlog(ML_ERROR, "bad root_blkno: 0\n");
2295 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2296 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2297 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2298 mlog(ML_ERROR,
2299 "Superblock slots found greater than file system "
2300 "maximum: found %u, max %u\n",
2301 le16_to_cpu(di->id2.i_super.s_max_slots),
2302 OCFS2_MAX_SLOTS);
2303 } else {
2304 /* found it! */
2305 status = 0;
2306 }
2307 }
2308
Joel Beckerd030cc92008-12-11 15:04:14 -08002309out:
Mark Fashehccd979b2005-12-15 14:31:24 -08002310 mlog_exit(status);
2311 return status;
2312}
2313
2314static int ocfs2_check_volume(struct ocfs2_super *osb)
2315{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002316 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002317 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002318 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002319 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2320 * recover
2321 * ourselves. */
2322
2323 mlog_entry_void();
2324
2325 /* Init our journal object. */
2326 status = ocfs2_journal_init(osb->journal, &dirty);
2327 if (status < 0) {
2328 mlog(ML_ERROR, "Could not initialize journal!\n");
2329 goto finally;
2330 }
2331
2332 /* If the journal was unmounted cleanly then we don't want to
2333 * recover anything. Otherwise, journal_load will do that
2334 * dirty work for us :) */
2335 if (!dirty) {
2336 status = ocfs2_journal_wipe(osb->journal, 0);
2337 if (status < 0) {
2338 mlog_errno(status);
2339 goto finally;
2340 }
2341 } else {
2342 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2343 "recovering volume.\n");
2344 }
2345
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002346 local = ocfs2_mount_local(osb);
2347
Mark Fashehccd979b2005-12-15 14:31:24 -08002348 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002349 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002350 if (status < 0) {
2351 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2352 goto finally;
2353 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002354
2355 if (dirty) {
2356 /* recover my local alloc if we didn't unmount cleanly. */
2357 status = ocfs2_begin_local_alloc_recovery(osb,
2358 osb->slot_num,
2359 &local_alloc);
2360 if (status < 0) {
2361 mlog_errno(status);
2362 goto finally;
2363 }
2364 /* we complete the recovery process after we've marked
2365 * ourselves as mounted. */
2366 }
2367
2368 mlog(0, "Journal loaded.\n");
2369
2370 status = ocfs2_load_local_alloc(osb);
2371 if (status < 0) {
2372 mlog_errno(status);
2373 goto finally;
2374 }
2375
2376 if (dirty) {
2377 /* Recovery will be completed after we've mounted the
2378 * rest of the volume. */
2379 osb->dirty = 1;
2380 osb->local_alloc_copy = local_alloc;
2381 local_alloc = NULL;
2382 }
2383
2384 /* go through each journal, trylock it and if you get the
2385 * lock, and it's marked as dirty, set the bit in the recover
2386 * map and launch a recovery thread for it. */
2387 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002388 if (status < 0) {
2389 mlog_errno(status);
2390 goto finally;
2391 }
2392
2393 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002394 if (status < 0)
2395 mlog_errno(status);
2396
2397finally:
2398 if (local_alloc)
2399 kfree(local_alloc);
2400
2401 mlog_exit(status);
2402 return status;
2403}
2404
2405/*
2406 * The routine gets called from dismount or close whenever a dismount on
2407 * volume is requested and the osb open count becomes 1.
2408 * It will remove the osb from the global list and also free up all the
2409 * initialized resources and fileobject.
2410 */
2411static void ocfs2_delete_osb(struct ocfs2_super *osb)
2412{
2413 mlog_entry_void();
2414
2415 /* This function assumes that the caller has the main osb resource */
2416
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002417 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002418
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002419 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002420 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002421 /* FIXME
2422 * This belongs in journal shutdown, but because we have to
2423 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2424 * we free it here.
2425 */
2426 kfree(osb->journal);
2427 if (osb->local_alloc_copy)
2428 kfree(osb->local_alloc_copy);
2429 kfree(osb->uuid_str);
2430 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2431 memset(osb, 0, sizeof(struct ocfs2_super));
2432
2433 mlog_exit_void();
2434}
2435
2436/* Put OCFS2 into a readonly state, or (if the user specifies it),
2437 * panic(). We do not support continue-on-error operation. */
2438static void ocfs2_handle_error(struct super_block *sb)
2439{
2440 struct ocfs2_super *osb = OCFS2_SB(sb);
2441
2442 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2443 panic("OCFS2: (device %s): panic forced after error\n",
2444 sb->s_id);
2445
2446 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2447
2448 if (sb->s_flags & MS_RDONLY &&
2449 (ocfs2_is_soft_readonly(osb) ||
2450 ocfs2_is_hard_readonly(osb)))
2451 return;
2452
2453 printk(KERN_CRIT "File system is now read-only due to the potential "
2454 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2455 "system is unmounted.\n");
2456 sb->s_flags |= MS_RDONLY;
2457 ocfs2_set_ro_flag(osb, 0);
2458}
2459
2460static char error_buf[1024];
2461
2462void __ocfs2_error(struct super_block *sb,
2463 const char *function,
2464 const char *fmt, ...)
2465{
2466 va_list args;
2467
2468 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002469 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002470 va_end(args);
2471
2472 /* Not using mlog here because we want to show the actual
2473 * function the error came from. */
2474 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2475 sb->s_id, function, error_buf);
2476
2477 ocfs2_handle_error(sb);
2478}
2479
2480/* Handle critical errors. This is intentionally more drastic than
2481 * ocfs2_handle_error, so we only use for things like journal errors,
2482 * etc. */
2483void __ocfs2_abort(struct super_block* sb,
2484 const char *function,
2485 const char *fmt, ...)
2486{
2487 va_list args;
2488
2489 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002490 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002491 va_end(args);
2492
2493 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2494 sb->s_id, function, error_buf);
2495
2496 /* We don't have the cluster support yet to go straight to
2497 * hard readonly in here. Until then, we want to keep
2498 * ocfs2_abort() so that we can at least mark critical
2499 * errors.
2500 *
2501 * TODO: This should abort the journal and alert other nodes
2502 * that our slot needs recovery. */
2503
2504 /* Force a panic(). This stinks, but it's better than letting
2505 * things continue without having a proper hard readonly
2506 * here. */
Sunil Mushrana2f2ddb2009-08-19 15:16:01 -07002507 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2508 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08002509 ocfs2_handle_error(sb);
2510}
2511
2512module_init(ocfs2_init);
2513module_exit(ocfs2_exit);