Commit | Line | Data |
---|---|---|
328970de | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
fa60ce2c | 2 | /* |
ccd979bd MF |
3 | * super.c |
4 | * | |
5 | * load/unload driver, mount/dismount volumes | |
6 | * | |
7 | * Copyright (C) 2002, 2004 Oracle. All rights reserved. | |
ccd979bd MF |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/fs.h> | |
12 | #include <linux/types.h> | |
13 | #include <linux/slab.h> | |
14 | #include <linux/highmem.h> | |
ccd979bd MF |
15 | #include <linux/init.h> |
16 | #include <linux/random.h> | |
17 | #include <linux/statfs.h> | |
18 | #include <linux/moduleparam.h> | |
19 | #include <linux/blkdev.h> | |
20 | #include <linux/socket.h> | |
21 | #include <linux/inet.h> | |
9be53fe6 ES |
22 | #include <linux/fs_parser.h> |
23 | #include <linux/fs_context.h> | |
ccd979bd MF |
24 | #include <linux/crc32.h> |
25 | #include <linux/debugfs.h> | |
6953b4c0 | 26 | #include <linux/seq_file.h> |
19ece546 | 27 | #include <linux/quotaops.h> |
f361bf4a | 28 | #include <linux/signal.h> |
ccd979bd | 29 | |
80a9a84d WW |
30 | #define CREATE_TRACE_POINTS |
31 | #include "ocfs2_trace.h" | |
32 | ||
ccd979bd MF |
33 | #include <cluster/masklog.h> |
34 | ||
35 | #include "ocfs2.h" | |
36 | ||
37 | /* this should be the only file to include a version 1 header */ | |
38 | #include "ocfs1_fs_compat.h" | |
39 | ||
40 | #include "alloc.h" | |
a11f7e63 | 41 | #include "aops.h" |
d030cc97 | 42 | #include "blockcheck.h" |
ccd979bd MF |
43 | #include "dlmglue.h" |
44 | #include "export.h" | |
45 | #include "extent_map.h" | |
46 | #include "heartbeat.h" | |
47 | #include "inode.h" | |
48 | #include "journal.h" | |
49 | #include "localalloc.h" | |
50 | #include "namei.h" | |
51 | #include "slot_map.h" | |
52 | #include "super.h" | |
53 | #include "sysfile.h" | |
54 | #include "uptodate.h" | |
cf1d6c76 | 55 | #include "xattr.h" |
9e33d69f | 56 | #include "quota.h" |
374a263e | 57 | #include "refcounttree.h" |
b89c5428 | 58 | #include "suballoc.h" |
ccd979bd MF |
59 | |
60 | #include "buffer_head_io.h" | |
a849d468 | 61 | #include "filecheck.h" |
ccd979bd | 62 | |
1a5c4e2a | 63 | static struct kmem_cache *ocfs2_inode_cachep; |
9e33d69f JK |
64 | struct kmem_cache *ocfs2_dquot_cachep; |
65 | struct kmem_cache *ocfs2_qf_chunk_cachep; | |
ccd979bd | 66 | |
1a5c4e2a | 67 | static struct dentry *ocfs2_debugfs_root; |
ccd979bd MF |
68 | |
69 | MODULE_AUTHOR("Oracle"); | |
70 | MODULE_LICENSE("GPL"); | |
ff8fb335 | 71 | MODULE_DESCRIPTION("OCFS2 cluster file system"); |
ccd979bd | 72 | |
c0123ade TY |
73 | struct mount_options |
74 | { | |
d147b3d6 | 75 | unsigned long commit_interval; |
c0123ade TY |
76 | unsigned long mount_opt; |
77 | unsigned int atime_quantum; | |
38d51b2d | 78 | unsigned short slot; |
73c8a800 | 79 | int localalloc_opt; |
d02f00cc | 80 | unsigned int resv_level; |
83f92318 | 81 | int dir_resv_level; |
b61817e1 | 82 | char cluster_stack[OCFS2_STACK_LABEL_LEN + 1]; |
9be53fe6 | 83 | bool user_stack; |
c0123ade TY |
84 | }; |
85 | ||
9be53fe6 | 86 | static int ocfs2_parse_param(struct fs_context *fc, struct fs_parameter *param); |
5297aad8 JK |
87 | static int ocfs2_check_set_options(struct super_block *sb, |
88 | struct mount_options *options); | |
34c80b1d | 89 | static int ocfs2_show_options(struct seq_file *s, struct dentry *root); |
ccd979bd MF |
90 | static void ocfs2_put_super(struct super_block *sb); |
91 | static int ocfs2_mount_volume(struct super_block *sb); | |
ccd979bd MF |
92 | static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err); |
93 | static int ocfs2_initialize_mem_caches(void); | |
94 | static void ocfs2_free_mem_caches(void); | |
95 | static void ocfs2_delete_osb(struct ocfs2_super *osb); | |
96 | ||
726c3342 | 97 | static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf); |
ccd979bd MF |
98 | |
99 | static int ocfs2_sync_fs(struct super_block *sb, int wait); | |
100 | ||
101 | static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb); | |
102 | static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb); | |
bddb8eb3 | 103 | static void ocfs2_release_system_inodes(struct ocfs2_super *osb); |
ccd979bd MF |
104 | static int ocfs2_check_volume(struct ocfs2_super *osb); |
105 | static int ocfs2_verify_volume(struct ocfs2_dinode *di, | |
106 | struct buffer_head *bh, | |
73be192b JB |
107 | u32 sectsize, |
108 | struct ocfs2_blockcheck_stats *stats); | |
ccd979bd MF |
109 | static int ocfs2_initialize_super(struct super_block *sb, |
110 | struct buffer_head *bh, | |
73be192b JB |
111 | int sector_size, |
112 | struct ocfs2_blockcheck_stats *stats); | |
ccd979bd MF |
113 | static int ocfs2_get_sector(struct super_block *sb, |
114 | struct buffer_head **bh, | |
115 | int block, | |
116 | int sect_size); | |
ccd979bd | 117 | static struct inode *ocfs2_alloc_inode(struct super_block *sb); |
e91b9194 | 118 | static void ocfs2_free_inode(struct inode *inode); |
19ece546 JK |
119 | static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend); |
120 | static int ocfs2_enable_quotas(struct ocfs2_super *osb); | |
121 | static void ocfs2_disable_quotas(struct ocfs2_super *osb); | |
ccd979bd | 122 | |
ccb49011 | 123 | static struct dquot __rcu **ocfs2_get_dquots(struct inode *inode) |
1c92ec67 JK |
124 | { |
125 | return OCFS2_I(inode)->i_dquot; | |
126 | } | |
127 | ||
ee9b6d61 | 128 | static const struct super_operations ocfs2_sops = { |
ccd979bd MF |
129 | .statfs = ocfs2_statfs, |
130 | .alloc_inode = ocfs2_alloc_inode, | |
e91b9194 | 131 | .free_inode = ocfs2_free_inode, |
ccd979bd | 132 | .drop_inode = ocfs2_drop_inode, |
066d92dc | 133 | .evict_inode = ocfs2_evict_inode, |
ccd979bd | 134 | .sync_fs = ocfs2_sync_fs, |
ccd979bd | 135 | .put_super = ocfs2_put_super, |
d550071c | 136 | .show_options = ocfs2_show_options, |
9e33d69f JK |
137 | .quota_read = ocfs2_quota_read, |
138 | .quota_write = ocfs2_quota_write, | |
1c92ec67 | 139 | .get_dquots = ocfs2_get_dquots, |
ccd979bd MF |
140 | }; |
141 | ||
142 | enum { | |
143 | Opt_barrier, | |
9be53fe6 | 144 | Opt_errors, |
ccd979bd | 145 | Opt_intr, |
9be53fe6 ES |
146 | Opt_heartbeat, |
147 | Opt_data, | |
7f1a37e3 | 148 | Opt_atime_quantum, |
baf4661a | 149 | Opt_slot, |
d147b3d6 | 150 | Opt_commit, |
2fbe8d1e | 151 | Opt_localalloc, |
53fc622b | 152 | Opt_localflocks, |
b61817e1 | 153 | Opt_stack, |
cf1d6c76 | 154 | Opt_user_xattr, |
12462f1d | 155 | Opt_inode64, |
a68979b8 | 156 | Opt_acl, |
19ece546 JK |
157 | Opt_usrquota, |
158 | Opt_grpquota, | |
9be53fe6 | 159 | Opt_coherency, |
d02f00cc | 160 | Opt_resv_level, |
83f92318 | 161 | Opt_dir_resv_level, |
1dfeb768 | 162 | Opt_journal_async_commit, |
ccd979bd MF |
163 | }; |
164 | ||
9be53fe6 ES |
165 | static const struct constant_table ocfs2_param_errors[] = { |
166 | {"panic", OCFS2_MOUNT_ERRORS_PANIC}, | |
167 | {"remount-ro", OCFS2_MOUNT_ERRORS_ROFS}, | |
168 | {"continue", OCFS2_MOUNT_ERRORS_CONT}, | |
169 | {} | |
170 | }; | |
171 | ||
172 | static const struct constant_table ocfs2_param_heartbeat[] = { | |
173 | {"local", OCFS2_MOUNT_HB_LOCAL}, | |
174 | {"none", OCFS2_MOUNT_HB_NONE}, | |
175 | {"global", OCFS2_MOUNT_HB_GLOBAL}, | |
176 | {} | |
177 | }; | |
178 | ||
179 | static const struct constant_table ocfs2_param_data[] = { | |
180 | {"writeback", OCFS2_MOUNT_DATA_WRITEBACK}, | |
181 | {"ordered", 0}, | |
182 | {} | |
183 | }; | |
184 | ||
185 | static const struct constant_table ocfs2_param_coherency[] = { | |
186 | {"buffered", OCFS2_MOUNT_COHERENCY_BUFFERED}, | |
187 | {"full", 0}, | |
188 | {} | |
189 | }; | |
190 | ||
191 | static const struct fs_parameter_spec ocfs2_param_spec[] = { | |
192 | fsparam_u32 ("barrier", Opt_barrier), | |
193 | fsparam_enum ("errors", Opt_errors, ocfs2_param_errors), | |
194 | fsparam_flag_no ("intr", Opt_intr), | |
195 | fsparam_enum ("heartbeat", Opt_heartbeat, ocfs2_param_heartbeat), | |
196 | fsparam_enum ("data", Opt_data, ocfs2_param_data), | |
197 | fsparam_u32 ("atime_quantum", Opt_atime_quantum), | |
198 | fsparam_u32 ("preferred_slot", Opt_slot), | |
199 | fsparam_u32 ("commit", Opt_commit), | |
200 | fsparam_s32 ("localalloc", Opt_localalloc), | |
201 | fsparam_flag ("localflocks", Opt_localflocks), | |
202 | fsparam_string ("cluster_stack", Opt_stack), | |
203 | fsparam_flag_no ("user_xattr", Opt_user_xattr), | |
204 | fsparam_flag ("inode64", Opt_inode64), | |
205 | fsparam_flag_no ("acl", Opt_acl), | |
206 | fsparam_flag ("usrquota", Opt_usrquota), | |
207 | fsparam_flag ("grpquota", Opt_grpquota), | |
208 | fsparam_enum ("coherency", Opt_coherency, ocfs2_param_coherency), | |
209 | fsparam_u32 ("resv_level", Opt_resv_level), | |
210 | fsparam_u32 ("dir_resv_level", Opt_dir_resv_level), | |
211 | fsparam_flag ("journal_async_commit", Opt_journal_async_commit), | |
212 | {} | |
ccd979bd MF |
213 | }; |
214 | ||
50397507 SM |
215 | #ifdef CONFIG_DEBUG_FS |
216 | static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len) | |
217 | { | |
50397507 SM |
218 | struct ocfs2_cluster_connection *cconn = osb->cconn; |
219 | struct ocfs2_recovery_map *rm = osb->recovery_map; | |
df152c24 SM |
220 | struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan; |
221 | int i, out = 0; | |
bfd97a03 | 222 | unsigned long flags; |
50397507 | 223 | |
d293d3af | 224 | out += scnprintf(buf + out, len - out, |
50397507 SM |
225 | "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n", |
226 | "Device", osb->dev_str, osb->uuid_str, | |
227 | osb->fs_generation, osb->vol_label); | |
228 | ||
d293d3af | 229 | out += scnprintf(buf + out, len - out, |
50397507 SM |
230 | "%10s => State: %d Flags: 0x%lX\n", "Volume", |
231 | atomic_read(&osb->vol_state), osb->osb_flags); | |
232 | ||
d293d3af | 233 | out += scnprintf(buf + out, len - out, |
50397507 SM |
234 | "%10s => Block: %lu Cluster: %d\n", "Sizes", |
235 | osb->sb->s_blocksize, osb->s_clustersize); | |
236 | ||
d293d3af | 237 | out += scnprintf(buf + out, len - out, |
50397507 SM |
238 | "%10s => Compat: 0x%X Incompat: 0x%X " |
239 | "ROcompat: 0x%X\n", | |
240 | "Features", osb->s_feature_compat, | |
241 | osb->s_feature_incompat, osb->s_feature_ro_compat); | |
242 | ||
d293d3af | 243 | out += scnprintf(buf + out, len - out, |
50397507 SM |
244 | "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount", |
245 | osb->s_mount_opt, osb->s_atime_quantum); | |
246 | ||
c3d38840 | 247 | if (cconn) { |
d293d3af | 248 | out += scnprintf(buf + out, len - out, |
c3d38840 SM |
249 | "%10s => Stack: %s Name: %*s " |
250 | "Version: %d.%d\n", "Cluster", | |
251 | (*osb->osb_cluster_stack == '\0' ? | |
252 | "o2cb" : osb->osb_cluster_stack), | |
253 | cconn->cc_namelen, cconn->cc_name, | |
254 | cconn->cc_version.pv_major, | |
255 | cconn->cc_version.pv_minor); | |
256 | } | |
50397507 | 257 | |
bfd97a03 | 258 | spin_lock_irqsave(&osb->dc_task_lock, flags); |
d293d3af | 259 | out += scnprintf(buf + out, len - out, |
50397507 SM |
260 | "%10s => Pid: %d Count: %lu WakeSeq: %lu " |
261 | "WorkSeq: %lu\n", "DownCnvt", | |
c3d38840 SM |
262 | (osb->dc_task ? task_pid_nr(osb->dc_task) : -1), |
263 | osb->blocked_lock_count, osb->dc_wake_sequence, | |
264 | osb->dc_work_sequence); | |
bfd97a03 | 265 | spin_unlock_irqrestore(&osb->dc_task_lock, flags); |
50397507 SM |
266 | |
267 | spin_lock(&osb->osb_lock); | |
d293d3af | 268 | out += scnprintf(buf + out, len - out, "%10s => Pid: %d Nodes:", |
50397507 SM |
269 | "Recovery", |
270 | (osb->recovery_thread_task ? | |
271 | task_pid_nr(osb->recovery_thread_task) : -1)); | |
272 | if (rm->rm_used == 0) | |
d293d3af | 273 | out += scnprintf(buf + out, len - out, " None\n"); |
50397507 SM |
274 | else { |
275 | for (i = 0; i < rm->rm_used; i++) | |
d293d3af | 276 | out += scnprintf(buf + out, len - out, " %d", |
50397507 | 277 | rm->rm_entries[i]); |
d293d3af | 278 | out += scnprintf(buf + out, len - out, "\n"); |
50397507 SM |
279 | } |
280 | spin_unlock(&osb->osb_lock); | |
281 | ||
d293d3af | 282 | out += scnprintf(buf + out, len - out, |
8fa9d17f | 283 | "%10s => Pid: %d Interval: %lu\n", "Commit", |
c3d38840 | 284 | (osb->commit_task ? task_pid_nr(osb->commit_task) : -1), |
8fa9d17f | 285 | osb->osb_commit_interval); |
50397507 | 286 | |
d293d3af | 287 | out += scnprintf(buf + out, len - out, |
c3d38840 | 288 | "%10s => State: %d TxnId: %lu NumTxns: %d\n", |
50397507 | 289 | "Journal", osb->journal->j_state, |
c3d38840 SM |
290 | osb->journal->j_trans_id, |
291 | atomic_read(&osb->journal->j_num_trans)); | |
50397507 | 292 | |
d293d3af | 293 | out += scnprintf(buf + out, len - out, |
50397507 SM |
294 | "%10s => GlobalAllocs: %d LocalAllocs: %d " |
295 | "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n", | |
296 | "Stats", | |
297 | atomic_read(&osb->alloc_stats.bitmap_data), | |
298 | atomic_read(&osb->alloc_stats.local_data), | |
299 | atomic_read(&osb->alloc_stats.bg_allocs), | |
300 | atomic_read(&osb->alloc_stats.moves), | |
301 | atomic_read(&osb->alloc_stats.bg_extends)); | |
302 | ||
d293d3af | 303 | out += scnprintf(buf + out, len - out, |
50397507 SM |
304 | "%10s => State: %u Descriptor: %llu Size: %u bits " |
305 | "Default: %u bits\n", | |
306 | "LocalAlloc", osb->local_alloc_state, | |
307 | (unsigned long long)osb->la_last_gd, | |
308 | osb->local_alloc_bits, osb->local_alloc_default_bits); | |
309 | ||
310 | spin_lock(&osb->osb_lock); | |
d293d3af | 311 | out += scnprintf(buf + out, len - out, |
b89c5428 TY |
312 | "%10s => InodeSlot: %d StolenInodes: %d, " |
313 | "MetaSlot: %d StolenMeta: %d\n", "Steal", | |
50397507 | 314 | osb->s_inode_steal_slot, |
b89c5428 TY |
315 | atomic_read(&osb->s_num_inodes_stolen), |
316 | osb->s_meta_steal_slot, | |
317 | atomic_read(&osb->s_num_meta_stolen)); | |
50397507 SM |
318 | spin_unlock(&osb->osb_lock); |
319 | ||
d293d3af TI |
320 | out += scnprintf(buf + out, len - out, "OrphanScan => "); |
321 | out += scnprintf(buf + out, len - out, "Local: %u Global: %u ", | |
df152c24 | 322 | os->os_count, os->os_seqno); |
d293d3af | 323 | out += scnprintf(buf + out, len - out, " Last Scan: "); |
df152c24 | 324 | if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE) |
d293d3af | 325 | out += scnprintf(buf + out, len - out, "Disabled\n"); |
df152c24 | 326 | else |
d293d3af | 327 | out += scnprintf(buf + out, len - out, "%lu seconds ago\n", |
395627b0 | 328 | (unsigned long)(ktime_get_seconds() - os->os_scantime)); |
df152c24 | 329 | |
d293d3af | 330 | out += scnprintf(buf + out, len - out, "%10s => %3s %10s\n", |
50397507 | 331 | "Slots", "Num", "RecoGen"); |
50397507 | 332 | for (i = 0; i < osb->max_slots; ++i) { |
d293d3af | 333 | out += scnprintf(buf + out, len - out, |
50397507 SM |
334 | "%10s %c %3d %10d\n", |
335 | " ", | |
336 | (i == osb->slot_num ? '*' : ' '), | |
337 | i, osb->slot_recovery_generations[i]); | |
338 | } | |
339 | ||
340 | return out; | |
341 | } | |
342 | ||
343 | static int ocfs2_osb_debug_open(struct inode *inode, struct file *file) | |
344 | { | |
345 | struct ocfs2_super *osb = inode->i_private; | |
346 | char *buf = NULL; | |
347 | ||
348 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | |
349 | if (!buf) | |
350 | goto bail; | |
351 | ||
352 | i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE)); | |
353 | ||
354 | file->private_data = buf; | |
355 | ||
356 | return 0; | |
357 | bail: | |
358 | return -ENOMEM; | |
359 | } | |
360 | ||
361 | static int ocfs2_debug_release(struct inode *inode, struct file *file) | |
362 | { | |
363 | kfree(file->private_data); | |
364 | return 0; | |
365 | } | |
366 | ||
367 | static ssize_t ocfs2_debug_read(struct file *file, char __user *buf, | |
368 | size_t nbytes, loff_t *ppos) | |
369 | { | |
370 | return simple_read_from_buffer(buf, nbytes, ppos, file->private_data, | |
371 | i_size_read(file->f_mapping->host)); | |
372 | } | |
373 | #else | |
374 | static int ocfs2_osb_debug_open(struct inode *inode, struct file *file) | |
375 | { | |
376 | return 0; | |
377 | } | |
378 | static int ocfs2_debug_release(struct inode *inode, struct file *file) | |
379 | { | |
380 | return 0; | |
381 | } | |
382 | static ssize_t ocfs2_debug_read(struct file *file, char __user *buf, | |
383 | size_t nbytes, loff_t *ppos) | |
384 | { | |
385 | return 0; | |
386 | } | |
387 | #endif /* CONFIG_DEBUG_FS */ | |
388 | ||
828c0950 | 389 | static const struct file_operations ocfs2_osb_debug_fops = { |
50397507 SM |
390 | .open = ocfs2_osb_debug_open, |
391 | .release = ocfs2_debug_release, | |
392 | .read = ocfs2_debug_read, | |
393 | .llseek = generic_file_llseek, | |
394 | }; | |
395 | ||
ccd979bd MF |
396 | static int ocfs2_sync_fs(struct super_block *sb, int wait) |
397 | { | |
bddb8eb3 | 398 | int status; |
ccd979bd MF |
399 | tid_t target; |
400 | struct ocfs2_super *osb = OCFS2_SB(sb); | |
401 | ||
ccd979bd MF |
402 | if (ocfs2_is_hard_readonly(osb)) |
403 | return -EROFS; | |
404 | ||
405 | if (wait) { | |
406 | status = ocfs2_flush_truncate_log(osb); | |
407 | if (status < 0) | |
408 | mlog_errno(status); | |
409 | } else { | |
410 | ocfs2_schedule_truncate_log_flush(osb, 0); | |
411 | } | |
412 | ||
1119d3c0 | 413 | if (jbd2_journal_start_commit(osb->journal->j_journal, |
2b4e30fb | 414 | &target)) { |
ccd979bd | 415 | if (wait) |
1119d3c0 | 416 | jbd2_log_wait_commit(osb->journal->j_journal, |
2b4e30fb | 417 | target); |
ccd979bd MF |
418 | } |
419 | return 0; | |
420 | } | |
421 | ||
1a224ad1 JK |
422 | static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino) |
423 | { | |
424 | if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA) | |
425 | && (ino == USER_QUOTA_SYSTEM_INODE | |
426 | || ino == LOCAL_USER_QUOTA_SYSTEM_INODE)) | |
427 | return 0; | |
428 | if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA) | |
429 | && (ino == GROUP_QUOTA_SYSTEM_INODE | |
430 | || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE)) | |
431 | return 0; | |
432 | return 1; | |
433 | } | |
434 | ||
ccd979bd MF |
435 | static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb) |
436 | { | |
437 | struct inode *new = NULL; | |
438 | int status = 0; | |
439 | int i; | |
440 | ||
5fa0613e | 441 | new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0); |
ccd979bd MF |
442 | if (IS_ERR(new)) { |
443 | status = PTR_ERR(new); | |
444 | mlog_errno(status); | |
445 | goto bail; | |
446 | } | |
447 | osb->root_inode = new; | |
448 | ||
5fa0613e | 449 | new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0); |
ccd979bd MF |
450 | if (IS_ERR(new)) { |
451 | status = PTR_ERR(new); | |
452 | mlog_errno(status); | |
453 | goto bail; | |
454 | } | |
455 | osb->sys_root_inode = new; | |
456 | ||
457 | for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE; | |
458 | i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) { | |
1a224ad1 JK |
459 | if (!ocfs2_need_system_inode(osb, i)) |
460 | continue; | |
ccd979bd MF |
461 | new = ocfs2_get_system_file_inode(osb, i, osb->slot_num); |
462 | if (!new) { | |
463 | ocfs2_release_system_inodes(osb); | |
025bcbde | 464 | status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL; |
ccd979bd | 465 | mlog_errno(status); |
ccd979bd MF |
466 | mlog(ML_ERROR, "Unable to load system inode %d, " |
467 | "possibly corrupt fs?", i); | |
468 | goto bail; | |
469 | } | |
470 | // the array now has one ref, so drop this one | |
471 | iput(new); | |
472 | } | |
473 | ||
474 | bail: | |
c1e8d35e TM |
475 | if (status) |
476 | mlog_errno(status); | |
ccd979bd MF |
477 | return status; |
478 | } | |
479 | ||
480 | static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb) | |
481 | { | |
482 | struct inode *new = NULL; | |
483 | int status = 0; | |
484 | int i; | |
485 | ||
ccd979bd MF |
486 | for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1; |
487 | i < NUM_SYSTEM_INODES; | |
488 | i++) { | |
1a224ad1 JK |
489 | if (!ocfs2_need_system_inode(osb, i)) |
490 | continue; | |
ccd979bd MF |
491 | new = ocfs2_get_system_file_inode(osb, i, osb->slot_num); |
492 | if (!new) { | |
493 | ocfs2_release_system_inodes(osb); | |
025bcbde | 494 | status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL; |
ccd979bd MF |
495 | mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n", |
496 | status, i, osb->slot_num); | |
497 | goto bail; | |
498 | } | |
499 | /* the array now has one ref, so drop this one */ | |
500 | iput(new); | |
501 | } | |
502 | ||
503 | bail: | |
c1e8d35e TM |
504 | if (status) |
505 | mlog_errno(status); | |
ccd979bd MF |
506 | return status; |
507 | } | |
508 | ||
bddb8eb3 | 509 | static void ocfs2_release_system_inodes(struct ocfs2_super *osb) |
ccd979bd | 510 | { |
bddb8eb3 | 511 | int i; |
ccd979bd MF |
512 | struct inode *inode; |
513 | ||
b4d693fc TM |
514 | for (i = 0; i < NUM_GLOBAL_SYSTEM_INODES; i++) { |
515 | inode = osb->global_system_inodes[i]; | |
ccd979bd MF |
516 | if (inode) { |
517 | iput(inode); | |
b4d693fc | 518 | osb->global_system_inodes[i] = NULL; |
ccd979bd MF |
519 | } |
520 | } | |
521 | ||
522 | inode = osb->sys_root_inode; | |
523 | if (inode) { | |
524 | iput(inode); | |
525 | osb->sys_root_inode = NULL; | |
526 | } | |
527 | ||
528 | inode = osb->root_inode; | |
529 | if (inode) { | |
530 | iput(inode); | |
531 | osb->root_inode = NULL; | |
532 | } | |
533 | ||
b4d693fc | 534 | if (!osb->local_system_inodes) |
c1e8d35e | 535 | return; |
b4d693fc TM |
536 | |
537 | for (i = 0; i < NUM_LOCAL_SYSTEM_INODES * osb->max_slots; i++) { | |
538 | if (osb->local_system_inodes[i]) { | |
539 | iput(osb->local_system_inodes[i]); | |
540 | osb->local_system_inodes[i] = NULL; | |
541 | } | |
542 | } | |
543 | ||
544 | kfree(osb->local_system_inodes); | |
545 | osb->local_system_inodes = NULL; | |
ccd979bd MF |
546 | } |
547 | ||
548 | /* We're allocating fs objects, use GFP_NOFS */ | |
549 | static struct inode *ocfs2_alloc_inode(struct super_block *sb) | |
550 | { | |
551 | struct ocfs2_inode_info *oi; | |
552 | ||
fd60b288 | 553 | oi = alloc_inode_sb(sb, ocfs2_inode_cachep, GFP_NOFS); |
ccd979bd MF |
554 | if (!oi) |
555 | return NULL; | |
556 | ||
2931cdcb DW |
557 | oi->i_sync_tid = 0; |
558 | oi->i_datasync_tid = 0; | |
1c92ec67 | 559 | memset(&oi->i_dquot, 0, sizeof(oi->i_dquot)); |
2931cdcb | 560 | |
2b4e30fb | 561 | jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode); |
ccd979bd MF |
562 | return &oi->vfs_inode; |
563 | } | |
564 | ||
e91b9194 | 565 | static void ocfs2_free_inode(struct inode *inode) |
ccd979bd MF |
566 | { |
567 | kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode)); | |
568 | } | |
569 | ||
5a254031 MF |
570 | static unsigned long long ocfs2_max_file_offset(unsigned int bbits, |
571 | unsigned int cbits) | |
ccd979bd | 572 | { |
5a254031 MF |
573 | unsigned int bytes = 1 << cbits; |
574 | unsigned int trim = bytes; | |
575 | unsigned int bitshift = 32; | |
576 | ||
577 | /* | |
578 | * i_size and all block offsets in ocfs2 are always 64 bits | |
579 | * wide. i_clusters is 32 bits, in cluster-sized units. So on | |
580 | * 64 bit platforms, cluster size will be the limiting factor. | |
ccd979bd MF |
581 | */ |
582 | ||
583 | #if BITS_PER_LONG == 32 | |
2ecd05ae | 584 | BUILD_BUG_ON(sizeof(sector_t) != 8); |
5a254031 MF |
585 | /* |
586 | * We might be limited by page cache size. | |
587 | */ | |
09cbfeaf KS |
588 | if (bytes > PAGE_SIZE) { |
589 | bytes = PAGE_SIZE; | |
5a254031 MF |
590 | trim = 1; |
591 | /* | |
592 | * Shift by 31 here so that we don't get larger than | |
593 | * MAX_LFS_FILESIZE | |
594 | */ | |
595 | bitshift = 31; | |
596 | } | |
ccd979bd MF |
597 | #endif |
598 | ||
5a254031 MF |
599 | /* |
600 | * Trim by a whole cluster when we can actually approach the | |
601 | * on-disk limits. Otherwise we can overflow i_clusters when | |
602 | * an extent start is at the max offset. | |
603 | */ | |
604 | return (((unsigned long long)bytes) << bitshift) - trim; | |
ccd979bd MF |
605 | } |
606 | ||
9be53fe6 | 607 | static int ocfs2_reconfigure(struct fs_context *fc) |
ccd979bd MF |
608 | { |
609 | int incompat_features; | |
610 | int ret = 0; | |
9be53fe6 ES |
611 | struct mount_options *parsed_options = fc->fs_private; |
612 | struct super_block *sb = fc->root->d_sb; | |
ccd979bd | 613 | struct ocfs2_super *osb = OCFS2_SB(sb); |
2c442719 | 614 | u32 tmp; |
ccd979bd | 615 | |
02b9984d TT |
616 | sync_filesystem(sb); |
617 | ||
9be53fe6 | 618 | if (!ocfs2_check_set_options(sb, parsed_options)) { |
ccd979bd MF |
619 | ret = -EINVAL; |
620 | goto out; | |
621 | } | |
622 | ||
2c442719 SM |
623 | tmp = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL | |
624 | OCFS2_MOUNT_HB_NONE; | |
9be53fe6 | 625 | if ((osb->s_mount_opt & tmp) != (parsed_options->mount_opt & tmp)) { |
ccd979bd MF |
626 | ret = -EINVAL; |
627 | mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n"); | |
628 | goto out; | |
629 | } | |
630 | ||
631 | if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) != | |
9be53fe6 | 632 | (parsed_options->mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) { |
ccd979bd MF |
633 | ret = -EINVAL; |
634 | mlog(ML_ERROR, "Cannot change data mode on remount\n"); | |
635 | goto out; | |
636 | } | |
637 | ||
12462f1d JB |
638 | /* Probably don't want this on remount; it might |
639 | * mess with other nodes */ | |
640 | if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) && | |
9be53fe6 | 641 | (parsed_options->mount_opt & OCFS2_MOUNT_INODE64)) { |
12462f1d JB |
642 | ret = -EINVAL; |
643 | mlog(ML_ERROR, "Cannot enable inode64 on remount\n"); | |
644 | goto out; | |
645 | } | |
646 | ||
ccd979bd | 647 | /* We're going to/from readonly mode. */ |
9be53fe6 | 648 | if ((bool)(fc->sb_flags & SB_RDONLY) != sb_rdonly(sb)) { |
19ece546 | 649 | /* Disable quota accounting before remounting RO */ |
9be53fe6 | 650 | if (fc->sb_flags & SB_RDONLY) { |
19ece546 JK |
651 | ret = ocfs2_susp_quotas(osb, 0); |
652 | if (ret < 0) | |
653 | goto out; | |
654 | } | |
ccd979bd MF |
655 | /* Lock here so the check of HARD_RO and the potential |
656 | * setting of SOFT_RO is atomic. */ | |
657 | spin_lock(&osb->osb_lock); | |
658 | if (osb->osb_flags & OCFS2_OSB_HARD_RO) { | |
659 | mlog(ML_ERROR, "Remount on readonly device is forbidden.\n"); | |
660 | ret = -EROFS; | |
661 | goto unlock_osb; | |
662 | } | |
663 | ||
9be53fe6 | 664 | if (fc->sb_flags & SB_RDONLY) { |
1751e8a6 | 665 | sb->s_flags |= SB_RDONLY; |
ccd979bd MF |
666 | osb->osb_flags |= OCFS2_OSB_SOFT_RO; |
667 | } else { | |
ccd979bd MF |
668 | if (osb->osb_flags & OCFS2_OSB_ERROR_FS) { |
669 | mlog(ML_ERROR, "Cannot remount RDWR " | |
670 | "filesystem due to previous errors.\n"); | |
671 | ret = -EROFS; | |
672 | goto unlock_osb; | |
673 | } | |
674 | incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP); | |
675 | if (incompat_features) { | |
676 | mlog(ML_ERROR, "Cannot remount RDWR because " | |
677 | "of unsupported optional features " | |
678 | "(%x).\n", incompat_features); | |
679 | ret = -EINVAL; | |
680 | goto unlock_osb; | |
681 | } | |
1751e8a6 | 682 | sb->s_flags &= ~SB_RDONLY; |
ccd979bd MF |
683 | osb->osb_flags &= ~OCFS2_OSB_SOFT_RO; |
684 | } | |
9be53fe6 | 685 | trace_ocfs2_remount(sb->s_flags, osb->osb_flags, fc->sb_flags); |
ccd979bd MF |
686 | unlock_osb: |
687 | spin_unlock(&osb->osb_lock); | |
19ece546 | 688 | /* Enable quota accounting after remounting RW */ |
9be53fe6 | 689 | if (!ret && !(fc->sb_flags & SB_RDONLY)) { |
19ece546 JK |
690 | if (sb_any_quota_suspended(sb)) |
691 | ret = ocfs2_susp_quotas(osb, 1); | |
692 | else | |
693 | ret = ocfs2_enable_quotas(osb); | |
694 | if (ret < 0) { | |
695 | /* Return back changes... */ | |
696 | spin_lock(&osb->osb_lock); | |
1751e8a6 | 697 | sb->s_flags |= SB_RDONLY; |
19ece546 JK |
698 | osb->osb_flags |= OCFS2_OSB_SOFT_RO; |
699 | spin_unlock(&osb->osb_lock); | |
700 | goto out; | |
701 | } | |
702 | } | |
ccd979bd MF |
703 | } |
704 | ||
705 | if (!ret) { | |
ccd979bd MF |
706 | /* Only save off the new mount options in case of a successful |
707 | * remount. */ | |
9be53fe6 ES |
708 | osb->s_mount_opt = parsed_options->mount_opt; |
709 | osb->s_atime_quantum = parsed_options->atime_quantum; | |
710 | osb->preferred_slot = parsed_options->slot; | |
711 | if (parsed_options->commit_interval) | |
712 | osb->osb_commit_interval = parsed_options->commit_interval; | |
e001e796 MF |
713 | |
714 | if (!ocfs2_is_hard_readonly(osb)) | |
715 | ocfs2_set_journal_params(osb); | |
57b09bb5 | 716 | |
1751e8a6 | 717 | sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | |
57b09bb5 | 718 | ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? |
1751e8a6 | 719 | SB_POSIXACL : 0); |
ccd979bd MF |
720 | } |
721 | out: | |
722 | return ret; | |
723 | } | |
724 | ||
725 | static int ocfs2_sb_probe(struct super_block *sb, | |
726 | struct buffer_head **bh, | |
73be192b JB |
727 | int *sector_size, |
728 | struct ocfs2_blockcheck_stats *stats) | |
ccd979bd | 729 | { |
bddb8eb3 | 730 | int status, tmpstat; |
ccd979bd MF |
731 | struct ocfs1_vol_disk_hdr *hdr; |
732 | struct ocfs2_dinode *di; | |
733 | int blksize; | |
734 | ||
735 | *bh = NULL; | |
736 | ||
737 | /* may be > 512 */ | |
e1defc4f | 738 | *sector_size = bdev_logical_block_size(sb->s_bdev); |
ccd979bd MF |
739 | if (*sector_size > OCFS2_MAX_BLOCKSIZE) { |
740 | mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n", | |
741 | *sector_size, OCFS2_MAX_BLOCKSIZE); | |
742 | status = -EINVAL; | |
743 | goto bail; | |
744 | } | |
745 | ||
746 | /* Can this really happen? */ | |
747 | if (*sector_size < OCFS2_MIN_BLOCKSIZE) | |
748 | *sector_size = OCFS2_MIN_BLOCKSIZE; | |
749 | ||
750 | /* check block zero for old format */ | |
751 | status = ocfs2_get_sector(sb, bh, 0, *sector_size); | |
752 | if (status < 0) { | |
753 | mlog_errno(status); | |
754 | goto bail; | |
755 | } | |
756 | hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data; | |
757 | if (hdr->major_version == OCFS1_MAJOR_VERSION) { | |
758 | mlog(ML_ERROR, "incompatible version: %u.%u\n", | |
759 | hdr->major_version, hdr->minor_version); | |
760 | status = -EINVAL; | |
761 | } | |
762 | if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE, | |
763 | strlen(OCFS1_VOLUME_SIGNATURE)) == 0) { | |
764 | mlog(ML_ERROR, "incompatible volume signature: %8s\n", | |
765 | hdr->signature); | |
766 | status = -EINVAL; | |
767 | } | |
768 | brelse(*bh); | |
769 | *bh = NULL; | |
770 | if (status < 0) { | |
771 | mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be " | |
772 | "upgraded before mounting with ocfs v2\n"); | |
773 | goto bail; | |
774 | } | |
775 | ||
776 | /* | |
777 | * Now check at magic offset for 512, 1024, 2048, 4096 | |
778 | * blocksizes. 4096 is the maximum blocksize because it is | |
779 | * the minimum clustersize. | |
780 | */ | |
781 | status = -EINVAL; | |
782 | for (blksize = *sector_size; | |
783 | blksize <= OCFS2_MAX_BLOCKSIZE; | |
784 | blksize <<= 1) { | |
785 | tmpstat = ocfs2_get_sector(sb, bh, | |
786 | OCFS2_SUPER_BLOCK_BLKNO, | |
787 | blksize); | |
788 | if (tmpstat < 0) { | |
789 | status = tmpstat; | |
790 | mlog_errno(status); | |
fb5cbe9e | 791 | break; |
ccd979bd MF |
792 | } |
793 | di = (struct ocfs2_dinode *) (*bh)->b_data; | |
73be192b | 794 | memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats)); |
1c1d9793 | 795 | spin_lock_init(&stats->b_lock); |
fb5cbe9e JB |
796 | tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats); |
797 | if (tmpstat < 0) { | |
798 | brelse(*bh); | |
799 | *bh = NULL; | |
800 | } | |
801 | if (tmpstat != -EAGAIN) { | |
802 | status = tmpstat; | |
ccd979bd | 803 | break; |
fb5cbe9e | 804 | } |
ccd979bd MF |
805 | } |
806 | ||
807 | bail: | |
808 | return status; | |
809 | } | |
810 | ||
c271c5c2 SM |
811 | static int ocfs2_verify_heartbeat(struct ocfs2_super *osb) |
812 | { | |
2c442719 SM |
813 | u32 hb_enabled = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL; |
814 | ||
815 | if (osb->s_mount_opt & hb_enabled) { | |
816 | if (ocfs2_mount_local(osb)) { | |
c271c5c2 SM |
817 | mlog(ML_ERROR, "Cannot heartbeat on a locally " |
818 | "mounted device.\n"); | |
819 | return -EINVAL; | |
820 | } | |
2c442719 | 821 | if (ocfs2_userspace_stack(osb)) { |
b61817e1 JB |
822 | mlog(ML_ERROR, "Userspace stack expected, but " |
823 | "o2cb heartbeat arguments passed to mount\n"); | |
824 | return -EINVAL; | |
825 | } | |
2c442719 SM |
826 | if (((osb->s_mount_opt & OCFS2_MOUNT_HB_GLOBAL) && |
827 | !ocfs2_cluster_o2cb_global_heartbeat(osb)) || | |
828 | ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) && | |
829 | ocfs2_cluster_o2cb_global_heartbeat(osb))) { | |
830 | mlog(ML_ERROR, "Mismatching o2cb heartbeat modes\n"); | |
831 | return -EINVAL; | |
832 | } | |
b61817e1 JB |
833 | } |
834 | ||
2c442719 | 835 | if (!(osb->s_mount_opt & hb_enabled)) { |
b61817e1 JB |
836 | if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) && |
837 | !ocfs2_userspace_stack(osb)) { | |
c271c5c2 SM |
838 | mlog(ML_ERROR, "Heartbeat has to be started to mount " |
839 | "a read-write clustered device.\n"); | |
840 | return -EINVAL; | |
841 | } | |
842 | } | |
843 | ||
844 | return 0; | |
845 | } | |
846 | ||
b61817e1 JB |
847 | /* |
848 | * If we're using a userspace stack, mount should have passed | |
849 | * a name that matches the disk. If not, mount should not | |
850 | * have passed a stack. | |
851 | */ | |
852 | static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb, | |
853 | struct mount_options *mopt) | |
854 | { | |
855 | if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) { | |
856 | mlog(ML_ERROR, | |
857 | "cluster stack passed to mount, but this filesystem " | |
858 | "does not support it\n"); | |
859 | return -EINVAL; | |
860 | } | |
861 | ||
862 | if (ocfs2_userspace_stack(osb) && | |
863 | strncmp(osb->osb_cluster_stack, mopt->cluster_stack, | |
864 | OCFS2_STACK_LABEL_LEN)) { | |
865 | mlog(ML_ERROR, | |
866 | "cluster stack passed to mount (\"%s\") does not " | |
867 | "match the filesystem (\"%s\")\n", | |
868 | mopt->cluster_stack, | |
869 | osb->osb_cluster_stack); | |
870 | return -EINVAL; | |
871 | } | |
872 | ||
873 | return 0; | |
874 | } | |
875 | ||
19ece546 JK |
876 | static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend) |
877 | { | |
878 | int type; | |
879 | struct super_block *sb = osb->sb; | |
52362810 JK |
880 | unsigned int feature[OCFS2_MAXQUOTAS] = { |
881 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA, | |
882 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA}; | |
19ece546 JK |
883 | int status = 0; |
884 | ||
52362810 | 885 | for (type = 0; type < OCFS2_MAXQUOTAS; type++) { |
19ece546 JK |
886 | if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type])) |
887 | continue; | |
888 | if (unsuspend) | |
0f0dd62f | 889 | status = dquot_resume(sb, type); |
eea7feb0 JK |
890 | else { |
891 | struct ocfs2_mem_dqinfo *oinfo; | |
892 | ||
893 | /* Cancel periodic syncing before suspending */ | |
894 | oinfo = sb_dqinfo(sb, type)->dqi_priv; | |
895 | cancel_delayed_work_sync(&oinfo->dqi_sync_work); | |
0f0dd62f | 896 | status = dquot_suspend(sb, type); |
eea7feb0 | 897 | } |
19ece546 JK |
898 | if (status < 0) |
899 | break; | |
900 | } | |
901 | if (status < 0) | |
902 | mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on " | |
903 | "remount (error = %d).\n", status); | |
904 | return status; | |
905 | } | |
906 | ||
907 | static int ocfs2_enable_quotas(struct ocfs2_super *osb) | |
908 | { | |
52362810 | 909 | struct inode *inode[OCFS2_MAXQUOTAS] = { NULL, NULL }; |
19ece546 | 910 | struct super_block *sb = osb->sb; |
52362810 JK |
911 | unsigned int feature[OCFS2_MAXQUOTAS] = { |
912 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA, | |
913 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA}; | |
914 | unsigned int ino[OCFS2_MAXQUOTAS] = { | |
915 | LOCAL_USER_QUOTA_SYSTEM_INODE, | |
19ece546 JK |
916 | LOCAL_GROUP_QUOTA_SYSTEM_INODE }; |
917 | int status; | |
918 | int type; | |
919 | ||
920 | sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE; | |
52362810 | 921 | for (type = 0; type < OCFS2_MAXQUOTAS; type++) { |
19ece546 JK |
922 | if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type])) |
923 | continue; | |
924 | inode[type] = ocfs2_get_system_file_inode(osb, ino[type], | |
925 | osb->slot_num); | |
926 | if (!inode[type]) { | |
927 | status = -ENOENT; | |
928 | goto out_quota_off; | |
929 | } | |
7212b95e JK |
930 | status = dquot_load_quota_inode(inode[type], type, QFMT_OCFS2, |
931 | DQUOT_USAGE_ENABLED); | |
19ece546 JK |
932 | if (status < 0) |
933 | goto out_quota_off; | |
934 | } | |
935 | ||
52362810 | 936 | for (type = 0; type < OCFS2_MAXQUOTAS; type++) |
19ece546 JK |
937 | iput(inode[type]); |
938 | return 0; | |
939 | out_quota_off: | |
940 | ocfs2_disable_quotas(osb); | |
52362810 | 941 | for (type = 0; type < OCFS2_MAXQUOTAS; type++) |
19ece546 JK |
942 | iput(inode[type]); |
943 | mlog_errno(status); | |
944 | return status; | |
945 | } | |
946 | ||
947 | static void ocfs2_disable_quotas(struct ocfs2_super *osb) | |
948 | { | |
949 | int type; | |
950 | struct inode *inode; | |
951 | struct super_block *sb = osb->sb; | |
c06bcbfa | 952 | struct ocfs2_mem_dqinfo *oinfo; |
19ece546 JK |
953 | |
954 | /* We mostly ignore errors in this function because there's not much | |
955 | * we can do when we see them */ | |
52362810 | 956 | for (type = 0; type < OCFS2_MAXQUOTAS; type++) { |
19ece546 JK |
957 | if (!sb_has_quota_loaded(sb, type)) |
958 | continue; | |
50d92788 LH |
959 | if (!sb_has_quota_suspended(sb, type)) { |
960 | oinfo = sb_dqinfo(sb, type)->dqi_priv; | |
961 | cancel_delayed_work_sync(&oinfo->dqi_sync_work); | |
962 | } | |
19ece546 JK |
963 | inode = igrab(sb->s_dquot.files[type]); |
964 | /* Turn off quotas. This will remove all dquot structures from | |
965 | * memory and so they will be automatically synced to global | |
966 | * quota files */ | |
0f0dd62f CH |
967 | dquot_disable(sb, type, DQUOT_USAGE_ENABLED | |
968 | DQUOT_LIMITS_ENABLED); | |
19ece546 JK |
969 | iput(inode); |
970 | } | |
971 | } | |
972 | ||
9be53fe6 | 973 | static int ocfs2_fill_super(struct super_block *sb, struct fs_context *fc) |
ccd979bd MF |
974 | { |
975 | struct dentry *root; | |
976 | int status, sector_size; | |
9be53fe6 | 977 | struct mount_options *parsed_options = fc->fs_private; |
ccd979bd MF |
978 | struct inode *inode = NULL; |
979 | struct ocfs2_super *osb = NULL; | |
980 | struct buffer_head *bh = NULL; | |
49fa8140 | 981 | char nodestr[12]; |
73be192b | 982 | struct ocfs2_blockcheck_stats stats; |
ccd979bd | 983 | |
9be53fe6 | 984 | trace_ocfs2_fill_super(sb, fc, fc->sb_flags & SB_SILENT); |
ccd979bd MF |
985 | |
986 | /* probe for superblock */ | |
73be192b | 987 | status = ocfs2_sb_probe(sb, &bh, §or_size, &stats); |
ccd979bd MF |
988 | if (status < 0) { |
989 | mlog(ML_ERROR, "superblock probe failed!\n"); | |
f1e75d12 | 990 | goto out; |
ccd979bd MF |
991 | } |
992 | ||
73be192b | 993 | status = ocfs2_initialize_super(sb, bh, sector_size, &stats); |
ccd979bd MF |
994 | brelse(bh); |
995 | bh = NULL; | |
f1e75d12 HZO |
996 | if (status < 0) |
997 | goto out; | |
998 | ||
999 | osb = OCFS2_SB(sb); | |
a68979b8 | 1000 | |
9be53fe6 | 1001 | if (!ocfs2_check_set_options(sb, parsed_options)) { |
5297aad8 | 1002 | status = -EINVAL; |
f1e75d12 | 1003 | goto out_super; |
5297aad8 | 1004 | } |
9be53fe6 ES |
1005 | osb->s_mount_opt = parsed_options->mount_opt; |
1006 | osb->s_atime_quantum = parsed_options->atime_quantum; | |
1007 | osb->preferred_slot = parsed_options->slot; | |
1008 | osb->osb_commit_interval = parsed_options->commit_interval; | |
1009 | ||
1010 | ocfs2_la_set_sizes(osb, parsed_options->localalloc_opt); | |
1011 | osb->osb_resv_level = parsed_options->resv_level; | |
1012 | osb->osb_dir_resv_level = parsed_options->resv_level; | |
1013 | if (parsed_options->dir_resv_level == -1) | |
1014 | osb->osb_dir_resv_level = parsed_options->resv_level; | |
83f92318 | 1015 | else |
9be53fe6 | 1016 | osb->osb_dir_resv_level = parsed_options->dir_resv_level; |
ccd979bd | 1017 | |
9be53fe6 | 1018 | status = ocfs2_verify_userspace_stack(osb, parsed_options); |
b61817e1 | 1019 | if (status) |
f1e75d12 | 1020 | goto out_super; |
b61817e1 | 1021 | |
ccd979bd MF |
1022 | sb->s_magic = OCFS2_SUPER_MAGIC; |
1023 | ||
1751e8a6 LT |
1024 | sb->s_flags = (sb->s_flags & ~(SB_POSIXACL | SB_NOSEC)) | |
1025 | ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0); | |
a68979b8 | 1026 | |
1751e8a6 | 1027 | /* Hard readonly mode only if: bdev_read_only, SB_RDONLY, |
ccd979bd MF |
1028 | * heartbeat=none */ |
1029 | if (bdev_read_only(sb->s_bdev)) { | |
bc98a42c | 1030 | if (!sb_rdonly(sb)) { |
ccd979bd MF |
1031 | status = -EACCES; |
1032 | mlog(ML_ERROR, "Readonly device detected but readonly " | |
1033 | "mount was not specified.\n"); | |
f1e75d12 | 1034 | goto out_super; |
ccd979bd MF |
1035 | } |
1036 | ||
1037 | /* You should not be able to start a local heartbeat | |
1038 | * on a readonly device. */ | |
1039 | if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) { | |
1040 | status = -EROFS; | |
1041 | mlog(ML_ERROR, "Local heartbeat specified on readonly " | |
1042 | "device.\n"); | |
f1e75d12 | 1043 | goto out_super; |
ccd979bd MF |
1044 | } |
1045 | ||
1046 | status = ocfs2_check_journals_nolocks(osb); | |
1047 | if (status < 0) { | |
1048 | if (status == -EROFS) | |
1049 | mlog(ML_ERROR, "Recovery required on readonly " | |
1050 | "file system, but write access is " | |
1051 | "unavailable.\n"); | |
f1e75d12 | 1052 | goto out_super; |
ccd979bd MF |
1053 | } |
1054 | ||
1055 | ocfs2_set_ro_flag(osb, 1); | |
1056 | ||
619c200d SM |
1057 | printk(KERN_NOTICE "ocfs2: Readonly device (%s) detected. " |
1058 | "Cluster services will not be used for this mount. " | |
1059 | "Recovery will be skipped.\n", osb->dev_str); | |
ccd979bd MF |
1060 | } |
1061 | ||
1062 | if (!ocfs2_is_hard_readonly(osb)) { | |
bc98a42c | 1063 | if (sb_rdonly(sb)) |
ccd979bd MF |
1064 | ocfs2_set_ro_flag(osb, 0); |
1065 | } | |
1066 | ||
c271c5c2 | 1067 | status = ocfs2_verify_heartbeat(osb); |
f1e75d12 HZO |
1068 | if (status < 0) |
1069 | goto out_super; | |
c271c5c2 | 1070 | |
ccd979bd MF |
1071 | osb->osb_debug_root = debugfs_create_dir(osb->uuid_str, |
1072 | ocfs2_debugfs_root); | |
ccd979bd | 1073 | |
5e7a3ed9 GKH |
1074 | debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root, |
1075 | osb, &ocfs2_osb_debug_fops); | |
50397507 | 1076 | |
685d03c3 JQ |
1077 | if (ocfs2_meta_ecc(osb)) { |
1078 | ocfs2_initialize_journal_triggers(sb, osb->s_journal_triggers); | |
e581595e GKH |
1079 | ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats, |
1080 | osb->osb_debug_root); | |
685d03c3 | 1081 | } |
73be192b | 1082 | |
ccd979bd | 1083 | status = ocfs2_mount_volume(sb); |
ccd979bd | 1084 | if (status < 0) |
f1e75d12 | 1085 | goto out_debugfs; |
ccd979bd | 1086 | |
be0d93f0 AV |
1087 | if (osb->root_inode) |
1088 | inode = igrab(osb->root_inode); | |
1089 | ||
ccd979bd MF |
1090 | if (!inode) { |
1091 | status = -EIO; | |
f1e75d12 | 1092 | goto out_dismount; |
ccd979bd MF |
1093 | } |
1094 | ||
5f483c4a GH |
1095 | osb->osb_dev_kset = kset_create_and_add(sb->s_id, NULL, |
1096 | &ocfs2_kset->kobj); | |
1097 | if (!osb->osb_dev_kset) { | |
1098 | status = -ENOMEM; | |
1099 | mlog(ML_ERROR, "Unable to create device kset %s.\n", sb->s_id); | |
f1e75d12 | 1100 | goto out_dismount; |
5f483c4a GH |
1101 | } |
1102 | ||
1103 | /* Create filecheck sysfs related directories/files at | |
1104 | * /sys/fs/ocfs2/<devname>/filecheck */ | |
1105 | if (ocfs2_filecheck_create_sysfs(osb)) { | |
1106 | status = -ENOMEM; | |
1107 | mlog(ML_ERROR, "Unable to create filecheck sysfs directory at " | |
1108 | "/sys/fs/ocfs2/%s/filecheck.\n", sb->s_id); | |
f1e75d12 | 1109 | goto out_dismount; |
5f483c4a GH |
1110 | } |
1111 | ||
7b0b1332 JQ |
1112 | root = d_make_root(inode); |
1113 | if (!root) { | |
1114 | status = -ENOMEM; | |
f1e75d12 | 1115 | goto out_dismount; |
7b0b1332 JQ |
1116 | } |
1117 | ||
1118 | sb->s_root = root; | |
1119 | ||
1120 | ocfs2_complete_mount_recovery(osb); | |
1121 | ||
c271c5c2 SM |
1122 | if (ocfs2_mount_local(osb)) |
1123 | snprintf(nodestr, sizeof(nodestr), "local"); | |
1124 | else | |
19fdb624 | 1125 | snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num); |
c271c5c2 SM |
1126 | |
1127 | printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) " | |
781ee3e2 | 1128 | "with %s data mode.\n", |
c271c5c2 | 1129 | osb->dev_str, nodestr, osb->slot_num, |
ccd979bd MF |
1130 | osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" : |
1131 | "ordered"); | |
1132 | ||
1133 | atomic_set(&osb->vol_state, VOLUME_MOUNTED); | |
1134 | wake_up(&osb->osb_mount_event); | |
1135 | ||
19ece546 JK |
1136 | /* Now we can initialize quotas because we can afford to wait |
1137 | * for cluster locks recovery now. That also means that truncation | |
1138 | * log recovery can happen but that waits for proper quota setup */ | |
bc98a42c | 1139 | if (!sb_rdonly(sb)) { |
19ece546 JK |
1140 | status = ocfs2_enable_quotas(osb); |
1141 | if (status < 0) { | |
1142 | /* We have to err-out specially here because | |
1143 | * s_root is already set */ | |
1144 | mlog_errno(status); | |
1145 | atomic_set(&osb->vol_state, VOLUME_DISABLED); | |
1146 | wake_up(&osb->osb_mount_event); | |
19ece546 JK |
1147 | return status; |
1148 | } | |
1149 | } | |
1150 | ||
1151 | ocfs2_complete_quota_recovery(osb); | |
1152 | ||
1153 | /* Now we wake up again for processes waiting for quotas */ | |
1154 | atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS); | |
1155 | wake_up(&osb->osb_mount_event); | |
1156 | ||
df152c24 | 1157 | /* Start this when the mount is almost sure of being successful */ |
8b712cd5 | 1158 | ocfs2_orphan_scan_start(osb); |
df152c24 | 1159 | |
ccd979bd MF |
1160 | return status; |
1161 | ||
f1e75d12 HZO |
1162 | out_dismount: |
1163 | atomic_set(&osb->vol_state, VOLUME_DISABLED); | |
1164 | wake_up(&osb->osb_mount_event); | |
ce2fcf15 | 1165 | ocfs2_free_replay_slots(osb); |
f1e75d12 HZO |
1166 | ocfs2_dismount_volume(sb, 1); |
1167 | goto out; | |
1168 | ||
1169 | out_debugfs: | |
1170 | debugfs_remove_recursive(osb->osb_debug_root); | |
1171 | out_super: | |
1172 | ocfs2_release_system_inodes(osb); | |
1173 | kfree(osb->recovery_map); | |
1174 | ocfs2_delete_osb(osb); | |
1175 | kfree(osb); | |
1176 | out: | |
1177 | mlog_errno(status); | |
ccd979bd | 1178 | |
ccd979bd MF |
1179 | return status; |
1180 | } | |
1181 | ||
9be53fe6 ES |
1182 | static int ocfs2_get_tree(struct fs_context *fc) |
1183 | { | |
1184 | return get_tree_bdev(fc, ocfs2_fill_super); | |
1185 | } | |
1186 | ||
1187 | static void ocfs2_free_fc(struct fs_context *fc) | |
1188 | { | |
1189 | kfree(fc->fs_private); | |
1190 | } | |
1191 | ||
1192 | static const struct fs_context_operations ocfs2_context_ops = { | |
1193 | .parse_param = ocfs2_parse_param, | |
1194 | .get_tree = ocfs2_get_tree, | |
1195 | .reconfigure = ocfs2_reconfigure, | |
1196 | .free = ocfs2_free_fc, | |
1197 | }; | |
1198 | ||
1199 | static int ocfs2_init_fs_context(struct fs_context *fc) | |
ccd979bd | 1200 | { |
9be53fe6 ES |
1201 | struct mount_options *mopt; |
1202 | ||
1203 | mopt = kzalloc(sizeof(struct mount_options), GFP_KERNEL); | |
1204 | if (!mopt) | |
1205 | return -EINVAL; | |
1206 | ||
1207 | mopt->commit_interval = 0; | |
1208 | mopt->mount_opt = OCFS2_MOUNT_NOINTR; | |
1209 | mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM; | |
1210 | mopt->slot = OCFS2_INVALID_SLOT; | |
1211 | mopt->localalloc_opt = -1; | |
1212 | mopt->cluster_stack[0] = '\0'; | |
1213 | mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL; | |
1214 | mopt->dir_resv_level = -1; | |
1215 | ||
1216 | fc->fs_private = mopt; | |
1217 | fc->ops = &ocfs2_context_ops; | |
1218 | ||
1219 | return 0; | |
ccd979bd MF |
1220 | } |
1221 | ||
1222 | static struct file_system_type ocfs2_fs_type = { | |
1223 | .owner = THIS_MODULE, | |
1224 | .name = "ocfs2", | |
8ed6b237 | 1225 | .kill_sb = kill_block_super, |
1ba9da2f | 1226 | .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE, |
9be53fe6 ES |
1227 | .next = NULL, |
1228 | .init_fs_context = ocfs2_init_fs_context, | |
1229 | .parameters = ocfs2_param_spec, | |
ccd979bd | 1230 | }; |
91417705 | 1231 | MODULE_ALIAS_FS("ocfs2"); |
ccd979bd | 1232 | |
5297aad8 JK |
1233 | static int ocfs2_check_set_options(struct super_block *sb, |
1234 | struct mount_options *options) | |
1235 | { | |
9be53fe6 ES |
1236 | if (options->user_stack == 0) { |
1237 | u32 tmp; | |
1238 | ||
1239 | /* Ensure only one heartbeat mode */ | |
1240 | tmp = options->mount_opt & (OCFS2_MOUNT_HB_LOCAL | | |
1241 | OCFS2_MOUNT_HB_GLOBAL | | |
1242 | OCFS2_MOUNT_HB_NONE); | |
1243 | if (hweight32(tmp) != 1) { | |
1244 | mlog(ML_ERROR, "Invalid heartbeat mount options\n"); | |
1245 | return 0; | |
1246 | } | |
1247 | } | |
5297aad8 JK |
1248 | if (options->mount_opt & OCFS2_MOUNT_USRQUOTA && |
1249 | !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | |
1250 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) { | |
1251 | mlog(ML_ERROR, "User quotas were requested, but this " | |
1252 | "filesystem does not have the feature enabled.\n"); | |
1253 | return 0; | |
1254 | } | |
1255 | if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA && | |
1256 | !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | |
1257 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) { | |
1258 | mlog(ML_ERROR, "Group quotas were requested, but this " | |
1259 | "filesystem does not have the feature enabled.\n"); | |
1260 | return 0; | |
1261 | } | |
1262 | if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL && | |
1263 | !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) { | |
1264 | mlog(ML_ERROR, "ACL support requested but extended attributes " | |
1265 | "feature is not enabled\n"); | |
1266 | return 0; | |
1267 | } | |
1268 | /* No ACL setting specified? Use XATTR feature... */ | |
1269 | if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL | | |
1270 | OCFS2_MOUNT_NO_POSIX_ACL))) { | |
1271 | if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) | |
1272 | options->mount_opt |= OCFS2_MOUNT_POSIX_ACL; | |
1273 | else | |
1274 | options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL; | |
1275 | } | |
1276 | return 1; | |
1277 | } | |
1278 | ||
9be53fe6 | 1279 | static int ocfs2_parse_param(struct fs_context *fc, struct fs_parameter *param) |
ccd979bd | 1280 | { |
9be53fe6 ES |
1281 | struct fs_parse_result result; |
1282 | int opt; | |
1283 | struct mount_options *mopt = fc->fs_private; | |
1284 | bool is_remount = (fc->purpose & FS_CONTEXT_FOR_RECONFIGURE); | |
1285 | ||
1286 | trace_ocfs2_parse_options(is_remount, param->key); | |
1287 | ||
1288 | opt = fs_parse(fc, ocfs2_param_spec, param, &result); | |
1289 | if (opt < 0) | |
1290 | return opt; | |
1291 | ||
1292 | switch (opt) { | |
1293 | case Opt_heartbeat: | |
1294 | mopt->mount_opt |= result.uint_32; | |
1295 | break; | |
1296 | case Opt_barrier: | |
1297 | if (result.uint_32) | |
1298 | mopt->mount_opt |= OCFS2_MOUNT_BARRIER; | |
1299 | else | |
1300 | mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER; | |
1301 | break; | |
1302 | case Opt_intr: | |
1303 | if (result.negated) | |
c0123ade | 1304 | mopt->mount_opt |= OCFS2_MOUNT_NOINTR; |
9be53fe6 ES |
1305 | else |
1306 | mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR; | |
1307 | break; | |
1308 | case Opt_errors: | |
1309 | mopt->mount_opt &= ~(OCFS2_MOUNT_ERRORS_CONT | | |
1310 | OCFS2_MOUNT_ERRORS_ROFS | | |
1311 | OCFS2_MOUNT_ERRORS_PANIC); | |
1312 | mopt->mount_opt |= result.uint_32; | |
1313 | break; | |
1314 | case Opt_data: | |
1315 | mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK; | |
1316 | mopt->mount_opt |= result.uint_32; | |
1317 | break; | |
1318 | case Opt_user_xattr: | |
1319 | if (result.negated) | |
cf1d6c76 | 1320 | mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR; |
9be53fe6 ES |
1321 | else |
1322 | mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR; | |
1323 | break; | |
1324 | case Opt_atime_quantum: | |
1325 | mopt->atime_quantum = result.uint_32; | |
1326 | break; | |
1327 | case Opt_slot: | |
1328 | if (result.uint_32) | |
1329 | mopt->slot = (u16)result.uint_32; | |
1330 | break; | |
1331 | case Opt_commit: | |
1332 | if (result.uint_32 == 0) | |
1333 | mopt->commit_interval = HZ * JBD2_DEFAULT_MAX_COMMIT_AGE; | |
1334 | else | |
1335 | mopt->commit_interval = HZ * result.uint_32; | |
1336 | break; | |
1337 | case Opt_localalloc: | |
1338 | if (result.int_32 >= 0) | |
1339 | mopt->localalloc_opt = result.int_32; | |
1340 | break; | |
1341 | case Opt_localflocks: | |
1342 | /* | |
1343 | * Changing this during remount could race flock() requests, or | |
1344 | * "unbalance" existing ones (e.g., a lock is taken in one mode | |
1345 | * but dropped in the other). If users care enough to flip | |
1346 | * locking modes during remount, we could add a "local" flag to | |
1347 | * individual flock structures for proper tracking of state. | |
1348 | */ | |
1349 | if (!is_remount) | |
1350 | mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS; | |
1351 | break; | |
1352 | case Opt_stack: | |
1353 | /* Check both that the option we were passed is of the right | |
1354 | * length and that it is a proper string of the right length. | |
1355 | */ | |
1356 | if (strlen(param->string) != OCFS2_STACK_LABEL_LEN) { | |
1357 | mlog(ML_ERROR, "Invalid cluster_stack option\n"); | |
1358 | return -EINVAL; | |
1359 | } | |
1360 | memcpy(mopt->cluster_stack, param->string, OCFS2_STACK_LABEL_LEN); | |
1361 | mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0'; | |
1362 | /* | |
1363 | * Open code the memcmp here as we don't have an osb to pass | |
1364 | * to ocfs2_userspace_stack(). | |
1365 | */ | |
1366 | if (memcmp(mopt->cluster_stack, | |
1367 | OCFS2_CLASSIC_CLUSTER_STACK, | |
1368 | OCFS2_STACK_LABEL_LEN)) | |
1369 | mopt->user_stack = 1; | |
1370 | break; | |
1371 | case Opt_inode64: | |
1372 | mopt->mount_opt |= OCFS2_MOUNT_INODE64; | |
1373 | break; | |
1374 | case Opt_usrquota: | |
1375 | mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA; | |
1376 | break; | |
1377 | case Opt_grpquota: | |
1378 | mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA; | |
1379 | break; | |
1380 | case Opt_coherency: | |
1381 | mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED; | |
1382 | mopt->mount_opt |= result.uint_32; | |
1383 | break; | |
1384 | case Opt_acl: | |
1385 | if (result.negated) { | |
5297aad8 | 1386 | mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL; |
a68979b8 | 1387 | mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; |
9be53fe6 ES |
1388 | } else { |
1389 | mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL; | |
1390 | mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL; | |
1391 | } | |
1392 | break; | |
1393 | case Opt_resv_level: | |
1394 | if (is_remount) | |
a68979b8 | 1395 | break; |
9be53fe6 ES |
1396 | if (result.uint_32 >= OCFS2_MIN_RESV_LEVEL && |
1397 | result.uint_32 < OCFS2_MAX_RESV_LEVEL) | |
1398 | mopt->resv_level = result.uint_32; | |
1399 | break; | |
1400 | case Opt_dir_resv_level: | |
1401 | if (is_remount) | |
1dfeb768 | 1402 | break; |
9be53fe6 ES |
1403 | if (result.uint_32 >= OCFS2_MIN_RESV_LEVEL && |
1404 | result.uint_32 < OCFS2_MAX_RESV_LEVEL) | |
1405 | mopt->dir_resv_level = result.uint_32; | |
1406 | break; | |
1407 | case Opt_journal_async_commit: | |
1408 | mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT; | |
1409 | break; | |
1410 | default: | |
1411 | return -EINVAL; | |
2c442719 SM |
1412 | } |
1413 | ||
9be53fe6 | 1414 | return 0; |
ccd979bd MF |
1415 | } |
1416 | ||
34c80b1d | 1417 | static int ocfs2_show_options(struct seq_file *s, struct dentry *root) |
d550071c | 1418 | { |
34c80b1d | 1419 | struct ocfs2_super *osb = OCFS2_SB(root->d_sb); |
d550071c | 1420 | unsigned long opts = osb->s_mount_opt; |
ebcee4b5 | 1421 | unsigned int local_alloc_megs; |
d550071c | 1422 | |
2c442719 SM |
1423 | if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) { |
1424 | seq_printf(s, ",_netdev"); | |
1425 | if (opts & OCFS2_MOUNT_HB_LOCAL) | |
1426 | seq_printf(s, ",%s", OCFS2_HB_LOCAL); | |
1427 | else | |
1428 | seq_printf(s, ",%s", OCFS2_HB_GLOBAL); | |
1429 | } else | |
1430 | seq_printf(s, ",%s", OCFS2_HB_NONE); | |
d550071c SM |
1431 | |
1432 | if (opts & OCFS2_MOUNT_NOINTR) | |
1433 | seq_printf(s, ",nointr"); | |
1434 | ||
1435 | if (opts & OCFS2_MOUNT_DATA_WRITEBACK) | |
1436 | seq_printf(s, ",data=writeback"); | |
1437 | else | |
1438 | seq_printf(s, ",data=ordered"); | |
1439 | ||
1440 | if (opts & OCFS2_MOUNT_BARRIER) | |
1441 | seq_printf(s, ",barrier=1"); | |
1442 | ||
1443 | if (opts & OCFS2_MOUNT_ERRORS_PANIC) | |
1444 | seq_printf(s, ",errors=panic"); | |
7d0fb914 GR |
1445 | else if (opts & OCFS2_MOUNT_ERRORS_CONT) |
1446 | seq_printf(s, ",errors=continue"); | |
d550071c SM |
1447 | else |
1448 | seq_printf(s, ",errors=remount-ro"); | |
1449 | ||
1450 | if (osb->preferred_slot != OCFS2_INVALID_SLOT) | |
1451 | seq_printf(s, ",preferred_slot=%d", osb->preferred_slot); | |
1452 | ||
34c80b1d | 1453 | seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum); |
d550071c | 1454 | |
d147b3d6 MF |
1455 | if (osb->osb_commit_interval) |
1456 | seq_printf(s, ",commit=%u", | |
1457 | (unsigned) (osb->osb_commit_interval / HZ)); | |
1458 | ||
ebcee4b5 | 1459 | local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits); |
6b82021b | 1460 | if (local_alloc_megs != ocfs2_la_default_mb(osb)) |
ebcee4b5 | 1461 | seq_printf(s, ",localalloc=%d", local_alloc_megs); |
2fbe8d1e | 1462 | |
53fc622b MF |
1463 | if (opts & OCFS2_MOUNT_LOCALFLOCKS) |
1464 | seq_printf(s, ",localflocks,"); | |
1465 | ||
b61817e1 | 1466 | if (osb->osb_cluster_stack[0]) |
a53fb69b | 1467 | seq_show_option(s, "cluster_stack", osb->osb_cluster_stack); |
19ece546 JK |
1468 | if (opts & OCFS2_MOUNT_USRQUOTA) |
1469 | seq_printf(s, ",usrquota"); | |
1470 | if (opts & OCFS2_MOUNT_GRPQUOTA) | |
1471 | seq_printf(s, ",grpquota"); | |
b61817e1 | 1472 | |
7bdb0d18 TY |
1473 | if (opts & OCFS2_MOUNT_COHERENCY_BUFFERED) |
1474 | seq_printf(s, ",coherency=buffered"); | |
1475 | else | |
1476 | seq_printf(s, ",coherency=full"); | |
1477 | ||
b0f73cfc SM |
1478 | if (opts & OCFS2_MOUNT_NOUSERXATTR) |
1479 | seq_printf(s, ",nouser_xattr"); | |
1480 | else | |
1481 | seq_printf(s, ",user_xattr"); | |
1482 | ||
12462f1d JB |
1483 | if (opts & OCFS2_MOUNT_INODE64) |
1484 | seq_printf(s, ",inode64"); | |
1485 | ||
a68979b8 TY |
1486 | if (opts & OCFS2_MOUNT_POSIX_ACL) |
1487 | seq_printf(s, ",acl"); | |
1488 | else | |
1489 | seq_printf(s, ",noacl"); | |
a68979b8 | 1490 | |
d02f00cc MF |
1491 | if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL) |
1492 | seq_printf(s, ",resv_level=%d", osb->osb_resv_level); | |
1493 | ||
83f92318 MF |
1494 | if (osb->osb_dir_resv_level != osb->osb_resv_level) |
1495 | seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level); | |
1496 | ||
1dfeb768 | 1497 | if (opts & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT) |
1498 | seq_printf(s, ",journal_async_commit"); | |
1499 | ||
d550071c SM |
1500 | return 0; |
1501 | } | |
1502 | ||
ccd979bd MF |
1503 | static int __init ocfs2_init(void) |
1504 | { | |
c18ceab0 | 1505 | int status; |
a11f7e63 | 1506 | |
ccd979bd | 1507 | status = init_ocfs2_uptodate_cache(); |
342827d7 AV |
1508 | if (status < 0) |
1509 | goto out1; | |
ccd979bd MF |
1510 | |
1511 | status = ocfs2_initialize_mem_caches(); | |
342827d7 AV |
1512 | if (status < 0) |
1513 | goto out2; | |
ccd979bd | 1514 | |
ccd979bd | 1515 | ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL); |
ccd979bd | 1516 | |
63e0c48a JB |
1517 | ocfs2_set_locking_protocol(); |
1518 | ||
a838e5dc KS |
1519 | register_quota_format(&ocfs2_quota_format); |
1520 | ||
342827d7 AV |
1521 | status = register_filesystem(&ocfs2_fs_type); |
1522 | if (!status) | |
1523 | return 0; | |
ccd979bd | 1524 | |
342827d7 | 1525 | unregister_quota_format(&ocfs2_quota_format); |
35ddf78e | 1526 | debugfs_remove(ocfs2_debugfs_root); |
342827d7 AV |
1527 | ocfs2_free_mem_caches(); |
1528 | out2: | |
1529 | exit_ocfs2_uptodate_cache(); | |
1530 | out1: | |
1531 | mlog_errno(status); | |
1532 | return status; | |
ccd979bd MF |
1533 | } |
1534 | ||
1535 | static void __exit ocfs2_exit(void) | |
1536 | { | |
9e33d69f JK |
1537 | unregister_quota_format(&ocfs2_quota_format); |
1538 | ||
ccd979bd MF |
1539 | debugfs_remove(ocfs2_debugfs_root); |
1540 | ||
1541 | ocfs2_free_mem_caches(); | |
1542 | ||
1543 | unregister_filesystem(&ocfs2_fs_type); | |
1544 | ||
ccd979bd | 1545 | exit_ocfs2_uptodate_cache(); |
ccd979bd MF |
1546 | } |
1547 | ||
1548 | static void ocfs2_put_super(struct super_block *sb) | |
1549 | { | |
32a42d39 | 1550 | trace_ocfs2_put_super(sb); |
ccd979bd MF |
1551 | |
1552 | ocfs2_sync_blockdev(sb); | |
1553 | ocfs2_dismount_volume(sb, 0); | |
ccd979bd MF |
1554 | } |
1555 | ||
726c3342 | 1556 | static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf) |
ccd979bd MF |
1557 | { |
1558 | struct ocfs2_super *osb; | |
1559 | u32 numbits, freebits; | |
1560 | int status; | |
1561 | struct ocfs2_dinode *bm_lock; | |
1562 | struct buffer_head *bh = NULL; | |
1563 | struct inode *inode = NULL; | |
1564 | ||
32a42d39 | 1565 | trace_ocfs2_statfs(dentry->d_sb, buf); |
ccd979bd | 1566 | |
726c3342 | 1567 | osb = OCFS2_SB(dentry->d_sb); |
ccd979bd MF |
1568 | |
1569 | inode = ocfs2_get_system_file_inode(osb, | |
1570 | GLOBAL_BITMAP_SYSTEM_INODE, | |
1571 | OCFS2_INVALID_SLOT); | |
1572 | if (!inode) { | |
1573 | mlog(ML_ERROR, "failed to get bitmap inode\n"); | |
1574 | status = -EIO; | |
1575 | goto bail; | |
1576 | } | |
1577 | ||
e63aecb6 | 1578 | status = ocfs2_inode_lock(inode, &bh, 0); |
ccd979bd MF |
1579 | if (status < 0) { |
1580 | mlog_errno(status); | |
1581 | goto bail; | |
1582 | } | |
1583 | ||
1584 | bm_lock = (struct ocfs2_dinode *) bh->b_data; | |
1585 | ||
1586 | numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total); | |
1587 | freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used); | |
1588 | ||
1589 | buf->f_type = OCFS2_SUPER_MAGIC; | |
726c3342 | 1590 | buf->f_bsize = dentry->d_sb->s_blocksize; |
ccd979bd MF |
1591 | buf->f_namelen = OCFS2_MAX_FILENAME_LEN; |
1592 | buf->f_blocks = ((sector_t) numbits) * | |
1593 | (osb->s_clustersize >> osb->sb->s_blocksize_bits); | |
1594 | buf->f_bfree = ((sector_t) freebits) * | |
1595 | (osb->s_clustersize >> osb->sb->s_blocksize_bits); | |
1596 | buf->f_bavail = buf->f_bfree; | |
1597 | buf->f_files = numbits; | |
1598 | buf->f_ffree = freebits; | |
837711f8 CL |
1599 | buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN) |
1600 | & 0xFFFFFFFFUL; | |
1601 | buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN, | |
1602 | OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL; | |
ccd979bd MF |
1603 | |
1604 | brelse(bh); | |
1605 | ||
e63aecb6 | 1606 | ocfs2_inode_unlock(inode, 0); |
ccd979bd MF |
1607 | status = 0; |
1608 | bail: | |
72865d92 | 1609 | iput(inode); |
ccd979bd | 1610 | |
c1e8d35e TM |
1611 | if (status) |
1612 | mlog_errno(status); | |
ccd979bd MF |
1613 | |
1614 | return status; | |
1615 | } | |
1616 | ||
51cc5068 | 1617 | static void ocfs2_inode_init_once(void *data) |
ccd979bd MF |
1618 | { |
1619 | struct ocfs2_inode_info *oi = data; | |
1620 | ||
a35afb83 CL |
1621 | oi->ip_flags = 0; |
1622 | oi->ip_open_count = 0; | |
1623 | spin_lock_init(&oi->ip_lock); | |
1624 | ocfs2_extent_map_init(&oi->vfs_inode); | |
1625 | INIT_LIST_HEAD(&oi->ip_io_markers); | |
4506cfb6 | 1626 | INIT_LIST_HEAD(&oi->ip_unwritten_list); |
a35afb83 | 1627 | oi->ip_dir_start_lookup = 0; |
a35afb83 | 1628 | init_rwsem(&oi->ip_alloc_sem); |
cf1d6c76 | 1629 | init_rwsem(&oi->ip_xattr_sem); |
a35afb83 | 1630 | mutex_init(&oi->ip_io_mutex); |
ccd979bd | 1631 | |
a35afb83 CL |
1632 | oi->ip_blkno = 0ULL; |
1633 | oi->ip_clusters = 0; | |
f5785283 | 1634 | oi->ip_next_orphan = NULL; |
ccd979bd | 1635 | |
4fe370af MF |
1636 | ocfs2_resv_init_once(&oi->ip_la_data_resv); |
1637 | ||
a35afb83 | 1638 | ocfs2_lock_res_init_once(&oi->ip_rw_lockres); |
e63aecb6 | 1639 | ocfs2_lock_res_init_once(&oi->ip_inode_lockres); |
a35afb83 | 1640 | ocfs2_lock_res_init_once(&oi->ip_open_lockres); |
ccd979bd | 1641 | |
8cb471e8 | 1642 | ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode), |
6e5a3d75 | 1643 | &ocfs2_inode_caching_ops); |
ccd979bd | 1644 | |
a35afb83 | 1645 | inode_init_once(&oi->vfs_inode); |
ccd979bd MF |
1646 | } |
1647 | ||
1648 | static int ocfs2_initialize_mem_caches(void) | |
1649 | { | |
1650 | ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache", | |
fffb60f9 PJ |
1651 | sizeof(struct ocfs2_inode_info), |
1652 | 0, | |
1653 | (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| | |
f88c3fb8 | 1654 | SLAB_ACCOUNT), |
20c2df83 | 1655 | ocfs2_inode_init_once); |
9e33d69f JK |
1656 | ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache", |
1657 | sizeof(struct ocfs2_dquot), | |
1658 | 0, | |
46bd9449 | 1659 | SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, |
9e33d69f JK |
1660 | NULL); |
1661 | ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache", | |
1662 | sizeof(struct ocfs2_quota_chunk), | |
1663 | 0, | |
46bd9449 | 1664 | SLAB_RECLAIM_ACCOUNT, |
9e33d69f JK |
1665 | NULL); |
1666 | if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep || | |
1667 | !ocfs2_qf_chunk_cachep) { | |
a17b485a | 1668 | kmem_cache_destroy(ocfs2_inode_cachep); |
1669 | kmem_cache_destroy(ocfs2_dquot_cachep); | |
1670 | kmem_cache_destroy(ocfs2_qf_chunk_cachep); | |
ccd979bd | 1671 | return -ENOMEM; |
9e33d69f | 1672 | } |
ccd979bd | 1673 | |
ccd979bd MF |
1674 | return 0; |
1675 | } | |
1676 | ||
1677 | static void ocfs2_free_mem_caches(void) | |
1678 | { | |
8c0a8537 KS |
1679 | /* |
1680 | * Make sure all delayed rcu free inodes are flushed before we | |
1681 | * destroy cache. | |
1682 | */ | |
1683 | rcu_barrier(); | |
a17b485a | 1684 | kmem_cache_destroy(ocfs2_inode_cachep); |
ccd979bd | 1685 | ocfs2_inode_cachep = NULL; |
9e33d69f | 1686 | |
a17b485a | 1687 | kmem_cache_destroy(ocfs2_dquot_cachep); |
9e33d69f JK |
1688 | ocfs2_dquot_cachep = NULL; |
1689 | ||
a17b485a | 1690 | kmem_cache_destroy(ocfs2_qf_chunk_cachep); |
9e33d69f | 1691 | ocfs2_qf_chunk_cachep = NULL; |
ccd979bd MF |
1692 | } |
1693 | ||
1694 | static int ocfs2_get_sector(struct super_block *sb, | |
1695 | struct buffer_head **bh, | |
1696 | int block, | |
1697 | int sect_size) | |
1698 | { | |
1699 | if (!sb_set_blocksize(sb, sect_size)) { | |
1700 | mlog(ML_ERROR, "unable to set blocksize\n"); | |
1701 | return -EIO; | |
1702 | } | |
1703 | ||
1704 | *bh = sb_getblk(sb, block); | |
1705 | if (!*bh) { | |
7391a294 RX |
1706 | mlog_errno(-ENOMEM); |
1707 | return -ENOMEM; | |
ccd979bd MF |
1708 | } |
1709 | lock_buffer(*bh); | |
1710 | if (!buffer_dirty(*bh)) | |
1711 | clear_buffer_uptodate(*bh); | |
1712 | unlock_buffer(*bh); | |
54d9171d | 1713 | if (bh_read(*bh, 0) < 0) { |
28d57d43 | 1714 | mlog_errno(-EIO); |
1715 | brelse(*bh); | |
1716 | *bh = NULL; | |
1717 | return -EIO; | |
1718 | } | |
1719 | ||
ccd979bd MF |
1720 | return 0; |
1721 | } | |
1722 | ||
ccd979bd MF |
1723 | static int ocfs2_mount_volume(struct super_block *sb) |
1724 | { | |
1725 | int status = 0; | |
ccd979bd MF |
1726 | struct ocfs2_super *osb = OCFS2_SB(sb); |
1727 | ||
ccd979bd | 1728 | if (ocfs2_is_hard_readonly(osb)) |
0737e01d | 1729 | goto out; |
ccd979bd | 1730 | |
5500ab4e GH |
1731 | mutex_init(&osb->obs_trim_fs_mutex); |
1732 | ||
ccd979bd MF |
1733 | status = ocfs2_dlm_init(osb); |
1734 | if (status < 0) { | |
1735 | mlog_errno(status); | |
a52370b3 GH |
1736 | if (status == -EBADR && ocfs2_userspace_stack(osb)) |
1737 | mlog(ML_ERROR, "couldn't mount because cluster name on" | |
1738 | " disk does not match the running cluster name.\n"); | |
0737e01d | 1739 | goto out; |
ccd979bd MF |
1740 | } |
1741 | ||
ccd979bd MF |
1742 | status = ocfs2_super_lock(osb, 1); |
1743 | if (status < 0) { | |
1744 | mlog_errno(status); | |
0737e01d | 1745 | goto out_dlm; |
ccd979bd | 1746 | } |
ccd979bd MF |
1747 | |
1748 | /* This will load up the node map and add ourselves to it. */ | |
1749 | status = ocfs2_find_slot(osb); | |
1750 | if (status < 0) { | |
1751 | mlog_errno(status); | |
0737e01d | 1752 | goto out_super_lock; |
ccd979bd MF |
1753 | } |
1754 | ||
ccd979bd MF |
1755 | /* load all node-local system inodes */ |
1756 | status = ocfs2_init_local_system_inodes(osb); | |
1757 | if (status < 0) { | |
1758 | mlog_errno(status); | |
0737e01d | 1759 | goto out_super_lock; |
ccd979bd MF |
1760 | } |
1761 | ||
1762 | status = ocfs2_check_volume(osb); | |
1763 | if (status < 0) { | |
1764 | mlog_errno(status); | |
0737e01d | 1765 | goto out_system_inodes; |
ccd979bd MF |
1766 | } |
1767 | ||
1768 | status = ocfs2_truncate_log_init(osb); | |
0737e01d | 1769 | if (status < 0) { |
ccd979bd | 1770 | mlog_errno(status); |
ce2fcf15 | 1771 | goto out_check_volume; |
0737e01d | 1772 | } |
c271c5c2 | 1773 | |
0737e01d HZO |
1774 | ocfs2_super_unlock(osb, 1); |
1775 | return 0; | |
ccd979bd | 1776 | |
ce2fcf15 LZ |
1777 | out_check_volume: |
1778 | ocfs2_free_replay_slots(osb); | |
0737e01d HZO |
1779 | out_system_inodes: |
1780 | if (osb->local_alloc_state == OCFS2_LA_ENABLED) | |
1781 | ocfs2_shutdown_local_alloc(osb); | |
1782 | ocfs2_release_system_inodes(osb); | |
1783 | /* before journal shutdown, we should release slot_info */ | |
1784 | ocfs2_free_slot_info(osb); | |
1785 | ocfs2_journal_shutdown(osb); | |
1786 | out_super_lock: | |
1787 | ocfs2_super_unlock(osb, 1); | |
1788 | out_dlm: | |
1789 | ocfs2_dlm_shutdown(osb, 0); | |
1790 | out: | |
ccd979bd MF |
1791 | return status; |
1792 | } | |
1793 | ||
ccd979bd MF |
1794 | static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err) |
1795 | { | |
286eaa95 | 1796 | int tmp, hangup_needed = 0; |
ccd979bd | 1797 | struct ocfs2_super *osb = NULL; |
99d7a882 | 1798 | char nodestr[12]; |
ccd979bd | 1799 | |
32a42d39 | 1800 | trace_ocfs2_dismount_volume(sb); |
ccd979bd MF |
1801 | |
1802 | BUG_ON(!sb); | |
1803 | osb = OCFS2_SB(sb); | |
1804 | BUG_ON(!osb); | |
1805 | ||
a0f8a9a9 | 1806 | /* Remove file check sysfs related directories/files, |
5f483c4a GH |
1807 | * and wait for the pending file check operations */ |
1808 | ocfs2_filecheck_remove_sysfs(osb); | |
1809 | ||
1810 | kset_unregister(osb->osb_dev_kset); | |
1811 | ||
692684e1 SM |
1812 | /* Orphan scan should be stopped as early as possible */ |
1813 | ocfs2_orphan_scan_stop(osb); | |
1814 | ||
fcaf3b26 JK |
1815 | /* Stop quota recovery so that we can disable quotas */ |
1816 | ocfs2_recovery_disable_quota(osb); | |
1817 | ||
19ece546 JK |
1818 | ocfs2_disable_quotas(osb); |
1819 | ||
e3a767b6 JK |
1820 | /* All dquots should be freed by now */ |
1821 | WARN_ON(!llist_empty(&osb->dquot_drop_list)); | |
1822 | /* Wait for worker to be done with the work structure in osb */ | |
1823 | cancel_work_sync(&osb->dquot_drop_work); | |
1824 | ||
ccd979bd MF |
1825 | ocfs2_shutdown_local_alloc(osb); |
1826 | ||
b253bfd8 X |
1827 | ocfs2_truncate_log_shutdown(osb); |
1828 | ||
553abd04 JB |
1829 | /* This will disable recovery and flush any recovery work. */ |
1830 | ocfs2_recovery_exit(osb); | |
ccd979bd | 1831 | |
ccd979bd MF |
1832 | ocfs2_sync_blockdev(sb); |
1833 | ||
374a263e TM |
1834 | ocfs2_purge_refcount_trees(osb); |
1835 | ||
4670c46d JB |
1836 | /* No cluster connection means we've failed during mount, so skip |
1837 | * all the steps which depended on that to complete. */ | |
1838 | if (osb->cconn) { | |
ccd979bd MF |
1839 | tmp = ocfs2_super_lock(osb, 1); |
1840 | if (tmp < 0) { | |
1841 | mlog_errno(tmp); | |
1842 | return; | |
1843 | } | |
19b613d4 | 1844 | } |
ccd979bd | 1845 | |
19b613d4 MF |
1846 | if (osb->slot_num != OCFS2_INVALID_SLOT) |
1847 | ocfs2_put_slot(osb); | |
ccd979bd | 1848 | |
4670c46d | 1849 | if (osb->cconn) |
ccd979bd | 1850 | ocfs2_super_unlock(osb, 1); |
ccd979bd MF |
1851 | |
1852 | ocfs2_release_system_inodes(osb); | |
1853 | ||
da5e7c87 VV |
1854 | ocfs2_journal_shutdown(osb); |
1855 | ||
6953b4c0 | 1856 | /* |
6953b4c0 JB |
1857 | * If we're dismounting due to mount error, mount.ocfs2 will clean |
1858 | * up heartbeat. If we're a local mount, there is no heartbeat. | |
1859 | * If we failed before we got a uuid_str yet, we can't stop | |
1860 | * heartbeat. Otherwise, do it. | |
1861 | */ | |
03efed8a TY |
1862 | if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str && |
1863 | !ocfs2_is_hard_readonly(osb)) | |
286eaa95 JB |
1864 | hangup_needed = 1; |
1865 | ||
550842cc | 1866 | ocfs2_dlm_shutdown(osb, hangup_needed); |
286eaa95 | 1867 | |
73be192b | 1868 | ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats); |
5e7a3ed9 | 1869 | debugfs_remove_recursive(osb->osb_debug_root); |
286eaa95 JB |
1870 | |
1871 | if (hangup_needed) | |
6953b4c0 | 1872 | ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str)); |
ccd979bd MF |
1873 | |
1874 | atomic_set(&osb->vol_state, VOLUME_DISMOUNTED); | |
1875 | ||
c271c5c2 SM |
1876 | if (ocfs2_mount_local(osb)) |
1877 | snprintf(nodestr, sizeof(nodestr), "local"); | |
1878 | else | |
19fdb624 | 1879 | snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num); |
c271c5c2 SM |
1880 | |
1881 | printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n", | |
1882 | osb->dev_str, nodestr); | |
ccd979bd MF |
1883 | |
1884 | ocfs2_delete_osb(osb); | |
1885 | kfree(osb); | |
1886 | sb->s_dev = 0; | |
1887 | sb->s_fs_info = NULL; | |
1888 | } | |
1889 | ||
1890 | static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid, | |
1891 | unsigned uuid_bytes) | |
1892 | { | |
1893 | int i, ret; | |
1894 | char *ptr; | |
1895 | ||
1896 | BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN); | |
1897 | ||
cd861280 | 1898 | osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL); |
ccd979bd MF |
1899 | if (osb->uuid_str == NULL) |
1900 | return -ENOMEM; | |
1901 | ||
ccd979bd MF |
1902 | for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) { |
1903 | /* print with null */ | |
1904 | ret = snprintf(ptr, 3, "%02X", uuid[i]); | |
1905 | if (ret != 2) /* drop super cleans up */ | |
1906 | return -EINVAL; | |
1907 | /* then only advance past the last char */ | |
1908 | ptr += 2; | |
1909 | } | |
1910 | ||
1911 | return 0; | |
1912 | } | |
1913 | ||
3bdb8efd PL |
1914 | /* Make sure entire volume is addressable by our journal. Requires |
1915 | osb_clusters_at_boot to be valid and for the journal to have been | |
1916 | initialized by ocfs2_journal_init(). */ | |
1917 | static int ocfs2_journal_addressable(struct ocfs2_super *osb) | |
1918 | { | |
1919 | int status = 0; | |
1920 | u64 max_block = | |
1921 | ocfs2_clusters_to_blocks(osb->sb, | |
1922 | osb->osb_clusters_at_boot) - 1; | |
1923 | ||
1924 | /* 32-bit block number is always OK. */ | |
1925 | if (max_block <= (u32)~0ULL) | |
1926 | goto out; | |
1927 | ||
1928 | /* Volume is "huge", so see if our journal is new enough to | |
1929 | support it. */ | |
1930 | if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb, | |
1931 | OCFS2_FEATURE_COMPAT_JBD2_SB) && | |
1932 | jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0, | |
1933 | JBD2_FEATURE_INCOMPAT_64BIT))) { | |
1934 | mlog(ML_ERROR, "The journal cannot address the entire volume. " | |
1935 | "Enable the 'block64' journal option with tunefs.ocfs2"); | |
1936 | status = -EFBIG; | |
1937 | goto out; | |
1938 | } | |
1939 | ||
1940 | out: | |
1941 | return status; | |
1942 | } | |
1943 | ||
ccd979bd MF |
1944 | static int ocfs2_initialize_super(struct super_block *sb, |
1945 | struct buffer_head *bh, | |
73be192b JB |
1946 | int sector_size, |
1947 | struct ocfs2_blockcheck_stats *stats) | |
ccd979bd | 1948 | { |
bddb8eb3 | 1949 | int status; |
5a254031 MF |
1950 | int i, cbits, bbits; |
1951 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; | |
ccd979bd | 1952 | struct inode *inode = NULL; |
ccd979bd | 1953 | struct ocfs2_super *osb; |
3bdb8efd | 1954 | u64 total_blocks; |
ccd979bd | 1955 | |
cd861280 | 1956 | osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL); |
ccd979bd MF |
1957 | if (!osb) { |
1958 | status = -ENOMEM; | |
1959 | mlog_errno(status); | |
a8a986db | 1960 | goto out; |
ccd979bd MF |
1961 | } |
1962 | ||
1963 | sb->s_fs_info = osb; | |
1964 | sb->s_op = &ocfs2_sops; | |
ba87167c | 1965 | sb->s_d_op = &ocfs2_dentry_ops; |
ccd979bd | 1966 | sb->s_export_op = &ocfs2_export_ops; |
664dbd5f | 1967 | sb->s_qcop = &dquot_quotactl_sysfile_ops; |
19ece546 | 1968 | sb->dq_op = &ocfs2_quota_operations; |
1c92ec67 | 1969 | sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP; |
cf1d6c76 | 1970 | sb->s_xattr = ocfs2_xattr_handlers; |
e0dceaf0 | 1971 | sb->s_time_gran = 1; |
1751e8a6 | 1972 | sb->s_flags |= SB_NOATIME; |
ccd979bd | 1973 | /* this is needed to support O_LARGEFILE */ |
5a254031 MF |
1974 | cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits); |
1975 | bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits); | |
1976 | sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits); | |
a4af51ce KO |
1977 | super_set_uuid(sb, di->id2.i_super.s_uuid, |
1978 | sizeof(di->id2.i_super.s_uuid)); | |
ccd979bd | 1979 | |
9b7895ef MF |
1980 | osb->osb_dx_mask = (1 << (cbits - bbits)) - 1; |
1981 | ||
1982 | for (i = 0; i < 3; i++) | |
1983 | osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]); | |
1984 | osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash); | |
1985 | ||
ccd979bd | 1986 | osb->sb = sb; |
ccd979bd | 1987 | osb->s_sectsize_bits = blksize_bits(sector_size); |
ebdec83b | 1988 | BUG_ON(!osb->s_sectsize_bits); |
ccd979bd | 1989 | |
34d024f8 MF |
1990 | spin_lock_init(&osb->dc_task_lock); |
1991 | init_waitqueue_head(&osb->dc_event); | |
1992 | osb->dc_work_sequence = 0; | |
1993 | osb->dc_wake_sequence = 0; | |
ccd979bd MF |
1994 | INIT_LIST_HEAD(&osb->blocked_lock_list); |
1995 | osb->blocked_lock_count = 0; | |
ccd979bd | 1996 | spin_lock_init(&osb->osb_lock); |
c8b9cf9a | 1997 | spin_lock_init(&osb->osb_xattr_lock); |
b89c5428 | 1998 | ocfs2_init_steal_slots(osb); |
ccd979bd | 1999 | |
43b10a20 | 2000 | mutex_init(&osb->system_file_mutex); |
2001 | ||
ccd979bd MF |
2002 | atomic_set(&osb->alloc_stats.moves, 0); |
2003 | atomic_set(&osb->alloc_stats.local_data, 0); | |
2004 | atomic_set(&osb->alloc_stats.bitmap_data, 0); | |
2005 | atomic_set(&osb->alloc_stats.bg_allocs, 0); | |
2006 | atomic_set(&osb->alloc_stats.bg_extends, 0); | |
2007 | ||
73be192b JB |
2008 | /* Copy the blockcheck stats from the superblock probe */ |
2009 | osb->osb_ecc_stats = *stats; | |
2010 | ||
ccd979bd MF |
2011 | ocfs2_init_node_maps(osb); |
2012 | ||
2013 | snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u", | |
2014 | MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev)); | |
2015 | ||
75d9bbc7 GR |
2016 | osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots); |
2017 | if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) { | |
2018 | mlog(ML_ERROR, "Invalid number of node slots (%u)\n", | |
2019 | osb->max_slots); | |
2020 | status = -EINVAL; | |
a8a986db | 2021 | goto out; |
75d9bbc7 | 2022 | } |
75d9bbc7 | 2023 | |
8b712cd5 JM |
2024 | ocfs2_orphan_scan_init(osb); |
2025 | ||
553abd04 JB |
2026 | status = ocfs2_recovery_init(osb); |
2027 | if (status) { | |
2028 | mlog(ML_ERROR, "Unable to initialize recovery state\n"); | |
2029 | mlog_errno(status); | |
a8a986db | 2030 | goto out; |
553abd04 | 2031 | } |
ccd979bd MF |
2032 | |
2033 | init_waitqueue_head(&osb->checkpoint_event); | |
ccd979bd | 2034 | |
7f1a37e3 TY |
2035 | osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM; |
2036 | ||
ccd979bd MF |
2037 | osb->slot_num = OCFS2_INVALID_SLOT; |
2038 | ||
8154da3d TY |
2039 | osb->s_xattr_inline_size = le16_to_cpu( |
2040 | di->id2.i_super.s_xattr_inline_size); | |
fdd77704 | 2041 | |
ccd979bd MF |
2042 | osb->local_alloc_state = OCFS2_LA_UNUSED; |
2043 | osb->local_alloc_bh = NULL; | |
9c7af40b | 2044 | INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker); |
ccd979bd | 2045 | |
ccd979bd MF |
2046 | init_waitqueue_head(&osb->osb_mount_event); |
2047 | ||
54bd3f7c | 2048 | ocfs2_resmap_init(osb, &osb->osb_la_resmap); |
d02f00cc | 2049 | |
ccd979bd MF |
2050 | osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL); |
2051 | if (!osb->vol_label) { | |
2052 | mlog(ML_ERROR, "unable to alloc vol label\n"); | |
2053 | status = -ENOMEM; | |
a8a986db | 2054 | goto out_recovery_map; |
ccd979bd MF |
2055 | } |
2056 | ||
539d8264 SM |
2057 | osb->slot_recovery_generations = |
2058 | kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations), | |
2059 | GFP_KERNEL); | |
2060 | if (!osb->slot_recovery_generations) { | |
2061 | status = -ENOMEM; | |
2062 | mlog_errno(status); | |
a8a986db | 2063 | goto out_vol_label; |
539d8264 SM |
2064 | } |
2065 | ||
b4df6ed8 MF |
2066 | init_waitqueue_head(&osb->osb_wipe_event); |
2067 | osb->osb_orphan_wipes = kcalloc(osb->max_slots, | |
2068 | sizeof(*osb->osb_orphan_wipes), | |
2069 | GFP_KERNEL); | |
2070 | if (!osb->osb_orphan_wipes) { | |
2071 | status = -ENOMEM; | |
2072 | mlog_errno(status); | |
a8a986db | 2073 | goto out_slot_recovery_gen; |
b4df6ed8 MF |
2074 | } |
2075 | ||
374a263e TM |
2076 | osb->osb_rf_lock_tree = RB_ROOT; |
2077 | ||
ccd979bd MF |
2078 | osb->s_feature_compat = |
2079 | le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat); | |
2080 | osb->s_feature_ro_compat = | |
2081 | le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat); | |
2082 | osb->s_feature_incompat = | |
2083 | le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat); | |
2084 | ||
2085 | if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) { | |
2086 | mlog(ML_ERROR, "couldn't mount because of unsupported " | |
2087 | "optional features (%x).\n", i); | |
2088 | status = -EINVAL; | |
a8a986db | 2089 | goto out_orphan_wipes; |
ccd979bd | 2090 | } |
bc98a42c | 2091 | if (!sb_rdonly(osb->sb) && (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) { |
ccd979bd MF |
2092 | mlog(ML_ERROR, "couldn't mount RDWR because of " |
2093 | "unsupported optional features (%x).\n", i); | |
2094 | status = -EINVAL; | |
a8a986db | 2095 | goto out_orphan_wipes; |
ccd979bd MF |
2096 | } |
2097 | ||
98f486f2 | 2098 | if (ocfs2_clusterinfo_valid(osb)) { |
b15fa922 VV |
2099 | /* |
2100 | * ci_stack and ci_cluster in ocfs2_cluster_info may not be null | |
2101 | * terminated, so make sure no overflow happens here by using | |
2102 | * memcpy. Destination strings will always be null terminated | |
2103 | * because osb is allocated using kzalloc. | |
2104 | */ | |
98f486f2 SM |
2105 | osb->osb_stackflags = |
2106 | OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags; | |
b15fa922 | 2107 | memcpy(osb->osb_cluster_stack, |
b61817e1 | 2108 | OCFS2_RAW_SB(di)->s_cluster_info.ci_stack, |
b15fa922 | 2109 | OCFS2_STACK_LABEL_LEN); |
b61817e1 JB |
2110 | if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) { |
2111 | mlog(ML_ERROR, | |
2112 | "couldn't mount because of an invalid " | |
2113 | "cluster stack label (%s) \n", | |
2114 | osb->osb_cluster_stack); | |
2115 | status = -EINVAL; | |
a8a986db | 2116 | goto out_orphan_wipes; |
b61817e1 | 2117 | } |
b15fa922 | 2118 | memcpy(osb->osb_cluster_name, |
c74a3bdd | 2119 | OCFS2_RAW_SB(di)->s_cluster_info.ci_cluster, |
b15fa922 | 2120 | OCFS2_CLUSTER_NAME_LEN); |
b61817e1 JB |
2121 | } else { |
2122 | /* The empty string is identical with classic tools that | |
2123 | * don't know about s_cluster_info. */ | |
2124 | osb->osb_cluster_stack[0] = '\0'; | |
2125 | } | |
2126 | ||
ccd979bd MF |
2127 | get_random_bytes(&osb->s_next_generation, sizeof(u32)); |
2128 | ||
bb20b31d HZO |
2129 | /* |
2130 | * FIXME | |
2131 | * This should be done in ocfs2_journal_init(), but any inode | |
2132 | * writes back operation will cause the filesystem to crash. | |
2133 | */ | |
2134 | status = ocfs2_journal_alloc(osb); | |
2135 | if (status < 0) | |
a8a986db | 2136 | goto out_orphan_wipes; |
bb20b31d | 2137 | |
e3a767b6 JK |
2138 | INIT_WORK(&osb->dquot_drop_work, ocfs2_drop_dquot_refs); |
2139 | init_llist_head(&osb->dquot_drop_list); | |
2140 | ||
ccd979bd MF |
2141 | /* get some pseudo constants for clustersize bits */ |
2142 | osb->s_clustersize_bits = | |
2143 | le32_to_cpu(di->id2.i_super.s_clustersize_bits); | |
2144 | osb->s_clustersize = 1 << osb->s_clustersize_bits; | |
ccd979bd MF |
2145 | |
2146 | if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE || | |
2147 | osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) { | |
2148 | mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n", | |
2149 | osb->s_clustersize); | |
2150 | status = -EINVAL; | |
a8a986db | 2151 | goto out_journal; |
ccd979bd MF |
2152 | } |
2153 | ||
3bdb8efd PL |
2154 | total_blocks = ocfs2_clusters_to_blocks(osb->sb, |
2155 | le32_to_cpu(di->i_clusters)); | |
2156 | ||
2157 | status = generic_check_addressable(osb->sb->s_blocksize_bits, | |
2158 | total_blocks); | |
2159 | if (status) { | |
2160 | mlog(ML_ERROR, "Volume too large " | |
2161 | "to mount safely on this system"); | |
2162 | status = -EFBIG; | |
a8a986db | 2163 | goto out_journal; |
ccd979bd MF |
2164 | } |
2165 | ||
2166 | if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid, | |
2167 | sizeof(di->id2.i_super.s_uuid))) { | |
2168 | mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n"); | |
2169 | status = -ENOMEM; | |
a8a986db | 2170 | goto out_journal; |
ccd979bd MF |
2171 | } |
2172 | ||
c97e21fe | 2173 | strscpy(osb->vol_label, di->id2.i_super.s_label, |
69201bb1 | 2174 | OCFS2_MAX_VOL_LABEL_LEN); |
ccd979bd MF |
2175 | osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno); |
2176 | osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno); | |
2177 | osb->first_cluster_group_blkno = | |
2178 | le64_to_cpu(di->id2.i_super.s_first_cluster_group); | |
2179 | osb->fs_generation = le32_to_cpu(di->i_fs_generation); | |
cf1d6c76 | 2180 | osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash); |
32a42d39 TM |
2181 | trace_ocfs2_initialize_super(osb->vol_label, osb->uuid_str, |
2182 | (unsigned long long)osb->root_blkno, | |
2183 | (unsigned long long)osb->system_dir_blkno, | |
2184 | osb->s_clustersize_bits); | |
ccd979bd MF |
2185 | |
2186 | osb->osb_dlm_debug = ocfs2_new_dlm_debug(); | |
2187 | if (!osb->osb_dlm_debug) { | |
2188 | status = -ENOMEM; | |
2189 | mlog_errno(status); | |
a8a986db | 2190 | goto out_uuid_str; |
ccd979bd MF |
2191 | } |
2192 | ||
2193 | atomic_set(&osb->vol_state, VOLUME_INIT); | |
2194 | ||
2195 | /* load root, system_dir, and all global system inodes */ | |
2196 | status = ocfs2_init_global_system_inodes(osb); | |
2197 | if (status < 0) { | |
2198 | mlog_errno(status); | |
a8a986db | 2199 | goto out_dlm_out; |
ccd979bd MF |
2200 | } |
2201 | ||
2202 | /* | |
2203 | * global bitmap | |
2204 | */ | |
2205 | inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE, | |
2206 | OCFS2_INVALID_SLOT); | |
2207 | if (!inode) { | |
2208 | status = -EINVAL; | |
2209 | mlog_errno(status); | |
a8a986db | 2210 | goto out_system_inodes; |
ccd979bd MF |
2211 | } |
2212 | ||
2213 | osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno; | |
6b82021b | 2214 | osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters; |
ccd979bd | 2215 | iput(inode); |
ccd979bd | 2216 | |
8571882c TM |
2217 | osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0, |
2218 | osb->s_feature_incompat) * 8; | |
ccd979bd MF |
2219 | |
2220 | status = ocfs2_init_slot_info(osb); | |
2221 | if (status < 0) { | |
2222 | mlog_errno(status); | |
a8a986db | 2223 | goto out_system_inodes; |
ccd979bd MF |
2224 | } |
2225 | ||
44be9756 | 2226 | osb->ocfs2_wq = alloc_ordered_workqueue("ocfs2_wq", WQ_MEM_RECLAIM); |
35ddf78e | 2227 | if (!osb->ocfs2_wq) { |
2228 | status = -ENOMEM; | |
2229 | mlog_errno(status); | |
a8a986db | 2230 | goto out_slot_info; |
35ddf78e | 2231 | } |
2232 | ||
a8a986db HZO |
2233 | return status; |
2234 | ||
2235 | out_slot_info: | |
2236 | ocfs2_free_slot_info(osb); | |
2237 | out_system_inodes: | |
2238 | ocfs2_release_system_inodes(osb); | |
2239 | out_dlm_out: | |
2240 | ocfs2_put_dlm_debug(osb->osb_dlm_debug); | |
2241 | out_uuid_str: | |
2242 | kfree(osb->uuid_str); | |
2243 | out_journal: | |
2244 | kfree(osb->journal); | |
2245 | out_orphan_wipes: | |
2246 | kfree(osb->osb_orphan_wipes); | |
2247 | out_slot_recovery_gen: | |
2248 | kfree(osb->slot_recovery_generations); | |
2249 | out_vol_label: | |
2250 | kfree(osb->vol_label); | |
2251 | out_recovery_map: | |
2252 | kfree(osb->recovery_map); | |
2253 | out: | |
2254 | kfree(osb); | |
2255 | sb->s_fs_info = NULL; | |
ccd979bd MF |
2256 | return status; |
2257 | } | |
2258 | ||
2259 | /* | |
2260 | * will return: -EAGAIN if it is ok to keep searching for superblocks | |
2261 | * -EINVAL if there is a bad superblock | |
2262 | * 0 on success | |
2263 | */ | |
2264 | static int ocfs2_verify_volume(struct ocfs2_dinode *di, | |
2265 | struct buffer_head *bh, | |
73be192b JB |
2266 | u32 blksz, |
2267 | struct ocfs2_blockcheck_stats *stats) | |
ccd979bd MF |
2268 | { |
2269 | int status = -EAGAIN; | |
23aab037 | 2270 | u32 blksz_bits; |
ccd979bd | 2271 | |
ccd979bd MF |
2272 | if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE, |
2273 | strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) { | |
d030cc97 JB |
2274 | /* We have to do a raw check of the feature here */ |
2275 | if (le32_to_cpu(di->id2.i_super.s_feature_incompat) & | |
2276 | OCFS2_FEATURE_INCOMPAT_META_ECC) { | |
2277 | status = ocfs2_block_check_validate(bh->b_data, | |
2278 | bh->b_size, | |
73be192b JB |
2279 | &di->i_check, |
2280 | stats); | |
d030cc97 JB |
2281 | if (status) |
2282 | goto out; | |
2283 | } | |
ccd979bd | 2284 | status = -EINVAL; |
23aab037 DA |
2285 | /* Acceptable block sizes are 512 bytes, 1K, 2K and 4K. */ |
2286 | blksz_bits = le32_to_cpu(di->id2.i_super.s_blocksize_bits); | |
2287 | if (blksz_bits < 9 || blksz_bits > 12) { | |
ccd979bd | 2288 | mlog(ML_ERROR, "found superblock with incorrect block " |
23aab037 DA |
2289 | "size bits: found %u, should be 9, 10, 11, or 12\n", |
2290 | blksz_bits); | |
f921da2c | 2291 | } else if ((1 << blksz_bits) != blksz) { |
23aab037 DA |
2292 | mlog(ML_ERROR, "found superblock with incorrect block " |
2293 | "size: found %u, should be %u\n", 1 << blksz_bits, blksz); | |
ccd979bd MF |
2294 | } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) != |
2295 | OCFS2_MAJOR_REV_LEVEL || | |
2296 | le16_to_cpu(di->id2.i_super.s_minor_rev_level) != | |
2297 | OCFS2_MINOR_REV_LEVEL) { | |
2298 | mlog(ML_ERROR, "found superblock with bad version: " | |
2299 | "found %u.%u, should be %u.%u\n", | |
2300 | le16_to_cpu(di->id2.i_super.s_major_rev_level), | |
2301 | le16_to_cpu(di->id2.i_super.s_minor_rev_level), | |
2302 | OCFS2_MAJOR_REV_LEVEL, | |
2303 | OCFS2_MINOR_REV_LEVEL); | |
2304 | } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) { | |
2305 | mlog(ML_ERROR, "bad block number on superblock: " | |
b0697053 | 2306 | "found %llu, should be %llu\n", |
1ca1a111 | 2307 | (unsigned long long)le64_to_cpu(di->i_blkno), |
b0697053 | 2308 | (unsigned long long)bh->b_blocknr); |
ccd979bd MF |
2309 | } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 || |
2310 | le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) { | |
7f86b294 | 2311 | mlog(ML_ERROR, "bad cluster size bit found: %u\n", |
2312 | le32_to_cpu(di->id2.i_super.s_clustersize_bits)); | |
ccd979bd MF |
2313 | } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) { |
2314 | mlog(ML_ERROR, "bad root_blkno: 0\n"); | |
2315 | } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) { | |
2316 | mlog(ML_ERROR, "bad system_dir_blkno: 0\n"); | |
2317 | } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) { | |
2318 | mlog(ML_ERROR, | |
2319 | "Superblock slots found greater than file system " | |
2320 | "maximum: found %u, max %u\n", | |
2321 | le16_to_cpu(di->id2.i_super.s_max_slots), | |
2322 | OCFS2_MAX_SLOTS); | |
2323 | } else { | |
2324 | /* found it! */ | |
2325 | status = 0; | |
2326 | } | |
2327 | } | |
2328 | ||
d030cc97 | 2329 | out: |
c1e8d35e TM |
2330 | if (status && status != -EAGAIN) |
2331 | mlog_errno(status); | |
ccd979bd MF |
2332 | return status; |
2333 | } | |
2334 | ||
2335 | static int ocfs2_check_volume(struct ocfs2_super *osb) | |
2336 | { | |
bddb8eb3 | 2337 | int status; |
ccd979bd | 2338 | int dirty; |
c271c5c2 | 2339 | int local; |
ccd979bd MF |
2340 | struct ocfs2_dinode *local_alloc = NULL; /* only used if we |
2341 | * recover | |
2342 | * ourselves. */ | |
2343 | ||
ccd979bd | 2344 | /* Init our journal object. */ |
da5e7c87 | 2345 | status = ocfs2_journal_init(osb, &dirty); |
ccd979bd MF |
2346 | if (status < 0) { |
2347 | mlog(ML_ERROR, "Could not initialize journal!\n"); | |
2348 | goto finally; | |
2349 | } | |
2350 | ||
3bdb8efd PL |
2351 | /* Now that journal has been initialized, check to make sure |
2352 | entire volume is addressable. */ | |
2353 | status = ocfs2_journal_addressable(osb); | |
2354 | if (status) | |
2355 | goto finally; | |
2356 | ||
ccd979bd MF |
2357 | /* If the journal was unmounted cleanly then we don't want to |
2358 | * recover anything. Otherwise, journal_load will do that | |
2359 | * dirty work for us :) */ | |
2360 | if (!dirty) { | |
2361 | status = ocfs2_journal_wipe(osb->journal, 0); | |
2362 | if (status < 0) { | |
2363 | mlog_errno(status); | |
2364 | goto finally; | |
2365 | } | |
2366 | } else { | |
619c200d SM |
2367 | printk(KERN_NOTICE "ocfs2: File system on device (%s) was not " |
2368 | "unmounted cleanly, recovering it.\n", osb->dev_str); | |
ccd979bd MF |
2369 | } |
2370 | ||
c271c5c2 SM |
2371 | local = ocfs2_mount_local(osb); |
2372 | ||
ccd979bd | 2373 | /* will play back anything left in the journal. */ |
539d8264 | 2374 | status = ocfs2_journal_load(osb->journal, local, dirty); |
01af4820 WW |
2375 | if (status < 0) { |
2376 | mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status); | |
2377 | goto finally; | |
2378 | } | |
ccd979bd | 2379 | |
1dfeb768 | 2380 | if (osb->s_mount_opt & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT) |
2381 | jbd2_journal_set_features(osb->journal->j_journal, | |
2382 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, | |
2383 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); | |
2384 | else | |
2385 | jbd2_journal_clear_features(osb->journal->j_journal, | |
2386 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, | |
2387 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); | |
2388 | ||
ccd979bd MF |
2389 | if (dirty) { |
2390 | /* recover my local alloc if we didn't unmount cleanly. */ | |
2391 | status = ocfs2_begin_local_alloc_recovery(osb, | |
2392 | osb->slot_num, | |
2393 | &local_alloc); | |
2394 | if (status < 0) { | |
2395 | mlog_errno(status); | |
2396 | goto finally; | |
2397 | } | |
2398 | /* we complete the recovery process after we've marked | |
2399 | * ourselves as mounted. */ | |
2400 | } | |
2401 | ||
ccd979bd MF |
2402 | status = ocfs2_load_local_alloc(osb); |
2403 | if (status < 0) { | |
2404 | mlog_errno(status); | |
2405 | goto finally; | |
2406 | } | |
2407 | ||
2408 | if (dirty) { | |
2409 | /* Recovery will be completed after we've mounted the | |
2410 | * rest of the volume. */ | |
ccd979bd MF |
2411 | osb->local_alloc_copy = local_alloc; |
2412 | local_alloc = NULL; | |
2413 | } | |
2414 | ||
2415 | /* go through each journal, trylock it and if you get the | |
2416 | * lock, and it's marked as dirty, set the bit in the recover | |
2417 | * map and launch a recovery thread for it. */ | |
2418 | status = ocfs2_mark_dead_nodes(osb); | |
9140db04 SE |
2419 | if (status < 0) { |
2420 | mlog_errno(status); | |
2421 | goto finally; | |
2422 | } | |
2423 | ||
2424 | status = ocfs2_compute_replay_slots(osb); | |
ccd979bd MF |
2425 | if (status < 0) |
2426 | mlog_errno(status); | |
2427 | ||
2428 | finally: | |
d787ab09 | 2429 | kfree(local_alloc); |
ccd979bd | 2430 | |
c1e8d35e TM |
2431 | if (status) |
2432 | mlog_errno(status); | |
ccd979bd MF |
2433 | return status; |
2434 | } | |
2435 | ||
2436 | /* | |
2437 | * The routine gets called from dismount or close whenever a dismount on | |
2438 | * volume is requested and the osb open count becomes 1. | |
2439 | * It will remove the osb from the global list and also free up all the | |
2440 | * initialized resources and fileobject. | |
2441 | */ | |
2442 | static void ocfs2_delete_osb(struct ocfs2_super *osb) | |
2443 | { | |
ccd979bd MF |
2444 | /* This function assumes that the caller has the main osb resource */ |
2445 | ||
35ddf78e | 2446 | /* ocfs2_initializer_super have already created this workqueue */ |
23e0813a | 2447 | if (osb->ocfs2_wq) |
35ddf78e | 2448 | destroy_workqueue(osb->ocfs2_wq); |
35ddf78e | 2449 | |
8e8a4603 | 2450 | ocfs2_free_slot_info(osb); |
ccd979bd | 2451 | |
b4df6ed8 | 2452 | kfree(osb->osb_orphan_wipes); |
539d8264 | 2453 | kfree(osb->slot_recovery_generations); |
bb20b31d HZO |
2454 | /* FIXME |
2455 | * This belongs in journal shutdown, but because we have to | |
2456 | * allocate osb->journal at the middle of ocfs2_initialize_super(), | |
2457 | * we free it here. | |
2458 | */ | |
2459 | kfree(osb->journal); | |
d787ab09 | 2460 | kfree(osb->local_alloc_copy); |
ccd979bd | 2461 | kfree(osb->uuid_str); |
f13a568e | 2462 | kfree(osb->vol_label); |
ccd979bd MF |
2463 | ocfs2_put_dlm_debug(osb->osb_dlm_debug); |
2464 | memset(osb, 0, sizeof(struct ocfs2_super)); | |
ccd979bd MF |
2465 | } |
2466 | ||
7d0fb914 GR |
2467 | /* Depending on the mount option passed, perform one of the following: |
2468 | * Put OCFS2 into a readonly state (default) | |
2469 | * Return EIO so that only the process errs | |
2470 | * Fix the error as if fsck.ocfs2 -y | |
2471 | * panic | |
2472 | */ | |
2473 | static int ocfs2_handle_error(struct super_block *sb) | |
ccd979bd MF |
2474 | { |
2475 | struct ocfs2_super *osb = OCFS2_SB(sb); | |
7d0fb914 | 2476 | int rv = 0; |
ccd979bd MF |
2477 | |
2478 | ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS); | |
7d0fb914 GR |
2479 | pr_crit("On-disk corruption discovered. " |
2480 | "Please run fsck.ocfs2 once the filesystem is unmounted.\n"); | |
ccd979bd | 2481 | |
7d0fb914 GR |
2482 | if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) { |
2483 | panic("OCFS2: (device %s): panic forced after error\n", | |
2484 | sb->s_id); | |
2485 | } else if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_CONT) { | |
2486 | pr_crit("OCFS2: Returning error to the calling process.\n"); | |
2487 | rv = -EIO; | |
2488 | } else { /* default option */ | |
2489 | rv = -EROFS; | |
bc98a42c | 2490 | if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb))) |
7d0fb914 GR |
2491 | return rv; |
2492 | ||
2493 | pr_crit("OCFS2: File system is now read-only.\n"); | |
1751e8a6 | 2494 | sb->s_flags |= SB_RDONLY; |
7d0fb914 GR |
2495 | ocfs2_set_ro_flag(osb, 0); |
2496 | } | |
2497 | ||
2498 | return rv; | |
ccd979bd MF |
2499 | } |
2500 | ||
7d0fb914 | 2501 | int __ocfs2_error(struct super_block *sb, const char *function, |
1543306e | 2502 | const char *fmt, ...) |
ccd979bd | 2503 | { |
1543306e | 2504 | struct va_format vaf; |
ccd979bd MF |
2505 | va_list args; |
2506 | ||
2507 | va_start(args, fmt); | |
1543306e JP |
2508 | vaf.fmt = fmt; |
2509 | vaf.va = &args; | |
ccd979bd MF |
2510 | |
2511 | /* Not using mlog here because we want to show the actual | |
2512 | * function the error came from. */ | |
7ecef14a | 2513 | printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %pV", |
1543306e JP |
2514 | sb->s_id, function, &vaf); |
2515 | ||
2516 | va_end(args); | |
ccd979bd | 2517 | |
7d0fb914 | 2518 | return ocfs2_handle_error(sb); |
ccd979bd MF |
2519 | } |
2520 | ||
2521 | /* Handle critical errors. This is intentionally more drastic than | |
2522 | * ocfs2_handle_error, so we only use for things like journal errors, | |
2523 | * etc. */ | |
1543306e | 2524 | void __ocfs2_abort(struct super_block *sb, const char *function, |
ccd979bd MF |
2525 | const char *fmt, ...) |
2526 | { | |
1543306e | 2527 | struct va_format vaf; |
ccd979bd MF |
2528 | va_list args; |
2529 | ||
2530 | va_start(args, fmt); | |
ccd979bd | 2531 | |
1543306e JP |
2532 | vaf.fmt = fmt; |
2533 | vaf.va = &args; | |
2534 | ||
7ecef14a | 2535 | printk(KERN_CRIT "OCFS2: abort (device %s): %s: %pV", |
1543306e JP |
2536 | sb->s_id, function, &vaf); |
2537 | ||
2538 | va_end(args); | |
ccd979bd MF |
2539 | |
2540 | /* We don't have the cluster support yet to go straight to | |
2541 | * hard readonly in here. Until then, we want to keep | |
2542 | * ocfs2_abort() so that we can at least mark critical | |
2543 | * errors. | |
2544 | * | |
2545 | * TODO: This should abort the journal and alert other nodes | |
2546 | * that our slot needs recovery. */ | |
2547 | ||
2548 | /* Force a panic(). This stinks, but it's better than letting | |
2549 | * things continue without having a proper hard readonly | |
2550 | * here. */ | |
a2f2ddbf SM |
2551 | if (!ocfs2_mount_local(OCFS2_SB(sb))) |
2552 | OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC; | |
ccd979bd MF |
2553 | ocfs2_handle_error(sb); |
2554 | } | |
2555 | ||
e4b963f1 JB |
2556 | /* |
2557 | * Void signal blockers, because in-kernel sigprocmask() only fails | |
2558 | * when SIG_* is wrong. | |
2559 | */ | |
2560 | void ocfs2_block_signals(sigset_t *oldset) | |
2561 | { | |
2562 | int rc; | |
2563 | sigset_t blocked; | |
2564 | ||
2565 | sigfillset(&blocked); | |
2566 | rc = sigprocmask(SIG_BLOCK, &blocked, oldset); | |
2567 | BUG_ON(rc); | |
2568 | } | |
2569 | ||
2570 | void ocfs2_unblock_signals(sigset_t *oldset) | |
2571 | { | |
2572 | int rc = sigprocmask(SIG_SETMASK, oldset, NULL); | |
2573 | BUG_ON(rc); | |
2574 | } | |
2575 | ||
ccd979bd MF |
2576 | module_init(ocfs2_init); |
2577 | module_exit(ocfs2_exit); |