Blame view

fs/gfs2/util.c 7.38 KB
b3b94faa5   David Teigland   [GFS2] The core o...
1
2
  /*
   * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3a8a9a103   Steven Whitehouse   [GFS2] Update cop...
3
   * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
b3b94faa5   David Teigland   [GFS2] The core o...
4
5
6
   *
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
e9fc2aa09   Steven Whitehouse   [GFS2] Update cop...
7
   * of the GNU General Public License version 2.
b3b94faa5   David Teigland   [GFS2] The core o...
8
   */
d77d1b58a   Joe Perches   GFS2: Use pr_<lev...
9
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
b3b94faa5   David Teigland   [GFS2] The core o...
10
11
12
13
  #include <linux/spinlock.h>
  #include <linux/completion.h>
  #include <linux/buffer_head.h>
  #include <linux/crc32.h>
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
14
  #include <linux/gfs2_ondisk.h>
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
15
  #include <linux/uaccess.h>
b3b94faa5   David Teigland   [GFS2] The core o...
16
17
  
  #include "gfs2.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
18
  #include "incore.h"
b3b94faa5   David Teigland   [GFS2] The core o...
19
  #include "glock.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
20
  #include "util.h"
b3b94faa5   David Teigland   [GFS2] The core o...
21

e18b890bb   Christoph Lameter   [PATCH] slab: rem...
22
  struct kmem_cache *gfs2_glock_cachep __read_mostly;
009d85183   Steven Whitehouse   GFS2: Metadata ad...
23
  struct kmem_cache *gfs2_glock_aspace_cachep __read_mostly;
e18b890bb   Christoph Lameter   [PATCH] slab: rem...
24
25
  struct kmem_cache *gfs2_inode_cachep __read_mostly;
  struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
6bdd9be62   Bob Peterson   [GFS2] Allocate g...
26
  struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
37b2c8377   Steven Whitehouse   GFS2: Clean up & ...
27
  struct kmem_cache *gfs2_quotad_cachep __read_mostly;
b54e9a0b9   Bob Peterson   GFS2: Extract quo...
28
  struct kmem_cache *gfs2_qadata_cachep __read_mostly;
e8c92ed76   Steven Whitehouse   GFS2: Clean up lo...
29
  mempool_t *gfs2_page_pool __read_mostly;
b3b94faa5   David Teigland   [GFS2] The core o...
30

b3b94faa5   David Teigland   [GFS2] The core o...
31
32
  void gfs2_assert_i(struct gfs2_sbd *sdp)
  {
8382e26b2   Joe Perches   GFS2: Use fs_<lev...
33
34
  	fs_emerg(sdp, "fatal assertion failed
  ");
b3b94faa5   David Teigland   [GFS2] The core o...
35
  }
cb94eb066   Joe Perches   GFS2: Convert gfs...
36
  int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...)
da755fdb4   Steven Whitehouse   [GFS2] Remove lm....
37
  {
f057f6cdf   Steven Whitehouse   GFS2: Merge lock_...
38
39
  	struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  	const struct lm_lockops *lm = ls->ls_ops;
da755fdb4   Steven Whitehouse   [GFS2] Remove lm....
40
  	va_list args;
cb94eb066   Joe Perches   GFS2: Convert gfs...
41
  	struct va_format vaf;
da755fdb4   Steven Whitehouse   [GFS2] Remove lm....
42

d34843d0c   Bob Peterson   GFS2: Add "-o err...
43
44
  	if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW &&
  	    test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
da755fdb4   Steven Whitehouse   [GFS2] Remove lm....
45
46
47
  		return 0;
  
  	va_start(args, fmt);
cb94eb066   Joe Perches   GFS2: Convert gfs...
48
49
50
51
52
  
  	vaf.fmt = fmt;
  	vaf.va = &args;
  
  	fs_err(sdp, "%pV", &vaf);
da755fdb4   Steven Whitehouse   [GFS2] Remove lm....
53
  	va_end(args);
d34843d0c   Bob Peterson   GFS2: Add "-o err...
54
55
56
57
  	if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW) {
  		fs_err(sdp, "about to withdraw this file system
  ");
  		BUG_ON(sdp->sd_args.ar_debug);
da755fdb4   Steven Whitehouse   [GFS2] Remove lm....
58

d34843d0c   Bob Peterson   GFS2: Add "-o err...
59
  		kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE);
f057f6cdf   Steven Whitehouse   GFS2: Merge lock_...
60

fd95e81cb   Steven Whitehouse   GFS2: Reinstate w...
61
62
  		if (!strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm"))
  			wait_for_completion(&sdp->sd_wdack);
d34843d0c   Bob Peterson   GFS2: Add "-o err...
63
64
65
66
67
  		if (lm->lm_unmount) {
  			fs_err(sdp, "telling LM to unmount
  ");
  			lm->lm_unmount(sdp);
  		}
3e11e5304   Benjamin Marzinski   GFS2: ignore unlo...
68
  		set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
d34843d0c   Bob Peterson   GFS2: Add "-o err...
69
70
71
  		fs_err(sdp, "withdrawn
  ");
  		dump_stack();
f057f6cdf   Steven Whitehouse   GFS2: Merge lock_...
72
  	}
d34843d0c   Bob Peterson   GFS2: Add "-o err...
73
74
  
  	if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
d77d1b58a   Joe Perches   GFS2: Use pr_<lev...
75
76
  		panic("GFS2: fsid=%s: panic requested
  ", sdp->sd_fsname);
da755fdb4   Steven Whitehouse   [GFS2] Remove lm....
77
78
79
  
  	return -1;
  }
b3b94faa5   David Teigland   [GFS2] The core o...
80
81
82
83
84
85
86
87
88
89
90
  /**
   * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
   * Returns: -1 if this call withdrew the machine,
   *          -2 if it was already withdrawn
   */
  
  int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  			   const char *function, char *file, unsigned int line)
  {
  	int me;
  	me = gfs2_lm_withdraw(sdp,
cb94eb066   Joe Perches   GFS2: Convert gfs...
91
92
93
94
95
  			      "fatal: assertion \"%s\" failed
  "
  			      "   function = %s, file = %s, line = %u
  ",
  			      assertion, function, file, line);
18ec7d5c3   Steven Whitehouse   [GFS2] Make journ...
96
  	dump_stack();
b3b94faa5   David Teigland   [GFS2] The core o...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  	return (me) ? -1 : -2;
  }
  
  /**
   * gfs2_assert_warn_i - Print a message to the console if @assertion is false
   * Returns: -1 if we printed something
   *          -2 if we didn't
   */
  
  int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  		       const char *function, char *file, unsigned int line)
  {
  	if (time_before(jiffies,
  			sdp->sd_last_warning +
  			gfs2_tune_get(sdp, gt_complain_secs) * HZ))
  		return -2;
d34843d0c   Bob Peterson   GFS2: Add "-o err...
113
  	if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
8382e26b2   Joe Perches   GFS2: Use fs_<lev...
114
115
116
  		fs_warn(sdp, "warning: assertion \"%s\" failed at function = %s, file = %s, line = %u
  ",
  			assertion, function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
117
118
119
  
  	if (sdp->sd_args.ar_debug)
  		BUG();
18ec7d5c3   Steven Whitehouse   [GFS2] Make journ...
120
121
  	else
  		dump_stack();
b3b94faa5   David Teigland   [GFS2] The core o...
122

d34843d0c   Bob Peterson   GFS2: Add "-o err...
123
124
125
126
127
128
129
  	if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
  		panic("GFS2: fsid=%s: warning: assertion \"%s\" failed
  "
  		      "GFS2: fsid=%s:   function = %s, file = %s, line = %u
  ",
  		      sdp->sd_fsname, assertion,
  		      sdp->sd_fsname, function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  	sdp->sd_last_warning = jiffies;
  
  	return -1;
  }
  
  /**
   * gfs2_consist_i - Flag a filesystem consistency error and withdraw
   * Returns: -1 if this call withdrew the machine,
   *          0 if it was already withdrawn
   */
  
  int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
  		   char *file, unsigned int line)
  {
  	int rv;
  	rv = gfs2_lm_withdraw(sdp,
cb94eb066   Joe Perches   GFS2: Convert gfs...
146
147
148
  			      "fatal: filesystem consistency error - function = %s, file = %s, line = %u
  ",
  			      function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
149
150
151
152
153
154
155
156
157
158
159
160
  	return rv;
  }
  
  /**
   * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
   * Returns: -1 if this call withdrew the machine,
   *          0 if it was already withdrawn
   */
  
  int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
  			 const char *function, char *file, unsigned int line)
  {
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
161
  	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
b3b94faa5   David Teigland   [GFS2] The core o...
162
163
  	int rv;
  	rv = gfs2_lm_withdraw(sdp,
cb94eb066   Joe Perches   GFS2: Convert gfs...
164
165
166
167
168
169
170
171
172
  			      "fatal: filesystem consistency error
  "
  			      "  inode = %llu %llu
  "
  			      "  function = %s, file = %s, line = %u
  ",
  			      (unsigned long long)ip->i_no_formal_ino,
  			      (unsigned long long)ip->i_no_addr,
  			      function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
  	return rv;
  }
  
  /**
   * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
   * Returns: -1 if this call withdrew the machine,
   *          0 if it was already withdrawn
   */
  
  int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  			 const char *function, char *file, unsigned int line)
  {
  	struct gfs2_sbd *sdp = rgd->rd_sbd;
  	int rv;
  	rv = gfs2_lm_withdraw(sdp,
cb94eb066   Joe Perches   GFS2: Convert gfs...
188
189
190
191
192
193
194
195
  			      "fatal: filesystem consistency error
  "
  			      "  RG = %llu
  "
  			      "  function = %s, file = %s, line = %u
  ",
  			      (unsigned long long)rgd->rd_addr,
  			      function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  	return rv;
  }
  
  /**
   * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
   * Returns: -1 if this call withdrew the machine,
   *          -2 if it was already withdrawn
   */
  
  int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  		       const char *type, const char *function, char *file,
  		       unsigned int line)
  {
  	int me;
  	me = gfs2_lm_withdraw(sdp,
cb94eb066   Joe Perches   GFS2: Convert gfs...
211
212
213
214
215
216
217
218
  			      "fatal: invalid metadata block
  "
  			      "  bh = %llu (%s)
  "
  			      "  function = %s, file = %s, line = %u
  ",
  			      (unsigned long long)bh->b_blocknr, type,
  			      function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
219
220
221
222
223
224
225
226
227
228
  	return (me) ? -1 : -2;
  }
  
  /**
   * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
   * Returns: -1 if this call withdrew the machine,
   *          -2 if it was already withdrawn
   */
  
  int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
cd915493f   Steven Whitehouse   [GFS2] Change all...
229
  			   u16 type, u16 t, const char *function,
b3b94faa5   David Teigland   [GFS2] The core o...
230
231
232
233
  			   char *file, unsigned int line)
  {
  	int me;
  	me = gfs2_lm_withdraw(sdp,
cb94eb066   Joe Perches   GFS2: Convert gfs...
234
235
236
237
238
239
240
241
  			      "fatal: invalid metadata block
  "
  			      "  bh = %llu (type: exp=%u, found=%u)
  "
  			      "  function = %s, file = %s, line = %u
  ",
  			      (unsigned long long)bh->b_blocknr, type, t,
  			      function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
  	return (me) ? -1 : -2;
  }
  
  /**
   * gfs2_io_error_i - Flag an I/O error and withdraw
   * Returns: -1 if this call withdrew the machine,
   *          0 if it was already withdrawn
   */
  
  int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
  		    unsigned int line)
  {
  	int rv;
  	rv = gfs2_lm_withdraw(sdp,
cb94eb066   Joe Perches   GFS2: Convert gfs...
256
257
258
259
260
  			      "fatal: I/O error
  "
  			      "  function = %s, file = %s, line = %u
  ",
  			      function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
261
262
263
264
265
266
267
268
269
270
271
272
273
274
  	return rv;
  }
  
  /**
   * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
   * Returns: -1 if this call withdrew the machine,
   *          0 if it was already withdrawn
   */
  
  int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  		       const char *function, char *file, unsigned int line)
  {
  	int rv;
  	rv = gfs2_lm_withdraw(sdp,
cb94eb066   Joe Perches   GFS2: Convert gfs...
275
276
277
278
279
280
281
282
  			      "fatal: I/O error
  "
  			      "  block = %llu
  "
  			      "  function = %s, file = %s, line = %u
  ",
  			      (unsigned long long)bh->b_blocknr,
  			      function, file, line);
b3b94faa5   David Teigland   [GFS2] The core o...
283
284
  	return rv;
  }