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