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