Blame view

fs/ocfs2/super.c 69.2 KB
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  /* -*- mode: c; c-basic-offset: 8; -*-
   * vim: noexpandtab sw=8 ts=8 sts=0:
   *
   * super.c
   *
   * load/unload driver, mount/dismount volumes
   *
   * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public
   * License as published by the Free Software Foundation; either
   * version 2 of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * General Public License for more details.
   *
   * You should have received a copy of the GNU General Public
   * License along with this program; if not, write to the
   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA 021110-1307, USA.
   */
  
  #include <linux/module.h>
  #include <linux/fs.h>
  #include <linux/types.h>
  #include <linux/slab.h>
  #include <linux/highmem.h>
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
31
32
33
34
35
36
37
38
39
40
  #include <linux/init.h>
  #include <linux/random.h>
  #include <linux/statfs.h>
  #include <linux/moduleparam.h>
  #include <linux/blkdev.h>
  #include <linux/socket.h>
  #include <linux/inet.h>
  #include <linux/parser.h>
  #include <linux/crc32.h>
  #include <linux/debugfs.h>
d550071c0   Sunil Mushran   ocfs2: Implement ...
41
  #include <linux/mount.h>
6953b4c00   Joel Becker   ocfs2: Move o2hb ...
42
  #include <linux/seq_file.h>
19ece546a   Jan Kara   ocfs2: Enable quo...
43
  #include <linux/quotaops.h>
1cfd8bd0f   Dan Magenheimer   ocfs2: add cleanc...
44
  #include <linux/cleancache.h>
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
45

80a9a84da   Wengang Wang   ocfs2: Add ocfs2_...
46
47
  #define CREATE_TRACE_POINTS
  #include "ocfs2_trace.h"
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
48
49
50
51
52
53
54
55
  #include <cluster/masklog.h>
  
  #include "ocfs2.h"
  
  /* this should be the only file to include a version 1 header */
  #include "ocfs1_fs_compat.h"
  
  #include "alloc.h"
a11f7e63c   Mark Fasheh   ocfs2: serialize ...
56
  #include "aops.h"
d030cc978   Joel Becker   ocfs2: Validate s...
57
  #include "blockcheck.h"
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
58
59
60
61
62
63
64
65
66
67
68
69
70
  #include "dlmglue.h"
  #include "export.h"
  #include "extent_map.h"
  #include "heartbeat.h"
  #include "inode.h"
  #include "journal.h"
  #include "localalloc.h"
  #include "namei.h"
  #include "slot_map.h"
  #include "super.h"
  #include "sysfile.h"
  #include "uptodate.h"
  #include "ver.h"
cf1d6c763   Tiger Yang   ocfs2: Add extend...
71
  #include "xattr.h"
9e33d69f5   Jan Kara   ocfs2: Implementa...
72
  #include "quota.h"
374a263e7   Tao Ma   ocfs2: Add refcou...
73
  #include "refcounttree.h"
b89c54282   Tiger Yang   ocfs2: add extent...
74
  #include "suballoc.h"
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
75
76
  
  #include "buffer_head_io.h"
e18b890bb   Christoph Lameter   [PATCH] slab: rem...
77
  static struct kmem_cache *ocfs2_inode_cachep = NULL;
9e33d69f5   Jan Kara   ocfs2: Implementa...
78
79
  struct kmem_cache *ocfs2_dquot_cachep;
  struct kmem_cache *ocfs2_qf_chunk_cachep;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
80

25985edce   Lucas De Marchi   Fix common misspe...
81
  /* OCFS2 needs to schedule several different types of work which
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
82
83
84
85
86
87
88
89
90
   * require cluster locking, disk I/O, recovery waits, etc. Since these
   * types of work tend to be heavy we avoid using the kernel events
   * workqueue and schedule on our own. */
  struct workqueue_struct *ocfs2_wq = NULL;
  
  static struct dentry *ocfs2_debugfs_root = NULL;
  
  MODULE_AUTHOR("Oracle");
  MODULE_LICENSE("GPL");
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
91
92
  struct mount_options
  {
d147b3d63   Mark Fasheh   ocfs2: Support co...
93
  	unsigned long	commit_interval;
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
94
95
96
  	unsigned long	mount_opt;
  	unsigned int	atime_quantum;
  	signed short	slot;
73c8a8000   Mark Fasheh   ocfs2: clean up l...
97
  	int		localalloc_opt;
d02f00cc0   Mark Fasheh   ocfs2: allocation...
98
  	unsigned int	resv_level;
83f92318f   Mark Fasheh   ocfs2: Add dir_re...
99
  	int		dir_resv_level;
b61817e11   Joel Becker   ocfs2: Add the US...
100
  	char		cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
101
  };
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
102
  static int ocfs2_parse_options(struct super_block *sb, char *options,
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
103
  			       struct mount_options *mopt,
baf4661a8   Sunil Mushran   ocfs2: Add "prefe...
104
  			       int is_remount);
5297aad80   Jan Kara   ocfs2: Make acl u...
105
106
  static int ocfs2_check_set_options(struct super_block *sb,
  				   struct mount_options *options);
d550071c0   Sunil Mushran   ocfs2: Implement ...
107
  static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
108
109
110
111
112
113
114
  static void ocfs2_put_super(struct super_block *sb);
  static int ocfs2_mount_volume(struct super_block *sb);
  static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
  static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
  static int ocfs2_initialize_mem_caches(void);
  static void ocfs2_free_mem_caches(void);
  static void ocfs2_delete_osb(struct ocfs2_super *osb);
726c33422   David Howells   [PATCH] VFS: Perm...
115
  static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
116
117
118
119
120
  
  static int ocfs2_sync_fs(struct super_block *sb, int wait);
  
  static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
  static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
bddb8eb37   Denis Cheng   [PATCH] fs/ocfs2/...
121
  static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
122
123
124
  static int ocfs2_check_volume(struct ocfs2_super *osb);
  static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  			       struct buffer_head *bh,
73be192b1   Joel Becker   ocfs2: Add statis...
125
126
  			       u32 sectsize,
  			       struct ocfs2_blockcheck_stats *stats);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
127
128
  static int ocfs2_initialize_super(struct super_block *sb,
  				  struct buffer_head *bh,
73be192b1   Joel Becker   ocfs2: Add statis...
129
130
  				  int sector_size,
  				  struct ocfs2_blockcheck_stats *stats);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
131
132
133
134
  static int ocfs2_get_sector(struct super_block *sb,
  			    struct buffer_head **bh,
  			    int block,
  			    int sect_size);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
135
136
  static struct inode *ocfs2_alloc_inode(struct super_block *sb);
  static void ocfs2_destroy_inode(struct inode *inode);
19ece546a   Jan Kara   ocfs2: Enable quo...
137
138
139
  static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
  static int ocfs2_enable_quotas(struct ocfs2_super *osb);
  static void ocfs2_disable_quotas(struct ocfs2_super *osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
140

ee9b6d61a   Josef 'Jeff' Sipek   [PATCH] Mark stru...
141
  static const struct super_operations ocfs2_sops = {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
142
143
144
145
  	.statfs		= ocfs2_statfs,
  	.alloc_inode	= ocfs2_alloc_inode,
  	.destroy_inode	= ocfs2_destroy_inode,
  	.drop_inode	= ocfs2_drop_inode,
066d92dcb   Al Viro   convert ocfs2 to ...
146
  	.evict_inode	= ocfs2_evict_inode,
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
147
  	.sync_fs	= ocfs2_sync_fs,
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
148
149
  	.put_super	= ocfs2_put_super,
  	.remount_fs	= ocfs2_remount,
d550071c0   Sunil Mushran   ocfs2: Implement ...
150
  	.show_options   = ocfs2_show_options,
9e33d69f5   Jan Kara   ocfs2: Implementa...
151
152
  	.quota_read	= ocfs2_quota_read,
  	.quota_write	= ocfs2_quota_write,
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
153
154
155
156
157
158
159
160
161
162
  };
  
  enum {
  	Opt_barrier,
  	Opt_err_panic,
  	Opt_err_ro,
  	Opt_intr,
  	Opt_nointr,
  	Opt_hb_none,
  	Opt_hb_local,
2c442719e   Sunil Mushran   (2c442719e90a44a6...
163
  	Opt_hb_global,
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
164
165
  	Opt_data_ordered,
  	Opt_data_writeback,
7f1a37e31   Tiger Yang   ocfs2: core atime...
166
  	Opt_atime_quantum,
baf4661a8   Sunil Mushran   ocfs2: Add "prefe...
167
  	Opt_slot,
d147b3d63   Mark Fasheh   ocfs2: Support co...
168
  	Opt_commit,
2fbe8d1eb   Sunil Mushran   ocfs2: Local allo...
169
  	Opt_localalloc,
53fc622b9   Mark Fasheh   [PATCH 2/2] ocfs2...
170
  	Opt_localflocks,
b61817e11   Joel Becker   ocfs2: Add the US...
171
  	Opt_stack,
cf1d6c763   Tiger Yang   ocfs2: Add extend...
172
173
  	Opt_user_xattr,
  	Opt_nouser_xattr,
12462f1d9   Joel Becker   ocfs2: Add the 'i...
174
  	Opt_inode64,
a68979b85   Tiger Yang   ocfs2: add mount ...
175
176
  	Opt_acl,
  	Opt_noacl,
19ece546a   Jan Kara   ocfs2: Enable quo...
177
178
  	Opt_usrquota,
  	Opt_grpquota,
7bdb0d18b   Tristan Ye   ocfs2: Add a moun...
179
180
  	Opt_coherency_buffered,
  	Opt_coherency_full,
d02f00cc0   Mark Fasheh   ocfs2: allocation...
181
  	Opt_resv_level,
83f92318f   Mark Fasheh   ocfs2: Add dir_re...
182
  	Opt_dir_resv_level,
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
183
184
  	Opt_err,
  };
a447c0932   Steven Whitehouse   vfs: Use const fo...
185
  static const match_table_t tokens = {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
186
187
188
189
190
191
192
  	{Opt_barrier, "barrier=%u"},
  	{Opt_err_panic, "errors=panic"},
  	{Opt_err_ro, "errors=remount-ro"},
  	{Opt_intr, "intr"},
  	{Opt_nointr, "nointr"},
  	{Opt_hb_none, OCFS2_HB_NONE},
  	{Opt_hb_local, OCFS2_HB_LOCAL},
2c442719e   Sunil Mushran   (2c442719e90a44a6...
193
  	{Opt_hb_global, OCFS2_HB_GLOBAL},
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
194
195
  	{Opt_data_ordered, "data=ordered"},
  	{Opt_data_writeback, "data=writeback"},
7f1a37e31   Tiger Yang   ocfs2: core atime...
196
  	{Opt_atime_quantum, "atime_quantum=%u"},
baf4661a8   Sunil Mushran   ocfs2: Add "prefe...
197
  	{Opt_slot, "preferred_slot=%u"},
d147b3d63   Mark Fasheh   ocfs2: Support co...
198
  	{Opt_commit, "commit=%u"},
2fbe8d1eb   Sunil Mushran   ocfs2: Local allo...
199
  	{Opt_localalloc, "localalloc=%d"},
53fc622b9   Mark Fasheh   [PATCH 2/2] ocfs2...
200
  	{Opt_localflocks, "localflocks"},
b61817e11   Joel Becker   ocfs2: Add the US...
201
  	{Opt_stack, "cluster_stack=%s"},
cf1d6c763   Tiger Yang   ocfs2: Add extend...
202
203
  	{Opt_user_xattr, "user_xattr"},
  	{Opt_nouser_xattr, "nouser_xattr"},
12462f1d9   Joel Becker   ocfs2: Add the 'i...
204
  	{Opt_inode64, "inode64"},
a68979b85   Tiger Yang   ocfs2: add mount ...
205
206
  	{Opt_acl, "acl"},
  	{Opt_noacl, "noacl"},
19ece546a   Jan Kara   ocfs2: Enable quo...
207
208
  	{Opt_usrquota, "usrquota"},
  	{Opt_grpquota, "grpquota"},
7bdb0d18b   Tristan Ye   ocfs2: Add a moun...
209
210
  	{Opt_coherency_buffered, "coherency=buffered"},
  	{Opt_coherency_full, "coherency=full"},
d02f00cc0   Mark Fasheh   ocfs2: allocation...
211
  	{Opt_resv_level, "resv_level=%u"},
83f92318f   Mark Fasheh   ocfs2: Add dir_re...
212
  	{Opt_dir_resv_level, "dir_resv_level=%u"},
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
213
214
  	{Opt_err, NULL}
  };
50397507e   Sunil Mushran   ocfs2: Expose the...
215
216
217
  #ifdef CONFIG_DEBUG_FS
  static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
  {
50397507e   Sunil Mushran   ocfs2: Expose the...
218
219
  	struct ocfs2_cluster_connection *cconn = osb->cconn;
  	struct ocfs2_recovery_map *rm = osb->recovery_map;
df152c241   Sunil Mushran   ocfs2: Disable or...
220
221
  	struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
  	int i, out = 0;
50397507e   Sunil Mushran   ocfs2: Expose the...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
  
  	out += snprintf(buf + out, len - out,
  			"%10s => Id: %-s  Uuid: %-s  Gen: 0x%X  Label: %-s
  ",
  			"Device", osb->dev_str, osb->uuid_str,
  			osb->fs_generation, osb->vol_label);
  
  	out += snprintf(buf + out, len - out,
  			"%10s => State: %d  Flags: 0x%lX
  ", "Volume",
  			atomic_read(&osb->vol_state), osb->osb_flags);
  
  	out += snprintf(buf + out, len - out,
  			"%10s => Block: %lu  Cluster: %d
  ", "Sizes",
  			osb->sb->s_blocksize, osb->s_clustersize);
  
  	out += snprintf(buf + out, len - out,
  			"%10s => Compat: 0x%X  Incompat: 0x%X  "
  			"ROcompat: 0x%X
  ",
  			"Features", osb->s_feature_compat,
  			osb->s_feature_incompat, osb->s_feature_ro_compat);
  
  	out += snprintf(buf + out, len - out,
  			"%10s => Opts: 0x%lX  AtimeQuanta: %u
  ", "Mount",
  			osb->s_mount_opt, osb->s_atime_quantum);
c3d38840a   Sunil Mushran   ocfs2: Fix ocfs2_...
250
251
252
253
254
255
256
257
258
259
260
  	if (cconn) {
  		out += snprintf(buf + out, len - out,
  				"%10s => Stack: %s  Name: %*s  "
  				"Version: %d.%d
  ", "Cluster",
  				(*osb->osb_cluster_stack == '\0' ?
  				 "o2cb" : osb->osb_cluster_stack),
  				cconn->cc_namelen, cconn->cc_name,
  				cconn->cc_version.pv_major,
  				cconn->cc_version.pv_minor);
  	}
50397507e   Sunil Mushran   ocfs2: Expose the...
261
262
263
264
265
266
  
  	spin_lock(&osb->dc_task_lock);
  	out += snprintf(buf + out, len - out,
  			"%10s => Pid: %d  Count: %lu  WakeSeq: %lu  "
  			"WorkSeq: %lu
  ", "DownCnvt",
c3d38840a   Sunil Mushran   ocfs2: Fix ocfs2_...
267
268
269
  			(osb->dc_task ?  task_pid_nr(osb->dc_task) : -1),
  			osb->blocked_lock_count, osb->dc_wake_sequence,
  			osb->dc_work_sequence);
50397507e   Sunil Mushran   ocfs2: Expose the...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
  	spin_unlock(&osb->dc_task_lock);
  
  	spin_lock(&osb->osb_lock);
  	out += snprintf(buf + out, len - out, "%10s => Pid: %d  Nodes:",
  			"Recovery",
  			(osb->recovery_thread_task ?
  			 task_pid_nr(osb->recovery_thread_task) : -1));
  	if (rm->rm_used == 0)
  		out += snprintf(buf + out, len - out, " None
  ");
  	else {
  		for (i = 0; i < rm->rm_used; i++)
  			out += snprintf(buf + out, len - out, " %d",
  					rm->rm_entries[i]);
  		out += snprintf(buf + out, len - out, "
  ");
  	}
  	spin_unlock(&osb->osb_lock);
  
  	out += snprintf(buf + out, len - out,
  			"%10s => Pid: %d  Interval: %lu  Needs: %d
  ", "Commit",
c3d38840a   Sunil Mushran   ocfs2: Fix ocfs2_...
292
293
  			(osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
  			osb->osb_commit_interval,
50397507e   Sunil Mushran   ocfs2: Expose the...
294
295
296
  			atomic_read(&osb->needs_checkpoint));
  
  	out += snprintf(buf + out, len - out,
c3d38840a   Sunil Mushran   ocfs2: Fix ocfs2_...
297
298
  			"%10s => State: %d  TxnId: %lu  NumTxns: %d
  ",
50397507e   Sunil Mushran   ocfs2: Expose the...
299
  			"Journal", osb->journal->j_state,
c3d38840a   Sunil Mushran   ocfs2: Fix ocfs2_...
300
301
  			osb->journal->j_trans_id,
  			atomic_read(&osb->journal->j_num_trans));
50397507e   Sunil Mushran   ocfs2: Expose the...
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
  
  	out += snprintf(buf + out, len - out,
  			"%10s => GlobalAllocs: %d  LocalAllocs: %d  "
  			"SubAllocs: %d  LAWinMoves: %d  SAExtends: %d
  ",
  			"Stats",
  			atomic_read(&osb->alloc_stats.bitmap_data),
  			atomic_read(&osb->alloc_stats.local_data),
  			atomic_read(&osb->alloc_stats.bg_allocs),
  			atomic_read(&osb->alloc_stats.moves),
  			atomic_read(&osb->alloc_stats.bg_extends));
  
  	out += snprintf(buf + out, len - out,
  			"%10s => State: %u  Descriptor: %llu  Size: %u bits  "
  			"Default: %u bits
  ",
  			"LocalAlloc", osb->local_alloc_state,
  			(unsigned long long)osb->la_last_gd,
  			osb->local_alloc_bits, osb->local_alloc_default_bits);
  
  	spin_lock(&osb->osb_lock);
  	out += snprintf(buf + out, len - out,
b89c54282   Tiger Yang   ocfs2: add extent...
324
325
326
  			"%10s => InodeSlot: %d  StolenInodes: %d, "
  			"MetaSlot: %d  StolenMeta: %d
  ", "Steal",
50397507e   Sunil Mushran   ocfs2: Expose the...
327
  			osb->s_inode_steal_slot,
b89c54282   Tiger Yang   ocfs2: add extent...
328
329
330
  			atomic_read(&osb->s_num_inodes_stolen),
  			osb->s_meta_steal_slot,
  			atomic_read(&osb->s_num_meta_stolen));
50397507e   Sunil Mushran   ocfs2: Expose the...
331
  	spin_unlock(&osb->osb_lock);
df152c241   Sunil Mushran   ocfs2: Disable or...
332
333
334
335
336
337
338
339
340
341
342
  	out += snprintf(buf + out, len - out, "OrphanScan => ");
  	out += snprintf(buf + out, len - out, "Local: %u  Global: %u ",
  			os->os_count, os->os_seqno);
  	out += snprintf(buf + out, len - out, " Last Scan: ");
  	if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
  		out += snprintf(buf + out, len - out, "Disabled
  ");
  	else
  		out += snprintf(buf + out, len - out, "%lu seconds ago
  ",
  				(get_seconds() - os->os_scantime.tv_sec));
50397507e   Sunil Mushran   ocfs2: Expose the...
343
344
345
  	out += snprintf(buf + out, len - out, "%10s => %3s  %10s
  ",
  			"Slots", "Num", "RecoGen");
50397507e   Sunil Mushran   ocfs2: Expose the...
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
  	for (i = 0; i < osb->max_slots; ++i) {
  		out += snprintf(buf + out, len - out,
  				"%10s  %c %3d  %10d
  ",
  				" ",
  				(i == osb->slot_num ? '*' : ' '),
  				i, osb->slot_recovery_generations[i]);
  	}
  
  	return out;
  }
  
  static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  {
  	struct ocfs2_super *osb = inode->i_private;
  	char *buf = NULL;
  
  	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  	if (!buf)
  		goto bail;
  
  	i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
  
  	file->private_data = buf;
  
  	return 0;
  bail:
  	return -ENOMEM;
  }
  
  static int ocfs2_debug_release(struct inode *inode, struct file *file)
  {
  	kfree(file->private_data);
  	return 0;
  }
  
  static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  				size_t nbytes, loff_t *ppos)
  {
  	return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
  				       i_size_read(file->f_mapping->host));
  }
  #else
  static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  {
  	return 0;
  }
  static int ocfs2_debug_release(struct inode *inode, struct file *file)
  {
  	return 0;
  }
  static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  				size_t nbytes, loff_t *ppos)
  {
  	return 0;
  }
  #endif	/* CONFIG_DEBUG_FS */
828c09509   Alexey Dobriyan   const: constify r...
403
  static const struct file_operations ocfs2_osb_debug_fops = {
50397507e   Sunil Mushran   ocfs2: Expose the...
404
405
406
407
408
  	.open =		ocfs2_osb_debug_open,
  	.release =	ocfs2_debug_release,
  	.read =		ocfs2_debug_read,
  	.llseek =	generic_file_llseek,
  };
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
409
410
  static int ocfs2_sync_fs(struct super_block *sb, int wait)
  {
bddb8eb37   Denis Cheng   [PATCH] fs/ocfs2/...
411
  	int status;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
412
413
  	tid_t target;
  	struct ocfs2_super *osb = OCFS2_SB(sb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
414
415
416
417
418
419
420
421
422
423
  	if (ocfs2_is_hard_readonly(osb))
  		return -EROFS;
  
  	if (wait) {
  		status = ocfs2_flush_truncate_log(osb);
  		if (status < 0)
  			mlog_errno(status);
  	} else {
  		ocfs2_schedule_truncate_log_flush(osb, 0);
  	}
2b4e30fbd   Joel Becker   ocfs2: Switch ove...
424
425
  	if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
  				      &target)) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
426
  		if (wait)
2b4e30fbd   Joel Becker   ocfs2: Switch ove...
427
428
  			jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
  					     target);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
429
430
431
  	}
  	return 0;
  }
1a224ad11   Jan Kara   ocfs2: Assign fea...
432
433
434
435
436
437
438
439
440
441
442
443
  static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
  {
  	if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
  	    && (ino == USER_QUOTA_SYSTEM_INODE
  		|| ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
  		return 0;
  	if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  	    && (ino == GROUP_QUOTA_SYSTEM_INODE
  		|| ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
  		return 0;
  	return 1;
  }
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
444
445
446
447
448
  static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
  {
  	struct inode *new = NULL;
  	int status = 0;
  	int i;
5fa0613ea   Jan Kara   ocfs2: Silence fa...
449
  	new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
450
451
452
453
454
455
  	if (IS_ERR(new)) {
  		status = PTR_ERR(new);
  		mlog_errno(status);
  		goto bail;
  	}
  	osb->root_inode = new;
5fa0613ea   Jan Kara   ocfs2: Silence fa...
456
  	new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
457
458
459
460
461
462
463
464
465
  	if (IS_ERR(new)) {
  		status = PTR_ERR(new);
  		mlog_errno(status);
  		goto bail;
  	}
  	osb->sys_root_inode = new;
  
  	for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
  	     i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
1a224ad11   Jan Kara   ocfs2: Assign fea...
466
467
  		if (!ocfs2_need_system_inode(osb, i))
  			continue;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
  		new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  		if (!new) {
  			ocfs2_release_system_inodes(osb);
  			status = -EINVAL;
  			mlog_errno(status);
  			/* FIXME: Should ERROR_RO_FS */
  			mlog(ML_ERROR, "Unable to load system inode %d, "
  			     "possibly corrupt fs?", i);
  			goto bail;
  		}
  		// the array now has one ref, so drop this one
  		iput(new);
  	}
  
  bail:
c1e8d35ef   Tao Ma   ocfs2: Remove EXI...
483
484
  	if (status)
  		mlog_errno(status);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
485
486
487
488
489
490
491
492
  	return status;
  }
  
  static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
  {
  	struct inode *new = NULL;
  	int status = 0;
  	int i;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
493
494
495
  	for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
  	     i < NUM_SYSTEM_INODES;
  	     i++) {
1a224ad11   Jan Kara   ocfs2: Assign fea...
496
497
  		if (!ocfs2_need_system_inode(osb, i))
  			continue;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
498
499
500
501
502
503
504
505
506
507
508
509
510
511
  		new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  		if (!new) {
  			ocfs2_release_system_inodes(osb);
  			status = -EINVAL;
  			mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d
  ",
  			     status, i, osb->slot_num);
  			goto bail;
  		}
  		/* the array now has one ref, so drop this one */
  		iput(new);
  	}
  
  bail:
c1e8d35ef   Tao Ma   ocfs2: Remove EXI...
512
513
  	if (status)
  		mlog_errno(status);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
514
515
  	return status;
  }
bddb8eb37   Denis Cheng   [PATCH] fs/ocfs2/...
516
  static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
517
  {
bddb8eb37   Denis Cheng   [PATCH] fs/ocfs2/...
518
  	int i;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
519
  	struct inode *inode;
b4d693fcc   Tao Ma   ocfs2: Cache syst...
520
521
  	for (i = 0; i < NUM_GLOBAL_SYSTEM_INODES; i++) {
  		inode = osb->global_system_inodes[i];
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
522
523
  		if (inode) {
  			iput(inode);
b4d693fcc   Tao Ma   ocfs2: Cache syst...
524
  			osb->global_system_inodes[i] = NULL;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
525
526
527
528
529
530
531
532
533
534
535
536
537
538
  		}
  	}
  
  	inode = osb->sys_root_inode;
  	if (inode) {
  		iput(inode);
  		osb->sys_root_inode = NULL;
  	}
  
  	inode = osb->root_inode;
  	if (inode) {
  		iput(inode);
  		osb->root_inode = NULL;
  	}
b4d693fcc   Tao Ma   ocfs2: Cache syst...
539
  	if (!osb->local_system_inodes)
c1e8d35ef   Tao Ma   ocfs2: Remove EXI...
540
  		return;
b4d693fcc   Tao Ma   ocfs2: Cache syst...
541
542
543
544
545
546
547
548
549
550
  
  	for (i = 0; i < NUM_LOCAL_SYSTEM_INODES * osb->max_slots; i++) {
  		if (osb->local_system_inodes[i]) {
  			iput(osb->local_system_inodes[i]);
  			osb->local_system_inodes[i] = NULL;
  		}
  	}
  
  	kfree(osb->local_system_inodes);
  	osb->local_system_inodes = NULL;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
551
552
553
554
555
556
  }
  
  /* We're allocating fs objects, use GFP_NOFS */
  static struct inode *ocfs2_alloc_inode(struct super_block *sb)
  {
  	struct ocfs2_inode_info *oi;
e6b4f8da3   Christoph Lameter   [PATCH] slab: rem...
557
  	oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
558
559
  	if (!oi)
  		return NULL;
2b4e30fbd   Joel Becker   ocfs2: Switch ove...
560
  	jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
561
562
  	return &oi->vfs_inode;
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
563
  static void ocfs2_i_callback(struct rcu_head *head)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
564
  {
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
565
566
  	struct inode *inode = container_of(head, struct inode, i_rcu);
  	INIT_LIST_HEAD(&inode->i_dentry);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
567
568
  	kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
569
570
571
572
  static void ocfs2_destroy_inode(struct inode *inode)
  {
  	call_rcu(&inode->i_rcu, ocfs2_i_callback);
  }
5a2540317   Mark Fasheh   ocfs2: Fix max of...
573
574
  static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
  						unsigned int cbits)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
575
  {
5a2540317   Mark Fasheh   ocfs2: Fix max of...
576
577
578
579
580
581
582
583
  	unsigned int bytes = 1 << cbits;
  	unsigned int trim = bytes;
  	unsigned int bitshift = 32;
  
  	/*
  	 * i_size and all block offsets in ocfs2 are always 64 bits
  	 * wide. i_clusters is 32 bits, in cluster-sized units. So on
  	 * 64 bit platforms, cluster size will be the limiting factor.
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
584
585
586
  	 */
  
  #if BITS_PER_LONG == 32
90c699a9e   Bartlomiej Zolnierkiewicz   block: rename CON...
587
  # if defined(CONFIG_LBDAF)
2ecd05ae6   Alexey Dobriyan   [PATCH] fs/*: use...
588
  	BUILD_BUG_ON(sizeof(sector_t) != 8);
5a2540317   Mark Fasheh   ocfs2: Fix max of...
589
590
591
592
593
594
595
596
597
598
599
600
  	/*
  	 * We might be limited by page cache size.
  	 */
  	if (bytes > PAGE_CACHE_SIZE) {
  		bytes = PAGE_CACHE_SIZE;
  		trim = 1;
  		/*
  		 * Shift by 31 here so that we don't get larger than
  		 * MAX_LFS_FILESIZE
  		 */
  		bitshift = 31;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
601
  # else
5a2540317   Mark Fasheh   ocfs2: Fix max of...
602
603
604
605
606
607
608
  	/*
  	 * We are limited by the size of sector_t. Use block size, as
  	 * that's what we expose to the VFS.
  	 */
  	bytes = 1 << bbits;
  	trim = 1;
  	bitshift = 31;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
609
610
  # endif
  #endif
5a2540317   Mark Fasheh   ocfs2: Fix max of...
611
612
613
614
615
616
  	/*
  	 * Trim by a whole cluster when we can actually approach the
  	 * on-disk limits. Otherwise we can overflow i_clusters when
  	 * an extent start is at the max offset.
  	 */
  	return (((unsigned long long)bytes) << bitshift) - trim;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
617
618
619
620
621
622
  }
  
  static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
  {
  	int incompat_features;
  	int ret = 0;
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
623
  	struct mount_options parsed_options;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
624
  	struct ocfs2_super *osb = OCFS2_SB(sb);
2c442719e   Sunil Mushran   (2c442719e90a44a6...
625
  	u32 tmp;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
626

5297aad80   Jan Kara   ocfs2: Make acl u...
627
628
  	if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
  	    !ocfs2_check_set_options(sb, &parsed_options)) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
629
630
631
  		ret = -EINVAL;
  		goto out;
  	}
2c442719e   Sunil Mushran   (2c442719e90a44a6...
632
633
634
  	tmp = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL |
  		OCFS2_MOUNT_HB_NONE;
  	if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
635
636
637
638
639
640
641
  		ret = -EINVAL;
  		mlog(ML_ERROR, "Cannot change heartbeat mode on remount
  ");
  		goto out;
  	}
  
  	if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
642
  	    (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
643
644
645
646
647
  		ret = -EINVAL;
  		mlog(ML_ERROR, "Cannot change data mode on remount
  ");
  		goto out;
  	}
12462f1d9   Joel Becker   ocfs2: Add the 'i...
648
649
650
651
652
653
654
655
656
  	/* Probably don't want this on remount; it might
  	 * mess with other nodes */
  	if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
  	    (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
  		ret = -EINVAL;
  		mlog(ML_ERROR, "Cannot enable inode64 on remount
  ");
  		goto out;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
657
658
  	/* We're going to/from readonly mode. */
  	if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
19ece546a   Jan Kara   ocfs2: Enable quo...
659
660
661
662
663
664
  		/* Disable quota accounting before remounting RO */
  		if (*flags & MS_RDONLY) {
  			ret = ocfs2_susp_quotas(osb, 0);
  			if (ret < 0)
  				goto out;
  		}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
665
666
667
668
669
670
671
672
673
674
675
  		/* Lock here so the check of HARD_RO and the potential
  		 * setting of SOFT_RO is atomic. */
  		spin_lock(&osb->osb_lock);
  		if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
  			mlog(ML_ERROR, "Remount on readonly device is forbidden.
  ");
  			ret = -EROFS;
  			goto unlock_osb;
  		}
  
  		if (*flags & MS_RDONLY) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
676
677
678
  			sb->s_flags |= MS_RDONLY;
  			osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  		} else {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
  			if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
  				mlog(ML_ERROR, "Cannot remount RDWR "
  				     "filesystem due to previous errors.
  ");
  				ret = -EROFS;
  				goto unlock_osb;
  			}
  			incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
  			if (incompat_features) {
  				mlog(ML_ERROR, "Cannot remount RDWR because "
  				     "of unsupported optional features "
  				     "(%x).
  ", incompat_features);
  				ret = -EINVAL;
  				goto unlock_osb;
  			}
  			sb->s_flags &= ~MS_RDONLY;
  			osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
  		}
32a42d392   Tao Ma   ocfs2: Remove mas...
698
  		trace_ocfs2_remount(sb->s_flags, osb->osb_flags, *flags);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
699
700
  unlock_osb:
  		spin_unlock(&osb->osb_lock);
19ece546a   Jan Kara   ocfs2: Enable quo...
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
  		/* Enable quota accounting after remounting RW */
  		if (!ret && !(*flags & MS_RDONLY)) {
  			if (sb_any_quota_suspended(sb))
  				ret = ocfs2_susp_quotas(osb, 1);
  			else
  				ret = ocfs2_enable_quotas(osb);
  			if (ret < 0) {
  				/* Return back changes... */
  				spin_lock(&osb->osb_lock);
  				sb->s_flags |= MS_RDONLY;
  				osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  				spin_unlock(&osb->osb_lock);
  				goto out;
  			}
  		}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
716
717
718
  	}
  
  	if (!ret) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
719
720
  		/* Only save off the new mount options in case of a successful
  		 * remount. */
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
721
722
723
  		osb->s_mount_opt = parsed_options.mount_opt;
  		osb->s_atime_quantum = parsed_options.atime_quantum;
  		osb->preferred_slot = parsed_options.slot;
d147b3d63   Mark Fasheh   ocfs2: Support co...
724
725
  		if (parsed_options.commit_interval)
  			osb->osb_commit_interval = parsed_options.commit_interval;
e001e796e   Mark Fasheh   ocfs2: Reset jour...
726
727
728
  
  		if (!ocfs2_is_hard_readonly(osb))
  			ocfs2_set_journal_params(osb);
57b09bb5e   Jan Kara   ocfs2: Set MS_POS...
729
730
731
732
  
  		sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  			((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
  							MS_POSIXACL : 0);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
733
734
735
736
737
738
739
  	}
  out:
  	return ret;
  }
  
  static int ocfs2_sb_probe(struct super_block *sb,
  			  struct buffer_head **bh,
73be192b1   Joel Becker   ocfs2: Add statis...
740
741
  			  int *sector_size,
  			  struct ocfs2_blockcheck_stats *stats)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
742
  {
bddb8eb37   Denis Cheng   [PATCH] fs/ocfs2/...
743
  	int status, tmpstat;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
744
745
746
747
748
749
750
  	struct ocfs1_vol_disk_hdr *hdr;
  	struct ocfs2_dinode *di;
  	int blksize;
  
  	*bh = NULL;
  
  	/* may be > 512 */
e1defc4ff   Martin K. Petersen   block: Do away wi...
751
  	*sector_size = bdev_logical_block_size(sb->s_bdev);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
  	if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
  		mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)
  ",
  		     *sector_size, OCFS2_MAX_BLOCKSIZE);
  		status = -EINVAL;
  		goto bail;
  	}
  
  	/* Can this really happen? */
  	if (*sector_size < OCFS2_MIN_BLOCKSIZE)
  		*sector_size = OCFS2_MIN_BLOCKSIZE;
  
  	/* check block zero for old format */
  	status = ocfs2_get_sector(sb, bh, 0, *sector_size);
  	if (status < 0) {
  		mlog_errno(status);
  		goto bail;
  	}
  	hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
  	if (hdr->major_version == OCFS1_MAJOR_VERSION) {
  		mlog(ML_ERROR, "incompatible version: %u.%u
  ",
  		     hdr->major_version, hdr->minor_version);
  		status = -EINVAL;
  	}
  	if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
  		   strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
  		mlog(ML_ERROR, "incompatible volume signature: %8s
  ",
  		     hdr->signature);
  		status = -EINVAL;
  	}
  	brelse(*bh);
  	*bh = NULL;
  	if (status < 0) {
  		mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
  		     "upgraded before mounting with ocfs v2
  ");
  		goto bail;
  	}
  
  	/*
  	 * Now check at magic offset for 512, 1024, 2048, 4096
  	 * blocksizes.  4096 is the maximum blocksize because it is
  	 * the minimum clustersize.
  	 */
  	status = -EINVAL;
  	for (blksize = *sector_size;
  	     blksize <= OCFS2_MAX_BLOCKSIZE;
  	     blksize <<= 1) {
  		tmpstat = ocfs2_get_sector(sb, bh,
  					   OCFS2_SUPER_BLOCK_BLKNO,
  					   blksize);
  		if (tmpstat < 0) {
  			status = tmpstat;
  			mlog_errno(status);
fb5cbe9ef   Joel Becker   ocfs2: Return -EI...
808
  			break;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
809
810
  		}
  		di = (struct ocfs2_dinode *) (*bh)->b_data;
73be192b1   Joel Becker   ocfs2: Add statis...
811
  		memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
1c1d9793f   Jan Kara   ocfs2: Fix initia...
812
  		spin_lock_init(&stats->b_lock);
fb5cbe9ef   Joel Becker   ocfs2: Return -EI...
813
814
815
816
817
818
819
  		tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
  		if (tmpstat < 0) {
  			brelse(*bh);
  			*bh = NULL;
  		}
  		if (tmpstat != -EAGAIN) {
  			status = tmpstat;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
820
  			break;
fb5cbe9ef   Joel Becker   ocfs2: Return -EI...
821
  		}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
822
823
824
825
826
  	}
  
  bail:
  	return status;
  }
c271c5c22   Sunil Mushran   ocfs2: local mounts
827
828
  static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
  {
2c442719e   Sunil Mushran   (2c442719e90a44a6...
829
830
831
832
  	u32 hb_enabled = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL;
  
  	if (osb->s_mount_opt & hb_enabled) {
  		if (ocfs2_mount_local(osb)) {
c271c5c22   Sunil Mushran   ocfs2: local mounts
833
834
835
836
837
  			mlog(ML_ERROR, "Cannot heartbeat on a locally "
  			     "mounted device.
  ");
  			return -EINVAL;
  		}
2c442719e   Sunil Mushran   (2c442719e90a44a6...
838
  		if (ocfs2_userspace_stack(osb)) {
b61817e11   Joel Becker   ocfs2: Add the US...
839
840
841
842
843
  			mlog(ML_ERROR, "Userspace stack expected, but "
  			     "o2cb heartbeat arguments passed to mount
  ");
  			return -EINVAL;
  		}
2c442719e   Sunil Mushran   (2c442719e90a44a6...
844
845
846
847
848
849
850
851
  		if (((osb->s_mount_opt & OCFS2_MOUNT_HB_GLOBAL) &&
  		     !ocfs2_cluster_o2cb_global_heartbeat(osb)) ||
  		    ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) &&
  		     ocfs2_cluster_o2cb_global_heartbeat(osb))) {
  			mlog(ML_ERROR, "Mismatching o2cb heartbeat modes
  ");
  			return -EINVAL;
  		}
b61817e11   Joel Becker   ocfs2: Add the US...
852
  	}
2c442719e   Sunil Mushran   (2c442719e90a44a6...
853
  	if (!(osb->s_mount_opt & hb_enabled)) {
b61817e11   Joel Becker   ocfs2: Add the US...
854
855
  		if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
  		    !ocfs2_userspace_stack(osb)) {
c271c5c22   Sunil Mushran   ocfs2: local mounts
856
857
858
859
860
861
862
863
864
  			mlog(ML_ERROR, "Heartbeat has to be started to mount "
  			     "a read-write clustered device.
  ");
  			return -EINVAL;
  		}
  	}
  
  	return 0;
  }
b61817e11   Joel Becker   ocfs2: Add the US...
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
  /*
   * If we're using a userspace stack, mount should have passed
   * a name that matches the disk.  If not, mount should not
   * have passed a stack.
   */
  static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
  					struct mount_options *mopt)
  {
  	if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
  		mlog(ML_ERROR,
  		     "cluster stack passed to mount, but this filesystem "
  		     "does not support it
  ");
  		return -EINVAL;
  	}
  
  	if (ocfs2_userspace_stack(osb) &&
  	    strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
  		    OCFS2_STACK_LABEL_LEN)) {
  		mlog(ML_ERROR,
  		     "cluster stack passed to mount (\"%s\") does not "
  		     "match the filesystem (\"%s\")
  ",
  		     mopt->cluster_stack,
  		     osb->osb_cluster_stack);
  		return -EINVAL;
  	}
  
  	return 0;
  }
19ece546a   Jan Kara   ocfs2: Enable quo...
895
896
897
898
899
900
901
902
903
904
905
906
  static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
  {
  	int type;
  	struct super_block *sb = osb->sb;
  	unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  					     OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  	int status = 0;
  
  	for (type = 0; type < MAXQUOTAS; type++) {
  		if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  			continue;
  		if (unsuspend)
0f0dd62fd   Christoph Hellwig   quota: kill the v...
907
  			status = dquot_resume(sb, type);
eea7feb07   Jan Kara   ocfs2: Fix use af...
908
909
910
911
912
913
  		else {
  			struct ocfs2_mem_dqinfo *oinfo;
  
  			/* Cancel periodic syncing before suspending */
  			oinfo = sb_dqinfo(sb, type)->dqi_priv;
  			cancel_delayed_work_sync(&oinfo->dqi_sync_work);
0f0dd62fd   Christoph Hellwig   quota: kill the v...
914
  			status = dquot_suspend(sb, type);
eea7feb07   Jan Kara   ocfs2: Fix use af...
915
  		}
19ece546a   Jan Kara   ocfs2: Enable quo...
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
  		if (status < 0)
  			break;
  	}
  	if (status < 0)
  		mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
  		     "remount (error = %d).
  ", status);
  	return status;
  }
  
  static int ocfs2_enable_quotas(struct ocfs2_super *osb)
  {
  	struct inode *inode[MAXQUOTAS] = { NULL, NULL };
  	struct super_block *sb = osb->sb;
  	unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  					     OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  	unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
  					LOCAL_GROUP_QUOTA_SYSTEM_INODE };
  	int status;
  	int type;
  
  	sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
  	for (type = 0; type < MAXQUOTAS; type++) {
  		if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  			continue;
  		inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
  							osb->slot_num);
  		if (!inode[type]) {
  			status = -ENOENT;
  			goto out_quota_off;
  		}
287a80958   Christoph Hellwig   quota: rename def...
947
948
  		status = dquot_enable(inode[type], type, QFMT_OCFS2,
  				      DQUOT_USAGE_ENABLED);
19ece546a   Jan Kara   ocfs2: Enable quo...
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
  		if (status < 0)
  			goto out_quota_off;
  	}
  
  	for (type = 0; type < MAXQUOTAS; type++)
  		iput(inode[type]);
  	return 0;
  out_quota_off:
  	ocfs2_disable_quotas(osb);
  	for (type = 0; type < MAXQUOTAS; type++)
  		iput(inode[type]);
  	mlog_errno(status);
  	return status;
  }
  
  static void ocfs2_disable_quotas(struct ocfs2_super *osb)
  {
  	int type;
  	struct inode *inode;
  	struct super_block *sb = osb->sb;
c06bcbfa1   Jan Kara   ocfs2: Fix lock i...
969
  	struct ocfs2_mem_dqinfo *oinfo;
19ece546a   Jan Kara   ocfs2: Enable quo...
970
971
972
973
974
975
  
  	/* We mostly ignore errors in this function because there's not much
  	 * we can do when we see them */
  	for (type = 0; type < MAXQUOTAS; type++) {
  		if (!sb_has_quota_loaded(sb, type))
  			continue;
c06bcbfa1   Jan Kara   ocfs2: Fix lock i...
976
977
978
  		/* Cancel periodic syncing before we grab dqonoff_mutex */
  		oinfo = sb_dqinfo(sb, type)->dqi_priv;
  		cancel_delayed_work_sync(&oinfo->dqi_sync_work);
19ece546a   Jan Kara   ocfs2: Enable quo...
979
980
981
982
  		inode = igrab(sb->s_dquot.files[type]);
  		/* Turn off quotas. This will remove all dquot structures from
  		 * memory and so they will be automatically synced to global
  		 * quota files */
0f0dd62fd   Christoph Hellwig   quota: kill the v...
983
984
  		dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
  					DQUOT_LIMITS_ENABLED);
19ece546a   Jan Kara   ocfs2: Enable quo...
985
986
987
988
989
990
991
  		if (!inode)
  			continue;
  		iput(inode);
  	}
  }
  
  /* Handle quota on quotactl */
f00c9e44a   Jan Kara   quota: Fix deadlo...
992
  static int ocfs2_quota_on(struct super_block *sb, int type, int format_id)
19ece546a   Jan Kara   ocfs2: Enable quo...
993
994
995
996
997
998
  {
  	unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  					     OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  
  	if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  		return -EINVAL;
287a80958   Christoph Hellwig   quota: rename def...
999
1000
  	return dquot_enable(sb_dqopt(sb)->files[type], type,
  			    format_id, DQUOT_LIMITS_ENABLED);
19ece546a   Jan Kara   ocfs2: Enable quo...
1001
1002
1003
  }
  
  /* Handle quota off quotactl */
307ae18a5   Christoph Hellwig   quota: drop remou...
1004
  static int ocfs2_quota_off(struct super_block *sb, int type)
19ece546a   Jan Kara   ocfs2: Enable quo...
1005
  {
0f0dd62fd   Christoph Hellwig   quota: kill the v...
1006
  	return dquot_disable(sb, type, DQUOT_LIMITS_ENABLED);
19ece546a   Jan Kara   ocfs2: Enable quo...
1007
  }
0d54b217a   Alexey Dobriyan   const: make struc...
1008
  static const struct quotactl_ops ocfs2_quotactl_ops = {
f00c9e44a   Jan Kara   quota: Fix deadlo...
1009
  	.quota_on_meta	= ocfs2_quota_on,
19ece546a   Jan Kara   ocfs2: Enable quo...
1010
  	.quota_off	= ocfs2_quota_off,
287a80958   Christoph Hellwig   quota: rename def...
1011
1012
1013
1014
1015
  	.quota_sync	= dquot_quota_sync,
  	.get_info	= dquot_get_dqinfo,
  	.set_info	= dquot_set_dqinfo,
  	.get_dqblk	= dquot_get_dqblk,
  	.set_dqblk	= dquot_set_dqblk,
19ece546a   Jan Kara   ocfs2: Enable quo...
1016
  };
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1017
1018
1019
1020
  static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
  {
  	struct dentry *root;
  	int status, sector_size;
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1021
  	struct mount_options parsed_options;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1022
1023
1024
  	struct inode *inode = NULL;
  	struct ocfs2_super *osb = NULL;
  	struct buffer_head *bh = NULL;
c271c5c22   Sunil Mushran   ocfs2: local mounts
1025
  	char nodestr[8];
73be192b1   Joel Becker   ocfs2: Add statis...
1026
  	struct ocfs2_blockcheck_stats stats;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1027

32a42d392   Tao Ma   ocfs2: Remove mas...
1028
  	trace_ocfs2_fill_super(sb, data, silent);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1029

c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1030
  	if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1031
1032
1033
1034
1035
  		status = -EINVAL;
  		goto read_super_error;
  	}
  
  	/* probe for superblock */
73be192b1   Joel Becker   ocfs2: Add statis...
1036
  	status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1037
1038
1039
1040
1041
  	if (status < 0) {
  		mlog(ML_ERROR, "superblock probe failed!
  ");
  		goto read_super_error;
  	}
73be192b1   Joel Becker   ocfs2: Add statis...
1042
  	status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1043
1044
1045
1046
1047
1048
1049
  	osb = OCFS2_SB(sb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto read_super_error;
  	}
  	brelse(bh);
  	bh = NULL;
a68979b85   Tiger Yang   ocfs2: add mount ...
1050

5297aad80   Jan Kara   ocfs2: Make acl u...
1051
1052
1053
1054
  	if (!ocfs2_check_set_options(sb, &parsed_options)) {
  		status = -EINVAL;
  		goto read_super_error;
  	}
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1055
1056
1057
  	osb->s_mount_opt = parsed_options.mount_opt;
  	osb->s_atime_quantum = parsed_options.atime_quantum;
  	osb->preferred_slot = parsed_options.slot;
d147b3d63   Mark Fasheh   ocfs2: Support co...
1058
  	osb->osb_commit_interval = parsed_options.commit_interval;
73c8a8000   Mark Fasheh   ocfs2: clean up l...
1059
1060
  
  	ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
d02f00cc0   Mark Fasheh   ocfs2: allocation...
1061
  	osb->osb_resv_level = parsed_options.resv_level;
83f92318f   Mark Fasheh   ocfs2: Add dir_re...
1062
1063
1064
1065
1066
  	osb->osb_dir_resv_level = parsed_options.resv_level;
  	if (parsed_options.dir_resv_level == -1)
  		osb->osb_dir_resv_level = parsed_options.resv_level;
  	else
  		osb->osb_dir_resv_level = parsed_options.dir_resv_level;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1067

b61817e11   Joel Becker   ocfs2: Add the US...
1068
1069
1070
  	status = ocfs2_verify_userspace_stack(osb, &parsed_options);
  	if (status)
  		goto read_super_error;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1071
  	sb->s_magic = OCFS2_SUPER_MAGIC;
9e1f1de02   Al Viro   more conservative...
1072
  	sb->s_flags = (sb->s_flags & ~(MS_POSIXACL | MS_NOSEC)) |
a68979b85   Tiger Yang   ocfs2: add mount ...
1073
  		((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
  	/* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
  	 * heartbeat=none */
  	if (bdev_read_only(sb->s_bdev)) {
  		if (!(sb->s_flags & MS_RDONLY)) {
  			status = -EACCES;
  			mlog(ML_ERROR, "Readonly device detected but readonly "
  			     "mount was not specified.
  ");
  			goto read_super_error;
  		}
  
  		/* You should not be able to start a local heartbeat
  		 * on a readonly device. */
  		if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  			status = -EROFS;
  			mlog(ML_ERROR, "Local heartbeat specified on readonly "
  			     "device.
  ");
  			goto read_super_error;
  		}
  
  		status = ocfs2_check_journals_nolocks(osb);
  		if (status < 0) {
  			if (status == -EROFS)
  				mlog(ML_ERROR, "Recovery required on readonly "
  				     "file system, but write access is "
  				     "unavailable.
  ");
  			else
2bd632165   Sunil Mushran   ocfs2/trivial: Re...
1103
  				mlog_errno(status);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1104
1105
1106
1107
  			goto read_super_error;
  		}
  
  		ocfs2_set_ro_flag(osb, 1);
619c200de   Sunil Mushran   ocfs2: Clean up m...
1108
1109
1110
1111
  		printk(KERN_NOTICE "ocfs2: Readonly device (%s) detected. "
  		       "Cluster services will not be used for this mount. "
  		       "Recovery will be skipped.
  ", osb->dev_str);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1112
1113
1114
  	}
  
  	if (!ocfs2_is_hard_readonly(osb)) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1115
1116
1117
  		if (sb->s_flags & MS_RDONLY)
  			ocfs2_set_ro_flag(osb, 0);
  	}
c271c5c22   Sunil Mushran   ocfs2: local mounts
1118
1119
1120
1121
1122
  	status = ocfs2_verify_heartbeat(osb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto read_super_error;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1123
1124
1125
1126
1127
1128
1129
1130
  	osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
  						 ocfs2_debugfs_root);
  	if (!osb->osb_debug_root) {
  		status = -EINVAL;
  		mlog(ML_ERROR, "Unable to create per-mount debugfs root.
  ");
  		goto read_super_error;
  	}
50397507e   Sunil Mushran   ocfs2: Expose the...
1131
1132
1133
1134
1135
1136
1137
1138
1139
  	osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
  					    osb->osb_debug_root,
  					    osb,
  					    &ocfs2_osb_debug_fops);
  	if (!osb->osb_ctxt) {
  		status = -EINVAL;
  		mlog_errno(status);
  		goto read_super_error;
  	}
73be192b1   Joel Becker   ocfs2: Add statis...
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
  	if (ocfs2_meta_ecc(osb)) {
  		status = ocfs2_blockcheck_stats_debugfs_install(
  						&osb->osb_ecc_stats,
  						osb->osb_debug_root);
  		if (status) {
  			mlog(ML_ERROR,
  			     "Unable to create blockcheck statistics "
  			     "files
  ");
  			goto read_super_error;
  		}
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
  	status = ocfs2_mount_volume(sb);
  	if (osb->root_inode)
  		inode = igrab(osb->root_inode);
  
  	if (status < 0)
  		goto read_super_error;
  
  	if (!inode) {
  		status = -EIO;
  		mlog_errno(status);
  		goto read_super_error;
  	}
  
  	root = d_alloc_root(inode);
  	if (!root) {
  		status = -ENOMEM;
  		mlog_errno(status);
  		goto read_super_error;
  	}
  
  	sb->s_root = root;
  
  	ocfs2_complete_mount_recovery(osb);
c271c5c22   Sunil Mushran   ocfs2: local mounts
1175
1176
1177
  	if (ocfs2_mount_local(osb))
  		snprintf(nodestr, sizeof(nodestr), "local");
  	else
19fdb624d   Joel Becker   ocfs2: Abstract o...
1178
  		snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
c271c5c22   Sunil Mushran   ocfs2: local mounts
1179
1180
  
  	printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
781ee3e2b   Sunil Mushran   ocfs2: Cleanup me...
1181
1182
  	       "with %s data mode.
  ",
c271c5c22   Sunil Mushran   ocfs2: local mounts
1183
  	       osb->dev_str, nodestr, osb->slot_num,
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1184
1185
1186
1187
1188
  	       osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  	       "ordered");
  
  	atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  	wake_up(&osb->osb_mount_event);
19ece546a   Jan Kara   ocfs2: Enable quo...
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
  	/* Now we can initialize quotas because we can afford to wait
  	 * for cluster locks recovery now. That also means that truncation
  	 * log recovery can happen but that waits for proper quota setup */
  	if (!(sb->s_flags & MS_RDONLY)) {
  		status = ocfs2_enable_quotas(osb);
  		if (status < 0) {
  			/* We have to err-out specially here because
  			 * s_root is already set */
  			mlog_errno(status);
  			atomic_set(&osb->vol_state, VOLUME_DISABLED);
  			wake_up(&osb->osb_mount_event);
19ece546a   Jan Kara   ocfs2: Enable quo...
1200
1201
1202
1203
1204
1205
1206
1207
1208
  			return status;
  		}
  	}
  
  	ocfs2_complete_quota_recovery(osb);
  
  	/* Now we wake up again for processes waiting for quotas */
  	atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
  	wake_up(&osb->osb_mount_event);
df152c241   Sunil Mushran   ocfs2: Disable or...
1209
  	/* Start this when the mount is almost sure of being successful */
8b712cd58   Jeff Mahoney   ocfs2: Fixup orph...
1210
  	ocfs2_orphan_scan_start(osb);
df152c241   Sunil Mushran   ocfs2: Disable or...
1211

ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1212
1213
1214
  	return status;
  
  read_super_error:
a81cb88b6   Mark Fasheh   ocfs2: Don't chec...
1215
  	brelse(bh);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1216
1217
1218
1219
1220
1221
1222
1223
1224
  
  	if (inode)
  		iput(inode);
  
  	if (osb) {
  		atomic_set(&osb->vol_state, VOLUME_DISABLED);
  		wake_up(&osb->osb_mount_event);
  		ocfs2_dismount_volume(sb, 1);
  	}
c1e8d35ef   Tao Ma   ocfs2: Remove EXI...
1225
1226
  	if (status)
  		mlog_errno(status);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1227
1228
  	return status;
  }
152a08366   Al Viro   new helper: mount...
1229
  static struct dentry *ocfs2_mount(struct file_system_type *fs_type,
454e2398b   David Howells   [PATCH] VFS: Perm...
1230
1231
  			int flags,
  			const char *dev_name,
152a08366   Al Viro   new helper: mount...
1232
  			void *data)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1233
  {
152a08366   Al Viro   new helper: mount...
1234
  	return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1235
  }
f7b1aa69b   Jan Kara   ocfs2: Fix deadlo...
1236
1237
1238
  static void ocfs2_kill_sb(struct super_block *sb)
  {
  	struct ocfs2_super *osb = OCFS2_SB(sb);
5fd131893   Jan Kara   ocfs2: Don't oops...
1239
1240
1241
  	/* Failed mount? */
  	if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
  		goto out;
f7b1aa69b   Jan Kara   ocfs2: Fix deadlo...
1242
1243
1244
1245
1246
1247
  	/* Prevent further queueing of inode drop events */
  	spin_lock(&dentry_list_lock);
  	ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
  	spin_unlock(&dentry_list_lock);
  	/* Wait for work to finish and/or remove it */
  	cancel_work_sync(&osb->dentry_lock_work);
5fd131893   Jan Kara   ocfs2: Don't oops...
1248
  out:
f7b1aa69b   Jan Kara   ocfs2: Fix deadlo...
1249
1250
  	kill_block_super(sb);
  }
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1251
1252
1253
  static struct file_system_type ocfs2_fs_type = {
  	.owner          = THIS_MODULE,
  	.name           = "ocfs2",
152a08366   Al Viro   new helper: mount...
1254
  	.mount          = ocfs2_mount,
f7b1aa69b   Jan Kara   ocfs2: Fix deadlo...
1255
  	.kill_sb        = ocfs2_kill_sb,
1ba9da2ff   Mark Fasheh   ocfs2: manually d...
1256
  	.fs_flags       = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1257
1258
  	.next           = NULL
  };
5297aad80   Jan Kara   ocfs2: Make acl u...
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
  static int ocfs2_check_set_options(struct super_block *sb,
  				   struct mount_options *options)
  {
  	if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
  	    !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  					 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  		mlog(ML_ERROR, "User quotas were requested, but this "
  		     "filesystem does not have the feature enabled.
  ");
  		return 0;
  	}
  	if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
  	    !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  					 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  		mlog(ML_ERROR, "Group quotas were requested, but this "
  		     "filesystem does not have the feature enabled.
  ");
  		return 0;
  	}
  	if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
  	    !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
  		mlog(ML_ERROR, "ACL support requested but extended attributes "
  		     "feature is not enabled
  ");
  		return 0;
  	}
  	/* No ACL setting specified? Use XATTR feature... */
  	if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
  				    OCFS2_MOUNT_NO_POSIX_ACL))) {
  		if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
  			options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  		else
  			options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  	}
  	return 1;
  }
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1295
1296
  static int ocfs2_parse_options(struct super_block *sb,
  			       char *options,
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1297
  			       struct mount_options *mopt,
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1298
1299
  			       int is_remount)
  {
52c303c56   Mark Fasheh   ocfs2: Check hear...
1300
  	int status, user_stack = 0;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1301
  	char *p;
2c442719e   Sunil Mushran   (2c442719e90a44a6...
1302
  	u32 tmp;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1303

32a42d392   Tao Ma   ocfs2: Remove mas...
1304
  	trace_ocfs2_parse_options(is_remount, options ? options : "(none)");
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1305

d147b3d63   Mark Fasheh   ocfs2: Support co...
1306
  	mopt->commit_interval = 0;
4b37fcb7d   Sunil Mushran   ocfs2: Make noint...
1307
  	mopt->mount_opt = OCFS2_MOUNT_NOINTR;
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1308
1309
  	mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  	mopt->slot = OCFS2_INVALID_SLOT;
73c8a8000   Mark Fasheh   ocfs2: clean up l...
1310
  	mopt->localalloc_opt = -1;
b61817e11   Joel Becker   ocfs2: Add the US...
1311
  	mopt->cluster_stack[0] = '\0';
d02f00cc0   Mark Fasheh   ocfs2: allocation...
1312
  	mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
83f92318f   Mark Fasheh   ocfs2: Add dir_re...
1313
  	mopt->dir_resv_level = -1;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
  
  	if (!options) {
  		status = 1;
  		goto bail;
  	}
  
  	while ((p = strsep(&options, ",")) != NULL) {
  		int token, option;
  		substring_t args[MAX_OPT_ARGS];
  
  		if (!*p)
  			continue;
  
  		token = match_token(p, tokens, args);
  		switch (token) {
  		case Opt_hb_local:
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1330
  			mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1331
1332
  			break;
  		case Opt_hb_none:
2c442719e   Sunil Mushran   (2c442719e90a44a6...
1333
1334
1335
1336
  			mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
  			break;
  		case Opt_hb_global:
  			mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1337
1338
1339
1340
1341
1342
1343
  			break;
  		case Opt_barrier:
  			if (match_int(&args[0], &option)) {
  				status = 0;
  				goto bail;
  			}
  			if (option)
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1344
  				mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1345
  			else
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1346
  				mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1347
1348
  			break;
  		case Opt_intr:
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1349
  			mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1350
1351
  			break;
  		case Opt_nointr:
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1352
  			mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1353
1354
  			break;
  		case Opt_err_panic:
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1355
  			mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1356
1357
  			break;
  		case Opt_err_ro:
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1358
  			mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1359
1360
  			break;
  		case Opt_data_ordered:
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1361
  			mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1362
1363
  			break;
  		case Opt_data_writeback:
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1364
  			mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1365
  			break;
cf1d6c763   Tiger Yang   ocfs2: Add extend...
1366
1367
1368
1369
1370
1371
  		case Opt_user_xattr:
  			mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  			break;
  		case Opt_nouser_xattr:
  			mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  			break;
7f1a37e31   Tiger Yang   ocfs2: core atime...
1372
1373
1374
1375
1376
1377
  		case Opt_atime_quantum:
  			if (match_int(&args[0], &option)) {
  				status = 0;
  				goto bail;
  			}
  			if (option >= 0)
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1378
  				mopt->atime_quantum = option;
7f1a37e31   Tiger Yang   ocfs2: core atime...
1379
  			break;
baf4661a8   Sunil Mushran   ocfs2: Add "prefe...
1380
1381
1382
1383
1384
1385
1386
  		case Opt_slot:
  			option = 0;
  			if (match_int(&args[0], &option)) {
  				status = 0;
  				goto bail;
  			}
  			if (option)
c0123adef   Tiger Yang   [PATCH] ocfs2: fi...
1387
  				mopt->slot = (s16)option;
baf4661a8   Sunil Mushran   ocfs2: Add "prefe...
1388
  			break;
d147b3d63   Mark Fasheh   ocfs2: Support co...
1389
1390
1391
1392
1393
1394
1395
1396
1397
  		case Opt_commit:
  			option = 0;
  			if (match_int(&args[0], &option)) {
  				status = 0;
  				goto bail;
  			}
  			if (option < 0)
  				return 0;
  			if (option == 0)
2b4e30fbd   Joel Becker   ocfs2: Switch ove...
1398
  				option = JBD2_DEFAULT_MAX_COMMIT_AGE;
d147b3d63   Mark Fasheh   ocfs2: Support co...
1399
1400
  			mopt->commit_interval = HZ * option;
  			break;
2fbe8d1eb   Sunil Mushran   ocfs2: Local allo...
1401
1402
1403
1404
1405
1406
  		case Opt_localalloc:
  			option = 0;
  			if (match_int(&args[0], &option)) {
  				status = 0;
  				goto bail;
  			}
73c8a8000   Mark Fasheh   ocfs2: clean up l...
1407
  			if (option >= 0)
2fbe8d1eb   Sunil Mushran   ocfs2: Local allo...
1408
1409
  				mopt->localalloc_opt = option;
  			break;
53fc622b9   Mark Fasheh   [PATCH 2/2] ocfs2...
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
  		case Opt_localflocks:
  			/*
  			 * Changing this during remount could race
  			 * flock() requests, or "unbalance" existing
  			 * ones (e.g., a lock is taken in one mode but
  			 * dropped in the other). If users care enough
  			 * to flip locking modes during remount, we
  			 * could add a "local" flag to individual
  			 * flock structures for proper tracking of
  			 * state.
  			 */
  			if (!is_remount)
  				mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  			break;
b61817e11   Joel Becker   ocfs2: Add the US...
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
  		case Opt_stack:
  			/* Check both that the option we were passed
  			 * is of the right length and that it is a proper
  			 * string of the right length.
  			 */
  			if (((args[0].to - args[0].from) !=
  			     OCFS2_STACK_LABEL_LEN) ||
  			    (strnlen(args[0].from,
  				     OCFS2_STACK_LABEL_LEN) !=
  			     OCFS2_STACK_LABEL_LEN)) {
  				mlog(ML_ERROR,
  				     "Invalid cluster_stack option
  ");
  				status = 0;
  				goto bail;
  			}
  			memcpy(mopt->cluster_stack, args[0].from,
  			       OCFS2_STACK_LABEL_LEN);
  			mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
52c303c56   Mark Fasheh   ocfs2: Check hear...
1443
1444
1445
1446
1447
1448
1449
1450
1451
  			/*
  			 * Open code the memcmp here as we don't have
  			 * an osb to pass to
  			 * ocfs2_userspace_stack().
  			 */
  			if (memcmp(mopt->cluster_stack,
  				   OCFS2_CLASSIC_CLUSTER_STACK,
  				   OCFS2_STACK_LABEL_LEN))
  				user_stack = 1;
b61817e11   Joel Becker   ocfs2: Add the US...
1452
  			break;
12462f1d9   Joel Becker   ocfs2: Add the 'i...
1453
1454
1455
  		case Opt_inode64:
  			mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  			break;
19ece546a   Jan Kara   ocfs2: Enable quo...
1456
  		case Opt_usrquota:
19ece546a   Jan Kara   ocfs2: Enable quo...
1457
1458
1459
  			mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
  			break;
  		case Opt_grpquota:
19ece546a   Jan Kara   ocfs2: Enable quo...
1460
1461
  			mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
  			break;
7bdb0d18b   Tristan Ye   ocfs2: Add a moun...
1462
1463
1464
1465
1466
1467
  		case Opt_coherency_buffered:
  			mopt->mount_opt |= OCFS2_MOUNT_COHERENCY_BUFFERED;
  			break;
  		case Opt_coherency_full:
  			mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED;
  			break;
a68979b85   Tiger Yang   ocfs2: add mount ...
1468
1469
  		case Opt_acl:
  			mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
5297aad80   Jan Kara   ocfs2: Make acl u...
1470
  			mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
a68979b85   Tiger Yang   ocfs2: add mount ...
1471
1472
  			break;
  		case Opt_noacl:
5297aad80   Jan Kara   ocfs2: Make acl u...
1473
  			mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
a68979b85   Tiger Yang   ocfs2: add mount ...
1474
1475
  			mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  			break;
d02f00cc0   Mark Fasheh   ocfs2: allocation...
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
  		case Opt_resv_level:
  			if (is_remount)
  				break;
  			if (match_int(&args[0], &option)) {
  				status = 0;
  				goto bail;
  			}
  			if (option >= OCFS2_MIN_RESV_LEVEL &&
  			    option < OCFS2_MAX_RESV_LEVEL)
  				mopt->resv_level = option;
  			break;
83f92318f   Mark Fasheh   ocfs2: Add dir_re...
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
  		case Opt_dir_resv_level:
  			if (is_remount)
  				break;
  			if (match_int(&args[0], &option)) {
  				status = 0;
  				goto bail;
  			}
  			if (option >= OCFS2_MIN_RESV_LEVEL &&
  			    option < OCFS2_MAX_RESV_LEVEL)
  				mopt->dir_resv_level = option;
  			break;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1498
1499
1500
1501
1502
1503
1504
1505
1506
  		default:
  			mlog(ML_ERROR,
  			     "Unrecognized mount option \"%s\" "
  			     "or missing value
  ", p);
  			status = 0;
  			goto bail;
  		}
  	}
52c303c56   Mark Fasheh   ocfs2: Check hear...
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
  	if (user_stack == 0) {
  		/* Ensure only one heartbeat mode */
  		tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL |
  					 OCFS2_MOUNT_HB_GLOBAL |
  					 OCFS2_MOUNT_HB_NONE);
  		if (hweight32(tmp) != 1) {
  			mlog(ML_ERROR, "Invalid heartbeat mount options
  ");
  			status = 0;
  			goto bail;
  		}
2c442719e   Sunil Mushran   (2c442719e90a44a6...
1518
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1519
1520
1521
  	status = 1;
  
  bail:
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1522
1523
  	return status;
  }
d550071c0   Sunil Mushran   ocfs2: Implement ...
1524
1525
1526
1527
  static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  {
  	struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
  	unsigned long opts = osb->s_mount_opt;
ebcee4b5c   Mark Fasheh   ocfs2: Track loca...
1528
  	unsigned int local_alloc_megs;
d550071c0   Sunil Mushran   ocfs2: Implement ...
1529

2c442719e   Sunil Mushran   (2c442719e90a44a6...
1530
1531
1532
1533
1534
1535
1536
1537
  	if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
  		seq_printf(s, ",_netdev");
  		if (opts & OCFS2_MOUNT_HB_LOCAL)
  			seq_printf(s, ",%s", OCFS2_HB_LOCAL);
  		else
  			seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
  	} else
  		seq_printf(s, ",%s", OCFS2_HB_NONE);
d550071c0   Sunil Mushran   ocfs2: Implement ...
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
  
  	if (opts & OCFS2_MOUNT_NOINTR)
  		seq_printf(s, ",nointr");
  
  	if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  		seq_printf(s, ",data=writeback");
  	else
  		seq_printf(s, ",data=ordered");
  
  	if (opts & OCFS2_MOUNT_BARRIER)
  		seq_printf(s, ",barrier=1");
  
  	if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  		seq_printf(s, ",errors=panic");
  	else
  		seq_printf(s, ",errors=remount-ro");
  
  	if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  		seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
e2b0c215c   Tiger Yang   ocfs2: clean up m...
1557
  	if (!(mnt->mnt_flags & MNT_NOATIME) && !(mnt->mnt_flags & MNT_RELATIME))
d550071c0   Sunil Mushran   ocfs2: Implement ...
1558
  		seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
d147b3d63   Mark Fasheh   ocfs2: Support co...
1559
1560
1561
  	if (osb->osb_commit_interval)
  		seq_printf(s, ",commit=%u",
  			   (unsigned) (osb->osb_commit_interval / HZ));
ebcee4b5c   Mark Fasheh   ocfs2: Track loca...
1562
  	local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
6b82021b9   Mark Fasheh   ocfs2: increase t...
1563
  	if (local_alloc_megs != ocfs2_la_default_mb(osb))
ebcee4b5c   Mark Fasheh   ocfs2: Track loca...
1564
  		seq_printf(s, ",localalloc=%d", local_alloc_megs);
2fbe8d1eb   Sunil Mushran   ocfs2: Local allo...
1565

53fc622b9   Mark Fasheh   [PATCH 2/2] ocfs2...
1566
1567
  	if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  		seq_printf(s, ",localflocks,");
b61817e11   Joel Becker   ocfs2: Add the US...
1568
1569
1570
  	if (osb->osb_cluster_stack[0])
  		seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
  			   osb->osb_cluster_stack);
19ece546a   Jan Kara   ocfs2: Enable quo...
1571
1572
1573
1574
  	if (opts & OCFS2_MOUNT_USRQUOTA)
  		seq_printf(s, ",usrquota");
  	if (opts & OCFS2_MOUNT_GRPQUOTA)
  		seq_printf(s, ",grpquota");
b61817e11   Joel Becker   ocfs2: Add the US...
1575

7bdb0d18b   Tristan Ye   ocfs2: Add a moun...
1576
1577
1578
1579
  	if (opts & OCFS2_MOUNT_COHERENCY_BUFFERED)
  		seq_printf(s, ",coherency=buffered");
  	else
  		seq_printf(s, ",coherency=full");
b0f73cfc3   Sunil Mushran   ocfs2: Add xattr ...
1580
1581
1582
1583
  	if (opts & OCFS2_MOUNT_NOUSERXATTR)
  		seq_printf(s, ",nouser_xattr");
  	else
  		seq_printf(s, ",user_xattr");
12462f1d9   Joel Becker   ocfs2: Add the 'i...
1584
1585
  	if (opts & OCFS2_MOUNT_INODE64)
  		seq_printf(s, ",inode64");
a68979b85   Tiger Yang   ocfs2: add mount ...
1586
1587
1588
1589
  	if (opts & OCFS2_MOUNT_POSIX_ACL)
  		seq_printf(s, ",acl");
  	else
  		seq_printf(s, ",noacl");
a68979b85   Tiger Yang   ocfs2: add mount ...
1590

d02f00cc0   Mark Fasheh   ocfs2: allocation...
1591
1592
  	if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
  		seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
83f92318f   Mark Fasheh   ocfs2: Add dir_re...
1593
1594
  	if (osb->osb_dir_resv_level != osb->osb_resv_level)
  		seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
d550071c0   Sunil Mushran   ocfs2: Implement ...
1595
1596
  	return 0;
  }
a11f7e63c   Mark Fasheh   ocfs2: serialize ...
1597
  wait_queue_head_t ocfs2__ioend_wq[OCFS2_IOEND_WQ_HASH_SZ];
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1598
1599
  static int __init ocfs2_init(void)
  {
a11f7e63c   Mark Fasheh   ocfs2: serialize ...
1600
  	int status, i;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1601

ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1602
  	ocfs2_print_version();
a11f7e63c   Mark Fasheh   ocfs2: serialize ...
1603
1604
  	for (i = 0; i < OCFS2_IOEND_WQ_HASH_SZ; i++)
  		init_waitqueue_head(&ocfs2__ioend_wq[i]);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
  	status = init_ocfs2_uptodate_cache();
  	if (status < 0) {
  		mlog_errno(status);
  		goto leave;
  	}
  
  	status = ocfs2_initialize_mem_caches();
  	if (status < 0) {
  		mlog_errno(status);
  		goto leave;
  	}
  
  	ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
  	if (!ocfs2_wq) {
  		status = -ENOMEM;
  		goto leave;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1622
1623
1624
1625
1626
1627
  	ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  	if (!ocfs2_debugfs_root) {
  		status = -EFAULT;
  		mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.
  ");
  	}
63e0c48ae   Joel Becker   ocfs2: Clean up s...
1628
  	ocfs2_set_locking_protocol();
9e33d69f5   Jan Kara   ocfs2: Implementa...
1629
  	status = register_quota_format(&ocfs2_quota_format);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1630
1631
1632
1633
  leave:
  	if (status < 0) {
  		ocfs2_free_mem_caches();
  		exit_ocfs2_uptodate_cache();
c1e8d35ef   Tao Ma   ocfs2: Remove EXI...
1634
  		mlog_errno(status);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1635
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1636
1637
1638
1639
1640
1641
1642
1643
  	if (status >= 0) {
  		return register_filesystem(&ocfs2_fs_type);
  	} else
  		return -1;
  }
  
  static void __exit ocfs2_exit(void)
  {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1644
1645
1646
1647
  	if (ocfs2_wq) {
  		flush_workqueue(ocfs2_wq);
  		destroy_workqueue(ocfs2_wq);
  	}
9e33d69f5   Jan Kara   ocfs2: Implementa...
1648
  	unregister_quota_format(&ocfs2_quota_format);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1649
1650
1651
1652
1653
  	debugfs_remove(ocfs2_debugfs_root);
  
  	ocfs2_free_mem_caches();
  
  	unregister_filesystem(&ocfs2_fs_type);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1654
  	exit_ocfs2_uptodate_cache();
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1655
1656
1657
1658
  }
  
  static void ocfs2_put_super(struct super_block *sb)
  {
32a42d392   Tao Ma   ocfs2: Remove mas...
1659
  	trace_ocfs2_put_super(sb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1660
1661
1662
  
  	ocfs2_sync_blockdev(sb);
  	ocfs2_dismount_volume(sb, 0);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1663
  }
726c33422   David Howells   [PATCH] VFS: Perm...
1664
  static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1665
1666
1667
1668
1669
1670
1671
  {
  	struct ocfs2_super *osb;
  	u32 numbits, freebits;
  	int status;
  	struct ocfs2_dinode *bm_lock;
  	struct buffer_head *bh = NULL;
  	struct inode *inode = NULL;
32a42d392   Tao Ma   ocfs2: Remove mas...
1672
  	trace_ocfs2_statfs(dentry->d_sb, buf);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1673

726c33422   David Howells   [PATCH] VFS: Perm...
1674
  	osb = OCFS2_SB(dentry->d_sb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
  
  	inode = ocfs2_get_system_file_inode(osb,
  					    GLOBAL_BITMAP_SYSTEM_INODE,
  					    OCFS2_INVALID_SLOT);
  	if (!inode) {
  		mlog(ML_ERROR, "failed to get bitmap inode
  ");
  		status = -EIO;
  		goto bail;
  	}
e63aecb65   Mark Fasheh   ocfs2: Rename ocf...
1685
  	status = ocfs2_inode_lock(inode, &bh, 0);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
  	if (status < 0) {
  		mlog_errno(status);
  		goto bail;
  	}
  
  	bm_lock = (struct ocfs2_dinode *) bh->b_data;
  
  	numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  	freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  
  	buf->f_type = OCFS2_SUPER_MAGIC;
726c33422   David Howells   [PATCH] VFS: Perm...
1697
  	buf->f_bsize = dentry->d_sb->s_blocksize;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1698
1699
1700
1701
1702
1703
1704
1705
  	buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  	buf->f_blocks = ((sector_t) numbits) *
  			(osb->s_clustersize >> osb->sb->s_blocksize_bits);
  	buf->f_bfree = ((sector_t) freebits) *
  		       (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  	buf->f_bavail = buf->f_bfree;
  	buf->f_files = numbits;
  	buf->f_ffree = freebits;
837711f86   Coly Li   ocfs2: return f_f...
1706
1707
1708
1709
  	buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
  				& 0xFFFFFFFFUL;
  	buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
  				OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1710
1711
  
  	brelse(bh);
e63aecb65   Mark Fasheh   ocfs2: Rename ocf...
1712
  	ocfs2_inode_unlock(inode, 0);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1713
1714
1715
1716
  	status = 0;
  bail:
  	if (inode)
  		iput(inode);
c1e8d35ef   Tao Ma   ocfs2: Remove EXI...
1717
1718
  	if (status)
  		mlog_errno(status);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1719
1720
1721
  
  	return status;
  }
51cc50685   Alexey Dobriyan   SL*B: drop kmem c...
1722
  static void ocfs2_inode_init_once(void *data)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1723
1724
  {
  	struct ocfs2_inode_info *oi = data;
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
1725
1726
1727
1728
1729
  	oi->ip_flags = 0;
  	oi->ip_open_count = 0;
  	spin_lock_init(&oi->ip_lock);
  	ocfs2_extent_map_init(&oi->vfs_inode);
  	INIT_LIST_HEAD(&oi->ip_io_markers);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
1730
  	oi->ip_dir_start_lookup = 0;
a11f7e63c   Mark Fasheh   ocfs2: serialize ...
1731
  	atomic_set(&oi->ip_unaligned_aio, 0);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
1732
  	init_rwsem(&oi->ip_alloc_sem);
cf1d6c763   Tiger Yang   ocfs2: Add extend...
1733
  	init_rwsem(&oi->ip_xattr_sem);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
1734
  	mutex_init(&oi->ip_io_mutex);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1735

a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
1736
1737
  	oi->ip_blkno = 0ULL;
  	oi->ip_clusters = 0;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1738

4fe370afa   Mark Fasheh   ocfs2: use alloca...
1739
  	ocfs2_resv_init_once(&oi->ip_la_data_resv);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
1740
  	ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
e63aecb65   Mark Fasheh   ocfs2: Rename ocf...
1741
  	ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
1742
  	ocfs2_lock_res_init_once(&oi->ip_open_lockres);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1743

8cb471e8f   Joel Becker   ocfs2: Take the i...
1744
  	ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
6e5a3d753   Joel Becker   ocfs2: Change met...
1745
  				  &ocfs2_inode_caching_ops);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1746

a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
1747
  	inode_init_once(&oi->vfs_inode);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1748
1749
1750
1751
1752
  }
  
  static int ocfs2_initialize_mem_caches(void)
  {
  	ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
fffb60f93   Paul Jackson   [PATCH] cpuset me...
1753
1754
1755
1756
  				       sizeof(struct ocfs2_inode_info),
  				       0,
  				       (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  						SLAB_MEM_SPREAD),
20c2df83d   Paul Mundt   mm: Remove slab d...
1757
  				       ocfs2_inode_init_once);
9e33d69f5   Jan Kara   ocfs2: Implementa...
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
  	ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
  					sizeof(struct ocfs2_dquot),
  					0,
  					(SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  						SLAB_MEM_SPREAD),
  					NULL);
  	ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
  					sizeof(struct ocfs2_quota_chunk),
  					0,
  					(SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  					NULL);
  	if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
  	    !ocfs2_qf_chunk_cachep) {
  		if (ocfs2_inode_cachep)
  			kmem_cache_destroy(ocfs2_inode_cachep);
  		if (ocfs2_dquot_cachep)
  			kmem_cache_destroy(ocfs2_dquot_cachep);
  		if (ocfs2_qf_chunk_cachep)
  			kmem_cache_destroy(ocfs2_qf_chunk_cachep);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1777
  		return -ENOMEM;
9e33d69f5   Jan Kara   ocfs2: Implementa...
1778
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1779

ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1780
1781
1782
1783
1784
1785
1786
  	return 0;
  }
  
  static void ocfs2_free_mem_caches(void)
  {
  	if (ocfs2_inode_cachep)
  		kmem_cache_destroy(ocfs2_inode_cachep);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1787
  	ocfs2_inode_cachep = NULL;
9e33d69f5   Jan Kara   ocfs2: Implementa...
1788
1789
1790
1791
1792
1793
1794
1795
  
  	if (ocfs2_dquot_cachep)
  		kmem_cache_destroy(ocfs2_dquot_cachep);
  	ocfs2_dquot_cachep = NULL;
  
  	if (ocfs2_qf_chunk_cachep)
  		kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  	ocfs2_qf_chunk_cachep = NULL;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
  }
  
  static int ocfs2_get_sector(struct super_block *sb,
  			    struct buffer_head **bh,
  			    int block,
  			    int sect_size)
  {
  	if (!sb_set_blocksize(sb, sect_size)) {
  		mlog(ML_ERROR, "unable to set blocksize
  ");
  		return -EIO;
  	}
  
  	*bh = sb_getblk(sb, block);
  	if (!*bh) {
  		mlog_errno(-EIO);
  		return -EIO;
  	}
  	lock_buffer(*bh);
  	if (!buffer_dirty(*bh))
  		clear_buffer_uptodate(*bh);
  	unlock_buffer(*bh);
  	ll_rw_block(READ, 1, bh);
  	wait_on_buffer(*bh);
28d57d437   wengang wang   ocfs2: add IO err...
1820
1821
1822
1823
1824
1825
  	if (!buffer_uptodate(*bh)) {
  		mlog_errno(-EIO);
  		brelse(*bh);
  		*bh = NULL;
  		return -EIO;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1826
1827
  	return 0;
  }
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1828
1829
1830
1831
1832
  static int ocfs2_mount_volume(struct super_block *sb)
  {
  	int status = 0;
  	int unlock_super = 0;
  	struct ocfs2_super *osb = OCFS2_SB(sb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1833
1834
  	if (ocfs2_is_hard_readonly(osb))
  		goto leave;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1835
1836
1837
1838
1839
  	status = ocfs2_dlm_init(osb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto leave;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
  	status = ocfs2_super_lock(osb, 1);
  	if (status < 0) {
  		mlog_errno(status);
  		goto leave;
  	}
  	unlock_super = 1;
  
  	/* This will load up the node map and add ourselves to it. */
  	status = ocfs2_find_slot(osb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto leave;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
  	/* load all node-local system inodes */
  	status = ocfs2_init_local_system_inodes(osb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto leave;
  	}
  
  	status = ocfs2_check_volume(osb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto leave;
  	}
  
  	status = ocfs2_truncate_log_init(osb);
06c59bb89   Tao Ma   ocfs2: Remove red...
1867
  	if (status < 0)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1868
  		mlog_errno(status);
c271c5c22   Sunil Mushran   ocfs2: local mounts
1869

ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1870
1871
1872
  leave:
  	if (unlock_super)
  		ocfs2_super_unlock(osb, 1);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1873
1874
  	return status;
  }
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1875
1876
  static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  {
286eaa95c   Joel Becker   ocfs2: Break out ...
1877
  	int tmp, hangup_needed = 0;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1878
  	struct ocfs2_super *osb = NULL;
c271c5c22   Sunil Mushran   ocfs2: local mounts
1879
  	char nodestr[8];
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1880

32a42d392   Tao Ma   ocfs2: Remove mas...
1881
  	trace_ocfs2_dismount_volume(sb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1882
1883
1884
1885
  
  	BUG_ON(!sb);
  	osb = OCFS2_SB(sb);
  	BUG_ON(!osb);
50397507e   Sunil Mushran   ocfs2: Expose the...
1886
  	debugfs_remove(osb->osb_ctxt);
f7b1aa69b   Jan Kara   ocfs2: Fix deadlo...
1887
1888
1889
1890
1891
  	/*
  	 * Flush inode dropping work queue so that deletes are
  	 * performed while the filesystem is still working
  	 */
  	ocfs2_drop_all_dl_inodes(osb);
692684e19   Sunil Mushran   ocfs2: Stop orpha...
1892
1893
  	/* Orphan scan should be stopped as early as possible */
  	ocfs2_orphan_scan_stop(osb);
19ece546a   Jan Kara   ocfs2: Enable quo...
1894
  	ocfs2_disable_quotas(osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1895
1896
1897
  	ocfs2_shutdown_local_alloc(osb);
  
  	ocfs2_truncate_log_shutdown(osb);
553abd046   Joel Becker   ocfs2: Change the...
1898
1899
  	/* This will disable recovery and flush any recovery work. */
  	ocfs2_recovery_exit(osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1900
1901
1902
1903
  
  	ocfs2_journal_shutdown(osb);
  
  	ocfs2_sync_blockdev(sb);
374a263e7   Tao Ma   ocfs2: Add refcou...
1904
  	ocfs2_purge_refcount_trees(osb);
4670c46de   Joel Becker   ocfs2: Introduce ...
1905
1906
1907
  	/* No cluster connection means we've failed during mount, so skip
  	 * all the steps which depended on that to complete. */
  	if (osb->cconn) {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1908
1909
1910
1911
1912
  		tmp = ocfs2_super_lock(osb, 1);
  		if (tmp < 0) {
  			mlog_errno(tmp);
  			return;
  		}
19b613d41   Mark Fasheh   ocfs2: Clear slot...
1913
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1914

19b613d41   Mark Fasheh   ocfs2: Clear slot...
1915
1916
  	if (osb->slot_num != OCFS2_INVALID_SLOT)
  		ocfs2_put_slot(osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1917

4670c46de   Joel Becker   ocfs2: Introduce ...
1918
  	if (osb->cconn)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1919
  		ocfs2_super_unlock(osb, 1);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1920
1921
  
  	ocfs2_release_system_inodes(osb);
6953b4c00   Joel Becker   ocfs2: Move o2hb ...
1922
  	/*
6953b4c00   Joel Becker   ocfs2: Move o2hb ...
1923
1924
1925
1926
1927
  	 * If we're dismounting due to mount error, mount.ocfs2 will clean
  	 * up heartbeat.  If we're a local mount, there is no heartbeat.
  	 * If we failed before we got a uuid_str yet, we can't stop
  	 * heartbeat.  Otherwise, do it.
  	 */
03efed8a2   Tiger Yang   ocfs2: Bugfix for...
1928
1929
  	if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str &&
  	    !ocfs2_is_hard_readonly(osb))
286eaa95c   Joel Becker   ocfs2: Break out ...
1930
1931
1932
1933
  		hangup_needed = 1;
  
  	if (osb->cconn)
  		ocfs2_dlm_shutdown(osb, hangup_needed);
73be192b1   Joel Becker   ocfs2: Add statis...
1934
  	ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
286eaa95c   Joel Becker   ocfs2: Break out ...
1935
1936
1937
  	debugfs_remove(osb->osb_debug_root);
  
  	if (hangup_needed)
6953b4c00   Joel Becker   ocfs2: Move o2hb ...
1938
  		ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1939
1940
  
  	atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
c271c5c22   Sunil Mushran   ocfs2: local mounts
1941
1942
1943
  	if (ocfs2_mount_local(osb))
  		snprintf(nodestr, sizeof(nodestr), "local");
  	else
19fdb624d   Joel Becker   ocfs2: Abstract o...
1944
  		snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
c271c5c22   Sunil Mushran   ocfs2: local mounts
1945
1946
1947
1948
  
  	printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)
  ",
  	       osb->dev_str, nodestr);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
  
  	ocfs2_delete_osb(osb);
  	kfree(osb);
  	sb->s_dev = 0;
  	sb->s_fs_info = NULL;
  }
  
  static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  				unsigned uuid_bytes)
  {
  	int i, ret;
  	char *ptr;
  
  	BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
cd8612808   Robert P. J. Day   [PATCH] Fix numer...
1963
  	osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1964
1965
  	if (osb->uuid_str == NULL)
  		return -ENOMEM;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
  	for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  		/* print with null */
  		ret = snprintf(ptr, 3, "%02X", uuid[i]);
  		if (ret != 2) /* drop super cleans up */
  			return -EINVAL;
  		/* then only advance past the last char */
  		ptr += 2;
  	}
  
  	return 0;
  }
3bdb8efd9   Patrick J. LoPresti   OCFS2: Allow huge...
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
  /* Make sure entire volume is addressable by our journal.  Requires
     osb_clusters_at_boot to be valid and for the journal to have been
     initialized by ocfs2_journal_init(). */
  static int ocfs2_journal_addressable(struct ocfs2_super *osb)
  {
  	int status = 0;
  	u64 max_block =
  		ocfs2_clusters_to_blocks(osb->sb,
  					 osb->osb_clusters_at_boot) - 1;
  
  	/* 32-bit block number is always OK. */
  	if (max_block <= (u32)~0ULL)
  		goto out;
  
  	/* Volume is "huge", so see if our journal is new enough to
  	   support it. */
  	if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb,
  				       OCFS2_FEATURE_COMPAT_JBD2_SB) &&
  	      jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0,
  					       JBD2_FEATURE_INCOMPAT_64BIT))) {
  		mlog(ML_ERROR, "The journal cannot address the entire volume. "
  		     "Enable the 'block64' journal option with tunefs.ocfs2");
  		status = -EFBIG;
  		goto out;
  	}
  
   out:
  	return status;
  }
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2006
2007
  static int ocfs2_initialize_super(struct super_block *sb,
  				  struct buffer_head *bh,
73be192b1   Joel Becker   ocfs2: Add statis...
2008
2009
  				  int sector_size,
  				  struct ocfs2_blockcheck_stats *stats)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2010
  {
bddb8eb37   Denis Cheng   [PATCH] fs/ocfs2/...
2011
  	int status;
5a2540317   Mark Fasheh   ocfs2: Fix max of...
2012
2013
  	int i, cbits, bbits;
  	struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2014
  	struct inode *inode = NULL;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2015
2016
2017
  	struct ocfs2_journal *journal;
  	__le32 uuid_net_key;
  	struct ocfs2_super *osb;
3bdb8efd9   Patrick J. LoPresti   OCFS2: Allow huge...
2018
  	u64 total_blocks;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2019

cd8612808   Robert P. J. Day   [PATCH] Fix numer...
2020
  	osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2021
2022
2023
2024
2025
2026
2027
2028
  	if (!osb) {
  		status = -ENOMEM;
  		mlog_errno(status);
  		goto bail;
  	}
  
  	sb->s_fs_info = osb;
  	sb->s_op = &ocfs2_sops;
ba87167c0   Al Viro   switch ocfs2, clo...
2029
  	sb->s_d_op = &ocfs2_dentry_ops;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2030
  	sb->s_export_op = &ocfs2_export_ops;
19ece546a   Jan Kara   ocfs2: Enable quo...
2031
2032
  	sb->s_qcop = &ocfs2_quotactl_ops;
  	sb->dq_op = &ocfs2_quota_operations;
cf1d6c763   Tiger Yang   ocfs2: Add extend...
2033
  	sb->s_xattr = ocfs2_xattr_handlers;
e0dceaf0a   Mark Fasheh   ocfs2: set non-de...
2034
  	sb->s_time_gran = 1;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2035
2036
  	sb->s_flags |= MS_NOATIME;
  	/* this is needed to support O_LARGEFILE */
5a2540317   Mark Fasheh   ocfs2: Fix max of...
2037
2038
2039
  	cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  	bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  	sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2040

9b7895efa   Mark Fasheh   ocfs2: Add a name...
2041
2042
2043
2044
2045
  	osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
  
  	for (i = 0; i < 3; i++)
  		osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
  	osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2046
2047
2048
  	osb->sb = sb;
  	/* Save off for ocfs2_rw_direct */
  	osb->s_sectsize_bits = blksize_bits(sector_size);
ebdec83ba   Eric Sesterhenn / snakebyte   [PATCH] BUG_ON() ...
2049
  	BUG_ON(!osb->s_sectsize_bits);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2050

34d024f84   Mark Fasheh   ocfs2: Remove mou...
2051
2052
2053
2054
  	spin_lock_init(&osb->dc_task_lock);
  	init_waitqueue_head(&osb->dc_event);
  	osb->dc_work_sequence = 0;
  	osb->dc_wake_sequence = 0;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2055
2056
  	INIT_LIST_HEAD(&osb->blocked_lock_list);
  	osb->blocked_lock_count = 0;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2057
  	spin_lock_init(&osb->osb_lock);
c8b9cf9a7   Tao Ma   ocfs2: lock the m...
2058
  	spin_lock_init(&osb->osb_xattr_lock);
b89c54282   Tiger Yang   ocfs2: add extent...
2059
  	ocfs2_init_steal_slots(osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2060
2061
2062
2063
2064
2065
  
  	atomic_set(&osb->alloc_stats.moves, 0);
  	atomic_set(&osb->alloc_stats.local_data, 0);
  	atomic_set(&osb->alloc_stats.bitmap_data, 0);
  	atomic_set(&osb->alloc_stats.bg_allocs, 0);
  	atomic_set(&osb->alloc_stats.bg_extends, 0);
73be192b1   Joel Becker   ocfs2: Add statis...
2066
2067
  	/* Copy the blockcheck stats from the superblock probe */
  	osb->osb_ecc_stats = *stats;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2068
2069
2070
2071
  	ocfs2_init_node_maps(osb);
  
  	snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  		 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
75d9bbc73   Goldwyn Rodrigues   Initialize max_sl...
2072
2073
2074
2075
2076
2077
2078
2079
  	osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  	if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  		mlog(ML_ERROR, "Invalid number of node slots (%u)
  ",
  		     osb->max_slots);
  		status = -EINVAL;
  		goto bail;
  	}
75d9bbc73   Goldwyn Rodrigues   Initialize max_sl...
2080

8b712cd58   Jeff Mahoney   ocfs2: Fixup orph...
2081
  	ocfs2_orphan_scan_init(osb);
553abd046   Joel Becker   ocfs2: Change the...
2082
2083
2084
2085
2086
2087
2088
  	status = ocfs2_recovery_init(osb);
  	if (status) {
  		mlog(ML_ERROR, "Unable to initialize recovery state
  ");
  		mlog_errno(status);
  		goto bail;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2089
2090
2091
  
  	init_waitqueue_head(&osb->checkpoint_event);
  	atomic_set(&osb->needs_checkpoint, 0);
7f1a37e31   Tiger Yang   ocfs2: core atime...
2092
  	osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2093
  	osb->slot_num = OCFS2_INVALID_SLOT;
8154da3d2   Tiger Yang   ocfs2: Add incomp...
2094
2095
  	osb->s_xattr_inline_size = le16_to_cpu(
  					di->id2.i_super.s_xattr_inline_size);
fdd77704a   Tiger Yang   ocfs2: reserve in...
2096

ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2097
2098
  	osb->local_alloc_state = OCFS2_LA_UNUSED;
  	osb->local_alloc_bh = NULL;
9c7af40b2   Mark Fasheh   ocfs2: throttle b...
2099
  	INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2100

ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2101
  	init_waitqueue_head(&osb->osb_mount_event);
d02f00cc0   Mark Fasheh   ocfs2: allocation...
2102
2103
2104
2105
2106
  	status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
  	if (status) {
  		mlog_errno(status);
  		goto bail;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2107
2108
2109
2110
2111
2112
2113
  	osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  	if (!osb->vol_label) {
  		mlog(ML_ERROR, "unable to alloc vol label
  ");
  		status = -ENOMEM;
  		goto bail;
  	}
539d82640   Sunil Mushran   [PATCH 2/2] ocfs2...
2114
2115
2116
2117
2118
2119
2120
2121
  	osb->slot_recovery_generations =
  		kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  			GFP_KERNEL);
  	if (!osb->slot_recovery_generations) {
  		status = -ENOMEM;
  		mlog_errno(status);
  		goto bail;
  	}
b4df6ed8d   Mark Fasheh   [PATCH] ocfs2: fi...
2122
2123
2124
2125
2126
2127
2128
2129
2130
  	init_waitqueue_head(&osb->osb_wipe_event);
  	osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  					sizeof(*osb->osb_orphan_wipes),
  					GFP_KERNEL);
  	if (!osb->osb_orphan_wipes) {
  		status = -ENOMEM;
  		mlog_errno(status);
  		goto bail;
  	}
374a263e7   Tao Ma   ocfs2: Add refcou...
2131
  	osb->osb_rf_lock_tree = RB_ROOT;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
  	osb->s_feature_compat =
  		le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  	osb->s_feature_ro_compat =
  		le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  	osb->s_feature_incompat =
  		le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  
  	if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  		mlog(ML_ERROR, "couldn't mount because of unsupported "
  		     "optional features (%x).
  ", i);
  		status = -EINVAL;
  		goto bail;
  	}
  	if (!(osb->sb->s_flags & MS_RDONLY) &&
  	    (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  		mlog(ML_ERROR, "couldn't mount RDWR because of "
  		     "unsupported optional features (%x).
  ", i);
  		status = -EINVAL;
  		goto bail;
  	}
98f486f23   Sunil Mushran   (98f486f23bc5b6a6...
2154
2155
2156
  	if (ocfs2_clusterinfo_valid(osb)) {
  		osb->osb_stackflags =
  			OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
b61817e11   Joel Becker   ocfs2: Add the US...
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
  		memcpy(osb->osb_cluster_stack,
  		       OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  		       OCFS2_STACK_LABEL_LEN);
  		osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  		if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  			mlog(ML_ERROR,
  			     "couldn't mount because of an invalid "
  			     "cluster stack label (%s) 
  ",
  			     osb->osb_cluster_stack);
  			status = -EINVAL;
  			goto bail;
  		}
  	} else {
  		/* The empty string is identical with classic tools that
  		 * don't know about s_cluster_info. */
  		osb->osb_cluster_stack[0] = '\0';
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
  	get_random_bytes(&osb->s_next_generation, sizeof(u32));
  
  	/* FIXME
  	 * This should be done in ocfs2_journal_init(), but unknown
  	 * ordering issues will cause the filesystem to crash.
  	 * If anyone wants to figure out what part of the code
  	 * refers to osb->journal before ocfs2_journal_init() is run,
  	 * be my guest.
  	 */
  	/* initialize our journal structure */
cd8612808   Robert P. J. Day   [PATCH] Fix numer...
2185
  	journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
  	if (!journal) {
  		mlog(ML_ERROR, "unable to alloc journal
  ");
  		status = -ENOMEM;
  		goto bail;
  	}
  	osb->journal = journal;
  	journal->j_osb = osb;
  
  	atomic_set(&journal->j_num_trans, 0);
  	init_rwsem(&journal->j_trans_barrier);
  	init_waitqueue_head(&journal->j_checkpointed);
  	spin_lock_init(&journal->j_lock);
  	journal->j_trans_id = (unsigned long) 1;
  	INIT_LIST_HEAD(&journal->j_la_cleanups);
c4028958b   David Howells   WorkStruct: make ...
2201
  	INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2202
  	journal->j_state = OCFS2_JOURNAL_FREE;
ea455f8ab   Jan Kara   ocfs2: Push out d...
2203
2204
  	INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
  	osb->dentry_lock_list = NULL;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2205
2206
2207
2208
  	/* get some pseudo constants for clustersize bits */
  	osb->s_clustersize_bits =
  		le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  	osb->s_clustersize = 1 << osb->s_clustersize_bits;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2209
2210
2211
2212
2213
2214
2215
2216
2217
  
  	if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  	    osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  		mlog(ML_ERROR, "Volume has invalid cluster size (%d)
  ",
  		     osb->s_clustersize);
  		status = -EINVAL;
  		goto bail;
  	}
3bdb8efd9   Patrick J. LoPresti   OCFS2: Allow huge...
2218
2219
2220
2221
2222
2223
2224
2225
2226
  	total_blocks = ocfs2_clusters_to_blocks(osb->sb,
  						le32_to_cpu(di->i_clusters));
  
  	status = generic_check_addressable(osb->sb->s_blocksize_bits,
  					   total_blocks);
  	if (status) {
  		mlog(ML_ERROR, "Volume too large "
  		     "to mount safely on this system");
  		status = -EFBIG;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
  		goto bail;
  	}
  
  	if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  				 sizeof(di->id2.i_super.s_uuid))) {
  		mlog(ML_ERROR, "Out of memory trying to setup our uuid.
  ");
  		status = -ENOMEM;
  		goto bail;
  	}
784270435   Mark Fasheh   ocfs2: clean up s...
2237
  	memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2238
2239
2240
2241
2242
2243
2244
2245
  
  	strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
  	osb->vol_label[63] = '\0';
  	osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  	osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  	osb->first_cluster_group_blkno =
  		le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  	osb->fs_generation = le32_to_cpu(di->i_fs_generation);
cf1d6c763   Tiger Yang   ocfs2: Add extend...
2246
  	osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
32a42d392   Tao Ma   ocfs2: Remove mas...
2247
2248
2249
2250
  	trace_ocfs2_initialize_super(osb->vol_label, osb->uuid_str,
  				     (unsigned long long)osb->root_blkno,
  				     (unsigned long long)osb->system_dir_blkno,
  				     osb->s_clustersize_bits);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
  
  	osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  	if (!osb->osb_dlm_debug) {
  		status = -ENOMEM;
  		mlog_errno(status);
  		goto bail;
  	}
  
  	atomic_set(&osb->vol_state, VOLUME_INIT);
  
  	/* load root, system_dir, and all global system inodes */
  	status = ocfs2_init_global_system_inodes(osb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto bail;
  	}
  
  	/*
  	 * global bitmap
  	 */
  	inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  					    OCFS2_INVALID_SLOT);
  	if (!inode) {
  		status = -EINVAL;
  		mlog_errno(status);
  		goto bail;
  	}
  
  	osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
6b82021b9   Mark Fasheh   ocfs2: increase t...
2280
  	osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2281
  	iput(inode);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2282

8571882c2   Tao Ma   ocfs2: ocfs2_grou...
2283
2284
  	osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
  				 osb->s_feature_incompat) * 8;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2285
2286
2287
2288
2289
2290
  
  	status = ocfs2_init_slot_info(osb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto bail;
  	}
e41d33af7   Dan Magenheimer   ocfs2: send corre...
2291
  	cleancache_init_shared_fs((char *)&di->id2.i_super.s_uuid, sb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2292

ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2293
  bail:
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
  	return status;
  }
  
  /*
   * will return: -EAGAIN if it is ok to keep searching for superblocks
   *              -EINVAL if there is a bad superblock
   *              0 on success
   */
  static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  			       struct buffer_head *bh,
73be192b1   Joel Becker   ocfs2: Add statis...
2304
2305
  			       u32 blksz,
  			       struct ocfs2_blockcheck_stats *stats)
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2306
2307
  {
  	int status = -EAGAIN;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2308
2309
  	if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  		   strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
d030cc978   Joel Becker   ocfs2: Validate s...
2310
2311
2312
2313
2314
  		/* We have to do a raw check of the feature here */
  		if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
  		    OCFS2_FEATURE_INCOMPAT_META_ECC) {
  			status = ocfs2_block_check_validate(bh->b_data,
  							    bh->b_size,
73be192b1   Joel Becker   ocfs2: Add statis...
2315
2316
  							    &di->i_check,
  							    stats);
d030cc978   Joel Becker   ocfs2: Validate s...
2317
2318
2319
  			if (status)
  				goto out;
  		}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
  		status = -EINVAL;
  		if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  			mlog(ML_ERROR, "found superblock with incorrect block "
  			     "size: found %u, should be %u
  ",
  			     1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  			       blksz);
  		} else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  			   OCFS2_MAJOR_REV_LEVEL ||
  			   le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  			   OCFS2_MINOR_REV_LEVEL) {
  			mlog(ML_ERROR, "found superblock with bad version: "
  			     "found %u.%u, should be %u.%u
  ",
  			     le16_to_cpu(di->id2.i_super.s_major_rev_level),
  			     le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  			     OCFS2_MAJOR_REV_LEVEL,
  			     OCFS2_MINOR_REV_LEVEL);
  		} else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  			mlog(ML_ERROR, "bad block number on superblock: "
b0697053f   Mark Fasheh   ocfs2: don't use ...
2340
2341
  			     "found %llu, should be %llu
  ",
1ca1a111b   Mark Fasheh   ocfs2: fix sparse...
2342
  			     (unsigned long long)le64_to_cpu(di->i_blkno),
b0697053f   Mark Fasheh   ocfs2: don't use ...
2343
  			     (unsigned long long)bh->b_blocknr);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
  		} else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  			    le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  			mlog(ML_ERROR, "bad cluster size found: %u
  ",
  			     1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  		} else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  			mlog(ML_ERROR, "bad root_blkno: 0
  ");
  		} else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  			mlog(ML_ERROR, "bad system_dir_blkno: 0
  ");
  		} else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  			mlog(ML_ERROR,
  			     "Superblock slots found greater than file system "
  			     "maximum: found %u, max %u
  ",
  			     le16_to_cpu(di->id2.i_super.s_max_slots),
  			     OCFS2_MAX_SLOTS);
  		} else {
  			/* found it! */
  			status = 0;
  		}
  	}
d030cc978   Joel Becker   ocfs2: Validate s...
2367
  out:
c1e8d35ef   Tao Ma   ocfs2: Remove EXI...
2368
2369
  	if (status && status != -EAGAIN)
  		mlog_errno(status);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2370
2371
2372
2373
2374
  	return status;
  }
  
  static int ocfs2_check_volume(struct ocfs2_super *osb)
  {
bddb8eb37   Denis Cheng   [PATCH] fs/ocfs2/...
2375
  	int status;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2376
  	int dirty;
c271c5c22   Sunil Mushran   ocfs2: local mounts
2377
  	int local;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2378
2379
2380
  	struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  						  * recover
  						  * ourselves. */
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2381
2382
2383
2384
2385
2386
2387
  	/* Init our journal object. */
  	status = ocfs2_journal_init(osb->journal, &dirty);
  	if (status < 0) {
  		mlog(ML_ERROR, "Could not initialize journal!
  ");
  		goto finally;
  	}
3bdb8efd9   Patrick J. LoPresti   OCFS2: Allow huge...
2388
2389
2390
2391
2392
  	/* Now that journal has been initialized, check to make sure
  	   entire volume is addressable. */
  	status = ocfs2_journal_addressable(osb);
  	if (status)
  		goto finally;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
  	/* If the journal was unmounted cleanly then we don't want to
  	 * recover anything. Otherwise, journal_load will do that
  	 * dirty work for us :) */
  	if (!dirty) {
  		status = ocfs2_journal_wipe(osb->journal, 0);
  		if (status < 0) {
  			mlog_errno(status);
  			goto finally;
  		}
  	} else {
619c200de   Sunil Mushran   ocfs2: Clean up m...
2403
2404
2405
  		printk(KERN_NOTICE "ocfs2: File system on device (%s) was not "
  		       "unmounted cleanly, recovering it.
  ", osb->dev_str);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2406
  	}
c271c5c22   Sunil Mushran   ocfs2: local mounts
2407
  	local = ocfs2_mount_local(osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2408
  	/* will play back anything left in the journal. */
539d82640   Sunil Mushran   [PATCH 2/2] ocfs2...
2409
  	status = ocfs2_journal_load(osb->journal, local, dirty);
01af48203   Wengang Wang   ocfs2: Handle err...
2410
2411
2412
2413
2414
  	if (status < 0) {
  		mlog(ML_ERROR, "ocfs2 journal load failed! %d
  ", status);
  		goto finally;
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
  
  	if (dirty) {
  		/* recover my local alloc if we didn't unmount cleanly. */
  		status = ocfs2_begin_local_alloc_recovery(osb,
  							  osb->slot_num,
  							  &local_alloc);
  		if (status < 0) {
  			mlog_errno(status);
  			goto finally;
  		}
  		/* we complete the recovery process after we've marked
  		 * ourselves as mounted. */
  	}
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
  	status = ocfs2_load_local_alloc(osb);
  	if (status < 0) {
  		mlog_errno(status);
  		goto finally;
  	}
  
  	if (dirty) {
  		/* Recovery will be completed after we've mounted the
  		 * rest of the volume. */
  		osb->dirty = 1;
  		osb->local_alloc_copy = local_alloc;
  		local_alloc = NULL;
  	}
  
  	/* go through each journal, trylock it and if you get the
  	 * lock, and it's marked as dirty, set the bit in the recover
  	 * map and launch a recovery thread for it. */
  	status = ocfs2_mark_dead_nodes(osb);
9140db04e   Srinivas Eeda   ocfs2: recover or...
2446
2447
2448
2449
2450
2451
  	if (status < 0) {
  		mlog_errno(status);
  		goto finally;
  	}
  
  	status = ocfs2_compute_replay_slots(osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2452
2453
2454
2455
2456
2457
  	if (status < 0)
  		mlog_errno(status);
  
  finally:
  	if (local_alloc)
  		kfree(local_alloc);
c1e8d35ef   Tao Ma   ocfs2: Remove EXI...
2458
2459
  	if (status)
  		mlog_errno(status);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
  	return status;
  }
  
  /*
   * The routine gets called from dismount or close whenever a dismount on
   * volume is requested and the osb open count becomes 1.
   * It will remove the osb from the global list and also free up all the
   * initialized resources and fileobject.
   */
  static void ocfs2_delete_osb(struct ocfs2_super *osb)
  {
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2471
  	/* This function assumes that the caller has the main osb resource */
8e8a4603b   Mark Fasheh   ocfs2: Move slot ...
2472
  	ocfs2_free_slot_info(osb);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2473

b4df6ed8d   Mark Fasheh   [PATCH] ocfs2: fi...
2474
  	kfree(osb->osb_orphan_wipes);
539d82640   Sunil Mushran   [PATCH 2/2] ocfs2...
2475
  	kfree(osb->slot_recovery_generations);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2476
2477
  	/* FIXME
  	 * This belongs in journal shutdown, but because we have to
421f91d21   Uwe Kleine-König   fix typos concern...
2478
  	 * allocate osb->journal at the start of ocfs2_initialize_osb(),
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2479
2480
2481
2482
2483
2484
2485
2486
  	 * we free it here.
  	 */
  	kfree(osb->journal);
  	if (osb->local_alloc_copy)
  		kfree(osb->local_alloc_copy);
  	kfree(osb->uuid_str);
  	ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  	memset(osb, 0, sizeof(struct ocfs2_super));
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
  }
  
  /* Put OCFS2 into a readonly state, or (if the user specifies it),
   * panic(). We do not support continue-on-error operation. */
  static void ocfs2_handle_error(struct super_block *sb)
  {
  	struct ocfs2_super *osb = OCFS2_SB(sb);
  
  	if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
  		panic("OCFS2: (device %s): panic forced after error
  ",
  		      sb->s_id);
  
  	ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  
  	if (sb->s_flags & MS_RDONLY &&
  	    (ocfs2_is_soft_readonly(osb) ||
  	     ocfs2_is_hard_readonly(osb)))
  		return;
  
  	printk(KERN_CRIT "File system is now read-only due to the potential "
  	       "of on-disk corruption. Please run fsck.ocfs2 once the file "
  	       "system is unmounted.
  ");
  	sb->s_flags |= MS_RDONLY;
  	ocfs2_set_ro_flag(osb, 0);
  }
  
  static char error_buf[1024];
  
  void __ocfs2_error(struct super_block *sb,
  		   const char *function,
  		   const char *fmt, ...)
  {
  	va_list args;
  
  	va_start(args, fmt);
4a6e617a4   Alexey Dobriyan   [PATCH] fs/*: tri...
2524
  	vsnprintf(error_buf, sizeof(error_buf), fmt, args);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
  	va_end(args);
  
  	/* Not using mlog here because we want to show the actual
  	 * function the error came from. */
  	printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s
  ",
  	       sb->s_id, function, error_buf);
  
  	ocfs2_handle_error(sb);
  }
  
  /* Handle critical errors. This is intentionally more drastic than
   * ocfs2_handle_error, so we only use for things like journal errors,
   * etc. */
  void __ocfs2_abort(struct super_block* sb,
  		   const char *function,
  		   const char *fmt, ...)
  {
  	va_list args;
  
  	va_start(args, fmt);
4a6e617a4   Alexey Dobriyan   [PATCH] fs/*: tri...
2546
  	vsnprintf(error_buf, sizeof(error_buf), fmt, args);
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
  	va_end(args);
  
  	printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s
  ",
  	       sb->s_id, function, error_buf);
  
  	/* We don't have the cluster support yet to go straight to
  	 * hard readonly in here. Until then, we want to keep
  	 * ocfs2_abort() so that we can at least mark critical
  	 * errors.
  	 *
  	 * TODO: This should abort the journal and alert other nodes
  	 * that our slot needs recovery. */
  
  	/* Force a panic(). This stinks, but it's better than letting
  	 * things continue without having a proper hard readonly
  	 * here. */
a2f2ddbf2   Sunil Mushran   ocfs2: __ocfs2_ab...
2564
2565
  	if (!ocfs2_mount_local(OCFS2_SB(sb)))
  		OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2566
2567
  	ocfs2_handle_error(sb);
  }
e4b963f10   Joel Becker   ocfs2: Wrap signa...
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
  /*
   * Void signal blockers, because in-kernel sigprocmask() only fails
   * when SIG_* is wrong.
   */
  void ocfs2_block_signals(sigset_t *oldset)
  {
  	int rc;
  	sigset_t blocked;
  
  	sigfillset(&blocked);
  	rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
  	BUG_ON(rc);
  }
  
  void ocfs2_unblock_signals(sigset_t *oldset)
  {
  	int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
  	BUG_ON(rc);
  }
ccd979bdb   Mark Fasheh   [PATCH] OCFS2: Th...
2587
2588
  module_init(ocfs2_init);
  module_exit(ocfs2_exit);