perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / fs / gfs2 / util.c
blob0a814ccac41d2a8106f717ae0d200dbe865c38f4
1 /*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/crc32.h>
16 #include <linux/gfs2_ondisk.h>
17 #include <linux/uaccess.h>
19 #include "gfs2.h"
20 #include "incore.h"
21 #include "glock.h"
22 #include "rgrp.h"
23 #include "util.h"
25 struct kmem_cache *gfs2_glock_cachep __read_mostly;
26 struct kmem_cache *gfs2_glock_aspace_cachep __read_mostly;
27 struct kmem_cache *gfs2_inode_cachep __read_mostly;
28 struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
29 struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
30 struct kmem_cache *gfs2_quotad_cachep __read_mostly;
31 struct kmem_cache *gfs2_qadata_cachep __read_mostly;
32 mempool_t *gfs2_page_pool __read_mostly;
34 void gfs2_assert_i(struct gfs2_sbd *sdp)
36 fs_emerg(sdp, "fatal assertion failed\n");
39 int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...)
41 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
42 const struct lm_lockops *lm = ls->ls_ops;
43 va_list args;
44 struct va_format vaf;
46 if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW &&
47 test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
48 return 0;
50 if (fmt) {
51 va_start(args, fmt);
53 vaf.fmt = fmt;
54 vaf.va = &args;
56 fs_err(sdp, "%pV", &vaf);
58 va_end(args);
61 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);
65 kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE);
67 if (!strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm"))
68 wait_for_completion(&sdp->sd_wdack);
70 if (lm->lm_unmount) {
71 fs_err(sdp, "telling LM to unmount\n");
72 lm->lm_unmount(sdp);
74 set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
75 fs_err(sdp, "withdrawn\n");
76 dump_stack();
79 if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
80 panic("GFS2: fsid=%s: panic requested\n", sdp->sd_fsname);
82 return -1;
85 /**
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
91 int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
92 const char *function, char *file, unsigned int line)
94 int me;
95 me = gfs2_lm_withdraw(sdp,
96 "fatal: assertion \"%s\" failed\n"
97 " function = %s, file = %s, line = %u\n",
98 assertion, function, file, line);
99 dump_stack();
100 return (me) ? -1 : -2;
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
109 int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
110 const char *function, char *file, unsigned int line)
112 if (time_before(jiffies,
113 sdp->sd_last_warning +
114 gfs2_tune_get(sdp, gt_complain_secs) * HZ))
115 return -2;
117 if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
118 fs_warn(sdp, "warning: assertion \"%s\" failed at function = %s, file = %s, line = %u\n",
119 assertion, function, file, line);
121 if (sdp->sd_args.ar_debug)
122 BUG();
123 else
124 dump_stack();
126 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);
132 sdp->sd_last_warning = jiffies;
134 return -1;
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
143 int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
144 char *file, unsigned int line)
146 int rv;
147 rv = gfs2_lm_withdraw(sdp,
148 "fatal: filesystem consistency error - function = %s, file = %s, line = %u\n",
149 function, file, line);
150 return rv;
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
159 int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
160 const char *function, char *file, unsigned int line)
162 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
163 int rv;
164 rv = gfs2_lm_withdraw(sdp,
165 "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);
171 return rv;
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
180 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
181 const char *function, char *file, unsigned int line)
183 struct gfs2_sbd *sdp = rgd->rd_sbd;
184 int rv;
186 gfs2_rgrp_dump(NULL, rgd->rd_gl);
187 rv = gfs2_lm_withdraw(sdp,
188 "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);
193 return rv;
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
202 int 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)
206 int me;
207 me = gfs2_lm_withdraw(sdp,
208 "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);
213 return (me) ? -1 : -2;
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
222 int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
223 u16 type, u16 t, const char *function,
224 char *file, unsigned int line)
226 int me;
227 me = gfs2_lm_withdraw(sdp,
228 "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);
233 return (me) ? -1 : -2;
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
242 int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
243 unsigned int line)
245 int rv;
246 rv = gfs2_lm_withdraw(sdp,
247 "fatal: I/O error\n"
248 " function = %s, file = %s, line = %u\n",
249 function, file, line);
250 return rv;
254 * gfs2_io_error_bh_i - Flag a buffer I/O error
255 * @withdraw: withdraw the filesystem
258 void 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)
262 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);
269 if (withdraw)
270 gfs2_lm_withdraw(sdp, NULL);