blob: 4e009ad303a1b0a2ea6df52b244cb55dead2d535 [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,
Al Viro066d92d2010-06-08 21:28:10 -0400148 .evict_inode = ocfs2_evict_inode,
Mark Fashehccd979b2005-12-15 14:31:24 -0800149 .sync_fs = ocfs2_sync_fs,
Mark Fashehccd979b2005-12-15 14:31:24 -0800150 .put_super = ocfs2_put_super,
151 .remount_fs = ocfs2_remount,
Sunil Mushrand5500712007-09-06 13:34:16 -0700152 .show_options = ocfs2_show_options,
Jan Kara9e33d692008-08-25 19:56:50 +0200153 .quota_read = ocfs2_quota_read,
154 .quota_write = ocfs2_quota_write,
Mark Fashehccd979b2005-12-15 14:31:24 -0800155};
156
157enum {
158 Opt_barrier,
159 Opt_err_panic,
160 Opt_err_ro,
161 Opt_intr,
162 Opt_nointr,
163 Opt_hb_none,
164 Opt_hb_local,
Sunil Mushran2c442712010-10-07 15:23:50 -0700165 Opt_hb_global,
Mark Fashehccd979b2005-12-15 14:31:24 -0800166 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},
Sunil Mushran2c442712010-10-07 15:23:50 -0700194 {Opt_hb_global, OCFS2_HB_GLOBAL},
Mark Fashehccd979b2005-12-15 14:31:24 -0800195 {Opt_data_ordered, "data=ordered"},
196 {Opt_data_writeback, "data=writeback"},
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800197 {Opt_atime_quantum, "atime_quantum=%u"},
Sunil Mushranbaf46612007-06-18 17:00:24 -0700198 {Opt_slot, "preferred_slot=%u"},
Mark Fashehd147b3d2007-11-07 14:40:36 -0800199 {Opt_commit, "commit=%u"},
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800200 {Opt_localalloc, "localalloc=%d"},
Mark Fasheh53fc6222007-12-20 16:49:04 -0800201 {Opt_localflocks, "localflocks"},
Joel Beckerb61817e2008-02-01 15:08:23 -0800202 {Opt_stack, "cluster_stack=%s"},
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800203 {Opt_user_xattr, "user_xattr"},
204 {Opt_nouser_xattr, "nouser_xattr"},
Joel Becker12462f12008-09-03 20:03:40 -0700205 {Opt_inode64, "inode64"},
Tiger Yanga68979b2008-11-14 11:17:52 +0800206 {Opt_acl, "acl"},
207 {Opt_noacl, "noacl"},
Jan Kara19ece542008-08-21 20:13:17 +0200208 {Opt_usrquota, "usrquota"},
209 {Opt_grpquota, "grpquota"},
Mark Fashehd02f00c2009-12-07 13:10:48 -0800210 {Opt_resv_level, "resv_level=%u"},
Mark Fasheh83f92312010-04-05 18:17:16 -0700211 {Opt_dir_resv_level, "dir_resv_level=%u"},
Mark Fashehccd979b2005-12-15 14:31:24 -0800212 {Opt_err, NULL}
213};
214
Sunil Mushran50397502008-12-17 14:17:43 -0800215#ifdef CONFIG_DEBUG_FS
216static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
217{
Sunil Mushran50397502008-12-17 14:17:43 -0800218 struct ocfs2_cluster_connection *cconn = osb->cconn;
219 struct ocfs2_recovery_map *rm = osb->recovery_map;
Sunil Mushrandf152c22009-06-22 11:40:07 -0700220 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
221 int i, out = 0;
Sunil Mushran50397502008-12-17 14:17:43 -0800222
223 out += snprintf(buf + out, len - out,
224 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
225 "Device", osb->dev_str, osb->uuid_str,
226 osb->fs_generation, osb->vol_label);
227
228 out += snprintf(buf + out, len - out,
229 "%10s => State: %d Flags: 0x%lX\n", "Volume",
230 atomic_read(&osb->vol_state), osb->osb_flags);
231
232 out += snprintf(buf + out, len - out,
233 "%10s => Block: %lu Cluster: %d\n", "Sizes",
234 osb->sb->s_blocksize, osb->s_clustersize);
235
236 out += snprintf(buf + out, len - out,
237 "%10s => Compat: 0x%X Incompat: 0x%X "
238 "ROcompat: 0x%X\n",
239 "Features", osb->s_feature_compat,
240 osb->s_feature_incompat, osb->s_feature_ro_compat);
241
242 out += snprintf(buf + out, len - out,
243 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
244 osb->s_mount_opt, osb->s_atime_quantum);
245
Sunil Mushranc3d38842009-06-19 14:45:55 -0700246 if (cconn) {
247 out += snprintf(buf + out, len - out,
248 "%10s => Stack: %s Name: %*s "
249 "Version: %d.%d\n", "Cluster",
250 (*osb->osb_cluster_stack == '\0' ?
251 "o2cb" : osb->osb_cluster_stack),
252 cconn->cc_namelen, cconn->cc_name,
253 cconn->cc_version.pv_major,
254 cconn->cc_version.pv_minor);
255 }
Sunil Mushran50397502008-12-17 14:17:43 -0800256
257 spin_lock(&osb->dc_task_lock);
258 out += snprintf(buf + out, len - out,
259 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
260 "WorkSeq: %lu\n", "DownCnvt",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700261 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
262 osb->blocked_lock_count, osb->dc_wake_sequence,
263 osb->dc_work_sequence);
Sunil Mushran50397502008-12-17 14:17:43 -0800264 spin_unlock(&osb->dc_task_lock);
265
266 spin_lock(&osb->osb_lock);
267 out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
268 "Recovery",
269 (osb->recovery_thread_task ?
270 task_pid_nr(osb->recovery_thread_task) : -1));
271 if (rm->rm_used == 0)
272 out += snprintf(buf + out, len - out, " None\n");
273 else {
274 for (i = 0; i < rm->rm_used; i++)
275 out += snprintf(buf + out, len - out, " %d",
276 rm->rm_entries[i]);
277 out += snprintf(buf + out, len - out, "\n");
278 }
279 spin_unlock(&osb->osb_lock);
280
281 out += snprintf(buf + out, len - out,
282 "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700283 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
284 osb->osb_commit_interval,
Sunil Mushran50397502008-12-17 14:17:43 -0800285 atomic_read(&osb->needs_checkpoint));
286
287 out += snprintf(buf + out, len - out,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700288 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
Sunil Mushran50397502008-12-17 14:17:43 -0800289 "Journal", osb->journal->j_state,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700290 osb->journal->j_trans_id,
291 atomic_read(&osb->journal->j_num_trans));
Sunil Mushran50397502008-12-17 14:17:43 -0800292
293 out += snprintf(buf + out, len - out,
294 "%10s => GlobalAllocs: %d LocalAllocs: %d "
295 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
296 "Stats",
297 atomic_read(&osb->alloc_stats.bitmap_data),
298 atomic_read(&osb->alloc_stats.local_data),
299 atomic_read(&osb->alloc_stats.bg_allocs),
300 atomic_read(&osb->alloc_stats.moves),
301 atomic_read(&osb->alloc_stats.bg_extends));
302
303 out += snprintf(buf + out, len - out,
304 "%10s => State: %u Descriptor: %llu Size: %u bits "
305 "Default: %u bits\n",
306 "LocalAlloc", osb->local_alloc_state,
307 (unsigned long long)osb->la_last_gd,
308 osb->local_alloc_bits, osb->local_alloc_default_bits);
309
310 spin_lock(&osb->osb_lock);
311 out += snprintf(buf + out, len - out,
Tiger Yangb89c5422010-01-25 14:11:06 +0800312 "%10s => InodeSlot: %d StolenInodes: %d, "
313 "MetaSlot: %d StolenMeta: %d\n", "Steal",
Sunil Mushran50397502008-12-17 14:17:43 -0800314 osb->s_inode_steal_slot,
Tiger Yangb89c5422010-01-25 14:11:06 +0800315 atomic_read(&osb->s_num_inodes_stolen),
316 osb->s_meta_steal_slot,
317 atomic_read(&osb->s_num_meta_stolen));
Sunil Mushran50397502008-12-17 14:17:43 -0800318 spin_unlock(&osb->osb_lock);
319
Sunil Mushrandf152c22009-06-22 11:40:07 -0700320 out += snprintf(buf + out, len - out, "OrphanScan => ");
321 out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
322 os->os_count, os->os_seqno);
323 out += snprintf(buf + out, len - out, " Last Scan: ");
324 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
325 out += snprintf(buf + out, len - out, "Disabled\n");
326 else
327 out += snprintf(buf + out, len - out, "%lu seconds ago\n",
328 (get_seconds() - os->os_scantime.tv_sec));
329
Sunil Mushran50397502008-12-17 14:17:43 -0800330 out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
331 "Slots", "Num", "RecoGen");
Sunil Mushran50397502008-12-17 14:17:43 -0800332 for (i = 0; i < osb->max_slots; ++i) {
333 out += snprintf(buf + out, len - out,
334 "%10s %c %3d %10d\n",
335 " ",
336 (i == osb->slot_num ? '*' : ' '),
337 i, osb->slot_recovery_generations[i]);
338 }
339
340 return out;
341}
342
343static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
344{
345 struct ocfs2_super *osb = inode->i_private;
346 char *buf = NULL;
347
348 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
349 if (!buf)
350 goto bail;
351
352 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
353
354 file->private_data = buf;
355
356 return 0;
357bail:
358 return -ENOMEM;
359}
360
361static int ocfs2_debug_release(struct inode *inode, struct file *file)
362{
363 kfree(file->private_data);
364 return 0;
365}
366
367static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
368 size_t nbytes, loff_t *ppos)
369{
370 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
371 i_size_read(file->f_mapping->host));
372}
373#else
374static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
375{
376 return 0;
377}
378static int ocfs2_debug_release(struct inode *inode, struct file *file)
379{
380 return 0;
381}
382static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
383 size_t nbytes, loff_t *ppos)
384{
385 return 0;
386}
387#endif /* CONFIG_DEBUG_FS */
388
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700389static const struct file_operations ocfs2_osb_debug_fops = {
Sunil Mushran50397502008-12-17 14:17:43 -0800390 .open = ocfs2_osb_debug_open,
391 .release = ocfs2_debug_release,
392 .read = ocfs2_debug_read,
393 .llseek = generic_file_llseek,
394};
395
Mark Fashehccd979b2005-12-15 14:31:24 -0800396static int ocfs2_sync_fs(struct super_block *sb, int wait)
397{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800398 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -0800399 tid_t target;
400 struct ocfs2_super *osb = OCFS2_SB(sb);
401
Mark Fashehccd979b2005-12-15 14:31:24 -0800402 if (ocfs2_is_hard_readonly(osb))
403 return -EROFS;
404
405 if (wait) {
406 status = ocfs2_flush_truncate_log(osb);
407 if (status < 0)
408 mlog_errno(status);
409 } else {
410 ocfs2_schedule_truncate_log_flush(osb, 0);
411 }
412
Joel Becker2b4e30f2008-09-03 20:03:41 -0700413 if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
414 &target)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800415 if (wait)
Joel Becker2b4e30f2008-09-03 20:03:41 -0700416 jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
417 target);
Mark Fashehccd979b2005-12-15 14:31:24 -0800418 }
419 return 0;
420}
421
Jan Kara1a224ad2008-08-20 15:43:36 +0200422static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
423{
424 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
425 && (ino == USER_QUOTA_SYSTEM_INODE
426 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
427 return 0;
428 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
429 && (ino == GROUP_QUOTA_SYSTEM_INODE
430 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
431 return 0;
432 return 1;
433}
434
Mark Fashehccd979b2005-12-15 14:31:24 -0800435static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
436{
437 struct inode *new = NULL;
438 int status = 0;
439 int i;
440
441 mlog_entry_void();
442
Jan Kara5fa06132008-01-11 00:11:45 +0100443 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800444 if (IS_ERR(new)) {
445 status = PTR_ERR(new);
446 mlog_errno(status);
447 goto bail;
448 }
449 osb->root_inode = new;
450
Jan Kara5fa06132008-01-11 00:11:45 +0100451 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800452 if (IS_ERR(new)) {
453 status = PTR_ERR(new);
454 mlog_errno(status);
455 goto bail;
456 }
457 osb->sys_root_inode = new;
458
459 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
460 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200461 if (!ocfs2_need_system_inode(osb, i))
462 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800463 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
464 if (!new) {
465 ocfs2_release_system_inodes(osb);
466 status = -EINVAL;
467 mlog_errno(status);
468 /* FIXME: Should ERROR_RO_FS */
469 mlog(ML_ERROR, "Unable to load system inode %d, "
470 "possibly corrupt fs?", i);
471 goto bail;
472 }
473 // the array now has one ref, so drop this one
474 iput(new);
475 }
476
477bail:
478 mlog_exit(status);
479 return status;
480}
481
482static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
483{
484 struct inode *new = NULL;
485 int status = 0;
486 int i;
487
488 mlog_entry_void();
489
490 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
491 i < NUM_SYSTEM_INODES;
492 i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200493 if (!ocfs2_need_system_inode(osb, i))
494 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800495 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
496 if (!new) {
497 ocfs2_release_system_inodes(osb);
498 status = -EINVAL;
499 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
500 status, i, osb->slot_num);
501 goto bail;
502 }
503 /* the array now has one ref, so drop this one */
504 iput(new);
505 }
506
507bail:
508 mlog_exit(status);
509 return status;
510}
511
Denis Chengbddb8eb32007-09-27 02:10:04 +0800512static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
Mark Fashehccd979b2005-12-15 14:31:24 -0800513{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800514 int i;
Mark Fashehccd979b2005-12-15 14:31:24 -0800515 struct inode *inode;
516
517 mlog_entry_void();
518
519 for (i = 0; i < NUM_SYSTEM_INODES; i++) {
520 inode = osb->system_inodes[i];
521 if (inode) {
522 iput(inode);
523 osb->system_inodes[i] = NULL;
524 }
525 }
526
527 inode = osb->sys_root_inode;
528 if (inode) {
529 iput(inode);
530 osb->sys_root_inode = NULL;
531 }
532
533 inode = osb->root_inode;
534 if (inode) {
535 iput(inode);
536 osb->root_inode = NULL;
537 }
538
Denis Chengbddb8eb32007-09-27 02:10:04 +0800539 mlog_exit(0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800540}
541
542/* We're allocating fs objects, use GFP_NOFS */
543static struct inode *ocfs2_alloc_inode(struct super_block *sb)
544{
545 struct ocfs2_inode_info *oi;
546
Christoph Lametere6b4f8d2006-12-06 20:33:14 -0800547 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
Mark Fashehccd979b2005-12-15 14:31:24 -0800548 if (!oi)
549 return NULL;
550
Joel Becker2b4e30f2008-09-03 20:03:41 -0700551 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -0800552 return &oi->vfs_inode;
553}
554
555static void ocfs2_destroy_inode(struct inode *inode)
556{
557 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
558}
559
Mark Fasheh5a254032007-07-20 12:56:16 -0700560static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
561 unsigned int cbits)
Mark Fashehccd979b2005-12-15 14:31:24 -0800562{
Mark Fasheh5a254032007-07-20 12:56:16 -0700563 unsigned int bytes = 1 << cbits;
564 unsigned int trim = bytes;
565 unsigned int bitshift = 32;
Mark Fashehccd979b2005-12-15 14:31:24 -0800566
Mark Fasheh5a254032007-07-20 12:56:16 -0700567 /*
568 * i_size and all block offsets in ocfs2 are always 64 bits
569 * wide. i_clusters is 32 bits, in cluster-sized units. So on
570 * 64 bit platforms, cluster size will be the limiting factor.
Mark Fashehccd979b2005-12-15 14:31:24 -0800571 */
572
573#if BITS_PER_LONG == 32
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +0200574# if defined(CONFIG_LBDAF)
Alexey Dobriyan2ecd05a2006-10-11 01:22:05 -0700575 BUILD_BUG_ON(sizeof(sector_t) != 8);
Mark Fasheh5a254032007-07-20 12:56:16 -0700576 /*
577 * We might be limited by page cache size.
578 */
579 if (bytes > PAGE_CACHE_SIZE) {
580 bytes = PAGE_CACHE_SIZE;
581 trim = 1;
582 /*
583 * Shift by 31 here so that we don't get larger than
584 * MAX_LFS_FILESIZE
585 */
586 bitshift = 31;
587 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800588# else
Mark Fasheh5a254032007-07-20 12:56:16 -0700589 /*
590 * We are limited by the size of sector_t. Use block size, as
591 * that's what we expose to the VFS.
592 */
593 bytes = 1 << bbits;
594 trim = 1;
595 bitshift = 31;
Mark Fashehccd979b2005-12-15 14:31:24 -0800596# endif
597#endif
598
Mark Fasheh5a254032007-07-20 12:56:16 -0700599 /*
600 * Trim by a whole cluster when we can actually approach the
601 * on-disk limits. Otherwise we can overflow i_clusters when
602 * an extent start is at the max offset.
603 */
604 return (((unsigned long long)bytes) << bitshift) - trim;
Mark Fashehccd979b2005-12-15 14:31:24 -0800605}
606
607static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
608{
609 int incompat_features;
610 int ret = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800611 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800612 struct ocfs2_super *osb = OCFS2_SB(sb);
Sunil Mushran2c442712010-10-07 15:23:50 -0700613 u32 tmp;
Mark Fashehccd979b2005-12-15 14:31:24 -0800614
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200615 lock_kernel();
616
Jan Kara5297aad2009-10-15 14:54:04 +0200617 if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
618 !ocfs2_check_set_options(sb, &parsed_options)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800619 ret = -EINVAL;
620 goto out;
621 }
622
Sunil Mushran2c442712010-10-07 15:23:50 -0700623 tmp = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL |
624 OCFS2_MOUNT_HB_NONE;
625 if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800626 ret = -EINVAL;
627 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
628 goto out;
629 }
630
631 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800632 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800633 ret = -EINVAL;
634 mlog(ML_ERROR, "Cannot change data mode on remount\n");
635 goto out;
636 }
637
Joel Becker12462f12008-09-03 20:03:40 -0700638 /* Probably don't want this on remount; it might
639 * mess with other nodes */
640 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
641 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
642 ret = -EINVAL;
643 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
644 goto out;
645 }
646
Mark Fashehccd979b2005-12-15 14:31:24 -0800647 /* We're going to/from readonly mode. */
648 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
Jan Kara19ece542008-08-21 20:13:17 +0200649 /* Disable quota accounting before remounting RO */
650 if (*flags & MS_RDONLY) {
651 ret = ocfs2_susp_quotas(osb, 0);
652 if (ret < 0)
653 goto out;
654 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800655 /* Lock here so the check of HARD_RO and the potential
656 * setting of SOFT_RO is atomic. */
657 spin_lock(&osb->osb_lock);
658 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
659 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
660 ret = -EROFS;
661 goto unlock_osb;
662 }
663
664 if (*flags & MS_RDONLY) {
665 mlog(0, "Going to ro mode.\n");
666 sb->s_flags |= MS_RDONLY;
667 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
668 } else {
669 mlog(0, "Making ro filesystem writeable.\n");
670
671 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
672 mlog(ML_ERROR, "Cannot remount RDWR "
673 "filesystem due to previous errors.\n");
674 ret = -EROFS;
675 goto unlock_osb;
676 }
677 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
678 if (incompat_features) {
679 mlog(ML_ERROR, "Cannot remount RDWR because "
680 "of unsupported optional features "
681 "(%x).\n", incompat_features);
682 ret = -EINVAL;
683 goto unlock_osb;
684 }
685 sb->s_flags &= ~MS_RDONLY;
686 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
687 }
688unlock_osb:
689 spin_unlock(&osb->osb_lock);
Jan Kara19ece542008-08-21 20:13:17 +0200690 /* Enable quota accounting after remounting RW */
691 if (!ret && !(*flags & MS_RDONLY)) {
692 if (sb_any_quota_suspended(sb))
693 ret = ocfs2_susp_quotas(osb, 1);
694 else
695 ret = ocfs2_enable_quotas(osb);
696 if (ret < 0) {
697 /* Return back changes... */
698 spin_lock(&osb->osb_lock);
699 sb->s_flags |= MS_RDONLY;
700 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
701 spin_unlock(&osb->osb_lock);
702 goto out;
703 }
704 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800705 }
706
707 if (!ret) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800708 /* Only save off the new mount options in case of a successful
709 * remount. */
Tiger Yangc0123ad2007-09-08 00:16:10 +0800710 osb->s_mount_opt = parsed_options.mount_opt;
711 osb->s_atime_quantum = parsed_options.atime_quantum;
712 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -0800713 if (parsed_options.commit_interval)
714 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fashehe001e792007-11-07 14:21:45 -0800715
716 if (!ocfs2_is_hard_readonly(osb))
717 ocfs2_set_journal_params(osb);
Jan Kara57b09bb2009-10-15 14:54:05 +0200718
719 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
720 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
721 MS_POSIXACL : 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800722 }
723out:
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200724 unlock_kernel();
Mark Fashehccd979b2005-12-15 14:31:24 -0800725 return ret;
726}
727
728static int ocfs2_sb_probe(struct super_block *sb,
729 struct buffer_head **bh,
Joel Becker73be1922009-01-06 14:57:08 -0800730 int *sector_size,
731 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -0800732{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800733 int status, tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800734 struct ocfs1_vol_disk_hdr *hdr;
735 struct ocfs2_dinode *di;
736 int blksize;
737
738 *bh = NULL;
739
740 /* may be > 512 */
Martin K. Petersene1defc42009-05-22 17:17:49 -0400741 *sector_size = bdev_logical_block_size(sb->s_bdev);
Mark Fashehccd979b2005-12-15 14:31:24 -0800742 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
743 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
744 *sector_size, OCFS2_MAX_BLOCKSIZE);
745 status = -EINVAL;
746 goto bail;
747 }
748
749 /* Can this really happen? */
750 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
751 *sector_size = OCFS2_MIN_BLOCKSIZE;
752
753 /* check block zero for old format */
754 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
755 if (status < 0) {
756 mlog_errno(status);
757 goto bail;
758 }
759 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
760 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
761 mlog(ML_ERROR, "incompatible version: %u.%u\n",
762 hdr->major_version, hdr->minor_version);
763 status = -EINVAL;
764 }
765 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
766 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
767 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
768 hdr->signature);
769 status = -EINVAL;
770 }
771 brelse(*bh);
772 *bh = NULL;
773 if (status < 0) {
774 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
775 "upgraded before mounting with ocfs v2\n");
776 goto bail;
777 }
778
779 /*
780 * Now check at magic offset for 512, 1024, 2048, 4096
781 * blocksizes. 4096 is the maximum blocksize because it is
782 * the minimum clustersize.
783 */
784 status = -EINVAL;
785 for (blksize = *sector_size;
786 blksize <= OCFS2_MAX_BLOCKSIZE;
787 blksize <<= 1) {
788 tmpstat = ocfs2_get_sector(sb, bh,
789 OCFS2_SUPER_BLOCK_BLKNO,
790 blksize);
791 if (tmpstat < 0) {
792 status = tmpstat;
793 mlog_errno(status);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700794 break;
Mark Fashehccd979b2005-12-15 14:31:24 -0800795 }
796 di = (struct ocfs2_dinode *) (*bh)->b_data;
Joel Becker73be1922009-01-06 14:57:08 -0800797 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
Jan Kara1c1d9792009-07-22 13:17:19 +0200798 spin_lock_init(&stats->b_lock);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700799 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
800 if (tmpstat < 0) {
801 brelse(*bh);
802 *bh = NULL;
803 }
804 if (tmpstat != -EAGAIN) {
805 status = tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800806 break;
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700807 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800808 }
809
810bail:
811 return status;
812}
813
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800814static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
815{
Sunil Mushran2c442712010-10-07 15:23:50 -0700816 u32 hb_enabled = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL;
817
818 if (osb->s_mount_opt & hb_enabled) {
819 if (ocfs2_mount_local(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800820 mlog(ML_ERROR, "Cannot heartbeat on a locally "
821 "mounted device.\n");
822 return -EINVAL;
823 }
Sunil Mushran2c442712010-10-07 15:23:50 -0700824 if (ocfs2_userspace_stack(osb)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800825 mlog(ML_ERROR, "Userspace stack expected, but "
826 "o2cb heartbeat arguments passed to mount\n");
827 return -EINVAL;
828 }
Sunil Mushran2c442712010-10-07 15:23:50 -0700829 if (((osb->s_mount_opt & OCFS2_MOUNT_HB_GLOBAL) &&
830 !ocfs2_cluster_o2cb_global_heartbeat(osb)) ||
831 ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) &&
832 ocfs2_cluster_o2cb_global_heartbeat(osb))) {
833 mlog(ML_ERROR, "Mismatching o2cb heartbeat modes\n");
834 return -EINVAL;
835 }
Joel Beckerb61817e2008-02-01 15:08:23 -0800836 }
837
Sunil Mushran2c442712010-10-07 15:23:50 -0700838 if (!(osb->s_mount_opt & hb_enabled)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800839 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
840 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800841 mlog(ML_ERROR, "Heartbeat has to be started to mount "
842 "a read-write clustered device.\n");
843 return -EINVAL;
844 }
845 }
846
847 return 0;
848}
849
Joel Beckerb61817e2008-02-01 15:08:23 -0800850/*
851 * If we're using a userspace stack, mount should have passed
852 * a name that matches the disk. If not, mount should not
853 * have passed a stack.
854 */
855static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
856 struct mount_options *mopt)
857{
858 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
859 mlog(ML_ERROR,
860 "cluster stack passed to mount, but this filesystem "
861 "does not support it\n");
862 return -EINVAL;
863 }
864
865 if (ocfs2_userspace_stack(osb) &&
866 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
867 OCFS2_STACK_LABEL_LEN)) {
868 mlog(ML_ERROR,
869 "cluster stack passed to mount (\"%s\") does not "
870 "match the filesystem (\"%s\")\n",
871 mopt->cluster_stack,
872 osb->osb_cluster_stack);
873 return -EINVAL;
874 }
875
876 return 0;
877}
878
Jan Kara19ece542008-08-21 20:13:17 +0200879static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
880{
881 int type;
882 struct super_block *sb = osb->sb;
883 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
884 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
885 int status = 0;
886
887 for (type = 0; type < MAXQUOTAS; type++) {
888 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
889 continue;
890 if (unsuspend)
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400891 status = dquot_resume(sb, type);
Jan Karaeea7feb2010-05-13 22:14:53 +0200892 else {
893 struct ocfs2_mem_dqinfo *oinfo;
894
895 /* Cancel periodic syncing before suspending */
896 oinfo = sb_dqinfo(sb, type)->dqi_priv;
897 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400898 status = dquot_suspend(sb, type);
Jan Karaeea7feb2010-05-13 22:14:53 +0200899 }
Jan Kara19ece542008-08-21 20:13:17 +0200900 if (status < 0)
901 break;
902 }
903 if (status < 0)
904 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
905 "remount (error = %d).\n", status);
906 return status;
907}
908
909static int ocfs2_enable_quotas(struct ocfs2_super *osb)
910{
911 struct inode *inode[MAXQUOTAS] = { NULL, NULL };
912 struct super_block *sb = osb->sb;
913 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
914 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
915 unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
916 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
917 int status;
918 int type;
919
920 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
921 for (type = 0; type < MAXQUOTAS; type++) {
922 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
923 continue;
924 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
925 osb->slot_num);
926 if (!inode[type]) {
927 status = -ENOENT;
928 goto out_quota_off;
929 }
Christoph Hellwig287a8092010-05-19 07:16:45 -0400930 status = dquot_enable(inode[type], type, QFMT_OCFS2,
931 DQUOT_USAGE_ENABLED);
Jan Kara19ece542008-08-21 20:13:17 +0200932 if (status < 0)
933 goto out_quota_off;
934 }
935
936 for (type = 0; type < MAXQUOTAS; type++)
937 iput(inode[type]);
938 return 0;
939out_quota_off:
940 ocfs2_disable_quotas(osb);
941 for (type = 0; type < MAXQUOTAS; type++)
942 iput(inode[type]);
943 mlog_errno(status);
944 return status;
945}
946
947static void ocfs2_disable_quotas(struct ocfs2_super *osb)
948{
949 int type;
950 struct inode *inode;
951 struct super_block *sb = osb->sb;
Jan Karac06bcbf2010-05-13 22:14:53 +0200952 struct ocfs2_mem_dqinfo *oinfo;
Jan Kara19ece542008-08-21 20:13:17 +0200953
954 /* We mostly ignore errors in this function because there's not much
955 * we can do when we see them */
956 for (type = 0; type < MAXQUOTAS; type++) {
957 if (!sb_has_quota_loaded(sb, type))
958 continue;
Jan Karac06bcbf2010-05-13 22:14:53 +0200959 /* Cancel periodic syncing before we grab dqonoff_mutex */
960 oinfo = sb_dqinfo(sb, type)->dqi_priv;
961 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
Jan Kara19ece542008-08-21 20:13:17 +0200962 inode = igrab(sb->s_dquot.files[type]);
963 /* Turn off quotas. This will remove all dquot structures from
964 * memory and so they will be automatically synced to global
965 * quota files */
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400966 dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
967 DQUOT_LIMITS_ENABLED);
Jan Kara19ece542008-08-21 20:13:17 +0200968 if (!inode)
969 continue;
970 iput(inode);
971 }
972}
973
974/* Handle quota on quotactl */
975static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
Christoph Hellwig307ae182010-05-19 07:16:43 -0400976 char *path)
Jan Kara19ece542008-08-21 20:13:17 +0200977{
978 unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
979 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
980
981 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
982 return -EINVAL;
983
Christoph Hellwig287a8092010-05-19 07:16:45 -0400984 return dquot_enable(sb_dqopt(sb)->files[type], type,
985 format_id, DQUOT_LIMITS_ENABLED);
Jan Kara19ece542008-08-21 20:13:17 +0200986}
987
988/* Handle quota off quotactl */
Christoph Hellwig307ae182010-05-19 07:16:43 -0400989static int ocfs2_quota_off(struct super_block *sb, int type)
Jan Kara19ece542008-08-21 20:13:17 +0200990{
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400991 return dquot_disable(sb, type, DQUOT_LIMITS_ENABLED);
Jan Kara19ece542008-08-21 20:13:17 +0200992}
993
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700994static const struct quotactl_ops ocfs2_quotactl_ops = {
Jan Kara19ece542008-08-21 20:13:17 +0200995 .quota_on = ocfs2_quota_on,
996 .quota_off = ocfs2_quota_off,
Christoph Hellwig287a8092010-05-19 07:16:45 -0400997 .quota_sync = dquot_quota_sync,
998 .get_info = dquot_get_dqinfo,
999 .set_info = dquot_set_dqinfo,
1000 .get_dqblk = dquot_get_dqblk,
1001 .set_dqblk = dquot_set_dqblk,
Jan Kara19ece542008-08-21 20:13:17 +02001002};
1003
Mark Fashehccd979b2005-12-15 14:31:24 -08001004static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
1005{
1006 struct dentry *root;
1007 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001008 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -08001009 struct inode *inode = NULL;
1010 struct ocfs2_super *osb = NULL;
1011 struct buffer_head *bh = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001012 char nodestr[8];
Joel Becker73be1922009-01-06 14:57:08 -08001013 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -08001014
1015 mlog_entry("%p, %p, %i", sb, data, silent);
1016
Tiger Yangc0123ad2007-09-08 00:16:10 +08001017 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001018 status = -EINVAL;
1019 goto read_super_error;
1020 }
1021
1022 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -08001023 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001024 if (status < 0) {
1025 mlog(ML_ERROR, "superblock probe failed!\n");
1026 goto read_super_error;
1027 }
1028
Joel Becker73be1922009-01-06 14:57:08 -08001029 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001030 osb = OCFS2_SB(sb);
1031 if (status < 0) {
1032 mlog_errno(status);
1033 goto read_super_error;
1034 }
1035 brelse(bh);
1036 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001037
Jan Kara5297aad2009-10-15 14:54:04 +02001038 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1039 status = -EINVAL;
1040 goto read_super_error;
1041 }
Tiger Yangc0123ad2007-09-08 00:16:10 +08001042 osb->s_mount_opt = parsed_options.mount_opt;
1043 osb->s_atime_quantum = parsed_options.atime_quantum;
1044 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001045 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh73c8a802010-04-05 18:17:13 -07001046
1047 ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
Mark Fashehd02f00c2009-12-07 13:10:48 -08001048 osb->osb_resv_level = parsed_options.resv_level;
Mark Fasheh83f92312010-04-05 18:17:16 -07001049 osb->osb_dir_resv_level = parsed_options.resv_level;
1050 if (parsed_options.dir_resv_level == -1)
1051 osb->osb_dir_resv_level = parsed_options.resv_level;
1052 else
1053 osb->osb_dir_resv_level = parsed_options.dir_resv_level;
Mark Fashehccd979b2005-12-15 14:31:24 -08001054
Joel Beckerb61817e2008-02-01 15:08:23 -08001055 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1056 if (status)
1057 goto read_super_error;
1058
Mark Fashehccd979b2005-12-15 14:31:24 -08001059 sb->s_magic = OCFS2_SUPER_MAGIC;
1060
Tiger Yanga68979b2008-11-14 11:17:52 +08001061 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1062 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1063
Mark Fashehccd979b2005-12-15 14:31:24 -08001064 /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
1065 * heartbeat=none */
1066 if (bdev_read_only(sb->s_bdev)) {
1067 if (!(sb->s_flags & MS_RDONLY)) {
1068 status = -EACCES;
1069 mlog(ML_ERROR, "Readonly device detected but readonly "
1070 "mount was not specified.\n");
1071 goto read_super_error;
1072 }
1073
1074 /* You should not be able to start a local heartbeat
1075 * on a readonly device. */
1076 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1077 status = -EROFS;
1078 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1079 "device.\n");
1080 goto read_super_error;
1081 }
1082
1083 status = ocfs2_check_journals_nolocks(osb);
1084 if (status < 0) {
1085 if (status == -EROFS)
1086 mlog(ML_ERROR, "Recovery required on readonly "
1087 "file system, but write access is "
1088 "unavailable.\n");
1089 else
Sunil Mushran2bd63212010-01-25 16:57:38 -08001090 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -08001091 goto read_super_error;
1092 }
1093
1094 ocfs2_set_ro_flag(osb, 1);
1095
1096 printk(KERN_NOTICE "Readonly device detected. No cluster "
1097 "services will be utilized for this mount. Recovery "
1098 "will be skipped.\n");
1099 }
1100
1101 if (!ocfs2_is_hard_readonly(osb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001102 if (sb->s_flags & MS_RDONLY)
1103 ocfs2_set_ro_flag(osb, 0);
1104 }
1105
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001106 status = ocfs2_verify_heartbeat(osb);
1107 if (status < 0) {
1108 mlog_errno(status);
1109 goto read_super_error;
1110 }
1111
Mark Fashehccd979b2005-12-15 14:31:24 -08001112 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1113 ocfs2_debugfs_root);
1114 if (!osb->osb_debug_root) {
1115 status = -EINVAL;
1116 mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
1117 goto read_super_error;
1118 }
1119
Sunil Mushran50397502008-12-17 14:17:43 -08001120 osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
1121 osb->osb_debug_root,
1122 osb,
1123 &ocfs2_osb_debug_fops);
1124 if (!osb->osb_ctxt) {
1125 status = -EINVAL;
1126 mlog_errno(status);
1127 goto read_super_error;
1128 }
1129
Joel Becker73be1922009-01-06 14:57:08 -08001130 if (ocfs2_meta_ecc(osb)) {
1131 status = ocfs2_blockcheck_stats_debugfs_install(
1132 &osb->osb_ecc_stats,
1133 osb->osb_debug_root);
1134 if (status) {
1135 mlog(ML_ERROR,
1136 "Unable to create blockcheck statistics "
1137 "files\n");
1138 goto read_super_error;
1139 }
1140 }
1141
Mark Fashehccd979b2005-12-15 14:31:24 -08001142 status = ocfs2_mount_volume(sb);
1143 if (osb->root_inode)
1144 inode = igrab(osb->root_inode);
1145
1146 if (status < 0)
1147 goto read_super_error;
1148
1149 if (!inode) {
1150 status = -EIO;
1151 mlog_errno(status);
1152 goto read_super_error;
1153 }
1154
1155 root = d_alloc_root(inode);
1156 if (!root) {
1157 status = -ENOMEM;
1158 mlog_errno(status);
1159 goto read_super_error;
1160 }
1161
1162 sb->s_root = root;
1163
1164 ocfs2_complete_mount_recovery(osb);
1165
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001166 if (ocfs2_mount_local(osb))
1167 snprintf(nodestr, sizeof(nodestr), "local");
1168 else
Joel Becker19fdb622008-01-30 15:38:24 -08001169 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001170
1171 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001172 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001173 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001174 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1175 "ordered");
1176
1177 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1178 wake_up(&osb->osb_mount_event);
1179
Jan Kara19ece542008-08-21 20:13:17 +02001180 /* Now we can initialize quotas because we can afford to wait
1181 * for cluster locks recovery now. That also means that truncation
1182 * log recovery can happen but that waits for proper quota setup */
1183 if (!(sb->s_flags & MS_RDONLY)) {
1184 status = ocfs2_enable_quotas(osb);
1185 if (status < 0) {
1186 /* We have to err-out specially here because
1187 * s_root is already set */
1188 mlog_errno(status);
1189 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1190 wake_up(&osb->osb_mount_event);
1191 mlog_exit(status);
1192 return status;
1193 }
1194 }
1195
1196 ocfs2_complete_quota_recovery(osb);
1197
1198 /* Now we wake up again for processes waiting for quotas */
1199 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1200 wake_up(&osb->osb_mount_event);
1201
Sunil Mushrandf152c22009-06-22 11:40:07 -07001202 /* Start this when the mount is almost sure of being successful */
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04001203 ocfs2_orphan_scan_start(osb);
Sunil Mushrandf152c22009-06-22 11:40:07 -07001204
Mark Fashehccd979b2005-12-15 14:31:24 -08001205 mlog_exit(status);
1206 return status;
1207
1208read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001209 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001210
1211 if (inode)
1212 iput(inode);
1213
1214 if (osb) {
1215 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1216 wake_up(&osb->osb_mount_event);
1217 ocfs2_dismount_volume(sb, 1);
1218 }
1219
1220 mlog_exit(status);
1221 return status;
1222}
1223
David Howells454e2392006-06-23 02:02:57 -07001224static int ocfs2_get_sb(struct file_system_type *fs_type,
1225 int flags,
1226 const char *dev_name,
1227 void *data,
1228 struct vfsmount *mnt)
Mark Fashehccd979b2005-12-15 14:31:24 -08001229{
David Howells454e2392006-06-23 02:02:57 -07001230 return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
1231 mnt);
Mark Fashehccd979b2005-12-15 14:31:24 -08001232}
1233
Jan Karaf7b1aa62009-07-20 12:12:36 +02001234static void ocfs2_kill_sb(struct super_block *sb)
1235{
1236 struct ocfs2_super *osb = OCFS2_SB(sb);
1237
Jan Kara5fd13182009-07-30 17:01:53 +02001238 /* Failed mount? */
1239 if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
1240 goto out;
1241
Jan Karaf7b1aa62009-07-20 12:12:36 +02001242 /* Prevent further queueing of inode drop events */
1243 spin_lock(&dentry_list_lock);
1244 ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
1245 spin_unlock(&dentry_list_lock);
1246 /* Wait for work to finish and/or remove it */
1247 cancel_work_sync(&osb->dentry_lock_work);
Jan Kara5fd13182009-07-30 17:01:53 +02001248out:
Jan Karaf7b1aa62009-07-20 12:12:36 +02001249 kill_block_super(sb);
1250}
1251
Mark Fashehccd979b2005-12-15 14:31:24 -08001252static struct file_system_type ocfs2_fs_type = {
1253 .owner = THIS_MODULE,
1254 .name = "ocfs2",
1255 .get_sb = ocfs2_get_sb, /* is this called when we mount
1256 * the fs? */
Jan Karaf7b1aa62009-07-20 12:12:36 +02001257 .kill_sb = ocfs2_kill_sb,
1258
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001259 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001260 .next = NULL
1261};
1262
Jan Kara5297aad2009-10-15 14:54:04 +02001263static int ocfs2_check_set_options(struct super_block *sb,
1264 struct mount_options *options)
1265{
1266 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1267 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1268 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1269 mlog(ML_ERROR, "User quotas were requested, but this "
1270 "filesystem does not have the feature enabled.\n");
1271 return 0;
1272 }
1273 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1274 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1275 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1276 mlog(ML_ERROR, "Group quotas were requested, but this "
1277 "filesystem does not have the feature enabled.\n");
1278 return 0;
1279 }
1280 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1281 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1282 mlog(ML_ERROR, "ACL support requested but extended attributes "
1283 "feature is not enabled\n");
1284 return 0;
1285 }
1286 /* No ACL setting specified? Use XATTR feature... */
1287 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1288 OCFS2_MOUNT_NO_POSIX_ACL))) {
1289 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1290 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1291 else
1292 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1293 }
1294 return 1;
1295}
1296
Mark Fashehccd979b2005-12-15 14:31:24 -08001297static int ocfs2_parse_options(struct super_block *sb,
1298 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001299 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001300 int is_remount)
1301{
1302 int status;
1303 char *p;
Sunil Mushran2c442712010-10-07 15:23:50 -07001304 u32 tmp;
Mark Fashehccd979b2005-12-15 14:31:24 -08001305
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:
Sunil Mushran2c442712010-10-07 15:23:50 -07001336 mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
1337 break;
1338 case Opt_hb_global:
1339 mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001340 break;
1341 case Opt_barrier:
1342 if (match_int(&args[0], &option)) {
1343 status = 0;
1344 goto bail;
1345 }
1346 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001347 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001348 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001349 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001350 break;
1351 case Opt_intr:
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_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001355 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001356 break;
1357 case Opt_err_panic:
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_err_ro:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001361 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001362 break;
1363 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001364 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001365 break;
1366 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001367 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001368 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001369 case Opt_user_xattr:
1370 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1371 break;
1372 case Opt_nouser_xattr:
1373 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1374 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001375 case Opt_atime_quantum:
1376 if (match_int(&args[0], &option)) {
1377 status = 0;
1378 goto bail;
1379 }
1380 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001381 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001382 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001383 case Opt_slot:
1384 option = 0;
1385 if (match_int(&args[0], &option)) {
1386 status = 0;
1387 goto bail;
1388 }
1389 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001390 mopt->slot = (s16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001391 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001392 case Opt_commit:
1393 option = 0;
1394 if (match_int(&args[0], &option)) {
1395 status = 0;
1396 goto bail;
1397 }
1398 if (option < 0)
1399 return 0;
1400 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001401 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001402 mopt->commit_interval = HZ * option;
1403 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001404 case Opt_localalloc:
1405 option = 0;
1406 if (match_int(&args[0], &option)) {
1407 status = 0;
1408 goto bail;
1409 }
Mark Fasheh73c8a802010-04-05 18:17:13 -07001410 if (option >= 0)
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001411 mopt->localalloc_opt = option;
1412 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001413 case Opt_localflocks:
1414 /*
1415 * Changing this during remount could race
1416 * flock() requests, or "unbalance" existing
1417 * ones (e.g., a lock is taken in one mode but
1418 * dropped in the other). If users care enough
1419 * to flip locking modes during remount, we
1420 * could add a "local" flag to individual
1421 * flock structures for proper tracking of
1422 * state.
1423 */
1424 if (!is_remount)
1425 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1426 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001427 case Opt_stack:
1428 /* Check both that the option we were passed
1429 * is of the right length and that it is a proper
1430 * string of the right length.
1431 */
1432 if (((args[0].to - args[0].from) !=
1433 OCFS2_STACK_LABEL_LEN) ||
1434 (strnlen(args[0].from,
1435 OCFS2_STACK_LABEL_LEN) !=
1436 OCFS2_STACK_LABEL_LEN)) {
1437 mlog(ML_ERROR,
1438 "Invalid cluster_stack option\n");
1439 status = 0;
1440 goto bail;
1441 }
1442 memcpy(mopt->cluster_stack, args[0].from,
1443 OCFS2_STACK_LABEL_LEN);
1444 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
1445 break;
Joel Becker12462f12008-09-03 20:03:40 -07001446 case Opt_inode64:
1447 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1448 break;
Jan Kara19ece542008-08-21 20:13:17 +02001449 case Opt_usrquota:
Jan Kara19ece542008-08-21 20:13:17 +02001450 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1451 break;
1452 case Opt_grpquota:
Jan Kara19ece542008-08-21 20:13:17 +02001453 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1454 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001455 case Opt_acl:
1456 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
Jan Kara5297aad2009-10-15 14:54:04 +02001457 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001458 break;
1459 case Opt_noacl:
Jan Kara5297aad2009-10-15 14:54:04 +02001460 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001461 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1462 break;
Mark Fashehd02f00c2009-12-07 13:10:48 -08001463 case Opt_resv_level:
1464 if (is_remount)
1465 break;
1466 if (match_int(&args[0], &option)) {
1467 status = 0;
1468 goto bail;
1469 }
1470 if (option >= OCFS2_MIN_RESV_LEVEL &&
1471 option < OCFS2_MAX_RESV_LEVEL)
1472 mopt->resv_level = option;
1473 break;
Mark Fasheh83f92312010-04-05 18:17:16 -07001474 case Opt_dir_resv_level:
1475 if (is_remount)
1476 break;
1477 if (match_int(&args[0], &option)) {
1478 status = 0;
1479 goto bail;
1480 }
1481 if (option >= OCFS2_MIN_RESV_LEVEL &&
1482 option < OCFS2_MAX_RESV_LEVEL)
1483 mopt->dir_resv_level = option;
1484 break;
Mark Fashehccd979b2005-12-15 14:31:24 -08001485 default:
1486 mlog(ML_ERROR,
1487 "Unrecognized mount option \"%s\" "
1488 "or missing value\n", p);
1489 status = 0;
1490 goto bail;
1491 }
1492 }
1493
Sunil Mushran2c442712010-10-07 15:23:50 -07001494 /* Ensure only one heartbeat mode */
1495 tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL |
1496 OCFS2_MOUNT_HB_NONE);
1497 if (hweight32(tmp) != 1) {
1498 mlog(ML_ERROR, "Invalid heartbeat mount options\n");
1499 status = 0;
1500 goto bail;
1501 }
1502
Mark Fashehccd979b2005-12-15 14:31:24 -08001503 status = 1;
1504
1505bail:
1506 mlog_exit(status);
1507 return status;
1508}
1509
Sunil Mushrand5500712007-09-06 13:34:16 -07001510static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1511{
1512 struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
1513 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001514 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001515
Sunil Mushran2c442712010-10-07 15:23:50 -07001516 if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
1517 seq_printf(s, ",_netdev");
1518 if (opts & OCFS2_MOUNT_HB_LOCAL)
1519 seq_printf(s, ",%s", OCFS2_HB_LOCAL);
1520 else
1521 seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
1522 } else
1523 seq_printf(s, ",%s", OCFS2_HB_NONE);
Sunil Mushrand5500712007-09-06 13:34:16 -07001524
1525 if (opts & OCFS2_MOUNT_NOINTR)
1526 seq_printf(s, ",nointr");
1527
1528 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1529 seq_printf(s, ",data=writeback");
1530 else
1531 seq_printf(s, ",data=ordered");
1532
1533 if (opts & OCFS2_MOUNT_BARRIER)
1534 seq_printf(s, ",barrier=1");
1535
1536 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1537 seq_printf(s, ",errors=panic");
1538 else
1539 seq_printf(s, ",errors=remount-ro");
1540
1541 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1542 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1543
1544 if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
1545 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
1546
Mark Fashehd147b3d2007-11-07 14:40:36 -08001547 if (osb->osb_commit_interval)
1548 seq_printf(s, ",commit=%u",
1549 (unsigned) (osb->osb_commit_interval / HZ));
1550
Mark Fashehebcee4b2008-07-28 14:55:20 -07001551 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
Mark Fasheh6b820212010-04-05 18:17:14 -07001552 if (local_alloc_megs != ocfs2_la_default_mb(osb))
Mark Fashehebcee4b2008-07-28 14:55:20 -07001553 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001554
Mark Fasheh53fc6222007-12-20 16:49:04 -08001555 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1556 seq_printf(s, ",localflocks,");
1557
Joel Beckerb61817e2008-02-01 15:08:23 -08001558 if (osb->osb_cluster_stack[0])
1559 seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
1560 osb->osb_cluster_stack);
Jan Kara19ece542008-08-21 20:13:17 +02001561 if (opts & OCFS2_MOUNT_USRQUOTA)
1562 seq_printf(s, ",usrquota");
1563 if (opts & OCFS2_MOUNT_GRPQUOTA)
1564 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001565
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001566 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1567 seq_printf(s, ",nouser_xattr");
1568 else
1569 seq_printf(s, ",user_xattr");
1570
Joel Becker12462f12008-09-03 20:03:40 -07001571 if (opts & OCFS2_MOUNT_INODE64)
1572 seq_printf(s, ",inode64");
1573
Tiger Yanga68979b2008-11-14 11:17:52 +08001574 if (opts & OCFS2_MOUNT_POSIX_ACL)
1575 seq_printf(s, ",acl");
1576 else
1577 seq_printf(s, ",noacl");
Tiger Yanga68979b2008-11-14 11:17:52 +08001578
Mark Fashehd02f00c2009-12-07 13:10:48 -08001579 if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
1580 seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
1581
Mark Fasheh83f92312010-04-05 18:17:16 -07001582 if (osb->osb_dir_resv_level != osb->osb_resv_level)
1583 seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
1584
Sunil Mushrand5500712007-09-06 13:34:16 -07001585 return 0;
1586}
1587
Mark Fashehccd979b2005-12-15 14:31:24 -08001588static int __init ocfs2_init(void)
1589{
1590 int status;
1591
1592 mlog_entry_void();
1593
1594 ocfs2_print_version();
1595
Mark Fashehccd979b2005-12-15 14:31:24 -08001596 status = init_ocfs2_uptodate_cache();
1597 if (status < 0) {
1598 mlog_errno(status);
1599 goto leave;
1600 }
1601
1602 status = ocfs2_initialize_mem_caches();
1603 if (status < 0) {
1604 mlog_errno(status);
1605 goto leave;
1606 }
1607
1608 ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
1609 if (!ocfs2_wq) {
1610 status = -ENOMEM;
1611 goto leave;
1612 }
1613
Mark Fashehccd979b2005-12-15 14:31:24 -08001614 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
1615 if (!ocfs2_debugfs_root) {
1616 status = -EFAULT;
1617 mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
1618 }
1619
Mark Fasheh171bf932008-10-20 15:36:47 +02001620 status = ocfs2_quota_setup();
1621 if (status)
1622 goto leave;
1623
Joel Becker63e0c482008-01-30 16:58:36 -08001624 ocfs2_set_locking_protocol();
1625
Jan Kara9e33d692008-08-25 19:56:50 +02001626 status = register_quota_format(&ocfs2_quota_format);
Mark Fashehccd979b2005-12-15 14:31:24 -08001627leave:
1628 if (status < 0) {
Mark Fasheh171bf932008-10-20 15:36:47 +02001629 ocfs2_quota_shutdown();
Mark Fashehccd979b2005-12-15 14:31:24 -08001630 ocfs2_free_mem_caches();
1631 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001632 }
1633
1634 mlog_exit(status);
1635
1636 if (status >= 0) {
1637 return register_filesystem(&ocfs2_fs_type);
1638 } else
1639 return -1;
1640}
1641
1642static void __exit ocfs2_exit(void)
1643{
1644 mlog_entry_void();
1645
Mark Fasheh171bf932008-10-20 15:36:47 +02001646 ocfs2_quota_shutdown();
1647
Mark Fashehccd979b2005-12-15 14:31:24 -08001648 if (ocfs2_wq) {
1649 flush_workqueue(ocfs2_wq);
1650 destroy_workqueue(ocfs2_wq);
1651 }
1652
Jan Kara9e33d692008-08-25 19:56:50 +02001653 unregister_quota_format(&ocfs2_quota_format);
1654
Mark Fashehccd979b2005-12-15 14:31:24 -08001655 debugfs_remove(ocfs2_debugfs_root);
1656
1657 ocfs2_free_mem_caches();
1658
1659 unregister_filesystem(&ocfs2_fs_type);
1660
Mark Fashehccd979b2005-12-15 14:31:24 -08001661 exit_ocfs2_uptodate_cache();
1662
1663 mlog_exit_void();
1664}
1665
1666static void ocfs2_put_super(struct super_block *sb)
1667{
1668 mlog_entry("(0x%p)\n", sb);
1669
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001670 lock_kernel();
1671
Mark Fashehccd979b2005-12-15 14:31:24 -08001672 ocfs2_sync_blockdev(sb);
1673 ocfs2_dismount_volume(sb, 0);
1674
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02001675 unlock_kernel();
1676
Mark Fashehccd979b2005-12-15 14:31:24 -08001677 mlog_exit_void();
1678}
1679
David Howells726c3342006-06-23 02:02:58 -07001680static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001681{
1682 struct ocfs2_super *osb;
1683 u32 numbits, freebits;
1684 int status;
1685 struct ocfs2_dinode *bm_lock;
1686 struct buffer_head *bh = NULL;
1687 struct inode *inode = NULL;
1688
David Howells726c3342006-06-23 02:02:58 -07001689 mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001690
David Howells726c3342006-06-23 02:02:58 -07001691 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001692
1693 inode = ocfs2_get_system_file_inode(osb,
1694 GLOBAL_BITMAP_SYSTEM_INODE,
1695 OCFS2_INVALID_SLOT);
1696 if (!inode) {
1697 mlog(ML_ERROR, "failed to get bitmap inode\n");
1698 status = -EIO;
1699 goto bail;
1700 }
1701
Mark Fashehe63aecb62007-10-18 15:30:42 -07001702 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001703 if (status < 0) {
1704 mlog_errno(status);
1705 goto bail;
1706 }
1707
1708 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1709
1710 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1711 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1712
1713 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001714 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001715 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1716 buf->f_blocks = ((sector_t) numbits) *
1717 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1718 buf->f_bfree = ((sector_t) freebits) *
1719 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1720 buf->f_bavail = buf->f_bfree;
1721 buf->f_files = numbits;
1722 buf->f_ffree = freebits;
Coly Li837711f2009-01-16 16:33:05 +08001723 buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1724 & 0xFFFFFFFFUL;
1725 buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1726 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001727
1728 brelse(bh);
1729
Mark Fashehe63aecb62007-10-18 15:30:42 -07001730 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001731 status = 0;
1732bail:
1733 if (inode)
1734 iput(inode);
1735
1736 mlog_exit(status);
1737
1738 return status;
1739}
1740
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001741static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001742{
1743 struct ocfs2_inode_info *oi = data;
1744
Christoph Lametera35afb82007-05-16 22:10:57 -07001745 oi->ip_flags = 0;
1746 oi->ip_open_count = 0;
1747 spin_lock_init(&oi->ip_lock);
1748 ocfs2_extent_map_init(&oi->vfs_inode);
1749 INIT_LIST_HEAD(&oi->ip_io_markers);
Christoph Lametera35afb82007-05-16 22:10:57 -07001750 oi->ip_dir_start_lookup = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001751
Christoph Lametera35afb82007-05-16 22:10:57 -07001752 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001753 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001754 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001755
Christoph Lametera35afb82007-05-16 22:10:57 -07001756 oi->ip_blkno = 0ULL;
1757 oi->ip_clusters = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001758
Mark Fasheh4fe370a2009-12-07 13:15:40 -08001759 ocfs2_resv_init_once(&oi->ip_la_data_resv);
1760
Christoph Lametera35afb82007-05-16 22:10:57 -07001761 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001762 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001763 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001764
Joel Becker8cb471e2009-02-10 20:00:41 -08001765 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
Joel Becker6e5a3d72009-02-10 19:00:37 -08001766 &ocfs2_inode_caching_ops);
Mark Fashehccd979b2005-12-15 14:31:24 -08001767
Christoph Lametera35afb82007-05-16 22:10:57 -07001768 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001769}
1770
1771static int ocfs2_initialize_mem_caches(void)
1772{
1773 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001774 sizeof(struct ocfs2_inode_info),
1775 0,
1776 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1777 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001778 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001779 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1780 sizeof(struct ocfs2_dquot),
1781 0,
1782 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1783 SLAB_MEM_SPREAD),
1784 NULL);
1785 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1786 sizeof(struct ocfs2_quota_chunk),
1787 0,
1788 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1789 NULL);
1790 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1791 !ocfs2_qf_chunk_cachep) {
1792 if (ocfs2_inode_cachep)
1793 kmem_cache_destroy(ocfs2_inode_cachep);
1794 if (ocfs2_dquot_cachep)
1795 kmem_cache_destroy(ocfs2_dquot_cachep);
1796 if (ocfs2_qf_chunk_cachep)
1797 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001798 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001799 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001800
Mark Fashehccd979b2005-12-15 14:31:24 -08001801 return 0;
1802}
1803
1804static void ocfs2_free_mem_caches(void)
1805{
1806 if (ocfs2_inode_cachep)
1807 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001808 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001809
1810 if (ocfs2_dquot_cachep)
1811 kmem_cache_destroy(ocfs2_dquot_cachep);
1812 ocfs2_dquot_cachep = NULL;
1813
1814 if (ocfs2_qf_chunk_cachep)
1815 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
1816 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001817}
1818
1819static int ocfs2_get_sector(struct super_block *sb,
1820 struct buffer_head **bh,
1821 int block,
1822 int sect_size)
1823{
1824 if (!sb_set_blocksize(sb, sect_size)) {
1825 mlog(ML_ERROR, "unable to set blocksize\n");
1826 return -EIO;
1827 }
1828
1829 *bh = sb_getblk(sb, block);
1830 if (!*bh) {
1831 mlog_errno(-EIO);
1832 return -EIO;
1833 }
1834 lock_buffer(*bh);
1835 if (!buffer_dirty(*bh))
1836 clear_buffer_uptodate(*bh);
1837 unlock_buffer(*bh);
1838 ll_rw_block(READ, 1, bh);
1839 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001840 if (!buffer_uptodate(*bh)) {
1841 mlog_errno(-EIO);
1842 brelse(*bh);
1843 *bh = NULL;
1844 return -EIO;
1845 }
1846
Mark Fashehccd979b2005-12-15 14:31:24 -08001847 return 0;
1848}
1849
Mark Fashehccd979b2005-12-15 14:31:24 -08001850static int ocfs2_mount_volume(struct super_block *sb)
1851{
1852 int status = 0;
1853 int unlock_super = 0;
1854 struct ocfs2_super *osb = OCFS2_SB(sb);
1855
1856 mlog_entry_void();
1857
1858 if (ocfs2_is_hard_readonly(osb))
1859 goto leave;
1860
Mark Fashehccd979b2005-12-15 14:31:24 -08001861 status = ocfs2_dlm_init(osb);
1862 if (status < 0) {
1863 mlog_errno(status);
1864 goto leave;
1865 }
1866
Mark Fashehccd979b2005-12-15 14:31:24 -08001867 status = ocfs2_super_lock(osb, 1);
1868 if (status < 0) {
1869 mlog_errno(status);
1870 goto leave;
1871 }
1872 unlock_super = 1;
1873
1874 /* This will load up the node map and add ourselves to it. */
1875 status = ocfs2_find_slot(osb);
1876 if (status < 0) {
1877 mlog_errno(status);
1878 goto leave;
1879 }
1880
Mark Fashehccd979b2005-12-15 14:31:24 -08001881 /* load all node-local system inodes */
1882 status = ocfs2_init_local_system_inodes(osb);
1883 if (status < 0) {
1884 mlog_errno(status);
1885 goto leave;
1886 }
1887
1888 status = ocfs2_check_volume(osb);
1889 if (status < 0) {
1890 mlog_errno(status);
1891 goto leave;
1892 }
1893
1894 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001895 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001896 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001897
Mark Fashehccd979b2005-12-15 14:31:24 -08001898leave:
1899 if (unlock_super)
1900 ocfs2_super_unlock(osb, 1);
1901
1902 mlog_exit(status);
1903 return status;
1904}
1905
Mark Fashehccd979b2005-12-15 14:31:24 -08001906static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1907{
Joel Becker286eaa92008-02-01 15:03:57 -08001908 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001909 struct ocfs2_super *osb = NULL;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001910 char nodestr[8];
Mark Fashehccd979b2005-12-15 14:31:24 -08001911
1912 mlog_entry("(0x%p)\n", sb);
1913
1914 BUG_ON(!sb);
1915 osb = OCFS2_SB(sb);
1916 BUG_ON(!osb);
1917
Sunil Mushran50397502008-12-17 14:17:43 -08001918 debugfs_remove(osb->osb_ctxt);
1919
Jan Karaf7b1aa62009-07-20 12:12:36 +02001920 /*
1921 * Flush inode dropping work queue so that deletes are
1922 * performed while the filesystem is still working
1923 */
1924 ocfs2_drop_all_dl_inodes(osb);
1925
Sunil Mushran692684e2009-06-19 16:53:17 -07001926 /* Orphan scan should be stopped as early as possible */
1927 ocfs2_orphan_scan_stop(osb);
1928
Jan Kara19ece542008-08-21 20:13:17 +02001929 ocfs2_disable_quotas(osb);
1930
Mark Fashehccd979b2005-12-15 14:31:24 -08001931 ocfs2_shutdown_local_alloc(osb);
1932
1933 ocfs2_truncate_log_shutdown(osb);
1934
Joel Becker553abd02008-02-01 12:03:57 -08001935 /* This will disable recovery and flush any recovery work. */
1936 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001937
1938 ocfs2_journal_shutdown(osb);
1939
1940 ocfs2_sync_blockdev(sb);
1941
Tao Ma374a2632009-08-24 11:13:37 +08001942 ocfs2_purge_refcount_trees(osb);
1943
Joel Becker4670c462008-02-01 14:39:35 -08001944 /* No cluster connection means we've failed during mount, so skip
1945 * all the steps which depended on that to complete. */
1946 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001947 tmp = ocfs2_super_lock(osb, 1);
1948 if (tmp < 0) {
1949 mlog_errno(tmp);
1950 return;
1951 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001952 }
1953
Mark Fasheh19b613d2007-10-04 14:47:09 -07001954 if (osb->slot_num != OCFS2_INVALID_SLOT)
1955 ocfs2_put_slot(osb);
1956
Joel Becker4670c462008-02-01 14:39:35 -08001957 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001958 ocfs2_super_unlock(osb, 1);
1959
Mark Fashehccd979b2005-12-15 14:31:24 -08001960 ocfs2_release_system_inodes(osb);
1961
Joel Becker6953b4c2008-01-29 16:59:56 -08001962 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001963 * If we're dismounting due to mount error, mount.ocfs2 will clean
1964 * up heartbeat. If we're a local mount, there is no heartbeat.
1965 * If we failed before we got a uuid_str yet, we can't stop
1966 * heartbeat. Otherwise, do it.
1967 */
1968 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
Joel Becker286eaa92008-02-01 15:03:57 -08001969 hangup_needed = 1;
1970
1971 if (osb->cconn)
1972 ocfs2_dlm_shutdown(osb, hangup_needed);
1973
Joel Becker73be1922009-01-06 14:57:08 -08001974 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Joel Becker286eaa92008-02-01 15:03:57 -08001975 debugfs_remove(osb->osb_debug_root);
1976
1977 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001978 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001979
1980 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1981
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001982 if (ocfs2_mount_local(osb))
1983 snprintf(nodestr, sizeof(nodestr), "local");
1984 else
Joel Becker19fdb622008-01-30 15:38:24 -08001985 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001986
1987 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1988 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001989
1990 ocfs2_delete_osb(osb);
1991 kfree(osb);
1992 sb->s_dev = 0;
1993 sb->s_fs_info = NULL;
1994}
1995
1996static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1997 unsigned uuid_bytes)
1998{
1999 int i, ret;
2000 char *ptr;
2001
2002 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
2003
Robert P. J. Daycd861282006-12-13 00:34:52 -08002004 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002005 if (osb->uuid_str == NULL)
2006 return -ENOMEM;
2007
Mark Fashehccd979b2005-12-15 14:31:24 -08002008 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
2009 /* print with null */
2010 ret = snprintf(ptr, 3, "%02X", uuid[i]);
2011 if (ret != 2) /* drop super cleans up */
2012 return -EINVAL;
2013 /* then only advance past the last char */
2014 ptr += 2;
2015 }
2016
2017 return 0;
2018}
2019
2020static int ocfs2_initialize_super(struct super_block *sb,
2021 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002022 int sector_size,
2023 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002024{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002025 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07002026 int i, cbits, bbits;
2027 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08002028 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08002029 struct ocfs2_journal *journal;
2030 __le32 uuid_net_key;
2031 struct ocfs2_super *osb;
2032
2033 mlog_entry_void();
2034
Robert P. J. Daycd861282006-12-13 00:34:52 -08002035 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002036 if (!osb) {
2037 status = -ENOMEM;
2038 mlog_errno(status);
2039 goto bail;
2040 }
2041
2042 sb->s_fs_info = osb;
2043 sb->s_op = &ocfs2_sops;
2044 sb->s_export_op = &ocfs2_export_ops;
Jan Kara19ece542008-08-21 20:13:17 +02002045 sb->s_qcop = &ocfs2_quotactl_ops;
2046 sb->dq_op = &ocfs2_quota_operations;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002047 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07002048 sb->s_time_gran = 1;
Mark Fashehccd979b2005-12-15 14:31:24 -08002049 sb->s_flags |= MS_NOATIME;
2050 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07002051 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2052 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
2053 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Mark Fashehccd979b2005-12-15 14:31:24 -08002054
Mark Fasheh9b7895e2008-11-12 16:27:44 -08002055 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
2056
2057 for (i = 0; i < 3; i++)
2058 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
2059 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2060
Mark Fashehccd979b2005-12-15 14:31:24 -08002061 osb->sb = sb;
2062 /* Save off for ocfs2_rw_direct */
2063 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01002064 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08002065
Mark Fasheh34d024f2007-09-24 15:56:19 -07002066 spin_lock_init(&osb->dc_task_lock);
2067 init_waitqueue_head(&osb->dc_event);
2068 osb->dc_work_sequence = 0;
2069 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002070 INIT_LIST_HEAD(&osb->blocked_lock_list);
2071 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002072 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08002073 spin_lock_init(&osb->osb_xattr_lock);
Tiger Yangb89c5422010-01-25 14:11:06 +08002074 ocfs2_init_steal_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002075
2076 atomic_set(&osb->alloc_stats.moves, 0);
2077 atomic_set(&osb->alloc_stats.local_data, 0);
2078 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2079 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2080 atomic_set(&osb->alloc_stats.bg_extends, 0);
2081
Joel Becker73be1922009-01-06 14:57:08 -08002082 /* Copy the blockcheck stats from the superblock probe */
2083 osb->osb_ecc_stats = *stats;
2084
Mark Fashehccd979b2005-12-15 14:31:24 -08002085 ocfs2_init_node_maps(osb);
2086
2087 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2088 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2089
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04002090 ocfs2_orphan_scan_init(osb);
2091
Joel Becker553abd02008-02-01 12:03:57 -08002092 status = ocfs2_recovery_init(osb);
2093 if (status) {
2094 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2095 mlog_errno(status);
2096 goto bail;
2097 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002098
2099 init_waitqueue_head(&osb->checkpoint_event);
2100 atomic_set(&osb->needs_checkpoint, 0);
2101
Tiger Yang7f1a37e2006-11-15 15:48:42 +08002102 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2103
Mark Fashehccd979b2005-12-15 14:31:24 -08002104 osb->slot_num = OCFS2_INVALID_SLOT;
2105
Tiger Yang8154da32008-08-18 17:11:46 +08002106 osb->s_xattr_inline_size = le16_to_cpu(
2107 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002108
Mark Fashehccd979b2005-12-15 14:31:24 -08002109 osb->local_alloc_state = OCFS2_LA_UNUSED;
2110 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002111 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002112
Mark Fashehccd979b2005-12-15 14:31:24 -08002113 init_waitqueue_head(&osb->osb_mount_event);
2114
Mark Fashehd02f00c2009-12-07 13:10:48 -08002115 status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
2116 if (status) {
2117 mlog_errno(status);
2118 goto bail;
2119 }
2120
Mark Fashehccd979b2005-12-15 14:31:24 -08002121 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2122 if (!osb->vol_label) {
2123 mlog(ML_ERROR, "unable to alloc vol label\n");
2124 status = -ENOMEM;
2125 goto bail;
2126 }
2127
Mark Fashehccd979b2005-12-15 14:31:24 -08002128 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2129 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2130 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2131 osb->max_slots);
2132 status = -EINVAL;
2133 goto bail;
2134 }
Sunil Mushran781ee3e2006-04-27 16:41:31 -07002135 mlog(0, "max_slots for this device: %u\n", osb->max_slots);
Mark Fashehccd979b2005-12-15 14:31:24 -08002136
Sunil Mushran539d8262008-07-14 17:31:10 -07002137 osb->slot_recovery_generations =
2138 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2139 GFP_KERNEL);
2140 if (!osb->slot_recovery_generations) {
2141 status = -ENOMEM;
2142 mlog_errno(status);
2143 goto bail;
2144 }
2145
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002146 init_waitqueue_head(&osb->osb_wipe_event);
2147 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2148 sizeof(*osb->osb_orphan_wipes),
2149 GFP_KERNEL);
2150 if (!osb->osb_orphan_wipes) {
2151 status = -ENOMEM;
2152 mlog_errno(status);
2153 goto bail;
2154 }
2155
Tao Ma374a2632009-08-24 11:13:37 +08002156 osb->osb_rf_lock_tree = RB_ROOT;
2157
Mark Fashehccd979b2005-12-15 14:31:24 -08002158 osb->s_feature_compat =
2159 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2160 osb->s_feature_ro_compat =
2161 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2162 osb->s_feature_incompat =
2163 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2164
2165 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2166 mlog(ML_ERROR, "couldn't mount because of unsupported "
2167 "optional features (%x).\n", i);
2168 status = -EINVAL;
2169 goto bail;
2170 }
2171 if (!(osb->sb->s_flags & MS_RDONLY) &&
2172 (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
2173 mlog(ML_ERROR, "couldn't mount RDWR because of "
2174 "unsupported optional features (%x).\n", i);
2175 status = -EINVAL;
2176 goto bail;
2177 }
2178
Sunil Mushran98f486f22010-10-09 10:24:46 -07002179 if (ocfs2_clusterinfo_valid(osb)) {
2180 osb->osb_stackflags =
2181 OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
Joel Beckerb61817e2008-02-01 15:08:23 -08002182 memcpy(osb->osb_cluster_stack,
2183 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
2184 OCFS2_STACK_LABEL_LEN);
2185 osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
2186 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2187 mlog(ML_ERROR,
2188 "couldn't mount because of an invalid "
2189 "cluster stack label (%s) \n",
2190 osb->osb_cluster_stack);
2191 status = -EINVAL;
2192 goto bail;
2193 }
2194 } else {
2195 /* The empty string is identical with classic tools that
2196 * don't know about s_cluster_info. */
2197 osb->osb_cluster_stack[0] = '\0';
2198 }
2199
Mark Fashehccd979b2005-12-15 14:31:24 -08002200 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2201
2202 /* FIXME
2203 * This should be done in ocfs2_journal_init(), but unknown
2204 * ordering issues will cause the filesystem to crash.
2205 * If anyone wants to figure out what part of the code
2206 * refers to osb->journal before ocfs2_journal_init() is run,
2207 * be my guest.
2208 */
2209 /* initialize our journal structure */
2210
Robert P. J. Daycd861282006-12-13 00:34:52 -08002211 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002212 if (!journal) {
2213 mlog(ML_ERROR, "unable to alloc journal\n");
2214 status = -ENOMEM;
2215 goto bail;
2216 }
2217 osb->journal = journal;
2218 journal->j_osb = osb;
2219
2220 atomic_set(&journal->j_num_trans, 0);
2221 init_rwsem(&journal->j_trans_barrier);
2222 init_waitqueue_head(&journal->j_checkpointed);
2223 spin_lock_init(&journal->j_lock);
2224 journal->j_trans_id = (unsigned long) 1;
2225 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002226 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002227 journal->j_state = OCFS2_JOURNAL_FREE;
2228
Jan Karaea455f82009-01-12 23:20:31 +01002229 INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
2230 osb->dentry_lock_list = NULL;
2231
Mark Fashehccd979b2005-12-15 14:31:24 -08002232 /* get some pseudo constants for clustersize bits */
2233 osb->s_clustersize_bits =
2234 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2235 osb->s_clustersize = 1 << osb->s_clustersize_bits;
2236 mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
2237
2238 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2239 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2240 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2241 osb->s_clustersize);
2242 status = -EINVAL;
2243 goto bail;
2244 }
2245
2246 if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
2247 > (u32)~0UL) {
2248 mlog(ML_ERROR, "Volume might try to write to blocks beyond "
2249 "what jbd can address in 32 bits.\n");
2250 status = -EINVAL;
2251 goto bail;
2252 }
2253
2254 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2255 sizeof(di->id2.i_super.s_uuid))) {
2256 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2257 status = -ENOMEM;
2258 goto bail;
2259 }
2260
Mark Fasheh78427042006-05-04 12:03:26 -07002261 memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
Mark Fashehccd979b2005-12-15 14:31:24 -08002262
2263 strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
2264 osb->vol_label[63] = '\0';
2265 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2266 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2267 osb->first_cluster_group_blkno =
2268 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2269 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002270 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Mark Fashehccd979b2005-12-15 14:31:24 -08002271 mlog(0, "vol_label: %s\n", osb->vol_label);
2272 mlog(0, "uuid: %s\n", osb->uuid_str);
Mark Fashehb06970532006-03-03 10:24:33 -08002273 mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
2274 (unsigned long long)osb->root_blkno,
2275 (unsigned long long)osb->system_dir_blkno);
Mark Fashehccd979b2005-12-15 14:31:24 -08002276
2277 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2278 if (!osb->osb_dlm_debug) {
2279 status = -ENOMEM;
2280 mlog_errno(status);
2281 goto bail;
2282 }
2283
2284 atomic_set(&osb->vol_state, VOLUME_INIT);
2285
2286 /* load root, system_dir, and all global system inodes */
2287 status = ocfs2_init_global_system_inodes(osb);
2288 if (status < 0) {
2289 mlog_errno(status);
2290 goto bail;
2291 }
2292
2293 /*
2294 * global bitmap
2295 */
2296 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2297 OCFS2_INVALID_SLOT);
2298 if (!inode) {
2299 status = -EINVAL;
2300 mlog_errno(status);
2301 goto bail;
2302 }
2303
2304 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fasheh6b820212010-04-05 18:17:14 -07002305 osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
Mark Fashehccd979b2005-12-15 14:31:24 -08002306 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002307
Tao Ma85718822010-04-13 14:38:06 +08002308 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
2309 osb->s_feature_incompat) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002310
2311 status = ocfs2_init_slot_info(osb);
2312 if (status < 0) {
2313 mlog_errno(status);
2314 goto bail;
2315 }
2316
Mark Fashehccd979b2005-12-15 14:31:24 -08002317bail:
2318 mlog_exit(status);
2319 return status;
2320}
2321
2322/*
2323 * will return: -EAGAIN if it is ok to keep searching for superblocks
2324 * -EINVAL if there is a bad superblock
2325 * 0 on success
2326 */
2327static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2328 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002329 u32 blksz,
2330 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002331{
2332 int status = -EAGAIN;
2333
2334 mlog_entry_void();
2335
2336 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2337 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002338 /* We have to do a raw check of the feature here */
2339 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2340 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2341 status = ocfs2_block_check_validate(bh->b_data,
2342 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002343 &di->i_check,
2344 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002345 if (status)
2346 goto out;
2347 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002348 status = -EINVAL;
2349 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2350 mlog(ML_ERROR, "found superblock with incorrect block "
2351 "size: found %u, should be %u\n",
2352 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2353 blksz);
2354 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2355 OCFS2_MAJOR_REV_LEVEL ||
2356 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2357 OCFS2_MINOR_REV_LEVEL) {
2358 mlog(ML_ERROR, "found superblock with bad version: "
2359 "found %u.%u, should be %u.%u\n",
2360 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2361 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2362 OCFS2_MAJOR_REV_LEVEL,
2363 OCFS2_MINOR_REV_LEVEL);
2364 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2365 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb06970532006-03-03 10:24:33 -08002366 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002367 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb06970532006-03-03 10:24:33 -08002368 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002369 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2370 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2371 mlog(ML_ERROR, "bad cluster size found: %u\n",
2372 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2373 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2374 mlog(ML_ERROR, "bad root_blkno: 0\n");
2375 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2376 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2377 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2378 mlog(ML_ERROR,
2379 "Superblock slots found greater than file system "
2380 "maximum: found %u, max %u\n",
2381 le16_to_cpu(di->id2.i_super.s_max_slots),
2382 OCFS2_MAX_SLOTS);
2383 } else {
2384 /* found it! */
2385 status = 0;
2386 }
2387 }
2388
Joel Beckerd030cc92008-12-11 15:04:14 -08002389out:
Mark Fashehccd979b2005-12-15 14:31:24 -08002390 mlog_exit(status);
2391 return status;
2392}
2393
2394static int ocfs2_check_volume(struct ocfs2_super *osb)
2395{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002396 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002397 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002398 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002399 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2400 * recover
2401 * ourselves. */
2402
2403 mlog_entry_void();
2404
2405 /* Init our journal object. */
2406 status = ocfs2_journal_init(osb->journal, &dirty);
2407 if (status < 0) {
2408 mlog(ML_ERROR, "Could not initialize journal!\n");
2409 goto finally;
2410 }
2411
2412 /* If the journal was unmounted cleanly then we don't want to
2413 * recover anything. Otherwise, journal_load will do that
2414 * dirty work for us :) */
2415 if (!dirty) {
2416 status = ocfs2_journal_wipe(osb->journal, 0);
2417 if (status < 0) {
2418 mlog_errno(status);
2419 goto finally;
2420 }
2421 } else {
2422 mlog(ML_NOTICE, "File system was not unmounted cleanly, "
2423 "recovering volume.\n");
2424 }
2425
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002426 local = ocfs2_mount_local(osb);
2427
Mark Fashehccd979b2005-12-15 14:31:24 -08002428 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002429 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002430 if (status < 0) {
2431 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2432 goto finally;
2433 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002434
2435 if (dirty) {
2436 /* recover my local alloc if we didn't unmount cleanly. */
2437 status = ocfs2_begin_local_alloc_recovery(osb,
2438 osb->slot_num,
2439 &local_alloc);
2440 if (status < 0) {
2441 mlog_errno(status);
2442 goto finally;
2443 }
2444 /* we complete the recovery process after we've marked
2445 * ourselves as mounted. */
2446 }
2447
2448 mlog(0, "Journal loaded.\n");
2449
2450 status = ocfs2_load_local_alloc(osb);
2451 if (status < 0) {
2452 mlog_errno(status);
2453 goto finally;
2454 }
2455
2456 if (dirty) {
2457 /* Recovery will be completed after we've mounted the
2458 * rest of the volume. */
2459 osb->dirty = 1;
2460 osb->local_alloc_copy = local_alloc;
2461 local_alloc = NULL;
2462 }
2463
2464 /* go through each journal, trylock it and if you get the
2465 * lock, and it's marked as dirty, set the bit in the recover
2466 * map and launch a recovery thread for it. */
2467 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002468 if (status < 0) {
2469 mlog_errno(status);
2470 goto finally;
2471 }
2472
2473 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002474 if (status < 0)
2475 mlog_errno(status);
2476
2477finally:
2478 if (local_alloc)
2479 kfree(local_alloc);
2480
2481 mlog_exit(status);
2482 return status;
2483}
2484
2485/*
2486 * The routine gets called from dismount or close whenever a dismount on
2487 * volume is requested and the osb open count becomes 1.
2488 * It will remove the osb from the global list and also free up all the
2489 * initialized resources and fileobject.
2490 */
2491static void ocfs2_delete_osb(struct ocfs2_super *osb)
2492{
2493 mlog_entry_void();
2494
2495 /* This function assumes that the caller has the main osb resource */
2496
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002497 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002498
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002499 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002500 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002501 /* FIXME
2502 * This belongs in journal shutdown, but because we have to
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02002503 * allocate osb->journal at the start of ocfs2_initialize_osb(),
Mark Fashehccd979b2005-12-15 14:31:24 -08002504 * we free it here.
2505 */
2506 kfree(osb->journal);
2507 if (osb->local_alloc_copy)
2508 kfree(osb->local_alloc_copy);
2509 kfree(osb->uuid_str);
2510 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2511 memset(osb, 0, sizeof(struct ocfs2_super));
2512
2513 mlog_exit_void();
2514}
2515
2516/* Put OCFS2 into a readonly state, or (if the user specifies it),
2517 * panic(). We do not support continue-on-error operation. */
2518static void ocfs2_handle_error(struct super_block *sb)
2519{
2520 struct ocfs2_super *osb = OCFS2_SB(sb);
2521
2522 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
2523 panic("OCFS2: (device %s): panic forced after error\n",
2524 sb->s_id);
2525
2526 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
2527
2528 if (sb->s_flags & MS_RDONLY &&
2529 (ocfs2_is_soft_readonly(osb) ||
2530 ocfs2_is_hard_readonly(osb)))
2531 return;
2532
2533 printk(KERN_CRIT "File system is now read-only due to the potential "
2534 "of on-disk corruption. Please run fsck.ocfs2 once the file "
2535 "system is unmounted.\n");
2536 sb->s_flags |= MS_RDONLY;
2537 ocfs2_set_ro_flag(osb, 0);
2538}
2539
2540static char error_buf[1024];
2541
2542void __ocfs2_error(struct super_block *sb,
2543 const char *function,
2544 const char *fmt, ...)
2545{
2546 va_list args;
2547
2548 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002549 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002550 va_end(args);
2551
2552 /* Not using mlog here because we want to show the actual
2553 * function the error came from. */
2554 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
2555 sb->s_id, function, error_buf);
2556
2557 ocfs2_handle_error(sb);
2558}
2559
2560/* Handle critical errors. This is intentionally more drastic than
2561 * ocfs2_handle_error, so we only use for things like journal errors,
2562 * etc. */
2563void __ocfs2_abort(struct super_block* sb,
2564 const char *function,
2565 const char *fmt, ...)
2566{
2567 va_list args;
2568
2569 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08002570 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002571 va_end(args);
2572
2573 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
2574 sb->s_id, function, error_buf);
2575
2576 /* We don't have the cluster support yet to go straight to
2577 * hard readonly in here. Until then, we want to keep
2578 * ocfs2_abort() so that we can at least mark critical
2579 * errors.
2580 *
2581 * TODO: This should abort the journal and alert other nodes
2582 * that our slot needs recovery. */
2583
2584 /* Force a panic(). This stinks, but it's better than letting
2585 * things continue without having a proper hard readonly
2586 * here. */
Sunil Mushrana2f2ddb2009-08-19 15:16:01 -07002587 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2588 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08002589 ocfs2_handle_error(sb);
2590}
2591
Joel Beckere4b963f2009-09-02 17:17:36 -07002592/*
2593 * Void signal blockers, because in-kernel sigprocmask() only fails
2594 * when SIG_* is wrong.
2595 */
2596void ocfs2_block_signals(sigset_t *oldset)
2597{
2598 int rc;
2599 sigset_t blocked;
2600
2601 sigfillset(&blocked);
2602 rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
2603 BUG_ON(rc);
2604}
2605
2606void ocfs2_unblock_signals(sigset_t *oldset)
2607{
2608 int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
2609 BUG_ON(rc);
2610}
2611
Mark Fashehccd979b2005-12-15 14:31:24 -08002612module_init(ocfs2_init);
2613module_exit(ocfs2_exit);