blob: 59c811de0dc7a36e58ede891c3dde0735d911cab [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"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050022#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000023
Christoph Lametere18b8902006-12-06 20:33:20 -080024struct kmem_cache *gfs2_glock_cachep __read_mostly;
Steven Whitehouse009d8512009-12-08 12:12:13 +000025struct kmem_cache *gfs2_glock_aspace_cachep __read_mostly;
Christoph Lametere18b8902006-12-06 20:33:20 -080026struct kmem_cache *gfs2_inode_cachep __read_mostly;
27struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
Bob Peterson6bdd9be2008-01-28 17:20:26 -060028struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
Steven Whitehouse37b2c832008-11-17 14:25:37 +000029struct kmem_cache *gfs2_quotad_cachep __read_mostly;
Bob Petersonb54e9a02015-10-26 10:40:28 -050030struct kmem_cache *gfs2_qadata_cachep __read_mostly;
Steven Whitehousee8c92ed2012-04-16 09:28:31 +010031mempool_t *gfs2_page_pool __read_mostly;
David Teiglandb3b94fa2006-01-16 16:50:04 +000032
David Teiglandb3b94fa2006-01-16 16:50:04 +000033void gfs2_assert_i(struct gfs2_sbd *sdp)
34{
Joe Perches8382e262014-03-06 12:10:46 -080035 fs_emerg(sdp, "fatal assertion failed\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +000036}
37
Joe Perchescb94eb02014-03-06 12:17:21 -080038int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...)
Steven Whitehouseda755fd2008-01-30 15:34:04 +000039{
Steven Whitehousef057f6c2009-01-12 10:43:39 +000040 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
41 const struct lm_lockops *lm = ls->ls_ops;
Steven Whitehouseda755fd2008-01-30 15:34:04 +000042 va_list args;
Joe Perchescb94eb02014-03-06 12:17:21 -080043 struct va_format vaf;
Steven Whitehouseda755fd2008-01-30 15:34:04 +000044
Bob Petersond34843d2009-08-24 10:44:18 +010045 if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW &&
46 test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
Steven Whitehouseda755fd2008-01-30 15:34:04 +000047 return 0;
48
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +010049 if (fmt) {
50 va_start(args, fmt);
Joe Perchescb94eb02014-03-06 12:17:21 -080051
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +010052 vaf.fmt = fmt;
53 vaf.va = &args;
Joe Perchescb94eb02014-03-06 12:17:21 -080054
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +010055 fs_err(sdp, "%pV", &vaf);
Joe Perchescb94eb02014-03-06 12:17:21 -080056
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +010057 va_end(args);
58 }
Steven Whitehouseda755fd2008-01-30 15:34:04 +000059
Bob Petersond34843d2009-08-24 10:44:18 +010060 if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW) {
61 fs_err(sdp, "about to withdraw this file system\n");
62 BUG_ON(sdp->sd_args.ar_debug);
Steven Whitehouseda755fd2008-01-30 15:34:04 +000063
Bob Petersond34843d2009-08-24 10:44:18 +010064 kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE);
Steven Whitehousef057f6c2009-01-12 10:43:39 +000065
Steven Whitehousefd95e812013-02-13 12:21:40 +000066 if (!strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm"))
67 wait_for_completion(&sdp->sd_wdack);
68
Bob Petersond34843d2009-08-24 10:44:18 +010069 if (lm->lm_unmount) {
70 fs_err(sdp, "telling LM to unmount\n");
71 lm->lm_unmount(sdp);
72 }
Benjamin Marzinski3e11e5302016-03-23 14:29:59 -040073 set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
Bob Petersond34843d2009-08-24 10:44:18 +010074 fs_err(sdp, "withdrawn\n");
75 dump_stack();
Steven Whitehousef057f6c2009-01-12 10:43:39 +000076 }
Bob Petersond34843d2009-08-24 10:44:18 +010077
78 if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
Joe Perchesd77d1b52014-03-06 12:10:45 -080079 panic("GFS2: fsid=%s: panic requested\n", sdp->sd_fsname);
Steven Whitehouseda755fd2008-01-30 15:34:04 +000080
81 return -1;
82}
83
David Teiglandb3b94fa2006-01-16 16:50:04 +000084/**
85 * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
86 * Returns: -1 if this call withdrew the machine,
87 * -2 if it was already withdrawn
88 */
89
90int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
91 const char *function, char *file, unsigned int line)
92{
93 int me;
94 me = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -080095 "fatal: assertion \"%s\" failed\n"
96 " function = %s, file = %s, line = %u\n",
97 assertion, function, file, line);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000098 dump_stack();
David Teiglandb3b94fa2006-01-16 16:50:04 +000099 return (me) ? -1 : -2;
100}
101
102/**
103 * gfs2_assert_warn_i - Print a message to the console if @assertion is false
104 * Returns: -1 if we printed something
105 * -2 if we didn't
106 */
107
108int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
109 const char *function, char *file, unsigned int line)
110{
111 if (time_before(jiffies,
112 sdp->sd_last_warning +
113 gfs2_tune_get(sdp, gt_complain_secs) * HZ))
114 return -2;
115
Bob Petersond34843d2009-08-24 10:44:18 +0100116 if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
Joe Perches8382e262014-03-06 12:10:46 -0800117 fs_warn(sdp, "warning: assertion \"%s\" failed at function = %s, file = %s, line = %u\n",
118 assertion, function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000119
120 if (sdp->sd_args.ar_debug)
121 BUG();
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000122 else
123 dump_stack();
David Teiglandb3b94fa2006-01-16 16:50:04 +0000124
Bob Petersond34843d2009-08-24 10:44:18 +0100125 if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
126 panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
127 "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
128 sdp->sd_fsname, assertion,
129 sdp->sd_fsname, function, file, line);
130
David Teiglandb3b94fa2006-01-16 16:50:04 +0000131 sdp->sd_last_warning = jiffies;
132
133 return -1;
134}
135
136/**
137 * gfs2_consist_i - Flag a filesystem consistency error and withdraw
138 * Returns: -1 if this call withdrew the machine,
139 * 0 if it was already withdrawn
140 */
141
142int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
143 char *file, unsigned int line)
144{
145 int rv;
146 rv = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800147 "fatal: filesystem consistency error - function = %s, file = %s, line = %u\n",
148 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000149 return rv;
150}
151
152/**
153 * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
154 * Returns: -1 if this call withdrew the machine,
155 * 0 if it was already withdrawn
156 */
157
158int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
159 const char *function, char *file, unsigned int line)
160{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400161 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000162 int rv;
163 rv = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800164 "fatal: filesystem consistency error\n"
165 " inode = %llu %llu\n"
166 " function = %s, file = %s, line = %u\n",
167 (unsigned long long)ip->i_no_formal_ino,
168 (unsigned long long)ip->i_no_addr,
169 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000170 return rv;
171}
172
173/**
174 * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
175 * Returns: -1 if this call withdrew the machine,
176 * 0 if it was already withdrawn
177 */
178
179int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
180 const char *function, char *file, unsigned int line)
181{
182 struct gfs2_sbd *sdp = rgd->rd_sbd;
183 int rv;
184 rv = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800185 "fatal: filesystem consistency error\n"
186 " RG = %llu\n"
187 " function = %s, file = %s, line = %u\n",
188 (unsigned long long)rgd->rd_addr,
189 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000190 return rv;
191}
192
193/**
194 * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
195 * Returns: -1 if this call withdrew the machine,
196 * -2 if it was already withdrawn
197 */
198
199int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
200 const char *type, const char *function, char *file,
201 unsigned int line)
202{
203 int me;
204 me = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800205 "fatal: invalid metadata block\n"
206 " bh = %llu (%s)\n"
207 " function = %s, file = %s, line = %u\n",
208 (unsigned long long)bh->b_blocknr, type,
209 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000210 return (me) ? -1 : -2;
211}
212
213/**
214 * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
215 * Returns: -1 if this call withdrew the machine,
216 * -2 if it was already withdrawn
217 */
218
219int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
Steven Whitehousecd915492006-09-04 12:49:07 -0400220 u16 type, u16 t, const char *function,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000221 char *file, unsigned int line)
222{
223 int me;
224 me = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800225 "fatal: invalid metadata block\n"
226 " bh = %llu (type: exp=%u, found=%u)\n"
227 " function = %s, file = %s, line = %u\n",
228 (unsigned long long)bh->b_blocknr, type, t,
229 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000230 return (me) ? -1 : -2;
231}
232
233/**
234 * gfs2_io_error_i - Flag an I/O error and withdraw
235 * Returns: -1 if this call withdrew the machine,
236 * 0 if it was already withdrawn
237 */
238
239int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
240 unsigned int line)
241{
242 int rv;
243 rv = gfs2_lm_withdraw(sdp,
Joe Perchescb94eb02014-03-06 12:17:21 -0800244 "fatal: I/O error\n"
245 " function = %s, file = %s, line = %u\n",
246 function, file, line);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000247 return rv;
248}
249
250/**
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +0100251 * gfs2_io_error_bh_i - Flag a buffer I/O error
252 * @withdraw: withdraw the filesystem
David Teiglandb3b94fa2006-01-16 16:50:04 +0000253 */
254
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +0100255void gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
256 const char *function, char *file, unsigned int line,
257 bool withdraw)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000258{
Andreas Gruenbacher9e1a9ec2018-06-07 11:56:46 +0100259 fs_err(sdp,
260 "fatal: I/O error\n"
261 " block = %llu\n"
262 " function = %s, file = %s, line = %u\n",
263 (unsigned long long)bh->b_blocknr,
264 function, file, line);
265 if (withdraw)
266 gfs2_lm_withdraw(sdp, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000267}
268