xref: /openbmc/linux/fs/gfs2/util.h (revision d77d1b58)
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
4  *
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  */
9 
10 #ifndef __UTIL_DOT_H__
11 #define __UTIL_DOT_H__
12 
13 #ifdef pr_fmt
14 #undef pr_fmt
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #endif
17 
18 #include <linux/mempool.h>
19 
20 #include "incore.h"
21 
22 #define fs_warn(fs, fmt, ...)						\
23 	pr_warn("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
24 #define fs_err(fs, fmt, ...)						\
25 	pr_err("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
26 #define fs_info(fs, fmt, ...)						\
27 	pr_info("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
28 
29 void gfs2_assert_i(struct gfs2_sbd *sdp);
30 
31 #define gfs2_assert(sdp, assertion) \
32 do { \
33 	if (unlikely(!(assertion))) { \
34 		gfs2_assert_i(sdp); \
35 		BUG(); \
36         } \
37 } while (0)
38 
39 
40 int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
41 			   const char *function, char *file, unsigned int line);
42 
43 #define gfs2_assert_withdraw(sdp, assertion) \
44 ((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \
45 					__func__, __FILE__, __LINE__))
46 
47 
48 int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
49 		       const char *function, char *file, unsigned int line);
50 
51 #define gfs2_assert_warn(sdp, assertion) \
52 ((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \
53 					__func__, __FILE__, __LINE__))
54 
55 
56 int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide,
57 		   const char *function, char *file, unsigned int line);
58 
59 #define gfs2_consist(sdp) \
60 gfs2_consist_i((sdp), 0, __func__, __FILE__, __LINE__)
61 
62 
63 int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
64 			 const char *function, char *file, unsigned int line);
65 
66 #define gfs2_consist_inode(ip) \
67 gfs2_consist_inode_i((ip), 0, __func__, __FILE__, __LINE__)
68 
69 
70 int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
71 			 const char *function, char *file, unsigned int line);
72 
73 #define gfs2_consist_rgrpd(rgd) \
74 gfs2_consist_rgrpd_i((rgd), 0, __func__, __FILE__, __LINE__)
75 
76 
77 int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
78 		       const char *type, const char *function,
79 		       char *file, unsigned int line);
80 
81 static inline int gfs2_meta_check(struct gfs2_sbd *sdp,
82 				    struct buffer_head *bh)
83 {
84 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
85 	u32 magic = be32_to_cpu(mh->mh_magic);
86 	if (unlikely(magic != GFS2_MAGIC)) {
87 		pr_err("Magic number missing at %llu\n",
88 		       (unsigned long long)bh->b_blocknr);
89 		return -EIO;
90 	}
91 	return 0;
92 }
93 
94 int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
95 			   u16 type, u16 t,
96 			   const char *function,
97 			   char *file, unsigned int line);
98 
99 static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
100 					struct buffer_head *bh,
101 					u16 type,
102 					const char *function,
103 					char *file, unsigned int line)
104 {
105 	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
106 	u32 magic = be32_to_cpu(mh->mh_magic);
107 	u16 t = be32_to_cpu(mh->mh_type);
108 	if (unlikely(magic != GFS2_MAGIC))
109 		return gfs2_meta_check_ii(sdp, bh, "magic number", function,
110 					  file, line);
111         if (unlikely(t != type))
112 		return gfs2_metatype_check_ii(sdp, bh, type, t, function,
113 					      file, line);
114 	return 0;
115 }
116 
117 #define gfs2_metatype_check(sdp, bh, type) \
118 gfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__)
119 
120 static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
121 				     u16 format)
122 {
123 	struct gfs2_meta_header *mh;
124 	mh = (struct gfs2_meta_header *)bh->b_data;
125 	mh->mh_type = cpu_to_be32(type);
126 	mh->mh_format = cpu_to_be32(format);
127 }
128 
129 
130 int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
131 		    char *file, unsigned int line);
132 
133 #define gfs2_io_error(sdp) \
134 gfs2_io_error_i((sdp), __func__, __FILE__, __LINE__);
135 
136 
137 int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
138 		       const char *function, char *file, unsigned int line);
139 
140 #define gfs2_io_error_bh(sdp, bh) \
141 gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__);
142 
143 
144 extern struct kmem_cache *gfs2_glock_cachep;
145 extern struct kmem_cache *gfs2_glock_aspace_cachep;
146 extern struct kmem_cache *gfs2_inode_cachep;
147 extern struct kmem_cache *gfs2_bufdata_cachep;
148 extern struct kmem_cache *gfs2_rgrpd_cachep;
149 extern struct kmem_cache *gfs2_quotad_cachep;
150 extern struct kmem_cache *gfs2_rsrv_cachep;
151 extern mempool_t *gfs2_page_pool;
152 
153 static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
154 					   unsigned int *p)
155 {
156 	unsigned int x;
157 	spin_lock(&gt->gt_spin);
158 	x = *p;
159 	spin_unlock(&gt->gt_spin);
160 	return x;
161 }
162 
163 #define gfs2_tune_get(sdp, field) \
164 gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field)
165 
166 int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...);
167 
168 #endif /* __UTIL_DOT_H__ */
169 
170