blob: c86bd4e60e207dc5765164b6b9bd5cbf7b5c18c9 [file] [log] [blame]
Thomas Gleixner328970d2019-05-24 12:04:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Masahiro Yamadafa60ce22021-05-06 18:06:44 -07002/*
Mark Fashehccd979b2005-12-15 14:31:24 -08003 * super.c
4 *
5 * load/unload driver, mount/dismount volumes
6 *
7 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
Mark Fashehccd979b2005-12-15 14:31:24 -08008 */
9
10#include <linux/module.h>
11#include <linux/fs.h>
12#include <linux/types.h>
13#include <linux/slab.h>
14#include <linux/highmem.h>
Mark Fashehccd979b2005-12-15 14:31:24 -080015#include <linux/init.h>
16#include <linux/random.h>
17#include <linux/statfs.h>
18#include <linux/moduleparam.h>
19#include <linux/blkdev.h>
20#include <linux/socket.h>
21#include <linux/inet.h>
22#include <linux/parser.h>
23#include <linux/crc32.h>
24#include <linux/debugfs.h>
Sunil Mushrand5500712007-09-06 13:34:16 -070025#include <linux/mount.h>
Joel Becker6953b4c2008-01-29 16:59:56 -080026#include <linux/seq_file.h>
Jan Kara19ece542008-08-21 20:13:17 +020027#include <linux/quotaops.h>
Dan Magenheimer1cfd8bd2011-05-26 10:02:08 -060028#include <linux/cleancache.h>
Ingo Molnarf361bf42017-02-03 23:47:37 +010029#include <linux/signal.h>
Mark Fashehccd979b2005-12-15 14:31:24 -080030
Wengang Wang80a9a842011-02-21 11:13:14 +080031#define CREATE_TRACE_POINTS
32#include "ocfs2_trace.h"
33
Mark Fashehccd979b2005-12-15 14:31:24 -080034#include <cluster/masklog.h>
35
36#include "ocfs2.h"
37
38/* this should be the only file to include a version 1 header */
39#include "ocfs1_fs_compat.h"
40
41#include "alloc.h"
Mark Fasheha11f7e62011-06-22 14:23:38 -070042#include "aops.h"
Joel Beckerd030cc92008-12-11 15:04:14 -080043#include "blockcheck.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080044#include "dlmglue.h"
45#include "export.h"
46#include "extent_map.h"
47#include "heartbeat.h"
48#include "inode.h"
49#include "journal.h"
50#include "localalloc.h"
51#include "namei.h"
52#include "slot_map.h"
53#include "super.h"
54#include "sysfile.h"
55#include "uptodate.h"
Tiger Yangcf1d6c72008-08-18 17:11:00 +080056#include "xattr.h"
Jan Kara9e33d692008-08-25 19:56:50 +020057#include "quota.h"
Tao Ma374a2632009-08-24 11:13:37 +080058#include "refcounttree.h"
Tiger Yangb89c5422010-01-25 14:11:06 +080059#include "suballoc.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080060
61#include "buffer_head_io.h"
Gang Hea849d462016-03-22 14:24:27 -070062#include "filecheck.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080063
Fabian Frederick1a5c4e22014-06-04 16:06:06 -070064static struct kmem_cache *ocfs2_inode_cachep;
Jan Kara9e33d692008-08-25 19:56:50 +020065struct kmem_cache *ocfs2_dquot_cachep;
66struct kmem_cache *ocfs2_qf_chunk_cachep;
Mark Fashehccd979b2005-12-15 14:31:24 -080067
Fabian Frederick1a5c4e22014-06-04 16:06:06 -070068static struct dentry *ocfs2_debugfs_root;
Mark Fashehccd979b2005-12-15 14:31:24 -080069
70MODULE_AUTHOR("Oracle");
71MODULE_LICENSE("GPL");
Goldwyn Rodriguesff8fb332014-01-21 15:48:20 -080072MODULE_DESCRIPTION("OCFS2 cluster file system");
Mark Fashehccd979b2005-12-15 14:31:24 -080073
Tiger Yangc0123ad2007-09-08 00:16:10 +080074struct mount_options
75{
Mark Fashehd147b3d2007-11-07 14:40:36 -080076 unsigned long commit_interval;
Tiger Yangc0123ad2007-09-08 00:16:10 +080077 unsigned long mount_opt;
78 unsigned int atime_quantum;
Junxiao Bi38d51b22020-08-06 23:18:02 -070079 unsigned short slot;
Mark Fasheh73c8a802010-04-05 18:17:13 -070080 int localalloc_opt;
Mark Fashehd02f00c2009-12-07 13:10:48 -080081 unsigned int resv_level;
Mark Fasheh83f92312010-04-05 18:17:16 -070082 int dir_resv_level;
Joel Beckerb61817e2008-02-01 15:08:23 -080083 char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
Tiger Yangc0123ad2007-09-08 00:16:10 +080084};
85
Mark Fashehccd979b2005-12-15 14:31:24 -080086static int ocfs2_parse_options(struct super_block *sb, char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +080087 struct mount_options *mopt,
Sunil Mushranbaf46612007-06-18 17:00:24 -070088 int is_remount);
Jan Kara5297aad2009-10-15 14:54:04 +020089static int ocfs2_check_set_options(struct super_block *sb,
90 struct mount_options *options);
Al Viro34c80b12011-12-08 21:32:45 -050091static int ocfs2_show_options(struct seq_file *s, struct dentry *root);
Mark Fashehccd979b2005-12-15 14:31:24 -080092static void ocfs2_put_super(struct super_block *sb);
93static int ocfs2_mount_volume(struct super_block *sb);
94static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
95static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
96static int ocfs2_initialize_mem_caches(void);
97static void ocfs2_free_mem_caches(void);
98static void ocfs2_delete_osb(struct ocfs2_super *osb);
99
David Howells726c3342006-06-23 02:02:58 -0700100static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
Mark Fashehccd979b2005-12-15 14:31:24 -0800101
102static int ocfs2_sync_fs(struct super_block *sb, int wait);
103
104static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
105static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
Denis Chengbddb8eb32007-09-27 02:10:04 +0800106static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800107static int ocfs2_check_volume(struct ocfs2_super *osb);
108static int ocfs2_verify_volume(struct ocfs2_dinode *di,
109 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800110 u32 sectsize,
111 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800112static int ocfs2_initialize_super(struct super_block *sb,
113 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -0800114 int sector_size,
115 struct ocfs2_blockcheck_stats *stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800116static int ocfs2_get_sector(struct super_block *sb,
117 struct buffer_head **bh,
118 int block,
119 int sect_size);
Mark Fashehccd979b2005-12-15 14:31:24 -0800120static struct inode *ocfs2_alloc_inode(struct super_block *sb);
Al Viroe91b9192019-04-15 20:26:42 -0400121static void ocfs2_free_inode(struct inode *inode);
Jan Kara19ece542008-08-21 20:13:17 +0200122static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
123static int ocfs2_enable_quotas(struct ocfs2_super *osb);
124static void ocfs2_disable_quotas(struct ocfs2_super *osb);
Mark Fashehccd979b2005-12-15 14:31:24 -0800125
Jan Kara1c92ec62014-09-29 15:02:51 +0200126static struct dquot **ocfs2_get_dquots(struct inode *inode)
127{
128 return OCFS2_I(inode)->i_dquot;
129}
130
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800131static const struct super_operations ocfs2_sops = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800132 .statfs = ocfs2_statfs,
133 .alloc_inode = ocfs2_alloc_inode,
Al Viroe91b9192019-04-15 20:26:42 -0400134 .free_inode = ocfs2_free_inode,
Mark Fashehccd979b2005-12-15 14:31:24 -0800135 .drop_inode = ocfs2_drop_inode,
Al Viro066d92d2010-06-08 21:28:10 -0400136 .evict_inode = ocfs2_evict_inode,
Mark Fashehccd979b2005-12-15 14:31:24 -0800137 .sync_fs = ocfs2_sync_fs,
Mark Fashehccd979b2005-12-15 14:31:24 -0800138 .put_super = ocfs2_put_super,
139 .remount_fs = ocfs2_remount,
Sunil Mushrand5500712007-09-06 13:34:16 -0700140 .show_options = ocfs2_show_options,
Jan Kara9e33d692008-08-25 19:56:50 +0200141 .quota_read = ocfs2_quota_read,
142 .quota_write = ocfs2_quota_write,
Jan Kara1c92ec62014-09-29 15:02:51 +0200143 .get_dquots = ocfs2_get_dquots,
Mark Fashehccd979b2005-12-15 14:31:24 -0800144};
145
146enum {
147 Opt_barrier,
148 Opt_err_panic,
149 Opt_err_ro,
150 Opt_intr,
151 Opt_nointr,
152 Opt_hb_none,
153 Opt_hb_local,
Sunil Mushran2c442712010-10-07 15:23:50 -0700154 Opt_hb_global,
Mark Fashehccd979b2005-12-15 14:31:24 -0800155 Opt_data_ordered,
156 Opt_data_writeback,
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800157 Opt_atime_quantum,
Sunil Mushranbaf46612007-06-18 17:00:24 -0700158 Opt_slot,
Mark Fashehd147b3d2007-11-07 14:40:36 -0800159 Opt_commit,
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800160 Opt_localalloc,
Mark Fasheh53fc6222007-12-20 16:49:04 -0800161 Opt_localflocks,
Joel Beckerb61817e2008-02-01 15:08:23 -0800162 Opt_stack,
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800163 Opt_user_xattr,
164 Opt_nouser_xattr,
Joel Becker12462f12008-09-03 20:03:40 -0700165 Opt_inode64,
Tiger Yanga68979b2008-11-14 11:17:52 +0800166 Opt_acl,
167 Opt_noacl,
Jan Kara19ece542008-08-21 20:13:17 +0200168 Opt_usrquota,
169 Opt_grpquota,
Tristan Ye7bdb0d12010-10-11 16:46:39 +0800170 Opt_coherency_buffered,
171 Opt_coherency_full,
Mark Fashehd02f00c2009-12-07 13:10:48 -0800172 Opt_resv_level,
Mark Fasheh83f92312010-04-05 18:17:16 -0700173 Opt_dir_resv_level,
alex chen1dfeb762015-02-10 14:09:04 -0800174 Opt_journal_async_commit,
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -0700175 Opt_err_cont,
Gang He912f6552020-06-01 21:45:29 -0700176 Opt_nocluster,
Mark Fashehccd979b2005-12-15 14:31:24 -0800177 Opt_err,
178};
179
Steven Whitehousea447c092008-10-13 10:46:57 +0100180static const match_table_t tokens = {
Mark Fashehccd979b2005-12-15 14:31:24 -0800181 {Opt_barrier, "barrier=%u"},
182 {Opt_err_panic, "errors=panic"},
183 {Opt_err_ro, "errors=remount-ro"},
184 {Opt_intr, "intr"},
185 {Opt_nointr, "nointr"},
186 {Opt_hb_none, OCFS2_HB_NONE},
187 {Opt_hb_local, OCFS2_HB_LOCAL},
Sunil Mushran2c442712010-10-07 15:23:50 -0700188 {Opt_hb_global, OCFS2_HB_GLOBAL},
Mark Fashehccd979b2005-12-15 14:31:24 -0800189 {Opt_data_ordered, "data=ordered"},
190 {Opt_data_writeback, "data=writeback"},
Tiger Yang7f1a37e2006-11-15 15:48:42 +0800191 {Opt_atime_quantum, "atime_quantum=%u"},
Sunil Mushranbaf46612007-06-18 17:00:24 -0700192 {Opt_slot, "preferred_slot=%u"},
Mark Fashehd147b3d2007-11-07 14:40:36 -0800193 {Opt_commit, "commit=%u"},
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800194 {Opt_localalloc, "localalloc=%d"},
Mark Fasheh53fc6222007-12-20 16:49:04 -0800195 {Opt_localflocks, "localflocks"},
Joel Beckerb61817e2008-02-01 15:08:23 -0800196 {Opt_stack, "cluster_stack=%s"},
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800197 {Opt_user_xattr, "user_xattr"},
198 {Opt_nouser_xattr, "nouser_xattr"},
Joel Becker12462f12008-09-03 20:03:40 -0700199 {Opt_inode64, "inode64"},
Tiger Yanga68979b2008-11-14 11:17:52 +0800200 {Opt_acl, "acl"},
201 {Opt_noacl, "noacl"},
Jan Kara19ece542008-08-21 20:13:17 +0200202 {Opt_usrquota, "usrquota"},
203 {Opt_grpquota, "grpquota"},
Tristan Ye7bdb0d12010-10-11 16:46:39 +0800204 {Opt_coherency_buffered, "coherency=buffered"},
205 {Opt_coherency_full, "coherency=full"},
Mark Fashehd02f00c2009-12-07 13:10:48 -0800206 {Opt_resv_level, "resv_level=%u"},
Mark Fasheh83f92312010-04-05 18:17:16 -0700207 {Opt_dir_resv_level, "dir_resv_level=%u"},
alex chen1dfeb762015-02-10 14:09:04 -0800208 {Opt_journal_async_commit, "journal_async_commit"},
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -0700209 {Opt_err_cont, "errors=continue"},
Gang He912f6552020-06-01 21:45:29 -0700210 {Opt_nocluster, "nocluster"},
Mark Fashehccd979b2005-12-15 14:31:24 -0800211 {Opt_err, NULL}
212};
213
Sunil Mushran50397502008-12-17 14:17:43 -0800214#ifdef CONFIG_DEBUG_FS
215static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
216{
Sunil Mushran50397502008-12-17 14:17:43 -0800217 struct ocfs2_cluster_connection *cconn = osb->cconn;
218 struct ocfs2_recovery_map *rm = osb->recovery_map;
Sunil Mushrandf152c22009-06-22 11:40:07 -0700219 struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
220 int i, out = 0;
jiangyiwenbfd97a02016-03-15 14:53:01 -0700221 unsigned long flags;
Sunil Mushran50397502008-12-17 14:17:43 -0800222
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700223 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800224 "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
225 "Device", osb->dev_str, osb->uuid_str,
226 osb->fs_generation, osb->vol_label);
227
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700228 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800229 "%10s => State: %d Flags: 0x%lX\n", "Volume",
230 atomic_read(&osb->vol_state), osb->osb_flags);
231
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700232 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800233 "%10s => Block: %lu Cluster: %d\n", "Sizes",
234 osb->sb->s_blocksize, osb->s_clustersize);
235
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700236 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800237 "%10s => Compat: 0x%X Incompat: 0x%X "
238 "ROcompat: 0x%X\n",
239 "Features", osb->s_feature_compat,
240 osb->s_feature_incompat, osb->s_feature_ro_compat);
241
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700242 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800243 "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
244 osb->s_mount_opt, osb->s_atime_quantum);
245
Sunil Mushranc3d38842009-06-19 14:45:55 -0700246 if (cconn) {
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700247 out += scnprintf(buf + out, len - out,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700248 "%10s => Stack: %s Name: %*s "
249 "Version: %d.%d\n", "Cluster",
250 (*osb->osb_cluster_stack == '\0' ?
251 "o2cb" : osb->osb_cluster_stack),
252 cconn->cc_namelen, cconn->cc_name,
253 cconn->cc_version.pv_major,
254 cconn->cc_version.pv_minor);
255 }
Sunil Mushran50397502008-12-17 14:17:43 -0800256
jiangyiwenbfd97a02016-03-15 14:53:01 -0700257 spin_lock_irqsave(&osb->dc_task_lock, flags);
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700258 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800259 "%10s => Pid: %d Count: %lu WakeSeq: %lu "
260 "WorkSeq: %lu\n", "DownCnvt",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700261 (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
262 osb->blocked_lock_count, osb->dc_wake_sequence,
263 osb->dc_work_sequence);
jiangyiwenbfd97a02016-03-15 14:53:01 -0700264 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
Sunil Mushran50397502008-12-17 14:17:43 -0800265
266 spin_lock(&osb->osb_lock);
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700267 out += scnprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
Sunil Mushran50397502008-12-17 14:17:43 -0800268 "Recovery",
269 (osb->recovery_thread_task ?
270 task_pid_nr(osb->recovery_thread_task) : -1));
271 if (rm->rm_used == 0)
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700272 out += scnprintf(buf + out, len - out, " None\n");
Sunil Mushran50397502008-12-17 14:17:43 -0800273 else {
274 for (i = 0; i < rm->rm_used; i++)
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700275 out += scnprintf(buf + out, len - out, " %d",
Sunil Mushran50397502008-12-17 14:17:43 -0800276 rm->rm_entries[i]);
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700277 out += scnprintf(buf + out, len - out, "\n");
Sunil Mushran50397502008-12-17 14:17:43 -0800278 }
279 spin_unlock(&osb->osb_lock);
280
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700281 out += scnprintf(buf + out, len - out,
Goldwyn Rodrigues8fa9d172013-07-03 15:00:51 -0700282 "%10s => Pid: %d Interval: %lu\n", "Commit",
Sunil Mushranc3d38842009-06-19 14:45:55 -0700283 (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
Goldwyn Rodrigues8fa9d172013-07-03 15:00:51 -0700284 osb->osb_commit_interval);
Sunil Mushran50397502008-12-17 14:17:43 -0800285
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700286 out += scnprintf(buf + out, len - out,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700287 "%10s => State: %d TxnId: %lu NumTxns: %d\n",
Sunil Mushran50397502008-12-17 14:17:43 -0800288 "Journal", osb->journal->j_state,
Sunil Mushranc3d38842009-06-19 14:45:55 -0700289 osb->journal->j_trans_id,
290 atomic_read(&osb->journal->j_num_trans));
Sunil Mushran50397502008-12-17 14:17:43 -0800291
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700292 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800293 "%10s => GlobalAllocs: %d LocalAllocs: %d "
294 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
295 "Stats",
296 atomic_read(&osb->alloc_stats.bitmap_data),
297 atomic_read(&osb->alloc_stats.local_data),
298 atomic_read(&osb->alloc_stats.bg_allocs),
299 atomic_read(&osb->alloc_stats.moves),
300 atomic_read(&osb->alloc_stats.bg_extends));
301
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700302 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800303 "%10s => State: %u Descriptor: %llu Size: %u bits "
304 "Default: %u bits\n",
305 "LocalAlloc", osb->local_alloc_state,
306 (unsigned long long)osb->la_last_gd,
307 osb->local_alloc_bits, osb->local_alloc_default_bits);
308
309 spin_lock(&osb->osb_lock);
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700310 out += scnprintf(buf + out, len - out,
Tiger Yangb89c5422010-01-25 14:11:06 +0800311 "%10s => InodeSlot: %d StolenInodes: %d, "
312 "MetaSlot: %d StolenMeta: %d\n", "Steal",
Sunil Mushran50397502008-12-17 14:17:43 -0800313 osb->s_inode_steal_slot,
Tiger Yangb89c5422010-01-25 14:11:06 +0800314 atomic_read(&osb->s_num_inodes_stolen),
315 osb->s_meta_steal_slot,
316 atomic_read(&osb->s_num_meta_stolen));
Sunil Mushran50397502008-12-17 14:17:43 -0800317 spin_unlock(&osb->osb_lock);
318
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700319 out += scnprintf(buf + out, len - out, "OrphanScan => ");
320 out += scnprintf(buf + out, len - out, "Local: %u Global: %u ",
Sunil Mushrandf152c22009-06-22 11:40:07 -0700321 os->os_count, os->os_seqno);
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700322 out += scnprintf(buf + out, len - out, " Last Scan: ");
Sunil Mushrandf152c22009-06-22 11:40:07 -0700323 if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700324 out += scnprintf(buf + out, len - out, "Disabled\n");
Sunil Mushrandf152c22009-06-22 11:40:07 -0700325 else
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700326 out += scnprintf(buf + out, len - out, "%lu seconds ago\n",
Deepa Dinamani395627b2016-12-12 16:41:23 -0800327 (unsigned long)(ktime_get_seconds() - os->os_scantime));
Sunil Mushrandf152c22009-06-22 11:40:07 -0700328
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700329 out += scnprintf(buf + out, len - out, "%10s => %3s %10s\n",
Sunil Mushran50397502008-12-17 14:17:43 -0800330 "Slots", "Num", "RecoGen");
Sunil Mushran50397502008-12-17 14:17:43 -0800331 for (i = 0; i < osb->max_slots; ++i) {
Takashi Iwaid293d3a2020-04-01 21:04:05 -0700332 out += scnprintf(buf + out, len - out,
Sunil Mushran50397502008-12-17 14:17:43 -0800333 "%10s %c %3d %10d\n",
334 " ",
335 (i == osb->slot_num ? '*' : ' '),
336 i, osb->slot_recovery_generations[i]);
337 }
338
339 return out;
340}
341
342static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
343{
344 struct ocfs2_super *osb = inode->i_private;
345 char *buf = NULL;
346
347 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
348 if (!buf)
349 goto bail;
350
351 i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
352
353 file->private_data = buf;
354
355 return 0;
356bail:
357 return -ENOMEM;
358}
359
360static int ocfs2_debug_release(struct inode *inode, struct file *file)
361{
362 kfree(file->private_data);
363 return 0;
364}
365
366static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
367 size_t nbytes, loff_t *ppos)
368{
369 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
370 i_size_read(file->f_mapping->host));
371}
372#else
373static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
374{
375 return 0;
376}
377static int ocfs2_debug_release(struct inode *inode, struct file *file)
378{
379 return 0;
380}
381static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
382 size_t nbytes, loff_t *ppos)
383{
384 return 0;
385}
386#endif /* CONFIG_DEBUG_FS */
387
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700388static const struct file_operations ocfs2_osb_debug_fops = {
Sunil Mushran50397502008-12-17 14:17:43 -0800389 .open = ocfs2_osb_debug_open,
390 .release = ocfs2_debug_release,
391 .read = ocfs2_debug_read,
392 .llseek = generic_file_llseek,
393};
394
Mark Fashehccd979b2005-12-15 14:31:24 -0800395static int ocfs2_sync_fs(struct super_block *sb, int wait)
396{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800397 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -0800398 tid_t target;
399 struct ocfs2_super *osb = OCFS2_SB(sb);
400
Mark Fashehccd979b2005-12-15 14:31:24 -0800401 if (ocfs2_is_hard_readonly(osb))
402 return -EROFS;
403
404 if (wait) {
405 status = ocfs2_flush_truncate_log(osb);
406 if (status < 0)
407 mlog_errno(status);
408 } else {
409 ocfs2_schedule_truncate_log_flush(osb, 0);
410 }
411
piaojun1119d3c2018-04-05 16:18:33 -0700412 if (jbd2_journal_start_commit(osb->journal->j_journal,
Joel Becker2b4e30f2008-09-03 20:03:41 -0700413 &target)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800414 if (wait)
piaojun1119d3c2018-04-05 16:18:33 -0700415 jbd2_log_wait_commit(osb->journal->j_journal,
Joel Becker2b4e30f2008-09-03 20:03:41 -0700416 target);
Mark Fashehccd979b2005-12-15 14:31:24 -0800417 }
418 return 0;
419}
420
Jan Kara1a224ad2008-08-20 15:43:36 +0200421static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
422{
423 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
424 && (ino == USER_QUOTA_SYSTEM_INODE
425 || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
426 return 0;
427 if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
428 && (ino == GROUP_QUOTA_SYSTEM_INODE
429 || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
430 return 0;
431 return 1;
432}
433
Mark Fashehccd979b2005-12-15 14:31:24 -0800434static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
435{
436 struct inode *new = NULL;
437 int status = 0;
438 int i;
439
Jan Kara5fa06132008-01-11 00:11:45 +0100440 new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800441 if (IS_ERR(new)) {
442 status = PTR_ERR(new);
443 mlog_errno(status);
444 goto bail;
445 }
446 osb->root_inode = new;
447
Jan Kara5fa06132008-01-11 00:11:45 +0100448 new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800449 if (IS_ERR(new)) {
450 status = PTR_ERR(new);
451 mlog_errno(status);
452 goto bail;
453 }
454 osb->sys_root_inode = new;
455
456 for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
457 i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200458 if (!ocfs2_need_system_inode(osb, i))
459 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800460 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
461 if (!new) {
462 ocfs2_release_system_inodes(osb);
piaojun025bcbd2018-01-31 16:14:44 -0800463 status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL;
Mark Fashehccd979b2005-12-15 14:31:24 -0800464 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -0800465 mlog(ML_ERROR, "Unable to load system inode %d, "
466 "possibly corrupt fs?", i);
467 goto bail;
468 }
469 // the array now has one ref, so drop this one
470 iput(new);
471 }
472
473bail:
Tao Mac1e8d352011-03-07 16:43:21 +0800474 if (status)
475 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -0800476 return status;
477}
478
479static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
480{
481 struct inode *new = NULL;
482 int status = 0;
483 int i;
484
Mark Fashehccd979b2005-12-15 14:31:24 -0800485 for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
486 i < NUM_SYSTEM_INODES;
487 i++) {
Jan Kara1a224ad2008-08-20 15:43:36 +0200488 if (!ocfs2_need_system_inode(osb, i))
489 continue;
Mark Fashehccd979b2005-12-15 14:31:24 -0800490 new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
491 if (!new) {
492 ocfs2_release_system_inodes(osb);
piaojun025bcbd2018-01-31 16:14:44 -0800493 status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL;
Mark Fashehccd979b2005-12-15 14:31:24 -0800494 mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
495 status, i, osb->slot_num);
496 goto bail;
497 }
498 /* the array now has one ref, so drop this one */
499 iput(new);
500 }
501
502bail:
Tao Mac1e8d352011-03-07 16:43:21 +0800503 if (status)
504 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -0800505 return status;
506}
507
Denis Chengbddb8eb32007-09-27 02:10:04 +0800508static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
Mark Fashehccd979b2005-12-15 14:31:24 -0800509{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800510 int i;
Mark Fashehccd979b2005-12-15 14:31:24 -0800511 struct inode *inode;
512
Tao Mab4d693f2010-08-16 16:58:21 +0800513 for (i = 0; i < NUM_GLOBAL_SYSTEM_INODES; i++) {
514 inode = osb->global_system_inodes[i];
Mark Fashehccd979b2005-12-15 14:31:24 -0800515 if (inode) {
516 iput(inode);
Tao Mab4d693f2010-08-16 16:58:21 +0800517 osb->global_system_inodes[i] = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -0800518 }
519 }
520
521 inode = osb->sys_root_inode;
522 if (inode) {
523 iput(inode);
524 osb->sys_root_inode = NULL;
525 }
526
527 inode = osb->root_inode;
528 if (inode) {
529 iput(inode);
530 osb->root_inode = NULL;
531 }
532
Tao Mab4d693f2010-08-16 16:58:21 +0800533 if (!osb->local_system_inodes)
Tao Mac1e8d352011-03-07 16:43:21 +0800534 return;
Tao Mab4d693f2010-08-16 16:58:21 +0800535
536 for (i = 0; i < NUM_LOCAL_SYSTEM_INODES * osb->max_slots; i++) {
537 if (osb->local_system_inodes[i]) {
538 iput(osb->local_system_inodes[i]);
539 osb->local_system_inodes[i] = NULL;
540 }
541 }
542
543 kfree(osb->local_system_inodes);
544 osb->local_system_inodes = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -0800545}
546
547/* We're allocating fs objects, use GFP_NOFS */
548static struct inode *ocfs2_alloc_inode(struct super_block *sb)
549{
550 struct ocfs2_inode_info *oi;
551
Christoph Lametere6b4f8d2006-12-06 20:33:14 -0800552 oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
Mark Fashehccd979b2005-12-15 14:31:24 -0800553 if (!oi)
554 return NULL;
555
Darrick J. Wong2931cdc2014-04-03 14:46:48 -0700556 oi->i_sync_tid = 0;
557 oi->i_datasync_tid = 0;
Jan Kara1c92ec62014-09-29 15:02:51 +0200558 memset(&oi->i_dquot, 0, sizeof(oi->i_dquot));
Darrick J. Wong2931cdc2014-04-03 14:46:48 -0700559
Joel Becker2b4e30f2008-09-03 20:03:41 -0700560 jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -0800561 return &oi->vfs_inode;
562}
563
Al Viroe91b9192019-04-15 20:26:42 -0400564static void ocfs2_free_inode(struct inode *inode)
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100565{
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100566 kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
567}
568
Mark Fasheh5a254032007-07-20 12:56:16 -0700569static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
570 unsigned int cbits)
Mark Fashehccd979b2005-12-15 14:31:24 -0800571{
Mark Fasheh5a254032007-07-20 12:56:16 -0700572 unsigned int bytes = 1 << cbits;
573 unsigned int trim = bytes;
574 unsigned int bitshift = 32;
Mark Fashehccd979b2005-12-15 14:31:24 -0800575
Mark Fasheh5a254032007-07-20 12:56:16 -0700576 /*
577 * i_size and all block offsets in ocfs2 are always 64 bits
578 * wide. i_clusters is 32 bits, in cluster-sized units. So on
579 * 64 bit platforms, cluster size will be the limiting factor.
Mark Fashehccd979b2005-12-15 14:31:24 -0800580 */
581
582#if BITS_PER_LONG == 32
Alexey Dobriyan2ecd05a2006-10-11 01:22:05 -0700583 BUILD_BUG_ON(sizeof(sector_t) != 8);
Mark Fasheh5a254032007-07-20 12:56:16 -0700584 /*
585 * We might be limited by page cache size.
586 */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300587 if (bytes > PAGE_SIZE) {
588 bytes = PAGE_SIZE;
Mark Fasheh5a254032007-07-20 12:56:16 -0700589 trim = 1;
590 /*
591 * Shift by 31 here so that we don't get larger than
592 * MAX_LFS_FILESIZE
593 */
594 bitshift = 31;
595 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800596#endif
597
Mark Fasheh5a254032007-07-20 12:56:16 -0700598 /*
599 * Trim by a whole cluster when we can actually approach the
600 * on-disk limits. Otherwise we can overflow i_clusters when
601 * an extent start is at the max offset.
602 */
603 return (((unsigned long long)bytes) << bitshift) - trim;
Mark Fashehccd979b2005-12-15 14:31:24 -0800604}
605
606static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
607{
608 int incompat_features;
609 int ret = 0;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800610 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800611 struct ocfs2_super *osb = OCFS2_SB(sb);
Sunil Mushran2c442712010-10-07 15:23:50 -0700612 u32 tmp;
Mark Fashehccd979b2005-12-15 14:31:24 -0800613
Theodore Ts'o02b99842014-03-13 10:14:33 -0400614 sync_filesystem(sb);
615
Jan Kara5297aad2009-10-15 14:54:04 +0200616 if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
617 !ocfs2_check_set_options(sb, &parsed_options)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800618 ret = -EINVAL;
619 goto out;
620 }
621
Gang He912f6552020-06-01 21:45:29 -0700622 tmp = OCFS2_MOUNT_NOCLUSTER;
623 if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
624 ret = -EINVAL;
625 mlog(ML_ERROR, "Cannot change nocluster option on remount\n");
626 goto out;
627 }
628
Sunil Mushran2c442712010-10-07 15:23:50 -0700629 tmp = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL |
630 OCFS2_MOUNT_HB_NONE;
631 if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800632 ret = -EINVAL;
633 mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
634 goto out;
635 }
636
637 if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
Tiger Yangc0123ad2007-09-08 00:16:10 +0800638 (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800639 ret = -EINVAL;
640 mlog(ML_ERROR, "Cannot change data mode on remount\n");
641 goto out;
642 }
643
Joel Becker12462f12008-09-03 20:03:40 -0700644 /* Probably don't want this on remount; it might
645 * mess with other nodes */
646 if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
647 (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
648 ret = -EINVAL;
649 mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
650 goto out;
651 }
652
Mark Fashehccd979b2005-12-15 14:31:24 -0800653 /* We're going to/from readonly mode. */
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800654 if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) {
Jan Kara19ece542008-08-21 20:13:17 +0200655 /* Disable quota accounting before remounting RO */
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800656 if (*flags & SB_RDONLY) {
Jan Kara19ece542008-08-21 20:13:17 +0200657 ret = ocfs2_susp_quotas(osb, 0);
658 if (ret < 0)
659 goto out;
660 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800661 /* Lock here so the check of HARD_RO and the potential
662 * setting of SOFT_RO is atomic. */
663 spin_lock(&osb->osb_lock);
664 if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
665 mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
666 ret = -EROFS;
667 goto unlock_osb;
668 }
669
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800670 if (*flags & SB_RDONLY) {
671 sb->s_flags |= SB_RDONLY;
Mark Fashehccd979b2005-12-15 14:31:24 -0800672 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
673 } else {
Mark Fashehccd979b2005-12-15 14:31:24 -0800674 if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
675 mlog(ML_ERROR, "Cannot remount RDWR "
676 "filesystem due to previous errors.\n");
677 ret = -EROFS;
678 goto unlock_osb;
679 }
680 incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
681 if (incompat_features) {
682 mlog(ML_ERROR, "Cannot remount RDWR because "
683 "of unsupported optional features "
684 "(%x).\n", incompat_features);
685 ret = -EINVAL;
686 goto unlock_osb;
687 }
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800688 sb->s_flags &= ~SB_RDONLY;
Mark Fashehccd979b2005-12-15 14:31:24 -0800689 osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
690 }
Tao Ma32a42d32011-02-23 21:29:08 +0800691 trace_ocfs2_remount(sb->s_flags, osb->osb_flags, *flags);
Mark Fashehccd979b2005-12-15 14:31:24 -0800692unlock_osb:
693 spin_unlock(&osb->osb_lock);
Jan Kara19ece542008-08-21 20:13:17 +0200694 /* Enable quota accounting after remounting RW */
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800695 if (!ret && !(*flags & SB_RDONLY)) {
Jan Kara19ece542008-08-21 20:13:17 +0200696 if (sb_any_quota_suspended(sb))
697 ret = ocfs2_susp_quotas(osb, 1);
698 else
699 ret = ocfs2_enable_quotas(osb);
700 if (ret < 0) {
701 /* Return back changes... */
702 spin_lock(&osb->osb_lock);
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800703 sb->s_flags |= SB_RDONLY;
Jan Kara19ece542008-08-21 20:13:17 +0200704 osb->osb_flags |= OCFS2_OSB_SOFT_RO;
705 spin_unlock(&osb->osb_lock);
706 goto out;
707 }
708 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800709 }
710
711 if (!ret) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800712 /* Only save off the new mount options in case of a successful
713 * remount. */
Tiger Yangc0123ad2007-09-08 00:16:10 +0800714 osb->s_mount_opt = parsed_options.mount_opt;
715 osb->s_atime_quantum = parsed_options.atime_quantum;
716 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -0800717 if (parsed_options.commit_interval)
718 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fashehe001e792007-11-07 14:21:45 -0800719
720 if (!ocfs2_is_hard_readonly(osb))
721 ocfs2_set_journal_params(osb);
Jan Kara57b09bb2009-10-15 14:54:05 +0200722
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800723 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
Jan Kara57b09bb2009-10-15 14:54:05 +0200724 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800725 SB_POSIXACL : 0);
Mark Fashehccd979b2005-12-15 14:31:24 -0800726 }
727out:
728 return ret;
729}
730
731static int ocfs2_sb_probe(struct super_block *sb,
732 struct buffer_head **bh,
Joel Becker73be1922009-01-06 14:57:08 -0800733 int *sector_size,
734 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -0800735{
Denis Chengbddb8eb32007-09-27 02:10:04 +0800736 int status, tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800737 struct ocfs1_vol_disk_hdr *hdr;
738 struct ocfs2_dinode *di;
739 int blksize;
740
741 *bh = NULL;
742
743 /* may be > 512 */
Martin K. Petersene1defc42009-05-22 17:17:49 -0400744 *sector_size = bdev_logical_block_size(sb->s_bdev);
Mark Fashehccd979b2005-12-15 14:31:24 -0800745 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
746 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
747 *sector_size, OCFS2_MAX_BLOCKSIZE);
748 status = -EINVAL;
749 goto bail;
750 }
751
752 /* Can this really happen? */
753 if (*sector_size < OCFS2_MIN_BLOCKSIZE)
754 *sector_size = OCFS2_MIN_BLOCKSIZE;
755
756 /* check block zero for old format */
757 status = ocfs2_get_sector(sb, bh, 0, *sector_size);
758 if (status < 0) {
759 mlog_errno(status);
760 goto bail;
761 }
762 hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
763 if (hdr->major_version == OCFS1_MAJOR_VERSION) {
764 mlog(ML_ERROR, "incompatible version: %u.%u\n",
765 hdr->major_version, hdr->minor_version);
766 status = -EINVAL;
767 }
768 if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
769 strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
770 mlog(ML_ERROR, "incompatible volume signature: %8s\n",
771 hdr->signature);
772 status = -EINVAL;
773 }
774 brelse(*bh);
775 *bh = NULL;
776 if (status < 0) {
777 mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
778 "upgraded before mounting with ocfs v2\n");
779 goto bail;
780 }
781
782 /*
783 * Now check at magic offset for 512, 1024, 2048, 4096
784 * blocksizes. 4096 is the maximum blocksize because it is
785 * the minimum clustersize.
786 */
787 status = -EINVAL;
788 for (blksize = *sector_size;
789 blksize <= OCFS2_MAX_BLOCKSIZE;
790 blksize <<= 1) {
791 tmpstat = ocfs2_get_sector(sb, bh,
792 OCFS2_SUPER_BLOCK_BLKNO,
793 blksize);
794 if (tmpstat < 0) {
795 status = tmpstat;
796 mlog_errno(status);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700797 break;
Mark Fashehccd979b2005-12-15 14:31:24 -0800798 }
799 di = (struct ocfs2_dinode *) (*bh)->b_data;
Joel Becker73be1922009-01-06 14:57:08 -0800800 memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
Jan Kara1c1d9792009-07-22 13:17:19 +0200801 spin_lock_init(&stats->b_lock);
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700802 tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
803 if (tmpstat < 0) {
804 brelse(*bh);
805 *bh = NULL;
806 }
807 if (tmpstat != -EAGAIN) {
808 status = tmpstat;
Mark Fashehccd979b2005-12-15 14:31:24 -0800809 break;
Joel Beckerfb5cbe92009-10-28 22:28:24 -0700810 }
Mark Fashehccd979b2005-12-15 14:31:24 -0800811 }
812
813bail:
814 return status;
815}
816
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800817static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
818{
Sunil Mushran2c442712010-10-07 15:23:50 -0700819 u32 hb_enabled = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL;
820
821 if (osb->s_mount_opt & hb_enabled) {
822 if (ocfs2_mount_local(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800823 mlog(ML_ERROR, "Cannot heartbeat on a locally "
824 "mounted device.\n");
825 return -EINVAL;
826 }
Sunil Mushran2c442712010-10-07 15:23:50 -0700827 if (ocfs2_userspace_stack(osb)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800828 mlog(ML_ERROR, "Userspace stack expected, but "
829 "o2cb heartbeat arguments passed to mount\n");
830 return -EINVAL;
831 }
Sunil Mushran2c442712010-10-07 15:23:50 -0700832 if (((osb->s_mount_opt & OCFS2_MOUNT_HB_GLOBAL) &&
833 !ocfs2_cluster_o2cb_global_heartbeat(osb)) ||
834 ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) &&
835 ocfs2_cluster_o2cb_global_heartbeat(osb))) {
836 mlog(ML_ERROR, "Mismatching o2cb heartbeat modes\n");
837 return -EINVAL;
838 }
Joel Beckerb61817e2008-02-01 15:08:23 -0800839 }
840
Sunil Mushran2c442712010-10-07 15:23:50 -0700841 if (!(osb->s_mount_opt & hb_enabled)) {
Joel Beckerb61817e2008-02-01 15:08:23 -0800842 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
843 !ocfs2_userspace_stack(osb)) {
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800844 mlog(ML_ERROR, "Heartbeat has to be started to mount "
845 "a read-write clustered device.\n");
846 return -EINVAL;
847 }
848 }
849
850 return 0;
851}
852
Joel Beckerb61817e2008-02-01 15:08:23 -0800853/*
854 * If we're using a userspace stack, mount should have passed
855 * a name that matches the disk. If not, mount should not
856 * have passed a stack.
857 */
858static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
859 struct mount_options *mopt)
860{
861 if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
862 mlog(ML_ERROR,
863 "cluster stack passed to mount, but this filesystem "
864 "does not support it\n");
865 return -EINVAL;
866 }
867
868 if (ocfs2_userspace_stack(osb) &&
Gang He912f6552020-06-01 21:45:29 -0700869 !(osb->s_mount_opt & OCFS2_MOUNT_NOCLUSTER) &&
Joel Beckerb61817e2008-02-01 15:08:23 -0800870 strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
871 OCFS2_STACK_LABEL_LEN)) {
872 mlog(ML_ERROR,
873 "cluster stack passed to mount (\"%s\") does not "
874 "match the filesystem (\"%s\")\n",
875 mopt->cluster_stack,
876 osb->osb_cluster_stack);
877 return -EINVAL;
878 }
879
880 return 0;
881}
882
Jan Kara19ece542008-08-21 20:13:17 +0200883static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
884{
885 int type;
886 struct super_block *sb = osb->sb;
Jan Kara52362812014-09-10 21:06:39 +0200887 unsigned int feature[OCFS2_MAXQUOTAS] = {
888 OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
889 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
Jan Kara19ece542008-08-21 20:13:17 +0200890 int status = 0;
891
Jan Kara52362812014-09-10 21:06:39 +0200892 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
Jan Kara19ece542008-08-21 20:13:17 +0200893 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
894 continue;
895 if (unsuspend)
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400896 status = dquot_resume(sb, type);
Jan Karaeea7feb2010-05-13 22:14:53 +0200897 else {
898 struct ocfs2_mem_dqinfo *oinfo;
899
900 /* Cancel periodic syncing before suspending */
901 oinfo = sb_dqinfo(sb, type)->dqi_priv;
902 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400903 status = dquot_suspend(sb, type);
Jan Karaeea7feb2010-05-13 22:14:53 +0200904 }
Jan Kara19ece542008-08-21 20:13:17 +0200905 if (status < 0)
906 break;
907 }
908 if (status < 0)
909 mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
910 "remount (error = %d).\n", status);
911 return status;
912}
913
914static int ocfs2_enable_quotas(struct ocfs2_super *osb)
915{
Jan Kara52362812014-09-10 21:06:39 +0200916 struct inode *inode[OCFS2_MAXQUOTAS] = { NULL, NULL };
Jan Kara19ece542008-08-21 20:13:17 +0200917 struct super_block *sb = osb->sb;
Jan Kara52362812014-09-10 21:06:39 +0200918 unsigned int feature[OCFS2_MAXQUOTAS] = {
919 OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
920 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
921 unsigned int ino[OCFS2_MAXQUOTAS] = {
922 LOCAL_USER_QUOTA_SYSTEM_INODE,
Jan Kara19ece542008-08-21 20:13:17 +0200923 LOCAL_GROUP_QUOTA_SYSTEM_INODE };
924 int status;
925 int type;
926
927 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
Jan Kara52362812014-09-10 21:06:39 +0200928 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
Jan Kara19ece542008-08-21 20:13:17 +0200929 if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
930 continue;
931 inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
932 osb->slot_num);
933 if (!inode[type]) {
934 status = -ENOENT;
935 goto out_quota_off;
936 }
Jan Kara7212b952019-11-01 18:55:38 +0100937 status = dquot_load_quota_inode(inode[type], type, QFMT_OCFS2,
938 DQUOT_USAGE_ENABLED);
Jan Kara19ece542008-08-21 20:13:17 +0200939 if (status < 0)
940 goto out_quota_off;
941 }
942
Jan Kara52362812014-09-10 21:06:39 +0200943 for (type = 0; type < OCFS2_MAXQUOTAS; type++)
Jan Kara19ece542008-08-21 20:13:17 +0200944 iput(inode[type]);
945 return 0;
946out_quota_off:
947 ocfs2_disable_quotas(osb);
Jan Kara52362812014-09-10 21:06:39 +0200948 for (type = 0; type < OCFS2_MAXQUOTAS; type++)
Jan Kara19ece542008-08-21 20:13:17 +0200949 iput(inode[type]);
950 mlog_errno(status);
951 return status;
952}
953
954static void ocfs2_disable_quotas(struct ocfs2_super *osb)
955{
956 int type;
957 struct inode *inode;
958 struct super_block *sb = osb->sb;
Jan Karac06bcbf2010-05-13 22:14:53 +0200959 struct ocfs2_mem_dqinfo *oinfo;
Jan Kara19ece542008-08-21 20:13:17 +0200960
961 /* We mostly ignore errors in this function because there's not much
962 * we can do when we see them */
Jan Kara52362812014-09-10 21:06:39 +0200963 for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
Jan Kara19ece542008-08-21 20:13:17 +0200964 if (!sb_has_quota_loaded(sb, type))
965 continue;
Jan Karac06bcbf2010-05-13 22:14:53 +0200966 oinfo = sb_dqinfo(sb, type)->dqi_priv;
967 cancel_delayed_work_sync(&oinfo->dqi_sync_work);
Jan Kara19ece542008-08-21 20:13:17 +0200968 inode = igrab(sb->s_dquot.files[type]);
969 /* Turn off quotas. This will remove all dquot structures from
970 * memory and so they will be automatically synced to global
971 * quota files */
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400972 dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
973 DQUOT_LIMITS_ENABLED);
Jan Kara19ece542008-08-21 20:13:17 +0200974 iput(inode);
975 }
976}
977
Mark Fashehccd979b2005-12-15 14:31:24 -0800978static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
979{
980 struct dentry *root;
981 int status, sector_size;
Tiger Yangc0123ad2007-09-08 00:16:10 +0800982 struct mount_options parsed_options;
Mark Fashehccd979b2005-12-15 14:31:24 -0800983 struct inode *inode = NULL;
984 struct ocfs2_super *osb = NULL;
985 struct buffer_head *bh = NULL;
Goldwyn Rodrigues49fa8140e2013-08-28 16:35:21 -0700986 char nodestr[12];
Joel Becker73be1922009-01-06 14:57:08 -0800987 struct ocfs2_blockcheck_stats stats;
Mark Fashehccd979b2005-12-15 14:31:24 -0800988
Tao Ma32a42d32011-02-23 21:29:08 +0800989 trace_ocfs2_fill_super(sb, data, silent);
Mark Fashehccd979b2005-12-15 14:31:24 -0800990
Tiger Yangc0123ad2007-09-08 00:16:10 +0800991 if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
Mark Fashehccd979b2005-12-15 14:31:24 -0800992 status = -EINVAL;
993 goto read_super_error;
994 }
995
996 /* probe for superblock */
Joel Becker73be1922009-01-06 14:57:08 -0800997 status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -0800998 if (status < 0) {
999 mlog(ML_ERROR, "superblock probe failed!\n");
1000 goto read_super_error;
1001 }
1002
Joel Becker73be1922009-01-06 14:57:08 -08001003 status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
Mark Fashehccd979b2005-12-15 14:31:24 -08001004 osb = OCFS2_SB(sb);
1005 if (status < 0) {
1006 mlog_errno(status);
1007 goto read_super_error;
1008 }
1009 brelse(bh);
1010 bh = NULL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001011
Jan Kara5297aad2009-10-15 14:54:04 +02001012 if (!ocfs2_check_set_options(sb, &parsed_options)) {
1013 status = -EINVAL;
1014 goto read_super_error;
1015 }
Tiger Yangc0123ad2007-09-08 00:16:10 +08001016 osb->s_mount_opt = parsed_options.mount_opt;
1017 osb->s_atime_quantum = parsed_options.atime_quantum;
1018 osb->preferred_slot = parsed_options.slot;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001019 osb->osb_commit_interval = parsed_options.commit_interval;
Mark Fasheh73c8a802010-04-05 18:17:13 -07001020
1021 ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
Mark Fashehd02f00c2009-12-07 13:10:48 -08001022 osb->osb_resv_level = parsed_options.resv_level;
Mark Fasheh83f92312010-04-05 18:17:16 -07001023 osb->osb_dir_resv_level = parsed_options.resv_level;
1024 if (parsed_options.dir_resv_level == -1)
1025 osb->osb_dir_resv_level = parsed_options.resv_level;
1026 else
1027 osb->osb_dir_resv_level = parsed_options.dir_resv_level;
Mark Fashehccd979b2005-12-15 14:31:24 -08001028
Joel Beckerb61817e2008-02-01 15:08:23 -08001029 status = ocfs2_verify_userspace_stack(osb, &parsed_options);
1030 if (status)
1031 goto read_super_error;
1032
Mark Fashehccd979b2005-12-15 14:31:24 -08001033 sb->s_magic = OCFS2_SUPER_MAGIC;
1034
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001035 sb->s_flags = (sb->s_flags & ~(SB_POSIXACL | SB_NOSEC)) |
1036 ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0);
Tiger Yanga68979b2008-11-14 11:17:52 +08001037
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001038 /* Hard readonly mode only if: bdev_read_only, SB_RDONLY,
Mark Fashehccd979b2005-12-15 14:31:24 -08001039 * heartbeat=none */
1040 if (bdev_read_only(sb->s_bdev)) {
David Howellsbc98a422017-07-17 08:45:34 +01001041 if (!sb_rdonly(sb)) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001042 status = -EACCES;
1043 mlog(ML_ERROR, "Readonly device detected but readonly "
1044 "mount was not specified.\n");
1045 goto read_super_error;
1046 }
1047
1048 /* You should not be able to start a local heartbeat
1049 * on a readonly device. */
1050 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
1051 status = -EROFS;
1052 mlog(ML_ERROR, "Local heartbeat specified on readonly "
1053 "device.\n");
1054 goto read_super_error;
1055 }
1056
1057 status = ocfs2_check_journals_nolocks(osb);
1058 if (status < 0) {
1059 if (status == -EROFS)
1060 mlog(ML_ERROR, "Recovery required on readonly "
1061 "file system, but write access is "
1062 "unavailable.\n");
1063 else
Sunil Mushran2bd63212010-01-25 16:57:38 -08001064 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -08001065 goto read_super_error;
1066 }
1067
1068 ocfs2_set_ro_flag(osb, 1);
1069
Sunil Mushran619c2002011-07-24 10:34:54 -07001070 printk(KERN_NOTICE "ocfs2: Readonly device (%s) detected. "
1071 "Cluster services will not be used for this mount. "
1072 "Recovery will be skipped.\n", osb->dev_str);
Mark Fashehccd979b2005-12-15 14:31:24 -08001073 }
1074
1075 if (!ocfs2_is_hard_readonly(osb)) {
David Howellsbc98a422017-07-17 08:45:34 +01001076 if (sb_rdonly(sb))
Mark Fashehccd979b2005-12-15 14:31:24 -08001077 ocfs2_set_ro_flag(osb, 0);
1078 }
1079
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001080 status = ocfs2_verify_heartbeat(osb);
1081 if (status < 0) {
1082 mlog_errno(status);
1083 goto read_super_error;
1084 }
1085
Mark Fashehccd979b2005-12-15 14:31:24 -08001086 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
1087 ocfs2_debugfs_root);
Mark Fashehccd979b2005-12-15 14:31:24 -08001088
Greg Kroah-Hartman5e7a3ed2019-09-23 15:33:15 -07001089 debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root,
1090 osb, &ocfs2_osb_debug_fops);
Sunil Mushran50397502008-12-17 14:17:43 -08001091
Greg Kroah-Hartmane5815952019-07-11 20:53:12 -07001092 if (ocfs2_meta_ecc(osb))
1093 ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats,
1094 osb->osb_debug_root);
Joel Becker73be1922009-01-06 14:57:08 -08001095
Mark Fashehccd979b2005-12-15 14:31:24 -08001096 status = ocfs2_mount_volume(sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001097 if (status < 0)
1098 goto read_super_error;
1099
Al Virobe0d93f2012-02-12 21:46:49 -05001100 if (osb->root_inode)
1101 inode = igrab(osb->root_inode);
1102
Mark Fashehccd979b2005-12-15 14:31:24 -08001103 if (!inode) {
1104 status = -EIO;
1105 mlog_errno(status);
1106 goto read_super_error;
1107 }
1108
Al Viro48fde702012-01-08 22:15:13 -05001109 root = d_make_root(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001110 if (!root) {
1111 status = -ENOMEM;
1112 mlog_errno(status);
1113 goto read_super_error;
1114 }
1115
1116 sb->s_root = root;
1117
1118 ocfs2_complete_mount_recovery(osb);
1119
Gang He5f483c42018-04-05 16:19:29 -07001120 osb->osb_dev_kset = kset_create_and_add(sb->s_id, NULL,
1121 &ocfs2_kset->kobj);
1122 if (!osb->osb_dev_kset) {
1123 status = -ENOMEM;
1124 mlog(ML_ERROR, "Unable to create device kset %s.\n", sb->s_id);
1125 goto read_super_error;
1126 }
1127
1128 /* Create filecheck sysfs related directories/files at
1129 * /sys/fs/ocfs2/<devname>/filecheck */
1130 if (ocfs2_filecheck_create_sysfs(osb)) {
1131 status = -ENOMEM;
1132 mlog(ML_ERROR, "Unable to create filecheck sysfs directory at "
1133 "/sys/fs/ocfs2/%s/filecheck.\n", sb->s_id);
1134 goto read_super_error;
1135 }
1136
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001137 if (ocfs2_mount_local(osb))
1138 snprintf(nodestr, sizeof(nodestr), "local");
1139 else
Joel Becker19fdb622008-01-30 15:38:24 -08001140 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001141
1142 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
Sunil Mushran781ee3e2006-04-27 16:41:31 -07001143 "with %s data mode.\n",
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001144 osb->dev_str, nodestr, osb->slot_num,
Mark Fashehccd979b2005-12-15 14:31:24 -08001145 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
1146 "ordered");
1147
Gang He912f6552020-06-01 21:45:29 -07001148 if ((osb->s_mount_opt & OCFS2_MOUNT_NOCLUSTER) &&
1149 !(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT))
1150 printk(KERN_NOTICE "ocfs2: The shared device (%s) is mounted "
1151 "without cluster aware mode.\n", osb->dev_str);
1152
Mark Fashehccd979b2005-12-15 14:31:24 -08001153 atomic_set(&osb->vol_state, VOLUME_MOUNTED);
1154 wake_up(&osb->osb_mount_event);
1155
Jan Kara19ece542008-08-21 20:13:17 +02001156 /* Now we can initialize quotas because we can afford to wait
1157 * for cluster locks recovery now. That also means that truncation
1158 * log recovery can happen but that waits for proper quota setup */
David Howellsbc98a422017-07-17 08:45:34 +01001159 if (!sb_rdonly(sb)) {
Jan Kara19ece542008-08-21 20:13:17 +02001160 status = ocfs2_enable_quotas(osb);
1161 if (status < 0) {
1162 /* We have to err-out specially here because
1163 * s_root is already set */
1164 mlog_errno(status);
1165 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1166 wake_up(&osb->osb_mount_event);
Jan Kara19ece542008-08-21 20:13:17 +02001167 return status;
1168 }
1169 }
1170
1171 ocfs2_complete_quota_recovery(osb);
1172
1173 /* Now we wake up again for processes waiting for quotas */
1174 atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
1175 wake_up(&osb->osb_mount_event);
1176
Sunil Mushrandf152c22009-06-22 11:40:07 -07001177 /* Start this when the mount is almost sure of being successful */
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04001178 ocfs2_orphan_scan_start(osb);
Sunil Mushrandf152c22009-06-22 11:40:07 -07001179
Mark Fashehccd979b2005-12-15 14:31:24 -08001180 return status;
1181
1182read_super_error:
Mark Fasheha81cb882008-10-07 14:25:16 -07001183 brelse(bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001184
Gang Hea52370b2018-01-31 16:14:29 -08001185 if (status)
1186 mlog_errno(status);
1187
Mark Fashehccd979b2005-12-15 14:31:24 -08001188 if (osb) {
1189 atomic_set(&osb->vol_state, VOLUME_DISABLED);
1190 wake_up(&osb->osb_mount_event);
1191 ocfs2_dismount_volume(sb, 1);
1192 }
1193
Mark Fashehccd979b2005-12-15 14:31:24 -08001194 return status;
1195}
1196
Al Viro152a0832010-07-25 00:46:55 +04001197static struct dentry *ocfs2_mount(struct file_system_type *fs_type,
David Howells454e2392006-06-23 02:02:57 -07001198 int flags,
1199 const char *dev_name,
Al Viro152a0832010-07-25 00:46:55 +04001200 void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001201{
Al Viro152a0832010-07-25 00:46:55 +04001202 return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
Mark Fashehccd979b2005-12-15 14:31:24 -08001203}
1204
1205static struct file_system_type ocfs2_fs_type = {
1206 .owner = THIS_MODULE,
1207 .name = "ocfs2",
Al Viro152a0832010-07-25 00:46:55 +04001208 .mount = ocfs2_mount,
Goldwyn Rodrigues8ed6b232014-04-03 14:46:59 -07001209 .kill_sb = kill_block_super,
Mark Fasheh1ba9da22006-09-08 14:22:54 -07001210 .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
Mark Fashehccd979b2005-12-15 14:31:24 -08001211 .next = NULL
1212};
Eric W. Biederman91417702013-03-07 01:08:55 -08001213MODULE_ALIAS_FS("ocfs2");
Mark Fashehccd979b2005-12-15 14:31:24 -08001214
Jan Kara5297aad2009-10-15 14:54:04 +02001215static int ocfs2_check_set_options(struct super_block *sb,
1216 struct mount_options *options)
1217{
1218 if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
1219 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1220 OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
1221 mlog(ML_ERROR, "User quotas were requested, but this "
1222 "filesystem does not have the feature enabled.\n");
1223 return 0;
1224 }
1225 if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
1226 !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
1227 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
1228 mlog(ML_ERROR, "Group quotas were requested, but this "
1229 "filesystem does not have the feature enabled.\n");
1230 return 0;
1231 }
1232 if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
1233 !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
1234 mlog(ML_ERROR, "ACL support requested but extended attributes "
1235 "feature is not enabled\n");
1236 return 0;
1237 }
1238 /* No ACL setting specified? Use XATTR feature... */
1239 if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
1240 OCFS2_MOUNT_NO_POSIX_ACL))) {
1241 if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
1242 options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
1243 else
1244 options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
1245 }
1246 return 1;
1247}
1248
Mark Fashehccd979b2005-12-15 14:31:24 -08001249static int ocfs2_parse_options(struct super_block *sb,
1250 char *options,
Tiger Yangc0123ad2007-09-08 00:16:10 +08001251 struct mount_options *mopt,
Mark Fashehccd979b2005-12-15 14:31:24 -08001252 int is_remount)
1253{
Mark Fasheh52c303c2011-01-31 11:31:04 -08001254 int status, user_stack = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001255 char *p;
Sunil Mushran2c442712010-10-07 15:23:50 -07001256 u32 tmp;
Norton.Zhu3eb5bdf2016-01-14 15:17:09 -08001257 int token, option;
1258 substring_t args[MAX_OPT_ARGS];
Mark Fashehccd979b2005-12-15 14:31:24 -08001259
Tao Ma32a42d32011-02-23 21:29:08 +08001260 trace_ocfs2_parse_options(is_remount, options ? options : "(none)");
Mark Fashehccd979b2005-12-15 14:31:24 -08001261
Mark Fashehd147b3d2007-11-07 14:40:36 -08001262 mopt->commit_interval = 0;
Sunil Mushran4b37fcb2010-04-13 18:00:31 -07001263 mopt->mount_opt = OCFS2_MOUNT_NOINTR;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001264 mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
1265 mopt->slot = OCFS2_INVALID_SLOT;
Mark Fasheh73c8a802010-04-05 18:17:13 -07001266 mopt->localalloc_opt = -1;
Joel Beckerb61817e2008-02-01 15:08:23 -08001267 mopt->cluster_stack[0] = '\0';
Mark Fashehd02f00c2009-12-07 13:10:48 -08001268 mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
Mark Fasheh83f92312010-04-05 18:17:16 -07001269 mopt->dir_resv_level = -1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001270
1271 if (!options) {
1272 status = 1;
1273 goto bail;
1274 }
1275
1276 while ((p = strsep(&options, ",")) != NULL) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001277 if (!*p)
1278 continue;
1279
1280 token = match_token(p, tokens, args);
1281 switch (token) {
1282 case Opt_hb_local:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001283 mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001284 break;
1285 case Opt_hb_none:
Sunil Mushran2c442712010-10-07 15:23:50 -07001286 mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
1287 break;
1288 case Opt_hb_global:
1289 mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001290 break;
1291 case Opt_barrier:
1292 if (match_int(&args[0], &option)) {
1293 status = 0;
1294 goto bail;
1295 }
1296 if (option)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001297 mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001298 else
Tiger Yangc0123ad2007-09-08 00:16:10 +08001299 mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
Mark Fashehccd979b2005-12-15 14:31:24 -08001300 break;
1301 case Opt_intr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001302 mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001303 break;
1304 case Opt_nointr:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001305 mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
Mark Fashehccd979b2005-12-15 14:31:24 -08001306 break;
1307 case Opt_err_panic:
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07001308 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
1309 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001310 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08001311 break;
1312 case Opt_err_ro:
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07001313 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
Tiger Yangc0123ad2007-09-08 00:16:10 +08001314 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07001315 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_ROFS;
1316 break;
1317 case Opt_err_cont:
1318 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
1319 mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
1320 mopt->mount_opt |= OCFS2_MOUNT_ERRORS_CONT;
Mark Fashehccd979b2005-12-15 14:31:24 -08001321 break;
1322 case Opt_data_ordered:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001323 mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001324 break;
1325 case Opt_data_writeback:
Tiger Yangc0123ad2007-09-08 00:16:10 +08001326 mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
Mark Fashehccd979b2005-12-15 14:31:24 -08001327 break;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001328 case Opt_user_xattr:
1329 mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
1330 break;
1331 case Opt_nouser_xattr:
1332 mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
1333 break;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001334 case Opt_atime_quantum:
1335 if (match_int(&args[0], &option)) {
1336 status = 0;
1337 goto bail;
1338 }
1339 if (option >= 0)
Tiger Yangc0123ad2007-09-08 00:16:10 +08001340 mopt->atime_quantum = option;
Tiger Yang7f1a37e2006-11-15 15:48:42 +08001341 break;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001342 case Opt_slot:
Sunil Mushranbaf46612007-06-18 17:00:24 -07001343 if (match_int(&args[0], &option)) {
1344 status = 0;
1345 goto bail;
1346 }
1347 if (option)
Junxiao Bi38d51b22020-08-06 23:18:02 -07001348 mopt->slot = (u16)option;
Sunil Mushranbaf46612007-06-18 17:00:24 -07001349 break;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001350 case Opt_commit:
Mark Fashehd147b3d2007-11-07 14:40:36 -08001351 if (match_int(&args[0], &option)) {
1352 status = 0;
1353 goto bail;
1354 }
1355 if (option < 0)
1356 return 0;
1357 if (option == 0)
Joel Becker2b4e30f2008-09-03 20:03:41 -07001358 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
Mark Fashehd147b3d2007-11-07 14:40:36 -08001359 mopt->commit_interval = HZ * option;
1360 break;
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001361 case Opt_localalloc:
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001362 if (match_int(&args[0], &option)) {
1363 status = 0;
1364 goto bail;
1365 }
Mark Fasheh73c8a802010-04-05 18:17:13 -07001366 if (option >= 0)
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001367 mopt->localalloc_opt = option;
1368 break;
Mark Fasheh53fc6222007-12-20 16:49:04 -08001369 case Opt_localflocks:
1370 /*
1371 * Changing this during remount could race
1372 * flock() requests, or "unbalance" existing
1373 * ones (e.g., a lock is taken in one mode but
1374 * dropped in the other). If users care enough
1375 * to flip locking modes during remount, we
1376 * could add a "local" flag to individual
1377 * flock structures for proper tracking of
1378 * state.
1379 */
1380 if (!is_remount)
1381 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
1382 break;
Joel Beckerb61817e2008-02-01 15:08:23 -08001383 case Opt_stack:
1384 /* Check both that the option we were passed
1385 * is of the right length and that it is a proper
1386 * string of the right length.
1387 */
1388 if (((args[0].to - args[0].from) !=
1389 OCFS2_STACK_LABEL_LEN) ||
1390 (strnlen(args[0].from,
1391 OCFS2_STACK_LABEL_LEN) !=
1392 OCFS2_STACK_LABEL_LEN)) {
1393 mlog(ML_ERROR,
1394 "Invalid cluster_stack option\n");
1395 status = 0;
1396 goto bail;
1397 }
1398 memcpy(mopt->cluster_stack, args[0].from,
1399 OCFS2_STACK_LABEL_LEN);
1400 mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
Mark Fasheh52c303c2011-01-31 11:31:04 -08001401 /*
1402 * Open code the memcmp here as we don't have
1403 * an osb to pass to
1404 * ocfs2_userspace_stack().
1405 */
1406 if (memcmp(mopt->cluster_stack,
1407 OCFS2_CLASSIC_CLUSTER_STACK,
1408 OCFS2_STACK_LABEL_LEN))
1409 user_stack = 1;
Joel Beckerb61817e2008-02-01 15:08:23 -08001410 break;
Joel Becker12462f12008-09-03 20:03:40 -07001411 case Opt_inode64:
1412 mopt->mount_opt |= OCFS2_MOUNT_INODE64;
1413 break;
Jan Kara19ece542008-08-21 20:13:17 +02001414 case Opt_usrquota:
Jan Kara19ece542008-08-21 20:13:17 +02001415 mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
1416 break;
1417 case Opt_grpquota:
Jan Kara19ece542008-08-21 20:13:17 +02001418 mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
1419 break;
Tristan Ye7bdb0d12010-10-11 16:46:39 +08001420 case Opt_coherency_buffered:
1421 mopt->mount_opt |= OCFS2_MOUNT_COHERENCY_BUFFERED;
1422 break;
1423 case Opt_coherency_full:
1424 mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED;
1425 break;
Tiger Yanga68979b2008-11-14 11:17:52 +08001426 case Opt_acl:
1427 mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
Jan Kara5297aad2009-10-15 14:54:04 +02001428 mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001429 break;
1430 case Opt_noacl:
Jan Kara5297aad2009-10-15 14:54:04 +02001431 mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
Tiger Yanga68979b2008-11-14 11:17:52 +08001432 mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
1433 break;
Mark Fashehd02f00c2009-12-07 13:10:48 -08001434 case Opt_resv_level:
1435 if (is_remount)
1436 break;
1437 if (match_int(&args[0], &option)) {
1438 status = 0;
1439 goto bail;
1440 }
1441 if (option >= OCFS2_MIN_RESV_LEVEL &&
1442 option < OCFS2_MAX_RESV_LEVEL)
1443 mopt->resv_level = option;
1444 break;
Mark Fasheh83f92312010-04-05 18:17:16 -07001445 case Opt_dir_resv_level:
1446 if (is_remount)
1447 break;
1448 if (match_int(&args[0], &option)) {
1449 status = 0;
1450 goto bail;
1451 }
1452 if (option >= OCFS2_MIN_RESV_LEVEL &&
1453 option < OCFS2_MAX_RESV_LEVEL)
1454 mopt->dir_resv_level = option;
1455 break;
alex chen1dfeb762015-02-10 14:09:04 -08001456 case Opt_journal_async_commit:
1457 mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
1458 break;
Gang He912f6552020-06-01 21:45:29 -07001459 case Opt_nocluster:
1460 mopt->mount_opt |= OCFS2_MOUNT_NOCLUSTER;
1461 break;
Mark Fashehccd979b2005-12-15 14:31:24 -08001462 default:
1463 mlog(ML_ERROR,
1464 "Unrecognized mount option \"%s\" "
1465 "or missing value\n", p);
1466 status = 0;
1467 goto bail;
1468 }
1469 }
1470
Mark Fasheh52c303c2011-01-31 11:31:04 -08001471 if (user_stack == 0) {
1472 /* Ensure only one heartbeat mode */
1473 tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL |
1474 OCFS2_MOUNT_HB_GLOBAL |
1475 OCFS2_MOUNT_HB_NONE);
1476 if (hweight32(tmp) != 1) {
1477 mlog(ML_ERROR, "Invalid heartbeat mount options\n");
1478 status = 0;
1479 goto bail;
1480 }
Sunil Mushran2c442712010-10-07 15:23:50 -07001481 }
1482
Mark Fashehccd979b2005-12-15 14:31:24 -08001483 status = 1;
1484
1485bail:
Mark Fashehccd979b2005-12-15 14:31:24 -08001486 return status;
1487}
1488
Al Viro34c80b12011-12-08 21:32:45 -05001489static int ocfs2_show_options(struct seq_file *s, struct dentry *root)
Sunil Mushrand5500712007-09-06 13:34:16 -07001490{
Al Viro34c80b12011-12-08 21:32:45 -05001491 struct ocfs2_super *osb = OCFS2_SB(root->d_sb);
Sunil Mushrand5500712007-09-06 13:34:16 -07001492 unsigned long opts = osb->s_mount_opt;
Mark Fashehebcee4b2008-07-28 14:55:20 -07001493 unsigned int local_alloc_megs;
Sunil Mushrand5500712007-09-06 13:34:16 -07001494
Sunil Mushran2c442712010-10-07 15:23:50 -07001495 if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
1496 seq_printf(s, ",_netdev");
1497 if (opts & OCFS2_MOUNT_HB_LOCAL)
1498 seq_printf(s, ",%s", OCFS2_HB_LOCAL);
1499 else
1500 seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
1501 } else
1502 seq_printf(s, ",%s", OCFS2_HB_NONE);
Sunil Mushrand5500712007-09-06 13:34:16 -07001503
1504 if (opts & OCFS2_MOUNT_NOINTR)
1505 seq_printf(s, ",nointr");
1506
1507 if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
1508 seq_printf(s, ",data=writeback");
1509 else
1510 seq_printf(s, ",data=ordered");
1511
1512 if (opts & OCFS2_MOUNT_BARRIER)
1513 seq_printf(s, ",barrier=1");
1514
1515 if (opts & OCFS2_MOUNT_ERRORS_PANIC)
1516 seq_printf(s, ",errors=panic");
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07001517 else if (opts & OCFS2_MOUNT_ERRORS_CONT)
1518 seq_printf(s, ",errors=continue");
Sunil Mushrand5500712007-09-06 13:34:16 -07001519 else
1520 seq_printf(s, ",errors=remount-ro");
1521
1522 if (osb->preferred_slot != OCFS2_INVALID_SLOT)
1523 seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
1524
Al Viro34c80b12011-12-08 21:32:45 -05001525 seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
Sunil Mushrand5500712007-09-06 13:34:16 -07001526
Mark Fashehd147b3d2007-11-07 14:40:36 -08001527 if (osb->osb_commit_interval)
1528 seq_printf(s, ",commit=%u",
1529 (unsigned) (osb->osb_commit_interval / HZ));
1530
Mark Fashehebcee4b2008-07-28 14:55:20 -07001531 local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
Mark Fasheh6b820212010-04-05 18:17:14 -07001532 if (local_alloc_megs != ocfs2_la_default_mb(osb))
Mark Fashehebcee4b2008-07-28 14:55:20 -07001533 seq_printf(s, ",localalloc=%d", local_alloc_megs);
Sunil Mushran2fbe8d12007-12-20 14:58:11 -08001534
Mark Fasheh53fc6222007-12-20 16:49:04 -08001535 if (opts & OCFS2_MOUNT_LOCALFLOCKS)
1536 seq_printf(s, ",localflocks,");
1537
Joel Beckerb61817e2008-02-01 15:08:23 -08001538 if (osb->osb_cluster_stack[0])
Kees Cooka068acf2015-09-04 15:44:57 -07001539 seq_show_option_n(s, "cluster_stack", osb->osb_cluster_stack,
1540 OCFS2_STACK_LABEL_LEN);
Jan Kara19ece542008-08-21 20:13:17 +02001541 if (opts & OCFS2_MOUNT_USRQUOTA)
1542 seq_printf(s, ",usrquota");
1543 if (opts & OCFS2_MOUNT_GRPQUOTA)
1544 seq_printf(s, ",grpquota");
Joel Beckerb61817e2008-02-01 15:08:23 -08001545
Tristan Ye7bdb0d12010-10-11 16:46:39 +08001546 if (opts & OCFS2_MOUNT_COHERENCY_BUFFERED)
1547 seq_printf(s, ",coherency=buffered");
1548 else
1549 seq_printf(s, ",coherency=full");
1550
Sunil Mushranb0f73cf2008-09-05 11:29:14 -07001551 if (opts & OCFS2_MOUNT_NOUSERXATTR)
1552 seq_printf(s, ",nouser_xattr");
1553 else
1554 seq_printf(s, ",user_xattr");
1555
Joel Becker12462f12008-09-03 20:03:40 -07001556 if (opts & OCFS2_MOUNT_INODE64)
1557 seq_printf(s, ",inode64");
1558
Tiger Yanga68979b2008-11-14 11:17:52 +08001559 if (opts & OCFS2_MOUNT_POSIX_ACL)
1560 seq_printf(s, ",acl");
1561 else
1562 seq_printf(s, ",noacl");
Tiger Yanga68979b2008-11-14 11:17:52 +08001563
Mark Fashehd02f00c2009-12-07 13:10:48 -08001564 if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
1565 seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
1566
Mark Fasheh83f92312010-04-05 18:17:16 -07001567 if (osb->osb_dir_resv_level != osb->osb_resv_level)
1568 seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
1569
alex chen1dfeb762015-02-10 14:09:04 -08001570 if (opts & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
1571 seq_printf(s, ",journal_async_commit");
1572
Gang He912f6552020-06-01 21:45:29 -07001573 if (opts & OCFS2_MOUNT_NOCLUSTER)
1574 seq_printf(s, ",nocluster");
1575
Sunil Mushrand5500712007-09-06 13:34:16 -07001576 return 0;
1577}
1578
Mark Fashehccd979b2005-12-15 14:31:24 -08001579static int __init ocfs2_init(void)
1580{
Wengang Wangc18ceab2014-04-03 14:46:46 -07001581 int status;
Mark Fasheha11f7e62011-06-22 14:23:38 -07001582
Mark Fashehccd979b2005-12-15 14:31:24 -08001583 status = init_ocfs2_uptodate_cache();
Al Viro342827d2012-03-17 22:03:58 -04001584 if (status < 0)
1585 goto out1;
Mark Fashehccd979b2005-12-15 14:31:24 -08001586
1587 status = ocfs2_initialize_mem_caches();
Al Viro342827d2012-03-17 22:03:58 -04001588 if (status < 0)
1589 goto out2;
Mark Fashehccd979b2005-12-15 14:31:24 -08001590
Mark Fashehccd979b2005-12-15 14:31:24 -08001591 ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001592
Joel Becker63e0c482008-01-30 16:58:36 -08001593 ocfs2_set_locking_protocol();
1594
Jan Kara9e33d692008-08-25 19:56:50 +02001595 status = register_quota_format(&ocfs2_quota_format);
Al Viro342827d2012-03-17 22:03:58 -04001596 if (status < 0)
jiangyiwen35ddf782016-03-25 14:21:32 -07001597 goto out3;
Al Viro342827d2012-03-17 22:03:58 -04001598 status = register_filesystem(&ocfs2_fs_type);
1599 if (!status)
1600 return 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001601
Al Viro342827d2012-03-17 22:03:58 -04001602 unregister_quota_format(&ocfs2_quota_format);
Al Viro342827d2012-03-17 22:03:58 -04001603out3:
jiangyiwen35ddf782016-03-25 14:21:32 -07001604 debugfs_remove(ocfs2_debugfs_root);
Al Viro342827d2012-03-17 22:03:58 -04001605 ocfs2_free_mem_caches();
1606out2:
1607 exit_ocfs2_uptodate_cache();
1608out1:
1609 mlog_errno(status);
1610 return status;
Mark Fashehccd979b2005-12-15 14:31:24 -08001611}
1612
1613static void __exit ocfs2_exit(void)
1614{
Jan Kara9e33d692008-08-25 19:56:50 +02001615 unregister_quota_format(&ocfs2_quota_format);
1616
Mark Fashehccd979b2005-12-15 14:31:24 -08001617 debugfs_remove(ocfs2_debugfs_root);
1618
1619 ocfs2_free_mem_caches();
1620
1621 unregister_filesystem(&ocfs2_fs_type);
1622
Mark Fashehccd979b2005-12-15 14:31:24 -08001623 exit_ocfs2_uptodate_cache();
Mark Fashehccd979b2005-12-15 14:31:24 -08001624}
1625
1626static void ocfs2_put_super(struct super_block *sb)
1627{
Tao Ma32a42d32011-02-23 21:29:08 +08001628 trace_ocfs2_put_super(sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001629
1630 ocfs2_sync_blockdev(sb);
1631 ocfs2_dismount_volume(sb, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001632}
1633
David Howells726c3342006-06-23 02:02:58 -07001634static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
Mark Fashehccd979b2005-12-15 14:31:24 -08001635{
1636 struct ocfs2_super *osb;
1637 u32 numbits, freebits;
1638 int status;
1639 struct ocfs2_dinode *bm_lock;
1640 struct buffer_head *bh = NULL;
1641 struct inode *inode = NULL;
1642
Tao Ma32a42d32011-02-23 21:29:08 +08001643 trace_ocfs2_statfs(dentry->d_sb, buf);
Mark Fashehccd979b2005-12-15 14:31:24 -08001644
David Howells726c3342006-06-23 02:02:58 -07001645 osb = OCFS2_SB(dentry->d_sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001646
1647 inode = ocfs2_get_system_file_inode(osb,
1648 GLOBAL_BITMAP_SYSTEM_INODE,
1649 OCFS2_INVALID_SLOT);
1650 if (!inode) {
1651 mlog(ML_ERROR, "failed to get bitmap inode\n");
1652 status = -EIO;
1653 goto bail;
1654 }
1655
Mark Fashehe63aecb62007-10-18 15:30:42 -07001656 status = ocfs2_inode_lock(inode, &bh, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001657 if (status < 0) {
1658 mlog_errno(status);
1659 goto bail;
1660 }
1661
1662 bm_lock = (struct ocfs2_dinode *) bh->b_data;
1663
1664 numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
1665 freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
1666
1667 buf->f_type = OCFS2_SUPER_MAGIC;
David Howells726c3342006-06-23 02:02:58 -07001668 buf->f_bsize = dentry->d_sb->s_blocksize;
Mark Fashehccd979b2005-12-15 14:31:24 -08001669 buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
1670 buf->f_blocks = ((sector_t) numbits) *
1671 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1672 buf->f_bfree = ((sector_t) freebits) *
1673 (osb->s_clustersize >> osb->sb->s_blocksize_bits);
1674 buf->f_bavail = buf->f_bfree;
1675 buf->f_files = numbits;
1676 buf->f_ffree = freebits;
Coly Li837711f2009-01-16 16:33:05 +08001677 buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
1678 & 0xFFFFFFFFUL;
1679 buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
1680 OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001681
1682 brelse(bh);
1683
Mark Fashehe63aecb62007-10-18 15:30:42 -07001684 ocfs2_inode_unlock(inode, 0);
Mark Fashehccd979b2005-12-15 14:31:24 -08001685 status = 0;
1686bail:
Joseph Qi72865d92016-01-14 15:17:27 -08001687 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001688
Tao Mac1e8d352011-03-07 16:43:21 +08001689 if (status)
1690 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -08001691
1692 return status;
1693}
1694
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001695static void ocfs2_inode_init_once(void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -08001696{
1697 struct ocfs2_inode_info *oi = data;
1698
Christoph Lametera35afb82007-05-16 22:10:57 -07001699 oi->ip_flags = 0;
1700 oi->ip_open_count = 0;
1701 spin_lock_init(&oi->ip_lock);
1702 ocfs2_extent_map_init(&oi->vfs_inode);
1703 INIT_LIST_HEAD(&oi->ip_io_markers);
Ryan Ding4506cfb2016-03-25 14:21:06 -07001704 INIT_LIST_HEAD(&oi->ip_unwritten_list);
Christoph Lametera35afb82007-05-16 22:10:57 -07001705 oi->ip_dir_start_lookup = 0;
Christoph Lametera35afb82007-05-16 22:10:57 -07001706 init_rwsem(&oi->ip_alloc_sem);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001707 init_rwsem(&oi->ip_xattr_sem);
Christoph Lametera35afb82007-05-16 22:10:57 -07001708 mutex_init(&oi->ip_io_mutex);
Mark Fashehccd979b2005-12-15 14:31:24 -08001709
Christoph Lametera35afb82007-05-16 22:10:57 -07001710 oi->ip_blkno = 0ULL;
1711 oi->ip_clusters = 0;
Wengang Wangf5785282020-11-13 22:52:23 -08001712 oi->ip_next_orphan = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001713
Mark Fasheh4fe370a2009-12-07 13:15:40 -08001714 ocfs2_resv_init_once(&oi->ip_la_data_resv);
1715
Christoph Lametera35afb82007-05-16 22:10:57 -07001716 ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
Mark Fashehe63aecb62007-10-18 15:30:42 -07001717 ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
Christoph Lametera35afb82007-05-16 22:10:57 -07001718 ocfs2_lock_res_init_once(&oi->ip_open_lockres);
Mark Fashehccd979b2005-12-15 14:31:24 -08001719
Joel Becker8cb471e2009-02-10 20:00:41 -08001720 ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
Joel Becker6e5a3d72009-02-10 19:00:37 -08001721 &ocfs2_inode_caching_ops);
Mark Fashehccd979b2005-12-15 14:31:24 -08001722
Christoph Lametera35afb82007-05-16 22:10:57 -07001723 inode_init_once(&oi->vfs_inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001724}
1725
1726static int ocfs2_initialize_mem_caches(void)
1727{
1728 ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001729 sizeof(struct ocfs2_inode_info),
1730 0,
1731 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
Vladimir Davydov5d097052016-01-14 15:18:21 -08001732 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
Paul Mundt20c2df82007-07-20 10:11:58 +09001733 ocfs2_inode_init_once);
Jan Kara9e33d692008-08-25 19:56:50 +02001734 ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
1735 sizeof(struct ocfs2_dquot),
1736 0,
1737 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1738 SLAB_MEM_SPREAD),
1739 NULL);
1740 ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
1741 sizeof(struct ocfs2_quota_chunk),
1742 0,
1743 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
1744 NULL);
1745 if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
1746 !ocfs2_qf_chunk_cachep) {
piaojuna17b4852018-04-05 16:18:52 -07001747 kmem_cache_destroy(ocfs2_inode_cachep);
1748 kmem_cache_destroy(ocfs2_dquot_cachep);
1749 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001750 return -ENOMEM;
Jan Kara9e33d692008-08-25 19:56:50 +02001751 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001752
Mark Fashehccd979b2005-12-15 14:31:24 -08001753 return 0;
1754}
1755
1756static void ocfs2_free_mem_caches(void)
1757{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +10001758 /*
1759 * Make sure all delayed rcu free inodes are flushed before we
1760 * destroy cache.
1761 */
1762 rcu_barrier();
piaojuna17b4852018-04-05 16:18:52 -07001763 kmem_cache_destroy(ocfs2_inode_cachep);
Mark Fashehccd979b2005-12-15 14:31:24 -08001764 ocfs2_inode_cachep = NULL;
Jan Kara9e33d692008-08-25 19:56:50 +02001765
piaojuna17b4852018-04-05 16:18:52 -07001766 kmem_cache_destroy(ocfs2_dquot_cachep);
Jan Kara9e33d692008-08-25 19:56:50 +02001767 ocfs2_dquot_cachep = NULL;
1768
piaojuna17b4852018-04-05 16:18:52 -07001769 kmem_cache_destroy(ocfs2_qf_chunk_cachep);
Jan Kara9e33d692008-08-25 19:56:50 +02001770 ocfs2_qf_chunk_cachep = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08001771}
1772
1773static int ocfs2_get_sector(struct super_block *sb,
1774 struct buffer_head **bh,
1775 int block,
1776 int sect_size)
1777{
1778 if (!sb_set_blocksize(sb, sect_size)) {
1779 mlog(ML_ERROR, "unable to set blocksize\n");
1780 return -EIO;
1781 }
1782
1783 *bh = sb_getblk(sb, block);
1784 if (!*bh) {
Rui Xiang7391a292013-11-12 15:06:54 -08001785 mlog_errno(-ENOMEM);
1786 return -ENOMEM;
Mark Fashehccd979b2005-12-15 14:31:24 -08001787 }
1788 lock_buffer(*bh);
1789 if (!buffer_dirty(*bh))
1790 clear_buffer_uptodate(*bh);
1791 unlock_buffer(*bh);
Mike Christiedfec8a12016-06-05 14:31:44 -05001792 ll_rw_block(REQ_OP_READ, 0, 1, bh);
Mark Fashehccd979b2005-12-15 14:31:24 -08001793 wait_on_buffer(*bh);
wengang wang28d57d42009-02-13 10:11:47 +08001794 if (!buffer_uptodate(*bh)) {
1795 mlog_errno(-EIO);
1796 brelse(*bh);
1797 *bh = NULL;
1798 return -EIO;
1799 }
1800
Mark Fashehccd979b2005-12-15 14:31:24 -08001801 return 0;
1802}
1803
Mark Fashehccd979b2005-12-15 14:31:24 -08001804static int ocfs2_mount_volume(struct super_block *sb)
1805{
1806 int status = 0;
1807 int unlock_super = 0;
1808 struct ocfs2_super *osb = OCFS2_SB(sb);
1809
Mark Fashehccd979b2005-12-15 14:31:24 -08001810 if (ocfs2_is_hard_readonly(osb))
1811 goto leave;
1812
Gang He5500ab42019-03-05 15:41:45 -08001813 mutex_init(&osb->obs_trim_fs_mutex);
1814
Mark Fashehccd979b2005-12-15 14:31:24 -08001815 status = ocfs2_dlm_init(osb);
1816 if (status < 0) {
1817 mlog_errno(status);
Gang Hea52370b2018-01-31 16:14:29 -08001818 if (status == -EBADR && ocfs2_userspace_stack(osb))
1819 mlog(ML_ERROR, "couldn't mount because cluster name on"
1820 " disk does not match the running cluster name.\n");
Mark Fashehccd979b2005-12-15 14:31:24 -08001821 goto leave;
1822 }
1823
Mark Fashehccd979b2005-12-15 14:31:24 -08001824 status = ocfs2_super_lock(osb, 1);
1825 if (status < 0) {
1826 mlog_errno(status);
1827 goto leave;
1828 }
1829 unlock_super = 1;
1830
1831 /* This will load up the node map and add ourselves to it. */
1832 status = ocfs2_find_slot(osb);
1833 if (status < 0) {
1834 mlog_errno(status);
1835 goto leave;
1836 }
1837
Mark Fashehccd979b2005-12-15 14:31:24 -08001838 /* load all node-local system inodes */
1839 status = ocfs2_init_local_system_inodes(osb);
1840 if (status < 0) {
1841 mlog_errno(status);
1842 goto leave;
1843 }
1844
1845 status = ocfs2_check_volume(osb);
1846 if (status < 0) {
1847 mlog_errno(status);
1848 goto leave;
1849 }
1850
1851 status = ocfs2_truncate_log_init(osb);
Tao Ma06c59bb2009-05-19 06:47:20 +08001852 if (status < 0)
Mark Fashehccd979b2005-12-15 14:31:24 -08001853 mlog_errno(status);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001854
Mark Fashehccd979b2005-12-15 14:31:24 -08001855leave:
1856 if (unlock_super)
1857 ocfs2_super_unlock(osb, 1);
1858
Mark Fashehccd979b2005-12-15 14:31:24 -08001859 return status;
1860}
1861
Mark Fashehccd979b2005-12-15 14:31:24 -08001862static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1863{
Joel Becker286eaa92008-02-01 15:03:57 -08001864 int tmp, hangup_needed = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08001865 struct ocfs2_super *osb = NULL;
Goldwyn Rodrigues99d7a882013-09-24 15:27:32 -07001866 char nodestr[12];
Mark Fashehccd979b2005-12-15 14:31:24 -08001867
Tao Ma32a42d32011-02-23 21:29:08 +08001868 trace_ocfs2_dismount_volume(sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001869
1870 BUG_ON(!sb);
1871 osb = OCFS2_SB(sb);
1872 BUG_ON(!osb);
1873
Gang He5f483c42018-04-05 16:19:29 -07001874 /* Remove file check sysfs related directores/files,
1875 * and wait for the pending file check operations */
1876 ocfs2_filecheck_remove_sysfs(osb);
1877
1878 kset_unregister(osb->osb_dev_kset);
1879
Sunil Mushran692684e2009-06-19 16:53:17 -07001880 /* Orphan scan should be stopped as early as possible */
1881 ocfs2_orphan_scan_stop(osb);
1882
Jan Kara19ece542008-08-21 20:13:17 +02001883 ocfs2_disable_quotas(osb);
1884
Jan Karae3a767b2014-04-03 14:46:56 -07001885 /* All dquots should be freed by now */
1886 WARN_ON(!llist_empty(&osb->dquot_drop_list));
1887 /* Wait for worker to be done with the work structure in osb */
1888 cancel_work_sync(&osb->dquot_drop_work);
1889
Mark Fashehccd979b2005-12-15 14:31:24 -08001890 ocfs2_shutdown_local_alloc(osb);
1891
Xue jiufeib253bfd2014-06-23 13:22:08 -07001892 ocfs2_truncate_log_shutdown(osb);
1893
Joel Becker553abd02008-02-01 12:03:57 -08001894 /* This will disable recovery and flush any recovery work. */
1895 ocfs2_recovery_exit(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08001896
1897 ocfs2_journal_shutdown(osb);
1898
1899 ocfs2_sync_blockdev(sb);
1900
Tao Ma374a2632009-08-24 11:13:37 +08001901 ocfs2_purge_refcount_trees(osb);
1902
Joel Becker4670c462008-02-01 14:39:35 -08001903 /* No cluster connection means we've failed during mount, so skip
1904 * all the steps which depended on that to complete. */
1905 if (osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -08001906 tmp = ocfs2_super_lock(osb, 1);
1907 if (tmp < 0) {
1908 mlog_errno(tmp);
1909 return;
1910 }
Mark Fashehccd979b2005-12-15 14:31:24 -08001911 }
1912
Mark Fasheh19b613d2007-10-04 14:47:09 -07001913 if (osb->slot_num != OCFS2_INVALID_SLOT)
1914 ocfs2_put_slot(osb);
1915
Joel Becker4670c462008-02-01 14:39:35 -08001916 if (osb->cconn)
Mark Fasheh19b613d2007-10-04 14:47:09 -07001917 ocfs2_super_unlock(osb, 1);
1918
Mark Fashehccd979b2005-12-15 14:31:24 -08001919 ocfs2_release_system_inodes(osb);
1920
Joel Becker6953b4c2008-01-29 16:59:56 -08001921 /*
Joel Becker6953b4c2008-01-29 16:59:56 -08001922 * If we're dismounting due to mount error, mount.ocfs2 will clean
1923 * up heartbeat. If we're a local mount, there is no heartbeat.
1924 * If we failed before we got a uuid_str yet, we can't stop
1925 * heartbeat. Otherwise, do it.
1926 */
Tiger Yang03efed82011-05-28 00:34:19 +08001927 if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str &&
1928 !ocfs2_is_hard_readonly(osb))
Joel Becker286eaa92008-02-01 15:03:57 -08001929 hangup_needed = 1;
1930
1931 if (osb->cconn)
1932 ocfs2_dlm_shutdown(osb, hangup_needed);
1933
Joel Becker73be1922009-01-06 14:57:08 -08001934 ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
Greg Kroah-Hartman5e7a3ed2019-09-23 15:33:15 -07001935 debugfs_remove_recursive(osb->osb_debug_root);
Joel Becker286eaa92008-02-01 15:03:57 -08001936
1937 if (hangup_needed)
Joel Becker6953b4c2008-01-29 16:59:56 -08001938 ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
Mark Fashehccd979b2005-12-15 14:31:24 -08001939
1940 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1941
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001942 if (ocfs2_mount_local(osb))
1943 snprintf(nodestr, sizeof(nodestr), "local");
1944 else
Joel Becker19fdb622008-01-30 15:38:24 -08001945 snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
Sunil Mushranc271c5c2006-12-05 17:56:35 -08001946
1947 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1948 osb->dev_str, nodestr);
Mark Fashehccd979b2005-12-15 14:31:24 -08001949
1950 ocfs2_delete_osb(osb);
1951 kfree(osb);
1952 sb->s_dev = 0;
1953 sb->s_fs_info = NULL;
1954}
1955
1956static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
1957 unsigned uuid_bytes)
1958{
1959 int i, ret;
1960 char *ptr;
1961
1962 BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
1963
Robert P. J. Daycd861282006-12-13 00:34:52 -08001964 osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08001965 if (osb->uuid_str == NULL)
1966 return -ENOMEM;
1967
Mark Fashehccd979b2005-12-15 14:31:24 -08001968 for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
1969 /* print with null */
1970 ret = snprintf(ptr, 3, "%02X", uuid[i]);
1971 if (ret != 2) /* drop super cleans up */
1972 return -EINVAL;
1973 /* then only advance past the last char */
1974 ptr += 2;
1975 }
1976
1977 return 0;
1978}
1979
Patrick J. LoPresti3bdb8ef2010-07-22 15:05:57 -07001980/* Make sure entire volume is addressable by our journal. Requires
1981 osb_clusters_at_boot to be valid and for the journal to have been
1982 initialized by ocfs2_journal_init(). */
1983static int ocfs2_journal_addressable(struct ocfs2_super *osb)
1984{
1985 int status = 0;
1986 u64 max_block =
1987 ocfs2_clusters_to_blocks(osb->sb,
1988 osb->osb_clusters_at_boot) - 1;
1989
1990 /* 32-bit block number is always OK. */
1991 if (max_block <= (u32)~0ULL)
1992 goto out;
1993
1994 /* Volume is "huge", so see if our journal is new enough to
1995 support it. */
1996 if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb,
1997 OCFS2_FEATURE_COMPAT_JBD2_SB) &&
1998 jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0,
1999 JBD2_FEATURE_INCOMPAT_64BIT))) {
2000 mlog(ML_ERROR, "The journal cannot address the entire volume. "
2001 "Enable the 'block64' journal option with tunefs.ocfs2");
2002 status = -EFBIG;
2003 goto out;
2004 }
2005
2006 out:
2007 return status;
2008}
2009
Mark Fashehccd979b2005-12-15 14:31:24 -08002010static int ocfs2_initialize_super(struct super_block *sb,
2011 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002012 int sector_size,
2013 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002014{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002015 int status;
Mark Fasheh5a254032007-07-20 12:56:16 -07002016 int i, cbits, bbits;
2017 struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
Mark Fashehccd979b2005-12-15 14:31:24 -08002018 struct inode *inode = NULL;
Mark Fashehccd979b2005-12-15 14:31:24 -08002019 struct ocfs2_journal *journal;
Mark Fashehccd979b2005-12-15 14:31:24 -08002020 struct ocfs2_super *osb;
Patrick J. LoPresti3bdb8ef2010-07-22 15:05:57 -07002021 u64 total_blocks;
Mark Fashehccd979b2005-12-15 14:31:24 -08002022
Robert P. J. Daycd861282006-12-13 00:34:52 -08002023 osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002024 if (!osb) {
2025 status = -ENOMEM;
2026 mlog_errno(status);
2027 goto bail;
2028 }
2029
2030 sb->s_fs_info = osb;
2031 sb->s_op = &ocfs2_sops;
Al Viroba871672010-12-18 12:10:00 -05002032 sb->s_d_op = &ocfs2_dentry_ops;
Mark Fashehccd979b2005-12-15 14:31:24 -08002033 sb->s_export_op = &ocfs2_export_ops;
Jan Kara664dbd52014-10-08 18:30:19 +02002034 sb->s_qcop = &dquot_quotactl_sysfile_ops;
Jan Kara19ece542008-08-21 20:13:17 +02002035 sb->dq_op = &ocfs2_quota_operations;
Jan Kara1c92ec62014-09-29 15:02:51 +02002036 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002037 sb->s_xattr = ocfs2_xattr_handlers;
Mark Fashehe0dceaf2007-08-09 16:52:30 -07002038 sb->s_time_gran = 1;
Linus Torvalds1751e8a2017-11-27 13:05:09 -08002039 sb->s_flags |= SB_NOATIME;
Mark Fashehccd979b2005-12-15 14:31:24 -08002040 /* this is needed to support O_LARGEFILE */
Mark Fasheh5a254032007-07-20 12:56:16 -07002041 cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2042 bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
2043 sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
Christoph Hellwig85787092017-05-10 15:06:33 +02002044 memcpy(&sb->s_uuid, di->id2.i_super.s_uuid,
Vladimir Davydov58be19d2015-04-14 15:46:39 -07002045 sizeof(di->id2.i_super.s_uuid));
Mark Fashehccd979b2005-12-15 14:31:24 -08002046
Mark Fasheh9b7895e2008-11-12 16:27:44 -08002047 osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
2048
2049 for (i = 0; i < 3; i++)
2050 osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
2051 osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
2052
Mark Fashehccd979b2005-12-15 14:31:24 -08002053 osb->sb = sb;
Mark Fashehccd979b2005-12-15 14:31:24 -08002054 osb->s_sectsize_bits = blksize_bits(sector_size);
Eric Sesterhenn / snakebyteebdec832006-01-27 10:32:52 +01002055 BUG_ON(!osb->s_sectsize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08002056
Mark Fasheh34d024f2007-09-24 15:56:19 -07002057 spin_lock_init(&osb->dc_task_lock);
2058 init_waitqueue_head(&osb->dc_event);
2059 osb->dc_work_sequence = 0;
2060 osb->dc_wake_sequence = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002061 INIT_LIST_HEAD(&osb->blocked_lock_list);
2062 osb->blocked_lock_count = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002063 spin_lock_init(&osb->osb_lock);
Tao Mac8b9cf92009-02-24 17:40:26 -08002064 spin_lock_init(&osb->osb_xattr_lock);
Tiger Yangb89c5422010-01-25 14:11:06 +08002065 ocfs2_init_steal_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002066
jiangyiwen43b10a22014-04-03 14:47:13 -07002067 mutex_init(&osb->system_file_mutex);
2068
Mark Fashehccd979b2005-12-15 14:31:24 -08002069 atomic_set(&osb->alloc_stats.moves, 0);
2070 atomic_set(&osb->alloc_stats.local_data, 0);
2071 atomic_set(&osb->alloc_stats.bitmap_data, 0);
2072 atomic_set(&osb->alloc_stats.bg_allocs, 0);
2073 atomic_set(&osb->alloc_stats.bg_extends, 0);
2074
Joel Becker73be1922009-01-06 14:57:08 -08002075 /* Copy the blockcheck stats from the superblock probe */
2076 osb->osb_ecc_stats = *stats;
2077
Mark Fashehccd979b2005-12-15 14:31:24 -08002078 ocfs2_init_node_maps(osb);
2079
2080 snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
2081 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
2082
Goldwyn Rodrigues75d9bbc2010-10-11 12:57:09 -05002083 osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
2084 if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
2085 mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
2086 osb->max_slots);
2087 status = -EINVAL;
2088 goto bail;
2089 }
Goldwyn Rodrigues75d9bbc2010-10-11 12:57:09 -05002090
Jeff Mahoney8b712cd2009-07-07 17:22:12 -04002091 ocfs2_orphan_scan_init(osb);
2092
Joel Becker553abd02008-02-01 12:03:57 -08002093 status = ocfs2_recovery_init(osb);
2094 if (status) {
2095 mlog(ML_ERROR, "Unable to initialize recovery state\n");
2096 mlog_errno(status);
2097 goto bail;
2098 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002099
2100 init_waitqueue_head(&osb->checkpoint_event);
Mark Fashehccd979b2005-12-15 14:31:24 -08002101
Tiger Yang7f1a37e2006-11-15 15:48:42 +08002102 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
2103
Mark Fashehccd979b2005-12-15 14:31:24 -08002104 osb->slot_num = OCFS2_INVALID_SLOT;
2105
Tiger Yang8154da32008-08-18 17:11:46 +08002106 osb->s_xattr_inline_size = le16_to_cpu(
2107 di->id2.i_super.s_xattr_inline_size);
Tiger Yangfdd77702008-08-18 17:08:55 +08002108
Mark Fashehccd979b2005-12-15 14:31:24 -08002109 osb->local_alloc_state = OCFS2_LA_UNUSED;
2110 osb->local_alloc_bh = NULL;
Mark Fasheh9c7af402008-07-28 18:02:53 -07002111 INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
Mark Fashehccd979b2005-12-15 14:31:24 -08002112
Mark Fashehccd979b2005-12-15 14:31:24 -08002113 init_waitqueue_head(&osb->osb_mount_event);
2114
Mark Fashehd02f00c2009-12-07 13:10:48 -08002115 status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
2116 if (status) {
2117 mlog_errno(status);
2118 goto bail;
2119 }
2120
Mark Fashehccd979b2005-12-15 14:31:24 -08002121 osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
2122 if (!osb->vol_label) {
2123 mlog(ML_ERROR, "unable to alloc vol label\n");
2124 status = -ENOMEM;
2125 goto bail;
2126 }
2127
Sunil Mushran539d8262008-07-14 17:31:10 -07002128 osb->slot_recovery_generations =
2129 kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
2130 GFP_KERNEL);
2131 if (!osb->slot_recovery_generations) {
2132 status = -ENOMEM;
2133 mlog_errno(status);
2134 goto bail;
2135 }
2136
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002137 init_waitqueue_head(&osb->osb_wipe_event);
2138 osb->osb_orphan_wipes = kcalloc(osb->max_slots,
2139 sizeof(*osb->osb_orphan_wipes),
2140 GFP_KERNEL);
2141 if (!osb->osb_orphan_wipes) {
2142 status = -ENOMEM;
2143 mlog_errno(status);
2144 goto bail;
2145 }
2146
Tao Ma374a2632009-08-24 11:13:37 +08002147 osb->osb_rf_lock_tree = RB_ROOT;
2148
Mark Fashehccd979b2005-12-15 14:31:24 -08002149 osb->s_feature_compat =
2150 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
2151 osb->s_feature_ro_compat =
2152 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
2153 osb->s_feature_incompat =
2154 le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
2155
2156 if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
2157 mlog(ML_ERROR, "couldn't mount because of unsupported "
2158 "optional features (%x).\n", i);
2159 status = -EINVAL;
2160 goto bail;
2161 }
David Howellsbc98a422017-07-17 08:45:34 +01002162 if (!sb_rdonly(osb->sb) && (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
Mark Fashehccd979b2005-12-15 14:31:24 -08002163 mlog(ML_ERROR, "couldn't mount RDWR because of "
2164 "unsupported optional features (%x).\n", i);
2165 status = -EINVAL;
2166 goto bail;
2167 }
2168
Sunil Mushran98f486f22010-10-09 10:24:46 -07002169 if (ocfs2_clusterinfo_valid(osb)) {
2170 osb->osb_stackflags =
2171 OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
Goldwyn Rodriguesc74a3bd2014-01-21 15:48:21 -08002172 strlcpy(osb->osb_cluster_stack,
Joel Beckerb61817e2008-02-01 15:08:23 -08002173 OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
Goldwyn Rodriguesc74a3bd2014-01-21 15:48:21 -08002174 OCFS2_STACK_LABEL_LEN + 1);
Joel Beckerb61817e2008-02-01 15:08:23 -08002175 if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
2176 mlog(ML_ERROR,
2177 "couldn't mount because of an invalid "
2178 "cluster stack label (%s) \n",
2179 osb->osb_cluster_stack);
2180 status = -EINVAL;
2181 goto bail;
2182 }
Goldwyn Rodriguesc74a3bd2014-01-21 15:48:21 -08002183 strlcpy(osb->osb_cluster_name,
2184 OCFS2_RAW_SB(di)->s_cluster_info.ci_cluster,
2185 OCFS2_CLUSTER_NAME_LEN + 1);
Joel Beckerb61817e2008-02-01 15:08:23 -08002186 } else {
2187 /* The empty string is identical with classic tools that
2188 * don't know about s_cluster_info. */
2189 osb->osb_cluster_stack[0] = '\0';
2190 }
2191
Mark Fashehccd979b2005-12-15 14:31:24 -08002192 get_random_bytes(&osb->s_next_generation, sizeof(u32));
2193
2194 /* FIXME
2195 * This should be done in ocfs2_journal_init(), but unknown
2196 * ordering issues will cause the filesystem to crash.
2197 * If anyone wants to figure out what part of the code
2198 * refers to osb->journal before ocfs2_journal_init() is run,
2199 * be my guest.
2200 */
2201 /* initialize our journal structure */
2202
Robert P. J. Daycd861282006-12-13 00:34:52 -08002203 journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
Mark Fashehccd979b2005-12-15 14:31:24 -08002204 if (!journal) {
2205 mlog(ML_ERROR, "unable to alloc journal\n");
2206 status = -ENOMEM;
2207 goto bail;
2208 }
2209 osb->journal = journal;
2210 journal->j_osb = osb;
2211
2212 atomic_set(&journal->j_num_trans, 0);
2213 init_rwsem(&journal->j_trans_barrier);
2214 init_waitqueue_head(&journal->j_checkpointed);
2215 spin_lock_init(&journal->j_lock);
2216 journal->j_trans_id = (unsigned long) 1;
2217 INIT_LIST_HEAD(&journal->j_la_cleanups);
David Howellsc4028952006-11-22 14:57:56 +00002218 INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
Mark Fashehccd979b2005-12-15 14:31:24 -08002219 journal->j_state = OCFS2_JOURNAL_FREE;
2220
Jan Karae3a767b2014-04-03 14:46:56 -07002221 INIT_WORK(&osb->dquot_drop_work, ocfs2_drop_dquot_refs);
2222 init_llist_head(&osb->dquot_drop_list);
2223
Mark Fashehccd979b2005-12-15 14:31:24 -08002224 /* get some pseudo constants for clustersize bits */
2225 osb->s_clustersize_bits =
2226 le32_to_cpu(di->id2.i_super.s_clustersize_bits);
2227 osb->s_clustersize = 1 << osb->s_clustersize_bits;
Mark Fashehccd979b2005-12-15 14:31:24 -08002228
2229 if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
2230 osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
2231 mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
2232 osb->s_clustersize);
2233 status = -EINVAL;
2234 goto bail;
2235 }
2236
Patrick J. LoPresti3bdb8ef2010-07-22 15:05:57 -07002237 total_blocks = ocfs2_clusters_to_blocks(osb->sb,
2238 le32_to_cpu(di->i_clusters));
2239
2240 status = generic_check_addressable(osb->sb->s_blocksize_bits,
2241 total_blocks);
2242 if (status) {
2243 mlog(ML_ERROR, "Volume too large "
2244 "to mount safely on this system");
2245 status = -EFBIG;
Mark Fashehccd979b2005-12-15 14:31:24 -08002246 goto bail;
2247 }
2248
2249 if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
2250 sizeof(di->id2.i_super.s_uuid))) {
2251 mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
2252 status = -ENOMEM;
2253 goto bail;
2254 }
2255
Fabian Frederick69201bb2014-06-04 16:06:07 -07002256 strlcpy(osb->vol_label, di->id2.i_super.s_label,
2257 OCFS2_MAX_VOL_LABEL_LEN);
Mark Fashehccd979b2005-12-15 14:31:24 -08002258 osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
2259 osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
2260 osb->first_cluster_group_blkno =
2261 le64_to_cpu(di->id2.i_super.s_first_cluster_group);
2262 osb->fs_generation = le32_to_cpu(di->i_fs_generation);
Tiger Yangcf1d6c72008-08-18 17:11:00 +08002263 osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
Tao Ma32a42d32011-02-23 21:29:08 +08002264 trace_ocfs2_initialize_super(osb->vol_label, osb->uuid_str,
2265 (unsigned long long)osb->root_blkno,
2266 (unsigned long long)osb->system_dir_blkno,
2267 osb->s_clustersize_bits);
Mark Fashehccd979b2005-12-15 14:31:24 -08002268
2269 osb->osb_dlm_debug = ocfs2_new_dlm_debug();
2270 if (!osb->osb_dlm_debug) {
2271 status = -ENOMEM;
2272 mlog_errno(status);
2273 goto bail;
2274 }
2275
2276 atomic_set(&osb->vol_state, VOLUME_INIT);
2277
2278 /* load root, system_dir, and all global system inodes */
2279 status = ocfs2_init_global_system_inodes(osb);
2280 if (status < 0) {
2281 mlog_errno(status);
2282 goto bail;
2283 }
2284
2285 /*
2286 * global bitmap
2287 */
2288 inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
2289 OCFS2_INVALID_SLOT);
2290 if (!inode) {
2291 status = -EINVAL;
2292 mlog_errno(status);
2293 goto bail;
2294 }
2295
2296 osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
Mark Fasheh6b820212010-04-05 18:17:14 -07002297 osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
Mark Fashehccd979b2005-12-15 14:31:24 -08002298 iput(inode);
Mark Fashehccd979b2005-12-15 14:31:24 -08002299
Tao Ma85718822010-04-13 14:38:06 +08002300 osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
2301 osb->s_feature_incompat) * 8;
Mark Fashehccd979b2005-12-15 14:31:24 -08002302
2303 status = ocfs2_init_slot_info(osb);
2304 if (status < 0) {
2305 mlog_errno(status);
2306 goto bail;
2307 }
Vladimir Davydov9de16262015-04-14 15:46:42 -07002308 cleancache_init_shared_fs(sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002309
Bhaktipriya Shridhar44be9752016-10-07 16:57:13 -07002310 osb->ocfs2_wq = alloc_ordered_workqueue("ocfs2_wq", WQ_MEM_RECLAIM);
jiangyiwen35ddf782016-03-25 14:21:32 -07002311 if (!osb->ocfs2_wq) {
2312 status = -ENOMEM;
2313 mlog_errno(status);
2314 }
2315
Mark Fashehccd979b2005-12-15 14:31:24 -08002316bail:
Mark Fashehccd979b2005-12-15 14:31:24 -08002317 return status;
2318}
2319
2320/*
2321 * will return: -EAGAIN if it is ok to keep searching for superblocks
2322 * -EINVAL if there is a bad superblock
2323 * 0 on success
2324 */
2325static int ocfs2_verify_volume(struct ocfs2_dinode *di,
2326 struct buffer_head *bh,
Joel Becker73be1922009-01-06 14:57:08 -08002327 u32 blksz,
2328 struct ocfs2_blockcheck_stats *stats)
Mark Fashehccd979b2005-12-15 14:31:24 -08002329{
2330 int status = -EAGAIN;
2331
Mark Fashehccd979b2005-12-15 14:31:24 -08002332 if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
2333 strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
Joel Beckerd030cc92008-12-11 15:04:14 -08002334 /* We have to do a raw check of the feature here */
2335 if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
2336 OCFS2_FEATURE_INCOMPAT_META_ECC) {
2337 status = ocfs2_block_check_validate(bh->b_data,
2338 bh->b_size,
Joel Becker73be1922009-01-06 14:57:08 -08002339 &di->i_check,
2340 stats);
Joel Beckerd030cc92008-12-11 15:04:14 -08002341 if (status)
2342 goto out;
2343 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002344 status = -EINVAL;
2345 if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
2346 mlog(ML_ERROR, "found superblock with incorrect block "
2347 "size: found %u, should be %u\n",
2348 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
2349 blksz);
2350 } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
2351 OCFS2_MAJOR_REV_LEVEL ||
2352 le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
2353 OCFS2_MINOR_REV_LEVEL) {
2354 mlog(ML_ERROR, "found superblock with bad version: "
2355 "found %u.%u, should be %u.%u\n",
2356 le16_to_cpu(di->id2.i_super.s_major_rev_level),
2357 le16_to_cpu(di->id2.i_super.s_minor_rev_level),
2358 OCFS2_MAJOR_REV_LEVEL,
2359 OCFS2_MINOR_REV_LEVEL);
2360 } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
2361 mlog(ML_ERROR, "bad block number on superblock: "
Mark Fashehb06970532006-03-03 10:24:33 -08002362 "found %llu, should be %llu\n",
Mark Fasheh1ca1a112007-04-27 16:01:25 -07002363 (unsigned long long)le64_to_cpu(di->i_blkno),
Mark Fashehb06970532006-03-03 10:24:33 -08002364 (unsigned long long)bh->b_blocknr);
Mark Fashehccd979b2005-12-15 14:31:24 -08002365 } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
2366 le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
2367 mlog(ML_ERROR, "bad cluster size found: %u\n",
2368 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
2369 } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
2370 mlog(ML_ERROR, "bad root_blkno: 0\n");
2371 } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
2372 mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
2373 } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
2374 mlog(ML_ERROR,
2375 "Superblock slots found greater than file system "
2376 "maximum: found %u, max %u\n",
2377 le16_to_cpu(di->id2.i_super.s_max_slots),
2378 OCFS2_MAX_SLOTS);
2379 } else {
2380 /* found it! */
2381 status = 0;
2382 }
2383 }
2384
Joel Beckerd030cc92008-12-11 15:04:14 -08002385out:
Tao Mac1e8d352011-03-07 16:43:21 +08002386 if (status && status != -EAGAIN)
2387 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -08002388 return status;
2389}
2390
2391static int ocfs2_check_volume(struct ocfs2_super *osb)
2392{
Denis Chengbddb8eb32007-09-27 02:10:04 +08002393 int status;
Mark Fashehccd979b2005-12-15 14:31:24 -08002394 int dirty;
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002395 int local;
Mark Fashehccd979b2005-12-15 14:31:24 -08002396 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
2397 * recover
2398 * ourselves. */
2399
Mark Fashehccd979b2005-12-15 14:31:24 -08002400 /* Init our journal object. */
2401 status = ocfs2_journal_init(osb->journal, &dirty);
2402 if (status < 0) {
2403 mlog(ML_ERROR, "Could not initialize journal!\n");
2404 goto finally;
2405 }
2406
Patrick J. LoPresti3bdb8ef2010-07-22 15:05:57 -07002407 /* Now that journal has been initialized, check to make sure
2408 entire volume is addressable. */
2409 status = ocfs2_journal_addressable(osb);
2410 if (status)
2411 goto finally;
2412
Mark Fashehccd979b2005-12-15 14:31:24 -08002413 /* If the journal was unmounted cleanly then we don't want to
2414 * recover anything. Otherwise, journal_load will do that
2415 * dirty work for us :) */
2416 if (!dirty) {
2417 status = ocfs2_journal_wipe(osb->journal, 0);
2418 if (status < 0) {
2419 mlog_errno(status);
2420 goto finally;
2421 }
2422 } else {
Sunil Mushran619c2002011-07-24 10:34:54 -07002423 printk(KERN_NOTICE "ocfs2: File system on device (%s) was not "
2424 "unmounted cleanly, recovering it.\n", osb->dev_str);
Mark Fashehccd979b2005-12-15 14:31:24 -08002425 }
2426
Sunil Mushranc271c5c2006-12-05 17:56:35 -08002427 local = ocfs2_mount_local(osb);
2428
Mark Fashehccd979b2005-12-15 14:31:24 -08002429 /* will play back anything left in the journal. */
Sunil Mushran539d8262008-07-14 17:31:10 -07002430 status = ocfs2_journal_load(osb->journal, local, dirty);
Wengang Wang01af4822008-06-10 14:24:48 +08002431 if (status < 0) {
2432 mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
2433 goto finally;
2434 }
Mark Fashehccd979b2005-12-15 14:31:24 -08002435
alex chen1dfeb762015-02-10 14:09:04 -08002436 if (osb->s_mount_opt & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
2437 jbd2_journal_set_features(osb->journal->j_journal,
2438 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2439 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2440 else
2441 jbd2_journal_clear_features(osb->journal->j_journal,
2442 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2443 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2444
Mark Fashehccd979b2005-12-15 14:31:24 -08002445 if (dirty) {
2446 /* recover my local alloc if we didn't unmount cleanly. */
2447 status = ocfs2_begin_local_alloc_recovery(osb,
2448 osb->slot_num,
2449 &local_alloc);
2450 if (status < 0) {
2451 mlog_errno(status);
2452 goto finally;
2453 }
2454 /* we complete the recovery process after we've marked
2455 * ourselves as mounted. */
2456 }
2457
Mark Fashehccd979b2005-12-15 14:31:24 -08002458 status = ocfs2_load_local_alloc(osb);
2459 if (status < 0) {
2460 mlog_errno(status);
2461 goto finally;
2462 }
2463
2464 if (dirty) {
2465 /* Recovery will be completed after we've mounted the
2466 * rest of the volume. */
Mark Fashehccd979b2005-12-15 14:31:24 -08002467 osb->local_alloc_copy = local_alloc;
2468 local_alloc = NULL;
2469 }
2470
2471 /* go through each journal, trylock it and if you get the
2472 * lock, and it's marked as dirty, set the bit in the recover
2473 * map and launch a recovery thread for it. */
2474 status = ocfs2_mark_dead_nodes(osb);
Srinivas Eeda9140db02009-03-06 14:21:46 -08002475 if (status < 0) {
2476 mlog_errno(status);
2477 goto finally;
2478 }
2479
2480 status = ocfs2_compute_replay_slots(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002481 if (status < 0)
2482 mlog_errno(status);
2483
2484finally:
Tim Gardnerd787ab02013-02-21 16:42:44 -08002485 kfree(local_alloc);
Mark Fashehccd979b2005-12-15 14:31:24 -08002486
Tao Mac1e8d352011-03-07 16:43:21 +08002487 if (status)
2488 mlog_errno(status);
Mark Fashehccd979b2005-12-15 14:31:24 -08002489 return status;
2490}
2491
2492/*
2493 * The routine gets called from dismount or close whenever a dismount on
2494 * volume is requested and the osb open count becomes 1.
2495 * It will remove the osb from the global list and also free up all the
2496 * initialized resources and fileobject.
2497 */
2498static void ocfs2_delete_osb(struct ocfs2_super *osb)
2499{
Mark Fashehccd979b2005-12-15 14:31:24 -08002500 /* This function assumes that the caller has the main osb resource */
2501
jiangyiwen35ddf782016-03-25 14:21:32 -07002502 /* ocfs2_initializer_super have already created this workqueue */
piaojun23e08132017-11-15 17:31:25 -08002503 if (osb->ocfs2_wq)
jiangyiwen35ddf782016-03-25 14:21:32 -07002504 destroy_workqueue(osb->ocfs2_wq);
jiangyiwen35ddf782016-03-25 14:21:32 -07002505
Mark Fasheh8e8a4602008-02-01 11:59:09 -08002506 ocfs2_free_slot_info(osb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002507
Mark Fashehb4df6ed2006-02-22 17:35:08 -08002508 kfree(osb->osb_orphan_wipes);
Sunil Mushran539d8262008-07-14 17:31:10 -07002509 kfree(osb->slot_recovery_generations);
Mark Fashehccd979b2005-12-15 14:31:24 -08002510 /* FIXME
2511 * This belongs in journal shutdown, but because we have to
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02002512 * allocate osb->journal at the start of ocfs2_initialize_osb(),
Mark Fashehccd979b2005-12-15 14:31:24 -08002513 * we free it here.
2514 */
2515 kfree(osb->journal);
Tim Gardnerd787ab02013-02-21 16:42:44 -08002516 kfree(osb->local_alloc_copy);
Mark Fashehccd979b2005-12-15 14:31:24 -08002517 kfree(osb->uuid_str);
Joseph Qif13a5682014-09-25 16:05:11 -07002518 kfree(osb->vol_label);
Mark Fashehccd979b2005-12-15 14:31:24 -08002519 ocfs2_put_dlm_debug(osb->osb_dlm_debug);
2520 memset(osb, 0, sizeof(struct ocfs2_super));
Mark Fashehccd979b2005-12-15 14:31:24 -08002521}
2522
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002523/* Depending on the mount option passed, perform one of the following:
2524 * Put OCFS2 into a readonly state (default)
2525 * Return EIO so that only the process errs
2526 * Fix the error as if fsck.ocfs2 -y
2527 * panic
2528 */
2529static int ocfs2_handle_error(struct super_block *sb)
Mark Fashehccd979b2005-12-15 14:31:24 -08002530{
2531 struct ocfs2_super *osb = OCFS2_SB(sb);
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002532 int rv = 0;
Mark Fashehccd979b2005-12-15 14:31:24 -08002533
2534 ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002535 pr_crit("On-disk corruption discovered. "
2536 "Please run fsck.ocfs2 once the filesystem is unmounted.\n");
Mark Fashehccd979b2005-12-15 14:31:24 -08002537
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002538 if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) {
2539 panic("OCFS2: (device %s): panic forced after error\n",
2540 sb->s_id);
2541 } else if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_CONT) {
2542 pr_crit("OCFS2: Returning error to the calling process.\n");
2543 rv = -EIO;
2544 } else { /* default option */
2545 rv = -EROFS;
David Howellsbc98a422017-07-17 08:45:34 +01002546 if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)))
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002547 return rv;
Mark Fashehccd979b2005-12-15 14:31:24 -08002548
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002549 pr_crit("OCFS2: File system is now read-only.\n");
Linus Torvalds1751e8a2017-11-27 13:05:09 -08002550 sb->s_flags |= SB_RDONLY;
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002551 ocfs2_set_ro_flag(osb, 0);
2552 }
2553
2554 return rv;
Mark Fashehccd979b2005-12-15 14:31:24 -08002555}
2556
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002557int __ocfs2_error(struct super_block *sb, const char *function,
Joe Perches1543306e2015-04-14 15:43:46 -07002558 const char *fmt, ...)
Mark Fashehccd979b2005-12-15 14:31:24 -08002559{
Joe Perches1543306e2015-04-14 15:43:46 -07002560 struct va_format vaf;
Mark Fashehccd979b2005-12-15 14:31:24 -08002561 va_list args;
2562
2563 va_start(args, fmt);
Joe Perches1543306e2015-04-14 15:43:46 -07002564 vaf.fmt = fmt;
2565 vaf.va = &args;
Mark Fashehccd979b2005-12-15 14:31:24 -08002566
2567 /* Not using mlog here because we want to show the actual
2568 * function the error came from. */
Joe Perches7ecef142015-09-04 15:44:51 -07002569 printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %pV",
Joe Perches1543306e2015-04-14 15:43:46 -07002570 sb->s_id, function, &vaf);
2571
2572 va_end(args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002573
Goldwyn Rodrigues7d0fb912015-09-04 15:44:11 -07002574 return ocfs2_handle_error(sb);
Mark Fashehccd979b2005-12-15 14:31:24 -08002575}
2576
2577/* Handle critical errors. This is intentionally more drastic than
2578 * ocfs2_handle_error, so we only use for things like journal errors,
2579 * etc. */
Joe Perches1543306e2015-04-14 15:43:46 -07002580void __ocfs2_abort(struct super_block *sb, const char *function,
Mark Fashehccd979b2005-12-15 14:31:24 -08002581 const char *fmt, ...)
2582{
Joe Perches1543306e2015-04-14 15:43:46 -07002583 struct va_format vaf;
Mark Fashehccd979b2005-12-15 14:31:24 -08002584 va_list args;
2585
2586 va_start(args, fmt);
Mark Fashehccd979b2005-12-15 14:31:24 -08002587
Joe Perches1543306e2015-04-14 15:43:46 -07002588 vaf.fmt = fmt;
2589 vaf.va = &args;
2590
Joe Perches7ecef142015-09-04 15:44:51 -07002591 printk(KERN_CRIT "OCFS2: abort (device %s): %s: %pV",
Joe Perches1543306e2015-04-14 15:43:46 -07002592 sb->s_id, function, &vaf);
2593
2594 va_end(args);
Mark Fashehccd979b2005-12-15 14:31:24 -08002595
2596 /* We don't have the cluster support yet to go straight to
2597 * hard readonly in here. Until then, we want to keep
2598 * ocfs2_abort() so that we can at least mark critical
2599 * errors.
2600 *
2601 * TODO: This should abort the journal and alert other nodes
2602 * that our slot needs recovery. */
2603
2604 /* Force a panic(). This stinks, but it's better than letting
2605 * things continue without having a proper hard readonly
2606 * here. */
Sunil Mushrana2f2ddb2009-08-19 15:16:01 -07002607 if (!ocfs2_mount_local(OCFS2_SB(sb)))
2608 OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
Mark Fashehccd979b2005-12-15 14:31:24 -08002609 ocfs2_handle_error(sb);
2610}
2611
Joel Beckere4b963f2009-09-02 17:17:36 -07002612/*
2613 * Void signal blockers, because in-kernel sigprocmask() only fails
2614 * when SIG_* is wrong.
2615 */
2616void ocfs2_block_signals(sigset_t *oldset)
2617{
2618 int rc;
2619 sigset_t blocked;
2620
2621 sigfillset(&blocked);
2622 rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
2623 BUG_ON(rc);
2624}
2625
2626void ocfs2_unblock_signals(sigset_t *oldset)
2627{
2628 int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
2629 BUG_ON(rc);
2630}
2631
Mark Fashehccd979b2005-12-15 14:31:24 -08002632module_init(ocfs2_init);
2633module_exit(ocfs2_exit);