blob: 66f9984a983c9696d6132499a8ab6ed9e31f37d2 [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;
Mark Fasheh73c8a802010-04-05 18:17:13 -070097 int localalloc_opt;
Mark Fashehd02f00c2009-12-07 13:10:48 -080098 unsigned int resv_level;
Mark Fasheh83f92312010-04-05 18:17:16 -070099 int dir_resv_level;
Joel Beckerb61817e2008-02-01 15:08:23 -0800100 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
Tiger Yangc0123ad2007-09-08 00:16:10 +0800101};
102
Mark Fashehccd979b2005-12-15 14:31:24 -0800103static int ocfs2_parse_options(struct super_block *sb, char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +0800104 struct mount_options *mopt,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700105 int is_remount);
Jan Kara5297aad2009-10-15 14:54:04 +0200106static int ocfs2_check_set_options(struct super_block *sb,
107 struct mount_options *options);
Sunil Mushrand5500712007-09-06 13:34:16 -0700108static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -0800109static void ocfs2_put_super(struct super_block *sb);
110static int ocfs2_mount_volume(struct super_block *sb);
111static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
112static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
113static int ocfs2_initialize_mem_caches(void);
114static void ocfs2_free_mem_caches(void);
115static void ocfs2_delete_osb(struct ocfs2_super *osb);
116
David Howells726c3342006-06-23 02:02:58 -0700117static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
Mark Fashehccd979b2005-12-15 14:31:24 -0800118
119static int ocfs2_sync_fs(struct super_block *sb, int wait);
120
121static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
122static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
Denis Chengbddb8eb32007-09-27 02:10:04 +0800123static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800124static int ocfs2_check_volume(struct ocfs2_super *osb);
125static int ocfs2_verify_volume(struct ocfs2_dinode *di,
126 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800127 u32 sectsize,
128 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800129static int ocfs2_initialize_super(struct super_block *sb,
130 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800131 int sector_size,
132 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800133static int ocfs2_get_sector(struct super_block *sb,
134 struct buffer_head **bh,
135 int block,
136 int sect_size);
Mark Fashehccd979b2005-12-15 14:31:24 -0800137static struct inode *ocfs2_alloc_inode(struct super_block *sb);
138static void ocfs2_destroy_inode(struct inode *inode);
Jan Kara19ece542008-08-21 20:13:17 +0200139static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
140static int ocfs2_enable_quotas(struct ocfs2_super *osb);
141static void ocfs2_disable_quotas(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800142
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800143static const struct super_operations ocfs2_sops = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800144 .statfs = ocfs2_statfs,
145 .alloc_inode = ocfs2_alloc_inode,
146 .destroy_inode = ocfs2_destroy_inode,
147 .drop_inode = ocfs2_drop_inode,
148 .clear_inode = ocfs2_clear_inode,
149 .delete_inode = ocfs2_delete_inode,
150 .sync_fs = ocfs2_sync_fs,
Mark Fashehccd979b2005-12-15 14:31:24 -0800151 .put_super = ocfs2_put_super,
152 .remount_fs = ocfs2_remount,
Sunil Mushrand5500712007-09-06 13:34:16 -0700153 .show_options = ocfs2_show_options,
Jan Kara9e33d692008-08-25 19:56:50 +0200154 .quota_read = ocfs2_quota_read,
155 .quota_write = ocfs2_quota_write,
Mark Fashehccd979b2005-12-15 14:31:24 -0800156};
157
158enum {
159 Opt_barrier,
160 Opt_err_panic,
161 Opt_err_ro,
162 Opt_intr,
163 Opt_nointr,
164 Opt_hb_none,
165 Opt_hb_local,
166 Opt_data_ordered,
167 Opt_data_writeback,
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800168 Opt_atime_quantum,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700169 Opt_slot,
Mark Fashehd147b3d2007-11-07 14:40:36 -0800170 Opt_commit,
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800171 Opt_localalloc,
Mark Fasheh53fc6222007-12-20 16:49:04 -0800172 Opt_localflocks,
Joel Beckerb61817e2008-02-01 15:08:23 -0800173 Opt_stack,
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800174 Opt_user_xattr,
175 Opt_nouser_xattr,
Joel Becker12462f12008-09-03 20:03:40 -0700176 Opt_inode64,
Tiger Yanga68979b2008-11-14 11:17:52 +0800177 Opt_acl,
178 Opt_noacl,
Jan Kara19ece542008-08-21 20:13:17 +0200179 Opt_usrquota,
180 Opt_grpquota,
Mark Fashehd02f00c2009-12-07 13:10:48 -0800181 Opt_resv_level,
Mark Fasheh83f92312010-04-05 18:17:16 -0700182 Opt_dir_resv_level,
Mark Fashehccd979b2005-12-15 14:31:24 -0800183 Opt_err,
184};
185
Steven Whitehousea447c092008-10-13 10:46:57 +0100186static const match_table_t tokens = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800187 {Opt_barrier, "barrier=%u"},
188 {Opt_err_panic, "errors=panic"},
189 {Opt_err_ro, "errors=remount-ro"},
190 {Opt_intr, "intr"},
191 {Opt_nointr, "nointr"},
192 {Opt_hb_none, OCFS2_HB_NONE},
193 {Opt_hb_local, OCFS2_HB_LOCAL},
194 {Opt_data_ordered, "data=ordered"},
195 {Opt_data_writeback, "data=writeback"},
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800196 {Opt_atime_quantum, "atime_quantum=%u"},
Sunil Mushranbaf46612007-06-18 17:00:24 -0700197 {Opt_slot, "preferred_slot=%u"},
Mark Fashehd147b3d2007-11-07 14:40:36 -0800198 {Opt_commit, "commit=%u"},
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800199 {Opt_localalloc, "localalloc=%d"},
Mark Fasheh53fc6222007-12-20 16:49:04 -0800200 {Opt_localflocks, "localflocks"},
Joel Beckerb61817e2008-02-01 15:08:23 -0800201 {Opt_stack, "cluster_stack=%s"},
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800202 {Opt_user_xattr, "user_xattr"},
203 {Opt_nouser_xattr, "nouser_xattr"},
Joel Becker12462f12008-09-03 20:03:40 -0700204 {Opt_inode64, "inode64"},
Tiger Yanga68979b2008-11-14 11:17:52 +0800205 {Opt_acl, "acl"},
206 {Opt_noacl, "noacl"},
Jan Kara19ece542008-08-21 20:13:17 +0200207 {Opt_usrquota, "usrquota"},
208 {Opt_grpquota, "grpquota"},
Mark Fashehd02f00c2009-12-07 13:10:48 -0800209 {Opt_resv_level, "resv_level=%u"},
Mark Fasheh83f92312010-04-05 18:17:16 -0700210 {Opt_dir_resv_level, "dir_resv_level=%u"},
Mark Fashehccd979b2005-12-15 14:31:24 -0800211 {Opt_err, NULL}
212};
213
Sunil Mushran50397502008-12-17 14:17:43 -0800214#ifdef CONFIG_DEBUG_FS
215static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
216{
Sunil Mushran50397502008-12-17 14:17:43 -0800217 struct ocfs2_cluster_connection *cconn = osb->cconn;
218 struct ocfs2_recovery_map *rm = osb->recovery_map;
Sunil Mushrandf152c22009-06-22 11:40:07 -0700219 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
220 int i, out = 0;
Sunil Mushran50397502008-12-17 14:17:43 -0800221
222 out += snprintf(buf + out, len - out,
223 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
224 "Device", osb->dev_str, osb->uuid_str,
225 osb->fs_generation, osb->vol_label);
226
227 out += snprintf(buf + out, len - out,
228 "%10s => State: %d Flags: 0x%lX\n", "Volume",
229 atomic_read(&osb->vol_state), osb->osb_flags);
230
231 out += snprintf(buf + out, len - out,
232 "%10s => Block: %lu Cluster: %d\n", "Sizes",
233 osb->sb->s_blocksize, osb->s_clustersize);
234
235 out += snprintf(buf + out, len - out,
236 "%10s => Compat: 0x%X Incompat: 0x%X "
237 "ROcompat: 0x%X\n",
238 "Features", osb->s_feature_compat,
239 osb->s_feature_incompat, osb->s_feature_ro_compat);
240
241 out += snprintf(buf + out, len - out,
242 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
243 osb->s_mount_opt, osb->s_atime_quantum);
244
Sunil Mushranc3d38842009-06-19 14:45:55 -0700245 if (cconn) {
246 out += snprintf(buf + out, len - out,
247 "%10s => Stack: %s Name: %*s "
248 "Version: %d.%d\n", "Cluster",
249 (*osb->osb_cluster_stack == '\0' ?
250 "o2cb" : osb->osb_cluster_stack),
251 cconn->cc_namelen, cconn->cc_name,
252 cconn->cc_version.pv_major,
253 cconn->cc_version.pv_minor);
254 }
Sunil Mushran50397502008-12-17 14:17:43 -0800255
256 spin_lock(&osb->dc_task_lock);
257 out += snprintf(buf + out, len - out,
258 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
259 "WorkSeq: %lu\n", "DownCnvt",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700260 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
261 osb->blocked_lock_count, osb->dc_wake_sequence,
262 osb->dc_work_sequence);
Sunil Mushran50397502008-12-17 14:17:43 -0800263 spin_unlock(&osb->dc_task_lock);
264
265 spin_lock(&osb->osb_lock);
266 out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
267 "Recovery",
268 (osb->recovery_thread_task ?
269 task_pid_nr(osb->recovery_thread_task) : -1));
270 if (rm->rm_used == 0)
271 out += snprintf(buf + out, len - out, " None\n");
272 else {
273 for (i = 0; i < rm->rm_used; i++)
274 out += snprintf(buf + out, len - out, " %d",
275 rm->rm_entries[i]);
276 out += snprintf(buf + out, len - out, "\n");
277 }
278 spin_unlock(&osb->osb_lock);
279
280 out += snprintf(buf + out, len - out,
281 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700282 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
283 osb->osb_commit_interval,
Sunil Mushran50397502008-12-17 14:17:43 -0800284 atomic_read(&osb->needs_checkpoint));
285
286 out += snprintf(buf + out, len - out,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700287 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
Sunil Mushran50397502008-12-17 14:17:43 -0800288 "Journal", osb->journal->j_state,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700289 osb->journal->j_trans_id,
290 atomic_read(&osb->journal->j_num_trans));
Sunil Mushran50397502008-12-17 14:17:43 -0800291
292 out += snprintf(buf + out, len - out,
293 "%10s => GlobalAllocs: %d LocalAllocs: %d "
294 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
295 "Stats",
296 atomic_read(&osb->alloc_stats.bitmap_data),
297 atomic_read(&osb->alloc_stats.local_data),
298 atomic_read(&osb->alloc_stats.bg_allocs),
299 atomic_read(&osb->alloc_stats.moves),
300 atomic_read(&osb->alloc_stats.bg_extends));
301
302 out += snprintf(buf + out, len - out,
303 "%10s => State: %u Descriptor: %llu Size: %u bits "
304 "Default: %u bits\n",
305 "LocalAlloc", osb->local_alloc_state,
306 (unsigned long long)osb->la_last_gd,
307 osb->local_alloc_bits, osb->local_alloc_default_bits);
308
309 spin_lock(&osb->osb_lock);
310 out += snprintf(buf + out, len - out,
Tiger Yangb89c5422010-01-25 14:11:06 +0800311 "%10s => InodeSlot: %d StolenInodes: %d, "
312 "MetaSlot: %d StolenMeta: %d\n", "Steal",
Sunil Mushran50397502008-12-17 14:17:43 -0800313 osb->s_inode_steal_slot,
Tiger Yangb89c5422010-01-25 14:11:06 +0800314 atomic_read(&osb->s_num_inodes_stolen),
315 osb->s_meta_steal_slot,
316 atomic_read(&osb->s_num_meta_stolen));
Sunil Mushran50397502008-12-17 14:17:43 -0800317 spin_unlock(&osb->osb_lock);
318
Sunil Mushrandf152c22009-06-22 11:40:07 -0700319 out += snprintf(buf + out, len - out, "OrphanScan => ");
320 out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
321 os->os_count, os->os_seqno);
322 out += snprintf(buf + out, len - out, " Last Scan: ");
323 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
324 out += snprintf(buf + out, len - out, "Disabled\n");
325 else
326 out += snprintf(buf + out, len - out, "%lu seconds ago\n",
327 (get_seconds() - os->os_scantime.tv_sec));
328
Sunil Mushran50397502008-12-17 14:17:43 -0800329 out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
330 "Slots", "Num", "RecoGen");
Sunil Mushran50397502008-12-17 14:17:43 -0800331 for (i = 0; i < osb->max_slots; ++i) {
332 out += snprintf(buf + out, len - out,
333 "%10s %c %3d %10d\n",
334 " ",
335 (i == osb->slot_num ? '*' : ' '),
336 i, osb->slot_recovery_generations[i]);
337 }
338
339 return out;
340}
341
342static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
343{
344 struct ocfs2_super *osb = inode->i_private;
345 char *buf = NULL;
346
347 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
348 if (!buf)
349 goto bail;
350
351 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
352
353 file->private_data = buf;
354
355 return 0;
356bail:
357 return -ENOMEM;
358}
359
360static int ocfs2_debug_release(struct inode *inode, struct file *file)
361{
362 kfree(file->private_data);
363 return 0;
364}
365
366static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
367 size_t nbytes, loff_t *ppos)
368{
369 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
370 i_size_read(file->f_mapping->host));
371}
372#else
373static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
374{
375 return 0;
376}
377static int ocfs2_debug_release(struct inode *inode, struct file *file)
378{
379 return 0;
380}
381static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
382 size_t nbytes, loff_t *ppos)
383{
384 return 0;
385}
386#endif /* CONFIG_DEBUG_FS */
387
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700388static const struct file_operations ocfs2_osb_debug_fops = {
Sunil Mushran50397502008-12-17 14:17:43 -0800389 .open = ocfs2_osb_debug_open,
390 .release = ocfs2_debug_release,
391 .read = ocfs2_debug_read,
392 .llseek = generic_file_llseek,
393};
394
Mark Fashehccd979b2005-12-15 14:31:24 -0800395static int ocfs2_sync_fs(struct super_block *sb, int wait)
396{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800397 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -0800398 tid_t target;
399 struct ocfs2_super *osb = OCFS2_SB(sb);
400
Mark Fashehccd979b2005-12-15 14:31:24 -0800401 if (ocfs2_is_hard_readonly(osb))
402 return -EROFS;
403
404 if (wait) {
405 status = ocfs2_flush_truncate_log(osb);
406 if (status < 0)
407 mlog_errno(status);
408 } else {
409 ocfs2_schedule_truncate_log_flush(osb, 0);
410 }
411
Joel Becker2b4e30f2008-09-03 20:03:41 -0700412 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
413 &target)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800414 if (wait)
Joel Becker2b4e30f2008-09-03 20:03:41 -0700415 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
416 target);
Mark Fashehccd979b2005-12-15 14:31:24 -0800417 }
418 return 0;
419}
420
Jan Kara1a224ad2008-08-20 15:43:36 +0200421static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
422{
423 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
424 && (ino == USER_QUOTA_SYSTEM_INODE
425 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
426 return 0;
427 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
428 && (ino == GROUP_QUOTA_SYSTEM_INODE
429 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
430 return 0;
431 return 1;
432}
433
Mark Fashehccd979b2005-12-15 14:31:24 -0800434static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
435{
436 struct inode *new = NULL;
437 int status = 0;
438 int i;
439
440 mlog_entry_void();
441
Jan Kara5fa06132008-01-11 00:11:45 +0100442 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800443 if (IS_ERR(new)) {
444 status = PTR_ERR(new);
445 mlog_errno(status);
446 goto bail;
447 }
448 osb->root_inode = new;
449
Jan Kara5fa06132008-01-11 00:11:45 +0100450 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800451 if (IS_ERR(new)) {
452 status = PTR_ERR(new);
453 mlog_errno(status);
454 goto bail;
455 }
456 osb->sys_root_inode = new;
457
458 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
459 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200460 if (!ocfs2_need_system_inode(osb, i))
461 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800462 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
463 if (!new) {
464 ocfs2_release_system_inodes(osb);
465 status = -EINVAL;
466 mlog_errno(status);
467 /* FIXME: Should ERROR_RO_FS */
468 mlog(ML_ERROR, "Unable to load system inode %d, "
469 "possibly corrupt fs?", i);
470 goto bail;
471 }
472 // the array now has one ref, so drop this one
473 iput(new);
474 }
475
476bail:
477 mlog_exit(status);
478 return status;
479}
480
481static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
482{
483 struct inode *new = NULL;
484 int status = 0;
485 int i;
486
487 mlog_entry_void();
488
489 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
490 i < NUM_SYSTEM_INODES;
491 i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200492 if (!ocfs2_need_system_inode(osb, i))
493 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800494 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
495 if (!new) {
496 ocfs2_release_system_inodes(osb);
497 status = -EINVAL;
498 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
499 status, i, osb->slot_num);
500 goto bail;
501 }
502 /* the array now has one ref, so drop this one */
503 iput(new);
504 }
505
506bail:
507 mlog_exit(status);
508 return status;
509}
510
Denis Chengbddb8eb32007-09-27 02:10:04 +0800511static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
Mark Fashehccd979b2005-12-15 14:31:24 -0800512{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800513 int i;
Mark Fashehccd979b2005-12-15 14:31:24 -0800514 struct inode *inode;
515
516 mlog_entry_void();
517
518 for (i = 0; i < NUM_SYSTEM_INODES; i++) {
519 inode = osb->system_inodes[i];
520 if (inode) {
521 iput(inode);
522 osb->system_inodes[i] = NULL;
523 }
524 }
525
526 inode = osb->sys_root_inode;
527 if (inode) {
528 iput(inode);
529 osb->sys_root_inode = NULL;
530 }
531
532 inode = osb->root_inode;
533 if (inode) {
534 iput(inode);
535 osb->root_inode = NULL;
536 }
537
Denis Chengbddb8eb32007-09-27 02:10:04 +0800538 mlog_exit(0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800539}
540
541/* We're allocating fs objects, use GFP_NOFS */
542static struct inode *ocfs2_alloc_inode(struct super_block *sb)
543{
544 struct ocfs2_inode_info *oi;
545
Christoph Lametere6b4f8d2006-12-06 20:33:14 -0800546 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
Mark Fashehccd979b2005-12-15 14:31:24 -0800547 if (!oi)
548 return NULL;
549
Joel Becker2b4e30f2008-09-03 20:03:41 -0700550 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -0800551 return &oi->vfs_inode;
552}
553
554static void ocfs2_destroy_inode(struct inode *inode)
555{
556 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
557}
558
Mark Fasheh5a254032007-07-20 12:56:16 -0700559static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
560 unsigned int cbits)
Mark Fashehccd979b2005-12-15 14:31:24 -0800561{
Mark Fasheh5a254032007-07-20 12:56:16 -0700562 unsigned int bytes = 1 << cbits;
563 unsigned int trim = bytes;
564 unsigned int bitshift = 32;
Mark Fashehccd979b2005-12-15 14:31:24 -0800565
Mark Fasheh5a254032007-07-20 12:56:16 -0700566 /*
567 * i_size and all block offsets in ocfs2 are always 64 bits
568 * wide. i_clusters is 32 bits, in cluster-sized units. So on
569 * 64 bit platforms, cluster size will be the limiting factor.
Mark Fashehccd979b2005-12-15 14:31:24 -0800570 */
571
572#if BITS_PER_LONG == 32
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +0200573# if defined(CONFIG_LBDAF)
Alexey Dobriyan2ecd05a2006-10-11 01:22:05 -0700574 BUILD_BUG_ON(sizeof(sector_t) != 8);
Mark Fasheh5a254032007-07-20 12:56:16 -0700575 /*
576 * We might be limited by page cache size.
577 */
578 if (bytes > PAGE_CACHE_SIZE) {
579 bytes = PAGE_CACHE_SIZE;
580 trim = 1;
581 /*
582 * Shift by 31 here so that we don't get larger than
583 * MAX_LFS_FILESIZE
584 */
585 bitshift = 31;
586 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800587# else
Mark Fasheh5a254032007-07-20 12:56:16 -0700588 /*
589 * We are limited by the size of sector_t. Use block size, as
590 * that's what we expose to the VFS.
591 */
592 bytes = 1 << bbits;
593 trim = 1;
594 bitshift = 31;
Mark Fashehccd979b2005-12-15 14:31:24 -0800595# endif
596#endif
597
Mark Fasheh5a254032007-07-20 12:56:16 -0700598 /*
599 * Trim by a whole cluster when we can actually approach the
600 * on-disk limits. Otherwise we can overflow i_clusters when
601 * an extent start is at the max offset.
602 */
603 return (((unsigned long long)bytes) << bitshift) - trim;
Mark Fashehccd979b2005-12-15 14:31:24 -0800604}
605
606static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
607{
608 int incompat_features;
609 int ret = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800610 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800611 struct ocfs2_super *osb = OCFS2_SB(sb);
612
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200613 lock_kernel();
614
Jan Kara5297aad2009-10-15 14:54:04 +0200615 if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
616 !ocfs2_check_set_options(sb, &parsed_options)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800617 ret = -EINVAL;
618 goto out;
619 }
620
621 if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800622 (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800623 ret = -EINVAL;
624 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
625 goto out;
626 }
627
628 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800629 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800630 ret = -EINVAL;
631 mlog(ML_ERROR, "Cannot change data mode on remount\n");
632 goto out;
633 }
634
Joel Becker12462f12008-09-03 20:03:40 -0700635 /* Probably don't want this on remount; it might
636 * mess with other nodes */
637 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
638 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
639 ret = -EINVAL;
640 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
641 goto out;
642 }
643
Mark Fashehccd979b2005-12-15 14:31:24 -0800644 /* We're going to/from readonly mode. */
645 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
Jan Kara19ece542008-08-21 20:13:17 +0200646 /* Disable quota accounting before remounting RO */
647 if (*flags & MS_RDONLY) {
648 ret = ocfs2_susp_quotas(osb, 0);
649 if (ret < 0)
650 goto out;
651 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800652 /* Lock here so the check of HARD_RO and the potential
653 * setting of SOFT_RO is atomic. */
654 spin_lock(&osb->osb_lock);
655 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
656 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
657 ret = -EROFS;
658 goto unlock_osb;
659 }
660
661 if (*flags & MS_RDONLY) {
662 mlog(0, "Going to ro mode.\n");
663 sb->s_flags |= MS_RDONLY;
664 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
665 } else {
666 mlog(0, "Making ro filesystem writeable.\n");
667
668 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
669 mlog(ML_ERROR, "Cannot remount RDWR "
670 "filesystem due to previous errors.\n");
671 ret = -EROFS;
672 goto unlock_osb;
673 }
674 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
675 if (incompat_features) {
676 mlog(ML_ERROR, "Cannot remount RDWR because "
677 "of unsupported optional features "
678 "(%x).\n", incompat_features);
679 ret = -EINVAL;
680 goto unlock_osb;
681 }
682 sb->s_flags &= ~MS_RDONLY;
683 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
684 }
685unlock_osb:
686 spin_unlock(&osb->osb_lock);
Jan Kara19ece542008-08-21 20:13:17 +0200687 /* Enable quota accounting after remounting RW */
688 if (!ret && !(*flags & MS_RDONLY)) {
689 if (sb_any_quota_suspended(sb))
690 ret = ocfs2_susp_quotas(osb, 1);
691 else
692 ret = ocfs2_enable_quotas(osb);
693 if (ret < 0) {
694 /* Return back changes... */
695 spin_lock(&osb->osb_lock);
696 sb->s_flags |= MS_RDONLY;
697 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
698 spin_unlock(&osb->osb_lock);
699 goto out;
700 }
701 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800702 }
703
704 if (!ret) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800705 /* Only save off the new mount options in case of a successful
706 * remount. */
Tiger Yangc0123ad2007-09-08 00:16:10 +0800707 osb->s_mount_opt = parsed_options.mount_opt;
708 osb->s_atime_quantum = parsed_options.atime_quantum;
709 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -0800710 if (parsed_options.commit_interval)
711 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fashehe001e792007-11-07 14:21:45 -0800712
713 if (!ocfs2_is_hard_readonly(osb))
714 ocfs2_set_journal_params(osb);
Jan Kara57b09bb2009-10-15 14:54:05 +0200715
716 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
717 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
718 MS_POSIXACL : 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800719 }
720out:
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200721 unlock_kernel();
Mark Fashehccd979b2005-12-15 14:31:24 -0800722 return ret;
723}
724
725static int ocfs2_sb_probe(struct super_block *sb,
726 struct buffer_head **bh,
Joel Becker73be1922009-01-06 14:57:08 -0800727 int *sector_size,
728 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -0800729{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800730 int status, tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800731 struct ocfs1_vol_disk_hdr *hdr;
732 struct ocfs2_dinode *di;
733 int blksize;
734
735 *bh = NULL;
736
737 /* may be > 512 */
Martin K. Petersene1defc42009-05-22 17:17:49 -0400738 *sector_size = bdev_logical_block_size(sb->s_bdev);
Mark Fashehccd979b2005-12-15 14:31:24 -0800739 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
740 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
741 *sector_size, OCFS2_MAX_BLOCKSIZE);
742 status = -EINVAL;
743 goto bail;
744 }
745
746 /* Can this really happen? */
747 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
748 *sector_size = OCFS2_MIN_BLOCKSIZE;
749
750 /* check block zero for old format */
751 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
752 if (status < 0) {
753 mlog_errno(status);
754 goto bail;
755 }
756 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
757 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
758 mlog(ML_ERROR, "incompatible version: %u.%u\n",
759 hdr->major_version, hdr->minor_version);
760 status = -EINVAL;
761 }
762 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
763 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
764 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
765 hdr->signature);
766 status = -EINVAL;
767 }
768 brelse(*bh);
769 *bh = NULL;
770 if (status < 0) {
771 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
772 "upgraded before mounting with ocfs v2\n");
773 goto bail;
774 }
775
776 /*
777 * Now check at magic offset for 512, 1024, 2048, 4096
778 * blocksizes. 4096 is the maximum blocksize because it is
779 * the minimum clustersize.
780 */
781 status = -EINVAL;
782 for (blksize = *sector_size;
783 blksize <= OCFS2_MAX_BLOCKSIZE;
784 blksize <<= 1) {
785 tmpstat = ocfs2_get_sector(sb, bh,
786 OCFS2_SUPER_BLOCK_BLKNO,
787 blksize);
788 if (tmpstat < 0) {
789 status = tmpstat;
790 mlog_errno(status);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700791 break;
Mark Fashehccd979b2005-12-15 14:31:24 -0800792 }
793 di = (struct ocfs2_dinode *) (*bh)->b_data;
Joel Becker73be1922009-01-06 14:57:08 -0800794 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
Jan Kara1c1d9792009-07-22 13:17:19 +0200795 spin_lock_init(&stats->b_lock);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700796 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
797 if (tmpstat < 0) {
798 brelse(*bh);
799 *bh = NULL;
800 }
801 if (tmpstat != -EAGAIN) {
802 status = tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800803 break;
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700804 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800805 }
806
807bail:
808 return status;
809}
810
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800811static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
812{
813 if (ocfs2_mount_local(osb)) {
814 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
815 mlog(ML_ERROR, "Cannot heartbeat on a locally "
816 "mounted device.\n");
817 return -EINVAL;
818 }
819 }
820
Joel Beckerb61817e2008-02-01 15:08:23 -0800821 if (ocfs2_userspace_stack(osb)) {
822 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
823 mlog(ML_ERROR, "Userspace stack expected, but "
824 "o2cb heartbeat arguments passed to mount\n");
825 return -EINVAL;
826 }
827 }
828
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800829 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800830 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
831 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800832 mlog(ML_ERROR, "Heartbeat has to be started to mount "
833 "a read-write clustered device.\n");
834 return -EINVAL;
835 }
836 }
837
838 return 0;
839}
840
Joel Beckerb61817e2008-02-01 15:08:23 -0800841/*
842 * If we're using a userspace stack, mount should have passed
843 * a name that matches the disk. If not, mount should not
844 * have passed a stack.
845 */
846static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
847 struct mount_options *mopt)
848{
849 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
850 mlog(ML_ERROR,
851 "cluster stack passed to mount, but this filesystem "
852 "does not support it\n");
853 return -EINVAL;
854 }
855
856 if (ocfs2_userspace_stack(osb) &&
857 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
858 OCFS2_STACK_LABEL_LEN)) {
859 mlog(ML_ERROR,
860 "cluster stack passed to mount (\"%s\") does not "
861 "match the filesystem (\"%s\")\n",
862 mopt->cluster_stack,
863 osb->osb_cluster_stack);
864 return -EINVAL;
865 }
866
867 return 0;
868}
869
Jan Kara19ece542008-08-21 20:13:17 +0200870static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
871{
872 int type;
873 struct super_block *sb = osb->sb;
874 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
875 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
876 int status = 0;
877
878 for (type = 0; type < MAXQUOTAS; type++) {
879 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
880 continue;
881 if (unsuspend)
882 status = vfs_quota_enable(
883 sb_dqopt(sb)->files[type],
884 type, QFMT_OCFS2,
885 DQUOT_SUSPENDED);
Jan Karaeea7feb2010-05-13 22:14:53 +0200886 else {
887 struct ocfs2_mem_dqinfo *oinfo;
888
889 /* Cancel periodic syncing before suspending */
890 oinfo = sb_dqinfo(sb, type)->dqi_priv;
891 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
Jan Kara19ece542008-08-21 20:13:17 +0200892 status = vfs_quota_disable(sb, type,
893 DQUOT_SUSPENDED);
Jan Karaeea7feb2010-05-13 22:14:53 +0200894 }
Jan Kara19ece542008-08-21 20:13:17 +0200895 if (status < 0)
896 break;
897 }
898 if (status < 0)
899 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
900 "remount (error = %d).\n", status);
901 return status;
902}
903
904static int ocfs2_enable_quotas(struct ocfs2_super *osb)
905{
906 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
907 struct super_block *sb = osb->sb;
908 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
909 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
910 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
911 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
912 int status;
913 int type;
914
915 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
916 for (type = 0; type < MAXQUOTAS; type++) {
917 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
918 continue;
919 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
920 osb->slot_num);
921 if (!inode[type]) {
922 status = -ENOENT;
923 goto out_quota_off;
924 }
925 status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
926 DQUOT_USAGE_ENABLED);
927 if (status < 0)
928 goto out_quota_off;
929 }
930
931 for (type = 0; type < MAXQUOTAS; type++)
932 iput(inode[type]);
933 return 0;
934out_quota_off:
935 ocfs2_disable_quotas(osb);
936 for (type = 0; type < MAXQUOTAS; type++)
937 iput(inode[type]);
938 mlog_errno(status);
939 return status;
940}
941
942static void ocfs2_disable_quotas(struct ocfs2_super *osb)
943{
944 int type;
945 struct inode *inode;
946 struct super_block *sb = osb->sb;
Jan Karac06bcbf2010-05-13 22:14:53 +0200947 struct ocfs2_mem_dqinfo *oinfo;
Jan Kara19ece542008-08-21 20:13:17 +0200948
949 /* We mostly ignore errors in this function because there's not much
950 * we can do when we see them */
951 for (type = 0; type < MAXQUOTAS; type++) {
952 if (!sb_has_quota_loaded(sb, type))
953 continue;
Jan Karac06bcbf2010-05-13 22:14:53 +0200954 /* Cancel periodic syncing before we grab dqonoff_mutex */
955 oinfo = sb_dqinfo(sb, type)->dqi_priv;
956 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
Jan Kara19ece542008-08-21 20:13:17 +0200957 inode = igrab(sb->s_dquot.files[type]);
958 /* Turn off quotas. This will remove all dquot structures from
959 * memory and so they will be automatically synced to global
960 * quota files */
961 vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
962 DQUOT_LIMITS_ENABLED);
963 if (!inode)
964 continue;
965 iput(inode);
966 }
967}
968
969/* Handle quota on quotactl */
970static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
971 char *path, int remount)
972{
973 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
974 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
975
976 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
977 return -EINVAL;
978
979 if (remount)
980 return 0; /* Just ignore it has been handled in
981 * ocfs2_remount() */
982 return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
983 format_id, DQUOT_LIMITS_ENABLED);
984}
985
986/* Handle quota off quotactl */
987static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
988{
989 if (remount)
990 return 0; /* Ignore now and handle later in
991 * ocfs2_remount() */
992 return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
993}
994
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700995static const struct quotactl_ops ocfs2_quotactl_ops = {
Jan Kara19ece542008-08-21 20:13:17 +0200996 .quota_on = ocfs2_quota_on,
997 .quota_off = ocfs2_quota_off,
998 .quota_sync = vfs_quota_sync,
999 .get_info = vfs_get_dqinfo,
1000 .set_info = vfs_set_dqinfo,
1001 .get_dqblk = vfs_get_dqblk,
1002 .set_dqblk = vfs_set_dqblk,
1003};
1004
Mark Fashehccd979b2005-12-15 14:31:24 -08001005static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
1006{
1007 struct dentry *root;
1008 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001009 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -08001010 struct inode *inode = NULL;
1011 struct ocfs2_super *osb = NULL;
1012 struct buffer_head *bh = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001013 char nodestr[8];
Joel Becker73be1922009-01-06 14:57:08 -08001014 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -08001015
1016 mlog_entry("%p, %p, %i", sb, data, silent);
1017
Tiger Yangc0123ad2007-09-08 00:16:10 +08001018 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001019 status = -EINVAL;
1020 goto read_super_error;
1021 }
1022
1023 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -08001024 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001025 if (status < 0) {
1026 mlog(ML_ERROR, "superblock probe failed!\n");
1027 goto read_super_error;
1028 }
1029
Joel Becker73be1922009-01-06 14:57:08 -08001030 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001031 osb = OCFS2_SB(sb);
1032 if (status < 0) {
1033 mlog_errno(status);
1034 goto read_super_error;
1035 }
1036 brelse(bh);
1037 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001038
Jan Kara5297aad2009-10-15 14:54:04 +02001039 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1040 status = -EINVAL;
1041 goto read_super_error;
1042 }
Tiger Yangc0123ad2007-09-08 00:16:10 +08001043 osb->s_mount_opt = parsed_options.mount_opt;
1044 osb->s_atime_quantum = parsed_options.atime_quantum;
1045 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001046 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh73c8a802010-04-05 18:17:13 -07001047
1048 ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
Mark Fashehd02f00c2009-12-07 13:10:48 -08001049 osb->osb_resv_level = parsed_options.resv_level;
Mark Fasheh83f92312010-04-05 18:17:16 -07001050 osb->osb_dir_resv_level = parsed_options.resv_level;
1051 if (parsed_options.dir_resv_level == -1)
1052 osb->osb_dir_resv_level = parsed_options.resv_level;
1053 else
1054 osb->osb_dir_resv_level = parsed_options.dir_resv_level;
Mark Fashehccd979b2005-12-15 14:31:24 -08001055
Joel Beckerb61817e2008-02-01 15:08:23 -08001056 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1057 if (status)
1058 goto read_super_error;
1059
Mark Fashehccd979b2005-12-15 14:31:24 -08001060 sb->s_magic = OCFS2_SUPER_MAGIC;
1061
Tiger Yanga68979b2008-11-14 11:17:52 +08001062 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1063 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1064
Mark Fashehccd979b2005-12-15 14:31:24 -08001065 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1066 * heartbeat=none */
1067 if (bdev_read_only(sb->s_bdev)) {
1068 if (!(sb->s_flags & MS_RDONLY)) {
1069 status = -EACCES;
1070 mlog(ML_ERROR, "Readonly device detected but readonly "
1071 "mount was not specified.\n");
1072 goto read_super_error;
1073 }
1074
1075 /* You should not be able to start a local heartbeat
1076 * on a readonly device. */
1077 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1078 status = -EROFS;
1079 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1080 "device.\n");
1081 goto read_super_error;
1082 }
1083
1084 status = ocfs2_check_journals_nolocks(osb);
1085 if (status < 0) {
1086 if (status == -EROFS)
1087 mlog(ML_ERROR, "Recovery required on readonly "
1088 "file system, but write access is "
1089 "unavailable.\n");
1090 else
Sunil Mushran2bd63212010-01-25 16:57:38 -08001091 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -08001092 goto read_super_error;
1093 }
1094
1095 ocfs2_set_ro_flag(osb, 1);
1096
1097 printk(KERN_NOTICE "Readonly device detected. No cluster "
1098 "services will be utilized for this mount. Recovery "
1099 "will be skipped.\n");
1100 }
1101
1102 if (!ocfs2_is_hard_readonly(osb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001103 if (sb->s_flags & MS_RDONLY)
1104 ocfs2_set_ro_flag(osb, 0);
1105 }
1106
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001107 status = ocfs2_verify_heartbeat(osb);
1108 if (status < 0) {
1109 mlog_errno(status);
1110 goto read_super_error;
1111 }
1112
Mark Fashehccd979b2005-12-15 14:31:24 -08001113 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1114 ocfs2_debugfs_root);
1115 if (!osb->osb_debug_root) {
1116 status = -EINVAL;
1117 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1118 goto read_super_error;
1119 }
1120
Sunil Mushran50397502008-12-17 14:17:43 -08001121 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1122 osb->osb_debug_root,
1123 osb,
1124 &ocfs2_osb_debug_fops);
1125 if (!osb->osb_ctxt) {
1126 status = -EINVAL;
1127 mlog_errno(status);
1128 goto read_super_error;
1129 }
1130
Joel Becker73be1922009-01-06 14:57:08 -08001131 if (ocfs2_meta_ecc(osb)) {
1132 status = ocfs2_blockcheck_stats_debugfs_install(
1133 &osb->osb_ecc_stats,
1134 osb->osb_debug_root);
1135 if (status) {
1136 mlog(ML_ERROR,
1137 "Unable to create blockcheck statistics "
1138 "files\n");
1139 goto read_super_error;
1140 }
1141 }
1142
Mark Fashehccd979b2005-12-15 14:31:24 -08001143 status = ocfs2_mount_volume(sb);
1144 if (osb->root_inode)
1145 inode = igrab(osb->root_inode);
1146
1147 if (status < 0)
1148 goto read_super_error;
1149
1150 if (!inode) {
1151 status = -EIO;
1152 mlog_errno(status);
1153 goto read_super_error;
1154 }
1155
1156 root = d_alloc_root(inode);
1157 if (!root) {
1158 status = -ENOMEM;
1159 mlog_errno(status);
1160 goto read_super_error;
1161 }
1162
1163 sb->s_root = root;
1164
1165 ocfs2_complete_mount_recovery(osb);
1166
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001167 if (ocfs2_mount_local(osb))
1168 snprintf(nodestr, sizeof(nodestr), "local");
1169 else
Joel Becker19fdb622008-01-30 15:38:24 -08001170 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001171
1172 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001173 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001174 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001175 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1176 "ordered");
1177
1178 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1179 wake_up(&osb->osb_mount_event);
1180
Jan Kara19ece542008-08-21 20:13:17 +02001181 /* Now we can initialize quotas because we can afford to wait
1182 * for cluster locks recovery now. That also means that truncation
1183 * log recovery can happen but that waits for proper quota setup */
1184 if (!(sb->s_flags & MS_RDONLY)) {
1185 status = ocfs2_enable_quotas(osb);
1186 if (status < 0) {
1187 /* We have to err-out specially here because
1188 * s_root is already set */
1189 mlog_errno(status);
1190 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1191 wake_up(&osb->osb_mount_event);
1192 mlog_exit(status);
1193 return status;
1194 }
1195 }
1196
1197 ocfs2_complete_quota_recovery(osb);
1198
1199 /* Now we wake up again for processes waiting for quotas */
1200 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1201 wake_up(&osb->osb_mount_event);
1202
Sunil Mushrandf152c22009-06-22 11:40:07 -07001203 /* Start this when the mount is almost sure of being successful */
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04001204 ocfs2_orphan_scan_start(osb);
Sunil Mushrandf152c22009-06-22 11:40:07 -07001205
Mark Fashehccd979b2005-12-15 14:31:24 -08001206 mlog_exit(status);
1207 return status;
1208
1209read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001210 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001211
1212 if (inode)
1213 iput(inode);
1214
1215 if (osb) {
1216 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1217 wake_up(&osb->osb_mount_event);
1218 ocfs2_dismount_volume(sb, 1);
1219 }
1220
1221 mlog_exit(status);
1222 return status;
1223}
1224
David Howells454e2392006-06-23 02:02:57 -07001225static int ocfs2_get_sb(struct file_system_type *fs_type,
1226 int flags,
1227 const char *dev_name,
1228 void *data,
1229 struct vfsmount *mnt)
Mark Fashehccd979b2005-12-15 14:31:24 -08001230{
David Howells454e2392006-06-23 02:02:57 -07001231 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1232 mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -08001233}
1234
Jan Karaf7b1aa62009-07-20 12:12:36 +02001235static void ocfs2_kill_sb(struct super_block *sb)
1236{
1237 struct ocfs2_super *osb = OCFS2_SB(sb);
1238
Jan Kara5fd13182009-07-30 17:01:53 +02001239 /* Failed mount? */
1240 if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1241 goto out;
1242
Jan Karaf7b1aa62009-07-20 12:12:36 +02001243 /* Prevent further queueing of inode drop events */
1244 spin_lock(&dentry_list_lock);
1245 ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1246 spin_unlock(&dentry_list_lock);
1247 /* Wait for work to finish and/or remove it */
1248 cancel_work_sync(&osb->dentry_lock_work);
Jan Kara5fd13182009-07-30 17:01:53 +02001249out:
Jan Karaf7b1aa62009-07-20 12:12:36 +02001250 kill_block_super(sb);
1251}
1252
Mark Fashehccd979b2005-12-15 14:31:24 -08001253static struct file_system_type ocfs2_fs_type = {
1254 .owner = THIS_MODULE,
1255 .name = "ocfs2",
1256 .get_sb = ocfs2_get_sb, /* is this called when we mount
1257 * the fs? */
Jan Karaf7b1aa62009-07-20 12:12:36 +02001258 .kill_sb = ocfs2_kill_sb,
1259
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001260 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001261 .next = NULL
1262};
1263
Jan Kara5297aad2009-10-15 14:54:04 +02001264static int ocfs2_check_set_options(struct super_block *sb,
1265 struct mount_options *options)
1266{
1267 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1268 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1269 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1270 mlog(ML_ERROR, "User quotas were requested, but this "
1271 "filesystem does not have the feature enabled.\n");
1272 return 0;
1273 }
1274 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1275 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1276 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1277 mlog(ML_ERROR, "Group quotas were requested, but this "
1278 "filesystem does not have the feature enabled.\n");
1279 return 0;
1280 }
1281 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1282 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1283 mlog(ML_ERROR, "ACL support requested but extended attributes "
1284 "feature is not enabled\n");
1285 return 0;
1286 }
1287 /* No ACL setting specified? Use XATTR feature... */
1288 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1289 OCFS2_MOUNT_NO_POSIX_ACL))) {
1290 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1291 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1292 else
1293 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1294 }
1295 return 1;
1296}
1297
Mark Fashehccd979b2005-12-15 14:31:24 -08001298static int ocfs2_parse_options(struct super_block *sb,
1299 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001300 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001301 int is_remount)
1302{
1303 int status;
1304 char *p;
1305
1306 mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
1307 options ? options : "(none)");
1308
Mark Fashehd147b3d2007-11-07 14:40:36 -08001309 mopt->commit_interval = 0;
Sunil Mushran4b37fcb2010-04-13 18:00:31 -07001310 mopt->mount_opt = OCFS2_MOUNT_NOINTR;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001311 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1312 mopt->slot = OCFS2_INVALID_SLOT;
Mark Fasheh73c8a802010-04-05 18:17:13 -07001313 mopt->localalloc_opt = -1;
Joel Beckerb61817e2008-02-01 15:08:23 -08001314 mopt->cluster_stack[0] = '\0';
Mark Fashehd02f00c2009-12-07 13:10:48 -08001315 mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
Mark Fasheh83f92312010-04-05 18:17:16 -07001316 mopt->dir_resv_level = -1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001317
1318 if (!options) {
1319 status = 1;
1320 goto bail;
1321 }
1322
1323 while ((p = strsep(&options, ",")) != NULL) {
1324 int token, option;
1325 substring_t args[MAX_OPT_ARGS];
1326
1327 if (!*p)
1328 continue;
1329
1330 token = match_token(p, tokens, args);
1331 switch (token) {
1332 case Opt_hb_local:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001333 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001334 break;
1335 case Opt_hb_none:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001336 mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001337 break;
1338 case Opt_barrier:
1339 if (match_int(&args[0], &option)) {
1340 status = 0;
1341 goto bail;
1342 }
1343 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001344 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001345 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001346 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001347 break;
1348 case Opt_intr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001349 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001350 break;
1351 case Opt_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001352 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001353 break;
1354 case Opt_err_panic:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001355 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001356 break;
1357 case Opt_err_ro:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001358 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001359 break;
1360 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001361 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001362 break;
1363 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001364 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001365 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001366 case Opt_user_xattr:
1367 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1368 break;
1369 case Opt_nouser_xattr:
1370 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1371 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001372 case Opt_atime_quantum:
1373 if (match_int(&args[0], &option)) {
1374 status = 0;
1375 goto bail;
1376 }
1377 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001378 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001379 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001380 case Opt_slot:
1381 option = 0;
1382 if (match_int(&args[0], &option)) {
1383 status = 0;
1384 goto bail;
1385 }
1386 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001387 mopt->slot = (s16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001388 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001389 case Opt_commit:
1390 option = 0;
1391 if (match_int(&args[0], &option)) {
1392 status = 0;
1393 goto bail;
1394 }
1395 if (option < 0)
1396 return 0;
1397 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001398 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001399 mopt->commit_interval = HZ * option;
1400 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001401 case Opt_localalloc:
1402 option = 0;
1403 if (match_int(&args[0], &option)) {
1404 status = 0;
1405 goto bail;
1406 }
Mark Fasheh73c8a802010-04-05 18:17:13 -07001407 if (option >= 0)
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001408 mopt->localalloc_opt = option;
1409 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001410 case Opt_localflocks:
1411 /*
1412 * Changing this during remount could race
1413 * flock() requests, or "unbalance" existing
1414 * ones (e.g., a lock is taken in one mode but
1415 * dropped in the other). If users care enough
1416 * to flip locking modes during remount, we
1417 * could add a "local" flag to individual
1418 * flock structures for proper tracking of
1419 * state.
1420 */
1421 if (!is_remount)
1422 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1423 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001424 case Opt_stack:
1425 /* Check both that the option we were passed
1426 * is of the right length and that it is a proper
1427 * string of the right length.
1428 */
1429 if (((args[0].to - args[0].from) !=
1430 OCFS2_STACK_LABEL_LEN) ||
1431 (strnlen(args[0].from,
1432 OCFS2_STACK_LABEL_LEN) !=
1433 OCFS2_STACK_LABEL_LEN)) {
1434 mlog(ML_ERROR,
1435 "Invalid cluster_stack option\n");
1436 status = 0;
1437 goto bail;
1438 }
1439 memcpy(mopt->cluster_stack, args[0].from,
1440 OCFS2_STACK_LABEL_LEN);
1441 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1442 break;
Joel Becker12462f12008-09-03 20:03:40 -07001443 case Opt_inode64:
1444 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1445 break;
Jan Kara19ece542008-08-21 20:13:17 +02001446 case Opt_usrquota:
Jan Kara19ece542008-08-21 20:13:17 +02001447 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1448 break;
1449 case Opt_grpquota:
Jan Kara19ece542008-08-21 20:13:17 +02001450 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1451 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001452 case Opt_acl:
1453 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
Jan Kara5297aad2009-10-15 14:54:04 +02001454 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001455 break;
1456 case Opt_noacl:
Jan Kara5297aad2009-10-15 14:54:04 +02001457 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001458 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1459 break;
Mark Fashehd02f00c2009-12-07 13:10:48 -08001460 case Opt_resv_level:
1461 if (is_remount)
1462 break;
1463 if (match_int(&args[0], &option)) {
1464 status = 0;
1465 goto bail;
1466 }
1467 if (option >= OCFS2_MIN_RESV_LEVEL &&
1468 option < OCFS2_MAX_RESV_LEVEL)
1469 mopt->resv_level = option;
1470 break;
Mark Fasheh83f92312010-04-05 18:17:16 -07001471 case Opt_dir_resv_level:
1472 if (is_remount)
1473 break;
1474 if (match_int(&args[0], &option)) {
1475 status = 0;
1476 goto bail;
1477 }
1478 if (option >= OCFS2_MIN_RESV_LEVEL &&
1479 option < OCFS2_MAX_RESV_LEVEL)
1480 mopt->dir_resv_level = option;
1481 break;
Mark Fashehccd979b2005-12-15 14:31:24 -08001482 default:
1483 mlog(ML_ERROR,
1484 "Unrecognized mount option \"%s\" "
1485 "or missing value\n", p);
1486 status = 0;
1487 goto bail;
1488 }
1489 }
1490
1491 status = 1;
1492
1493bail:
1494 mlog_exit(status);
1495 return status;
1496}
1497
Sunil Mushrand5500712007-09-06 13:34:16 -07001498static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1499{
1500 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1501 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001502 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001503
1504 if (opts & OCFS2_MOUNT_HB_LOCAL)
1505 seq_printf(s, ",_netdev,heartbeat=local");
1506 else
1507 seq_printf(s, ",heartbeat=none");
1508
1509 if (opts & OCFS2_MOUNT_NOINTR)
1510 seq_printf(s, ",nointr");
1511
1512 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1513 seq_printf(s, ",data=writeback");
1514 else
1515 seq_printf(s, ",data=ordered");
1516
1517 if (opts & OCFS2_MOUNT_BARRIER)
1518 seq_printf(s, ",barrier=1");
1519
1520 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1521 seq_printf(s, ",errors=panic");
1522 else
1523 seq_printf(s, ",errors=remount-ro");
1524
1525 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1526 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1527
1528 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1529 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1530
Mark Fashehd147b3d2007-11-07 14:40:36 -08001531 if (osb->osb_commit_interval)
1532 seq_printf(s, ",commit=%u",
1533 (unsigned) (osb->osb_commit_interval / HZ));
1534
Mark Fashehebcee4b2008-07-28 14:55:20 -07001535 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
Mark Fasheh6b820212010-04-05 18:17:14 -07001536 if (local_alloc_megs != ocfs2_la_default_mb(osb))
Mark Fashehebcee4b2008-07-28 14:55:20 -07001537 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001538
Mark Fasheh53fc6222007-12-20 16:49:04 -08001539 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1540 seq_printf(s, ",localflocks,");
1541
Joel Beckerb61817e2008-02-01 15:08:23 -08001542 if (osb->osb_cluster_stack[0])
1543 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1544 osb->osb_cluster_stack);
Jan Kara19ece542008-08-21 20:13:17 +02001545 if (opts & OCFS2_MOUNT_USRQUOTA)
1546 seq_printf(s, ",usrquota");
1547 if (opts & OCFS2_MOUNT_GRPQUOTA)
1548 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001549
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001550 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1551 seq_printf(s, ",nouser_xattr");
1552 else
1553 seq_printf(s, ",user_xattr");
1554
Joel Becker12462f12008-09-03 20:03:40 -07001555 if (opts & OCFS2_MOUNT_INODE64)
1556 seq_printf(s, ",inode64");
1557
Tiger Yanga68979b2008-11-14 11:17:52 +08001558 if (opts & OCFS2_MOUNT_POSIX_ACL)
1559 seq_printf(s, ",acl");
1560 else
1561 seq_printf(s, ",noacl");
Tiger Yanga68979b2008-11-14 11:17:52 +08001562
Mark Fashehd02f00c2009-12-07 13:10:48 -08001563 if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
1564 seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
1565
Mark Fasheh83f92312010-04-05 18:17:16 -07001566 if (osb->osb_dir_resv_level != osb->osb_resv_level)
1567 seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
1568
Sunil Mushrand5500712007-09-06 13:34:16 -07001569 return 0;
1570}
1571
Mark Fashehccd979b2005-12-15 14:31:24 -08001572static int __init ocfs2_init(void)
1573{
1574 int status;
1575
1576 mlog_entry_void();
1577
1578 ocfs2_print_version();
1579
Mark Fashehccd979b2005-12-15 14:31:24 -08001580 status = init_ocfs2_uptodate_cache();
1581 if (status < 0) {
1582 mlog_errno(status);
1583 goto leave;
1584 }
1585
1586 status = ocfs2_initialize_mem_caches();
1587 if (status < 0) {
1588 mlog_errno(status);
1589 goto leave;
1590 }
1591
1592 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1593 if (!ocfs2_wq) {
1594 status = -ENOMEM;
1595 goto leave;
1596 }
1597
Mark Fashehccd979b2005-12-15 14:31:24 -08001598 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1599 if (!ocfs2_debugfs_root) {
1600 status = -EFAULT;
1601 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1602 }
1603
Mark Fasheh171bf932008-10-20 15:36:47 +02001604 status = ocfs2_quota_setup();
1605 if (status)
1606 goto leave;
1607
Joel Becker63e0c482008-01-30 16:58:36 -08001608 ocfs2_set_locking_protocol();
1609
Jan Kara9e33d692008-08-25 19:56:50 +02001610 status = register_quota_format(&ocfs2_quota_format);
Mark Fashehccd979b2005-12-15 14:31:24 -08001611leave:
1612 if (status < 0) {
Mark Fasheh171bf932008-10-20 15:36:47 +02001613 ocfs2_quota_shutdown();
Mark Fashehccd979b2005-12-15 14:31:24 -08001614 ocfs2_free_mem_caches();
1615 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001616 }
1617
1618 mlog_exit(status);
1619
1620 if (status >= 0) {
1621 return register_filesystem(&ocfs2_fs_type);
1622 } else
1623 return -1;
1624}
1625
1626static void __exit ocfs2_exit(void)
1627{
1628 mlog_entry_void();
1629
Mark Fasheh171bf932008-10-20 15:36:47 +02001630 ocfs2_quota_shutdown();
1631
Mark Fashehccd979b2005-12-15 14:31:24 -08001632 if (ocfs2_wq) {
1633 flush_workqueue(ocfs2_wq);
1634 destroy_workqueue(ocfs2_wq);
1635 }
1636
Jan Kara9e33d692008-08-25 19:56:50 +02001637 unregister_quota_format(&ocfs2_quota_format);
1638
Mark Fashehccd979b2005-12-15 14:31:24 -08001639 debugfs_remove(ocfs2_debugfs_root);
1640
1641 ocfs2_free_mem_caches();
1642
1643 unregister_filesystem(&ocfs2_fs_type);
1644
Mark Fashehccd979b2005-12-15 14:31:24 -08001645 exit_ocfs2_uptodate_cache();
1646
1647 mlog_exit_void();
1648}
1649
1650static void ocfs2_put_super(struct super_block *sb)
1651{
1652 mlog_entry("(0x%p)\n", sb);
1653
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001654 lock_kernel();
1655
Mark Fashehccd979b2005-12-15 14:31:24 -08001656 ocfs2_sync_blockdev(sb);
1657 ocfs2_dismount_volume(sb, 0);
1658
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001659 unlock_kernel();
1660
Mark Fashehccd979b2005-12-15 14:31:24 -08001661 mlog_exit_void();
1662}
1663
David Howells726c3342006-06-23 02:02:58 -07001664static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001665{
1666 struct ocfs2_super *osb;
1667 u32 numbits, freebits;
1668 int status;
1669 struct ocfs2_dinode *bm_lock;
1670 struct buffer_head *bh = NULL;
1671 struct inode *inode = NULL;
1672
David Howells726c3342006-06-23 02:02:58 -07001673 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001674
David Howells726c3342006-06-23 02:02:58 -07001675 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001676
1677 inode = ocfs2_get_system_file_inode(osb,
1678 GLOBAL_BITMAP_SYSTEM_INODE,
1679 OCFS2_INVALID_SLOT);
1680 if (!inode) {
1681 mlog(ML_ERROR, "failed to get bitmap inode\n");
1682 status = -EIO;
1683 goto bail;
1684 }
1685
Mark Fashehe63aecb62007-10-18 15:30:42 -07001686 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001687 if (status < 0) {
1688 mlog_errno(status);
1689 goto bail;
1690 }
1691
1692 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1693
1694 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1695 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1696
1697 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001698 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001699 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1700 buf->f_blocks = ((sector_t) numbits) *
1701 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1702 buf->f_bfree = ((sector_t) freebits) *
1703 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1704 buf->f_bavail = buf->f_bfree;
1705 buf->f_files = numbits;
1706 buf->f_ffree = freebits;
Coly Li837711f2009-01-16 16:33:05 +08001707 buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1708 & 0xFFFFFFFFUL;
1709 buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1710 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001711
1712 brelse(bh);
1713
Mark Fashehe63aecb62007-10-18 15:30:42 -07001714 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001715 status = 0;
1716bail:
1717 if (inode)
1718 iput(inode);
1719
1720 mlog_exit(status);
1721
1722 return status;
1723}
1724
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001725static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001726{
1727 struct ocfs2_inode_info *oi = data;
1728
Christoph Lametera35afb82007-05-16 22:10:57 -07001729 oi->ip_flags = 0;
1730 oi->ip_open_count = 0;
1731 spin_lock_init(&oi->ip_lock);
1732 ocfs2_extent_map_init(&oi->vfs_inode);
1733 INIT_LIST_HEAD(&oi->ip_io_markers);
Christoph Lametera35afb82007-05-16 22:10:57 -07001734 oi->ip_dir_start_lookup = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001735
Christoph Lametera35afb82007-05-16 22:10:57 -07001736 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001737 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001738 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001739
Christoph Lametera35afb82007-05-16 22:10:57 -07001740 oi->ip_blkno = 0ULL;
1741 oi->ip_clusters = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001742
Mark Fasheh4fe370a2009-12-07 13:15:40 -08001743 ocfs2_resv_init_once(&oi->ip_la_data_resv);
1744
Christoph Lametera35afb82007-05-16 22:10:57 -07001745 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001746 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001747 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001748
Joel Becker8cb471e2009-02-10 20:00:41 -08001749 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
Joel Becker6e5a3d72009-02-10 19:00:37 -08001750 &ocfs2_inode_caching_ops);
Mark Fashehccd979b2005-12-15 14:31:24 -08001751
Christoph Lametera35afb82007-05-16 22:10:57 -07001752 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001753}
1754
1755static int ocfs2_initialize_mem_caches(void)
1756{
1757 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001758 sizeof(struct ocfs2_inode_info),
1759 0,
1760 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1761 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001762 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001763 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1764 sizeof(struct ocfs2_dquot),
1765 0,
1766 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1767 SLAB_MEM_SPREAD),
1768 NULL);
1769 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1770 sizeof(struct ocfs2_quota_chunk),
1771 0,
1772 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1773 NULL);
1774 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1775 !ocfs2_qf_chunk_cachep) {
1776 if (ocfs2_inode_cachep)
1777 kmem_cache_destroy(ocfs2_inode_cachep);
1778 if (ocfs2_dquot_cachep)
1779 kmem_cache_destroy(ocfs2_dquot_cachep);
1780 if (ocfs2_qf_chunk_cachep)
1781 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001782 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001783 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001784
Mark Fashehccd979b2005-12-15 14:31:24 -08001785 return 0;
1786}
1787
1788static void ocfs2_free_mem_caches(void)
1789{
1790 if (ocfs2_inode_cachep)
1791 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001792 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001793
1794 if (ocfs2_dquot_cachep)
1795 kmem_cache_destroy(ocfs2_dquot_cachep);
1796 ocfs2_dquot_cachep = NULL;
1797
1798 if (ocfs2_qf_chunk_cachep)
1799 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1800 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001801}
1802
1803static int ocfs2_get_sector(struct super_block *sb,
1804 struct buffer_head **bh,
1805 int block,
1806 int sect_size)
1807{
1808 if (!sb_set_blocksize(sb, sect_size)) {
1809 mlog(ML_ERROR, "unable to set blocksize\n");
1810 return -EIO;
1811 }
1812
1813 *bh = sb_getblk(sb, block);
1814 if (!*bh) {
1815 mlog_errno(-EIO);
1816 return -EIO;
1817 }
1818 lock_buffer(*bh);
1819 if (!buffer_dirty(*bh))
1820 clear_buffer_uptodate(*bh);
1821 unlock_buffer(*bh);
1822 ll_rw_block(READ, 1, bh);
1823 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001824 if (!buffer_uptodate(*bh)) {
1825 mlog_errno(-EIO);
1826 brelse(*bh);
1827 *bh = NULL;
1828 return -EIO;
1829 }
1830
Mark Fashehccd979b2005-12-15 14:31:24 -08001831 return 0;
1832}
1833
Mark Fashehccd979b2005-12-15 14:31:24 -08001834static int ocfs2_mount_volume(struct super_block *sb)
1835{
1836 int status = 0;
1837 int unlock_super = 0;
1838 struct ocfs2_super *osb = OCFS2_SB(sb);
1839
1840 mlog_entry_void();
1841
1842 if (ocfs2_is_hard_readonly(osb))
1843 goto leave;
1844
Mark Fashehccd979b2005-12-15 14:31:24 -08001845 status = ocfs2_dlm_init(osb);
1846 if (status < 0) {
1847 mlog_errno(status);
1848 goto leave;
1849 }
1850
Mark Fashehccd979b2005-12-15 14:31:24 -08001851 status = ocfs2_super_lock(osb, 1);
1852 if (status < 0) {
1853 mlog_errno(status);
1854 goto leave;
1855 }
1856 unlock_super = 1;
1857
1858 /* This will load up the node map and add ourselves to it. */
1859 status = ocfs2_find_slot(osb);
1860 if (status < 0) {
1861 mlog_errno(status);
1862 goto leave;
1863 }
1864
Mark Fashehccd979b2005-12-15 14:31:24 -08001865 /* load all node-local system inodes */
1866 status = ocfs2_init_local_system_inodes(osb);
1867 if (status < 0) {
1868 mlog_errno(status);
1869 goto leave;
1870 }
1871
1872 status = ocfs2_check_volume(osb);
1873 if (status < 0) {
1874 mlog_errno(status);
1875 goto leave;
1876 }
1877
1878 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001879 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001880 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001881
Mark Fashehccd979b2005-12-15 14:31:24 -08001882leave:
1883 if (unlock_super)
1884 ocfs2_super_unlock(osb, 1);
1885
1886 mlog_exit(status);
1887 return status;
1888}
1889
Mark Fashehccd979b2005-12-15 14:31:24 -08001890static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1891{
Joel Becker286eaa92008-02-01 15:03:57 -08001892 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001893 struct ocfs2_super *osb = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001894 char nodestr[8];
Mark Fashehccd979b2005-12-15 14:31:24 -08001895
1896 mlog_entry("(0x%p)\n", sb);
1897
1898 BUG_ON(!sb);
1899 osb = OCFS2_SB(sb);
1900 BUG_ON(!osb);
1901
Sunil Mushran50397502008-12-17 14:17:43 -08001902 debugfs_remove(osb->osb_ctxt);
1903
Jan Karaf7b1aa62009-07-20 12:12:36 +02001904 /*
1905 * Flush inode dropping work queue so that deletes are
1906 * performed while the filesystem is still working
1907 */
1908 ocfs2_drop_all_dl_inodes(osb);
1909
Sunil Mushran692684e2009-06-19 16:53:17 -07001910 /* Orphan scan should be stopped as early as possible */
1911 ocfs2_orphan_scan_stop(osb);
1912
Jan Kara19ece542008-08-21 20:13:17 +02001913 ocfs2_disable_quotas(osb);
1914
Mark Fashehccd979b2005-12-15 14:31:24 -08001915 ocfs2_shutdown_local_alloc(osb);
1916
1917 ocfs2_truncate_log_shutdown(osb);
1918
Joel Becker553abd02008-02-01 12:03:57 -08001919 /* This will disable recovery and flush any recovery work. */
1920 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001921
1922 ocfs2_journal_shutdown(osb);
1923
1924 ocfs2_sync_blockdev(sb);
1925
Tao Ma374a2632009-08-24 11:13:37 +08001926 ocfs2_purge_refcount_trees(osb);
1927
Joel Becker4670c462008-02-01 14:39:35 -08001928 /* No cluster connection means we've failed during mount, so skip
1929 * all the steps which depended on that to complete. */
1930 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001931 tmp = ocfs2_super_lock(osb, 1);
1932 if (tmp < 0) {
1933 mlog_errno(tmp);
1934 return;
1935 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001936 }
1937
Mark Fasheh19b613d2007-10-04 14:47:09 -07001938 if (osb->slot_num != OCFS2_INVALID_SLOT)
1939 ocfs2_put_slot(osb);
1940
Joel Becker4670c462008-02-01 14:39:35 -08001941 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001942 ocfs2_super_unlock(osb, 1);
1943
Mark Fashehccd979b2005-12-15 14:31:24 -08001944 ocfs2_release_system_inodes(osb);
1945
Joel Becker6953b4c2008-01-29 16:59:56 -08001946 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001947 * If we're dismounting due to mount error, mount.ocfs2 will clean
1948 * up heartbeat. If we're a local mount, there is no heartbeat.
1949 * If we failed before we got a uuid_str yet, we can't stop
1950 * heartbeat. Otherwise, do it.
1951 */
1952 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
Joel Becker286eaa92008-02-01 15:03:57 -08001953 hangup_needed = 1;
1954
1955 if (osb->cconn)
1956 ocfs2_dlm_shutdown(osb, hangup_needed);
1957
Joel Becker73be1922009-01-06 14:57:08 -08001958 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Joel Becker286eaa92008-02-01 15:03:57 -08001959 debugfs_remove(osb->osb_debug_root);
1960
1961 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001962 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001963
1964 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1965
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001966 if (ocfs2_mount_local(osb))
1967 snprintf(nodestr, sizeof(nodestr), "local");
1968 else
Joel Becker19fdb622008-01-30 15:38:24 -08001969 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001970
1971 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1972 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001973
1974 ocfs2_delete_osb(osb);
1975 kfree(osb);
1976 sb->s_dev = 0;
1977 sb->s_fs_info = NULL;
1978}
1979
1980static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1981 unsigned uuid_bytes)
1982{
1983 int i, ret;
1984 char *ptr;
1985
1986 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1987
Robert P. J. Daycd861282006-12-13 00:34:52 -08001988 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001989 if (osb->uuid_str == NULL)
1990 return -ENOMEM;
1991
Mark Fashehccd979b2005-12-15 14:31:24 -08001992 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1993 /* print with null */
1994 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1995 if (ret != 2) /* drop super cleans up */
1996 return -EINVAL;
1997 /* then only advance past the last char */
1998 ptr += 2;
1999 }
2000
2001 return 0;
2002}
2003
2004static int ocfs2_initialize_super(struct super_block *sb,
2005 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002006 int sector_size,
2007 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002008{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002009 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07002010 int i, cbits, bbits;
2011 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08002012 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08002013 struct ocfs2_journal *journal;
2014 __le32 uuid_net_key;
2015 struct ocfs2_super *osb;
2016
2017 mlog_entry_void();
2018
Robert P. J. Daycd861282006-12-13 00:34:52 -08002019 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002020 if (!osb) {
2021 status = -ENOMEM;
2022 mlog_errno(status);
2023 goto bail;
2024 }
2025
2026 sb->s_fs_info = osb;
2027 sb->s_op = &ocfs2_sops;
2028 sb->s_export_op = &ocfs2_export_ops;
Jan Kara19ece542008-08-21 20:13:17 +02002029 sb->s_qcop = &ocfs2_quotactl_ops;
2030 sb->dq_op = &ocfs2_quota_operations;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002031 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07002032 sb->s_time_gran = 1;
Mark Fashehccd979b2005-12-15 14:31:24 -08002033 sb->s_flags |= MS_NOATIME;
2034 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07002035 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2036 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
2037 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Mark Fashehccd979b2005-12-15 14:31:24 -08002038
Mark Fasheh9b7895e2008-11-12 16:27:44 -08002039 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
2040
2041 for (i = 0; i < 3; i++)
2042 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
2043 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2044
Mark Fashehccd979b2005-12-15 14:31:24 -08002045 osb->sb = sb;
2046 /* Save off for ocfs2_rw_direct */
2047 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01002048 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08002049
Mark Fasheh34d024f2007-09-24 15:56:19 -07002050 spin_lock_init(&osb->dc_task_lock);
2051 init_waitqueue_head(&osb->dc_event);
2052 osb->dc_work_sequence = 0;
2053 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002054 INIT_LIST_HEAD(&osb->blocked_lock_list);
2055 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002056 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08002057 spin_lock_init(&osb->osb_xattr_lock);
Tiger Yangb89c5422010-01-25 14:11:06 +08002058 ocfs2_init_steal_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002059
2060 atomic_set(&osb->alloc_stats.moves, 0);
2061 atomic_set(&osb->alloc_stats.local_data, 0);
2062 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2063 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2064 atomic_set(&osb->alloc_stats.bg_extends, 0);
2065
Joel Becker73be1922009-01-06 14:57:08 -08002066 /* Copy the blockcheck stats from the superblock probe */
2067 osb->osb_ecc_stats = *stats;
2068
Mark Fashehccd979b2005-12-15 14:31:24 -08002069 ocfs2_init_node_maps(osb);
2070
2071 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2072 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2073
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04002074 ocfs2_orphan_scan_init(osb);
2075
Joel Becker553abd02008-02-01 12:03:57 -08002076 status = ocfs2_recovery_init(osb);
2077 if (status) {
2078 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2079 mlog_errno(status);
2080 goto bail;
2081 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002082
2083 init_waitqueue_head(&osb->checkpoint_event);
2084 atomic_set(&osb->needs_checkpoint, 0);
2085
Tiger Yang7f1a37e2006-11-15 15:48:42 +08002086 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2087
Mark Fashehccd979b2005-12-15 14:31:24 -08002088 osb->slot_num = OCFS2_INVALID_SLOT;
2089
Tiger Yang8154da32008-08-18 17:11:46 +08002090 osb->s_xattr_inline_size = le16_to_cpu(
2091 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002092
Mark Fashehccd979b2005-12-15 14:31:24 -08002093 osb->local_alloc_state = OCFS2_LA_UNUSED;
2094 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002095 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002096
Mark Fashehccd979b2005-12-15 14:31:24 -08002097 init_waitqueue_head(&osb->osb_mount_event);
2098
Mark Fashehd02f00c2009-12-07 13:10:48 -08002099 status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
2100 if (status) {
2101 mlog_errno(status);
2102 goto bail;
2103 }
2104
Mark Fashehccd979b2005-12-15 14:31:24 -08002105 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2106 if (!osb->vol_label) {
2107 mlog(ML_ERROR, "unable to alloc vol label\n");
2108 status = -ENOMEM;
2109 goto bail;
2110 }
2111
Mark Fashehccd979b2005-12-15 14:31:24 -08002112 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2113 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2114 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2115 osb->max_slots);
2116 status = -EINVAL;
2117 goto bail;
2118 }
Sunil Mushran781ee3e2006-04-27 16:41:31 -07002119 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
Mark Fashehccd979b2005-12-15 14:31:24 -08002120
Sunil Mushran539d8262008-07-14 17:31:10 -07002121 osb->slot_recovery_generations =
2122 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2123 GFP_KERNEL);
2124 if (!osb->slot_recovery_generations) {
2125 status = -ENOMEM;
2126 mlog_errno(status);
2127 goto bail;
2128 }
2129
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002130 init_waitqueue_head(&osb->osb_wipe_event);
2131 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2132 sizeof(*osb->osb_orphan_wipes),
2133 GFP_KERNEL);
2134 if (!osb->osb_orphan_wipes) {
2135 status = -ENOMEM;
2136 mlog_errno(status);
2137 goto bail;
2138 }
2139
Tao Ma374a2632009-08-24 11:13:37 +08002140 osb->osb_rf_lock_tree = RB_ROOT;
2141
Mark Fashehccd979b2005-12-15 14:31:24 -08002142 osb->s_feature_compat =
2143 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2144 osb->s_feature_ro_compat =
2145 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2146 osb->s_feature_incompat =
2147 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2148
2149 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2150 mlog(ML_ERROR, "couldn't mount because of unsupported "
2151 "optional features (%x).\n", i);
2152 status = -EINVAL;
2153 goto bail;
2154 }
2155 if (!(osb->sb->s_flags & MS_RDONLY) &&
2156 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2157 mlog(ML_ERROR, "couldn't mount RDWR because of "
2158 "unsupported optional features (%x).\n", i);
2159 status = -EINVAL;
2160 goto bail;
2161 }
2162
Joel Beckerb61817e2008-02-01 15:08:23 -08002163 if (ocfs2_userspace_stack(osb)) {
2164 memcpy(osb->osb_cluster_stack,
2165 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2166 OCFS2_STACK_LABEL_LEN);
2167 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2168 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2169 mlog(ML_ERROR,
2170 "couldn't mount because of an invalid "
2171 "cluster stack label (%s) \n",
2172 osb->osb_cluster_stack);
2173 status = -EINVAL;
2174 goto bail;
2175 }
2176 } else {
2177 /* The empty string is identical with classic tools that
2178 * don't know about s_cluster_info. */
2179 osb->osb_cluster_stack[0] = '\0';
2180 }
2181
Mark Fashehccd979b2005-12-15 14:31:24 -08002182 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2183
2184 /* FIXME
2185 * This should be done in ocfs2_journal_init(), but unknown
2186 * ordering issues will cause the filesystem to crash.
2187 * If anyone wants to figure out what part of the code
2188 * refers to osb->journal before ocfs2_journal_init() is run,
2189 * be my guest.
2190 */
2191 /* initialize our journal structure */
2192
Robert P. J. Daycd861282006-12-13 00:34:52 -08002193 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002194 if (!journal) {
2195 mlog(ML_ERROR, "unable to alloc journal\n");
2196 status = -ENOMEM;
2197 goto bail;
2198 }
2199 osb->journal = journal;
2200 journal->j_osb = osb;
2201
2202 atomic_set(&journal->j_num_trans, 0);
2203 init_rwsem(&journal->j_trans_barrier);
2204 init_waitqueue_head(&journal->j_checkpointed);
2205 spin_lock_init(&journal->j_lock);
2206 journal->j_trans_id = (unsigned long) 1;
2207 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002208 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002209 journal->j_state = OCFS2_JOURNAL_FREE;
2210
Jan Karaea455f82009-01-12 23:20:31 +01002211 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2212 osb->dentry_lock_list = NULL;
2213
Mark Fashehccd979b2005-12-15 14:31:24 -08002214 /* get some pseudo constants for clustersize bits */
2215 osb->s_clustersize_bits =
2216 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2217 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2218 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2219
2220 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2221 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2222 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2223 osb->s_clustersize);
2224 status = -EINVAL;
2225 goto bail;
2226 }
2227
2228 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2229 > (u32)~0UL) {
2230 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2231 "what jbd can address in 32 bits.\n");
2232 status = -EINVAL;
2233 goto bail;
2234 }
2235
2236 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2237 sizeof(di->id2.i_super.s_uuid))) {
2238 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2239 status = -ENOMEM;
2240 goto bail;
2241 }
2242
Mark Fasheh78427042006-05-04 12:03:26 -07002243 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
Mark Fashehccd979b2005-12-15 14:31:24 -08002244
2245 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2246 osb->vol_label[63] = '\0';
2247 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2248 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2249 osb->first_cluster_group_blkno =
2250 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2251 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002252 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Mark Fashehccd979b2005-12-15 14:31:24 -08002253 mlog(0, "vol_label: %s\n", osb->vol_label);
2254 mlog(0, "uuid: %s\n", osb->uuid_str);
Mark Fashehb0697052006-03-03 10:24:33 -08002255 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2256 (unsigned long long)osb->root_blkno,
2257 (unsigned long long)osb->system_dir_blkno);
Mark Fashehccd979b2005-12-15 14:31:24 -08002258
2259 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2260 if (!osb->osb_dlm_debug) {
2261 status = -ENOMEM;
2262 mlog_errno(status);
2263 goto bail;
2264 }
2265
2266 atomic_set(&osb->vol_state, VOLUME_INIT);
2267
2268 /* load root, system_dir, and all global system inodes */
2269 status = ocfs2_init_global_system_inodes(osb);
2270 if (status < 0) {
2271 mlog_errno(status);
2272 goto bail;
2273 }
2274
2275 /*
2276 * global bitmap
2277 */
2278 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2279 OCFS2_INVALID_SLOT);
2280 if (!inode) {
2281 status = -EINVAL;
2282 mlog_errno(status);
2283 goto bail;
2284 }
2285
2286 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fasheh6b820212010-04-05 18:17:14 -07002287 osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
Mark Fashehccd979b2005-12-15 14:31:24 -08002288 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002289
Tao Ma85718822010-04-13 14:38:06 +08002290 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
2291 osb->s_feature_incompat) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002292
2293 status = ocfs2_init_slot_info(osb);
2294 if (status < 0) {
2295 mlog_errno(status);
2296 goto bail;
2297 }
2298
Mark Fashehccd979b2005-12-15 14:31:24 -08002299bail:
2300 mlog_exit(status);
2301 return status;
2302}
2303
2304/*
2305 * will return: -EAGAIN if it is ok to keep searching for superblocks
2306 * -EINVAL if there is a bad superblock
2307 * 0 on success
2308 */
2309static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2310 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002311 u32 blksz,
2312 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002313{
2314 int status = -EAGAIN;
2315
2316 mlog_entry_void();
2317
2318 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2319 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002320 /* We have to do a raw check of the feature here */
2321 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2322 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2323 status = ocfs2_block_check_validate(bh->b_data,
2324 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002325 &di->i_check,
2326 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002327 if (status)
2328 goto out;
2329 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002330 status = -EINVAL;
2331 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2332 mlog(ML_ERROR, "found superblock with incorrect block "
2333 "size: found %u, should be %u\n",
2334 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2335 blksz);
2336 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2337 OCFS2_MAJOR_REV_LEVEL ||
2338 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2339 OCFS2_MINOR_REV_LEVEL) {
2340 mlog(ML_ERROR, "found superblock with bad version: "
2341 "found %u.%u, should be %u.%u\n",
2342 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2343 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2344 OCFS2_MAJOR_REV_LEVEL,
2345 OCFS2_MINOR_REV_LEVEL);
2346 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2347 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb0697052006-03-03 10:24:33 -08002348 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002349 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb0697052006-03-03 10:24:33 -08002350 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002351 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2352 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2353 mlog(ML_ERROR, "bad cluster size found: %u\n",
2354 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2355 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2356 mlog(ML_ERROR, "bad root_blkno: 0\n");
2357 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2358 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2359 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2360 mlog(ML_ERROR,
2361 "Superblock slots found greater than file system "
2362 "maximum: found %u, max %u\n",
2363 le16_to_cpu(di->id2.i_super.s_max_slots),
2364 OCFS2_MAX_SLOTS);
2365 } else {
2366 /* found it! */
2367 status = 0;
2368 }
2369 }
2370
Joel Beckerd030cc92008-12-11 15:04:14 -08002371out:
Mark Fashehccd979b2005-12-15 14:31:24 -08002372 mlog_exit(status);
2373 return status;
2374}
2375
2376static int ocfs2_check_volume(struct ocfs2_super *osb)
2377{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002378 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002379 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002380 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002381 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2382 * recover
2383 * ourselves. */
2384
2385 mlog_entry_void();
2386
2387 /* Init our journal object. */
2388 status = ocfs2_journal_init(osb->journal, &dirty);
2389 if (status < 0) {
2390 mlog(ML_ERROR, "Could not initialize journal!\n");
2391 goto finally;
2392 }
2393
2394 /* If the journal was unmounted cleanly then we don't want to
2395 * recover anything. Otherwise, journal_load will do that
2396 * dirty work for us :) */
2397 if (!dirty) {
2398 status = ocfs2_journal_wipe(osb->journal, 0);
2399 if (status < 0) {
2400 mlog_errno(status);
2401 goto finally;
2402 }
2403 } else {
2404 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2405 "recovering volume.\n");
2406 }
2407
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002408 local = ocfs2_mount_local(osb);
2409
Mark Fashehccd979b2005-12-15 14:31:24 -08002410 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002411 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002412 if (status < 0) {
2413 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2414 goto finally;
2415 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002416
2417 if (dirty) {
2418 /* recover my local alloc if we didn't unmount cleanly. */
2419 status = ocfs2_begin_local_alloc_recovery(osb,
2420 osb->slot_num,
2421 &local_alloc);
2422 if (status < 0) {
2423 mlog_errno(status);
2424 goto finally;
2425 }
2426 /* we complete the recovery process after we've marked
2427 * ourselves as mounted. */
2428 }
2429
2430 mlog(0, "Journal loaded.\n");
2431
2432 status = ocfs2_load_local_alloc(osb);
2433 if (status < 0) {
2434 mlog_errno(status);
2435 goto finally;
2436 }
2437
2438 if (dirty) {
2439 /* Recovery will be completed after we've mounted the
2440 * rest of the volume. */
2441 osb->dirty = 1;
2442 osb->local_alloc_copy = local_alloc;
2443 local_alloc = NULL;
2444 }
2445
2446 /* go through each journal, trylock it and if you get the
2447 * lock, and it's marked as dirty, set the bit in the recover
2448 * map and launch a recovery thread for it. */
2449 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002450 if (status < 0) {
2451 mlog_errno(status);
2452 goto finally;
2453 }
2454
2455 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002456 if (status < 0)
2457 mlog_errno(status);
2458
2459finally:
2460 if (local_alloc)
2461 kfree(local_alloc);
2462
2463 mlog_exit(status);
2464 return status;
2465}
2466
2467/*
2468 * The routine gets called from dismount or close whenever a dismount on
2469 * volume is requested and the osb open count becomes 1.
2470 * It will remove the osb from the global list and also free up all the
2471 * initialized resources and fileobject.
2472 */
2473static void ocfs2_delete_osb(struct ocfs2_super *osb)
2474{
2475 mlog_entry_void();
2476
2477 /* This function assumes that the caller has the main osb resource */
2478
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002479 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002480
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002481 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002482 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002483 /* FIXME
2484 * This belongs in journal shutdown, but because we have to
2485 * allocate osb->journal at the start of ocfs2_initalize_osb(),
2486 * we free it here.
2487 */
2488 kfree(osb->journal);
2489 if (osb->local_alloc_copy)
2490 kfree(osb->local_alloc_copy);
2491 kfree(osb->uuid_str);
2492 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2493 memset(osb, 0, sizeof(struct ocfs2_super));
2494
2495 mlog_exit_void();
2496}
2497
2498/* Put OCFS2 into a readonly state, or (if the user specifies it),
2499 * panic(). We do not support continue-on-error operation. */
2500static void ocfs2_handle_error(struct super_block *sb)
2501{
2502 struct ocfs2_super *osb = OCFS2_SB(sb);
2503
2504 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2505 panic("OCFS2: (device %s): panic forced after error\n",
2506 sb->s_id);
2507
2508 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2509
2510 if (sb->s_flags & MS_RDONLY &&
2511 (ocfs2_is_soft_readonly(osb) ||
2512 ocfs2_is_hard_readonly(osb)))
2513 return;
2514
2515 printk(KERN_CRIT "File system is now read-only due to the potential "
2516 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2517 "system is unmounted.\n");
2518 sb->s_flags |= MS_RDONLY;
2519 ocfs2_set_ro_flag(osb, 0);
2520}
2521
2522static char error_buf[1024];
2523
2524void __ocfs2_error(struct super_block *sb,
2525 const char *function,
2526 const char *fmt, ...)
2527{
2528 va_list args;
2529
2530 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002531 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002532 va_end(args);
2533
2534 /* Not using mlog here because we want to show the actual
2535 * function the error came from. */
2536 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2537 sb->s_id, function, error_buf);
2538
2539 ocfs2_handle_error(sb);
2540}
2541
2542/* Handle critical errors. This is intentionally more drastic than
2543 * ocfs2_handle_error, so we only use for things like journal errors,
2544 * etc. */
2545void __ocfs2_abort(struct super_block* sb,
2546 const char *function,
2547 const char *fmt, ...)
2548{
2549 va_list args;
2550
2551 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002552 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002553 va_end(args);
2554
2555 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2556 sb->s_id, function, error_buf);
2557
2558 /* We don't have the cluster support yet to go straight to
2559 * hard readonly in here. Until then, we want to keep
2560 * ocfs2_abort() so that we can at least mark critical
2561 * errors.
2562 *
2563 * TODO: This should abort the journal and alert other nodes
2564 * that our slot needs recovery. */
2565
2566 /* Force a panic(). This stinks, but it's better than letting
2567 * things continue without having a proper hard readonly
2568 * here. */
Sunil Mushrana2f2ddb2009-08-19 15:16:01 -07002569 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2570 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08002571 ocfs2_handle_error(sb);
2572}
2573
Joel Beckere4b963f2009-09-02 17:17:36 -07002574/*
2575 * Void signal blockers, because in-kernel sigprocmask() only fails
2576 * when SIG_* is wrong.
2577 */
2578void ocfs2_block_signals(sigset_t *oldset)
2579{
2580 int rc;
2581 sigset_t blocked;
2582
2583 sigfillset(&blocked);
2584 rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
2585 BUG_ON(rc);
2586}
2587
2588void ocfs2_unblock_signals(sigset_t *oldset)
2589{
2590 int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
2591 BUG_ON(rc);
2592}
2593
Mark Fashehccd979b2005-12-15 14:31:24 -08002594module_init(ocfs2_init);
2595module_exit(ocfs2_exit);