blob: 0a814ccac41d2a8106f717ae0d200dbe865c38f4 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
Joe Perchesd77d1b52014-03-06 12:10:45 -080010#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
David Teiglandb3b94fa2006-01-16 16:50:04 +000012#include <linux/spinlock.h>
13#include <linux/completion.h>
14#include <linux/buffer_head.h>
15#include <linux/crc32.h>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050016#include <linux/gfs2_ondisk.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080017#include <linux/uaccess.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000018
19#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050020#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000021#include "glock.h"
Bob Peterson72244b62018-08-15 12:09:49 -050022#include "rgrp.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050023#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000024
Christoph Lametere18b8902006-12-06 20:33:20 -080025struct kmem_cache *gfs2_glock_cachep __read_mostly;
Steven Whitehouse009d8512009-12-08 12:12:13 +000026struct kmem_cache *gfs2_glock_aspace_cachep __read_mostly;
Christoph Lametere18b8902006-12-06 20:33:20 -080027struct kmem_cache *gfs2_inode_cachep __read_mostly;
28struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
Bob Peterson6bdd9be2008-01-28 17:20:26 -060029struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
Steven Whitehouse37b2c832008-11-17 14:25:37 +000030struct kmem_cache *gfs2_quotad_cachep __read_mostly;
Bob Petersonb54e9a02015-10-26 10:40:28 -050031struct kmem_cache *gfs2_qadata_cachep __read_mostly;
Steven Whitehousee8c92ed2012-04-16 09:28:31 +010032mempool_t *gfs2_page_pool __read_mostly;
David Teiglandb3b94fa2006-01-16 16:50:04 +000033
David Teiglandb3b94fa2006-01-16 16:50:04 +000034void gfs2_assert_i(struct gfs2_sbd *sdp)
35{
Joe Perches8382e262014-03-06 12:10:46 -080036 fs_emerg(sdp, "fatal assertion failed\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +000037}
38
Joe Perchescb94eb02014-03-06 12:17:21 -080039int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...)
Steven Whitehouseda755fd2008-01-30 15:34:04 +000040{
Steven Whitehousef057f6c2009-01-12 10:43:39 +000041 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
42 const struct lm_lockops *lm = ls->ls_ops;
Steven Whitehouseda755fd2008-01-30 15:34:04 +000043 va_list args;
Joe Perchescb94eb02014-03-06 12:17:21 -080044 struct va_format vaf;
Steven Whitehouseda755fd2008-01-30 15:34:04 +000045
Bob Petersond34843d2009-08-24 10:44:18 +010046 if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW &&
47 test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
Steven Whitehouseda755fd2008-01-30 15:34:04 +000048 return 0;
49
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +010050 if (fmt) {
51 va_start(args, fmt);
Joe Perchescb94eb02014-03-06 12:17:21 -080052
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +010053 vaf.fmt = fmt;
54 vaf.va = &args;
Joe Perchescb94eb02014-03-06 12:17:21 -080055
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +010056 fs_err(sdp, "%pV", &vaf);
Joe Perchescb94eb02014-03-06 12:17:21 -080057
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +010058 va_end(args);
59 }
Steven Whitehouseda755fd2008-01-30 15:34:04 +000060
Bob Petersond34843d2009-08-24 10:44:18 +010061 if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW) {
62 fs_err(sdp, "about to withdraw this file system\n");
63 BUG_ON(sdp->sd_args.ar_debug);
Steven Whitehouseda755fd2008-01-30 15:34:04 +000064
Bob Petersond34843d2009-08-24 10:44:18 +010065 kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE);
Steven Whitehousef057f6c2009-01-12 10:43:39 +000066
Steven Whitehousefd95e812013-02-13 12:21:40 +000067 if (!strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm"))
68 wait_for_completion(&sdp->sd_wdack);
69
Bob Petersond34843d2009-08-24 10:44:18 +010070 if (lm->lm_unmount) {
71 fs_err(sdp, "telling LM to unmount\n");
72 lm->lm_unmount(sdp);
73 }
Benjamin Marzinski3e11e532016-03-23 14:29:59 -040074 set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
Bob Petersond34843d2009-08-24 10:44:18 +010075 fs_err(sdp, "withdrawn\n");
76 dump_stack();
Steven Whitehousef057f6c2009-01-12 10:43:39 +000077 }
Bob Petersond34843d2009-08-24 10:44:18 +010078
79 if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
Joe Perchesd77d1b52014-03-06 12:10:45 -080080 panic("GFS2: fsid=%s: panic requested\n", sdp->sd_fsname);
Steven Whitehouseda755fd2008-01-30 15:34:04 +000081
82 return -1;
83}
84
David Teiglandb3b94fa2006-01-16 16:50:04 +000085/**
86 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
87 * Returns: -1 if this call withdrew the machine,
88 * -2 if it was already withdrawn
89 */
90
91int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
92 const char *function, char *file, unsigned int line)
93{
94 int me;
95 me = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -080096 "fatal: assertion \"%s\" failed\n"
97 " function = %s, file = %s, line = %u\n",
98 assertion, function, file, line);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000099 dump_stack();
David Teiglandb3b94fa2006-01-16 16:50:04 +0000100 return (me) ? -1 : -2;
101}
102
103/**
104 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
105 * Returns: -1 if we printed something
106 * -2 if we didn't
107 */
108
109int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
110 const char *function, char *file, unsigned int line)
111{
112 if (time_before(jiffies,
113 sdp->sd_last_warning +
114 gfs2_tune_get(sdp, gt_complain_secs) * HZ))
115 return -2;
116
Bob Petersond34843d2009-08-24 10:44:18 +0100117 if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
Joe Perches8382e262014-03-06 12:10:46 -0800118 fs_warn(sdp, "warning: assertion \"%s\" failed at function = %s, file = %s, line = %u\n",
119 assertion, function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000120
121 if (sdp->sd_args.ar_debug)
122 BUG();
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000123 else
124 dump_stack();
David Teiglandb3b94fa2006-01-16 16:50:04 +0000125
Bob Petersond34843d2009-08-24 10:44:18 +0100126 if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
127 panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
128 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
129 sdp->sd_fsname, assertion,
130 sdp->sd_fsname, function, file, line);
131
David Teiglandb3b94fa2006-01-16 16:50:04 +0000132 sdp->sd_last_warning = jiffies;
133
134 return -1;
135}
136
137/**
138 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
139 * Returns: -1 if this call withdrew the machine,
140 * 0 if it was already withdrawn
141 */
142
143int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
144 char *file, unsigned int line)
145{
146 int rv;
147 rv = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800148 "fatal: filesystem consistency error - function = %s, file = %s, line = %u\n",
149 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000150 return rv;
151}
152
153/**
154 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
155 * Returns: -1 if this call withdrew the machine,
156 * 0 if it was already withdrawn
157 */
158
159int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
160 const char *function, char *file, unsigned int line)
161{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400162 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000163 int rv;
164 rv = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800165 "fatal: filesystem consistency error\n"
166 " inode = %llu %llu\n"
167 " function = %s, file = %s, line = %u\n",
168 (unsigned long long)ip->i_no_formal_ino,
169 (unsigned long long)ip->i_no_addr,
170 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000171 return rv;
172}
173
174/**
175 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
176 * Returns: -1 if this call withdrew the machine,
177 * 0 if it was already withdrawn
178 */
179
180int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
181 const char *function, char *file, unsigned int line)
182{
183 struct gfs2_sbd *sdp = rgd->rd_sbd;
184 int rv;
Bob Peterson72244b62018-08-15 12:09:49 -0500185
186 gfs2_rgrp_dump(NULL, rgd->rd_gl);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000187 rv = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800188 "fatal: filesystem consistency error\n"
189 " RG = %llu\n"
190 " function = %s, file = %s, line = %u\n",
191 (unsigned long long)rgd->rd_addr,
192 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000193 return rv;
194}
195
196/**
197 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
198 * Returns: -1 if this call withdrew the machine,
199 * -2 if it was already withdrawn
200 */
201
202int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
203 const char *type, const char *function, char *file,
204 unsigned int line)
205{
206 int me;
207 me = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800208 "fatal: invalid metadata block\n"
209 " bh = %llu (%s)\n"
210 " function = %s, file = %s, line = %u\n",
211 (unsigned long long)bh->b_blocknr, type,
212 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000213 return (me) ? -1 : -2;
214}
215
216/**
217 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
218 * Returns: -1 if this call withdrew the machine,
219 * -2 if it was already withdrawn
220 */
221
222int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
Steven Whitehousecd915492006-09-04 12:49:07 -0400223 u16 type, u16 t, const char *function,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000224 char *file, unsigned int line)
225{
226 int me;
227 me = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800228 "fatal: invalid metadata block\n"
229 " bh = %llu (type: exp=%u, found=%u)\n"
230 " function = %s, file = %s, line = %u\n",
231 (unsigned long long)bh->b_blocknr, type, t,
232 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000233 return (me) ? -1 : -2;
234}
235
236/**
237 * gfs2_io_error_i - Flag an I/O error and withdraw
238 * Returns: -1 if this call withdrew the machine,
239 * 0 if it was already withdrawn
240 */
241
242int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
243 unsigned int line)
244{
245 int rv;
246 rv = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800247 "fatal: I/O error\n"
248 " function = %s, file = %s, line = %u\n",
249 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000250 return rv;
251}
252
253/**
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +0100254 * gfs2_io_error_bh_i - Flag a buffer I/O error
255 * @withdraw: withdraw the filesystem
David Teiglandb3b94fa2006-01-16 16:50:04 +0000256 */
257
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +0100258void gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
259 const char *function, char *file, unsigned int line,
260 bool withdraw)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000261{
Bob Petersonb524abc2018-10-04 10:21:07 -0500262 if (!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
263 fs_err(sdp,
264 "fatal: I/O error\n"
265 " block = %llu\n"
266 " function = %s, file = %s, line = %u\n",
267 (unsigned long long)bh->b_blocknr,
268 function, file, line);
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +0100269 if (withdraw)
270 gfs2_lm_withdraw(sdp, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000271}
272